19 #include <netinet/in.h> 43 return applied_hash_aces;
50 DBG(
"HASH ADD/DEL: %016llx %016llx %016llx %016llx %016llx %016llx %016llx add %d",
71 kv_val->applied_entry_index = new_index;
82 u32 index,
int is_add)
101 DBG(
"activate_applied_ace_hash_entry lc_index %d new_index %d", lc_index, new_index);
105 DBG(
"APPLY ADD KY: %016llx %016llx %016llx %016llx %016llx %016llx",
111 int res = BV (clib_bihash_search) (&am->
acl_lookup_hash, &kv, &result);
117 ASSERT(first_index != ~0);
118 DBG(
"A key already exists, with applied entry index: %d", first_index);
123 DBG(
"...advance to chained entry index: %d", last_index);
201 DBG0(
"HASH ACL apply: lc_index %d acl %d", lc_index, acl_index);
216 int base_offset =
vec_len(*applied_hash_aces);
227 clib_warning(
"BUG: trying to apply twice acl_index %d on lc_index %d, according to lc",
228 acl_index, lc_index);
232 u32 index2 =
vec_search((*hash_acl_applied_lc_index), lc_index);
234 clib_warning(
"BUG: trying to apply twice acl_index %d on lc_index %d, according to hash h-acl info",
235 acl_index, lc_index);
238 vec_add1((*hash_acl_applied_lc_index), lc_index);
257 u32 new_index = base_offset +
i;
283 u32 an_index = curr_index;
298 u32 old_index,
u32 new_index)
315 applied_hash_aces, new_index, 1);
346 DBG(
"UNAPPLY DEACTIVATE: lc_index %d applied index %d", lc_index, old_index);
356 DBG(
"UNAPPLY = index %d head index to update %d", old_index, head_index);
381 applied_hash_aces, old_index, 0);
395 uword *new_lookup_bitmap = 0;
419 DBG0(
"HASH ACL unapply: lc_index %d acl %d", lc_index, acl_index);
429 clib_warning(
"BUG: trying to unapply unapplied acl_index %d on lc_index %d, according to lc",
430 acl_index, lc_index);
435 u32 index2 =
vec_search((*hash_acl_applied_lc_index), lc_index);
437 clib_warning(
"BUG: trying to unapply twice acl_index %d on lc_index %d, according to h-acl info",
438 acl_index, lc_index);
441 vec_del1((*hash_acl_applied_lc_index), index2);
445 for(i=0; i <
vec_len((*applied_hash_aces)); i++) {
447 DBG(
"Found applied ACL#%d at applied index %d", acl_index, i);
451 if (
vec_len((*applied_hash_aces)) <= i) {
452 DBG(
"Did not find applied ACL#%d at lc_index %d", acl_index, lc_index);
460 int tail_len =
vec_len((*applied_hash_aces)) - tail_offset;
461 DBG(
"base_offset: %d, tail_offset: %d, tail_len: %d", base_offset, tail_offset, tail_len);
465 applied_hash_aces, base_offset + i);
467 for(i=0; i < tail_len; i ++) {
470 DBG(
"UNAPPLY MOVE: lc_index %d, applied index %d -> %d", lc_index, tail_offset+i, base_offset + i);
498 int start_index =
vec_search((*applied_acls), acl_index);
500 DBG0(
"Start index for acl %d in lc_index %d is %d", acl_index, lc_index, start_index);
508 for(i =
vec_len(*applied_acls) - 1; i > start_index; i--) {
511 for(i = start_index; i <
vec_len(*applied_acls); i++) {
531 if (port_first == port_last) {
536 if ((port_first == 0) && (port_last == 65535)) {
558 memset(mask, 0,
sizeof(*mask));
578 if (match_nonfirst_fragment) {
609 pmatch[j] = pmatch[j] & pmask[j];
620 if(memcmp(&mte->mask, mask, sizeof(*mask)) == 0)
621 return (mte - am->ace_mask_type_pool);
632 if(~0 == mask_type_index) {
642 ASSERT(mask_type_index < 32768);
646 return mask_type_index;
672 DBG(
"HASH ACL add : %d", acl_index);
677 memset(ha, 0,
sizeof(*ha));
682 for(i=0; i < a->
count; i++) {
685 memset(&ace_info, 0,
sizeof(ace_info));
724 DBG0(
"HASH ACL delete : %d", acl_index);
739 u32 *lc_list_copy = 0;
780 vlib_cli_output(vm,
" %3d: %016llx %016llx %016llx %016llx %016llx %016llx refcount %d",
781 mte - am->ace_mask_type_pool,
782 mte->mask.kv.key[0], mte->mask.kv.key[1], mte->mask.kv.key[2],
783 mte->mask.kv.key[3], mte->mask.kv.key[4], mte->mask.kv.value, mte->refcount);
798 if ((acl_index != ~0) && (acl_index !=
i))
813 " %4d: %016llx %016llx %016llx %016llx %016llx %016llx mask index %d acl %d rule %d action %d src/dst portrange not ^2: %d,%d\n",
814 j, m[0], m[1], m[2], m[3], m[4], m[5],
826 " %4d: acl %d rule %d action %d bitmask-ready rule %d next %d prev %d tail %d hitcount %lld",
844 if ((lc_index != ~0) && (lc_index != lci))
static void move_applied_ace_hash_entry(acl_main_t *am, u32 lc_index, applied_hash_ace_entry_t **applied_hash_aces, u32 old_index, u32 new_index)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static void deactivate_applied_ace_hash_entry(acl_main_t *am, u32 lc_index, applied_hash_ace_entry_t **applied_hash_aces, u32 old_index)
static u8 * format_bitmap_hex(u8 *s, va_list *args)
Format a bitmap as a string of hex bytes.
void acl_plugin_show_tables_mask_type(void)
static void * hash_acl_set_heap(acl_main_t *am)
void hash_acl_unapply(acl_main_t *am, u32 lc_index, int acl_index)
void acl_plugin_hash_acl_set_trace_heap(int on)
void acl_plugin_show_tables_applied_info(u32 lc_index)
void hash_acl_reapply(acl_main_t *am, u32 lc_index, int acl_index)
#define clib_error(format, args...)
int l4_match_nonfirst_fragment
void * mheap_alloc(void *memory, uword size)
static uword * clib_bitmap_or(uword *ai, uword *bi)
Logical operator across two bitmaps.
static u8 make_port_mask(u16 *portmask, u16 port_first, u16 port_last)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static mheap_t * mheap_header(u8 *v)
static void applied_hash_entries_analyze(acl_main_t *am, applied_hash_ace_entry_t **applied_hash_aces)
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. ...
#define MHEAP_FLAG_THREAD_SAFE
static u32 find_head_applied_ace_index(applied_hash_ace_entry_t **applied_hash_aces, u32 curr_index)
void hash_acl_add(acl_main_t *am, int acl_index)
u32 ** lc_index_vec_by_acl
u16 dst_port_or_code_last
u32 next_applied_entry_index
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
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 activate_applied_ace_hash_entry(acl_main_t *am, u32 lc_index, applied_hash_ace_entry_t **applied_hash_aces, u32 new_index)
#define ip46_address_mask_ip4(ip46)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
#define vec_search(v, E)
Search a vector for the index of the entry that matches.
static void release_mask_type_index(acl_main_t *am, u32 mask_type_index)
void hash_acl_apply(acl_main_t *am, u32 lc_index, int acl_index, u32 acl_position)
static u32 assign_mask_type_index(acl_main_t *am, fa_5tuple_t *mask)
int hash_acl_exists(acl_main_t *am, int acl_index)
static void add_del_hashtable_entry(acl_main_t *am, u32 lc_index, applied_hash_ace_entry_t **applied_hash_aces, u32 index, int is_add)
uword * mask_type_index_bitmap
static void hash_acl_build_applied_lookup_bitmap(acl_main_t *am, u32 lc_index)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u8 dst_portrange_not_powerof2
u16 dst_port_or_code_first
hash_acl_info_t * hash_acl_infos
#define pool_put(P, E)
Free an object E in pool P.
#define vec_dup(V)
Return copy of vector (no header, no alignment)
#define vec_del1(v, i)
Delete the element at index I.
clib_bihash_48_8_t acl_lookup_hash
void show_hash_acl_hash(vlib_main_t *vm, acl_main_t *am, u32 verbose)
void acl_plugin_hash_acl_set_validate_heap(int on)
void clib_bihash_init(clib_bihash *h, char *name, u32 nbuckets, uword memory_size)
initialize a bounded index extensible hash table
u16 src_port_or_type_first
void acl_plugin_show_tables_bihash(u32 show_bihash_verbose)
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
void acl_plugin_print_pae(vlib_main_t *vm, int j, applied_hash_ace_entry_t *pae)
uword * mask_type_index_bitmap
applied_hash_acl_info_t * applied_hash_acl_info_by_lc_index
#define vec_free(V)
Free vector's memory (no header).
int acl_lookup_hash_initialized
static void * clib_mem_set_heap(void *heap)
void hash_acl_delete(acl_main_t *am, int acl_index)
#define clib_warning(format, args...)
#define clib_memcpy(a, b, c)
applied_hash_ace_entry_t ** hash_entry_vec_by_lc_index
u32 hash_lookup_hash_buckets
u16 src_port_or_type_last
#define MHEAP_FLAG_VALIDATE
#define clib_bitmap_free(v)
Free a bitmap.
static void make_mask_and_match_from_rule(fa_5tuple_t *mask, acl_rule_t *r, hash_ace_info_t *hi, int match_nonfirst_fragment)
static applied_hash_ace_entry_t ** get_applied_hash_aces(acl_main_t *am, u32 lc_index)
ace_mask_type_entry_t * ace_mask_type_pool
#define MHEAP_FLAG_SMALL_OBJECT_CACHE
static u32 find_mask_type_index(acl_main_t *am, fa_5tuple_t *mask)
u32 prev_applied_entry_index
static void fill_applied_hash_ace_kv(acl_main_t *am, applied_hash_ace_entry_t **applied_hash_aces, u32 lc_index, u32 new_index, clib_bihash_kv_48_8_t *kv)
acl_lookup_context_t * acl_lookup_contexts
uword hash_lookup_mheap_size
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void hashtable_add_del(acl_main_t *am, clib_bihash_kv_48_8_t *kv, int is_add)
static void ip6_address_mask_from_width(ip6_address_t *a, u32 width)
void mheap_validate(void *v)
#define vec_foreach(var, vec)
Vector iterator.
u32 tail_applied_entry_index
static void make_address_mask(ip46_address_t *addr, u8 is_ipv6, u8 prefix_len)
#define CLIB_CACHE_LINE_BYTES
void acl_plugin_show_tables_acl_hash_info(u32 acl_index)
u8 src_portrange_not_powerof2
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
u32 hash_lookup_hash_memory
foreach_fa_cleaner_counter vlib_main_t * vlib_main