xref: /openbsd-src/sys/net/if_bridge.h (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: if_bridge.h,v 1.15 2001/06/09 06:16:37 angelos Exp $	*/
2 
3 /*
4  * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
5  * All rights reserved.
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 by Jason L. Wright
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _NET_IF_BRIDGE_H_
35 #define _NET_IF_BRIDGE_H_
36 
37 /*
38  * Bridge control request: add/delete member interfaces.
39  */
40 struct ifbreq {
41 	char		ifbr_name[IFNAMSIZ];	/* bridge ifs name */
42 	char		ifbr_ifsname[IFNAMSIZ];	/* member ifs name */
43 	u_int32_t	ifbr_ifsflags;		/* member ifs flags */
44 	u_int8_t	ifbr_state;		/* member stp state */
45 	u_int8_t	ifbr_priority;		/* member stp priority */
46 	u_int8_t	ifbr_portno;		/* member port number */
47 };
48 /* SIOCBRDGIFFLGS, SIOCBRDGIFFLGS */
49 #define	IFBIF_LEARNING		0x01	/* ifs can learn */
50 #define	IFBIF_DISCOVER		0x02	/* ifs sends packets w/unknown dest */
51 #define	IFBIF_BLOCKNONIP 	0x04	/* ifs blocks non-IP/ARP in/out */
52 #define	IFBIF_STP		0x08	/* ifs participates in spanning tree */
53 /* SIOCBRDGFLUSH */
54 #define	IFBF_FLUSHDYN	0x0	/* flush dynamic addresses only */
55 #define	IFBF_FLUSHALL	0x1	/* flush all addresses from cache */
56 
57 /* port states */
58 #define	BSTP_IFSTATE_DISABLED	0
59 #define	BSTP_IFSTATE_LISTENING	1
60 #define	BSTP_IFSTATE_LEARNING	2
61 #define	BSTP_IFSTATE_FORWARDING	3
62 #define	BSTP_IFSTATE_BLOCKING	4
63 
64 /*
65  * Interface list structure
66  */
67 struct ifbifconf {
68 	char		ifbic_name[IFNAMSIZ];	/* bridge ifs name */
69 	u_int32_t	ifbic_len;		/* buffer size */
70 	union {
71 		caddr_t	ifbicu_buf;
72 		struct	ifbreq *ifbicu_req;
73 	} ifbic_ifbicu;
74 #define	ifbic_buf	ifbic_ifbicu.ifbicu_buf
75 #define	ifbic_req	ifbic_ifbicu.ifbicu_req
76 };
77 
78 /*
79  * Bridge address request
80  */
81 struct ifbareq {
82 	char			ifba_name[IFNAMSIZ];	/* bridge name */
83 	char			ifba_ifsname[IFNAMSIZ];	/* destination ifs */
84 	u_int8_t		ifba_age;		/* address age */
85 	u_int8_t		ifba_flags;		/* address flags */
86 	struct ether_addr	ifba_dst;		/* destination addr */
87 };
88 
89 #define	IFBAF_TYPEMASK		0x03		/* address type mask */
90 #define	IFBAF_DYNAMIC		0x00		/* dynamically learned */
91 #define	IFBAF_STATIC		0x01		/* static address */
92 
93 struct ifbaconf {
94 	char			ifbac_name[IFNAMSIZ];	/* bridge ifs name */
95 	u_int32_t		ifbac_len;		/* buffer size */
96 	union {
97 		caddr_t	ifbacu_buf;			/* buffer */
98 		struct ifbareq *ifbacu_req;		/* request pointer */
99 	} ifbac_ifbacu;
100 #define	ifbac_buf	ifbac_ifbacu.ifbacu_buf
101 #define	ifbac_req	ifbac_ifbacu.ifbacu_req
102 };
103 
104 struct ifbrparam {
105 	char			ifbrp_name[IFNAMSIZ];
106 	union {
107 		u_int32_t	ifbrpu_csize;		/* cache size */
108 		u_int32_t	ifbrpu_ctime;		/* cache time (sec) */
109 		u_int16_t	ifbrpu_prio;		/* bridge priority */
110 		u_int8_t	ifbrpu_hellotime;	/* hello time (sec) */
111 		u_int8_t	ifbrpu_fwddelay;	/* fwd delay (sec) */
112 		u_int8_t	ifbrpu_maxage;		/* max age (sec) */
113 	} ifbrp_ifbrpu;
114 };
115 #define	ifbrp_csize	ifbrp_ifbrpu.ifbrpu_csize
116 #define	ifbrp_ctime	ifbrp_ifbrpu.ifbrpu_ctime
117 #define	ifbrp_prio	ifbrp_ifbrpu.ifbrpu_prio
118 #define	ifbrp_hellotime	ifbrp_ifbrpu.ifbrpu_hellotime
119 #define	ifbrp_fwddelay	ifbrp_ifbrpu.ifbrpu_fwddelay
120 #define	ifbrp_maxage	ifbrp_ifbrpu.ifbrpu_maxage
121 
122 /*
123  * Bridge mac rules
124  */
125 struct ifbrlreq {
126 	char			ifbr_name[IFNAMSIZ];	/* bridge ifs name */
127 	char			ifbr_ifsname[IFNAMSIZ];	/* member ifs name */
128 	u_int8_t		ifbr_action;		/* disposition */
129 	u_int8_t		ifbr_flags;		/* flags */
130 	struct ether_addr	ifbr_src;		/* source mac */
131 	struct ether_addr	ifbr_dst;		/* destination mac */
132 };
133 #define	BRL_ACTION_BLOCK	0x01			/* block frame */
134 #define	BRL_ACTION_PASS		0x02			/* pass frame */
135 #define	BRL_FLAG_IN		0x08			/* input rule */
136 #define	BRL_FLAG_OUT		0x04			/* output rule */
137 #define	BRL_FLAG_SRCVALID	0x02			/* src valid */
138 #define	BRL_FLAG_DSTVALID	0x01			/* dst valid */
139 
140 struct ifbrlconf {
141 	char		ifbrl_name[IFNAMSIZ];	/* bridge ifs name */
142 	char		ifbrl_ifsname[IFNAMSIZ];/* member ifs name */
143 	u_int32_t	ifbrl_len;		/* buffer size */
144 	union {
145 		caddr_t	ifbrlu_buf;
146 		struct	ifbrlreq *ifbrlu_req;
147 	} ifbrl_ifbrlu;
148 #define	ifbrl_buf	ifbrl_ifbrlu.ifbrlu_buf
149 #define	ifbrl_req	ifbrl_ifbrlu.ifbrlu_req
150 };
151 
152 #ifdef _KERNEL
153 /*
154  * Bridge filtering rules
155  */
156 SIMPLEQ_HEAD(brl_head, brl_node);
157 
158 struct brl_node {
159 	SIMPLEQ_ENTRY(brl_node)	brl_next;	/* next rule */
160 	struct ether_addr	brl_src;	/* source mac address */
161 	struct ether_addr	brl_dst;	/* destination mac address */
162 	u_int8_t		brl_action;	/* what to do with match */
163 	u_int8_t		brl_flags;	/* comparision flags */
164 };
165 
166 struct bridge_timer {
167 	u_int16_t active;
168 	u_int16_t value;
169 };
170 
171 struct bstp_config_unit {
172 	u_int64_t	cu_rootid;
173 	u_int64_t	cu_bridge_id;
174 	u_int32_t	cu_root_path_cost;
175 	u_int16_t	cu_message_age;
176 	u_int16_t	cu_max_age;
177 	u_int16_t	cu_hello_time;
178 	u_int16_t	cu_forward_delay;
179 	u_int16_t	cu_port_id;
180 	u_int8_t	cu_message_type;
181 	u_int8_t	cu_topology_change_acknowledgment;
182 	u_int8_t	cu_topology_change;
183 };
184 
185 struct bstp_tcn_unit {
186 	u_int8_t	tu_message_type;
187 };
188 
189 /*
190  * Bridge interface list
191  */
192 struct bridge_iflist {
193 	LIST_ENTRY(bridge_iflist)	next;		/* next in list */
194 	u_int64_t			bif_designated_root;
195 	u_int64_t			bif_designated_bridge;
196 	u_int32_t			bif_path_cost;
197 	u_int32_t			bif_designated_cost;
198 	struct bridge_timer		bif_hold_timer;
199 	struct bridge_timer		bif_message_age_timer;
200 	struct bridge_timer		bif_forward_delay_timer;
201 	struct bstp_config_unit		bif_config_bpdu;
202 	u_int16_t			bif_port_id;
203 	u_int16_t			bif_designated_port;
204 	u_int8_t			bif_state;
205 	u_int8_t			bif_topology_change_acknowledge;
206 	u_int8_t			bif_config_pending;
207 	u_int8_t			bif_change_detection_enabled;
208 	u_int8_t			bif_priority;
209 	struct brl_head			bif_brlin;	/* input rules */
210 	struct brl_head			bif_brlout;	/* output rules */
211 	struct				ifnet *ifp;	/* member interface */
212 	u_int32_t			bif_flags;	/* member flags */
213 };
214 
215 /*
216  * Bridge route node
217  */
218 struct bridge_rtnode {
219 	LIST_ENTRY(bridge_rtnode)	brt_next;	/* next in list */
220 	struct				ifnet *brt_if;	/* destination ifs */
221 	u_int8_t			brt_flags;	/* address flags */
222 	u_int8_t			brt_age;	/* age counter */
223 	struct				ether_addr brt_addr;	/* dst addr */
224 };
225 
226 /*
227  * Software state for each bridge
228  */
229 struct bridge_softc {
230 	struct				ifnet sc_if;	/* the interface */
231 	u_int64_t			sc_designated_root;
232 	u_int64_t			sc_bridge_id;
233 	struct bridge_iflist		*sc_root_port;
234 	u_int32_t			sc_root_path_cost;
235 	u_int16_t			sc_max_age;
236 	u_int16_t			sc_hello_time;
237 	u_int16_t			sc_forward_delay;
238 	u_int16_t			sc_bridge_max_age;
239 	u_int16_t			sc_bridge_hello_time;
240 	u_int16_t			sc_bridge_forward_delay;
241 	u_int16_t			sc_topology_change_time;
242 	u_int16_t			sc_hold_time;
243 	u_int16_t			sc_bridge_priority;
244 	u_int8_t			sc_topology_change_detected;
245 	u_int8_t			sc_topology_change;
246 	struct bridge_timer		sc_hello_timer;
247 	struct bridge_timer		sc_topology_change_timer;
248 	struct bridge_timer		sc_tcn_timer;
249 	u_int32_t			sc_brtmax;	/* max # addresses */
250 	u_int32_t			sc_brtcnt;	/* current # addrs */
251 	u_int32_t			sc_brttimeout;	/* timeout ticks */
252 	u_int32_t			sc_hashkey;	/* hash key */
253 	struct timeout			sc_brtimeout;	/* timeout state */
254 	struct timeout			sc_bstptimeout;	/* stp timeout */
255 	LIST_HEAD(, bridge_iflist)	sc_iflist;	/* interface list */
256 	LIST_HEAD(bridge_rthead, bridge_rtnode)	*sc_rts;/* hash table */
257 };
258 
259 extern u_int8_t bstp_etheraddr[];
260 
261 void	bridge_ifdetach __P((struct ifnet *));
262 struct mbuf *bridge_input __P((struct ifnet *, struct ether_header *,
263     struct mbuf *));
264 int	bridge_output __P((struct ifnet *, struct mbuf *, struct sockaddr *,
265     struct rtentry *rt));
266 struct mbuf *bstp_input __P((struct bridge_softc *, struct ifnet *,
267     struct ether_header *, struct mbuf *));
268 void	bstp_initialization __P((struct bridge_softc *));
269 int	bstp_ioctl __P((struct ifnet *, u_long, caddr_t));
270 #endif /* _KERNEL */
271 #endif /* _NET_IF_BRIDGE_H_ */
272