Prefer the global list of interfaces that will stay.

I know one line is >80 chars with this diff, I'll rename
find_pfxlist_reachable_router() to pfxrtr_find_reachable() for
consistency afterward.  This should be enough.

ok?

Index: netinet6/nd6_rtr.c
===================================================================
RCS file: /cvs/src/sys/netinet6/nd6_rtr.c,v
retrieving revision 1.155
diff -u -p -r1.155 nd6_rtr.c
--- netinet6/nd6_rtr.c  9 Feb 2017 15:23:35 -0000       1.155
+++ netinet6/nd6_rtr.c  2 Mar 2017 10:23:04 -0000
@@ -1519,8 +1519,10 @@ find_pfxlist_reachable_router(struct nd_
 void
 pfxlist_onlink_check(void)
 {
+       struct ifnet *ifp;
+       struct ifaddr *ifa;
        struct nd_prefix *pr;
-       struct in6_ifaddr *ia6;
+       struct in6_ifaddr *ia6, *pia6 = NULL;
        char addr[INET6_ADDRSTRLEN];
 
        /*
@@ -1624,42 +1626,54 @@ pfxlist_onlink_check(void)
         * always be attached.
         * The precise detection logic is same as the one for prefixes.
         */
-       TAILQ_FOREACH(ia6, &in6_ifaddr, ia_list) {
-               if (!(ia6->ia6_flags & IN6_IFF_AUTOCONF))
-                       continue;
+       TAILQ_FOREACH(ifp, &ifnet, if_list) {
+               TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
+                       if (ifa->ifa_addr->sa_family != AF_INET6)
+                               continue;
+
+                       ia6 = ifatoia6(ifa);
+                       if ((ia6->ia6_flags & IN6_IFF_AUTOCONF) == 0)
+                               continue;
 
-               if (ia6->ia6_ndpr == NULL) {
                        /*
                         * This can happen when we first configure the address
                         * (i.e. the address exists, but the prefix does not).
                         * XXX: complicated relationships...
                         */
-                       continue;
+                       if (ia6->ia6_ndpr == NULL)
+                               continue;
+
+                       if (find_pfxlist_reachable_router(ia6->ia6_ndpr)) {
+                               pia6 = ia6;
+                               break;
+                       }
                }
 
-               if (find_pfxlist_reachable_router(ia6->ia6_ndpr))
+               if (pia6 != NULL)
                        break;
        }
-       if (ia6) {
-               TAILQ_FOREACH(ia6, &in6_ifaddr, ia_list) {
-                       if ((ia6->ia6_flags & IN6_IFF_AUTOCONF) == 0)
-                               continue;
 
-                       if (ia6->ia6_ndpr == NULL) /* XXX: see above. */
+       TAILQ_FOREACH(ifp, &ifnet, if_list) {
+               TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
+                       if (ifa->ifa_addr->sa_family != AF_INET6)
                                continue;
 
-                       if (find_pfxlist_reachable_router(ia6->ia6_ndpr))
-                               ia6->ia6_flags &= ~IN6_IFF_DETACHED;
-                       else
-                               ia6->ia6_flags |= IN6_IFF_DETACHED;
-               }
-       }
-       else {
-               TAILQ_FOREACH(ia6, &in6_ifaddr, ia_list) {
+                       ia6 = ifatoia6(ifa);
                        if ((ia6->ia6_flags & IN6_IFF_AUTOCONF) == 0)
                                continue;
 
-                       ia6->ia6_flags &= ~IN6_IFF_DETACHED;
+                       if (pia6 != NULL) {
+                               /* XXX: see above. */
+                               if (ia6->ia6_ndpr == NULL)
+                                       continue;
+
+                               if 
(find_pfxlist_reachable_router(ia6->ia6_ndpr))
+                                       ia6->ia6_flags &= ~IN6_IFF_DETACHED;
+                               else
+                                       ia6->ia6_flags |= IN6_IFF_DETACHED;
+                       } else {
+                               ia6->ia6_flags &= ~IN6_IFF_DETACHED;
+                       }
                }
        }
 }

Reply via email to