1 /* $NetBSD: bridgestp.c,v 1.5 2003/11/28 08:56:48 keihan Exp $ */
4 * SPDX-License-Identifier: BSD-2-Clause-NetBSD
6 * Copyright (c) 2000 Jason L. Wright (jason@thought.net)
7 * Copyright (c) 2006 Andrew Thompson (thompsa@FreeBSD.org)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 * OpenBSD: bridgestp.c,v 1.5 2001/03/22 03:48:29 jason Exp
35 * Implementation of the spanning tree protocol as defined in
36 * ISO/IEC 802.1D-2004, June 9, 2004.
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
42 #include <sys/param.h>
43 #include <sys/systm.h>
45 #include <sys/socket.h>
46 #include <sys/sockio.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
49 #include <sys/callout.h>
50 #include <sys/module.h>
53 #include <sys/mutex.h>
54 #include <sys/taskqueue.h>
57 #include <net/if_var.h>
58 #include <net/if_dl.h>
59 #include <net/if_types.h>
60 #include <net/if_llc.h>
61 #include <net/if_media.h>
64 #include <netinet/in.h>
65 #include <netinet/in_systm.h>
66 #include <netinet/in_var.h>
67 #include <netinet/if_ether.h>
68 #include <net/bridgestp.h>
70 #ifdef BRIDGESTP_DEBUG
71 #define DPRINTF(fmt, arg...) printf("bstp: " fmt, ##arg)
73 #define DPRINTF(fmt, arg...) (void)0
76 #define PV2ADDR(pv, eaddr) do { \
77 eaddr[0] = pv >> 40; \
78 eaddr[1] = pv >> 32; \
79 eaddr[2] = pv >> 24; \
80 eaddr[3] = pv >> 16; \
89 const uint8_t bstp_etheraddr[] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
91 LIST_HEAD(, bstp_state) bstp_list;
92 static struct mtx bstp_list_mtx;
94 static void bstp_transmit(struct bstp_state *, struct bstp_port *);
95 static void bstp_transmit_bpdu(struct bstp_state *, struct bstp_port *);
96 static void bstp_transmit_tcn(struct bstp_state *, struct bstp_port *);
97 static void bstp_decode_bpdu(struct bstp_port *, struct bstp_cbpdu *,
98 struct bstp_config_unit *);
99 static void bstp_send_bpdu(struct bstp_state *, struct bstp_port *,
100 struct bstp_cbpdu *);
101 static int bstp_pdu_flags(struct bstp_port *);
102 static void bstp_received_stp(struct bstp_state *, struct bstp_port *,
103 struct mbuf **, struct bstp_tbpdu *);
104 static void bstp_received_rstp(struct bstp_state *, struct bstp_port *,
105 struct mbuf **, struct bstp_tbpdu *);
106 static void bstp_received_tcn(struct bstp_state *, struct bstp_port *,
107 struct bstp_tcn_unit *);
108 static void bstp_received_bpdu(struct bstp_state *, struct bstp_port *,
109 struct bstp_config_unit *);
110 static int bstp_pdu_rcvtype(struct bstp_port *, struct bstp_config_unit *);
111 static int bstp_pdu_bettersame(struct bstp_port *, int);
112 static int bstp_info_cmp(struct bstp_pri_vector *,
113 struct bstp_pri_vector *);
114 static int bstp_info_superior(struct bstp_pri_vector *,
115 struct bstp_pri_vector *);
116 static void bstp_assign_roles(struct bstp_state *);
117 static void bstp_update_roles(struct bstp_state *, struct bstp_port *);
118 static void bstp_update_state(struct bstp_state *, struct bstp_port *);
119 static void bstp_update_tc(struct bstp_port *);
120 static void bstp_update_info(struct bstp_port *);
121 static void bstp_set_other_tcprop(struct bstp_port *);
122 static void bstp_set_all_reroot(struct bstp_state *);
123 static void bstp_set_all_sync(struct bstp_state *);
124 static void bstp_set_port_state(struct bstp_port *, int);
125 static void bstp_set_port_role(struct bstp_port *, int);
126 static void bstp_set_port_proto(struct bstp_port *, int);
127 static void bstp_set_port_tc(struct bstp_port *, int);
128 static void bstp_set_timer_tc(struct bstp_port *);
129 static void bstp_set_timer_msgage(struct bstp_port *);
130 static int bstp_rerooted(struct bstp_state *, struct bstp_port *);
131 static uint32_t bstp_calc_path_cost(struct bstp_port *);
132 static void bstp_notify_state(void *, int);
133 static void bstp_notify_rtage(void *, int);
134 static void bstp_ifupdstatus(void *, int);
135 static void bstp_enable_port(struct bstp_state *, struct bstp_port *);
136 static void bstp_disable_port(struct bstp_state *, struct bstp_port *);
137 static void bstp_tick(void *);
138 static void bstp_timer_start(struct bstp_timer *, uint16_t);
139 static void bstp_timer_stop(struct bstp_timer *);
140 static void bstp_timer_latch(struct bstp_timer *);
141 static int bstp_timer_dectest(struct bstp_timer *);
142 static void bstp_hello_timer_expiry(struct bstp_state *,
144 static void bstp_message_age_expiry(struct bstp_state *,
146 static void bstp_migrate_delay_expiry(struct bstp_state *,
148 static void bstp_edge_delay_expiry(struct bstp_state *,
150 static int bstp_addr_cmp(const uint8_t *, const uint8_t *);
151 static int bstp_same_bridgeid(uint64_t, uint64_t);
152 static void bstp_reinit(struct bstp_state *);
155 bstp_transmit(struct bstp_state *bs, struct bstp_port *bp)
159 if (bs->bs_running == 0)
163 * a PDU can only be sent if we have tx quota left and the
164 * hello timer is running.
166 if (bp->bp_hello_timer.active == 0) {
167 /* Test if it needs to be reset */
168 bstp_hello_timer_expiry(bs, bp);
171 if (bp->bp_txcount > bs->bs_txholdcount)
172 /* Ran out of karma */
175 if (bp->bp_protover == BSTP_PROTO_RSTP) {
176 bstp_transmit_bpdu(bs, bp);
179 switch (bp->bp_role) {
180 case BSTP_ROLE_DESIGNATED:
181 bstp_transmit_bpdu(bs, bp);
186 bstp_transmit_tcn(bs, bp);
190 bstp_timer_start(&bp->bp_hello_timer, bp->bp_desg_htime);
191 bp->bp_flags &= ~BSTP_PORT_NEWINFO;
195 bstp_transmit_bpdu(struct bstp_state *bs, struct bstp_port *bp)
197 struct bstp_cbpdu bpdu;
199 BSTP_LOCK_ASSERT(bs);
201 bpdu.cbu_rootpri = htons(bp->bp_desg_pv.pv_root_id >> 48);
202 PV2ADDR(bp->bp_desg_pv.pv_root_id, bpdu.cbu_rootaddr);
204 bpdu.cbu_rootpathcost = htonl(bp->bp_desg_pv.pv_cost);
206 bpdu.cbu_bridgepri = htons(bp->bp_desg_pv.pv_dbridge_id >> 48);
207 PV2ADDR(bp->bp_desg_pv.pv_dbridge_id, bpdu.cbu_bridgeaddr);
209 bpdu.cbu_portid = htons(bp->bp_port_id);
210 bpdu.cbu_messageage = htons(bp->bp_desg_msg_age);
211 bpdu.cbu_maxage = htons(bp->bp_desg_max_age);
212 bpdu.cbu_hellotime = htons(bp->bp_desg_htime);
213 bpdu.cbu_forwarddelay = htons(bp->bp_desg_fdelay);
215 bpdu.cbu_flags = bstp_pdu_flags(bp);
217 switch (bp->bp_protover) {
219 bpdu.cbu_bpdutype = BSTP_MSGTYPE_CFG;
222 case BSTP_PROTO_RSTP:
223 bpdu.cbu_bpdutype = BSTP_MSGTYPE_RSTP;
227 bstp_send_bpdu(bs, bp, &bpdu);
231 bstp_transmit_tcn(struct bstp_state *bs, struct bstp_port *bp)
233 struct bstp_tbpdu bpdu;
234 struct ifnet *ifp = bp->bp_ifp;
235 struct ether_header *eh;
238 KASSERT(bp == bs->bs_root_port, ("%s: bad root port\n", __func__));
240 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
243 m = m_gethdr(M_NOWAIT, MT_DATA);
247 m->m_pkthdr.rcvif = ifp;
248 m->m_pkthdr.len = sizeof(*eh) + sizeof(bpdu);
249 m->m_len = m->m_pkthdr.len;
251 eh = mtod(m, struct ether_header *);
253 memcpy(eh->ether_shost, IF_LLADDR(ifp), ETHER_ADDR_LEN);
254 memcpy(eh->ether_dhost, bstp_etheraddr, ETHER_ADDR_LEN);
255 eh->ether_type = htons(sizeof(bpdu));
257 bpdu.tbu_ssap = bpdu.tbu_dsap = LLC_8021D_LSAP;
258 bpdu.tbu_ctl = LLC_UI;
259 bpdu.tbu_protoid = 0;
260 bpdu.tbu_protover = 0;
261 bpdu.tbu_bpdutype = BSTP_MSGTYPE_TCN;
263 memcpy(mtod(m, caddr_t) + sizeof(*eh), &bpdu, sizeof(bpdu));
266 ifp->if_transmit(ifp, m);
270 bstp_decode_bpdu(struct bstp_port *bp, struct bstp_cbpdu *cpdu,
271 struct bstp_config_unit *cu)
275 cu->cu_pv.pv_root_id =
276 (((uint64_t)ntohs(cpdu->cbu_rootpri)) << 48) |
277 (((uint64_t)cpdu->cbu_rootaddr[0]) << 40) |
278 (((uint64_t)cpdu->cbu_rootaddr[1]) << 32) |
279 (((uint64_t)cpdu->cbu_rootaddr[2]) << 24) |
280 (((uint64_t)cpdu->cbu_rootaddr[3]) << 16) |
281 (((uint64_t)cpdu->cbu_rootaddr[4]) << 8) |
282 (((uint64_t)cpdu->cbu_rootaddr[5]) << 0);
284 cu->cu_pv.pv_dbridge_id =
285 (((uint64_t)ntohs(cpdu->cbu_bridgepri)) << 48) |
286 (((uint64_t)cpdu->cbu_bridgeaddr[0]) << 40) |
287 (((uint64_t)cpdu->cbu_bridgeaddr[1]) << 32) |
288 (((uint64_t)cpdu->cbu_bridgeaddr[2]) << 24) |
289 (((uint64_t)cpdu->cbu_bridgeaddr[3]) << 16) |
290 (((uint64_t)cpdu->cbu_bridgeaddr[4]) << 8) |
291 (((uint64_t)cpdu->cbu_bridgeaddr[5]) << 0);
293 cu->cu_pv.pv_cost = ntohl(cpdu->cbu_rootpathcost);
294 cu->cu_message_age = ntohs(cpdu->cbu_messageage);
295 cu->cu_max_age = ntohs(cpdu->cbu_maxage);
296 cu->cu_hello_time = ntohs(cpdu->cbu_hellotime);
297 cu->cu_forward_delay = ntohs(cpdu->cbu_forwarddelay);
298 cu->cu_pv.pv_dport_id = ntohs(cpdu->cbu_portid);
299 cu->cu_pv.pv_port_id = bp->bp_port_id;
300 cu->cu_message_type = cpdu->cbu_bpdutype;
302 /* Strip off unused flags in STP mode */
303 flags = cpdu->cbu_flags;
304 switch (cpdu->cbu_protover) {
306 flags &= BSTP_PDU_STPMASK;
307 /* A STP BPDU explicitly conveys a Designated Port */
308 cu->cu_role = BSTP_ROLE_DESIGNATED;
311 case BSTP_PROTO_RSTP:
312 flags &= BSTP_PDU_RSTPMASK;
316 cu->cu_topology_change_ack =
317 (flags & BSTP_PDU_F_TCA) ? 1 : 0;
319 (flags & BSTP_PDU_F_P) ? 1 : 0;
321 (flags & BSTP_PDU_F_A) ? 1 : 0;
323 (flags & BSTP_PDU_F_L) ? 1 : 0;
325 (flags & BSTP_PDU_F_F) ? 1 : 0;
326 cu->cu_topology_change =
327 (flags & BSTP_PDU_F_TC) ? 1 : 0;
329 switch ((flags & BSTP_PDU_PRMASK) >> BSTP_PDU_PRSHIFT) {
330 case BSTP_PDU_F_ROOT:
331 cu->cu_role = BSTP_ROLE_ROOT;
334 cu->cu_role = BSTP_ROLE_ALTERNATE;
336 case BSTP_PDU_F_DESG:
337 cu->cu_role = BSTP_ROLE_DESIGNATED;
343 bstp_send_bpdu(struct bstp_state *bs, struct bstp_port *bp,
344 struct bstp_cbpdu *bpdu)
348 struct ether_header *eh;
350 BSTP_LOCK_ASSERT(bs);
355 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
358 m = m_gethdr(M_NOWAIT, MT_DATA);
362 eh = mtod(m, struct ether_header *);
364 bpdu->cbu_ssap = bpdu->cbu_dsap = LLC_8021D_LSAP;
365 bpdu->cbu_ctl = LLC_UI;
366 bpdu->cbu_protoid = htons(BSTP_PROTO_ID);
368 memcpy(eh->ether_shost, IF_LLADDR(ifp), ETHER_ADDR_LEN);
369 memcpy(eh->ether_dhost, bstp_etheraddr, ETHER_ADDR_LEN);
371 switch (bpdu->cbu_bpdutype) {
372 case BSTP_MSGTYPE_CFG:
373 bpdu->cbu_protover = BSTP_PROTO_STP;
374 m->m_pkthdr.len = sizeof(*eh) + BSTP_BPDU_STP_LEN;
375 eh->ether_type = htons(BSTP_BPDU_STP_LEN);
376 memcpy(mtod(m, caddr_t) + sizeof(*eh), bpdu,
380 case BSTP_MSGTYPE_RSTP:
381 bpdu->cbu_protover = BSTP_PROTO_RSTP;
382 bpdu->cbu_versionlen = htons(0);
383 m->m_pkthdr.len = sizeof(*eh) + BSTP_BPDU_RSTP_LEN;
384 eh->ether_type = htons(BSTP_BPDU_RSTP_LEN);
385 memcpy(mtod(m, caddr_t) + sizeof(*eh), bpdu,
390 panic("not implemented");
392 m->m_pkthdr.rcvif = ifp;
393 m->m_len = m->m_pkthdr.len;
396 ifp->if_transmit(ifp, m);
400 bstp_pdu_flags(struct bstp_port *bp)
404 if (bp->bp_proposing && bp->bp_state != BSTP_IFSTATE_FORWARDING)
405 flags |= BSTP_PDU_F_P;
408 flags |= BSTP_PDU_F_A;
410 if (bp->bp_tc_timer.active)
411 flags |= BSTP_PDU_F_TC;
414 flags |= BSTP_PDU_F_TCA;
416 switch (bp->bp_state) {
417 case BSTP_IFSTATE_LEARNING:
418 flags |= BSTP_PDU_F_L;
421 case BSTP_IFSTATE_FORWARDING:
422 flags |= (BSTP_PDU_F_L | BSTP_PDU_F_F);
426 switch (bp->bp_role) {
429 (BSTP_PDU_F_ROOT << BSTP_PDU_PRSHIFT);
432 case BSTP_ROLE_ALTERNATE:
433 case BSTP_ROLE_BACKUP: /* fall through */
435 (BSTP_PDU_F_ALT << BSTP_PDU_PRSHIFT);
438 case BSTP_ROLE_DESIGNATED:
440 (BSTP_PDU_F_DESG << BSTP_PDU_PRSHIFT);
444 /* Strip off unused flags in either mode */
445 switch (bp->bp_protover) {
447 flags &= BSTP_PDU_STPMASK;
449 case BSTP_PROTO_RSTP:
450 flags &= BSTP_PDU_RSTPMASK;
457 bstp_input(struct bstp_port *bp, struct ifnet *ifp, struct mbuf *m)
459 struct bstp_state *bs = bp->bp_bs;
460 struct ether_header *eh;
461 struct bstp_tbpdu tpdu;
464 if (bp->bp_active == 0) {
471 eh = mtod(m, struct ether_header *);
473 len = ntohs(eh->ether_type);
474 if (len < sizeof(tpdu))
477 m_adj(m, ETHER_HDR_LEN);
479 if (m->m_pkthdr.len > len)
480 m_adj(m, len - m->m_pkthdr.len);
481 if (m->m_len < sizeof(tpdu) &&
482 (m = m_pullup(m, sizeof(tpdu))) == NULL)
485 memcpy(&tpdu, mtod(m, caddr_t), sizeof(tpdu));
487 /* basic packet checks */
488 if (tpdu.tbu_dsap != LLC_8021D_LSAP ||
489 tpdu.tbu_ssap != LLC_8021D_LSAP ||
490 tpdu.tbu_ctl != LLC_UI)
492 if (tpdu.tbu_protoid != BSTP_PROTO_ID)
496 * We can treat later versions of the PDU as the same as the maximum
497 * version we implement. All additional parameters/flags are ignored.
499 if (tpdu.tbu_protover > BSTP_PROTO_MAX)
500 tpdu.tbu_protover = BSTP_PROTO_MAX;
502 if (tpdu.tbu_protover != bp->bp_protover) {
504 * Wait for the migration delay timer to expire before changing
505 * protocol version to avoid flip-flops.
507 if (bp->bp_flags & BSTP_PORT_CANMIGRATE)
508 bstp_set_port_proto(bp, tpdu.tbu_protover);
513 /* Clear operedge upon receiving a PDU on the port */
515 bstp_timer_start(&bp->bp_edge_delay_timer,
516 BSTP_DEFAULT_MIGRATE_DELAY);
518 switch (tpdu.tbu_protover) {
520 bstp_received_stp(bs, bp, &m, &tpdu);
523 case BSTP_PROTO_RSTP:
524 bstp_received_rstp(bs, bp, &m, &tpdu);
534 bstp_received_stp(struct bstp_state *bs, struct bstp_port *bp,
535 struct mbuf **mp, struct bstp_tbpdu *tpdu)
537 struct bstp_cbpdu cpdu;
538 struct bstp_config_unit *cu = &bp->bp_msg_cu;
539 struct bstp_tcn_unit tu;
541 switch (tpdu->tbu_bpdutype) {
542 case BSTP_MSGTYPE_TCN:
543 tu.tu_message_type = tpdu->tbu_bpdutype;
544 bstp_received_tcn(bs, bp, &tu);
546 case BSTP_MSGTYPE_CFG:
547 if ((*mp)->m_len < BSTP_BPDU_STP_LEN &&
548 (*mp = m_pullup(*mp, BSTP_BPDU_STP_LEN)) == NULL)
550 memcpy(&cpdu, mtod(*mp, caddr_t), BSTP_BPDU_STP_LEN);
552 bstp_decode_bpdu(bp, &cpdu, cu);
553 bstp_received_bpdu(bs, bp, cu);
559 bstp_received_rstp(struct bstp_state *bs, struct bstp_port *bp,
560 struct mbuf **mp, struct bstp_tbpdu *tpdu)
562 struct bstp_cbpdu cpdu;
563 struct bstp_config_unit *cu = &bp->bp_msg_cu;
565 if (tpdu->tbu_bpdutype != BSTP_MSGTYPE_RSTP)
568 if ((*mp)->m_len < BSTP_BPDU_RSTP_LEN &&
569 (*mp = m_pullup(*mp, BSTP_BPDU_RSTP_LEN)) == NULL)
571 memcpy(&cpdu, mtod(*mp, caddr_t), BSTP_BPDU_RSTP_LEN);
573 bstp_decode_bpdu(bp, &cpdu, cu);
574 bstp_received_bpdu(bs, bp, cu);
578 bstp_received_tcn(struct bstp_state *bs, struct bstp_port *bp,
579 struct bstp_tcn_unit *tcn)
586 bstp_received_bpdu(struct bstp_state *bs, struct bstp_port *bp,
587 struct bstp_config_unit *cu)
591 BSTP_LOCK_ASSERT(bs);
593 /* We need to have transitioned to INFO_MINE before proceeding */
594 switch (bp->bp_infois) {
595 case BSTP_INFO_DISABLED:
601 if (cu->cu_message_age >= cu->cu_max_age) {
604 if (cu->cu_max_age < BSTP_MIN_MAX_AGE ||
605 cu->cu_max_age > BSTP_MAX_MAX_AGE) {
608 if (cu->cu_forward_delay < BSTP_MIN_FORWARD_DELAY ||
609 cu->cu_forward_delay > BSTP_MAX_FORWARD_DELAY) {
612 if (cu->cu_hello_time < BSTP_MIN_HELLO_TIME ||
613 cu->cu_hello_time > BSTP_MAX_HELLO_TIME) {
617 type = bstp_pdu_rcvtype(bp, cu);
620 case BSTP_PDU_SUPERIOR:
621 bs->bs_allsynced = 0;
623 bp->bp_proposing = 0;
625 if (cu->cu_proposal && cu->cu_forwarding == 0)
627 if (cu->cu_topology_change)
629 if (cu->cu_topology_change_ack)
633 !bstp_pdu_bettersame(bp, BSTP_INFO_RECEIVED))
636 /* copy the received priority and timers to the port */
637 bp->bp_port_pv = cu->cu_pv;
638 bp->bp_port_msg_age = cu->cu_message_age;
639 bp->bp_port_max_age = cu->cu_max_age;
640 bp->bp_port_fdelay = cu->cu_forward_delay;
642 (cu->cu_hello_time > BSTP_MIN_HELLO_TIME ?
643 cu->cu_hello_time : BSTP_MIN_HELLO_TIME);
645 /* set expiry for the new info */
646 bstp_set_timer_msgage(bp);
648 bp->bp_infois = BSTP_INFO_RECEIVED;
649 bstp_assign_roles(bs);
652 case BSTP_PDU_REPEATED:
653 if (cu->cu_proposal && cu->cu_forwarding == 0)
655 if (cu->cu_topology_change)
657 if (cu->cu_topology_change_ack)
660 /* rearm the age timer */
661 bstp_set_timer_msgage(bp);
664 case BSTP_PDU_INFERIOR:
665 if (cu->cu_learning) {
667 bp->bp_proposing = 0;
671 case BSTP_PDU_INFERIORALT:
673 * only point to point links are allowed fast
674 * transitions to forwarding.
676 if (cu->cu_agree && bp->bp_ptp_link) {
678 bp->bp_proposing = 0;
682 if (cu->cu_topology_change)
684 if (cu->cu_topology_change_ack)
689 return; /* do nothing */
691 /* update the state machines with the new data */
692 bstp_update_state(bs, bp);
696 bstp_pdu_rcvtype(struct bstp_port *bp, struct bstp_config_unit *cu)
700 /* default return type */
701 type = BSTP_PDU_OTHER;
703 switch (cu->cu_role) {
704 case BSTP_ROLE_DESIGNATED:
705 if (bstp_info_superior(&bp->bp_port_pv, &cu->cu_pv))
706 /* bpdu priority is superior */
707 type = BSTP_PDU_SUPERIOR;
708 else if (bstp_info_cmp(&bp->bp_port_pv, &cu->cu_pv) ==
710 if (bp->bp_port_msg_age != cu->cu_message_age ||
711 bp->bp_port_max_age != cu->cu_max_age ||
712 bp->bp_port_fdelay != cu->cu_forward_delay ||
713 bp->bp_port_htime != cu->cu_hello_time)
714 /* bpdu priority is equal and timers differ */
715 type = BSTP_PDU_SUPERIOR;
718 type = BSTP_PDU_REPEATED;
720 /* bpdu priority is worse */
721 type = BSTP_PDU_INFERIOR;
726 case BSTP_ROLE_ALTERNATE:
727 case BSTP_ROLE_BACKUP:
728 if (bstp_info_cmp(&bp->bp_port_pv, &cu->cu_pv) <= INFO_SAME)
730 * not a designated port and priority is the same or
733 type = BSTP_PDU_INFERIORALT;
741 bstp_pdu_bettersame(struct bstp_port *bp, int newinfo)
743 if (newinfo == BSTP_INFO_RECEIVED &&
744 bp->bp_infois == BSTP_INFO_RECEIVED &&
745 bstp_info_cmp(&bp->bp_port_pv, &bp->bp_msg_cu.cu_pv) >= INFO_SAME)
748 if (newinfo == BSTP_INFO_MINE &&
749 bp->bp_infois == BSTP_INFO_MINE &&
750 bstp_info_cmp(&bp->bp_port_pv, &bp->bp_desg_pv) >= INFO_SAME)
757 bstp_info_cmp(struct bstp_pri_vector *pv,
758 struct bstp_pri_vector *cpv)
760 if (cpv->pv_root_id < pv->pv_root_id)
761 return (INFO_BETTER);
762 if (cpv->pv_root_id > pv->pv_root_id)
765 if (cpv->pv_cost < pv->pv_cost)
766 return (INFO_BETTER);
767 if (cpv->pv_cost > pv->pv_cost)
770 if (cpv->pv_dbridge_id < pv->pv_dbridge_id)
771 return (INFO_BETTER);
772 if (cpv->pv_dbridge_id > pv->pv_dbridge_id)
775 if (cpv->pv_dport_id < pv->pv_dport_id)
776 return (INFO_BETTER);
777 if (cpv->pv_dport_id > pv->pv_dport_id)
784 * This message priority vector is superior to the port priority vector and
785 * will replace it if, and only if, the message priority vector is better than
786 * the port priority vector, or the message has been transmitted from the same
787 * designated bridge and designated port as the port priority vector.
790 bstp_info_superior(struct bstp_pri_vector *pv,
791 struct bstp_pri_vector *cpv)
793 if (bstp_info_cmp(pv, cpv) == INFO_BETTER ||
794 (bstp_same_bridgeid(pv->pv_dbridge_id, cpv->pv_dbridge_id) &&
795 (cpv->pv_dport_id & 0xfff) == (pv->pv_dport_id & 0xfff)))
801 bstp_assign_roles(struct bstp_state *bs)
803 struct bstp_port *bp, *rbp = NULL;
804 struct bstp_pri_vector pv;
806 /* default to our priority vector */
807 bs->bs_root_pv = bs->bs_bridge_pv;
808 bs->bs_root_msg_age = 0;
809 bs->bs_root_max_age = bs->bs_bridge_max_age;
810 bs->bs_root_fdelay = bs->bs_bridge_fdelay;
811 bs->bs_root_htime = bs->bs_bridge_htime;
812 bs->bs_root_port = NULL;
814 /* check if any received info supersedes us */
815 LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
816 if (bp->bp_infois != BSTP_INFO_RECEIVED)
820 pv.pv_cost += bp->bp_path_cost;
823 * The root priority vector is the best of the set comprising
824 * the bridge priority vector plus all root path priority
825 * vectors whose bridge address is not equal to us.
827 if (bstp_same_bridgeid(pv.pv_dbridge_id,
828 bs->bs_bridge_pv.pv_dbridge_id) == 0 &&
829 bstp_info_cmp(&bs->bs_root_pv, &pv) == INFO_BETTER) {
830 /* the port vector replaces the root */
832 bs->bs_root_msg_age = bp->bp_port_msg_age +
833 BSTP_MESSAGE_AGE_INCR;
834 bs->bs_root_max_age = bp->bp_port_max_age;
835 bs->bs_root_fdelay = bp->bp_port_fdelay;
836 bs->bs_root_htime = bp->bp_port_htime;
841 LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
842 /* calculate the port designated vector */
843 bp->bp_desg_pv.pv_root_id = bs->bs_root_pv.pv_root_id;
844 bp->bp_desg_pv.pv_cost = bs->bs_root_pv.pv_cost;
845 bp->bp_desg_pv.pv_dbridge_id = bs->bs_bridge_pv.pv_dbridge_id;
846 bp->bp_desg_pv.pv_dport_id = bp->bp_port_id;
847 bp->bp_desg_pv.pv_port_id = bp->bp_port_id;
849 /* calculate designated times */
850 bp->bp_desg_msg_age = bs->bs_root_msg_age;
851 bp->bp_desg_max_age = bs->bs_root_max_age;
852 bp->bp_desg_fdelay = bs->bs_root_fdelay;
853 bp->bp_desg_htime = bs->bs_bridge_htime;
855 switch (bp->bp_infois) {
856 case BSTP_INFO_DISABLED:
857 bstp_set_port_role(bp, BSTP_ROLE_DISABLED);
861 bstp_set_port_role(bp, BSTP_ROLE_DESIGNATED);
862 bstp_update_info(bp);
866 bstp_set_port_role(bp, BSTP_ROLE_DESIGNATED);
867 /* update the port info if stale */
868 if (bstp_info_cmp(&bp->bp_port_pv,
869 &bp->bp_desg_pv) != INFO_SAME ||
871 (bp->bp_port_msg_age != rbp->bp_port_msg_age ||
872 bp->bp_port_max_age != rbp->bp_port_max_age ||
873 bp->bp_port_fdelay != rbp->bp_port_fdelay ||
874 bp->bp_port_htime != rbp->bp_port_htime)))
875 bstp_update_info(bp);
878 case BSTP_INFO_RECEIVED:
881 * root priority is derived from this
882 * port, make it the root port.
884 bstp_set_port_role(bp, BSTP_ROLE_ROOT);
885 bs->bs_root_port = bp;
886 } else if (bstp_info_cmp(&bp->bp_port_pv,
887 &bp->bp_desg_pv) == INFO_BETTER) {
889 * the port priority is lower than the root
892 bstp_set_port_role(bp, BSTP_ROLE_DESIGNATED);
893 bstp_update_info(bp);
895 if (bstp_same_bridgeid(
896 bp->bp_port_pv.pv_dbridge_id,
897 bs->bs_bridge_pv.pv_dbridge_id)) {
899 * the designated bridge refers to
900 * another port on this bridge.
902 bstp_set_port_role(bp,
906 * the port is an inferior path to the
909 bstp_set_port_role(bp,
910 BSTP_ROLE_ALTERNATE);
919 bstp_update_state(struct bstp_state *bs, struct bstp_port *bp)
921 struct bstp_port *bp2;
924 BSTP_LOCK_ASSERT(bs);
926 /* check if all the ports have syncronised again */
927 if (!bs->bs_allsynced) {
929 LIST_FOREACH(bp2, &bs->bs_bplist, bp_next) {
930 if (!(bp2->bp_synced ||
931 bp2->bp_role == BSTP_ROLE_ROOT)) {
936 bs->bs_allsynced = synced;
939 bstp_update_roles(bs, bp);
944 bstp_update_roles(struct bstp_state *bs, struct bstp_port *bp)
948 switch (bp->bp_role) {
949 case BSTP_ROLE_DISABLED:
950 /* Clear any flags if set */
951 if (bp->bp_sync || !bp->bp_synced || bp->bp_reroot) {
958 case BSTP_ROLE_ALTERNATE:
959 case BSTP_ROLE_BACKUP:
960 if ((bs->bs_allsynced && !bp->bp_agree) ||
961 (bp->bp_proposed && bp->bp_agree)) {
964 bp->bp_flags |= BSTP_PORT_NEWINFO;
965 DPRINTF("%s -> ALTERNATE_AGREED\n",
966 bp->bp_ifp->if_xname);
969 if (bp->bp_proposed && !bp->bp_agree) {
970 bstp_set_all_sync(bs);
972 DPRINTF("%s -> ALTERNATE_PROPOSED\n",
973 bp->bp_ifp->if_xname);
976 /* Clear any flags if set */
977 if (bp->bp_sync || !bp->bp_synced || bp->bp_reroot) {
981 DPRINTF("%s -> ALTERNATE_PORT\n", bp->bp_ifp->if_xname);
986 if (bp->bp_state != BSTP_IFSTATE_FORWARDING && !bp->bp_reroot) {
987 bstp_set_all_reroot(bs);
988 DPRINTF("%s -> ROOT_REROOT\n", bp->bp_ifp->if_xname);
991 if ((bs->bs_allsynced && !bp->bp_agree) ||
992 (bp->bp_proposed && bp->bp_agree)) {
996 bp->bp_flags |= BSTP_PORT_NEWINFO;
997 DPRINTF("%s -> ROOT_AGREED\n", bp->bp_ifp->if_xname);
1000 if (bp->bp_proposed && !bp->bp_agree) {
1001 bstp_set_all_sync(bs);
1002 bp->bp_proposed = 0;
1003 DPRINTF("%s -> ROOT_PROPOSED\n", bp->bp_ifp->if_xname);
1006 if (bp->bp_state != BSTP_IFSTATE_FORWARDING &&
1007 (bp->bp_forward_delay_timer.active == 0 ||
1008 (bstp_rerooted(bs, bp) &&
1009 bp->bp_recent_backup_timer.active == 0 &&
1010 bp->bp_protover == BSTP_PROTO_RSTP))) {
1011 switch (bp->bp_state) {
1012 case BSTP_IFSTATE_DISCARDING:
1013 bstp_set_port_state(bp, BSTP_IFSTATE_LEARNING);
1015 case BSTP_IFSTATE_LEARNING:
1016 bstp_set_port_state(bp,
1017 BSTP_IFSTATE_FORWARDING);
1022 if (bp->bp_state == BSTP_IFSTATE_FORWARDING && bp->bp_reroot) {
1024 DPRINTF("%s -> ROOT_REROOTED\n", bp->bp_ifp->if_xname);
1028 case BSTP_ROLE_DESIGNATED:
1029 if (bp->bp_recent_root_timer.active == 0 && bp->bp_reroot) {
1031 DPRINTF("%s -> DESIGNATED_RETIRED\n",
1032 bp->bp_ifp->if_xname);
1035 if ((bp->bp_state == BSTP_IFSTATE_DISCARDING &&
1036 !bp->bp_synced) || (bp->bp_agreed && !bp->bp_synced) ||
1037 (bp->bp_operedge && !bp->bp_synced) ||
1038 (bp->bp_sync && bp->bp_synced)) {
1039 bstp_timer_stop(&bp->bp_recent_root_timer);
1042 DPRINTF("%s -> DESIGNATED_SYNCED\n",
1043 bp->bp_ifp->if_xname);
1046 if (bp->bp_state != BSTP_IFSTATE_FORWARDING &&
1047 !bp->bp_agreed && !bp->bp_proposing &&
1049 bp->bp_proposing = 1;
1050 bp->bp_flags |= BSTP_PORT_NEWINFO;
1051 bstp_timer_start(&bp->bp_edge_delay_timer,
1052 (bp->bp_ptp_link ? BSTP_DEFAULT_MIGRATE_DELAY :
1053 bp->bp_desg_max_age));
1054 DPRINTF("%s -> DESIGNATED_PROPOSE\n",
1055 bp->bp_ifp->if_xname);
1058 if (bp->bp_state != BSTP_IFSTATE_FORWARDING &&
1059 (bp->bp_forward_delay_timer.active == 0 || bp->bp_agreed ||
1061 (bp->bp_recent_root_timer.active == 0 || !bp->bp_reroot) &&
1064 DPRINTF("%s -> AGREED\n", bp->bp_ifp->if_xname);
1066 * If agreed|operedge then go straight to forwarding,
1067 * otherwise follow discard -> learn -> forward.
1069 if (bp->bp_agreed || bp->bp_operedge ||
1070 bp->bp_state == BSTP_IFSTATE_LEARNING) {
1071 bstp_set_port_state(bp,
1072 BSTP_IFSTATE_FORWARDING);
1073 bp->bp_agreed = bp->bp_protover;
1074 } else if (bp->bp_state == BSTP_IFSTATE_DISCARDING)
1075 bstp_set_port_state(bp, BSTP_IFSTATE_LEARNING);
1078 if (((bp->bp_sync && !bp->bp_synced) ||
1079 (bp->bp_reroot && bp->bp_recent_root_timer.active) ||
1080 (bp->bp_flags & BSTP_PORT_DISPUTED)) && !bp->bp_operedge &&
1081 bp->bp_state != BSTP_IFSTATE_DISCARDING) {
1082 bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
1083 bp->bp_flags &= ~BSTP_PORT_DISPUTED;
1084 bstp_timer_start(&bp->bp_forward_delay_timer,
1085 bp->bp_protover == BSTP_PROTO_RSTP ?
1086 bp->bp_desg_htime : bp->bp_desg_fdelay);
1087 DPRINTF("%s -> DESIGNATED_DISCARD\n",
1088 bp->bp_ifp->if_xname);
1093 if (bp->bp_flags & BSTP_PORT_NEWINFO)
1094 bstp_transmit(bs, bp);
1098 bstp_update_tc(struct bstp_port *bp)
1100 switch (bp->bp_tcstate) {
1101 case BSTP_TCSTATE_ACTIVE:
1102 if ((bp->bp_role != BSTP_ROLE_DESIGNATED &&
1103 bp->bp_role != BSTP_ROLE_ROOT) || bp->bp_operedge)
1104 bstp_set_port_tc(bp, BSTP_TCSTATE_LEARNING);
1107 bstp_set_port_tc(bp, BSTP_TCSTATE_TCN);
1109 bstp_set_port_tc(bp, BSTP_TCSTATE_TC);
1111 if (bp->bp_tc_prop && !bp->bp_operedge)
1112 bstp_set_port_tc(bp, BSTP_TCSTATE_PROPAG);
1115 bstp_set_port_tc(bp, BSTP_TCSTATE_ACK);
1118 case BSTP_TCSTATE_INACTIVE:
1119 if ((bp->bp_state == BSTP_IFSTATE_LEARNING ||
1120 bp->bp_state == BSTP_IFSTATE_FORWARDING) &&
1121 bp->bp_fdbflush == 0)
1122 bstp_set_port_tc(bp, BSTP_TCSTATE_LEARNING);
1125 case BSTP_TCSTATE_LEARNING:
1126 if (bp->bp_rcvdtc || bp->bp_rcvdtcn || bp->bp_rcvdtca ||
1128 bstp_set_port_tc(bp, BSTP_TCSTATE_LEARNING);
1129 else if (bp->bp_role != BSTP_ROLE_DESIGNATED &&
1130 bp->bp_role != BSTP_ROLE_ROOT &&
1131 bp->bp_state == BSTP_IFSTATE_DISCARDING)
1132 bstp_set_port_tc(bp, BSTP_TCSTATE_INACTIVE);
1134 if ((bp->bp_role == BSTP_ROLE_DESIGNATED ||
1135 bp->bp_role == BSTP_ROLE_ROOT) &&
1136 bp->bp_state == BSTP_IFSTATE_FORWARDING &&
1138 bstp_set_port_tc(bp, BSTP_TCSTATE_DETECTED);
1141 /* these are transient states and go straight back to ACTIVE */
1142 case BSTP_TCSTATE_DETECTED:
1143 case BSTP_TCSTATE_TCN:
1144 case BSTP_TCSTATE_TC:
1145 case BSTP_TCSTATE_PROPAG:
1146 case BSTP_TCSTATE_ACK:
1147 DPRINTF("Invalid TC state for %s\n",
1148 bp->bp_ifp->if_xname);
1155 bstp_update_info(struct bstp_port *bp)
1157 struct bstp_state *bs = bp->bp_bs;
1159 bp->bp_proposing = 0;
1160 bp->bp_proposed = 0;
1162 if (bp->bp_agreed && !bstp_pdu_bettersame(bp, BSTP_INFO_MINE))
1165 if (bp->bp_synced && !bp->bp_agreed) {
1167 bs->bs_allsynced = 0;
1170 /* copy the designated pv to the port */
1171 bp->bp_port_pv = bp->bp_desg_pv;
1172 bp->bp_port_msg_age = bp->bp_desg_msg_age;
1173 bp->bp_port_max_age = bp->bp_desg_max_age;
1174 bp->bp_port_fdelay = bp->bp_desg_fdelay;
1175 bp->bp_port_htime = bp->bp_desg_htime;
1176 bp->bp_infois = BSTP_INFO_MINE;
1178 /* Set transmit flag but do not immediately send */
1179 bp->bp_flags |= BSTP_PORT_NEWINFO;
1182 /* set tcprop on every port other than the caller */
1184 bstp_set_other_tcprop(struct bstp_port *bp)
1186 struct bstp_state *bs = bp->bp_bs;
1187 struct bstp_port *bp2;
1189 BSTP_LOCK_ASSERT(bs);
1191 LIST_FOREACH(bp2, &bs->bs_bplist, bp_next) {
1194 bp2->bp_tc_prop = 1;
1199 bstp_set_all_reroot(struct bstp_state *bs)
1201 struct bstp_port *bp;
1203 BSTP_LOCK_ASSERT(bs);
1205 LIST_FOREACH(bp, &bs->bs_bplist, bp_next)
1210 bstp_set_all_sync(struct bstp_state *bs)
1212 struct bstp_port *bp;
1214 BSTP_LOCK_ASSERT(bs);
1216 LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
1218 bp->bp_synced = 0; /* Not explicit in spec */
1221 bs->bs_allsynced = 0;
1225 bstp_set_port_state(struct bstp_port *bp, int state)
1227 if (bp->bp_state == state)
1230 bp->bp_state = state;
1232 switch (bp->bp_state) {
1233 case BSTP_IFSTATE_DISCARDING:
1234 DPRINTF("state changed to DISCARDING on %s\n",
1235 bp->bp_ifp->if_xname);
1238 case BSTP_IFSTATE_LEARNING:
1239 DPRINTF("state changed to LEARNING on %s\n",
1240 bp->bp_ifp->if_xname);
1242 bstp_timer_start(&bp->bp_forward_delay_timer,
1243 bp->bp_protover == BSTP_PROTO_RSTP ?
1244 bp->bp_desg_htime : bp->bp_desg_fdelay);
1247 case BSTP_IFSTATE_FORWARDING:
1248 DPRINTF("state changed to FORWARDING on %s\n",
1249 bp->bp_ifp->if_xname);
1251 bstp_timer_stop(&bp->bp_forward_delay_timer);
1252 /* Record that we enabled forwarding */
1253 bp->bp_forward_transitions++;
1257 /* notify the parent bridge */
1258 taskqueue_enqueue(taskqueue_swi, &bp->bp_statetask);
1262 bstp_set_port_role(struct bstp_port *bp, int role)
1264 struct bstp_state *bs = bp->bp_bs;
1266 if (bp->bp_role == role)
1269 /* perform pre-change tasks */
1270 switch (bp->bp_role) {
1271 case BSTP_ROLE_DISABLED:
1272 bstp_timer_start(&bp->bp_forward_delay_timer,
1273 bp->bp_desg_max_age);
1276 case BSTP_ROLE_BACKUP:
1277 bstp_timer_start(&bp->bp_recent_backup_timer,
1278 bp->bp_desg_htime * 2);
1280 case BSTP_ROLE_ALTERNATE:
1281 bstp_timer_start(&bp->bp_forward_delay_timer,
1282 bp->bp_desg_fdelay);
1288 case BSTP_ROLE_ROOT:
1289 bstp_timer_start(&bp->bp_recent_root_timer,
1290 BSTP_DEFAULT_FORWARD_DELAY);
1295 /* clear values not carried between roles */
1296 bp->bp_proposing = 0;
1297 bs->bs_allsynced = 0;
1299 /* initialise the new role */
1300 switch (bp->bp_role) {
1301 case BSTP_ROLE_DISABLED:
1302 case BSTP_ROLE_ALTERNATE:
1303 case BSTP_ROLE_BACKUP:
1304 DPRINTF("%s role -> ALT/BACK/DISABLED\n",
1305 bp->bp_ifp->if_xname);
1306 bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
1307 bstp_timer_stop(&bp->bp_recent_root_timer);
1308 bstp_timer_latch(&bp->bp_forward_delay_timer);
1314 case BSTP_ROLE_ROOT:
1315 DPRINTF("%s role -> ROOT\n",
1316 bp->bp_ifp->if_xname);
1317 bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
1318 bstp_timer_latch(&bp->bp_recent_root_timer);
1319 bp->bp_proposing = 0;
1322 case BSTP_ROLE_DESIGNATED:
1323 DPRINTF("%s role -> DESIGNATED\n",
1324 bp->bp_ifp->if_xname);
1325 bstp_timer_start(&bp->bp_hello_timer,
1331 /* let the TC state know that the role changed */
1336 bstp_set_port_proto(struct bstp_port *bp, int proto)
1338 struct bstp_state *bs = bp->bp_bs;
1340 /* supported protocol versions */
1342 case BSTP_PROTO_STP:
1343 /* we can downgrade protocols only */
1344 bstp_timer_stop(&bp->bp_migrate_delay_timer);
1345 /* clear unsupported features */
1346 bp->bp_operedge = 0;
1347 /* STP compat mode only uses 16 bits of the 32 */
1348 if (bp->bp_path_cost > 65535)
1349 bp->bp_path_cost = 65535;
1352 case BSTP_PROTO_RSTP:
1353 bstp_timer_start(&bp->bp_migrate_delay_timer,
1354 bs->bs_migration_delay);
1358 DPRINTF("Unsupported STP version %d\n", proto);
1362 bp->bp_protover = proto;
1363 bp->bp_flags &= ~BSTP_PORT_CANMIGRATE;
1367 bstp_set_port_tc(struct bstp_port *bp, int state)
1369 struct bstp_state *bs = bp->bp_bs;
1371 bp->bp_tcstate = state;
1373 /* initialise the new state */
1374 switch (bp->bp_tcstate) {
1375 case BSTP_TCSTATE_ACTIVE:
1376 DPRINTF("%s -> TC_ACTIVE\n", bp->bp_ifp->if_xname);
1380 case BSTP_TCSTATE_INACTIVE:
1381 bstp_timer_stop(&bp->bp_tc_timer);
1382 /* flush routes on the parent bridge */
1383 bp->bp_fdbflush = 1;
1384 taskqueue_enqueue(taskqueue_swi, &bp->bp_rtagetask);
1386 DPRINTF("%s -> TC_INACTIVE\n", bp->bp_ifp->if_xname);
1389 case BSTP_TCSTATE_LEARNING:
1394 DPRINTF("%s -> TC_LEARNING\n", bp->bp_ifp->if_xname);
1397 case BSTP_TCSTATE_DETECTED:
1398 bstp_set_timer_tc(bp);
1399 bstp_set_other_tcprop(bp);
1400 /* send out notification */
1401 bp->bp_flags |= BSTP_PORT_NEWINFO;
1402 bstp_transmit(bs, bp);
1403 getmicrotime(&bs->bs_last_tc_time);
1404 DPRINTF("%s -> TC_DETECTED\n", bp->bp_ifp->if_xname);
1405 bp->bp_tcstate = BSTP_TCSTATE_ACTIVE; /* UCT */
1408 case BSTP_TCSTATE_TCN:
1409 bstp_set_timer_tc(bp);
1410 DPRINTF("%s -> TC_TCN\n", bp->bp_ifp->if_xname);
1412 case BSTP_TCSTATE_TC:
1415 if (bp->bp_role == BSTP_ROLE_DESIGNATED)
1418 bstp_set_other_tcprop(bp);
1419 DPRINTF("%s -> TC_TC\n", bp->bp_ifp->if_xname);
1420 bp->bp_tcstate = BSTP_TCSTATE_ACTIVE; /* UCT */
1423 case BSTP_TCSTATE_PROPAG:
1424 /* flush routes on the parent bridge */
1425 bp->bp_fdbflush = 1;
1426 taskqueue_enqueue(taskqueue_swi, &bp->bp_rtagetask);
1428 bstp_set_timer_tc(bp);
1429 DPRINTF("%s -> TC_PROPAG\n", bp->bp_ifp->if_xname);
1430 bp->bp_tcstate = BSTP_TCSTATE_ACTIVE; /* UCT */
1433 case BSTP_TCSTATE_ACK:
1434 bstp_timer_stop(&bp->bp_tc_timer);
1436 DPRINTF("%s -> TC_ACK\n", bp->bp_ifp->if_xname);
1437 bp->bp_tcstate = BSTP_TCSTATE_ACTIVE; /* UCT */
1443 bstp_set_timer_tc(struct bstp_port *bp)
1445 struct bstp_state *bs = bp->bp_bs;
1447 if (bp->bp_tc_timer.active)
1450 switch (bp->bp_protover) {
1451 case BSTP_PROTO_RSTP:
1452 bstp_timer_start(&bp->bp_tc_timer,
1453 bp->bp_desg_htime + BSTP_TICK_VAL);
1454 bp->bp_flags |= BSTP_PORT_NEWINFO;
1457 case BSTP_PROTO_STP:
1458 bstp_timer_start(&bp->bp_tc_timer,
1459 bs->bs_root_max_age + bs->bs_root_fdelay);
1465 bstp_set_timer_msgage(struct bstp_port *bp)
1467 if (bp->bp_port_msg_age + BSTP_MESSAGE_AGE_INCR <=
1468 bp->bp_port_max_age) {
1469 bstp_timer_start(&bp->bp_message_age_timer,
1470 bp->bp_port_htime * 3);
1472 /* expires immediately */
1473 bstp_timer_start(&bp->bp_message_age_timer, 0);
1477 bstp_rerooted(struct bstp_state *bs, struct bstp_port *bp)
1479 struct bstp_port *bp2;
1482 LIST_FOREACH(bp2, &bs->bs_bplist, bp_next) {
1485 if (bp2->bp_recent_root_timer.active) {
1494 bstp_set_htime(struct bstp_state *bs, int t)
1496 /* convert seconds to ticks */
1499 /* value can only be changed in leagacy stp mode */
1500 if (bs->bs_protover != BSTP_PROTO_STP)
1503 if (t < BSTP_MIN_HELLO_TIME || t > BSTP_MAX_HELLO_TIME)
1507 bs->bs_bridge_htime = t;
1514 bstp_set_fdelay(struct bstp_state *bs, int t)
1516 /* convert seconds to ticks */
1519 if (t < BSTP_MIN_FORWARD_DELAY || t > BSTP_MAX_FORWARD_DELAY)
1523 bs->bs_bridge_fdelay = t;
1530 bstp_set_maxage(struct bstp_state *bs, int t)
1532 /* convert seconds to ticks */
1535 if (t < BSTP_MIN_MAX_AGE || t > BSTP_MAX_MAX_AGE)
1539 bs->bs_bridge_max_age = t;
1546 bstp_set_holdcount(struct bstp_state *bs, int count)
1548 struct bstp_port *bp;
1550 if (count < BSTP_MIN_HOLD_COUNT ||
1551 count > BSTP_MAX_HOLD_COUNT)
1555 bs->bs_txholdcount = count;
1556 LIST_FOREACH(bp, &bs->bs_bplist, bp_next)
1563 bstp_set_protocol(struct bstp_state *bs, int proto)
1565 struct bstp_port *bp;
1568 /* Supported protocol versions */
1569 case BSTP_PROTO_STP:
1570 case BSTP_PROTO_RSTP:
1578 bs->bs_protover = proto;
1579 bs->bs_bridge_htime = BSTP_DEFAULT_HELLO_TIME;
1580 LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
1582 bp->bp_infois = BSTP_INFO_DISABLED;
1584 bstp_set_port_proto(bp, bs->bs_protover);
1585 bstp_set_port_role(bp, BSTP_ROLE_DISABLED);
1586 bstp_set_port_tc(bp, BSTP_TCSTATE_INACTIVE);
1587 bstp_timer_stop(&bp->bp_recent_backup_timer);
1595 bstp_set_priority(struct bstp_state *bs, int pri)
1597 if (pri < 0 || pri > BSTP_MAX_PRIORITY)
1600 /* Limit to steps of 4096 */
1604 bs->bs_bridge_priority = pri;
1611 bstp_set_port_priority(struct bstp_port *bp, int pri)
1613 struct bstp_state *bs = bp->bp_bs;
1615 if (pri < 0 || pri > BSTP_MAX_PORT_PRIORITY)
1618 /* Limit to steps of 16 */
1622 bp->bp_priority = pri;
1629 bstp_set_path_cost(struct bstp_port *bp, uint32_t path_cost)
1631 struct bstp_state *bs = bp->bp_bs;
1633 if (path_cost > BSTP_MAX_PATH_COST)
1636 /* STP compat mode only uses 16 bits of the 32 */
1637 if (bp->bp_protover == BSTP_PROTO_STP && path_cost > 65535)
1642 if (path_cost == 0) { /* use auto */
1643 bp->bp_flags &= ~BSTP_PORT_ADMCOST;
1644 bp->bp_path_cost = bstp_calc_path_cost(bp);
1646 bp->bp_path_cost = path_cost;
1647 bp->bp_flags |= BSTP_PORT_ADMCOST;
1655 bstp_set_edge(struct bstp_port *bp, int set)
1657 struct bstp_state *bs = bp->bp_bs;
1660 if ((bp->bp_operedge = set) == 0)
1661 bp->bp_flags &= ~BSTP_PORT_ADMEDGE;
1663 bp->bp_flags |= BSTP_PORT_ADMEDGE;
1669 bstp_set_autoedge(struct bstp_port *bp, int set)
1671 struct bstp_state *bs = bp->bp_bs;
1675 bp->bp_flags |= BSTP_PORT_AUTOEDGE;
1676 /* we may be able to transition straight to edge */
1677 if (bp->bp_edge_delay_timer.active == 0)
1678 bstp_edge_delay_expiry(bs, bp);
1680 bp->bp_flags &= ~BSTP_PORT_AUTOEDGE;
1686 bstp_set_ptp(struct bstp_port *bp, int set)
1688 struct bstp_state *bs = bp->bp_bs;
1691 bp->bp_ptp_link = set;
1697 bstp_set_autoptp(struct bstp_port *bp, int set)
1699 struct bstp_state *bs = bp->bp_bs;
1703 bp->bp_flags |= BSTP_PORT_AUTOPTP;
1704 if (bp->bp_role != BSTP_ROLE_DISABLED)
1705 taskqueue_enqueue(taskqueue_swi, &bp->bp_mediatask);
1707 bp->bp_flags &= ~BSTP_PORT_AUTOPTP;
1713 * Calculate the path cost according to the link speed.
1716 bstp_calc_path_cost(struct bstp_port *bp)
1718 struct ifnet *ifp = bp->bp_ifp;
1721 /* If the priority has been manually set then retain the value */
1722 if (bp->bp_flags & BSTP_PORT_ADMCOST)
1723 return bp->bp_path_cost;
1725 if (ifp->if_link_state == LINK_STATE_DOWN) {
1726 /* Recalc when the link comes up again */
1727 bp->bp_flags |= BSTP_PORT_PNDCOST;
1728 return (BSTP_DEFAULT_PATH_COST);
1731 if (ifp->if_baudrate < 1000)
1732 return (BSTP_DEFAULT_PATH_COST);
1734 /* formula from section 17.14, IEEE Std 802.1D-2004 */
1735 path_cost = 20000000000ULL / (ifp->if_baudrate / 1000);
1737 if (path_cost > BSTP_MAX_PATH_COST)
1738 path_cost = BSTP_MAX_PATH_COST;
1740 /* STP compat mode only uses 16 bits of the 32 */
1741 if (bp->bp_protover == BSTP_PROTO_STP && path_cost > 65535)
1748 * Notify the bridge that a port state has changed, we need to do this from a
1749 * taskqueue to avoid a LOR.
1752 bstp_notify_state(void *arg, int pending)
1754 struct bstp_port *bp = (struct bstp_port *)arg;
1755 struct bstp_state *bs = bp->bp_bs;
1757 if (bp->bp_active == 1 && bs->bs_state_cb != NULL)
1758 (*bs->bs_state_cb)(bp->bp_ifp, bp->bp_state);
1762 * Flush the routes on the bridge port, we need to do this from a
1763 * taskqueue to avoid a LOR.
1766 bstp_notify_rtage(void *arg, int pending)
1768 struct bstp_port *bp = (struct bstp_port *)arg;
1769 struct bstp_state *bs = bp->bp_bs;
1773 switch (bp->bp_protover) {
1774 case BSTP_PROTO_STP:
1775 /* convert to seconds */
1776 age = bp->bp_desg_fdelay / BSTP_TICK_VAL;
1779 case BSTP_PROTO_RSTP:
1785 if (bp->bp_active == 1 && bs->bs_rtage_cb != NULL)
1786 (*bs->bs_rtage_cb)(bp->bp_ifp, age);
1788 /* flush is complete */
1790 bp->bp_fdbflush = 0;
1795 bstp_linkstate(struct bstp_port *bp)
1797 struct bstp_state *bs = bp->bp_bs;
1802 bstp_ifupdstatus(bp, 0);
1804 bstp_update_state(bs, bp);
1809 bstp_ifupdstatus(void *arg, int pending)
1811 struct bstp_port *bp = (struct bstp_port *)arg;
1812 struct bstp_state *bs = bp->bp_bs;
1813 struct ifnet *ifp = bp->bp_ifp;
1814 struct ifmediareq ifmr;
1820 bzero((char *)&ifmr, sizeof(ifmr));
1821 error = (*ifp->if_ioctl)(ifp, SIOCGIFMEDIA, (caddr_t)&ifmr);
1825 if ((error == 0) && (ifp->if_flags & IFF_UP)) {
1826 if (ifmr.ifm_status & IFM_ACTIVE) {
1827 /* A full-duplex link is assumed to be point to point */
1828 if (bp->bp_flags & BSTP_PORT_AUTOPTP) {
1831 fdx = ifmr.ifm_active & IFM_FDX ? 1 : 0;
1832 if (bp->bp_ptp_link ^ fdx) {
1833 bp->bp_ptp_link = fdx;
1838 /* Calc the cost if the link was down previously */
1839 if (bp->bp_flags & BSTP_PORT_PNDCOST) {
1842 cost = bstp_calc_path_cost(bp);
1843 if (bp->bp_path_cost != cost) {
1844 bp->bp_path_cost = cost;
1847 bp->bp_flags &= ~BSTP_PORT_PNDCOST;
1850 if (bp->bp_role == BSTP_ROLE_DISABLED) {
1851 bstp_enable_port(bs, bp);
1855 if (bp->bp_role != BSTP_ROLE_DISABLED) {
1856 bstp_disable_port(bs, bp);
1858 if ((bp->bp_flags & BSTP_PORT_ADMEDGE) &&
1859 bp->bp_protover == BSTP_PROTO_RSTP)
1860 bp->bp_operedge = 1;
1863 } else if (bp->bp_infois != BSTP_INFO_DISABLED) {
1864 bstp_disable_port(bs, bp);
1868 bstp_assign_roles(bs);
1873 bstp_enable_port(struct bstp_state *bs, struct bstp_port *bp)
1875 bp->bp_infois = BSTP_INFO_AGED;
1879 bstp_disable_port(struct bstp_state *bs, struct bstp_port *bp)
1881 bp->bp_infois = BSTP_INFO_DISABLED;
1885 bstp_tick(void *arg)
1887 struct epoch_tracker et;
1888 struct bstp_state *bs = arg;
1889 struct bstp_port *bp;
1891 BSTP_LOCK_ASSERT(bs);
1893 if (bs->bs_running == 0)
1896 NET_EPOCH_ENTER(et);
1897 CURVNET_SET(bs->bs_vnet);
1899 /* poll link events on interfaces that do not support linkstate */
1900 if (bstp_timer_dectest(&bs->bs_link_timer)) {
1901 LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
1902 if (!(bp->bp_ifp->if_capabilities & IFCAP_LINKSTATE))
1903 taskqueue_enqueue(taskqueue_swi, &bp->bp_mediatask);
1905 bstp_timer_start(&bs->bs_link_timer, BSTP_LINK_TIMER);
1908 LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
1909 /* no events need to happen for these */
1910 bstp_timer_dectest(&bp->bp_tc_timer);
1911 bstp_timer_dectest(&bp->bp_recent_root_timer);
1912 bstp_timer_dectest(&bp->bp_forward_delay_timer);
1913 bstp_timer_dectest(&bp->bp_recent_backup_timer);
1915 if (bstp_timer_dectest(&bp->bp_hello_timer))
1916 bstp_hello_timer_expiry(bs, bp);
1918 if (bstp_timer_dectest(&bp->bp_message_age_timer))
1919 bstp_message_age_expiry(bs, bp);
1921 if (bstp_timer_dectest(&bp->bp_migrate_delay_timer))
1922 bstp_migrate_delay_expiry(bs, bp);
1924 if (bstp_timer_dectest(&bp->bp_edge_delay_timer))
1925 bstp_edge_delay_expiry(bs, bp);
1927 /* update the various state machines for the port */
1928 bstp_update_state(bs, bp);
1930 if (bp->bp_txcount > 0)
1937 callout_reset(&bs->bs_bstpcallout, hz, bstp_tick, bs);
1941 bstp_timer_start(struct bstp_timer *t, uint16_t v)
1949 bstp_timer_stop(struct bstp_timer *t)
1957 bstp_timer_latch(struct bstp_timer *t)
1964 bstp_timer_dectest(struct bstp_timer *t)
1966 if (t->active == 0 || t->latched)
1968 t->value -= BSTP_TICK_VAL;
1969 if (t->value <= 0) {
1977 bstp_hello_timer_expiry(struct bstp_state *bs, struct bstp_port *bp)
1979 if ((bp->bp_flags & BSTP_PORT_NEWINFO) ||
1980 bp->bp_role == BSTP_ROLE_DESIGNATED ||
1981 (bp->bp_role == BSTP_ROLE_ROOT &&
1982 bp->bp_tc_timer.active == 1)) {
1983 bstp_timer_start(&bp->bp_hello_timer, bp->bp_desg_htime);
1984 bp->bp_flags |= BSTP_PORT_NEWINFO;
1985 bstp_transmit(bs, bp);
1990 bstp_message_age_expiry(struct bstp_state *bs, struct bstp_port *bp)
1992 if (bp->bp_infois == BSTP_INFO_RECEIVED) {
1993 bp->bp_infois = BSTP_INFO_AGED;
1994 bstp_assign_roles(bs);
1995 DPRINTF("aged info on %s\n", bp->bp_ifp->if_xname);
2000 bstp_migrate_delay_expiry(struct bstp_state *bs, struct bstp_port *bp)
2002 bp->bp_flags |= BSTP_PORT_CANMIGRATE;
2006 bstp_edge_delay_expiry(struct bstp_state *bs, struct bstp_port *bp)
2008 if ((bp->bp_flags & BSTP_PORT_AUTOEDGE) &&
2009 bp->bp_protover == BSTP_PROTO_RSTP && bp->bp_proposing &&
2010 bp->bp_role == BSTP_ROLE_DESIGNATED) {
2011 bp->bp_operedge = 1;
2012 DPRINTF("%s -> edge port\n", bp->bp_ifp->if_xname);
2017 bstp_addr_cmp(const uint8_t *a, const uint8_t *b)
2021 for (i = 0, d = 0; i < ETHER_ADDR_LEN && d == 0; i++) {
2022 d = ((int)a[i]) - ((int)b[i]);
2029 * compare the bridge address component of the bridgeid
2032 bstp_same_bridgeid(uint64_t id1, uint64_t id2)
2034 u_char addr1[ETHER_ADDR_LEN];
2035 u_char addr2[ETHER_ADDR_LEN];
2037 PV2ADDR(id1, addr1);
2038 PV2ADDR(id2, addr2);
2040 if (bstp_addr_cmp(addr1, addr2) == 0)
2047 bstp_reinit(struct bstp_state *bs)
2049 struct epoch_tracker et;
2050 struct bstp_port *bp;
2051 struct ifnet *ifp, *mif;
2054 static const u_char llzero[ETHER_ADDR_LEN]; /* 00:00:00:00:00:00 */
2056 BSTP_LOCK_ASSERT(bs);
2058 if (LIST_EMPTY(&bs->bs_bplist))
2062 bridgeptr = LIST_FIRST(&bs->bs_bplist)->bp_ifp->if_bridge;
2063 KASSERT(bridgeptr != NULL, ("Invalid bridge pointer"));
2065 * Search through the Ethernet adapters and find the one with the
2066 * lowest value. Make sure the adapter which we take the MAC address
2067 * from is part of this bridge, so we can have more than one independent
2068 * bridges in the same STP domain.
2070 NET_EPOCH_ENTER(et);
2071 CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
2072 if (ifp->if_type != IFT_ETHER && ifp->if_type != IFT_L2VLAN)
2073 continue; /* Not Ethernet */
2075 if (ifp->if_bridge != bridgeptr)
2076 continue; /* Not part of our bridge */
2078 if (bstp_addr_cmp(IF_LLADDR(ifp), llzero) == 0)
2079 continue; /* No mac address set */
2085 if (bstp_addr_cmp(IF_LLADDR(ifp), IF_LLADDR(mif)) < 0) {
2094 e_addr = IF_LLADDR(mif);
2095 bs->bs_bridge_pv.pv_dbridge_id =
2096 (((uint64_t)bs->bs_bridge_priority) << 48) |
2097 (((uint64_t)e_addr[0]) << 40) |
2098 (((uint64_t)e_addr[1]) << 32) |
2099 (((uint64_t)e_addr[2]) << 24) |
2100 (((uint64_t)e_addr[3]) << 16) |
2101 (((uint64_t)e_addr[4]) << 8) |
2102 (((uint64_t)e_addr[5]));
2104 bs->bs_bridge_pv.pv_root_id = bs->bs_bridge_pv.pv_dbridge_id;
2105 bs->bs_bridge_pv.pv_cost = 0;
2106 bs->bs_bridge_pv.pv_dport_id = 0;
2107 bs->bs_bridge_pv.pv_port_id = 0;
2109 if (bs->bs_running && callout_pending(&bs->bs_bstpcallout) == 0)
2110 callout_reset(&bs->bs_bstpcallout, hz, bstp_tick, bs);
2112 LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
2113 bp->bp_port_id = (bp->bp_priority << 8) |
2114 (bp->bp_ifp->if_index & 0xfff);
2115 taskqueue_enqueue(taskqueue_swi, &bp->bp_mediatask);
2118 bstp_assign_roles(bs);
2119 bstp_timer_start(&bs->bs_link_timer, BSTP_LINK_TIMER);
2123 /* Set the bridge and root id (lower bits) to zero */
2124 bs->bs_bridge_pv.pv_dbridge_id =
2125 ((uint64_t)bs->bs_bridge_priority) << 48;
2126 bs->bs_bridge_pv.pv_root_id = bs->bs_bridge_pv.pv_dbridge_id;
2127 bs->bs_root_pv = bs->bs_bridge_pv;
2128 /* Disable any remaining ports, they will have no MAC address */
2129 LIST_FOREACH(bp, &bs->bs_bplist, bp_next) {
2130 bp->bp_infois = BSTP_INFO_DISABLED;
2131 bstp_set_port_role(bp, BSTP_ROLE_DISABLED);
2133 callout_stop(&bs->bs_bstpcallout);
2137 bstp_modevent(module_t mod, int type, void *data)
2141 mtx_init(&bstp_list_mtx, "bridgestp list", NULL, MTX_DEF);
2142 LIST_INIT(&bstp_list);
2145 mtx_destroy(&bstp_list_mtx);
2148 return (EOPNOTSUPP);
2153 static moduledata_t bstp_mod = {
2159 DECLARE_MODULE(bridgestp, bstp_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
2160 MODULE_VERSION(bridgestp, 1);
2163 bstp_attach(struct bstp_state *bs, struct bstp_cb_ops *cb)
2166 callout_init_mtx(&bs->bs_bstpcallout, &bs->bs_mtx, 0);
2167 LIST_INIT(&bs->bs_bplist);
2169 bs->bs_bridge_max_age = BSTP_DEFAULT_MAX_AGE;
2170 bs->bs_bridge_htime = BSTP_DEFAULT_HELLO_TIME;
2171 bs->bs_bridge_fdelay = BSTP_DEFAULT_FORWARD_DELAY;
2172 bs->bs_bridge_priority = BSTP_DEFAULT_BRIDGE_PRIORITY;
2173 bs->bs_hold_time = BSTP_DEFAULT_HOLD_TIME;
2174 bs->bs_migration_delay = BSTP_DEFAULT_MIGRATE_DELAY;
2175 bs->bs_txholdcount = BSTP_DEFAULT_HOLD_COUNT;
2176 bs->bs_protover = BSTP_PROTO_RSTP;
2177 bs->bs_state_cb = cb->bcb_state;
2178 bs->bs_rtage_cb = cb->bcb_rtage;
2179 bs->bs_vnet = curvnet;
2181 getmicrotime(&bs->bs_last_tc_time);
2183 mtx_lock(&bstp_list_mtx);
2184 LIST_INSERT_HEAD(&bstp_list, bs, bs_list);
2185 mtx_unlock(&bstp_list_mtx);
2189 bstp_detach(struct bstp_state *bs)
2191 KASSERT(LIST_EMPTY(&bs->bs_bplist), ("bstp still active"));
2193 mtx_lock(&bstp_list_mtx);
2194 LIST_REMOVE(bs, bs_list);
2195 mtx_unlock(&bstp_list_mtx);
2196 callout_drain(&bs->bs_bstpcallout);
2197 BSTP_LOCK_DESTROY(bs);
2201 bstp_init(struct bstp_state *bs)
2204 callout_reset(&bs->bs_bstpcallout, hz, bstp_tick, bs);
2211 bstp_stop(struct bstp_state *bs)
2213 struct bstp_port *bp;
2217 LIST_FOREACH(bp, &bs->bs_bplist, bp_next)
2218 bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
2221 callout_stop(&bs->bs_bstpcallout);
2226 bstp_create(struct bstp_state *bs, struct bstp_port *bp, struct ifnet *ifp)
2228 bzero(bp, sizeof(struct bstp_port));
2233 bp->bp_priority = BSTP_DEFAULT_PORT_PRIORITY;
2234 TASK_INIT(&bp->bp_statetask, 0, bstp_notify_state, bp);
2235 TASK_INIT(&bp->bp_rtagetask, 0, bstp_notify_rtage, bp);
2236 TASK_INIT(&bp->bp_mediatask, 0, bstp_ifupdstatus, bp);
2239 bp->bp_infois = BSTP_INFO_DISABLED;
2240 bp->bp_flags = BSTP_PORT_AUTOEDGE|BSTP_PORT_AUTOPTP;
2241 bstp_set_port_state(bp, BSTP_IFSTATE_DISCARDING);
2242 bstp_set_port_proto(bp, bs->bs_protover);
2243 bstp_set_port_role(bp, BSTP_ROLE_DISABLED);
2244 bstp_set_port_tc(bp, BSTP_TCSTATE_INACTIVE);
2245 bp->bp_path_cost = bstp_calc_path_cost(bp);
2251 bstp_enable(struct bstp_port *bp)
2253 struct bstp_state *bs = bp->bp_bs;
2254 struct ifnet *ifp = bp->bp_ifp;
2256 KASSERT(bp->bp_active == 0, ("already a bstp member"));
2257 NET_EPOCH_ASSERT(); /* Because bstp_update_roles() causes traffic. */
2259 switch (ifp->if_type) {
2260 case IFT_ETHER: /* These can do spanning tree. */
2264 /* Nothing else can. */
2269 LIST_INSERT_HEAD(&bs->bs_bplist, bp, bp_next);
2271 bp->bp_flags |= BSTP_PORT_NEWINFO;
2273 bstp_update_roles(bs, bp);
2279 bstp_disable(struct bstp_port *bp)
2281 struct bstp_state *bs = bp->bp_bs;
2283 KASSERT(bp->bp_active == 1, ("not a bstp member"));
2286 bstp_disable_port(bs, bp);
2287 LIST_REMOVE(bp, bp_next);
2294 * The bstp_port structure is about to be freed by the parent bridge.
2297 bstp_destroy(struct bstp_port *bp)
2299 KASSERT(bp->bp_active == 0, ("port is still attached"));
2300 taskqueue_drain(taskqueue_swi, &bp->bp_statetask);
2301 taskqueue_drain(taskqueue_swi, &bp->bp_rtagetask);
2302 taskqueue_drain(taskqueue_swi, &bp->bp_mediatask);
2304 if (bp->bp_bs->bs_root_port == bp)
2305 bstp_assign_roles(bp->bp_bs);