Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Now dhcpdiscover() works and the DHCP Offer contains port set option …

…( .leases must be empty)
  • Loading branch information...
commit b06911a865c155ee0929648937af11e5a169f1f8 1 parent 9dad36b
gnocuil authored
2  dhcp-4.2.3-P2/common/tables.c
View
@@ -211,7 +211,7 @@ static struct option dhcp_options[] = {
{ "vivco", "Evendor-class.", &dhcp_universe, 124, 1 },
{ "vivso", "Evendor.", &dhcp_universe, 125, 1 },
/* pset option, newly defined. */
- { "port-set", "S", &dhcp_universe, 224, 1 },//[pset] modified by Liu Cong
+ { "port-set", "SA", &dhcp_universe, 224, 1 },//[pset] modified by Liu Cong
#if 0
/* Referenced by RFC 4578.
5 dhcp-4.2.3-P2/includes/dhcpd.h
View
@@ -929,7 +929,8 @@ struct pool {
int index;
TIME valid_from; /* deny pool use before this date */
TIME valid_until; /* deny pool use after this date */
-
+ int port_set; /* [pset] is the leases in this pool contains port set? */
+
#if defined (FAILOVER_PROTOCOL)
dhcp_failover_state_t *failover_peer;
#endif
@@ -1637,7 +1638,7 @@ HASH_FUNCTIONS_DECL (option_code, const unsigned *, struct option,
HASH_FUNCTIONS_DECL (dns_zone, const char *, struct dns_zone, dns_zone_hash_t)
HASH_FUNCTIONS_DECL(lease_ip, const unsigned char *, struct lease,
lease_ip_hash_t)
-HASH_FUNCTIONS_DECL(lease_ip_pset, const unsigned char *, struct lease,
+HASH_FUNCTIONS_DECL(lease_ip_pset, struct iaddr_pset *, struct lease,
lease_ip_hash_t)//[pset] added by Liu Cong
HASH_FUNCTIONS_DECL(lease_id, const unsigned char *, struct lease,
lease_id_hash_t)
13 dhcp-4.2.3-P2/server/confpars.c
View
@@ -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,13 +1514,9 @@ 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;
@@ -1683,8 +1679,9 @@ print_shared_network(group->shared_network);
!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);
+ if (pp -> port_set != pool -> port_set)//[pset]added by Liu Cong
+ continue;
+
/* 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) {
@@ -1702,7 +1699,7 @@ printf("pp->free=%x frees=%d\n", (int)pp->free, pp->free_leases);
;
pool_reference (p, pool, MDL);
}
-
+if (!debug_pool) debug_pool = pool -> shared_network -> pools;//[pset]
/* Don't allow a pool declaration with no addresses, since it is
probably a configuration error. */
if (!lpchain) {
27 dhcp-4.2.3-P2/server/dhcp.c
View
@@ -2716,10 +2716,10 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp, hp)
/*add the DHO_PORT_SET option
* mim
- */
+ */printf("before DHP_PORT_SET: mask=%04x index=%04x\n", lease->ip_pset.pset_mask, lease->ip_pset.pset_index);
i = DHO_PORT_SET;
- if( !lookup_option(&dhcp_universe, state->options,i)){
- oc = (struct option_cache *) 0;
+ if( !(oc=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);
if(make_const_data( &oc->expression,
@@ -2732,7 +2732,13 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp, hp)
state->options,oc);
}
option_cache_dereference(&oc, MDL);
- }
+ }*/
+ } else {
+ printf("else: op=%d\n", oc->expression->op);
+ struct expression *exp = oc -> expression -> data.concat[0];
+ *(u_int16_t*)(exp -> data.const_data.buffer -> data) = ntohs(lease->ip_pset.pset_index);
+ exp = oc -> expression -> data.concat[1];
+ *(u_int16_t*)(exp -> data.const_data.buffer -> data) = ntohs(lease->ip_pset.pset_mask);
}
/* Use the subnet mask from the subnet declaration if no other
@@ -4153,11 +4159,14 @@ int allocate_lease (struct lease **lp, struct packet *packet,
struct lease *candl = (struct lease *)0;
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);
+ printf("\tpool=%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("\tpool->next=%x\n", (int)pool->next);
+
+ if (pool->port_set != checkPortsetInOption55(packet))//[pset]
+ continue;
if ((pool -> prohibit_list &&
permitted (packet, pool -> prohibit_list)) ||
(pool -> permit_list &&
2  dhcp-4.2.3-P2/server/dhcpd.conf
View
@@ -35,7 +35,7 @@ shared-network gnocuil {
}
subnet 192.168.1.0 netmask 255.255.255.0 {
- option port-set 0xF800;
+ option port-set 0x1234,0xF800;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8;
12 dhcp-4.2.3-P2/server/dhcpd.leases
View
@@ -1,5 +1,15 @@
# 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\030\0060E\010\000'\366\002\307";
+server-duid "\000\001\000\001\030\006iq\010\000'\366\002\307";
+lease 192.168.2.151 {
+ starts 2 2012/10/09 04:50:19;
+ ends 2 2012/10/09 05:00:19;
+ cltt 2 2012/10/09 04:50:19;
+ binding state active;
+ next binding state free;
+ rewind binding state free;
+ hardware ethernet 08:00:27:f3:0f:45;
+ client-hostname "thuos-VirtualBox";
+}
38 dhcp-4.2.3-P2/server/mdb.c
View
@@ -780,19 +780,28 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
}
/* Check if the subnet has a port set option, [pset] added by Liu Cong */
- printf("**************check for pset option!******************\n");
+ printf("**************check pset option!******************\n");
u_int16_t pset_mask;
struct executable_statement *ep;
+ pool->port_set = 0;
ratio1 = 0;
for (ep = subnet -> group -> statements; ep; ep = ep -> next) {
if (ep -> op == supersede_option_statement) {
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));
- printf("%x\n", pset_mask);
+ printf("\tpset found!!!\n");
+ printf("\top=%d\n", ep -> data.option -> expression -> op);
+
+ struct expression *exp = ep -> data.option -> expression -> data.concat[1];
+ printf("\texp->op=%d\n", exp->op);
+ printf("\texp->data.const_data.len=%d\n", exp->data.const_data.len);
+ printf("\texp->data.const_data.buffer=%x\n", *(u_int16_t*)(exp->data.const_data.buffer->data));
+
+ //pset_mask = ntohs(*(u_int16_t*)(ep -> data.option -> expression -> data.const_data.buffer -> data));
+ pset_mask = ntohs(*(u_int16_t*)(exp -> data.const_data.buffer -> data));
+ printf("\tmask=%04x\n", pset_mask);
ratio1 = 1 << mask_bits_pset(pset_mask);
- printf("ratio1=%d\n", ratio1);
+ printf("\tratio1=%d\n", ratio1);
+ pool->port_set = 1;
break;
}
}
@@ -905,7 +914,7 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
/* Fill out the lease structures with some minimal information. */
for (i = 0; ratio1 > 0 && i < max - min + 1; i++) {//printf("i=%d\n", i);
- for (j = 0; j < ratio1; j++){
+ for (j = 1; j < ratio1; j++){
struct lease *lp = (struct lease *)0;
#if defined (COMPACT_LEASES)
@@ -951,7 +960,7 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
lease_dereference (&lt, MDL);
}else
lease_ip_pset_hash_add(lease_ip_pset_hash,
- (const unsigned char*) &(lp->ip_pset), lp->ip_pset.ip_addr.len,
+ &(lp->ip_pset), lp->ip_pset.ip_addr.len,
lp, MDL);//[pset] modified by Liu Cong
/* Put the lease on the chain for the caller. */
if (lpchain) {
@@ -2081,7 +2090,7 @@ int find_lease_by_ip_addr (struct lease **lp, struct iaddr addr,
int find_lease_by_ip_pset (struct lease **lp, struct iaddr_pset pset,
const char *file, int line)
{
- return lease_ip_pset_hash_lookup(lp, lease_ip_pset_hash, (const unsigned char*) &pset,
+ return lease_ip_pset_hash_lookup(lp, lease_ip_pset_hash, &pset,
pset.ip_addr.len, file, line);//[pset] modified by Liu Cong
}
/********************************************************************/
@@ -2667,8 +2676,12 @@ lease_instantiate(const void *key, unsigned len, void *object)
XXX orphan, which we *should* keep around until it expires,
XXX but which right now we just forget. */
if (!lease -> pool) {
- lease_ip_hash_delete(lease_ip_addr_hash, lease->ip_addr.iabuf,
- lease->ip_addr.len, MDL);
+ if (lease -> ip_pset.pset_mask == 0)//[pset]
+ lease_ip_hash_delete(lease_ip_addr_hash, lease->ip_addr.iabuf,
+ lease->ip_addr.len, MDL);
+ else
+ lease_ip_pset_hash_delete(lease_ip_pset_hash, &lease->ip_pset,
+ lease->ip_addr.len, MDL);
return ISC_R_SUCCESS;
}
@@ -2727,6 +2740,7 @@ void expire_all_pools ()
/* First, go over the hash list and actually put all the leases
on the appropriate lists. */
lease_ip_hash_foreach(lease_ip_addr_hash, lease_instantiate);
+ lease_ip_pset_hash_foreach(lease_ip_pset_hash, lease_instantiate);//[pset] added by Liu Cong
/* Loop through each pool in each shared network and call the
* expiry routine on the pool. It is no longer safe to follow
@@ -2822,7 +2836,7 @@ void dump_subnets ()
HASH_FUNCTIONS(lease_ip, const unsigned char *, struct lease, lease_ip_hash_t,
lease_reference, lease_dereference, do_ip4_hash)
-HASH_FUNCTIONS(lease_ip_pset, const unsigned char *, struct lease, lease_ip_hash_t,//[pset]added by Liu Cong
+HASH_FUNCTIONS(lease_ip_pset, struct iaddr_pset *, struct lease, lease_ip_hash_t,//[pset]added by Liu Cong
lease_reference, lease_dereference, do_ip4_pset_hash)
HASH_FUNCTIONS(lease_id, const unsigned char *, struct lease, lease_id_hash_t,
lease_reference, lease_dereference, do_id_hash)
Please sign in to comment.
Something went wrong with that request. Please try again.