xref: /dragonfly/sys/net/bridge/if_bridgevar.h (revision 49781055)
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.1 2005/12/21 16:40:25 corecode Exp $
70  */
71 
72 /*
73  * Data structure and control definitions for bridge interfaces.
74  */
75 
76 #include <sys/callout.h>
77 #include <sys/queue.h>
78 
79 /*
80  * Commands used in the SIOCSDRVSPEC ioctl.  Note the lookup of the
81  * bridge interface itself is keyed off the ifdrv structure.
82  */
83 #define	BRDGADD			0	/* add bridge member (ifbreq) */
84 #define	BRDGDEL			1	/* delete bridge member (ifbreq) */
85 #define	BRDGGIFFLGS		2	/* get member if flags (ifbreq) */
86 #define	BRDGSIFFLGS		3	/* set member if flags (ifbreq) */
87 #define	BRDGSCACHE		4	/* set cache size (ifbrparam) */
88 #define	BRDGGCACHE		5	/* get cache size (ifbrparam) */
89 #define	BRDGGIFS		6	/* get member list (ifbifconf) */
90 #define	BRDGRTS			7	/* get address list (ifbaconf) */
91 #define	BRDGSADDR		8	/* set static address (ifbareq) */
92 #define	BRDGSTO			9	/* set cache timeout (ifbrparam) */
93 #define	BRDGGTO			10	/* get cache timeout (ifbrparam) */
94 #define	BRDGDADDR		11	/* delete address (ifbareq) */
95 #define	BRDGFLUSH		12	/* flush address cache (ifbreq) */
96 
97 #define	BRDGGPRI		13	/* get priority (ifbrparam) */
98 #define	BRDGSPRI		14	/* set priority (ifbrparam) */
99 #define	BRDGGHT			15	/* get hello time (ifbrparam) */
100 #define	BRDGSHT			16	/* set hello time (ifbrparam) */
101 #define	BRDGGFD			17	/* get forward delay (ifbrparam) */
102 #define	BRDGSFD			18	/* set forward delay (ifbrparam) */
103 #define	BRDGGMA			19	/* get max age (ifbrparam) */
104 #define	BRDGSMA			20	/* set max age (ifbrparam) */
105 #define	BRDGSIFPRIO		21	/* set if priority (ifbreq) */
106 #define BRDGSIFCOST		22	/* set if path cost (ifbreq) */
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_path_cost;		/* member if STP cost */
117 	uint8_t		ifbr_portno;		/* member if port number */
118 };
119 
120 /* BRDGGIFFLAGS, BRDGSIFFLAGS */
121 #define	IFBIF_LEARNING		0x01	/* if can learn */
122 #define	IFBIF_DISCOVER		0x02	/* if sends packets w/ unknown dest. */
123 #define	IFBIF_STP		0x04	/* if participates in spanning tree */
124 
125 #define	IFBIFBITS	"\020\1LEARNING\2DISCOVER\3STP"
126 
127 /* BRDGFLUSH */
128 #define	IFBF_FLUSHDYN		0x00	/* flush learned addresses only */
129 #define	IFBF_FLUSHALL		0x01	/* flush all addresses */
130 
131 /* STP port states */
132 #define	BSTP_IFSTATE_DISABLED	0
133 #define	BSTP_IFSTATE_LISTENING	1
134 #define	BSTP_IFSTATE_LEARNING	2
135 #define	BSTP_IFSTATE_FORWARDING	3
136 #define	BSTP_IFSTATE_BLOCKING	4
137 
138 /*
139  * Interface list structure.
140  */
141 struct ifbifconf {
142 	uint32_t	ifbic_len;	/* buffer size */
143 	union {
144 		caddr_t	ifbicu_buf;
145 		struct ifbreq *ifbicu_req;
146 	} ifbic_ifbicu;
147 #define	ifbic_buf	ifbic_ifbicu.ifbicu_buf
148 #define	ifbic_req	ifbic_ifbicu.ifbicu_req
149 };
150 
151 /*
152  * Bridge address request.
153  */
154 struct ifbareq {
155 	char		ifba_ifsname[IFNAMSIZ];	/* member if name */
156 	unsigned long	ifba_expire;		/* address expire time */
157 	uint8_t		ifba_flags;		/* address flags */
158 	uint8_t		ifba_dst[ETHER_ADDR_LEN];/* destination address */
159 };
160 
161 #define	IFBAF_TYPEMASK	0x03	/* address type mask */
162 #define	IFBAF_DYNAMIC	0x00	/* dynamically learned address */
163 #define	IFBAF_STATIC	0x01	/* static address */
164 
165 #define	IFBAFBITS	"\020\1STATIC"
166 
167 /*
168  * Address list structure.
169  */
170 struct ifbaconf {
171 	uint32_t	ifbac_len;	/* buffer size */
172 	union {
173 		caddr_t ifbacu_buf;
174 		struct ifbareq *ifbacu_req;
175 	} ifbac_ifbacu;
176 #define	ifbac_buf	ifbac_ifbacu.ifbacu_buf
177 #define	ifbac_req	ifbac_ifbacu.ifbacu_req
178 };
179 
180 /*
181  * Bridge parameter structure.
182  */
183 struct ifbrparam {
184 	union {
185 		uint32_t ifbrpu_int32;
186 		uint16_t ifbrpu_int16;
187 		uint8_t ifbrpu_int8;
188 	} ifbrp_ifbrpu;
189 };
190 #define	ifbrp_csize	ifbrp_ifbrpu.ifbrpu_int32	/* cache size */
191 #define	ifbrp_ctime	ifbrp_ifbrpu.ifbrpu_int32	/* cache time (sec) */
192 #define	ifbrp_prio	ifbrp_ifbrpu.ifbrpu_int16	/* bridge priority */
193 #define	ifbrp_hellotime	ifbrp_ifbrpu.ifbrpu_int8	/* hello time (sec) */
194 #define	ifbrp_fwddelay	ifbrp_ifbrpu.ifbrpu_int8	/* fwd time (sec) */
195 #define	ifbrp_maxage	ifbrp_ifbrpu.ifbrpu_int8	/* max age (sec) */
196 
197 #ifdef _KERNEL
198 /*
199  * Timekeeping structure used in spanning tree code.
200  */
201 struct bridge_timer {
202 	uint16_t	active;
203 	uint16_t	value;
204 };
205 
206 struct bstp_config_unit {
207 	uint64_t	cu_rootid;
208 	uint64_t	cu_bridge_id;
209 	uint32_t	cu_root_path_cost;
210 	uint16_t	cu_message_age;
211 	uint16_t	cu_max_age;
212 	uint16_t	cu_hello_time;
213 	uint16_t	cu_forward_delay;
214 	uint16_t	cu_port_id;
215 	uint8_t		cu_message_type;
216 	uint8_t		cu_topology_change_acknowledgment;
217 	uint8_t		cu_topology_change;
218 };
219 
220 struct bstp_tcn_unit {
221 	uint8_t		tu_message_type;
222 };
223 
224 /*
225  * Bridge interface list entry.
226  */
227 struct bridge_iflist {
228 	LIST_ENTRY(bridge_iflist) bif_next;
229 	uint64_t		bif_designated_root;
230 	uint64_t		bif_designated_bridge;
231 	uint32_t		bif_path_cost;
232 	uint32_t		bif_designated_cost;
233 	struct bridge_timer	bif_hold_timer;
234 	struct bridge_timer	bif_message_age_timer;
235 	struct bridge_timer	bif_forward_delay_timer;
236 	struct bstp_config_unit	bif_config_bpdu;
237 	uint16_t		bif_port_id;
238 	uint16_t		bif_designated_port;
239 	uint8_t			bif_state;
240 	uint8_t			bif_topology_change_acknowledge;
241 	uint8_t			bif_config_pending;
242 	uint8_t			bif_change_detection_enabled;
243 	uint8_t			bif_priority;
244 	struct ifnet		*bif_ifp;	/* member if */
245 	uint32_t		bif_flags;	/* member if flags */
246 };
247 
248 /*
249  * Bridge route node.
250  */
251 struct bridge_rtnode {
252 	LIST_ENTRY(bridge_rtnode) brt_hash;	/* hash table linkage */
253 	LIST_ENTRY(bridge_rtnode) brt_list;	/* list linkage */
254 	struct ifnet		*brt_ifp;	/* destination if */
255 	unsigned long		brt_expire;	/* expiration time */
256 	uint8_t			brt_flags;	/* address flags */
257 	uint8_t			brt_addr[ETHER_ADDR_LEN];
258 };
259 
260 /*
261  * Software state for each bridge.
262  */
263 struct bridge_softc {
264 	struct arpcom           sc_arp;
265 	struct ifnet		*sc_ifp;	/* make this an interface */
266 	LIST_ENTRY(bridge_softc) sc_list;
267 	uint64_t		sc_designated_root;
268 	uint64_t		sc_bridge_id;
269 	struct bridge_iflist	*sc_root_port;
270 	uint32_t		sc_root_path_cost;
271 	uint16_t		sc_max_age;
272 	uint16_t		sc_hello_time;
273 	uint16_t		sc_forward_delay;
274 	uint16_t		sc_bridge_max_age;
275 	uint16_t		sc_bridge_hello_time;
276 	uint16_t		sc_bridge_forward_delay;
277 	uint16_t		sc_topology_change_time;
278 	uint16_t		sc_hold_time;
279 	uint16_t		sc_bridge_priority;
280 	uint8_t			sc_topology_change_detected;
281 	uint8_t			sc_topology_change;
282 	struct bridge_timer	sc_hello_timer;
283 	struct bridge_timer	sc_topology_change_timer;
284 	struct bridge_timer	sc_tcn_timer;
285 	uint32_t		sc_brtmax;	/* max # of addresses */
286 	uint32_t		sc_brtcnt;	/* cur. # of addresses */
287 	uint32_t		sc_brttimeout;	/* rt timeout in seconds */
288 	struct callout		sc_brcallout;	/* bridge callout */
289 	struct callout		sc_bstpcallout;	/* STP callout */
290 	LIST_HEAD(, bridge_iflist) sc_iflist;	/* member interface list */
291 	LIST_HEAD(, bridge_rtnode) *sc_rthash;	/* our forwarding table */
292 	LIST_HEAD(, bridge_rtnode) sc_rtlist;	/* list version of above */
293 	uint32_t		sc_rthash_key;	/* key for hash */
294 };
295 #define sc_if                   sc_arp.ac_if
296 
297 extern const uint8_t bstp_etheraddr[];
298 
299 void	bridge_ifdetach(struct ifnet *);
300 void	bridge_rtdelete(struct bridge_softc *, struct ifnet *ifp, int);
301 
302 int	bridge_output_serialized(struct ifnet *, struct mbuf *,
303 	    struct sockaddr *, struct rtentry *);
304 struct mbuf *bridge_input(struct ifnet *, struct mbuf *);
305 
306 extern	void	(*bstp_linkstate_p)(struct ifnet *ifp, int state);
307 
308 void	bstp_initialization(struct bridge_softc *);
309 void	bstp_linkstate(struct ifnet *, int);
310 void	bstp_stop(struct bridge_softc *);
311 struct mbuf *bstp_input(struct ifnet *, struct mbuf *);
312 
313 void	bridge_enqueue(struct bridge_softc *, struct ifnet *, struct mbuf *);
314 
315 #endif /* _KERNEL */
316