From owner-svn-src-all@FreeBSD.ORG Fri Mar 12 14:51:42 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 A8CFB106564A; Fri, 12 Mar 2010 14:51:42 +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 976308FC1A; Fri, 12 Mar 2010 14:51:42 +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 o2CEpgcf030009; Fri, 12 Mar 2010 14:51:42 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2CEpgws030007; Fri, 12 Mar 2010 14:51:42 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201003121451.o2CEpgws030007@svn.freebsd.org> From: Gleb Smirnoff Date: Fri, 12 Mar 2010 14:51:42 +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: r205082 - head/sys/netgraph 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 14:51:42 -0000 Author: glebius Date: Fri Mar 12 14:51:42 2010 New Revision: 205082 URL: http://svn.freebsd.org/changeset/base/205082 Log: Fix 'netstat -f netgraph', which I had broken in r163463 ling time ago in 2006. This linked list is actually needed for userland. PR: kern/140446 Submitted by: Adrian Steinmann Modified: head/sys/netgraph/ng_socket.c Modified: head/sys/netgraph/ng_socket.c ============================================================================== --- head/sys/netgraph/ng_socket.c Fri Mar 12 13:53:52 2010 (r205081) +++ head/sys/netgraph/ng_socket.c Fri Mar 12 14:51:42 2010 (r205082) @@ -156,6 +156,11 @@ static u_long ngpdg_recvspace = 20 * 102 SYSCTL_INT(_net_graph, OID_AUTO, recvspace, CTLFLAG_RW, &ngpdg_recvspace , 0, "Maximum space for incoming Netgraph datagrams"); +/* List of all sockets (for netstat -f netgraph) */ +static LIST_HEAD(, ngpcb) ngsocklist; + +static struct mtx ngsocketlist_mtx; + #define sotongpcb(so) ((struct ngpcb *)(so)->so_pcb) /* If getting unexplained errors returned, set this to "kdb_enter("X"); */ @@ -584,6 +589,10 @@ ng_attach_common(struct socket *so, int so->so_pcb = (caddr_t)pcbp; pcbp->ng_socket = so; + /* Add the socket to linked list */ + mtx_lock(&ngsocketlist_mtx); + LIST_INSERT_HEAD(&ngsocklist, pcbp, socks); + mtx_unlock(&ngsocketlist_mtx); return (0); } @@ -617,6 +626,9 @@ ng_detach_common(struct ngpcb *pcbp, int } pcbp->ng_socket->so_pcb = NULL; + mtx_lock(&ngsocketlist_mtx); + LIST_REMOVE(pcbp, socks); + mtx_unlock(&ngsocketlist_mtx); free(pcbp, M_PCB); } @@ -1115,8 +1127,14 @@ ngs_mod_event(module_t mod, int event, v switch (event) { case MOD_LOAD: + mtx_init(&ngsocketlist_mtx, "ng_socketlist", NULL, MTX_DEF); break; case MOD_UNLOAD: + /* Ensure there are no open netgraph sockets. */ + if (!LIST_EMPTY(&ngsocklist)) { + error = EBUSY; + break; + } #ifdef NOTYET /* Unregister protocol domain XXX can't do this yet.. */ #endif