diff options
author | Dainis Jonitis <dainis.jonitis@ubnt.com> | 2018-11-26 14:43:45 +0200 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2019-05-03 14:45:55 +0200 |
commit | 39e11ed2d9de55a2661c21176b74263988e932d3 (patch) | |
tree | 68921ced55b0e94658bc26a9bd37e5d07df4fd69 /src/dhcpv4.c | |
parent | 4a600ce5b1f3f2d877ad68ce0cc199a122d30abd (diff) |
dhcpv4: DHCP pool size is off-by-one
1. "limit" option should specify the size of dynamic pool. The dhcpv4_end
includes the last valid pool address.
2. Also handle 7 bit host addresses when not directly specified in config file.
3. Make sure code does what documentation says and default 'start'/'limit'
pool options to 100 and 150 respectively.
Signed-off-by: Dainis Jonitis <dainis.jonitis@ubnt.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/dhcpv4.c')
-rw-r--r-- | src/dhcpv4.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 370e1b9..679b793 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -263,18 +263,21 @@ static int setup_dhcpv4_addresses(struct interface *iface) end = start = iface->dhcpv4_local.s_addr & iface->dhcpv4_mask.s_addr; /* Auto allocate ranges */ - if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffff00) { + if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffff00) { /* /24, 150 of 256, [100..249] */ iface->dhcpv4_start_ip.s_addr = start | htonl(100); - iface->dhcpv4_end_ip.s_addr = end | htonl(250); - } else if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffffc0) { + iface->dhcpv4_end_ip.s_addr = end | htonl(100 + 150 - 1); + } else if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffff80) { /* /25, 100 of 128, [20..119] */ + iface->dhcpv4_start_ip.s_addr = start | htonl(20); + iface->dhcpv4_end_ip.s_addr = end | htonl(20 + 100 - 1); + } else if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffffc0) { /* /26, 50 of 64, [10..59] */ iface->dhcpv4_start_ip.s_addr = start | htonl(10); - iface->dhcpv4_end_ip.s_addr = end | htonl(60); - } else if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffffe0) { + iface->dhcpv4_end_ip.s_addr = end | htonl(10 + 50 - 1); + } else if (ntohl(iface->dhcpv4_mask.s_addr) <= 0xffffffe0) { /* /27, 20 of 32, [10..29] */ iface->dhcpv4_start_ip.s_addr = start | htonl(10); - iface->dhcpv4_end_ip.s_addr = end | htonl(30); - } else { + iface->dhcpv4_end_ip.s_addr = end | htonl(10 + 20 - 1); + } else { /* /28, 10 of 16, [3..12] */ iface->dhcpv4_start_ip.s_addr = start | htonl(3); - iface->dhcpv4_end_ip.s_addr = end | htonl(12); + iface->dhcpv4_end_ip.s_addr = end | htonl(3 + 10 - 1); } return 0; |