From owner-svn-src-head@FreeBSD.ORG Wed Feb 19 08:29:08 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2A001341; Wed, 19 Feb 2014 08:29:08 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 163DB18DD; Wed, 19 Feb 2014 08:29:08 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s1J8T7Dd021910; Wed, 19 Feb 2014 08:29:07 GMT (envelope-from zec@svn.freebsd.org) Received: (from zec@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s1J8T7fQ021909; Wed, 19 Feb 2014 08:29:07 GMT (envelope-from zec@svn.freebsd.org) Message-Id: <201402190829.s1J8T7fQ021909@svn.freebsd.org> From: Marko Zec Date: Wed, 19 Feb 2014 08:29:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r262215 - head/sys/net X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 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: Wed, 19 Feb 2014 08:29:08 -0000 Author: zec Date: Wed Feb 19 08:29:07 2014 New Revision: 262215 URL: http://svnweb.freebsd.org/changeset/base/262215 Log: V_irtualize rtsock refcounting, which reduces the chances for panics on teardown of vnets without active routing sockets while at least one routing socket is active elsewhere. Tested by: Vijay Singh MFC after: 3 days Modified: head/sys/net/rtsock.c Modified: head/sys/net/rtsock.c ============================================================================== --- head/sys/net/rtsock.c Wed Feb 19 08:15:09 2014 (r262214) +++ head/sys/net/rtsock.c Wed Feb 19 08:29:07 2014 (r262215) @@ -154,12 +154,14 @@ int (*carp_get_vhid_p)(struct ifaddr *); */ #define RTS_FILTER_FIB M_PROTO8 -static struct { +typedef struct { int ip_count; /* attached w/ AF_INET */ int ip6_count; /* attached w/ AF_INET6 */ int ipx_count; /* attached w/ AF_IPX */ int any_count; /* total attached */ -} route_cb; +} route_cb_t; +static VNET_DEFINE(route_cb_t, route_cb); +#define V_route_cb VNET(route_cb) struct mtx rtsock_mtx; MTX_SYSINIT(rtsock, &rtsock_mtx, "rtsock route_cb lock", MTX_DEF); @@ -317,16 +319,16 @@ rts_attach(struct socket *so, int proto, RTSOCK_LOCK(); switch(rp->rcb_proto.sp_protocol) { case AF_INET: - route_cb.ip_count++; + V_route_cb.ip_count++; break; case AF_INET6: - route_cb.ip6_count++; + V_route_cb.ip6_count++; break; case AF_IPX: - route_cb.ipx_count++; + V_route_cb.ipx_count++; break; } - route_cb.any_count++; + V_route_cb.any_count++; RTSOCK_UNLOCK(); soisconnected(so); so->so_options |= SO_USELOOPBACK; @@ -360,16 +362,16 @@ rts_detach(struct socket *so) RTSOCK_LOCK(); switch(rp->rcb_proto.sp_protocol) { case AF_INET: - route_cb.ip_count--; + V_route_cb.ip_count--; break; case AF_INET6: - route_cb.ip6_count--; + V_route_cb.ip6_count--; break; case AF_IPX: - route_cb.ipx_count--; + V_route_cb.ipx_count--; break; } - route_cb.any_count--; + V_route_cb.any_count--; RTSOCK_UNLOCK(); raw_usrreqs.pru_detach(so); } @@ -943,7 +945,7 @@ flush: * Check to see if we don't want our own messages. */ if ((so->so_options & SO_USELOOPBACK) == 0) { - if (route_cb.any_count <= 1) { + if (V_route_cb.any_count <= 1) { if (rtm) Free(rtm); m_freem(m); @@ -1274,7 +1276,7 @@ rt_missmsg_fib(int type, struct rt_addri struct mbuf *m; struct sockaddr *sa = rtinfo->rti_info[RTAX_DST]; - if (route_cb.any_count == 0) + if (V_route_cb.any_count == 0) return; m = rt_msg1(type, rtinfo); if (m == NULL) @@ -1312,7 +1314,7 @@ rt_ifmsg(struct ifnet *ifp) struct mbuf *m; struct rt_addrinfo info; - if (route_cb.any_count == 0) + if (V_route_cb.any_count == 0) return; bzero((caddr_t)&info, sizeof(info)); m = rt_msg1(RTM_IFINFO, &info); @@ -1342,7 +1344,7 @@ rtsock_addrmsg(int cmd, struct ifaddr *i struct ifa_msghdr *ifam; struct ifnet *ifp = ifa->ifa_ifp; - if (route_cb.any_count == 0) + if (V_route_cb.any_count == 0) return (0); ncmd = cmd == RTM_ADD ? RTM_NEWADDR : RTM_DELADDR; @@ -1390,7 +1392,7 @@ rtsock_routemsg(int cmd, struct ifnet *i struct mbuf *m; struct rt_msghdr *rtm; - if (route_cb.any_count == 0) + if (V_route_cb.any_count == 0) return (0); bzero((caddr_t)&info, sizeof(info)); @@ -1428,7 +1430,7 @@ rt_newmaddrmsg(int cmd, struct ifmultiad struct ifnet *ifp = ifma->ifma_ifp; struct ifma_msghdr *ifmam; - if (route_cb.any_count == 0) + if (V_route_cb.any_count == 0) return; bzero((caddr_t)&info, sizeof(info)); @@ -1457,7 +1459,7 @@ rt_makeifannouncemsg(struct ifnet *ifp, struct if_announcemsghdr *ifan; struct mbuf *m; - if (route_cb.any_count == 0) + if (V_route_cb.any_count == 0) return NULL; bzero((caddr_t)info, sizeof(*info)); m = rt_msg1(type, info);