The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/net/if_bridgevar.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: if_bridgevar.h,v 1.4 2003/07/08 07:13:50 itojun Exp $  */
    2 
    3 /*
    4  * Copyright 2001 Wasabi Systems, Inc.
    5  * All rights reserved.
    6  *
    7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  * 1. Redistributions of source code must retain the above copyright
   13  *    notice, this list of conditions and the following disclaimer.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  * 3. All advertising materials mentioning features or use of this software
   18  *    must display the following acknowledgement:
   19  *      This product includes software developed for the NetBSD Project by
   20  *      Wasabi Systems, Inc.
   21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
   22  *    or promote products derived from this software without specific prior
   23  *    written permission.
   24  *
   25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
   26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
   29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   35  * POSSIBILITY OF SUCH DAMAGE.
   36  */
   37 
   38 /*
   39  * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
   40  * All rights reserved.
   41  *
   42  * Redistribution and use in source and binary forms, with or without
   43  * modification, are permitted provided that the following conditions
   44  * are met:
   45  * 1. Redistributions of source code must retain the above copyright
   46  *    notice, this list of conditions and the following disclaimer.
   47  * 2. Redistributions in binary form must reproduce the above copyright
   48  *    notice, this list of conditions and the following disclaimer in the
   49  *    documentation and/or other materials provided with the distribution.
   50  * 3. All advertising materials mentioning features or use of this software
   51  *    must display the following acknowledgement:
   52  *      This product includes software developed by Jason L. Wright
   53  * 4. The name of the author may not be used to endorse or promote products
   54  *    derived from this software without specific prior written permission.
   55  *
   56  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   57  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   58  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   59  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
   60  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   61  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   62  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   63  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   64  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   65  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   66  * POSSIBILITY OF SUCH DAMAGE.
   67  *
   68  * OpenBSD: if_bridge.h,v 1.14 2001/03/22 03:48:29 jason Exp
   69  *
   70  * $FreeBSD: releng/6.2/sys/net/if_bridgevar.h 163589 2006-10-21 19:10:39Z thompsa $
   71  */
   72 
   73 /*
   74  * Data structure and control definitions for bridge interfaces.
   75  */
   76 
   77 #include <sys/callout.h>
   78 #include <sys/queue.h>
   79 #include <sys/condvar.h>
   80 
   81 /*
   82  * Commands used in the SIOCSDRVSPEC ioctl.  Note the lookup of the
   83  * bridge interface itself is keyed off the ifdrv structure.
   84  */
   85 #define BRDGADD                 0       /* add bridge member (ifbreq) */
   86 #define BRDGDEL                 1       /* delete bridge member (ifbreq) */
   87 #define BRDGGIFFLGS             2       /* get member if flags (ifbreq) */
   88 #define BRDGSIFFLGS             3       /* set member if flags (ifbreq) */
   89 #define BRDGSCACHE              4       /* set cache size (ifbrparam) */
   90 #define BRDGGCACHE              5       /* get cache size (ifbrparam) */
   91 #define BRDGGIFS                6       /* get member list (ifbifconf) */
   92 #define BRDGRTS                 7       /* get address list (ifbaconf) */
   93 #define BRDGSADDR               8       /* set static address (ifbareq) */
   94 #define BRDGSTO                 9       /* set cache timeout (ifbrparam) */
   95 #define BRDGGTO                 10      /* get cache timeout (ifbrparam) */
   96 #define BRDGDADDR               11      /* delete address (ifbareq) */
   97 #define BRDGFLUSH               12      /* flush address cache (ifbreq) */
   98 
   99 #define BRDGGPRI                13      /* get priority (ifbrparam) */
  100 #define BRDGSPRI                14      /* set priority (ifbrparam) */
  101 #define BRDGGHT                 15      /* get hello time (ifbrparam) */
  102 #define BRDGSHT                 16      /* set hello time (ifbrparam) */
  103 #define BRDGGFD                 17      /* get forward delay (ifbrparam) */
  104 #define BRDGSFD                 18      /* set forward delay (ifbrparam) */
  105 #define BRDGGMA                 19      /* get max age (ifbrparam) */
  106 #define BRDGSMA                 20      /* set max age (ifbrparam) */
  107 #define BRDGSIFPRIO             21      /* set if priority (ifbreq) */
  108 #define BRDGSIFCOST             22      /* set if path cost (ifbreq) */
  109 #define BRDGADDS                23      /* add bridge span member (ifbreq) */
  110 #define BRDGDELS                24      /* delete bridge span member (ifbreq) */
  111 #define BRDGPARAM               25      /* get bridge STP params (ifbropreq) */
  112 #define BRDGGRTE                26      /* get cache drops (ifbrparam) */
  113 #define BRDGGIFSSTP             27      /* get member STP params list
  114                                          * (ifbpstpconf) */
  115 
  116 /*
  117  * Generic bridge control request.
  118  */
  119 struct ifbreq {
  120         char            ifbr_ifsname[IFNAMSIZ]; /* member if name */
  121         uint32_t        ifbr_ifsflags;          /* member if flags */
  122         uint8_t         ifbr_state;             /* member if STP state */
  123         uint8_t         ifbr_priority;          /* member if STP priority */
  124         uint8_t         ifbr_path_cost;         /* member if STP cost */
  125         uint8_t         ifbr_portno;            /* member if port number */
  126 };
  127 
  128 /* BRDGGIFFLAGS, BRDGSIFFLAGS */
  129 #define IFBIF_LEARNING          0x01    /* if can learn */
  130 #define IFBIF_DISCOVER          0x02    /* if sends packets w/ unknown dest. */
  131 #define IFBIF_STP               0x04    /* if participates in spanning tree */
  132 #define IFBIF_SPAN              0x08    /* if is a span port */
  133 
  134 #define IFBIFBITS       "\020\1LEARNING\2DISCOVER\3STP\4SPAN"
  135 
  136 /* BRDGFLUSH */
  137 #define IFBF_FLUSHDYN           0x00    /* flush learned addresses only */
  138 #define IFBF_FLUSHALL           0x01    /* flush all addresses */
  139 
  140 /* STP port states */
  141 #define BSTP_IFSTATE_DISABLED   0
  142 #define BSTP_IFSTATE_LISTENING  1
  143 #define BSTP_IFSTATE_LEARNING   2
  144 #define BSTP_IFSTATE_FORWARDING 3
  145 #define BSTP_IFSTATE_BLOCKING   4
  146 
  147 /*
  148  * Interface list structure.
  149  */
  150 struct ifbifconf {
  151         uint32_t        ifbic_len;      /* buffer size */
  152         union {
  153                 caddr_t ifbicu_buf;
  154                 struct ifbreq *ifbicu_req;
  155         } ifbic_ifbicu;
  156 #define ifbic_buf       ifbic_ifbicu.ifbicu_buf
  157 #define ifbic_req       ifbic_ifbicu.ifbicu_req
  158 };
  159 
  160 /*
  161  * Bridge address request.
  162  */
  163 struct ifbareq {
  164         char            ifba_ifsname[IFNAMSIZ]; /* member if name */
  165         unsigned long   ifba_expire;            /* address expire time */
  166         uint8_t         ifba_flags;             /* address flags */
  167         uint8_t         ifba_dst[ETHER_ADDR_LEN];/* destination address */
  168 };
  169 
  170 #define IFBAF_TYPEMASK  0x03    /* address type mask */
  171 #define IFBAF_DYNAMIC   0x00    /* dynamically learned address */
  172 #define IFBAF_STATIC    0x01    /* static address */
  173 
  174 #define IFBAFBITS       "\020\1STATIC"
  175 
  176 /*
  177  * Address list structure.
  178  */
  179 struct ifbaconf {
  180         uint32_t        ifbac_len;      /* buffer size */
  181         union {
  182                 caddr_t ifbacu_buf;
  183                 struct ifbareq *ifbacu_req;
  184         } ifbac_ifbacu;
  185 #define ifbac_buf       ifbac_ifbacu.ifbacu_buf
  186 #define ifbac_req       ifbac_ifbacu.ifbacu_req
  187 };
  188 
  189 /*
  190  * Bridge parameter structure.
  191  */
  192 struct ifbrparam {
  193         union {
  194                 uint32_t ifbrpu_int32;
  195                 uint16_t ifbrpu_int16;
  196                 uint8_t ifbrpu_int8;
  197         } ifbrp_ifbrpu;
  198 };
  199 #define ifbrp_csize     ifbrp_ifbrpu.ifbrpu_int32       /* cache size */
  200 #define ifbrp_ctime     ifbrp_ifbrpu.ifbrpu_int32       /* cache time (sec) */
  201 #define ifbrp_prio      ifbrp_ifbrpu.ifbrpu_int16       /* bridge priority */
  202 #define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_int8        /* hello time (sec) */
  203 #define ifbrp_fwddelay  ifbrp_ifbrpu.ifbrpu_int8        /* fwd time (sec) */
  204 #define ifbrp_maxage    ifbrp_ifbrpu.ifbrpu_int8        /* max age (sec) */
  205 #define ifbrp_cexceeded ifbrp_ifbrpu.ifbrpu_int32       /* # of cache dropped
  206                                                          * adresses */
  207 /*
  208  * Bridge current operational parameters structure.
  209  */
  210 struct ifbropreq {
  211         uint8_t         ifbop_maxage;
  212         uint8_t         ifbop_hellotime;
  213         uint8_t         ifbop_fwddelay;
  214         uint16_t        ifbop_root_port;
  215         uint32_t        ifbop_root_path_cost;
  216         uint64_t        ifbop_designated_root;
  217         struct timeval  ifbop_last_tc_time;
  218 };
  219 
  220 /*
  221  * Bridge member operational STP params structure.
  222  */
  223 struct ifbpstpreq {
  224         uint8_t         ifbp_portno;            /* bp STP port number */
  225         uint32_t        ifbp_fwd_trans;         /* bp STP fwd transitions */
  226         uint32_t        ifbp_design_cost;       /* bp STP designated cost */
  227         uint32_t        ifbp_design_port;       /* bp STP designated port */
  228         uint64_t        ifbp_design_bridge;     /* bp STP designated bridge */
  229         uint64_t        ifbp_design_root;       /* bp STP designated root */
  230 };
  231 
  232 /*
  233  * Bridge STP ports list structure.
  234  */
  235 struct ifbpstpconf {
  236         uint32_t        ifbpstp_len;    /* buffer size */
  237         union {
  238                 caddr_t ifbpstpu_buf;
  239                 struct ifbpstpreq *ifbpstpu_req;
  240         } ifbpstp_ifbpstpu;
  241 #define ifbpstp_buf     ifbpstp_ifbpstpu.ifbpstpu_buf
  242 #define ifbpstp_req     ifbpstp_ifbpstpu.ifbpstpu_req
  243 };
  244 
  245 #ifdef _KERNEL
  246 /*
  247  * Timekeeping structure used in spanning tree code.
  248  */
  249 struct bridge_timer {
  250         uint16_t        active;
  251         uint16_t        value;
  252 };
  253 
  254 struct bstp_config_unit {
  255         uint64_t        cu_rootid;
  256         uint64_t        cu_bridge_id;
  257         uint32_t        cu_root_path_cost;
  258         uint16_t        cu_message_age;
  259         uint16_t        cu_max_age;
  260         uint16_t        cu_hello_time;
  261         uint16_t        cu_forward_delay;
  262         uint16_t        cu_port_id;
  263         uint8_t         cu_message_type;
  264         uint8_t         cu_topology_change_acknowledgment;
  265         uint8_t         cu_topology_change;
  266 };
  267 
  268 struct bstp_tcn_unit {
  269         uint8_t         tu_message_type;
  270 };
  271 
  272 /*
  273  * Bridge interface list entry.
  274  */
  275 struct bridge_iflist {
  276         LIST_ENTRY(bridge_iflist) bif_next;
  277         uint64_t                bif_designated_root;
  278         uint64_t                bif_designated_bridge;
  279         uint32_t                bif_path_cost;
  280         uint32_t                bif_designated_cost;
  281         struct bridge_timer     bif_hold_timer;
  282         struct bridge_timer     bif_message_age_timer;
  283         struct bridge_timer     bif_forward_delay_timer;
  284         struct bstp_config_unit bif_config_bpdu;
  285         uint16_t                bif_port_id;
  286         uint16_t                bif_designated_port;
  287         uint8_t                 bif_state;
  288         uint8_t                 bif_topology_change_acknowledge;
  289         uint8_t                 bif_config_pending;
  290         uint8_t                 bif_change_detection_enabled;
  291         uint8_t                 bif_priority;
  292         struct ifnet            *bif_ifp;       /* member if */
  293         uint32_t                bif_flags;      /* member if flags */
  294         int                     bif_mutecap;    /* member muted caps */
  295         uint32_t                bif_forward_transitions;
  296 };
  297 
  298 /*
  299  * Bridge route node.
  300  */
  301 struct bridge_rtnode {
  302         LIST_ENTRY(bridge_rtnode) brt_hash;     /* hash table linkage */
  303         LIST_ENTRY(bridge_rtnode) brt_list;     /* list linkage */
  304         struct ifnet            *brt_ifp;       /* destination if */
  305         unsigned long           brt_expire;     /* expiration time */
  306         uint8_t                 brt_flags;      /* address flags */
  307         uint8_t                 brt_addr[ETHER_ADDR_LEN];
  308 };
  309 
  310 /*
  311  * Software state for each bridge.
  312  */
  313 struct bridge_softc {
  314         struct ifnet            *sc_ifp;        /* make this an interface */
  315         LIST_ENTRY(bridge_softc) sc_list;
  316         struct mtx              sc_mtx;
  317         struct cv               sc_cv;
  318         uint64_t                sc_designated_root;
  319         uint64_t                sc_bridge_id;
  320         struct bridge_iflist    *sc_root_port;
  321         uint32_t                sc_root_path_cost;
  322         uint16_t                sc_max_age;
  323         uint16_t                sc_hello_time;
  324         uint16_t                sc_forward_delay;
  325         uint16_t                sc_bridge_max_age;
  326         uint16_t                sc_bridge_hello_time;
  327         uint16_t                sc_bridge_forward_delay;
  328         uint16_t                sc_topology_change_time;
  329         uint16_t                sc_hold_time;
  330         uint16_t                sc_bridge_priority;
  331         uint8_t                 sc_topology_change_detected;
  332         uint8_t                 sc_topology_change;
  333         struct bridge_timer     sc_hello_timer;
  334         struct bridge_timer     sc_topology_change_timer;
  335         struct bridge_timer     sc_tcn_timer;
  336         uint32_t                sc_brtmax;      /* max # of addresses */
  337         uint32_t                sc_brtcnt;      /* cur. # of addresses */
  338         uint32_t                sc_brttimeout;  /* rt timeout in seconds */
  339         struct callout          sc_brcallout;   /* bridge callout */
  340         struct callout          sc_bstpcallout; /* STP callout */
  341         uint32_t                sc_iflist_ref;  /* refcount for sc_iflist */
  342         uint32_t                sc_iflist_xcnt; /* refcount for sc_iflist */
  343         LIST_HEAD(, bridge_iflist) sc_iflist;   /* member interface list */
  344         LIST_HEAD(, bridge_rtnode) *sc_rthash;  /* our forwarding table */
  345         LIST_HEAD(, bridge_rtnode) sc_rtlist;   /* list version of above */
  346         uint32_t                sc_rthash_key;  /* key for hash */
  347         LIST_HEAD(, bridge_iflist) sc_spanlist; /* span ports list */
  348         struct bridge_timer     sc_link_timer;
  349         uint32_t                sc_brtexceeded; /* # of cache drops */
  350         struct timeval          sc_last_tc_time;
  351 };
  352 
  353 #define BRIDGE_LOCK_INIT(_sc)           do {                    \
  354         mtx_init(&(_sc)->sc_mtx, "if_bridge", NULL, MTX_DEF);   \
  355         cv_init(&(_sc)->sc_cv, "if_bridge_cv");                 \
  356 } while (0)
  357 #define BRIDGE_LOCK_DESTROY(_sc)        do {    \
  358         mtx_destroy(&(_sc)->sc_mtx);            \
  359         cv_destroy(&(_sc)->sc_cv);              \
  360 } while (0)
  361 #define BRIDGE_LOCK(_sc)                mtx_lock(&(_sc)->sc_mtx)
  362 #define BRIDGE_UNLOCK(_sc)              mtx_unlock(&(_sc)->sc_mtx)
  363 #define BRIDGE_LOCKED(_sc)              mtx_owned(&(_sc)->sc_mtx)
  364 #define BRIDGE_LOCK_ASSERT(_sc)         mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
  365 #define BRIDGE_LOCK2REF(_sc, _err)      do {    \
  366         mtx_assert(&(_sc)->sc_mtx, MA_OWNED);   \
  367         if ((_sc)->sc_iflist_xcnt > 0)          \
  368                 (_err) = EBUSY;                 \
  369         else                                    \
  370                 (_sc)->sc_iflist_ref++;         \
  371         mtx_unlock(&(_sc)->sc_mtx);             \
  372 } while (0)
  373 #define BRIDGE_UNREF(_sc)               do {                            \
  374         mtx_lock(&(_sc)->sc_mtx);                                       \
  375         (_sc)->sc_iflist_ref--;                                         \
  376         if (((_sc)->sc_iflist_xcnt > 0) && ((_sc)->sc_iflist_ref == 0)) \
  377                 cv_broadcast(&(_sc)->sc_cv);                            \
  378         mtx_unlock(&(_sc)->sc_mtx);                                     \
  379 } while (0)
  380 #define BRIDGE_XLOCK(_sc)               do {            \
  381         mtx_assert(&(_sc)->sc_mtx, MA_OWNED);           \
  382         (_sc)->sc_iflist_xcnt++;                        \
  383         while ((_sc)->sc_iflist_ref > 0)                \
  384                 cv_wait(&(_sc)->sc_cv, &(_sc)->sc_mtx); \
  385 } while (0)
  386 #define BRIDGE_XDROP(_sc)               do {    \
  387         mtx_assert(&(_sc)->sc_mtx, MA_OWNED);   \
  388         (_sc)->sc_iflist_xcnt--;                \
  389 } while (0)
  390 
  391 #define BRIDGE_INPUT(_ifp, _m)          do {            \
  392         KASSERT(bridge_input_p != NULL,                 \
  393             ("%s: if_bridge not loaded!", __func__));   \
  394         _m = (*bridge_input_p)(_ifp, _m);               \
  395         if (_m != NULL)                                 \
  396                 _ifp = _m->m_pkthdr.rcvif;              \
  397 } while (0)
  398 
  399 #define BRIDGE_OUTPUT(_ifp, _m, _err)   do {                    \
  400         KASSERT(bridge_output_p != NULL,                        \
  401             ("%s: if_bridge not loaded!", __func__));           \
  402         _err = (*bridge_output_p)(_ifp, _m, NULL, NULL);        \
  403 } while (0)
  404 
  405 extern const uint8_t bstp_etheraddr[];
  406 
  407 void    bridge_enqueue(struct bridge_softc *, struct ifnet *, struct mbuf *);
  408 void    bridge_rtdelete(struct bridge_softc *, struct ifnet *ifp, int);
  409 
  410 extern  struct mbuf *(*bridge_input_p)(struct ifnet *, struct mbuf *);
  411 extern  int (*bridge_output_p)(struct ifnet *, struct mbuf *,
  412                 struct sockaddr *, struct rtentry *);
  413 extern  void (*bridge_dn_p)(struct mbuf *, struct ifnet *);
  414 extern  void (*bstp_linkstate_p)(struct ifnet *ifp, int state);
  415 
  416 void    bstp_initialization(struct bridge_softc *);
  417 void    bstp_linkstate(struct ifnet *, int);
  418 void    bstp_stop(struct bridge_softc *);
  419 struct mbuf *bstp_input(struct ifnet *, struct mbuf *);
  420 
  421 
  422 #endif /* _KERNEL */

Cache object: 7110fbc98f3c72e5e998ac699f8e9a48


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.