From owner-svn-src-head@FreeBSD.ORG Mon Jan 23 15:39:45 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 813AA106564A; Mon, 23 Jan 2012 15:39:45 +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 661DA8FC14; Mon, 23 Jan 2012 15:39:45 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q0NFdjqY032644; Mon, 23 Jan 2012 15:39:45 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q0NFdjwo032640; Mon, 23 Jan 2012 15:39:45 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201201231539.q0NFdjwo032640@svn.freebsd.org> From: Gleb Smirnoff Date: Mon, 23 Jan 2012 15:39:45 +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: r230481 - in head: sys/netgraph usr.bin/netstat X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jan 2012 15:39:45 -0000 Author: glebius Date: Mon Jan 23 15:39:45 2012 New Revision: 230481 URL: http://svn.freebsd.org/changeset/base/230481 Log: In ng_socket(4) expose less kernel internals to userland. This commit breaks ABI, but makes probability of ABI breakage in future less. 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 Mon Jan 23 15:17:14 2012 (r230480) +++ head/sys/netgraph/ng_socket.c Mon Jan 23 15:39:45 2012 (r230481) @@ -162,6 +162,19 @@ static struct mtx ngsocketlist_mtx; #define TRAP_ERROR #endif +/* Per-node private data */ +struct ngsock { + struct ng_node *node; /* the associated netgraph node */ + struct ngpcb *datasock; /* optional data socket */ + struct ngpcb *ctlsock; /* optional control socket */ + int flags; + int refs; + struct mtx mtx; /* mtx to wait on */ + int error; /* place to store error */ +}; + +#define NGS_FLAG_NOLINGER 1 /* close with last hook */ + /*************************************************************** Control sockets ***************************************************************/ @@ -535,9 +548,7 @@ ng_attach_cntl(struct socket *so) pcbp->sockdata = priv; priv->refs++; priv->node = node; - - /* Store a hint for netstat(1). */ - priv->node_id = priv->node->nd_ID; + pcbp->node_id = node->nd_ID; /* hint for netstat(1) */ /* Link the node and the private data. */ NG_NODE_SET_PRIVATE(priv->node, priv); @@ -608,6 +619,7 @@ ng_detach_common(struct ngpcb *pcbp, int panic("%s", __func__); } pcbp->sockdata = NULL; + pcbp->node_id = 0; ng_socket_free_priv(priv); } @@ -698,6 +710,7 @@ ng_connect_data(struct sockaddr *nam, st mtx_lock(&priv->mtx); priv->datasock = pcbp; pcbp->sockdata = priv; + pcbp->node_id = priv->node->nd_ID; /* hint for netstat(1) */ priv->refs++; mtx_unlock(&priv->mtx); NG_FREE_ITEM(item); /* drop the reference to the node */ Modified: head/sys/netgraph/ng_socketvar.h ============================================================================== --- head/sys/netgraph/ng_socketvar.h Mon Jan 23 15:17:14 2012 (r230480) +++ head/sys/netgraph/ng_socketvar.h Mon Jan 23 15:39:45 2012 (r230481) @@ -50,20 +50,6 @@ struct ngpcb { struct ngsock *sockdata; /* netgraph info */ LIST_ENTRY(ngpcb) socks; /* linked list of sockets */ int type; /* NG_CONTROL or NG_DATA */ -}; - -/* Per-node private data */ -struct ngsock { - struct ng_node *node; /* the associated netgraph node */ - struct ngpcb *datasock; /* optional data socket */ - struct ngpcb *ctlsock; /* optional control socket */ - int flags; - 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 */ - #endif /* _NETGRAPH_NG_SOCKETVAR_H_ */ - Modified: head/usr.bin/netstat/netgraph.c ============================================================================== --- head/usr.bin/netstat/netgraph.c Mon Jan 23 15:17:14 2012 (r230480) +++ head/usr.bin/netstat/netgraph.c Mon Jan 23 15:39:45 2012 (r230481) @@ -67,7 +67,6 @@ netgraphprotopr(u_long off, const char * { struct ngpcb *this, *next; struct ngpcb ngpcb; - struct ngsock info; struct socket sockb; int debug = 1; @@ -165,15 +164,10 @@ netgraphprotopr(u_long off, const char * printf("%-5.5s %6u %6u ", name, sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc); - /* Get ngsock structure */ - 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_id == 0 || csock == -1) + if (ngpcb.node_id == 0 || csock == -1) goto finish; - snprintf(path, sizeof(path), "[%x]:", info.node_id); + snprintf(path, sizeof(path), "[%x]:", ngpcb.node_id); if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, NGM_NODEINFO, NULL, 0) < 0) goto finish;