bridgestp.h revision 160867
1/* $NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $ */ 2 3/* 4 * Copyright 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38/* 39 * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) 40 * All rights reserved. 41 * 42 * Redistribution and use in source and binary forms, with or without 43 * modification, are permitted provided that the following conditions 44 * are met: 45 * 1. Redistributions of source code must retain the above copyright 46 * notice, this list of conditions and the following disclaimer. 47 * 2. Redistributions in binary form must reproduce the above copyright 48 * notice, this list of conditions and the following disclaimer in the 49 * documentation and/or other materials provided with the distribution. 50 * 3. All advertising materials mentioning features or use of this software 51 * must display the following acknowledgement: 52 * This product includes software developed by Jason L. Wright 53 * 4. The name of the author may not be used to endorse or promote products 54 * derived from this software without specific prior written permission. 55 * 56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 57 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 58 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 59 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 60 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 61 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 62 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 65 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 66 * POSSIBILITY OF SUCH DAMAGE. 67 * 68 * OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp 69 * 70 * $FreeBSD: head/sys/net/bridgestp.h 160867 2006-07-31 20:24:46Z thompsa $ 71 */ 72 73/* 74 * Data structure and control definitions for STP interfaces. 75 */ 76 77#include <sys/callout.h> 78#include <sys/queue.h> 79 80/* STP port states */ 81#define BSTP_IFSTATE_DISABLED 0 82#define BSTP_IFSTATE_LISTENING 1 83#define BSTP_IFSTATE_LEARNING 2 84#define BSTP_IFSTATE_FORWARDING 3 85#define BSTP_IFSTATE_BLOCKING 4 86 87#ifdef _KERNEL 88 89/* 90 * Spanning tree defaults. 91 */ 92#define BSTP_DEFAULT_MAX_AGE (20 * 256) 93#define BSTP_DEFAULT_HELLO_TIME (2 * 256) 94#define BSTP_DEFAULT_FORWARD_DELAY (15 * 256) 95#define BSTP_DEFAULT_HOLD_TIME (1 * 256) 96#define BSTP_DEFAULT_BRIDGE_PRIORITY 0x8000 97#define BSTP_DEFAULT_PORT_PRIORITY 0x80 98#define BSTP_DEFAULT_PATH_COST 55 99 100/* BPDU message types */ 101#define BSTP_MSGTYPE_CFG 0x00 /* Configuration */ 102#define BSTP_MSGTYPE_TCN 0x80 /* Topology chg notification */ 103 104/* BPDU flags */ 105#define BSTP_FLAG_TC 0x01 /* Topology change */ 106#define BSTP_FLAG_TCA 0x80 /* Topology change ack */ 107 108#define BSTP_MESSAGE_AGE_INCR (1 * 256) /* in 256ths of a second */ 109#define BSTP_TICK_VAL (1 * 256) /* in 256ths of a second */ 110#define BSTP_LINK_TIMER (BSTP_TICK_VAL * 30) 111 112/* 113 * Because BPDU's do not make nicely aligned structures, two different 114 * declarations are used: bstp_?bpdu (wire representation, packed) and 115 * bstp_*_unit (internal, nicely aligned version). 116 */ 117 118/* configuration bridge protocol data unit */ 119struct bstp_cbpdu { 120 uint8_t cbu_dsap; /* LLC: destination sap */ 121 uint8_t cbu_ssap; /* LLC: source sap */ 122 uint8_t cbu_ctl; /* LLC: control */ 123 uint16_t cbu_protoid; /* protocol id */ 124 uint8_t cbu_protover; /* protocol version */ 125 uint8_t cbu_bpdutype; /* message type */ 126 uint8_t cbu_flags; /* flags (below) */ 127 128 /* root id */ 129 uint16_t cbu_rootpri; /* root priority */ 130 uint8_t cbu_rootaddr[6]; /* root address */ 131 132 uint32_t cbu_rootpathcost; /* root path cost */ 133 134 /* bridge id */ 135 uint16_t cbu_bridgepri; /* bridge priority */ 136 uint8_t cbu_bridgeaddr[6]; /* bridge address */ 137 138 uint16_t cbu_portid; /* port id */ 139 uint16_t cbu_messageage; /* current message age */ 140 uint16_t cbu_maxage; /* maximum age */ 141 uint16_t cbu_hellotime; /* hello time */ 142 uint16_t cbu_forwarddelay; /* forwarding delay */ 143} __attribute__((__packed__)); 144 145/* topology change notification bridge protocol data unit */ 146struct bstp_tbpdu { 147 uint8_t tbu_dsap; /* LLC: destination sap */ 148 uint8_t tbu_ssap; /* LLC: source sap */ 149 uint8_t tbu_ctl; /* LLC: control */ 150 uint16_t tbu_protoid; /* protocol id */ 151 uint8_t tbu_protover; /* protocol version */ 152 uint8_t tbu_bpdutype; /* message type */ 153} __attribute__((__packed__)); 154 155/* 156 * Timekeeping structure used in spanning tree code. 157 */ 158struct bstp_timer { 159 uint16_t active; 160 uint16_t value; 161}; 162 163struct bstp_config_unit { 164 uint64_t cu_rootid; 165 uint64_t cu_bridge_id; 166 uint32_t cu_root_path_cost; 167 uint16_t cu_message_age; 168 uint16_t cu_max_age; 169 uint16_t cu_hello_time; 170 uint16_t cu_forward_delay; 171 uint16_t cu_port_id; 172 uint8_t cu_message_type; 173 uint8_t cu_topology_change_acknowledgment; 174 uint8_t cu_topology_change; 175}; 176 177struct bstp_tcn_unit { 178 uint8_t tu_message_type; 179}; 180 181/* 182 * Bridge interface list entry. 183 */ 184struct bstp_port { 185 LIST_ENTRY(bstp_port) bp_next; 186 struct ifnet *bp_ifp; /* parent if */ 187 struct bstp_state *bp_bs; 188 int bp_active; 189 uint64_t bp_designated_root; 190 uint64_t bp_designated_bridge; 191 uint32_t bp_path_cost; 192 uint32_t bp_designated_cost; 193 struct bstp_timer bp_hold_timer; 194 struct bstp_timer bp_message_age_timer; 195 struct bstp_timer bp_forward_delay_timer; 196 struct bstp_config_unit bp_config_bpdu; 197 uint16_t bp_port_id; 198 uint16_t bp_designated_port; 199 uint8_t bp_state; 200 uint8_t bp_topology_change_acknowledge; 201 uint8_t bp_config_pending; 202 uint8_t bp_change_detection_enabled; 203 uint8_t bp_priority; 204 uint32_t bp_forward_transitions; 205}; 206 207/* 208 * Software state for each bridge STP. 209 */ 210struct bstp_state { 211 LIST_ENTRY(bstp_state) bs_list; 212 struct mtx bs_mtx; 213 uint64_t bs_designated_root; 214 uint64_t bs_bridge_id; 215 struct bstp_port *bs_root_port; 216 uint32_t bs_root_path_cost; 217 uint16_t bs_max_age; 218 uint16_t bs_hello_time; 219 uint16_t bs_forward_delay; 220 uint16_t bs_bridge_max_age; 221 uint16_t bs_bridge_hello_time; 222 uint16_t bs_bridge_forward_delay; 223 uint16_t bs_topology_change_time; 224 uint16_t bs_hold_time; 225 uint16_t bs_bridge_priority; 226 uint8_t bs_topology_change_detected; 227 uint8_t bs_topology_change; 228 struct bstp_timer bs_hello_timer; 229 struct bstp_timer bs_topology_change_timer; 230 struct bstp_timer bs_tcn_timer; 231 struct callout bs_bstpcallout; /* STP callout */ 232 struct bstp_timer bs_link_timer; 233 struct timeval bs_last_tc_time; 234 LIST_HEAD(, bstp_port) bs_bplist; 235}; 236 237#define BSTP_LOCK_INIT(_bs) mtx_init(&(_bs)->bs_mtx, "bstp", \ 238 NULL, MTX_DEF) 239#define BSTP_LOCK_DESTROY(_bs) mtx_destroy(&(_bs)->bs_mtx) 240#define BSTP_LOCK(_bs) mtx_lock(&(_bs)->bs_mtx) 241#define BSTP_UNLOCK(_bs) mtx_unlock(&(_bs)->bs_mtx) 242#define BSTP_LOCK_ASSERT(_bs) mtx_assert(&(_bs)->bs_mtx, MA_OWNED) 243 244extern const uint8_t bstp_etheraddr[]; 245 246extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state); 247 248void bstp_attach(struct bstp_state *); 249void bstp_detach(struct bstp_state *); 250void bstp_init(struct bstp_state *); 251void bstp_reinit(struct bstp_state *); 252void bstp_stop(struct bstp_state *); 253int bstp_add(struct bstp_state *, struct bstp_port *, struct ifnet *); 254void bstp_delete(struct bstp_port *); 255void bstp_linkstate(struct ifnet *, int); 256struct mbuf *bstp_input(struct bstp_port *, struct ifnet *, struct mbuf *); 257 258#endif /* _KERNEL */ 259