Source-Changes-HG archive

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

[src/trunk]: src/sys vlan: Register the callback to update link-state of vlan...



details:   https://anonhg.NetBSD.org/src/rev/5ba75b5b463e
branches:  trunk
changeset: 1023871:5ba75b5b463e
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Thu Sep 30 03:47:27 2021 +0000

description:
vlan: Register the callback to update link-state of vlan I/F
to link-state change hook

The callback is registered in every vlan I/F even if the parent
interface is the same. Therefore it is not needed to search the
vlan I/F by the parent interface unlike the previous callback.

diffstat:

 sys/net/if_ethersubr.c              |   9 +------
 sys/net/if_vlan.c                   |  41 +++++++++++++++++++-----------------
 sys/net/if_vlanvar.h                |   3 +-
 sys/rump/librump/rumpnet/net_stub.c |   5 +--
 4 files changed, 27 insertions(+), 31 deletions(-)

diffs (175 lines):

diff -r c82ae03c4e2f -r 5ba75b5b463e sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Thu Sep 30 03:43:25 2021 +0000
+++ b/sys/net/if_ethersubr.c    Thu Sep 30 03:47:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ethersubr.c,v 1.294 2021/09/30 03:15:25 yamaguchi Exp $     */
+/*     $NetBSD: if_ethersubr.c,v 1.295 2021/09/30 03:47:27 yamaguchi 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.294 2021/09/30 03:15:25 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.295 2021/09/30 03:47:27 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1008,12 +1008,7 @@
 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
 }
 
 /*
diff -r c82ae03c4e2f -r 5ba75b5b463e sys/net/if_vlan.c
--- a/sys/net/if_vlan.c Thu Sep 30 03:43:25 2021 +0000
+++ b/sys/net/if_vlan.c Thu Sep 30 03:47:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vlan.c,v 1.161 2021/07/17 15:37:04 hannken Exp $    */
+/*     $NetBSD: if_vlan.c,v 1.162 2021/09/30 03:47:27 yamaguchi 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.161 2021/07/17 15:37:04 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.162 2021/09/30 03:47:27 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -156,6 +156,7 @@
                                         */
        kmutex_t ifv_lock;              /* writer lock for ifv_mib */
        pserialize_t ifv_psz;
+       void *ifv_linkstate_hook;
 
        LIST_HEAD(__vlan_mchead, vlan_mc_entry) ifv_mc_listhead;
        LIST_ENTRY(ifvlan) ifv_list;
@@ -195,6 +196,7 @@
 static int     vlan_ioctl(struct ifnet *, u_long, void *);
 static void    vlan_start(struct ifnet *);
 static int     vlan_transmit(struct ifnet *, struct mbuf *);
+static void    vlan_link_state_changed(void *);
 static void    vlan_unconfig(struct ifnet *);
 static int     vlan_unconfig_locked(struct ifvlan *, struct ifvlan_linkmib *);
 static void    vlan_hash_init(void);
@@ -549,10 +551,11 @@
        nmib_psref = NULL;
        omib_cleanup = true;
 
-
        /*
         * We inherit the parents link state.
         */
+       ifv->ifv_linkstate_hook = if_linkstate_change_establish(p,
+           vlan_link_state_changed, ifv);
        if_link_state_change(&ifv->ifv_if, p->if_link_state);
 
 done:
@@ -684,6 +687,8 @@
        pserialize_perform(vlan_psz);
        mutex_exit(&ifv_hash.lock);
        PSLIST_ENTRY_DESTROY(ifv, ifv_hash);
+       if_linkstate_change_disestablish(p,
+           ifv->ifv_linkstate_hook, NULL);
 
        vlan_linkmib_update(ifv, nmib);
        if_link_state_change(ifp, LINK_STATE_DOWN);
@@ -1733,30 +1738,28 @@
 /*
  * If the parent link state changed, the vlan link state should change also.
  */
-void
-vlan_link_state_changed(struct ifnet *p, int link_state)
+static void
+vlan_link_state_changed(void *xifv)
 {
-       struct ifvlan *ifv;
+       struct ifvlan *ifv = xifv;
+       struct ifnet *ifp, *p;
        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;
+       mib = vlan_getref_linkmib(ifv, &psref);
+       if (mib == NULL)
+               return;
 
-               if (mib->ifvm_p == p) {
-                       ifp = &mib->ifvm_ifvlan->ifv_if;
-                       if_link_state_change(ifp, link_state);
-               }
-
+       if (mib->ifvm_p == NULL) {
                vlan_putref_linkmib(mib, &psref);
+               return;
        }
 
-       mutex_exit(&ifv_list.lock);
+       ifp = &ifv->ifv_if;
+       p = mib->ifvm_p;
+       if_link_state_change(ifp, p->if_link_state);
+
+       vlan_putref_linkmib(mib, &psref);
 }
 
 /*
diff -r c82ae03c4e2f -r 5ba75b5b463e sys/net/if_vlanvar.h
--- a/sys/net/if_vlanvar.h      Thu Sep 30 03:43:25 2021 +0000
+++ b/sys/net/if_vlanvar.h      Thu Sep 30 03:47:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vlanvar.h,v 1.14 2020/09/26 18:38:09 roy Exp $      */
+/*     $NetBSD: if_vlanvar.h,v 1.15 2021/09/30 03:47:27 yamaguchi Exp $        */
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -83,7 +83,6 @@
 #ifdef _KERNEL
 void   vlan_input(struct ifnet *, struct mbuf *);
 void   vlan_ifdetach(struct ifnet *);
-void   vlan_link_state_changed(struct ifnet *, int);
 
 /*
  * Locking notes:
diff -r c82ae03c4e2f -r 5ba75b5b463e sys/rump/librump/rumpnet/net_stub.c
--- a/sys/rump/librump/rumpnet/net_stub.c       Thu Sep 30 03:43:25 2021 +0000
+++ b/sys/rump/librump/rumpnet/net_stub.c       Thu Sep 30 03:47:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net_stub.c,v 1.45 2021/09/30 03:39:39 yamaguchi Exp $  */
+/*     $NetBSD: net_stub.c,v 1.46 2021/09/30 03:47:28 yamaguchi Exp $  */
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.45 2021/09/30 03:39:39 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.46 2021/09/30 03:47:28 yamaguchi Exp $");
 
 #include <sys/mutex.h>
 #include <sys/param.h>
@@ -75,7 +75,6 @@
 /* vlan */
 __weak_alias(vlan_input,rumpnet_stub);
 __weak_alias(vlan_ifdetach,rumpnet_stub);
-__weak_alias(vlan_link_state_changed,rumpnet_stub);
 
 /* ipsec */
 /* FIXME: should modularize netipsec and reduce reverse symbol references */



Home | Main Index | Thread Index | Old Index