summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2010-03-12 15:04:59 +0000
committerglebius <glebius@FreeBSD.org>2010-03-12 15:04:59 +0000
commite93d3296963195868bf04a7a6820ceef4c6a679d (patch)
tree608f4dd8db5f440fa1f16dda8e93c606342dccf2
parentaad46e823b4427474c2bf12ea7446b15d1dc6835 (diff)
downloadFreeBSD-src-e93d3296963195868bf04a7a6820ceef4c6a679d.zip
FreeBSD-src-e93d3296963195868bf04a7a6820ceef4c6a679d.tar.gz
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
-rw-r--r--sys/netgraph/ng_socket.c3
-rw-r--r--sys/netgraph/ng_socketvar.h1
-rw-r--r--usr.bin/netstat/netgraph.c6
3 files changed, 7 insertions, 3 deletions
diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c
index efee333..28e4f0e 100644
--- a/sys/netgraph/ng_socket.c
+++ b/sys/netgraph/ng_socket.c
@@ -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);
diff --git a/sys/netgraph/ng_socketvar.h b/sys/netgraph/ng_socketvar.h
index 3cf8103..c1e59dc 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 */
diff --git a/usr.bin/netstat/netgraph.c b/usr.bin/netstat/netgraph.c
index c4dd647..d510414 100644
--- a/usr.bin/netstat/netgraph.c
+++ b/usr.bin/netstat/netgraph.c
@@ -166,14 +166,14 @@ netgraphprotopr(u_long off, const char *name, int af1 __unused,
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;
OpenPOWER on IntegriCloud