From e7c0d7b34882cb39def6e5056d525b0ddc428534 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Sun, 28 Feb 2021 17:56:54 +0000 Subject: [PATCH] dhcp-host selection fix for v4/v6. Avoid treating a --dhcp-host which has an IPv6 address as eligable for use with DHCPv4 on the grounds that it has no address, and vice-versa. --- CHANGELOG | 6 ++++++ src/dhcp-common.c | 28 +++++++++++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cc6ee69..a5b2c44 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,12 @@ version 2.85 sorts before v2.83test1. This fixes the problem which lead to 2.84 announcing itself as 2.84rc2. + Avoid treating a --dhcp-host which has an IPv6 address + as eligable for use with DHCPv4 on the grounds that it has + no address, and vice-versa. Thanks to Viktor Papp for + spotting the problem. (This bug was fixed was back in 2.67, and + then regessed in 2.81). + version 2.84 Fix a problem, introduced in 2.83, which could see DNS replies diff --git a/src/dhcp-common.c b/src/dhcp-common.c index befd8a0..36bc38a 100644 --- a/src/dhcp-common.c +++ b/src/dhcp-common.c @@ -280,31 +280,29 @@ static int is_config_in_context(struct dhcp_context *context, struct dhcp_config { if (!context) /* called via find_config() from lease_update_from_configs() */ return 1; + + if (!(config->flags & (CONFIG_ADDR | CONFIG_ADDR6))) + return 1; #ifdef HAVE_DHCP6 if (context->flags & CONTEXT_V6) { struct addrlist *addr_list; - if (!(config->flags & CONFIG_ADDR6)) - return 1; - - for (; context; context = context->current) - for (addr_list = config->addr6; addr_list; addr_list = addr_list->next) - { - if ((addr_list->flags & ADDRLIST_WILDCARD) && context->prefix == 64) - return 1; - - if (is_same_net6(&addr_list->addr.addr6, &context->start6, context->prefix)) - return 1; - } + if (config->flags & CONFIG_ADDR6) + for (; context; context = context->current) + for (addr_list = config->addr6; addr_list; addr_list = addr_list->next) + { + if ((addr_list->flags & ADDRLIST_WILDCARD) && context->prefix == 64) + return 1; + + if (is_same_net6(&addr_list->addr.addr6, &context->start6, context->prefix)) + return 1; + } } else #endif { - if (!(config->flags & CONFIG_ADDR)) - return 1; - for (; context; context = context->current) if ((config->flags & CONFIG_ADDR) && is_same_net(config->addr, context->start, context->netmask)) return 1;