Date: Tue, 9 Mar 2004 12:31:44 -0800 (PST) From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 48518 for review Message-ID: <200403092031.i29KViL7002955@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/cdefs.h> -__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 <sys/ctype.h> #include <sys/param.h> #include <sys/systm.h> -#include <sys/sockio.h> -#include <sys/mbuf.h> -#include <sys/malloc.h> #include <sys/kernel.h> #include <sys/socket.h> #include <sys/queue.h> @@ -46,24 +43,15 @@ #include <net/if.h> #include <net/if_arp.h> -#include <net/ethernet.h> -#include <net/if_dl.h> #include <net/if_media.h> -#include <net/bpf.h> - -#include <machine/bus_memio.h> -#include <machine/bus_pio.h> #include <machine/bus.h> #include <machine/resource.h> #include <sys/bus.h> #include <sys/rman.h> #include <net80211/ieee80211_var.h> -#include <net80211/ieee80211_ioctl.h> -#include <dev/wi/if_wavelan_ieee.h> - #include <compat/ndis/pe_var.h> #include <compat/ndis/resource_var.h> #include <compat/ndis/ntoskrnl_var.h> @@ -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 <sys/cdefs.h> -__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 <sys/param.h> #include <sys/systm.h> -#include <sys/sockio.h> -#include <sys/mbuf.h> -#include <sys/malloc.h> #include <sys/kernel.h> #include <sys/socket.h> #include <sys/queue.h> @@ -45,23 +42,14 @@ #include <net/if.h> #include <net/if_arp.h> -#include <net/ethernet.h> -#include <net/if_dl.h> #include <net/if_media.h> -#include <net/bpf.h> - -#include <machine/bus_memio.h> -#include <machine/bus_pio.h> #include <machine/bus.h> #include <machine/resource.h> #include <sys/bus.h> #include <sys/rman.h> #include <net80211/ieee80211_var.h> -#include <net80211/ieee80211_ioctl.h> - -#include <dev/wi/if_wavelan_ieee.h> #include <dev/pci/pcireg.h> #include <dev/pci/pcivar.h> ==== //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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200403092031.i29KViL7002955>