if_bridgevar.h revision 171678
1146985Sthompsa/* $NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $ */ 2146985Sthompsa 3146985Sthompsa/* 4146985Sthompsa * Copyright 2001 Wasabi Systems, Inc. 5146985Sthompsa * All rights reserved. 6146985Sthompsa * 7146985Sthompsa * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8146985Sthompsa * 9146985Sthompsa * Redistribution and use in source and binary forms, with or without 10146985Sthompsa * modification, are permitted provided that the following conditions 11146985Sthompsa * are met: 12146985Sthompsa * 1. Redistributions of source code must retain the above copyright 13146985Sthompsa * notice, this list of conditions and the following disclaimer. 14146985Sthompsa * 2. Redistributions in binary form must reproduce the above copyright 15146985Sthompsa * notice, this list of conditions and the following disclaimer in the 16146985Sthompsa * documentation and/or other materials provided with the distribution. 17146985Sthompsa * 3. All advertising materials mentioning features or use of this software 18146985Sthompsa * must display the following acknowledgement: 19146985Sthompsa * This product includes software developed for the NetBSD Project by 20146985Sthompsa * Wasabi Systems, Inc. 21146985Sthompsa * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22146985Sthompsa * or promote products derived from this software without specific prior 23146985Sthompsa * written permission. 24146985Sthompsa * 25146985Sthompsa * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26146985Sthompsa * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27146985Sthompsa * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28146985Sthompsa * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29146985Sthompsa * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30146985Sthompsa * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31146985Sthompsa * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32146985Sthompsa * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33146985Sthompsa * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34146985Sthompsa * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35146985Sthompsa * POSSIBILITY OF SUCH DAMAGE. 36146985Sthompsa */ 37146985Sthompsa 38146985Sthompsa/* 39146985Sthompsa * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) 40146985Sthompsa * All rights reserved. 41146985Sthompsa * 42146985Sthompsa * Redistribution and use in source and binary forms, with or without 43146985Sthompsa * modification, are permitted provided that the following conditions 44146985Sthompsa * are met: 45146985Sthompsa * 1. Redistributions of source code must retain the above copyright 46146985Sthompsa * notice, this list of conditions and the following disclaimer. 47146985Sthompsa * 2. Redistributions in binary form must reproduce the above copyright 48146985Sthompsa * notice, this list of conditions and the following disclaimer in the 49146985Sthompsa * documentation and/or other materials provided with the distribution. 50146985Sthompsa * 3. All advertising materials mentioning features or use of this software 51146985Sthompsa * must display the following acknowledgement: 52146985Sthompsa * This product includes software developed by Jason L. Wright 53146985Sthompsa * 4. The name of the author may not be used to endorse or promote products 54146985Sthompsa * derived from this software without specific prior written permission. 55146985Sthompsa * 56146985Sthompsa * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 57146985Sthompsa * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 58146985Sthompsa * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 59146985Sthompsa * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 60146985Sthompsa * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 61146985Sthompsa * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 62146985Sthompsa * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63146985Sthompsa * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 64146985Sthompsa * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 65146985Sthompsa * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 66146985Sthompsa * POSSIBILITY OF SUCH DAMAGE. 67146985Sthompsa * 68146985Sthompsa * OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp 69146985Sthompsa * 70146985Sthompsa * $FreeBSD: head/sys/net/if_bridgevar.h 171678 2007-08-01 00:33:52Z thompsa $ 71146985Sthompsa */ 72146985Sthompsa 73146985Sthompsa/* 74146985Sthompsa * Data structure and control definitions for bridge interfaces. 75146985Sthompsa */ 76146985Sthompsa 77146985Sthompsa#include <sys/callout.h> 78146985Sthompsa#include <sys/queue.h> 79151305Sthompsa#include <sys/condvar.h> 80146985Sthompsa 81146985Sthompsa/* 82146985Sthompsa * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the 83146985Sthompsa * bridge interface itself is keyed off the ifdrv structure. 84146985Sthompsa */ 85146985Sthompsa#define BRDGADD 0 /* add bridge member (ifbreq) */ 86146985Sthompsa#define BRDGDEL 1 /* delete bridge member (ifbreq) */ 87146985Sthompsa#define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */ 88146985Sthompsa#define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */ 89146985Sthompsa#define BRDGSCACHE 4 /* set cache size (ifbrparam) */ 90146985Sthompsa#define BRDGGCACHE 5 /* get cache size (ifbrparam) */ 91146985Sthompsa#define BRDGGIFS 6 /* get member list (ifbifconf) */ 92146985Sthompsa#define BRDGRTS 7 /* get address list (ifbaconf) */ 93146985Sthompsa#define BRDGSADDR 8 /* set static address (ifbareq) */ 94146985Sthompsa#define BRDGSTO 9 /* set cache timeout (ifbrparam) */ 95146985Sthompsa#define BRDGGTO 10 /* get cache timeout (ifbrparam) */ 96146985Sthompsa#define BRDGDADDR 11 /* delete address (ifbareq) */ 97146985Sthompsa#define BRDGFLUSH 12 /* flush address cache (ifbreq) */ 98146985Sthompsa 99146985Sthompsa#define BRDGGPRI 13 /* get priority (ifbrparam) */ 100146985Sthompsa#define BRDGSPRI 14 /* set priority (ifbrparam) */ 101146985Sthompsa#define BRDGGHT 15 /* get hello time (ifbrparam) */ 102146985Sthompsa#define BRDGSHT 16 /* set hello time (ifbrparam) */ 103146985Sthompsa#define BRDGGFD 17 /* get forward delay (ifbrparam) */ 104146985Sthompsa#define BRDGSFD 18 /* set forward delay (ifbrparam) */ 105146985Sthompsa#define BRDGGMA 19 /* get max age (ifbrparam) */ 106146985Sthompsa#define BRDGSMA 20 /* set max age (ifbrparam) */ 107146985Sthompsa#define BRDGSIFPRIO 21 /* set if priority (ifbreq) */ 108153967Sthompsa#define BRDGSIFCOST 22 /* set if path cost (ifbreq) */ 109153408Sthompsa#define BRDGADDS 23 /* add bridge span member (ifbreq) */ 110153408Sthompsa#define BRDGDELS 24 /* delete bridge span member (ifbreq) */ 111160867Sthompsa#define BRDGPARAM 25 /* get bridge STP params (ifbropreq) */ 112160867Sthompsa#define BRDGGRTE 26 /* get cache drops (ifbrparam) */ 113160867Sthompsa#define BRDGGIFSSTP 27 /* get member STP params list 114160867Sthompsa * (ifbpstpconf) */ 115163863Sthompsa#define BRDGSPROTO 28 /* set protocol (ifbrparam) */ 116163863Sthompsa#define BRDGSTXHC 29 /* set tx hold count (ifbrparam) */ 117146985Sthompsa 118146985Sthompsa/* 119146985Sthompsa * Generic bridge control request. 120146985Sthompsa */ 121146985Sthompsastruct ifbreq { 122146985Sthompsa char ifbr_ifsname[IFNAMSIZ]; /* member if name */ 123146985Sthompsa uint32_t ifbr_ifsflags; /* member if flags */ 124163863Sthompsa uint32_t ifbr_stpflags; /* member if STP flags */ 125163863Sthompsa uint32_t ifbr_path_cost; /* member if STP cost */ 126163863Sthompsa uint8_t ifbr_portno; /* member if port number */ 127163863Sthompsa uint8_t ifbr_priority; /* member if STP priority */ 128163863Sthompsa uint8_t ifbr_proto; /* member if STP protocol */ 129163863Sthompsa uint8_t ifbr_role; /* member if STP role */ 130146985Sthompsa uint8_t ifbr_state; /* member if STP state */ 131146985Sthompsa}; 132146985Sthompsa 133146985Sthompsa/* BRDGGIFFLAGS, BRDGSIFFLAGS */ 134164653Sthompsa#define IFBIF_LEARNING 0x0001 /* if can learn */ 135164653Sthompsa#define IFBIF_DISCOVER 0x0002 /* if sends packets w/ unknown dest. */ 136164653Sthompsa#define IFBIF_STP 0x0004 /* if participates in spanning tree */ 137164653Sthompsa#define IFBIF_SPAN 0x0008 /* if is a span port */ 138164653Sthompsa#define IFBIF_STICKY 0x0010 /* if learned addresses stick */ 139164653Sthompsa#define IFBIF_BSTP_EDGE 0x0020 /* member stp edge port */ 140164653Sthompsa#define IFBIF_BSTP_AUTOEDGE 0x0040 /* member stp autoedge enabled */ 141165105Sthompsa#define IFBIF_BSTP_PTP 0x0080 /* member stp point to point */ 142165105Sthompsa#define IFBIF_BSTP_AUTOPTP 0x0100 /* member stp autoptp enabled */ 143164880Ssyrinx#define IFBIF_BSTP_ADMEDGE 0x0200 /* member stp admin edge enabled */ 144164880Ssyrinx#define IFBIF_BSTP_ADMCOST 0x0400 /* member stp admin path cost */ 145171678Sthompsa#define IFBIF_PRIVATE 0x0800 /* if is a private segment */ 146146985Sthompsa 147164653Sthompsa#define IFBIFBITS "\020\001LEARNING\002DISCOVER\003STP\004SPAN" \ 148171678Sthompsa "\005STICKY\014PRIVATE\006EDGE\007AUTOEDGE\010PTP" \ 149171678Sthompsa "\011AUTOPTP" 150165105Sthompsa#define IFBIFMASK ~(IFBIF_BSTP_EDGE|IFBIF_BSTP_AUTOEDGE|IFBIF_BSTP_PTP| \ 151165105Sthompsa IFBIF_BSTP_AUTOPTP|IFBIF_BSTP_ADMEDGE| \ 152164880Ssyrinx IFBIF_BSTP_ADMCOST) /* not saved */ 153146985Sthompsa 154146985Sthompsa/* BRDGFLUSH */ 155146985Sthompsa#define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */ 156146985Sthompsa#define IFBF_FLUSHALL 0x01 /* flush all addresses */ 157146985Sthompsa 158146985Sthompsa/* 159146985Sthompsa * Interface list structure. 160146985Sthompsa */ 161146985Sthompsastruct ifbifconf { 162146985Sthompsa uint32_t ifbic_len; /* buffer size */ 163146985Sthompsa union { 164146985Sthompsa caddr_t ifbicu_buf; 165146985Sthompsa struct ifbreq *ifbicu_req; 166146985Sthompsa } ifbic_ifbicu; 167146985Sthompsa#define ifbic_buf ifbic_ifbicu.ifbicu_buf 168146985Sthompsa#define ifbic_req ifbic_ifbicu.ifbicu_req 169146985Sthompsa}; 170146985Sthompsa 171146985Sthompsa/* 172146985Sthompsa * Bridge address request. 173146985Sthompsa */ 174146985Sthompsastruct ifbareq { 175146985Sthompsa char ifba_ifsname[IFNAMSIZ]; /* member if name */ 176146985Sthompsa unsigned long ifba_expire; /* address expire time */ 177146985Sthompsa uint8_t ifba_flags; /* address flags */ 178146985Sthompsa uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */ 179170681Sthompsa uint16_t ifba_vlan; /* vlan id */ 180146985Sthompsa}; 181146985Sthompsa 182146985Sthompsa#define IFBAF_TYPEMASK 0x03 /* address type mask */ 183146985Sthompsa#define IFBAF_DYNAMIC 0x00 /* dynamically learned address */ 184146985Sthompsa#define IFBAF_STATIC 0x01 /* static address */ 185164112Sthompsa#define IFBAF_STICKY 0x02 /* sticky address */ 186146985Sthompsa 187164112Sthompsa#define IFBAFBITS "\020\1STATIC\2STICKY" 188146985Sthompsa 189146985Sthompsa/* 190146985Sthompsa * Address list structure. 191146985Sthompsa */ 192146985Sthompsastruct ifbaconf { 193146985Sthompsa uint32_t ifbac_len; /* buffer size */ 194146985Sthompsa union { 195146985Sthompsa caddr_t ifbacu_buf; 196146985Sthompsa struct ifbareq *ifbacu_req; 197146985Sthompsa } ifbac_ifbacu; 198146985Sthompsa#define ifbac_buf ifbac_ifbacu.ifbacu_buf 199146985Sthompsa#define ifbac_req ifbac_ifbacu.ifbacu_req 200146985Sthompsa}; 201146985Sthompsa 202146985Sthompsa/* 203146985Sthompsa * Bridge parameter structure. 204146985Sthompsa */ 205146985Sthompsastruct ifbrparam { 206146985Sthompsa union { 207146985Sthompsa uint32_t ifbrpu_int32; 208146985Sthompsa uint16_t ifbrpu_int16; 209146985Sthompsa uint8_t ifbrpu_int8; 210146985Sthompsa } ifbrp_ifbrpu; 211146985Sthompsa}; 212146985Sthompsa#define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */ 213146985Sthompsa#define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */ 214146985Sthompsa#define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */ 215163863Sthompsa#define ifbrp_proto ifbrp_ifbrpu.ifbrpu_int8 /* bridge protocol */ 216163863Sthompsa#define ifbrp_txhc ifbrp_ifbrpu.ifbrpu_int8 /* bpdu tx holdcount */ 217146985Sthompsa#define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */ 218146985Sthompsa#define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */ 219146985Sthompsa#define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */ 220160867Sthompsa#define ifbrp_cexceeded ifbrp_ifbrpu.ifbrpu_int32 /* # of cache dropped 221160867Sthompsa * adresses */ 222160867Sthompsa/* 223160867Sthompsa * Bridge current operational parameters structure. 224160867Sthompsa */ 225160867Sthompsastruct ifbropreq { 226163863Sthompsa uint8_t ifbop_holdcount; 227160867Sthompsa uint8_t ifbop_maxage; 228160867Sthompsa uint8_t ifbop_hellotime; 229160867Sthompsa uint8_t ifbop_fwddelay; 230163863Sthompsa uint8_t ifbop_protocol; 231163863Sthompsa uint16_t ifbop_priority; 232160867Sthompsa uint16_t ifbop_root_port; 233160867Sthompsa uint32_t ifbop_root_path_cost; 234164653Sthompsa uint64_t ifbop_bridgeid; 235160867Sthompsa uint64_t ifbop_designated_root; 236164653Sthompsa uint64_t ifbop_designated_bridge; 237160867Sthompsa struct timeval ifbop_last_tc_time; 238160867Sthompsa}; 239146985Sthompsa 240160867Sthompsa/* 241160867Sthompsa * Bridge member operational STP params structure. 242160867Sthompsa */ 243160867Sthompsastruct ifbpstpreq { 244160867Sthompsa uint8_t ifbp_portno; /* bp STP port number */ 245160867Sthompsa uint32_t ifbp_fwd_trans; /* bp STP fwd transitions */ 246160867Sthompsa uint32_t ifbp_design_cost; /* bp STP designated cost */ 247160867Sthompsa uint32_t ifbp_design_port; /* bp STP designated port */ 248160867Sthompsa uint64_t ifbp_design_bridge; /* bp STP designated bridge */ 249160867Sthompsa uint64_t ifbp_design_root; /* bp STP designated root */ 250160867Sthompsa}; 251160867Sthompsa 252160867Sthompsa/* 253160867Sthompsa * Bridge STP ports list structure. 254160867Sthompsa */ 255160867Sthompsastruct ifbpstpconf { 256160867Sthompsa uint32_t ifbpstp_len; /* buffer size */ 257160867Sthompsa union { 258160867Sthompsa caddr_t ifbpstpu_buf; 259160867Sthompsa struct ifbpstpreq *ifbpstpu_req; 260160867Sthompsa } ifbpstp_ifbpstpu; 261160867Sthompsa#define ifbpstp_buf ifbpstp_ifbpstpu.ifbpstpu_buf 262160867Sthompsa#define ifbpstp_req ifbpstp_ifbpstpu.ifbpstpu_req 263160867Sthompsa}; 264160867Sthompsa 265146985Sthompsa#ifdef _KERNEL 266146985Sthompsa 267146985Sthompsa#define BRIDGE_LOCK_INIT(_sc) do { \ 268146985Sthompsa mtx_init(&(_sc)->sc_mtx, "if_bridge", NULL, MTX_DEF); \ 269146985Sthompsa cv_init(&(_sc)->sc_cv, "if_bridge_cv"); \ 270146985Sthompsa} while (0) 271146985Sthompsa#define BRIDGE_LOCK_DESTROY(_sc) do { \ 272146985Sthompsa mtx_destroy(&(_sc)->sc_mtx); \ 273146985Sthompsa cv_destroy(&(_sc)->sc_cv); \ 274146985Sthompsa} while (0) 275146985Sthompsa#define BRIDGE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 276146985Sthompsa#define BRIDGE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 277146985Sthompsa#define BRIDGE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED) 278146985Sthompsa#define BRIDGE_LOCK2REF(_sc, _err) do { \ 279146985Sthompsa mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \ 280146985Sthompsa if ((_sc)->sc_iflist_xcnt > 0) \ 281146985Sthompsa (_err) = EBUSY; \ 282146985Sthompsa else \ 283146985Sthompsa (_sc)->sc_iflist_ref++; \ 284146985Sthompsa mtx_unlock(&(_sc)->sc_mtx); \ 285146985Sthompsa} while (0) 286146985Sthompsa#define BRIDGE_UNREF(_sc) do { \ 287146985Sthompsa mtx_lock(&(_sc)->sc_mtx); \ 288146985Sthompsa (_sc)->sc_iflist_ref--; \ 289146985Sthompsa if (((_sc)->sc_iflist_xcnt > 0) && ((_sc)->sc_iflist_ref == 0)) \ 290146985Sthompsa cv_broadcast(&(_sc)->sc_cv); \ 291146985Sthompsa mtx_unlock(&(_sc)->sc_mtx); \ 292146985Sthompsa} while (0) 293146985Sthompsa#define BRIDGE_XLOCK(_sc) do { \ 294146985Sthompsa mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \ 295146985Sthompsa (_sc)->sc_iflist_xcnt++; \ 296146985Sthompsa while ((_sc)->sc_iflist_ref > 0) \ 297146985Sthompsa cv_wait(&(_sc)->sc_cv, &(_sc)->sc_mtx); \ 298146985Sthompsa} while (0) 299146985Sthompsa#define BRIDGE_XDROP(_sc) do { \ 300146985Sthompsa mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \ 301146985Sthompsa (_sc)->sc_iflist_xcnt--; \ 302146985Sthompsa} while (0) 303146985Sthompsa 304151305Sthompsa#define BRIDGE_INPUT(_ifp, _m) do { \ 305151305Sthompsa KASSERT(bridge_input_p != NULL, \ 306151305Sthompsa ("%s: if_bridge not loaded!", __func__)); \ 307151305Sthompsa _m = (*bridge_input_p)(_ifp, _m); \ 308151305Sthompsa if (_m != NULL) \ 309151305Sthompsa _ifp = _m->m_pkthdr.rcvif; \ 310151305Sthompsa} while (0) 311151305Sthompsa 312151305Sthompsa#define BRIDGE_OUTPUT(_ifp, _m, _err) do { \ 313151305Sthompsa KASSERT(bridge_output_p != NULL, \ 314151305Sthompsa ("%s: if_bridge not loaded!", __func__)); \ 315151305Sthompsa _err = (*bridge_output_p)(_ifp, _m, NULL, NULL); \ 316151305Sthompsa} while (0) 317151305Sthompsa 318151305Sthompsaextern struct mbuf *(*bridge_input_p)(struct ifnet *, struct mbuf *); 319151305Sthompsaextern int (*bridge_output_p)(struct ifnet *, struct mbuf *, 320151305Sthompsa struct sockaddr *, struct rtentry *); 321151305Sthompsaextern void (*bridge_dn_p)(struct mbuf *, struct ifnet *); 322146985Sthompsa 323146985Sthompsa#endif /* _KERNEL */ 324