xref: /freebsd/sys/net/if_bridgevar.h (revision 48cb3fee25862a6adc10fe0b2c2dc15c7fd7fd9e)
1 /*	$NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $	*/
2 
3 /*
4  * SPDX-License-Identifier: BSD-4-Clause
5  *
6  * Copyright 2001 Wasabi Systems, Inc.
7  * All rights reserved.
8  *
9  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed for the NetBSD Project by
22  *	Wasabi Systems, Inc.
23  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
24  *    or promote products derived from this software without specific prior
25  *    written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 /*
41  * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
42  * All rights reserved.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *	This product includes software developed by Jason L. Wright
55  * 4. The name of the author may not be used to endorse or promote products
56  *    derived from this software without specific prior written permission.
57  *
58  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
60  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
61  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
62  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
63  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
64  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
66  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
67  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68  * POSSIBILITY OF SUCH DAMAGE.
69  *
70  * OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp
71  *
72  * $FreeBSD$
73  */
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 <sys/condvar.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	BRDGPARAM		25	/* get bridge STP params (ifbropreq) */
114 #define	BRDGGRTE		26	/* get cache drops (ifbrparam) */
115 #define	BRDGGIFSSTP		27	/* get member STP params list
116 					 * (ifbpstpconf) */
117 #define	BRDGSPROTO		28	/* set protocol (ifbrparam) */
118 #define	BRDGSTXHC		29	/* set tx hold count (ifbrparam) */
119 #define	BRDGSIFAMAX		30	/* set max interface addrs (ifbreq) */
120 
121 /*
122  * Generic bridge control request.
123  */
124 struct ifbreq {
125 	char		ifbr_ifsname[IFNAMSIZ];	/* member if name */
126 	uint32_t	ifbr_ifsflags;		/* member if flags */
127 	uint32_t	ifbr_stpflags;		/* member if STP flags */
128 	uint32_t	ifbr_path_cost;		/* member if STP cost */
129 	uint8_t		ifbr_portno;		/* member if port number */
130 	uint8_t		ifbr_priority;		/* member if STP priority */
131 	uint8_t		ifbr_proto;		/* member if STP protocol */
132 	uint8_t		ifbr_role;		/* member if STP role */
133 	uint8_t		ifbr_state;		/* member if STP state */
134 	uint32_t	ifbr_addrcnt;		/* member if addr number */
135 	uint32_t	ifbr_addrmax;		/* member if addr max */
136 	uint32_t	ifbr_addrexceeded;	/* member if addr violations */
137 	uint8_t		pad[32];
138 };
139 
140 /* BRDGGIFFLAGS, BRDGSIFFLAGS */
141 #define	IFBIF_LEARNING		0x0001	/* if can learn */
142 #define	IFBIF_DISCOVER		0x0002	/* if sends packets w/ unknown dest. */
143 #define	IFBIF_STP		0x0004	/* if participates in spanning tree */
144 #define	IFBIF_SPAN		0x0008	/* if is a span port */
145 #define	IFBIF_STICKY		0x0010	/* if learned addresses stick */
146 #define	IFBIF_BSTP_EDGE		0x0020	/* member stp edge port */
147 #define	IFBIF_BSTP_AUTOEDGE	0x0040	/* member stp autoedge enabled */
148 #define	IFBIF_BSTP_PTP		0x0080	/* member stp point to point */
149 #define	IFBIF_BSTP_AUTOPTP	0x0100	/* member stp autoptp enabled */
150 #define	IFBIF_BSTP_ADMEDGE	0x0200	/* member stp admin edge enabled */
151 #define	IFBIF_BSTP_ADMCOST	0x0400	/* member stp admin path cost */
152 #define	IFBIF_PRIVATE		0x0800	/* if is a private segment */
153 
154 #define	IFBIFBITS	"\020\001LEARNING\002DISCOVER\003STP\004SPAN" \
155 			"\005STICKY\014PRIVATE\006EDGE\007AUTOEDGE\010PTP" \
156 			"\011AUTOPTP"
157 #define	IFBIFMASK	~(IFBIF_BSTP_EDGE|IFBIF_BSTP_AUTOEDGE|IFBIF_BSTP_PTP| \
158 			IFBIF_BSTP_AUTOPTP|IFBIF_BSTP_ADMEDGE| \
159 			IFBIF_BSTP_ADMCOST)	/* not saved */
160 
161 /* BRDGFLUSH */
162 #define	IFBF_FLUSHDYN		0x00	/* flush learned addresses only */
163 #define	IFBF_FLUSHALL		0x01	/* flush all addresses */
164 
165 /*
166  * Interface list structure.
167  */
168 struct ifbifconf {
169 	uint32_t	ifbic_len;	/* buffer size */
170 	union {
171 		caddr_t	ifbicu_buf;
172 		struct ifbreq *ifbicu_req;
173 	} ifbic_ifbicu;
174 #define	ifbic_buf	ifbic_ifbicu.ifbicu_buf
175 #define	ifbic_req	ifbic_ifbicu.ifbicu_req
176 };
177 
178 /*
179  * Bridge address request.
180  */
181 struct ifbareq {
182 	char		ifba_ifsname[IFNAMSIZ];	/* member if name */
183 	unsigned long	ifba_expire;		/* address expire time */
184 	uint8_t		ifba_flags;		/* address flags */
185 	uint8_t		ifba_dst[ETHER_ADDR_LEN];/* destination address */
186 	uint16_t	ifba_vlan;		/* vlan id */
187 };
188 
189 #define	IFBAF_TYPEMASK	0x03	/* address type mask */
190 #define	IFBAF_DYNAMIC	0x00	/* dynamically learned address */
191 #define	IFBAF_STATIC	0x01	/* static address */
192 #define	IFBAF_STICKY	0x02	/* sticky address */
193 
194 #define	IFBAFBITS	"\020\1STATIC\2STICKY"
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_proto	ifbrp_ifbrpu.ifbrpu_int8	/* bridge protocol */
223 #define	ifbrp_txhc	ifbrp_ifbrpu.ifbrpu_int8	/* bpdu tx holdcount */
224 #define	ifbrp_hellotime	ifbrp_ifbrpu.ifbrpu_int8	/* hello time (sec) */
225 #define	ifbrp_fwddelay	ifbrp_ifbrpu.ifbrpu_int8	/* fwd time (sec) */
226 #define	ifbrp_maxage	ifbrp_ifbrpu.ifbrpu_int8	/* max age (sec) */
227 #define	ifbrp_cexceeded ifbrp_ifbrpu.ifbrpu_int32	/* # of cache dropped
228 							 * adresses */
229 /*
230  * Bridge current operational parameters structure.
231  */
232 struct ifbropreq {
233 	uint8_t		ifbop_holdcount;
234 	uint8_t		ifbop_maxage;
235 	uint8_t		ifbop_hellotime;
236 	uint8_t		ifbop_fwddelay;
237 	uint8_t		ifbop_protocol;
238 	uint16_t	ifbop_priority;
239 	uint16_t	ifbop_root_port;
240 	uint32_t	ifbop_root_path_cost;
241 	uint64_t	ifbop_bridgeid;
242 	uint64_t	ifbop_designated_root;
243 	uint64_t	ifbop_designated_bridge;
244 	struct timeval	ifbop_last_tc_time;
245 };
246 
247 /*
248  * Bridge member operational STP params structure.
249  */
250 struct ifbpstpreq {
251 	uint8_t		ifbp_portno;		/* bp STP port number */
252 	uint32_t	ifbp_fwd_trans;		/* bp STP fwd transitions */
253 	uint32_t	ifbp_design_cost;	/* bp STP designated cost */
254 	uint32_t	ifbp_design_port;	/* bp STP designated port */
255 	uint64_t	ifbp_design_bridge;	/* bp STP designated bridge */
256 	uint64_t	ifbp_design_root;	/* bp STP designated root */
257 };
258 
259 /*
260  * Bridge STP ports list structure.
261  */
262 struct ifbpstpconf {
263 	uint32_t	ifbpstp_len;	/* buffer size */
264 	union {
265 		caddr_t	ifbpstpu_buf;
266 		struct ifbpstpreq *ifbpstpu_req;
267 	} ifbpstp_ifbpstpu;
268 #define	ifbpstp_buf	ifbpstp_ifbpstpu.ifbpstpu_buf
269 #define	ifbpstp_req	ifbpstp_ifbpstpu.ifbpstpu_req
270 };
271 
272 #define STP_STATES \
273     "disabled",    \
274     "listening",   \
275     "learning",    \
276     "forwarding",  \
277     "blocking",    \
278     "discarding"
279 
280 #define STP_PROTOS \
281     "stp",         \
282     "-",           \
283     "rstp"
284 
285 #define STP_ROLES \
286     "disabled",   \
287     "root",       \
288     "designated", \
289     "alternate",  \
290     "backup"
291 
292 #define PV2ID(pv, epri, eaddr)	do { \
293 	epri     = pv >> 48;         \
294 	eaddr[0] = pv >> 40;         \
295 	eaddr[1] = pv >> 32;         \
296 	eaddr[2] = pv >> 24;         \
297 	eaddr[3] = pv >> 16;         \
298 	eaddr[4] = pv >> 8;          \
299 	eaddr[5] = pv >> 0;          \
300 } while (0)
301 
302 #ifdef _KERNEL
303 
304 #define BRIDGE_INPUT(_ifp, _m)		do {			\
305 		KASSERT((_ifp)->if_bridge_input != NULL,		\
306 	    ("%s: if_bridge not loaded!", __func__));	\
307 	_m = (*(_ifp)->if_bridge_input)(_ifp, _m);			\
308 	if (_m != NULL)					\
309 		_ifp = _m->m_pkthdr.rcvif;		\
310 } while (0)
311 
312 #define BRIDGE_OUTPUT(_ifp, _m, _err)	do {    		\
313 	KASSERT((_ifp)->if_bridge_output != NULL,		\
314 	    ("%s: if_bridge not loaded!", __func__));		\
315 	_err = (*(_ifp)->if_bridge_output)(_ifp, _m, NULL, NULL);	\
316 } while (0)
317 
318 extern	void (*bridge_dn_p)(struct mbuf *, struct ifnet *);
319 
320 #endif /* _KERNEL */
321