Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Initialize DAD components properly
details: https://anonhg.NetBSD.org/src/rev/be950d6635f8
branches: trunk
changeset: 454682:be950d6635f8
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Wed Sep 25 09:52:32 2019 +0000
description:
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 d1c58795c859 -r be950d6635f8 sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c Tue Sep 24 21:33:48 2019 +0000
+++ b/sys/netinet/if_arp.c Wed Sep 25 09:52:32 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_arp.c,v 1.287 2019/09/01 22:09:02 roy Exp $ */
+/* $NetBSD: if_arp.c,v 1.288 2019/09/25 09:52:32 ozaki-r 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.287 2019/09/01 22:09:02 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.288 2019/09/25 09:52:32 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -153,6 +153,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 *,
@@ -264,6 +265,8 @@
#ifdef MBUFTRACE
MOWNER_ATTACH(&arpdomain.dom_mowner);
#endif
+
+ arp_dad_init();
}
static void
@@ -1510,10 +1513,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)
{
@@ -1588,12 +1598,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
@@ -1662,9 +1666,6 @@
{
struct dadq *dp;
- if (!dad_init)
- return;
-
mutex_enter(&arp_dad_lock);
dp = arp_dad_find(ifa);
if (dp == NULL) {
diff -r d1c58795c859 -r be950d6635f8 sys/netinet6/nd6.c
--- a/sys/netinet6/nd6.c Tue Sep 24 21:33:48 2019 +0000
+++ b/sys/netinet6/nd6.c Wed Sep 25 09:52:32 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nd6.c,v 1.263 2019/09/01 19:26:21 roy Exp $ */
+/* $NetBSD: nd6.c,v 1.264 2019/09/25 09:52:32 ozaki-r 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.263 2019/09/01 19:26:21 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.264 2019/09/25 09:52:32 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -137,6 +137,8 @@
{
int error;
+ nd6_nbr_init();
+
rw_init(&nd6_lock);
/* initialization of the default router list */
diff -r d1c58795c859 -r be950d6635f8 sys/netinet6/nd6.h
--- a/sys/netinet6/nd6.h Tue Sep 24 21:33:48 2019 +0000
+++ b/sys/netinet6/nd6.h Wed Sep 25 09:52:32 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nd6.h,v 1.87 2019/09/01 19:26:21 roy Exp $ */
+/* $NetBSD: nd6.h,v 1.88 2019/09/25 09:52:32 ozaki-r Exp $ */
/* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */
/*
@@ -430,6 +430,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 d1c58795c859 -r be950d6635f8 sys/netinet6/nd6_nbr.c
--- a/sys/netinet6/nd6_nbr.c Tue Sep 24 21:33:48 2019 +0000
+++ b/sys/netinet6/nd6_nbr.c Wed Sep 25 09:52:32 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nd6_nbr.c,v 1.173 2019/09/18 08:18:05 ozaki-r Exp $ */
+/* $NetBSD: nd6_nbr.c,v 1.174 2019/09/25 09:52:32 ozaki-r 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.173 2019/09/18 08:18:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.174 2019/09/25 09:52:32 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -1124,9 +1124,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, struct nd_opt_nonce *nonce, bool *found_nonce)
{
@@ -1238,12 +1245,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:
@@ -1321,9 +1322,6 @@
{
struct dadq *dp;
- if (!dad_init)
- return;
-
mutex_enter(&nd6_dad_lock);
dp = nd6_dad_find(ifa, NULL, NULL);
if (dp == NULL) {
Home |
Main Index |
Thread Index |
Old Index