Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Ensure to not turn on IFF_RUNNING of an interface until ...



details:   https://anonhg.NetBSD.org/src/rev/d3e9884787c1
branches:  trunk
changeset: 357963:d3e9884787c1
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Dec 06 07:40:16 2017 +0000

description:
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.)

diffstat:

 sys/net/agr/if_agr.c    |   8 ++++----
 sys/net/if_bridge.c     |  16 ++++++----------
 sys/net/if_etherip.c    |  10 +++++-----
 sys/net/if_faith.c      |   6 +++---
 sys/net/if_loop.c       |  10 +++++++---
 sys/net/if_tun.c        |   7 +++----
 sys/net/if_vlan.c       |  10 ++++++----
 sys/netcan/if_canloop.c |   9 ++++++---
 8 files changed, 40 insertions(+), 36 deletions(-)

diffs (truncated from 339 to 300 lines):

diff -r cbedb82b7c32 -r d3e9884787c1 sys/net/agr/if_agr.c
--- a/sys/net/agr/if_agr.c      Wed Dec 06 05:59:59 2017 +0000
+++ b/sys/net/agr/if_agr.c      Wed Dec 06 07:40:16 2017 +0000
@@ -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 @@
                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 @@
        if (error && port) {
                free(port, M_DEVBUF);
        }
+       if (error == 0)
+               ifp->if_flags |= IFF_RUNNING;
        return error;
 
 cleanup:
diff -r cbedb82b7c32 -r d3e9884787c1 sys/net/if_bridge.c
--- a/sys/net/if_bridge.c       Wed Dec 06 05:59:59 2017 +0000
+++ b/sys/net/if_bridge.c       Wed Dec 06 07:40:16 2017 +0000
@@ -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 @@
 {
        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 @@
 {
        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;
 }
 
 /*
diff -r cbedb82b7c32 -r d3e9884787c1 sys/net/if_etherip.c
--- a/sys/net/if_etherip.c      Wed Dec 06 05:59:59 2017 +0000
+++ b/sys/net/if_etherip.c      Wed Dec 06 07:40:16 2017 +0000
@@ -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 <rosenfeld%grumpf.hope-2000.org@localhost>
@@ -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 @@
        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 @@
 
        s = splsoftnet();
 
+       ifp->if_flags &= ~IFF_RUNNING;
+
        if (sc->sc_si) {
                softint_disestablish(sc->sc_si);
                sc->sc_si = NULL;
@@ -583,7 +584,6 @@
                sc->sc_dst = NULL;
        }
 
-       ifp->if_flags &= ~IFF_RUNNING;
        splx(s);
 }
 
diff -r cbedb82b7c32 -r d3e9884787c1 sys/net/if_faith.c
--- a/sys/net/if_faith.c        Wed Dec 06 05:59:59 2017 +0000
+++ b/sys/net/if_faith.c        Wed Dec 06 07:40:16 2017 +0000
@@ -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 @@
        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.
                 */
diff -r cbedb82b7c32 -r d3e9884787c1 sys/net/if_loop.c
--- a/sys/net/if_loop.c Wed Dec 06 05:59:59 2017 +0000
+++ b/sys/net/if_loop.c Wed Dec 06 07:40:16 2017 +0000
@@ -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 @@
        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 @@
        MOWNER_ATTACH(ifp->if_mowner);
 #endif
 
+       ifp->if_flags |= IFF_RUNNING;
+
        return (0);
 }
 
@@ -221,6 +223,8 @@
        if (ifp == lo0ifp)
                return (EPERM);
 
+       ifp->if_flags &= ~IFF_RUNNING;
+
 #ifdef MBUFTRACE
        MOWNER_DETACH(ifp->if_mowner);
        free(ifp->if_mowner, M_DEVBUF);
diff -r cbedb82b7c32 -r d3e9884787c1 sys/net/if_tun.c
--- a/sys/net/if_tun.c  Wed Dec 06 05:59:59 2017 +0000
+++ b/sys/net/if_tun.c  Wed Dec 06 07:40:16 2017 +0000
@@ -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 <jpo%cs.nott.ac.uk@localhost>
@@ -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 @@
        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 @@
        default:
                break;
        }
+       ifp->if_flags |= IFF_UP | IFF_RUNNING;
        mutex_exit(&tp->tun_lock);
 }
 
diff -r cbedb82b7c32 -r d3e9884787c1 sys/net/if_vlan.c
--- a/sys/net/if_vlan.c Wed Dec 06 05:59:59 2017 +0000
+++ b/sys/net/if_vlan.c Wed Dec 06 07:40:16 2017 +0000
@@ -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 @@
        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 @@
        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 @@
                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:
diff -r cbedb82b7c32 -r d3e9884787c1 sys/netcan/if_canloop.c
--- a/sys/netcan/if_canloop.c   Wed Dec 06 05:59:59 2017 +0000
+++ b/sys/netcan/if_canloop.c   Wed Dec 06 07:40:16 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_canloop.c,v 1.3 2017/11/16 03:07:18 ozaki-r Exp $   */



Home | Main Index | Thread Index | Old Index