/* $NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $ */12/*3* SPDX-License-Identifier: BSD-4-Clause4*5* Copyright 2001 Wasabi Systems, Inc.6* All rights reserved.7*8* Written by Jason R. Thorpe for Wasabi Systems, Inc.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. All advertising materials mentioning features or use of this software19* must display the following acknowledgement:20* This product includes software developed for the NetBSD Project by21* Wasabi Systems, Inc.22* 4. The name of Wasabi Systems, Inc. may not be used to endorse23* or promote products derived from this software without specific prior24* written permission.25*26* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND27* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED28* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR29* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC30* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR31* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF32* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS33* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN34* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)35* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE36* POSSIBILITY OF SUCH DAMAGE.37*/3839/*40* Copyright (c) 1999, 2000 Jason L. Wright ([email protected])41* All rights reserved.42*43* Redistribution and use in source and binary forms, with or without44* modification, are permitted provided that the following conditions45* are met:46* 1. Redistributions of source code must retain the above copyright47* notice, this list of conditions and the following disclaimer.48* 2. Redistributions in binary form must reproduce the above copyright49* notice, this list of conditions and the following disclaimer in the50* documentation and/or other materials provided with the distribution.51* 3. All advertising materials mentioning features or use of this software52* must display the following acknowledgement:53* This product includes software developed by Jason L. Wright54* 4. The name of the author may not be used to endorse or promote products55* derived from this software without specific prior written permission.56*57* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR58* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED59* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE60* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,61* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES62* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR63* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)64* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,65* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN66* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE67* POSSIBILITY OF SUCH DAMAGE.68*69* OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp70*/7172/*73* Data structure and control definitions for bridge interfaces.74*/7576#ifndef _NET_IF_BRIDGEVAR_H_77#define _NET_IF_BRIDGEVAR_H_7879#include <sys/types.h>80#include <sys/_bitset.h>81#include <sys/bitset.h>82#include <sys/callout.h>83#include <sys/queue.h>84#include <sys/condvar.h>8586#include <net/ethernet.h>87#include <net/if.h>8889/*90* Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the91* bridge interface itself is keyed off the ifdrv structure.92*/93#define BRDGADD 0 /* add bridge member (ifbreq) */94#define BRDGDEL 1 /* delete bridge member (ifbreq) */95#define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */96#define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */97#define BRDGSCACHE 4 /* set cache size (ifbrparam) */98#define BRDGGCACHE 5 /* get cache size (ifbrparam) */99#define BRDGGIFS 6 /* get member list (ifbifconf) */100#define BRDGRTS 7 /* get address list (ifbaconf) */101#define BRDGSADDR 8 /* set static address (ifbareq) */102#define BRDGSTO 9 /* set cache timeout (ifbrparam) */103#define BRDGGTO 10 /* get cache timeout (ifbrparam) */104#define BRDGDADDR 11 /* delete address (ifbareq) */105#define BRDGFLUSH 12 /* flush address cache (ifbreq) */106107#define BRDGGPRI 13 /* get priority (ifbrparam) */108#define BRDGSPRI 14 /* set priority (ifbrparam) */109#define BRDGGHT 15 /* get hello time (ifbrparam) */110#define BRDGSHT 16 /* set hello time (ifbrparam) */111#define BRDGGFD 17 /* get forward delay (ifbrparam) */112#define BRDGSFD 18 /* set forward delay (ifbrparam) */113#define BRDGGMA 19 /* get max age (ifbrparam) */114#define BRDGSMA 20 /* set max age (ifbrparam) */115#define BRDGSIFPRIO 21 /* set if priority (ifbreq) */116#define BRDGSIFCOST 22 /* set if path cost (ifbreq) */117#define BRDGADDS 23 /* add bridge span member (ifbreq) */118#define BRDGDELS 24 /* delete bridge span member (ifbreq) */119#define BRDGPARAM 25 /* get bridge STP params (ifbropreq) */120#define BRDGGRTE 26 /* get cache drops (ifbrparam) */121#define BRDGGIFSSTP 27 /* get member STP params list122* (ifbpstpconf) */123#define BRDGSPROTO 28 /* set protocol (ifbrparam) */124#define BRDGSTXHC 29 /* set tx hold count (ifbrparam) */125#define BRDGSIFAMAX 30 /* set max interface addrs (ifbreq) */126#define BRDGSIFPVID 31 /* set if PVID */127#define BRDGSIFVLANSET 32 /* set if vlan set */128#define BRDGGIFVLANSET 33 /* get if vlan set */129#define BRDGGFLAGS 34 /* get bridge flags (ifbrparam) */130#define BRDGSFLAGS 35 /* set bridge flags (ifbrparam) */131#define BRDGGDEFPVID 36 /* get default pvid (ifbrparam) */132#define BRDGSDEFPVID 37 /* set default pvid (ifbrparam) */133#define BRDGSIFVLANPROTO 38 /* set if vlan protocol (ifbreq) */134135/* BRDGSFLAGS, Bridge flags (non-interface-specific) */136typedef uint32_t ifbr_flags_t;137138#define IFBRF_VLANFILTER (1U<<0) /* VLAN filtering enabled */139#define IFBRF_DEFQINQ (1U<<1) /* 802.1ad Q-in-Q allowed by default */140141#define IFBRFBITS "\020\01VLANFILTER\02DEFQINQ"142143/*144* Generic bridge control request.145*/146struct ifbreq {147char ifbr_ifsname[IFNAMSIZ]; /* member if name */148uint32_t ifbr_ifsflags; /* member if flags */149uint32_t ifbr_stpflags; /* member if STP flags */150uint32_t ifbr_path_cost; /* member if STP cost */151uint8_t ifbr_portno; /* member if port number */152uint8_t ifbr_priority; /* member if STP priority */153uint8_t ifbr_proto; /* member if STP protocol */154uint8_t ifbr_role; /* member if STP role */155uint8_t ifbr_state; /* member if STP state */156uint32_t ifbr_addrcnt; /* member if addr number */157uint32_t ifbr_addrmax; /* member if addr max */158uint32_t ifbr_addrexceeded; /* member if addr violations */159ether_vlanid_t ifbr_pvid; /* member if PVID */160uint16_t ifbr_vlanproto; /* member if VLAN protocol */161uint8_t pad[28];162};163164/* BRDGGIFFLAGS, BRDGSIFFLAGS */165#define IFBIF_LEARNING 0x0001 /* if can learn */166#define IFBIF_DISCOVER 0x0002 /* if sends packets w/ unknown dest. */167#define IFBIF_STP 0x0004 /* if participates in spanning tree */168#define IFBIF_SPAN 0x0008 /* if is a span port */169#define IFBIF_STICKY 0x0010 /* if learned addresses stick */170#define IFBIF_BSTP_EDGE 0x0020 /* member stp edge port */171#define IFBIF_BSTP_AUTOEDGE 0x0040 /* member stp autoedge enabled */172#define IFBIF_BSTP_PTP 0x0080 /* member stp point to point */173#define IFBIF_BSTP_AUTOPTP 0x0100 /* member stp autoptp enabled */174#define IFBIF_BSTP_ADMEDGE 0x0200 /* member stp admin edge enabled */175#define IFBIF_BSTP_ADMCOST 0x0400 /* member stp admin path cost */176#define IFBIF_PRIVATE 0x0800 /* if is a private segment */177#define IFBIF_QINQ 0x1000 /* if allows 802.1ad Q-in-Q */178179#define IFBIFBITS "\020\001LEARNING\002DISCOVER\003STP\004SPAN" \180"\005STICKY\014PRIVATE\006EDGE\007AUTOEDGE\010PTP" \181"\011AUTOPTP\015QINQ"182#define IFBIFMASK ~(IFBIF_BSTP_EDGE|IFBIF_BSTP_AUTOEDGE|IFBIF_BSTP_PTP| \183IFBIF_BSTP_AUTOPTP|IFBIF_BSTP_ADMEDGE| \184IFBIF_BSTP_ADMCOST) /* not saved */185186/* BRDGFLUSH */187#define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */188#define IFBF_FLUSHALL 0x01 /* flush all addresses */189190/*191* Interface list structure.192*/193struct ifbifconf {194uint32_t ifbic_len; /* buffer size */195union {196caddr_t ifbicu_buf;197struct ifbreq *ifbicu_req;198} ifbic_ifbicu;199#define ifbic_buf ifbic_ifbicu.ifbicu_buf200#define ifbic_req ifbic_ifbicu.ifbicu_req201};202203/*204* Bridge address request.205*/206struct ifbareq {207char ifba_ifsname[IFNAMSIZ]; /* member if name */208unsigned long ifba_expire; /* address expire time */209uint8_t ifba_flags; /* address flags */210uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */211ether_vlanid_t ifba_vlan; /* vlan id */212};213214#define IFBAF_TYPEMASK 0x03 /* address type mask */215#define IFBAF_DYNAMIC 0x00 /* dynamically learned address */216#define IFBAF_STATIC 0x01 /* static address */217#define IFBAF_STICKY 0x02 /* sticky address */218219#define IFBAFBITS "\020\1STATIC\2STICKY"220221/*222* Address list structure.223*/224struct ifbaconf {225uint32_t ifbac_len; /* buffer size */226union {227caddr_t ifbacu_buf;228struct ifbareq *ifbacu_req;229} ifbac_ifbacu;230#define ifbac_buf ifbac_ifbacu.ifbacu_buf231#define ifbac_req ifbac_ifbacu.ifbacu_req232};233234/*235* Bridge parameter structure.236*/237struct ifbrparam {238union {239uint32_t ifbrpu_int32;240uint16_t ifbrpu_int16;241uint8_t ifbrpu_int8;242} ifbrp_ifbrpu;243};244#define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */245#define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */246#define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */247#define ifbrp_proto ifbrp_ifbrpu.ifbrpu_int8 /* bridge protocol */248#define ifbrp_txhc ifbrp_ifbrpu.ifbrpu_int8 /* bpdu tx holdcount */249#define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */250#define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */251#define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */252#define ifbrp_cexceeded ifbrp_ifbrpu.ifbrpu_int32 /* # of cache dropped253* addresses */254#define ifbrp_flags ifbrp_ifbrpu.ifbrpu_int32 /* bridge flags */255#define ifbrp_defpvid ifbrp_ifbrpu.ifbrpu_int16 /* default pvid */256#define ifbrp_vlanproto ifbrp_ifbrpu.ifbrpu_int8 /* vlan protocol */257258/*259* Bridge current operational parameters structure.260*/261struct ifbropreq {262uint8_t ifbop_holdcount;263uint8_t ifbop_maxage;264uint8_t ifbop_hellotime;265uint8_t ifbop_fwddelay;266uint8_t ifbop_protocol;267uint16_t ifbop_priority;268uint16_t ifbop_root_port;269uint32_t ifbop_root_path_cost;270uint64_t ifbop_bridgeid;271uint64_t ifbop_designated_root;272uint64_t ifbop_designated_bridge;273struct timeval ifbop_last_tc_time;274};275276/*277* Bridge member operational STP params structure.278*/279struct ifbpstpreq {280uint8_t ifbp_portno; /* bp STP port number */281uint32_t ifbp_fwd_trans; /* bp STP fwd transitions */282uint32_t ifbp_design_cost; /* bp STP designated cost */283uint32_t ifbp_design_port; /* bp STP designated port */284uint64_t ifbp_design_bridge; /* bp STP designated bridge */285uint64_t ifbp_design_root; /* bp STP designated root */286};287288/*289* Bridge STP ports list structure.290*/291struct ifbpstpconf {292uint32_t ifbpstp_len; /* buffer size */293union {294caddr_t ifbpstpu_buf;295struct ifbpstpreq *ifbpstpu_req;296} ifbpstp_ifbpstpu;297#define ifbpstp_buf ifbpstp_ifbpstpu.ifbpstpu_buf298#define ifbpstp_req ifbpstp_ifbpstpu.ifbpstpu_req299};300301#define STP_STATES \302"disabled", \303"listening", \304"learning", \305"forwarding", \306"blocking", \307"discarding"308309#define STP_PROTOS \310"stp", \311"-", \312"rstp"313314#define STP_ROLES \315"disabled", \316"root", \317"designated", \318"alternate", \319"backup"320321#define PV2ID(pv, epri, eaddr) do { \322epri = pv >> 48; \323eaddr[0] = pv >> 40; \324eaddr[1] = pv >> 32; \325eaddr[2] = pv >> 24; \326eaddr[3] = pv >> 16; \327eaddr[4] = pv >> 8; \328eaddr[5] = pv >> 0; \329} while (0)330331/*332* Bridge VLAN access request.333*/334#define BRVLAN_SETSIZE 4096335typedef __BITSET_DEFINE(ifbvlan_set, BRVLAN_SETSIZE) ifbvlan_set_t;336337#define BRVLAN_SET(set, bit) __BIT_SET(BRVLAN_SETSIZE, (bit), set)338#define BRVLAN_CLR(set, bit) __BIT_CLR(BRVLAN_SETSIZE, (bit), set)339#define BRVLAN_TEST(set, bit) __BIT_ISSET(BRVLAN_SETSIZE, (bit), set)340341#define BRDG_VLAN_OP_SET 1 /* replace current vlan set */342#define BRDG_VLAN_OP_ADD 2 /* add vlans to current set */343#define BRDG_VLAN_OP_DEL 3 /* remove vlans from current set */344345struct ifbif_vlan_req {346char bv_ifname[IFNAMSIZ];347uint8_t bv_op;348ifbvlan_set_t bv_set;349};350351#ifdef _KERNEL352353#define BRIDGE_INPUT(_ifp, _m) do { \354KASSERT((_ifp)->if_bridge_input != NULL, \355("%s: if_bridge not loaded!", __func__)); \356_m = (*(_ifp)->if_bridge_input)(_ifp, _m); \357if (_m != NULL) { \358_ifp = _m->m_pkthdr.rcvif; \359m->m_flags &= ~M_BRIDGE_INJECT; \360} \361} while (0)362363#define BRIDGE_OUTPUT(_ifp, _m, _err) do { \364KASSERT((_ifp)->if_bridge_output != NULL, \365("%s: if_bridge not loaded!", __func__)); \366_err = (*(_ifp)->if_bridge_output)(_ifp, _m, NULL, NULL); \367} while (0)368369extern void (*bridge_dn_p)(struct mbuf *, struct ifnet *);370extern bool (*bridge_same_p)(const void *, const void *);371extern void *(*bridge_get_softc_p)(struct ifnet *);372extern bool (*bridge_member_ifaddrs_p)(void);373374#endif /* _KERNEL */375376#endif /* _NET_IF_BRIDGEVAR_H_ */377378379