Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet6 inet6: Use generic Neighor Detection rather tha...



details:   https://anonhg.NetBSD.org/src/rev/7911140878aa
branches:  trunk
changeset: 954814:7911140878aa
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Sep 11 15:03:33 2020 +0000

description:
inet6: Use generic Neighor Detection rather than IPv6 specific

No functional change intended.

diffstat:

 sys/netinet6/icmp6.c   |   48 ++--
 sys/netinet6/nd6.c     |  420 +++++++++++-------------------------------------
 sys/netinet6/nd6.h     |   43 +---
 sys/netinet6/nd6_nbr.c |   39 ++--
 4 files changed, 153 insertions(+), 397 deletions(-)

diffs (truncated from 876 to 300 lines):

diff -r e71fb5454de0 -r 7911140878aa sys/netinet6/icmp6.c
--- a/sys/netinet6/icmp6.c      Fri Sep 11 15:01:26 2020 +0000
+++ b/sys/netinet6/icmp6.c      Fri Sep 11 15:03:33 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: icmp6.c,v 1.246 2020/07/27 14:52:55 roy Exp $  */
+/*     $NetBSD: icmp6.c,v 1.247 2020/09/11 15:03:33 roy Exp $  */
 /*     $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.246 2020/07/27 14:52:55 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.247 2020/09/11 15:03:33 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -87,6 +87,7 @@
 #include <net/route.h>
 #include <net/if_dl.h>
 #include <net/if_types.h>
+#include <net/nd.h>
 
 #include <netinet/in.h>
 #include <netinet/in_var.h>
@@ -98,9 +99,9 @@
 #include <netinet6/icmp6_private.h>
 #include <netinet6/mld6_var.h>
 #include <netinet6/in6_pcb.h>
-#include <netinet6/nd6.h>
 #include <netinet6/in6_ifattach.h>
 #include <netinet6/ip6protosw.h>
+#include <netinet6/nd6.h>
 #include <netinet6/scope6_var.h>
 
 #ifdef IPSEC
@@ -2953,7 +2954,6 @@
 static void
 sysctl_net_inet6_icmp6_setup(struct sysctllog **clog)
 {
-       extern int nd6_maxqueuelen; /* defined in nd6.c */
 
        sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT,
@@ -3008,23 +3008,37 @@
                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                       CTLTYPE_INT, "nd6_delay",
                       SYSCTL_DESCR("First probe delay time"),
-                      NULL, 0, &nd6_delay, 0,
+                      NULL, 0, &nd6_nd_domain.nd_delay, 0,
                       CTL_NET, PF_INET6, IPPROTO_ICMPV6,
                       ICMPV6CTL_ND6_DELAY, CTL_EOL);
        sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+                      CTLTYPE_INT, "nd6_mmaxtries",
+                      SYSCTL_DESCR("Number of multicast discovery attempts"),
+                      NULL, 0, &nd6_nd_domain.nd_mmaxtries, 0,
+                      CTL_NET, PF_INET6, IPPROTO_ICMPV6,
+                      ICMPV6CTL_ND6_MMAXTRIES, CTL_EOL);
+       sysctl_createv(clog, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                       CTLTYPE_INT, "nd6_umaxtries",
                       SYSCTL_DESCR("Number of unicast discovery attempts"),
-                      NULL, 0, &nd6_umaxtries, 0,
+                      NULL, 0, &nd6_nd_domain.nd_umaxtries, 0,
                       CTL_NET, PF_INET6, IPPROTO_ICMPV6,
                       ICMPV6CTL_ND6_UMAXTRIES, CTL_EOL);
        sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-                      CTLTYPE_INT, "nd6_mmaxtries",
-                      SYSCTL_DESCR("Number of multicast discovery attempts"),
-                      NULL, 0, &nd6_mmaxtries, 0,
+                      CTLTYPE_INT, "nd6_maxnudhint",
+                      SYSCTL_DESCR("Maximum neighbor unreachable hint count"),
+                      NULL, 0, &nd6_nd_domain.nd_maxnudhint, 0,
                       CTL_NET, PF_INET6, IPPROTO_ICMPV6,
-                      ICMPV6CTL_ND6_MMAXTRIES, CTL_EOL);
+                      ICMPV6CTL_ND6_MAXNUDHINT, CTL_EOL);
+       sysctl_createv(clog, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+                      CTLTYPE_INT, "maxqueuelen",
+                      SYSCTL_DESCR("max packet queue len for a unresolved ND"),
+                      NULL, 1, &nd6_nd_domain.nd_maxqueuelen, 0,
+                      CTL_NET, PF_INET6, IPPROTO_ICMPV6,
+                      ICMPV6CTL_ND6_MAXQLEN, CTL_EOL);
        sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                       CTLTYPE_INT, "nd6_useloopback",
@@ -3056,13 +3070,6 @@
                       ICMPV6CTL_ERRPPSLIMIT, CTL_EOL);
        sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-                      CTLTYPE_INT, "nd6_maxnudhint",
-                      SYSCTL_DESCR("Maximum neighbor unreachable hint count"),
-                      NULL, 0, &nd6_maxnudhint, 0,
-                      CTL_NET, PF_INET6, IPPROTO_ICMPV6,
-                      ICMPV6CTL_ND6_MAXNUDHINT, CTL_EOL);
-       sysctl_createv(clog, 0, NULL, NULL,
-                      CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                       CTLTYPE_INT, "mtudisc_hiwat",
                       SYSCTL_DESCR("Low mark on MTU Discovery route timers"),
                       NULL, 0, &icmp6_mtudisc_hiwat, 0,
@@ -3098,13 +3105,6 @@
                       CTL_NET, PF_INET6, IPPROTO_ICMPV6,
                       OICMPV6CTL_ND6_PRLIST, CTL_EOL);
 #endif
-       sysctl_createv(clog, 0, NULL, NULL,
-                      CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-                      CTLTYPE_INT, "maxqueuelen",
-                      SYSCTL_DESCR("max packet queue len for a unresolved ND"),
-                      NULL, 1, &nd6_maxqueuelen, 0,
-                      CTL_NET, PF_INET6, IPPROTO_ICMPV6,
-                      ICMPV6CTL_ND6_MAXQLEN, CTL_EOL);
 }
 
 void
diff -r e71fb5454de0 -r 7911140878aa sys/netinet6/nd6.c
--- a/sys/netinet6/nd6.c        Fri Sep 11 15:01:26 2020 +0000
+++ b/sys/netinet6/nd6.c        Fri Sep 11 15:03:33 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nd6.c,v 1.271 2020/06/12 11:04:45 roy Exp $    */
+/*     $NetBSD: nd6.c,v 1.272 2020/09/11 15:03:33 roy Exp $    */
 /*     $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $   */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.271 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.272 2020/09/11 15:03:33 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -62,6 +62,7 @@
 #include <net/if_dl.h>
 #include <net/if_llatbl.h>
 #include <net/if_types.h>
+#include <net/nd.h>
 #include <net/route.h>
 #include <net/if_ether.h>
 #include <net/if_arc.h>
@@ -86,19 +87,11 @@
 
 /* timer values */
 int    nd6_prune       = 1;    /* walk list every 1 seconds */
-int    nd6_delay       = 5;    /* delay first probe time 5 second */
-int    nd6_umaxtries   = 3;    /* maximum unicast query */
-int    nd6_mmaxtries   = 3;    /* maximum multicast query */
 int    nd6_useloopback = 1;    /* use loopback interface for local traffic */
-int    nd6_gctimer     = (60 * 60 * 24); /* 1 day: garbage collection timer */
 
 /* preventing too many loops in ND option parsing */
 int nd6_maxndopt = 10; /* max # of ND options allowed */
 
-int nd6_maxnudhint = 0;        /* max # of subsequent upper layer hints */
-
-int nd6_maxqueuelen = 1; /* max # of packets cached in unresolved ND entries */
-
 #ifdef ND6_DEBUG
 int nd6_debug = 1;
 #else
@@ -111,10 +104,16 @@
 
 static void nd6_slowtimo(void *);
 static void nd6_free(struct llentry *, int);
-static void nd6_llinfo_timer(void *);
+static bool nd6_nud_enabled(struct ifnet *);
+static unsigned int nd6_llinfo_reachable(struct ifnet *);
+static unsigned int nd6_llinfo_retrans(struct ifnet *);
+static union nd_addr *nd6_llinfo_holdsrc(struct llentry *, union nd_addr *);
+static void nd6_llinfo_output(struct ifnet *, const union nd_addr *,
+    const union nd_addr *, const uint8_t *, const union nd_addr *);
+static void nd6_llinfo_missed(struct ifnet *, const union nd_addr *,
+    struct mbuf *);
 static void nd6_timer(void *);
 static void nd6_timer_work(struct work *, void *);
-static void clear_llinfo_pqueue(struct llentry *);
 static struct nd_opt_hdr *nd6_option(union nd_opts *);
 
 static callout_t nd6_slowtimo_ch;
@@ -122,6 +121,22 @@
 static struct workqueue        *nd6_timer_wq;
 static struct work     nd6_timer_wk;
 
+struct nd_domain nd6_nd_domain = {
+       .nd_family = AF_INET6,
+       .nd_delay = 5,          /* delay first probe time 5 second */
+       .nd_mmaxtries = 3,      /* maximum unicast query */
+       .nd_umaxtries = 3,      /* maximum multicast query */
+       .nd_maxnudhint = 0,     /* max # of subsequent upper layer hints */
+       .nd_maxqueuelen = 1,    /* max # of packets in unresolved ND entries */
+       .nd_nud_enabled = nd6_nud_enabled,
+       .nd_reachable = nd6_llinfo_reachable,
+       .nd_retrans = nd6_llinfo_retrans,
+       .nd_holdsrc = nd6_llinfo_holdsrc,
+       .nd_output = nd6_llinfo_output,
+       .nd_missed = nd6_llinfo_missed,
+       .nd_free = nd6_free,
+};
+
 MALLOC_DEFINE(M_IP6NDP, "NDP", "IPv6 Neighbour Discovery");
 
 void
@@ -129,6 +144,7 @@
 {
        int error;
 
+       nd_attach_domain(&nd6_nd_domain);
        nd6_nbr_init();
 
        rw_init(&nd6_lock);
@@ -326,44 +342,6 @@
 }
 
 /*
- * ND6 timer routine to handle ND6 entries
- */
-void
-nd6_llinfo_settimer(struct llentry *ln, time_t xtick)
-{
-
-       CTASSERT(sizeof(time_t) > sizeof(int));
-       LLE_WLOCK_ASSERT(ln);
-
-       KASSERT(xtick >= 0);
-
-       /*
-        * We have to take care of a reference leak which occurs if
-        * callout_reset overwrites a pending callout schedule.  Unfortunately
-        * we don't have a mean to know the overwrite, so we need to know it
-        * using callout_stop.  We need to call callout_pending first to exclude
-        * the case that the callout has never been scheduled.
-        */
-       if (callout_pending(&ln->la_timer)) {
-               bool expired = callout_stop(&ln->la_timer);
-               if (!expired)
-                       LLE_REMREF(ln);
-       }
-
-       ln->ln_expire = time_uptime + xtick / hz;
-       LLE_ADDREF(ln);
-       if (xtick > INT_MAX) {
-               ln->ln_ntick = xtick - INT_MAX;
-               callout_reset(&ln->ln_timer_ch, INT_MAX,
-                   nd6_llinfo_timer, ln);
-       } else {
-               ln->ln_ntick = 0;
-               callout_reset(&ln->ln_timer_ch, xtick,
-                   nd6_llinfo_timer, ln);
-       }
-}
-
-/*
  * Gets source address of the first packet in hold queue
  * and stores it in @src.
  * Returns pointer to @src (if hold queue is not empty) or NULL.
@@ -389,148 +367,67 @@
        return src;
 }
 
-static void
-nd6_llinfo_timer(void *arg)
+static union nd_addr *
+nd6_llinfo_holdsrc(struct llentry *ln, union nd_addr *src)
 {
-       struct llentry *ln = arg;
-       struct ifnet *ifp;
-       struct nd_kifinfo *ndi;
-       bool send_ns = false;
-       const struct in6_addr *daddr6 = NULL;
-       const struct in6_addr *taddr6 = &ln->r_l3addr.addr6;
-       struct sockaddr_in6 dsin6, tsin6;
-       struct mbuf *m = NULL;
-       bool missed = false;
 
-       SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
-
-       LLE_WLOCK(ln);
-       if ((ln->la_flags & LLE_LINKED) == 0)
-               goto out;
-       if (ln->ln_ntick > 0) {
-               nd6_llinfo_settimer(ln, ln->ln_ntick);
-               goto out;
-       }
-
-       ifp = ln->lle_tbl->llt_ifp;
-       KASSERT(ifp != NULL);
-
-       ndi = ND_IFINFO(ifp);
+       if (nd6_llinfo_get_holdsrc(ln, &src->nd_addr6) == NULL)
+               return NULL;
+       return src;
+}
 
-       switch (ln->ln_state) {
-       case ND6_LLINFO_WAITDELETE:
-               LLE_REMREF(ln);
-               nd6_free(ln, 0);



Home | Main Index | Thread Index | Old Index