From owner-p4-projects@FreeBSD.ORG Tue Mar 9 12:31:45 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id ADE9316A4D0; Tue, 9 Mar 2004 12:31:45 -0800 (PST) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 866DC16A4CF for ; Tue, 9 Mar 2004 12:31:45 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 76D3143D2D for ; Tue, 9 Mar 2004 12:31:45 -0800 (PST) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.10/8.12.10) with ESMTP id i29KVjGe002964 for ; Tue, 9 Mar 2004 12:31:45 -0800 (PST) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.10/8.12.10/Submit) id i29KViL7002955 for perforce@freebsd.org; Tue, 9 Mar 2004 12:31:44 -0800 (PST) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Tue, 9 Mar 2004 12:31:44 -0800 (PST) Message-Id: <200403092031.i29KViL7002955@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Subject: PERFORCE change 48518 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Mar 2004 20:31:46 -0000 http://perforce.freebsd.org/chv.cgi?CH=48518 Change 48518 by rwatson@rwatson_paprika on 2004/03/09 12:31:40 Loop back locking of global variables for if_faith, if_stf. Merg NDIS cleanup. Affected files ... .. //depot/projects/netperf_socket/sys/dev/if_ndis/if_ndis_pccard.c#2 integrate .. //depot/projects/netperf_socket/sys/dev/if_ndis/if_ndis_pci.c#3 integrate .. //depot/projects/netperf_socket/sys/net/if_faith.c#2 integrate .. //depot/projects/netperf_socket/sys/net/if_stf.c#3 integrate Differences ... ==== //depot/projects/netperf_socket/sys/dev/if_ndis/if_ndis_pccard.c#2 (text+ko) ==== @@ -31,14 +31,11 @@ */ #include -__FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis_pccard.c,v 1.1 2004/03/07 02:49:06 wpaul Exp $"); +__FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis_pccard.c,v 1.2 2004/03/09 20:29:21 wpaul Exp $"); #include #include #include -#include -#include -#include #include #include #include @@ -46,24 +43,15 @@ #include #include -#include -#include #include -#include - -#include -#include #include #include #include #include #include -#include -#include - #include #include #include @@ -200,8 +188,6 @@ struct ndis_pccard_type *t; int devidx = 0; const char *prodstr, *vendstr; - struct resource_list *rl; - struct resource_list_entry *rle; sc = device_get_softc(dev); unit = device_get_unit(dev); ==== //depot/projects/netperf_socket/sys/dev/if_ndis/if_ndis_pci.c#3 (text+ko) ==== @@ -31,13 +31,10 @@ */ #include -__FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis_pci.c,v 1.2 2004/03/09 18:39:40 wpaul Exp $"); +__FBSDID("$FreeBSD: src/sys/dev/if_ndis/if_ndis_pci.c,v 1.3 2004/03/09 20:29:21 wpaul Exp $"); #include #include -#include -#include -#include #include #include #include @@ -45,23 +42,14 @@ #include #include -#include -#include #include -#include - -#include -#include #include #include #include #include #include -#include - -#include #include #include ==== //depot/projects/netperf_socket/sys/net/if_faith.c#2 (text+ko) ==== @@ -32,7 +32,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/net/if_faith.c,v 1.25 2003/12/28 03:55:59 sam Exp $ + * $FreeBSD: src/sys/net/if_faith.c,v 1.26 2004/03/09 19:23:06 rwatson Exp $ */ /* * derived from @@ -99,11 +99,13 @@ static int faithmodevent(module_t, int, void *); +static struct mtx faith_mtx; static MALLOC_DEFINE(M_FAITH, FAITHNAME, "Firewall Assisted Tunnel Interface"); static LIST_HEAD(, faith_softc) faith_softc_list; int faith_clone_create(struct if_clone *, int); void faith_clone_destroy(struct ifnet *); +static void faith_destroy(struct faith_softc *); struct if_clone faith_cloner = IF_CLONE_INITIALIZER(FAITHNAME, faith_clone_create, faith_clone_destroy, 0, IF_MAXUNIT); @@ -116,9 +118,11 @@ int type; void *data; { + struct faith_softc *sc; switch (type) { case MOD_LOAD: + mtx_init(&faith_mtx, "faith_mtx", NULL, MTX_DEF); LIST_INIT(&faith_softc_list); if_clone_attach(&faith_cloner); @@ -134,10 +138,15 @@ if_clone_detach(&faith_cloner); - while (!LIST_EMPTY(&faith_softc_list)) - faith_clone_destroy( - &LIST_FIRST(&faith_softc_list)->sc_if); - + mtx_lock(&faith_mtx); + while ((sc = LIST_FIRST(&faith_softc_list)) != NULL) { + LIST_REMOVE(sc, sc_list); + mtx_unlock(&faith_mtx); + faith_destroy(sc); + mtx_lock(&faith_mtx); + } + mtx_unlock(&faith_mtx); + mtx_destroy(&faith_mtx); break; } return 0; @@ -176,21 +185,32 @@ sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen; if_attach(&sc->sc_if); bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int)); + mtx_lock(&faith_mtx); LIST_INSERT_HEAD(&faith_softc_list, sc, sc_list); + mtx_unlock(&faith_mtx); return (0); } +static void +faith_destroy(struct faith_softc *sc) +{ + + bpfdetach(&sc->sc_if); + if_detach(&sc->sc_if); + free(sc, M_FAITH); +} + void faith_clone_destroy(ifp) struct ifnet *ifp; { struct faith_softc *sc = (void *) ifp; + mtx_lock(&faith_mtx); LIST_REMOVE(sc, sc_list); - bpfdetach(ifp); - if_detach(ifp); + mtx_unlock(&faith_mtx); - free(sc, M_FAITH); + faith_destroy(sc); } int ==== //depot/projects/netperf_socket/sys/net/if_stf.c#3 (text+ko) ==== @@ -1,4 +1,4 @@ -/* $FreeBSD: src/sys/net/if_stf.c,v 1.36 2004/03/07 05:15:42 rwatson Exp $ */ +/* $FreeBSD: src/sys/net/if_stf.c,v 1.37 2004/03/09 20:29:19 rwatson Exp $ */ /* $KAME: if_stf.c,v 1.73 2001/12/03 11:08:30 keiichi Exp $ */ /* @@ -138,6 +138,13 @@ LIST_ENTRY(stf_softc) sc_list; /* all stf's are linked */ }; +/* + * All mutable global variables in if_stf.c are protected by stf_mtx. + * XXXRW: Note that mutable fields in the softc are not currently locked: + * in particular, sc_ro needs to be protected from concurrent entrance + * of stf_output(). + */ +static struct mtx stf_mtx; static LIST_HEAD(, stf_softc) stf_softc_list; static MALLOC_DEFINE(M_STF, STFNAME, "6to4 Tunnel Interface"); @@ -197,24 +204,36 @@ sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN; if_attach(&sc->sc_if); bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int)); + mtx_lock(&stf_mtx); LIST_INSERT_HEAD(&stf_softc_list, sc, sc_list); + mtx_unlock(&stf_mtx); return (0); } +static void +stf_destroy(struct stf_softc *sc) +{ + int err; + + err = encap_detach(sc->encap_cookie); + KASSERT(err == 0, ("Unexpected error detaching encap_cookie")); + bpfdetach(&sc->sc_if); + if_detach(&sc->sc_if); + + free(sc, M_STF); +} + void stf_clone_destroy(ifp) struct ifnet *ifp; { - int err; struct stf_softc *sc = (void *) ifp; + mtx_lock(&stf_mtx); LIST_REMOVE(sc, sc_list); - err = encap_detach(sc->encap_cookie); - KASSERT(err == 0, ("Unexpected error detaching encap_cookie")); - bpfdetach(ifp); - if_detach(ifp); + mtx_unlock(&stf_mtx); - free(sc, M_STF); + stf_destroy(sc); } static int @@ -223,9 +242,11 @@ int type; void *data; { + struct stf_softc *sc; switch (type) { case MOD_LOAD: + mtx_init(&stf_mtx, "stf_mtx", NULL, MTX_DEF); LIST_INIT(&stf_softc_list); if_clone_attach(&stf_cloner); @@ -233,8 +254,15 @@ case MOD_UNLOAD: if_clone_detach(&stf_cloner); - while (!LIST_EMPTY(&stf_softc_list)) - stf_clone_destroy(&LIST_FIRST(&stf_softc_list)->sc_if); + mtx_lock(&stf_mtx); + while ((sc = LIST_FIRST(&stf_softc_list)) != NULL) { + LIST_REMOVE(sc, sc_list); + mtx_unlock(&stf_mtx); + stf_destroy(sc); + mtx_lock(&stf_mtx); + } + mtx_unlock(&stf_mtx); + mtx_destroy(&stf_mtx); break; } @@ -467,6 +495,9 @@ else ip_ecn_ingress(ECN_NOCARE, &ip->ip_tos, &tos); + /* + * XXXRW: Locking of sc_ro required. + */ dst4 = (struct sockaddr_in *)&sc->sc_ro.ro_dst; if (dst4->sin_family != AF_INET || bcmp(&dst4->sin_addr, &ip->ip_dst, sizeof(ip->ip_dst)) != 0) {