From owner-svn-src-all@FreeBSD.ORG Fri Mar 12 15:05:00 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 595E4106566C; Fri, 12 Mar 2010 15:05:00 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2D0758FC16; Fri, 12 Mar 2010 15:05:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o2CF50i4033057; Fri, 12 Mar 2010 15:05:00 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2CF50MB033023; Fri, 12 Mar 2010 15:05:00 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201003121505.o2CF50MB033023@svn.freebsd.org> From: Gleb Smirnoff Date: Fri, 12 Mar 2010 15:05:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205083 - in head: sys/netgraph usr.bin/netstat X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Mar 2010 15:05:00 -0000 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;