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));
292 u32 * r_rule_match_p,
u32 * trace_bitmap)
303 *r_rule_match_p = -1;
317 (&pkt_5tuple->
ip6_addr[1], &
r->dst.ip6,
r->dst_prefixlen))
320 (&pkt_5tuple->
ip6_addr[0], &
r->src.ip6,
r->src_prefixlen))
324 (&pkt_5tuple->
ip4_addr[1], &
r->dst.ip4,
r->dst_prefixlen))
327 (&pkt_5tuple->
ip4_addr[0], &
r->src.ip4,
r->src_prefixlen))
333 if (pkt_5tuple->
l4.
proto !=
r->proto)
337 am->l4_match_nonfirst_fragment))
340 *trace_bitmap |= 0x80000000;
341 *r_action =
r->is_permit;
353 #ifdef FA_NODE_VERBOSE_DEBUG
355 (
"ACL_FA_NODE_DBG acl %d rule %d pkt proto %d match rule %d",
360 (pkt_5tuple->
l4.
port[0],
r->src_port_or_type_first,
361 r->src_port_or_type_last,
is_ip6))
364 #ifdef FA_NODE_VERBOSE_DEBUG
366 (
"ACL_FA_NODE_DBG acl %d rule %d pkt sport %d match rule [%d..%d]",
368 r->src_port_or_type_last);
372 (pkt_5tuple->
l4.
port[1],
r->dst_port_or_code_first,
373 r->dst_port_or_code_last,
is_ip6))
376 #ifdef FA_NODE_VERBOSE_DEBUG
378 (
"ACL_FA_NODE_DBG acl %d rule %d pkt dport %d match rule [%d..%d]",
380 r->dst_port_or_code_last);
388 #ifdef FA_NODE_VERBOSE_DEBUG
389 clib_warning (
"ACL_FA_NODE_DBG acl %d rule %d FULL-MATCH, action %d",
392 *r_action =
r->is_permit;
405 u32 * r_rule_match_p,
u32 * trace_bitmap)
409 r_acl_match_p, r_rule_match_p, trace_bitmap);
415 u32 * rule_match_p,
u32 * trace_bitmap)
427 #ifdef FA_NODE_VERBOSE_DEBUG
428 clib_warning (
"ACL_FA_NODE_DBG: Trying to match ACL: %d",
433 acl_match_p, rule_match_p, trace_bitmap))
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 ?",
469 r->src_port_or_type_first, match->
l4.
port[0],
r->src_port_or_type_last,
470 r->dst_port_or_code_first, match->
l4.
port[1],
r->dst_port_or_code_last);
473 return ( ((
r->src_port_or_type_first <= match->
l4.
port[0]) &&
r->src_port_or_type_last >= match->
l4.
port[0]) &&
474 ((
r->dst_port_or_code_first <= match->
l4.
port[1]) &&
r->dst_port_or_code_last >= match->
l4.
port[1]) );
488 (&pkt_5tuple->
ip6_addr[1], &
r->dst.ip6,
r->dst_prefixlen))
491 (&pkt_5tuple->
ip6_addr[0], &
r->src.ip6,
r->src_prefixlen))
497 (&pkt_5tuple->
ip4_addr[1], &
r->dst.ip4,
r->dst_prefixlen))
500 (&pkt_5tuple->
ip4_addr[0], &
r->src.ip4,
r->src_prefixlen))
506 if (pkt_5tuple->
l4.
proto !=
r->proto)
515 (pkt_5tuple->
l4.
port[0],
r->src_port_or_type_first,
516 r->src_port_or_type_last, pkt_5tuple->
pkt.
is_ip6))
521 (pkt_5tuple->
l4.
port[1],
r->dst_port_or_code_first,
522 r->dst_port_or_code_last, pkt_5tuple->
pkt.
is_ip6))
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++;
603 clib_bihash_search_inline_2_48_8 (&
am->acl_lookup_hash, &kv, &result);
608 u32 curr_index = result_val->applied_entry_index;
615 if (crs[
i].applied_entry_index >= curr_match_index)
626 DBG (
"MATCH-RESULT: %d", curr_match_index);
627 return curr_match_index;
633 u32 * rule_match_p,
u32 * trace_bitmap)
638 if (match_index <
vec_len((*applied_hash_aces))) {
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);
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);