16 #ifndef included_acl_inlines_h 17 #define included_acl_inlines_h 28 #define LOAD_SYMBOL_FROM_PLUGIN_TO(p, s, st) \ 30 st = vlib_get_plugin_symbol(p, #s); \ 32 return clib_error_return(0, \ 33 "Plugin %s and/or symbol %s not found.", p, #s); \ 36 #define LOAD_SYMBOL(s) LOAD_SYMBOL_FROM_PLUGIN_TO("acl_plugin.so", s, s) 82 for(ii=0; ii<6; ii++) {
96 static u8 icmp_protos_v4v6[] = { IP_PROTOCOL_ICMP, IP_PROTOCOL_ICMP6 };
123 frag_offset = clib_net_to_host_u16(frag_offset) >> 3;
140 l4_offset += 8 * (1 + (
u16) nwords);
173 ports[0] = icmph->type;
174 ports[1] = icmph->code;
178 else if (IP_PROTOCOL_TCP == proto)
180 ports[0] = clib_net_to_host_u16(tcph->src_port);
181 ports[1] = clib_net_to_host_u16(tcph->dst_port);
185 else if (IP_PROTOCOL_UDP == proto)
187 ports[0] = clib_net_to_host_u16(udph->
src_port);
188 ports[1] = clib_net_to_host_u16(udph->
dst_port);
200 .l4_flags = tmp_l4_flags,
201 .lsb_of_sw_if_index = sw_if_index0 & 0xffff };
208 int is_input,
int is_l2_path,
fa_5tuple_t * p5tuple_pkt)
221 l3_offset =
vnet_buffer(b0)->ip.save_rewrite_length;
249 uint32_t a1 = clib_net_to_host_u32 (addr1->
as_u32);
250 uint32_t a2 = clib_net_to_host_u32 (addr2->
as_u32);
251 uint32_t mask0 = 0xffffffff - ((1 << (32 - prefixlen)) - 1);
252 return (a1 & mask0) == a2;
264 if (memcmp (addr1, addr2, prefixlen / 8))
271 u8 b1 = *((
u8 *) addr1 + 1 + prefixlen / 8);
272 u8 b2 = *((
u8 *) addr2 + 1 + prefixlen / 8);
273 u8 mask0 = (0xff - ((1 << (8 - (prefixlen % 8))) - 1));
274 return (b1 & mask0) == b2;
286 return ((port >= port_first) && (port <= port_last));
291 int is_ip6,
u8 * r_action,
u32 * r_acl_match_p,
292 u32 * r_rule_match_p,
u32 * trace_bitmap)
303 *r_rule_match_p = -1;
308 for (i = 0; i <
vec_len(acl_rules); i++)
340 *trace_bitmap |= 0x80000000;
353 #ifdef FA_NODE_VERBOSE_DEBUG 355 (
"ACL_FA_NODE_DBG acl %d rule %d pkt proto %d match rule %d",
364 #ifdef FA_NODE_VERBOSE_DEBUG 366 (
"ACL_FA_NODE_DBG acl %d rule %d pkt sport %d match rule [%d..%d]",
376 #ifdef FA_NODE_VERBOSE_DEBUG 378 (
"ACL_FA_NODE_DBG acl %d rule %d pkt dport %d match rule [%d..%d]",
388 #ifdef FA_NODE_VERBOSE_DEBUG 389 clib_warning (
"ACL_FA_NODE_DBG acl %d rule %d FULL-MATCH, action %d",
404 int is_ip6,
u8 * r_action,
u32 * r_acl_match_p,
405 u32 * r_rule_match_p,
u32 * trace_bitmap)
409 r_acl_match_p, r_rule_match_p, trace_bitmap);
414 int is_ip6,
u8 *r_action,
u32 *acl_pos_p,
u32 * acl_match_p,
415 u32 * rule_match_p,
u32 * trace_bitmap)
425 for (i = 0; i <
vec_len (acl_vector); i++)
427 #ifdef FA_NODE_VERBOSE_DEBUG 428 clib_warning (
"ACL_FA_NODE_DBG: Trying to match ACL: %d",
432 (am, acl_vector[i], pkt_5tuple, is_ip6, &action,
433 acl_match_p, rule_match_p, trace_bitmap))
440 if (vec_len (acl_vector) > 0)
444 #ifdef FA_NODE_VERBOSE_DEBUG 445 clib_warning (
"ACL_FA_NODE_DBG: No ACL on lc_index %d", lc_index);
467 #ifdef FA_NODE_VERBOSE_DEBUG 468 clib_warning(
"PORTMATCH: %d <= %d <= %d && %d <= %d <= %d ?",
542 u64 *pmatch = (
u64 *) match;
545 int mask_type_index, order_index;
546 u32 curr_match_index = (~0 - 1);
559 DBG (
"TRYING TO MATCH: %016llx %016llx %016llx %016llx %016llx %016llx",
560 pmatch[0], pmatch[1], pmatch[2], pmatch[3], pmatch[4], pmatch[5]);
562 for (order_index = 0; order_index <
vec_len ((*hash_applied_mask_info_vec));
575 pmatch = (
u64 *) match;
586 *pkey++ = *pmatch++ & *pmask++;
587 *pkey++ = *pmatch++ & *pmask++;
588 *pkey++ = *pmatch++ & *pmask++;
589 *pkey++ = *pmatch++ & *pmask++;
590 *pkey++ = *pmatch++ & *pmask++;
591 *pkey++ = *pmatch++ & *pmask++;
608 u32 curr_index = result_val->applied_entry_index;
613 for (i = 0; i <
vec_len (crs); i++)
615 if (crs[i].applied_entry_index >= curr_match_index)
626 DBG (
"MATCH-RESULT: %d", curr_match_index);
627 return curr_match_index;
632 int is_ip6,
u8 *action,
u32 *acl_pos_p,
u32 * acl_match_p,
633 u32 * rule_match_p,
u32 * trace_bitmap)
638 if (match_index <
vec_len((*applied_hash_aces))) {
655 int is_ip6,
u8 * r_action,
658 u32 * r_rule_match_p,
673 r_acl_pos_p, r_acl_match_p, r_rule_match_p, trace_bitmap);
676 r_acl_pos_p, r_acl_match_p, r_rule_match_p, trace_bitmap);
680 r_acl_pos_p, r_acl_match_p, r_rule_match_p, trace_bitmap);
688 int is_ip6,
u8 * r_action,
691 u32 * r_rule_match_p,
708 r_acl_pos_p, r_acl_match_p, r_rule_match_p, trace_bitmap);
711 r_acl_pos_p, r_acl_match_p, r_rule_match_p, trace_bitmap);
715 r_acl_pos_p, r_acl_match_p, r_rule_match_p, trace_bitmap);
static void acl_fill_5tuple(acl_main_t *am, u32 sw_if_index0, vlib_buffer_t *b0, int is_ip6, int is_input, int is_l2_path, fa_5tuple_t *p5tuple_pkt)
vlib_combined_counter_main_t * combined_acl_counters
static int acl_plugin_single_acl_match_5tuple(void *p_acl_main, u32 acl_index, fa_5tuple_t *pkt_5tuple, int is_ip6, u8 *r_action, u32 *r_acl_match_p, u32 *r_rule_match_p, u32 *trace_bitmap)
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
int l4_match_nonfirst_fragment
static int fa_acl_match_ip4_addr(ip4_address_t *addr1, ip4_address_t *addr2, int prefixlen)
clib_error_t * acl_plugin_methods_vtable_init(acl_plugin_methods_t *m)
static void acl_fill_5tuple_l3_data(acl_main_t *am, vlib_buffer_t *b0, int is_ip6, int l3_offset, fa_5tuple_t *p5tuple_pkt)
#define ethernet_buffer_header_size(b)
Determine the size of the Ethernet headers of the current frame in the buffer.
static int fa_acl_match_port(u16 port, u16 port_first, u16 port_last, int is_ip6)
u16 current_length
Nbytes between current data and the end of this buffer.
static int fa_acl_match_ip6_addr(ip6_address_t *addr1, ip6_address_t *addr2, int prefixlen)
struct _tcp_header tcp_header_t
static void * get_ptr_to_offset(vlib_buffer_t *b0, int offset)
u16 dst_port_or_code_last
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void acl_fill_5tuple_l4_and_pkt_data(acl_main_t *am, u32 sw_if_index0, vlib_buffer_t *b0, int is_ip6, int is_input, int l3_offset, fa_session_l4_key_t *p5tuple_l4, fa_packet_info_t *p5tuple_pkt)
static int hash_multi_acl_match_5tuple(void *p_acl_main, u32 lc_index, fa_5tuple_t *pkt_5tuple, int is_ip6, u8 *action, u32 *acl_pos_p, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap)
static u32 multi_acl_match_get_applied_ace_index(acl_main_t *am, int is_ip6, fa_5tuple_t *match)
static void acl_plugin_fill_5tuple_inline(void *p_acl_main, u32 lc_index, vlib_buffer_t *b0, int is_ip6, int is_input, int is_l2_path, fa_5tuple_opaque_t *p5tuple_pkt)
collision_match_rule_t * colliding_rules
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u16 dst_port_or_code_first
hash_applied_mask_info_t ** hash_applied_mask_info_vec_by_lc_index
uword * fa_ipv6_known_eh_bitmap
static int acl_plugin_match_5tuple_inline_and_count(void *p_acl_main, u32 lc_index, fa_5tuple_opaque_t *pkt_5tuple, int is_ip6, u8 *r_action, u32 *r_acl_pos_p, u32 *r_acl_match_p, u32 *r_rule_match_p, u32 *trace_bitmap, u32 packet_size)
static int ip4_get_fragment_offset(const ip4_header_t *i)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
clib_bihash_48_8_t acl_lookup_hash
u16 src_port_or_type_first
#define clib_warning(format, args...)
int use_hash_acl_matching
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
static clib_error_t * acl_plugin_exports_init(acl_plugin_methods_t *m)
applied_hash_ace_entry_t ** hash_entry_vec_by_lc_index
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
static int single_acl_match_5tuple(acl_main_t *am, u32 acl_index, fa_5tuple_t *pkt_5tuple, int is_ip6, u8 *r_action, u32 *r_acl_match_p, u32 *r_rule_match_p, u32 *trace_bitmap)
static int offset_within_packet(vlib_buffer_t *b0, int offset)
static int match_portranges(acl_main_t *am, fa_5tuple_t *match, u32 index)
static int acl_plugin_match_5tuple_inline(void *p_acl_main, u32 lc_index, fa_5tuple_opaque_t *pkt_5tuple, int is_ip6, u8 *r_action, u32 *r_acl_pos_p, u32 *r_acl_match_p, u32 *r_rule_match_p, u32 *trace_bitmap)
u16 src_port_or_type_last
static int offset_beyond_packet(vlib_buffer_t *b0, int offset)
ace_mask_type_entry_t * ace_mask_type_pool
static int single_rule_match_5tuple(acl_rule_t *r, int is_ip6, fa_5tuple_t *pkt_5tuple)
template key/value backing page structure
acl_lookup_context_t * acl_lookup_contexts
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
VLIB buffer representation.
static_always_inline uword os_get_thread_index(void)
clib_error_t *(* acl_plugin_methods_vtable_init_fn_t)(acl_plugin_methods_t *m)
struct clib_bihash_value offset
template key/value backing page structure
#define LOAD_SYMBOL_FROM_PLUGIN_TO(p, s, st)
ip4_address_t ip4_addr[2]
static int ip4_header_bytes(const ip4_header_t *i)
static int linear_multi_acl_match_5tuple(void *p_acl_main, u32 lc_index, fa_5tuple_t *pkt_5tuple, int is_ip6, u8 *r_action, u32 *acl_pos_p, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap)
vl_api_fib_path_nh_proto_t proto
ip6_address_t ip6_addr[2]