16 #ifndef included_acl_inlines_h 17 #define included_acl_inlines_h 28 #ifdef ACL_PLUGIN_EXTERNAL_EXPORTS 46 #ifdef ACL_PLUGIN_EXTERNAL_EXPORTS 58 #ifdef ACL_PLUGIN_EXTERNAL_EXPORTS 68 #ifdef ACL_PLUGIN_EXTERNAL_EXPORTS 78 #ifdef ACL_PLUGIN_EXTERNAL_EXPORTS 86 #ifdef ACL_PLUGIN_EXTERNAL_EXPORTS 94 #ifdef ACL_PLUGIN_DEFINED_BELOW_IN_FILE 104 #ifdef ACL_PLUGIN_EXTERNAL_EXPORTS 107 int is_ip6,
u8 * r_action,
110 u32 * r_rule_match_p,
115 int is_ip6,
u8 * r_action,
118 u32 * r_rule_match_p,
122 #ifdef ACL_PLUGIN_DEFINED_BELOW_IN_FILE 126 int is_ip6,
u8 * r_action,
129 u32 * r_rule_match_p,
130 u32 * trace_bitmap) {
131 return acl_plugin_match_5tuple(lc_index, pkt_5tuple, is_ip6, r_action, r_acl_pos_p, r_acl_match_p, r_rule_match_p, trace_bitmap);
135 #ifdef ACL_PLUGIN_EXTERNAL_EXPORTS 137 #define LOAD_SYMBOL_FROM_PLUGIN_TO(p, s, st) \ 139 st = vlib_get_plugin_symbol(p, #s); \ 141 return clib_error_return(0, \ 142 "Plugin %s and/or symbol %s not found.", p, #s); \ 145 #define LOAD_SYMBOL(s) LOAD_SYMBOL_FROM_PLUGIN_TO("acl_plugin.so", s, s) 147 static inline clib_error_t * acl_plugin_exports_init (
void)
149 LOAD_SYMBOL_FROM_PLUGIN_TO(
"acl_plugin.so",
acl_main, p_acl_main);
180 int is_input,
int is_l2_path,
fa_5tuple_t * p5tuple_pkt)
183 static u8 icmp_protos_v4v6[] = { IP_PROTOCOL_ICMP, IP_PROTOCOL_ICMP6 };
199 l3_offset =
vnet_buffer(b0)->ip.save_rewrite_length;
204 p5tuple_pkt->
kv.
key[4] = 0;
213 src_address) + l3_offset),
214 sizeof (p5tuple_pkt->
addr));
218 protocol) + l3_offset);
220 #ifdef FA_NODE_VERBOSE_DEBUG 221 clib_warning (
"ACL_FA_NODE_DBG: proto: %d, l4_offset: %d", proto,
236 frag_offset = clib_net_to_host_u16(frag_offset) >> 3;
253 l4_offset += 8 * (1 + (
u16) nwords);
255 #ifdef FA_NODE_VERBOSE_DEBUG 256 clib_warning (
"ACL_FA_NODE_DBG: new proto: %d, new offset: %d",
266 p5tuple_pkt->
kv.
key[0] = 0;
267 p5tuple_pkt->
kv.
key[1] = 0;
268 p5tuple_pkt->
kv.
key[2] = 0;
269 p5tuple_pkt->
kv.
key[3] = 0;
273 src_address) + l3_offset),
274 sizeof (p5tuple_pkt->
addr[0].ip4));
278 dst_address) + l3_offset),
279 sizeof (p5tuple_pkt->
addr[1].ip4));
283 protocol) + l3_offset);
285 u16 flags_and_fragment_offset;
289 flags_and_fragment_offset)) + l3_offset,
290 sizeof(flags_and_fragment_offset));
291 flags_and_fragment_offset = clib_net_to_host_u16 (flags_and_fragment_offset);
306 if (icmp_protos_v4v6[is_ip6] == proto)
311 l4_offset + offsetof (icmp46_header_t,
316 l4_offset + offsetof (icmp46_header_t,
319 else if ((IP_PROTOCOL_TCP == proto) || (IP_PROTOCOL_UDP == proto))
326 p5tuple_pkt->
l4.
port[0] = clib_net_to_host_u16 (ports[0]);
327 p5tuple_pkt->
l4.
port[1] = clib_net_to_host_u16 (ports[1]);
364 int prefixlen,
int is_ip6)
373 if (memcmp (addr1, addr2, prefixlen / 8))
380 u8 b1 = *((
u8 *) addr1 + 1 + prefixlen / 8);
381 u8 b2 = *((
u8 *) addr2 + 1 + prefixlen / 8);
382 u8 mask0 = (0xff - ((1 << (8 - (prefixlen % 8))) - 1));
383 return (b1 & mask0) == b2;
393 uint32_t a1 = clib_net_to_host_u32 (addr1->ip4.as_u32);
394 uint32_t a2 = clib_net_to_host_u32 (addr2->ip4.as_u32);
395 uint32_t mask0 = 0xffffffff - ((1 << (32 - prefixlen)) - 1);
396 return (a1 & mask0) == a2;
403 return ((port >= port_first) && (port <= port_last));
408 int is_ip6,
u8 * r_action,
u32 * r_acl_match_p,
409 u32 * r_rule_match_p,
u32 * trace_bitmap)
418 *r_acl_match_p = acl_index;
420 *r_rule_match_p = -1;
424 a = am->
acls + acl_index;
425 for (i = 0; i < a->
count; i++)
428 #ifdef FA_NODE_VERBOSE_DEBUG 429 clib_warning(
"ACL_FA_NODE_DBG acl %d rule %d tag %s", acl_index, i, a->
tag);
439 #ifdef FA_NODE_VERBOSE_DEBUG 441 (
"ACL_FA_NODE_DBG acl %d rule %d pkt dst addr %U match rule addr %U/%d",
452 #ifdef FA_NODE_VERBOSE_DEBUG 454 (
"ACL_FA_NODE_DBG acl %d rule %d pkt src addr %U match rule addr %U/%d",
460 (
"ACL_FA_NODE_DBG acl %d rule %d trying to match pkt proto %d with rule %d",
472 *trace_bitmap |= 0x80000000;
475 *r_acl_match_p = acl_index;
485 #ifdef FA_NODE_VERBOSE_DEBUG 487 (
"ACL_FA_NODE_DBG acl %d rule %d pkt proto %d match rule %d",
496 #ifdef FA_NODE_VERBOSE_DEBUG 498 (
"ACL_FA_NODE_DBG acl %d rule %d pkt sport %d match rule [%d..%d]",
508 #ifdef FA_NODE_VERBOSE_DEBUG 510 (
"ACL_FA_NODE_DBG acl %d rule %d pkt dport %d match rule [%d..%d]",
520 #ifdef FA_NODE_VERBOSE_DEBUG 521 clib_warning (
"ACL_FA_NODE_DBG acl %d rule %d FULL-MATCH, action %d",
526 *r_acl_match_p = acl_index;
536 int is_ip6,
u8 * r_action,
u32 * r_acl_match_p,
537 u32 * r_rule_match_p,
u32 * trace_bitmap)
541 r_acl_match_p, r_rule_match_p, trace_bitmap);
546 int is_ip6,
u8 *r_action,
u32 *acl_pos_p,
u32 * acl_match_p,
547 u32 * rule_match_p,
u32 * trace_bitmap)
557 for (i = 0; i <
vec_len (acl_vector); i++)
559 #ifdef FA_NODE_VERBOSE_DEBUG 560 clib_warning (
"ACL_FA_NODE_DBG: Trying to match ACL: %d",
564 (am, acl_vector[i], pkt_5tuple, is_ip6, &action,
565 acl_match_p, rule_match_p, trace_bitmap))
572 if (vec_len (acl_vector) > 0)
576 #ifdef FA_NODE_VERBOSE_DEBUG 577 clib_warning (
"ACL_FA_NODE_DBG: No ACL on lc_index %d", lc_index);
599 #ifdef FA_NODE_VERBOSE_DEBUG 600 clib_warning(
"PORTMATCH: %d <= %d <= %d && %d <= %d <= %d ?",
616 u64 *pmatch = (
u64 *)match;
620 u32 curr_match_index = ~0;
626 DBG(
"TRYING TO MATCH: %016llx %016llx %016llx %016llx %016llx %016llx",
627 pmatch[0], pmatch[1], pmatch[2], pmatch[3], pmatch[4], pmatch[5]);
635 pmatch = (
u64 *)match;
646 *pkey++ = *pmatch++ & *pmask++;
647 *pkey++ = *pmatch++ & *pmask++;
648 *pkey++ = *pmatch++ & *pmask++;
649 *pkey++ = *pmatch++ & *pmask++;
650 *pkey++ = *pmatch++ & *pmask++;
651 *pkey++ = *pmatch++ & *pmask++;
654 DBG(
" KEY %3d: %016llx %016llx %016llx %016llx %016llx %016llx", mask_type_index,
656 int res = clib_bihash_search_48_8 (&am->
acl_lookup_hash, &kv, &result);
658 DBG(
"ACL-MATCH! result_val: %016llx", result_val->as_u64);
659 if (result_val->applied_entry_index < curr_match_index) {
668 u32 curr_index = result_val->applied_entry_index;
675 if (curr_index < curr_match_index) {
676 DBG(
"The index %d is the new candidate in portrange matches.", curr_index);
677 curr_match_index = curr_index;
679 DBG(
"Curr portmatch index %d is too big vs. current matched one %d", curr_index, curr_match_index);
683 DBG(
"This match is the new candidate");
684 curr_match_index = result_val->applied_entry_index;
685 if (!result_val->shadowed) {
693 DBG(
"MATCH-RESULT: %d", curr_match_index);
694 return curr_match_index;
699 int is_ip6,
u8 *action,
u32 *acl_pos_p,
u32 * acl_match_p,
700 u32 * rule_match_p,
u32 * trace_bitmap)
705 if (match_index <
vec_len((*applied_hash_aces))) {
722 int is_ip6,
u8 * r_action,
725 u32 * r_rule_match_p,
733 r_acl_pos_p, r_acl_match_p, r_rule_match_p, trace_bitmap);
736 r_acl_pos_p, r_acl_match_p, r_rule_match_p, trace_bitmap);
int l4_match_nonfirst_fragment
#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)
static int acl_plugin_single_acl_match_5tuple(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)
struct _tcp_header tcp_header_t
#define pool_len(p)
Number of elements in pool vector.
static void * get_ptr_to_offset(vlib_buffer_t *b0, int offset)
u16 dst_port_or_code_last
u32 next_applied_entry_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
void acl_plugin_put_lookup_context_index(u32 lc_index)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u16 current_length
Nbytes between current data and the end of this buffer.
u16 dst_port_or_code_first
static void acl_fill_5tuple(acl_main_t *am, vlib_buffer_t *b0, int is_ip6, int is_input, int is_l2_path, fa_5tuple_t *p5tuple_pkt)
uword * fa_ipv6_known_eh_bitmap
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static int linear_multi_acl_match_5tuple(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)
clib_bihash_48_8_t acl_lookup_hash
u16 src_port_or_type_first
applied_hash_acl_info_t * applied_hash_acl_info_by_lc_index
#define clib_warning(format, args...)
#define clib_memcpy(a, b, c)
int use_hash_acl_matching
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
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 hash_multi_acl_match_5tuple(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)
u16 src_port_or_type_last
static int acl_plugin_match_5tuple_inline(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)
static int fa_acl_match_addr(ip46_address_t *addr1, ip46_address_t *addr2, int prefixlen, int is_ip6)
ace_mask_type_entry_t * ace_mask_type_pool
template key/value backing page structure
acl_lookup_context_t * acl_lookup_contexts
int acl_plugin_get_lookup_context_index(u32 acl_user_id, u32 val1, u32 val2)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
int acl_plugin_set_acl_vec_for_context(u32 lc_index, u32 *acl_list)
struct clib_bihash_value offset
template key/value backing page structure
static u32 multi_acl_match_get_applied_ace_index(acl_main_t *am, fa_5tuple_t *match)
u32 acl_plugin_register_user_module(char *caller_module_string, char *val1_label, char *val2_label)
u8 acl_plugin_acl_exists(u32 acl_index)
int acl_plugin_match_5tuple(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)
static void acl_plugin_fill_5tuple_inline(u32 lc_index, vlib_buffer_t *b0, int is_ip6, int is_input, int is_l2_path, fa_5tuple_opaque_t *p5tuple_pkt)
void acl_plugin_fill_5tuple(u32 lc_index, vlib_buffer_t *b0, int is_ip6, int is_input, int is_l2_path, fa_5tuple_opaque_t *p5tuple_pkt)