summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2006-12-03 13:41:20 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2006-12-03 13:41:20 +0000
commitc3539f4fca699b326a362ae19444253885976af0 (patch)
treeee022dd19a1ee5c59a446ac90a40dbb39ededb15 /sys/net
parentef660dffed30ce764d25a4ab3bbe8b3f8ff79108 (diff)
Add Rapid Spanning Tree Protocol support (802.1d-2004) based on work
by Andrew Thompson (thompsa@freebsd.org). The local changes include adoption to our bridge code, reduced stack usage and many other bits. If stp is enabled, RSTP will now be used by default. Thanks for help from Andrew. This code has been in snaps for while now, commit encouraged by deraadt@
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/bridgestp.c2700
-rw-r--r--sys/net/if.c10
-rw-r--r--sys/net/if_bridge.c374
-rw-r--r--sys/net/if_bridge.h266
4 files changed, 2331 insertions, 1019 deletions
diff --git a/sys/net/bridgestp.c b/sys/net/bridgestp.c
index a621f86c1c4..a43f5143adc 100644
--- a/sys/net/bridgestp.c
+++ b/sys/net/bridgestp.c
@@ -1,7 +1,8 @@
-/* $OpenBSD: bridgestp.c,v 1.22 2006/11/24 11:50:32 reyk Exp $ */
+/* $OpenBSD: bridgestp.c,v 1.23 2006/12/03 13:41:19 reyk Exp $ */
/*
* Copyright (c) 2000 Jason L. Wright (jason@thought.net)
+ * Copyright (c) 2006 Andrew Thompson (thompsa@FreeBSD.org)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -28,10 +29,13 @@
/*
* Implementation of the spanning tree protocol as defined in
- * ISO/IEC Final DIS 15802-3 (IEEE P802.1D/D17), May 25, 1998.
- * (In English: IEEE 802.1D, Draft 17, 1998)
+ * ISO/IEC 802.1D-2004, June 9, 2004.
*/
+#if 0
+__FBSDID("$FreeBSD: /repoman/r/ncvs/src/sys/net/bridgestp.c,v 1.25 2006/11/03 03:34:04 thompsa Exp $");
+#endif
+
#include "bridge.h"
#if NBRIDGE > 0
@@ -47,6 +51,7 @@
#include <net/if.h>
#include <net/if_types.h>
+#include <net/if_dl.h>
#include <net/if_llc.h>
#include <net/if_media.h>
#include <net/route.h>
@@ -66,16 +71,116 @@
#include <net/if_bridge.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
+#define BSTP_IFSTATE_DISCARDING 5
+
+#define BSTP_TCSTATE_ACTIVE 1
+#define BSTP_TCSTATE_DETECTED 2
+#define BSTP_TCSTATE_INACTIVE 3
+#define BSTP_TCSTATE_LEARNING 4
+#define BSTP_TCSTATE_PROPAG 5
+#define BSTP_TCSTATE_ACK 6
+#define BSTP_TCSTATE_TC 7
+#define BSTP_TCSTATE_TCN 8
+
+#define BSTP_ROLE_DISABLED 0
+#define BSTP_ROLE_ROOT 1
+#define BSTP_ROLE_DESIGNATED 2
+#define BSTP_ROLE_ALTERNATE 3
+#define BSTP_ROLE_BACKUP 4
+
+/* STP port flags */
+#define BSTP_PORT_CANMIGRATE 0x0001
+#define BSTP_PORT_NEWINFO 0x0002
+#define BSTP_PORT_DISPUTED 0x0004
+#define BSTP_PORT_ADMCOST 0x0008
+#define BSTP_PORT_AUTOEDGE 0x0010
+
+/* BPDU priority */
+#define BSTP_PDU_SUPERIOR 1
+#define BSTP_PDU_REPEATED 2
+#define BSTP_PDU_INFERIOR 3
+#define BSTP_PDU_INFERIORALT 4
+#define BSTP_PDU_OTHER 5
+
+/* BPDU flags */
+#define BSTP_PDU_PRMASK 0x0c /* Port Role */
+#define BSTP_PDU_PRSHIFT 2 /* Port Role offset */
+#define BSTP_PDU_F_UNKN 0x00 /* Unknown port (00) */
+#define BSTP_PDU_F_ALT 0x01 /* Alt/Backup port (01) */
+#define BSTP_PDU_F_ROOT 0x02 /* Root port (10) */
+#define BSTP_PDU_F_DESG 0x03 /* Designated port (11) */
+
+#define BSTP_PDU_STPMASK 0x81 /* strip unused STP flags */
+#define BSTP_PDU_RSTPMASK 0x7f /* strip unused RSTP flags */
+#define BSTP_PDU_F_TC 0x01 /* Topology change */
+#define BSTP_PDU_F_P 0x02 /* Proposal flag */
+#define BSTP_PDU_F_L 0x10 /* Learning flag */
+#define BSTP_PDU_F_F 0x20 /* Forwarding flag */
+#define BSTP_PDU_F_A 0x40 /* Agreement flag */
+#define BSTP_PDU_F_TCA 0x80 /* Topology change ack */
+
+/*
+ * 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_MIGRATE_DELAY (3 * 256)
+#define BSTP_DEFAULT_HOLD_COUNT 6
+#define BSTP_DEFAULT_BRIDGE_PRIORITY 0x8000
+#define BSTP_DEFAULT_PORT_PRIORITY 0x80
+#define BSTP_DEFAULT_PATH_COST 55
+#define BSTP_MIN_HELLO_TIME (1 * 256)
+#define BSTP_MIN_MAX_AGE (6 * 256)
+#define BSTP_MIN_FORWARD_DELAY (4 * 256)
+#define BSTP_MIN_HOLD_COUNT 1
+#define BSTP_MAX_HELLO_TIME (2 * 256)
+#define BSTP_MAX_MAX_AGE (40 * 256)
+#define BSTP_MAX_FORWARD_DELAY (30 * 256)
+#define BSTP_MAX_HOLD_COUNT 10
+#define BSTP_MAX_PRIORITY 61440
+#define BSTP_MAX_PORT_PRIORITY 240
+#define BSTP_MAX_PATH_COST 200000000
+
/* BPDU message types */
#define BSTP_MSGTYPE_CFG 0x00 /* Configuration */
+#define BSTP_MSGTYPE_RSTP 0x02 /* Rapid STP */
#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_INFO_RECIEVED 1
+#define BSTP_INFO_MINE 2
+#define BSTP_INFO_AGED 3
+#define BSTP_INFO_DISABLED 4
#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 * 15)
+
+#ifdef BRIDGESTP_DEBUG
+#define DPRINTF(fmt, arg...) printf("bstp: " fmt, ##arg)
+#else
+#define DPRINTF(fmt, arg...)
+#endif
+
+#define PV2ADDR(pv, eaddr) do { \
+ eaddr[0] = pv >> 40; \
+ eaddr[1] = pv >> 32; \
+ eaddr[2] = pv >> 24; \
+ eaddr[3] = pv >> 16; \
+ eaddr[4] = pv >> 8; \
+ eaddr[5] = pv >> 0; \
+} while (0)
+
+#define INFO_BETTER 1
+#define INFO_SAME 0
+#define INFO_WORSE -1
/*
* Because BPDU's do not make nicely aligned structures, two different
@@ -108,8 +213,12 @@ struct bstp_cbpdu {
u_int16_t cbu_maxage; /* maximum age */
u_int16_t cbu_hellotime; /* hello time */
u_int16_t cbu_forwarddelay; /* forwarding delay */
+ u_int8_t cbu_versionlen; /* version 1 length */
} __packed;
+#define BSTP_BPDU_STP_LEN (3 + 35) /* LLC + STP pdu */
+#define BSTP_BPDU_RSTP_LEN (3 + 36) /* LLC + RSTP pdu */
+
/* topology change notification bridge protocol data unit */
struct bstp_tbpdu {
u_int8_t tbu_dsap; /* LLC: destination sap */
@@ -120,283 +229,155 @@ struct bstp_tbpdu {
u_int8_t tbu_bpdutype; /* message type */
} __packed;
-u_int8_t bstp_etheraddr[] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
-
-void bstp_initialization(struct bridge_softc *);
-void bstp_stop(struct bridge_softc *);
-void bstp_initialize_port(struct bridge_softc *, struct bridge_iflist *);
-void bstp_ifupdstatus(struct bridge_softc *, struct bridge_iflist *);
-void bstp_enable_port(struct bridge_softc *, struct bridge_iflist *);
-void bstp_disable_port(struct bridge_softc *, struct bridge_iflist *);
-void bstp_enable_change_detection(struct bridge_iflist *);
-void bstp_disable_change_detection(struct bridge_iflist *);
-int bstp_root_bridge(struct bridge_softc *sc);
-int bstp_supersedes_port_info(struct bridge_softc *, struct bridge_iflist *,
- struct bstp_config_unit *);
-int bstp_designated_port(struct bridge_softc *, struct bridge_iflist *);
-int bstp_designated_for_some_port(struct bridge_softc *);
-void bstp_transmit_config(struct bridge_softc *, struct bridge_iflist *);
-void bstp_transmit_tcn(struct bridge_softc *);
-struct mbuf *bstp_input(struct bridge_softc *, struct ifnet *,
- struct ether_header *, struct mbuf *);
-void bstp_received_config_bpdu(struct bridge_softc *, struct bridge_iflist *,
- struct bstp_config_unit *);
-void bstp_received_tcn_bpdu(struct bridge_softc *, struct bridge_iflist *,
- struct bstp_tcn_unit *);
-void bstp_record_config_information(struct bridge_softc *,
- struct bridge_iflist *, struct bstp_config_unit *);
-void bstp_record_config_timeout_values(struct bridge_softc *,
- struct bstp_config_unit *);
-void bstp_config_bpdu_generation(struct bridge_softc *);
-void bstp_send_config_bpdu(struct bridge_iflist *, struct bstp_config_unit *);
-void bstp_configuration_update(struct bridge_softc *);
-void bstp_root_selection(struct bridge_softc *);
-void bstp_designated_port_selection(struct bridge_softc *);
-void bstp_become_designated_port(struct bridge_softc *, struct bridge_iflist *);
-void bstp_port_state_selection(struct bridge_softc *);
-void bstp_make_forwarding(struct bridge_softc *, struct bridge_iflist *);
-void bstp_make_blocking(struct bridge_softc *, struct bridge_iflist *);
-void bstp_set_port_state(struct bridge_iflist *, u_int8_t);
-void bstp_set_bridge_priority(struct bridge_softc *, u_int64_t);
-void bstp_set_port_priority(struct bridge_softc *, struct bridge_iflist *,
- u_int16_t);
-void bstp_set_path_cost(struct bridge_softc *, struct bridge_iflist *,
- u_int32_t);
-void bstp_topology_change_detection(struct bridge_softc *);
-void bstp_topology_change_acknowledged(struct bridge_softc *);
-void bstp_acknowledge_topology_change(struct bridge_softc *,
- struct bridge_iflist *);
-
-void bstp_tick(void *);
-void bstp_timer_start(struct bridge_timer *, u_int16_t);
-void bstp_timer_stop(struct bridge_timer *);
-int bstp_timer_expired(struct bridge_timer *, u_int16_t);
-
-void bstp_hold_timer_expiry(struct bridge_softc *, struct bridge_iflist *);
-void bstp_message_age_timer_expiry(struct bridge_softc *,
- struct bridge_iflist *);
-void bstp_forward_delay_timer_expiry(struct bridge_softc *,
- struct bridge_iflist *);
-void bstp_topology_change_timer_expiry(struct bridge_softc *);
-void bstp_tcn_timer_expiry(struct bridge_softc *);
-void bstp_hello_timer_expiry(struct bridge_softc *);
+const u_int8_t bstp_etheraddr[] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
+
+LIST_HEAD(, bstp_state) bstp_list;
+
+void bstp_transmit(struct bstp_state *, struct bstp_port *);
+void bstp_transmit_bpdu(struct bstp_state *, struct bstp_port *);
+void bstp_transmit_tcn(struct bstp_state *, struct bstp_port *);
+void bstp_decode_bpdu(struct bstp_port *, struct bstp_cbpdu *,
+ struct bstp_config_unit *);
+void bstp_send_bpdu(struct bstp_state *, struct bstp_port *,
+ struct bstp_cbpdu *);
+int bstp_pdu_flags(struct bstp_port *);
+void bstp_received_stp(struct bstp_state *, struct bstp_port *,
+ struct mbuf **, struct bstp_tbpdu *);
+void bstp_received_rstp(struct bstp_state *, struct bstp_port *,
+ struct mbuf **, struct bstp_tbpdu *);
+void bstp_received_tcn(struct bstp_state *, struct bstp_port *,
+ struct bstp_tcn_unit *);
+void bstp_received_bpdu(struct bstp_state *, struct bstp_port *,
+ struct bstp_config_unit *);
+int bstp_pdu_rcvtype(struct bstp_port *, struct bstp_config_unit *);
+int bstp_pdu_bettersame(struct bstp_port *, int);
+int bstp_info_cmp(struct bstp_pri_vector *,
+ struct bstp_pri_vector *);
+int bstp_info_superior(struct bstp_pri_vector *,
+ struct bstp_pri_vector *);
+void bstp_assign_roles(struct bstp_state *);
+void bstp_update_roles(struct bstp_state *, struct bstp_port *);
+void bstp_update_state(struct bstp_state *, struct bstp_port *);
+void bstp_update_tc(struct bstp_port *);
+void bstp_update_info(struct bstp_port *);
+void bstp_set_other_tcprop(struct bstp_port *);
+void bstp_set_all_reroot(struct bstp_state *);
+void bstp_set_all_sync(struct bstp_state *);
+void bstp_set_port_state(struct bstp_port *, int);
+void bstp_set_port_role(struct bstp_port *, int);
+void bstp_set_port_proto(struct bstp_port *, int);
+void bstp_set_port_tc(struct bstp_port *, int);
+void bstp_set_timer_tc(struct bstp_port *);
+void bstp_set_timer_msgage(struct bstp_port *);
+int bstp_rerooted(struct bstp_state *, struct bstp_port *);
+u_int32_t bstp_calc_path_cost(struct bstp_port *);
+void bstp_notify_rtage(void *, int);
+void bstp_ifupdstatus(struct bstp_state *, struct bstp_port *);
+void bstp_enable_port(struct bstp_state *, struct bstp_port *);
+void bstp_disable_port(struct bstp_state *, struct bstp_port *);
+void bstp_tick(void *);
+void bstp_timer_start(struct bstp_timer *, u_int16_t);
+void bstp_timer_stop(struct bstp_timer *);
+void bstp_timer_latch(struct bstp_timer *);
+int bstp_timer_expired(struct bstp_timer *);
+void bstp_hello_timer_expiry(struct bstp_state *,
+ struct bstp_port *);
+void bstp_message_age_expiry(struct bstp_state *,
+ struct bstp_port *);
+void bstp_migrate_delay_expiry(struct bstp_state *,
+ struct bstp_port *);
+void bstp_edge_delay_expiry(struct bstp_state *,
+ struct bstp_port *);
+int bstp_addr_cmp(const u_int8_t *, const u_int8_t *);
+int bstp_same_bridgeid(u_int64_t, u_int64_t);
void
-bstp_transmit_config(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
+bstp_attach(int n)
{
- if (bif->bif_hold_timer.active) {
- bif->bif_config_pending = 1;
- return;
- }
-
- bif->bif_config_bpdu.cu_message_type = BSTP_MSGTYPE_CFG;
- bif->bif_config_bpdu.cu_rootid = sc->sc_designated_root;
- bif->bif_config_bpdu.cu_root_path_cost = sc->sc_root_path_cost;
- bif->bif_config_bpdu.cu_bridge_id = sc->sc_bridge_id;
- bif->bif_config_bpdu.cu_port_id = bif->bif_port_id;
-
- if (bstp_root_bridge(sc))
- bif->bif_config_bpdu.cu_message_age = 0;
- else
- bif->bif_config_bpdu.cu_message_age =
- sc->sc_root_port->bif_message_age_timer.value +
- BSTP_MESSAGE_AGE_INCR;
-
- bif->bif_config_bpdu.cu_max_age = sc->sc_max_age;
- bif->bif_config_bpdu.cu_hello_time = sc->sc_hello_time;
- bif->bif_config_bpdu.cu_forward_delay = sc->sc_forward_delay;
- bif->bif_config_bpdu.cu_topology_change_acknowledgment
- = bif->bif_topology_change_acknowledge;
- bif->bif_config_bpdu.cu_topology_change = sc->sc_topology_change;
-
- if (bif->bif_config_bpdu.cu_message_age < sc->sc_max_age) {
- bif->bif_topology_change_acknowledge = 0;
- bif->bif_config_pending = 0;
- bstp_send_config_bpdu(bif, &bif->bif_config_bpdu);
- bstp_timer_start(&bif->bif_hold_timer, 0);
- }
+ LIST_INIT(&bstp_list);
}
void
-bstp_send_config_bpdu(bif, cu)
- struct bridge_iflist *bif;
- struct bstp_config_unit *cu;
+bstp_transmit(struct bstp_state *bs, struct bstp_port *bp)
{
- struct arpcom *arp;
- struct ifnet *ifp;
- struct mbuf *m;
- struct ether_header eh;
- struct bstp_cbpdu bpdu;
- int s, error;
-
- s = splnet();
- ifp = bif->ifp;
- arp = (struct arpcom *)ifp;
-
- if ((ifp->if_flags & IFF_RUNNING) == 0) {
- splx(s);
- return;
- }
-#ifdef ALTQ
- if (!ALTQ_IS_ENABLED(&ifp->if_snd))
-#endif
- if (IF_QFULL(&ifp->if_snd)) {
- splx(s);
+ if ((bs->bs_ifflags & IFF_RUNNING) == 0 || bp == NULL)
return;
- }
- MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m == NULL) {
- splx(s);
+ /*
+ * a PDU can only be sent if we have tx quota left and the
+ * hello timer is running.
+ */
+ if (bp->bp_hello_timer.active == 0) {
+ /* Test if it needs to be reset */
+ bstp_hello_timer_expiry(bs, bp);
return;
}
- m->m_pkthdr.rcvif = ifp;
- m->m_pkthdr.len = sizeof(eh) + sizeof(bpdu);
- m->m_len = m->m_pkthdr.len;
-
- bpdu.cbu_ssap = bpdu.cbu_dsap = LLC_8021D_LSAP;
- bpdu.cbu_ctl = LLC_UI;
- bpdu.cbu_protoid = htons(0);
- bpdu.cbu_protover = 0;
- bpdu.cbu_bpdutype = cu->cu_message_type;
- bpdu.cbu_flags = (cu->cu_topology_change ? BSTP_FLAG_TC : 0) |
- (cu->cu_topology_change_acknowledgment ? BSTP_FLAG_TCA : 0);
-
- bpdu.cbu_rootpri = htons(cu->cu_rootid >> 48);
- bpdu.cbu_rootaddr[0] = cu->cu_rootid >> 40;
- bpdu.cbu_rootaddr[1] = cu->cu_rootid >> 32;
- bpdu.cbu_rootaddr[2] = cu->cu_rootid >> 24;
- bpdu.cbu_rootaddr[3] = cu->cu_rootid >> 16;
- bpdu.cbu_rootaddr[4] = cu->cu_rootid >> 8;
- bpdu.cbu_rootaddr[5] = cu->cu_rootid >> 0;
-
- bpdu.cbu_rootpathcost = htonl(cu->cu_root_path_cost);
-
- bpdu.cbu_bridgepri = htons(cu->cu_bridge_id >> 48);
- bpdu.cbu_bridgeaddr[0] = cu->cu_bridge_id >> 40;
- bpdu.cbu_bridgeaddr[1] = cu->cu_bridge_id >> 32;
- bpdu.cbu_bridgeaddr[2] = cu->cu_bridge_id >> 24;
- bpdu.cbu_bridgeaddr[3] = cu->cu_bridge_id >> 16;
- bpdu.cbu_bridgeaddr[4] = cu->cu_bridge_id >> 8;
- bpdu.cbu_bridgeaddr[5] = cu->cu_bridge_id >> 0;
-
- bpdu.cbu_portid = htons(cu->cu_port_id);
- bpdu.cbu_messageage = htons(cu->cu_message_age);
- bpdu.cbu_maxage = htons(cu->cu_max_age);
- bpdu.cbu_hellotime = htons(cu->cu_hello_time);
- bpdu.cbu_forwarddelay = htons(cu->cu_forward_delay);
-
- bcopy(arp->ac_enaddr, eh.ether_shost, ETHER_ADDR_LEN);
- bcopy(bstp_etheraddr, eh.ether_dhost, ETHER_ADDR_LEN);
- eh.ether_type = htons(sizeof(bpdu));
-
- bcopy(&eh, m->m_data, sizeof(eh));
- bcopy(&bpdu, m->m_data + sizeof(eh), sizeof(bpdu));
+ if (bp->bp_txcount > bs->bs_txholdcount)
+ /* Ran out of karma */
+ return;
- IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
- if (error == 0 && (ifp->if_flags & IFF_OACTIVE) == 0)
- (*ifp->if_start)(ifp);
- splx(s);
-}
+ if (bp->bp_protover == BSTP_PROTO_RSTP) {
+ bstp_transmit_bpdu(bs, bp);
+ bp->bp_tc_ack = 0;
+ } else { /* STP */
+ switch (bp->bp_role) {
+ case BSTP_ROLE_DESIGNATED:
+ bstp_transmit_bpdu(bs, bp);
+ bp->bp_tc_ack = 0;
+ break;
-int
-bstp_root_bridge(sc)
- struct bridge_softc *sc;
-{
- return (sc->sc_designated_root == sc->sc_bridge_id);
+ case BSTP_ROLE_ROOT:
+ bstp_transmit_tcn(bs, bp);
+ break;
+ }
+ }
+ bstp_timer_start(&bp->bp_hello_timer, bp->bp_desg_htime);
+ bp->bp_flags &= ~BSTP_PORT_NEWINFO;
}
-int
-bstp_supersedes_port_info(sc, bif, cu)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
- struct bstp_config_unit *cu;
+void
+bstp_transmit_bpdu(struct bstp_state *bs, struct bstp_port *bp)
{
- if (cu->cu_rootid < bif->bif_designated_root)
- return (1);
- if (cu->cu_rootid > bif->bif_designated_root)
- return (0);
-
- if (cu->cu_root_path_cost < bif->bif_designated_cost)
- return (1);
- if (cu->cu_root_path_cost > bif->bif_designated_cost)
- return (0);
+ struct bstp_cbpdu bpdu;
- if (cu->cu_bridge_id < bif->bif_designated_bridge)
- return (1);
- if (cu->cu_bridge_id > bif->bif_designated_bridge)
- return (0);
+ bpdu.cbu_rootpri = htons(bp->bp_desg_pv.pv_root_id >> 48);
+ PV2ADDR(bp->bp_desg_pv.pv_root_id, bpdu.cbu_rootaddr);
- if (sc->sc_bridge_id != cu->cu_bridge_id)
- return (1);
- if (cu->cu_port_id <= bif->bif_designated_port)
- return (1);
- return (0);
-}
+ bpdu.cbu_rootpathcost = htonl(bp->bp_desg_pv.pv_cost);
-void
-bstp_record_config_information(sc, bif, cu)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
- struct bstp_config_unit *cu;
-{
- bif->bif_designated_root = cu->cu_rootid;
- bif->bif_designated_cost = cu->cu_root_path_cost;
- bif->bif_designated_bridge = cu->cu_bridge_id;
- bif->bif_designated_port = cu->cu_port_id;
- bstp_timer_start(&bif->bif_message_age_timer, cu->cu_message_age);
-}
+ bpdu.cbu_bridgepri = htons(bp->bp_desg_pv.pv_dbridge_id >> 48);
+ PV2ADDR(bp->bp_desg_pv.pv_dbridge_id, bpdu.cbu_bridgeaddr);
-void
-bstp_record_config_timeout_values(sc, config)
- struct bridge_softc *sc;
- struct bstp_config_unit *config;
-{
- sc->sc_max_age = config->cu_max_age;
- sc->sc_hello_time = config->cu_hello_time;
- sc->sc_forward_delay = config->cu_forward_delay;
- sc->sc_topology_change = config->cu_topology_change;
-}
+ bpdu.cbu_portid = htons(bp->bp_port_id);
+ bpdu.cbu_messageage = htons(bp->bp_desg_msg_age);
+ bpdu.cbu_maxage = htons(bp->bp_desg_max_age);
+ bpdu.cbu_hellotime = htons(bp->bp_desg_htime);
+ bpdu.cbu_forwarddelay = htons(bp->bp_desg_fdelay);
-void
-bstp_config_bpdu_generation(sc)
- struct bridge_softc *sc;
-{
- struct bridge_iflist *bif;
+ bpdu.cbu_flags = bstp_pdu_flags(bp);
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bstp_designated_port(sc, bif) &&
- (bif->bif_state != BSTP_IFSTATE_DISABLED))
- bstp_transmit_config(sc, bif);
+ switch (bp->bp_protover) {
+ case BSTP_PROTO_STP:
+ bpdu.cbu_bpdutype = BSTP_MSGTYPE_CFG;
+ break;
+ case BSTP_PROTO_RSTP:
+ bpdu.cbu_bpdutype = BSTP_MSGTYPE_RSTP;
+ break;
}
-}
-int
-bstp_designated_port(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
-{
- return ((bif->bif_designated_bridge == sc->sc_bridge_id)
- && (bif->bif_designated_port == bif->bif_port_id));
+ bstp_send_bpdu(bs, bp, &bpdu);
}
void
-bstp_transmit_tcn(sc)
- struct bridge_softc *sc;
+bstp_transmit_tcn(struct bstp_state *bs, struct bstp_port *bp)
{
struct bstp_tbpdu bpdu;
- struct bridge_iflist *bif = sc->sc_root_port;
- struct ifnet *ifp = bif->ifp;
- struct arpcom *arp = (struct arpcom *)ifp;
+ struct ifnet *ifp = bp->bp_ifp;
struct ether_header *eh;
struct mbuf *m;
- int s, error;
+ int s,error;
- if ((ifp->if_flags & IFF_RUNNING) == 0)
+ if (ifp == NULL || (ifp->if_flags & IFF_RUNNING) == 0)
return;
MGETHDR(m, M_DONTWAIT, MT_DATA);
@@ -407,7 +388,7 @@ bstp_transmit_tcn(sc)
m->m_len = m->m_pkthdr.len;
eh = mtod(m, struct ether_header *);
- bcopy(arp->ac_enaddr, eh->ether_shost, ETHER_ADDR_LEN);
+ bcopy(LLADDR(ifp->if_sadl), eh->ether_shost, ETHER_ADDR_LEN);
bcopy(bstp_etheraddr, eh->ether_dhost, ETHER_ADDR_LEN);
eh->ether_type = htons(sizeof(bpdu));
@@ -416,237 +397,209 @@ bstp_transmit_tcn(sc)
bpdu.tbu_protoid = 0;
bpdu.tbu_protover = 0;
bpdu.tbu_bpdutype = BSTP_MSGTYPE_TCN;
- bcopy(&bpdu, m->m_data + sizeof(*eh), sizeof(bpdu));
+ bcopy(&bpdu, mtod(m, caddr_t) + sizeof(*eh), sizeof(bpdu));
s = splnet();
+ bp->bp_txcount++;
IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
if (error == 0 && (ifp->if_flags & IFF_OACTIVE) == 0)
(*ifp->if_start)(ifp);
- m = NULL;
splx(s);
}
void
-bstp_configuration_update(sc)
- struct bridge_softc *sc;
+bstp_decode_bpdu(struct bstp_port *bp, struct bstp_cbpdu *cpdu,
+ struct bstp_config_unit *cu)
{
- bstp_root_selection(sc);
- bstp_designated_port_selection(sc);
+ int flags;
+
+ cu->cu_pv.pv_root_id =
+ (((u_int64_t)ntohs(cpdu->cbu_rootpri)) << 48) |
+ (((u_int64_t)cpdu->cbu_rootaddr[0]) << 40) |
+ (((u_int64_t)cpdu->cbu_rootaddr[1]) << 32) |
+ (((u_int64_t)cpdu->cbu_rootaddr[2]) << 24) |
+ (((u_int64_t)cpdu->cbu_rootaddr[3]) << 16) |
+ (((u_int64_t)cpdu->cbu_rootaddr[4]) << 8) |
+ (((u_int64_t)cpdu->cbu_rootaddr[5]) << 0);
+
+ cu->cu_pv.pv_dbridge_id =
+ (((u_int64_t)ntohs(cpdu->cbu_bridgepri)) << 48) |
+ (((u_int64_t)cpdu->cbu_bridgeaddr[0]) << 40) |
+ (((u_int64_t)cpdu->cbu_bridgeaddr[1]) << 32) |
+ (((u_int64_t)cpdu->cbu_bridgeaddr[2]) << 24) |
+ (((u_int64_t)cpdu->cbu_bridgeaddr[3]) << 16) |
+ (((u_int64_t)cpdu->cbu_bridgeaddr[4]) << 8) |
+ (((u_int64_t)cpdu->cbu_bridgeaddr[5]) << 0);
+
+ cu->cu_pv.pv_cost = ntohl(cpdu->cbu_rootpathcost);
+ cu->cu_message_age = ntohs(cpdu->cbu_messageage);
+ cu->cu_max_age = ntohs(cpdu->cbu_maxage);
+ cu->cu_hello_time = ntohs(cpdu->cbu_hellotime);
+ cu->cu_forward_delay = ntohs(cpdu->cbu_forwarddelay);
+ cu->cu_pv.pv_dport_id = ntohs(cpdu->cbu_portid);
+ cu->cu_pv.pv_port_id = bp->bp_port_id;
+ cu->cu_message_type = cpdu->cbu_bpdutype;
+
+ /* Strip off unused flags in STP mode */
+ flags = cpdu->cbu_flags;
+ switch (cpdu->cbu_protover) {
+ case BSTP_PROTO_STP:
+ flags &= BSTP_PDU_STPMASK;
+ /* A STP BPDU explicitly conveys a Designated Port */
+ cu->cu_role = BSTP_ROLE_DESIGNATED;
+ break;
+ case BSTP_PROTO_RSTP:
+ flags &= BSTP_PDU_RSTPMASK;
+ break;
+ }
+
+ cu->cu_topology_change_ack =
+ (flags & BSTP_PDU_F_TCA) ? 1 : 0;
+ cu->cu_proposal =
+ (flags & BSTP_PDU_F_P) ? 1 : 0;
+ cu->cu_agree =
+ (flags & BSTP_PDU_F_A) ? 1 : 0;
+ cu->cu_learning =
+ (flags & BSTP_PDU_F_L) ? 1 : 0;
+ cu->cu_forwarding =
+ (flags & BSTP_PDU_F_F) ? 1 : 0;
+ cu->cu_topology_change =
+ (flags & BSTP_PDU_F_TC) ? 1 : 0;
+
+ switch ((flags & BSTP_PDU_PRMASK) >> BSTP_PDU_PRSHIFT) {
+ case BSTP_PDU_F_ROOT:
+ cu->cu_role = BSTP_ROLE_ROOT;
+ break;
+ case BSTP_PDU_F_ALT:
+ cu->cu_role = BSTP_ROLE_ALTERNATE;
+ break;
+ case BSTP_PDU_F_DESG:
+ cu->cu_role = BSTP_ROLE_DESIGNATED;
+ break;
+ }
}
void
-bstp_root_selection(sc)
- struct bridge_softc *sc;
+bstp_send_bpdu(struct bstp_state *bs, struct bstp_port *bp,
+ struct bstp_cbpdu *bpdu)
{
- struct bridge_iflist *root_port = NULL, *bif;
+ struct ifnet *ifp = bp->bp_ifp;
+ struct mbuf *m;
+ struct ether_header *eh;
+ int s, error;
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bstp_designated_port(sc, bif))
- continue;
- if (bif->bif_state == BSTP_IFSTATE_DISABLED)
- continue;
- if (bif->bif_designated_root >= sc->sc_bridge_id)
- continue;
- if (root_port == NULL)
- goto set_port;
+ s = splnet();
+ if (ifp == NULL || (ifp->if_flags & IFF_RUNNING) == 0)
+ goto done;
- if (bif->bif_designated_root < root_port->bif_designated_root)
- goto set_port;
- if (bif->bif_designated_root > root_port->bif_designated_root)
- continue;
+#ifdef ALTQ
+ if (!ALTQ_IS_ENABLED(&ifp->if_snd))
+#endif
+ if (IF_QFULL(&ifp->if_snd))
+ goto done;
- if ((bif->bif_designated_cost + bif->bif_path_cost) <
- (root_port->bif_designated_cost + root_port->bif_path_cost))
- goto set_port;
- if ((bif->bif_designated_cost + bif->bif_path_cost) >
- (root_port->bif_designated_cost + root_port->bif_path_cost))
- continue;
+ MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if (m == NULL)
+ goto done;
- if (bif->bif_designated_bridge < root_port->bif_designated_bridge)
- goto set_port;
- if (bif->bif_designated_bridge > root_port->bif_designated_bridge)
- continue;
+ eh = mtod(m, struct ether_header *);
- if (bif->bif_designated_port < root_port->bif_designated_port)
- goto set_port;
- if (bif->bif_designated_port > root_port->bif_designated_port)
- continue;
+ bpdu->cbu_ssap = bpdu->cbu_dsap = LLC_8021D_LSAP;
+ bpdu->cbu_ctl = LLC_UI;
+ bpdu->cbu_protoid = htons(BSTP_PROTO_ID);
- if (bif->bif_port_id >= root_port->bif_port_id)
- continue;
-set_port:
- root_port = bif;
- }
+ memcpy(eh->ether_shost, LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
+ memcpy(eh->ether_dhost, bstp_etheraddr, ETHER_ADDR_LEN);
- sc->sc_root_port = root_port;
- if (root_port == NULL) {
- sc->sc_designated_root = sc->sc_bridge_id;
- sc->sc_root_path_cost = 0;
- } else {
- sc->sc_designated_root = root_port->bif_designated_root;
- sc->sc_root_path_cost = root_port->bif_designated_cost +
- root_port->bif_path_cost;
+ switch (bpdu->cbu_bpdutype) {
+ case BSTP_MSGTYPE_CFG:
+ bpdu->cbu_protover = BSTP_PROTO_STP;
+ m->m_pkthdr.len = sizeof(*eh) + BSTP_BPDU_STP_LEN;
+ eh->ether_type = htons(BSTP_BPDU_STP_LEN);
+ memcpy(mtod(m, caddr_t) + sizeof(*eh), bpdu,
+ BSTP_BPDU_STP_LEN);
+ break;
+ case BSTP_MSGTYPE_RSTP:
+ bpdu->cbu_protover = BSTP_PROTO_RSTP;
+ bpdu->cbu_versionlen = htons(0);
+ m->m_pkthdr.len = sizeof(*eh) + BSTP_BPDU_RSTP_LEN;
+ eh->ether_type = htons(BSTP_BPDU_RSTP_LEN);
+ memcpy(mtod(m, caddr_t) + sizeof(*eh), bpdu,
+ BSTP_BPDU_RSTP_LEN);
+ break;
+ default:
+ panic("not implemented");
}
+ m->m_pkthdr.rcvif = ifp;
+ m->m_len = m->m_pkthdr.len;
+
+ bp->bp_txcount++;
+ IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
+ if (error == 0 && (ifp->if_flags & IFF_OACTIVE) == 0)
+ (*ifp->if_start)(ifp);
+ done:
+ splx(s);
}
-void
-bstp_designated_port_selection(sc)
- struct bridge_softc *sc;
+int
+bstp_pdu_flags(struct bstp_port *bp)
{
- struct bridge_iflist *bif;
-
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bstp_designated_port(sc, bif))
- goto designated;
- if (bif->bif_designated_root != sc->sc_designated_root)
- goto designated;
-
- if (sc->sc_root_path_cost < bif->bif_designated_cost)
- goto designated;
- if (sc->sc_root_path_cost > bif->bif_designated_cost)
- continue;
-
- if (sc->sc_bridge_id < bif->bif_designated_bridge)
- goto designated;
- if (sc->sc_bridge_id > bif->bif_designated_bridge)
- continue;
+ int flags = 0;
- if (bif->bif_port_id > bif->bif_designated_port)
- continue;
-designated:
- bstp_become_designated_port(sc, bif);
- }
-}
+ if (bp->bp_proposing && bp->bp_state != BSTP_IFSTATE_FORWARDING)
+ flags |= BSTP_PDU_F_P;
-void
-bstp_become_designated_port(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
-{
- bif->bif_designated_root = sc->sc_designated_root;
- bif->bif_designated_cost = sc->sc_root_path_cost;
- bif->bif_designated_bridge = sc->sc_bridge_id;
- bif->bif_designated_port = bif->bif_port_id;
-}
+ if (bp->bp_agree)
+ flags |= BSTP_PDU_F_A;
-void
-bstp_port_state_selection(sc)
- struct bridge_softc *sc;
-{
- struct bridge_iflist *bif;
+ if (bp->bp_tc_timer.active)
+ flags |= BSTP_PDU_F_TC;
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bif == sc->sc_root_port) {
- bif->bif_config_pending = 0;
- bif->bif_topology_change_acknowledge = 0;
- bstp_make_forwarding(sc, bif);
- } else if (bstp_designated_port(sc, bif)) {
- bstp_timer_stop(&bif->bif_message_age_timer);
- bstp_make_forwarding(sc, bif);
- } else {
- bif->bif_config_pending = 0;
- bif->bif_topology_change_acknowledge = 0;
- bstp_make_blocking(sc, bif);
- }
- }
-}
+ if (bp->bp_tc_ack)
+ flags |= BSTP_PDU_F_TCA;
-void
-bstp_make_forwarding(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
-{
- if (bif->bif_state == BSTP_IFSTATE_BLOCKING) {
- bstp_set_port_state(bif, BSTP_IFSTATE_LISTENING);
- bstp_timer_start(&bif->bif_forward_delay_timer, 0);
+ switch (bp->bp_state) {
+ case BSTP_IFSTATE_LEARNING:
+ flags |= BSTP_PDU_F_L;
+ break;
+ case BSTP_IFSTATE_FORWARDING:
+ flags |= (BSTP_PDU_F_L | BSTP_PDU_F_F);
+ break;
}
-}
-void
-bstp_make_blocking(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
-{
- if ((bif->bif_state != BSTP_IFSTATE_DISABLED) &&
- (bif->bif_state != BSTP_IFSTATE_BLOCKING)) {
- if ((bif->bif_state == BSTP_IFSTATE_FORWARDING) ||
- (bif->bif_state == BSTP_IFSTATE_LEARNING)) {
- if (bif->bif_change_detection_enabled) {
- bstp_topology_change_detection(sc);
- }
- bridge_rtdelete(sc, bif->ifp, 1);
- }
- bstp_set_port_state(bif, BSTP_IFSTATE_BLOCKING);
- bstp_timer_stop(&bif->bif_forward_delay_timer);
+ switch (bp->bp_role) {
+ case BSTP_ROLE_ROOT:
+ flags |= (BSTP_PDU_F_ROOT << BSTP_PDU_PRSHIFT);
+ break;
+ case BSTP_ROLE_ALTERNATE:
+ case BSTP_ROLE_BACKUP:
+ flags |= (BSTP_PDU_F_ALT << BSTP_PDU_PRSHIFT);
+ break;
+ case BSTP_ROLE_DESIGNATED:
+ flags |= (BSTP_PDU_F_DESG << BSTP_PDU_PRSHIFT);
+ break;
}
-}
-void
-bstp_set_port_state(bif, state)
- struct bridge_iflist *bif;
- u_int8_t state;
-{
- bif->bif_state = state;
-}
-
-void
-bstp_topology_change_detection(sc)
- struct bridge_softc *sc;
-{
- if (bstp_root_bridge(sc)) {
- sc->sc_topology_change = 1;
- bstp_timer_start(&sc->sc_topology_change_timer, 0);
- } else if (!sc->sc_topology_change_detected) {
- bstp_transmit_tcn(sc);
- bstp_timer_start(&sc->sc_tcn_timer, 0);
+ /* Strip off unused flags in either mode */
+ switch (bp->bp_protover) {
+ case BSTP_PROTO_STP:
+ flags &= BSTP_PDU_STPMASK;
+ break;
+ case BSTP_PROTO_RSTP:
+ flags &= BSTP_PDU_RSTPMASK;
+ break;
}
- sc->sc_topology_change_detected = 1;
-}
-
-void
-bstp_topology_change_acknowledged(sc)
- struct bridge_softc *sc;
-{
- sc->sc_topology_change_detected = 0;
- bstp_timer_stop(&sc->sc_tcn_timer);
-}
-
-void
-bstp_acknowledge_topology_change(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
-{
- bif->bif_topology_change_acknowledge = 1;
- bstp_transmit_config(sc, bif);
+ return (flags);
}
struct mbuf *
-bstp_input(sc, ifp, eh, m)
- struct bridge_softc *sc;
- struct ifnet *ifp;
- struct ether_header *eh;
- struct mbuf *m;
+bstp_input(struct bstp_state *bs, struct bstp_port *bp,
+ struct ether_header *eh, struct mbuf *m)
{
- struct bridge_iflist *bif = NULL;
struct bstp_tbpdu tpdu;
- struct bstp_cbpdu cpdu;
- struct bstp_config_unit cu;
- struct bstp_tcn_unit tu;
u_int16_t len;
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bif->ifp == ifp)
- break;
- }
- if (bif == NULL)
+ if (bs == NULL || bp == NULL || bp->bp_active == 0)
goto out;
len = ntohs(eh->ether_type);
@@ -662,594 +615,1699 @@ bstp_input(sc, ifp, eh, m)
tpdu.tbu_ssap != LLC_8021D_LSAP ||
tpdu.tbu_ctl != LLC_UI)
goto out;
- if (tpdu.tbu_protoid != 0 || tpdu.tbu_protover != 0)
+ if (tpdu.tbu_protoid != BSTP_PROTO_ID)
goto out;
- switch (tpdu.tbu_bpdutype) {
- case BSTP_MSGTYPE_TCN:
- tu.tu_message_type = tpdu.tbu_bpdutype;
- bstp_received_tcn_bpdu(sc, bif, &tu);
- break;
- case BSTP_MSGTYPE_CFG:
- if ((m = m_pullup(m, sizeof(cpdu))) == NULL)
+ /*
+ * We can treat later versions of the PDU as the same as the maximum
+ * version we implement. All additional parameters/flags are ignored.
+ */
+ if (tpdu.tbu_protover > BSTP_PROTO_MAX)
+ tpdu.tbu_protover = BSTP_PROTO_MAX;
+
+ if (tpdu.tbu_protover != bp->bp_protover) {
+ /*
+ * Wait for the migration delay timer to expire before changing
+ * protocol version to avoid flip-flops.
+ */
+ if (bp->bp_flags & BSTP_PORT_CANMIGRATE)
+ bstp_set_port_proto(bp, tpdu.tbu_protover);
+ else
goto out;
- bcopy(mtod(m, struct bstp_cpdu *), &cpdu, sizeof(cpdu));
-
- cu.cu_rootid =
- (((u_int64_t)ntohs(cpdu.cbu_rootpri)) << 48) |
- (((u_int64_t)cpdu.cbu_rootaddr[0]) << 40) |
- (((u_int64_t)cpdu.cbu_rootaddr[1]) << 32) |
- (((u_int64_t)cpdu.cbu_rootaddr[2]) << 24) |
- (((u_int64_t)cpdu.cbu_rootaddr[3]) << 16) |
- (((u_int64_t)cpdu.cbu_rootaddr[4]) << 8) |
- (((u_int64_t)cpdu.cbu_rootaddr[5]) << 0);
-
- cu.cu_bridge_id =
- (((u_int64_t)ntohs(cpdu.cbu_bridgepri)) << 48) |
- (((u_int64_t)cpdu.cbu_bridgeaddr[0]) << 40) |
- (((u_int64_t)cpdu.cbu_bridgeaddr[1]) << 32) |
- (((u_int64_t)cpdu.cbu_bridgeaddr[2]) << 24) |
- (((u_int64_t)cpdu.cbu_bridgeaddr[3]) << 16) |
- (((u_int64_t)cpdu.cbu_bridgeaddr[4]) << 8) |
- (((u_int64_t)cpdu.cbu_bridgeaddr[5]) << 0);
-
- cu.cu_root_path_cost = ntohl(cpdu.cbu_rootpathcost);
- cu.cu_message_age = ntohs(cpdu.cbu_messageage);
- cu.cu_max_age = ntohs(cpdu.cbu_maxage);
- cu.cu_hello_time = ntohs(cpdu.cbu_hellotime);
- cu.cu_forward_delay = ntohs(cpdu.cbu_forwarddelay);
- cu.cu_port_id = ntohs(cpdu.cbu_portid);
- cu.cu_message_type = cpdu.cbu_bpdutype;
- cu.cu_topology_change_acknowledgment =
- (cpdu.cbu_flags & BSTP_FLAG_TCA) ? 1 : 0;
- cu.cu_topology_change =
- (cpdu.cbu_flags & BSTP_FLAG_TC) ? 1 : 0;
- bstp_received_config_bpdu(sc, bif, &cu);
- break;
- default:
- goto out;
}
-out:
+ /* Clear operedge upon receiving a PDU on the port */
+ bp->bp_operedge = 0;
+ bstp_timer_start(&bp->bp_edge_delay_timer,
+ BSTP_DEFAULT_MIGRATE_DELAY);
+
+ switch (tpdu.tbu_protover) {
+ case BSTP_PROTO_STP:
+ bstp_received_stp(bs, bp, &m, &tpdu);
+ break;
+ case BSTP_PROTO_RSTP:
+ bstp_received_rstp(bs, bp, &m, &tpdu);
+ break;
+ }
+ out:
if (m)
m_freem(m);
return (NULL);
}
void
-bstp_received_config_bpdu(sc, bif, cu)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
- struct bstp_config_unit *cu;
+bstp_received_stp(struct bstp_state *bs, struct bstp_port *bp,
+ struct mbuf **mp, struct bstp_tbpdu *tpdu)
{
- int root;
-
- root = bstp_root_bridge(sc);
-
- if (bif->bif_state != BSTP_IFSTATE_DISABLED) {
- if (bstp_supersedes_port_info(sc, bif, cu)) {
- bstp_record_config_information(sc, bif, cu);
- bstp_configuration_update(sc);
- bstp_port_state_selection(sc);
-
- if ((!bstp_root_bridge(sc)) && root) {
- bstp_timer_stop(&sc->sc_hello_timer);
-
- if (sc->sc_topology_change_detected) {
- bstp_timer_stop(&sc->sc_topology_change_timer);
- bstp_transmit_tcn(sc);
- bstp_timer_start(&sc->sc_tcn_timer, 0);
- }
- }
+ struct bstp_cbpdu cpdu;
+ struct bstp_config_unit *cu = &bp->bp_msg_cu;
+ struct bstp_tcn_unit tu;
- if (bif == sc->sc_root_port) {
- bstp_record_config_timeout_values(sc, cu);
- bstp_config_bpdu_generation(sc);
+ switch (tpdu->tbu_bpdutype) {
+ case BSTP_MSGTYPE_TCN:
+ tu.tu_message_type = tpdu->tbu_bpdutype;
+ bstp_received_tcn(bs, bp, &tu);
+ break;
+ case BSTP_MSGTYPE_CFG:
+ if ((*mp)->m_len < BSTP_BPDU_STP_LEN &&
+ (*mp = m_pullup(*mp, BSTP_BPDU_STP_LEN)) == NULL)
+ return;
+ memcpy(&cpdu, mtod(*mp, caddr_t), BSTP_BPDU_STP_LEN);
- if (cu->cu_topology_change_acknowledgment)
- bstp_topology_change_acknowledged(sc);
- }
- } else if (bstp_designated_port(sc, bif))
- bstp_transmit_config(sc, bif);
+ bstp_decode_bpdu(bp, &cpdu, cu);
+ bstp_received_bpdu(bs, bp, cu);
+ break;
}
}
void
-bstp_received_tcn_bpdu(sc, bif, tcn)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
- struct bstp_tcn_unit *tcn;
+bstp_received_rstp(struct bstp_state *bs, struct bstp_port *bp,
+ struct mbuf **mp, struct bstp_tbpdu *tpdu)
{
- if (bif->bif_state != BSTP_IFSTATE_DISABLED &&
- bstp_designated_port(sc, bif)) {
- bstp_topology_change_detection(sc);
- bstp_acknowledge_topology_change(sc, bif);
- }
+ struct bstp_cbpdu cpdu;
+ struct bstp_config_unit *cu = &bp->bp_msg_cu;
+
+ if (tpdu->tbu_bpdutype != BSTP_MSGTYPE_RSTP)
+ return;
+
+ if ((*mp)->m_len < BSTP_BPDU_RSTP_LEN &&
+ (*mp = m_pullup(*mp, BSTP_BPDU_RSTP_LEN)) == NULL)
+ return;
+ memcpy(&cpdu, mtod(*mp, caddr_t), BSTP_BPDU_RSTP_LEN);
+
+ bstp_decode_bpdu(bp, &cpdu, cu);
+ bstp_received_bpdu(bs, bp, cu);
}
void
-bstp_hello_timer_expiry(sc)
- struct bridge_softc *sc;
+bstp_received_tcn(struct bstp_state *bs, struct bstp_port *bp,
+ struct bstp_tcn_unit *tcn)
{
- bstp_config_bpdu_generation(sc);
- bstp_timer_start(&sc->sc_hello_timer, 0);
+ bp->bp_rcvdtcn = 1;
+ bstp_update_tc(bp);
}
void
-bstp_message_age_timer_expiry(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
+bstp_received_bpdu(struct bstp_state *bs, struct bstp_port *bp,
+ struct bstp_config_unit *cu)
{
- int root;
-
- root = bstp_root_bridge(sc);
- bstp_become_designated_port(sc, bif);
- bstp_configuration_update(sc);
- bstp_port_state_selection(sc);
-
- if ((bstp_root_bridge(sc)) && (!root)) {
- sc->sc_max_age = sc->sc_bridge_max_age;
- sc->sc_hello_time = sc->sc_bridge_hello_time;
- sc->sc_forward_delay = sc->sc_bridge_forward_delay;
-
- bstp_topology_change_detection(sc);
- bstp_timer_stop(&sc->sc_tcn_timer);
- bstp_config_bpdu_generation(sc);
- bstp_timer_start(&sc->sc_hello_timer, 0);
+ int type;
+
+ /* We need to have transitioned to INFO_MINE before proceeding */
+ switch (bp->bp_infois) {
+ case BSTP_INFO_DISABLED:
+ case BSTP_INFO_AGED:
+ return;
+ }
+
+ type = bstp_pdu_rcvtype(bp, cu);
+
+ switch (type) {
+ case BSTP_PDU_SUPERIOR:
+ bs->bs_allsynced = 0;
+ bp->bp_agreed = 0;
+ bp->bp_proposing = 0;
+
+ if (cu->cu_proposal && cu->cu_forwarding == 0)
+ bp->bp_proposed = 1;
+ if (cu->cu_topology_change)
+ bp->bp_rcvdtc = 1;
+ if (cu->cu_topology_change_ack)
+ bp->bp_rcvdtca = 1;
+
+ if (bp->bp_agree &&
+ !bstp_pdu_bettersame(bp, BSTP_INFO_RECIEVED))
+ bp->bp_agree = 0;
+
+ /* copy the received priority and timers to the port */
+ bp->bp_port_pv = cu->cu_pv;
+ bp->bp_port_msg_age = cu->cu_message_age;
+ bp->bp_port_max_age = cu->cu_max_age;
+ bp->bp_port_fdelay = cu->cu_forward_delay;
+ bp->bp_port_htime =
+ (cu->cu_hello_time > BSTP_MIN_HELLO_TIME ?
+ cu->cu_hello_time : BSTP_MIN_HELLO_TIME);
+
+ /* set expiry for the new info */
+ bstp_set_timer_msgage(bp);
+
+ bp->bp_infois = BSTP_INFO_RECIEVED;
+ bstp_assign_roles(bs);
+ break;
+
+ case BSTP_PDU_REPEATED:
+ if (cu->cu_proposal && cu->cu_forwarding == 0)
+ bp->bp_proposed = 1;
+ if (cu->cu_topology_change)
+ bp->bp_rcvdtc = 1;
+ if (cu->cu_topology_change_ack)
+ bp->bp_rcvdtca = 1;
+
+ /* rearm the age timer */
+ bstp_set_timer_msgage(bp);
+ break;
+
+ case BSTP_PDU_INFERIOR:
+ if (cu->cu_learning) {
+ bp->bp_agreed = 1;
+ bp->bp_proposing = 0;
+ }
+ break;
+
+ case BSTP_PDU_INFERIORALT:
+ /*
+ * only point to point links are allowed fast
+ * transitions to forwarding.
+ */
+ if (cu->cu_agree && bp->bp_p2p_link) {
+ bp->bp_agreed = 1;
+ bp->bp_proposing = 0;
+ } else
+ bp->bp_agreed = 0;
+
+ if (cu->cu_topology_change)
+ bp->bp_rcvdtc = 1;
+ if (cu->cu_topology_change_ack)
+ bp->bp_rcvdtca = 1;
+ break;
+
+ case BSTP_PDU_OTHER:
+ return; /* do nothing */
}
+
+ /* update the state machines with the new data */
+ bstp_update_state(bs, bp);
}
-void
-bstp_forward_delay_timer_expiry(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
+int
+bstp_pdu_rcvtype(struct bstp_port *bp, struct bstp_config_unit *cu)
{
- if (bif->bif_state == BSTP_IFSTATE_LISTENING) {
- bstp_set_port_state(bif, BSTP_IFSTATE_LEARNING);
- bstp_timer_start(&bif->bif_forward_delay_timer, 0);
- } else if (bif->bif_state == BSTP_IFSTATE_LEARNING) {
- bstp_set_port_state(bif, BSTP_IFSTATE_FORWARDING);
- if (bstp_designated_for_some_port(sc) &&
- bif->bif_change_detection_enabled)
- bstp_topology_change_detection(sc);
+ int type;
+
+ /* default return type */
+ type = BSTP_PDU_OTHER;
+
+ switch (cu->cu_role) {
+ case BSTP_ROLE_DESIGNATED:
+ if (bstp_info_superior(&bp->bp_port_pv, &cu->cu_pv))
+ /* bpdu priority is superior */
+ type = BSTP_PDU_SUPERIOR;
+ else if (bstp_info_cmp(&bp->bp_port_pv, &cu->cu_pv) ==
+ INFO_SAME) {
+ if (bp->bp_port_msg_age != cu->cu_message_age ||
+ bp->bp_port_max_age != cu->cu_max_age ||
+ bp->bp_port_fdelay != cu->cu_forward_delay ||
+ bp->bp_port_htime != cu->cu_hello_time)
+ /* bpdu priority is equal and timers differ */
+ type = BSTP_PDU_SUPERIOR;
+ else
+ /* bpdu is equal */
+ type = BSTP_PDU_REPEATED;
+ } else
+ /* bpdu priority is worse */
+ type = BSTP_PDU_INFERIOR;
+
+ break;
+
+ case BSTP_ROLE_ROOT:
+ case BSTP_ROLE_ALTERNATE:
+ case BSTP_ROLE_BACKUP:
+ if (bstp_info_cmp(&bp->bp_port_pv, &cu->cu_pv) <= INFO_SAME)
+ /*
+ * not a designated port and priority is the same or
+ * worse
+ */
+ type = BSTP_PDU_INFERIORALT;
+ break;
}
+
+ return (type);
}
int
-bstp_designated_for_some_port(sc)
- struct bridge_softc *sc;
+bstp_pdu_bettersame(struct bstp_port *bp, int newinfo)
{
+ if (newinfo == BSTP_INFO_RECIEVED &&
+ bp->bp_infois == BSTP_INFO_RECIEVED &&
+ bstp_info_cmp(&bp->bp_port_pv, &bp->bp_msg_cu.cu_pv) >= INFO_SAME)
+ return (1);
- struct bridge_iflist *bif;
+ if (newinfo == BSTP_INFO_MINE &&
+ bp->bp_infois == BSTP_INFO_MINE &&
+ bstp_info_cmp(&bp->bp_port_pv, &bp->bp_desg_pv) >= INFO_SAME)
+ return (1);
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bif->bif_designated_bridge == sc->sc_bridge_id)
- return (1);
- }
return (0);
}
-void
-bstp_tcn_timer_expiry(sc)
- struct bridge_softc *sc;
+int
+bstp_info_cmp(struct bstp_pri_vector *pv,
+ struct bstp_pri_vector *cpv)
{
- bstp_transmit_tcn(sc);
- bstp_timer_start(&sc->sc_tcn_timer, 0);
+ if (cpv->pv_root_id < pv->pv_root_id)
+ return (INFO_BETTER);
+ if (cpv->pv_root_id > pv->pv_root_id)
+ return (INFO_WORSE);
+
+ if (cpv->pv_cost < pv->pv_cost)
+ return (INFO_BETTER);
+ if (cpv->pv_cost > pv->pv_cost)
+ return (INFO_WORSE);
+
+ if (cpv->pv_dbridge_id < pv->pv_dbridge_id)
+ return (INFO_BETTER);
+ if (cpv->pv_dbridge_id > pv->pv_dbridge_id)
+ return (INFO_WORSE);
+
+ if (cpv->pv_dport_id < pv->pv_dport_id)
+ return (INFO_BETTER);
+ if (cpv->pv_dport_id > pv->pv_dport_id)
+ return (INFO_WORSE);
+
+ return (INFO_SAME);
+}
+
+/*
+ * This message priority vector is superior to the port priority vector and
+ * will replace it if, and only if, the message priority vector is better than
+ * the port priority vector, or the message has been transmitted from the same
+ * designated bridge and designated port as the port priority vector.
+ */
+int
+bstp_info_superior(struct bstp_pri_vector *pv,
+ struct bstp_pri_vector *cpv)
+{
+ if (bstp_info_cmp(pv, cpv) == INFO_BETTER ||
+ (bstp_same_bridgeid(pv->pv_dbridge_id, cpv->pv_dbridge_id) &&
+ (cpv->pv_dport_id & 0xfff) == (pv->pv_dport_id & 0xfff)))
+ return (1);
+ return (0);
}
void
-bstp_topology_change_timer_expiry(sc)
- struct bridge_softc *sc;
+bstp_assign_roles(struct bstp_state *bs)
{
- sc->sc_topology_change_detected = 0;
- sc->sc_topology_change = 0;
+ struct bstp_port *bp, *rbp = NULL;
+ struct bstp_pri_vector pv;
+
+ /* default to our priority vector */
+ bs->bs_root_pv = bs->bs_bridge_pv;
+ bs->bs_root_msg_age = 0;
+ bs->bs_root_max_age = bs->bs_bridge_max_age;
+ bs->bs_root_fdelay = bs->bs_bridge_fdelay;
+ bs->bs_root_htime = bs->bs_bridge_htime;
+ bs->bs_root_port = NULL;
+
+ /* check if any recieved info supersedes us */
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
+ if (bp->bp_infois != BSTP_INFO_RECIEVED)
+ continue;
+
+ pv = bp->bp_port_pv;
+ pv.pv_cost += bp->bp_path_cost;
+
+ /*
+ * The root priority vector is the best of the set comprising
+ * the bridge priority vector plus all root path priority
+ * vectors whose bridge address is not equal to us.
+ */
+ if (bstp_same_bridgeid(pv.pv_dbridge_id,
+ bs->bs_bridge_pv.pv_dbridge_id) == 0 &&
+ bstp_info_cmp(&bs->bs_root_pv, &pv) == INFO_BETTER) {
+ /* the port vector replaces the root */
+ bs->bs_root_pv = pv;
+ bs->bs_root_msg_age = bp->bp_port_msg_age +
+ BSTP_MESSAGE_AGE_INCR;
+ bs->bs_root_max_age = bp->bp_port_max_age;
+ bs->bs_root_fdelay = bp->bp_port_fdelay;
+ bs->bs_root_htime = bp->bp_port_htime;
+ rbp = bp;
+ }
+ }
+
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
+ /* calculate the port designated vector */
+ bp->bp_desg_pv.pv_root_id = bs->bs_root_pv.pv_root_id;
+ bp->bp_desg_pv.pv_cost = bs->bs_root_pv.pv_cost;
+ bp->bp_desg_pv.pv_dbridge_id = bs->bs_bridge_pv.pv_dbridge_id;
+ bp->bp_desg_pv.pv_dport_id = bp->bp_port_id;
+ bp->bp_desg_pv.pv_port_id = bp->bp_port_id;
+
+ /* calculate designated times */
+ bp->bp_desg_msg_age = bs->bs_root_msg_age;
+ bp->bp_desg_max_age = bs->bs_root_max_age;
+ bp->bp_desg_fdelay = bs->bs_root_fdelay;
+ bp->bp_desg_htime = bs->bs_bridge_htime;
+
+
+ switch (bp->bp_infois) {
+ case BSTP_INFO_DISABLED:
+ bstp_set_port_role(bp, BSTP_ROLE_DISABLED);
+ break;
+
+ case BSTP_INFO_AGED:
+ bstp_set_port_role(bp, BSTP_ROLE_DESIGNATED);
+ bstp_update_info(bp);
+ break;
+
+ case BSTP_INFO_MINE:
+ bstp_set_port_role(bp, BSTP_ROLE_DESIGNATED);
+ /* update the port info if stale */
+ if (bstp_info_cmp(&bp->bp_port_pv,
+ &bp->bp_desg_pv) != INFO_SAME ||
+ (rbp != NULL &&
+ (bp->bp_port_msg_age != rbp->bp_port_msg_age ||
+ bp->bp_port_max_age != rbp->bp_port_max_age ||
+ bp->bp_port_fdelay != rbp->bp_port_fdelay ||
+ bp->bp_port_htime != rbp->bp_port_htime)))
+ bstp_update_info(bp);
+ break;
+
+ case BSTP_INFO_RECIEVED:
+ if (bp == rbp) {
+ /*
+ * root priority is derived from this
+ * port, make it the root port.
+ */
+ bstp_set_port_role(bp, BSTP_ROLE_ROOT);
+ bs->bs_root_port = bp;
+ } else if (bstp_info_cmp(&bp->bp_port_pv,
+ &bp->bp_desg_pv) == INFO_BETTER) {
+ /*
+ * the port priority is lower than the root
+ * port.
+ */
+ bstp_set_port_role(bp, BSTP_ROLE_DESIGNATED);
+ bstp_update_info(bp);
+ } else {
+ if (bstp_same_bridgeid(
+ bp->bp_port_pv.pv_dbridge_id,
+ bs->bs_bridge_pv.pv_dbridge_id)) {
+ /*
+ * the designated bridge refers to
+ * another port on this bridge.
+ */
+ bstp_set_port_role(bp,
+ BSTP_ROLE_BACKUP);
+ } else {
+ /*
+ * the port is an inferior path to the
+ * root bridge.
+ */
+ bstp_set_port_role(bp,
+ BSTP_ROLE_ALTERNATE);
+ }
+ }
+ break;
+ }
+ }
}
void
-bstp_hold_timer_expiry(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
+bstp_update_state(struct bstp_state *bs, struct bstp_port *bp)
{
- if (bif->bif_config_pending)
- bstp_transmit_config(sc, bif);
+ struct bstp_port *bp2;
+ int synced;
+
+ /* check if all the ports have syncronised again */
+ if (!bs->bs_allsynced) {
+ synced = 1;
+ LIST_FOREACH(bp2, &bs->bs_bplist, bp_next) {
+ if (!(bp->bp_synced ||
+ bp->bp_role == BSTP_ROLE_ROOT)) {
+ synced = 0;
+ break;
+ }
+ }
+ bs->bs_allsynced = synced;
+ }
+
+ bstp_update_roles(bs, bp);
+ bstp_update_tc(bp);
}
void
-bstp_initialization(sc)
- struct bridge_softc *sc;
+bstp_update_roles(struct bstp_state *bs, struct bstp_port *bp)
{
- struct bridge_iflist *bif, *mif;
- struct arpcom *ac, *mac;
+ switch (bp->bp_role) {
+ case BSTP_ROLE_DISABLED:
+ /* Clear any flags if set */
+ if (bp->bp_sync || !bp->bp_synced || bp->bp_reroot) {
+ bp->bp_sync = 0;
+ bp->bp_synced = 1;
+ bp->bp_reroot = 0;
+ }
+ break;
- mif = NULL; mac = NULL;
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bif->ifp->if_type != IFT_ETHER)
- continue;
- bif->bif_port_id = (bif->bif_priority << 8) |
- (bif->ifp->if_index & 0xff);
+ case BSTP_ROLE_ALTERNATE:
+ case BSTP_ROLE_BACKUP:
+ if ((bs->bs_allsynced && !bp->bp_agree) ||
+ (bp->bp_proposed && bp->bp_agree)) {
+ bp->bp_proposed = 0;
+ bp->bp_agree = 1;
+ bp->bp_flags |= BSTP_PORT_NEWINFO;
+ DPRINTF("%s -> ALTERNATE_AGREED\n",
+ bp->bp_ifp->if_xname);
+ }
- if (mif == NULL) {
- mif = bif;
- mac = (struct arpcom *)bif->ifp;
- continue;
+ if (bp->bp_proposed && !bp->bp_agree) {
+ bstp_set_all_sync(bs);
+ bp->bp_proposed = 0;
+ DPRINTF("%s -> ALTERNATE_PROPOSED\n",
+ bp->bp_ifp->if_xname);
}
- ac = (struct arpcom *)bif->ifp;
- if (memcmp(ac->ac_enaddr, mac->ac_enaddr, ETHER_ADDR_LEN) < 0) {
- mif = bif;
- mac = (struct arpcom *)bif->ifp;
- continue;
+
+ /* Clear any flags if set */
+ if (bp->bp_sync || !bp->bp_synced || bp->bp_reroot) {
+ bp->bp_sync = 0;
+ bp->bp_synced = 1;
+ bp->bp_reroot = 0;
+ DPRINTF("%s -> ALTERNATE_PORT\n", bp->bp_ifp->if_xname);
}
- }
- if (mif == NULL) {
- bstp_stop(sc);
- return;
+ break;
+
+ case BSTP_ROLE_ROOT:
+ if (bp->bp_state != BSTP_IFSTATE_FORWARDING && !bp->bp_reroot) {
+ bstp_set_all_reroot(bs);
+ DPRINTF("%s -> ROOT_REROOT\n", bp->bp_ifp->if_xname);
+ }
+
+ if ((bs->bs_allsynced && !bp->bp_agree) ||
+ (bp->bp_proposed && bp->bp_agree)) {
+ bp->bp_proposed = 0;
+ bp->bp_sync = 0;
+ bp->bp_agree = 1;
+ bp->bp_flags |= BSTP_PORT_NEWINFO;
+ DPRINTF("%s -> ROOT_AGREED\n", bp->bp_ifp->if_xname);
+ }
+
+ if (bp->bp_proposed && !bp->bp_agree) {
+ bstp_set_all_sync(bs);
+ bp->bp_proposed = 0;
+ DPRINTF("%s -> ROOT_PROPOSED\n", bp->bp_ifp->if_xname);
+ }
+
+ if (bp->bp_state != BSTP_IFSTATE_FORWARDING &&
+ (bp->bp_forward_delay_timer.active == 0 ||
+ (bstp_rerooted(bs, bp) &&
+ bp->bp_recent_backup_timer.active == 0 &&
+ bp->bp_protover == BSTP_PROTO_RSTP))) {
+ switch (bp->bp_state) {
+ case BSTP_IFSTATE_DISCARDING:
+ bstp_set_port_state(bp, BSTP_IFSTATE_LEARNING);
+ break;
+ case BSTP_IFSTATE_LEARNING:
+ bstp_set_port_state(bp,
+ BSTP_IFSTATE_FORWARDING);
+ break;
+ }
+ }
+
+ if (bp->bp_state == BSTP_IFSTATE_FORWARDING && bp->bp_reroot) {
+ bp->bp_reroot = 0;
+ DPRINTF("%s -> ROOT_REROOTED\n", bp->bp_ifp->if_xname);
+ }
+ break;
+
+ case BSTP_ROLE_DESIGNATED:
+ if (bp->bp_recent_root_timer.active == 0 && bp->bp_reroot) {
+ bp->bp_reroot = 0;
+ DPRINTF("%s -> DESIGNATED_RETIRED\n",
+ bp->bp_ifp->if_xname);
+ }
+
+ if ((bp->bp_state == BSTP_IFSTATE_DISCARDING &&
+ !bp->bp_synced) || (bp->bp_agreed && !bp->bp_synced) ||
+ (bp->bp_operedge && !bp->bp_synced) ||
+ (bp->bp_sync && bp->bp_synced)) {
+ bstp_timer_stop(&bp->bp_recent_root_timer);
+ bp->bp_synced = 1;
+ bp->bp_sync = 0;
+ DPRINTF("%s -> DESIGNATED_SYNCED\n",
+ bp->bp_ifp->if_xname);
+ }
+
+ if (bp->bp_state != BSTP_IFSTATE_FORWARDING &&
+ !bp->bp_agreed && !bp->bp_proposing &&
+ !bp->bp_operedge) {
+ bp->bp_proposing = 1;
+ bp->bp_flags |= BSTP_PORT_NEWINFO;
+ bstp_timer_start(&bp->bp_edge_delay_timer,
+ (bp->bp_p2p_link ? BSTP_DEFAULT_MIGRATE_DELAY :
+ bp->bp_desg_max_age));
+ DPRINTF("%s -> DESIGNATED_PROPOSE\n",
+ bp->bp_ifp->if_xname);
+ }
+
+ if (bp->bp_state != BSTP_IFSTATE_FORWARDING &&
+ (bp->bp_forward_delay_timer.active == 0 || bp->bp_agreed ||
+ bp->bp_operedge) &&
+ (bp->bp_recent_root_timer.active == 0 || !bp->bp_reroot) &&
+ !bp->bp_sync) {
+ if (bp->bp_agreed)
+ DPRINTF("%s -> AGREED\n", bp->bp_ifp->if_xname);
+ /*
+ * If agreed|operedge then go straight to forwarding,
+ * otherwise follow discard -> learn -> forward.
+ */
+ if (bp->bp_agreed || bp->bp_operedge ||
+ bp->bp_state == BSTP_IFSTATE_LEARNING) {
+ bstp_set_port_state(bp,
+ BSTP_IFSTATE_FORWARDING);
+ bp->bp_agreed = bp->bp_protover;
+ } else if (bp->bp_state == BSTP_IFSTATE_DISCARDING)
+ bstp_set_port_state(bp, BSTP_IFSTATE_LEARNING);
+ }
+
+ if (((bp->bp_sync && !bp->bp_synced) ||
+ (bp->bp_reroot && bp->bp_recent_root_timer.active) ||
+ (bp->bp_flags & BSTP_PORT_DISPUTED)) && !bp->bp_operedge &&
+ bp->bp_state != BSTP_IFSTATE_DISCARDING) {
+ bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
+ bp->bp_flags &= ~BSTP_PORT_DISPUTED;
+ bstp_timer_start(&bp->bp_forward_delay_timer,
+ bp->bp_protover == BSTP_PROTO_RSTP ?
+ bp->bp_desg_htime : bp->bp_desg_fdelay);
+ DPRINTF("%s -> DESIGNATED_DISCARD\n",
+ bp->bp_ifp->if_xname);
+ }
+ break;
}
- sc->sc_bridge_id =
- (((u_int64_t)sc->sc_bridge_priority) << 48) |
- (((u_int64_t)mac->ac_enaddr[0]) << 40) |
- (((u_int64_t)mac->ac_enaddr[1]) << 32) |
- ((unsigned int)mac->ac_enaddr[2] << 24) |
- ((unsigned int)mac->ac_enaddr[3] << 16) |
- ((unsigned int)mac->ac_enaddr[4] << 8) |
- ((unsigned int)mac->ac_enaddr[5]);
-
- sc->sc_designated_root = sc->sc_bridge_id;
- sc->sc_root_path_cost = 0;
- sc->sc_root_port = NULL;
-
- sc->sc_max_age = sc->sc_bridge_max_age;
- sc->sc_hello_time = sc->sc_bridge_hello_time;
- sc->sc_forward_delay = sc->sc_bridge_forward_delay;
- sc->sc_topology_change_detected = 0;
- sc->sc_topology_change = 0;
- bstp_timer_stop(&sc->sc_tcn_timer);
- bstp_timer_stop(&sc->sc_topology_change_timer);
-
- if (!timeout_initialized(&sc->sc_bstptimeout))
- timeout_set(&sc->sc_bstptimeout, bstp_tick, sc);
- if (!timeout_pending(&sc->sc_bstptimeout))
- timeout_add(&sc->sc_bstptimeout, hz);
-
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (bif->bif_flags & IFBIF_STP)
- bstp_enable_port(sc, bif);
- else
- bstp_disable_port(sc, bif);
+ if (bp->bp_flags & BSTP_PORT_NEWINFO)
+ bstp_transmit(bs, bp);
+}
+
+void
+bstp_update_tc(struct bstp_port *bp)
+{
+ switch (bp->bp_tcstate) {
+ case BSTP_TCSTATE_ACTIVE:
+ if ((bp->bp_role != BSTP_ROLE_DESIGNATED &&
+ bp->bp_role != BSTP_ROLE_ROOT) || bp->bp_operedge)
+ bstp_set_port_tc(bp, BSTP_TCSTATE_LEARNING);
+
+ if (bp->bp_rcvdtcn)
+ bstp_set_port_tc(bp, BSTP_TCSTATE_TCN);
+ if (bp->bp_rcvdtc)
+ bstp_set_port_tc(bp, BSTP_TCSTATE_TC);
+
+ if (bp->bp_tc_prop && !bp->bp_operedge)
+ bstp_set_port_tc(bp, BSTP_TCSTATE_PROPAG);
+
+ if (bp->bp_rcvdtca)
+ bstp_set_port_tc(bp, BSTP_TCSTATE_ACK);
+ break;
+
+ case BSTP_TCSTATE_INACTIVE:
+ if ((bp->bp_state == BSTP_IFSTATE_LEARNING ||
+ bp->bp_state == BSTP_IFSTATE_FORWARDING) &&
+ bp->bp_fdbflush == 0)
+ bstp_set_port_tc(bp, BSTP_TCSTATE_LEARNING);
+ break;
+
+ case BSTP_TCSTATE_LEARNING:
+ if (bp->bp_rcvdtc || bp->bp_rcvdtcn || bp->bp_rcvdtca ||
+ bp->bp_tc_prop)
+ bstp_set_port_tc(bp, BSTP_TCSTATE_LEARNING);
+ else if (bp->bp_role != BSTP_ROLE_DESIGNATED &&
+ bp->bp_role != BSTP_ROLE_ROOT &&
+ bp->bp_state == BSTP_IFSTATE_DISCARDING)
+ bstp_set_port_tc(bp, BSTP_TCSTATE_INACTIVE);
+
+ if ((bp->bp_role == BSTP_ROLE_DESIGNATED ||
+ bp->bp_role == BSTP_ROLE_ROOT) &&
+ bp->bp_state == BSTP_IFSTATE_FORWARDING &&
+ !bp->bp_operedge)
+ bstp_set_port_tc(bp, BSTP_TCSTATE_DETECTED);
+ break;
+
+ /* these are transient states and go straight back to ACTIVE */
+ case BSTP_TCSTATE_DETECTED:
+ case BSTP_TCSTATE_TCN:
+ case BSTP_TCSTATE_TC:
+ case BSTP_TCSTATE_PROPAG:
+ case BSTP_TCSTATE_ACK:
+ DPRINTF("Invalid TC state for %s\n",
+ bp->bp_ifp->if_xname);
+ break;
}
- bstp_port_state_selection(sc);
- bstp_config_bpdu_generation(sc);
- bstp_timer_start(&sc->sc_hello_timer, 0);
}
void
-bstp_stop(sc)
- struct bridge_softc *sc;
+bstp_update_info(struct bstp_port *bp)
{
+ struct bstp_state *bs = bp->bp_bs;
- struct bridge_iflist *bif;
+ bp->bp_proposing = 0;
+ bp->bp_proposed = 0;
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- bstp_set_port_state(bif, BSTP_IFSTATE_DISABLED);
- bstp_timer_stop(&bif->bif_hold_timer);
- bstp_timer_stop(&bif->bif_message_age_timer);
- bstp_timer_stop(&bif->bif_forward_delay_timer);
+ if (bp->bp_agreed && !bstp_pdu_bettersame(bp, BSTP_INFO_MINE))
+ bp->bp_agreed = 0;
+
+ if (bp->bp_synced && !bp->bp_agreed) {
+ bp->bp_synced = 0;
+ bs->bs_allsynced = 0;
}
- if (timeout_initialized(&sc->sc_bstptimeout) &&
- timeout_pending(&sc->sc_bstptimeout))
- timeout_del(&sc->sc_bstptimeout);
+ /* copy the designated pv to the port */
+ bp->bp_port_pv = bp->bp_desg_pv;
+ bp->bp_port_msg_age = bp->bp_desg_msg_age;
+ bp->bp_port_max_age = bp->bp_desg_max_age;
+ bp->bp_port_fdelay = bp->bp_desg_fdelay;
+ bp->bp_port_htime = bp->bp_desg_htime;
+ bp->bp_infois = BSTP_INFO_MINE;
- bstp_timer_stop(&sc->sc_topology_change_timer);
- bstp_timer_stop(&sc->sc_tcn_timer);
- bstp_timer_stop(&sc->sc_hello_timer);
+ /* Set transmit flag but do not immediately send */
+ bp->bp_flags |= BSTP_PORT_NEWINFO;
+}
+/* set tcprop on every port other than the caller */
+void
+bstp_set_other_tcprop(struct bstp_port *bp)
+{
+ struct bstp_state *bs = bp->bp_bs;
+ struct bstp_port *bp2;
+
+ LIST_FOREACH(bp2, &bs->bs_bplist, bp_next) {
+ if (bp2 == bp)
+ continue;
+ bp->bp_tc_prop = 1;
+ }
}
void
-bstp_initialize_port(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
+bstp_set_all_reroot(struct bstp_state *bs)
{
- bstp_become_designated_port(sc, bif);
- bstp_set_port_state(bif, BSTP_IFSTATE_BLOCKING);
- bif->bif_topology_change_acknowledge = 0;
- bif->bif_config_pending = 0;
- bstp_enable_change_detection(bif);
- bstp_timer_stop(&bif->bif_message_age_timer);
- bstp_timer_stop(&bif->bif_forward_delay_timer);
- bstp_timer_stop(&bif->bif_hold_timer);
+ struct bstp_port *bp;
+
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next)
+ bp->bp_reroot = 1;
}
void
-bstp_enable_port(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
+bstp_set_all_sync(struct bstp_state *bs)
{
- bstp_initialize_port(sc, bif);
- bstp_port_state_selection(sc);
+ struct bstp_port *bp;
+
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
+ bp->bp_sync = 1;
+ bp->bp_synced = 0; /* Not explicit in spec */
+ }
+
+ bs->bs_allsynced = 0;
}
void
-bstp_disable_port(sc, bif)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
+bstp_set_port_state(struct bstp_port *bp, int state)
{
- int root;
-
- root = bstp_root_bridge(sc);
- bstp_become_designated_port(sc, bif);
- bstp_set_port_state(bif, BSTP_IFSTATE_DISABLED);
- bif->bif_topology_change_acknowledge = 0;
- bif->bif_config_pending = 0;
- bstp_timer_stop(&bif->bif_message_age_timer);
- bstp_timer_stop(&bif->bif_forward_delay_timer);
- bstp_configuration_update(sc);
- bstp_port_state_selection(sc);
- bridge_rtdelete(sc, bif->ifp, 1);
-
- if (bstp_root_bridge(sc) && (!root)) {
- sc->sc_max_age = sc->sc_bridge_max_age;
- sc->sc_hello_time = sc->sc_bridge_hello_time;
- sc->sc_forward_delay = sc->sc_bridge_forward_delay;
-
- bstp_topology_change_detection(sc);
- bstp_timer_stop(&sc->sc_tcn_timer);
- bstp_config_bpdu_generation(sc);
- bstp_timer_start(&sc->sc_hello_timer, 0);
+ if (bp->bp_state == state)
+ return;
+
+ bp->bp_state = state;
+
+ switch (bp->bp_state) {
+ case BSTP_IFSTATE_DISCARDING:
+ DPRINTF("state changed to DISCARDING on %s\n",
+ bp->bp_ifp->if_xname);
+ break;
+
+ case BSTP_IFSTATE_LEARNING:
+ DPRINTF("state changed to LEARNING on %s\n",
+ bp->bp_ifp->if_xname);
+
+ bstp_timer_start(&bp->bp_forward_delay_timer,
+ bp->bp_protover == BSTP_PROTO_RSTP ?
+ bp->bp_desg_htime : bp->bp_desg_fdelay);
+ break;
+
+ case BSTP_IFSTATE_FORWARDING:
+ DPRINTF("state changed to FORWARDING on %s\n",
+ bp->bp_ifp->if_xname);
+
+ bstp_timer_stop(&bp->bp_forward_delay_timer);
+ /* Record that we enabled forwarding */
+ bp->bp_forward_transitions++;
+ break;
}
}
void
-bstp_set_bridge_priority(sc, new_bridge_id)
- struct bridge_softc *sc;
- u_int64_t new_bridge_id;
+bstp_set_port_role(struct bstp_port *bp, int role)
{
- int root;
- struct bridge_iflist *bif;
+ struct bstp_state *bs = bp->bp_bs;
- root = bstp_root_bridge(sc);
+ if (bp->bp_role == role)
+ return;
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bstp_designated_port(sc, bif))
- bif->bif_designated_bridge = new_bridge_id;
+ /* perform pre-change tasks */
+ switch (bp->bp_role) {
+ case BSTP_ROLE_DISABLED:
+ bstp_timer_start(&bp->bp_forward_delay_timer,
+ bp->bp_desg_max_age);
+ break;
+
+ case BSTP_ROLE_BACKUP:
+ bstp_timer_start(&bp->bp_recent_backup_timer,
+ bp->bp_desg_htime * 2);
+ /* FALLTHROUGH */
+ case BSTP_ROLE_ALTERNATE:
+ bstp_timer_start(&bp->bp_forward_delay_timer,
+ bp->bp_desg_fdelay);
+ bp->bp_sync = 0;
+ bp->bp_synced = 1;
+ bp->bp_reroot = 0;
+ break;
+
+ case BSTP_ROLE_ROOT:
+ bstp_timer_start(&bp->bp_recent_root_timer,
+ BSTP_DEFAULT_FORWARD_DELAY);
+ break;
}
- sc->sc_bridge_id = new_bridge_id;
+ bp->bp_role = role;
+ /* clear values not carried between roles */
+ bp->bp_proposing = 0;
+ bs->bs_allsynced = 0;
+
+ /* initialise the new role */
+ switch (bp->bp_role) {
+ case BSTP_ROLE_DISABLED:
+ case BSTP_ROLE_ALTERNATE:
+ case BSTP_ROLE_BACKUP:
+ DPRINTF("%s role -> ALT/BACK/DISABLED\n",
+ bp->bp_ifp->if_xname);
+ bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
+ bstp_timer_stop(&bp->bp_recent_root_timer);
+ bstp_timer_latch(&bp->bp_forward_delay_timer);
+ bp->bp_sync = 0;
+ bp->bp_synced = 1;
+ bp->bp_reroot = 0;
+ break;
+
+ case BSTP_ROLE_ROOT:
+ DPRINTF("%s role -> ROOT\n",
+ bp->bp_ifp->if_xname);
+ bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
+ bstp_timer_latch(&bp->bp_recent_root_timer);
+ bp->bp_proposing = 0;
+ break;
+
+ case BSTP_ROLE_DESIGNATED:
+ DPRINTF("%s role -> DESIGNATED\n",
+ bp->bp_ifp->if_xname);
+ bstp_timer_start(&bp->bp_hello_timer,
+ bp->bp_desg_htime);
+ bp->bp_agree = 0;
+ break;
+ }
+
+ /* let the TC state know that the role changed */
+ bstp_update_tc(bp);
+}
- bstp_configuration_update(sc);
- bstp_port_state_selection(sc);
+void
+bstp_set_port_proto(struct bstp_port *bp, int proto)
+{
+ struct bstp_state *bs = bp->bp_bs;
+
+ /* supported protocol versions */
+ switch (proto) {
+ case BSTP_PROTO_STP:
+ /* we can downgrade protocols only */
+ bstp_timer_stop(&bp->bp_migrate_delay_timer);
+ /* clear unsupported features */
+ bp->bp_operedge = 0;
+ break;
- if (bstp_root_bridge(sc) && (!root)) {
- sc->sc_max_age = sc->sc_bridge_max_age;
- sc->sc_hello_time = sc->sc_bridge_hello_time;
- sc->sc_forward_delay = sc->sc_bridge_forward_delay;
+ case BSTP_PROTO_RSTP:
+ bstp_timer_start(&bp->bp_migrate_delay_timer,
+ bs->bs_migration_delay);
+ break;
- bstp_topology_change_detection(sc);
- bstp_timer_stop(&sc->sc_tcn_timer);
- bstp_config_bpdu_generation(sc);
- bstp_timer_start(&sc->sc_hello_timer, 0);
+ default:
+ DPRINTF("Unsupported STP version %d\n", proto);
+ return;
}
+
+ bp->bp_protover = proto;
+ bp->bp_flags &= ~BSTP_PORT_CANMIGRATE;
}
void
-bstp_set_port_priority(sc, bif, new_port_id)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
- u_int16_t new_port_id;
+bstp_set_port_tc(struct bstp_port *bp, int state)
{
- if (bstp_designated_port(sc, bif))
- bif->bif_designated_port = new_port_id;
+ struct bstp_state *bs = bp->bp_bs;
+
+ bp->bp_tcstate = state;
+
+ /* initialise the new state */
+ switch (bp->bp_tcstate) {
+ case BSTP_TCSTATE_ACTIVE:
+ DPRINTF("%s -> TC_ACTIVE\n", bp->bp_ifp->if_xname);
+ /* nothing to do */
+ break;
+
+ case BSTP_TCSTATE_INACTIVE:
+ bstp_timer_stop(&bp->bp_tc_timer);
+ /* flush routes on the parent bridge */
+ bp->bp_fdbflush = 1;
+ bstp_notify_rtage(bp->bp_ifp, 0);
+ bp->bp_tc_ack = 0;
+ DPRINTF("%s -> TC_INACTIVE\n", bp->bp_ifp->if_xname);
+ break;
+
+ case BSTP_TCSTATE_LEARNING:
+ bp->bp_rcvdtc = 0;
+ bp->bp_rcvdtcn = 0;
+ bp->bp_rcvdtca = 0;
+ bp->bp_tc_prop = 0;
+ DPRINTF("%s -> TC_LEARNING\n", bp->bp_ifp->if_xname);
+ break;
+
+ case BSTP_TCSTATE_DETECTED:
+ bstp_set_timer_tc(bp);
+ bstp_set_other_tcprop(bp);
+ /* send out notification */
+ bp->bp_flags |= BSTP_PORT_NEWINFO;
+ bstp_transmit(bs, bp);
+ getmicrotime(&bs->bs_last_tc_time);
+ DPRINTF("%s -> TC_DETECTED\n", bp->bp_ifp->if_xname);
+ bp->bp_tcstate = BSTP_TCSTATE_ACTIVE; /* UCT */
+ break;
- bif->bif_port_id = new_port_id;
+ case BSTP_TCSTATE_TCN:
+ bstp_set_timer_tc(bp);
+ DPRINTF("%s -> TC_TCN\n", bp->bp_ifp->if_xname);
+ /* FALLTROUGH */
+ case BSTP_TCSTATE_TC:
+ bp->bp_rcvdtc = 0;
+ bp->bp_rcvdtcn = 0;
+ if (bp->bp_role == BSTP_ROLE_DESIGNATED)
+ bp->bp_tc_ack = 1;
+
+ bstp_set_other_tcprop(bp);
+ DPRINTF("%s -> TC_TC\n", bp->bp_ifp->if_xname);
+ bp->bp_tcstate = BSTP_TCSTATE_ACTIVE; /* UCT */
+ break;
+
+ case BSTP_TCSTATE_PROPAG:
+ /* flush routes on the parent bridge */
+ bp->bp_fdbflush = 1;
+ bstp_notify_rtage(bp->bp_ifp, 0);
+ bp->bp_tc_prop = 0;
+ bstp_set_timer_tc(bp);
+ DPRINTF("%s -> TC_PROPAG\n", bp->bp_ifp->if_xname);
+ bp->bp_tcstate = BSTP_TCSTATE_ACTIVE; /* UCT */
+ break;
- if ((sc->sc_bridge_id == bif->bif_designated_bridge) &&
- (bif->bif_port_id < bif->bif_designated_port)) {
- bstp_become_designated_port(sc, bif);
- bstp_port_state_selection(sc);
+ case BSTP_TCSTATE_ACK:
+ bstp_timer_stop(&bp->bp_tc_timer);
+ bp->bp_rcvdtca = 0;
+ DPRINTF("%s -> TC_ACK\n", bp->bp_ifp->if_xname);
+ bp->bp_tcstate = BSTP_TCSTATE_ACTIVE; /* UCT */
+ break;
}
}
void
-bstp_set_path_cost(sc, bif, path_cost)
- struct bridge_softc *sc;
- struct bridge_iflist *bif;
- u_int32_t path_cost;
+bstp_set_timer_tc(struct bstp_port *bp)
{
- bif->bif_path_cost = path_cost;
- bstp_configuration_update(sc);
- bstp_port_state_selection(sc);
+ struct bstp_state *bs = bp->bp_bs;
+
+ if (bp->bp_tc_timer.active)
+ return;
+
+ switch (bp->bp_protover) {
+ case BSTP_PROTO_RSTP:
+ bstp_timer_start(&bp->bp_tc_timer,
+ bp->bp_desg_htime + BSTP_TICK_VAL);
+ bp->bp_flags |= BSTP_PORT_NEWINFO;
+ break;
+ case BSTP_PROTO_STP:
+ bstp_timer_start(&bp->bp_tc_timer,
+ bs->bs_root_max_age + bs->bs_root_fdelay);
+ break;
+ }
}
void
-bstp_enable_change_detection(bif)
- struct bridge_iflist *bif;
+bstp_set_timer_msgage(struct bstp_port *bp)
{
- bif->bif_change_detection_enabled = 1;
+ if (bp->bp_port_msg_age + BSTP_MESSAGE_AGE_INCR <=
+ bp->bp_port_max_age) {
+ bstp_timer_start(&bp->bp_message_age_timer,
+ bp->bp_port_htime * 3);
+ } else
+ /* expires immediately */
+ bstp_timer_start(&bp->bp_message_age_timer, 0);
+}
+
+int
+bstp_rerooted(struct bstp_state *bs, struct bstp_port *bp)
+{
+ struct bstp_port *bp2;
+ int rr_set = 0;
+
+ LIST_FOREACH(bp2, &bs->bs_bplist, bp_next) {
+ if (bp2 == bp)
+ continue;
+ if (bp2->bp_recent_root_timer.active) {
+ rr_set = 1;
+ break;
+ }
+ }
+ return (!rr_set);
+}
+
+/*
+ * Calculate the path cost according to the link speed.
+ */
+u_int32_t
+bstp_calc_path_cost(struct bstp_port *bp)
+{
+ struct ifnet *ifp = bp->bp_ifp;
+ u_int32_t path_cost;
+
+ /* If the priority has been manually set then retain the value */
+ if (bp->bp_flags & BSTP_PORT_ADMCOST)
+ return bp->bp_path_cost;
+
+ if (ifp->if_baudrate < 1000)
+ return (BSTP_DEFAULT_PATH_COST);
+
+ /* formula from section 17.14, IEEE Std 802.1D-2004 */
+ path_cost = 20000000000ULL / (ifp->if_baudrate / 1000);
+
+ if (path_cost > BSTP_MAX_PATH_COST)
+ path_cost = BSTP_MAX_PATH_COST;
+
+ /* STP compat mode only uses 16 bits of the 32 */
+ if (bp->bp_protover == BSTP_PROTO_STP && path_cost > 65535)
+ path_cost = 65535;
+
+ return (path_cost);
}
void
-bstp_disable_change_detection(bif)
- struct bridge_iflist *bif;
+bstp_notify_rtage(void *arg, int pending)
{
- bif->bif_change_detection_enabled = 0;
+ struct bstp_port *bp = (struct bstp_port *)arg;
+ int age = 0;
+
+ splassert(IPL_NET);
+
+ switch (bp->bp_protover) {
+ case BSTP_PROTO_STP:
+ /* convert to seconds */
+ age = bp->bp_desg_fdelay / BSTP_TICK_VAL;
+ break;
+ case BSTP_PROTO_RSTP:
+ age = 0;
+ break;
+ }
+
+ if (bp->bp_active == 1)
+ bridge_rtagenode(bp->bp_ifp, age);
+
+ /* flush is complete */
+ bp->bp_fdbflush = 0;
}
void
-bstp_ifupdstatus(sc, bif)
+bstp_ifstate(void *arg)
+{
+ struct ifnet *ifp = (struct ifnet *)arg;
struct bridge_softc *sc;
- struct bridge_iflist *bif;
+ struct bridge_iflist *p;
+ struct bstp_port *bp;
+ struct bstp_state *bs;
+ int s;
+
+ if (ifp->if_type == IFT_BRIDGE)
+ return;
+ sc = (struct bridge_softc *)ifp->if_bridge;
+
+ s = splnet();
+ LIST_FOREACH(p, &sc->sc_iflist, next) {
+ if ((p->bif_flags & IFBIF_STP) == 0)
+ continue;
+ if (p->ifp == ifp)
+ break;
+ }
+ if (p == LIST_END(&sc->sc_iflist))
+ goto done;
+ if ((bp = p->bif_stp) == NULL)
+ goto done;
+ if ((bs = bp->bp_bs) == NULL)
+ goto done;
+
+ /* update the link state */
+ bstp_ifupdstatus(bs, bp);
+ bstp_update_state(bs, bp);
+ done:
+ splx(s);
+}
+
+void
+bstp_ifupdstatus(struct bstp_state *bs, struct bstp_port *bp)
{
- struct ifnet *ifp = bif->ifp;
+ struct ifnet *ifp = bp->bp_ifp;
+
+ if (ifp == NULL)
+ return;
+
+ bp->bp_path_cost = bstp_calc_path_cost(bp);
if ((ifp->if_flags & IFF_UP) &&
ifp->if_link_state != LINK_STATE_DOWN) {
- if (bif->bif_state == BSTP_IFSTATE_DISABLED)
- bstp_enable_port(sc, bif);
+ if (bp->bp_flags & BSTP_PORT_AUTOP2P) {
+ /* A full-duplex link is assumed to be p2p */
+ bp->bp_p2p_link = ifp->if_link_state ==
+ LINK_STATE_FULL_DUPLEX ? 1 : 0;
+ }
+
+ if (bp->bp_infois == BSTP_INFO_DISABLED)
+ bstp_enable_port(bs, bp);
} else {
- if (bif->bif_state != BSTP_IFSTATE_DISABLED)
- bstp_disable_port(sc, bif);
+ if (bp->bp_infois != BSTP_INFO_DISABLED)
+ bstp_disable_port(bs, bp);
}
}
void
-bstp_tick(vsc)
- void *vsc;
+bstp_enable_port(struct bstp_state *bs, struct bstp_port *bp)
+{
+ bp->bp_infois = BSTP_INFO_AGED;
+ bstp_assign_roles(bs);
+}
+
+void
+bstp_disable_port(struct bstp_state *bs, struct bstp_port *bp)
+{
+ bp->bp_infois = BSTP_INFO_DISABLED;
+ bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
+ bstp_assign_roles(bs);
+}
+
+void
+bstp_tick(void *arg)
{
- struct bridge_softc *sc = vsc;
- struct bridge_iflist *bif;
+ struct bstp_state *bs = (struct bstp_state *)arg;
+ struct bstp_port *bp;
int s;
s = splnet();
+ if ((bs->bs_ifflags & IFF_RUNNING) == 0) {
+ splx(s);
+ return;
+ }
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- bstp_ifupdstatus(sc, bif);
+ /* slow timer to catch missed link events */
+ if (bstp_timer_expired(&bs->bs_link_timer)) {
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next)
+ bstp_ifupdstatus(bs, bp);
+ bstp_timer_start(&bs->bs_link_timer, BSTP_LINK_TIMER);
}
- if (bstp_timer_expired(&sc->sc_hello_timer, sc->sc_hello_time))
- bstp_hello_timer_expiry(sc);
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
+ /* no events need to happen for these */
+ bstp_timer_expired(&bp->bp_tc_timer);
+ bstp_timer_expired(&bp->bp_recent_root_timer);
+ bstp_timer_expired(&bp->bp_forward_delay_timer);
+ bstp_timer_expired(&bp->bp_recent_backup_timer);
- if (bstp_timer_expired(&sc->sc_tcn_timer, sc->sc_bridge_hello_time))
- bstp_tcn_timer_expiry(sc);
+ if (bstp_timer_expired(&bp->bp_hello_timer))
+ bstp_hello_timer_expiry(bs, bp);
- if (bstp_timer_expired(&sc->sc_topology_change_timer,
- sc->sc_topology_change_time))
- bstp_topology_change_timer_expiry(sc);
+ if (bstp_timer_expired(&bp->bp_message_age_timer))
+ bstp_message_age_expiry(bs, bp);
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bstp_timer_expired(&bif->bif_message_age_timer,
- sc->sc_max_age))
- bstp_message_age_timer_expiry(sc, bif);
- }
+ if (bstp_timer_expired(&bp->bp_migrate_delay_timer))
+ bstp_migrate_delay_expiry(bs, bp);
- LIST_FOREACH(bif, &sc->sc_iflist, next) {
- if (!(bif->bif_flags & IFBIF_STP))
- continue;
- if (bstp_timer_expired(&bif->bif_forward_delay_timer,
- sc->sc_forward_delay))
- bstp_forward_delay_timer_expiry(sc, bif);
+ if (bstp_timer_expired(&bp->bp_edge_delay_timer))
+ bstp_edge_delay_expiry(bs, bp);
+
+ /* update the various state machines for the port */
+ bstp_update_state(bs, bp);
- if (bstp_timer_expired(&bif->bif_hold_timer,
- sc->sc_hold_time))
- bstp_hold_timer_expiry(sc, bif);
+ if (bp->bp_txcount > 0)
+ bp->bp_txcount--;
}
- if (sc->sc_if.if_flags & IFF_RUNNING)
- timeout_add(&sc->sc_bstptimeout, hz);
+ if (bs->bs_ifp->if_flags & IFF_RUNNING)
+ timeout_add(&bs->bs_bstptimeout, hz);
splx(s);
}
void
-bstp_timer_start(t, v)
- struct bridge_timer *t;
- u_int16_t v;
+bstp_timer_start(struct bstp_timer *t, u_int16_t v)
{
t->value = v;
t->active = 1;
+ t->latched = 0;
}
void
-bstp_timer_stop(t)
- struct bridge_timer *t;
+bstp_timer_stop(struct bstp_timer *t)
{
t->value = 0;
t->active = 0;
+ t->latched = 0;
+}
+
+void
+bstp_timer_latch(struct bstp_timer *t)
+{
+ t->latched = 1;
+ t->active = 1;
}
int
-bstp_timer_expired(t, v)
- struct bridge_timer *t;
- u_int16_t v;
+bstp_timer_expired(struct bstp_timer *t)
{
- if (!t->active)
+ if (t->active == 0 || t->latched)
return (0);
- t->value += BSTP_TICK_VAL;
- if (t->value >= v) {
+ t->value -= BSTP_TICK_VAL;
+ if (t->value <= 0) {
bstp_timer_stop(t);
return (1);
}
return (0);
+}
+
+void
+bstp_hello_timer_expiry(struct bstp_state *bs, struct bstp_port *bp)
+{
+ if ((bp->bp_flags & BSTP_PORT_NEWINFO) ||
+ bp->bp_role == BSTP_ROLE_DESIGNATED ||
+ (bp->bp_role == BSTP_ROLE_ROOT &&
+ bp->bp_tc_timer.active == 1)) {
+ bstp_timer_start(&bp->bp_hello_timer, bp->bp_desg_htime);
+ bp->bp_flags |= BSTP_PORT_NEWINFO;
+ bstp_transmit(bs, bp);
+ }
+}
+
+void
+bstp_message_age_expiry(struct bstp_state *bs, struct bstp_port *bp)
+{
+ if (bp->bp_infois == BSTP_INFO_RECIEVED) {
+ bp->bp_infois = BSTP_INFO_AGED;
+ bstp_assign_roles(bs);
+ DPRINTF("aged info on %s\n", bp->bp_ifp->if_xname);
+ }
+}
+
+void
+bstp_migrate_delay_expiry(struct bstp_state *bs, struct bstp_port *bp)
+{
+ bp->bp_flags |= BSTP_PORT_CANMIGRATE;
+}
+
+void
+bstp_edge_delay_expiry(struct bstp_state *bs, struct bstp_port *bp)
+{
+ if ((bp->bp_flags & BSTP_PORT_AUTOEDGE) &&
+ bp->bp_protover == BSTP_PROTO_RSTP && bp->bp_proposing &&
+ bp->bp_role == BSTP_ROLE_DESIGNATED)
+ bp->bp_operedge = 1;
+}
+
+int
+bstp_addr_cmp(const u_int8_t *a, const u_int8_t *b)
+{
+ int i, d;
+
+ for (i = 0, d = 0; i < ETHER_ADDR_LEN && d == 0; i++) {
+ d = ((int)a[i]) - ((int)b[i]);
+ }
+
+ return (d);
+}
+
+/*
+ * compare the bridge address component of the bridgeid
+ */
+int
+bstp_same_bridgeid(u_int64_t id1, u_int64_t id2)
+{
+ u_char addr1[ETHER_ADDR_LEN];
+ u_char addr2[ETHER_ADDR_LEN];
+
+ PV2ADDR(id1, addr1);
+ PV2ADDR(id2, addr2);
+
+ if (bstp_addr_cmp(addr1, addr2) == 0)
+ return (1);
+
+ return (0);
+}
+
+void
+bstp_initialization(struct bstp_state *bs)
+{
+ struct bstp_port *bp;
+ struct ifnet *ifp, *mif;
+ u_char *e_addr;
+
+ if (LIST_EMPTY(&bs->bs_bplist)) {
+ bstp_stop(bs);
+ return;
+ }
+
+ mif = NULL;
+ /*
+ * Search through the Ethernet interfaces and find the one
+ * with the lowest value. The adapter which we take the MAC
+ * address from does not need to be part of the bridge, it just
+ * needs to be a unique value. It is not possible for mif to be
+ * null, at this point we have at least one STP port and hence
+ * at least one NIC.
+ */
+ TAILQ_FOREACH(ifp, &ifnet, if_list) {
+ if (ifp->if_type != IFT_ETHER)
+ continue;
+ if (mif == NULL) {
+ mif = ifp;
+ continue;
+ }
+ if (bstp_addr_cmp(LLADDR(ifp->if_sadl),
+ LLADDR(mif->if_sadl)) < 0) {
+ mif = ifp;
+ continue;
+ }
+ }
+
+ e_addr = LLADDR(mif->if_sadl);
+ bs->bs_bridge_pv.pv_dbridge_id =
+ (((u_int64_t)bs->bs_bridge_priority) << 48) |
+ (((u_int64_t)e_addr[0]) << 40) |
+ (((u_int64_t)e_addr[1]) << 32) |
+ (((u_int64_t)e_addr[2]) << 24) |
+ (((u_int64_t)e_addr[3]) << 16) |
+ (((u_int64_t)e_addr[4]) << 8) |
+ (((u_int64_t)e_addr[5]));
+
+ bs->bs_bridge_pv.pv_root_id = bs->bs_bridge_pv.pv_dbridge_id;
+ bs->bs_bridge_pv.pv_cost = 0;
+ bs->bs_bridge_pv.pv_dport_id = 0;
+ bs->bs_bridge_pv.pv_port_id = 0;
+
+ if (!timeout_initialized(&bs->bs_bstptimeout))
+ timeout_set(&bs->bs_bstptimeout, bstp_tick, bs);
+ if (bs->bs_ifflags & IFF_RUNNING &&
+ !timeout_pending(&bs->bs_bstptimeout))
+ timeout_add(&bs->bs_bstptimeout, hz);
+
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
+ bp->bp_port_id = (bp->bp_priority << 8) |
+ (bp->bp_ifp->if_index & 0xfff);
+ bstp_ifupdstatus(bs, bp);
+ }
+
+ bstp_assign_roles(bs);
+ bstp_timer_start(&bs->bs_link_timer, BSTP_LINK_TIMER);
+}
+
+struct bstp_state *
+bstp_create(struct ifnet *ifp)
+{
+ struct bstp_state *bs;
+ int s;
+
+ s = splnet();
+ bs = (struct bstp_state *)malloc(sizeof(*bs), M_DEVBUF, M_WAITOK);
+ bzero(bs, sizeof(*bs));
+ LIST_INIT(&bs->bs_bplist);
+
+ bs->bs_ifp = ifp;
+ bs->bs_bridge_max_age = BSTP_DEFAULT_MAX_AGE;
+ bs->bs_bridge_htime = BSTP_DEFAULT_HELLO_TIME;
+ bs->bs_bridge_fdelay = BSTP_DEFAULT_FORWARD_DELAY;
+ bs->bs_bridge_priority = BSTP_DEFAULT_BRIDGE_PRIORITY;
+ bs->bs_hold_time = BSTP_DEFAULT_HOLD_TIME;
+ bs->bs_migration_delay = BSTP_DEFAULT_MIGRATE_DELAY;
+ bs->bs_txholdcount = BSTP_DEFAULT_HOLD_COUNT;
+ bs->bs_protover = BSTP_PROTO_RSTP; /* STP instead of RSTP? */
+
+ getmicrotime(&bs->bs_last_tc_time);
+
+ LIST_INSERT_HEAD(&bstp_list, bs, bs_list);
+ splx(s);
+
+ return (bs);
+}
+
+void
+bstp_destroy(struct bstp_state *bs)
+{
+ int s;
+
+ if (bs == NULL)
+ return;
+
+ if (!LIST_EMPTY(&bs->bs_bplist))
+ panic("bstp still active");
+
+ s = splnet();
+ LIST_REMOVE(bs, bs_list);
+ free(bs, M_DEVBUF);
+ splx(s);
+}
+
+void
+bstp_stop(struct bstp_state *bs)
+{
+ struct bstp_port *bp;
+
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next)
+ bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
+
+ if (timeout_initialized(&bs->bs_bstptimeout) &&
+ timeout_pending(&bs->bs_bstptimeout))
+ timeout_del(&bs->bs_bstptimeout);
+}
+
+struct bstp_port *
+bstp_add(struct bstp_state *bs, struct ifnet *ifp)
+{
+ struct bstp_port *bp;
+
+ switch (ifp->if_type) {
+ case IFT_ETHER: /* These can do spanning tree. */
+ break;
+ default:
+ /* Nothing else can. */
+ return (NULL);
+ }
+
+ bp = (struct bstp_port *)malloc(sizeof(*bp), M_DEVBUF, M_NOWAIT);
+ if (bp == NULL)
+ return (NULL);
+ bzero(bp, sizeof(*bp));
+
+ bp->bp_ifp = ifp;
+ bp->bp_bs = bs;
+ bp->bp_priority = BSTP_DEFAULT_PORT_PRIORITY;
+ bp->bp_txcount = 0;
+
+ /* Init state */
+ bp->bp_infois = BSTP_INFO_DISABLED;
+ bp->bp_flags = BSTP_PORT_AUTOEDGE | BSTP_PORT_AUTOP2P;
+ bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
+ bstp_set_port_proto(bp, bs->bs_protover);
+ bstp_set_port_role(bp, BSTP_ROLE_DISABLED);
+ bstp_set_port_tc(bp, BSTP_TCSTATE_INACTIVE);
+ bp->bp_path_cost = bstp_calc_path_cost(bp);
+
+ LIST_INSERT_HEAD(&bs->bs_bplist, bp, bp_next);
+
+ bp->bp_active = 1;
+ bp->bp_flags |= BSTP_PORT_NEWINFO;
+ bstp_initialization(bs);
+ bstp_update_roles(bs, bp);
+
+ /* Register callback for physical link state changes */
+ if (ifp->if_linkstatehooks != NULL)
+ bp->bp_lhcookie = hook_establish(ifp->if_linkstatehooks, 1,
+ bstp_ifstate, ifp);
+
+ return (bp);
+}
+void
+bstp_delete(struct bstp_port *bp)
+{
+ struct bstp_state *bs = bp->bp_bs;
+ struct ifnet *ifp = bp->bp_ifp;
+
+ if (!bp->bp_active)
+ panic("not a bstp member");
+
+ if (ifp != NULL && ifp->if_linkstatehooks != NULL)
+ hook_disestablish(ifp->if_linkstatehooks, bp->bp_lhcookie);
+
+ LIST_REMOVE(bp, bp_next);
+ bp->bp_bs = NULL;
+ bp->bp_active = 0;
+ free(bp, M_DEVBUF);
+ bstp_initialization(bs);
+}
+
+u_int8_t
+bstp_getstate(struct bstp_state *bs, struct bstp_port *bp)
+{
+ u_int8_t state = bp->bp_state;
+
+ if (bs->bs_protover != BSTP_PROTO_STP)
+ return (state);
+
+ /*
+ * Translate RSTP roles and states to STP port states
+ * (IEEE Std 802.1D-2004 Table 17-1).
+ */
+ if (bp->bp_role == BSTP_ROLE_DISABLED)
+ state = BSTP_IFSTATE_DISABLED;
+ else if (bp->bp_role == BSTP_ROLE_ALTERNATE ||
+ bp->bp_role == BSTP_ROLE_BACKUP)
+ state = BSTP_IFSTATE_BLOCKING;
+ else if (state == BSTP_IFSTATE_DISCARDING)
+ state = BSTP_IFSTATE_LISTENING;
+
+ return (state);
+}
+
+void
+bstp_ifsflags(struct bstp_port *bp, u_int flags)
+{
+ struct bstp_state *bs;
+
+ if ((flags & IFBIF_STP) == 0)
+ return;
+ bs = bp->bp_bs;
+
+ /*
+ * Set edge status
+ */
+ if (flags & IFBIF_BSTP_AUTOEDGE) {
+ if ((bp->bp_flags & BSTP_PORT_AUTOEDGE) == 0) {
+ bp->bp_flags |= BSTP_PORT_AUTOEDGE;
+
+ /* we may be able to transition straight to edge */
+ if (bp->bp_edge_delay_timer.active == 0)
+ bstp_edge_delay_expiry(bs, bp);
+ }
+ } else
+ bp->bp_flags &= ~BSTP_PORT_AUTOEDGE;
+
+ if (flags & IFBIF_BSTP_EDGE)
+ bp->bp_operedge = 1;
+ else
+ bp->bp_operedge = 0;
+
+ /*
+ * Set point to point status
+ */
+ if (flags & IFBIF_BSTP_AUTOP2P) {
+ if ((bp->bp_flags & BSTP_PORT_AUTOP2P) == 0) {
+ bp->bp_flags |= BSTP_PORT_AUTOP2P;
+
+ bstp_ifupdstatus(bs, bp);
+ }
+ } else
+ bp->bp_flags &= ~BSTP_PORT_AUTOP2P;
+
+ if (flags & IFBIF_BSTP_P2P)
+ bp->bp_p2p_link = 1;
+ else
+ bp->bp_p2p_link = 0;
}
int
-bstp_ioctl(ifp, cmd, data)
- struct ifnet *ifp;
- u_long cmd;
- caddr_t data;
+bstp_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
struct bridge_softc *sc = (struct bridge_softc *)ifp;
- struct ifbrparam *bp = (struct ifbrparam *)data;
- int r = 0, err = 0;
+ struct bstp_state *bs = sc->sc_stp;
+ struct ifbrparam *ifbp = (struct ifbrparam *)data;
+ struct ifbreq *ifbr = (struct ifbreq *)data;
+ struct bridge_iflist *p;
+ struct ifnet *ifs;
+ struct bstp_port *bp;
+ int r = 0, err = 0, val;
switch (cmd) {
- case SIOCBRDGGPRI:
- bp->ifbrp_prio = sc->sc_bridge_priority;
- break;
- case SIOCBRDGGMA:
- bp->ifbrp_maxage = sc->sc_bridge_max_age >> 8;
+ case SIOCBRDGSIFPRIO:
+ case SIOCBRDGSIFCOST:
+ ifs = ifunit(ifbr->ifbr_ifsname);
+ if (ifs == NULL) {
+ err = ENOENT;
+ break;
+ }
+ if ((caddr_t)sc != ifs->if_bridge) {
+ err = ESRCH;
+ break;
+ }
+ LIST_FOREACH(p, &sc->sc_iflist, next) {
+ if (p->ifp == ifs)
+ break;
+ }
+ if (p == LIST_END(&sc->sc_iflist)) {
+ err = ESRCH;
+ break;
+ }
+ if ((p->bif_flags & IFBIF_STP) == 0) {
+ err = EINVAL;
+ break;
+ }
+ bp = p->bif_stp;
break;
- case SIOCBRDGGHT:
- bp->ifbrp_hellotime = sc->sc_bridge_hello_time >> 8;
+ default:
break;
- case SIOCBRDGGFD:
- bp->ifbrp_fwddelay = sc->sc_bridge_forward_delay >> 8;
+ }
+ if (err)
+ return (err);
+
+ switch (cmd) {
+ case SIOCBRDGGPRI:
+ ifbp->ifbrp_prio = bs->bs_bridge_priority;
break;
case SIOCBRDGSPRI:
- sc->sc_bridge_priority = bp->ifbrp_prio;
+ val = ifbp->ifbrp_prio;
+ if (val < 0 || val > BSTP_MAX_PRIORITY) {
+ err = EINVAL;
+ break;
+ }
+
+ /* Limit to steps of 4096 */
+ val -= val % 4096;
+ bs->bs_bridge_priority = val;
r = 1;
break;
+ case SIOCBRDGGMA:
+ ifbp->ifbrp_maxage = bs->bs_bridge_max_age >> 8;
+ break;
case SIOCBRDGSMA:
- if (bp->ifbrp_maxage == 0) {
+ val = ifbp->ifbrp_maxage;
+
+ /* convert seconds to ticks */
+ val *= BSTP_TICK_VAL;
+
+ if (val < BSTP_MIN_MAX_AGE || val > BSTP_MAX_MAX_AGE) {
err = EINVAL;
break;
}
- sc->sc_bridge_max_age = bp->ifbrp_maxage << 8;
+ bs->bs_bridge_max_age = val;
r = 1;
break;
+ case SIOCBRDGGHT:
+ ifbp->ifbrp_hellotime = bs->bs_bridge_htime >> 8;
+ break;
case SIOCBRDGSHT:
- if (bp->ifbrp_hellotime == 0) {
+ val = ifbp->ifbrp_hellotime;
+
+ /* convert seconds to ticks */
+ val *= BSTP_TICK_VAL;
+
+ /* value can only be changed in leagacy stp mode */
+ if (bs->bs_protover != BSTP_PROTO_STP) {
+ err = EPERM;
+ break;
+ }
+ if (val < BSTP_MIN_HELLO_TIME || val > BSTP_MAX_HELLO_TIME) {
err = EINVAL;
break;
}
- sc->sc_bridge_hello_time = bp->ifbrp_hellotime << 8;
+ bs->bs_bridge_htime = val;
r = 1;
break;
+ case SIOCBRDGGFD:
+ ifbp->ifbrp_fwddelay = bs->bs_bridge_fdelay >> 8;
+ break;
case SIOCBRDGSFD:
- if (bp->ifbrp_fwddelay == 0) {
+ val = ifbp->ifbrp_fwddelay;
+
+ /* convert seconds to ticks */
+ val *= BSTP_TICK_VAL;
+
+ if (val < BSTP_MIN_FORWARD_DELAY ||
+ val > BSTP_MAX_FORWARD_DELAY) {
err = EINVAL;
break;
}
- sc->sc_bridge_forward_delay = bp->ifbrp_fwddelay << 8;
+ bs->bs_bridge_fdelay = val;
r = 1;
break;
- case SIOCBRDGADD:
- case SIOCBRDGDEL:
- case SIOCBRDGSIFFLGS:
+ case SIOCBRDGSTXHC:
+ val = ifbp->ifbrp_txhc;
+
+ if (val < BSTP_MIN_HOLD_COUNT || val > BSTP_MAX_HOLD_COUNT) {
+ err = EINVAL;
+ break;
+ }
+ bs->bs_txholdcount = val;
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next)
+ bp->bp_txcount = 0;
+ break;
case SIOCBRDGSIFPRIO:
+ val = ifbr->ifbr_priority;
+ if (val < 0 || val > BSTP_MAX_PORT_PRIORITY)
+ return (EINVAL);
+
+ /* Limit to steps of 16 */
+ val -= val % 16;
+ bp->bp_priority = val;
+ r = 1;
+ break;
case SIOCBRDGSIFCOST:
+ val = ifbr->ifbr_path_cost;
+ if (val > BSTP_MAX_PATH_COST) {
+ err = EINVAL;
+ break;
+ }
+ if (val == 0) { /* use auto */
+ bp->bp_flags &= ~BSTP_PORT_ADMCOST;
+ bp->bp_path_cost = bstp_calc_path_cost(bp);
+ } else {
+ bp->bp_path_cost = val;
+ bp->bp_flags |= BSTP_PORT_ADMCOST;
+ }
r = 1;
break;
+ case SIOCBRDGSPROTO:
+ val = ifbp->ifbrp_proto;
+
+ /* Supported protocol versions */
+ switch (val) {
+ case BSTP_PROTO_STP:
+ case BSTP_PROTO_RSTP:
+ bs->bs_protover = val;
+ bs->bs_bridge_htime = BSTP_DEFAULT_HELLO_TIME;
+ LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
+ /* reinit state */
+ bp->bp_infois = BSTP_INFO_DISABLED;
+ bp->bp_txcount = 0;
+ bstp_set_port_proto(bp, bs->bs_protover);
+ bstp_set_port_role(bp, BSTP_ROLE_DISABLED);
+ bstp_set_port_tc(bp, BSTP_TCSTATE_INACTIVE);
+ bstp_timer_stop(&bp->bp_recent_backup_timer);
+ }
+ r = 1;
+ break;
+ default:
+ err = EINVAL;
+ }
+ break;
default:
break;
}
if (r)
- bstp_initialization(sc);
+ bstp_initialization(bs);
return (err);
}
-
#endif /* NBRIDGE */
diff --git a/sys/net/if.c b/sys/net/if.c
index fe3a6bcc463..6e157e572c1 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.152 2006/11/24 20:57:46 canacar Exp $ */
+/* $OpenBSD: if.c,v 1.153 2006/12/03 13:41:19 reyk Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -1029,6 +1029,10 @@ if_down(struct ifnet *ifp)
if (ifp->if_carp)
carp_carpdev_state(ifp);
#endif
+#if NBRIDGE > 0
+ if (ifp->if_bridge)
+ bstp_ifstate(ifp);
+#endif
rt_ifmsg(ifp);
}
@@ -1058,6 +1062,10 @@ if_up(struct ifnet *ifp)
if (ifp->if_carp)
carp_carpdev_state(ifp);
#endif
+#if NBRIDGE > 0
+ if (ifp->if_bridge)
+ bstp_ifstate(ifp);
+#endif
rt_ifmsg(ifp);
#ifdef INET6
in6_if_up(ifp);
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
index e2c90680014..b92d931210f 100644
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_bridge.c,v 1.153 2006/11/30 13:25:03 henning Exp $ */
+/* $OpenBSD: if_bridge.c,v 1.154 2006/12/03 13:41:19 reyk Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
@@ -101,15 +101,6 @@
#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
*/
@@ -168,6 +159,7 @@ int bridge_ipsec(struct bridge_softc *, struct ifnet *,
#endif
int bridge_clone_create(struct if_clone *, int);
int bridge_clone_destroy(struct ifnet *ifp);
+int bridge_delete(struct bridge_softc *, struct bridge_iflist *);
#define ETHERADDR_IS_IP_MCAST(a) \
/* struct etheraddr *a; */ \
@@ -186,6 +178,7 @@ bridgeattach(int n)
{
LIST_INIT(&bridge_list);
if_clone_attach(&bridge_cloner);
+ bstp_attach(n);
}
int
@@ -200,13 +193,14 @@ bridge_clone_create(struct if_clone *ifc, int unit)
return (ENOMEM);
bzero(sc, sizeof(*sc));
+ sc->sc_stp = bstp_create(&sc->sc_if);
+ if (!sc->sc_stp) {
+ free(sc, M_DEVBUF);
+ return (ENOMEM);
+ }
+
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;
timeout_set(&sc->sc_brtimeout, bridge_timer, sc);
LIST_INIT(&sc->sc_iflist);
LIST_INIT(&sc->sc_spanlist);
@@ -214,7 +208,7 @@ bridge_clone_create(struct if_clone *ifc, int unit)
LIST_INIT(&sc->sc_rts[i]);
sc->sc_hashkey = arc4random();
ifp = &sc->sc_if;
- snprintf(ifp->if_xname, sizeof ifp->if_xname, "%s%d", ifc->ifc_name,
+ snprintf(ifp->if_xname, sizeof ifp->if_xname, "%s%d", ifc->ifc_name,
unit);
ifp->if_softc = sc;
ifp->if_mtu = ETHERMTU;
@@ -222,14 +216,18 @@ bridge_clone_create(struct if_clone *ifc, int unit)
ifp->if_output = bridge_output;
ifp->if_start = bridge_start;
ifp->if_type = IFT_BRIDGE;
- ifp->if_snd.ifq_maxlen = ifqmaxlen;
ifp->if_hdrlen = ETHER_HDR_LEN;
+ IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
+ IFQ_SET_READY(&ifp->if_snd);
+
if_attach(ifp);
if_alloc_sadl(ifp);
+
#if NBPFILTER > 0
bpfattach(&sc->sc_if.if_bpf, ifp,
DLT_EN10MB, ETHER_HDR_LEN);
#endif
+
s = splnet();
LIST_INSERT_HEAD(&bridge_list, sc, sc_list);
splx(s);
@@ -246,14 +244,8 @@ bridge_clone_destroy(struct ifnet *ifp)
bridge_stop(sc);
bridge_rtflush(sc, IFBF_FLUSHALL);
- while ((bif = LIST_FIRST(&sc->sc_iflist)) != NULL) {
- /* XXX shared with ioctl and detach */
- /* XXX promisc disable? */
- LIST_REMOVE(bif, next);
- bridge_flushrule(bif);
- bif->ifp->if_bridge = NULL;
- free(bif, M_DEVBUF);
- }
+ while ((bif = LIST_FIRST(&sc->sc_iflist)) != NULL)
+ bridge_delete(sc, bif);
while ((bif = LIST_FIRST(&sc->sc_spanlist)) != NULL) {
LIST_REMOVE(bif, next);
free(bif, M_DEVBUF);
@@ -263,6 +255,7 @@ bridge_clone_destroy(struct ifnet *ifp)
LIST_REMOVE(sc, sc_list);
splx(s);
+ bstp_destroy(sc->sc_stp);
if_detach(ifp);
free(sc, M_DEVBUF);
@@ -270,26 +263,43 @@ bridge_clone_destroy(struct ifnet *ifp)
}
int
+bridge_delete(struct bridge_softc *sc, struct bridge_iflist *p)
+{
+ int error;
+
+ if (p->bif_flags & IFBIF_STP)
+ bstp_delete(p->bif_stp);
+
+ p->ifp->if_bridge = NULL;
+ error = ifpromisc(p->ifp, 0);
+
+ LIST_REMOVE(p, next);
+ bridge_rtdelete(sc, p->ifp, 0);
+ bridge_flushrule(p);
+ free(p, M_DEVBUF);
+
+ return (error);
+}
+
+int
bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
- struct proc *prc = curproc; /* XXX */
- struct ifnet *ifs;
struct bridge_softc *sc = (struct bridge_softc *)ifp->if_softc;
struct ifbreq *req = (struct ifbreq *)data;
- struct ifbaconf *baconf = (struct ifbaconf *)data;
struct ifbareq *bareq = (struct ifbareq *)data;
struct ifbrparam *bparam = (struct ifbrparam *)data;
- struct ifbifconf *bifconf = (struct ifbifconf *)data;
struct ifbrlreq *brlreq = (struct ifbrlreq *)data;
- struct ifbrlconf *brlconf = (struct ifbrlconf *)data;
- struct ifreq ifreq;
- int error = 0, s;
+ struct ifbropreq *brop = (struct ifbropreq *)data;
+ struct ifnet *ifs;
struct bridge_iflist *p;
+ struct bstp_port *bp;
+ struct bstp_state *bs = sc->sc_stp;
+ int error = 0, s;
s = splnet();
switch (cmd) {
case SIOCBRDGADD:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
ifs = ifunit(req->ifbr_ifsname);
@@ -318,6 +328,8 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
if (ifs->if_type == IFT_ETHER) {
if ((ifs->if_flags & IFF_UP) == 0) {
+ struct ifreq ifreq;
+
/*
* Bring interface up long enough to set
* promiscuous flag, then shut it down again.
@@ -361,7 +373,7 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
break;
}
- p = (struct bridge_iflist *) malloc(
+ p = (struct bridge_iflist *)malloc(
sizeof(struct bridge_iflist), M_DEVBUF, M_NOWAIT);
if (p == NULL) {
if (ifs->if_type == IFT_ETHER)
@@ -373,41 +385,33 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
p->ifp = ifs;
p->bif_flags = IFBIF_LEARNING | IFBIF_DISCOVER;
- p->bif_priority = BSTP_DEFAULT_PORT_PRIORITY;
- p->bif_path_cost = BSTP_DEFAULT_PATH_COST;
SIMPLEQ_INIT(&p->bif_brlin);
SIMPLEQ_INIT(&p->bif_brlout);
- LIST_INSERT_HEAD(&sc->sc_iflist, p, next);
ifs->if_bridge = (caddr_t)sc;
+ LIST_INSERT_HEAD(&sc->sc_iflist, p, next);
break;
case SIOCBRDGDEL:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
LIST_FOREACH(p, &sc->sc_iflist, next) {
if (strncmp(p->ifp->if_xname, req->ifbr_ifsname,
sizeof(p->ifp->if_xname)) == 0) {
- p->ifp->if_bridge = NULL;
-
- error = ifpromisc(p->ifp, 0);
-
- LIST_REMOVE(p, next);
- bridge_rtdelete(sc, p->ifp, 0);
- bridge_flushrule(p);
- free(p, M_DEVBUF);
+ error = bridge_delete(sc, p);
+ p = NULL;
break;
}
}
- if (p == LIST_END(&sc->sc_iflist)) {
+ if (p != NULL && p == LIST_END(&sc->sc_iflist)) {
error = ENOENT;
break;
}
break;
case SIOCBRDGIFS:
- error = bridge_bifconf(sc, bifconf);
+ error = bridge_bifconf(sc, (struct ifbifconf *)data);
break;
case SIOCBRDGADDS:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
ifs = ifunit(req->ifbr_ifsname);
if (ifs == NULL) { /* no such interface */
@@ -438,12 +442,13 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
}
bzero(p, sizeof(struct bridge_iflist));
p->ifp = ifs;
+ p->bif_flags = IFBIF_SPAN;
SIMPLEQ_INIT(&p->bif_brlin);
SIMPLEQ_INIT(&p->bif_brlout);
LIST_INSERT_HEAD(&sc->sc_spanlist, p, next);
break;
case SIOCBRDGDELS:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
LIST_FOREACH(p, &sc->sc_spanlist, next) {
if (strncmp(p->ifp->if_xname, req->ifbr_ifsname,
@@ -477,13 +482,35 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
break;
}
req->ifbr_ifsflags = p->bif_flags;
- req->ifbr_state = p->bif_state;
- req->ifbr_priority = p->bif_priority;
- req->ifbr_path_cost = p->bif_path_cost;
- req->ifbr_portno = p->ifp->if_index & 0xff;
+ req->ifbr_portno = p->ifp->if_index & 0xfff;
+ if (p->bif_flags & IFBIF_STP) {
+ bp = p->bif_stp;
+ req->ifbr_state = bstp_getstate(bs, bp);
+ req->ifbr_priority = bp->bp_priority;
+ req->ifbr_path_cost = bp->bp_path_cost;
+ req->ifbr_proto = bp->bp_protover;
+ req->ifbr_role = bp->bp_role;
+ req->ifbr_stpflags = bp->bp_flags;
+ req->ifbr_fwd_trans = bp->bp_forward_transitions;
+ req->ifbr_desg_bridge = bp->bp_desg_pv.pv_dbridge_id;
+ req->ifbr_desg_port = bp->bp_desg_pv.pv_dport_id;
+ req->ifbr_root_bridge = bp->bp_desg_pv.pv_root_id;
+ req->ifbr_root_cost = bp->bp_desg_pv.pv_cost;
+ req->ifbr_root_port = bp->bp_desg_pv.pv_port_id;
+
+ /* Copy STP state options as flags */
+ if (bp->bp_operedge)
+ req->ifbr_ifsflags |= IFBIF_BSTP_EDGE;
+ if (bp->bp_flags & BSTP_PORT_AUTOEDGE)
+ req->ifbr_ifsflags |= IFBIF_BSTP_AUTOEDGE;
+ if (bp->bp_p2p_link)
+ req->ifbr_ifsflags |= IFBIF_BSTP_P2P;
+ if (bp->bp_flags & BSTP_PORT_AUTOP2P)
+ req->ifbr_ifsflags |= IFBIF_BSTP_AUTOP2P;
+ }
break;
case SIOCBRDGSIFFLGS:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
ifs = ifunit(req->ifbr_ifsname);
if (ifs == NULL) {
@@ -506,54 +533,35 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
error = EINVAL;
break;
}
- if ((req->ifbr_ifsflags & IFBIF_STP) &&
- (ifs->if_type != IFT_ETHER)) {
- error = EINVAL;
- break;
+ if (req->ifbr_ifsflags & IFBIF_STP) {
+ if ((p->bif_flags & IFBIF_STP) == 0) {
+ /* Enable STP */
+ if ((p->bif_stp = bstp_add(sc->sc_stp,
+ p->ifp)) == NULL) {
+ error = ENOMEM;
+ break;
+ }
+ } else {
+ /* Update STP flags */
+ bstp_ifsflags(p->bif_stp, req->ifbr_ifsflags);
+ }
+ } else if (p->bif_flags & IFBIF_STP) {
+ bstp_delete(p->bif_stp);
+ p->bif_stp = NULL;
}
p->bif_flags = req->ifbr_ifsflags;
break;
- case SIOCBRDGSIFPRIO:
- case SIOCBRDGSIFCOST:
- if ((error = suser(prc, 0)) != 0)
- break;
- ifs = ifunit(req->ifbr_ifsname);
- if (ifs == NULL) {
- error = ENOENT;
- break;
- }
- if ((caddr_t)sc != ifs->if_bridge) {
- error = ESRCH;
- break;
- }
- LIST_FOREACH(p, &sc->sc_iflist, next) {
- if (p->ifp == ifs)
- break;
- }
- if (p == LIST_END(&sc->sc_iflist)) {
- error = ESRCH;
- break;
- }
- if (cmd == SIOCBRDGSIFPRIO)
- p->bif_priority = req->ifbr_priority;
- else {
- if (req->ifbr_path_cost < 1)
- error = EINVAL;
- else
- p->bif_path_cost = req->ifbr_path_cost;
- }
- break;
case SIOCBRDGRTS:
- error = bridge_rtfind(sc, baconf);
+ error = bridge_rtfind(sc, (struct ifbaconf *)data);
break;
case SIOCBRDGFLUSH:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
error = bridge_rtflush(sc, req->ifbr_ifsflags);
break;
case SIOCBRDGSADDR:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
ifs = ifunit(bareq->ifba_ifsname);
@@ -574,7 +582,7 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
error = ENOMEM;
break;
case SIOCBRDGDADDR:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
error = bridge_rtdaddr(sc, &bareq->ifba_dst);
break;
@@ -582,13 +590,13 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
bparam->ifbrp_csize = sc->sc_brtmax;
break;
case SIOCBRDGSCACHE:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
sc->sc_brtmax = bparam->ifbrp_csize;
bridge_rttrim(sc);
break;
case SIOCBRDGSTO:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
if (bparam->ifbrp_ctime < 0 ||
bparam->ifbrp_ctime > INT_MAX / hz) {
@@ -612,7 +620,7 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
break;
case SIOCBRDGARL:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
ifs = ifunit(brlreq->ifbr_ifsname);
if (ifs == NULL) {
@@ -650,7 +658,7 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
}
break;
case SIOCBRDGFRL:
- if ((error = suser(prc, 0)) != 0)
+ if ((error = suser(curproc, 0)) != 0)
break;
ifs = ifunit(brlreq->ifbr_ifsname);
if (ifs == NULL) {
@@ -673,7 +681,25 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
error = bridge_flushrule(p);
break;
case SIOCBRDGGRL:
- error = bridge_brlconf(sc, brlconf);
+ error = bridge_brlconf(sc, (struct ifbrlconf *)data);
+ break;
+ case SIOCBRDGGPARAM:
+ if ((bp = bs->bs_root_port) == NULL)
+ brop->ifbop_root_port = 0;
+ else
+ brop->ifbop_root_port = bp->bp_ifp->if_index;
+ brop->ifbop_maxage = bs->bs_bridge_max_age >> 8;
+ brop->ifbop_hellotime = bs->bs_bridge_htime >> 8;
+ brop->ifbop_fwddelay = bs->bs_bridge_fdelay >> 8;
+ brop->ifbop_holdcount = bs->bs_txholdcount;
+ brop->ifbop_priority = bs->bs_bridge_priority;
+ brop->ifbop_protocol = bs->bs_protover;
+ brop->ifbop_root_bridge = bs->bs_root_pv.pv_root_id;
+ brop->ifbop_root_path_cost = bs->bs_root_pv.pv_cost;
+ brop->ifbop_root_port = bs->bs_root_pv.pv_port_id;
+ brop->ifbop_desg_bridge = bs->bs_root_pv.pv_dbridge_id;
+ brop->ifbop_last_tc_time.tv_sec = bs->bs_last_tc_time.tv_sec;
+ brop->ifbop_last_tc_time.tv_usec = bs->bs_last_tc_time.tv_usec;
break;
case SIOCBRDGGPRI:
case SIOCBRDGGMA:
@@ -684,10 +710,15 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
case SIOCBRDGSFD:
case SIOCBRDGSMA:
case SIOCBRDGSHT:
- error = suser(prc, 0);
+ case SIOCBRDGSTXHC:
+ case SIOCBRDGSPROTO:
+ case SIOCBRDGSIFPRIO:
+ case SIOCBRDGSIFCOST:
+ error = suser(curproc, 0);
break;
default:
error = EINVAL;
+ break;
}
if (!error)
@@ -736,9 +767,7 @@ bridge_update(struct ifnet *ifp, struct ether_addr *ea, int delete)
addr[3] == 0 && addr[4] == 0 && addr[5] == 0)) {
/* Care must be taken with spanning tree */
if ((bif->bif_flags & IFBIF_STP) &&
- (bif->bif_state == BSTP_IFSTATE_BLOCKING ||
- bif->bif_state == BSTP_IFSTATE_LISTENING ||
- bif->bif_state == BSTP_IFSTATE_DISABLED))
+ (bif->bif_state == BSTP_IFSTATE_DISCARDING))
return;
/* Delete the address from the bridge */
@@ -758,9 +787,11 @@ int
bridge_bifconf(struct bridge_softc *sc, struct ifbifconf *bifc)
{
struct bridge_iflist *p;
+ struct bstp_port *bp;
+ struct bstp_state *bs = sc->sc_stp;
u_int32_t total = 0, i = 0;
int error = 0;
- struct ifbreq breq;
+ struct ifbreq *breq = NULL;
LIST_FOREACH(p, &sc->sc_iflist, next)
total++;
@@ -773,45 +804,70 @@ bridge_bifconf(struct bridge_softc *sc, struct ifbifconf *bifc)
goto done;
}
+ if ((breq = (struct ifbreq *)
+ malloc(sizeof(*breq), M_DEVBUF, M_NOWAIT)) == NULL)
+ goto done;
+
LIST_FOREACH(p, &sc->sc_iflist, next) {
- bzero(&breq, sizeof breq);
- if (bifc->ifbic_len < sizeof(breq))
+ bzero(breq, sizeof(*breq));
+ if (bifc->ifbic_len < sizeof(*breq))
break;
- strlcpy(breq.ifbr_name, sc->sc_if.if_xname, IFNAMSIZ);
- strlcpy(breq.ifbr_ifsname, p->ifp->if_xname, IFNAMSIZ);
- breq.ifbr_ifsflags = p->bif_flags;
- breq.ifbr_state = p->bif_state;
- breq.ifbr_priority = p->bif_priority;
- breq.ifbr_path_cost = p->bif_path_cost;
- breq.ifbr_portno = p->ifp->if_index & 0xff;
- error = copyout((caddr_t)&breq,
- (caddr_t)(bifc->ifbic_req + i), sizeof(breq));
+ strlcpy(breq->ifbr_name, sc->sc_if.if_xname, IFNAMSIZ);
+ strlcpy(breq->ifbr_ifsname, p->ifp->if_xname, IFNAMSIZ);
+ breq->ifbr_ifsflags = p->bif_flags;
+ breq->ifbr_portno = p->ifp->if_index & 0xfff;
+ if (p->bif_flags & IFBIF_STP) {
+ bp = p->bif_stp;
+ breq->ifbr_state = bstp_getstate(sc->sc_stp, bp);
+ breq->ifbr_priority = bp->bp_priority;
+ breq->ifbr_path_cost = bp->bp_path_cost;
+ breq->ifbr_proto = bp->bp_protover;
+ breq->ifbr_role = bp->bp_role;
+ breq->ifbr_stpflags = bp->bp_flags;
+ breq->ifbr_fwd_trans = bp->bp_forward_transitions;
+ breq->ifbr_root_bridge = bs->bs_root_pv.pv_root_id;
+ breq->ifbr_root_cost = bs->bs_root_pv.pv_cost;
+ breq->ifbr_root_port = bs->bs_root_pv.pv_port_id;
+ breq->ifbr_desg_bridge = bs->bs_root_pv.pv_dbridge_id;
+ breq->ifbr_desg_port = bs->bs_root_pv.pv_dport_id;
+
+ /* Copy STP state options as flags */
+ if (bp->bp_operedge)
+ breq->ifbr_ifsflags |= IFBIF_BSTP_EDGE;
+ if (bp->bp_flags & BSTP_PORT_AUTOEDGE)
+ breq->ifbr_ifsflags |= IFBIF_BSTP_AUTOEDGE;
+ if (bp->bp_p2p_link)
+ breq->ifbr_ifsflags |= IFBIF_BSTP_P2P;
+ if (bp->bp_flags & BSTP_PORT_AUTOP2P)
+ breq->ifbr_ifsflags |= IFBIF_BSTP_AUTOP2P;
+ }
+ error = copyout((caddr_t)breq,
+ (caddr_t)(bifc->ifbic_req + i), sizeof(*breq));
if (error)
goto done;
i++;
- bifc->ifbic_len -= sizeof(breq);
+ bifc->ifbic_len -= sizeof(*breq);
}
LIST_FOREACH(p, &sc->sc_spanlist, next) {
- bzero(&breq, sizeof breq);
- if (bifc->ifbic_len < sizeof(breq))
+ bzero(breq, sizeof(*breq));
+ if (bifc->ifbic_len < sizeof(*breq))
break;
- strlcpy(breq.ifbr_name, sc->sc_if.if_xname, IFNAMSIZ);
- strlcpy(breq.ifbr_ifsname, p->ifp->if_xname, IFNAMSIZ);
- breq.ifbr_ifsflags = p->bif_flags | IFBIF_SPAN;
- breq.ifbr_state = p->bif_state;
- breq.ifbr_priority = p->bif_priority;
- breq.ifbr_path_cost = p->bif_path_cost;
- breq.ifbr_portno = p->ifp->if_index & 0xff;
- error = copyout((caddr_t)&breq,
- (caddr_t)(bifc->ifbic_req + i), sizeof(breq));
+ strlcpy(breq->ifbr_name, sc->sc_if.if_xname, IFNAMSIZ);
+ strlcpy(breq->ifbr_ifsname, p->ifp->if_xname, IFNAMSIZ);
+ breq->ifbr_ifsflags = p->bif_flags | IFBIF_SPAN;
+ breq->ifbr_portno = p->ifp->if_index & 0xfff;
+ error = copyout((caddr_t)breq,
+ (caddr_t)(bifc->ifbic_req + i), sizeof(*breq));
if (error)
goto done;
i++;
- bifc->ifbic_len -= sizeof(breq);
+ bifc->ifbic_len -= sizeof(*breq);
}
done:
- bifc->ifbic_len = i * sizeof(breq);
+ if (breq != NULL)
+ free(breq, M_DEVBUF);
+ bifc->ifbic_len = i * sizeof(*breq);
return (error);
}
@@ -909,7 +965,7 @@ bridge_init(struct bridge_softc *sc)
return;
ifp->if_flags |= IFF_RUNNING;
- bstp_initialization(sc);
+ bstp_initialization(sc->sc_stp);
if (sc->sc_brttimeout != 0)
timeout_add(&sc->sc_brtimeout, sc->sc_brttimeout * hz);
@@ -1023,7 +1079,7 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *sa,
*/
if (dst_if != ifp &&
(p->bif_flags & IFBIF_STP) &&
- (p->bif_state != BSTP_IFSTATE_FORWARDING))
+ (p->bif_state == BSTP_IFSTATE_DISCARDING))
continue;
if ((p->bif_flags & IFBIF_DISCOVER) == 0 &&
@@ -1160,9 +1216,7 @@ bridgeintr_frame(struct bridge_softc *sc, struct mbuf *m)
}
if ((ifl->bif_flags & IFBIF_STP) &&
- (ifl->bif_state == BSTP_IFSTATE_BLOCKING ||
- ifl->bif_state == BSTP_IFSTATE_LISTENING ||
- ifl->bif_state == BSTP_IFSTATE_DISABLED)) {
+ (ifl->bif_state == BSTP_IFSTATE_DISCARDING)) {
m_freem(m);
return;
}
@@ -1283,8 +1337,7 @@ bridgeintr_frame(struct bridge_softc *sc, struct mbuf *m)
return;
}
if ((ifl->bif_flags & IFBIF_STP) &&
- (ifl->bif_state == BSTP_IFSTATE_DISABLED ||
- ifl->bif_state == BSTP_IFSTATE_BLOCKING)) {
+ (ifl->bif_state == BSTP_IFSTATE_DISCARDING)) {
m_freem(m);
return;
}
@@ -1348,19 +1401,16 @@ bridge_input(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m)
if (m->m_flags & (M_BCAST | M_MCAST)) {
/* Tap off 802.1D packets, they do not get forwarded */
if (bcmp(eh->ether_dhost, bstp_etheraddr, ETHER_ADDR_LEN) == 0) {
- m = bstp_input(sc, ifp, eh, m);
+ m = bstp_input(sc->sc_stp, ifl->bif_stp, eh, m);
if (m == NULL)
return (NULL);
}
/*
- * No need to queue frames for ifs in the blocking, disabled,
- * or listening state
+ * No need to queue frames for ifs in the discarding state
*/
if ((ifl->bif_flags & IFBIF_STP) &&
- ((ifl->bif_state == BSTP_IFSTATE_BLOCKING) ||
- (ifl->bif_state == BSTP_IFSTATE_LISTENING) ||
- (ifl->bif_state == BSTP_IFSTATE_DISABLED)))
+ (ifl->bif_state == BSTP_IFSTATE_DISCARDING))
return (m);
/*
@@ -1400,16 +1450,12 @@ bridge_input(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m)
}
/*
- * No need to queue frames for ifs in the blocking, disabled, or
- * listening state
+ * No need to queue frames for ifs in the discarding state
*/
if ((ifl->bif_flags & IFBIF_STP) &&
- ((ifl->bif_state == BSTP_IFSTATE_BLOCKING) ||
- (ifl->bif_state == BSTP_IFSTATE_LISTENING) ||
- (ifl->bif_state == BSTP_IFSTATE_DISABLED)))
+ (ifl->bif_state == BSTP_IFSTATE_DISCARDING))
return (m);
-
/*
* Unicast, make sure it's not for us.
*/
@@ -1493,7 +1539,7 @@ bridge_broadcast(struct bridge_softc *sc, struct ifnet *ifp,
continue;
if ((p->bif_flags & IFBIF_STP) &&
- (p->bif_state != BSTP_IFSTATE_FORWARDING))
+ (p->bif_state == BSTP_IFSTATE_DISCARDING))
continue;
if ((p->bif_flags & IFBIF_DISCOVER) == 0 &&
@@ -1860,6 +1906,38 @@ bridge_rtage(struct bridge_softc *sc)
timeout_add(&sc->sc_brtimeout, sc->sc_brttimeout * hz);
}
+void
+bridge_rtagenode(struct ifnet *ifp, int age)
+{
+ struct bridge_softc *sc = (struct bridge_softc *)ifp->if_bridge;
+ struct bridge_rtnode *n;
+ int i;
+
+ if (sc == NULL)
+ return;
+
+ /*
+ * If the age is zero then flush, otherwise set all the expiry times to
+ * age for the interface
+ */
+ if (age == 0)
+ bridge_rtdelete(sc, ifp, 1);
+ else {
+ for (i = 0; i < BRIDGE_RTABLE_SIZE; i++) {
+ n = LIST_FIRST(&sc->sc_rts[i]);
+ while (n != LIST_END(&sc->sc_rts[i])) {
+ /* Cap the expiry time to 'age' */
+ if (n->brt_if == ifp &&
+ n->brt_age > time_uptime + age &&
+ (n->brt_flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC)
+ n->brt_age = time_uptime + age;
+ }
+ }
+ }
+}
+
+
+
/*
* Remove all dynamic addresses from the cache
*/
diff --git a/sys/net/if_bridge.h b/sys/net/if_bridge.h
index 24e2abd2567..6401e8ec2f7 100644
--- a/sys/net/if_bridge.h
+++ b/sys/net/if_bridge.h
@@ -1,7 +1,8 @@
-/* $OpenBSD: if_bridge.h,v 1.29 2006/05/28 00:33:04 henning Exp $ */
+/* $OpenBSD: if_bridge.h,v 1.30 2006/12/03 13:41:19 reyk Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
+ * Copyright (c) 2006 Andrew Thompson (thompsa@FreeBSD.org)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -43,18 +44,34 @@ struct ifbreq {
char ifbr_name[IFNAMSIZ]; /* bridge ifs name */
char ifbr_ifsname[IFNAMSIZ]; /* member ifs name */
u_int32_t ifbr_ifsflags; /* member ifs flags */
+ u_int8_t ifbr_portno; /* member port number */
+
u_int8_t ifbr_state; /* member stp state */
u_int8_t ifbr_priority; /* member stp priority */
- u_int8_t ifbr_portno; /* member port number */
u_int32_t ifbr_path_cost; /* member stp path cost */
+ u_int32_t ifbr_stpflags; /* member stp flags */
+ u_int8_t ifbr_proto; /* member stp protocol */
+ u_int8_t ifbr_role; /* member stp role */
+ u_int32_t ifbr_fwd_trans; /* member stp fwd transitions */
+ u_int64_t ifbr_desg_bridge; /* member stp designated bridge */
+ u_int32_t ifbr_desg_port; /* member stp designated port */
+ u_int64_t ifbr_root_bridge; /* member stp root bridge */
+ u_int32_t ifbr_root_cost; /* member stp root cost */
+ u_int32_t ifbr_root_port; /* member stp root port */
};
+
/* SIOCBRDGIFFLGS, SIOCBRDGIFFLGS */
#define IFBIF_LEARNING 0x0001 /* ifs can learn */
#define IFBIF_DISCOVER 0x0002 /* ifs sends packets w/unknown dest */
#define IFBIF_BLOCKNONIP 0x0004 /* ifs blocks non-IP/ARP in/out */
#define IFBIF_STP 0x0008 /* ifs participates in spanning tree */
+#define IFBIF_BSTP_EDGE 0x0010 /* member stp edge port */
+#define IFBIF_BSTP_AUTOEDGE 0x0020 /* member stp autoedge enabled */
+#define IFBIF_BSTP_P2P 0x0040 /* member stp p2p */
+#define IFBIF_BSTP_AUTOP2P 0x0080 /* member stp autop2p enabled */
#define IFBIF_SPAN 0x0100 /* ifs is a span port (ro) */
#define IFBIF_RO_MASK 0xff00 /* read only bits */
+
/* SIOCBRDGFLUSH */
#define IFBF_FLUSHDYN 0x0 /* flush dynamic addresses only */
#define IFBF_FLUSHALL 0x1 /* flush all addresses from cache */
@@ -65,6 +82,22 @@ struct ifbreq {
#define BSTP_IFSTATE_LEARNING 2
#define BSTP_IFSTATE_FORWARDING 3
#define BSTP_IFSTATE_BLOCKING 4
+#define BSTP_IFSTATE_DISCARDING 5
+
+#define BSTP_TCSTATE_ACTIVE 1
+#define BSTP_TCSTATE_DETECTED 2
+#define BSTP_TCSTATE_INACTIVE 3
+#define BSTP_TCSTATE_LEARNING 4
+#define BSTP_TCSTATE_PROPAG 5
+#define BSTP_TCSTATE_ACK 6
+#define BSTP_TCSTATE_TC 7
+#define BSTP_TCSTATE_TCN 8
+
+#define BSTP_ROLE_DISABLED 0
+#define BSTP_ROLE_ROOT 1
+#define BSTP_ROLE_DESIGNATED 2
+#define BSTP_ROLE_ALTERNATE 3
+#define BSTP_ROLE_BACKUP 4
/*
* Interface list structure
@@ -115,15 +148,43 @@ struct ifbrparam {
u_int8_t ifbrpu_hellotime; /* hello time (sec) */
u_int8_t ifbrpu_fwddelay; /* fwd delay (sec) */
u_int8_t ifbrpu_maxage; /* max age (sec) */
+ u_int8_t ifbrpu_proto; /* bridge protocol */
+ u_int8_t ifbrpu_txhc; /* bpdu tx holdcount */
} ifbrp_ifbrpu;
};
#define ifbrp_csize ifbrp_ifbrpu.ifbrpu_csize
#define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_ctime
#define ifbrp_prio ifbrp_ifbrpu.ifbrpu_prio
+#define ifbrp_proto ifbrp_ifbrpu.ifbrpu_proto
+#define ifbrp_txhc ifbrp_ifbrpu.ifbrpu_txhc
#define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_hellotime
#define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_fwddelay
#define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_maxage
+/* Protocol versions */
+#define BSTP_PROTO_ID 0x00
+#define BSTP_PROTO_STP 0x00
+#define BSTP_PROTO_RSTP 0x02
+#define BSTP_PROTO_MAX BSTP_PROTO_RSTP
+
+/*
+ * Bridge current operational parameters structure.
+ */
+struct ifbropreq {
+ char ifbop_name[IFNAMSIZ];
+ u_int8_t ifbop_holdcount;
+ u_int8_t ifbop_maxage;
+ u_int8_t ifbop_hellotime;
+ u_int8_t ifbop_fwddelay;
+ u_int8_t ifbop_protocol;
+ u_int16_t ifbop_priority;
+ u_int64_t ifbop_root_bridge;
+ u_int16_t ifbop_root_port;
+ u_int32_t ifbop_root_path_cost;
+ u_int64_t ifbop_desg_bridge;
+ struct timeval ifbop_last_tc_time;
+};
+
/*
* Bridge mac rules
*/
@@ -156,6 +217,38 @@ struct ifbrlconf {
};
#ifdef _KERNEL
+/* STP port flags */
+#define BSTP_PORT_CANMIGRATE 0x0001
+#define BSTP_PORT_NEWINFO 0x0002
+#define BSTP_PORT_DISPUTED 0x0004
+#define BSTP_PORT_ADMCOST 0x0008
+#define BSTP_PORT_AUTOEDGE 0x0010
+#define BSTP_PORT_AUTOP2P 0x0020
+
+/* BPDU priority */
+#define BSTP_PDU_SUPERIOR 1
+#define BSTP_PDU_REPEATED 2
+#define BSTP_PDU_INFERIOR 3
+#define BSTP_PDU_INFERIORALT 4
+#define BSTP_PDU_OTHER 5
+
+/* BPDU flags */
+#define BSTP_PDU_PRMASK 0x0c /* Port Role */
+#define BSTP_PDU_PRSHIFT 2 /* Port Role offset */
+#define BSTP_PDU_F_UNKN 0x00 /* Unknown port (00) */
+#define BSTP_PDU_F_ALT 0x01 /* Alt/Backup port (01) */
+#define BSTP_PDU_F_ROOT 0x02 /* Root port (10) */
+#define BSTP_PDU_F_DESG 0x03 /* Designated port (11) */
+
+#define BSTP_PDU_STPMASK 0x81 /* strip unused STP flags */
+#define BSTP_PDU_RSTPMASK 0x7f /* strip unused RSTP flags */
+#define BSTP_PDU_F_TC 0x01 /* Topology change */
+#define BSTP_PDU_F_P 0x02 /* Proposal flag */
+#define BSTP_PDU_F_L 0x10 /* Learning flag */
+#define BSTP_PDU_F_F 0x20 /* Forwarding flag */
+#define BSTP_PDU_F_A 0x40 /* Agreement flag */
+#define BSTP_PDU_F_TCA 0x80 /* Topology change ack */
+
/*
* Bridge filtering rules
*/
@@ -170,54 +263,135 @@ struct brl_node {
u_int8_t brl_flags; /* comparision flags */
};
-struct bridge_timer {
- u_int16_t active;
- u_int16_t value;
+struct bstp_timer {
+ u_int16_t active;
+ u_int16_t value;
+ u_int32_t latched;
+};
+
+struct bstp_pri_vector {
+ u_int64_t pv_root_id;
+ u_int32_t pv_cost;
+ u_int64_t pv_dbridge_id;
+ u_int16_t pv_dport_id;
+ u_int16_t pv_port_id;
};
struct bstp_config_unit {
- u_int64_t cu_rootid;
- u_int64_t cu_bridge_id;
- u_int32_t cu_root_path_cost;
+ struct bstp_pri_vector cu_pv;
u_int16_t cu_message_age;
u_int16_t cu_max_age;
- u_int16_t cu_hello_time;
u_int16_t cu_forward_delay;
- u_int16_t cu_port_id;
+ u_int16_t cu_hello_time;
u_int8_t cu_message_type;
- u_int8_t cu_topology_change_acknowledgment;
+ u_int8_t cu_topology_change_ack;
u_int8_t cu_topology_change;
+ u_int8_t cu_proposal;
+ u_int8_t cu_agree;
+ u_int8_t cu_learning;
+ u_int8_t cu_forwarding;
+ u_int8_t cu_role;
};
struct bstp_tcn_unit {
u_int8_t tu_message_type;
};
+struct bstp_port {
+ LIST_ENTRY(bstp_port) bp_next;
+ struct ifnet *bp_ifp; /* parent if */
+ struct bstp_state *bp_bs;
+ void *bp_lhcookie; /* if linkstate hook */
+ u_int8_t bp_active;
+ u_int8_t bp_protover;
+ u_int32_t bp_flags;
+ u_int32_t bp_path_cost;
+ u_int16_t bp_port_msg_age;
+ u_int16_t bp_port_max_age;
+ u_int16_t bp_port_fdelay;
+ u_int16_t bp_port_htime;
+ u_int16_t bp_desg_msg_age;
+ u_int16_t bp_desg_max_age;
+ u_int16_t bp_desg_fdelay;
+ u_int16_t bp_desg_htime;
+ struct bstp_timer bp_edge_delay_timer;
+ struct bstp_timer bp_forward_delay_timer;
+ struct bstp_timer bp_hello_timer;
+ struct bstp_timer bp_message_age_timer;
+ struct bstp_timer bp_migrate_delay_timer;
+ struct bstp_timer bp_recent_backup_timer;
+ struct bstp_timer bp_recent_root_timer;
+ struct bstp_timer bp_tc_timer;
+ struct bstp_config_unit bp_msg_cu;
+ struct bstp_pri_vector bp_desg_pv;
+ struct bstp_pri_vector bp_port_pv;
+ u_int16_t bp_port_id;
+ u_int8_t bp_state;
+ u_int8_t bp_tcstate;
+ u_int8_t bp_role;
+ u_int8_t bp_infois;
+ u_int8_t bp_tc_ack;
+ u_int8_t bp_tc_prop;
+ u_int8_t bp_fdbflush;
+ u_int8_t bp_priority;
+ u_int8_t bp_p2p_link;
+ u_int8_t bp_agree;
+ u_int8_t bp_agreed;
+ u_int8_t bp_sync;
+ u_int8_t bp_synced;
+ u_int8_t bp_proposing;
+ u_int8_t bp_proposed;
+ u_int8_t bp_operedge;
+ u_int8_t bp_reroot;
+ u_int8_t bp_rcvdtc;
+ u_int8_t bp_rcvdtca;
+ u_int8_t bp_rcvdtcn;
+ u_int32_t bp_forward_transitions;
+ u_int8_t bp_txcount;
+};
+
+/*
+ * Software state for each bridge STP.
+ */
+struct bstp_state {
+ LIST_ENTRY(bstp_state) bs_list;
+ struct ifnet *bs_ifp;
+ struct bstp_pri_vector bs_bridge_pv;
+ struct bstp_pri_vector bs_root_pv;
+ struct bstp_port *bs_root_port;
+ u_int8_t bs_protover;
+ u_int16_t bs_migration_delay;
+ u_int16_t bs_edge_delay;
+ u_int16_t bs_bridge_max_age;
+ u_int16_t bs_bridge_fdelay;
+ u_int16_t bs_bridge_htime;
+ u_int16_t bs_root_msg_age;
+ u_int16_t bs_root_max_age;
+ u_int16_t bs_root_fdelay;
+ u_int16_t bs_root_htime;
+ u_int16_t bs_hold_time;
+ u_int16_t bs_bridge_priority;
+ u_int8_t bs_txholdcount;
+ u_int8_t bs_allsynced;
+ struct timeout bs_bstptimeout; /* stp timeout */
+ struct bstp_timer bs_link_timer;
+ struct timeval bs_last_tc_time;
+ LIST_HEAD(, bstp_port) bs_bplist;
+};
+#define bs_ifflags bs_ifp->if_flags
+
/*
* Bridge interface list
*/
struct bridge_iflist {
LIST_ENTRY(bridge_iflist) next; /* next in list */
- u_int64_t bif_designated_root;
- u_int64_t bif_designated_bridge;
- u_int32_t bif_path_cost;
- u_int32_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;
- u_int16_t bif_port_id;
- u_int16_t bif_designated_port;
- u_int8_t bif_state;
- u_int8_t bif_topology_change_acknowledge;
- u_int8_t bif_config_pending;
- u_int8_t bif_change_detection_enabled;
- u_int8_t bif_priority;
+ struct bstp_port *bif_stp; /* STP port state */
struct brl_head bif_brlin; /* input rules */
struct brl_head bif_brlout; /* output rules */
struct ifnet *ifp; /* member interface */
u_int32_t bif_flags; /* member flags */
};
+#define bif_state bif_stp->bp_state
/*
* Bridge route node
@@ -241,36 +415,19 @@ struct bridge_rtnode {
struct bridge_softc {
struct ifnet sc_if; /* the interface */
LIST_ENTRY(bridge_softc) sc_list; /* all bridges */
- u_int64_t sc_designated_root;
- u_int64_t sc_bridge_id;
struct bridge_iflist *sc_root_port;
- u_int32_t sc_root_path_cost;
- u_int16_t sc_max_age;
- u_int16_t sc_hello_time;
- u_int16_t sc_forward_delay;
- u_int16_t sc_bridge_max_age;
- u_int16_t sc_bridge_hello_time;
- u_int16_t sc_bridge_forward_delay;
- u_int16_t sc_topology_change_time;
- u_int16_t sc_hold_time;
- u_int16_t sc_bridge_priority;
- u_int8_t sc_topology_change_detected;
- u_int8_t sc_topology_change;
- struct bridge_timer sc_hello_timer;
- struct bridge_timer sc_topology_change_timer;
- struct bridge_timer sc_tcn_timer;
u_int32_t sc_brtmax; /* max # addresses */
u_int32_t sc_brtcnt; /* current # addrs */
int sc_brttimeout; /* timeout ticks */
u_int32_t sc_hashkey; /* hash key */
struct timeout sc_brtimeout; /* timeout state */
- struct timeout sc_bstptimeout; /* stp timeout */
+ struct bstp_state *sc_stp; /* stp state */
LIST_HEAD(, bridge_iflist) sc_iflist; /* interface list */
LIST_HEAD(, bridge_rtnode) sc_rts[BRIDGE_RTABLE_SIZE]; /* hash table */
LIST_HEAD(, bridge_iflist) sc_spanlist; /* span ports */
};
-extern u_int8_t bstp_etheraddr[];
+extern const u_int8_t bstp_etheraddr[];
void bridge_ifdetach(struct ifnet *);
struct mbuf *bridge_input(struct ifnet *, struct ether_header *,
@@ -278,10 +435,21 @@ struct mbuf *bridge_input(struct ifnet *, struct ether_header *,
int bridge_output(struct ifnet *, struct mbuf *, struct sockaddr *,
struct rtentry *);
void bridge_update(struct ifnet *, struct ether_addr *, int);
-struct mbuf *bstp_input(struct bridge_softc *, struct ifnet *,
- struct ether_header *, struct mbuf *);
-void bstp_initialization(struct bridge_softc *);
-int bstp_ioctl(struct ifnet *, u_long, caddr_t);
void bridge_rtdelete(struct bridge_softc *, struct ifnet *, int);
+void bridge_rtagenode(struct ifnet *, int);
+
+void bstp_attach(int);
+struct bstp_state *bstp_create(struct ifnet *);
+void bstp_destroy(struct bstp_state *);
+void bstp_initialization(struct bstp_state *);
+void bstp_stop(struct bstp_state *);
+int bstp_ioctl(struct ifnet *, u_long, caddr_t);
+struct bstp_port *bstp_add(struct bstp_state *, struct ifnet *);
+void bstp_delete(struct bstp_port *);
+struct mbuf *bstp_input(struct bstp_state *, struct bstp_port *,
+ struct ether_header *, struct mbuf *);
+void bstp_ifstate(void *);
+u_int8_t bstp_getstate(struct bstp_state *, struct bstp_port *);
+void bstp_ifsflags(struct bstp_port *, u_int);
#endif /* _KERNEL */
#endif /* _NET_IF_BRIDGE_H_ */