2 * Copyright (c) 2004-2009 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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 $ */
33 * Copyright 2001 Wasabi Systems, Inc.
34 * All rights reserved.
36 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
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
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.
68 * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
69 * All rights reserved.
71 * Redistribution and use in source and binary forms, with or without
72 * modification, are permitted provided that the following conditions
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.
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.
97 * OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp
101 * Data structure and control definitions for bridge interfaces.
104 #ifndef _NET_IF_BRIDGEVAR_H_
105 #define _NET_IF_BRIDGEVAR_H_
109 #include <sys/queue.h>
112 #include <net/ethernet.h>
115 * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the
116 * bridge interface itself is keyed off the ifdrv structure.
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) */
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) */
147 * Generic bridge control request.
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 */
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
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 */
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
183 #define IFBIFBITS "\020\1LEARNING\2DISCOVER\3STP"
185 #define IFBIFBITS "\020\1LEARNING\2DISCOVER\3STP\4PROXYSTA\5PROXYSTA_DISCOVER\6NO_FORWARDING"
188 #define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */
189 #define IFBF_FLUSHALL 0x01 /* flush all addresses */
192 #define IFBF_FILT_USEIPF 0x00000001 /* run pfil hooks on the bridge
194 #define IFBF_FILT_MEMBER 0x00000002 /* run pfil hooks on the member
196 #define IFBF_FILT_ONLYIP 0x00000004 /* only pass IP[46] packets when
198 #define IFBF_FILT_MASK 0x00000007 /* mask of valid values */
201 /* APPLE MODIFICATION <jhw@apple.com>: Default is to pass non-IP packets. */
202 #define IFBF_FILT_DEFAULT ( IFBF_FILT_USEIPF | IFBF_FILT_MEMBER )
204 #define IFBF_FILT_DEFAULT (IFBF_FILT_USEIPF | \
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
217 * Interface list structure.
223 uint32_t ifbic_len
; /* buffer size */
226 struct ifbreq
*ifbicu_req
;
228 #define ifbic_buf ifbic_ifbicu.ifbicu_buf
229 #define ifbic_req ifbic_ifbicu.ifbicu_req
232 #ifdef KERNEL_PRIVATE
234 uint32_t ifbic_len
; /* buffer size */
236 user32_addr_t ifbicu_buf
;
237 user32_addr_t ifbicu_req
;
242 uint32_t ifbic_len
; /* buffer size */
244 user64_addr_t ifbicu_buf
;
245 user64_addr_t ifbicu_req
;
248 #endif /* KERNEL_PRIVATE */
253 * Bridge address request.
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 */
265 #ifdef KERNEL_PRIVATE
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 */
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 */
279 #endif /* KERNEL_PRIVATE */
283 #define IFBAF_TYPEMASK 0x03 /* address type mask */
284 #define IFBAF_DYNAMIC 0x00 /* dynamically learned address */
285 #define IFBAF_STATIC 0x01 /* static address */
287 #define IFBAFBITS "\020\1STATIC"
290 * Address list structure.
296 uint32_t ifbac_len
; /* buffer size */
299 struct ifbareq
*ifbacu_req
;
301 #define ifbac_buf ifbac_ifbacu.ifbacu_buf
302 #define ifbac_req ifbac_ifbacu.ifbacu_req
305 #ifdef KERNEL_PRIVATE
307 uint32_t ifbac_len
; /* buffer size */
309 user32_addr_t ifbacu_buf
;
310 user32_addr_t ifbacu_req
;
315 uint32_t ifbac_len
; /* buffer size */
317 user64_addr_t ifbacu_buf
;
318 user64_addr_t ifbacu_req
;
321 #endif /* KERNEL_PRIVATE */
326 * Bridge parameter structure.
333 uint32_t ifbrpu_int32
;
334 uint16_t ifbrpu_int16
;
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 */
351 * Timekeeping structure used in spanning tree code.
353 struct bridge_timer
{
358 struct bstp_config_unit
{
360 uint64_t cu_bridge_id
;
361 uint32_t cu_root_path_cost
;
362 uint16_t cu_message_age
;
364 uint16_t cu_hello_time
;
365 uint16_t cu_forward_delay
;
367 uint8_t cu_message_type
;
368 uint8_t cu_topology_change_acknowledgment
;
369 uint8_t cu_topology_change
;
372 struct bstp_tcn_unit
{
373 uint8_t tu_message_type
;
379 * Bridge interface list entry.
380 * (VL) bridge_ifmember would be a better name, more descriptive
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
;
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
;
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 */
425 * Software state for each bridge.
427 struct bridge_softc
{
428 LIST_ENTRY(bridge_softc
) sc_list
;
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
;
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 */
461 char sc_if_xname
[IFNAMSIZ
];
462 bpf_packet_func sc_bpf_input
;
463 bpf_packet_func sc_bpf_output
;
468 #define SCF_DETACHING 0x1
470 extern const uint8_t bstp_etheraddr
[];
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);
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
*);
483 #endif /* !_NET_IF_BRIDGEVAR_H_ */