dnsmasq: backport latest patches
[openwrt/openwrt.git] / package / network / services / dnsmasq / patches / 0017-Alter-DHCP-address-selection-after-DECLINE-in-consec.patch
1 From e7bfd556c079c8b5e7425aed44abc35925b24043 Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Mon, 31 Dec 2018 20:51:15 +0000
4 Subject: [PATCH 17/57] Alter DHCP address selection after DECLINE in
5 consec-addr mode. Avoid offering the same address after a recieving a DECLINE
6 message to stop an infinite protocol loop. This has long been done in default
7 address allocation mode: this adds similar behaviour when allocaing addresses
8 consecutively.
9
10 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
11 ---
12 src/dhcp.c | 13 +++++++++++++
13 src/dhcp6.c | 11 +++++++++--
14 2 files changed, 22 insertions(+), 2 deletions(-)
15
16 --- a/src/dhcp.c
17 +++ b/src/dhcp.c
18 @@ -754,6 +754,19 @@ int address_allocate(struct dhcp_context
19 if (addr.s_addr == d->router.s_addr)
20 break;
21
22 + /* in consec-ip mode, skip addresses equal to
23 + the number of addresses rejected by clients. This
24 + should avoid the same client being offered the same
25 + address after it has rjected it. */
26 + if (option_bool(OPT_CONSEC_ADDR))
27 + {
28 + if (c->addr_epoch)
29 + {
30 + c->addr_epoch--;
31 + d = context; /* d non-NULL skips the address. */
32 + }
33 + }
34 +
35 /* Addresses which end in .255 and .0 are broken in Windows even when using
36 supernetting. ie dhcp-range=192.168.0.1,192.168.1.254,255,255,254.0
37 then 192.168.0.255 is a valid IP address, but not for Windows as it's
38 --- a/src/dhcp6.c
39 +++ b/src/dhcp6.c
40 @@ -431,8 +431,15 @@ struct dhcp_context *address6_allocate(s
41 else
42 {
43 if (!temp_addr && option_bool(OPT_CONSEC_ADDR))
44 - /* seed is largest extant lease addr in this context */
45 - start = lease_find_max_addr6(c) + serial;
46 + {
47 + /* seed is largest extant lease addr in this context,
48 + skip addresses equal to the number of addresses rejected
49 + by clients. This should avoid the same client being offered the same
50 + address after it has rjected it. */
51 + start = lease_find_max_addr6(c) + serial + c->addr_epoch;
52 + if (c->addr_epoch)
53 + c->addr_epoch--;
54 + }
55 else
56 {
57 u64 range = 1 + addr6part(&c->end6) - addr6part(&c->start6);