diff options
author | Ross Vandegrift <ross@kallisti.us> | 2023-01-16 13:35:46 -0800 |
---|---|---|
committer | Christian Marangi <ansuelsmth@gmail.com> | 2023-06-24 22:57:09 +0200 |
commit | c9e619f015fdcc520c850f8a16e5046fea9660da (patch) | |
tree | bdd745901a381f3a790f3d97857bd54341817f94 | |
parent | 52112643308bb02a3b4fa2894dd7d4340ba4a237 (diff) |
dhcpv4: improve error when a prefix is too long
If a user tries to enable dhcpv4 on an interface with a /29, odhcp won't work.
The logs will only contain a message that doesn't help identify the problem.
It'd be idea to support any prefix with a valid pool, but at least this would
point a confused user in the right direction.
Signed-off-by: Ross Vandegrift <ross@kallisti.us>
-rw-r--r-- | src/dhcpv4.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 2b2f41e..3191ff2 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -37,6 +37,7 @@ #define PACKET_SIZE(start, end) (((uint8_t *)end - (uint8_t *)start) < DHCPV4_MIN_PACKET_SIZE ? \ DHCPV4_MIN_PACKET_SIZE : (uint8_t *)end - (uint8_t *)start) +#define MAX_PREFIX_LEN 28 static void dhcpv4_netevent_cb(unsigned long event, struct netevent_handler_info *info); static int setup_dhcpv4_addresses(struct interface *iface); @@ -248,9 +249,9 @@ static int setup_dhcpv4_addresses(struct interface *iface) } } - /* Don't allocate IP range for subnets bigger than 28 */ - if (iface->addr4[0].prefix > 28) { - syslog(LOG_WARNING, "Auto allocation of DHCP range fails on %s", iface->name); + /* Don't allocate IP range for subnets smaller than /28 */ + if (iface->addr4[0].prefix > MAX_PREFIX_LEN) { + syslog(LOG_WARNING, "Auto allocation of DHCP range fails on %s (prefix length must be < %d).", iface->name, MAX_PREFIX_LEN + 1); return -1; } |