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_llatbl.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) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
    3  * Copyright (c) 2004-2008 Qing Li. All rights reserved.
    4  * Copyright (c) 2008 Kip Macy. All rights reserved.
    5  * 
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 
   15  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  */
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: releng/8.3/sys/net/if_llatbl.h 226235 2011-10-10 21:34:55Z qingli $");
   29 
   30 #ifndef _NET_IF_LLATBL_H_
   31 #define _NET_IF_LLATBL_H_
   32 
   33 #include <sys/_rwlock.h>
   34 #include <netinet/in.h>
   35 
   36 struct ifnet;
   37 struct sysctl_req;
   38 struct rt_msghdr;
   39 struct rt_addrinfo;
   40 
   41 struct llentry;
   42 LIST_HEAD(llentries, llentry);
   43 
   44 extern struct rwlock lltable_rwlock;
   45 #define LLTABLE_RLOCK()         rw_rlock(&lltable_rwlock)
   46 #define LLTABLE_RUNLOCK()       rw_runlock(&lltable_rwlock)
   47 #define LLTABLE_WLOCK()         rw_wlock(&lltable_rwlock)
   48 #define LLTABLE_WUNLOCK()       rw_wunlock(&lltable_rwlock)
   49 #define LLTABLE_LOCK_ASSERT()   rw_assert(&lltable_rwlock, RA_LOCKED)
   50 
   51 /*
   52  * Code referencing llentry must at least hold
   53  * a shared lock
   54  */
   55 struct llentry {
   56         LIST_ENTRY(llentry)      lle_next;
   57         struct rwlock            lle_lock;
   58         struct lltable           *lle_tbl;
   59         struct llentries         *lle_head;
   60         struct mbuf              *la_hold;
   61         int                      la_numheld;  /* # of packets currently held */
   62         time_t                   la_expire;
   63         uint16_t                 la_flags;    
   64         uint16_t                 la_asked;
   65         uint16_t                 la_preempt;
   66         uint16_t                 ln_byhint;
   67         int16_t                  ln_state;      /* IPv6 has ND6_LLINFO_NOSTATE == -2 */
   68         uint16_t                 ln_router; 
   69         time_t                   ln_ntick;
   70         int                      lle_refcnt;
   71                                  
   72         union {
   73                 uint64_t        mac_aligned;
   74                 uint16_t        mac16[3];
   75         } ll_addr;
   76 
   77         /* XXX af-private? */
   78         union {
   79                 struct callout  ln_timer_ch;
   80                 struct callout  la_timer;
   81         } lle_timer;
   82         /* NB: struct sockaddr must immediately follow */
   83 };
   84 
   85 #define LLE_WLOCK(lle)          rw_wlock(&(lle)->lle_lock)
   86 #define LLE_RLOCK(lle)          rw_rlock(&(lle)->lle_lock)
   87 #define LLE_WUNLOCK(lle)        rw_wunlock(&(lle)->lle_lock)
   88 #define LLE_RUNLOCK(lle)        rw_runlock(&(lle)->lle_lock)
   89 #define LLE_DOWNGRADE(lle)      rw_downgrade(&(lle)->lle_lock)
   90 #define LLE_TRY_UPGRADE(lle)    rw_try_upgrade(&(lle)->lle_lock)
   91 #define LLE_LOCK_INIT(lle)      rw_init_flags(&(lle)->lle_lock, "lle", RW_DUPOK)
   92 #define LLE_LOCK_DESTROY(lle)   rw_destroy(&(lle)->lle_lock)
   93 #define LLE_WLOCK_ASSERT(lle)   rw_assert(&(lle)->lle_lock, RA_WLOCKED)
   94 
   95 #define LLE_IS_VALID(lle)       (((lle) != NULL) && ((lle) != (void *)-1))
   96 
   97 #define LLE_ADDREF(lle) do {                                    \
   98         LLE_WLOCK_ASSERT(lle);                                  \
   99         KASSERT((lle)->lle_refcnt >= 0,                         \
  100                 ("negative refcnt %d", (lle)->lle_refcnt));     \
  101         (lle)->lle_refcnt++;                                    \
  102 } while (0)
  103 
  104 #define LLE_REMREF(lle) do {                                    \
  105         LLE_WLOCK_ASSERT(lle);                                  \
  106         KASSERT((lle)->lle_refcnt > 1,                          \
  107                 ("bogus refcnt %d", (lle)->lle_refcnt));        \
  108         (lle)->lle_refcnt--;                                    \
  109 } while (0)
  110 
  111 #define LLE_FREE_LOCKED(lle) do {                               \
  112         if ((lle)->lle_refcnt <= 1)                             \
  113                 (lle)->lle_tbl->llt_free((lle)->lle_tbl, (lle));\
  114         else {                                                  \
  115                 (lle)->lle_refcnt--;                            \
  116                 LLE_WUNLOCK(lle);                               \
  117         }                                                       \
  118         /* guard against invalid refs */                        \
  119         lle = NULL;                                             \
  120 } while (0)
  121 
  122 #define LLE_FREE(lle) do {                                      \
  123         LLE_WLOCK(lle);                                         \
  124         LLE_FREE_LOCKED(lle);                                   \
  125 } while (0)
  126 
  127 
  128 #define ln_timer_ch     lle_timer.ln_timer_ch
  129 #define la_timer        lle_timer.la_timer
  130 
  131 /* XXX bad name */
  132 #define L3_ADDR(lle)    ((struct sockaddr *)(&lle[1]))
  133 #define L3_ADDR_LEN(lle)        (((struct sockaddr *)(&lle[1]))->sa_len)
  134 
  135 #ifndef LLTBL_HASHTBL_SIZE
  136 #define LLTBL_HASHTBL_SIZE      32      /* default 32 ? */
  137 #endif
  138 
  139 #ifndef LLTBL_HASHMASK
  140 #define LLTBL_HASHMASK  (LLTBL_HASHTBL_SIZE - 1)
  141 #endif
  142 
  143 struct lltable {
  144         SLIST_ENTRY(lltable)    llt_link;
  145         struct llentries        lle_head[LLTBL_HASHTBL_SIZE];
  146         int                     llt_af;
  147         struct ifnet            *llt_ifp;
  148 
  149         void                    (*llt_free)(struct lltable *, struct llentry *);
  150         void                    (*llt_prefix_free)(struct lltable *,
  151                                     const struct sockaddr *prefix,
  152                                     const struct sockaddr *mask,
  153                                     u_int flags);
  154         struct llentry *        (*llt_lookup)(struct lltable *, u_int flags,
  155                                     const struct sockaddr *l3addr);
  156         int                     (*llt_dump)(struct lltable *,
  157                                      struct sysctl_req *);
  158 };
  159 MALLOC_DECLARE(M_LLTABLE);
  160 
  161 /*
  162  * flags to be passed to arplookup.
  163  */
  164 #define LLE_DELETED     0x0001  /* entry must be deleted */
  165 #define LLE_STATIC      0x0002  /* entry is static */
  166 #define LLE_IFADDR      0x0004  /* entry is interface addr */
  167 #define LLE_VALID       0x0008  /* ll_addr is valid */
  168 #define LLE_PROXY       0x0010  /* proxy entry ??? */
  169 #define LLE_PUB         0x0020  /* publish entry ??? */
  170 #define LLE_DELETE      0x4000  /* delete on a lookup - match LLE_IFADDR */
  171 #define LLE_CREATE      0x8000  /* create on a lookup miss */
  172 #define LLE_EXCLUSIVE   0x2000  /* return lle xlocked  */
  173 
  174 #define LLATBL_HASH(key, mask) \
  175         (((((((key >> 8) ^ key) >> 8) ^ key) >> 8) ^ key) & mask)
  176 
  177 struct lltable *lltable_init(struct ifnet *, int);
  178 void            lltable_free(struct lltable *);
  179 void            lltable_prefix_free(int, struct sockaddr *, 
  180                        struct sockaddr *, u_int);
  181 #if 0
  182 void            lltable_drain(int);
  183 #endif
  184 int             lltable_sysctl_dumparp(int, struct sysctl_req *);
  185 
  186 size_t          llentry_free(struct llentry *);
  187 int             llentry_update(struct llentry **, struct lltable *,
  188                        struct sockaddr_storage *, struct ifnet *);
  189 
  190 /*
  191  * Generic link layer address lookup function.
  192  */
  193 static __inline struct llentry *
  194 lla_lookup(struct lltable *llt, u_int flags, const struct sockaddr *l3addr)
  195 {
  196         return llt->llt_lookup(llt, flags, l3addr);
  197 }
  198 
  199 int             lla_rt_output(struct rt_msghdr *, struct rt_addrinfo *);
  200 #endif  /* _NET_IF_LLATBL_H_ */

Cache object: a5fd82aef810f45a80d9ee7781fe7f5b


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