/tmp/cvsuusTrc

This commit is contained in:
Andrew Thompson 2006-07-26 10:43:02 +00:00
parent e61a82f3e3
commit 96e47153ea
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=160703
4 changed files with 943 additions and 713 deletions

File diff suppressed because it is too large Load Diff

256
sys/net/bridgestp.h Normal file
View File

@ -0,0 +1,256 @@
/* $NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Jason L. Wright
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp
*
* $FreeBSD$
*/
/*
* Data structure and control definitions for STP interfaces.
*/
#include <sys/callout.h>
#include <sys/queue.h>
/* STP port states */
#define BSTP_IFSTATE_DISABLED 0
#define BSTP_IFSTATE_LISTENING 1
#define BSTP_IFSTATE_LEARNING 2
#define BSTP_IFSTATE_FORWARDING 3
#define BSTP_IFSTATE_BLOCKING 4
#ifdef _KERNEL
/*
* Spanning tree defaults.
*/
#define BSTP_DEFAULT_MAX_AGE (20 * 256)
#define BSTP_DEFAULT_HELLO_TIME (2 * 256)
#define BSTP_DEFAULT_FORWARD_DELAY (15 * 256)
#define BSTP_DEFAULT_HOLD_TIME (1 * 256)
#define BSTP_DEFAULT_BRIDGE_PRIORITY 0x8000
#define BSTP_DEFAULT_PORT_PRIORITY 0x80
#define BSTP_DEFAULT_PATH_COST 55
/* BPDU message types */
#define BSTP_MSGTYPE_CFG 0x00 /* Configuration */
#define BSTP_MSGTYPE_TCN 0x80 /* Topology chg notification */
/* BPDU flags */
#define BSTP_FLAG_TC 0x01 /* Topology change */
#define BSTP_FLAG_TCA 0x80 /* Topology change ack */
#define BSTP_MESSAGE_AGE_INCR (1 * 256) /* in 256ths of a second */
#define BSTP_TICK_VAL (1 * 256) /* in 256ths of a second */
#define BSTP_LINK_TIMER (BSTP_TICK_VAL * 30)
/*
* Because BPDU's do not make nicely aligned structures, two different
* declarations are used: bstp_?bpdu (wire representation, packed) and
* bstp_*_unit (internal, nicely aligned version).
*/
/* configuration bridge protocol data unit */
struct bstp_cbpdu {
uint8_t cbu_dsap; /* LLC: destination sap */
uint8_t cbu_ssap; /* LLC: source sap */
uint8_t cbu_ctl; /* LLC: control */
uint16_t cbu_protoid; /* protocol id */
uint8_t cbu_protover; /* protocol version */
uint8_t cbu_bpdutype; /* message type */
uint8_t cbu_flags; /* flags (below) */
/* root id */
uint16_t cbu_rootpri; /* root priority */
uint8_t cbu_rootaddr[6]; /* root address */
uint32_t cbu_rootpathcost; /* root path cost */
/* bridge id */
uint16_t cbu_bridgepri; /* bridge priority */
uint8_t cbu_bridgeaddr[6]; /* bridge address */
uint16_t cbu_portid; /* port id */
uint16_t cbu_messageage; /* current message age */
uint16_t cbu_maxage; /* maximum age */
uint16_t cbu_hellotime; /* hello time */
uint16_t cbu_forwarddelay; /* forwarding delay */
} __attribute__((__packed__));
/* topology change notification bridge protocol data unit */
struct bstp_tbpdu {
uint8_t tbu_dsap; /* LLC: destination sap */
uint8_t tbu_ssap; /* LLC: source sap */
uint8_t tbu_ctl; /* LLC: control */
uint16_t tbu_protoid; /* protocol id */
uint8_t tbu_protover; /* protocol version */
uint8_t tbu_bpdutype; /* message type */
} __attribute__((__packed__));
/*
* Timekeeping structure used in spanning tree code.
*/
struct bstp_timer {
uint16_t active;
uint16_t value;
};
struct bstp_config_unit {
uint64_t cu_rootid;
uint64_t cu_bridge_id;
uint32_t cu_root_path_cost;
uint16_t cu_message_age;
uint16_t cu_max_age;
uint16_t cu_hello_time;
uint16_t cu_forward_delay;
uint16_t cu_port_id;
uint8_t cu_message_type;
uint8_t cu_topology_change_acknowledgment;
uint8_t cu_topology_change;
};
struct bstp_tcn_unit {
uint8_t tu_message_type;
};
/*
* Bridge interface list entry.
*/
struct bstp_port {
LIST_ENTRY(bstp_port) bp_next;
struct ifnet *bp_ifp; /* parent if */
struct bstp_state *bp_bs;
int bp_active;
uint64_t bp_designated_root;
uint64_t bp_designated_bridge;
uint32_t bp_path_cost;
uint32_t bp_designated_cost;
struct bstp_timer bp_hold_timer;
struct bstp_timer bp_message_age_timer;
struct bstp_timer bp_forward_delay_timer;
struct bstp_config_unit bp_config_bpdu;
uint16_t bp_port_id;
uint16_t bp_designated_port;
uint8_t bp_state;
uint8_t bp_topology_change_acknowledge;
uint8_t bp_config_pending;
uint8_t bp_change_detection_enabled;
uint8_t bp_priority;
};
/*
* Software state for each bridge STP.
*/
struct bstp_state {
LIST_ENTRY(bstp_state) bs_list;
struct mtx bs_mtx;
uint64_t bs_designated_root;
uint64_t bs_bridge_id;
struct bstp_port *bs_root_port;
uint32_t bs_root_path_cost;
uint16_t bs_max_age;
uint16_t bs_hello_time;
uint16_t bs_forward_delay;
uint16_t bs_bridge_max_age;
uint16_t bs_bridge_hello_time;
uint16_t bs_bridge_forward_delay;
uint16_t bs_topology_change_time;
uint16_t bs_hold_time;
uint16_t bs_bridge_priority;
uint8_t bs_topology_change_detected;
uint8_t bs_topology_change;
struct bstp_timer bs_hello_timer;
struct bstp_timer bs_topology_change_timer;
struct bstp_timer bs_tcn_timer;
struct callout bs_bstpcallout; /* STP callout */
struct bstp_timer bs_link_timer;
LIST_HEAD(, bstp_port) bs_bplist;
};
#define BSTP_LOCK_INIT(_bs) mtx_init(&(_bs)->bs_mtx, "bstp", \
NULL, MTX_DEF)
#define BSTP_LOCK_DESTROY(_bs) mtx_destroy(&(_bs)->bs_mtx)
#define BSTP_LOCK(_bs) mtx_lock(&(_bs)->bs_mtx)
#define BSTP_UNLOCK(_bs) mtx_unlock(&(_bs)->bs_mtx)
#define BSTP_LOCK_ASSERT(_bs) mtx_assert(&(_bs)->bs_mtx, MA_OWNED)
extern const uint8_t bstp_etheraddr[];
extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state);
void bstp_attach(struct bstp_state *);
void bstp_detach(struct bstp_state *);
void bstp_init(struct bstp_state *);
void bstp_reinit(struct bstp_state *);
void bstp_stop(struct bstp_state *);
int bstp_add(struct bstp_state *, struct bstp_port *, struct ifnet *);
void bstp_delete(struct bstp_port *);
void bstp_linkstate(struct ifnet *, int);
struct mbuf *bstp_input(struct bstp_port *, struct ifnet *, struct mbuf *);
#endif /* _KERNEL */

View File

@ -126,6 +126,7 @@ __FBSDID("$FreeBSD$");
#endif
#include <machine/in_cksum.h>
#include <netinet/if_ether.h> /* for struct arpcom */
#include <net/bridgestp.h>
#include <net/if_bridgevar.h>
#include <net/if_llc.h>
@ -149,17 +150,6 @@ __FBSDID("$FreeBSD$");
#define BRIDGE_RTABLE_MAX 100
#endif
/*
* Spanning tree defaults.
*/
#define BSTP_DEFAULT_MAX_AGE (20 * 256)
#define BSTP_DEFAULT_HELLO_TIME (2 * 256)
#define BSTP_DEFAULT_FORWARD_DELAY (15 * 256)
#define BSTP_DEFAULT_HOLD_TIME (1 * 256)
#define BSTP_DEFAULT_BRIDGE_PRIORITY 0x8000
#define BSTP_DEFAULT_PORT_PRIORITY 0x80
#define BSTP_DEFAULT_PATH_COST 55
/*
* Timeout (in seconds) for entries learned dynamically.
*/
@ -471,17 +461,16 @@ bridge_clone_create(struct if_clone *ifc, int unit, caddr_t params)
sc->sc_brtmax = BRIDGE_RTABLE_MAX;
sc->sc_brttimeout = BRIDGE_RTABLE_TIMEOUT;
sc->sc_bridge_max_age = BSTP_DEFAULT_MAX_AGE;
sc->sc_bridge_hello_time = BSTP_DEFAULT_HELLO_TIME;
sc->sc_bridge_forward_delay = BSTP_DEFAULT_FORWARD_DELAY;
sc->sc_bridge_priority = BSTP_DEFAULT_BRIDGE_PRIORITY;
sc->sc_hold_time = BSTP_DEFAULT_HOLD_TIME;
sc->sc_stp.bs_bridge_max_age = BSTP_DEFAULT_MAX_AGE;
sc->sc_stp.bs_bridge_hello_time = BSTP_DEFAULT_HELLO_TIME;
sc->sc_stp.bs_bridge_forward_delay = BSTP_DEFAULT_FORWARD_DELAY;
sc->sc_stp.bs_bridge_priority = BSTP_DEFAULT_BRIDGE_PRIORITY;
sc->sc_stp.bs_hold_time = BSTP_DEFAULT_HOLD_TIME;
/* Initialize our routing table. */
bridge_rtable_init(sc);
callout_init_mtx(&sc->sc_brcallout, &sc->sc_mtx, 0);
callout_init_mtx(&sc->sc_bstpcallout, &sc->sc_mtx, 0);
LIST_INIT(&sc->sc_iflist);
LIST_INIT(&sc->sc_spanlist);
@ -519,6 +508,7 @@ bridge_clone_create(struct if_clone *ifc, int unit, caddr_t params)
mtx_unlock(&bridge_list_mtx);
}
bstp_attach(&sc->sc_stp);
ether_ifattach(ifp, eaddr);
/* Now undo some of the damage... */
ifp->if_baudrate = 0;
@ -557,12 +547,12 @@ bridge_clone_destroy(struct ifnet *ifp)
BRIDGE_UNLOCK(sc);
callout_drain(&sc->sc_brcallout);
callout_drain(&sc->sc_bstpcallout);
mtx_lock(&bridge_list_mtx);
LIST_REMOVE(sc, sc_list);
mtx_unlock(&bridge_list_mtx);
bstp_detach(&sc->sc_stp);
ether_ifdetach(ifp);
if_free_type(ifp, IFT_ETHER);
@ -801,6 +791,9 @@ bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif,
}
}
if (bif->bif_flags & IFBIF_STP)
bstp_delete(&bif->bif_stp);
ifs->if_bridge = NULL;
BRIDGE_XLOCK(sc);
LIST_REMOVE(bif, bif_next);
@ -809,9 +802,6 @@ bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif,
bridge_rtdelete(sc, ifs, IFBF_FLUSHALL);
free(bif, M_DEVBUF);
if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
bstp_initialization(sc);
}
/*
@ -873,8 +863,6 @@ bridge_ioctl_add(struct bridge_softc *sc, void *arg)
bif->bif_ifp = ifs;
bif->bif_flags = IFBIF_LEARNING | IFBIF_DISCOVER;
bif->bif_priority = BSTP_DEFAULT_PORT_PRIORITY;
bif->bif_path_cost = BSTP_DEFAULT_PATH_COST;
switch (ifs->if_type) {
case IFT_ETHER:
@ -905,11 +893,6 @@ bridge_ioctl_add(struct bridge_softc *sc, void *arg)
*/
LIST_INSERT_HEAD(&sc->sc_iflist, bif, bif_next);
if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
bstp_initialization(sc);
else
bstp_stop(sc);
out:
if (error) {
if (bif != NULL)
@ -948,9 +931,9 @@ bridge_ioctl_gifflags(struct bridge_softc *sc, void *arg)
return (ENOENT);
req->ifbr_ifsflags = bif->bif_flags;
req->ifbr_state = bif->bif_state;
req->ifbr_priority = bif->bif_priority;
req->ifbr_path_cost = bif->bif_path_cost;
req->ifbr_state = bif->bif_stp.bp_state;
req->ifbr_priority = bif->bif_stp.bp_priority;
req->ifbr_path_cost = bif->bif_stp.bp_path_cost;
req->ifbr_portno = bif->bif_ifp->if_index & 0xff;
return (0);
@ -961,6 +944,7 @@ bridge_ioctl_sifflags(struct bridge_softc *sc, void *arg)
{
struct ifbreq *req = arg;
struct bridge_iflist *bif;
int error;
BRIDGE_LOCK_ASSERT(sc);
@ -973,22 +957,19 @@ bridge_ioctl_sifflags(struct bridge_softc *sc, void *arg)
return (EINVAL);
if (req->ifbr_ifsflags & IFBIF_STP) {
switch (bif->bif_ifp->if_type) {
case IFT_ETHER:
/* These can do spanning tree. */
break;
default:
/* Nothing else can. */
return (EINVAL);
if ((bif->bif_flags & IFBIF_STP) == 0) {
error = bstp_add(&sc->sc_stp, &bif->bif_stp,
bif->bif_ifp);
if (error)
return (error);
}
} else {
if ((bif->bif_flags & IFBIF_STP) != 0)
bstp_delete(&bif->bif_stp);
}
bif->bif_flags = req->ifbr_ifsflags;
if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
bstp_initialization(sc);
return (0);
}
@ -1048,9 +1029,9 @@ bridge_ioctl_gifs(struct bridge_softc *sc, void *arg)
strlcpy(breq.ifbr_ifsname, bif->bif_ifp->if_xname,
sizeof(breq.ifbr_ifsname));
breq.ifbr_ifsflags = bif->bif_flags;
breq.ifbr_state = bif->bif_state;
breq.ifbr_priority = bif->bif_priority;
breq.ifbr_path_cost = bif->bif_path_cost;
breq.ifbr_state = bif->bif_stp.bp_state;
breq.ifbr_priority = bif->bif_stp.bp_priority;
breq.ifbr_path_cost = bif->bif_stp.bp_path_cost;
breq.ifbr_portno = bif->bif_ifp->if_index & 0xff;
error = copyout(&breq, bifc->ifbic_req + count, sizeof(breq));
if (error)
@ -1065,9 +1046,9 @@ bridge_ioctl_gifs(struct bridge_softc *sc, void *arg)
strlcpy(breq.ifbr_ifsname, bif->bif_ifp->if_xname,
sizeof(breq.ifbr_ifsname));
breq.ifbr_ifsflags = bif->bif_flags;
breq.ifbr_state = bif->bif_state;
breq.ifbr_priority = bif->bif_priority;
breq.ifbr_path_cost = bif->bif_path_cost;
breq.ifbr_state = bif->bif_stp.bp_state;
breq.ifbr_priority = bif->bif_stp.bp_priority;
breq.ifbr_path_cost = bif->bif_stp.bp_path_cost;
breq.ifbr_portno = bif->bif_ifp->if_index & 0xff;
error = copyout(&breq, bifc->ifbic_req + count, sizeof(breq));
if (error)
@ -1188,10 +1169,11 @@ static int
bridge_ioctl_gpri(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
BRIDGE_LOCK_ASSERT(sc);
param->ifbrp_prio = sc->sc_bridge_priority;
param->ifbrp_prio = bs->bs_bridge_priority;
return (0);
}
@ -1200,13 +1182,12 @@ static int
bridge_ioctl_spri(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
BRIDGE_LOCK_ASSERT(sc);
sc->sc_bridge_priority = param->ifbrp_prio;
if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
bstp_initialization(sc);
bs->bs_bridge_priority = param->ifbrp_prio;
bstp_reinit(bs);
return (0);
}
@ -1215,10 +1196,11 @@ static int
bridge_ioctl_ght(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
BRIDGE_LOCK_ASSERT(sc);
param->ifbrp_hellotime = sc->sc_bridge_hello_time >> 8;
param->ifbrp_hellotime = bs->bs_bridge_hello_time >> 8;
return (0);
}
@ -1227,15 +1209,14 @@ static int
bridge_ioctl_sht(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
BRIDGE_LOCK_ASSERT(sc);
if (param->ifbrp_hellotime == 0)
return (EINVAL);
sc->sc_bridge_hello_time = param->ifbrp_hellotime << 8;
if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
bstp_initialization(sc);
bs->bs_bridge_hello_time = param->ifbrp_hellotime << 8;
bstp_reinit(bs);
return (0);
}
@ -1244,10 +1225,11 @@ static int
bridge_ioctl_gfd(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
BRIDGE_LOCK_ASSERT(sc);
param->ifbrp_fwddelay = sc->sc_bridge_forward_delay >> 8;
param->ifbrp_fwddelay = bs->bs_bridge_forward_delay >> 8;
return (0);
}
@ -1256,15 +1238,14 @@ static int
bridge_ioctl_sfd(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
BRIDGE_LOCK_ASSERT(sc);
if (param->ifbrp_fwddelay == 0)
return (EINVAL);
sc->sc_bridge_forward_delay = param->ifbrp_fwddelay << 8;
if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
bstp_initialization(sc);
bs->bs_bridge_forward_delay = param->ifbrp_fwddelay << 8;
bstp_reinit(bs);
return (0);
}
@ -1273,10 +1254,11 @@ static int
bridge_ioctl_gma(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
BRIDGE_LOCK_ASSERT(sc);
param->ifbrp_maxage = sc->sc_bridge_max_age >> 8;
param->ifbrp_maxage = bs->bs_bridge_max_age >> 8;
return (0);
}
@ -1285,15 +1267,14 @@ static int
bridge_ioctl_sma(struct bridge_softc *sc, void *arg)
{
struct ifbrparam *param = arg;
struct bstp_state *bs = &sc->sc_stp;
BRIDGE_LOCK_ASSERT(sc);
if (param->ifbrp_maxage == 0)
return (EINVAL);
sc->sc_bridge_max_age = param->ifbrp_maxage << 8;
if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
bstp_initialization(sc);
bs->bs_bridge_max_age = param->ifbrp_maxage << 8;
bstp_reinit(bs);
return (0);
}
@ -1310,10 +1291,8 @@ bridge_ioctl_sifprio(struct bridge_softc *sc, void *arg)
if (bif == NULL)
return (ENOENT);
bif->bif_priority = req->ifbr_priority;
if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
bstp_initialization(sc);
bif->bif_stp.bp_priority = req->ifbr_priority;
bstp_reinit(&sc->sc_stp);
return (0);
}
@ -1330,10 +1309,8 @@ bridge_ioctl_sifcost(struct bridge_softc *sc, void *arg)
if (bif == NULL)
return (ENOENT);
bif->bif_path_cost = req->ifbr_path_cost;
if (sc->sc_ifp->if_drv_flags & IFF_DRV_RUNNING)
bstp_initialization(sc);
bif->bif_stp.bp_path_cost = req->ifbr_path_cost;
bstp_reinit(&sc->sc_stp);
return (0);
}
@ -1462,7 +1439,8 @@ bridge_init(void *xsc)
bridge_timer, sc);
ifp->if_drv_flags |= IFF_DRV_RUNNING;
bstp_initialization(sc);
bstp_init(&sc->sc_stp); /* Initialize Spanning Tree */
BRIDGE_UNLOCK(sc);
}
@ -1482,7 +1460,7 @@ bridge_stop(struct ifnet *ifp, int disable)
return;
callout_stop(&sc->sc_brcallout);
bstp_stop(sc);
bstp_stop(&sc->sc_stp);
bridge_rtflush(sc, IFBF_FLUSHDYN);
@ -1646,7 +1624,7 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *sa,
*/
if (dst_if != ifp &&
(bif->bif_flags & IFBIF_STP) != 0) {
switch (bif->bif_state) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_LISTENING:
case BSTP_IFSTATE_DISABLED:
@ -1764,7 +1742,7 @@ bridge_forward(struct bridge_softc *sc, struct mbuf *m)
}
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_state) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_LISTENING:
case BSTP_IFSTATE_DISABLED:
@ -1794,7 +1772,7 @@ bridge_forward(struct bridge_softc *sc, struct mbuf *m)
}
if ((bif->bif_flags & IFBIF_STP) != 0 &&
bif->bif_state == BSTP_IFSTATE_LEARNING) {
bif->bif_stp.bp_state == BSTP_IFSTATE_LEARNING) {
m_freem(m);
BRIDGE_UNLOCK(sc);
return;
@ -1871,7 +1849,7 @@ bridge_forward(struct bridge_softc *sc, struct mbuf *m)
}
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_state) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_DISABLED:
case BSTP_IFSTATE_BLOCKING:
BRIDGE_UNLOCK(sc);
@ -1962,7 +1940,7 @@ bridge_input(struct ifnet *ifp, struct mbuf *m)
/* Tap off 802.1D packets; they do not get forwarded. */
if (memcmp(eh->ether_dhost, bstp_etheraddr,
ETHER_ADDR_LEN) == 0) {
m = bstp_input(ifp, m);
m = bstp_input(&bif->bif_stp, ifp, m);
if (m == NULL) {
BRIDGE_UNLOCK(sc);
return (NULL);
@ -1970,7 +1948,7 @@ bridge_input(struct ifnet *ifp, struct mbuf *m)
}
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_state) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_LISTENING:
case BSTP_IFSTATE_DISABLED:
@ -2023,7 +2001,7 @@ bridge_input(struct ifnet *ifp, struct mbuf *m)
}
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_state) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_LISTENING:
case BSTP_IFSTATE_DISABLED:
@ -2117,7 +2095,7 @@ bridge_broadcast(struct bridge_softc *sc, struct ifnet *src_if,
continue;
if (bif->bif_flags & IFBIF_STP) {
switch (bif->bif_state) {
switch (bif->bif_stp.bp_state) {
case BSTP_IFSTATE_BLOCKING:
case BSTP_IFSTATE_DISABLED:
continue;

View File

@ -133,13 +133,6 @@ struct ifbreq {
#define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */
#define IFBF_FLUSHALL 0x01 /* flush all addresses */
/* STP port states */
#define BSTP_IFSTATE_DISABLED 0
#define BSTP_IFSTATE_LISTENING 1
#define BSTP_IFSTATE_LEARNING 2
#define BSTP_IFSTATE_FORWARDING 3
#define BSTP_IFSTATE_BLOCKING 4
/*
* Interface list structure.
*/
@ -200,53 +193,14 @@ struct ifbrparam {
#define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */
#ifdef _KERNEL
/*
* Timekeeping structure used in spanning tree code.
*/
struct bridge_timer {
uint16_t active;
uint16_t value;
};
struct bstp_config_unit {
uint64_t cu_rootid;
uint64_t cu_bridge_id;
uint32_t cu_root_path_cost;
uint16_t cu_message_age;
uint16_t cu_max_age;
uint16_t cu_hello_time;
uint16_t cu_forward_delay;
uint16_t cu_port_id;
uint8_t cu_message_type;
uint8_t cu_topology_change_acknowledgment;
uint8_t cu_topology_change;
};
struct bstp_tcn_unit {
uint8_t tu_message_type;
};
/*
* Bridge interface list entry.
*/
struct bridge_iflist {
LIST_ENTRY(bridge_iflist) bif_next;
uint64_t bif_designated_root;
uint64_t bif_designated_bridge;
uint32_t bif_path_cost;
uint32_t bif_designated_cost;
struct bridge_timer bif_hold_timer;
struct bridge_timer bif_message_age_timer;
struct bridge_timer bif_forward_delay_timer;
struct bstp_config_unit bif_config_bpdu;
uint16_t bif_port_id;
uint16_t bif_designated_port;
uint8_t bif_state;
uint8_t bif_topology_change_acknowledge;
uint8_t bif_config_pending;
uint8_t bif_change_detection_enabled;
uint8_t bif_priority;
struct ifnet *bif_ifp; /* member if */
struct bstp_port bif_stp; /* STP state */
uint32_t bif_flags; /* member if flags */
int bif_mutecap; /* member muted caps */
};
@ -271,29 +225,10 @@ struct bridge_softc {
LIST_ENTRY(bridge_softc) sc_list;
struct mtx sc_mtx;
struct cv sc_cv;
uint64_t sc_designated_root;
uint64_t sc_bridge_id;
struct bridge_iflist *sc_root_port;
uint32_t sc_root_path_cost;
uint16_t sc_max_age;
uint16_t sc_hello_time;
uint16_t sc_forward_delay;
uint16_t sc_bridge_max_age;
uint16_t sc_bridge_hello_time;
uint16_t sc_bridge_forward_delay;
uint16_t sc_topology_change_time;
uint16_t sc_hold_time;
uint16_t sc_bridge_priority;
uint8_t sc_topology_change_detected;
uint8_t sc_topology_change;
struct bridge_timer sc_hello_timer;
struct bridge_timer sc_topology_change_timer;
struct bridge_timer sc_tcn_timer;
uint32_t sc_brtmax; /* max # of addresses */
uint32_t sc_brtcnt; /* cur. # of addresses */
uint32_t sc_brttimeout; /* rt timeout in seconds */
struct callout sc_brcallout; /* bridge callout */
struct callout sc_bstpcallout; /* STP callout */
uint32_t sc_iflist_ref; /* refcount for sc_iflist */
uint32_t sc_iflist_xcnt; /* refcount for sc_iflist */
LIST_HEAD(, bridge_iflist) sc_iflist; /* member interface list */
@ -301,7 +236,7 @@ struct bridge_softc {
LIST_HEAD(, bridge_rtnode) sc_rtlist; /* list version of above */
uint32_t sc_rthash_key; /* key for hash */
LIST_HEAD(, bridge_iflist) sc_spanlist; /* span ports list */
struct bridge_timer sc_link_timer;
struct bstp_state sc_stp; /* STP state */
};
#define BRIDGE_LOCK_INIT(_sc) do { \
@ -356,8 +291,6 @@ struct bridge_softc {
_err = (*bridge_output_p)(_ifp, _m, NULL, NULL); \
} while (0)
extern const uint8_t bstp_etheraddr[];
void bridge_enqueue(struct bridge_softc *, struct ifnet *, struct mbuf *);
void bridge_rtdelete(struct bridge_softc *, struct ifnet *ifp, int);
@ -365,12 +298,5 @@ extern struct mbuf *(*bridge_input_p)(struct ifnet *, struct mbuf *);
extern int (*bridge_output_p)(struct ifnet *, struct mbuf *,
struct sockaddr *, struct rtentry *);
extern void (*bridge_dn_p)(struct mbuf *, struct ifnet *);
extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state);
void bstp_initialization(struct bridge_softc *);
void bstp_linkstate(struct ifnet *, int);
void bstp_stop(struct bridge_softc *);
struct mbuf *bstp_input(struct ifnet *, struct mbuf *);
#endif /* _KERNEL */