Permalink
Browse files

Merge branch 'master' of github.com:gnocuil/DHCPv4-over-v6

  • Loading branch information...
2 parents 8d162a5 + 9dad36b commit 94c5cbdb5d892f797c8f6fb2d842abce709a22b6 @YangjunZ YangjunZ committed Oct 9, 2012
@@ -161,7 +161,7 @@ struct dhcp_packet {
#define DHO_VIVCO_SUBOPTIONS 124
#define DHO_VIVSO_SUBOPTIONS 125
-#define DHO_PORT_SET 198 /*pset option, added*/
+#define DHO_PORT_SET 224 /*pset option, added*/
#define DHO_END 255
@@ -337,7 +337,7 @@ do_number_hash(const void *key, unsigned len, unsigned size)
unsigned
do_ip4_hash(const void *key, unsigned len, unsigned size)
-{
+{//printf("do_ip4_hash!\n");
u_int32_t number;
memcpy(&number, key, 4);
@@ -381,7 +381,7 @@ int mask_bits_pset(u_int16_t mask)//[pset] added by Liu Cong
unsigned
do_ip4_pset_hash(const void *key, unsigned len, unsigned size)//[pset] added by Liu Cong
-{
+{//printf("do_ip4_pset_hash!\n");
struct iaddr_pset* ip_pset = (struct iaddr_pset*) key;
u_int32_t number = do_ip4_hash(ip_pset->ip_addr.iabuf, len, size);
int bits = mask_bits_pset(ip_pset->pset_mask);
@@ -1407,7 +1407,7 @@ int permit_list_match (struct permit *lhs, struct permit *rhs)
}
return 1;
}
-
+extern void print_shared_network(struct shared_network *sn);
void parse_pool_statement (cfile, group, type)
struct parse *cfile;
struct group *group;
@@ -1514,9 +1514,13 @@ void parse_pool_statement (cfile, group, type)
#endif
case RANGE:
+printf("before parse_address_range...\n");
+print_shared_network(group->shared_network);
next_token (&val, (unsigned *)0, cfile);
parse_address_range (cfile, group, type,
pool, &lpchain);
+printf("after parse_address_range...\n");
+print_shared_network(group->shared_network);
break;
case ALLOW:
permit_head = &pool -> permit_list;
@@ -1679,7 +1683,8 @@ void parse_pool_statement (cfile, group, type)
!permit_list_match (pool -> prohibit_list,
pp -> prohibit_list))
continue;
-
+printf("*******************************merge!!!***********************\n");
+printf("pp->free=%x frees=%d\n", (int)pp->free, pp->free_leases);
/* Okay, we can merge these two pools. All we have to
do is fix up the leases, which all point to their pool. */
for (lp = lpchain; lp; lp = lp -> next) {
@@ -81,6 +81,27 @@ const int dhcp_type_name_max = ((sizeof dhcp_type_names) / sizeof (char *));
# define send_packet trace_packet_send
#endif
+static int
+checkPortsetInOption55(struct packet *packet) {
+ struct option_cache *oc;
+ oc = lookup_option (&dhcp_universe, packet -> options,
+ DHO_DHCP_PARAMETER_REQUEST_LIST);
+ if (oc) {
+
+ int i;
+ for (i = 0; i < oc->data.len; ++i) {
+ //printf("%d ", (unsigned int)oc->data.data[i]);
+ if (oc->data.data[i] == DHO_PORT_SET) {//found 224 in option 55!
+ printf("found 224 in option 55!\n");
+ return 1;
+ }
+ }
+ //printf("\n");
+ }
+ printf("didn't find 224 in option 55...\n");
+ return 0;
+}
+
void
dhcp (struct packet *packet) {
int ms_nulltp = 0;
@@ -148,7 +169,7 @@ dhcp (struct packet *packet) {
{
struct iaddr cip;
struct iaddr_pset ipset;//get pset-option from request packet. sunqi
-
+ printf("*************************dhcp.c,line 151***************\n");
/********if pset option exists, get it; else use original method. sunqi*******/
ipset.ip_addr.len = sizeof packet -> raw -> ciaddr;
@@ -158,7 +179,7 @@ dhcp (struct packet *packet) {
DHO_PORT_SET);
memset (&data, 0, sizeof data);
if (oc &&
- evaluate_option_cache (&data, packet, (struct lease)0,
+ evaluate_option_cache (&data, packet, (struct lease*)0,
(struct client_state *)0,
packet -> options, (struct option_state*)0,
&global_scope, oc, MDL)){
@@ -251,7 +272,10 @@ dhcp (struct packet *packet) {
/* Classify the client. */
classify_client (packet);
-
+
+ /* [pset] check whether option 55 contains port set option */
+ //checkPortsetInOption55(packet);
+
switch (packet -> packet_type) {
case DHCPDISCOVER:
dhcpdiscover (packet, ms_nulltp);
@@ -307,9 +331,12 @@ void dhcpdiscover (packet, ms_nulltp)
dhcp_failover_state_t *peer;
#endif
+ /* [pset] check whether option 55 contains port set option */
+ checkPortsetInOption55(packet);
+
find_lease (&lease, packet, packet -> shared_network,
0, &peer_has_leases, (struct lease *)0, MDL);
-
+ printf("dhcpdiscover: lease=%x mask=%x\n", (int)lease, lease?lease->ip_pset.pset_mask:0);//[pset]temp
if (lease && lease -> client_hostname) {
if ((strlen (lease -> client_hostname) <= 64) &&
db_printable((unsigned char *)lease->client_hostname))
@@ -375,10 +402,10 @@ void dhcpdiscover (packet, ms_nulltp)
#endif
/* If we didn't find a lease, try to allocate one... */
- if (!lease) {
+ if (!lease) {printf("before allocate_lease : shared_network=%x\n", (int)packet->shared_network);
if (!allocate_lease (&lease, packet,
packet -> shared_network -> pools,
- &peer_has_leases)) {
+ &peer_has_leases)) {printf("cannot allocate a lease!\n");
if (peer_has_leases)
log_error ("%s: peer holds all free leases",
msgbuf);
@@ -389,7 +416,7 @@ void dhcpdiscover (packet, ms_nulltp)
return;
}
}
-
+printf("allocated ip=%s\n", piaddr(lease->ip_pset.ip_addr));
#if defined (FAILOVER_PROTOCOL)
if (lease && lease -> pool && lease -> pool -> failover_peer) {
peer = lease -> pool -> failover_peer;
@@ -437,7 +464,7 @@ void dhcprequest (packet, ms_nulltp, ip_lease)
struct packet *packet;
int ms_nulltp;
struct lease *ip_lease;
-{
+{printf("dhcprequest!\n");
struct lease *lease;
struct iaddr cip;
struct iaddr sip;
@@ -2721,9 +2748,9 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp, hp)
if( !lookup_option(&dhcp_universe, state->options,i)){
oc = (struct option_cache *) 0;
if(option_cache_allocate(&oc, MDL)){
- u_int32_t tmp = htons(lease->ip_pset.pset_index) << 16 + htons(lease->ip_pset.pset_mask);
+ u_int32_t tmp = htons((lease->ip_pset.pset_index) << 16) + htons(lease->ip_pset.pset_mask);
if(make_const_data( &oc->expression,
- &tmp, 4,
+ (const unsigned char *)&tmp, 4,
0, 0, MDL)){
option_code_hash_lookup( &oc->option,
dhcp_universe.code_hash,
@@ -4152,7 +4179,12 @@ int allocate_lease (struct lease **lp, struct packet *packet,
struct lease *lease = (struct lease *)0;
struct lease *candl = (struct lease *)0;
- for (; pool ; pool = pool -> next) {
+ for (; pool ; pool = pool -> next) {printf("allocate_lease : pool=%x\n", (int)pool);
+ printf("pool=%x\n", (int)pool);
+ printf("pool->lease_count=%d\n", pool->lease_count);
+ printf("pool->free_leases=%d\n", pool->free_leases);
+ printf("pool->free=%x\n", (int)pool->free);
+ printf("pool->next=%x\n", (int)pool->next);
if ((pool -> prohibit_list &&
permitted (packet, pool -> prohibit_list)) ||
(pool -> permit_list &&
@@ -4222,7 +4254,7 @@ int allocate_lease (struct lease **lp, struct packet *packet,
if (pool -> free)
candl = pool -> free;
else
- candl = pool -> abandoned;
+ candl = pool -> abandoned;//printf("ip=%s\n", piaddr (candl->ip_pset.ip_addr));
}
/*
@@ -27,19 +27,24 @@ log-facility local7;
# The following line has been defined in the tables.c file.
# option port-set code 198 = array of unsigned integer 16;
-subnet 192.168.1.0 netmask 255.255.255.0 {
- option port-set 0xF800;
-
- range 192.168.1.10 192.168.1.100;
- option routers 192.168.1.1;
- option domain-name-servers 8.8.8.8;
-
-}
-
-subnet 192.168.1.0 netmask 255.255.255.0 {
- range 192.168.1.151 192.168.1.200;
- option routers 192.168.1.1;
- option domain-name-servers 8.8.8.8;
+shared-network gnocuil {
+ subnet 192.168.2.0 netmask 255.255.255.0 {
+ option routers 192.168.1.1;
+ option domain-name-servers 8.8.8.8;
+ }
+
+ subnet 192.168.1.0 netmask 255.255.255.0 {
+ option port-set 0xF800;
+ option routers 192.168.1.1;
+ option domain-name-servers 8.8.8.8;
+
+ }
+ pool {
+ range 192.168.2.151 192.168.2.200;
+ }
+ pool {
+ range 192.168.1.10 192.168.1.100;
+ }
}
@@ -1,14 +1,5 @@
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.2.3-P2
-server-duid "\000\001\000\001\027\371\\t\010\000',\302\257";
+server-duid "\000\001\000\001\030\0060E\010\000'\366\002\307";
-lease 192.168.1.151 {
- starts 6 2012/10/06 16:53:40;
- ends 6 2012/10/06 17:03:40;
- cltt 6 2012/10/06 16:53:40;
- binding state active;
- next binding state free;
- rewind binding state free;
- hardware ethernet 08:00:27:f3:0f:45;
-}
@@ -0,0 +1,22 @@
+# The format of this file is documented in the dhcpd.leases(5) manual page.
+# This lease file was written by isc-dhcp-4.2.3-P2
+
+lease 192.168.1.151 {
+ starts 1 2012/10/08 14:41:04;
+ ends 1 2012/10/08 14:51:04;
+ tstp 1 2012/10/08 14:51:04;
+ cltt 1 2012/10/08 14:41:04;
+ binding state free;
+ hardware ethernet 08:00:27:f3:0f:45;
+}
+server-duid "\000\001\000\001\027\371\\t\010\000',\302\257";
+
+lease 192.168.1.151 {
+ starts 1 2012/10/08 14:51:32;
+ ends 1 2012/10/08 15:01:32;
+ cltt 1 2012/10/08 14:51:32;
+ binding state active;
+ next binding state free;
+ rewind binding state free;
+ hardware ethernet 08:00:27:f3:0f:45;
+}
@@ -1,24 +0,0 @@
-# The format of this file is documented in the dhcpd.leases(5) manual page.
-# This lease file was written by isc-dhcp-4.2.3-P2
-
-lease 192.168.1.101 {
- starts 6 2012/10/06 16:48:12;
- ends 6 2012/10/06 16:58:12;
- tstp 6 2012/10/06 16:58:12;
- cltt 6 2012/10/06 16:48:12;
- binding state active;
- next binding state free;
- rewind binding state free;
- hardware ethernet 08:00:27:f3:0f:45;
-}
-server-duid "\000\001\000\001\027\371\\t\010\000',\302\257";
-
-lease 192.168.1.101 {
- starts 6 2012/10/06 16:52:22;
- ends 6 2012/10/06 17:02:22;
- cltt 6 2012/10/06 16:52:22;
- binding state active;
- next binding state free;
- rewind binding state free;
- hardware ethernet 08:00:27:f3:0f:45;
-}
View
@@ -715,15 +715,28 @@ int find_host_for_network (struct subnet **sp, struct host_decl **host,
return 0;
}
-
+void print_shared_network(struct shared_network *sn)
+{
+ printf("---------------print_shared_network : 0x%x---------------\n", (int)sn);
+ struct pool *pool = sn->pools;
+ for (; pool; pool = pool->next) {
+ printf("pool=%x\n", (int)pool);
+ printf("\tpool->lease_count=%d\n", pool->lease_count);
+ printf("\tpool->free_leases=%d\n", pool->free_leases);
+ printf("\tpool->free=%x\n", (int)pool->free);
+ }
+ printf("---------------print_shared_network over---------------\n");
+}
void new_address_range (cfile, low, high, subnet, pool, lpchain)
struct parse *cfile;
struct iaddr low, high;
struct subnet *subnet;
struct pool *pool;
struct lease **lpchain;
-{
+{printf("new_address_range: subnet=%x, subnet->shared_network=%x\n", (int)subnet, (int)subnet->shared_network);
+ printf("subnet->shared_network->pools=%x pool=%x\n", (int)subnet->shared_network->pools, (int)pool);
+
#if defined(COMPACT_LEASES)
struct lease *address_range;
struct lease *address_port_range;//[pset]
@@ -773,7 +786,7 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
ratio1 = 0;
for (ep = subnet -> group -> statements; ep; ep = ep -> next) {
if (ep -> op == supersede_option_statement) {
- if (ep -> data.option -> option -> code == 224) {
+ if (ep -> data.option -> option -> code == DHO_PORT_SET) {
printf("pset found!!!\n");
printf("%d\n", ep -> data.option -> expression -> op);
pset_mask = ntohs(*(u_int16_t*)(ep -> data.option -> expression -> data.const_data.buffer -> data));
@@ -847,6 +860,10 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
lp->next_binding_state = FTS_FREE;
lp->rewind_binding_state = FTS_FREE;
lp->flags = 0;
+ lp->ip_pset.ip_addr = lp->ip_addr;//[pset]
+ lp->ip_pset.pset_index = 0;//[pset]remember the portset index
+ lp->ip_pset.pset_mask = 0;
+
//printf("i=%d ip=%s\n", i, piaddr (lp -> ip_addr));
/* Remember the lease in the IP address hash. */
if (find_lease_by_ip_addr (&lt, lp -> ip_addr, MDL)) {
@@ -947,8 +964,10 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
lease_dereference (&lp, MDL);
}
}
+
+ print_shared_network(subnet->shared_network);
-
+ printf("subnet->shared_network->pools=%x pool=%x\n", (int)subnet->shared_network->pools, (int)pool);
}
int find_subnet (struct subnet **sp,
@@ -1,2 +1,4 @@
#!/bin/bash
+rm -f dhcpd.leases
+touch dhcpd.leases
./dhcpd -4 -p 67 -cf dhcpd.conf -lf dhcpd.leases -f

0 comments on commit 94c5cbd

Please sign in to comment.