From: Roy Marples Date: Mon, 17 Jun 2024 22:50:31 +0000 (+0100) Subject: linux: Prefer local over address when both in netlink RTA X-Git-Tag: v10.0.9~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21e3dbf9718671807aa4ac0feb9087c266023f18;p=thirdparty%2Fdhcpcd.git linux: Prefer local over address when both in netlink RTA Fixes #332. --- diff --git a/src/if-linux.c b/src/if-linux.c index 2a599516..cbc3fb64 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -804,7 +804,7 @@ link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm) int ret; #endif #ifdef INET6 - struct in6_addr addr6; + struct in6_addr *local6 = NULL, *address6 = NULL; int flags; #endif @@ -882,19 +882,24 @@ link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm) #endif #ifdef INET6 case AF_INET6: - memset(&addr6, 0, sizeof(addr6)); for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) { - switch (rta->rta_type) { + switch (rta->rta_type) { case IFA_ADDRESS: - memcpy(&addr6.s6_addr, RTA_DATA(rta), - sizeof(addr6.s6_addr)); + address6 = (struct in6_addr *)RTA_DATA(rta); + break; + case IFA_LOCAL: + local6 = (struct in6_addr *)RTA_DATA(rta); break; } } + if (local6 != NULL) + address6 = local6; + if (address6 == NULL) + break; /* should be impossible */ /* Validate RTM_DELADDR really means address deleted * and anything else really means address exists. */ - flags = if_addrflags6(ifp, &addr6, NULL); + flags = if_addrflags6(ifp, address6, NULL); if (nlm->nlmsg_type == RTM_DELADDR) { if (flags != -1) break; @@ -904,7 +909,7 @@ link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm) } ipv6_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name, - &addr6, ifa->ifa_prefixlen, ifa->ifa_flags, + address6, ifa->ifa_prefixlen, ifa->ifa_flags, (pid_t)nlm->nlmsg_pid); break; #endif