19 #include <netinet/in.h> 40 return applied_hash_aces;
58 DBG(
"PORTMATCH: %d <= %d <= %d && %d <= %d <= %d ?",
73 u64 *pmatch = (
u64 *)match;
77 u32 curr_match_index = ~0;
85 DBG(
"TRYING TO MATCH: %016llx %016llx %016llx %016llx %016llx %016llx",
86 pmatch[0], pmatch[1], pmatch[2], pmatch[3], pmatch[4], pmatch[5]);
94 pmatch = (
u64 *)match;
105 *pkey++ = *pmatch++ & *pmask++;
106 *pkey++ = *pmatch++ & *pmask++;
107 *pkey++ = *pmatch++ & *pmask++;
108 *pkey++ = *pmatch++ & *pmask++;
109 *pkey++ = *pmatch++ & *pmask++;
110 *pkey++ = *pmatch++ & *pmask++;
113 DBG(
" KEY %3d: %016llx %016llx %016llx %016llx %016llx %016llx", mask_type_index,
117 DBG(
"ACL-MATCH! result_val: %016llx", result_val->as_u64);
118 if (result_val->applied_entry_index < curr_match_index) {
127 u32 curr_index = result_val->applied_entry_index;
134 if (curr_index < curr_match_index) {
135 DBG(
"The index %d is the new candidate in portrange matches.", curr_index);
136 curr_match_index = curr_index;
138 DBG(
"Curr portmatch index %d is too big vs. current matched one %d", curr_index, curr_match_index);
142 DBG(
"This match is the new candidate");
143 curr_match_index = result_val->applied_entry_index;
144 if (!result_val->shadowed) {
152 DBG(
"MATCH-RESULT: %d", curr_match_index);
153 return curr_match_index;
159 DBG(
"HASH ADD/DEL: %016llx %016llx %016llx %016llx %016llx %016llx %016llx add %d",
168 u32 sw_if_index,
u8 is_input,
181 kv_val->applied_entry_index = new_index;
185 kv_val->shadowed = 1;
190 u32 sw_if_index,
u8 is_input,
192 u32 index,
int is_add)
204 u32 sw_if_index,
u8 is_input,
211 DBG(
"activate_applied_ace_hash_entry sw_if_index %d is_input %d new_index %d", sw_if_index, is_input, new_index);
215 DBG(
"APPLY ADD KY: %016llx %016llx %016llx %016llx %016llx %016llx",
227 ASSERT(first_index != ~0);
228 DBG(
"A key already exists, with applied entry index: %d", first_index);
233 DBG(
"...advance to chained entry index: %d", last_index);
306 DBG0(
"HASH ACL apply: sw_if_index %d is_input %d acl %d", sw_if_index, is_input, acl_index);
326 int base_offset =
vec_len(*applied_hash_aces);
338 clib_warning(
"BUG: trying to apply twice acl_index %d on sw_if_index %d is_input %d",
339 acl_index, sw_if_index, is_input);
343 u32 index2 =
vec_search((*hash_acl_applied_sw_if_index), sw_if_index);
345 clib_warning(
"BUG: trying to apply twice acl_index %d on (sw_if_index %d) is_input %d",
346 acl_index, sw_if_index, is_input);
349 vec_add1((*hash_acl_applied_sw_if_index), sw_if_index);
368 u32 new_index = base_offset +
i;
393 u32 an_index = curr_index;
406 u32 sw_if_index,
u8 is_input,
408 u32 old_index,
u32 new_index)
425 applied_hash_aces, new_index, 1);
451 u32 sw_if_index,
u8 is_input,
456 DBG(
"UNAPPLY DEACTIVATE: sw_if_index %d is_input %d, applied index %d", sw_if_index, is_input, old_index);
466 DBG(
"UNAPPLY = index %d head index to update %d", old_index, head_index);
491 applied_hash_aces, old_index, 0);
505 uword *new_lookup_bitmap = 0;
527 DBG0(
"HASH ACL unapply: sw_if_index %d is_input %d acl %d", sw_if_index, is_input, acl_index);
539 clib_warning(
"BUG: trying to unapply unapplied acl_index %d on sw_if_index %d is_input %d",
540 acl_index, sw_if_index, is_input);
545 u32 index2 =
vec_search((*hash_acl_applied_sw_if_index), sw_if_index);
547 clib_warning(
"BUG: trying to unapply twice acl_index %d on (sw_if_index %d) is_input %d",
548 acl_index, sw_if_index, is_input);
551 vec_del1((*hash_acl_applied_sw_if_index), index2);
555 for(i=0; i <
vec_len((*applied_hash_aces)); i++) {
557 DBG(
"Found applied ACL#%d at applied index %d", acl_index, i);
561 if (
vec_len((*applied_hash_aces)) <= i) {
562 DBG(
"Did not find applied ACL#%d at sw_if_index %d", acl_index, sw_if_index);
570 int tail_len =
vec_len((*applied_hash_aces)) - tail_offset;
571 DBG(
"base_offset: %d, tail_offset: %d, tail_len: %d", base_offset, tail_offset, tail_len);
575 applied_hash_aces, base_offset + i);
577 for(i=0; i < tail_len; i ++) {
580 DBG(
"UNAPPLY MOVE: sw_if_index %d is_input %d, applied index %d ->", sw_if_index, is_input, tail_offset+i, base_offset + i);
608 int start_index =
vec_search((*applied_acls), acl_index);
616 for(i =
vec_len(*applied_acls) - 1; i > start_index; i--) {
619 for(i = start_index; i <
vec_len(*applied_acls); i++) {
639 if (port_first == port_last) {
644 if ((port_first == 0) && (port_last == 65535)) {
666 memset(mask, 0,
sizeof(*mask));
687 if (match_nonfirst_fragment) {
718 pmatch[j] = pmatch[j] & pmask[j];
729 if(memcmp(&mte->mask, mask, sizeof(*mask)) == 0)
730 return (mte - am->ace_mask_type_pool);
741 if(~0 == mask_type_index) {
751 ASSERT(mask_type_index < 32768);
755 return mask_type_index;
772 DBG(
"HASH ACL add : %d", acl_index);
777 memset(ha, 0,
sizeof(*ha));
781 for(i=0; i < a->
count; i++) {
784 memset(&ace_info, 0,
sizeof(ace_info));
829 DBG0(
"HASH ACL delete : %d", acl_index);
844 u32 *interface_list_copy = 0;
871 int is_ip6,
int is_input,
u32 * acl_match_p,
872 u32 * rule_match_p,
u32 * trace_bitmap)
877 if (match_index <
vec_len((*applied_hash_aces))) {
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static u8 * format_bitmap_hex(u8 *s, va_list *args)
Format a bitmap as a string of hex bytes.
void acl_plugin_hash_acl_set_trace_heap(acl_main_t *am, int on)
sll srl srl sll sra u16x4 i
static void move_applied_ace_hash_entry(acl_main_t *am, u32 sw_if_index, u8 is_input, applied_hash_ace_entry_t **applied_hash_aces, u32 old_index, u32 new_index)
static void * hash_acl_set_heap(acl_main_t *am)
u32 ** input_acl_vec_by_sw_if_index
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. ...
static int match_portranges(acl_main_t *am, fa_5tuple_t *match, u32 index)
applied_hash_acl_info_t * output_applied_hash_acl_info_by_sw_if_index
#define MHEAP_FLAG_THREAD_SAFE
#define pool_len(p)
Number of elements in pool vector.
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)
u16 dst_port_or_code_last
u32 next_applied_entry_index
void acl_plugin_hash_acl_set_validate_heap(acl_main_t *am, int on)
#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.
#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.
static u32 multi_acl_match_get_applied_ace_index(acl_main_t *am, fa_5tuple_t *match)
#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_unapply(acl_main_t *am, u32 sw_if_index, u8 is_input, int acl_index)
u32 * inbound_sw_if_index_list
static u32 assign_mask_type_index(acl_main_t *am, fa_5tuple_t *mask)
uword * mask_type_index_bitmap
applied_hash_acl_info_t * input_applied_hash_acl_info_by_sw_if_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)
static void fill_applied_hash_ace_kv(acl_main_t *am, applied_hash_ace_entry_t **applied_hash_aces, u32 sw_if_index, u8 is_input, u32 new_index, clib_bihash_kv_48_8_t *kv)
#define vec_del1(v, i)
Delete the element at index I.
static void activate_applied_ace_hash_entry(acl_main_t *am, u32 sw_if_index, u8 is_input, applied_hash_ace_entry_t **applied_hash_aces, u32 new_index)
clib_bihash_48_8_t acl_lookup_hash
void show_hash_acl_hash(vlib_main_t *vm, acl_main_t *am, u32 verbose)
void clib_bihash_init(clib_bihash *h, char *name, u32 nbuckets, uword memory_size)
initialize a bounded index extensible hash table
u8 hash_multi_acl_match_5tuple(u32 sw_if_index, fa_5tuple_t *pkt_5tuple, int is_l2, int is_ip6, int is_input, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap)
u16 src_port_or_type_first
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
uword * mask_type_index_bitmap
applied_hash_ace_entry_t ** output_hash_entry_vec_by_sw_if_index
#define vec_free(V)
Free vector's memory (no header).
int acl_lookup_hash_initialized
u32 * outbound_sw_if_index_list
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)
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
static applied_hash_ace_entry_t ** get_applied_hash_aces(acl_main_t *am, int is_input, u32 sw_if_index)
u32 hash_lookup_hash_buckets
int clib_bihash_search(clib_bihash *h, clib_bihash_kv *search_v, clib_bihash_kv *return_v)
Search a bi-hash table.
u16 src_port_or_type_last
static void add_del_hashtable_entry(acl_main_t *am, u32 sw_if_index, u8 is_input, applied_hash_ace_entry_t **applied_hash_aces, u32 index, int is_add)
#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)
void hash_acl_reapply(acl_main_t *am, u32 sw_if_index, u8 is_input, int acl_index)
static void hash_acl_build_applied_lookup_bitmap(acl_main_t *am, u32 sw_if_index, u8 is_input)
#define MHEAP_FLAG_SMALL_OBJECT_CACHE
ace_mask_type_entry_t * ace_mask_type_pool
static u32 find_mask_type_index(acl_main_t *am, fa_5tuple_t *mask)
u32 prev_applied_entry_index
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 ** input_sw_if_index_vec_by_acl
static void hashtable_add_del(acl_main_t *am, clib_bihash_kv_48_8_t *kv, int is_add)
void hash_acl_apply(acl_main_t *am, u32 sw_if_index, u8 is_input, int acl_index)
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)
u32 ** output_sw_if_index_vec_by_acl
#define CLIB_CACHE_LINE_BYTES
u32 hash_lookup_mheap_size
u8 src_portrange_not_powerof2
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static void deactivate_applied_ace_hash_entry(acl_main_t *am, u32 sw_if_index, u8 is_input, applied_hash_ace_entry_t **applied_hash_aces, u32 old_index)
u32 ** output_acl_vec_by_sw_if_index
u32 hash_lookup_hash_memory
applied_hash_ace_entry_t ** input_hash_entry_vec_by_sw_if_index