Source-Changes-HG archive

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

[src/netbsd-8]: src/sys Pull up following revision(s) (requested by ozaki-r i...



details:   https://anonhg.NetBSD.org/src/rev/9bc854726d69
branches:  netbsd-8
changeset: 852574:9bc854726d69
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Sep 30 15:48:45 2019 +0000

description:
Pull up following revision(s) (requested by ozaki-r in ticket #1396):

        sys/netinet6/nd6.h: revision 1.88
        sys/netinet6/nd6_nbr.c: revision 1.174
        sys/netinet6/nd6.c: revision 1.264
        sys/netinet/if_arp.c: revision 1.288 (patch)

Initialize DAD components properly

The original code initialized each component in non-init functions such as
arp_dad_start and nd6_dad_find, conditionally based on a global flag for each.
However, it was racy because the flag and the code around it were not
protected by a lock and could cause a kernel panic at worst.

Fix the issue by initializing the components in bootup as usual.

diffstat:

 sys/netinet/if_arp.c   |  25 +++++++++++++------------
 sys/netinet6/nd6.c     |   6 ++++--
 sys/netinet6/nd6.h     |   3 ++-
 sys/netinet6/nd6_nbr.c |  22 ++++++++++------------
 4 files changed, 29 insertions(+), 27 deletions(-)

diffs (180 lines):

diff -r c84c26ceb83e -r 9bc854726d69 sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c      Sat Sep 28 07:48:30 2019 +0000
+++ b/sys/netinet/if_arp.c      Mon Sep 30 15:48:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.c,v 1.250.2.9 2018/11/06 14:38:58 martin Exp $  */
+/*     $NetBSD: if_arp.c,v 1.250.2.10 2019/09/30 15:48:45 martin Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.250.2.9 2018/11/06 14:38:58 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.250.2.10 2019/09/30 15:48:45 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -154,6 +154,7 @@
 #endif
 
 static void arp_init(void);
+static void arp_dad_init(void);
 
 static void arprequest(struct ifnet *,
     const struct in_addr *, const struct in_addr *,
@@ -288,6 +289,8 @@
        sysctl_net_inet_arp_setup(NULL);
        arpstat_percpu = percpu_alloc(sizeof(uint64_t) * ARP_NSTATS);
        IFQ_LOCK_INIT(&arpintrq);
+
+       arp_dad_init();
 }
 
 static void
@@ -1517,10 +1520,17 @@
 };
 
 static struct dadq_head dadq;
-static int dad_init = 0;
 static int dad_maxtry = 15;     /* max # of *tries* to transmit DAD packet */
 static kmutex_t arp_dad_lock;
 
+static void
+arp_dad_init(void)
+{
+
+       TAILQ_INIT(&dadq);
+       mutex_init(&arp_dad_lock, MUTEX_DEFAULT, IPL_NONE);
+}
+
 static struct dadq *
 arp_dad_find(struct ifaddr *ifa)
 {
@@ -1595,12 +1605,6 @@
        struct dadq *dp;
        char ipbuf[INET_ADDRSTRLEN];
 
-       if (!dad_init) {
-               TAILQ_INIT(&dadq);
-               mutex_init(&arp_dad_lock, MUTEX_DEFAULT, IPL_NONE);
-               dad_init++;
-       }
-
        /*
         * If we don't need DAD, don't do it.
         * - DAD is disabled (ip_dad_count == 0)
@@ -1669,9 +1673,6 @@
 {
        struct dadq *dp;
 
-       if (!dad_init)
-               return;
-
        mutex_enter(&arp_dad_lock);
        dp = arp_dad_find(ifa);
        if (dp == NULL) {
diff -r c84c26ceb83e -r 9bc854726d69 sys/netinet6/nd6.c
--- a/sys/netinet6/nd6.c        Sat Sep 28 07:48:30 2019 +0000
+++ b/sys/netinet6/nd6.c        Mon Sep 30 15:48:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nd6.c,v 1.232.2.12 2019/08/19 14:28:12 martin Exp $    */
+/*     $NetBSD: nd6.c,v 1.232.2.13 2019/09/30 15:48:45 martin 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.232.2.12 2019/08/19 14:28:12 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.232.2.13 2019/09/30 15:48:45 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -139,6 +139,8 @@
 {
        int error;
 
+       nd6_nbr_init();
+
        rw_init(&nd6_lock);
 
        /* initialization of the default router list */
diff -r c84c26ceb83e -r 9bc854726d69 sys/netinet6/nd6.h
--- a/sys/netinet6/nd6.h        Sat Sep 28 07:48:30 2019 +0000
+++ b/sys/netinet6/nd6.h        Mon Sep 30 15:48:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nd6.h,v 1.83.6.1 2017/07/07 13:57:26 martin Exp $      */
+/*     $NetBSD: nd6.h,v 1.83.6.2 2019/09/30 15:48:45 martin Exp $      */
 /*     $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $    */
 
 /*
@@ -426,6 +426,7 @@
 /* XXX: need nd6_var.h?? */
 /* nd6.c */
 void nd6_init(void);
+void nd6_nbr_init(void);
 struct nd_ifinfo *nd6_ifattach(struct ifnet *);
 void nd6_ifdetach(struct ifnet *, struct in6_ifextra *);
 int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *);
diff -r c84c26ceb83e -r 9bc854726d69 sys/netinet6/nd6_nbr.c
--- a/sys/netinet6/nd6_nbr.c    Sat Sep 28 07:48:30 2019 +0000
+++ b/sys/netinet6/nd6_nbr.c    Mon Sep 30 15:48:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nd6_nbr.c,v 1.138.6.8 2019/09/23 08:17:24 martin Exp $ */
+/*     $NetBSD: nd6_nbr.c,v 1.138.6.9 2019/09/30 15:48:45 martin Exp $ */
 /*     $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $        */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.138.6.8 2019/09/23 08:17:24 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.138.6.9 2019/09/30 15:48:45 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1076,9 +1076,16 @@
 };
 
 static struct dadq_head dadq;
-static int dad_init = 0;
 static kmutex_t nd6_dad_lock;
 
+void
+nd6_nbr_init(void)
+{
+
+       TAILQ_INIT(&dadq);
+       mutex_init(&nd6_dad_lock, MUTEX_DEFAULT, IPL_NONE);
+}
+
 static struct dadq *
 nd6_dad_find(struct ifaddr *ifa)
 {
@@ -1136,12 +1143,6 @@
        struct dadq *dp;
        char ip6buf[INET6_ADDRSTRLEN];
 
-       if (!dad_init) {
-               TAILQ_INIT(&dadq);
-               mutex_init(&nd6_dad_lock, MUTEX_DEFAULT, IPL_NONE);
-               dad_init++;
-       }
-
        /*
         * If we don't need DAD, don't do it.
         * There are several cases:
@@ -1219,9 +1220,6 @@
 {
        struct dadq *dp;
 
-       if (!dad_init)
-               return;
-
        mutex_enter(&nd6_dad_lock);
        dp = nd6_dad_find(ifa);
        if (dp == NULL) {



Home | Main Index | Thread Index | Old Index