[Dnsmasq-discuss] [PATCH] Find labelled IPv4 addresses for DHCP on Linux.
ooonea
ooonea at gmail.com
Mon Nov 16 14:38:50 UTC 2026
SIOCGIFADDR can return EADDRNOTAVAIL when every IPv4 address on an
interface has a label different from its name. DHCP then drops requests
although the interface has a usable address.
For that error on Linux, find an address by interface index through the
existing enumeration API. Preserve primary-address selection when the
ioctl succeeds and retain the interface and DHCP exclusion checks.
Assisted-by: OpenAI Codex
---
Tested real DHCP in an isolated network namespace, including IPv4-only
operation. Labelled interfaces receive an offer; ordinary addresses,
DHCP exclusions and interfaces without IPv4 addresses retain their
expected behavior. DNS label matching is unchanged.
src/dhcp.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/src/dhcp.c b/src/dhcp.c
index 6546741..7a3ae7f 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -30,6 +30,10 @@ struct match_param {
static int complete_context(struct in_addr local, int if_index, char *label,
struct in_addr netmask, struct in_addr broadcast, void *vparam);
+#ifdef HAVE_LINUX_NETWORK
+static int check_iface_addr(struct in_addr local, int if_index, char *label,
+ struct in_addr netmask, struct in_addr broadcast, void *vparam);
+#endif
static int check_listen_addrs(struct in_addr local, int if_index, char *label,
struct in_addr netmask, struct in_addr broadcast, void *vparam);
@@ -321,9 +325,23 @@ void dhcp_packet(time_t now, int pxe_fd)
iface_addr = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr;
else
{
- if (iface_check(AF_INET, NULL, ifr.ifr_name, NULL))
- my_syslog(MS_DHCP | LOG_WARNING, _("DHCP packet received on %s which has no address"), ifr.ifr_name);
- return;
+#ifdef HAVE_LINUX_NETWORK
+ struct match_param match;
+
+ match.ind = iface_index;
+ match.matched = 0;
+ /* Labels can hide every address from SIOCGIFADDR. */
+ if (errno == EADDRNOTAVAIL &&
+ iface_enumerate(AF_INET, &match, (callback_t){.af_inet=check_iface_addr}) > 0 &&
+ match.matched)
+ iface_addr = match.addr;
+ else
+#endif
+ {
+ if (iface_check(AF_INET, NULL, ifr.ifr_name, NULL))
+ my_syslog(MS_DHCP | LOG_WARNING, _("DHCP packet received on %s which has no address"), ifr.ifr_name);
+ return;
+ }
}
for (tmp = daemon->dhcp_except; tmp; tmp = tmp->next)
@@ -529,6 +547,27 @@ void dhcp_packet(time_t now, int pxe_fd)
}
}
+#ifdef HAVE_LINUX_NETWORK
+static int check_iface_addr(struct in_addr local, int if_index, char *label,
+ struct in_addr netmask, struct in_addr broadcast, void *vparam)
+{
+ struct match_param *param = vparam;
+
+ (void) label;
+ (void) netmask;
+ (void) broadcast;
+
+ if (if_index == param->ind && !param->matched)
+ {
+ param->matched = 1;
+ param->addr = local;
+ }
+
+ return 1;
+}
+
+#endif
+
/* check against secondary interface addresses */
static int check_listen_addrs(struct in_addr local, int if_index, char *label,
struct in_addr netmask, struct in_addr broadcast, void *vparam)
--
2.54.0
More information about the Dnsmasq-discuss
mailing list