Source-Changes-HG archive

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

[src/trunk]: src/sys/net vlan: match the interface link state with that of th...



details:   https://anonhg.NetBSD.org/src/rev/9c1f8ad32bb9
branches:  trunk
changeset: 976548:9c1f8ad32bb9
user:      roy <roy%NetBSD.org@localhost>
date:      Sat Sep 26 18:38:09 2020 +0000

description:
vlan: match the interface link state with that of the parent

Now addresses on a vlan will detach and undergo duplicate address
dectection on link state changes just as on a standard interface.

diffstat:

 sys/net/if_ethersubr.c |  16 ++++++++++++++--
 sys/net/if_vlan.c      |  49 +++++++++++++++++++++++++++++++++++++++++++++----
 sys/net/if_vlanvar.h   |   3 ++-
 3 files changed, 61 insertions(+), 7 deletions(-)

diffs (153 lines):

diff -r 209568cba61c -r 9c1f8ad32bb9 sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Sat Sep 26 18:35:12 2020 +0000
+++ b/sys/net/if_ethersubr.c    Sat Sep 26 18:38:09 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.288 2020/08/28 06:27:49 ozaki-r Exp $       */
+/*     $NetBSD: if_ethersubr.c,v 1.289 2020/09/26 18:38:09 roy Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.288 2020/08/28 06:27:49 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.289 2020/09/26 18:38:09 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -979,6 +979,17 @@
        return buf;
 }
 
+static void
+ether_link_state_changed(struct ifnet *ifp, int link_state)
+{
+#if NVLAN > 0
+       struct ethercom *ec = (void *)ifp;
+
+       if (ec->ec_nvlans)
+               vlan_link_state_changed(ifp, link_state);
+#endif
+}
+
 /*
  * Perform common duties while attaching to interface list
  */
@@ -993,6 +1004,7 @@
        ifp->if_mtu = ETHERMTU;
        ifp->if_output = ether_output;
        ifp->_if_input = ether_input;
+       ifp->if_link_state_changed = ether_link_state_changed;
        if (ifp->if_baudrate == 0)
                ifp->if_baudrate = IF_Mbps(10);         /* just a default */
 
diff -r 209568cba61c -r 9c1f8ad32bb9 sys/net/if_vlan.c
--- a/sys/net/if_vlan.c Sat Sep 26 18:35:12 2020 +0000
+++ b/sys/net/if_vlan.c Sat Sep 26 18:38:09 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vlan.c,v 1.152 2020/06/12 11:04:45 roy Exp $        */
+/*     $NetBSD: if_vlan.c,v 1.153 2020/09/26 18:38:09 roy 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.152 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.153 2020/09/26 18:38:09 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -355,9 +355,8 @@
        if_initname(ifp, ifc->ifc_name, unit);
        ifp->if_softc = ifv;
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
-       ifp->if_extflags = IFEF_NO_LINK_STATE_CHANGE;
 #ifdef NET_MPSAFE
-       ifp->if_extflags |= IFEF_MPSAFE;
+       ifp->if_extflags = IFEF_MPSAFE;
 #endif
        ifp->if_start = vlan_start;
        ifp->if_transmit = vlan_transmit;
@@ -371,6 +370,13 @@
                goto fail;
        }
 
+       /*
+        * Set the link state to down.
+        * When the parent interface attaches we will use that link state.
+        * When the parent interface link state changes, so will ours.
+        */
+       ifp->if_link_state = LINK_STATE_DOWN;
+
        vlan_reset_linkname(ifp);
        if_register(ifp);
        return 0;
@@ -562,6 +568,12 @@
        nmib_psref = NULL;
        omib_cleanup = true;
 
+
+       /*
+        * We inherit the parents link state.
+        */
+       if_link_state_change(&ifv->ifv_if, p->if_link_state);
+
 done:
        mutex_exit(&ifv->ifv_lock);
 
@@ -1669,6 +1681,35 @@
 }
 
 /*
+ * If the parent link state changed, the vlan link state should change also.
+ */
+void
+vlan_link_state_changed(struct ifnet *p, int link_state)
+{
+       struct ifvlan *ifv;
+       struct ifvlan_linkmib *mib;
+       struct psref psref;
+       struct ifnet *ifp;
+
+       mutex_enter(&ifv_list.lock);
+
+       LIST_FOREACH(ifv, &ifv_list.list, ifv_list) {
+               mib = vlan_getref_linkmib(ifv, &psref);
+               if (mib == NULL)
+                       continue;
+
+               if (mib->ifvm_p == p) {
+                       ifp = &mib->ifvm_ifvlan->ifv_if;
+                       if_link_state_change(ifp, link_state);
+               }
+
+               vlan_putref_linkmib(mib, &psref);
+       }
+
+       mutex_exit(&ifv_list.lock);
+}
+
+/*
  * Module infrastructure
  */
 #include "if_module.h"
diff -r 209568cba61c -r 9c1f8ad32bb9 sys/net/if_vlanvar.h
--- a/sys/net/if_vlanvar.h      Sat Sep 26 18:35:12 2020 +0000
+++ b/sys/net/if_vlanvar.h      Sat Sep 26 18:38:09 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vlanvar.h,v 1.13 2018/01/15 16:36:51 maxv Exp $     */
+/*     $NetBSD: if_vlanvar.h,v 1.14 2020/09/26 18:38:09 roy Exp $      */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -83,6 +83,7 @@
 #ifdef _KERNEL
 void   vlan_input(struct ifnet *, struct mbuf *);
 void   vlan_ifdetach(struct ifnet *);
+void   vlan_link_state_changed(struct ifnet *, int);
 
 /*
  * Locking notes:



Home | Main Index | Thread Index | Old Index