bridge_enqueue() does not use bridge(4)'s softc, so don't pretend that the
[dragonfly.git] / sys / net / bridge / if_bridgevar.h
blob781ce1fdb17f984cabade0930d9798e89d979958
1 /*
2 * Copyright 2001 Wasabi Systems, Inc.
3 * All rights reserved.
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
9 * are met:
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
21 * written permission.
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
42 * are met:
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.3 2007/06/06 13:10:39 sephe Exp $
73 * Data structure and control definitions for bridge interfaces.
76 #include <sys/callout.h>
77 #include <sys/queue.h>
80 * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the
81 * bridge interface itself is keyed off the ifdrv structure.
83 #define BRDGADD 0 /* add bridge member (ifbreq) */
84 #define BRDGDEL 1 /* delete bridge member (ifbreq) */
85 #define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */
86 #define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */
87 #define BRDGSCACHE 4 /* set cache size (ifbrparam) */
88 #define BRDGGCACHE 5 /* get cache size (ifbrparam) */
89 #define BRDGGIFS 6 /* get member list (ifbifconf) */
90 #define BRDGRTS 7 /* get address list (ifbaconf) */
91 #define BRDGSADDR 8 /* set static address (ifbareq) */
92 #define BRDGSTO 9 /* set cache timeout (ifbrparam) */
93 #define BRDGGTO 10 /* get cache timeout (ifbrparam) */
94 #define BRDGDADDR 11 /* delete address (ifbareq) */
95 #define BRDGFLUSH 12 /* flush address cache (ifbreq) */
97 #define BRDGGPRI 13 /* get priority (ifbrparam) */
98 #define BRDGSPRI 14 /* set priority (ifbrparam) */
99 #define BRDGGHT 15 /* get hello time (ifbrparam) */
100 #define BRDGSHT 16 /* set hello time (ifbrparam) */
101 #define BRDGGFD 17 /* get forward delay (ifbrparam) */
102 #define BRDGSFD 18 /* set forward delay (ifbrparam) */
103 #define BRDGGMA 19 /* get max age (ifbrparam) */
104 #define BRDGSMA 20 /* set max age (ifbrparam) */
105 #define BRDGSIFPRIO 21 /* set if priority (ifbreq) */
106 #define BRDGSIFCOST 22 /* set if path cost (ifbreq) */
107 #define BRDGADDS 23 /* add bridge span member (ifbreq) */
108 #define BRDGDELS 24 /* delete bridge span member (ifbreq) */
111 * Generic bridge control request.
113 struct ifbreq {
114 char ifbr_ifsname[IFNAMSIZ]; /* member if name */
115 uint32_t ifbr_ifsflags; /* member if flags */
116 uint8_t ifbr_state; /* member if STP state */
117 uint8_t ifbr_priority; /* member if STP priority */
118 uint8_t ifbr_path_cost; /* member if STP cost */
119 uint8_t ifbr_portno; /* member if port number */
122 /* BRDGGIFFLAGS, BRDGSIFFLAGS */
123 #define IFBIF_LEARNING 0x01 /* if can learn */
124 #define IFBIF_DISCOVER 0x02 /* if sends packets w/ unknown dest. */
125 #define IFBIF_STP 0x04 /* if participates in spanning tree */
126 #define IFBIF_SPAN 0x08 /* if is a span port */
128 #define IFBIFBITS "\020\1LEARNING\2DISCOVER\3STP\4SPAN"
130 /* BRDGFLUSH */
131 #define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */
132 #define IFBF_FLUSHALL 0x01 /* flush all addresses */
134 /* STP port states */
135 #define BSTP_IFSTATE_DISABLED 0
136 #define BSTP_IFSTATE_LISTENING 1
137 #define BSTP_IFSTATE_LEARNING 2
138 #define BSTP_IFSTATE_FORWARDING 3
139 #define BSTP_IFSTATE_BLOCKING 4
142 * Interface list structure.
144 struct ifbifconf {
145 uint32_t ifbic_len; /* buffer size */
146 union {
147 caddr_t ifbicu_buf;
148 struct ifbreq *ifbicu_req;
149 } ifbic_ifbicu;
150 #define ifbic_buf ifbic_ifbicu.ifbicu_buf
151 #define ifbic_req ifbic_ifbicu.ifbicu_req
155 * Bridge address request.
157 struct ifbareq {
158 char ifba_ifsname[IFNAMSIZ]; /* member if name */
159 unsigned long ifba_expire; /* address expire time */
160 uint8_t ifba_flags; /* address flags */
161 uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */
164 #define IFBAF_TYPEMASK 0x03 /* address type mask */
165 #define IFBAF_DYNAMIC 0x00 /* dynamically learned address */
166 #define IFBAF_STATIC 0x01 /* static address */
168 #define IFBAFBITS "\020\1STATIC"
171 * Address list structure.
173 struct ifbaconf {
174 uint32_t ifbac_len; /* buffer size */
175 union {
176 caddr_t ifbacu_buf;
177 struct ifbareq *ifbacu_req;
178 } ifbac_ifbacu;
179 #define ifbac_buf ifbac_ifbacu.ifbacu_buf
180 #define ifbac_req ifbac_ifbacu.ifbacu_req
184 * Bridge parameter structure.
186 struct ifbrparam {
187 union {
188 uint32_t ifbrpu_int32;
189 uint16_t ifbrpu_int16;
190 uint8_t ifbrpu_int8;
191 } ifbrp_ifbrpu;
193 #define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */
194 #define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */
195 #define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */
196 #define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */
197 #define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */
198 #define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */
200 #ifdef _KERNEL
202 * Timekeeping structure used in spanning tree code.
204 struct bridge_timer {
205 uint16_t active;
206 uint16_t value;
209 struct bstp_config_unit {
210 uint64_t cu_rootid;
211 uint64_t cu_bridge_id;
212 uint32_t cu_root_path_cost;
213 uint16_t cu_message_age;
214 uint16_t cu_max_age;
215 uint16_t cu_hello_time;
216 uint16_t cu_forward_delay;
217 uint16_t cu_port_id;
218 uint8_t cu_message_type;
219 uint8_t cu_topology_change_acknowledgment;
220 uint8_t cu_topology_change;
223 struct bstp_tcn_unit {
224 uint8_t tu_message_type;
228 * Bridge interface list entry.
230 struct bridge_iflist {
231 LIST_ENTRY(bridge_iflist) bif_next;
232 uint64_t bif_designated_root;
233 uint64_t bif_designated_bridge;
234 uint32_t bif_path_cost;
235 uint32_t bif_designated_cost;
236 struct bridge_timer bif_hold_timer;
237 struct bridge_timer bif_message_age_timer;
238 struct bridge_timer bif_forward_delay_timer;
239 struct bstp_config_unit bif_config_bpdu;
240 uint16_t bif_port_id;
241 uint16_t bif_designated_port;
242 uint8_t bif_state;
243 uint8_t bif_topology_change_acknowledge;
244 uint8_t bif_config_pending;
245 uint8_t bif_change_detection_enabled;
246 uint8_t bif_priority;
247 struct ifnet *bif_ifp; /* member if */
248 uint32_t bif_flags; /* member if flags */
249 int bif_mutecap; /* member muted caps */
253 * Bridge route node.
255 struct bridge_rtnode {
256 LIST_ENTRY(bridge_rtnode) brt_hash; /* hash table linkage */
257 LIST_ENTRY(bridge_rtnode) brt_list; /* list linkage */
258 struct ifnet *brt_ifp; /* destination if */
259 unsigned long brt_expire; /* expiration time */
260 uint8_t brt_flags; /* address flags */
261 uint8_t brt_addr[ETHER_ADDR_LEN];
265 * Software state for each bridge.
267 struct bridge_softc {
268 struct arpcom sc_arp;
269 struct ifnet *sc_ifp; /* make this an interface */
270 LIST_ENTRY(bridge_softc) sc_list;
271 uint64_t sc_designated_root;
272 uint64_t sc_bridge_id;
273 struct bridge_iflist *sc_root_port;
274 uint32_t sc_root_path_cost;
275 uint16_t sc_max_age;
276 uint16_t sc_hello_time;
277 uint16_t sc_forward_delay;
278 uint16_t sc_bridge_max_age;
279 uint16_t sc_bridge_hello_time;
280 uint16_t sc_bridge_forward_delay;
281 uint16_t sc_topology_change_time;
282 uint16_t sc_hold_time;
283 uint16_t sc_bridge_priority;
284 uint8_t sc_topology_change_detected;
285 uint8_t sc_topology_change;
286 struct bridge_timer sc_hello_timer;
287 struct bridge_timer sc_topology_change_timer;
288 struct bridge_timer sc_tcn_timer;
289 uint32_t sc_brtmax; /* max # of addresses */
290 uint32_t sc_brtcnt; /* cur. # of addresses */
291 uint32_t sc_brttimeout; /* rt timeout in seconds */
292 struct callout sc_brcallout; /* bridge callout */
293 struct callout sc_bstpcallout; /* STP callout */
294 LIST_HEAD(, bridge_iflist) sc_iflist; /* member interface list */
295 LIST_HEAD(, bridge_rtnode) *sc_rthash; /* our forwarding table */
296 LIST_HEAD(, bridge_rtnode) sc_rtlist; /* list version of above */
297 uint32_t sc_rthash_key; /* key for hash */
298 LIST_HEAD(, bridge_iflist) sc_spanlist; /* span ports list */
299 struct bridge_timer sc_link_timer;
301 #define sc_if sc_arp.ac_if
303 extern const uint8_t bstp_etheraddr[];
305 void bridge_rtdelete(struct bridge_softc *, struct ifnet *ifp, int);
307 extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state);
309 void bstp_initialization(struct bridge_softc *);
310 void bstp_linkstate(struct ifnet *, int);
311 void bstp_stop(struct bridge_softc *);
312 struct mbuf *bstp_input(struct ifnet *, struct mbuf *);
314 void bridge_enqueue(struct ifnet *, struct mbuf *);
316 #endif /* _KERNEL */