19 #include <netinet/in.h> 42 return applied_hash_aces;
49 DBG(
"HASH ADD/DEL: %016llx %016llx %016llx %016llx %016llx %016llx %016llx add %d",
88 for (i = 0; i < 2; i++)
103 for (i=0; i<6; i++) {
167 return clib_host_to_net_u32((clib_net_to_host_u32(mask) << numshifts) & 0xFFFFFFFF);
174 int shifts_per_relax[2][4] = { { 6, 5, 4, 2 }, { 3, 2, 1, 1 } };
176 int *shifts = shifts_per_relax[relax2];
177 if(ip4_mask->
as_u32 == 0xffffffff)
178 ip4_mask->
as_u32 = clib_host_to_net_u32((clib_net_to_host_u32(ip4_mask->
as_u32) << shifts[0])&0xFFFFFFFF);
192 if (ip6_mask->as_u64[0] == 0xffffffffffffffffULL) {
193 if (ip6_mask->as_u64[1] == 0xffffffffffffffffULL) {
195 ip6_mask->as_u64[1] = 0;
196 }
else if (ip6_mask->as_u64[1] == 0) {
198 ip6_mask->as_u64[0] = clib_host_to_net_u64(0xffffffffffffff00ULL);
207 int counter_s = 0, counter_d = 0;
227 const int deltaThreshold = 4;
229 int delta = counter_s - counter_d;
230 if (-delta > deltaThreshold) {
236 }
else if (delta > deltaThreshold) {
254 DBG(
"TM-relaxing-ERROR");
257 DBG(
"TM-relaxing-end");
267 if(memcmp(&mte->
mask, mask,
sizeof(*mask)) == 0)
279 if(~0 == mask_type_index) {
290 ASSERT(mask_type_index < 32768);
294 DBG0(
"ASSIGN MTE index %d new refcount %d", mask_type_index, mte->
refcount);
295 return mask_type_index;
301 DBG0(
"LOCK MTE index %d", mask_type_index);
304 DBG0(
"LOCK MTE index %d new refcount %d", mask_type_index, mte->
refcount);
311 DBG0(
"RELEAS MTE index %d", mask_type_index);
314 DBG0(
"RELEAS MTE index %d new refcount %d", mask_type_index, mte->
refcount);
326 u32 mask_type_index = ~0;
327 u32 for_mask_type_index = ~0;
335 if (
vec_len(*hash_applied_mask_info_vec) > 0) {
336 for(order_index =
vec_len((*hash_applied_mask_info_vec)) -1; order_index >= 0; order_index--) {
348 if(~0 == mask_type_index) {
350 DBG(
"TM-assigning mask type index-new one");
357 int spot =
vec_len((*hash_applied_mask_info_vec));
370 ASSERT(mask_type_index < 32768);
373 DBG0(
"TM-ASSIGN MTE index %d new refcount %d", mask_type_index, mte->
refcount);
374 return mask_type_index;
397 *pkey++ = *pmatch++ & *pmask++;
398 *pkey++ = *pmatch++ & *pmask++;
399 *pkey++ = *pmatch++ & *pmask++;
400 *pkey++ = *pmatch++ & *pmask++;
401 *pkey++ = *pmatch++ & *pmask++;
402 *pkey++ = *pmatch++ & *pmask++;
407 kv_val->applied_entry_index = new_index;
426 applied_hash_aces,
u32 lc_index)
428 DBG0(
"remake applied hash mask info lc_index %d", lc_index);
434 for (i = 0; i <
vec_len ((*applied_hash_aces)); i++)
440 u32 new_pointer =
vec_len (new_hash_applied_mask_info_vec);
442 for (search = 0; search <
vec_len (new_hash_applied_mask_info_vec);
450 vec_validate ((new_hash_applied_mask_info_vec), search);
452 if (search == new_pointer)
454 DBG0(
"remaking index %d", search);
473 vec_free ((*hash_applied_mask_info_vec));
474 (*hash_applied_mask_info_vec) = new_hash_applied_mask_info_vec;
479 u32 applied_entry_index)
483 while (i < _vec_len ((*pvec)))
491 DBG0(
"vec_del_collision_rule deleting one at index %d", i);
506 u32 head_index,
u32 applied_entry_index)
508 DBG0(
"DEL COLLIDING RULE: head_index %d applied index %d", head_index, applied_entry_index);
526 u32 head_index,
u32 applied_entry_index)
532 DBG0(
"ADD COLLIDING RULE: head_index %d applied index %d", head_index, applied_entry_index);
557 DBG(
"activate_applied_ace_hash_entry lc_index %d new_index %d", lc_index, new_index);
561 DBG(
"APPLY ADD KY: %016llx %016llx %016llx %016llx %016llx %016llx",
567 int res = BV (clib_bihash_search) (&am->
acl_lookup_hash, &kv, &result);
572 ASSERT(first_index != ~0);
575 DBG(
"A key already exists, with applied entry index: %d", first_index);
628 DBG0(
"HASH ACL apply: lc_index %d acl %d", lc_index, acl_index);
642 int base_offset =
vec_len(*applied_hash_aces);
653 clib_warning(
"BUG: trying to apply twice acl_index %d on lc_index %d, according to lc",
654 acl_index, lc_index);
659 u32 index2 =
vec_search((*hash_acl_applied_lc_index), lc_index);
661 clib_warning(
"BUG: trying to apply twice acl_index %d on lc_index %d, according to hash h-acl info",
662 acl_index, lc_index);
666 vec_add1((*hash_acl_applied_lc_index), lc_index);
683 int old_vec_len =
vec_len(*applied_hash_aces);
685 _vec_len((*applied_hash_aces)) = old_vec_len;
697 u32 new_index = base_offset +
i;
741 u32 old_index,
u32 new_index)
753 clib_warning(
"Moving pae from %d to %d", old_index, new_index);
760 applied_hash_aces, new_index, 1);
783 clib_warning(
"Head pae at index %d after adjustment", head_index);
799 DBG(
"UNAPPLY DEACTIVATE: lc_index %d applied index %d", lc_index, old_index);
801 clib_warning(
"Deactivating pae at index %d", old_index);
823 applied_hash_aces, next_pae_index, 1);
827 applied_hash_aces, old_index, 0);
830 DBG0(
"Releasing mask type index %d for pae index %d on lc_index %d", pae->
mask_type_index, old_index, lc_index);
845 DBG0(
"HASH ACL unapply: lc_index %d acl %d", lc_index, acl_index);
862 clib_warning(
"BUG: trying to unapply unapplied acl_index %d on lc_index %d, according to lc",
863 acl_index, lc_index);
868 u32 index2 =
vec_search((*hash_acl_applied_lc_index), lc_index);
870 clib_warning(
"BUG: trying to unapply twice acl_index %d on lc_index %d, according to h-acl info",
871 acl_index, lc_index);
874 vec_del1((*hash_acl_applied_lc_index), index2);
878 for(i=0; i <
vec_len((*applied_hash_aces)); i++) {
880 DBG(
"Found applied ACL#%d at applied index %d", acl_index, i);
884 if (
vec_len((*applied_hash_aces)) <= i) {
885 DBG(
"Did not find applied ACL#%d at lc_index %d", acl_index, lc_index);
892 int tail_len =
vec_len((*applied_hash_aces)) - tail_offset;
893 DBG(
"base_offset: %d, tail_offset: %d, tail_len: %d", base_offset, tail_offset, tail_len);
897 applied_hash_aces, base_offset + i);
899 for(i=0; i < tail_len; i ++) {
902 DBG0(
"UNAPPLY MOVE: lc_index %d, applied index %d -> %d", lc_index, tail_offset+i, base_offset + i);
910 if (
vec_len((*applied_hash_aces)) == 0) {
930 int start_index =
vec_search((*applied_acls), acl_index);
932 DBG0(
"Start index for acl %d in lc_index %d is %d", acl_index, lc_index, start_index);
940 for(i =
vec_len(*applied_acls) - 1; i > start_index; i--) {
943 for(i = start_index; i <
vec_len(*applied_acls); i++) {
959 int i, byte, bit, bitnum;
962 for (i = 0; i < width; i++)
964 bitnum = (7 - (i & 7));
967 a->
as_u8[byte] |= bit;
981 if (port_first == port_last) {
1018 if (r->
proto != 0) {
1044 u64 *pmask = (
u64 *)mask;
1047 for(j=0; j<6; j++) {
1048 pmatch[j] = pmatch[j] & pmask[j];
1064 DBG(
"HASH ACL add : %d", acl_index);
1081 for(i=0; i <
vec_len(acl_rules); i++) {
1110 DBG0(
"HASH ACL delete : %d", acl_index);
1125 u32 *lc_list_copy = 0;
1165 vlib_cli_output(vm,
" %3d: %016llx %016llx %016llx %016llx %016llx %016llx refcount %d",
1183 if ((acl_index != ~0) && (acl_index !=
i))
1196 " %4d: %016llx %016llx %016llx %016llx %016llx %016llx base mask index %d acl %d rule %d action %d\n",
1197 j, m[0], m[1], m[2], m[3], m[4], m[5],
1207 " %4d: acl %d ace %d acl pos %d pae index: %d",
1215 " %4d: acl %d rule %d action %d bitmask-ready rule %d mask type index: %d colliding_rules: %d collision_head_ae_idx %d hitcount %lld acl_pos: %d",
1228 " %4d: mask type index %d first rule index %d num_entries %d max_collisions %d",
1243 if ((lc_index != ~0) && (lc_index != lci))
1313 (clib_net_to_host_u64 (mask_addr->as_u64[0]) <
1314 clib_net_to_host_u64 (min_addr->as_u64[0]))
1316 ((clib_net_to_host_u64 (mask_addr->as_u64[0]) ==
1317 clib_net_to_host_u64 (min_addr->as_u64[0]))
1318 && (clib_net_to_host_u64 (mask_addr->as_u64[1]) <
1319 clib_net_to_host_u64 (min_addr->as_u64[1])));
1322 min_addr->as_u64[0] = mask_addr->as_u64[0];
1323 min_addr->as_u64[1] = mask_addr->as_u64[1];
1331 (clib_net_to_host_u64 (mask_addr->as_u64[0]) >
1332 clib_net_to_host_u64 (max_addr->as_u64[0]))
1334 ((clib_net_to_host_u64 (mask_addr->as_u64[0]) ==
1335 clib_net_to_host_u64 (max_addr->as_u64[0]))
1336 && (clib_net_to_host_u64 (mask_addr->as_u64[1]) >
1337 clib_net_to_host_u64 (max_addr->as_u64[1])));
1340 max_addr->as_u64[0] = mask_addr->as_u64[0];
1341 max_addr->as_u64[1] = mask_addr->as_u64[1];
1349 (clib_net_to_host_u32 (mask_addr->
as_u32) <
1350 clib_net_to_host_u32 (min_addr->
as_u32));
1359 (clib_net_to_host_u32 (mask_addr->
as_u32) >
1360 clib_net_to_host_u32 (max_addr->
as_u32));
1378 DBG(
"TM-split_partition - first_entry:%d", first_index);
1381 fa_5tuple_t the_min_tuple, *min_tuple = &the_min_tuple;
1382 fa_5tuple_t the_max_tuple, *max_tuple = &the_max_tuple;
1387 clib_memset(&the_min_tuple, 0,
sizeof(the_min_tuple));
1388 clib_memset(&the_max_tuple, 0,
sizeof(the_max_tuple));
1393 for(i=0; i<collisions; i++){
1395 pae =
vec_elt_at_index((*applied_hash_aces), colliding_rules[i].applied_entry_index);
1398 DBG(
"TM-collision: base_ace:%d (ace_mask:%d, first_collision_mask:%d)",
1448 int best_dim=-1, best_delta=0, delta=0;
1459 if(delta > best_delta){
1474 if(delta > best_delta){
1481 if(delta > best_delta){
1488 if(delta > best_delta){
1495 if(delta > best_delta){
1503 shifting = (best_delta)/2;
1506 clib_host_to_net_u32((clib_net_to_host_u32(max_tuple->
ip4_addr[0].
as_u32) << (shifting))&0xFFFFFFFF);
1510 shifting = (best_delta)/2;
1524 clib_host_to_net_u32((clib_net_to_host_u32(max_tuple->
ip4_addr[1].
as_u32) << (shifting))&0xFFFFFFFF);
1545 for (search=0; search <
vec_len((*hash_applied_mask_info_vec)); search++){
1558 DBG(
"TM-split_partition - mask type index-assigned!! -> %d", new_mask_type_index);
1560 if(coll_mask_type_index == new_mask_type_index){
1567 DBG(
"TM-Populate new partition");
1568 u32 r_ace_index = first_index;
1569 int repopulate_count = 0;
1572 collisions =
vec_len(temp_colliding_rules);
1574 for(i=0; i<collisions; i++){
1580 DBG(
"TM-Population-collision: base_ace:%d (ace_mask:%d, first_collision_mask:%d)",
1592 DBG(
"TM-new partition can insert -> applied_ace:%d", r_ace_index);
1600 if (++repopulate_count > 1)
1608 DBG(
"TM-Populate new partition-END");
1609 DBG(
"TM-split_partition - END");
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 ensure_ip4_max_addr(ip4_address_t *max_addr, ip4_address_t *mask_addr)
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)
void acl_plugin_show_tables_mask_type(void)
static void ensure_ip6_min_addr(ip6_address_t *min_addr, ip6_address_t *mask_addr)
void hash_acl_unapply(acl_main_t *am, u32 lc_index, int acl_index)
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 pool_foreach(VAR, POOL)
Iterate through pool.
#define clib_memcpy_fast(a, b, c)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void add_colliding_rule(acl_main_t *am, applied_hash_ace_entry_t **applied_hash_aces, u32 head_index, u32 applied_entry_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static u32 activate_applied_ace_hash_entry(acl_main_t *am, u32 lc_index, applied_hash_ace_entry_t **applied_hash_aces, u32 new_index)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
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
static void ensure_ip6_max_addr(ip6_address_t *max_addr, ip6_address_t *mask_addr)
u16 dst_port_or_code_last
static void make_port_mask(u16 *portmask, u16 port_first, u16 port_last)
#define ACL_HASH_LOOKUP_DEBUG
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 assign_mask_type_index_to_pae(acl_main_t *am, u32 lc_index, int is_ip6, applied_hash_ace_entry_t *pae)
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void lock_mask_type_index(acl_main_t *am, u32 mask_type_index)
#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)
collision_match_rule_t * colliding_rules
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void ip4_address_mask_from_width(ip4_address_t *a, u32 width)
u16 dst_port_or_code_first
hash_applied_mask_info_t ** hash_applied_mask_info_vec_by_lc_index
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 make_mask_and_match_from_rule(fa_5tuple_t *mask, acl_rule_t *r, hash_ace_info_t *hi)
#define vec_del1(v, i)
Delete the element at index I.
static void check_collision_count_and_maybe_split(acl_main_t *am, u32 lc_index, int is_ip6, u32 first_index)
clib_bihash_48_8_t acl_lookup_hash
void show_hash_acl_hash(vlib_main_t *vm, acl_main_t *am, u32 verbose)
static u32 shift_ip4_if(u32 mask, u32 thresh, int numshifts, u32 else_val)
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 with alignment A.
static void vec_del_collision_rule(collision_match_rule_t **pvec, u32 applied_entry_index)
static void split_partition(acl_main_t *am, u32 first_index, u32 lc_index, int is_ip6)
sll srl srl sll sra u16x4 i
applied_hash_acl_info_t * applied_hash_acl_info_by_lc_index
#define vec_free(V)
Free vector's memory (no header).
static void make_ip4_address_mask(ip4_address_t *addr, u8 prefix_len)
clib_bihash_kv_40_8_t kv_40_8
int acl_lookup_hash_initialized
void hash_acl_delete(acl_main_t *am, int acl_index)
#define clib_warning(format, args...)
static int count_bits(u64 word)
applied_hash_ace_entry_t ** hash_entry_vec_by_lc_index
static u8 first_mask_contains_second_mask(int is_ip6, fa_5tuple_t *mask1, fa_5tuple_t *mask2)
uword hash_lookup_hash_memory
int tuple_merge_split_threshold
static void relax_ip6_addr(ip6_address_t *ip6_mask, int relax2)
static void acl_plugin_print_colliding_rule(vlib_main_t *vm, int j, collision_match_rule_t *cr)
u32 hash_lookup_hash_buckets
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static void ensure_ip4_min_addr(ip4_address_t *min_addr, ip4_address_t *mask_addr)
#define vec_delete(V, N, M)
Delete N elements starting at element M.
u16 src_port_or_type_last
static void acl_plugin_print_pae(vlib_main_t *vm, int j, applied_hash_ace_entry_t *pae)
u32 collision_head_ae_index
static void acl_plugin_print_applied_mask_info(vlib_main_t *vm, int j, hash_applied_mask_info_t *mi)
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
static u32 find_mask_type_index(acl_main_t *am, fa_5tuple_t *mask)
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
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void relax_ip4_addr(ip4_address_t *ip4_mask, int relax2)
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)
static u32 tm_assign_mask_type_index(acl_main_t *am, fa_5tuple_t *mask, int is_ip6, u32 lc_index)
#define vec_foreach(var, vec)
Vector iterator.
static void del_colliding_rule(applied_hash_ace_entry_t **applied_hash_aces, u32 head_index, u32 applied_entry_index)
static void relax_tuple(fa_5tuple_t *mask, int is_ip6, int relax2)
ip4_address_t ip4_addr[2]
static void remake_hash_applied_mask_info_vec(acl_main_t *am, applied_hash_ace_entry_t **applied_hash_aces, u32 lc_index)
static void make_ip6_address_mask(ip6_address_t *addr, u8 prefix_len)
#define CLIB_CACHE_LINE_BYTES
static void set_collision_head_ae_index(applied_hash_ace_entry_t **applied_hash_aces, collision_match_rule_t *colliding_rules, u32 new_index)
void acl_plugin_show_tables_acl_hash_info(u32 acl_index)
ip6_address_t ip6_addr[2]
foreach_fa_cleaner_counter vlib_main_t * vlib_main