131997bf2SAndrew Thompson /* $NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $ */ 231997bf2SAndrew Thompson 331997bf2SAndrew Thompson /* 431997bf2SAndrew Thompson * Copyright 2001 Wasabi Systems, Inc. 531997bf2SAndrew Thompson * All rights reserved. 631997bf2SAndrew Thompson * 731997bf2SAndrew Thompson * Written by Jason R. Thorpe for Wasabi Systems, Inc. 831997bf2SAndrew Thompson * 931997bf2SAndrew Thompson * Redistribution and use in source and binary forms, with or without 1031997bf2SAndrew Thompson * modification, are permitted provided that the following conditions 1131997bf2SAndrew Thompson * are met: 1231997bf2SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1331997bf2SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1431997bf2SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1531997bf2SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1631997bf2SAndrew Thompson * documentation and/or other materials provided with the distribution. 1731997bf2SAndrew Thompson * 3. All advertising materials mentioning features or use of this software 1831997bf2SAndrew Thompson * must display the following acknowledgement: 1931997bf2SAndrew Thompson * This product includes software developed for the NetBSD Project by 2031997bf2SAndrew Thompson * Wasabi Systems, Inc. 2131997bf2SAndrew Thompson * 4. The name of Wasabi Systems, Inc. may not be used to endorse 2231997bf2SAndrew Thompson * or promote products derived from this software without specific prior 2331997bf2SAndrew Thompson * written permission. 2431997bf2SAndrew Thompson * 2531997bf2SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 2631997bf2SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2731997bf2SAndrew Thompson * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2831997bf2SAndrew Thompson * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 2931997bf2SAndrew Thompson * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3031997bf2SAndrew Thompson * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3131997bf2SAndrew Thompson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3231997bf2SAndrew Thompson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3331997bf2SAndrew Thompson * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3431997bf2SAndrew Thompson * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3531997bf2SAndrew Thompson * POSSIBILITY OF SUCH DAMAGE. 3631997bf2SAndrew Thompson */ 3731997bf2SAndrew Thompson 3831997bf2SAndrew Thompson /* 3931997bf2SAndrew Thompson * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) 4031997bf2SAndrew Thompson * All rights reserved. 4131997bf2SAndrew Thompson * 4231997bf2SAndrew Thompson * Redistribution and use in source and binary forms, with or without 4331997bf2SAndrew Thompson * modification, are permitted provided that the following conditions 4431997bf2SAndrew Thompson * are met: 4531997bf2SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 4631997bf2SAndrew Thompson * notice, this list of conditions and the following disclaimer. 4731997bf2SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 4831997bf2SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 4931997bf2SAndrew Thompson * documentation and/or other materials provided with the distribution. 5031997bf2SAndrew Thompson * 3. All advertising materials mentioning features or use of this software 5131997bf2SAndrew Thompson * must display the following acknowledgement: 5231997bf2SAndrew Thompson * This product includes software developed by Jason L. Wright 5331997bf2SAndrew Thompson * 4. The name of the author may not be used to endorse or promote products 5431997bf2SAndrew Thompson * derived from this software without specific prior written permission. 5531997bf2SAndrew Thompson * 5631997bf2SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 5731997bf2SAndrew Thompson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 5831997bf2SAndrew Thompson * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 5931997bf2SAndrew Thompson * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 6031997bf2SAndrew Thompson * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 6131997bf2SAndrew Thompson * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 6231997bf2SAndrew Thompson * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 6331997bf2SAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 6431997bf2SAndrew Thompson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 6531997bf2SAndrew Thompson * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 6631997bf2SAndrew Thompson * POSSIBILITY OF SUCH DAMAGE. 6731997bf2SAndrew Thompson * 6831997bf2SAndrew Thompson * OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp 6931997bf2SAndrew Thompson * 7031997bf2SAndrew Thompson * $FreeBSD$ 7131997bf2SAndrew Thompson */ 7231997bf2SAndrew Thompson 7331997bf2SAndrew Thompson /* 7431997bf2SAndrew Thompson * Data structure and control definitions for bridge interfaces. 7531997bf2SAndrew Thompson */ 7631997bf2SAndrew Thompson 7731997bf2SAndrew Thompson #include <sys/callout.h> 7831997bf2SAndrew Thompson #include <sys/queue.h> 7931997bf2SAndrew Thompson 8031997bf2SAndrew Thompson /* 8131997bf2SAndrew Thompson * Commands used in the SIOCSDRVSPEC ioctl. Note the lookup of the 8231997bf2SAndrew Thompson * bridge interface itself is keyed off the ifdrv structure. 8331997bf2SAndrew Thompson */ 8431997bf2SAndrew Thompson #define BRDGADD 0 /* add bridge member (ifbreq) */ 8531997bf2SAndrew Thompson #define BRDGDEL 1 /* delete bridge member (ifbreq) */ 8631997bf2SAndrew Thompson #define BRDGGIFFLGS 2 /* get member if flags (ifbreq) */ 8731997bf2SAndrew Thompson #define BRDGSIFFLGS 3 /* set member if flags (ifbreq) */ 8831997bf2SAndrew Thompson #define BRDGSCACHE 4 /* set cache size (ifbrparam) */ 8931997bf2SAndrew Thompson #define BRDGGCACHE 5 /* get cache size (ifbrparam) */ 9031997bf2SAndrew Thompson #define BRDGGIFS 6 /* get member list (ifbifconf) */ 9131997bf2SAndrew Thompson #define BRDGRTS 7 /* get address list (ifbaconf) */ 9231997bf2SAndrew Thompson #define BRDGSADDR 8 /* set static address (ifbareq) */ 9331997bf2SAndrew Thompson #define BRDGSTO 9 /* set cache timeout (ifbrparam) */ 9431997bf2SAndrew Thompson #define BRDGGTO 10 /* get cache timeout (ifbrparam) */ 9531997bf2SAndrew Thompson #define BRDGDADDR 11 /* delete address (ifbareq) */ 9631997bf2SAndrew Thompson #define BRDGFLUSH 12 /* flush address cache (ifbreq) */ 9731997bf2SAndrew Thompson 9831997bf2SAndrew Thompson #define BRDGGPRI 13 /* get priority (ifbrparam) */ 9931997bf2SAndrew Thompson #define BRDGSPRI 14 /* set priority (ifbrparam) */ 10031997bf2SAndrew Thompson #define BRDGGHT 15 /* get hello time (ifbrparam) */ 10131997bf2SAndrew Thompson #define BRDGSHT 16 /* set hello time (ifbrparam) */ 10231997bf2SAndrew Thompson #define BRDGGFD 17 /* get forward delay (ifbrparam) */ 10331997bf2SAndrew Thompson #define BRDGSFD 18 /* set forward delay (ifbrparam) */ 10431997bf2SAndrew Thompson #define BRDGGMA 19 /* get max age (ifbrparam) */ 10531997bf2SAndrew Thompson #define BRDGSMA 20 /* set max age (ifbrparam) */ 10631997bf2SAndrew Thompson #define BRDGSIFPRIO 21 /* set if priority (ifbreq) */ 10731997bf2SAndrew Thompson #define BRDGSIFCOST 22 /* set if path cost (ifbreq) */ 10831997bf2SAndrew Thompson 10931997bf2SAndrew Thompson /* 11031997bf2SAndrew Thompson * Generic bridge control request. 11131997bf2SAndrew Thompson */ 11231997bf2SAndrew Thompson struct ifbreq { 11331997bf2SAndrew Thompson char ifbr_ifsname[IFNAMSIZ]; /* member if name */ 11431997bf2SAndrew Thompson uint32_t ifbr_ifsflags; /* member if flags */ 11531997bf2SAndrew Thompson uint8_t ifbr_state; /* member if STP state */ 11631997bf2SAndrew Thompson uint8_t ifbr_priority; /* member if STP priority */ 11731997bf2SAndrew Thompson uint8_t ifbr_path_cost; /* member if STP cost */ 11831997bf2SAndrew Thompson uint8_t ifbr_portno; /* member if port number */ 11931997bf2SAndrew Thompson }; 12031997bf2SAndrew Thompson 12131997bf2SAndrew Thompson /* BRDGGIFFLAGS, BRDGSIFFLAGS */ 12231997bf2SAndrew Thompson #define IFBIF_LEARNING 0x01 /* if can learn */ 12331997bf2SAndrew Thompson #define IFBIF_DISCOVER 0x02 /* if sends packets w/ unknown dest. */ 12431997bf2SAndrew Thompson #define IFBIF_STP 0x04 /* if participates in spanning tree */ 12531997bf2SAndrew Thompson 12631997bf2SAndrew Thompson #define IFBIFBITS "\020\1LEARNING\2DISCOVER\3STP" 12731997bf2SAndrew Thompson 12831997bf2SAndrew Thompson /* BRDGFLUSH */ 12931997bf2SAndrew Thompson #define IFBF_FLUSHDYN 0x00 /* flush learned addresses only */ 13031997bf2SAndrew Thompson #define IFBF_FLUSHALL 0x01 /* flush all addresses */ 13131997bf2SAndrew Thompson 13231997bf2SAndrew Thompson /* STP port states */ 13331997bf2SAndrew Thompson #define BSTP_IFSTATE_DISABLED 0 13431997bf2SAndrew Thompson #define BSTP_IFSTATE_LISTENING 1 13531997bf2SAndrew Thompson #define BSTP_IFSTATE_LEARNING 2 13631997bf2SAndrew Thompson #define BSTP_IFSTATE_FORWARDING 3 13731997bf2SAndrew Thompson #define BSTP_IFSTATE_BLOCKING 4 13831997bf2SAndrew Thompson 13931997bf2SAndrew Thompson /* 14031997bf2SAndrew Thompson * Interface list structure. 14131997bf2SAndrew Thompson */ 14231997bf2SAndrew Thompson struct ifbifconf { 14331997bf2SAndrew Thompson uint32_t ifbic_len; /* buffer size */ 14431997bf2SAndrew Thompson union { 14531997bf2SAndrew Thompson caddr_t ifbicu_buf; 14631997bf2SAndrew Thompson struct ifbreq *ifbicu_req; 14731997bf2SAndrew Thompson } ifbic_ifbicu; 14831997bf2SAndrew Thompson #define ifbic_buf ifbic_ifbicu.ifbicu_buf 14931997bf2SAndrew Thompson #define ifbic_req ifbic_ifbicu.ifbicu_req 15031997bf2SAndrew Thompson }; 15131997bf2SAndrew Thompson 15231997bf2SAndrew Thompson /* 15331997bf2SAndrew Thompson * Bridge address request. 15431997bf2SAndrew Thompson */ 15531997bf2SAndrew Thompson struct ifbareq { 15631997bf2SAndrew Thompson char ifba_ifsname[IFNAMSIZ]; /* member if name */ 15731997bf2SAndrew Thompson unsigned long ifba_expire; /* address expire time */ 15831997bf2SAndrew Thompson uint8_t ifba_flags; /* address flags */ 15931997bf2SAndrew Thompson uint8_t ifba_dst[ETHER_ADDR_LEN];/* destination address */ 16031997bf2SAndrew Thompson }; 16131997bf2SAndrew Thompson 16231997bf2SAndrew Thompson #define IFBAF_TYPEMASK 0x03 /* address type mask */ 16331997bf2SAndrew Thompson #define IFBAF_DYNAMIC 0x00 /* dynamically learned address */ 16431997bf2SAndrew Thompson #define IFBAF_STATIC 0x01 /* static address */ 16531997bf2SAndrew Thompson 16631997bf2SAndrew Thompson #define IFBAFBITS "\020\1STATIC" 16731997bf2SAndrew Thompson 16831997bf2SAndrew Thompson /* 16931997bf2SAndrew Thompson * Address list structure. 17031997bf2SAndrew Thompson */ 17131997bf2SAndrew Thompson struct ifbaconf { 17231997bf2SAndrew Thompson uint32_t ifbac_len; /* buffer size */ 17331997bf2SAndrew Thompson union { 17431997bf2SAndrew Thompson caddr_t ifbacu_buf; 17531997bf2SAndrew Thompson struct ifbareq *ifbacu_req; 17631997bf2SAndrew Thompson } ifbac_ifbacu; 17731997bf2SAndrew Thompson #define ifbac_buf ifbac_ifbacu.ifbacu_buf 17831997bf2SAndrew Thompson #define ifbac_req ifbac_ifbacu.ifbacu_req 17931997bf2SAndrew Thompson }; 18031997bf2SAndrew Thompson 18131997bf2SAndrew Thompson /* 18231997bf2SAndrew Thompson * Bridge parameter structure. 18331997bf2SAndrew Thompson */ 18431997bf2SAndrew Thompson struct ifbrparam { 18531997bf2SAndrew Thompson union { 18631997bf2SAndrew Thompson uint32_t ifbrpu_int32; 18731997bf2SAndrew Thompson uint16_t ifbrpu_int16; 18831997bf2SAndrew Thompson uint8_t ifbrpu_int8; 18931997bf2SAndrew Thompson } ifbrp_ifbrpu; 19031997bf2SAndrew Thompson }; 19131997bf2SAndrew Thompson #define ifbrp_csize ifbrp_ifbrpu.ifbrpu_int32 /* cache size */ 19231997bf2SAndrew Thompson #define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_int32 /* cache time (sec) */ 19331997bf2SAndrew Thompson #define ifbrp_prio ifbrp_ifbrpu.ifbrpu_int16 /* bridge priority */ 19431997bf2SAndrew Thompson #define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8 /* hello time (sec) */ 19531997bf2SAndrew Thompson #define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_int8 /* fwd time (sec) */ 19631997bf2SAndrew Thompson #define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_int8 /* max age (sec) */ 19731997bf2SAndrew Thompson 19831997bf2SAndrew Thompson #ifdef _KERNEL 19931997bf2SAndrew Thompson /* 20031997bf2SAndrew Thompson * Timekeeping structure used in spanning tree code. 20131997bf2SAndrew Thompson */ 20231997bf2SAndrew Thompson struct bridge_timer { 20331997bf2SAndrew Thompson uint16_t active; 20431997bf2SAndrew Thompson uint16_t value; 20531997bf2SAndrew Thompson }; 20631997bf2SAndrew Thompson 20731997bf2SAndrew Thompson struct bstp_config_unit { 20831997bf2SAndrew Thompson uint64_t cu_rootid; 20931997bf2SAndrew Thompson uint64_t cu_bridge_id; 21031997bf2SAndrew Thompson uint32_t cu_root_path_cost; 21131997bf2SAndrew Thompson uint16_t cu_message_age; 21231997bf2SAndrew Thompson uint16_t cu_max_age; 21331997bf2SAndrew Thompson uint16_t cu_hello_time; 21431997bf2SAndrew Thompson uint16_t cu_forward_delay; 21531997bf2SAndrew Thompson uint16_t cu_port_id; 21631997bf2SAndrew Thompson uint8_t cu_message_type; 21731997bf2SAndrew Thompson uint8_t cu_topology_change_acknowledgment; 21831997bf2SAndrew Thompson uint8_t cu_topology_change; 21931997bf2SAndrew Thompson }; 22031997bf2SAndrew Thompson 22131997bf2SAndrew Thompson struct bstp_tcn_unit { 22231997bf2SAndrew Thompson uint8_t tu_message_type; 22331997bf2SAndrew Thompson }; 22431997bf2SAndrew Thompson 22531997bf2SAndrew Thompson /* 22631997bf2SAndrew Thompson * Bridge interface list entry. 22731997bf2SAndrew Thompson */ 22831997bf2SAndrew Thompson struct bridge_iflist { 22931997bf2SAndrew Thompson LIST_ENTRY(bridge_iflist) bif_next; 23031997bf2SAndrew Thompson uint64_t bif_designated_root; 23131997bf2SAndrew Thompson uint64_t bif_designated_bridge; 23231997bf2SAndrew Thompson uint32_t bif_path_cost; 23331997bf2SAndrew Thompson uint32_t bif_designated_cost; 23431997bf2SAndrew Thompson struct bridge_timer bif_hold_timer; 23531997bf2SAndrew Thompson struct bridge_timer bif_message_age_timer; 23631997bf2SAndrew Thompson struct bridge_timer bif_forward_delay_timer; 23731997bf2SAndrew Thompson struct bstp_config_unit bif_config_bpdu; 23831997bf2SAndrew Thompson uint16_t bif_port_id; 23931997bf2SAndrew Thompson uint16_t bif_designated_port; 24031997bf2SAndrew Thompson uint8_t bif_state; 24131997bf2SAndrew Thompson uint8_t bif_topology_change_acknowledge; 24231997bf2SAndrew Thompson uint8_t bif_config_pending; 24331997bf2SAndrew Thompson uint8_t bif_change_detection_enabled; 24431997bf2SAndrew Thompson uint8_t bif_priority; 24531997bf2SAndrew Thompson struct ifnet *bif_ifp; /* member if */ 24631997bf2SAndrew Thompson uint32_t bif_flags; /* member if flags */ 24731997bf2SAndrew Thompson }; 24831997bf2SAndrew Thompson 24931997bf2SAndrew Thompson /* 25031997bf2SAndrew Thompson * Bridge route node. 25131997bf2SAndrew Thompson */ 25231997bf2SAndrew Thompson struct bridge_rtnode { 25331997bf2SAndrew Thompson LIST_ENTRY(bridge_rtnode) brt_hash; /* hash table linkage */ 25431997bf2SAndrew Thompson LIST_ENTRY(bridge_rtnode) brt_list; /* list linkage */ 25531997bf2SAndrew Thompson struct ifnet *brt_ifp; /* destination if */ 25631997bf2SAndrew Thompson unsigned long brt_expire; /* expiration time */ 25731997bf2SAndrew Thompson uint8_t brt_flags; /* address flags */ 25831997bf2SAndrew Thompson uint8_t brt_addr[ETHER_ADDR_LEN]; 25931997bf2SAndrew Thompson }; 26031997bf2SAndrew Thompson 26131997bf2SAndrew Thompson /* 26231997bf2SAndrew Thompson * Software state for each bridge. 26331997bf2SAndrew Thompson */ 26431997bf2SAndrew Thompson struct bridge_softc { 26531997bf2SAndrew Thompson struct arpcom ifb_ac; /* make this an interface */ 26631997bf2SAndrew Thompson LIST_ENTRY(bridge_softc) sc_list; 26731997bf2SAndrew Thompson struct mtx sc_mtx; 26831997bf2SAndrew Thompson struct cv sc_cv; 26931997bf2SAndrew Thompson uint64_t sc_designated_root; 27031997bf2SAndrew Thompson uint64_t sc_bridge_id; 27131997bf2SAndrew Thompson struct bridge_iflist *sc_root_port; 27231997bf2SAndrew Thompson uint32_t sc_root_path_cost; 27331997bf2SAndrew Thompson uint16_t sc_max_age; 27431997bf2SAndrew Thompson uint16_t sc_hello_time; 27531997bf2SAndrew Thompson uint16_t sc_forward_delay; 27631997bf2SAndrew Thompson uint16_t sc_bridge_max_age; 27731997bf2SAndrew Thompson uint16_t sc_bridge_hello_time; 27831997bf2SAndrew Thompson uint16_t sc_bridge_forward_delay; 27931997bf2SAndrew Thompson uint16_t sc_topology_change_time; 28031997bf2SAndrew Thompson uint16_t sc_hold_time; 28131997bf2SAndrew Thompson uint16_t sc_bridge_priority; 28231997bf2SAndrew Thompson uint8_t sc_topology_change_detected; 28331997bf2SAndrew Thompson uint8_t sc_topology_change; 28431997bf2SAndrew Thompson struct bridge_timer sc_hello_timer; 28531997bf2SAndrew Thompson struct bridge_timer sc_topology_change_timer; 28631997bf2SAndrew Thompson struct bridge_timer sc_tcn_timer; 28731997bf2SAndrew Thompson uint32_t sc_brtmax; /* max # of addresses */ 28831997bf2SAndrew Thompson uint32_t sc_brtcnt; /* cur. # of addresses */ 28931997bf2SAndrew Thompson uint32_t sc_brttimeout; /* rt timeout in seconds */ 29031997bf2SAndrew Thompson struct callout sc_brcallout; /* bridge callout */ 29131997bf2SAndrew Thompson struct callout sc_bstpcallout; /* STP callout */ 29231997bf2SAndrew Thompson uint32_t sc_iflist_ref; /* refcount for sc_iflist */ 29331997bf2SAndrew Thompson uint32_t sc_iflist_xcnt; /* refcount for sc_iflist */ 29431997bf2SAndrew Thompson LIST_HEAD(, bridge_iflist) sc_iflist; /* member interface list */ 29531997bf2SAndrew Thompson LIST_HEAD(, bridge_rtnode) *sc_rthash; /* our forwarding table */ 29631997bf2SAndrew Thompson LIST_HEAD(, bridge_rtnode) sc_rtlist; /* list version of above */ 29731997bf2SAndrew Thompson uint32_t sc_rthash_key; /* key for hash */ 29831997bf2SAndrew Thompson }; 29931997bf2SAndrew Thompson 30031997bf2SAndrew Thompson #define BRIDGE_LOCK_INIT(_sc) do { \ 30131997bf2SAndrew Thompson mtx_init(&(_sc)->sc_mtx, "if_bridge", NULL, MTX_DEF); \ 30231997bf2SAndrew Thompson cv_init(&(_sc)->sc_cv, "if_bridge_cv"); \ 30331997bf2SAndrew Thompson } while (0) 30431997bf2SAndrew Thompson #define BRIDGE_LOCK_DESTROY(_sc) do { \ 30531997bf2SAndrew Thompson mtx_destroy(&(_sc)->sc_mtx); \ 30631997bf2SAndrew Thompson cv_destroy(&(_sc)->sc_cv); \ 30731997bf2SAndrew Thompson } while (0) 30831997bf2SAndrew Thompson #define BRIDGE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 30931997bf2SAndrew Thompson #define BRIDGE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 31031997bf2SAndrew Thompson #define BRIDGE_LOCKED(_sc) mtx_owned(&(_sc)->sc_mtx) 31131997bf2SAndrew Thompson #define BRIDGE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED) 31231997bf2SAndrew Thompson #define BRIDGE_LOCK2REF(_sc, _err) do { \ 31331997bf2SAndrew Thompson mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \ 31431997bf2SAndrew Thompson if ((_sc)->sc_iflist_xcnt > 0) \ 31531997bf2SAndrew Thompson (_err) = EBUSY; \ 31631997bf2SAndrew Thompson else \ 31731997bf2SAndrew Thompson (_sc)->sc_iflist_ref++; \ 31831997bf2SAndrew Thompson mtx_unlock(&(_sc)->sc_mtx); \ 31931997bf2SAndrew Thompson } while (0) 32031997bf2SAndrew Thompson #define BRIDGE_UNREF(_sc) do { \ 32131997bf2SAndrew Thompson mtx_lock(&(_sc)->sc_mtx); \ 32231997bf2SAndrew Thompson (_sc)->sc_iflist_ref--; \ 32331997bf2SAndrew Thompson if (((_sc)->sc_iflist_xcnt > 0) && ((_sc)->sc_iflist_ref == 0)) \ 32431997bf2SAndrew Thompson cv_broadcast(&(_sc)->sc_cv); \ 32531997bf2SAndrew Thompson mtx_unlock(&(_sc)->sc_mtx); \ 32631997bf2SAndrew Thompson } while (0) 32731997bf2SAndrew Thompson #define BRIDGE_XLOCK(_sc) do { \ 32831997bf2SAndrew Thompson mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \ 32931997bf2SAndrew Thompson (_sc)->sc_iflist_xcnt++; \ 33031997bf2SAndrew Thompson while ((_sc)->sc_iflist_ref > 0) \ 33131997bf2SAndrew Thompson cv_wait(&(_sc)->sc_cv, &(_sc)->sc_mtx); \ 33231997bf2SAndrew Thompson } while (0) 33331997bf2SAndrew Thompson #define BRIDGE_XDROP(_sc) do { \ 33431997bf2SAndrew Thompson mtx_assert(&(_sc)->sc_mtx, MA_OWNED); \ 33531997bf2SAndrew Thompson (_sc)->sc_iflist_xcnt--; \ 33631997bf2SAndrew Thompson } while (0) 33731997bf2SAndrew Thompson 33831997bf2SAndrew Thompson extern const uint8_t bstp_etheraddr[]; 33931997bf2SAndrew Thompson 34031997bf2SAndrew Thompson void bridge_ifdetach(struct ifnet *); 34131997bf2SAndrew Thompson void bridge_rtdelete(struct bridge_softc *, struct ifnet *ifp, int); 34231997bf2SAndrew Thompson 34331997bf2SAndrew Thompson int bridge_output(struct ifnet *, struct mbuf *, struct sockaddr *, 34431997bf2SAndrew Thompson struct rtentry *); 34531997bf2SAndrew Thompson struct mbuf *bridge_input(struct ifnet *, struct mbuf *); 34631997bf2SAndrew Thompson 34731997bf2SAndrew Thompson extern void (*bstp_linkstate_p)(struct ifnet *ifp, int state); 34831997bf2SAndrew Thompson 34931997bf2SAndrew Thompson void bstp_initialization(struct bridge_softc *); 35031997bf2SAndrew Thompson void bstp_linkstate(struct ifnet *, int); 35131997bf2SAndrew Thompson void bstp_stop(struct bridge_softc *); 35231997bf2SAndrew Thompson struct mbuf *bstp_input(struct ifnet *, struct mbuf *); 35331997bf2SAndrew Thompson 35431997bf2SAndrew Thompson void bridge_enqueue(struct bridge_softc *, struct ifnet *, struct mbuf *, 35531997bf2SAndrew Thompson int); 35631997bf2SAndrew Thompson 35731997bf2SAndrew Thompson #endif /* _KERNEL */ 358