]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Solaris: Fix address flags
authorRoy Marples <roy@marples.name>
Tue, 3 Sep 2019 22:38:50 +0000 (01:38 +0300)
committerRoy Marples <roy@marples.name>
Tue, 3 Sep 2019 22:38:50 +0000 (01:38 +0300)
We can use a lack of IFF_UP to set IN{,6}_IFF_TENTATIVE as well.

src/if-sun.c
src/ipv4.h
src/ipv6.c
src/ipv6.h

index c7d8a0786cd73916dd67df8411ce3a1de58106c1..52bd2e78c5d5335491261063c460e0330652e1be 100644 (file)
@@ -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
index d8204a7dcd842a28c18323f546f3957cc8f7b433..eaa0dcce9ab9fbfcf1bd845dcef017bf697ed15b 100644 (file)
@@ -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
index 419a3db304ebd83cb96c4f470280889d689ba51e..341e9dd3fa875b6b1d1dfd9df4677849cfd7a606 100644 (file)
@@ -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)
index a95d92689bfca8f54b4bb2c58bdf724dcc92b0ce..fe2f01a6ec47e7794b2d8655884dd5443b7ec171 100644 (file)
     * 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 \