Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved mdb.c by reading pset_mask from .conf; improved pset_hash;

  • Loading branch information...
commit a449f085f5807df58dac8711fcd9b3281196342c 1 parent c9c9cdc
@gnocuil authored
View
2  dhcp-4.2.3-P2/common/tables.c
@@ -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.
View
1  dhcp-4.2.3-P2/includes/dhcpd.h
@@ -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 *);
View
17 dhcp-4.2.3-P2/omapip/hash.c
@@ -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;
}
View
448 dhcp-4.2.3-P2/server/.deps/dhcpd-mdb.Tpo
@@ -0,0 +1,448 @@
+dhcpd-mdb.o: mdb.c ../includes/dhcpd.h ../includes/config.h \
+ /usr/include/sys/types.h /usr/include/features.h \
+ /usr/include/bits/predefs.h /usr/include/sys/cdefs.h \
+ /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \
+ /usr/include/gnu/stubs-32.h /usr/include/bits/types.h \
+ /usr/include/bits/typesizes.h /usr/include/time.h \
+ /usr/lib/gcc/i686-linux-gnu/4.4.5/include/stddef.h /usr/include/endian.h \
+ /usr/include/bits/endian.h /usr/include/bits/byteswap.h \
+ /usr/include/sys/select.h /usr/include/bits/select.h \
+ /usr/include/bits/sigset.h /usr/include/bits/time.h \
+ /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \
+ /usr/include/netinet/in.h /usr/include/stdint.h \
+ /usr/include/bits/wchar.h /usr/include/sys/socket.h \
+ /usr/include/sys/uio.h /usr/include/bits/uio.h \
+ /usr/include/bits/socket.h /usr/include/bits/sockaddr.h \
+ /usr/include/asm/socket.h /usr/include/asm-generic/socket.h \
+ /usr/include/asm/sockios.h /usr/include/asm-generic/sockios.h \
+ /usr/include/bits/in.h /usr/include/sys/un.h /usr/include/string.h \
+ /usr/include/xlocale.h /usr/include/arpa/inet.h /usr/include/errno.h \
+ /usr/include/bits/errno.h /usr/include/linux/errno.h \
+ /usr/include/asm/errno.h /usr/include/asm-generic/errno.h \
+ /usr/include/asm-generic/errno-base.h /usr/include/netdb.h \
+ /usr/include/rpc/netdb.h /usr/include/bits/siginfo.h \
+ /usr/include/bits/netdb.h /usr/include/fcntl.h /usr/include/bits/fcntl.h \
+ /usr/include/bits/stat.h /usr/include/stdio.h /usr/include/libio.h \
+ /usr/include/_G_config.h /usr/include/wchar.h \
+ /usr/lib/gcc/i686-linux-gnu/4.4.5/include/stdarg.h \
+ /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
+ /usr/include/unistd.h /usr/include/bits/posix_opt.h \
+ /usr/include/bits/environments.h /usr/include/bits/confname.h \
+ /usr/include/getopt.h /usr/include/stdlib.h \
+ /usr/include/bits/waitflags.h /usr/include/bits/waitstatus.h \
+ /usr/include/alloca.h /usr/include/sys/stat.h /usr/include/sys/mman.h \
+ /usr/include/bits/mman.h /usr/include/ctype.h /usr/include/net/if.h \
+ /usr/include/net/route.h /usr/include/net/if_arp.h /usr/include/setjmp.h \
+ /usr/include/bits/setjmp.h ../includes/cdefs.h ../includes/osdep.h \
+ ../includes/site.h /usr/include/inttypes.h ../includes/arpa/nameser.h \
+ ../includes/arpa/nameser_compat.h ../includes/minires.h \
+ ../includes/omapip/isclib.h ../includes/config.h /usr/include/syslog.h \
+ /usr/include/sys/syslog.h /usr/include/bits/syslog-path.h \
+ ../bind/include/isc/buffer.h ../bind/include/isc/lang.h \
+ ../bind/include/isc/magic.h ../bind/include/isc/types.h \
+ ../bind/include/isc/bind9.h ../bind/include/isc/namespace.h \
+ ../bind/include/isc/int.h ../bind/include/isc/offset.h \
+ /usr/lib/gcc/i686-linux-gnu/4.4.5/include-fixed/limits.h \
+ /usr/lib/gcc/i686-linux-gnu/4.4.5/include-fixed/syslimits.h \
+ /usr/include/limits.h /usr/include/bits/posix1_lim.h \
+ /usr/include/bits/local_lim.h /usr/include/linux/limits.h \
+ /usr/include/bits/posix2_lim.h /usr/include/bits/xopen_lim.h \
+ ../bind/include/isc/boolean.h ../bind/include/isc/list.h \
+ ../bind/include/isc/assertions.h ../bind/include/isc/platform.h \
+ ../bind/include/isc/lex.h ../bind/include/isc/region.h \
+ ../bind/include/isc/lib.h ../bind/include/isc/app.h \
+ ../bind/include/isc/eventclass.h ../bind/include/isc/result.h \
+ ../bind/include/isc/mem.h ../bind/include/isc/mutex.h \
+ ../bind/include/isc/xml.h ../bind/include/isc/parseint.h \
+ ../bind/include/isc/socket.h ../bind/include/isc/event.h \
+ ../bind/include/isc/time.h ../bind/include/isc/sockaddr.h \
+ ../bind/include/isc/net.h ../bind/include/isc/task.h \
+ ../bind/include/isc/stdtime.h ../bind/include/isc/timer.h \
+ ../bind/include/isc/heap.h ../bind/include/isc/random.h \
+ ../bind/include/dns/client.h ../bind/include/dns/tsig.h \
+ ../bind/include/isc/refcount.h ../bind/include/isc/atomic.h \
+ ../bind/include/isc/util.h ../bind/include/isc/error.h \
+ ../bind/include/isc/formatcheck.h ../bind/include/isc/rwlock.h \
+ ../bind/include/isc/condition.h ../bind/include/isc/stdio.h \
+ ../bind/include/dns/types.h ../bind/include/dns/enumtype.h \
+ ../bind/include/dns/enumclass.h ../bind/include/dns/name.h \
+ ../bind/include/dst/dst.h ../bind/include/dns/secalg.h \
+ ../bind/include/dst/gssapi.h ../bind/include/dns/fixedname.h \
+ ../bind/include/dns/keyvalues.h ../bind/include/dns/lib.h \
+ ../bind/include/dns/rdata.h ../bind/include/dns/message.h \
+ ../bind/include/dns/compress.h ../bind/include/dns/masterdump.h \
+ ../bind/include/dns/rdataclass.h ../bind/include/dns/rdatalist.h \
+ ../bind/include/dns/rdataset.h ../bind/include/dns/rdatastruct.h \
+ ../bind/include/isc/iterated_hash.h ../bind/include/isc/sha1.h \
+ ../bind/include/dns/rdatatype.h ../bind/include/dns/result.h \
+ ../bind/include/isc/resultclass.h ../bind/include/dns/tsec.h \
+ ../includes/omapip/result.h ../includes/omapip/result.h \
+ ../includes/dhcp.h ../includes/dhcp6.h ../includes/statement.h \
+ ../includes/tree.h ../includes/inet.h ../includes/dhctoken.h \
+ ../includes/omapip/omapip_p.h /usr/include/memory.h \
+ ../includes/omapip/convert.h ../includes/omapip/hash.h \
+ ../includes/omapip/omapip.h ../includes/omapip/trace.h \
+ ../includes/omapip/buffer.h ../includes/omapip/alloc.h \
+ ../includes/failover.h ../includes/ctrace.h
+
+../includes/dhcpd.h:
+
+../includes/config.h:
+
+/usr/include/sys/types.h:
+
+/usr/include/features.h:
+
+/usr/include/bits/predefs.h:
+
+/usr/include/sys/cdefs.h:
+
+/usr/include/bits/wordsize.h:
+
+/usr/include/gnu/stubs.h:
+
+/usr/include/gnu/stubs-32.h:
+
+/usr/include/bits/types.h:
+
+/usr/include/bits/typesizes.h:
+
+/usr/include/time.h:
+
+/usr/lib/gcc/i686-linux-gnu/4.4.5/include/stddef.h:
+
+/usr/include/endian.h:
+
+/usr/include/bits/endian.h:
+
+/usr/include/bits/byteswap.h:
+
+/usr/include/sys/select.h:
+
+/usr/include/bits/select.h:
+
+/usr/include/bits/sigset.h:
+
+/usr/include/bits/time.h:
+
+/usr/include/sys/sysmacros.h:
+
+/usr/include/bits/pthreadtypes.h:
+
+/usr/include/netinet/in.h:
+
+/usr/include/stdint.h:
+
+/usr/include/bits/wchar.h:
+
+/usr/include/sys/socket.h:
+
+/usr/include/sys/uio.h:
+
+/usr/include/bits/uio.h:
+
+/usr/include/bits/socket.h:
+
+/usr/include/bits/sockaddr.h:
+
+/usr/include/asm/socket.h:
+
+/usr/include/asm-generic/socket.h:
+
+/usr/include/asm/sockios.h:
+
+/usr/include/asm-generic/sockios.h:
+
+/usr/include/bits/in.h:
+
+/usr/include/sys/un.h:
+
+/usr/include/string.h:
+
+/usr/include/xlocale.h:
+
+/usr/include/arpa/inet.h:
+
+/usr/include/errno.h:
+
+/usr/include/bits/errno.h:
+
+/usr/include/linux/errno.h:
+
+/usr/include/asm/errno.h:
+
+/usr/include/asm-generic/errno.h:
+
+/usr/include/asm-generic/errno-base.h:
+
+/usr/include/netdb.h:
+
+/usr/include/rpc/netdb.h:
+
+/usr/include/bits/siginfo.h:
+
+/usr/include/bits/netdb.h:
+
+/usr/include/fcntl.h:
+
+/usr/include/bits/fcntl.h:
+
+/usr/include/bits/stat.h:
+
+/usr/include/stdio.h:
+
+/usr/include/libio.h:
+
+/usr/include/_G_config.h:
+
+/usr/include/wchar.h:
+
+/usr/lib/gcc/i686-linux-gnu/4.4.5/include/stdarg.h:
+
+/usr/include/bits/stdio_lim.h:
+
+/usr/include/bits/sys_errlist.h:
+
+/usr/include/unistd.h:
+
+/usr/include/bits/posix_opt.h:
+
+/usr/include/bits/environments.h:
+
+/usr/include/bits/confname.h:
+
+/usr/include/getopt.h:
+
+/usr/include/stdlib.h:
+
+/usr/include/bits/waitflags.h:
+
+/usr/include/bits/waitstatus.h:
+
+/usr/include/alloca.h:
+
+/usr/include/sys/stat.h:
+
+/usr/include/sys/mman.h:
+
+/usr/include/bits/mman.h:
+
+/usr/include/ctype.h:
+
+/usr/include/net/if.h:
+
+/usr/include/net/route.h:
+
+/usr/include/net/if_arp.h:
+
+/usr/include/setjmp.h:
+
+/usr/include/bits/setjmp.h:
+
+../includes/cdefs.h:
+
+../includes/osdep.h:
+
+../includes/site.h:
+
+/usr/include/inttypes.h:
+
+../includes/arpa/nameser.h:
+
+../includes/arpa/nameser_compat.h:
+
+../includes/minires.h:
+
+../includes/omapip/isclib.h:
+
+../includes/config.h:
+
+/usr/include/syslog.h:
+
+/usr/include/sys/syslog.h:
+
+/usr/include/bits/syslog-path.h:
+
+../bind/include/isc/buffer.h:
+
+../bind/include/isc/lang.h:
+
+../bind/include/isc/magic.h:
+
+../bind/include/isc/types.h:
+
+../bind/include/isc/bind9.h:
+
+../bind/include/isc/namespace.h:
+
+../bind/include/isc/int.h:
+
+../bind/include/isc/offset.h:
+
+/usr/lib/gcc/i686-linux-gnu/4.4.5/include-fixed/limits.h:
+
+/usr/lib/gcc/i686-linux-gnu/4.4.5/include-fixed/syslimits.h:
+
+/usr/include/limits.h:
+
+/usr/include/bits/posix1_lim.h:
+
+/usr/include/bits/local_lim.h:
+
+/usr/include/linux/limits.h:
+
+/usr/include/bits/posix2_lim.h:
+
+/usr/include/bits/xopen_lim.h:
+
+../bind/include/isc/boolean.h:
+
+../bind/include/isc/list.h:
+
+../bind/include/isc/assertions.h:
+
+../bind/include/isc/platform.h:
+
+../bind/include/isc/lex.h:
+
+../bind/include/isc/region.h:
+
+../bind/include/isc/lib.h:
+
+../bind/include/isc/app.h:
+
+../bind/include/isc/eventclass.h:
+
+../bind/include/isc/result.h:
+
+../bind/include/isc/mem.h:
+
+../bind/include/isc/mutex.h:
+
+../bind/include/isc/xml.h:
+
+../bind/include/isc/parseint.h:
+
+../bind/include/isc/socket.h:
+
+../bind/include/isc/event.h:
+
+../bind/include/isc/time.h:
+
+../bind/include/isc/sockaddr.h:
+
+../bind/include/isc/net.h:
+
+../bind/include/isc/task.h:
+
+../bind/include/isc/stdtime.h:
+
+../bind/include/isc/timer.h:
+
+../bind/include/isc/heap.h:
+
+../bind/include/isc/random.h:
+
+../bind/include/dns/client.h:
+
+../bind/include/dns/tsig.h:
+
+../bind/include/isc/refcount.h:
+
+../bind/include/isc/atomic.h:
+
+../bind/include/isc/util.h:
+
+../bind/include/isc/error.h:
+
+../bind/include/isc/formatcheck.h:
+
+../bind/include/isc/rwlock.h:
+
+../bind/include/isc/condition.h:
+
+../bind/include/isc/stdio.h:
+
+../bind/include/dns/types.h:
+
+../bind/include/dns/enumtype.h:
+
+../bind/include/dns/enumclass.h:
+
+../bind/include/dns/name.h:
+
+../bind/include/dst/dst.h:
+
+../bind/include/dns/secalg.h:
+
+../bind/include/dst/gssapi.h:
+
+../bind/include/dns/fixedname.h:
+
+../bind/include/dns/keyvalues.h:
+
+../bind/include/dns/lib.h:
+
+../bind/include/dns/rdata.h:
+
+../bind/include/dns/message.h:
+
+../bind/include/dns/compress.h:
+
+../bind/include/dns/masterdump.h:
+
+../bind/include/dns/rdataclass.h:
+
+../bind/include/dns/rdatalist.h:
+
+../bind/include/dns/rdataset.h:
+
+../bind/include/dns/rdatastruct.h:
+
+../bind/include/isc/iterated_hash.h:
+
+../bind/include/isc/sha1.h:
+
+../bind/include/dns/rdatatype.h:
+
+../bind/include/dns/result.h:
+
+../bind/include/isc/resultclass.h:
+
+../bind/include/dns/tsec.h:
+
+../includes/omapip/result.h:
+
+../includes/omapip/result.h:
+
+../includes/dhcp.h:
+
+../includes/dhcp6.h:
+
+../includes/statement.h:
+
+../includes/tree.h:
+
+../includes/inet.h:
+
+../includes/dhctoken.h:
+
+../includes/omapip/omapip_p.h:
+
+/usr/include/memory.h:
+
+../includes/omapip/convert.h:
+
+../includes/omapip/hash.h:
+
+../includes/omapip/omapip.h:
+
+../includes/omapip/trace.h:
+
+../includes/omapip/buffer.h:
+
+../includes/omapip/alloc.h:
+
+../includes/failover.h:
+
+../includes/ctrace.h:
View
13 dhcp-4.2.3-P2/server/dhcpd.conf
@@ -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;
+
}
View
17 dhcp-4.2.3-P2/server/dhcpd.leases
@@ -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;
View
19 dhcp-4.2.3-P2/server/dhcpd.leases~
@@ -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;
+}
View
37 dhcp-4.2.3-P2/server/mdb.c
@@ -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;
@@ -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))) {
@@ -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],
@@ -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;
@@ -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. */
@@ -926,7 +947,7 @@ void new_address_range (cfile, low, high, subnet, pool, lpchain)
lease_dereference (&lp, MDL);
}
}
-//puts("loop ends!");
+
}
View
2  dhcp-4.2.3-P2/server/open.sh
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.