Skip to content

Commit

Permalink
added several printf for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
gnocuil committed Oct 9, 2012
1 parent d862df6 commit 9dad36b
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 69 deletions.
4 changes: 2 additions & 2 deletions dhcp-4.2.3-P2/omapip/hash.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions dhcp-4.2.3-P2/server/confpars.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
48 changes: 40 additions & 8 deletions dhcp-4.2.3-P2/server/dhcp.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -4125,7 +4152,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 &&
Expand Down Expand Up @@ -4195,7 +4227,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));
}

/*
Expand Down
31 changes: 18 additions & 13 deletions dhcp-4.2.3-P2/server/dhcpd.conf
Expand Up @@ -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;
}
}

29 changes: 1 addition & 28 deletions dhcp-4.2.3-P2/server/dhcpd.leases
@@ -1,32 +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

lease 192.168.1.151 {
starts 6 2012/10/06 16:53:40;
ends 6 2012/10/06 17:03:40;
tstp 6 2012/10/06 17:03:40;
cltt 6 2012/10/06 16:53:40;
binding state free;
hardware ethernet 08:00:27:f3:0f:45;
}
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 1 2012/10/08 13:48:57;
ends 1 2012/10/08 13:58:57;
cltt 1 2012/10/08 13:48:57;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 08:00:27:f3:0f:45;
client-hostname "thuos-VirtualBox";
}
lease 192.168.1.151 {
starts 1 2012/10/08 13:49:46;
ends 1 2012/10/08 13:59:46;
cltt 1 2012/10/08 13:49:46;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 08:00:27:f3:0f:45;
}
22 changes: 22 additions & 0 deletions dhcp-4.2.3-P2/server/dhcpd.leases_
@@ -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;
}
13 changes: 0 additions & 13 deletions dhcp-4.2.3-P2/server/dhcpd.leases~
@@ -1,13 +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.151 {
starts 6 2012/10/06 16:53:40;
ends 6 2012/10/06 17:03:40;
tstp 6 2012/10/06 17:03:40;
cltt 6 2012/10/06 16:53:40;
binding state free;
hardware ethernet 08:00:27:f3:0f:45;
}
server-duid "\000\001\000\001\027\371\\t\010\000',\302\257";

25 changes: 22 additions & 3 deletions dhcp-4.2.3-P2/server/mdb.c
Expand Up @@ -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]
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions dhcp-4.2.3-P2/server/open.sh
@@ -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 9dad36b

Please sign in to comment.