1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #ifndef _NET_IF_BRIDGE_H_
36 #define _NET_IF_BRIDGE_H_
37
38 #include <net/pfvar.h>
39
40
41
42
43 struct ifbreq {
44 char ifbr_name[IFNAMSIZ];
45 char ifbr_ifsname[IFNAMSIZ];
46 u_int32_t ifbr_ifsflags;
47 u_int8_t ifbr_portno;
48
49 u_int8_t ifbr_state;
50 u_int8_t ifbr_priority;
51 u_int32_t ifbr_path_cost;
52 u_int32_t ifbr_stpflags;
53 u_int8_t ifbr_proto;
54 u_int8_t ifbr_role;
55 u_int32_t ifbr_fwd_trans;
56 u_int64_t ifbr_desg_bridge;
57 u_int32_t ifbr_desg_port;
58 u_int64_t ifbr_root_bridge;
59 u_int32_t ifbr_root_cost;
60 u_int32_t ifbr_root_port;
61 };
62
63
64 #define IFBIF_LEARNING 0x0001
65 #define IFBIF_DISCOVER 0x0002
66 #define IFBIF_BLOCKNONIP 0x0004
67 #define IFBIF_STP 0x0008
68 #define IFBIF_BSTP_EDGE 0x0010
69 #define IFBIF_BSTP_AUTOEDGE 0x0020
70 #define IFBIF_BSTP_PTP 0x0040
71 #define IFBIF_BSTP_AUTOPTP 0x0080
72 #define IFBIF_SPAN 0x0100
73 #define IFBIF_RO_MASK 0xff00
74
75
76 #define IFBF_FLUSHDYN 0x0
77 #define IFBF_FLUSHALL 0x1
78
79
80 #define BSTP_IFSTATE_DISABLED 0
81 #define BSTP_IFSTATE_LISTENING 1
82 #define BSTP_IFSTATE_LEARNING 2
83 #define BSTP_IFSTATE_FORWARDING 3
84 #define BSTP_IFSTATE_BLOCKING 4
85 #define BSTP_IFSTATE_DISCARDING 5
86
87 #define BSTP_TCSTATE_ACTIVE 1
88 #define BSTP_TCSTATE_DETECTED 2
89 #define BSTP_TCSTATE_INACTIVE 3
90 #define BSTP_TCSTATE_LEARNING 4
91 #define BSTP_TCSTATE_PROPAG 5
92 #define BSTP_TCSTATE_ACK 6
93 #define BSTP_TCSTATE_TC 7
94 #define BSTP_TCSTATE_TCN 8
95
96 #define BSTP_ROLE_DISABLED 0
97 #define BSTP_ROLE_ROOT 1
98 #define BSTP_ROLE_DESIGNATED 2
99 #define BSTP_ROLE_ALTERNATE 3
100 #define BSTP_ROLE_BACKUP 4
101
102
103
104
105 struct ifbifconf {
106 char ifbic_name[IFNAMSIZ];
107 u_int32_t ifbic_len;
108 union {
109 caddr_t ifbicu_buf;
110 struct ifbreq *ifbicu_req;
111 } ifbic_ifbicu;
112 #define ifbic_buf ifbic_ifbicu.ifbicu_buf
113 #define ifbic_req ifbic_ifbicu.ifbicu_req
114 };
115
116
117
118
119 struct ifbareq {
120 char ifba_name[IFNAMSIZ];
121 char ifba_ifsname[IFNAMSIZ];
122 u_int8_t ifba_age;
123 u_int8_t ifba_flags;
124 struct ether_addr ifba_dst;
125 };
126
127 #define IFBAF_TYPEMASK 0x03
128 #define IFBAF_DYNAMIC 0x00
129 #define IFBAF_STATIC 0x01
130
131 struct ifbaconf {
132 char ifbac_name[IFNAMSIZ];
133 u_int32_t ifbac_len;
134 union {
135 caddr_t ifbacu_buf;
136 struct ifbareq *ifbacu_req;
137 } ifbac_ifbacu;
138 #define ifbac_buf ifbac_ifbacu.ifbacu_buf
139 #define ifbac_req ifbac_ifbacu.ifbacu_req
140 };
141
142 struct ifbrparam {
143 char ifbrp_name[IFNAMSIZ];
144 union {
145 u_int32_t ifbrpu_csize;
146 int ifbrpu_ctime;
147 u_int16_t ifbrpu_prio;
148 u_int8_t ifbrpu_hellotime;
149 u_int8_t ifbrpu_fwddelay;
150 u_int8_t ifbrpu_maxage;
151 u_int8_t ifbrpu_proto;
152 u_int8_t ifbrpu_txhc;
153 } ifbrp_ifbrpu;
154 };
155 #define ifbrp_csize ifbrp_ifbrpu.ifbrpu_csize
156 #define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_ctime
157 #define ifbrp_prio ifbrp_ifbrpu.ifbrpu_prio
158 #define ifbrp_proto ifbrp_ifbrpu.ifbrpu_proto
159 #define ifbrp_txhc ifbrp_ifbrpu.ifbrpu_txhc
160 #define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_hellotime
161 #define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_fwddelay
162 #define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_maxage
163
164
165 #define BSTP_PROTO_ID 0x00
166 #define BSTP_PROTO_STP 0x00
167 #define BSTP_PROTO_RSTP 0x02
168 #define BSTP_PROTO_MAX BSTP_PROTO_RSTP
169
170
171
172
173 struct ifbropreq {
174 char ifbop_name[IFNAMSIZ];
175 u_int8_t ifbop_holdcount;
176 u_int8_t ifbop_maxage;
177 u_int8_t ifbop_hellotime;
178 u_int8_t ifbop_fwddelay;
179 u_int8_t ifbop_protocol;
180 u_int16_t ifbop_priority;
181 u_int64_t ifbop_root_bridge;
182 u_int16_t ifbop_root_port;
183 u_int32_t ifbop_root_path_cost;
184 u_int64_t ifbop_desg_bridge;
185 struct timeval ifbop_last_tc_time;
186 };
187
188
189
190
191 struct ifbrlreq {
192 char ifbr_name[IFNAMSIZ];
193 char ifbr_ifsname[IFNAMSIZ];
194 u_int8_t ifbr_action;
195 u_int8_t ifbr_flags;
196 struct ether_addr ifbr_src;
197 struct ether_addr ifbr_dst;
198 char ifbr_tagname[PF_TAG_NAME_SIZE];
199 };
200 #define BRL_ACTION_BLOCK 0x01
201 #define BRL_ACTION_PASS 0x02
202 #define BRL_FLAG_IN 0x08
203 #define BRL_FLAG_OUT 0x04
204 #define BRL_FLAG_SRCVALID 0x02
205 #define BRL_FLAG_DSTVALID 0x01
206
207 struct ifbrlconf {
208 char ifbrl_name[IFNAMSIZ];
209 char ifbrl_ifsname[IFNAMSIZ];
210 u_int32_t ifbrl_len;
211 union {
212 caddr_t ifbrlu_buf;
213 struct ifbrlreq *ifbrlu_req;
214 } ifbrl_ifbrlu;
215 #define ifbrl_buf ifbrl_ifbrlu.ifbrlu_buf
216 #define ifbrl_req ifbrl_ifbrlu.ifbrlu_req
217 };
218
219 #ifdef _KERNEL
220
221 #define BSTP_PORT_CANMIGRATE 0x0001
222 #define BSTP_PORT_NEWINFO 0x0002
223 #define BSTP_PORT_DISPUTED 0x0004
224 #define BSTP_PORT_ADMCOST 0x0008
225 #define BSTP_PORT_AUTOEDGE 0x0010
226 #define BSTP_PORT_AUTOPTP 0x0020
227
228
229 #define BSTP_PDU_SUPERIOR 1
230 #define BSTP_PDU_REPEATED 2
231 #define BSTP_PDU_INFERIOR 3
232 #define BSTP_PDU_INFERIORALT 4
233 #define BSTP_PDU_OTHER 5
234
235
236 #define BSTP_PDU_PRMASK 0x0c
237 #define BSTP_PDU_PRSHIFT 2
238 #define BSTP_PDU_F_UNKN 0x00
239 #define BSTP_PDU_F_ALT 0x01
240 #define BSTP_PDU_F_ROOT 0x02
241 #define BSTP_PDU_F_DESG 0x03
242
243 #define BSTP_PDU_STPMASK 0x81
244 #define BSTP_PDU_RSTPMASK 0x7f
245 #define BSTP_PDU_F_TC 0x01
246 #define BSTP_PDU_F_P 0x02
247 #define BSTP_PDU_F_L 0x10
248 #define BSTP_PDU_F_F 0x20
249 #define BSTP_PDU_F_A 0x40
250 #define BSTP_PDU_F_TCA 0x80
251
252
253
254
255 SIMPLEQ_HEAD(brl_head, brl_node);
256
257 struct brl_node {
258 SIMPLEQ_ENTRY(brl_node) brl_next;
259 struct ether_addr brl_src;
260 struct ether_addr brl_dst;
261 u_int16_t brl_tag;
262 u_int8_t brl_action;
263 u_int8_t brl_flags;
264 };
265
266 struct bstp_timer {
267 u_int16_t active;
268 u_int16_t value;
269 u_int32_t latched;
270 };
271
272 struct bstp_pri_vector {
273 u_int64_t pv_root_id;
274 u_int32_t pv_cost;
275 u_int64_t pv_dbridge_id;
276 u_int16_t pv_dport_id;
277 u_int16_t pv_port_id;
278 };
279
280 struct bstp_config_unit {
281 struct bstp_pri_vector cu_pv;
282 u_int16_t cu_message_age;
283 u_int16_t cu_max_age;
284 u_int16_t cu_forward_delay;
285 u_int16_t cu_hello_time;
286 u_int8_t cu_message_type;
287 u_int8_t cu_topology_change_ack;
288 u_int8_t cu_topology_change;
289 u_int8_t cu_proposal;
290 u_int8_t cu_agree;
291 u_int8_t cu_learning;
292 u_int8_t cu_forwarding;
293 u_int8_t cu_role;
294 };
295
296 struct bstp_tcn_unit {
297 u_int8_t tu_message_type;
298 };
299
300 struct bstp_port {
301 LIST_ENTRY(bstp_port) bp_next;
302 struct ifnet *bp_ifp;
303 struct bstp_state *bp_bs;
304 void *bp_lhcookie;
305 u_int8_t bp_active;
306 u_int8_t bp_protover;
307 u_int32_t bp_flags;
308 u_int32_t bp_path_cost;
309 u_int16_t bp_port_msg_age;
310 u_int16_t bp_port_max_age;
311 u_int16_t bp_port_fdelay;
312 u_int16_t bp_port_htime;
313 u_int16_t bp_desg_msg_age;
314 u_int16_t bp_desg_max_age;
315 u_int16_t bp_desg_fdelay;
316 u_int16_t bp_desg_htime;
317 struct bstp_timer bp_edge_delay_timer;
318 struct bstp_timer bp_forward_delay_timer;
319 struct bstp_timer bp_hello_timer;
320 struct bstp_timer bp_message_age_timer;
321 struct bstp_timer bp_migrate_delay_timer;
322 struct bstp_timer bp_recent_backup_timer;
323 struct bstp_timer bp_recent_root_timer;
324 struct bstp_timer bp_tc_timer;
325 struct bstp_config_unit bp_msg_cu;
326 struct bstp_pri_vector bp_desg_pv;
327 struct bstp_pri_vector bp_port_pv;
328 u_int16_t bp_port_id;
329 u_int8_t bp_state;
330 u_int8_t bp_tcstate;
331 u_int8_t bp_role;
332 u_int8_t bp_infois;
333 u_int8_t bp_tc_ack;
334 u_int8_t bp_tc_prop;
335 u_int8_t bp_fdbflush;
336 u_int8_t bp_priority;
337 u_int8_t bp_ptp_link;
338 u_int8_t bp_agree;
339 u_int8_t bp_agreed;
340 u_int8_t bp_sync;
341 u_int8_t bp_synced;
342 u_int8_t bp_proposing;
343 u_int8_t bp_proposed;
344 u_int8_t bp_operedge;
345 u_int8_t bp_reroot;
346 u_int8_t bp_rcvdtc;
347 u_int8_t bp_rcvdtca;
348 u_int8_t bp_rcvdtcn;
349 u_int32_t bp_forward_transitions;
350 u_int8_t bp_txcount;
351 };
352
353
354
355
356 struct bstp_state {
357 LIST_ENTRY(bstp_state) bs_list;
358 struct ifnet *bs_ifp;
359 struct bstp_pri_vector bs_bridge_pv;
360 struct bstp_pri_vector bs_root_pv;
361 struct bstp_port *bs_root_port;
362 u_int8_t bs_protover;
363 u_int16_t bs_migration_delay;
364 u_int16_t bs_edge_delay;
365 u_int16_t bs_bridge_max_age;
366 u_int16_t bs_bridge_fdelay;
367 u_int16_t bs_bridge_htime;
368 u_int16_t bs_root_msg_age;
369 u_int16_t bs_root_max_age;
370 u_int16_t bs_root_fdelay;
371 u_int16_t bs_root_htime;
372 u_int16_t bs_hold_time;
373 u_int16_t bs_bridge_priority;
374 u_int8_t bs_txholdcount;
375 u_int8_t bs_allsynced;
376 struct timeout bs_bstptimeout;
377 struct bstp_timer bs_link_timer;
378 struct timeval bs_last_tc_time;
379 LIST_HEAD(, bstp_port) bs_bplist;
380 };
381 #define bs_ifflags bs_ifp->if_flags
382
383
384
385
386 struct bridge_iflist {
387 LIST_ENTRY(bridge_iflist) next;
388 struct bstp_port *bif_stp;
389 struct brl_head bif_brlin;
390 struct brl_head bif_brlout;
391 struct ifnet *ifp;
392 u_int32_t bif_flags;
393 };
394 #define bif_state bif_stp->bp_state
395
396
397
398
399 struct bridge_rtnode {
400 LIST_ENTRY(bridge_rtnode) brt_next;
401 struct ifnet *brt_if;
402 u_int8_t brt_flags;
403 u_int8_t brt_age;
404 struct ether_addr brt_addr;
405 };
406
407 #ifndef BRIDGE_RTABLE_SIZE
408 #define BRIDGE_RTABLE_SIZE 1024
409 #endif
410 #define BRIDGE_RTABLE_MASK (BRIDGE_RTABLE_SIZE - 1)
411
412
413
414
415 struct bridge_softc {
416 struct ifnet sc_if;
417 LIST_ENTRY(bridge_softc) sc_list;
418 struct bridge_iflist *sc_root_port;
419 u_int32_t sc_brtmax;
420 u_int32_t sc_brtcnt;
421 int sc_brttimeout;
422 u_int32_t sc_hashkey;
423 struct timeout sc_brtimeout;
424 struct bstp_state *sc_stp;
425 LIST_HEAD(, bridge_iflist) sc_iflist;
426 LIST_HEAD(, bridge_rtnode) sc_rts[BRIDGE_RTABLE_SIZE];
427 LIST_HEAD(, bridge_iflist) sc_spanlist;
428 };
429
430 extern const u_int8_t bstp_etheraddr[];
431
432 void bridge_ifdetach(struct ifnet *);
433 struct mbuf *bridge_input(struct ifnet *, struct ether_header *,
434 struct mbuf *);
435 int bridge_output(struct ifnet *, struct mbuf *, struct sockaddr *,
436 struct rtentry *);
437 void bridge_update(struct ifnet *, struct ether_addr *, int);
438 void bridge_rtdelete(struct bridge_softc *, struct ifnet *, int);
439 void bridge_rtagenode(struct ifnet *, int);
440
441 void bstp_attach(int);
442 struct bstp_state *bstp_create(struct ifnet *);
443 void bstp_destroy(struct bstp_state *);
444 void bstp_initialization(struct bstp_state *);
445 void bstp_stop(struct bstp_state *);
446 int bstp_ioctl(struct ifnet *, u_long, caddr_t);
447 struct bstp_port *bstp_add(struct bstp_state *, struct ifnet *);
448 void bstp_delete(struct bstp_port *);
449 struct mbuf *bstp_input(struct bstp_state *, struct bstp_port *,
450 struct ether_header *, struct mbuf *);
451 void bstp_ifstate(void *);
452 u_int8_t bstp_getstate(struct bstp_state *, struct bstp_port *);
453 void bstp_ifsflags(struct bstp_port *, u_int);
454 #endif
455 #endif