Protect bridge_list with a mutex

This commit is contained in:
ozaki-r 2014-07-02 09:51:08 +00:00
parent 1aecea656e
commit a4bec2dd1b

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_bridge.c,v 1.85 2014/07/02 09:43:16 ozaki-r Exp $ */
/* $NetBSD: if_bridge.c,v 1.86 2014/07/02 09:51:08 ozaki-r Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.85 2014/07/02 09:43:16 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.86 2014/07/02 09:51:08 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_bridge_ipf.h"
@ -100,6 +100,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.85 2014/07/02 09:43:16 ozaki-r Exp $
#include <sys/kauth.h>
#include <sys/cpu.h>
#include <sys/cprng.h>
#include <sys/mutex.h>
#include <net/bpf.h>
#include <net/if.h>
@ -312,6 +313,7 @@ static const struct bridge_control bridge_control_table[] = {
static const int bridge_control_table_size = __arraycount(bridge_control_table);
static LIST_HEAD(, bridge_softc) bridge_list;
static kmutex_t bridge_list_lock;
static struct if_clone bridge_cloner =
IF_CLONE_INITIALIZER("bridge", bridge_clone_create, bridge_clone_destroy);
@ -329,6 +331,7 @@ bridgeattach(int n)
0, 0, 0, "brtpl", NULL, IPL_NET);
LIST_INIT(&bridge_list);
mutex_init(&bridge_list_lock, MUTEX_DEFAULT, IPL_NET);
if_clone_attach(&bridge_cloner);
}
@ -342,7 +345,6 @@ bridge_clone_create(struct if_clone *ifc, int unit)
{
struct bridge_softc *sc;
struct ifnet *ifp;
int s;
sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
ifp = &sc->sc_if;
@ -386,9 +388,9 @@ bridge_clone_create(struct if_clone *ifc, int unit)
if_alloc_sadl(ifp);
s = splnet();
mutex_enter(&bridge_list_lock);
LIST_INSERT_HEAD(&bridge_list, sc, sc_list);
splx(s);
mutex_exit(&bridge_list_lock);
return (0);
}
@ -415,7 +417,9 @@ bridge_clone_destroy(struct ifnet *ifp)
while ((bif = LIST_FIRST(&sc->sc_iflist)) != NULL)
bridge_delete_member(sc, bif);
mutex_enter(&bridge_list_lock);
LIST_REMOVE(sc, sc_list);
mutex_exit(&bridge_list_lock);
splx(s);