| 1 | /*	$OpenBSD: if_bridge.h,v 1.77 2025/11/21 04:44:26 dlg Exp $	*/ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) |
| 5 | * Copyright (c) 2006 Andrew Thompson (thompsa@FreeBSD.org) |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 26 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | * POSSIBILITY OF SUCH DAMAGE. |
| 28 | * |
| 29 | * Effort sponsored in part by the Defense Advanced Research Projects |
| 30 | * Agency (DARPA) and Air Force Research Laboratory, Air Force |
| 31 | * Materiel Command, USAF, under agreement number F30602-01-2-0537. |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | #ifndef _NET_IF_BRIDGE_H_ |
| 36 | #define _NET_IF_BRIDGE_H_ |
| 37 | |
| 38 | #include <sys/smr.h> |
| 39 | #include <sys/timeout.h> |
| 40 | #include <net/pfvar.h> |
| 41 | |
| 42 | #define IFBR_PVID_NULL		EVL_VLID_NULL |
| 43 | #define IFBR_PVID_MIN		EVL_VLID_MIN |
| 44 | #define IFBR_PVID_MAX		EVL_VLID_MAX |
| 45 | #define IFBR_PVID_NONE		0xffff |
| 46 | #define IFBR_PVID_DECLINE	0xfffe |
| 47 | |
| 48 | /* |
| 49 | * Bridge control request: add/delete member interfaces. |
| 50 | */ |
| 51 | struct ifbreq { |
| 52 | 	char		ifbr_name[IFNAMSIZ];	/* bridge ifs name */ |
| 53 | 	char		ifbr_ifsname[IFNAMSIZ];	/* member ifs name */ |
| 54 | 	u_int32_t	ifbr_ifsflags;		/* member ifs flags */ |
| 55 | 	u_int32_t	ifbr_portno;		/* member port number */ |
| 56 | 	u_int32_t	ifbr_protected;		/* protected domains */ |
| 57 | |
| 58 | 	u_int8_t	ifbr_state;		/* member stp state */ |
| 59 | 	u_int8_t	ifbr_priority;		/* member stp priority */ |
| 60 | 	u_int16_t	ifbr_pvid;		/* member port vlan id */ |
| 61 | 	u_int32_t	ifbr_path_cost;		/* member stp path cost */ |
| 62 | 	u_int32_t	ifbr_stpflags; /* member stp flags */ |
| 63 | 	u_int8_t	ifbr_proto;		/* member stp protocol */ |
| 64 | 	u_int8_t	ifbr_role;		/* member stp role */ |
| 65 | 	u_int32_t	ifbr_fwd_trans;		/* member stp fwd transitions */ |
| 66 | 	u_int64_t	ifbr_desg_bridge;	/* member stp designated bridge */ |
| 67 | 	u_int32_t	ifbr_desg_port;		/* member stp designated port */ |
| 68 | 	u_int64_t	ifbr_root_bridge;	/* member stp root bridge */ |
| 69 | 	u_int32_t	ifbr_root_cost;		/* member stp root cost */ |
| 70 | 	u_int32_t	ifbr_root_port;		/* member stp root port */ |
| 71 | }; |
| 72 | |
| 73 | /* SIOCBRDGIFFLGS, SIOCBRDGIFFLGS */ |
| 74 | #define	IFBIF_LEARNING		0x0001	/* ifs can learn */ |
| 75 | #define	IFBIF_DISCOVER		0x0002	/* ifs sends packets w/unknown dest */ |
| 76 | #define	IFBIF_BLOCKNONIP	0x0004	/* ifs blocks non-IP/ARP in/out */ |
| 77 | #define	IFBIF_STP		0x0008	/* ifs participates in spanning tree */ |
| 78 | #define IFBIF_BSTP_EDGE		0x0010	/* member stp edge port */ |
| 79 | #define IFBIF_BSTP_AUTOEDGE	0x0020 /* member stp autoedge enabled */ |
| 80 | #define IFBIF_BSTP_PTP		0x0040 /* member stp ptp */ |
| 81 | #define IFBIF_BSTP_AUTOPTP	0x0080	/* member stp autoptp enabled */ |
| 82 | #define	IFBIF_SPAN		0x0100	/* ifs is a span port (ro) */ |
| 83 | #define	IFBIF_LOCAL		0x1000	/* local port in switch(4) */ |
| 84 | #define	IFBIF_LOCKED		0x2000	/* restrict rx src mac with fib */ |
| 85 | #define	IFBIF_PVLAN_PTAGS	0x4000	/* only use tags for primary pvlans */ |
| 86 | #define	IFBIF_RO_MASK		0x0f00	/* read only bits */ |
| 87 | |
| 88 | /* SIOCBRDGFLUSH */ |
| 89 | #define	IFBF_FLUSHDYN	0x0	/* flush dynamic addresses only */ |
| 90 | #define	IFBF_FLUSHALL	0x1	/* flush all addresses from cache */ |
| 91 | |
| 92 | /* port states */ |
| 93 | #define	BSTP_IFSTATE_DISABLED	0 |
| 94 | #define	BSTP_IFSTATE_LISTENING	1 |
| 95 | #define	BSTP_IFSTATE_LEARNING	2 |
| 96 | #define	BSTP_IFSTATE_FORWARDING	3 |
| 97 | #define	BSTP_IFSTATE_BLOCKING	4 |
| 98 | #define	BSTP_IFSTATE_DISCARDING	5 |
| 99 | |
| 100 | #define	BSTP_TCSTATE_ACTIVE	1 |
| 101 | #define	BSTP_TCSTATE_DETECTED	2 |
| 102 | #define	BSTP_TCSTATE_INACTIVE	3 |
| 103 | #define	BSTP_TCSTATE_LEARNING	4 |
| 104 | #define	BSTP_TCSTATE_PROPAG	5 |
| 105 | #define	BSTP_TCSTATE_ACK	6 |
| 106 | #define	BSTP_TCSTATE_TC		7 |
| 107 | #define	BSTP_TCSTATE_TCN	8 |
| 108 | |
| 109 | #define	BSTP_ROLE_DISABLED	0 |
| 110 | #define	BSTP_ROLE_ROOT		1 |
| 111 | #define	BSTP_ROLE_DESIGNATED	2 |
| 112 | #define	BSTP_ROLE_ALTERNATE	3 |
| 113 | #define	BSTP_ROLE_BACKUP	4 |
| 114 | |
| 115 | /* |
| 116 | * Interface list structure |
| 117 | */ |
| 118 | struct ifbifconf { |
| 119 | 	char		ifbic_name[IFNAMSIZ];	/* bridge ifs name */ |
| 120 | 	u_int32_t	ifbic_len;		/* buffer size */ |
| 121 | 	union { |
| 122 | 		caddr_t	ifbicu_buf; |
| 123 | 		struct	ifbreq *ifbicu_req; |
| 124 | 	} ifbic_ifbicu; |
| 125 | #define	ifbic_buf	ifbic_ifbicu.ifbicu_buf |
| 126 | #define	ifbic_req	ifbic_ifbicu.ifbicu_req |
| 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * Bridge address request |
| 131 | */ |
| 132 | struct ifbareq { |
| 133 | 	char			ifba_name[IFNAMSIZ];	/* bridge name */ |
| 134 | 	char			ifba_ifsname[IFNAMSIZ];	/* destination ifs */ |
| 135 | 	u_int8_t		ifba_age;		/* address age */ |
| 136 | 	u_int8_t		ifba_flags;		/* address flags */ |
| 137 | 	struct ether_addr	ifba_dst;		/* destination addr */ |
| 138 | 	struct sockaddr_storage	ifba_dstsa;		/* tunnel endpoint */ |
| 139 | }; |
| 140 | |
| 141 | #define	IFBAF_TYPEMASK		0x03		/* address type mask */ |
| 142 | #define	IFBAF_DYNAMIC		0x00		/* dynamically learned */ |
| 143 | #define	IFBAF_STATIC		0x01		/* static address */ |
| 144 | |
| 145 | struct ifbvareq; |
| 146 | |
| 147 | struct ifbaconf { |
| 148 | 	char			ifbac_name[IFNAMSIZ];	/* bridge ifs name */ |
| 149 | 	u_int32_t		ifbac_len;		/* buffer size */ |
| 150 | 	union { |
| 151 | 		caddr_t	ifbacu_buf;			/* buffer */ |
| 152 | 		struct ifbareq *ifbacu_req;		/* request pointer */ |
| 153 | 		struct ifbvareq *ifbacu_vreq;		/* request pointer */ |
| 154 | 	} ifbac_ifbacu; |
| 155 | #define	ifbac_buf	ifbac_ifbacu.ifbacu_buf |
| 156 | #define	ifbac_req	ifbac_ifbacu.ifbacu_req |
| 157 | #define	ifbac_vreq	ifbac_ifbacu.ifbacu_vreq |
| 158 | }; |
| 159 | |
| 160 | struct ifbrparam { |
| 161 | 	char			ifbrp_name[IFNAMSIZ]; |
| 162 | 	union { |
| 163 | 		u_int32_t	ifbrpu_csize;		/* cache size */ |
| 164 | 		int		ifbrpu_ctime;		/* cache time (sec) */ |
| 165 | 		u_int16_t	ifbrpu_prio;		/* bridge priority */ |
| 166 | 		u_int8_t	ifbrpu_hellotime;	/* hello time (sec) */ |
| 167 | 		u_int8_t	ifbrpu_fwddelay;	/* fwd delay (sec) */ |
| 168 | 		u_int8_t	ifbrpu_maxage;		/* max age (sec) */ |
| 169 | 		u_int8_t	ifbrpu_proto;		/* bridge protocol */ |
| 170 | 		u_int8_t	ifbrpu_txhc;		/* bpdu tx holdcount */ |
| 171 | 	} ifbrp_ifbrpu; |
| 172 | }; |
| 173 | #define	ifbrp_csize	ifbrp_ifbrpu.ifbrpu_csize |
| 174 | #define	ifbrp_ctime	ifbrp_ifbrpu.ifbrpu_ctime |
| 175 | #define	ifbrp_prio	ifbrp_ifbrpu.ifbrpu_prio |
| 176 | #define	ifbrp_proto	ifbrp_ifbrpu.ifbrpu_proto |
| 177 | #define	ifbrp_txhc	ifbrp_ifbrpu.ifbrpu_txhc |
| 178 | #define	ifbrp_hellotime	ifbrp_ifbrpu.ifbrpu_hellotime |
| 179 | #define	ifbrp_fwddelay	ifbrp_ifbrpu.ifbrpu_fwddelay |
| 180 | #define	ifbrp_maxage	ifbrp_ifbrpu.ifbrpu_maxage |
| 181 | |
| 182 | /* Protocol versions */ |
| 183 | #define	BSTP_PROTO_ID		0x00 |
| 184 | #define	BSTP_PROTO_STP		0x00 |
| 185 | #define	BSTP_PROTO_RSTP		0x02 |
| 186 | #define	BSTP_PROTO_MAX		BSTP_PROTO_RSTP |
| 187 | |
| 188 | /* |
| 189 | * Bridge current operational parameters structure. |
| 190 | */ |
| 191 | struct ifbropreq { |
| 192 | 	char		ifbop_name[IFNAMSIZ]; |
| 193 | 	u_int8_t	ifbop_holdcount; |
| 194 | 	u_int8_t	ifbop_maxage; |
| 195 | 	u_int8_t	ifbop_hellotime; |
| 196 | 	u_int8_t	ifbop_fwddelay; |
| 197 | 	u_int8_t	ifbop_protocol; |
| 198 | 	u_int16_t	ifbop_priority; |
| 199 | 	u_int64_t	ifbop_root_bridge; |
| 200 | 	u_int16_t	ifbop_root_port; |
| 201 | 	u_int32_t	ifbop_root_path_cost; |
| 202 | 	u_int64_t	ifbop_desg_bridge; |
| 203 | 	struct timeval	ifbop_last_tc_time; |
| 204 | }; |
| 205 | |
| 206 | /* |
| 207 | * Bridge mac rules |
| 208 | */ |
| 209 | struct ifbrarpf { |
| 210 | 	u_int16_t		brla_flags; |
| 211 | 	u_int16_t		brla_op; |
| 212 | 	struct ether_addr	brla_sha; |
| 213 | 	struct in_addr		brla_spa; |
| 214 | 	struct ether_addr	brla_tha; |
| 215 | 	struct in_addr		brla_tpa; |
| 216 | }; |
| 217 | #define	BRLA_ARP	0x01 |
| 218 | #define	BRLA_RARP	0x02 |
| 219 | #define	BRLA_SHA	0x10 |
| 220 | #define	BRLA_SPA	0x20 |
| 221 | #define	BRLA_THA	0x40 |
| 222 | #define	BRLA_TPA	0x80 |
| 223 | |
| 224 | struct ifbrlreq { |
| 225 | 	char			ifbr_name[IFNAMSIZ];	/* bridge ifs name */ |
| 226 | 	char			ifbr_ifsname[IFNAMSIZ];	/* member ifs name */ |
| 227 | 	u_int8_t		ifbr_action;		/* disposition */ |
| 228 | 	u_int8_t		ifbr_flags;		/* flags */ |
| 229 | 	struct ether_addr	ifbr_src;		/* source mac */ |
| 230 | 	struct ether_addr	ifbr_dst;		/* destination mac */ |
| 231 | 	char			ifbr_tagname[PF_TAG_NAME_SIZE];	/* pf tagname */ |
| 232 | 	struct ifbrarpf		ifbr_arpf;		/* arp filter */ |
| 233 | }; |
| 234 | #define	BRL_ACTION_BLOCK	0x01			/* block frame */ |
| 235 | #define	BRL_ACTION_PASS		0x02			/* pass frame */ |
| 236 | #define	BRL_FLAG_IN		0x08			/* input rule */ |
| 237 | #define	BRL_FLAG_OUT		0x04			/* output rule */ |
| 238 | #define	BRL_FLAG_SRCVALID	0x02			/* src valid */ |
| 239 | #define	BRL_FLAG_DSTVALID	0x01			/* dst valid */ |
| 240 | |
| 241 | struct ifbrlconf { |
| 242 | 	char		ifbrl_name[IFNAMSIZ];	/* bridge ifs name */ |
| 243 | 	char		ifbrl_ifsname[IFNAMSIZ];/* member ifs name */ |
| 244 | 	u_int32_t	ifbrl_len;		/* buffer size */ |
| 245 | 	union { |
| 246 | 		caddr_t	ifbrlu_buf; |
| 247 | 		struct	ifbrlreq *ifbrlu_req; |
| 248 | 	} ifbrl_ifbrlu; |
| 249 | #define	ifbrl_buf	ifbrl_ifbrlu.ifbrlu_buf |
| 250 | #define	ifbrl_req	ifbrl_ifbrlu.ifbrlu_req |
| 251 | }; |
| 252 | |
| 253 | struct ifbvareq { |
| 254 | 	char			ifbva_name[IFNAMSIZ];	/* bridge name */ |
| 255 | 	char			ifbva_ifsname[IFNAMSIZ];	/* destination ifs */ |
| 256 | 	time_t			ifbva_created;		/* monotime */ |
| 257 | 	time_t			ifbva_used;		/* monotime */ |
| 258 | 	unsigned int		ifbva_flags;		/* address flags */ |
| 259 | 	uint16_t		ifbva_vid;		/* vlan */ |
| 260 | 	struct ether_addr	ifbva_dst;		/* destination addr */ |
| 261 | 	struct sockaddr_storage	ifbva_dstsa;		/* tunnel endpoint */ |
| 262 | }; |
| 263 | |
| 264 | struct ifbrvidmap { |
| 265 | 	char			ifbrvm_name[IFNAMSIZ]; |
| 266 | 	char			ifbrvm_ifsname[IFNAMSIZ]; |
| 267 | 	unsigned int		ifbrvm_op; |
| 268 | #define IFBRVM_OP_SET			0x0	/* kernel = ifbrvm_map */ |
| 269 | #define IFBRVM_OP_OR			0x1	/* kernel |= ifbrvm_map */ |
| 270 | #define IFBRVM_OP_ANDNOT		0x2	/* kernel &= ~ifbrvm_map */ |
| 271 | 	unsigned int		ifbrvm_gen; |
| 272 | 	uint8_t			ifbrvm_map[512]; |
| 273 | }; |
| 274 | |
| 275 | struct ifbrpvlan { |
| 276 | 	char			ifbrpv_name[IFNAMSIZ]; |
| 277 | 	uint16_t		ifbrpv_primary; |
| 278 | 	uint16_t		ifbrpv_secondary; |
| 279 | 	unsigned int		ifbrpv_type; |
| 280 | #define IFBRPV_T_PRIMARY		0 |
| 281 | #define IFBRPV_T_SECONDARY		1	/* for searching */ |
| 282 | #define IFBRPV_T_ISOLATED		2 |
| 283 | #define IFBRPV_T_COMMUNITY		3 |
| 284 | 	unsigned int		ifbrpv_gen; |
| 285 | }; |
| 286 | |
| 287 | #ifdef _KERNEL |
| 288 | |
| 289 | #include <sys/mutex.h> |
| 290 | |
| 291 | /* STP port flags */ |
| 292 | #define	BSTP_PORT_CANMIGRATE	0x0001 |
| 293 | #define	BSTP_PORT_NEWINFO	0x0002 |
| 294 | #define	BSTP_PORT_DISPUTED	0x0004 |
| 295 | #define	BSTP_PORT_ADMCOST	0x0008 |
| 296 | #define	BSTP_PORT_AUTOEDGE	0x0010 |
| 297 | #define	BSTP_PORT_AUTOPTP	0x0020 |
| 298 | |
| 299 | /* BPDU priority */ |
| 300 | #define	BSTP_PDU_SUPERIOR	1 |
| 301 | #define	BSTP_PDU_REPEATED	2 |
| 302 | #define	BSTP_PDU_INFERIOR	3 |
| 303 | #define	BSTP_PDU_INFERIORALT	4 |
| 304 | #define	BSTP_PDU_OTHER		5 |
| 305 | |
| 306 | /* BPDU flags */ |
| 307 | #define	BSTP_PDU_PRMASK		0x0c		/* Port Role */ |
| 308 | #define	BSTP_PDU_PRSHIFT	2		/* Port Role offset */ |
| 309 | #define	BSTP_PDU_F_UNKN		0x00		/* Unknown port (00) */ |
| 310 | #define	BSTP_PDU_F_ALT		0x01		/* Alt/Backup port (01) */ |
| 311 | #define	BSTP_PDU_F_ROOT		0x02		/* Root port (10) */ |
| 312 | #define	BSTP_PDU_F_DESG		0x03		/* Designated port (11) */ |
| 313 | |
| 314 | #define	BSTP_PDU_STPMASK	0x81		/* strip unused STP flags */ |
| 315 | #define	BSTP_PDU_RSTPMASK	0x7f		/* strip unused RSTP flags */ |
| 316 | #define	BSTP_PDU_F_TC		0x01		/* Topology change */ |
| 317 | #define	BSTP_PDU_F_P		0x02		/* Proposal flag */ |
| 318 | #define	BSTP_PDU_F_L		0x10		/* Learning flag */ |
| 319 | #define	BSTP_PDU_F_F		0x20		/* Forwarding flag */ |
| 320 | #define	BSTP_PDU_F_A		0x40		/* Agreement flag */ |
| 321 | #define	BSTP_PDU_F_TCA		0x80		/* Topology change ack */ |
| 322 | |
| 323 | /* |
| 324 | * Bridge filtering rules |
| 325 | */ |
| 326 | SIMPLEQ_HEAD(brl_head, brl_node); |
| 327 | |
| 328 | struct brl_node { |
| 329 | 	SIMPLEQ_ENTRY(brl_node)	brl_next;	/* next rule */ |
| 330 | 	struct ether_addr	brl_src;	/* source mac address */ |
| 331 | 	struct ether_addr	brl_dst;	/* destination mac address */ |
| 332 | 	u_int16_t		brl_tag;	/* pf tag ID */ |
| 333 | 	u_int8_t		brl_action;	/* what to do with match */ |
| 334 | 	u_int8_t		brl_flags;	/* comparison flags */ |
| 335 | 	struct ifbrarpf		brl_arpf;	/* arp filter */ |
| 336 | }; |
| 337 | |
| 338 | struct bstp_timer { |
| 339 | 	u_int16_t	active; |
| 340 | 	u_int16_t	value; |
| 341 | 	u_int32_t	latched; |
| 342 | }; |
| 343 | |
| 344 | struct bstp_pri_vector { |
| 345 | 	u_int64_t	pv_root_id; |
| 346 | 	u_int32_t	pv_cost; |
| 347 | 	u_int64_t	pv_dbridge_id; |
| 348 | 	u_int16_t	pv_dport_id; |
| 349 | 	u_int16_t	pv_port_id; |
| 350 | }; |
| 351 | |
| 352 | struct bstp_config_unit { |
| 353 | 	struct bstp_pri_vector	cu_pv; |
| 354 | 	u_int16_t	cu_message_age; |
| 355 | 	u_int16_t	cu_max_age; |
| 356 | 	u_int16_t	cu_forward_delay; |
| 357 | 	u_int16_t	cu_hello_time; |
| 358 | 	u_int8_t	cu_message_type; |
| 359 | 	u_int8_t	cu_topology_change_ack; |
| 360 | 	u_int8_t	cu_topology_change; |
| 361 | 	u_int8_t	cu_proposal; |
| 362 | 	u_int8_t	cu_agree; |
| 363 | 	u_int8_t	cu_learning; |
| 364 | 	u_int8_t	cu_forwarding; |
| 365 | 	u_int8_t	cu_role; |
| 366 | }; |
| 367 | |
| 368 | struct bstp_tcn_unit { |
| 369 | 	u_int8_t	tu_message_type; |
| 370 | }; |
| 371 | |
| 372 | struct bstp_port { |
| 373 | 	LIST_ENTRY(bstp_port)	bp_next; |
| 374 | 	unsigned int		bp_ifindex;	/* parent interface index */ |
| 375 | 	struct bstp_state	*bp_bs; |
| 376 | 	struct task		bp_ltask;	/* if linkstate hook */ |
| 377 | 	u_int8_t		bp_active; |
| 378 | 	u_int8_t		bp_protover; |
| 379 | 	u_int32_t		bp_flags; |
| 380 | 	u_int32_t		bp_path_cost; |
| 381 | 	u_int16_t		bp_port_msg_age; |
| 382 | 	u_int16_t		bp_port_max_age; |
| 383 | 	u_int16_t		bp_port_fdelay; |
| 384 | 	u_int16_t		bp_port_htime; |
| 385 | 	u_int16_t		bp_desg_msg_age; |
| 386 | 	u_int16_t		bp_desg_max_age; |
| 387 | 	u_int16_t		bp_desg_fdelay; |
| 388 | 	u_int16_t		bp_desg_htime; |
| 389 | 	struct bstp_timer	bp_edge_delay_timer; |
| 390 | 	struct bstp_timer	bp_forward_delay_timer; |
| 391 | 	struct bstp_timer	bp_hello_timer; |
| 392 | 	struct bstp_timer	bp_message_age_timer; |
| 393 | 	struct bstp_timer	bp_migrate_delay_timer; |
| 394 | 	struct bstp_timer	bp_recent_backup_timer; |
| 395 | 	struct bstp_timer	bp_recent_root_timer; |
| 396 | 	struct bstp_timer	bp_tc_timer; |
| 397 | 	struct bstp_config_unit bp_msg_cu; |
| 398 | 	struct bstp_pri_vector	bp_desg_pv; |
| 399 | 	struct bstp_pri_vector	bp_port_pv; |
| 400 | 	u_int16_t		bp_port_id; |
| 401 | 	u_int8_t		bp_state; |
| 402 | 	u_int8_t		bp_tcstate; |
| 403 | 	u_int8_t		bp_role; |
| 404 | 	u_int8_t		bp_infois; |
| 405 | 	u_int8_t		bp_tc_ack; |
| 406 | 	u_int8_t		bp_tc_prop; |
| 407 | 	u_int8_t		bp_fdbflush; |
| 408 | 	u_int8_t		bp_priority; |
| 409 | 	u_int8_t		bp_ptp_link; |
| 410 | 	u_int8_t		bp_agree; |
| 411 | 	u_int8_t		bp_agreed; |
| 412 | 	u_int8_t		bp_sync; |
| 413 | 	u_int8_t		bp_synced; |
| 414 | 	u_int8_t		bp_proposing; |
| 415 | 	u_int8_t		bp_proposed; |
| 416 | 	u_int8_t		bp_operedge; |
| 417 | 	u_int8_t		bp_reroot; |
| 418 | 	u_int8_t		bp_rcvdtc; |
| 419 | 	u_int8_t		bp_rcvdtca; |
| 420 | 	u_int8_t		bp_rcvdtcn; |
| 421 | 	u_int32_t		bp_forward_transitions; |
| 422 | 	u_int8_t		bp_txcount; |
| 423 | }; |
| 424 | |
| 425 | /* |
| 426 | * Software state for each bridge STP. |
| 427 | */ |
| 428 | struct bstp_state { |
| 429 | 	unsigned int		bs_ifindex; |
| 430 | 	struct bstp_pri_vector	bs_bridge_pv; |
| 431 | 	struct bstp_pri_vector	bs_root_pv; |
| 432 | 	struct bstp_port	*bs_root_port; |
| 433 | 	u_int8_t		bs_protover; |
| 434 | 	u_int16_t		bs_migration_delay; |
| 435 | 	u_int16_t		bs_edge_delay; |
| 436 | 	u_int16_t		bs_bridge_max_age; |
| 437 | 	u_int16_t		bs_bridge_fdelay; |
| 438 | 	u_int16_t		bs_bridge_htime; |
| 439 | 	u_int16_t		bs_root_msg_age; |
| 440 | 	u_int16_t		bs_root_max_age; |
| 441 | 	u_int16_t		bs_root_fdelay; |
| 442 | 	u_int16_t		bs_root_htime; |
| 443 | 	u_int16_t		bs_hold_time; |
| 444 | 	u_int16_t		bs_bridge_priority; |
| 445 | 	u_int8_t		bs_txholdcount; |
| 446 | 	u_int8_t		bs_allsynced; |
| 447 | 	struct timeout		bs_bstptimeout;		/* stp timeout */ |
| 448 | 	struct bstp_timer	bs_link_timer; |
| 449 | 	struct timeval		bs_last_tc_time; |
| 450 | 	LIST_HEAD(, bstp_port)	bs_bplist; |
| 451 | }; |
| 452 | |
| 453 | /* |
| 454 | * Bridge interface list |
| 455 | * |
| 456 | * Locks used to protect struct members in this file: |
| 457 | *	I	immutable after creation |
| 458 | *	k	kernel lock |
| 459 | */ |
| 460 | struct bridge_iflist { |
| 461 | 	SMR_SLIST_ENTRY(bridge_iflist)	bif_next;	/* [k] next in list */ |
| 462 | 	struct bridge_softc		*bridge_sc;	/* [I] sc backpointer */ |
| 463 | 	struct bstp_port		*bif_stp;	/* [I] STP port state */ |
| 464 | 	struct brl_head			bif_brlin;	/* [k] input rules */ |
| 465 | 	struct brl_head			bif_brlout;	/* [k] output rules */ |
| 466 | 	struct ifnet			*ifp;		/* [I] net interface */ |
| 467 | 	u_int32_t			bif_flags;	/* member flags */ |
| 468 | 	u_int32_t			bif_protected;	/* protected domains */ |
| 469 | 	struct task			bif_dtask; |
| 470 | }; |
| 471 | #define bif_state			bif_stp->bp_state |
| 472 | |
| 473 | /* |
| 474 | * XXX ip_ipsp.h's sockaddr_union should be converted to sockaddr * |
| 475 | * passing with correct sa_len, then a good approach for cleaning this |
| 476 | * will become more clear. |
| 477 | */ |
| 478 | union brsockaddr_union { |
| 479 | 	struct sockaddr		sa; |
| 480 | 	struct sockaddr_in	sin; |
| 481 | 	struct sockaddr_in6	sin6; |
| 482 | }; |
| 483 | |
| 484 | /* |
| 485 | * Bridge tunnel tagging |
| 486 | */ |
| 487 | struct bridge_tunneltag { |
| 488 | 	union brsockaddr_union		brtag_peer; |
| 489 | 	union brsockaddr_union		brtag_local; |
| 490 | 	u_int32_t			brtag_id; |
| 491 | }; |
| 492 | |
| 493 | /* |
| 494 | * Bridge route node |
| 495 | */ |
| 496 | struct bridge_rtnode { |
| 497 | 	LIST_ENTRY(bridge_rtnode)	brt_next;	/* next in list */ |
| 498 | 	unsigned int			brt_ifidx;	/* destination ifs */ |
| 499 | 	u_int8_t			brt_flags;	/* address flags */ |
| 500 | 	u_int8_t			brt_age;	/* age counter */ |
| 501 | 	struct ether_addr		brt_addr;	/* dst addr */ |
| 502 | 	struct bridge_tunneltag		brt_tunnel;	/* tunnel endpoint */ |
| 503 | }; |
| 504 | #define brt_family brt_tunnel.brtag_peer.sa.sa_family |
| 505 | |
| 506 | #ifndef BRIDGE_RTABLE_SIZE |
| 507 | #define BRIDGE_RTABLE_SIZE	1024 |
| 508 | #endif |
| 509 | #define BRIDGE_RTABLE_MASK	(BRIDGE_RTABLE_SIZE - 1) |
| 510 | |
| 511 | /* |
| 512 | * Software state for each bridge |
| 513 | * |
| 514 | * Locks used to protect struct members in this file: |
| 515 | *	I	immutable after creation |
| 516 | *	m	per-softc mutex |
| 517 | *	k	kernel lock |
| 518 | */ |
| 519 | struct bridge_softc { |
| 520 | 	struct ifnet			sc_if;	/* the interface */ |
| 521 | 	uint32_t			sc_brtmax;	/* [m] max # addresses */ |
| 522 | 	uint32_t			sc_brtcnt;	/* [m] current # addrs */ |
| 523 | 	int				sc_brttimeout;	/* timeout ticks */ |
| 524 | 	uint64_t			sc_hashkey[2];	/* [I] siphash key */ |
| 525 | 	struct timeout			sc_brtimeout;	/* timeout state */ |
| 526 | 	struct bstp_state		*sc_stp;	/* stp state */ |
| 527 | 	SMR_SLIST_HEAD(, bridge_iflist)	sc_iflist;	/* [k] interface list */ |
| 528 | 	SMR_SLIST_HEAD(, bridge_iflist)	sc_spanlist;	/* [k] span ports */ |
| 529 | 	struct mutex			sc_mtx;		/* mutex */ |
| 530 | 	LIST_HEAD(, bridge_rtnode)	sc_rts[BRIDGE_RTABLE_SIZE];	/* [m] hash table */ |
| 531 | }; |
| 532 | |
| 533 | extern const u_int8_t bstp_etheraddr[]; |
| 534 | struct llc; |
| 535 | |
| 536 | int	bridge_enqueue(struct ifnet *, struct mbuf *); |
| 537 | void	bridge_update(struct ifnet *, struct ether_addr *, int); |
| 538 | void	bridge_rtdelete(struct bridge_softc *, struct ifnet *, int); |
| 539 | void	bridge_rtagenode(struct ifnet *, int); |
| 540 | struct bridge_tunneltag *bridge_tunnel(struct mbuf *); |
| 541 | struct bridge_tunneltag *bridge_tunneltag(struct mbuf *); |
| 542 | void	bridge_tunneluntag(struct mbuf *); |
| 543 | void	bridge_copyaddr(struct sockaddr *, struct sockaddr *); |
| 544 | void	bridge_copytag(struct bridge_tunneltag *, struct bridge_tunneltag *); |
| 545 | |
| 546 | struct bstp_state *bstp_create(void); |
| 547 | void	bstp_enable(struct bstp_state *bs, unsigned int); |
| 548 | void	bstp_disable(struct bstp_state *bs); |
| 549 | void	bstp_destroy(struct bstp_state *); |
| 550 | void	bstp_initialization(struct bstp_state *); |
| 551 | void	bstp_stop(struct bstp_state *); |
| 552 | int	bstp_ioctl(struct ifnet *, u_long, caddr_t); |
| 553 | struct bstp_port *bstp_add(struct bstp_state *, struct ifnet *); |
| 554 | void	bstp_delete(struct bstp_port *); |
| 555 | struct mbuf *bstp_input(struct bstp_state *, struct bstp_port *, |
| 556 | struct ether_header *, struct mbuf *); |
| 557 | void	bstp_ifstate(void *); |
| 558 | u_int8_t bstp_getstate(struct bstp_state *, struct bstp_port *); |
| 559 | void	bstp_ifsflags(struct bstp_port *, u_int); |
| 560 | |
| 561 | int	bridgectl_ioctl(struct ifnet *, u_long, caddr_t); |
| 562 | int	bridge_rtupdate(struct bridge_softc *, |
| 563 | struct ether_addr *, struct ifnet *, int, u_int8_t, struct mbuf *); |
| 564 | unsigned int bridge_rtlookup(struct ifnet *, |
| 565 | struct ether_addr *, struct mbuf *); |
| 566 | void	bridge_rtflush(struct bridge_softc *, int); |
| 567 | void	bridge_rtage(void *); |
| 568 | |
| 569 | u_int8_t bridge_filterrule(struct brl_head *, struct ether_header *, |
| 570 | struct mbuf *); |
| 571 | void	bridge_flushrule(struct bridge_iflist *); |
| 572 | |
| 573 | void	bridge_fragment(struct ifnet *, struct ifnet *, struct ether_header *, |
| 574 | struct mbuf *); |
| 575 | struct bridge_iflist *bridge_getbif(struct ifnet *); |
| 576 | int	bridge_findbif(struct bridge_softc *, const char *, |
| 577 | struct bridge_iflist **); |
| 578 | |
| 579 | #endif /* _KERNEL */ |
| 580 | #endif /* _NET_IF_BRIDGE_H_ */ |