19 #include <arpa/inet.h> 26 return htonl(len == 32 ? a : a & ~(~0u >> len));
31 return len == 64 ?
addr : addr & ~(~0ull >>
len);
38 uword * hash, * result;
42 hash = lpm->
hash[pfxlen];
45 clib_warning(
"%U/%d already exists in table for domain %d",
56 lpm->
hash[pfxlen] = hash;
62 uword * hash, * result;
66 hash = lpm->
hash[pfxlen];
70 lpm->
hash[pfxlen] = hash;
76 uword * hash, * result;
80 for (mask_len = pfxlen; mask_len >= 0; mask_len--) {
81 hash = lpm->
hash[mask_len];
96 BVT(clib_bihash_kv) kv, v;
99 kv.key[1] =
masked_address64(addr->as_u64[1], pfxlen > 64 ? pfxlen - 64 : 0);
111 ip6_address_t *
addr = addr_v;
126 BVT(clib_bihash_kv) kv;
127 ip6_address_t *
addr = addr_v;
130 kv.key[1] =
masked_address64(addr->as_u64[1], pfxlen > 64 ? pfxlen - 64 : 0);
141 ip6_address_t *
addr = addr_v;
142 BVT(clib_bihash_kv) kv;
144 kv.key[1] =
masked_address64(addr->as_u64[1], pfxlen > 64 ? pfxlen - 64 : 0);
160 memset(lpm, 0,
sizeof(*lpm));
174 "LPM 128", 64*1024, 32<<20);
static int lpm_128_lookup_core(lpm_t *lpm, ip6_address_t *addr, u8 pfxlen, u32 *value)
lpm_t * lpm_table_init(enum lpm_type_e lpm_type)
#define hash_set(h, key, value)
#define hash_unset(h, key)
static uint32_t masked_address32(uint32_t addr, uint8_t len)
static void lpm_128_add(lpm_t *lpm, void *addr_v, u8 pfxlen, u32 value)
#define clib_bitmap_foreach(i, ai)
Macro to iterate across set bits in a bitmap.
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap. ...
void(* add)(struct lpm_ *lpm, void *addr_v, u8 pfxlen, u32 value)
int clib_bihash_add_del(clib_bihash *h, clib_bihash_kv *add_v, int is_add)
Add or delete a (key,value) pair from a bi-hash table.
static void hash_set_flags(void *v, uword flags)
u32(* lookup)(struct lpm_ *lpm, void *addr_v, u8 pfxlen)
static void lpm_32_add(lpm_t *lpm, void *addr_v, u8 pfxlen, u32 value)
void clib_bihash_init(clib_bihash *h, char *name, u32 nbuckets, uword memory_size)
initialize a bounded index extensible hash table
static uint64_t masked_address64(uint64_t addr, uint8_t len)
sll srl srl sll sra u16x4 i
#define clib_warning(format, args...)
static void lpm_128_delete(lpm_t *lpm, void *addr_v, u8 pfxlen)
#define hash_create(elts, value_bytes)
int clib_bihash_search_inline_2(clib_bihash *h, clib_bihash_kv *search_key, clib_bihash_kv *valuep)
Search a bi-hash table.
void(* delete)(struct lpm_ *lpm, void *addr_v, u8 pfxlen)
static void * clib_mem_alloc(uword size)
static u32 lpm_32_lookup(lpm_t *lpm, void *addr_v, u8 pfxlen)
#define HASH_FLAG_NO_AUTO_SHRINK
static u32 lpm_128_lookup(lpm_t *lpm, void *addr_v, u8 pfxlen)
u32 prefix_length_refcount[129]
uword * prefix_lengths_bitmap
static void lpm_32_delete(lpm_t *lpm, void *addr_v, u8 pfxlen)