Deleted Added
full compact
bridgestp.h (160899) bridgestp.h (163863)
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 *

--- 53 unchanged lines hidden (view full) ---

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 *
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 *

--- 53 unchanged lines hidden (view full) ---

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 160899 2006-08-02 02:47:27Z thompsa $
70 * $FreeBSD: head/sys/net/bridgestp.h 163863 2006-11-01 09:07:47Z 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
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#define BSTP_IFSTATE_DISCARDING 5
86
87
88#define BSTP_TCSTATE_ACTIVE 1
89#define BSTP_TCSTATE_DETECTED 2
90#define BSTP_TCSTATE_INACTIVE 3
91#define BSTP_TCSTATE_LEARNING 4
92#define BSTP_TCSTATE_PROPAG 5
93#define BSTP_TCSTATE_ACK 6
94#define BSTP_TCSTATE_TC 7
95#define BSTP_TCSTATE_TCN 8
96
97#define BSTP_ROLE_DISABLED 0
98#define BSTP_ROLE_ROOT 1
99#define BSTP_ROLE_DESIGNATED 2
100#define BSTP_ROLE_ALTERNATE 3
101#define BSTP_ROLE_BACKUP 4
102
87#ifdef _KERNEL
88
103#ifdef _KERNEL
104
105/* STP port flags */
106#define BSTP_PORT_CANMIGRATE 0x0001
107#define BSTP_PORT_NEWINFO 0x0002
108#define BSTP_PORT_DISPUTED 0x0004
109#define BSTP_PORT_ADMCOST 0x0008
110#define BSTP_PORT_AUTOEDGE 0x0010
111
112/* BPDU priority */
113#define BSTP_PDU_SUPERIOR 1
114#define BSTP_PDU_REPEATED 2
115#define BSTP_PDU_INFERIOR 3
116#define BSTP_PDU_INFERIORALT 4
117#define BSTP_PDU_OTHER 5
118
119/* BPDU flags */
120#define BSTP_PDU_PRMASK 0x0c /* Port Role */
121#define BSTP_PDU_PRSHIFT 2 /* Port Role offset */
122#define BSTP_PDU_F_UNKN 0x00 /* Unknown port (00) */
123#define BSTP_PDU_F_ALT 0x01 /* Alt/Backup port (01) */
124#define BSTP_PDU_F_ROOT 0x02 /* Root port (10) */
125#define BSTP_PDU_F_DESG 0x03 /* Designated port (11) */
126
127#define BSTP_PDU_STPMASK 0x81 /* strip unused STP flags */
128#define BSTP_PDU_RSTPMASK 0x7f /* strip unused RSTP flags */
129#define BSTP_PDU_F_TC 0x01 /* Topology change */
130#define BSTP_PDU_F_P 0x02 /* Proposal flag */
131#define BSTP_PDU_F_L 0x10 /* Learning flag */
132#define BSTP_PDU_F_F 0x20 /* Forwarding flag */
133#define BSTP_PDU_F_A 0x40 /* Agreement flag */
134#define BSTP_PDU_F_TCA 0x80 /* Topology change ack */
135
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)
136/*
137 * Spanning tree defaults.
138 */
139#define BSTP_DEFAULT_MAX_AGE (20 * 256)
140#define BSTP_DEFAULT_HELLO_TIME (2 * 256)
141#define BSTP_DEFAULT_FORWARD_DELAY (15 * 256)
142#define BSTP_DEFAULT_HOLD_TIME (1 * 256)
143#define BSTP_DEFAULT_MIGRATE_DELAY (3 * 256)
144#define BSTP_DEFAULT_HOLD_COUNT 6
96#define BSTP_DEFAULT_BRIDGE_PRIORITY 0x8000
97#define BSTP_DEFAULT_PORT_PRIORITY 0x80
98#define BSTP_DEFAULT_PATH_COST 55
145#define BSTP_DEFAULT_BRIDGE_PRIORITY 0x8000
146#define BSTP_DEFAULT_PORT_PRIORITY 0x80
147#define BSTP_DEFAULT_PATH_COST 55
148#define BSTP_MIN_HELLO_TIME (1 * 256)
149#define BSTP_MIN_MAX_AGE (6 * 256)
150#define BSTP_MIN_FORWARD_DELAY (4 * 256)
151#define BSTP_MIN_HOLD_COUNT 1
152#define BSTP_MAX_HELLO_TIME (2 * 256)
153#define BSTP_MAX_MAX_AGE (40 * 256)
154#define BSTP_MAX_FORWARD_DELAY (30 * 256)
155#define BSTP_MAX_HOLD_COUNT 10
156#define BSTP_MAX_PRIORITY 61440
157#define BSTP_MAX_PORT_PRIORITY 240
158#define BSTP_MAX_PATH_COST 200000000
99
100/* BPDU message types */
101#define BSTP_MSGTYPE_CFG 0x00 /* Configuration */
159
160/* BPDU message types */
161#define BSTP_MSGTYPE_CFG 0x00 /* Configuration */
162#define BSTP_MSGTYPE_RSTP 0x02 /* Rapid STP */
102#define BSTP_MSGTYPE_TCN 0x80 /* Topology chg notification */
103
163#define BSTP_MSGTYPE_TCN 0x80 /* Topology chg notification */
164
104/* BPDU flags */
105#define BSTP_FLAG_TC 0x01 /* Topology change */
106#define BSTP_FLAG_TCA 0x80 /* Topology change ack */
165/* Protocol versions */
166#define BSTP_PROTO_ID 0x00
167#define BSTP_PROTO_STP 0x00
168#define BSTP_PROTO_RSTP 0x02
169#define BSTP_PROTO_MAX BSTP_PROTO_RSTP
107
170
171#define BSTP_INFO_RECIEVED 1
172#define BSTP_INFO_MINE 2
173#define BSTP_INFO_AGED 3
174#define BSTP_INFO_DISABLED 4
175
176
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 */
177#define BSTP_MESSAGE_AGE_INCR (1 * 256) /* in 256ths of a second */
178#define BSTP_TICK_VAL (1 * 256) /* in 256ths of a second */
110#define BSTP_LINK_TIMER (BSTP_TICK_VAL * 30)
179#define BSTP_LINK_TIMER (BSTP_TICK_VAL * 15)
111
112/*
180
181/*
113 * * Driver callbacks for STP state changes
114 * */
182 * Driver callbacks for STP state changes
183 */
115typedef void (*bstp_state_cb_t)(struct ifnet *, int);
184typedef void (*bstp_state_cb_t)(struct ifnet *, int);
185typedef void (*bstp_rtage_cb_t)(struct ifnet *, int);
116
117/*
118 * Because BPDU's do not make nicely aligned structures, two different
119 * declarations are used: bstp_?bpdu (wire representation, packed) and
120 * bstp_*_unit (internal, nicely aligned version).
121 */
122
123/* configuration bridge protocol data unit */
124struct bstp_cbpdu {
125 uint8_t cbu_dsap; /* LLC: destination sap */
126 uint8_t cbu_ssap; /* LLC: source sap */
127 uint8_t cbu_ctl; /* LLC: control */
128 uint16_t cbu_protoid; /* protocol id */
129 uint8_t cbu_protover; /* protocol version */
130 uint8_t cbu_bpdutype; /* message type */
131 uint8_t cbu_flags; /* flags (below) */
132
133 /* root id */
134 uint16_t cbu_rootpri; /* root priority */
186
187/*
188 * Because BPDU's do not make nicely aligned structures, two different
189 * declarations are used: bstp_?bpdu (wire representation, packed) and
190 * bstp_*_unit (internal, nicely aligned version).
191 */
192
193/* configuration bridge protocol data unit */
194struct bstp_cbpdu {
195 uint8_t cbu_dsap; /* LLC: destination sap */
196 uint8_t cbu_ssap; /* LLC: source sap */
197 uint8_t cbu_ctl; /* LLC: control */
198 uint16_t cbu_protoid; /* protocol id */
199 uint8_t cbu_protover; /* protocol version */
200 uint8_t cbu_bpdutype; /* message type */
201 uint8_t cbu_flags; /* flags (below) */
202
203 /* root id */
204 uint16_t cbu_rootpri; /* root priority */
135 uint8_t cbu_rootaddr[6]; /* root address */
205 uint8_t cbu_rootaddr[6]; /* root address */
136
137 uint32_t cbu_rootpathcost; /* root path cost */
138
139 /* bridge id */
140 uint16_t cbu_bridgepri; /* bridge priority */
141 uint8_t cbu_bridgeaddr[6]; /* bridge address */
142
143 uint16_t cbu_portid; /* port id */
144 uint16_t cbu_messageage; /* current message age */
145 uint16_t cbu_maxage; /* maximum age */
146 uint16_t cbu_hellotime; /* hello time */
147 uint16_t cbu_forwarddelay; /* forwarding delay */
206
207 uint32_t cbu_rootpathcost; /* root path cost */
208
209 /* bridge id */
210 uint16_t cbu_bridgepri; /* bridge priority */
211 uint8_t cbu_bridgeaddr[6]; /* bridge address */
212
213 uint16_t cbu_portid; /* port id */
214 uint16_t cbu_messageage; /* current message age */
215 uint16_t cbu_maxage; /* maximum age */
216 uint16_t cbu_hellotime; /* hello time */
217 uint16_t cbu_forwarddelay; /* forwarding delay */
218 uint8_t cbu_versionlen; /* version 1 length */
148} __attribute__((__packed__));
219} __attribute__((__packed__));
220#define BSTP_BPDU_STP_LEN (3 + 35) /* LLC + STP pdu */
221#define BSTP_BPDU_RSTP_LEN (3 + 36) /* LLC + RSTP pdu */
149
150/* topology change notification bridge protocol data unit */
151struct bstp_tbpdu {
152 uint8_t tbu_dsap; /* LLC: destination sap */
153 uint8_t tbu_ssap; /* LLC: source sap */
154 uint8_t tbu_ctl; /* LLC: control */
155 uint16_t tbu_protoid; /* protocol id */
156 uint8_t tbu_protover; /* protocol version */
157 uint8_t tbu_bpdutype; /* message type */
158} __attribute__((__packed__));
159
160/*
161 * Timekeeping structure used in spanning tree code.
162 */
163struct bstp_timer {
222
223/* topology change notification bridge protocol data unit */
224struct bstp_tbpdu {
225 uint8_t tbu_dsap; /* LLC: destination sap */
226 uint8_t tbu_ssap; /* LLC: source sap */
227 uint8_t tbu_ctl; /* LLC: control */
228 uint16_t tbu_protoid; /* protocol id */
229 uint8_t tbu_protover; /* protocol version */
230 uint8_t tbu_bpdutype; /* message type */
231} __attribute__((__packed__));
232
233/*
234 * Timekeeping structure used in spanning tree code.
235 */
236struct bstp_timer {
164 uint16_t active;
165 uint16_t value;
237 int active;
238 int latched;
239 int value;
166};
167
240};
241
242struct bstp_pri_vector {
243 uint64_t pv_root_id;
244 uint32_t pv_cost;
245 uint64_t pv_dbridge_id;
246 uint16_t pv_dport_id;
247 uint16_t pv_port_id;
248};
249
168struct bstp_config_unit {
250struct bstp_config_unit {
169 uint64_t cu_rootid;
170 uint64_t cu_bridge_id;
171 uint32_t cu_root_path_cost;
251 struct bstp_pri_vector cu_pv;
172 uint16_t cu_message_age;
173 uint16_t cu_max_age;
252 uint16_t cu_message_age;
253 uint16_t cu_max_age;
174 uint16_t cu_hello_time;
175 uint16_t cu_forward_delay;
254 uint16_t cu_forward_delay;
176 uint16_t cu_port_id;
255 uint16_t cu_hello_time;
177 uint8_t cu_message_type;
256 uint8_t cu_message_type;
178 uint8_t cu_topology_change_acknowledgment;
257 uint8_t cu_topology_change_ack;
179 uint8_t cu_topology_change;
258 uint8_t cu_topology_change;
259 uint8_t cu_proposal;
260 uint8_t cu_agree;
261 uint8_t cu_learning;
262 uint8_t cu_forwarding;
263 uint8_t cu_role;
180};
181
182struct bstp_tcn_unit {
183 uint8_t tu_message_type;
184};
185
264};
265
266struct bstp_tcn_unit {
267 uint8_t tu_message_type;
268};
269
186/*
187 * Bridge interface list entry.
188 */
189struct bstp_port {
190 LIST_ENTRY(bstp_port) bp_next;
191 struct ifnet *bp_ifp; /* parent if */
192 struct bstp_state *bp_bs;
270struct bstp_port {
271 LIST_ENTRY(bstp_port) bp_next;
272 struct ifnet *bp_ifp; /* parent if */
273 struct bstp_state *bp_bs;
193 int bp_active;
194 uint64_t bp_designated_root;
195 uint64_t bp_designated_bridge;
274 uint8_t bp_active;
275 uint8_t bp_protover;
276 uint32_t bp_flags;
196 uint32_t bp_path_cost;
277 uint32_t bp_path_cost;
197 uint32_t bp_designated_cost;
198 struct bstp_timer bp_hold_timer;
199 struct bstp_timer bp_message_age_timer;
278 uint16_t bp_port_msg_age;
279 uint16_t bp_port_max_age;
280 uint16_t bp_port_fdelay;
281 uint16_t bp_port_htime;
282 uint16_t bp_desg_msg_age;
283 uint16_t bp_desg_max_age;
284 uint16_t bp_desg_fdelay;
285 uint16_t bp_desg_htime;
286 struct bstp_timer bp_edge_delay_timer;
200 struct bstp_timer bp_forward_delay_timer;
287 struct bstp_timer bp_forward_delay_timer;
201 struct bstp_config_unit bp_config_bpdu;
288 struct bstp_timer bp_hello_timer;
289 struct bstp_timer bp_message_age_timer;
290 struct bstp_timer bp_migrate_delay_timer;
291 struct bstp_timer bp_recent_backup_timer;
292 struct bstp_timer bp_recent_root_timer;
293 struct bstp_timer bp_tc_timer;
294 struct bstp_config_unit bp_msg_cu;
295 struct bstp_pri_vector bp_desg_pv;
296 struct bstp_pri_vector bp_port_pv;
202 uint16_t bp_port_id;
297 uint16_t bp_port_id;
203 uint16_t bp_designated_port;
204 uint8_t bp_state;
298 uint8_t bp_state;
205 uint8_t bp_topology_change_acknowledge;
206 uint8_t bp_config_pending;
207 uint8_t bp_change_detection_enabled;
299 uint8_t bp_tcstate;
300 uint8_t bp_role;
301 uint8_t bp_infois;
302 uint8_t bp_tc_ack;
303 uint8_t bp_tc_prop;
304 uint8_t bp_fdbflush;
208 uint8_t bp_priority;
305 uint8_t bp_priority;
306 uint8_t bp_p2p_link;
307 uint8_t bp_agree;
308 uint8_t bp_agreed;
309 uint8_t bp_sync;
310 uint8_t bp_synced;
311 uint8_t bp_proposing;
312 uint8_t bp_proposed;
313 uint8_t bp_operedge;
314 uint8_t bp_reroot;
315 uint8_t bp_rcvdtc;
316 uint8_t bp_rcvdtca;
317 uint8_t bp_rcvdtcn;
209 uint32_t bp_forward_transitions;
318 uint32_t bp_forward_transitions;
319 uint8_t bp_txcount;
210 struct task bp_statetask;
320 struct task bp_statetask;
321 struct task bp_rtagetask;
211};
212
213/*
214 * Software state for each bridge STP.
215 */
216struct bstp_state {
217 LIST_ENTRY(bstp_state) bs_list;
218 struct mtx bs_mtx;
322};
323
324/*
325 * Software state for each bridge STP.
326 */
327struct bstp_state {
328 LIST_ENTRY(bstp_state) bs_list;
329 struct mtx bs_mtx;
219 uint64_t bs_designated_root;
220 uint64_t bs_bridge_id;
330 struct bstp_pri_vector bs_bridge_pv;
331 struct bstp_pri_vector bs_root_pv;
221 struct bstp_port *bs_root_port;
332 struct bstp_port *bs_root_port;
222 uint32_t bs_root_path_cost;
223 uint16_t bs_max_age;
224 uint16_t bs_hello_time;
225 uint16_t bs_forward_delay;
333 uint8_t bs_protover;
334 uint16_t bs_migration_delay;
335 uint16_t bs_edge_delay;
226 uint16_t bs_bridge_max_age;
336 uint16_t bs_bridge_max_age;
227 uint16_t bs_bridge_hello_time;
228 uint16_t bs_bridge_forward_delay;
229 uint16_t bs_topology_change_time;
337 uint16_t bs_bridge_fdelay;
338 uint16_t bs_bridge_htime;
339 uint16_t bs_root_msg_age;
340 uint16_t bs_root_max_age;
341 uint16_t bs_root_fdelay;
342 uint16_t bs_root_htime;
230 uint16_t bs_hold_time;
231 uint16_t bs_bridge_priority;
343 uint16_t bs_hold_time;
344 uint16_t bs_bridge_priority;
232 uint8_t bs_topology_change_detected;
233 uint8_t bs_topology_change;
234 struct bstp_timer bs_hello_timer;
235 struct bstp_timer bs_topology_change_timer;
236 struct bstp_timer bs_tcn_timer;
345 uint8_t bs_txholdcount;
346 uint8_t bs_allsynced;
237 struct callout bs_bstpcallout; /* STP callout */
238 struct bstp_timer bs_link_timer;
239 struct timeval bs_last_tc_time;
240 LIST_HEAD(, bstp_port) bs_bplist;
241 bstp_state_cb_t bs_state_cb;
347 struct callout bs_bstpcallout; /* STP callout */
348 struct bstp_timer bs_link_timer;
349 struct timeval bs_last_tc_time;
350 LIST_HEAD(, bstp_port) bs_bplist;
351 bstp_state_cb_t bs_state_cb;
352 bstp_rtage_cb_t bs_rtage_cb;
242};
243
353};
354
244#define BSTP_LOCK_INIT(_bs) mtx_init(&(_bs)->bs_mtx, "bstp", \
245 NULL, MTX_DEF)
246#define BSTP_LOCK_DESTROY(_bs) mtx_destroy(&(_bs)->bs_mtx)
247#define BSTP_LOCK(_bs) mtx_lock(&(_bs)->bs_mtx)
248#define BSTP_UNLOCK(_bs) mtx_unlock(&(_bs)->bs_mtx)
249#define BSTP_LOCK_ASSERT(_bs) mtx_assert(&(_bs)->bs_mtx, MA_OWNED)
355#define BSTP_LOCK_INIT(_bs) mtx_init(&(_bs)->bs_mtx, "bstp", NULL, MTX_DEF)
356#define BSTP_LOCK_DESTROY(_bs) mtx_destroy(&(_bs)->bs_mtx)
357#define BSTP_LOCK(_bs) mtx_lock(&(_bs)->bs_mtx)
358#define BSTP_UNLOCK(_bs) mtx_unlock(&(_bs)->bs_mtx)
359#define BSTP_LOCK_ASSERT(_bs) mtx_assert(&(_bs)->bs_mtx, MA_OWNED)
250
251extern const uint8_t bstp_etheraddr[];
252
253extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state);
254
360
361extern const uint8_t bstp_etheraddr[];
362
363extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state);
364
255void bstp_attach(struct bstp_state *, bstp_state_cb_t);
365void bstp_attach(struct bstp_state *, bstp_state_cb_t, bstp_rtage_cb_t);
256void bstp_detach(struct bstp_state *);
257void bstp_init(struct bstp_state *);
366void bstp_detach(struct bstp_state *);
367void bstp_init(struct bstp_state *);
258void bstp_reinit(struct bstp_state *);
259void bstp_stop(struct bstp_state *);
260int bstp_add(struct bstp_state *, struct bstp_port *, struct ifnet *);
261void bstp_delete(struct bstp_port *);
262void bstp_drain(struct bstp_port *);
263void bstp_linkstate(struct ifnet *, int);
368void bstp_stop(struct bstp_state *);
369int bstp_add(struct bstp_state *, struct bstp_port *, struct ifnet *);
370void bstp_delete(struct bstp_port *);
371void bstp_drain(struct bstp_port *);
372void bstp_linkstate(struct ifnet *, int);
373int bstp_set_htime(struct bstp_state *, int);
374int bstp_set_fdelay(struct bstp_state *, int);
375int bstp_set_maxage(struct bstp_state *, int);
376int bstp_set_holdcount(struct bstp_state *, int);
377int bstp_set_protocol(struct bstp_state *, int);
378int bstp_set_priority(struct bstp_state *, int);
379int bstp_set_port_priority(struct bstp_port *, int);
380int bstp_set_path_cost(struct bstp_port *, uint32_t);
381int bstp_set_edge(struct bstp_port *, int);
382int bstp_set_autoedge(struct bstp_port *, int);
264struct mbuf *bstp_input(struct bstp_port *, struct ifnet *, struct mbuf *);
265
266#endif /* _KERNEL */
383struct mbuf *bstp_input(struct bstp_port *, struct ifnet *, struct mbuf *);
384
385#endif /* _KERNEL */