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.
This commit is contained in:
parent
146714e767
commit
042d1b5f86
|
@ -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 @@ int arp_debug = 0;
|
|||
#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 @@ arp_init(void)
|
|||
#ifdef MBUFTRACE
|
||||
MOWNER_ATTACH(&arpdomain.dom_mowner);
|
||||
#endif
|
||||
|
||||
arp_dad_init();
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1510,10 +1513,17 @@ struct dadq {
|
|||
};
|
||||
|
||||
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 @@ arp_dad_start(struct ifaddr *ifa)
|
|||
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 @@ arp_dad_stop(struct ifaddr *ifa)
|
|||
{
|
||||
struct dadq *dp;
|
||||
|
||||
if (!dad_init)
|
||||
return;
|
||||
|
||||
mutex_enter(&arp_dad_lock);
|
||||
dp = arp_dad_find(ifa);
|
||||
if (dp == NULL) {
|
||||
|
|
|
@ -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 @@ nd6_init(void)
|
|||
{
|
||||
int error;
|
||||
|
||||
nd6_nbr_init();
|
||||
|
||||
rw_init(&nd6_lock);
|
||||
|
||||
/* initialization of the default router list */
|
||||
|
|
|
@ -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 @@ union nd_opts {
|
|||
/* 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 *);
|
||||
|
|
|
@ -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 @@ struct dadq {
|
|||
};
|
||||
|
||||
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 @@ nd6_dad_start(struct ifaddr *ifa, int xtick)
|
|||
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 @@ nd6_dad_stop(struct ifaddr *ifa)
|
|||
{
|
||||
struct dadq *dp;
|
||||
|
||||
if (!dad_init)
|
||||
return;
|
||||
|
||||
mutex_enter(&nd6_dad_lock);
|
||||
dp = nd6_dad_find(ifa, NULL, NULL);
|
||||
if (dp == NULL) {
|
||||
|
|
Loading…
Reference in New Issue