0017-Alter-DHCP-address-selection-after-DECLINE-in-consec.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/32] 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. Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
  10. ---
  11. src/dhcp.c | 13 +++++++++++++
  12. src/dhcp6.c | 11 +++++++++--
  13. 2 files changed, 22 insertions(+), 2 deletions(-)
  14. --- a/src/dhcp.c
  15. +++ b/src/dhcp.c
  16. @@ -754,6 +754,19 @@ int address_allocate(struct dhcp_context
  17. if (addr.s_addr == d->router.s_addr)
  18. break;
  19. + /* in consec-ip mode, skip addresses equal to
  20. + the number of addresses rejected by clients. This
  21. + should avoid the same client being offered the same
  22. + address after it has rjected it. */
  23. + if (option_bool(OPT_CONSEC_ADDR))
  24. + {
  25. + if (c->addr_epoch)
  26. + {
  27. + c->addr_epoch--;
  28. + d = context; /* d non-NULL skips the address. */
  29. + }
  30. + }
  31. +
  32. /* Addresses which end in .255 and .0 are broken in Windows even when using
  33. supernetting. ie dhcp-range=192.168.0.1,192.168.1.254,255,255,254.0
  34. then 192.168.0.255 is a valid IP address, but not for Windows as it's
  35. --- a/src/dhcp6.c
  36. +++ b/src/dhcp6.c
  37. @@ -431,8 +431,15 @@ struct dhcp_context *address6_allocate(s
  38. else
  39. {
  40. if (!temp_addr && option_bool(OPT_CONSEC_ADDR))
  41. - /* seed is largest extant lease addr in this context */
  42. - start = lease_find_max_addr6(c) + serial;
  43. + {
  44. + /* seed is largest extant lease addr in this context,
  45. + skip addresses equal to the number of addresses rejected
  46. + by clients. This should avoid the same client being offered the same
  47. + address after it has rjected it. */
  48. + start = lease_find_max_addr6(c) + serial + c->addr_epoch;
  49. + if (c->addr_epoch)
  50. + c->addr_epoch--;
  51. + }
  52. else
  53. {
  54. u64 range = 1 + addr6part(&c->end6) - addr6part(&c->start6);