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/bridge.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 /*
    2  * Copyright (c) 1998 Luigi Rizzo
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
   10  *    notice, this list of conditions and the following disclaimer in the
   11  *    documentation and/or other materials provided with the distribution.
   12  *
   13  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   23  * SUCH DAMAGE.
   24  *
   25  */
   26 
   27 extern int do_bridge;
   28 /*
   29  * the hash table for bridge
   30  */
   31 typedef struct hash_table {
   32     struct ifnet *name ;
   33     u_char etheraddr[6] ;
   34     u_short used ;
   35 } bdg_hash_table ;
   36 
   37 extern bdg_hash_table *bdg_table ;
   38 
   39 #define BDG_MAX_PORTS 128
   40 extern unsigned char bdg_addresses[6*BDG_MAX_PORTS];
   41 extern int bdg_ports ;
   42 
   43 /*
   44  * out of the 6 bytes, the last ones are more "variable". Since
   45  * we are on a little endian machine, we have to do some gimmick...
   46  */
   47 #define HASH_SIZE 8192  /* must be a power of 2 */
   48 #define HASH_FN(addr)   (       \
   49         ntohs( ((short *)addr)[1] ^ ((short *)addr)[2] ) & (HASH_SIZE -1))
   50 
   51 #define IFF_MUTE        IFF_LINK2       /* will need a separate flag... */
   52 
   53 struct ifnet *bridge_in(struct mbuf *m);
   54 /* bdg_forward frees the mbuf if necessary, returning null */
   55 int bdg_forward (struct mbuf **m, struct ifnet *dst);
   56 
   57 #ifdef __i386__
   58 #define BDG_MATCH(a,b) ( \
   59     ((unsigned short *)(a))[2] == ((unsigned short *)(b))[2] && \
   60     *((unsigned int *)(a)) == *((unsigned int *)(b)) )
   61 #define IS_ETHER_BROADCAST(a) ( \
   62         *((unsigned int *)(a)) == 0xffffffff && \
   63         ((unsigned short *)(a))[2] == 0xffff )
   64 #else
   65 #warning... must complete these for the alpha etc.
   66 #define BDG_MATCH(a,b) (!bcmp(a, b, ETHER_ADDR_LEN) )
   67 #endif
   68 /*
   69  * The following constants are not legal ifnet pointers, and are used
   70  * as return values from the classifier, bridge_dst_lookup()
   71  * The same values are used as index in the statistics arrays,
   72  * with BDG_FORWARD replacing specifically forwarded packets.
   73  */
   74 #define BDG_BCAST       ( (struct ifnet *)1 )
   75 #define BDG_MCAST       ( (struct ifnet *)2 )
   76 #define BDG_LOCAL       ( (struct ifnet *)3 )
   77 #define BDG_DROP        ( (struct ifnet *)4 )
   78 #define BDG_UNKNOWN     ( (struct ifnet *)5 )
   79 #define BDG_IN          ( (struct ifnet *)7 )
   80 #define BDG_OUT         ( (struct ifnet *)8 )
   81 #define BDG_FORWARD     ( (struct ifnet *)9 )
   82 
   83 #define PF_BDG 3 /* XXX superhack */
   84 /*
   85  * statistics, passed up with sysctl interface and ns -p bdg
   86  */
   87 
   88 #define STAT_MAX (int)BDG_FORWARD
   89 struct bdg_port_stat {
   90     char name[16];
   91     u_long collisions;
   92     u_long p_in[STAT_MAX+1];
   93 } ;
   94 
   95 struct bdg_stats {
   96     struct bdg_port_stat s[16];
   97 } ;
   98 
   99 
  100 #define BDG_STAT(ifp, type) bdg_stats.s[ifp->if_index].p_in[(int)type]++ 
  101  
  102 #ifdef KERNEL
  103 /*
  104  * Find the right pkt destination:
  105  *      BDG_BCAST       is a broadcast
  106  *      BDG_MCAST       is a multicast
  107  *      BDG_LOCAL       is for a local address
  108  *      BDG_DROP        must be dropped
  109  *      other           ifp of the dest. interface (incl.self)
  110  */
  111 static inline
  112 struct ifnet *
  113 bridge_dst_lookup(struct mbuf *m)
  114 {
  115     struct ether_header *eh = mtod(m, struct ether_header *);
  116     struct ifnet *dst ;
  117     int index ;
  118     u_char *eth_addr = bdg_addresses ;
  119 
  120     if (IS_ETHER_BROADCAST(eh->ether_dhost))
  121         return BDG_BCAST ;
  122     if (eh->ether_dhost[0] & 1)
  123         return BDG_MCAST ;
  124     /*
  125      * Lookup local addresses in case one matches.
  126      */
  127     for (index = bdg_ports, eth_addr = bdg_addresses ;
  128                  index ; index--, eth_addr += 6 )
  129         if (BDG_MATCH(eth_addr, eh->ether_dhost) )
  130             return BDG_LOCAL ;
  131     /*
  132      * Look for a possible destination in table
  133      */
  134     index= HASH_FN( eh->ether_dhost );
  135     dst = bdg_table[index].name;
  136     if ( dst && BDG_MATCH( bdg_table[index].etheraddr, eh->ether_dhost) )
  137         return dst ;
  138     else
  139         return BDG_UNKNOWN ;
  140 }
  141 
  142 #endif /* KERNEL */

Cache object: 92989867799816765f55c1435e3be955


[ 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.