if_bridgevar.h revision 1.2 1 /* $NetBSD: if_bridgevar.h,v 1.2 2003/02/15 00:46:30 perseant 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 (at) 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
71 /*
72 * Data structure and control definitions for bridge interfaces.
73 */
74
75 #include <sys/callout.h>
76 #include <sys/queue.h>
77
78 /*
79 * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the
80 * bridge interface itself is keyed off the ifdrv structure.
81 */
82 #define BRDGADD 0 /* add bridge member (ifbreq) */
83 #define BRDGDEL 1 /* delete bridge member (ifbreq) */
84 #define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */
85 #define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */
86 #define BRDGSCACHE 4 /* set cache size (ifbrparam) */
87 #define BRDGGCACHE 5 /* get cache size (ifbrparam) */
88 #define BRDGGIFS 6 /* get member list (ifbifconf) */
89 #define BRDGRTS 7 /* get address list (ifbaconf) */
90 #define BRDGSADDR 8 /* set static address (ifbareq) */
91 #define BRDGSTO 9 /* set cache timeout (ifbrparam) */
92 #define BRDGGTO 10 /* get cache timeout (ifbrparam) */
93 #define BRDGDADDR 11 /* delete address (ifbareq) */
94 #define BRDGFLUSH 12 /* flush address cache (ifbreq) */
95
96 #define BRDGGPRI 13 /* get priority (ifbrparam) */
97 #define BRDGSPRI 14 /* set priority (ifbrparam) */
98 #define BRDGGHT 15 /* get hello time (ifbrparam) */
99 #define BRDGSHT 16 /* set hello time (ifbrparam) */
100 #define BRDGGFD 17 /* get forward delay (ifbrparam) */
101 #define BRDGSFD 18 /* set forward delay (ifbrparam) */
102 #define BRDGGMA 19 /* get max age (ifbrparam) */
103 #define BRDGSMA 20 /* set max age (ifbrparam) */
104 #define BRDGSIFPRIO 21 /* set if priority (ifbreq) */
105 #define BRDGGFILT 22 /* get filter flags (ifbrparam) */
106 #define BRDGSFILT 23 /* set filter flags (ifbrparam) */
107
108 /*
109 * Generic bridge control request.
110 */
111 struct ifbreq {
112 char ifbr_ifsname[IFNAMSIZ]; /* member if name */
113 uint32_t ifbr_ifsflags; /* member if flags */
114 uint8_t ifbr_state; /* member if STP state */
115 uint8_t ifbr_priority; /* member if STP priority */
116 uint8_t ifbr_portno; /* member if port number */
117 };
118
119 /* BRDGGIFFLAGS, BRDGSIFFLAGS */
120 #define IFBIF_LEARNING 0x01 /* if can learn */
121 #define IFBIF_DISCOVER 0x02 /* if sends packets w/ unknown dest. */
122 #define IFBIF_STP 0x04 /* if participates in spanning tree */
123
124 #define IFBIFBITS "\020\1LEARNING\2DISCOVER\3STP"
125
126 /* BRDGFLUSH */
127 #define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */
128 #define IFBF_FLUSHALL 0x01 /* flush all addresses */
129
130 /* BRDGSFILT */
131 #define IFBF_FILT_USEIPF 0x00000001 /* enable ipf on bridge */
132 #define IFBF_FILT_MASK 0x00000001 /* mask of valid values */
133
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
140
141 /*
142 * Interface list structure.
143 */
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
152 };
153
154 /*
155 * Bridge address request.
156 */
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 */
162 };
163
164 #define IFBAF_TYPEMASK 0x03 /* address type mask */
165 #define IFBAF_DYNAMIC 0x00 /* dynamically learned address */
166 #define IFBAF_STATIC 0x01 /* static address */
167
168 #define IFBAFBITS "\020\1STATIC"
169
170 /*
171 * Address list structure.
172 */
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
181 };
182
183 /*
184 * Bridge parameter structure.
185 */
186 struct ifbrparam {
187 union {
188 uint32_t ifbrpu_int32;
189 uint16_t ifbrpu_int16;
190 uint8_t ifbrpu_int8;
191 } ifbrp_ifbrpu;
192 };
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) */
199 #define ifbrp_filter ifbrp_ifbrpu.ifbrpu_int32 /* filtering flags */
200
201 #ifdef _KERNEL
202 /*
203 * Timekeeping structure used in spanning tree code.
204 */
205 struct bridge_timer {
206 uint16_t active;
207 uint16_t value;
208 };
209
210 struct bstp_config_unit {
211 uint64_t cu_rootid;
212 uint64_t cu_bridge_id;
213 uint32_t cu_root_path_cost;
214 uint16_t cu_message_age;
215 uint16_t cu_max_age;
216 uint16_t cu_hello_time;
217 uint16_t cu_forward_delay;
218 uint16_t cu_port_id;
219 uint8_t cu_message_type;
220 uint8_t cu_topology_change_acknowledgment;
221 uint8_t cu_topology_change;
222 };
223
224 struct bstp_tcn_unit {
225 uint8_t tu_message_type;
226 };
227
228 /*
229 * Bridge interface list entry.
230 */
231 struct bridge_iflist {
232 LIST_ENTRY(bridge_iflist) bif_next;
233 uint64_t bif_designated_root;
234 uint64_t bif_designated_bridge;
235 uint32_t bif_path_cost;
236 uint32_t bif_designated_cost;
237 struct bridge_timer bif_hold_timer;
238 struct bridge_timer bif_message_age_timer;
239 struct bridge_timer bif_forward_delay_timer;
240 struct bstp_config_unit bif_config_bpdu;
241 uint16_t bif_port_id;
242 uint16_t bif_designated_port;
243 uint8_t bif_state;
244 uint8_t bif_topology_change_acknowledge;
245 uint8_t bif_config_pending;
246 uint8_t bif_change_detection_enabled;
247 uint8_t bif_priority;
248 struct ifnet *bif_ifp; /* member if */
249 uint32_t bif_flags; /* member if flags */
250 };
251
252 /*
253 * Bridge route node.
254 */
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];
262 };
263
264 /*
265 * Software state for each bridge.
266 */
267 struct bridge_softc {
268 struct ifnet sc_if;
269 LIST_ENTRY(bridge_softc) sc_list;
270 uint64_t sc_designated_root;
271 uint64_t sc_bridge_id;
272 struct bridge_iflist *sc_root_port;
273 uint32_t sc_root_path_cost;
274 uint16_t sc_max_age;
275 uint16_t sc_hello_time;
276 uint16_t sc_forward_delay;
277 uint16_t sc_bridge_max_age;
278 uint16_t sc_bridge_hello_time;
279 uint16_t sc_bridge_forward_delay;
280 uint16_t sc_topology_change_time;
281 uint16_t sc_hold_time;
282 uint16_t sc_bridge_priority;
283 uint8_t sc_topology_change_detected;
284 uint8_t sc_topology_change;
285 struct bridge_timer sc_hello_timer;
286 struct bridge_timer sc_topology_change_timer;
287 struct bridge_timer sc_tcn_timer;
288 uint32_t sc_brtmax; /* max # of addresses */
289 uint32_t sc_brtcnt; /* cur. # of addresses */
290 uint32_t sc_brttimeout; /* rt timeout in seconds */
291 struct callout sc_brcallout; /* bridge callout */
292 struct callout sc_bstpcallout; /* STP callout */
293 LIST_HEAD(, bridge_iflist) sc_iflist; /* member interface list */
294 LIST_HEAD(, bridge_rtnode) *sc_rthash; /* our forwarding table */
295 LIST_HEAD(, bridge_rtnode) sc_rtlist; /* list version of above */
296 uint32_t sc_rthash_key; /* key for hash */
297 uint32_t sc_filter_flags; /* ipf and flags */
298 };
299
300 extern const uint8_t bstp_etheraddr[];
301
302 void bridge_ifdetach(struct ifnet *ifp);
303
304 int bridge_output(struct ifnet *ifp, struct mbuf *, struct sockaddr *,
305 struct rtentry *);
306 struct mbuf *bridge_input(struct ifnet *, struct mbuf *);
307
308 void bstp_initialization(struct bridge_softc *);
309 void bstp_stop(struct bridge_softc *);
310 struct mbuf *bstp_input(struct ifnet *, struct mbuf *);
311
312 void bridge_enqueue(struct bridge_softc *, struct ifnet *, struct mbuf *);
313
314 #endif /* _KERNEL */
315