aboutsummaryrefslogtreecommitdiff
path: root/sys/netgraph
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2010-04-02 11:07:55 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2010-04-02 11:07:55 +0000
commit033a5be7fa5f2de760ce40e5c2557eaf683f6531 (patch)
tree8ffce948d5d2264add56bd73e89634b82e4c0d42 /sys/netgraph
parentf3939d3288738bb2cb5ed779a0939878f569dabd (diff)
Notes
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/ng_socket.c21
-rw-r--r--sys/netgraph/ng_socketvar.h1
2 files changed, 22 insertions, 0 deletions
diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c
index af68c636d9bd..28e4f0e22488 100644
--- a/sys/netgraph/ng_socket.c
+++ b/sys/netgraph/ng_socket.c
@@ -156,6 +156,11 @@ static u_long ngpdg_recvspace = 20 * 1024;
SYSCTL_INT(_net_graph, OID_AUTO, recvspace, CTLFLAG_RW,
&ngpdg_recvspace , 0, "Maximum space for incoming Netgraph datagrams");
+/* List of all sockets (for netstat -f netgraph) */
+static LIST_HEAD(, ngpcb) ngsocklist;
+
+static struct mtx ngsocketlist_mtx;
+
#define sotongpcb(so) ((struct ngpcb *)(so)->so_pcb)
/* If getting unexplained errors returned, set this to "kdb_enter("X"); */
@@ -547,6 +552,9 @@ ng_attach_cntl(struct socket *so)
return (error);
}
+ /* Store a hint for netstat(1). */
+ priv->node_id = priv->node->nd_ID;
+
/* Link the node and the private data. */
NG_NODE_SET_PRIVATE(priv->node, priv);
NG_NODE_REF(priv->node);
@@ -584,6 +592,10 @@ ng_attach_common(struct socket *so, int type)
so->so_pcb = (caddr_t)pcbp;
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);
}
@@ -617,6 +629,9 @@ ng_detach_common(struct ngpcb *pcbp, int which)
}
pcbp->ng_socket->so_pcb = NULL;
+ mtx_lock(&ngsocketlist_mtx);
+ LIST_REMOVE(pcbp, socks);
+ mtx_unlock(&ngsocketlist_mtx);
free(pcbp, M_PCB);
}
@@ -1115,8 +1130,14 @@ ngs_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
+ mtx_init(&ngsocketlist_mtx, "ng_socketlist", NULL, MTX_DEF);
break;
case MOD_UNLOAD:
+ /* Ensure there are no open netgraph sockets. */
+ if (!LIST_EMPTY(&ngsocklist)) {
+ error = EBUSY;
+ break;
+ }
#ifdef NOTYET
/* Unregister protocol domain XXX can't do this yet.. */
#endif
diff --git a/sys/netgraph/ng_socketvar.h b/sys/netgraph/ng_socketvar.h
index 3cf81035541a..c1e59dcf8a2a 100644
--- a/sys/netgraph/ng_socketvar.h
+++ b/sys/netgraph/ng_socketvar.h
@@ -61,6 +61,7 @@ struct ngsock {
int refs;
struct mtx mtx; /* mtx to wait on */
int error; /* place to store error */
+ ng_ID_t node_id; /* a hint for netstat(1) to find the node */
};
#define NGS_FLAG_NOLINGER 1 /* close with last hook */