-fa_acl_match_port (u16 port, u16 port_first, u16 port_last, int is_ip6)
-{
- return ((port >= port_first) && (port <= port_last));
-}
-
-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)
-{
- int i;
- acl_list_t *a;
- acl_rule_t *r;
-
- if (pool_is_free_index (am->acls, acl_index))
- {
- if (r_acl_match_p)
- *r_acl_match_p = acl_index;
- if (r_rule_match_p)
- *r_rule_match_p = -1;
- /* the ACL does not exist but is used for policy. Block traffic. */
- return 0;
- }
- a = am->acls + acl_index;
- for (i = 0; i < a->count; i++)
- {
- r = a->rules + i;
- if (is_ip6 != r->is_ipv6)
- {
- continue;
- }
- if (!fa_acl_match_addr
- (&pkt_5tuple->addr[1], &r->dst, r->dst_prefixlen, is_ip6))
- continue;
-
-#ifdef FA_NODE_VERBOSE_DEBUG
- clib_warning
- ("ACL_FA_NODE_DBG acl %d rule %d pkt dst addr %U match rule addr %U/%d",
- acl_index, i, format_ip46_address, &pkt_5tuple->addr[1],
- r->is_ipv6 ? IP46_TYPE_IP6: IP46_TYPE_IP4, format_ip46_address,
- &r->dst, r->is_ipv6 ? IP46_TYPE_IP6: IP46_TYPE_IP4,
- r->dst_prefixlen);
-#endif
-
- if (!fa_acl_match_addr
- (&pkt_5tuple->addr[0], &r->src, r->src_prefixlen, is_ip6))
- continue;
-
-#ifdef FA_NODE_VERBOSE_DEBUG
- clib_warning
- ("ACL_FA_NODE_DBG acl %d rule %d pkt src addr %U match rule addr %U/%d",
- acl_index, i, format_ip46_address, &pkt_5tuple->addr[0],
- r->is_ipv6 ? IP46_TYPE_IP6: IP46_TYPE_IP4, format_ip46_address,
- &r->src, r->is_ipv6 ? IP46_TYPE_IP6: IP46_TYPE_IP4,
- r->src_prefixlen);
- clib_warning
- ("ACL_FA_NODE_DBG acl %d rule %d trying to match pkt proto %d with rule %d",
- acl_index, i, pkt_5tuple->l4.proto, r->proto);
-#endif
- if (r->proto)
- {
- if (pkt_5tuple->l4.proto != r->proto)
- continue;
-
- if (PREDICT_FALSE (pkt_5tuple->pkt.is_nonfirst_fragment &&
- am->l4_match_nonfirst_fragment))
- {
- /* non-initial fragment with frag match configured - match this rule */
- *trace_bitmap |= 0x80000000;
- *r_action = r->is_permit;
- if (r_acl_match_p)
- *r_acl_match_p = acl_index;
- if (r_rule_match_p)
- *r_rule_match_p = i;
- return 1;
- }
-
- /* A sanity check just to ensure we are about to match the ports extracted from the packet */
- if (PREDICT_FALSE (!pkt_5tuple->pkt.l4_valid))
- continue;
-
-#ifdef FA_NODE_VERBOSE_DEBUG
- clib_warning
- ("ACL_FA_NODE_DBG acl %d rule %d pkt proto %d match rule %d",
- acl_index, i, pkt_5tuple->l4.proto, r->proto);
-#endif
-
- if (!fa_acl_match_port
- (pkt_5tuple->l4.port[0], r->src_port_or_type_first,
- r->src_port_or_type_last, is_ip6))
- continue;
-
-#ifdef FA_NODE_VERBOSE_DEBUG
- clib_warning
- ("ACL_FA_NODE_DBG acl %d rule %d pkt sport %d match rule [%d..%d]",
- acl_index, i, pkt_5tuple->l4.port[0], r->src_port_or_type_first,
- r->src_port_or_type_last);
-#endif
-
- if (!fa_acl_match_port
- (pkt_5tuple->l4.port[1], r->dst_port_or_code_first,
- r->dst_port_or_code_last, is_ip6))
- continue;
-
-#ifdef FA_NODE_VERBOSE_DEBUG
- clib_warning
- ("ACL_FA_NODE_DBG acl %d rule %d pkt dport %d match rule [%d..%d]",
- acl_index, i, pkt_5tuple->l4.port[1], r->dst_port_or_code_first,
- r->dst_port_or_code_last);
-#endif
- if (pkt_5tuple->pkt.tcp_flags_valid
- && ((pkt_5tuple->pkt.tcp_flags & r->tcp_flags_mask) !=
- r->tcp_flags_value))
- continue;
- }
- /* everything matches! */
-#ifdef FA_NODE_VERBOSE_DEBUG
- clib_warning ("ACL_FA_NODE_DBG acl %d rule %d FULL-MATCH, action %d",
- acl_index, i, r->is_permit);
-#endif
- *r_action = r->is_permit;
- if (r_acl_match_p)
- *r_acl_match_p = acl_index;
- if (r_rule_match_p)
- *r_rule_match_p = i;
- return 1;
- }
- return 0;
-}
-
-static u8
-linear_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)
-{
- acl_main_t *am = &acl_main;
- int i;
- u32 *acl_vector;
- u8 action = 0;
-
- if (is_input)
- {
- vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
- acl_vector = am->input_acl_vec_by_sw_if_index[sw_if_index];
- }
- else
- {
- vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
- acl_vector = am->output_acl_vec_by_sw_if_index[sw_if_index];
- }
- for (i = 0; i < vec_len (acl_vector); i++)
- {
-#ifdef FA_NODE_VERBOSE_DEBUG
- clib_warning ("ACL_FA_NODE_DBG: Trying to match ACL: %d",
- acl_vector[i]);
-#endif
- if (single_acl_match_5tuple
- (am, acl_vector[i], pkt_5tuple, is_ip6, &action,
- acl_match_p, rule_match_p, trace_bitmap))
- {
- return action;
- }
- }
- if (vec_len (acl_vector) > 0)
- {
- /* If there are ACLs and none matched, deny by default */
- return 0;
- }
-#ifdef FA_NODE_VERBOSE_DEBUG
- clib_warning ("ACL_FA_NODE_DBG: No ACL on sw_if_index %d", sw_if_index);
-#endif
- /* Deny by default. If there are no ACLs defined we should not be here. */
- return 0;
-}
-
-static u8
-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)