kernel - Major bridging functionality completed
[dragonfly.git] / sys / net / bridge / if_bridgevar.h
CommitLineData
ac93838f
SS
1/*
2 * Copyright 2001 Wasabi Systems, Inc.
3 * All rights reserved.
4 *
5 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
6 *
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.
22 *
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.
34 */
35
36/*
37 * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
38 * All rights reserved.
39 *
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.
53 *
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.
65 *
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 $
30ced003 69 * $DragonFly: src/sys/net/bridge/if_bridgevar.h,v 1.10 2008/11/26 12:49:43 sephe Exp $
ac93838f
SS
70 */
71
8f7b13ef
SZ
72#ifndef _NET_IF_BRIDGEVAR_H
73#define _NET_IF_BRIDGEVAR_H
74
ac93838f
SS
75/*
76 * Data structure and control definitions for bridge interfaces.
77 */
78
79#include <sys/callout.h>
80#include <sys/queue.h>
81
82/*
83 * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the
84 * bridge interface itself is keyed off the ifdrv structure.
85 */
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) */
99
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) */
d217f5e5
SU
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) */
ac93838f
SS
112
113/*
114 * Generic bridge control request.
115 */
116struct ifbreq {
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 */
70d9a675
MD
123 uint64_t ifbr_designated_root; /* synthesized */
124 uint64_t ifbr_designated_bridge;
125 uint32_t ifbr_designated_cost;
126 uint16_t ifbr_designated_port;
3677aae9 127 uint16_t unused01;
70d9a675
MD
128 uint64_t ifbr_peer_root; /* from peer */
129 uint64_t ifbr_peer_bridge; /* from peer */
130 uint32_t ifbr_peer_cost; /* from peer */
131 uint16_t ifbr_peer_port; /* from peer */
132 uint16_t unused02;
ac93838f
SS
133};
134
135/* BRDGGIFFLAGS, BRDGSIFFLAGS */
136#define IFBIF_LEARNING 0x01 /* if can learn */
137#define IFBIF_DISCOVER 0x02 /* if sends packets w/ unknown dest. */
138#define IFBIF_STP 0x04 /* if participates in spanning tree */
d217f5e5 139#define IFBIF_SPAN 0x08 /* if is a span port */
70d9a675
MD
140#define IFBIF_DESIGNATED 0x10 /* mostly age timer expired */
141#define IFBIF_ROOT 0x20 /* selected root or near-root */
ac93838f 142
70d9a675
MD
143#define IFBIF_KEEPMASK (IFBIF_SPAN | IFBIF_DESIGNATED | IFBIF_ROOT)
144
145#define IFBIFBITS "\020\1LEARNING\2DISCOVER\3STP\4SPAN\5DESIGNATED" \
146 "\6ROOT"
ac93838f
SS
147
148/* BRDGFLUSH */
149#define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */
150#define IFBF_FLUSHALL 0x01 /* flush all addresses */
30ced003 151#define IFBF_FLUSHSYNC 0x02 /* synchronized flush */
ac93838f
SS
152
153/* STP port states */
154#define BSTP_IFSTATE_DISABLED 0
155#define BSTP_IFSTATE_LISTENING 1
156#define BSTP_IFSTATE_LEARNING 2
157#define BSTP_IFSTATE_FORWARDING 3
158#define BSTP_IFSTATE_BLOCKING 4
3677aae9 159#define BSTP_IFSTATE_L1BLOCKING 5 /* link1 blocking mode no-activity */
ac93838f
SS
160
161/*
162 * Interface list structure.
163 */
164struct ifbifconf {
165 uint32_t ifbic_len; /* buffer size */
166 union {
167 caddr_t ifbicu_buf;
168 struct ifbreq *ifbicu_req;
169 } ifbic_ifbicu;
170#define ifbic_buf ifbic_ifbicu.ifbicu_buf
171#define ifbic_req ifbic_ifbicu.ifbicu_req
172};
173
174/*
175 * Bridge address request.
176 */
177struct ifbareq {
178 char ifba_ifsname[IFNAMSIZ]; /* member if name */
179 unsigned long ifba_expire; /* address expire time */
180 uint8_t ifba_flags; /* address flags */
181 uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */
182};
183
184#define IFBAF_TYPEMASK 0x03 /* address type mask */
185#define IFBAF_DYNAMIC 0x00 /* dynamically learned address */
186#define IFBAF_STATIC 0x01 /* static address */
187
188#define IFBAFBITS "\020\1STATIC"
189
190/*
191 * Address list structure.
192 */
193struct ifbaconf {
194 uint32_t ifbac_len; /* buffer size */
195 union {
196 caddr_t ifbacu_buf;
197 struct ifbareq *ifbacu_req;
198 } ifbac_ifbacu;
199#define ifbac_buf ifbac_ifbacu.ifbacu_buf
200#define ifbac_req ifbac_ifbacu.ifbacu_req
201};
202
203/*
204 * Bridge parameter structure.
205 */
206struct ifbrparam {
207 union {
208 uint32_t ifbrpu_int32;
209 uint16_t ifbrpu_int16;
210 uint8_t ifbrpu_int8;
211 } ifbrp_ifbrpu;
212};
213#define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */
214#define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */
215#define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */
216#define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */
217#define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */
218#define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */
219
220#ifdef _KERNEL
221/*
222 * Timekeeping structure used in spanning tree code.
223 */
224struct bridge_timer {
225 uint16_t active;
226 uint16_t value;
227};
228
229struct bstp_config_unit {
230 uint64_t cu_rootid;
231 uint64_t cu_bridge_id;
232 uint32_t cu_root_path_cost;
233 uint16_t cu_message_age;
234 uint16_t cu_max_age;
235 uint16_t cu_hello_time;
236 uint16_t cu_forward_delay;
237 uint16_t cu_port_id;
238 uint8_t cu_message_type;
239 uint8_t cu_topology_change_acknowledgment;
240 uint8_t cu_topology_change;
241};
242
243struct bstp_tcn_unit {
244 uint8_t tu_message_type;
245};
246
247/*
8f7b13ef
SZ
248 * Bridge interface entry.
249 */
250struct bridge_ifinfo {
70d9a675
MD
251 uint64_t bifi_peer_root;
252 uint64_t bifi_peer_bridge;
253 uint32_t bifi_peer_cost;
254 uint16_t bifi_peer_port;
255 uint16_t bifi_unused02;
256 uint16_t bifi_port_id;
8f7b13ef 257 uint32_t bifi_path_cost;
8f7b13ef
SZ
258 struct bridge_timer bifi_hold_timer;
259 struct bridge_timer bifi_message_age_timer;
260 struct bridge_timer bifi_forward_delay_timer;
3677aae9 261 struct bridge_timer bifi_link1_timer;
8f7b13ef 262 struct bstp_config_unit bifi_config_bpdu;
70d9a675 263 uint32_t bifi_flags; /* member if flags */
8f7b13ef
SZ
264 uint8_t bifi_state;
265 uint8_t bifi_topology_change_acknowledge;
266 uint8_t bifi_config_pending;
267 uint8_t bifi_change_detection_enabled;
268 uint8_t bifi_priority;
269 struct ifnet *bifi_ifp; /* member if */
270 int bifi_mutecap; /* member muted caps */
271};
272
70d9a675
MD
273#define bif_peer_root bif_info->bifi_peer_root
274#define bif_peer_bridge bif_info->bifi_peer_bridge
275#define bif_peer_cost bif_info->bifi_peer_cost
276#define bif_peer_port bif_info->bifi_peer_port
8f7b13ef 277#define bif_path_cost bif_info->bifi_path_cost
8f7b13ef
SZ
278#define bif_hold_timer bif_info->bifi_hold_timer
279#define bif_message_age_timer bif_info->bifi_message_age_timer
280#define bif_forward_delay_timer bif_info->bifi_forward_delay_timer
3677aae9 281#define bif_link1_timer bif_info->bifi_link1_timer
8f7b13ef
SZ
282#define bif_config_bpdu bif_info->bifi_config_bpdu
283#define bif_port_id bif_info->bifi_port_id
8f7b13ef 284#define bif_state bif_info->bifi_state
70d9a675 285#define bif_flags bif_info->bifi_flags
8f7b13ef
SZ
286#define bif_topology_change_acknowledge \
287 bif_info->bifi_topology_change_acknowledge
288#define bif_config_pending bif_info->bifi_config_pending
289#define bif_change_detection_enabled bif_info->bifi_change_detection_enabled
290#define bif_priority bif_info->bifi_priority
70d9a675 291#define bif_message_age_timer bif_info->bifi_message_age_timer
8f7b13ef
SZ
292
293/*
ac93838f
SS
294 * Bridge interface list entry.
295 */
296struct bridge_iflist {
70d9a675 297 TAILQ_ENTRY(bridge_iflist) bif_next;
ac93838f 298 struct ifnet *bif_ifp; /* member if */
8f7b13ef
SZ
299 int bif_onlist;
300 struct bridge_ifinfo *bif_info;
ac93838f 301};
70d9a675 302TAILQ_HEAD(bridge_iflist_head, bridge_iflist);
ac93838f
SS
303
304/*
4394693c
SZ
305 * Bridge route info.
306 */
307struct bridge_rtinfo {
308 struct ifnet *bri_ifp; /* destination if */
309 unsigned long bri_expire; /* expiration time */
310 uint8_t bri_flags; /* address flags */
311 uint8_t bri_dead;
312 uint8_t bri_pad[2];
313};
314
315/*
ac93838f
SS
316 * Bridge route node.
317 */
318struct bridge_rtnode {
319 LIST_ENTRY(bridge_rtnode) brt_hash; /* hash table linkage */
320 LIST_ENTRY(bridge_rtnode) brt_list; /* list linkage */
ac93838f 321 uint8_t brt_addr[ETHER_ADDR_LEN];
4394693c
SZ
322 uint8_t brt_pad[2];
323 struct bridge_rtinfo *brt_info;
ac93838f 324};
4394693c 325LIST_HEAD(bridge_rtnode_head, bridge_rtnode);
ac93838f
SS
326
327/*
328 * Software state for each bridge.
329 */
330struct bridge_softc {
331 struct arpcom sc_arp;
332 struct ifnet *sc_ifp; /* make this an interface */
333 LIST_ENTRY(bridge_softc) sc_list;
ac93838f 334 uint64_t sc_bridge_id;
70d9a675
MD
335 uint64_t sc_designated_root;
336 uint64_t sc_designated_bridge;
337 uint32_t sc_designated_cost; /* root path cost */
338 uint16_t sc_designated_port;
339 uint16_t sc_unused01;
340 struct bridge_iflist *sc_root_port;
ac93838f
SS
341 uint16_t sc_max_age;
342 uint16_t sc_hello_time;
343 uint16_t sc_forward_delay;
344 uint16_t sc_bridge_max_age;
345 uint16_t sc_bridge_hello_time;
346 uint16_t sc_bridge_forward_delay;
347 uint16_t sc_topology_change_time;
348 uint16_t sc_hold_time;
349 uint16_t sc_bridge_priority;
350 uint8_t sc_topology_change_detected;
351 uint8_t sc_topology_change;
352 struct bridge_timer sc_hello_timer;
353 struct bridge_timer sc_topology_change_timer;
354 struct bridge_timer sc_tcn_timer;
355 uint32_t sc_brtmax; /* max # of addresses */
356 uint32_t sc_brtcnt; /* cur. # of addresses */
357 uint32_t sc_brttimeout; /* rt timeout in seconds */
358 struct callout sc_brcallout; /* bridge callout */
002c1265 359 struct netmsg_base sc_brtimemsg; /* bridge callout msg */
ac93838f 360 struct callout sc_bstpcallout; /* STP callout */
002c1265 361 struct netmsg_base sc_bstptimemsg; /* STP callout msg */
8f7b13ef
SZ
362 struct bridge_iflist_head *sc_iflists; /* percpu member if lists */
363 struct bridge_rtnode_head **sc_rthashs; /* percpu forwarding tables */
364 struct bridge_rtnode_head *sc_rtlists; /* percpu lists of the above */
ac93838f 365 uint32_t sc_rthash_key; /* key for hash */
8f7b13ef 366 struct bridge_iflist_head sc_spanlist; /* span ports list */
d895303b 367 int sc_span; /* has span ports */
d217f5e5 368 struct bridge_timer sc_link_timer;
ac93838f
SS
369};
370#define sc_if sc_arp.ac_if
371
e9d22060
SZ
372#define BRIDGE_CFGCPU 0
373#define BRIDGE_CFGPORT cpu_portfn(BRIDGE_CFGCPU)
374
ac93838f
SS
375extern const uint8_t bstp_etheraddr[];
376
ac93838f
SS
377void bridge_rtdelete(struct bridge_softc *, struct ifnet *ifp, int);
378
ac93838f
SS
379extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state);
380
381void bstp_initialization(struct bridge_softc *);
382void bstp_linkstate(struct ifnet *, int);
383void bstp_stop(struct bridge_softc *);
b2417333
SZ
384void bstp_input(struct bridge_softc *, struct bridge_iflist *,
385 struct mbuf *);
002c1265 386void bstp_tick_handler(netmsg_t);
70d9a675
MD
387int bstp_supersedes_port_info(struct bridge_softc *,
388 struct bridge_iflist *);
389
ac93838f 390
708a3bfa 391void bridge_enqueue(struct ifnet *, struct mbuf *);
ac93838f
SS
392
393#endif /* _KERNEL */
8f7b13ef
SZ
394
395#endif /* !_NET_IF_BRIDGEVAR_H */