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
This commit is contained in:
parent
60a25b4ba1
commit
c1b90938b1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=205083
@ -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);
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user