2 * Copyright 2001 Wasabi Systems, Inc.
5 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project by
18 * Wasabi Systems, Inc.
19 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
20 * or promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
37 * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by Jason L. Wright
51 * 4. The name of the author may not be used to endorse or promote products
52 * derived from this software without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
56 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
57 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
58 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
59 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
60 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
62 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
63 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 * POSSIBILITY OF SUCH DAMAGE.
66 * $OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp $
67 * $NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $
68 * $FreeBSD: src/sys/net/if_bridgevar.h,v 1.4 2005/07/06 01:24:45 thompsa Exp $
69 * $DragonFly: src/sys/net/bridge/if_bridgevar.h,v 1.10 2008/11/26 12:49:43 sephe Exp $
72 #ifndef _NET_IF_BRIDGEVAR_H
73 #define _NET_IF_BRIDGEVAR_H
76 * Data structure and control definitions for bridge interfaces.
79 #include <sys/callout.h>
80 #include <sys/queue.h>
83 * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the
84 * bridge interface itself is keyed off the ifdrv structure.
86 #define BRDGADD 0 /* add bridge member (ifbreq) */
87 #define BRDGDEL 1 /* delete bridge member (ifbreq) */
88 #define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */
89 #define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */
90 #define BRDGSCACHE 4 /* set cache size (ifbrparam) */
91 #define BRDGGCACHE 5 /* get cache size (ifbrparam) */
92 #define BRDGGIFS 6 /* get member list (ifbifconf) */
93 #define BRDGRTS 7 /* get address list (ifbaconf) */
94 #define BRDGSADDR 8 /* set static address (ifbareq) */
95 #define BRDGSTO 9 /* set cache timeout (ifbrparam) */
96 #define BRDGGTO 10 /* get cache timeout (ifbrparam) */
97 #define BRDGDADDR 11 /* delete address (ifbareq) */
98 #define BRDGFLUSH 12 /* flush address cache (ifbreq) */
100 #define BRDGGPRI 13 /* get priority (ifbrparam) */
101 #define BRDGSPRI 14 /* set priority (ifbrparam) */
102 #define BRDGGHT 15 /* get hello time (ifbrparam) */
103 #define BRDGSHT 16 /* set hello time (ifbrparam) */
104 #define BRDGGFD 17 /* get forward delay (ifbrparam) */
105 #define BRDGSFD 18 /* set forward delay (ifbrparam) */
106 #define BRDGGMA 19 /* get max age (ifbrparam) */
107 #define BRDGSMA 20 /* set max age (ifbrparam) */
108 #define BRDGSIFPRIO 21 /* set if priority (ifbreq) */
109 #define BRDGSIFCOST 22 /* set if path cost (ifbreq) */
110 #define BRDGADDS 23 /* add bridge span member (ifbreq) */
111 #define BRDGDELS 24 /* delete bridge span member (ifbreq) */
114 * Generic bridge control request.
117 char ifbr_ifsname[IFNAMSIZ]; /* member if name */
118 uint32_t ifbr_ifsflags; /* member if flags */
119 uint8_t ifbr_state; /* member if STP state */
120 uint8_t ifbr_priority; /* member if STP priority */
121 uint8_t ifbr_path_cost; /* member if STP cost */
122 uint8_t ifbr_portno; /* member if port number */
123 uint64_t ifbr_designated_root; /* current root id */
124 uint64_t ifbr_designated_bridge; /* current bridge id */
125 uint32_t ifbr_designated_cost; /* current cost calc */
126 uint16_t ifbr_designated_port; /* current port calc */
130 /* BRDGGIFFLAGS, BRDGSIFFLAGS */
131 #define IFBIF_LEARNING 0x01 /* if can learn */
132 #define IFBIF_DISCOVER 0x02 /* if sends packets w/ unknown dest. */
133 #define IFBIF_STP 0x04 /* if participates in spanning tree */
134 #define IFBIF_SPAN 0x08 /* if is a span port */
136 #define IFBIFBITS "\020\1LEARNING\2DISCOVER\3STP\4SPAN"
139 #define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */
140 #define IFBF_FLUSHALL 0x01 /* flush all addresses */
141 #define IFBF_FLUSHSYNC 0x02 /* synchronized flush */
143 /* STP port states */
144 #define BSTP_IFSTATE_DISABLED 0
145 #define BSTP_IFSTATE_LISTENING 1
146 #define BSTP_IFSTATE_LEARNING 2
147 #define BSTP_IFSTATE_FORWARDING 3
148 #define BSTP_IFSTATE_BLOCKING 4
149 #define BSTP_IFSTATE_L1BLOCKING 5 /* link1 blocking mode no-activity */
152 * Interface list structure.
155 uint32_t ifbic_len; /* buffer size */
158 struct ifbreq *ifbicu_req;
160 #define ifbic_buf ifbic_ifbicu.ifbicu_buf
161 #define ifbic_req ifbic_ifbicu.ifbicu_req
165 * Bridge address request.
168 char ifba_ifsname[IFNAMSIZ]; /* member if name */
169 unsigned long ifba_expire; /* address expire time */
170 uint8_t ifba_flags; /* address flags */
171 uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */
174 #define IFBAF_TYPEMASK 0x03 /* address type mask */
175 #define IFBAF_DYNAMIC 0x00 /* dynamically learned address */
176 #define IFBAF_STATIC 0x01 /* static address */
178 #define IFBAFBITS "\020\1STATIC"
181 * Address list structure.
184 uint32_t ifbac_len; /* buffer size */
187 struct ifbareq *ifbacu_req;
189 #define ifbac_buf ifbac_ifbacu.ifbacu_buf
190 #define ifbac_req ifbac_ifbacu.ifbacu_req
194 * Bridge parameter structure.
198 uint32_t ifbrpu_int32;
199 uint16_t ifbrpu_int16;
203 #define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */
204 #define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */
205 #define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */
206 #define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */
207 #define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */
208 #define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */
212 * Timekeeping structure used in spanning tree code.
214 struct bridge_timer {
219 struct bstp_config_unit {
221 uint64_t cu_bridge_id;
222 uint32_t cu_root_path_cost;
223 uint16_t cu_message_age;
225 uint16_t cu_hello_time;
226 uint16_t cu_forward_delay;
228 uint8_t cu_message_type;
229 uint8_t cu_topology_change_acknowledgment;
230 uint8_t cu_topology_change;
233 struct bstp_tcn_unit {
234 uint8_t tu_message_type;
238 * Bridge interface entry.
240 struct bridge_ifinfo {
241 uint64_t bifi_designated_root;
242 uint64_t bifi_designated_bridge;
243 uint32_t bifi_path_cost;
244 uint32_t bifi_designated_cost;
245 struct bridge_timer bifi_hold_timer;
246 struct bridge_timer bifi_message_age_timer;
247 struct bridge_timer bifi_forward_delay_timer;
248 struct bridge_timer bifi_link1_timer;
249 struct bstp_config_unit bifi_config_bpdu;
250 uint16_t bifi_port_id;
251 uint16_t bifi_designated_port;
253 uint8_t bifi_topology_change_acknowledge;
254 uint8_t bifi_config_pending;
255 uint8_t bifi_change_detection_enabled;
256 uint8_t bifi_priority;
257 struct ifnet *bifi_ifp; /* member if */
258 int bifi_mutecap; /* member muted caps */
261 #define bif_designated_root bif_info->bifi_designated_root
262 #define bif_designated_bridge bif_info->bifi_designated_bridge
263 #define bif_path_cost bif_info->bifi_path_cost
264 #define bif_designated_cost bif_info->bifi_designated_cost
265 #define bif_hold_timer bif_info->bifi_hold_timer
266 #define bif_message_age_timer bif_info->bifi_message_age_timer
267 #define bif_forward_delay_timer bif_info->bifi_forward_delay_timer
268 #define bif_link1_timer bif_info->bifi_link1_timer
269 #define bif_config_bpdu bif_info->bifi_config_bpdu
270 #define bif_port_id bif_info->bifi_port_id
271 #define bif_designated_port bif_info->bifi_designated_port
272 #define bif_state bif_info->bifi_state
273 #define bif_topology_change_acknowledge \
274 bif_info->bifi_topology_change_acknowledge
275 #define bif_config_pending bif_info->bifi_config_pending
276 #define bif_change_detection_enabled bif_info->bifi_change_detection_enabled
277 #define bif_priority bif_info->bifi_priority
280 * Bridge interface list entry.
282 struct bridge_iflist {
283 LIST_ENTRY(bridge_iflist) bif_next;
284 struct ifnet *bif_ifp; /* member if */
285 uint32_t bif_flags; /* member if flags */
287 struct bridge_ifinfo *bif_info;
289 LIST_HEAD(bridge_iflist_head, bridge_iflist);
294 struct bridge_rtinfo {
295 struct ifnet *bri_ifp; /* destination if */
296 unsigned long bri_expire; /* expiration time */
297 uint8_t bri_flags; /* address flags */
305 struct bridge_rtnode {
306 LIST_ENTRY(bridge_rtnode) brt_hash; /* hash table linkage */
307 LIST_ENTRY(bridge_rtnode) brt_list; /* list linkage */
308 uint8_t brt_addr[ETHER_ADDR_LEN];
310 struct bridge_rtinfo *brt_info;
312 LIST_HEAD(bridge_rtnode_head, bridge_rtnode);
315 * Software state for each bridge.
317 struct bridge_softc {
318 struct arpcom sc_arp;
319 struct ifnet *sc_ifp; /* make this an interface */
320 LIST_ENTRY(bridge_softc) sc_list;
321 uint64_t sc_designated_root;
322 uint64_t sc_bridge_id;
323 struct bridge_ifinfo *sc_root_port;
324 uint32_t sc_root_path_cost;
326 uint16_t sc_hello_time;
327 uint16_t sc_forward_delay;
328 uint16_t sc_bridge_max_age;
329 uint16_t sc_bridge_hello_time;
330 uint16_t sc_bridge_forward_delay;
331 uint16_t sc_topology_change_time;
332 uint16_t sc_hold_time;
333 uint16_t sc_bridge_priority;
334 uint8_t sc_topology_change_detected;
335 uint8_t sc_topology_change;
336 struct bridge_timer sc_hello_timer;
337 struct bridge_timer sc_topology_change_timer;
338 struct bridge_timer sc_tcn_timer;
339 uint32_t sc_brtmax; /* max # of addresses */
340 uint32_t sc_brtcnt; /* cur. # of addresses */
341 uint32_t sc_brttimeout; /* rt timeout in seconds */
342 struct callout sc_brcallout; /* bridge callout */
343 struct netmsg_base sc_brtimemsg; /* bridge callout msg */
344 struct callout sc_bstpcallout; /* STP callout */
345 struct netmsg_base sc_bstptimemsg; /* STP callout msg */
346 struct bridge_iflist_head *sc_iflists; /* percpu member if lists */
347 struct bridge_rtnode_head **sc_rthashs; /* percpu forwarding tables */
348 struct bridge_rtnode_head *sc_rtlists; /* percpu lists of the above */
349 uint32_t sc_rthash_key; /* key for hash */
350 struct bridge_iflist_head sc_spanlist; /* span ports list */
351 int sc_span; /* has span ports */
352 struct bridge_timer sc_link_timer;
354 #define sc_if sc_arp.ac_if
356 #define BRIDGE_CFGCPU 0
357 #define BRIDGE_CFGPORT cpu_portfn(BRIDGE_CFGCPU)
359 extern const uint8_t bstp_etheraddr[];
361 void bridge_rtdelete(struct bridge_softc *, struct ifnet *ifp, int);
363 extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state);
365 void bstp_initialization(struct bridge_softc *);
366 void bstp_linkstate(struct ifnet *, int);
367 void bstp_stop(struct bridge_softc *);
368 void bstp_input(struct bridge_softc *, struct bridge_iflist *,
370 void bstp_tick_handler(netmsg_t);
372 void bridge_enqueue(struct ifnet *, struct mbuf *);
376 #endif /* !_NET_IF_BRIDGEVAR_H */