Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet6 Fix default route selection



details:   https://anonhg.NetBSD.org/src/rev/8bd74fe85473
branches:  trunk
changeset: 930754:8bd74fe85473
user:      kim <kim%NetBSD.org@localhost>
date:      Mon Apr 13 14:04:27 2020 +0000

description:
Fix default route selection

The primary issue was that in revision 1.79 a check was added in the
nd6_defrouter_select() search loop to ignore the entry if RA processing
is enabled on its interface.  In practice this results in all entries
being ignored.

This fix reverses the condition, so that an entry is ignored when RA
processing is NOT enabled on its interface.  Further, the entry is
only ignored for being selected as the default router.  The currently
installed router must be identified regardless of the (current) status
of its interface, so that we can delete the route before installing a
new one.

I also added error logging when adding or deleting a route fails. This
should help the administrator (or kernel developer) in noticing possible
problems.

Finally, if deleting a route fails, the corresponding default route
entry no longer has its "installed" flag cleared, so that deletion will
be retried.  At a minimum, this will cause repeated messages about the
failed deletion as opposed to only getting repeated messages about the
installation of a new default route failing.

Fixes PR kern/55091 and also PR bin/54997 as far as the behaviour
observed with ndp(8).

diffstat:

 sys/netinet6/nd6_rtr.c |  36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)

diffs (79 lines):

diff -r 66d40376b51c -r 8bd74fe85473 sys/netinet6/nd6_rtr.c
--- a/sys/netinet6/nd6_rtr.c    Mon Apr 13 12:14:55 2020 +0000
+++ b/sys/netinet6/nd6_rtr.c    Mon Apr 13 14:04:27 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nd6_rtr.c,v 1.147 2019/12/27 10:17:56 msaitoh Exp $    */
+/*     $NetBSD: nd6_rtr.c,v 1.148 2020/04/13 14:04:27 kim Exp $        */
 /*     $KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $        */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.147 2019/12/27 10:17:56 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.148 2020/04/13 14:04:27 kim Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -487,6 +487,11 @@
        if (error == 0) {
                nd6_numroutes++;
                newdr->installed = 1;
+       } else {
+               char ip6buf[INET6_ADDRSTRLEN];
+               log(LOG_ERR, "defrouter_addreq: "
+                   "error %d adding default router %s on %s\n",
+                   error, IN6_PRINT(ip6buf, &newdr->rtaddr), newdr->ifp->if_xname);
        }
 #ifndef NET_MPSAFE
        splx(s);
@@ -596,10 +601,15 @@
 
        error = rtrequest_newmsg(RTM_DELETE, &def.sa, &gw.sa, &mask.sa,
            RTF_GATEWAY);
-       if (error == 0)
+       if (error == 0) {
                nd6_numroutes--;
-
-       dr->installed = 0;
+               dr->installed = 0;
+       } else {
+               char ip6buf[INET6_ADDRSTRLEN];
+               log(LOG_ERR, "defrouter_delreq: "
+                   "error %d deleting default router %s on %s\n",
+                   error, IN6_PRINT(ip6buf, &dr->rtaddr), dr->ifp->if_xname);
+       }
 }
 
 /*
@@ -675,14 +685,6 @@
         * the ordering rule of the list described in defrtrlist_update().
         */
        ND_DEFROUTER_LIST_FOREACH(dr) {
-               ndi = ND_IFINFO(dr->ifp);
-               if (nd6_accepts_rtadv(ndi))
-                       continue;
-
-               if (selected_dr == NULL &&
-                   nd6_is_llinfo_probreach(dr))
-                       selected_dr = dr;
-
                if (dr->installed && !installed_dr)
                        installed_dr = dr;
                else if (dr->installed && installed_dr) {
@@ -690,6 +692,14 @@
                        log(LOG_ERR, "nd6_defrouter_select: more than one router"
                            " is installed\n");
                }
+
+               ndi = ND_IFINFO(dr->ifp);
+               if (!nd6_accepts_rtadv(ndi))
+                       continue;
+
+               if (selected_dr == NULL &&
+                   nd6_is_llinfo_probreach(dr))
+                       selected_dr = dr;
        }
        /*
         * If none of the default routers was found to be reachable,



Home | Main Index | Thread Index | Old Index