From: Roy Marples Date: Tue, 3 Sep 2019 22:38:50 +0000 (+0300) Subject: Solaris: Fix address flags X-Git-Tag: v8.0.4~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ceece39805126284e444d9d8b15882240cd1c0f;p=thirdparty%2Fdhcpcd.git Solaris: Fix address flags We can use a lack of IFF_UP to set IN{,6}_IFF_TENTATIVE as well. --- diff --git a/src/if-sun.c b/src/if-sun.c index c7d8a078..52bd2e78 100644 --- a/src/if-sun.c +++ b/src/if-sun.c @@ -787,21 +787,23 @@ if_finishrt(struct dhcpcd_ctx *ctx, struct rt *rt) return 0; } -static uint64_t -if_addrflags0(int fd, const char *ifname, const struct sockaddr *sa) +static int +if_addrflags0(int fd, int af, const char *ifname) { struct lifreq lifr; + int flags; memset(&lifr, 0, sizeof(lifr)); strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name)); if (ioctl(fd, SIOCGLIFFLAGS, &lifr) == -1) - return 0; - if (ioctl(fd, SIOCGLIFADDR, &lifr) == -1) - return 0; - if (sa_cmp(sa, (struct sockaddr *)&lifr.lifr_addr) != 0) - return 0; + return -1; - return lifr.lifr_flags; + flags = 0; + if (lifr.lifr_flags & IFF_DUPLICATE) + flags |= af == AF_INET6 ? IN6_IFF_DUPLICATED:IN_IFF_DUPLICATED; + else if (!(lifr.lifr_flags & IFF_UP)) + flags |= af == AF_INET6 ? IN6_IFF_TENTATIVE:IN_IFF_TENTATIVE; + return flags; } static int @@ -963,7 +965,7 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam) if (if_getbrdaddr(ctx, ifalias, &bcast) == -1) return 0; } - flags = if_addrflags(ifp, &addr, ifalias); + flags = if_addrflags(ifp, NULL, ifalias); if (ifam->ifam_type == RTM_DELADDR) { if (flags != -1) return 0; @@ -996,7 +998,7 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam) return 0; strlcpy(ifalias, ia->alias, sizeof(ifalias)); } - flags = if_addrflags6(ifp, &addr6, ifalias); + flags = if_addrflags6(ifp, NULL, ifalias); if (ifam->ifam_type == RTM_DELADDR) { if (flags != -1) return 0; @@ -1615,21 +1617,11 @@ if_address(unsigned char cmd, const struct ipv4_addr *ia) } int -if_addrflags(const struct interface *ifp, const struct in_addr *addr, +if_addrflags(const struct interface *ifp, __unused const struct in_addr * ia, const char *alias) { - union sa_ss ss; - uint64_t aflags; - int flags; - sa_in_init(&ss.sa, addr); - aflags = if_addrflags0(ifp->ctx->pf_inet_fd, alias, &ss.sa); - if (aflags == 0) - return -1; - flags = 0; - if (aflags & IFF_DUPLICATE) - flags |= IN_IFF_DUPLICATED; - return flags; + return if_addrflags0(ifp->ctx->pf_inet_fd, AF_INET, alias); } #endif @@ -1670,23 +1662,13 @@ if_address6(unsigned char cmd, const struct ipv6_addr *ia) } int -if_addrflags6(const struct interface *ifp, const struct in6_addr *addr, +if_addrflags6(const struct interface *ifp, __unused const struct in6_addr *ia, const char *alias) { struct priv *priv; - union sa_ss ss; - uint64_t aflags; - int flags; priv = (struct priv *)ifp->ctx->priv; - sa_in6_init(&ss.sa, addr); - aflags = if_addrflags0(priv->pf_inet6_fd, alias, &ss.sa); - if (aflags == 0) - return -1; - flags = 0; - if (aflags & IFF_DUPLICATE) - flags |= IN6_IFF_DUPLICATED; - return flags; + return if_addrflags0(priv->pf_inet6_fd, AF_INET6, alias); } int diff --git a/src/ipv4.h b/src/ipv4.h index d8204a7d..eaa0dcce 100644 --- a/src/ipv4.h +++ b/src/ipv4.h @@ -63,8 +63,9 @@ * While it supports DaD, to seems to only expose IFF_DUPLICATE * so we have no way of knowing if it's tentative or not. * I don't even know if Solaris has any special treatment for tentative. */ +# define IN_IFF_TENTATIVE 0x01 # define IN_IFF_DUPLICATED 0x02 -# define IN_IFF_NOTUSEABLE IN_IFF_DUPLICATED +# define IN_IFF_DETACHED 0x00 #endif #ifdef IN_IFF_TENTATIVE diff --git a/src/ipv6.c b/src/ipv6.c index 419a3db3..341e9dd3 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -1102,8 +1102,8 @@ ipv6_handleifa(struct dhcpcd_ctx *ctx, dbp = inet_ntop(AF_INET6, &addr->s6_addr, dbuf, INET6_ADDRSTRLEN); - loginfox("%s: cmd %d addr %s", - ifname, cmd, dbp); + loginfox("%s: cmd %d addr %s addrflags %d", + ifname, cmd, dbp, addrflags); #endif if (ifs == NULL) diff --git a/src/ipv6.h b/src/ipv6.h index a95d9268..fe2f01a6 100644 --- a/src/ipv6.h +++ b/src/ipv6.h @@ -110,9 +110,9 @@ * While it supports DaD, to seems to only expose IFF_DUPLICATE * so we have no way of knowing if it's tentative or not. * I don't even know if Solaris has any special treatment for tentative. */ -# define IN6_IFF_TENTATIVE 0 +# define IN6_IFF_TENTATIVE 0x02 # define IN6_IFF_DUPLICATED 0x04 -# define IN6_IFF_DETACHED 0 +# define IN6_IFF_DETACHED 0x00 #endif #define IN6_IFF_NOTUSEABLE \