bridge: Register bridge_calc_link_state to link-state change hook

This commit is contained in:
yamaguchi 2021-09-30 03:35:55 +00:00
parent c4267a5360
commit b2fb0ac7fd
4 changed files with 21 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.c,v 1.492 2021/09/30 03:23:48 yamaguchi Exp $ */
/* $NetBSD: if.c,v 1.493 2021/09/30 03:35:55 yamaguchi Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.492 2021/09/30 03:23:48 yamaguchi Exp $");
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.493 2021/09/30 03:35:55 yamaguchi Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@ -2410,11 +2410,6 @@ if_link_state_change_process(struct ifnet *ifp, int link_state)
if (ifp->if_link_state_changed != NULL)
ifp->if_link_state_changed(ifp, link_state);
#if NBRIDGE > 0
if (ifp->if_bridge != NULL)
bridge_calc_link_state(ifp->if_bridge);
#endif
#if NLAGG > 0
if (ifp->if_type == IFT_IEEE8023ADLAG)
lagg_linkstate_changed(ifp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_bridge.c,v 1.181 2021/07/02 03:30:46 yamaguchi Exp $ */
/* $NetBSD: if_bridge.c,v 1.182 2021/09/30 03:35:55 yamaguchi Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.181 2021/07/02 03:30:46 yamaguchi Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.182 2021/09/30 03:35:55 yamaguchi Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -738,6 +738,10 @@ bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif)
PSLIST_WRITER_REMOVE(bif, bif_next);
BRIDGE_PSZ_PERFORM(sc);
if_linkstate_change_disestablish(ifs,
bif->bif_linkstate_hook, BRIDGE_LOCK_OBJ(sc));
BRIDGE_UNLOCK(sc);
switch (ifs->if_type) {
@ -796,9 +800,10 @@ bridge_calc_csum_flags(struct bridge_softc *sc)
*
* Calculate the link state based on each member interface.
*/
void
bridge_calc_link_state(struct bridge_softc *sc)
static void
bridge_calc_link_state(void *xsc)
{
struct bridge_softc *sc = xsc;
struct bridge_iflist *bif;
struct ifnet *ifs;
int link_state = LINK_STATE_DOWN;
@ -889,6 +894,8 @@ bridge_ioctl_add(struct bridge_softc *sc, void *arg)
bif->bif_flags = IFBIF_LEARNING | IFBIF_DISCOVER;
bif->bif_priority = BSTP_DEFAULT_PORT_PRIORITY;
bif->bif_path_cost = BSTP_DEFAULT_PATH_COST;
bif->bif_linkstate_hook = if_linkstate_change_establish(ifs,
bridge_calc_link_state, sc);
PSLIST_ENTRY_INIT(bif, bif_next);
psref_target_init(&bif->bif_psref, bridge_psref_class);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_bridgevar.h,v 1.35 2020/09/27 00:32:17 roy Exp $ */
/* $NetBSD: if_bridgevar.h,v 1.36 2021/09/30 03:35:55 yamaguchi Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@ -269,6 +269,7 @@ struct bridge_iflist {
struct ifnet *bif_ifp; /* member if */
uint32_t bif_flags; /* member if flags */
struct psref_target bif_psref;
void * *bif_linkstate_hook;
};
/*
@ -346,11 +347,11 @@ void bridge_enqueue(struct bridge_softc *, struct ifnet *, struct mbuf *,
int);
void bridge_calc_csum_flags(struct bridge_softc *);
void bridge_calc_link_state(struct bridge_softc *);
#define BRIDGE_LOCK(_sc) mutex_enter(&(_sc)->sc_iflist_psref.bip_lock)
#define BRIDGE_UNLOCK(_sc) mutex_exit(&(_sc)->sc_iflist_psref.bip_lock)
#define BRIDGE_LOCKED(_sc) mutex_owned(&(_sc)->sc_iflist_psref.bip_lock)
#define BRIDGE_LOCK_OBJ(_sc) (&(_sc)->sc_iflist_psref.bip_lock)
#define BRIDGE_LOCK(_sc) mutex_enter(BRIDGE_LOCK_OBJ(_sc))
#define BRIDGE_UNLOCK(_sc) mutex_exit(BRIDGE_LOCK_OBJ(_sc))
#define BRIDGE_LOCKED(_sc) mutex_owned(BRIDGE_LOCK_OBJ(_sc))
#define BRIDGE_PSZ_RENTER(__s) do { __s = pserialize_read_enter(); } while (0)
#define BRIDGE_PSZ_REXIT(__s) do { pserialize_read_exit(__s); } while (0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: net_stub.c,v 1.43 2021/07/14 03:19:24 ozaki-r Exp $ */
/* $NetBSD: net_stub.c,v 1.44 2021/09/30 03:35:55 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.43 2021/07/14 03:19:24 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.44 2021/09/30 03:35:55 yamaguchi Exp $");
#include <sys/mutex.h>
#include <sys/param.h>
@ -62,7 +62,6 @@ rumpnet_stub(void)
__weak_alias(bridge_ifdetach,rumpnet_stub);
__weak_alias(bridge_output,rumpnet_stub);
__weak_alias(bridge_calc_csum_flags,rumpnet_stub);
__weak_alias(bridge_calc_link_state,rumpnet_stub);
/* agr */
__weak_alias(agr_input,rumpnet_stub);