Module Name:    src
Committed By:   ozaki-r
Date:           Wed Dec  6 07:40:16 UTC 2017

Modified Files:
        src/sys/net: if_bridge.c if_etherip.c if_faith.c if_loop.c if_tun.c
            if_vlan.c
        src/sys/net/agr: if_agr.c
        src/sys/netcan: if_canloop.c

Log Message:
Ensure to not turn on IFF_RUNNING of an interface until its initialization 
completes

And ensure to turn off it before destruction as per IFF_RUNNING's description
"resource allocated". (The description is a bit doubtful though, I believe the
change is still proper.)


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/sys/net/if_bridge.c
cvs rdiff -u -r1.39 -r1.40 src/sys/net/if_etherip.c
cvs rdiff -u -r1.56 -r1.57 src/sys/net/if_faith.c
cvs rdiff -u -r1.99 -r1.100 src/sys/net/if_loop.c
cvs rdiff -u -r1.141 -r1.142 src/sys/net/if_tun.c
cvs rdiff -u -r1.115 -r1.116 src/sys/net/if_vlan.c
cvs rdiff -u -r1.42 -r1.43 src/sys/net/agr/if_agr.c
cvs rdiff -u -r1.3 -r1.4 src/sys/netcan/if_canloop.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/if_bridge.c
diff -u src/sys/net/if_bridge.c:1.142 src/sys/net/if_bridge.c:1.143
--- src/sys/net/if_bridge.c:1.142	Wed Dec  6 05:11:10 2017
+++ src/sys/net/if_bridge.c	Wed Dec  6 07:40:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridge.c,v 1.142 2017/12/06 05:11:10 ozaki-r Exp $	*/
+/*	$NetBSD: if_bridge.c,v 1.143 2017/12/06 07:40:16 ozaki-r Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.142 2017/12/06 05:11:10 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.143 2017/12/06 07:40:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bridge_ipf.h"
@@ -1328,14 +1328,13 @@ bridge_init(struct ifnet *ifp)
 {
 	struct bridge_softc *sc = ifp->if_softc;
 
-	if (ifp->if_flags & IFF_RUNNING)
-		return 0;
+	KASSERT((ifp->if_flags & IFF_RUNNING) == 0);
 
 	callout_reset(&sc->sc_brcallout, bridge_rtable_prune_period * hz,
 	    bridge_timer, sc);
+	bstp_initialization(sc);
 
 	ifp->if_flags |= IFF_RUNNING;
-	bstp_initialization(sc);
 	return 0;
 }
 
@@ -1349,15 +1348,12 @@ bridge_stop(struct ifnet *ifp, int disab
 {
 	struct bridge_softc *sc = ifp->if_softc;
 
-	if ((ifp->if_flags & IFF_RUNNING) == 0)
-		return;
+	KASSERT((ifp->if_flags & IFF_RUNNING) != 0);
+	ifp->if_flags &= ~IFF_RUNNING;
 
 	callout_stop(&sc->sc_brcallout);
 	bstp_stop(sc);
-
 	bridge_rtflush(sc, IFBF_FLUSHDYN);
-
-	ifp->if_flags &= ~IFF_RUNNING;
 }
 
 /*

Index: src/sys/net/if_etherip.c
diff -u src/sys/net/if_etherip.c:1.39 src/sys/net/if_etherip.c:1.40
--- src/sys/net/if_etherip.c:1.39	Mon Oct 23 09:31:18 2017
+++ src/sys/net/if_etherip.c	Wed Dec  6 07:40:16 2017
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_etherip.c,v 1.39 2017/10/23 09:31:18 msaitoh Exp $        */
+/*      $NetBSD: if_etherip.c,v 1.40 2017/12/06 07:40:16 ozaki-r Exp $        */
 
 /*
  *  Copyright (c) 2006, Hans Rosenfeld <rosenf...@grumpf.hope-2000.org>
@@ -86,7 +86,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_etherip.c,v 1.39 2017/10/23 09:31:18 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_etherip.c,v 1.40 2017/12/06 07:40:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -549,12 +549,11 @@ etherip_set_tunnel(struct ifnet *ifp,
 	if (odst)
 		sockaddr_free(odst);
 
-	ifp->if_flags |= IFF_RUNNING;
-
 	sc->sc_si = softint_establish(SOFTINT_NET, etheripintr, sc);
 	if (sc->sc_si == NULL)
 		error = ENOMEM;
 
+	ifp->if_flags |= IFF_RUNNING;
 out:
 	splx(s);
 
@@ -569,6 +568,8 @@ etherip_delete_tunnel(struct ifnet *ifp)
 
 	s = splsoftnet();
 
+	ifp->if_flags &= ~IFF_RUNNING;
+
 	if (sc->sc_si) {
 		softint_disestablish(sc->sc_si);
 		sc->sc_si = NULL;
@@ -583,7 +584,6 @@ etherip_delete_tunnel(struct ifnet *ifp)
 		sc->sc_dst = NULL;
 	}
 
-	ifp->if_flags &= ~IFF_RUNNING;
 	splx(s);
 }
 

Index: src/sys/net/if_faith.c
diff -u src/sys/net/if_faith.c:1.56 src/sys/net/if_faith.c:1.57
--- src/sys/net/if_faith.c:1.56	Mon Oct 23 09:32:00 2017
+++ src/sys/net/if_faith.c	Wed Dec  6 07:40:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_faith.c,v 1.56 2017/10/23 09:32:00 msaitoh Exp $	*/
+/*	$NetBSD: if_faith.c,v 1.57 2017/12/06 07:40:16 ozaki-r Exp $	*/
 /*	$KAME: if_faith.c,v 1.21 2001/02/20 07:59:26 itojun Exp $	*/
 
 /*
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.56 2017/10/23 09:32:00 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.57 2017/12/06 07:40:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -263,9 +263,9 @@ faithioctl(struct ifnet *ifp, u_long cmd
 	switch (cmd) {
 
 	case SIOCINITIFADDR:
-		ifp->if_flags |= IFF_UP | IFF_RUNNING;
 		ifa = (struct ifaddr *)data;
 		ifa->ifa_rtrequest = faithrtrequest;
+		ifp->if_flags |= IFF_UP | IFF_RUNNING;
 		/*
 		 * Everything else is done at a higher level.
 		 */

Index: src/sys/net/if_loop.c
diff -u src/sys/net/if_loop.c:1.99 src/sys/net/if_loop.c:1.100
--- src/sys/net/if_loop.c:1.99	Fri Nov 17 07:37:12 2017
+++ src/sys/net/if_loop.c	Wed Dec  6 07:40:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_loop.c,v 1.99 2017/11/17 07:37:12 ozaki-r Exp $	*/
+/*	$NetBSD: if_loop.c,v 1.100 2017/12/06 07:40:16 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.99 2017/11/17 07:37:12 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.100 2017/12/06 07:40:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -182,7 +182,7 @@ loop_clone_create(struct if_clone *ifc, 
 	if_initname(ifp, ifc->ifc_name, unit);
 
 	ifp->if_mtu = LOMTU;
-	ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST | IFF_RUNNING;
+	ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST;
 	ifp->if_extflags = IFEF_MPSAFE;
 	ifp->if_ioctl = loioctl;
 	ifp->if_output = looutput;
@@ -211,6 +211,8 @@ loop_clone_create(struct if_clone *ifc, 
 	MOWNER_ATTACH(ifp->if_mowner);
 #endif
 
+	ifp->if_flags |= IFF_RUNNING;
+
 	return (0);
 }
 
@@ -221,6 +223,8 @@ loop_clone_destroy(struct ifnet *ifp)
 	if (ifp == lo0ifp)
 		return (EPERM);
 
+	ifp->if_flags &= ~IFF_RUNNING;
+
 #ifdef MBUFTRACE
 	MOWNER_DETACH(ifp->if_mowner);
 	free(ifp->if_mowner, M_DEVBUF);

Index: src/sys/net/if_tun.c
diff -u src/sys/net/if_tun.c:1.141 src/sys/net/if_tun.c:1.142
--- src/sys/net/if_tun.c:1.141	Mon Oct 30 16:01:19 2017
+++ src/sys/net/if_tun.c	Wed Dec  6 07:40:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tun.c,v 1.141 2017/10/30 16:01:19 ozaki-r Exp $	*/
+/*	$NetBSD: if_tun.c,v 1.142 2017/12/06 07:40:16 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1988, Julian Onions <j...@cs.nott.ac.uk>
@@ -19,7 +19,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.141 2017/10/30 16:01:19 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.142 2017/12/06 07:40:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -421,8 +421,6 @@ tun_enable(struct tun_softc *tp, const s
 	TUNDEBUG("%s: %s\n", __func__, ifp->if_xname);
 
 	mutex_enter(&tp->tun_lock);
-	ifp->if_flags |= IFF_UP | IFF_RUNNING;
-
 	tp->tun_flags &= ~(TUN_IASET|TUN_DSTADDR);
 
 	switch (ifa->ifa_addr->sa_family) {
@@ -462,6 +460,7 @@ tun_enable(struct tun_softc *tp, const s
 	default:
 		break;
 	}
+	ifp->if_flags |= IFF_UP | IFF_RUNNING;
 	mutex_exit(&tp->tun_lock);
 }
 

Index: src/sys/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.115 src/sys/net/if_vlan.c:1.116
--- src/sys/net/if_vlan.c:1.115	Wed Dec  6 05:59:59 2017
+++ src/sys/net/if_vlan.c	Wed Dec  6 07:40:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.115 2017/12/06 05:59:59 ozaki-r Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.116 2017/12/06 07:40:16 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.115 2017/12/06 05:59:59 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.116 2017/12/06 07:40:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -584,6 +584,8 @@ vlan_unconfig_locked(struct ifvlan *ifv,
 	KASSERT(mutex_owned(ifp->if_ioctl_lock));
 	KASSERT(mutex_owned(&ifv->ifv_lock));
 
+	ifp->if_flags &= ~(IFF_UP|IFF_RUNNING);
+
 	omib = ifv->ifv_mib;
 	p = omib->ifvm_p;
 
@@ -652,7 +654,6 @@ vlan_unconfig_locked(struct ifvlan *ifv,
 	if ((ifp->if_flags & IFF_PROMISC) != 0)
 		vlan_safe_ifpromisc_locked(ifp, 0);
 	if_down(ifp);
-	ifp->if_flags &= ~(IFF_UP|IFF_RUNNING);
 	ifp->if_capabilities = 0;
 	mutex_enter(&ifv->ifv_lock);
 done:
@@ -974,10 +975,11 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd
 		if (error != 0) {
 			break;
 		}
-		ifp->if_flags |= IFF_RUNNING;
 
 		/* Update promiscuous mode, if necessary. */
 		vlan_set_promisc(ifp);
+
+		ifp->if_flags |= IFF_RUNNING;
 		break;
 
 	case SIOCGETVLAN:

Index: src/sys/net/agr/if_agr.c
diff -u src/sys/net/agr/if_agr.c:1.42 src/sys/net/agr/if_agr.c:1.43
--- src/sys/net/agr/if_agr.c:1.42	Wed Dec  6 04:37:00 2017
+++ src/sys/net/agr/if_agr.c	Wed Dec  6 07:40:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agr.c,v 1.42 2017/12/06 04:37:00 ozaki-r Exp $	*/
+/*	$NetBSD: if_agr.c,v 1.43 2017/12/06 07:40:16 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.42 2017/12/06 04:37:00 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.43 2017/12/06 07:40:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -648,8 +648,6 @@ agr_addport(struct ifnet *ifp, struct if
 		goto cleanup;
 	}
 
-	ifp->if_flags |= IFF_RUNNING;
-
 	agrport_config_promisc(port, (ifp->if_flags & IFF_PROMISC) != 0);
 	error = (*sc->sc_iftop->iftop_configmulti_port)(sc, port, true);
 	if (error) {
@@ -664,6 +662,8 @@ out:
 	if (error && port) {
 		free(port, M_DEVBUF);
 	}
+	if (error == 0)
+		ifp->if_flags |= IFF_RUNNING;
 	return error;
 
 cleanup:

Index: src/sys/netcan/if_canloop.c
diff -u src/sys/netcan/if_canloop.c:1.3 src/sys/netcan/if_canloop.c:1.4
--- src/sys/netcan/if_canloop.c:1.3	Thu Nov 16 03:07:18 2017
+++ src/sys/netcan/if_canloop.c	Wed Dec  6 07:40:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_canloop.c,v 1.3 2017/11/16 03:07:18 ozaki-r Exp $	*/
+/*	$NetBSD: if_canloop.c,v 1.4 2017/12/06 07:40:16 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_canloop.c,v 1.3 2017/11/16 03:07:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_canloop.c,v 1.4 2017/12/06 07:40:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_can.h"
@@ -111,7 +111,7 @@ canloop_clone_create(struct if_clone *if
 
 	if_initname(ifp, ifc->ifc_name, unit);
 
-	ifp->if_flags = IFF_LOOPBACK | IFF_RUNNING;
+	ifp->if_flags = IFF_LOOPBACK;
 	ifp->if_extflags = IFEF_MPSAFE;
 	ifp->if_ioctl = canloop_ioctl;
 	ifp->if_start = canloop_ifstart;
@@ -124,6 +124,7 @@ canloop_clone_create(struct if_clone *if
 	MOWNER_ATTACH(ifp->if_mowner);
 #endif
 	canloop_count++;
+	ifp->if_flags |= IFF_RUNNING;
 
 	return (0);
 }
@@ -132,6 +133,8 @@ static int
 canloop_clone_destroy(struct ifnet *ifp)
 {
 
+	ifp->if_flags &= ~IFF_RUNNING;
+
 #ifdef MBUFTRACE
 	MOWNER_DETACH(ifp->if_mowner);
 	free(ifp->if_mowner, M_DEVBUF);

Reply via email to