Module Name: src Committed By: yamaguchi Date: Thu Sep 30 03:47:28 UTC 2021
Modified Files: src/sys/net: if_ethersubr.c if_vlan.c if_vlanvar.h src/sys/rump/librump/rumpnet: net_stub.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.294 -r1.295 src/sys/net/if_ethersubr.c cvs rdiff -u -r1.161 -r1.162 src/sys/net/if_vlan.c cvs rdiff -u -r1.14 -r1.15 src/sys/net/if_vlanvar.h cvs rdiff -u -r1.45 -r1.46 src/sys/rump/librump/rumpnet/net_stub.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_ethersubr.c diff -u src/sys/net/if_ethersubr.c:1.294 src/sys/net/if_ethersubr.c:1.295 --- src/sys/net/if_ethersubr.c:1.294 Thu Sep 30 03:15:25 2021 +++ src/sys/net/if_ethersubr.c Thu Sep 30 03:47:27 2021 @@ -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 @@ ether_snprintf(char *buf, size_t len, co 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 } /* Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.161 src/sys/net/if_vlan.c:1.162 --- src/sys/net/if_vlan.c:1.161 Sat Jul 17 15:37:04 2021 +++ src/sys/net/if_vlan.c Thu Sep 30 03:47:27 2021 @@ -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 @@ struct ifvlan { */ 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_config(struct ifvlan *, 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 @@ vlan_config(struct ifvlan *ifv, struct i 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 @@ vlan_unconfig_locked(struct ifvlan *ifv, 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 @@ out: /* * 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; - if (mib->ifvm_p == p) { - ifp = &mib->ifvm_ifvlan->ifv_if; - if_link_state_change(ifp, link_state); - } + mib = vlan_getref_linkmib(ifv, &psref); + if (mib == NULL) + return; + 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); } /* Index: src/sys/net/if_vlanvar.h diff -u src/sys/net/if_vlanvar.h:1.14 src/sys/net/if_vlanvar.h:1.15 --- src/sys/net/if_vlanvar.h:1.14 Sat Sep 26 18:38:09 2020 +++ src/sys/net/if_vlanvar.h Thu Sep 30 03:47:27 2021 @@ -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 @@ struct vlanreq { #ifdef _KERNEL void vlan_input(struct ifnet *, struct mbuf *); void vlan_ifdetach(struct ifnet *); -void vlan_link_state_changed(struct ifnet *, int); /* * Locking notes: Index: src/sys/rump/librump/rumpnet/net_stub.c diff -u src/sys/rump/librump/rumpnet/net_stub.c:1.45 src/sys/rump/librump/rumpnet/net_stub.c:1.46 --- src/sys/rump/librump/rumpnet/net_stub.c:1.45 Thu Sep 30 03:39:39 2021 +++ src/sys/rump/librump/rumpnet/net_stub.c Thu Sep 30 03:47:28 2021 @@ -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 @@ __weak_alias(pppoedisc_input,rumpnet_stu /* 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 */