From owner-p4-projects@FreeBSD.ORG Mon May 17 10:31:10 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 64C141065678; Mon, 17 May 2010 10:31:10 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 28FFD1065673 for ; Mon, 17 May 2010 10:31:10 +0000 (UTC) (envelope-from zec@fer.hr) Received: from repoman.freebsd.org (unknown [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id F1E778FC1F for ; Mon, 17 May 2010 10:31:09 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o4HAV92q099209 for ; Mon, 17 May 2010 10:31:09 GMT (envelope-from zec@fer.hr) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o4HAV9EX099207 for perforce@freebsd.org; Mon, 17 May 2010 10:31:09 GMT (envelope-from zec@fer.hr) Date: Mon, 17 May 2010 10:31:09 GMT Message-Id: <201005171031.o4HAV9EX099207@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zec@fer.hr using -f From: Marko Zec To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 178379 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2010 10:31:10 -0000 http://p4web.freebsd.org/@@178379?ac=10 Change 178379 by zec@zec_nxlab on 2010/05/17 10:30:56 Add a global counter of all V_ip_mrouter instances, which we consult when making a decission on wheter or not to allow the module to be kldunloaded. Introduce a global flag which we set when starting to kldunload the module, in order to prevent new V_ip_mrouter sockets to become attached. All of this is completely untested. Affected files ... .. //depot/projects/vimage/src/sys/netinet/ip_mroute.c#34 edit Differences ... ==== //depot/projects/vimage/src/sys/netinet/ip_mroute.c#34 (text+ko) ==== @@ -142,6 +142,9 @@ mtx_init(&mrouter_mtx, "IPv4 multicast forwarding", NULL, MTX_DEF) #define MROUTER_LOCK_DESTROY() mtx_destroy(&mrouter_mtx) +static int ip_mrouter_cnt; /* # of vnets with active mrouters */ +static int ip_mrouter_unloading; /* Allow no more V_ip_mrouter sockets */ + static VNET_DEFINE(struct mrtstat, mrtstat); #define V_mrtstat VNET(mrtstat) SYSCTL_VNET_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW, @@ -673,6 +676,11 @@ MROUTER_LOCK(); + if (ip_mrouter_unloading) { + MROUTER_UNLOCK(); + return ENOPROTOOPT; + } + if (V_ip_mrouter != NULL) { MROUTER_UNLOCK(); return EADDRINUSE; @@ -694,6 +702,7 @@ callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, curvnet); V_ip_mrouter = so; + ip_mrouter_cnt++; MROUTER_UNLOCK(); @@ -724,6 +733,7 @@ * Detach/disable hooks to the reset of the system. */ V_ip_mrouter = NULL; + ip_mrouter_cnt--; mrt_api_config = 0; VIF_LOCK(); @@ -2890,8 +2900,13 @@ * just loaded and then unloaded w/o starting up a user * process we still need to cleanup. */ - if (V_ip_mrouter != NULL) + MROUTER_LOCK(); + if (ip_mrouter_cnt != 0) { + MROUTER_UNLOCK(); return (EINVAL); + } + ip_mrouter_unloading = 1; + MROUTER_UNLOCK(); if (pim_encap_cookie) { encap_detach(pim_encap_cookie);