2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
22 #include <vnet/l2/l2_classify.h>
23 #include <vnet/l2/l2_in_out_feat_arc.h>
24 #include <vnet/classify/in_out_acl.h>
25 #include <vpp/app/version.h>
27 #include <vnet/ethernet/ethernet_types_api.h>
29 #include <vlibapi/api.h>
30 #include <vlibmemory/api.h>
32 /* define message IDs */
33 #include <acl/acl.api_enum.h>
34 #include <acl/acl.api_types.h>
36 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
37 #include "manual_fns.h"
40 #include "public_inlines.h"
44 #define REPLY_MSG_ID_BASE am->msg_id_base
45 #include <vlibapi/api_helper_macros.h>
48 * The code for the bihash, used by the session management.
50 #include <vppinfra/bihash_40_8.h>
51 #include <vppinfra/bihash_template.h>
52 #include <vppinfra/bihash_template.c>
55 VLIB_PLUGIN_REGISTER () = {
56 .version = VPP_BUILD_VER,
57 .description = "Access Control Lists (ACL)",
61 /* methods exported from ACL-as-a-service */
62 static acl_plugin_methods_t acl_plugin;
66 format_vec16 (u8 * s, va_list * va)
68 u16 *v = va_arg (*va, u16 *);
69 char *fmt = va_arg (*va, char *);
71 for (i = 0; i < vec_len (v); i++)
75 s = format (s, fmt, v[i]);
81 acl_set_heap (acl_main_t * am)
83 if (0 == am->acl_mheap)
85 if (0 == am->acl_mheap_size)
87 vlib_thread_main_t *tm = vlib_get_thread_main ();
88 u64 per_worker_slack = 1000000LL;
91 ((u64) am->fa_conn_table_max_entries) * sizeof (fa_session_t);
92 u64 per_worker_size_with_slack = per_worker_slack + per_worker_size;
93 u64 main_slack = 2000000LL;
94 u64 bihash_size = (u64) am->fa_conn_table_hash_memory_size;
97 per_worker_size_with_slack * tm->n_vlib_mains + bihash_size +
100 u64 max_possible = ((uword) ~ 0);
101 if (am->acl_mheap_size > max_possible)
103 clib_warning ("ACL heap size requested: %lld, max possible %lld",
104 am->acl_mheap_size, max_possible);
107 am->acl_mheap = mheap_alloc_with_lock (0 /* use VM */ ,
110 if (0 == am->acl_mheap)
113 ("ACL plugin failed to allocate main heap of %U bytes, abort",
114 format_memory_size, am->acl_mheap_size);
117 void *oldheap = clib_mem_set_heap (am->acl_mheap);
122 acl_plugin_set_heap ()
124 acl_main_t *am = &acl_main;
125 return acl_set_heap (am);
129 acl_plugin_acl_set_validate_heap (acl_main_t * am, int on)
131 clib_mem_set_heap (acl_set_heap (am));
135 acl_plugin_acl_set_trace_heap (acl_main_t * am, int on)
137 clib_mem_set_heap (acl_set_heap (am));
141 vl_api_acl_plugin_get_version_t_handler (vl_api_acl_plugin_get_version_t * mp)
143 acl_main_t *am = &acl_main;
144 vl_api_acl_plugin_get_version_reply_t *rmp;
145 int msg_size = sizeof (*rmp);
146 vl_api_registration_t *reg;
148 reg = vl_api_client_index_to_registration (mp->client_index);
152 rmp = vl_msg_api_alloc (msg_size);
153 clib_memset (rmp, 0, msg_size);
155 ntohs (VL_API_ACL_PLUGIN_GET_VERSION_REPLY + am->msg_id_base);
156 rmp->context = mp->context;
157 rmp->major = htonl (ACL_PLUGIN_VERSION_MAJOR);
158 rmp->minor = htonl (ACL_PLUGIN_VERSION_MINOR);
160 vl_api_send_msg (reg, (u8 *) rmp);
164 vl_api_acl_plugin_control_ping_t_handler (vl_api_acl_plugin_control_ping_t *
167 vl_api_acl_plugin_control_ping_reply_t *rmp;
168 acl_main_t *am = &acl_main;
172 REPLY_MACRO2 (VL_API_ACL_PLUGIN_CONTROL_PING_REPLY,
174 rmp->vpe_pid = ntohl (getpid ());
180 print_clib_warning_and_reset (vlib_main_t * vm, u8 * out0)
182 clib_warning ("%v", out0);
183 vec_reset_length (out0);
187 print_cli_and_reset (vlib_main_t * vm, u8 * out0)
189 vlib_cli_output (vm, "%v", out0);
190 vec_reset_length (out0);
193 typedef void (*acl_vector_print_func_t) (vlib_main_t * vm, u8 * out0);
196 acl_print_acl_x (acl_vector_print_func_t vpr, vlib_main_t * vm,
197 acl_main_t * am, int acl_index)
200 acl_rule_t *acl_rules = am->acls[acl_index].rules;
201 u8 *out0 = format (0, "acl-index %u count %u tag {%s}\n", acl_index,
202 vec_len (acl_rules), am->acls[acl_index].tag);
205 for (j = 0; j < vec_len (acl_rules); j++)
208 out0 = format (out0, " %9d: %s ", j, r->is_ipv6 ? "ipv6" : "ipv4");
209 out0 = format_acl_action (out0, r->is_permit);
210 out0 = format (out0, " src %U/%d", format_ip46_address, &r->src,
211 r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
214 format (out0, " dst %U/%d", format_ip46_address, &r->dst,
215 r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4, r->dst_prefixlen);
216 out0 = format (out0, " proto %d", r->proto);
217 out0 = format (out0, " sport %d", r->src_port_or_type_first);
218 if (r->src_port_or_type_first != r->src_port_or_type_last)
220 out0 = format (out0, "-%d", r->src_port_or_type_last);
222 out0 = format (out0, " dport %d", r->dst_port_or_code_first);
223 if (r->dst_port_or_code_first != r->dst_port_or_code_last)
225 out0 = format (out0, "-%d", r->dst_port_or_code_last);
227 if (r->tcp_flags_mask || r->tcp_flags_value)
230 format (out0, " tcpflags %d mask %d", r->tcp_flags_value,
233 out0 = format (out0, "\n");
239 vl_api_acl_plugin_get_conn_table_max_entries_t_handler
240 (vl_api_acl_plugin_get_conn_table_max_entries_t * mp)
242 acl_main_t *am = &acl_main;
243 vl_api_acl_plugin_get_conn_table_max_entries_reply_t *rmp;
244 int msg_size = sizeof (*rmp);
245 vl_api_registration_t *rp;
247 rp = vl_api_client_index_to_registration (mp->client_index);
251 rmp = vl_msg_api_alloc (msg_size);
252 memset (rmp, 0, msg_size);
254 ntohs (VL_API_ACL_PLUGIN_GET_CONN_TABLE_MAX_ENTRIES_REPLY +
256 rmp->context = mp->context;
257 rmp->conn_table_max_entries = __bswap_64 (am->fa_conn_table_max_entries);
259 vl_api_send_msg (rp, (u8 *) rmp);
263 acl_print_acl (vlib_main_t * vm, acl_main_t * am, int acl_index)
265 acl_print_acl_x (print_cli_and_reset, vm, am, acl_index);
269 warning_acl_print_acl (vlib_main_t * vm, acl_main_t * am, int acl_index)
271 acl_print_acl_x (print_clib_warning_and_reset, vm, am, acl_index);
275 increment_policy_epoch (acl_main_t * am, u32 sw_if_index, int is_input)
278 u32 **ppolicy_epoch_by_swi =
279 is_input ? &am->input_policy_epoch_by_sw_if_index :
280 &am->output_policy_epoch_by_sw_if_index;
281 vec_validate (*ppolicy_epoch_by_swi, sw_if_index);
283 u32 *p_epoch = vec_elt_at_index ((*ppolicy_epoch_by_swi), sw_if_index);
285 ((1 + *p_epoch) & FA_POLICY_EPOCH_MASK) +
286 (is_input * FA_POLICY_EPOCH_IS_INPUT);
290 try_increment_acl_policy_epoch (acl_main_t * am, u32 acl_num, int is_input)
292 u32 ***p_swi_vec_by_acl = is_input ? &am->input_sw_if_index_vec_by_acl
293 : &am->output_sw_if_index_vec_by_acl;
294 if (acl_num < vec_len (*p_swi_vec_by_acl))
297 vec_foreach (p_swi, (*p_swi_vec_by_acl)[acl_num])
299 increment_policy_epoch (am, *p_swi, is_input);
306 policy_notify_acl_change (acl_main_t * am, u32 acl_num)
308 try_increment_acl_policy_epoch (am, acl_num, 0);
309 try_increment_acl_policy_epoch (am, acl_num, 1);
314 validate_and_reset_acl_counters (acl_main_t * am, u32 acl_index)
317 /* counters are set as vectors [acl#] pointing to vectors of [acl rule] */
318 acl_plugin_counter_lock (am);
320 int old_len = vec_len (am->combined_acl_counters);
322 vec_validate (am->combined_acl_counters, acl_index);
324 for (i = old_len; i < vec_len (am->combined_acl_counters); i++)
326 am->combined_acl_counters[i].name = 0;
327 /* filled in once only */
328 am->combined_acl_counters[i].stat_segment_name = (void *)
329 format (0, "/acl/%d/matches%c", i, 0);
330 i32 rule_count = vec_len (am->acls[i].rules);
331 /* Validate one extra so we always have at least one counter for an ACL */
332 vlib_validate_combined_counter (&am->combined_acl_counters[i],
334 vlib_clear_combined_counters (&am->combined_acl_counters[i]);
337 /* (re)validate for the actual ACL that is getting added/updated */
338 i32 rule_count = vec_len (am->acls[acl_index].rules);
339 /* Validate one extra so we always have at least one counter for an ACL */
340 vlib_validate_combined_counter (&am->combined_acl_counters[acl_index],
342 vlib_clear_combined_counters (&am->combined_acl_counters[acl_index]);
343 acl_plugin_counter_unlock (am);
347 acl_api_invalid_prefix (const vl_api_prefix_t * prefix)
349 ip_prefix_t ip_prefix;
350 return ip_prefix_decode2 (prefix, &ip_prefix);
354 acl_add_list (u32 count, vl_api_acl_rule_t rules[],
355 u32 * acl_list_index, u8 * tag)
357 acl_main_t *am = &acl_main;
360 acl_rule_t *acl_new_rules = 0;
363 if (am->trace_acl > 255)
364 clib_warning ("API dbg: acl_add_list index %d tag %s", *acl_list_index,
367 /* check if what they request is consistent */
368 for (i = 0; i < count; i++)
370 if (acl_api_invalid_prefix (&rules[i].src_prefix))
371 return VNET_API_ERROR_INVALID_SRC_ADDRESS;
372 if (acl_api_invalid_prefix (&rules[i].dst_prefix))
373 return VNET_API_ERROR_INVALID_DST_ADDRESS;
374 if (ntohs (rules[i].srcport_or_icmptype_first) >
375 ntohs (rules[i].srcport_or_icmptype_last))
376 return VNET_API_ERROR_INVALID_VALUE_2;
377 if (ntohs (rules[i].dstport_or_icmpcode_first) >
378 ntohs (rules[i].dstport_or_icmpcode_last))
379 return VNET_API_ERROR_INVALID_VALUE_2;
382 if (*acl_list_index != ~0)
384 /* They supplied some number, let's see if this ACL exists */
385 if (pool_is_free_index (am->acls, *acl_list_index))
387 /* tried to replace a non-existent ACL, no point doing anything */
389 ("acl-plugin-error: Trying to replace nonexistent ACL %d (tag %s)",
390 *acl_list_index, tag);
391 return VNET_API_ERROR_NO_SUCH_ENTRY;
397 ("acl-plugin-warning: supplied no rules for ACL %d (tag %s)",
398 *acl_list_index, tag);
401 void *oldheap = acl_set_heap (am);
403 /* Create and populate the rules */
405 vec_validate (acl_new_rules, count - 1);
407 for (i = 0; i < count; i++)
409 r = vec_elt_at_index (acl_new_rules, i);
410 clib_memset (r, 0, sizeof (*r));
411 r->is_permit = rules[i].is_permit;
412 r->is_ipv6 = rules[i].src_prefix.address.af;
413 ip_address_decode (&rules[i].src_prefix.address, &r->src);
414 ip_address_decode (&rules[i].dst_prefix.address, &r->dst);
415 r->src_prefixlen = rules[i].src_prefix.len;
416 r->dst_prefixlen = rules[i].dst_prefix.len;
417 r->proto = rules[i].proto;
418 r->src_port_or_type_first = ntohs (rules[i].srcport_or_icmptype_first);
419 r->src_port_or_type_last = ntohs (rules[i].srcport_or_icmptype_last);
420 r->dst_port_or_code_first = ntohs (rules[i].dstport_or_icmpcode_first);
421 r->dst_port_or_code_last = ntohs (rules[i].dstport_or_icmpcode_last);
422 r->tcp_flags_value = rules[i].tcp_flags_value;
423 r->tcp_flags_mask = rules[i].tcp_flags_mask;
426 if (~0 == *acl_list_index)
429 pool_get_aligned (am->acls, a, CLIB_CACHE_LINE_BYTES);
430 clib_memset (a, 0, sizeof (*a));
431 /* Will return the newly allocated ACL index */
432 *acl_list_index = a - am->acls;
436 a = am->acls + *acl_list_index;
437 /* Get rid of the old rules */
441 a->rules = acl_new_rules;
442 memcpy (a->tag, tag, sizeof (a->tag));
443 if (am->trace_acl > 255)
444 warning_acl_print_acl (am->vlib_main, am, *acl_list_index);
445 if (am->reclassify_sessions)
447 /* a change in an ACLs if they are applied may mean a new policy epoch */
448 policy_notify_acl_change (am, *acl_list_index);
451 /* stats segment expects global heap, so restore it temporarily */
452 clib_mem_set_heap (oldheap);
453 validate_and_reset_acl_counters (am, *acl_list_index);
454 oldheap = acl_set_heap (am);
456 /* notify the lookup contexts about the ACL changes */
457 acl_plugin_lookup_context_notify_acl_change (*acl_list_index);
458 clib_mem_set_heap (oldheap);
463 acl_is_used_by (u32 acl_index, u32 ** foo_index_vec_by_acl)
465 if (acl_index < vec_len (foo_index_vec_by_acl))
467 if (vec_len (vec_elt (foo_index_vec_by_acl, acl_index)) > 0)
469 /* ACL is applied somewhere. */
477 acl_del_list (u32 acl_list_index)
479 acl_main_t *am = &acl_main;
481 if (pool_is_free_index (am->acls, acl_list_index))
483 return VNET_API_ERROR_NO_SUCH_ENTRY;
485 if (acl_is_used_by (acl_list_index, am->input_sw_if_index_vec_by_acl))
486 return VNET_API_ERROR_ACL_IN_USE_INBOUND;
487 if (acl_is_used_by (acl_list_index, am->output_sw_if_index_vec_by_acl))
488 return VNET_API_ERROR_ACL_IN_USE_OUTBOUND;
489 /* lookup contexts cover other cases, not just inbound/outbound, so check that */
490 if (acl_is_used_by (acl_list_index, am->lc_index_vec_by_acl))
491 return VNET_API_ERROR_ACL_IN_USE_BY_LOOKUP_CONTEXT;
493 void *oldheap = acl_set_heap (am);
495 /* now we can delete the ACL itself */
496 a = pool_elt_at_index (am->acls, acl_list_index);
499 pool_put (am->acls, a);
500 /* acl_list_index is now free, notify the lookup contexts */
501 acl_plugin_lookup_context_notify_acl_change (acl_list_index);
502 clib_mem_set_heap (oldheap);
507 count_skip (u8 * p, u32 size)
509 u64 *p64 = (u64 *) p;
510 /* Be tolerant to null pointer */
514 while ((0ULL == *p64) && ((u8 *) p64 - p) < size)
518 return (p64 - (u64 *) p) / 2;
522 acl_classify_add_del_table_small (vnet_classify_main_t * cm, u8 * mask,
523 u32 mask_len, u32 next_table_index,
524 u32 miss_next_index, u32 * table_index,
528 u32 memory_size = 2 << 22;
529 u32 skip = count_skip (mask, mask_len);
530 u32 match = (mask_len / 16) - skip;
531 u8 *skip_mask_ptr = mask + 16 * skip;
532 u32 current_data_flag = 0;
533 int current_data_offset = 0;
538 void *oldheap = clib_mem_set_heap (cm->vlib_main->heap_base);
539 int ret = vnet_classify_add_del_table (cm, skip_mask_ptr, nbuckets,
540 memory_size, skip, match,
541 next_table_index, miss_next_index,
542 table_index, current_data_flag,
543 current_data_offset, is_add,
544 1 /* delete_chain */ );
545 clib_mem_set_heap (oldheap);
550 intf_has_etype_whitelist (acl_main_t * am, u32 sw_if_index, int is_input)
553 ? am->input_etype_whitelist_by_sw_if_index
554 : am->output_etype_whitelist_by_sw_if_index;
555 u16 *whitelist = (vec_len (v) > sw_if_index) ? vec_elt (v, sw_if_index) : 0;
556 return vec_len (whitelist) > 0;
560 acl_clear_sessions (acl_main_t * am, u32 sw_if_index)
562 void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
563 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
564 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX,
566 clib_mem_set_heap (oldheap);
571 acl_interface_in_enable_disable (acl_main_t * am, u32 sw_if_index,
577 if (pool_is_free_index (am->vnet_main->interface_main.sw_interfaces,
579 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
581 if (clib_bitmap_get (am->in_acl_on_sw_if_index, sw_if_index) ==
585 acl_fa_enable_disable (sw_if_index, 1, enable_disable);
587 void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
588 rv = vnet_l2_feature_enable_disable ("l2-input-ip4", "acl-plugin-in-ip4-l2",
589 sw_if_index, enable_disable, 0, 0);
591 clib_error ("Could not enable on input");
592 rv = vnet_l2_feature_enable_disable ("l2-input-ip6", "acl-plugin-in-ip6-l2",
593 sw_if_index, enable_disable, 0, 0);
595 clib_error ("Could not enable on input");
597 if (intf_has_etype_whitelist (am, sw_if_index, 1))
598 vnet_l2_feature_enable_disable ("l2-input-nonip",
599 "acl-plugin-in-nonip-l2", sw_if_index,
600 enable_disable, 0, 0);
602 clib_mem_set_heap (oldheap);
604 am->in_acl_on_sw_if_index =
605 clib_bitmap_set (am->in_acl_on_sw_if_index, sw_if_index, enable_disable);
611 acl_interface_out_enable_disable (acl_main_t * am, u32 sw_if_index,
617 if (pool_is_free_index (am->vnet_main->interface_main.sw_interfaces,
619 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
621 if (clib_bitmap_get (am->out_acl_on_sw_if_index, sw_if_index) ==
625 acl_fa_enable_disable (sw_if_index, 0, enable_disable);
627 void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
629 vnet_l2_feature_enable_disable ("l2-output-ip4", "acl-plugin-out-ip4-l2",
630 sw_if_index, enable_disable, 0, 0);
632 clib_error ("Could not enable on output");
634 vnet_l2_feature_enable_disable ("l2-output-ip6", "acl-plugin-out-ip6-l2",
635 sw_if_index, enable_disable, 0, 0);
637 clib_error ("Could not enable on output");
638 if (intf_has_etype_whitelist (am, sw_if_index, 0))
639 vnet_l2_feature_enable_disable ("l2-output-nonip",
640 "acl-plugin-out-nonip-l2", sw_if_index,
641 enable_disable, 0, 0);
644 clib_mem_set_heap (oldheap);
646 am->out_acl_on_sw_if_index =
647 clib_bitmap_set (am->out_acl_on_sw_if_index, sw_if_index, enable_disable);
653 acl_stats_intf_counters_enable_disable (acl_main_t * am, int enable_disable)
657 am->interface_acl_counters_enabled = enable_disable;
663 acl_interface_inout_enable_disable (acl_main_t * am, u32 sw_if_index,
664 int is_input, int enable_disable)
667 return acl_interface_in_enable_disable (am, sw_if_index, enable_disable);
669 return acl_interface_out_enable_disable (am, sw_if_index, enable_disable);
673 acl_is_not_defined (acl_main_t * am, u32 acl_list_index)
675 return (pool_is_free_index (am->acls, acl_list_index));
679 acl_interface_set_inout_acl_list (acl_main_t * am, u32 sw_if_index,
680 u8 is_input, u32 * vec_acl_list_index,
681 int *may_clear_sessions)
684 uword *seen_acl_bitmap = 0;
685 uword *old_seen_acl_bitmap = 0;
686 uword *change_acl_bitmap = 0;
691 if (am->trace_acl > 255)
693 ("API dbg: acl_interface_set_inout_acl_list: sw_if_index %d is_input %d acl_vec: [%U]",
694 sw_if_index, is_input, format_vec32, vec_acl_list_index, "%d");
696 vec_foreach (pacln, vec_acl_list_index)
698 if (acl_is_not_defined (am, *pacln))
700 /* ACL is not defined. Can not apply */
701 clib_warning ("ERROR: ACL %d not defined", *pacln);
702 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
705 if (clib_bitmap_get (seen_acl_bitmap, *pacln))
707 /* ACL being applied twice within the list. error. */
708 clib_warning ("ERROR: ACL %d being applied twice", *pacln);
709 rv = VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
712 seen_acl_bitmap = clib_bitmap_set (seen_acl_bitmap, *pacln, 1);
716 u32 **pinout_lc_index_by_sw_if_index =
718 input_lc_index_by_sw_if_index : &am->output_lc_index_by_sw_if_index;
720 u32 ***pinout_acl_vec_by_sw_if_index =
722 input_acl_vec_by_sw_if_index : &am->output_acl_vec_by_sw_if_index;
724 u32 ***pinout_sw_if_index_vec_by_acl =
726 input_sw_if_index_vec_by_acl : &am->output_sw_if_index_vec_by_acl;
728 vec_validate ((*pinout_acl_vec_by_sw_if_index), sw_if_index);
730 clib_bitmap_validate (old_seen_acl_bitmap, 1);
732 vec_foreach (pacln, (*pinout_acl_vec_by_sw_if_index)[sw_if_index])
734 old_seen_acl_bitmap = clib_bitmap_set (old_seen_acl_bitmap, *pacln, 1);
737 clib_bitmap_dup_xor (old_seen_acl_bitmap, seen_acl_bitmap);
739 if (am->trace_acl > 255)
740 clib_warning ("bitmaps: old seen %U new seen %U changed %U",
741 format_bitmap_hex, old_seen_acl_bitmap, format_bitmap_hex,
742 seen_acl_bitmap, format_bitmap_hex, change_acl_bitmap);
745 clib_bitmap_foreach(acln, change_acl_bitmap, ({
746 if (clib_bitmap_get(old_seen_acl_bitmap, acln)) {
747 /* ACL is being removed. */
748 if (acln < vec_len((*pinout_sw_if_index_vec_by_acl))) {
749 int index = vec_search((*pinout_sw_if_index_vec_by_acl)[acln], sw_if_index);
750 vec_del1((*pinout_sw_if_index_vec_by_acl)[acln], index);
753 /* ACL is being added. */
754 vec_validate((*pinout_sw_if_index_vec_by_acl), acln);
755 vec_add1((*pinout_sw_if_index_vec_by_acl)[acln], sw_if_index);
760 vec_free ((*pinout_acl_vec_by_sw_if_index)[sw_if_index]);
761 (*pinout_acl_vec_by_sw_if_index)[sw_if_index] =
762 vec_dup (vec_acl_list_index);
764 if (am->reclassify_sessions)
766 /* re-applying ACLs means a new policy epoch */
767 increment_policy_epoch (am, sw_if_index, is_input);
771 /* if no commonalities between the ACL# - then we should definitely clear the sessions */
772 if (may_clear_sessions && *may_clear_sessions
773 && !clib_bitmap_is_zero (change_acl_bitmap))
775 acl_clear_sessions (am, sw_if_index);
776 *may_clear_sessions = 0;
781 * prepare or delete the lookup context if necessary, and if context exists, set ACL list
783 vec_validate_init_empty ((*pinout_lc_index_by_sw_if_index), sw_if_index,
785 if (vec_len (vec_acl_list_index) > 0)
787 u32 lc_index = (*pinout_lc_index_by_sw_if_index)[sw_if_index];
791 acl_plugin.get_lookup_context_index (am->interface_acl_user_id,
792 sw_if_index, is_input);
793 (*pinout_lc_index_by_sw_if_index)[sw_if_index] = lc_index;
795 acl_plugin.set_acl_vec_for_context (lc_index, vec_acl_list_index);
799 if (~0 != (*pinout_lc_index_by_sw_if_index)[sw_if_index])
801 acl_plugin.put_lookup_context_index ((*pinout_lc_index_by_sw_if_index)[sw_if_index]);
802 (*pinout_lc_index_by_sw_if_index)[sw_if_index] = ~0;
806 /* ensure ACL processing is enabled/disabled as needed */
807 acl_interface_inout_enable_disable (am, sw_if_index, is_input,
808 vec_len (vec_acl_list_index) > 0);
811 clib_bitmap_free (change_acl_bitmap);
812 clib_bitmap_free (seen_acl_bitmap);
813 clib_bitmap_free (old_seen_acl_bitmap);
818 acl_interface_reset_inout_acls (u32 sw_if_index, u8 is_input,
819 int *may_clear_sessions)
821 acl_main_t *am = &acl_main;
822 void *oldheap = acl_set_heap (am);
823 acl_interface_set_inout_acl_list (am, sw_if_index, is_input, 0,
825 clib_mem_set_heap (oldheap);
829 acl_interface_add_del_inout_acl (u32 sw_if_index, u8 is_add, u8 is_input,
833 acl_main_t *am = &acl_main;
835 int may_clear_sessions = 1;
837 int error_already_applied = is_input ? VNET_API_ERROR_ACL_IN_USE_INBOUND
838 : VNET_API_ERROR_ACL_IN_USE_OUTBOUND;
840 u32 ***pinout_acl_vec_by_sw_if_index =
842 input_acl_vec_by_sw_if_index : &am->output_acl_vec_by_sw_if_index;
844 void *oldheap = acl_set_heap (am);
848 vec_validate ((*pinout_acl_vec_by_sw_if_index), sw_if_index);
849 u32 index = vec_search ((*pinout_acl_vec_by_sw_if_index)[sw_if_index],
854 rv = error_already_applied;
858 acl_vec = vec_dup ((*pinout_acl_vec_by_sw_if_index)[sw_if_index]);
859 vec_add1 (acl_vec, acl_list_index);
863 if (sw_if_index >= vec_len (*pinout_acl_vec_by_sw_if_index))
865 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
869 u32 index = vec_search ((*pinout_acl_vec_by_sw_if_index)[sw_if_index],
874 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
878 acl_vec = vec_dup ((*pinout_acl_vec_by_sw_if_index)[sw_if_index]);
879 vec_del1 (acl_vec, index);
882 rv = acl_interface_set_inout_acl_list (am, sw_if_index, is_input, acl_vec,
883 &may_clear_sessions);
886 clib_mem_set_heap (oldheap);
891 acl_set_etype_whitelists (acl_main_t * am, u32 sw_if_index, u16 * vec_in,
894 vec_validate (am->input_etype_whitelist_by_sw_if_index, sw_if_index);
895 vec_validate (am->output_etype_whitelist_by_sw_if_index, sw_if_index);
897 vec_free (am->input_etype_whitelist_by_sw_if_index[sw_if_index]);
898 vec_free (am->output_etype_whitelist_by_sw_if_index[sw_if_index]);
900 am->input_etype_whitelist_by_sw_if_index[sw_if_index] = vec_in;
901 am->output_etype_whitelist_by_sw_if_index[sw_if_index] = vec_out;
904 * if there are already inbound/outbound ACLs applied, toggle the
905 * enable/disable - this will recreate the necessary tables.
908 if (vec_len (am->input_acl_vec_by_sw_if_index) > sw_if_index)
910 if (vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]) > 0)
912 acl_interface_in_enable_disable (am, sw_if_index, 0);
913 acl_interface_in_enable_disable (am, sw_if_index, 1);
916 if (vec_len (am->output_acl_vec_by_sw_if_index) > sw_if_index)
918 if (vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]) > 0)
920 acl_interface_out_enable_disable (am, sw_if_index, 0);
921 acl_interface_out_enable_disable (am, sw_if_index, 1);
937 u32 dot1q_table_index;
938 u32 dot1ad_table_index;
939 u32 arp_dot1q_table_index;
940 u32 arp_dot1ad_table_index;
943 u32 out_arp_table_index;
944 u32 out_dot1q_table_index;
945 u32 out_dot1ad_table_index;
946 u32 out_arp_dot1q_table_index;
947 u32 out_arp_dot1ad_table_index;
948 } macip_match_type_t;
951 macip_find_match_type (macip_match_type_t * mv, u8 * mac_mask, u8 prefix_len,
957 for (i = 0; i < vec_len (mv); i++)
959 if ((mv[i].prefix_len == prefix_len) && (mv[i].is_ipv6 == is_ipv6)
960 && (0 == memcmp (mv[i].mac_mask, mac_mask, 6)))
970 /* Get metric used to sort match types.
971 The more specific and the more often seen - the bigger the metric */
973 match_type_metric (macip_match_type_t * m)
975 unsigned int mac_bits_set = 0;
976 unsigned int mac_byte;
978 for (i = 0; i < 6; i++)
980 mac_byte = m->mac_mask[i];
981 for (; mac_byte; mac_byte >>= 1)
982 mac_bits_set += mac_byte & 1;
985 * Attempt to place the more specific and the more used rules on top.
986 * There are obvious caveat corner cases to this, but they do not
987 * seem to be sensible in real world (e.g. specific IPv4 with wildcard MAC
988 * going with a wildcard IPv4 with a specific MAC).
990 return m->prefix_len + mac_bits_set + m->is_ipv6 + 10 * m->count;
994 match_type_compare (macip_match_type_t * m1, macip_match_type_t * m2)
996 /* Ascending sort based on the metric values */
997 return match_type_metric (m1) - match_type_metric (m2);
1000 /* Get the offset of L3 source within ethernet packet */
1002 get_l3_src_offset (int is6)
1005 return (sizeof (ethernet_header_t) +
1006 offsetof (ip6_header_t, src_address));
1008 return (sizeof (ethernet_header_t) +
1009 offsetof (ip4_header_t, src_address));
1013 get_l3_dst_offset (int is6)
1016 return (sizeof (ethernet_header_t) +
1017 offsetof (ip6_header_t, dst_address));
1019 return (sizeof (ethernet_header_t) +
1020 offsetof (ip4_header_t, dst_address));
1024 * return if the is_permit value also requires to create the egress tables
1025 * For backwards compatibility, we keep the is_permit = 1 to only
1026 * create the ingress tables, and the new value of 3 will also
1027 * create the egress tables based on destination.
1030 macip_permit_also_egress (u8 is_permit)
1032 return (is_permit == 3);
1036 macip_create_classify_tables (acl_main_t * am, u32 macip_acl_index)
1038 macip_match_type_t *mvec = NULL;
1039 macip_match_type_t *mt;
1040 macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1042 u32 match_type_index;
1046 vnet_classify_main_t *cm = &vnet_classify_main;
1048 /* Count the number of different types of rules */
1049 for (i = 0; i < a->count; i++)
1053 macip_find_match_type (mvec, a->rules[i].src_mac_mask,
1054 a->rules[i].src_prefixlen,
1055 a->rules[i].is_ipv6)))
1057 match_type_index = vec_len (mvec);
1058 vec_validate (mvec, match_type_index);
1059 memcpy (mvec[match_type_index].mac_mask,
1060 a->rules[i].src_mac_mask, 6);
1061 mvec[match_type_index].prefix_len = a->rules[i].src_prefixlen;
1062 mvec[match_type_index].is_ipv6 = a->rules[i].is_ipv6;
1063 mvec[match_type_index].has_egress = 0;
1064 mvec[match_type_index].table_index = ~0;
1065 mvec[match_type_index].arp_table_index = ~0;
1066 mvec[match_type_index].dot1q_table_index = ~0;
1067 mvec[match_type_index].dot1ad_table_index = ~0;
1068 mvec[match_type_index].arp_dot1q_table_index = ~0;
1069 mvec[match_type_index].arp_dot1ad_table_index = ~0;
1070 mvec[match_type_index].out_table_index = ~0;
1071 mvec[match_type_index].out_arp_table_index = ~0;
1072 mvec[match_type_index].out_dot1q_table_index = ~0;
1073 mvec[match_type_index].out_dot1ad_table_index = ~0;
1074 mvec[match_type_index].out_arp_dot1q_table_index = ~0;
1075 mvec[match_type_index].out_arp_dot1ad_table_index = ~0;
1077 mvec[match_type_index].count++;
1078 mvec[match_type_index].has_egress |=
1079 macip_permit_also_egress (a->rules[i].is_permit);
1081 /* Put the most frequently used tables last in the list so we can create classifier tables in reverse order */
1082 vec_sort_with_function (mvec, match_type_compare);
1083 /* Create the classifier tables */
1085 out_last_table = ~0;
1086 /* First add ARP tables */
1087 vec_foreach (mt, mvec)
1090 int is6 = mt->is_ipv6;
1092 u32 *last_tag_table;
1093 u32 *out_last_tag_table;
1100 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1101 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1102 | Destination Address |
1103 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1105 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
1107 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1108 | EtherType | Hardware Type |
1109 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1110 | Protocol Type | Hw addr len | Proto addr len|
1111 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1113 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
1114 | Sender Hardware Address |
1115 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1116 | Sender Protocol Address |
1117 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1118 | Target Hardware Address |
1119 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1120 | | TargetProtocolAddress |
1121 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1123 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1125 for (tags = 2; tags >= 0; tags--)
1127 clib_memset (mask, 0, sizeof (mask));
1128 /* source MAC address */
1129 memcpy (&mask[6], mt->mac_mask, 6);
1135 clib_memset (&mask[12], 0xff, 2); /* ethernet protocol */
1137 last_tag_table = &mt->arp_table_index;
1140 clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1141 clib_memset (&mask[16], 0xff, 2); /* ethernet protocol */
1143 last_tag_table = &mt->arp_dot1q_table_index;
1146 clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1147 clib_memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1148 clib_memset (&mask[20], 0xff, 2); /* ethernet protocol */
1150 last_tag_table = &mt->arp_dot1ad_table_index;
1154 /* sender hardware address within ARP */
1155 memcpy (&mask[l3_offset + 8], mt->mac_mask, 6);
1156 /* sender protocol address within ARP */
1157 for (i = 0; i < (mt->prefix_len / 8); i++)
1158 mask[l3_offset + 14 + i] = 0xff;
1159 if (mt->prefix_len % 8)
1160 mask[l3_offset + 14 + (mt->prefix_len / 8)] =
1161 0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1163 mask_len = ((l3_offset + 14 + ((mt->prefix_len + 7) / 8) +
1165 1)) / sizeof (u32x4)) * sizeof (u32x4);
1166 acl_classify_add_del_table_small (cm, mask, mask_len, last_table,
1167 (~0 == last_table) ? 0 : ~0,
1169 last_table = *last_tag_table;
1172 /* egress ARP table */
1173 clib_memset (mask, 0, sizeof (mask));
1179 clib_memset (&mask[12], 0xff, 2); /* ethernet protocol */
1181 out_last_tag_table = &mt->out_arp_table_index;
1184 clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1185 clib_memset (&mask[16], 0xff, 2); /* ethernet protocol */
1187 out_last_tag_table = &mt->out_arp_dot1q_table_index;
1190 clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1191 clib_memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1192 clib_memset (&mask[20], 0xff, 2); /* ethernet protocol */
1194 out_last_tag_table = &mt->out_arp_dot1ad_table_index;
1198 /* AYXX: FIXME here - can we tighten the ARP-related table more ? */
1199 /* mask captures just the destination and the ethertype */
1200 mask_len = ((l3_offset +
1202 1)) / sizeof (u32x4)) * sizeof (u32x4);
1203 acl_classify_add_del_table_small (cm, mask, mask_len,
1206 out_last_table) ? 0 : ~0,
1207 out_last_tag_table, 1);
1208 out_last_table = *out_last_tag_table;
1213 /* Now add IP[46] tables */
1214 vec_foreach (mt, mvec)
1217 int is6 = mt->is_ipv6;
1221 u32 *last_tag_table;
1222 u32 *out_last_tag_table;
1225 * create chained tables for VLAN (no-tags, dot1q and dot1ad) packets
1227 for (tags = 2; tags >= 0; tags--)
1229 clib_memset (mask, 0, sizeof (mask));
1230 memcpy (&mask[6], mt->mac_mask, 6);
1231 l3_src_offs = tags * 4 + get_l3_src_offset (is6);
1236 clib_memset (&mask[12], 0xff, 2); /* ethernet protocol */
1237 last_tag_table = &mt->table_index;
1240 clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1241 clib_memset (&mask[16], 0xff, 2); /* ethernet protocol */
1242 last_tag_table = &mt->dot1q_table_index;
1245 clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1246 clib_memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1247 clib_memset (&mask[20], 0xff, 2); /* ethernet protocol */
1248 last_tag_table = &mt->dot1ad_table_index;
1251 for (i = 0; i < (mt->prefix_len / 8); i++)
1253 mask[l3_src_offs + i] = 0xff;
1255 if (mt->prefix_len % 8)
1257 mask[l3_src_offs + (mt->prefix_len / 8)] =
1258 0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1261 * Round-up the number of bytes needed to store the prefix,
1262 * and round up the number of vectors too
1264 mask_len = ((l3_src_offs + ((mt->prefix_len + 7) / 8) +
1265 (sizeof (u32x4) - 1)) / sizeof (u32x4)) * sizeof (u32x4);
1266 acl_classify_add_del_table_small (cm, mask, mask_len, last_table,
1267 (~0 == last_table) ? 0 : ~0,
1269 last_table = *last_tag_table;
1273 for (tags = 2; tags >= 0; tags--)
1275 clib_memset (mask, 0, sizeof (mask));
1276 /* MAC destination */
1277 memcpy (&mask[0], mt->mac_mask, 6);
1278 l3_dst_offs = tags * 4 + get_l3_dst_offset (is6);
1283 clib_memset (&mask[12], 0xff, 2); /* ethernet protocol */
1284 out_last_tag_table = &mt->out_table_index;
1287 clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1288 clib_memset (&mask[16], 0xff, 2); /* ethernet protocol */
1289 out_last_tag_table = &mt->out_dot1q_table_index;
1292 clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1293 clib_memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1294 clib_memset (&mask[20], 0xff, 2); /* ethernet protocol */
1295 out_last_tag_table = &mt->out_dot1ad_table_index;
1298 for (i = 0; i < (mt->prefix_len / 8); i++)
1300 mask[l3_dst_offs + i] = 0xff;
1302 if (mt->prefix_len % 8)
1304 mask[l3_dst_offs + (mt->prefix_len / 8)] =
1305 0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1308 * Round-up the number of bytes needed to store the prefix,
1309 * and round up the number of vectors too
1311 mask_len = ((l3_dst_offs + ((mt->prefix_len + 7) / 8) +
1313 1)) / sizeof (u32x4)) * sizeof (u32x4);
1314 acl_classify_add_del_table_small (cm, mask, mask_len,
1316 (~0 == out_last_table) ? 0 : ~0,
1317 out_last_tag_table, 1);
1318 out_last_table = *out_last_tag_table;
1322 a->ip4_table_index = last_table;
1323 a->ip6_table_index = last_table;
1324 a->l2_table_index = last_table;
1326 a->out_ip4_table_index = out_last_table;
1327 a->out_ip6_table_index = out_last_table;
1328 a->out_l2_table_index = out_last_table;
1330 /* Populate the classifier tables with rules from the MACIP ACL */
1331 for (i = 0; i < a->count; i++)
1335 int is6 = a->rules[i].is_ipv6;
1342 macip_find_match_type (mvec, a->rules[i].src_mac_mask,
1343 a->rules[i].src_prefixlen,
1344 a->rules[i].is_ipv6);
1345 ASSERT (match_type_index != ~0);
1347 for (tags = 2; tags >= 0; tags--)
1349 clib_memset (mask, 0, sizeof (mask));
1350 l3_src_offs = tags * 4 + get_l3_src_offset (is6);
1351 memcpy (&mask[6], a->rules[i].src_mac, 6);
1356 tag_table = mvec[match_type_index].table_index;
1360 tag_table = mvec[match_type_index].dot1q_table_index;
1366 tag_table = mvec[match_type_index].dot1ad_table_index;
1376 memcpy (&mask[l3_src_offs], &a->rules[i].src_ip_addr.ip6, 16);
1378 mask[eth + 1] = 0xdd;
1382 memcpy (&mask[l3_src_offs], &a->rules[i].src_ip_addr.ip4, 4);
1384 mask[eth + 1] = 0x00;
1387 /* add session to table mvec[match_type_index].table_index; */
1388 vnet_classify_add_del_session (cm, tag_table,
1389 mask, a->rules[i].is_permit ? ~0 : 0,
1390 i, 0, action, metadata, 1);
1391 clib_memset (&mask[12], 0, sizeof (mask) - 12);
1394 /* add ARP table entry too */
1395 if (!is6 && (mvec[match_type_index].arp_table_index != ~0))
1397 clib_memset (mask, 0, sizeof (mask));
1398 memcpy (&mask[6], a->rules[i].src_mac, 6);
1400 for (tags = 2; tags >= 0; tags--)
1406 tag_table = mvec[match_type_index].arp_table_index;
1412 tag_table = mvec[match_type_index].arp_dot1q_table_index;
1420 tag_table = mvec[match_type_index].arp_dot1ad_table_index;
1431 memcpy (&mask[l3_src_offs + 8], a->rules[i].src_mac, 6);
1432 memcpy (&mask[l3_src_offs + 14], &a->rules[i].src_ip_addr.ip4,
1434 vnet_classify_add_del_session (cm, tag_table, mask,
1435 a->rules[i].is_permit ? ~0 : 0,
1436 i, 0, action, metadata, 1);
1439 if (macip_permit_also_egress (a->rules[i].is_permit))
1441 /* Add the egress entry with destination set */
1442 for (tags = 2; tags >= 0; tags--)
1444 clib_memset (mask, 0, sizeof (mask));
1445 l3_dst_offs = tags * 4 + get_l3_dst_offset (is6);
1446 /* src mac in the other direction becomes dst */
1447 memcpy (&mask[0], a->rules[i].src_mac, 6);
1452 tag_table = mvec[match_type_index].out_table_index;
1456 tag_table = mvec[match_type_index].out_dot1q_table_index;
1462 tag_table = mvec[match_type_index].out_dot1ad_table_index;
1472 memcpy (&mask[l3_dst_offs], &a->rules[i].src_ip_addr.ip6,
1475 mask[eth + 1] = 0xdd;
1479 memcpy (&mask[l3_dst_offs], &a->rules[i].src_ip_addr.ip4,
1482 mask[eth + 1] = 0x00;
1485 /* add session to table mvec[match_type_index].table_index; */
1486 vnet_classify_add_del_session (cm, tag_table,
1488 a->rules[i].is_permit ? ~0 : 0,
1489 i, 0, action, metadata, 1);
1490 // clib_memset (&mask[12], 0, sizeof (mask) - 12);
1493 /* add ARP table entry too */
1494 if (!is6 && (mvec[match_type_index].out_arp_table_index != ~0))
1496 for (tags = 2; tags >= 0; tags--)
1498 clib_memset (mask, 0, sizeof (mask));
1503 tag_table = mvec[match_type_index].out_arp_table_index;
1509 mvec[match_type_index].out_arp_dot1q_table_index;
1517 mvec[match_type_index].out_arp_dot1ad_table_index;
1527 vnet_classify_add_del_session (cm, tag_table,
1530 rules[i].is_permit ? ~0 : 0,
1531 i, 0, action, metadata, 1);
1540 macip_destroy_classify_tables (acl_main_t * am, u32 macip_acl_index)
1542 vnet_classify_main_t *cm = &vnet_classify_main;
1543 macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1545 if (a->ip4_table_index != ~0)
1547 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1548 &a->ip4_table_index, 0);
1549 a->ip4_table_index = ~0;
1551 if (a->ip6_table_index != ~0)
1553 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1554 &a->ip6_table_index, 0);
1555 a->ip6_table_index = ~0;
1557 if (a->l2_table_index != ~0)
1559 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0, &a->l2_table_index,
1561 a->l2_table_index = ~0;
1563 if (a->out_ip4_table_index != ~0)
1565 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1566 &a->out_ip4_table_index, 0);
1567 a->out_ip4_table_index = ~0;
1569 if (a->out_ip6_table_index != ~0)
1571 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1572 &a->out_ip6_table_index, 0);
1573 a->out_ip6_table_index = ~0;
1575 if (a->out_l2_table_index != ~0)
1577 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1578 &a->out_l2_table_index, 0);
1579 a->out_l2_table_index = ~0;
1584 macip_maybe_apply_unapply_classifier_tables (acl_main_t * am, u32 acl_index,
1590 macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, acl_index);
1592 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
1593 if (vec_elt (am->macip_acl_by_sw_if_index, i) == acl_index)
1595 rv0 = vnet_set_input_acl_intfc (am->vlib_main, i, a->ip4_table_index,
1596 a->ip6_table_index, a->l2_table_index,
1598 /* return the first unhappy outcome but make try to plough through. */
1601 vnet_set_output_acl_intfc (am->vlib_main, i, a->out_ip4_table_index,
1602 a->out_ip6_table_index,
1603 a->out_l2_table_index, is_apply);
1604 /* return the first unhappy outcome but make try to plough through. */
1611 macip_acl_add_list (u32 count, vl_api_macip_acl_rule_t rules[],
1612 u32 * acl_list_index, u8 * tag)
1614 acl_main_t *am = &acl_main;
1615 macip_acl_list_t *a;
1616 macip_acl_rule_t *r;
1617 macip_acl_rule_t *acl_new_rules = 0;
1621 if (*acl_list_index != ~0)
1623 /* They supplied some number, let's see if this MACIP ACL exists */
1624 if (pool_is_free_index (am->macip_acls, *acl_list_index))
1626 /* tried to replace a non-existent ACL, no point doing anything */
1628 ("acl-plugin-error: Trying to replace nonexistent MACIP ACL %d (tag %s)",
1629 *acl_list_index, tag);
1630 return VNET_API_ERROR_NO_SUCH_ENTRY;
1637 ("acl-plugin-warning: Trying to create empty MACIP ACL (tag %s)",
1640 /* if replacing the ACL, unapply the classifier tables first - they will be gone.. */
1641 if (~0 != *acl_list_index)
1642 rv = macip_maybe_apply_unapply_classifier_tables (am, *acl_list_index, 0);
1643 void *oldheap = acl_set_heap (am);
1644 /* Create and populate the rules */
1646 vec_validate (acl_new_rules, count - 1);
1648 for (i = 0; i < count; i++)
1650 r = &acl_new_rules[i];
1651 r->is_permit = rules[i].is_permit;
1652 r->is_ipv6 = rules[i].src_prefix.address.af;
1653 mac_address_decode (rules[i].src_mac, (mac_address_t *) & r->src_mac);
1654 mac_address_decode (rules[i].src_mac_mask,
1655 (mac_address_t *) & r->src_mac_mask);
1656 ip_address_decode (&rules[i].src_prefix.address, &r->src_ip_addr);
1657 r->src_prefixlen = rules[i].src_prefix.len;
1660 if (~0 == *acl_list_index)
1663 pool_get_aligned (am->macip_acls, a, CLIB_CACHE_LINE_BYTES);
1664 clib_memset (a, 0, sizeof (*a));
1665 /* Will return the newly allocated ACL index */
1666 *acl_list_index = a - am->macip_acls;
1670 a = pool_elt_at_index (am->macip_acls, *acl_list_index);
1673 vec_free (a->rules);
1675 macip_destroy_classify_tables (am, *acl_list_index);
1678 a->rules = acl_new_rules;
1680 memcpy (a->tag, tag, sizeof (a->tag));
1682 /* Create and populate the classifier tables */
1683 macip_create_classify_tables (am, *acl_list_index);
1684 clib_mem_set_heap (oldheap);
1685 /* If the ACL was already applied somewhere, reapply the newly created tables */
1687 || macip_maybe_apply_unapply_classifier_tables (am, *acl_list_index, 1);
1691 /* No check that sw_if_index denotes a valid interface - the callers
1692 * were supposed to validate.
1694 * That said, if sw_if_index corresponds to an interface that exists at all,
1695 * this function must return errors accordingly if the ACL is not applied.
1699 macip_acl_interface_del_acl (acl_main_t * am, u32 sw_if_index)
1702 u32 macip_acl_index;
1703 macip_acl_list_t *a;
1705 /* The vector is too short - MACIP ACL is not applied */
1706 if (sw_if_index >= vec_len (am->macip_acl_by_sw_if_index))
1707 return VNET_API_ERROR_NO_SUCH_ENTRY;
1709 macip_acl_index = am->macip_acl_by_sw_if_index[sw_if_index];
1710 /* No point in deleting MACIP ACL which is not applied */
1711 if (~0 == macip_acl_index)
1712 return VNET_API_ERROR_NO_SUCH_ENTRY;
1714 a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1715 /* remove the classifier tables off the interface L2 ACL */
1717 vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
1718 a->ip6_table_index, a->l2_table_index, 0);
1720 vnet_set_output_acl_intfc (am->vlib_main, sw_if_index,
1721 a->out_ip4_table_index, a->out_ip6_table_index,
1722 a->out_l2_table_index, 0);
1723 /* Unset the MACIP ACL index */
1724 am->macip_acl_by_sw_if_index[sw_if_index] = ~0;
1725 /* macip_acl_interface_add_acl did a vec_add1() to this previously, so [sw_if_index] should be valid */
1726 u32 index = vec_search (am->sw_if_index_vec_by_macip_acl[macip_acl_index],
1729 vec_del1 (am->sw_if_index_vec_by_macip_acl[macip_acl_index], index);
1733 /* No check for validity of sw_if_index - the callers were supposed to validate */
1736 macip_acl_interface_add_acl (acl_main_t * am, u32 sw_if_index,
1737 u32 macip_acl_index)
1739 macip_acl_list_t *a;
1741 if (pool_is_free_index (am->macip_acls, macip_acl_index))
1743 return VNET_API_ERROR_NO_SUCH_ENTRY;
1745 void *oldheap = acl_set_heap (am);
1746 a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1747 vec_validate_init_empty (am->macip_acl_by_sw_if_index, sw_if_index, ~0);
1748 vec_validate (am->sw_if_index_vec_by_macip_acl, macip_acl_index);
1749 vec_add1 (am->sw_if_index_vec_by_macip_acl[macip_acl_index], sw_if_index);
1750 clib_mem_set_heap (oldheap);
1751 /* If there already a MACIP ACL applied, unapply it */
1752 if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
1753 macip_acl_interface_del_acl (am, sw_if_index);
1754 am->macip_acl_by_sw_if_index[sw_if_index] = macip_acl_index;
1756 /* Apply the classifier tables for L2 ACLs */
1758 vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
1759 a->ip6_table_index, a->l2_table_index, 1);
1761 vnet_set_output_acl_intfc (am->vlib_main, sw_if_index,
1762 a->out_ip4_table_index, a->out_ip6_table_index,
1763 a->out_l2_table_index, 1);
1768 macip_acl_del_list (u32 acl_list_index)
1770 acl_main_t *am = &acl_main;
1771 macip_acl_list_t *a;
1773 if (pool_is_free_index (am->macip_acls, acl_list_index))
1775 return VNET_API_ERROR_NO_SUCH_ENTRY;
1778 /* delete any references to the ACL */
1779 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
1781 if (am->macip_acl_by_sw_if_index[i] == acl_list_index)
1783 macip_acl_interface_del_acl (am, i);
1787 void *oldheap = acl_set_heap (am);
1788 /* Now that classifier tables are detached, clean them up */
1789 macip_destroy_classify_tables (am, acl_list_index);
1791 /* now we can delete the ACL itself */
1792 a = pool_elt_at_index (am->macip_acls, acl_list_index);
1795 vec_free (a->rules);
1797 pool_put (am->macip_acls, a);
1798 clib_mem_set_heap (oldheap);
1804 macip_acl_interface_add_del_acl (u32 sw_if_index, u8 is_add,
1807 acl_main_t *am = &acl_main;
1811 rv = macip_acl_interface_add_acl (am, sw_if_index, acl_list_index);
1815 rv = macip_acl_interface_del_acl (am, sw_if_index);
1821 * If the client does not allocate enough memory for a variable-length
1822 * message, and then proceed to use it as if the full memory allocated,
1823 * absent the check we happily consume that on the VPP side, and go
1824 * along as if nothing happened. However, the resulting
1825 * effects range from just garbage in the API decode
1826 * (because the decoder snoops too far), to potential memory
1829 * This verifies that the actual length of the message is
1830 * at least expected_len, and complains loudly if it is not.
1832 * A failing check here is 100% a software bug on the API user side,
1833 * so we might as well yell.
1837 verify_message_len (void *mp, u32 expected_len, char *where)
1839 u32 supplied_len = vl_msg_api_get_msg_length (mp);
1840 if (supplied_len < expected_len)
1842 clib_warning ("%s: Supplied message length %d is less than expected %d",
1843 where, supplied_len, expected_len);
1852 /* API message handler */
1854 vl_api_acl_add_replace_t_handler (vl_api_acl_add_replace_t * mp)
1856 vl_api_acl_add_replace_reply_t *rmp;
1857 acl_main_t *am = &acl_main;
1859 u32 acl_list_index = ntohl (mp->acl_index);
1860 u32 acl_count = ntohl (mp->count);
1861 u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
1863 if (verify_message_len (mp, expected_len, "acl_add_replace"))
1865 rv = acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
1869 rv = VNET_API_ERROR_INVALID_VALUE;
1873 REPLY_MACRO2(VL_API_ACL_ADD_REPLACE_REPLY,
1875 rmp->acl_index = htonl(acl_list_index);
1881 vl_api_acl_del_t_handler (vl_api_acl_del_t * mp)
1883 acl_main_t *am = &acl_main;
1884 vl_api_acl_del_reply_t *rmp;
1887 rv = acl_del_list (ntohl (mp->acl_index));
1889 REPLY_MACRO (VL_API_ACL_DEL_REPLY);
1894 vl_api_acl_stats_intf_counters_enable_t_handler
1895 (vl_api_acl_stats_intf_counters_enable_t * mp)
1897 acl_main_t *am = &acl_main;
1898 vl_api_acl_stats_intf_counters_enable_reply_t *rmp;
1901 rv = acl_stats_intf_counters_enable_disable (am, mp->enable);
1903 REPLY_MACRO (VL_API_ACL_DEL_REPLY);
1908 vl_api_acl_interface_add_del_t_handler (vl_api_acl_interface_add_del_t * mp)
1910 acl_main_t *am = &acl_main;
1911 vnet_interface_main_t *im = &am->vnet_main->interface_main;
1912 u32 sw_if_index = ntohl (mp->sw_if_index);
1913 vl_api_acl_interface_add_del_reply_t *rmp;
1916 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
1917 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1920 acl_interface_add_del_inout_acl (sw_if_index, mp->is_add,
1921 mp->is_input, ntohl (mp->acl_index));
1923 REPLY_MACRO (VL_API_ACL_INTERFACE_ADD_DEL_REPLY);
1927 vl_api_acl_interface_set_acl_list_t_handler
1928 (vl_api_acl_interface_set_acl_list_t * mp)
1930 acl_main_t *am = &acl_main;
1931 vl_api_acl_interface_set_acl_list_reply_t *rmp;
1934 vnet_interface_main_t *im = &am->vnet_main->interface_main;
1935 u32 sw_if_index = ntohl (mp->sw_if_index);
1937 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
1938 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1941 int may_clear_sessions = 1;
1942 for (i = 0; i < mp->count; i++)
1944 if (acl_is_not_defined (am, ntohl (mp->acls[i])))
1946 /* ACL does not exist, so we can not apply it */
1947 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1952 void *oldheap = acl_set_heap (am);
1954 u32 *in_acl_vec = 0;
1955 u32 *out_acl_vec = 0;
1956 for (i = 0; i < mp->count; i++)
1957 if (i < mp->n_input)
1958 vec_add1 (in_acl_vec, clib_net_to_host_u32 (mp->acls[i]));
1960 vec_add1 (out_acl_vec, clib_net_to_host_u32 (mp->acls[i]));
1963 acl_interface_set_inout_acl_list (am, sw_if_index, 0, out_acl_vec,
1964 &may_clear_sessions);
1966 || acl_interface_set_inout_acl_list (am, sw_if_index, 1,
1968 &may_clear_sessions);
1969 vec_free (in_acl_vec);
1970 vec_free (out_acl_vec);
1971 clib_mem_set_heap (oldheap);
1975 REPLY_MACRO (VL_API_ACL_INTERFACE_SET_ACL_LIST_REPLY);
1979 copy_acl_rule_to_api_rule (vl_api_acl_rule_t * api_rule, acl_rule_t * r)
1981 api_rule->is_permit = r->is_permit;
1982 ip_address_encode (&r->src, r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
1983 &api_rule->src_prefix.address);
1984 ip_address_encode (&r->dst, r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
1985 &api_rule->dst_prefix.address);
1986 api_rule->src_prefix.len = r->src_prefixlen;
1987 api_rule->dst_prefix.len = r->dst_prefixlen;
1988 api_rule->proto = r->proto;
1989 api_rule->srcport_or_icmptype_first = htons (r->src_port_or_type_first);
1990 api_rule->srcport_or_icmptype_last = htons (r->src_port_or_type_last);
1991 api_rule->dstport_or_icmpcode_first = htons (r->dst_port_or_code_first);
1992 api_rule->dstport_or_icmpcode_last = htons (r->dst_port_or_code_last);
1993 api_rule->tcp_flags_mask = r->tcp_flags_mask;
1994 api_rule->tcp_flags_value = r->tcp_flags_value;
1998 send_acl_details (acl_main_t * am, vl_api_registration_t * reg,
1999 acl_list_t * acl, u32 context)
2001 vl_api_acl_details_t *mp;
2002 vl_api_acl_rule_t *rules;
2004 acl_rule_t *acl_rules = acl->rules;
2005 int msg_size = sizeof (*mp) + sizeof (mp->r[0]) * vec_len (acl_rules);
2006 void *oldheap = acl_set_heap (am);
2008 mp = vl_msg_api_alloc (msg_size);
2009 clib_memset (mp, 0, msg_size);
2010 mp->_vl_msg_id = ntohs (VL_API_ACL_DETAILS + am->msg_id_base);
2012 /* fill in the message */
2013 mp->context = context;
2014 mp->count = htonl (vec_len (acl_rules));
2015 mp->acl_index = htonl (acl - am->acls);
2016 memcpy (mp->tag, acl->tag, sizeof (mp->tag));
2017 // clib_memcpy (mp->r, acl->rules, acl->count * sizeof(acl->rules[0]));
2019 for (i = 0; i < vec_len (acl_rules); i++)
2021 copy_acl_rule_to_api_rule (&rules[i], &acl_rules[i]);
2024 clib_mem_set_heap (oldheap);
2025 vl_api_send_msg (reg, (u8 *) mp);
2030 vl_api_acl_dump_t_handler (vl_api_acl_dump_t * mp)
2032 acl_main_t *am = &acl_main;
2036 vl_api_registration_t *reg;
2038 reg = vl_api_client_index_to_registration (mp->client_index);
2042 if (mp->acl_index == ~0)
2045 /* Just dump all ACLs */
2046 pool_foreach (acl, am->acls,
2048 send_acl_details(am, reg, acl, mp->context);
2054 acl_index = ntohl (mp->acl_index);
2055 if (!pool_is_free_index (am->acls, acl_index))
2057 acl = pool_elt_at_index (am->acls, acl_index);
2058 send_acl_details (am, reg, acl, mp->context);
2064 /* FIXME API: should we signal an error here at all ? */
2070 send_acl_interface_list_details (acl_main_t * am,
2071 vl_api_registration_t * reg,
2072 u32 sw_if_index, u32 context)
2074 vl_api_acl_interface_list_details_t *mp;
2080 void *oldheap = acl_set_heap (am);
2082 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
2083 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
2085 clib_mem_set_heap (oldheap);
2087 n_input = vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]);
2088 n_output = vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]);
2089 count = n_input + n_output;
2091 msg_size = sizeof (*mp);
2092 msg_size += sizeof (mp->acls[0]) * count;
2094 mp = vl_msg_api_alloc (msg_size);
2095 clib_memset (mp, 0, msg_size);
2097 ntohs (VL_API_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
2099 /* fill in the message */
2100 mp->context = context;
2101 mp->sw_if_index = htonl (sw_if_index);
2103 mp->n_input = n_input;
2104 for (i = 0; i < n_input; i++)
2106 mp->acls[i] = htonl (am->input_acl_vec_by_sw_if_index[sw_if_index][i]);
2108 for (i = 0; i < n_output; i++)
2110 mp->acls[n_input + i] =
2111 htonl (am->output_acl_vec_by_sw_if_index[sw_if_index][i]);
2113 vl_api_send_msg (reg, (u8 *) mp);
2117 vl_api_acl_interface_list_dump_t_handler (vl_api_acl_interface_list_dump_t *
2120 acl_main_t *am = &acl_main;
2121 vnet_sw_interface_t *swif;
2122 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2125 vl_api_registration_t *reg;
2127 reg = vl_api_client_index_to_registration (mp->client_index);
2131 if (mp->sw_if_index == ~0)
2134 pool_foreach (swif, im->sw_interfaces,
2136 send_acl_interface_list_details(am, reg, swif->sw_if_index, mp->context);
2142 sw_if_index = ntohl (mp->sw_if_index);
2143 if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
2144 send_acl_interface_list_details (am, reg, sw_if_index, mp->context);
2148 /* MACIP ACL API handlers */
2151 vl_api_macip_acl_add_t_handler (vl_api_macip_acl_add_t * mp)
2153 vl_api_macip_acl_add_reply_t *rmp;
2154 acl_main_t *am = &acl_main;
2156 u32 acl_list_index = ~0;
2157 u32 acl_count = ntohl (mp->count);
2158 u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2160 if (verify_message_len (mp, expected_len, "macip_acl_add"))
2162 rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2166 rv = VNET_API_ERROR_INVALID_VALUE;
2170 REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLY,
2172 rmp->acl_index = htonl(acl_list_index);
2178 vl_api_macip_acl_add_replace_t_handler (vl_api_macip_acl_add_replace_t * mp)
2180 vl_api_macip_acl_add_replace_reply_t *rmp;
2181 acl_main_t *am = &acl_main;
2183 u32 acl_list_index = ntohl (mp->acl_index);
2184 u32 acl_count = ntohl (mp->count);
2185 u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2187 if (verify_message_len (mp, expected_len, "macip_acl_add_replace"))
2189 rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2193 rv = VNET_API_ERROR_INVALID_VALUE;
2197 REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLACE_REPLY,
2199 rmp->acl_index = htonl(acl_list_index);
2205 vl_api_macip_acl_del_t_handler (vl_api_macip_acl_del_t * mp)
2207 acl_main_t *am = &acl_main;
2208 vl_api_macip_acl_del_reply_t *rmp;
2211 rv = macip_acl_del_list (ntohl (mp->acl_index));
2213 REPLY_MACRO (VL_API_MACIP_ACL_DEL_REPLY);
2217 vl_api_macip_acl_interface_add_del_t_handler
2218 (vl_api_macip_acl_interface_add_del_t * mp)
2220 acl_main_t *am = &acl_main;
2221 vl_api_macip_acl_interface_add_del_reply_t *rmp;
2223 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2224 u32 sw_if_index = ntohl (mp->sw_if_index);
2226 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2227 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2230 macip_acl_interface_add_del_acl (ntohl (mp->sw_if_index), mp->is_add,
2231 ntohl (mp->acl_index));
2233 REPLY_MACRO (VL_API_MACIP_ACL_INTERFACE_ADD_DEL_REPLY);
2237 send_macip_acl_details (acl_main_t * am, vl_api_registration_t * reg,
2238 macip_acl_list_t * acl, u32 context)
2240 vl_api_macip_acl_details_t *mp;
2241 vl_api_macip_acl_rule_t *rules;
2242 macip_acl_rule_t *r;
2244 int msg_size = sizeof (*mp) + (acl ? sizeof (mp->r[0]) * acl->count : 0);
2246 mp = vl_msg_api_alloc (msg_size);
2247 clib_memset (mp, 0, msg_size);
2248 mp->_vl_msg_id = ntohs (VL_API_MACIP_ACL_DETAILS + am->msg_id_base);
2250 /* fill in the message */
2251 mp->context = context;
2254 memcpy (mp->tag, acl->tag, sizeof (mp->tag));
2255 mp->count = htonl (acl->count);
2256 mp->acl_index = htonl (acl - am->macip_acls);
2258 for (i = 0; i < acl->count; i++)
2261 rules[i].is_permit = r->is_permit;
2262 mac_address_encode ((mac_address_t *) & r->src_mac,
2264 mac_address_encode ((mac_address_t *) & r->src_mac_mask,
2265 rules[i].src_mac_mask);
2266 ip_address_encode (&r->src_ip_addr,
2267 r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
2268 &rules[i].src_prefix.address);
2269 rules[i].src_prefix.len = r->src_prefixlen;
2274 /* No martini, no party - no ACL applied to this interface. */
2279 vl_api_send_msg (reg, (u8 *) mp);
2284 vl_api_macip_acl_dump_t_handler (vl_api_macip_acl_dump_t * mp)
2286 acl_main_t *am = &acl_main;
2287 macip_acl_list_t *acl;
2289 vl_api_registration_t *reg;
2291 reg = vl_api_client_index_to_registration (mp->client_index);
2295 if (mp->acl_index == ~0)
2297 /* Just dump all ACLs for now, with sw_if_index = ~0 */
2299 pool_foreach (acl, am->macip_acls,
2301 send_macip_acl_details (am, reg, acl, mp->context);
2307 u32 acl_index = ntohl (mp->acl_index);
2308 if (!pool_is_free_index (am->macip_acls, acl_index))
2310 acl = pool_elt_at_index (am->macip_acls, acl_index);
2311 send_macip_acl_details (am, reg, acl, mp->context);
2317 vl_api_macip_acl_interface_get_t_handler (vl_api_macip_acl_interface_get_t *
2320 acl_main_t *am = &acl_main;
2321 vl_api_macip_acl_interface_get_reply_t *rmp;
2322 u32 count = vec_len (am->macip_acl_by_sw_if_index);
2323 int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]) * count;
2324 vl_api_registration_t *reg;
2327 reg = vl_api_client_index_to_registration (mp->client_index);
2331 rmp = vl_msg_api_alloc (msg_size);
2332 clib_memset (rmp, 0, msg_size);
2334 ntohs (VL_API_MACIP_ACL_INTERFACE_GET_REPLY + am->msg_id_base);
2335 rmp->context = mp->context;
2336 rmp->count = htonl (count);
2337 for (i = 0; i < count; i++)
2339 rmp->acls[i] = htonl (am->macip_acl_by_sw_if_index[i]);
2342 vl_api_send_msg (reg, (u8 *) rmp);
2346 send_macip_acl_interface_list_details (acl_main_t * am,
2347 vl_api_registration_t * reg,
2349 u32 acl_index, u32 context)
2351 vl_api_macip_acl_interface_list_details_t *rmp;
2352 /* at this time there is only ever 1 mac ip acl per interface */
2353 int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]);
2355 rmp = vl_msg_api_alloc (msg_size);
2356 clib_memset (rmp, 0, msg_size);
2358 ntohs (VL_API_MACIP_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
2360 /* fill in the message */
2361 rmp->context = context;
2363 rmp->sw_if_index = htonl (sw_if_index);
2364 rmp->acls[0] = htonl (acl_index);
2366 vl_api_send_msg (reg, (u8 *) rmp);
2370 vl_api_macip_acl_interface_list_dump_t_handler
2371 (vl_api_macip_acl_interface_list_dump_t * mp)
2373 vl_api_registration_t *reg;
2374 acl_main_t *am = &acl_main;
2375 u32 sw_if_index = ntohl (mp->sw_if_index);
2377 reg = vl_api_client_index_to_registration (mp->client_index);
2381 if (sw_if_index == ~0)
2383 vec_foreach_index (sw_if_index, am->macip_acl_by_sw_if_index)
2385 if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
2387 send_macip_acl_interface_list_details (am, reg, sw_if_index,
2388 am->macip_acl_by_sw_if_index
2396 if (vec_len (am->macip_acl_by_sw_if_index) > sw_if_index)
2398 send_macip_acl_interface_list_details (am, reg, sw_if_index,
2399 am->macip_acl_by_sw_if_index
2400 [sw_if_index], mp->context);
2406 vl_api_acl_interface_set_etype_whitelist_t_handler
2407 (vl_api_acl_interface_set_etype_whitelist_t * mp)
2409 acl_main_t *am = &acl_main;
2410 vl_api_acl_interface_set_etype_whitelist_reply_t *rmp;
2413 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2414 u32 sw_if_index = ntohl (mp->sw_if_index);
2415 u16 *vec_in = 0, *vec_out = 0;
2416 void *oldheap = acl_set_heap (am);
2418 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2419 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2422 for (i = 0; i < mp->count; i++)
2424 if (i < mp->n_input)
2425 vec_add1 (vec_in, ntohs (mp->whitelist[i]));
2427 vec_add1 (vec_out, ntohs (mp->whitelist[i]));
2429 rv = acl_set_etype_whitelists (am, sw_if_index, vec_in, vec_out);
2432 clib_mem_set_heap (oldheap);
2433 REPLY_MACRO (VL_API_ACL_INTERFACE_SET_ETYPE_WHITELIST_REPLY);
2437 send_acl_interface_etype_whitelist_details (acl_main_t * am,
2438 vl_api_registration_t * reg,
2439 u32 sw_if_index, u32 context)
2441 vl_api_acl_interface_etype_whitelist_details_t *mp;
2448 u16 *whitelist_in = 0;
2449 u16 *whitelist_out = 0;
2451 if (intf_has_etype_whitelist (am, sw_if_index, 0))
2453 vec_elt (am->output_etype_whitelist_by_sw_if_index, sw_if_index);
2455 if (intf_has_etype_whitelist (am, sw_if_index, 1))
2457 vec_elt (am->input_etype_whitelist_by_sw_if_index, sw_if_index);
2459 if ((0 == whitelist_in) && (0 == whitelist_out))
2460 return; /* nothing to do */
2462 void *oldheap = acl_set_heap (am);
2464 n_input = vec_len (whitelist_in);
2465 n_output = vec_len (whitelist_out);
2466 count = n_input + n_output;
2468 msg_size = sizeof (*mp);
2469 msg_size += sizeof (mp->whitelist[0]) * count;
2471 mp = vl_msg_api_alloc (msg_size);
2472 clib_memset (mp, 0, msg_size);
2474 ntohs (VL_API_ACL_INTERFACE_ETYPE_WHITELIST_DETAILS + am->msg_id_base);
2476 /* fill in the message */
2477 mp->context = context;
2478 mp->sw_if_index = htonl (sw_if_index);
2480 mp->n_input = n_input;
2481 for (i = 0; i < n_input; i++)
2483 mp->whitelist[i] = htons (whitelist_in[i]);
2485 for (i = 0; i < n_output; i++)
2487 mp->whitelist[n_input + i] = htons (whitelist_out[i]);
2489 clib_mem_set_heap (oldheap);
2490 vl_api_send_msg (reg, (u8 *) mp);
2495 vl_api_acl_interface_etype_whitelist_dump_t_handler
2496 (vl_api_acl_interface_list_dump_t * mp)
2498 acl_main_t *am = &acl_main;
2499 vnet_sw_interface_t *swif;
2500 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2503 vl_api_registration_t *reg;
2505 reg = vl_api_client_index_to_registration (mp->client_index);
2509 if (mp->sw_if_index == ~0)
2512 pool_foreach (swif, im->sw_interfaces,
2514 send_acl_interface_etype_whitelist_details(am, reg, swif->sw_if_index, mp->context);
2520 sw_if_index = ntohl (mp->sw_if_index);
2521 if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
2522 send_acl_interface_etype_whitelist_details (am, reg, sw_if_index,
2528 acl_set_timeout_sec (int timeout_type, u32 value)
2530 acl_main_t *am = &acl_main;
2531 clib_time_t *ct = &am->vlib_main->clib_time;
2533 if (timeout_type < ACL_N_TIMEOUTS)
2535 am->session_timeout_sec[timeout_type] = value;
2539 clib_warning ("Unknown timeout type %d", timeout_type);
2542 am->session_timeout[timeout_type] =
2543 (u64) (((f64) value) / ct->seconds_per_clock);
2547 acl_set_session_max_entries (u32 value)
2549 acl_main_t *am = &acl_main;
2550 am->fa_conn_table_max_entries = value;
2554 acl_set_skip_ipv6_eh (u32 eh, u32 value)
2556 acl_main_t *am = &acl_main;
2558 if ((eh < 256) && (value < 2))
2560 am->fa_ipv6_known_eh_bitmap =
2561 clib_bitmap_set (am->fa_ipv6_known_eh_bitmap, eh, value);
2569 static clib_error_t *
2570 acl_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
2572 acl_main_t *am = &acl_main;
2573 if (0 == am->acl_mheap)
2575 /* ACL heap is not initialized, so definitely nothing to do. */
2580 int may_clear_sessions = 1;
2581 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
2582 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX,
2584 /* also unapply any ACLs in case the users did not do so. */
2585 macip_acl_interface_del_acl (am, sw_if_index);
2586 acl_interface_reset_inout_acls (sw_if_index, 0, &may_clear_sessions);
2587 acl_interface_reset_inout_acls (sw_if_index, 1, &may_clear_sessions);
2592 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (acl_sw_interface_add_del);
2596 static clib_error_t *
2597 acl_set_aclplugin_fn (vlib_main_t * vm,
2598 unformat_input_t * input, vlib_cli_command_t * cmd)
2600 clib_error_t *error = 0;
2604 uword memory_size = 0;
2605 acl_main_t *am = &acl_main;
2607 if (unformat (input, "skip-ipv6-extension-header %u %u", &eh_val, &val))
2609 if (!acl_set_skip_ipv6_eh (eh_val, val))
2611 error = clib_error_return (0, "expecting eh=0..255, value=0..1");
2615 if (unformat (input, "use-hash-acl-matching %u", &val))
2617 am->use_hash_acl_matching = (val != 0);
2620 if (unformat (input, "l4-match-nonfirst-fragment %u", &val))
2622 am->l4_match_nonfirst_fragment = (val != 0);
2625 if (unformat (input, "reclassify-sessions %u", &val))
2627 am->reclassify_sessions = (val != 0);
2630 if (unformat (input, "event-trace"))
2632 if (!unformat (input, "%u", &val))
2634 error = clib_error_return (0,
2635 "expecting trace level, got `%U`",
2636 format_unformat_error, input);
2641 am->trace_acl = val;
2645 if (unformat (input, "heap"))
2647 if (unformat (input, "main"))
2649 if (unformat (input, "validate %u", &val))
2650 acl_plugin_acl_set_validate_heap (am, val);
2651 else if (unformat (input, "trace %u", &val))
2652 acl_plugin_acl_set_trace_heap (am, val);
2655 else if (unformat (input, "hash"))
2657 if (unformat (input, "validate %u", &val))
2658 acl_plugin_hash_acl_set_validate_heap (val);
2659 else if (unformat (input, "trace %u", &val))
2660 acl_plugin_hash_acl_set_trace_heap (val);
2665 if (unformat (input, "session"))
2667 if (unformat (input, "table"))
2669 /* The commands here are for tuning/testing. No user-serviceable parts inside */
2670 if (unformat (input, "max-entries"))
2672 if (!unformat (input, "%u", &val))
2674 error = clib_error_return (0,
2675 "expecting maximum number of entries, got `%U`",
2676 format_unformat_error, input);
2681 acl_set_session_max_entries (val);
2685 if (unformat (input, "hash-table-buckets"))
2687 if (!unformat (input, "%u", &val))
2689 error = clib_error_return (0,
2690 "expecting maximum number of hash table buckets, got `%U`",
2691 format_unformat_error, input);
2696 am->fa_conn_table_hash_num_buckets = val;
2700 if (unformat (input, "hash-table-memory"))
2702 if (!unformat (input, "%U", unformat_memory_size, &memory_size))
2704 error = clib_error_return (0,
2705 "expecting maximum amount of hash table memory, got `%U`",
2706 format_unformat_error, input);
2711 am->fa_conn_table_hash_memory_size = memory_size;
2715 if (unformat (input, "event-trace"))
2717 if (!unformat (input, "%u", &val))
2719 error = clib_error_return (0,
2720 "expecting trace level, got `%U`",
2721 format_unformat_error, input);
2726 am->trace_sessions = val;
2732 if (unformat (input, "timeout"))
2734 if (unformat (input, "udp"))
2736 if (unformat (input, "idle"))
2738 if (!unformat (input, "%u", &timeout))
2740 error = clib_error_return (0,
2741 "expecting timeout value in seconds, got `%U`",
2742 format_unformat_error,
2748 acl_set_timeout_sec (ACL_TIMEOUT_UDP_IDLE, timeout);
2753 if (unformat (input, "tcp"))
2755 if (unformat (input, "idle"))
2757 if (!unformat (input, "%u", &timeout))
2759 error = clib_error_return (0,
2760 "expecting timeout value in seconds, got `%U`",
2761 format_unformat_error,
2767 acl_set_timeout_sec (ACL_TIMEOUT_TCP_IDLE, timeout);
2771 if (unformat (input, "transient"))
2773 if (!unformat (input, "%u", &timeout))
2775 error = clib_error_return (0,
2776 "expecting timeout value in seconds, got `%U`",
2777 format_unformat_error,
2783 acl_set_timeout_sec (ACL_TIMEOUT_TCP_TRANSIENT,
2797 my_format_mac_address (u8 * s, va_list * args)
2799 u8 *a = va_arg (*args, u8 *);
2800 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
2801 a[0], a[1], a[2], a[3], a[4], a[5]);
2805 my_macip_acl_rule_t_pretty_format (u8 * out, va_list * args)
2807 macip_acl_rule_t *a = va_arg (*args, macip_acl_rule_t *);
2809 out = format (out, "%s action %d ip %U/%d mac %U mask %U",
2810 a->is_ipv6 ? "ipv6" : "ipv4", a->is_permit,
2811 format_ip46_address, &a->src_ip_addr,
2812 a->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
2814 my_format_mac_address, a->src_mac,
2815 my_format_mac_address, a->src_mac_mask);
2820 macip_acl_print (acl_main_t * am, u32 macip_acl_index)
2822 vlib_main_t *vm = am->vlib_main;
2825 /* Don't try to print someone else's memory */
2826 if (macip_acl_index >= vec_len (am->macip_acls))
2829 macip_acl_list_t *a = vec_elt_at_index (am->macip_acls, macip_acl_index);
2830 int free_pool_slot = pool_is_free_index (am->macip_acls, macip_acl_index);
2832 vlib_cli_output (vm,
2833 "MACIP acl_index: %d, count: %d (true len %d) tag {%s} is free pool slot: %d\n",
2834 macip_acl_index, a->count, vec_len (a->rules), a->tag,
2836 vlib_cli_output (vm,
2837 " ip4_table_index %d, ip6_table_index %d, l2_table_index %d\n",
2838 a->ip4_table_index, a->ip6_table_index, a->l2_table_index);
2839 vlib_cli_output (vm,
2840 " out_ip4_table_index %d, out_ip6_table_index %d, out_l2_table_index %d\n",
2841 a->out_ip4_table_index, a->out_ip6_table_index,
2842 a->out_l2_table_index);
2843 for (i = 0; i < vec_len (a->rules); i++)
2844 vlib_cli_output (vm, " rule %d: %U\n", i,
2845 my_macip_acl_rule_t_pretty_format,
2846 vec_elt_at_index (a->rules, i));
2850 static clib_error_t *
2851 acl_set_aclplugin_interface_fn (vlib_main_t * vm,
2852 unformat_input_t * input,
2853 vlib_cli_command_t * cmd)
2855 unformat_input_t _line_input, *line_input = &_line_input;
2856 u32 sw_if_index, is_add, is_input, acl_index;
2858 is_add = is_input = 1;
2859 acl_index = sw_if_index = ~0;
2861 if (!unformat_user (input, unformat_line_input, line_input))
2864 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2866 if (unformat (line_input, "%U",
2867 unformat_vnet_sw_interface, vnet_get_main (),
2870 else if (unformat (line_input, "add"))
2872 else if (unformat (line_input, "del"))
2874 else if (unformat (line_input, "acl %d", &acl_index))
2876 else if (unformat (line_input, "input"))
2878 else if (unformat (line_input, "output"))
2884 if (~0 == sw_if_index)
2885 return (clib_error_return (0, "invalid interface"));
2886 if (~0 == acl_index)
2887 return (clib_error_return (0, "invalid acl"));
2889 acl_interface_add_del_inout_acl (sw_if_index, is_add, is_input, acl_index);
2891 unformat_free (line_input);
2895 #define vec_validate_acl_rules(v, idx) \
2897 if (vec_len(v) < idx+1) { \
2898 vec_validate(v, idx); \
2899 v[idx].is_permit = 0x1; \
2900 v[idx].srcport_or_icmptype_last = 0xffff; \
2901 v[idx].dstport_or_icmpcode_last = 0xffff; \
2905 static clib_error_t *
2906 acl_set_aclplugin_acl_fn (vlib_main_t * vm,
2907 unformat_input_t * input, vlib_cli_command_t * cmd)
2909 unformat_input_t _line_input, *line_input = &_line_input;
2910 vl_api_acl_rule_t *rules = 0;
2913 int n_rules_override = -1;
2918 u32 tcpflags, tcpmask;
2919 u32 src_prefix_length = 0, dst_prefix_length = 0;
2920 ip46_address_t src, dst;
2921 u8 *tag = (u8 *) "cli";
2923 if (!unformat_user (input, unformat_line_input, line_input))
2926 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2928 if (unformat (line_input, "permit+reflect"))
2930 vec_validate_acl_rules (rules, rule_idx);
2931 rules[rule_idx].is_permit = 2;
2933 else if (unformat (line_input, "permit"))
2935 vec_validate_acl_rules (rules, rule_idx);
2936 rules[rule_idx].is_permit = 1;
2938 else if (unformat (line_input, "deny"))
2940 vec_validate_acl_rules (rules, rule_idx);
2941 rules[rule_idx].is_permit = 0;
2943 else if (unformat (line_input, "count %d", &n_rules_override))
2945 /* we will use this later */
2947 else if (unformat (line_input, "action %d", &action))
2949 vec_validate_acl_rules (rules, rule_idx);
2950 rules[rule_idx].is_permit = action;
2952 else if (unformat (line_input, "src %U/%d",
2953 unformat_ip46_address, &src, IP46_TYPE_ANY,
2954 &src_prefix_length))
2956 vec_validate_acl_rules (rules, rule_idx);
2957 ip_address_encode (&src, IP46_TYPE_ANY,
2958 &rules[rule_idx].src_prefix.address);
2959 rules[rule_idx].src_prefix.address.af = ADDRESS_IP4;
2960 rules[rule_idx].src_prefix.len = src_prefix_length;
2962 else if (unformat (line_input, "dst %U/%d",
2963 unformat_ip46_address, &dst, IP46_TYPE_ANY,
2964 &dst_prefix_length))
2966 vec_validate_acl_rules (rules, rule_idx);
2967 ip_address_encode (&dst, IP46_TYPE_ANY,
2968 &rules[rule_idx].dst_prefix.address);
2969 rules[rule_idx].dst_prefix.address.af = ADDRESS_IP4;
2970 rules[rule_idx].dst_prefix.len = dst_prefix_length;
2972 else if (unformat (line_input, "sport %d-%d", &port1, &port2))
2974 vec_validate_acl_rules (rules, rule_idx);
2975 rules[rule_idx].srcport_or_icmptype_first = htons (port1);
2976 rules[rule_idx].srcport_or_icmptype_last = htons (port2);
2978 else if (unformat (line_input, "sport %d", &port1))
2980 vec_validate_acl_rules (rules, rule_idx);
2981 rules[rule_idx].srcport_or_icmptype_first = htons (port1);
2982 rules[rule_idx].srcport_or_icmptype_last = htons (port1);
2984 else if (unformat (line_input, "dport %d-%d", &port1, &port2))
2986 vec_validate_acl_rules (rules, rule_idx);
2987 rules[rule_idx].dstport_or_icmpcode_first = htons (port1);
2988 rules[rule_idx].dstport_or_icmpcode_last = htons (port2);
2990 else if (unformat (line_input, "dport %d", &port1))
2992 vec_validate_acl_rules (rules, rule_idx);
2993 rules[rule_idx].dstport_or_icmpcode_first = htons (port1);
2994 rules[rule_idx].dstport_or_icmpcode_last = htons (port1);
2996 else if (unformat (line_input, "tcpflags %d %d", &tcpflags, &tcpmask))
2998 vec_validate_acl_rules (rules, rule_idx);
2999 rules[rule_idx].tcp_flags_value = tcpflags;
3000 rules[rule_idx].tcp_flags_mask = tcpmask;
3003 if (unformat (line_input, "tcpflags %d mask %d", &tcpflags, &tcpmask))
3005 vec_validate_acl_rules (rules, rule_idx);
3006 rules[rule_idx].tcp_flags_value = tcpflags;
3007 rules[rule_idx].tcp_flags_mask = tcpmask;
3009 else if (unformat (line_input, "proto %d", &proto))
3011 vec_validate_acl_rules (rules, rule_idx);
3012 rules[rule_idx].proto = proto;
3014 else if (unformat (line_input, "tag %s", &tag))
3017 else if (unformat (line_input, ","))
3020 vec_validate_acl_rules (rules, rule_idx);
3028 rv = acl_add_list (vec_len (rules), rules, &acl_index, tag);
3033 return (clib_error_return (0, "failed"));
3035 vlib_cli_output (vm, "ACL index:%d", acl_index);
3040 static clib_error_t *
3041 acl_show_aclplugin_macip_acl_fn (vlib_main_t * vm,
3043 input, vlib_cli_command_t * cmd)
3045 clib_error_t *error = 0;
3046 acl_main_t *am = &acl_main;
3050 (void) unformat (input, "index %u", &acl_index);
3052 for (i = 0; i < vec_len (am->macip_acls); i++)
3054 /* Don't attempt to show the ACLs that do not exist */
3055 if (pool_is_free_index (am->macip_acls, i))
3058 if ((acl_index != ~0) && (acl_index != i))
3063 macip_acl_print (am, i);
3064 if (i < vec_len (am->sw_if_index_vec_by_macip_acl))
3066 vlib_cli_output (vm, " applied on sw_if_index(s): %U\n",
3068 vec_elt (am->sw_if_index_vec_by_macip_acl, i),
3076 static clib_error_t *
3077 acl_show_aclplugin_macip_interface_fn (vlib_main_t * vm,
3079 input, vlib_cli_command_t * cmd)
3081 clib_error_t *error = 0;
3082 acl_main_t *am = &acl_main;
3084 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
3086 vlib_cli_output (vm, " sw_if_index %d: %d\n", i,
3087 vec_elt (am->macip_acl_by_sw_if_index, i));
3093 acl_plugin_show_acl (acl_main_t * am, u32 acl_index)
3096 vlib_main_t *vm = am->vlib_main;
3098 for (i = 0; i < vec_len (am->acls); i++)
3100 if (acl_is_not_defined (am, i))
3102 /* don't attempt to show the ACLs that do not exist */
3105 if ((acl_index != ~0) && (acl_index != i))
3109 acl_print_acl (vm, am, i);
3111 if (i < vec_len (am->input_sw_if_index_vec_by_acl))
3113 vlib_cli_output (vm, " applied inbound on sw_if_index: %U\n",
3114 format_vec32, am->input_sw_if_index_vec_by_acl[i],
3117 if (i < vec_len (am->output_sw_if_index_vec_by_acl))
3119 vlib_cli_output (vm, " applied outbound on sw_if_index: %U\n",
3120 format_vec32, am->output_sw_if_index_vec_by_acl[i],
3123 if (i < vec_len (am->lc_index_vec_by_acl))
3125 vlib_cli_output (vm, " used in lookup context index: %U\n",
3126 format_vec32, am->lc_index_vec_by_acl[i], "%d");
3131 static clib_error_t *
3132 acl_show_aclplugin_acl_fn (vlib_main_t * vm,
3133 unformat_input_t * input, vlib_cli_command_t * cmd)
3135 clib_error_t *error = 0;
3136 acl_main_t *am = &acl_main;
3139 (void) unformat (input, "index %u", &acl_index);
3141 acl_plugin_show_acl (am, acl_index);
3145 static clib_error_t *
3146 acl_show_aclplugin_lookup_context_fn (vlib_main_t * vm,
3147 unformat_input_t * input,
3148 vlib_cli_command_t * cmd)
3150 clib_error_t *error = 0;
3153 (void) unformat (input, "index %u", &lc_index);
3155 acl_plugin_show_lookup_context (lc_index);
3159 static clib_error_t *
3160 acl_show_aclplugin_lookup_user_fn (vlib_main_t * vm,
3161 unformat_input_t * input,
3162 vlib_cli_command_t * cmd)
3164 clib_error_t *error = 0;
3167 (void) unformat (input, "index %u", &lc_index);
3169 acl_plugin_show_lookup_user (lc_index);
3175 acl_plugin_show_interface (acl_main_t * am, u32 sw_if_index, int show_acl,
3178 vlib_main_t *vm = am->vlib_main;
3181 for (swi = 0; (swi < vec_len (am->input_acl_vec_by_sw_if_index)) ||
3182 (swi < vec_len (am->output_acl_vec_by_sw_if_index)); swi++)
3184 /* if we need a particular interface, skip all the others */
3185 if ((sw_if_index != ~0) && (sw_if_index != swi))
3188 vlib_cli_output (vm, "sw_if_index %d:\n", swi);
3189 if (swi < vec_len (am->input_policy_epoch_by_sw_if_index))
3190 vlib_cli_output (vm, " input policy epoch: %x\n",
3191 vec_elt (am->input_policy_epoch_by_sw_if_index,
3193 if (swi < vec_len (am->output_policy_epoch_by_sw_if_index))
3194 vlib_cli_output (vm, " output policy epoch: %x\n",
3195 vec_elt (am->output_policy_epoch_by_sw_if_index,
3199 if (intf_has_etype_whitelist (am, swi, 1))
3201 vlib_cli_output (vm, " input etype whitelist: %U", format_vec16,
3202 am->input_etype_whitelist_by_sw_if_index[swi],
3205 if (intf_has_etype_whitelist (am, swi, 0))
3207 vlib_cli_output (vm, " output etype whitelist: %U", format_vec16,
3208 am->output_etype_whitelist_by_sw_if_index[swi],
3212 if ((swi < vec_len (am->input_acl_vec_by_sw_if_index)) &&
3213 (vec_len (am->input_acl_vec_by_sw_if_index[swi]) > 0))
3215 vlib_cli_output (vm, " input acl(s): %U", format_vec32,
3216 am->input_acl_vec_by_sw_if_index[swi], "%d");
3219 vlib_cli_output (vm, "\n");
3220 vec_foreach (pj, am->input_acl_vec_by_sw_if_index[swi])
3222 acl_print_acl (vm, am, *pj);
3224 vlib_cli_output (vm, "\n");
3228 if ((swi < vec_len (am->output_acl_vec_by_sw_if_index)) &&
3229 (vec_len (am->output_acl_vec_by_sw_if_index[swi]) > 0))
3231 vlib_cli_output (vm, " output acl(s): %U", format_vec32,
3232 am->output_acl_vec_by_sw_if_index[swi], "%d");
3235 vlib_cli_output (vm, "\n");
3236 vec_foreach (pj, am->output_acl_vec_by_sw_if_index[swi])
3238 acl_print_acl (vm, am, *pj);
3240 vlib_cli_output (vm, "\n");
3243 if (detail && (swi < vec_len (am->input_lc_index_by_sw_if_index)))
3245 vlib_cli_output (vm, " input lookup context index: %d",
3246 am->input_lc_index_by_sw_if_index[swi]);
3248 if (detail && (swi < vec_len (am->output_lc_index_by_sw_if_index)))
3250 vlib_cli_output (vm, " output lookup context index: %d",
3251 am->output_lc_index_by_sw_if_index[swi]);
3258 static clib_error_t *
3259 acl_show_aclplugin_decode_5tuple_fn (vlib_main_t * vm,
3260 unformat_input_t * input,
3261 vlib_cli_command_t * cmd)
3263 clib_error_t *error = 0;
3264 u64 five_tuple[6] = { 0, 0, 0, 0, 0, 0 };
3267 (input, "%llx %llx %llx %llx %llx %llx", &five_tuple[0], &five_tuple[1],
3268 &five_tuple[2], &five_tuple[3], &five_tuple[4], &five_tuple[5]))
3269 vlib_cli_output (vm, "5-tuple structure decode: %U\n\n",
3270 format_acl_plugin_5tuple, five_tuple);
3272 error = clib_error_return (0, "expecting 6 hex integers");
3277 static clib_error_t *
3278 acl_show_aclplugin_interface_fn (vlib_main_t * vm,
3280 input, vlib_cli_command_t * cmd)
3282 clib_error_t *error = 0;
3283 acl_main_t *am = &acl_main;
3285 u32 sw_if_index = ~0;
3286 (void) unformat (input, "sw_if_index %u", &sw_if_index);
3287 int show_acl = unformat (input, "acl");
3288 int detail = unformat (input, "detail");
3290 acl_plugin_show_interface (am, sw_if_index, show_acl, detail);
3294 static clib_error_t *
3295 acl_show_aclplugin_memory_fn (vlib_main_t * vm,
3296 unformat_input_t * input,
3297 vlib_cli_command_t * cmd)
3299 clib_error_t *error = 0;
3300 acl_main_t *am = &acl_main;
3302 vlib_cli_output (vm, "ACL plugin main heap statistics:\n");
3305 vlib_cli_output (vm, " %U\n", format_mheap, am->acl_mheap, 1);
3309 vlib_cli_output (vm, " Not initialized\n");
3311 vlib_cli_output (vm, "ACL hash lookup support heap statistics:\n");
3312 if (am->hash_lookup_mheap)
3314 vlib_cli_output (vm, " %U\n", format_mheap, am->hash_lookup_mheap, 1);
3318 vlib_cli_output (vm, " Not initialized\n");
3324 acl_plugin_show_sessions (acl_main_t * am,
3325 u32 show_session_thread_id,
3326 u32 show_session_session_index)
3328 vlib_main_t *vm = am->vlib_main;
3330 vnet_interface_main_t *im = &am->vnet_main->interface_main;
3331 vnet_sw_interface_t *swif;
3332 u64 now = clib_cpu_time_now ();
3333 u64 clocks_per_second = am->vlib_main->clib_time.clocks_per_second;
3336 u64 n_adds = am->fa_session_total_adds;
3337 u64 n_dels = am->fa_session_total_dels;
3338 u64 n_deact = am->fa_session_total_deactivations;
3339 vlib_cli_output (vm, "Sessions total: add %lu - del %lu = %lu", n_adds,
3340 n_dels, n_adds - n_dels);
3341 vlib_cli_output (vm, "Sessions active: add %lu - deact %lu = %lu", n_adds,
3342 n_deact, n_adds - n_deact);
3343 vlib_cli_output (vm, "Sessions being purged: deact %lu - del %lu = %lu",
3344 n_deact, n_dels, n_deact - n_dels);
3346 vlib_cli_output (vm, "now: %lu clocks per second: %lu", now,
3348 vlib_cli_output (vm, "\n\nPer-thread data:");
3349 for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
3351 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
3352 vlib_cli_output (vm, "Thread #%d:", wk);
3353 if (show_session_thread_id == wk
3354 && show_session_session_index < pool_len (pw->fa_sessions_pool))
3356 vlib_cli_output (vm, " session index %u:",
3357 show_session_session_index);
3358 fa_session_t *sess =
3359 pw->fa_sessions_pool + show_session_session_index;
3360 u64 *m = (u64 *) & sess->info;
3361 vlib_cli_output (vm,
3362 " info: %016llx %016llx %016llx %016llx %016llx %016llx",
3363 m[0], m[1], m[2], m[3], m[4], m[5]);
3364 vlib_cli_output (vm, " sw_if_index: %u", sess->sw_if_index);
3365 vlib_cli_output (vm, " tcp_flags_seen: %x",
3366 sess->tcp_flags_seen.as_u16);
3367 vlib_cli_output (vm, " last active time: %lu",
3368 sess->last_active_time);
3369 vlib_cli_output (vm, " thread index: %u", sess->thread_index);
3370 vlib_cli_output (vm, " link enqueue time: %lu",
3371 sess->link_enqueue_time);
3372 vlib_cli_output (vm, " link next index: %u",
3373 sess->link_next_idx);
3374 vlib_cli_output (vm, " link prev index: %u",
3375 sess->link_prev_idx);
3376 vlib_cli_output (vm, " link list id: %u", sess->link_list_id);
3378 vlib_cli_output (vm, " connection add/del stats:", wk);
3380 pool_foreach (swif, im->sw_interfaces,
3382 u32 sw_if_index = swif->sw_if_index;
3384 (sw_if_index < vec_len (pw->fa_session_adds_by_sw_if_index) ?
3385 pw->fa_session_adds_by_sw_if_index[sw_if_index] :
3388 (sw_if_index < vec_len (pw->fa_session_dels_by_sw_if_index) ?
3389 pw->fa_session_dels_by_sw_if_index[sw_if_index] :
3391 u64 n_epoch_changes =
3392 (sw_if_index < vec_len (pw->fa_session_epoch_change_by_sw_if_index) ?
3393 pw->fa_session_epoch_change_by_sw_if_index[sw_if_index] :
3395 vlib_cli_output (vm,
3396 " sw_if_index %d: add %lu - del %lu = %lu; epoch chg: %lu",
3406 vlib_cli_output (vm, " connection timeout type lists:", wk);
3408 for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
3410 u32 head_session_index = pw->fa_conn_list_head[tt];
3411 vlib_cli_output (vm, " fa_conn_list_head[%d]: %d", tt,
3412 head_session_index);
3413 if (~0 != head_session_index)
3415 fa_session_t *sess = pw->fa_sessions_pool + head_session_index;
3416 vlib_cli_output (vm, " last active time: %lu",
3417 sess->last_active_time);
3418 vlib_cli_output (vm, " link enqueue time: %lu",
3419 sess->link_enqueue_time);
3423 vlib_cli_output (vm, " Next expiry time: %lu", pw->next_expiry_time);
3424 vlib_cli_output (vm, " Requeue until time: %lu",
3425 pw->requeue_until_time);
3426 vlib_cli_output (vm, " Current time wait interval: %lu",
3427 pw->current_time_wait_interval);
3428 vlib_cli_output (vm, " Count of deleted sessions: %lu",
3429 pw->cnt_deleted_sessions);
3430 vlib_cli_output (vm, " Delete already deleted: %lu",
3431 pw->cnt_already_deleted_sessions);
3432 vlib_cli_output (vm, " Session timers restarted: %lu",
3433 pw->cnt_session_timer_restarted);
3434 vlib_cli_output (vm, " Swipe until this time: %lu",
3435 pw->swipe_end_time);
3436 vlib_cli_output (vm, " sw_if_index serviced bitmap: %U",
3437 format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
3438 vlib_cli_output (vm, " pending clear intfc bitmap : %U",
3440 pw->pending_clear_sw_if_index_bitmap);
3441 vlib_cli_output (vm, " clear in progress: %u", pw->clear_in_process);
3442 vlib_cli_output (vm, " interrupt is pending: %d",
3443 pw->interrupt_is_pending);
3444 vlib_cli_output (vm, " interrupt is needed: %d",
3445 pw->interrupt_is_needed);
3446 vlib_cli_output (vm, " interrupt is unwanted: %d",
3447 pw->interrupt_is_unwanted);
3448 vlib_cli_output (vm, " interrupt generation: %d",
3449 pw->interrupt_generation);
3450 vlib_cli_output (vm, " received session change requests: %d",
3451 pw->rcvd_session_change_requests);
3452 vlib_cli_output (vm, " sent session change requests: %d",
3453 pw->sent_session_change_requests);
3455 vlib_cli_output (vm, "\n\nConn cleaner thread counters:");
3456 #define _(cnt, desc) vlib_cli_output(vm, " %20lu: %s", am->cnt, desc);
3457 foreach_fa_cleaner_counter;
3459 vlib_cli_output (vm, "Interrupt generation: %d",
3460 am->fa_interrupt_generation);
3461 vlib_cli_output (vm,
3462 "Sessions per interval: min %lu max %lu increment: %f ms current: %f ms",
3463 am->fa_min_deleted_sessions_per_interval,
3464 am->fa_max_deleted_sessions_per_interval,
3465 am->fa_cleaner_wait_time_increment * 1000.0,
3466 ((f64) am->fa_current_cleaner_timer_wait_interval) *
3467 1000.0 / (f64) vm->clib_time.clocks_per_second);
3468 vlib_cli_output (vm, "Reclassify sessions: %d", am->reclassify_sessions);
3471 static clib_error_t *
3472 acl_show_aclplugin_sessions_fn (vlib_main_t * vm,
3473 unformat_input_t * input,
3474 vlib_cli_command_t * cmd)
3476 clib_error_t *error = 0;
3477 acl_main_t *am = &acl_main;
3479 u32 show_bihash_verbose = 0;
3480 u32 show_session_thread_id = ~0;
3481 u32 show_session_session_index = ~0;
3482 (void) unformat (input, "thread %u index %u", &show_session_thread_id,
3483 &show_session_session_index);
3484 (void) unformat (input, "verbose %u", &show_bihash_verbose);
3486 acl_plugin_show_sessions (am, show_session_thread_id,
3487 show_session_session_index);
3488 show_fa_sessions_hash (vm, show_bihash_verbose);
3492 static clib_error_t *
3493 acl_show_aclplugin_tables_fn (vlib_main_t * vm,
3494 unformat_input_t * input,
3495 vlib_cli_command_t * cmd)
3497 clib_error_t *error = 0;
3501 int show_acl_hash_info = 0;
3502 int show_applied_info = 0;
3503 int show_mask_type = 0;
3504 int show_bihash = 0;
3505 u32 show_bihash_verbose = 0;
3507 if (unformat (input, "acl"))
3509 show_acl_hash_info = 1;
3510 /* mask-type is handy to see as well right there */
3512 unformat (input, "index %u", &acl_index);
3514 else if (unformat (input, "applied"))
3516 show_applied_info = 1;
3517 unformat (input, "lc_index %u", &lc_index);
3519 else if (unformat (input, "mask"))
3523 else if (unformat (input, "hash"))
3526 unformat (input, "verbose %u", &show_bihash_verbose);
3530 (show_mask_type || show_acl_hash_info || show_applied_info
3533 /* if no qualifiers specified, show all */
3535 show_acl_hash_info = 1;
3536 show_applied_info = 1;
3539 vlib_cli_output (vm, "Stats counters enabled for interface ACLs: %d",
3540 acl_main.interface_acl_counters_enabled);
3542 acl_plugin_show_tables_mask_type ();
3543 if (show_acl_hash_info)
3544 acl_plugin_show_tables_acl_hash_info (acl_index);
3545 if (show_applied_info)
3546 acl_plugin_show_tables_applied_info (lc_index);
3548 acl_plugin_show_tables_bihash (show_bihash_verbose);
3553 static clib_error_t *
3554 acl_clear_aclplugin_fn (vlib_main_t * vm,
3555 unformat_input_t * input, vlib_cli_command_t * cmd)
3557 clib_error_t *error = 0;
3558 acl_main_t *am = &acl_main;
3559 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
3560 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX, ~0);
3565 VLIB_CLI_COMMAND (aclplugin_set_command, static) = {
3566 .path = "set acl-plugin",
3567 .short_help = "set acl-plugin session timeout {{udp idle}|tcp {idle|transient}} <seconds>",
3568 .function = acl_set_aclplugin_fn,
3571 VLIB_CLI_COMMAND (aclplugin_show_acl_command, static) = {
3572 .path = "show acl-plugin acl",
3573 .short_help = "show acl-plugin acl [index N]",
3574 .function = acl_show_aclplugin_acl_fn,
3577 VLIB_CLI_COMMAND (aclplugin_show_lookup_context_command, static) = {
3578 .path = "show acl-plugin lookup context",
3579 .short_help = "show acl-plugin lookup context [index N]",
3580 .function = acl_show_aclplugin_lookup_context_fn,
3583 VLIB_CLI_COMMAND (aclplugin_show_lookup_user_command, static) = {
3584 .path = "show acl-plugin lookup user",
3585 .short_help = "show acl-plugin lookup user [index N]",
3586 .function = acl_show_aclplugin_lookup_user_fn,
3589 VLIB_CLI_COMMAND (aclplugin_show_decode_5tuple_command, static) = {
3590 .path = "show acl-plugin decode 5tuple",
3591 .short_help = "show acl-plugin decode 5tuple XXXX XXXX XXXX XXXX XXXX XXXX",
3592 .function = acl_show_aclplugin_decode_5tuple_fn,
3595 VLIB_CLI_COMMAND (aclplugin_show_interface_command, static) = {
3596 .path = "show acl-plugin interface",
3597 .short_help = "show acl-plugin interface [sw_if_index N] [acl]",
3598 .function = acl_show_aclplugin_interface_fn,
3601 VLIB_CLI_COMMAND (aclplugin_show_memory_command, static) = {
3602 .path = "show acl-plugin memory",
3603 .short_help = "show acl-plugin memory",
3604 .function = acl_show_aclplugin_memory_fn,
3607 VLIB_CLI_COMMAND (aclplugin_show_sessions_command, static) = {
3608 .path = "show acl-plugin sessions",
3609 .short_help = "show acl-plugin sessions",
3610 .function = acl_show_aclplugin_sessions_fn,
3613 VLIB_CLI_COMMAND (aclplugin_show_tables_command, static) = {
3614 .path = "show acl-plugin tables",
3615 .short_help = "show acl-plugin tables [ acl [index N] | applied [ lc_index N ] | mask | hash [verbose N] ]",
3616 .function = acl_show_aclplugin_tables_fn,
3619 VLIB_CLI_COMMAND (aclplugin_show_macip_acl_command, static) = {
3620 .path = "show acl-plugin macip acl",
3621 .short_help = "show acl-plugin macip acl [index N]",
3622 .function = acl_show_aclplugin_macip_acl_fn,
3625 VLIB_CLI_COMMAND (aclplugin_show_macip_interface_command, static) = {
3626 .path = "show acl-plugin macip interface",
3627 .short_help = "show acl-plugin macip interface",
3628 .function = acl_show_aclplugin_macip_interface_fn,
3631 VLIB_CLI_COMMAND (aclplugin_clear_command, static) = {
3632 .path = "clear acl-plugin sessions",
3633 .short_help = "clear acl-plugin sessions",
3634 .function = acl_clear_aclplugin_fn,
3638 * [un]Apply an ACL to an interface.
3639 * The ACL is applied in a given direction, either input or output.
3640 * The ACL being applied must already exist.
3643 * <b><em> set acl-plugin interface <input|output> acl <index> [del] </b></em>
3646 VLIB_CLI_COMMAND (aclplugin_set_interface_command, static) = {
3647 .path = "set acl-plugin interface",
3648 .short_help = "set acl-plugin interface <interface> <input|output> <acl INDEX> [del] ",
3649 .function = acl_set_aclplugin_interface_fn,
3653 * Create an Access Control List (ACL)
3654 * an ACL is composed of more than one Access control element (ACE). Multiple
3655 * ACEs can be specified with this command using a comma separated list.
3657 * Each ACE describes a tuple of src+dst IP prefix, ip protocol, src+dst port ranges.
3658 * (the ACL plugin also support ICMP types/codes instead of UDP/TCP ports, but
3659 * this CLI does not).
3661 * An ACL can optionally be assigned a 'tag' - which is an identifier understood
3662 * by the client. VPP does not examine it in any way.
3665 * <b><em> set acl-plugin acl <permit|deny> src <PREFIX> dst <PREFIX> proto <TCP|UDP> sport <X-Y> dport <X-Y> [tag FOO] </b></em>
3668 VLIB_CLI_COMMAND (aclplugin_set_acl_command, static) = {
3669 .path = "set acl-plugin acl",
3670 .short_help = "set acl-plugin acl <permit|deny> src <PREFIX> dst <PREFIX> proto X sport X-Y dport X-Y [tag FOO] {use comma separated list for multiple rules}",
3671 .function = acl_set_aclplugin_acl_fn,
3675 static clib_error_t *
3676 acl_plugin_config (vlib_main_t * vm, unformat_input_t * input)
3678 acl_main_t *am = &acl_main;
3679 u32 conn_table_hash_buckets;
3680 uword conn_table_hash_memory_size;
3681 u32 conn_table_max_entries;
3682 uword main_heap_size;
3683 uword hash_heap_size;
3684 u32 hash_lookup_hash_buckets;
3685 uword hash_lookup_hash_memory;
3686 u32 reclassify_sessions;
3687 u32 use_tuple_merge;
3688 u32 tuple_merge_split_threshold;
3690 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3693 (input, "connection hash buckets %d", &conn_table_hash_buckets))
3694 am->fa_conn_table_hash_num_buckets = conn_table_hash_buckets;
3697 (input, "connection hash memory %U", unformat_memory_size,
3698 &conn_table_hash_memory_size))
3699 am->fa_conn_table_hash_memory_size = conn_table_hash_memory_size;
3700 else if (unformat (input, "connection count max %d",
3701 &conn_table_max_entries))
3702 am->fa_conn_table_max_entries = conn_table_max_entries;
3705 (input, "main heap size %U", unformat_memory_size,
3707 am->acl_mheap_size = main_heap_size;
3710 (input, "hash lookup heap size %U", unformat_memory_size,
3712 am->hash_lookup_mheap_size = hash_heap_size;
3713 else if (unformat (input, "hash lookup hash buckets %d",
3714 &hash_lookup_hash_buckets))
3715 am->hash_lookup_hash_buckets = hash_lookup_hash_buckets;
3718 (input, "hash lookup hash memory %U", unformat_memory_size,
3719 &hash_lookup_hash_memory))
3720 am->hash_lookup_hash_memory = hash_lookup_hash_memory;
3721 else if (unformat (input, "use tuple merge %d", &use_tuple_merge))
3722 am->use_tuple_merge = use_tuple_merge;
3725 (input, "tuple merge split threshold %d",
3726 &tuple_merge_split_threshold))
3727 am->tuple_merge_split_threshold = tuple_merge_split_threshold;
3729 else if (unformat (input, "reclassify sessions %d",
3730 &reclassify_sessions))
3731 am->reclassify_sessions = reclassify_sessions;
3734 return clib_error_return (0, "unknown input '%U'",
3735 format_unformat_error, input);
3740 VLIB_CONFIG_FUNCTION (acl_plugin_config, "acl-plugin");
3742 /* Set up the API message handling tables */
3743 #include <vnet/format_fns.h>
3744 #include <acl/acl.api.c>
3746 static clib_error_t *
3747 acl_init (vlib_main_t * vm)
3749 acl_main_t *am = &acl_main;
3750 clib_error_t *error = 0;
3751 clib_memset (am, 0, sizeof (*am));
3753 am->vnet_main = vnet_get_main ();
3754 am->log_default = vlib_log_register_class ("acl_plugin", 0);
3756 /* Ask for a correctly-sized block of API message decode slots */
3757 am->msg_id_base = setup_message_id_table ();
3759 error = acl_plugin_exports_init (&acl_plugin);
3764 am->acl_mheap_size = 0; /* auto size when initializing */
3765 am->hash_lookup_mheap_size = ACL_PLUGIN_HASH_LOOKUP_HEAP_SIZE;
3767 am->hash_lookup_hash_buckets = ACL_PLUGIN_HASH_LOOKUP_HASH_BUCKETS;
3768 am->hash_lookup_hash_memory = ACL_PLUGIN_HASH_LOOKUP_HASH_MEMORY;
3770 am->session_timeout_sec[ACL_TIMEOUT_TCP_TRANSIENT] =
3771 TCP_SESSION_TRANSIENT_TIMEOUT_SEC;
3772 am->session_timeout_sec[ACL_TIMEOUT_TCP_IDLE] =
3773 TCP_SESSION_IDLE_TIMEOUT_SEC;
3774 am->session_timeout_sec[ACL_TIMEOUT_UDP_IDLE] =
3775 UDP_SESSION_IDLE_TIMEOUT_SEC;
3777 am->fa_conn_table_hash_num_buckets =
3778 ACL_FA_CONN_TABLE_DEFAULT_HASH_NUM_BUCKETS;
3779 am->fa_conn_table_hash_memory_size =
3780 ACL_FA_CONN_TABLE_DEFAULT_HASH_MEMORY_SIZE;
3781 am->fa_conn_table_max_entries = ACL_FA_CONN_TABLE_DEFAULT_MAX_ENTRIES;
3782 am->reclassify_sessions = 0;
3783 vlib_thread_main_t *tm = vlib_get_thread_main ();
3785 am->fa_min_deleted_sessions_per_interval =
3786 ACL_FA_DEFAULT_MIN_DELETED_SESSIONS_PER_INTERVAL;
3787 am->fa_max_deleted_sessions_per_interval =
3788 ACL_FA_DEFAULT_MAX_DELETED_SESSIONS_PER_INTERVAL;
3789 am->fa_cleaner_wait_time_increment =
3790 ACL_FA_DEFAULT_CLEANER_WAIT_TIME_INCREMENT;
3792 vec_validate (am->per_worker_data, tm->n_vlib_mains - 1);
3795 for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
3797 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
3798 if (tm->n_vlib_mains > 1)
3800 clib_spinlock_init (&pw->pending_session_change_request_lock);
3802 vec_validate (pw->expired,
3804 am->fa_max_deleted_sessions_per_interval);
3805 _vec_len (pw->expired) = 0;
3806 vec_validate_init_empty (pw->fa_conn_list_head, ACL_N_TIMEOUTS - 1,
3807 FA_SESSION_BOGUS_INDEX);
3808 vec_validate_init_empty (pw->fa_conn_list_tail, ACL_N_TIMEOUTS - 1,
3809 FA_SESSION_BOGUS_INDEX);
3810 vec_validate_init_empty (pw->fa_conn_list_head_expiry_time,
3811 ACL_N_TIMEOUTS - 1, ~0ULL);
3815 am->fa_cleaner_cnt_delete_by_sw_index = 0;
3816 am->fa_cleaner_cnt_delete_by_sw_index_ok = 0;
3817 am->fa_cleaner_cnt_unknown_event = 0;
3818 am->fa_cleaner_cnt_timer_restarted = 0;
3819 am->fa_cleaner_cnt_wait_with_timeout = 0;
3822 #define _(N, v, s) am->fa_ipv6_known_eh_bitmap = clib_bitmap_set(am->fa_ipv6_known_eh_bitmap, v, 1);
3825 am->l4_match_nonfirst_fragment = 1;
3827 /* use the new fancy hash-based matching */
3828 am->use_hash_acl_matching = 1;
3829 /* use tuplemerge by default */
3830 am->use_tuple_merge = 1;
3831 /* Set the default threshold */
3832 am->tuple_merge_split_threshold = TM_SPLIT_THRESHOLD;
3834 am->interface_acl_user_id =
3835 acl_plugin.register_user_module ("interface ACL", "sw_if_index",
3838 am->acl_counter_lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
3839 CLIB_CACHE_LINE_BYTES);
3840 am->acl_counter_lock[0] = 0; /* should be no need */
3845 VLIB_INIT_FUNCTION (acl_init);
3849 * fd.io coding-style-patch-verification: ON
3852 * eval: (c-set-style "gnu")