aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Watson <rwatson@FreeBSD.org>2004-07-12 04:45:46 +0000
committerRobert Watson <rwatson@FreeBSD.org>2004-07-12 04:45:46 +0000
commit943bb929afd9720bb6b8583b8e1cb40ef2e777c3 (patch)
tree057d953ffcbcf7bfaea687b8f82dcf61b8b9f117
parentb41e0f0f56e729972814d4be35bf380f7d349a17 (diff)
downloadsrc-943bb929afd9720bb6b8583b8e1cb40ef2e777c3.tar.gz
src-943bb929afd9720bb6b8583b8e1cb40ef2e777c3.zip
Introduce a global mtx 'ngsocketlist_mtx' to protect the global
ng_socket list during insert/delete.
Notes
Notes: svn path=/head/; revision=132013
-rw-r--r--sys/netgraph/ng_socket.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c
index 9a140b631ffd..52308f412c2c 100644
--- a/sys/netgraph/ng_socket.c
+++ b/sys/netgraph/ng_socket.c
@@ -55,6 +55,7 @@
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
+#include <sys/mutex.h>
#include <sys/protosw.h>
#include <sys/queue.h>
#include <sys/signalvar.h>
@@ -154,6 +155,9 @@ SYSCTL_INT(_net_graph, OID_AUTO, recvspace, CTLFLAG_RW,
/* List of all sockets */
static LIST_HEAD(, ngpcb) ngsocklist;
+static struct mtx ngsocketlist_mtx;
+MTX_SYSINIT(ngsocketlist, &ngsocketlist_mtx, "ng_socketlist", MTX_DEF);
+
#define sotongpcb(so) ((struct ngpcb *)(so)->so_pcb)
/* If getting unexplained errors returned, set this to "kdb_enter("X"); */
@@ -525,7 +529,9 @@ ng_attach_common(struct socket *so, int type)
pcbp->ng_socket = so;
/* Add the socket to linked list */
+ mtx_lock(&ngsocketlist_mtx);
LIST_INSERT_HEAD(&ngsocklist, pcbp, socks);
+ mtx_unlock(&ngsocketlist_mtx);
return (0);
}
@@ -558,7 +564,9 @@ ng_detach_common(struct ngpcb *pcbp, int which)
}
pcbp->ng_socket->so_pcb = NULL;
pcbp->ng_socket = NULL;
+ mtx_lock(&ngsocketlist_mtx);
LIST_REMOVE(pcbp, socks);
+ mtx_unlock(&ngsocketlist_mtx);
FREE(pcbp, M_PCB);
}