svn commit: r206088 - in stable/8: sys/netgraph usr.bin/netstat

Gleb Smirnoff glebius at FreeBSD.org
Fri Apr 2 11:07:55 UTC 2010


Author: glebius
Date: Fri Apr  2 11:07:55 2010
New Revision: 206088
URL: http://svn.freebsd.org/changeset/base/206088

Log:
  Merge r205082, r205083 that fix 'netstat -f netgraph' functionality.

Modified:
  stable/8/sys/netgraph/ng_socket.c
  stable/8/sys/netgraph/ng_socketvar.h
  stable/8/usr.bin/netstat/netgraph.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/xen/xenpci/   (props changed)
  stable/8/sys/net/   (props changed)
  stable/8/usr.bin/netstat/   (props changed)

Modified: stable/8/sys/netgraph/ng_socket.c
==============================================================================
--- stable/8/sys/netgraph/ng_socket.c	Fri Apr  2 11:05:59 2010	(r206087)
+++ stable/8/sys/netgraph/ng_socket.c	Fri Apr  2 11:07:55 2010	(r206088)
@@ -156,6 +156,11 @@ static u_long ngpdg_recvspace = 20 * 102
 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 
 	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
 	}
 
 	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, v
 
 	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

Modified: stable/8/sys/netgraph/ng_socketvar.h
==============================================================================
--- stable/8/sys/netgraph/ng_socketvar.h	Fri Apr  2 11:05:59 2010	(r206087)
+++ stable/8/sys/netgraph/ng_socketvar.h	Fri Apr  2 11:07:55 2010	(r206088)
@@ -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 */
 

Modified: stable/8/usr.bin/netstat/netgraph.c
==============================================================================
--- stable/8/usr.bin/netstat/netgraph.c	Fri Apr  2 11:05:59 2010	(r206087)
+++ stable/8/usr.bin/netstat/netgraph.c	Fri Apr  2 11:07:55 2010	(r206088)
@@ -166,14 +166,14 @@ netgraphprotopr(u_long off, const char *
 		    name, sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
 
 		/* Get ngsock structure */
-		if (ngpcb.sockdata == 0)	/* unconnected data socket */
+		if (ngpcb.sockdata == NULL)	/* unconnected data socket */
 			goto finish;
 		kread((u_long)ngpcb.sockdata, (char *)&info, sizeof(info));
 
 		/* Get info on associated node */
-		if (info.node == 0 || csock == -1)
+		if (info.node_id == 0 || csock == -1)
 			goto finish;
-		snprintf(path, sizeof(path), "[%lx]:", (u_long) info.node);
+		snprintf(path, sizeof(path), "[%x]:", info.node_id);
 		if (NgSendMsg(csock, path,
 		    NGM_GENERIC_COOKIE, NGM_NODEINFO, NULL, 0) < 0)
 			goto finish;


More information about the svn-src-stable-8 mailing list