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 73 /* 74 * Data structure and control definitions for bridge interfaces. 75 */ 76 77 #ifndef _NET_IF_BRIDGEVAR_H_ 78 #define _NET_IF_BRIDGEVAR_H_ 79 80 #include <sys/types.h> 81 #include <sys/_bitset.h> 82 #include <sys/bitset.h> 83 #include <sys/callout.h> 84 #include <sys/queue.h> 85 #include <sys/condvar.h> 86 87 #include <net/ethernet.h> 88 #include <net/if.h> 89 90 /* 91 * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the 92 * bridge interface itself is keyed off the ifdrv structure. 93 */ 94 #define BRDGADD 0 /* add bridge member (ifbreq) */ 95 #define BRDGDEL 1 /* delete bridge member (ifbreq) */ 96 #define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */ 97 #define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */ 98 #define BRDGSCACHE 4 /* set cache size (ifbrparam) */ 99 #define BRDGGCACHE 5 /* get cache size (ifbrparam) */ 100 #define BRDGGIFS 6 /* get member list (ifbifconf) */ 101 #define BRDGRTS 7 /* get address list (ifbaconf) */ 102 #define BRDGSADDR 8 /* set static address (ifbareq) */ 103 #define BRDGSTO 9 /* set cache timeout (ifbrparam) */ 104 #define BRDGGTO 10 /* get cache timeout (ifbrparam) */ 105 #define BRDGDADDR 11 /* delete address (ifbareq) */ 106 #define BRDGFLUSH 12 /* flush address cache (ifbreq) */ 107 108 #define BRDGGPRI 13 /* get priority (ifbrparam) */ 109 #define BRDGSPRI 14 /* set priority (ifbrparam) */ 110 #define BRDGGHT 15 /* get hello time (ifbrparam) */ 111 #define BRDGSHT 16 /* set hello time (ifbrparam) */ 112 #define BRDGGFD 17 /* get forward delay (ifbrparam) */ 113 #define BRDGSFD 18 /* set forward delay (ifbrparam) */ 114 #define BRDGGMA 19 /* get max age (ifbrparam) */ 115 #define BRDGSMA 20 /* set max age (ifbrparam) */ 116 #define BRDGSIFPRIO 21 /* set if priority (ifbreq) */ 117 #define BRDGSIFCOST 22 /* set if path cost (ifbreq) */ 118 #define BRDGADDS 23 /* add bridge span member (ifbreq) */ 119 #define BRDGDELS 24 /* delete bridge span member (ifbreq) */ 120 #define BRDGPARAM 25 /* get bridge STP params (ifbropreq) */ 121 #define BRDGGRTE 26 /* get cache drops (ifbrparam) */ 122 #define BRDGGIFSSTP 27 /* get member STP params list 123 * (ifbpstpconf) */ 124 #define BRDGSPROTO 28 /* set protocol (ifbrparam) */ 125 #define BRDGSTXHC 29 /* set tx hold count (ifbrparam) */ 126 #define BRDGSIFAMAX 30 /* set max interface addrs (ifbreq) */ 127 #define BRDGSIFPVID 31 /* set if PVID */ 128 #define BRDGSIFVLANSET 32 /* set if vlan set */ 129 #define BRDGGIFVLANSET 33 /* get if vlan set */ 130 #define BRDGGFLAGS 34 /* get bridge flags (ifbrparam) */ 131 #define BRDGSFLAGS 35 /* set bridge flags (ifbrparam) */ 132 #define BRDGGDEFPVID 36 /* get default pvid (ifbrparam) */ 133 #define BRDGSDEFPVID 37 /* set default pvid (ifbrparam) */ 134 135 /* BRDGSFLAGS, Bridge flags (non-interface-specific) */ 136 typedef uint32_t ifbr_flags_t; 137 138 #define IFBRF_VLANFILTER (1U<<0) /* VLAN filtering enabled */ 139 140 #define IFBRFBITS "\020\01VLANFILTER" 141 142 /* 143 * Generic bridge control request. 144 */ 145 struct ifbreq { 146 char ifbr_ifsname[IFNAMSIZ]; /* member if name */ 147 uint32_t ifbr_ifsflags; /* member if flags */ 148 uint32_t ifbr_stpflags; /* member if STP flags */ 149 uint32_t ifbr_path_cost; /* member if STP cost */ 150 uint8_t ifbr_portno; /* member if port number */ 151 uint8_t ifbr_priority; /* member if STP priority */ 152 uint8_t ifbr_proto; /* member if STP protocol */ 153 uint8_t ifbr_role; /* member if STP role */ 154 uint8_t ifbr_state; /* member if STP state */ 155 uint32_t ifbr_addrcnt; /* member if addr number */ 156 uint32_t ifbr_addrmax; /* member if addr max */ 157 uint32_t ifbr_addrexceeded; /* member if addr violations */ 158 ether_vlanid_t ifbr_pvid; /* member if PVID */ 159 uint8_t pad[32]; 160 }; 161 162 /* BRDGGIFFLAGS, BRDGSIFFLAGS */ 163 #define IFBIF_LEARNING 0x0001 /* if can learn */ 164 #define IFBIF_DISCOVER 0x0002 /* if sends packets w/ unknown dest. */ 165 #define IFBIF_STP 0x0004 /* if participates in spanning tree */ 166 #define IFBIF_SPAN 0x0008 /* if is a span port */ 167 #define IFBIF_STICKY 0x0010 /* if learned addresses stick */ 168 #define IFBIF_BSTP_EDGE 0x0020 /* member stp edge port */ 169 #define IFBIF_BSTP_AUTOEDGE 0x0040 /* member stp autoedge enabled */ 170 #define IFBIF_BSTP_PTP 0x0080 /* member stp point to point */ 171 #define IFBIF_BSTP_AUTOPTP 0x0100 /* member stp autoptp enabled */ 172 #define IFBIF_BSTP_ADMEDGE 0x0200 /* member stp admin edge enabled */ 173 #define IFBIF_BSTP_ADMCOST 0x0400 /* member stp admin path cost */ 174 #define IFBIF_PRIVATE 0x0800 /* if is a private segment */ 175 /* was IFBIF_VLANFILTER 0x1000 */ 176 #define IFBIF_QINQ 0x2000 /* if allows 802.1ad Q-in-Q */ 177 178 #define IFBIFBITS "\020\001LEARNING\002DISCOVER\003STP\004SPAN" \ 179 "\005STICKY\014PRIVATE\006EDGE\007AUTOEDGE\010PTP" \ 180 "\011AUTOPTP" 181 #define IFBIFMASK ~(IFBIF_BSTP_EDGE|IFBIF_BSTP_AUTOEDGE|IFBIF_BSTP_PTP| \ 182 IFBIF_BSTP_AUTOPTP|IFBIF_BSTP_ADMEDGE| \ 183 IFBIF_BSTP_ADMCOST) /* not saved */ 184 185 /* BRDGFLUSH */ 186 #define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */ 187 #define IFBF_FLUSHALL 0x01 /* flush all addresses */ 188 189 /* 190 * Interface list structure. 191 */ 192 struct ifbifconf { 193 uint32_t ifbic_len; /* buffer size */ 194 union { 195 caddr_t ifbicu_buf; 196 struct ifbreq *ifbicu_req; 197 } ifbic_ifbicu; 198 #define ifbic_buf ifbic_ifbicu.ifbicu_buf 199 #define ifbic_req ifbic_ifbicu.ifbicu_req 200 }; 201 202 /* 203 * Bridge address request. 204 */ 205 struct ifbareq { 206 char ifba_ifsname[IFNAMSIZ]; /* member if name */ 207 unsigned long ifba_expire; /* address expire time */ 208 uint8_t ifba_flags; /* address flags */ 209 uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */ 210 ether_vlanid_t ifba_vlan; /* vlan id */ 211 }; 212 213 #define IFBAF_TYPEMASK 0x03 /* address type mask */ 214 #define IFBAF_DYNAMIC 0x00 /* dynamically learned address */ 215 #define IFBAF_STATIC 0x01 /* static address */ 216 #define IFBAF_STICKY 0x02 /* sticky address */ 217 218 #define IFBAFBITS "\020\1STATIC\2STICKY" 219 220 /* 221 * Address list structure. 222 */ 223 struct ifbaconf { 224 uint32_t ifbac_len; /* buffer size */ 225 union { 226 caddr_t ifbacu_buf; 227 struct ifbareq *ifbacu_req; 228 } ifbac_ifbacu; 229 #define ifbac_buf ifbac_ifbacu.ifbacu_buf 230 #define ifbac_req ifbac_ifbacu.ifbacu_req 231 }; 232 233 /* 234 * Bridge parameter structure. 235 */ 236 struct ifbrparam { 237 union { 238 uint32_t ifbrpu_int32; 239 uint16_t ifbrpu_int16; 240 uint8_t ifbrpu_int8; 241 } ifbrp_ifbrpu; 242 }; 243 #define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */ 244 #define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */ 245 #define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */ 246 #define ifbrp_proto ifbrp_ifbrpu.ifbrpu_int8 /* bridge protocol */ 247 #define ifbrp_txhc ifbrp_ifbrpu.ifbrpu_int8 /* bpdu tx holdcount */ 248 #define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */ 249 #define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */ 250 #define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */ 251 #define ifbrp_cexceeded ifbrp_ifbrpu.ifbrpu_int32 /* # of cache dropped 252 * addresses */ 253 #define ifbrp_flags ifbrp_ifbrpu.ifbrpu_int32 /* bridge flags */ 254 #define ifbrp_defpvid ifbrp_ifbrpu.ifbrpu_int16 /* default pvid */ 255 256 /* 257 * Bridge current operational parameters structure. 258 */ 259 struct ifbropreq { 260 uint8_t ifbop_holdcount; 261 uint8_t ifbop_maxage; 262 uint8_t ifbop_hellotime; 263 uint8_t ifbop_fwddelay; 264 uint8_t ifbop_protocol; 265 uint16_t ifbop_priority; 266 uint16_t ifbop_root_port; 267 uint32_t ifbop_root_path_cost; 268 uint64_t ifbop_bridgeid; 269 uint64_t ifbop_designated_root; 270 uint64_t ifbop_designated_bridge; 271 struct timeval ifbop_last_tc_time; 272 }; 273 274 /* 275 * Bridge member operational STP params structure. 276 */ 277 struct ifbpstpreq { 278 uint8_t ifbp_portno; /* bp STP port number */ 279 uint32_t ifbp_fwd_trans; /* bp STP fwd transitions */ 280 uint32_t ifbp_design_cost; /* bp STP designated cost */ 281 uint32_t ifbp_design_port; /* bp STP designated port */ 282 uint64_t ifbp_design_bridge; /* bp STP designated bridge */ 283 uint64_t ifbp_design_root; /* bp STP designated root */ 284 }; 285 286 /* 287 * Bridge STP ports list structure. 288 */ 289 struct ifbpstpconf { 290 uint32_t ifbpstp_len; /* buffer size */ 291 union { 292 caddr_t ifbpstpu_buf; 293 struct ifbpstpreq *ifbpstpu_req; 294 } ifbpstp_ifbpstpu; 295 #define ifbpstp_buf ifbpstp_ifbpstpu.ifbpstpu_buf 296 #define ifbpstp_req ifbpstp_ifbpstpu.ifbpstpu_req 297 }; 298 299 #define STP_STATES \ 300 "disabled", \ 301 "listening", \ 302 "learning", \ 303 "forwarding", \ 304 "blocking", \ 305 "discarding" 306 307 #define STP_PROTOS \ 308 "stp", \ 309 "-", \ 310 "rstp" 311 312 #define STP_ROLES \ 313 "disabled", \ 314 "root", \ 315 "designated", \ 316 "alternate", \ 317 "backup" 318 319 #define PV2ID(pv, epri, eaddr) do { \ 320 epri = pv >> 48; \ 321 eaddr[0] = pv >> 40; \ 322 eaddr[1] = pv >> 32; \ 323 eaddr[2] = pv >> 24; \ 324 eaddr[3] = pv >> 16; \ 325 eaddr[4] = pv >> 8; \ 326 eaddr[5] = pv >> 0; \ 327 } while (0) 328 329 /* 330 * Bridge VLAN access request. 331 */ 332 #define BRVLAN_SETSIZE 4096 333 typedef __BITSET_DEFINE(ifbvlan_set, BRVLAN_SETSIZE) ifbvlan_set_t; 334 335 #define BRVLAN_SET(set, bit) __BIT_SET(BRVLAN_SETSIZE, (bit), set) 336 #define BRVLAN_CLR(set, bit) __BIT_CLR(BRVLAN_SETSIZE, (bit), set) 337 #define BRVLAN_TEST(set, bit) __BIT_ISSET(BRVLAN_SETSIZE, (bit), set) 338 339 #define BRDG_VLAN_OP_SET 1 /* replace current vlan set */ 340 #define BRDG_VLAN_OP_ADD 2 /* add vlans to current set */ 341 #define BRDG_VLAN_OP_DEL 3 /* remove vlans from current set */ 342 343 struct ifbif_vlan_req { 344 char bv_ifname[IFNAMSIZ]; 345 uint8_t bv_op; 346 ifbvlan_set_t bv_set; 347 }; 348 349 #ifdef _KERNEL 350 351 #define BRIDGE_INPUT(_ifp, _m) do { \ 352 KASSERT((_ifp)->if_bridge_input != NULL, \ 353 ("%s: if_bridge not loaded!", __func__)); \ 354 _m = (*(_ifp)->if_bridge_input)(_ifp, _m); \ 355 if (_m != NULL) { \ 356 _ifp = _m->m_pkthdr.rcvif; \ 357 m->m_flags &= ~M_BRIDGE_INJECT; \ 358 } \ 359 } while (0) 360 361 #define BRIDGE_OUTPUT(_ifp, _m, _err) do { \ 362 KASSERT((_ifp)->if_bridge_output != NULL, \ 363 ("%s: if_bridge not loaded!", __func__)); \ 364 _err = (*(_ifp)->if_bridge_output)(_ifp, _m, NULL, NULL); \ 365 } while (0) 366 367 extern void (*bridge_dn_p)(struct mbuf *, struct ifnet *); 368 extern bool (*bridge_same_p)(const void *, const void *); 369 extern void *(*bridge_get_softc_p)(struct ifnet *); 370 extern bool (*bridge_member_ifaddrs_p)(void); 371 372 #endif /* _KERNEL */ 373 374 #endif /* _NET_IF_BRIDGEVAR_H_ */ 375