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