Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net add lock for sclist to exclude ifconfig gifX add/del...
details: https://anonhg.NetBSD.org/src/rev/8363a87421e1
branches: trunk
changeset: 356363:8363a87421e1
user: knakahara <knakahara%NetBSD.org@localhost>
date: Thu Sep 21 09:46:14 2017 +0000
description:
add lock for sclist to exclude ifconfig gifX add/delete and ifconfig gifX tunnel
diffstat:
sys/net/if_gif.c | 27 ++++++++++++++++++++-------
1 files changed, 20 insertions(+), 7 deletions(-)
diffs (90 lines):
diff -r 342853654201 -r 8363a87421e1 sys/net/if_gif.c
--- a/sys/net/if_gif.c Thu Sep 21 09:42:03 2017 +0000
+++ b/sys/net/if_gif.c Thu Sep 21 09:46:14 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_gif.c,v 1.129 2017/09/21 09:42:03 knakahara Exp $ */
+/* $NetBSD: if_gif.c,v 1.130 2017/09/21 09:46:14 knakahara Exp $ */
/* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.129 2017/09/21 09:42:03 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.130 2017/09/21 09:46:14 knakahara Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -96,7 +96,11 @@
/*
* gif global variable definitions
*/
-static LIST_HEAD(, gif_softc) gif_softc_list;
+LIST_HEAD(gif_sclist, gif_softc);
+static struct {
+ struct gif_sclist list;
+ kmutex_t lock;
+} gif_softcs __cacheline_aligned;
static void gif_ro_init_pc(void *, void *, struct cpu_info *);
static void gif_ro_fini_pc(void *, void *, struct cpu_info *);
@@ -208,7 +212,8 @@
gifinit(void)
{
- LIST_INIT(&gif_softc_list);
+ mutex_init(&gif_softcs.lock, MUTEX_DEFAULT, IPL_NONE);
+ LIST_INIT(&gif_softcs.list);
if_clone_attach(&gif_cloner);
gif_sysctl_setup();
@@ -219,8 +224,11 @@
{
int error = 0;
- if (!LIST_EMPTY(&gif_softc_list))
+ mutex_enter(&gif_softcs.lock);
+ if (!LIST_EMPTY(&gif_softcs.list)) {
+ mutex_exit(&gif_softcs.lock);
error = EBUSY;
+ }
if (error == 0) {
if_clone_detach(&gif_cloner);
@@ -244,7 +252,9 @@
sc->gif_ro_percpu = percpu_alloc(sizeof(struct gif_ro));
percpu_foreach(sc->gif_ro_percpu, gif_ro_init_pc, NULL);
- LIST_INSERT_HEAD(&gif_softc_list, sc, gif_list);
+ mutex_enter(&gif_softcs.lock);
+ LIST_INSERT_HEAD(&gif_softcs.list, sc, gif_list);
+ mutex_exit(&gif_softcs.lock);
return (0);
}
@@ -994,7 +1004,8 @@
return error;
}
- LIST_FOREACH(sc2, &gif_softc_list, gif_list) {
+ mutex_enter(&gif_softcs.lock);
+ LIST_FOREACH(sc2, &gif_softcs.list, gif_list) {
if (sc2 == sc)
continue;
if (!sc2->gif_pdst || !sc2->gif_psrc)
@@ -1003,12 +1014,14 @@
if (sockaddr_cmp(sc2->gif_pdst, dst) == 0 &&
sockaddr_cmp(sc2->gif_psrc, src) == 0) {
/* continue to use the old configureation. */
+ mutex_exit(&gif_softcs.lock);
error = EADDRNOTAVAIL;
goto out;
}
/* XXX both end must be valid? (I mean, not 0.0.0.0) */
}
+ mutex_exit(&gif_softcs.lock);
nsrc = sockaddr_dup(src, M_WAITOK);
ndst = sockaddr_dup(dst, M_WAITOK);
Home |
Main Index |
Thread Index |
Old Index