svn commit: r205083 - in head: sys/netgraph usr.bin/netstat

Gleb Smirnoff glebius at FreeBSD.org
Fri Mar 12 15:05:00 UTC 2010


Author: glebius
Date: Fri Mar 12 15:04:59 2010
New Revision: 205083
URL: http://svn.freebsd.org/changeset/base/205083

Log:
  Now fix functionality of 'netstat -f netgraph' that hasn't worked
  starting from netgraph import in 1999.
  
  netstat(8) used pointer to node as node address, oops. That didn't
  work, we need the node ID in brackets to successfully address a node.
  We can't look into ng_node, due to inability to include netgraph/netgraph.h
  in userland code. So let the node make a hint for a userland, storing
  the node ID in its private data.
  
  MFC after:	2 weeks

Modified:
  head/sys/netgraph/ng_socket.c
  head/sys/netgraph/ng_socketvar.h
  head/usr.bin/netstat/netgraph.c

Modified: head/sys/netgraph/ng_socket.c
==============================================================================
--- head/sys/netgraph/ng_socket.c	Fri Mar 12 14:51:42 2010	(r205082)
+++ head/sys/netgraph/ng_socket.c	Fri Mar 12 15:04:59 2010	(r205083)
@@ -552,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);

Modified: head/sys/netgraph/ng_socketvar.h
==============================================================================
--- head/sys/netgraph/ng_socketvar.h	Fri Mar 12 14:51:42 2010	(r205082)
+++ head/sys/netgraph/ng_socketvar.h	Fri Mar 12 15:04:59 2010	(r205083)
@@ -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: head/usr.bin/netstat/netgraph.c
==============================================================================
--- head/usr.bin/netstat/netgraph.c	Fri Mar 12 14:51:42 2010	(r205082)
+++ head/usr.bin/netstat/netgraph.c	Fri Mar 12 15:04:59 2010	(r205083)
@@ -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-head mailing list