]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/if_bridgevar.h
6b47c922e5e024aee16ed66351cebfd7cd04e622
[apple/xnu.git] / bsd / net / if_bridgevar.h
1 /*
2 * Copyright (c) 2004-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 /* $apfw: if_bridgevar,v 1.7 2008/10/24 02:34:06 cbzimmer Exp $ */
30 /* $NetBSD: if_bridgevar.h,v 1.8 2005/12/10 23:21:38 elad Exp $ */
31
32 /*
33 * Copyright 2001 Wasabi Systems, Inc.
34 * All rights reserved.
35 *
36 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed for the NetBSD Project by
49 * Wasabi Systems, Inc.
50 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
51 * or promote products derived from this software without specific prior
52 * written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 * POSSIBILITY OF SUCH DAMAGE.
65 */
66
67 /*
68 * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
69 * All rights reserved.
70 *
71 * Redistribution and use in source and binary forms, with or without
72 * modification, are permitted provided that the following conditions
73 * are met:
74 * 1. Redistributions of source code must retain the above copyright
75 * notice, this list of conditions and the following disclaimer.
76 * 2. Redistributions in binary form must reproduce the above copyright
77 * notice, this list of conditions and the following disclaimer in the
78 * documentation and/or other materials provided with the distribution.
79 * 3. All advertising materials mentioning features or use of this software
80 * must display the following acknowledgement:
81 * This product includes software developed by Jason L. Wright
82 * 4. The name of the author may not be used to endorse or promote products
83 * derived from this software without specific prior written permission.
84 *
85 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
86 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
87 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
88 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
89 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
90 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
91 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
92 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
93 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
94 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
95 * POSSIBILITY OF SUCH DAMAGE.
96 *
97 * OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp
98 */
99
100 /*
101 * Data structure and control definitions for bridge interfaces.
102 */
103
104 #ifndef _NET_IF_BRIDGEVAR_H_
105 #define _NET_IF_BRIDGEVAR_H_
106
107 #ifdef PRIVATE
108
109 #include <sys/queue.h>
110
111 #include <net/if.h>
112 #include <net/ethernet.h>
113
114 /*
115 * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the
116 * bridge interface itself is keyed off the ifdrv structure.
117 */
118 #define BRDGADD 0 /* add bridge member (ifbreq) */
119 #define BRDGDEL 1 /* delete bridge member (ifbreq) */
120 #define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */
121 #define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */
122 #define BRDGSCACHE 4 /* set cache size (ifbrparam) */
123 #define BRDGGCACHE 5 /* get cache size (ifbrparam) */
124 #define BRDGGIFS 6 /* get member list (ifbifconf) */
125 #define BRDGRTS 7 /* get address list (ifbaconf) */
126 #define BRDGSADDR 8 /* set static address (ifbareq) */
127 #define BRDGSTO 9 /* set cache timeout (ifbrparam) */
128 #define BRDGGTO 10 /* get cache timeout (ifbrparam) */
129 #define BRDGDADDR 11 /* delete address (ifbareq) */
130 #define BRDGFLUSH 12 /* flush address cache (ifbreq) */
131
132 #define BRDGGPRI 13 /* get priority (ifbrparam) */
133 #define BRDGSPRI 14 /* set priority (ifbrparam) */
134 #define BRDGGHT 15 /* get hello time (ifbrparam) */
135 #define BRDGSHT 16 /* set hello time (ifbrparam) */
136 #define BRDGGFD 17 /* get forward delay (ifbrparam) */
137 #define BRDGSFD 18 /* set forward delay (ifbrparam) */
138 #define BRDGGMA 19 /* get max age (ifbrparam) */
139 #define BRDGSMA 20 /* set max age (ifbrparam) */
140 #define BRDGSIFPRIO 21 /* set if priority (ifbreq) */
141 #define BRDGSIFCOST 22 /* set if path cost (ifbreq) */
142 #define BRDGGFILT 23 /* get filter flags (ifbrparam) */
143 #define BRDGSFILT 24 /* set filter flags (ifbrparam) */
144 #define BRDGPURGE 25 /* purge address cache for a particular interface (ifbreq) */
145
146 /*
147 * Generic bridge control request.
148 */
149 #pragma pack(4)
150
151 struct ifbreq {
152 char ifbr_ifsname[IFNAMSIZ]; /* member if name */
153 uint32_t ifbr_ifsflags; /* member if flags */
154 uint16_t ifbr_portno; /* member if port number */
155 uint8_t ifbr_state; /* member if STP state */
156 uint8_t ifbr_priority; /* member if STP priority */
157 uint8_t ifbr_path_cost; /* member if STP cost */
158 };
159
160 #pragma pack()
161
162 /* BRDGGIFFLAGS, BRDGSIFFLAGS */
163 #define IFBIF_LEARNING 0x01 /* if can learn */
164 #define IFBIF_DISCOVER 0x02 /* if sends packets w/ unknown dest. */
165 #define IFBIF_STP 0x04 /* if participates in spanning tree */
166 /* APPLE MODIFICATION <cbz@apple.com>
167 add the following bits for ProxySTA:
168 IFBIF_PROXYSTA, IFBIF_PROXYSTA_DISCOVER
169 add the following bits for Guest Network
170 IFBIF_NO_FORWARDING
171 */
172 #define IFBIF_PROXYSTA 0x08 /* if interface is a proxy sta */
173 #define IFBIF_PROXYSTA_DISCOVER 0x10 /* if interface is used to discover proxy sta candidates */
174 #define IFBIF_NO_FORWARDING 0x20 /* if interface cannot forward traffic from one interface to the next */
175
176 /* APPLE MODIFICATION <cbz@apple.com>
177 add the following bits for ProxySTA:
178 PROXYSTA, PROXYSTA_DISCOVER
179 add the following bits for Guest Network
180 NO_FORWARDING
181 this was...
182
183 #define IFBIFBITS "\020\1LEARNING\2DISCOVER\3STP"
184 */
185 #define IFBIFBITS "\020\1LEARNING\2DISCOVER\3STP\4PROXYSTA\5PROXYSTA_DISCOVER\6NO_FORWARDING"
186
187 /* BRDGFLUSH */
188 #define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */
189 #define IFBF_FLUSHALL 0x01 /* flush all addresses */
190
191 /* BRDGSFILT */
192 #define IFBF_FILT_USEIPF 0x00000001 /* run pfil hooks on the bridge
193 interface */
194 #define IFBF_FILT_MEMBER 0x00000002 /* run pfil hooks on the member
195 interfaces */
196 #define IFBF_FILT_ONLYIP 0x00000004 /* only pass IP[46] packets when
197 pfil is enabled */
198 #define IFBF_FILT_MASK 0x00000007 /* mask of valid values */
199
200
201 /* APPLE MODIFICATION <jhw@apple.com>: Default is to pass non-IP packets. */
202 #define IFBF_FILT_DEFAULT ( IFBF_FILT_USEIPF | IFBF_FILT_MEMBER )
203 #if 0
204 #define IFBF_FILT_DEFAULT (IFBF_FILT_USEIPF | \
205 IFBF_FILT_MEMBER | \
206 IFBF_FILT_ONLYIP)
207 #endif
208
209 /* STP port states */
210 #define BSTP_IFSTATE_DISABLED 0
211 #define BSTP_IFSTATE_LISTENING 1
212 #define BSTP_IFSTATE_LEARNING 2
213 #define BSTP_IFSTATE_FORWARDING 3
214 #define BSTP_IFSTATE_BLOCKING 4
215
216 /*
217 * Interface list structure.
218 */
219
220 #pragma pack(4)
221
222 struct ifbifconf {
223 uint32_t ifbic_len; /* buffer size */
224 union {
225 caddr_t ifbicu_buf;
226 struct ifbreq *ifbicu_req;
227 } ifbic_ifbicu;
228 #define ifbic_buf ifbic_ifbicu.ifbicu_buf
229 #define ifbic_req ifbic_ifbicu.ifbicu_req
230 };
231
232 #ifdef KERNEL_PRIVATE
233 struct ifbifconf32 {
234 uint32_t ifbic_len; /* buffer size */
235 union {
236 user32_addr_t ifbicu_buf;
237 user32_addr_t ifbicu_req;
238 } ifbic_ifbicu;
239 };
240
241 struct ifbifconf64 {
242 uint32_t ifbic_len; /* buffer size */
243 union {
244 user64_addr_t ifbicu_buf;
245 user64_addr_t ifbicu_req;
246 } ifbic_ifbicu;
247 };
248 #endif /* KERNEL_PRIVATE */
249
250 #pragma pack()
251
252 /*
253 * Bridge address request.
254 */
255
256 #pragma pack(4)
257
258 struct ifbareq {
259 char ifba_ifsname[IFNAMSIZ]; /* member if name */
260 unsigned long ifba_expire; /* address expire time */
261 uint8_t ifba_flags; /* address flags */
262 uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */
263 };
264
265 #ifdef KERNEL_PRIVATE
266 struct ifbareq32 {
267 char ifba_ifsname[IFNAMSIZ]; /* member if name */
268 uint32_t ifba_expire; /* address expire time */
269 uint8_t ifba_flags; /* address flags */
270 uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */
271 };
272
273 struct ifbareq64 {
274 char ifba_ifsname[IFNAMSIZ]; /* member if name */
275 uint64_t ifba_expire; /* address expire time */
276 uint8_t ifba_flags; /* address flags */
277 uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */
278 };
279 #endif /* KERNEL_PRIVATE */
280
281 #pragma pack()
282
283 #define IFBAF_TYPEMASK 0x03 /* address type mask */
284 #define IFBAF_DYNAMIC 0x00 /* dynamically learned address */
285 #define IFBAF_STATIC 0x01 /* static address */
286
287 #define IFBAFBITS "\020\1STATIC"
288
289 /*
290 * Address list structure.
291 */
292
293 #pragma pack(4)
294
295 struct ifbaconf {
296 uint32_t ifbac_len; /* buffer size */
297 union {
298 caddr_t ifbacu_buf;
299 struct ifbareq *ifbacu_req;
300 } ifbac_ifbacu;
301 #define ifbac_buf ifbac_ifbacu.ifbacu_buf
302 #define ifbac_req ifbac_ifbacu.ifbacu_req
303 };
304
305 #ifdef KERNEL_PRIVATE
306 struct ifbaconf32 {
307 uint32_t ifbac_len; /* buffer size */
308 union {
309 user32_addr_t ifbacu_buf;
310 user32_addr_t ifbacu_req;
311 } ifbac_ifbacu;
312 };
313
314 struct ifbaconf64 {
315 uint32_t ifbac_len; /* buffer size */
316 union {
317 user64_addr_t ifbacu_buf;
318 user64_addr_t ifbacu_req;
319 } ifbac_ifbacu;
320 };
321 #endif /* KERNEL_PRIVATE */
322
323 #pragma pack()
324
325 /*
326 * Bridge parameter structure.
327 */
328
329 #pragma pack(4)
330
331 struct ifbrparam {
332 union {
333 uint32_t ifbrpu_int32;
334 uint16_t ifbrpu_int16;
335 uint8_t ifbrpu_int8;
336 } ifbrp_ifbrpu;
337 };
338
339 #pragma pack()
340
341 #define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */
342 #define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */
343 #define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */
344 #define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */
345 #define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */
346 #define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */
347 #define ifbrp_filter ifbrp_ifbrpu.ifbrpu_int32 /* filtering flags */
348
349 #ifdef KERNEL
350 /*
351 * Timekeeping structure used in spanning tree code.
352 */
353 struct bridge_timer {
354 uint16_t active;
355 uint16_t value;
356 };
357
358 struct bstp_config_unit {
359 uint64_t cu_rootid;
360 uint64_t cu_bridge_id;
361 uint32_t cu_root_path_cost;
362 uint16_t cu_message_age;
363 uint16_t cu_max_age;
364 uint16_t cu_hello_time;
365 uint16_t cu_forward_delay;
366 uint16_t cu_port_id;
367 uint8_t cu_message_type;
368 uint8_t cu_topology_change_acknowledgment;
369 uint8_t cu_topology_change;
370 };
371
372 struct bstp_tcn_unit {
373 uint8_t tu_message_type;
374 };
375
376 struct bridge_softc;
377
378 /*
379 * Bridge interface list entry.
380 * (VL) bridge_ifmember would be a better name, more descriptive
381 */
382 struct bridge_iflist {
383 LIST_ENTRY(bridge_iflist) bif_next;
384 uint64_t bif_designated_root;
385 uint64_t bif_designated_bridge;
386 uint32_t bif_path_cost;
387 uint32_t bif_designated_cost;
388 struct bridge_timer bif_hold_timer;
389 struct bridge_timer bif_message_age_timer;
390 struct bridge_timer bif_forward_delay_timer;
391 uint16_t bif_port_id;
392 uint16_t bif_designated_port;
393 struct bstp_config_unit bif_config_bpdu;
394 uint8_t bif_state;
395 uint8_t bif_topology_change_acknowledge;
396 uint8_t bif_config_pending;
397 uint8_t bif_change_detection_enabled;
398 uint8_t bif_priority;
399 struct ifnet *bif_ifp; /* member if */
400 uint32_t bif_flags; /* member if flags */
401 int bif_mutecap; /* member muted caps */
402 interface_filter_t bif_iff_ref;
403 struct bridge_softc *bif_sc;
404 };
405
406 /*
407 * Bridge route node.
408 */
409 struct bridge_rtnode {
410 LIST_ENTRY(bridge_rtnode) brt_hash; /* hash table linkage */
411 LIST_ENTRY(bridge_rtnode) brt_list; /* list linkage */
412 struct ifnet *brt_ifp; /* destination if */
413 unsigned long brt_expire; /* expiration time */
414 uint8_t brt_flags; /* address flags */
415 uint8_t brt_addr[ETHER_ADDR_LEN];
416 /* APPLE MODIFICATION <cbz@apple.com> - add the following elements:
417 brt_flags_ext, brt_ifp_proxysta */
418 #define IFBAF_EXT_PROXYSTA 0x01
419 uint8_t brt_flags_ext; /* extended flags */
420 struct ifnet *brt_ifp_proxysta; /* proxy sta if */
421 };
422
423
424 /*
425 * Software state for each bridge.
426 */
427 struct bridge_softc {
428 LIST_ENTRY(bridge_softc) sc_list;
429 struct ifnet *sc_if;
430 uint64_t sc_designated_root;
431 uint64_t sc_bridge_id;
432 struct bridge_iflist *sc_root_port;
433 uint32_t sc_root_path_cost;
434 uint16_t sc_max_age;
435 uint16_t sc_hello_time;
436 uint16_t sc_forward_delay;
437 uint16_t sc_bridge_max_age;
438 uint16_t sc_bridge_hello_time;
439 uint16_t sc_bridge_forward_delay;
440 uint16_t sc_topology_change_time;
441 uint16_t sc_hold_time;
442 uint16_t sc_bridge_priority;
443 uint8_t sc_topology_change_detected;
444 uint8_t sc_topology_change;
445 struct bridge_timer sc_hello_timer;
446 struct bridge_timer sc_topology_change_timer;
447 struct bridge_timer sc_tcn_timer;
448 uint32_t sc_brtmax; /* max # of addresses */
449 uint32_t sc_brtcnt; /* cur. # of addresses */
450 /* APPLE MODIFICATION <cbz@apple.com> - add the following elements:
451 sc_brtmax_proxysta */
452 uint32_t sc_brtmax_proxysta; /* max # of proxy sta addresses */
453 uint32_t sc_brttimeout; /* rt timeout in seconds */
454 LIST_HEAD(, bridge_iflist) sc_iflist; /* member interface list */
455 LIST_HEAD(, bridge_rtnode) *sc_rthash; /* our forwarding table */
456 LIST_HEAD(, bridge_rtnode) sc_rtlist; /* list version of above */
457 uint32_t sc_rthash_key; /* key for hash */
458 uint32_t sc_filter_flags; /* ipf and flags */
459
460 //(VL)
461 char sc_if_xname[IFNAMSIZ];
462 bpf_packet_func sc_bpf_input;
463 bpf_packet_func sc_bpf_output;
464 u_int32_t sc_flags;
465 lck_mtx_t *sc_mtx;
466 };
467
468 #define SCF_DETACHING 0x1
469
470 extern const uint8_t bstp_etheraddr[];
471
472 int bridgeattach(int);
473 void bridge_enqueue(struct bridge_softc *, struct ifnet *, struct mbuf *);
474 void bridge_rtdelete(struct bridge_softc *, struct ifnet *, int);
475
476 void bstp_initialization(struct bridge_softc *);
477 void bstp_stop(struct bridge_softc *);
478 struct mbuf *bstp_input(struct bridge_softc *, struct ifnet *, struct mbuf *);
479
480
481 #endif /* KERNEL */
482 #endif /* PRIVATE */
483 #endif /* !_NET_IF_BRIDGEVAR_H_ */
484