Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gnocuil/DHCPv4-over-v6
Browse files Browse the repository at this point in the history
  • Loading branch information
ynonenull committed Oct 7, 2012
2 parents 4510c09 + 32d04e5 commit ddcddd2
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 30 deletions.
1 change: 0 additions & 1 deletion DHCPv4-over-v6
Submodule DHCPv4-over-v6 deleted from 86133a
2 changes: 1 addition & 1 deletion dhcp-4.2.3-P2/common/tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -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", "SA", &dhcp_universe, 198, 1 },
{ "port-set", "S", &dhcp_universe, 224, 1 },//[pset] modified by Liu Cong

#if 0
/* Referenced by RFC 4578.
Expand Down
Binary file modified dhcp-4.2.3-P2/includes/.dhcpd.h.swp
Binary file not shown.
1 change: 1 addition & 0 deletions dhcp-4.2.3-P2/includes/dhcpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3277,6 +3277,7 @@ int find_lease_by_ip_addr (struct lease **, struct iaddr,
const char *, int);
int find_lease_by_ip_pset (struct lease **, struct iaddr_pset,
const char *, int); //[pset] modified by Liu Cong
int mask_bits_pset(u_int16_t);//[pset] added by Liu Cong
void uid_hash_add (struct lease *);
void uid_hash_delete (struct lease *);
void hw_hash_add (struct lease *);
Expand Down
17 changes: 14 additions & 3 deletions dhcp-4.2.3-P2/omapip/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,26 @@ piaddr222(const struct iaddr addr) {
addr.len);
// quell compiler warnings
return NULL;
}*/

int mask_bits_pset(u_int16_t mask)//[pset] added by Liu Cong
{
int result = 16;
while (mask && (mask & 1) == 0) {
--result;
mask >>= 1;
}
return result;
}
*/

unsigned
do_ip4_pset_hash(const void *key, unsigned len, unsigned size)//[pset] added by Liu Cong
{
struct iaddr_pset* ip_pset = (struct iaddr_pset*) key;
u_int32_t number = do_ip4_hash(ip_pset->ip_addr.iabuf, len, size);
number = (number << 2) | ip_pset->pset_index;
//printf("do_ip4_pset_hash! ip=%s port=%d number=%d\n", piaddr222 (ip_pset->ip_addr), ip_pset->pset_index, number);
int bits = mask_bits_pset(ip_pset->pset_mask);
number = (number << bits) | (ip_pset->pset_index >> (16 - bits));
//printf("do_ip4_pset_hash! ip=%s port=%x mask=%x number=%d\n", piaddr222 (ip_pset->ip_addr), ip_pset->pset_index, ip_pset->pset_mask, number);
return number % size;
}

Expand Down
33 changes: 32 additions & 1 deletion dhcp-4.2.3-P2/server/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,44 @@ dhcp (struct packet *packet) {
packet->options->universes[agent_universe.index] == NULL))
{
struct iaddr cip;
struct iaddr_pset ipset;//get pset-option from request packet. sunqi

/********if pset option exists, get it; else use original method. sunqi*******/

ipset.ip_addr.len = sizeof packet -> raw -> ciaddr;
memcpy (ipset.ip_addr.iabuf, &packet -> raw -> ciaddr,
sizeof packet -> raw -> ciaddr);
oc = lookup_option (&dhcp_universe, packet -> options,
DHO_PORT_SET);
memset (&data, 0, sizeof data);
if (oc &&
evaluate_option_cache (&data, packet, (struct lease)0,
(struct client_state *)0,
packet -> options, (struct option_state*)0,
&global_scope, oc, MDL)){
if (data.len == 4) {
u_int32_t tmp = getULong (data.data);
ipset.pset_index = tmp >> 16;
ipset.pset_mask = tmp;
} else {
printf("no port-set option found.");

}

data_string_forget (&data, MDL);


if (!find_lease_by_ip_pset (&lease, ipset, MDL))
goto nolease;

} else {/******************/

cip.len = sizeof packet -> raw -> ciaddr;
memcpy (cip.iabuf, &packet -> raw -> ciaddr,
sizeof packet -> raw -> ciaddr);
if (!find_lease_by_ip_addr (&lease, cip, MDL))
goto nolease;

}
/* If there are no agent options on the lease, it's not
interesting. */
if (!lease -> agent_options)
Expand Down
13 changes: 11 additions & 2 deletions dhcp-4.2.3-P2/server/dhcpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ log-facility local7;
# option port-set code 198 = array of unsigned integer 16;

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.200;
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;
option port-set 1024,2048;

}

17 changes: 4 additions & 13 deletions dhcp-4.2.3-P2/server/dhcpd.leases
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,10 @@

server-duid "\000\001\000\001\027\371\\t\010\000',\302\257";

lease 192.168.1.10 {
starts 5 2012/10/05 06:28:57;
ends 5 2012/10/05 06:38:57;
cltt 5 2012/10/05 06:28:57;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 08:00:27:f3:0f:45;
}
lease 192.168.1.10 {
starts 5 2012/10/05 06:29:11;
ends 5 2012/10/05 06:39:11;
cltt 5 2012/10/05 06:29:11;
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;
Expand Down
19 changes: 19 additions & 0 deletions dhcp-4.2.3-P2/server/dhcpd.leases~
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# 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;
}
37 changes: 29 additions & 8 deletions dhcp-4.2.3-P2/server/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ int find_host_for_network (struct subnet **sp, struct host_decl **host,
return 0;
}



void new_address_range (cfile, low, high, subnet, pool, lpchain)
struct parse *cfile;
struct iaddr low, high;
Expand Down Expand Up @@ -763,6 +765,25 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
MDL))
log_fatal ("Can't allocate lease/ip_pset hash");
}

/* Check if the subnet has a port set option, [pset] added by Liu Cong */
printf("**************check for pset option!******************\n");
u_int16_t pset_mask;
struct executable_statement *ep;
ratio1 = 0;
for (ep = subnet -> group -> statements; ep; ep = ep -> next) {
if (ep -> op == supersede_option_statement) {
if (ep -> data.option -> option -> code == 224) {
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);
ratio1 = 1 << mask_bits_pset(pset_mask);
printf("ratio1=%d\n", ratio1);
break;
}
}
}

/* Make sure that high and low addresses are in this subnet. */
if (!addr_eq(subnet->net, subnet_number(low, subnet->netmask))) {
Expand Down Expand Up @@ -799,9 +820,9 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
lowbuf, highbuf);
}
#endif
//puts("loop0 begins");

/* Fill out the lease structures with some minimal information. */
for (i = 0; i < max - min + 1; i++) {
for (i = 0; ratio1 == 0 && i < max - min + 1; i++) {
struct lease *lp = (struct lease *)0;
#if defined (COMPACT_LEASES)
omapi_object_initialize ((omapi_object_t *)&address_range [i],
Expand Down Expand Up @@ -864,9 +885,9 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
lowbuf, highbuf);
}
#endif
//puts("loop begins!");

/* Fill out the lease structures with some minimal information. */
for (i = 0; i < max - min + 1; i++) {//printf("i=%d\n", i);
for (i = 0; ratio1 > 0 && i < max - min + 1; i++) {//printf("i=%d\n", i);
for (j = 0; j < ratio1; j++){
struct lease *lp = (struct lease *)0;

Expand Down Expand Up @@ -896,9 +917,9 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
lp->flags = 0;

lp->ip_pset.ip_addr = lp->ip_addr;//[pset]
lp->ip_pset.ip_addr.iabuf[1] = j>>8;//Get the high and low 8bits represently
lp->ip_pset.ip_addr.iabuf[2] = j;
lp->ip_pset.pset_index = j;//[pset]remember the portset index
int bits = mask_bits_pset(pset_mask);
lp->ip_pset.pset_index = j << (16 - bits);//[pset]remember the portset index
lp->ip_pset.pset_mask = pset_mask;

/* Remember the lease in the IP address and port-set hash. */

Expand Down Expand Up @@ -926,7 +947,7 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
lease_dereference (&lp, MDL);
}
}
//puts("loop ends!");


}

Expand Down
2 changes: 1 addition & 1 deletion dhcp-4.2.3-P2/server/open.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
sudo ./dhcpd -4 -p 67 -cf dhcpd.conf -lf dhcpd.leases -f
./dhcpd -4 -p 67 -cf dhcpd.conf -lf dhcpd.leases -f

0 comments on commit ddcddd2

Please sign in to comment.