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/classify/input_acl.h>
24 #include <vpp/app/version.h>
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
29 /* define message IDs */
30 #include <acl/acl_msg_enum.h>
32 /* define message structures */
34 #include <acl/acl_all_api_h.h>
37 /* define generated endian-swappers */
39 #include <acl/acl_all_api_h.h>
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 #include <acl/acl_all_api_h.h>
48 /* Get the API version number */
49 #define vl_api_version(n,v) static u32 api_version=(v);
50 #include <acl/acl_all_api_h.h>
54 #include "hash_lookup.h"
58 #define REPLY_MSG_ID_BASE am->msg_id_base
59 #include <vlibapi/api_helper_macros.h>
61 /* List of message types that this plugin understands */
63 #define foreach_acl_plugin_api_msg \
64 _(ACL_PLUGIN_GET_VERSION, acl_plugin_get_version) \
65 _(ACL_PLUGIN_CONTROL_PING, acl_plugin_control_ping) \
66 _(ACL_ADD_REPLACE, acl_add_replace) \
68 _(ACL_INTERFACE_ADD_DEL, acl_interface_add_del) \
69 _(ACL_INTERFACE_SET_ACL_LIST, acl_interface_set_acl_list) \
70 _(ACL_DUMP, acl_dump) \
71 _(ACL_INTERFACE_LIST_DUMP, acl_interface_list_dump) \
72 _(MACIP_ACL_ADD, macip_acl_add) \
73 _(MACIP_ACL_ADD_REPLACE, macip_acl_add_replace) \
74 _(MACIP_ACL_DEL, macip_acl_del) \
75 _(MACIP_ACL_INTERFACE_ADD_DEL, macip_acl_interface_add_del) \
76 _(MACIP_ACL_DUMP, macip_acl_dump) \
77 _(MACIP_ACL_INTERFACE_GET, macip_acl_interface_get) \
78 _(MACIP_ACL_INTERFACE_LIST_DUMP, macip_acl_interface_list_dump)
82 VLIB_PLUGIN_REGISTER () = {
83 .version = VPP_BUILD_VER,
84 .description = "Access Control Lists",
90 acl_set_heap(acl_main_t *am)
92 if (0 == am->acl_mheap) {
93 am->acl_mheap = mheap_alloc (0 /* use VM */ , am->acl_mheap_size);
94 mheap_t *h = mheap_header (am->acl_mheap);
95 h->flags |= MHEAP_FLAG_THREAD_SAFE;
97 void *oldheap = clib_mem_set_heap(am->acl_mheap);
102 acl_plugin_acl_set_validate_heap(acl_main_t *am, int on)
104 clib_mem_set_heap(acl_set_heap(am));
105 mheap_t *h = mheap_header (am->acl_mheap);
107 h->flags |= MHEAP_FLAG_VALIDATE;
108 h->flags &= ~MHEAP_FLAG_SMALL_OBJECT_CACHE;
111 h->flags &= ~MHEAP_FLAG_VALIDATE;
112 h->flags |= MHEAP_FLAG_SMALL_OBJECT_CACHE;
117 acl_plugin_acl_set_trace_heap(acl_main_t *am, int on)
119 clib_mem_set_heap(acl_set_heap(am));
120 mheap_t *h = mheap_header (am->acl_mheap);
122 h->flags |= MHEAP_FLAG_TRACE;
124 h->flags &= ~MHEAP_FLAG_TRACE;
129 vl_api_acl_plugin_get_version_t_handler (vl_api_acl_plugin_get_version_t * mp)
131 acl_main_t *am = &acl_main;
132 vl_api_acl_plugin_get_version_reply_t *rmp;
133 int msg_size = sizeof (*rmp);
134 unix_shared_memory_queue_t *q;
136 q = vl_api_client_index_to_input_queue (mp->client_index);
142 rmp = vl_msg_api_alloc (msg_size);
143 memset (rmp, 0, msg_size);
145 ntohs (VL_API_ACL_PLUGIN_GET_VERSION_REPLY + am->msg_id_base);
146 rmp->context = mp->context;
147 rmp->major = htonl (ACL_PLUGIN_VERSION_MAJOR);
148 rmp->minor = htonl (ACL_PLUGIN_VERSION_MINOR);
150 vl_msg_api_send_shmem (q, (u8 *) & rmp);
154 vl_api_acl_plugin_control_ping_t_handler (vl_api_acl_plugin_control_ping_t * mp)
156 vl_api_acl_plugin_control_ping_reply_t *rmp;
157 acl_main_t *am = &acl_main;
161 REPLY_MACRO2 (VL_API_ACL_PLUGIN_CONTROL_PING_REPLY,
163 rmp->vpe_pid = ntohl (getpid ());
169 acl_add_list (u32 count, vl_api_acl_rule_t rules[],
170 u32 * acl_list_index, u8 * tag)
172 acl_main_t *am = &acl_main;
175 acl_rule_t *acl_new_rules = 0;
178 if (*acl_list_index != ~0)
180 /* They supplied some number, let's see if this ACL exists */
181 if (pool_is_free_index (am->acls, *acl_list_index))
183 /* tried to replace a non-existent ACL, no point doing anything */
184 clib_warning("acl-plugin-error: Trying to replace nonexistent ACL %d (tag %s)", *acl_list_index, tag);
189 clib_warning("acl-plugin-warning: supplied no rules for ACL %d (tag %s)", *acl_list_index, tag);
192 void *oldheap = acl_set_heap(am);
194 /* Create and populate the rules */
196 vec_validate(acl_new_rules, count-1);
198 for (i = 0; i < count; i++)
200 r = vec_elt_at_index(acl_new_rules, i);
201 memset(r, 0, sizeof(*r));
202 r->is_permit = rules[i].is_permit;
203 r->is_ipv6 = rules[i].is_ipv6;
206 memcpy (&r->src, rules[i].src_ip_addr, sizeof (r->src));
207 memcpy (&r->dst, rules[i].dst_ip_addr, sizeof (r->dst));
211 memcpy (&r->src.ip4, rules[i].src_ip_addr, sizeof (r->src.ip4));
212 memcpy (&r->dst.ip4, rules[i].dst_ip_addr, sizeof (r->dst.ip4));
214 r->src_prefixlen = rules[i].src_ip_prefix_len;
215 r->dst_prefixlen = rules[i].dst_ip_prefix_len;
216 r->proto = rules[i].proto;
217 r->src_port_or_type_first = ntohs ( rules[i].srcport_or_icmptype_first );
218 r->src_port_or_type_last = ntohs ( rules[i].srcport_or_icmptype_last );
219 r->dst_port_or_code_first = ntohs ( rules[i].dstport_or_icmpcode_first );
220 r->dst_port_or_code_last = ntohs ( rules[i].dstport_or_icmpcode_last );
221 r->tcp_flags_value = rules[i].tcp_flags_value;
222 r->tcp_flags_mask = rules[i].tcp_flags_mask;
225 if (~0 == *acl_list_index)
228 pool_get_aligned (am->acls, a, CLIB_CACHE_LINE_BYTES);
229 memset (a, 0, sizeof (*a));
230 /* Will return the newly allocated ACL index */
231 *acl_list_index = a - am->acls;
235 a = am->acls + *acl_list_index;
236 hash_acl_delete(am, *acl_list_index);
237 /* Get rid of the old rules */
241 a->rules = acl_new_rules;
243 memcpy (a->tag, tag, sizeof (a->tag));
244 hash_acl_add(am, *acl_list_index);
245 clib_mem_set_heap (oldheap);
250 acl_del_list (u32 acl_list_index)
252 acl_main_t *am = &acl_main;
255 if (pool_is_free_index (am->acls, acl_list_index))
260 if (acl_list_index < vec_len(am->input_sw_if_index_vec_by_acl)) {
261 if (vec_len(vec_elt(am->input_sw_if_index_vec_by_acl, acl_list_index)) > 0) {
262 /* ACL is applied somewhere inbound. Refuse to delete */
266 if (acl_list_index < vec_len(am->output_sw_if_index_vec_by_acl)) {
267 if (vec_len(vec_elt(am->output_sw_if_index_vec_by_acl, acl_list_index)) > 0) {
268 /* ACL is applied somewhere outbound. Refuse to delete */
273 void *oldheap = acl_set_heap(am);
274 /* delete any references to the ACL */
275 for (i = 0; i < vec_len (am->output_acl_vec_by_sw_if_index); i++)
277 for (ii = 0; ii < vec_len (am->output_acl_vec_by_sw_if_index[i]);
280 if (acl_list_index == am->output_acl_vec_by_sw_if_index[i][ii])
282 vec_del1 (am->output_acl_vec_by_sw_if_index[i], ii);
290 for (i = 0; i < vec_len (am->input_acl_vec_by_sw_if_index); i++)
292 for (ii = 0; ii < vec_len (am->input_acl_vec_by_sw_if_index[i]);
295 if (acl_list_index == am->input_acl_vec_by_sw_if_index[i][ii])
297 vec_del1 (am->input_acl_vec_by_sw_if_index[i], ii);
305 /* delete the hash table data */
307 hash_acl_delete(am, acl_list_index);
308 /* now we can delete the ACL itself */
309 a = pool_elt_at_index (am->acls, acl_list_index);
313 pool_put (am->acls, a);
314 clib_mem_set_heap (oldheap);
318 /* Some aids in ASCII graphing the content */
324 u8 ip4_5tuple_mask[] =
325 _(" dmac smac etype ")
326 _(ether) __ __ __ __ __ __ v __ __ __ __ __ __ v __ __ v
333 _(" ttl pr checksum ")
342 _("L4 T/U sport dport ")
352 u8 ip6_5tuple_mask[] =
353 _(" dmac smac etype ")
354 _(ether) __ __ __ __ __ __ v __ __ __ __ __ __ v __ __ v
356 _(0x0000) __ __ __ __
358 _(0x0004) __ __ XX __
360 _(0x0008) XX XX XX XX
361 _(0x000C) XX XX XX XX
362 _(0x0010) XX XX XX XX
363 _(0x0014) XX XX XX XX
365 _(0x0018) XX XX XX XX
366 _(0x001C) XX XX XX XX
367 _(0x0020) XX XX XX XX
368 _(0x0024) XX XX XX XX
369 _("L4T/U sport dport ")
370 _(tcpudp) XX XX XX XX _(padpad) __ __ __ __ _(padeth) __ __;
377 static int count_skip (u8 * p, u32 size)
379 u64 *p64 = (u64 *) p;
380 /* Be tolerant to null pointer */
384 while ((0ULL == *p64) && ((u8 *) p64 - p) < size)
388 return (p64 - (u64 *) p) / 2;
392 acl_classify_add_del_table_tiny (vnet_classify_main_t * cm, u8 * mask,
393 u32 mask_len, u32 next_table_index,
394 u32 miss_next_index, u32 * table_index,
398 u32 memory_size = 2 << 13;
399 u32 skip = count_skip (mask, mask_len);
400 u32 match = (mask_len / 16) - skip;
401 u8 *skip_mask_ptr = mask + 16 * skip;
402 u32 current_data_flag = 0;
403 int current_data_offset = 0;
407 void *oldheap = clib_mem_set_heap (cm->vlib_main->heap_base);
408 int ret = vnet_classify_add_del_table (cm, skip_mask_ptr, nbuckets,
409 memory_size, skip, match,
410 next_table_index, miss_next_index,
411 table_index, current_data_flag,
412 current_data_offset, is_add,
413 1 /* delete_chain */);
414 clib_mem_set_heap (oldheap);
419 acl_classify_add_del_table_small (vnet_classify_main_t * cm, u8 * mask,
420 u32 mask_len, u32 next_table_index,
421 u32 miss_next_index, u32 * table_index,
425 u32 memory_size = 2 << 20;
426 u32 skip = count_skip (mask, mask_len);
427 u32 match = (mask_len / 16) - skip;
428 u8 *skip_mask_ptr = mask + 16 * skip;
429 u32 current_data_flag = 0;
430 int current_data_offset = 0;
435 void *oldheap = clib_mem_set_heap (cm->vlib_main->heap_base);
436 int ret = vnet_classify_add_del_table (cm, skip_mask_ptr, nbuckets,
437 memory_size, skip, match,
438 next_table_index, miss_next_index,
439 table_index, current_data_flag,
440 current_data_offset, is_add,
441 1 /* delete_chain */);
442 clib_mem_set_heap (oldheap);
448 acl_unhook_l2_input_classify (acl_main_t * am, u32 sw_if_index)
450 vnet_classify_main_t *cm = &vnet_classify_main;
451 u32 ip4_table_index = ~0;
452 u32 ip6_table_index = ~0;
453 void *oldheap = acl_set_heap(am);
455 vec_validate_init_empty (am->acl_ip4_input_classify_table_by_sw_if_index,
457 vec_validate_init_empty (am->acl_ip6_input_classify_table_by_sw_if_index,
460 /* switch to global heap while calling vnet_* functions */
461 clib_mem_set_heap (cm->vlib_main->heap_base);
462 vnet_l2_input_classify_enable_disable (sw_if_index, 0);
464 if (am->acl_ip4_input_classify_table_by_sw_if_index[sw_if_index] != ~0)
467 am->acl_ip4_input_classify_table_by_sw_if_index[sw_if_index];
468 am->acl_ip4_input_classify_table_by_sw_if_index[sw_if_index] = ~0;
469 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
470 sizeof (ip4_5tuple_mask) - 1, ~0,
471 am->l2_input_classify_next_acl_ip4,
472 &ip4_table_index, 0);
474 if (am->acl_ip6_input_classify_table_by_sw_if_index[sw_if_index] != ~0)
477 am->acl_ip6_input_classify_table_by_sw_if_index[sw_if_index];
478 am->acl_ip6_input_classify_table_by_sw_if_index[sw_if_index] = ~0;
479 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
480 sizeof (ip6_5tuple_mask) - 1, ~0,
481 am->l2_input_classify_next_acl_ip6,
482 &ip6_table_index, 0);
484 clib_mem_set_heap (oldheap);
489 acl_unhook_l2_output_classify (acl_main_t * am, u32 sw_if_index)
491 vnet_classify_main_t *cm = &vnet_classify_main;
492 u32 ip4_table_index = ~0;
493 u32 ip6_table_index = ~0;
494 void *oldheap = acl_set_heap(am);
496 vec_validate_init_empty (am->acl_ip4_output_classify_table_by_sw_if_index,
498 vec_validate_init_empty (am->acl_ip6_output_classify_table_by_sw_if_index,
501 /* switch to global heap while calling vnet_* functions */
502 clib_mem_set_heap (cm->vlib_main->heap_base);
504 vnet_l2_output_classify_enable_disable (sw_if_index, 0);
506 if (am->acl_ip4_output_classify_table_by_sw_if_index[sw_if_index] != ~0)
509 am->acl_ip4_output_classify_table_by_sw_if_index[sw_if_index];
510 am->acl_ip4_output_classify_table_by_sw_if_index[sw_if_index] = ~0;
511 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
512 sizeof (ip4_5tuple_mask) - 1, ~0,
513 am->l2_output_classify_next_acl_ip4,
514 &ip4_table_index, 0);
516 if (am->acl_ip6_output_classify_table_by_sw_if_index[sw_if_index] != ~0)
519 am->acl_ip6_output_classify_table_by_sw_if_index[sw_if_index];
520 am->acl_ip6_output_classify_table_by_sw_if_index[sw_if_index] = ~0;
521 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
522 sizeof (ip6_5tuple_mask) - 1, ~0,
523 am->l2_output_classify_next_acl_ip6,
524 &ip6_table_index, 0);
526 clib_mem_set_heap (oldheap);
531 acl_hook_l2_input_classify (acl_main_t * am, u32 sw_if_index)
533 vnet_classify_main_t *cm = &vnet_classify_main;
534 u32 ip4_table_index = ~0;
535 u32 ip6_table_index = ~0;
538 void *prevheap = clib_mem_set_heap (cm->vlib_main->heap_base);
540 /* in case there were previous tables attached */
541 acl_unhook_l2_input_classify (am, sw_if_index);
543 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
544 sizeof (ip4_5tuple_mask) - 1, ~0,
545 am->l2_input_classify_next_acl_ip4,
546 &ip4_table_index, 1);
550 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
551 sizeof (ip6_5tuple_mask) - 1, ~0,
552 am->l2_input_classify_next_acl_ip6,
553 &ip6_table_index, 1);
556 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
557 sizeof (ip4_5tuple_mask) - 1, ~0,
558 am->l2_input_classify_next_acl_ip4,
559 &ip4_table_index, 0);
563 vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
564 ip6_table_index, ~0);
567 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
568 sizeof (ip6_5tuple_mask) - 1, ~0,
569 am->l2_input_classify_next_acl_ip6,
570 &ip6_table_index, 0);
571 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
572 sizeof (ip4_5tuple_mask) - 1, ~0,
573 am->l2_input_classify_next_acl_ip4,
574 &ip4_table_index, 0);
578 am->acl_ip4_input_classify_table_by_sw_if_index[sw_if_index] =
580 am->acl_ip6_input_classify_table_by_sw_if_index[sw_if_index] =
583 vnet_l2_input_classify_enable_disable (sw_if_index, 1);
585 clib_mem_set_heap (prevheap);
590 acl_hook_l2_output_classify (acl_main_t * am, u32 sw_if_index)
592 vnet_classify_main_t *cm = &vnet_classify_main;
593 u32 ip4_table_index = ~0;
594 u32 ip6_table_index = ~0;
597 void *prevheap = clib_mem_set_heap (cm->vlib_main->heap_base);
599 /* in case there were previous tables attached */
600 acl_unhook_l2_output_classify (am, sw_if_index);
602 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
603 sizeof (ip4_5tuple_mask) - 1, ~0,
604 am->l2_output_classify_next_acl_ip4,
605 &ip4_table_index, 1);
609 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
610 sizeof (ip6_5tuple_mask) - 1, ~0,
611 am->l2_output_classify_next_acl_ip6,
612 &ip6_table_index, 1);
615 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
616 sizeof (ip4_5tuple_mask) - 1, ~0,
617 am->l2_output_classify_next_acl_ip4,
618 &ip4_table_index, 0);
622 vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
623 ip6_table_index, ~0);
625 ("ACL enabling on interface sw_if_index %d, setting tables to the following: ip4: %d ip6: %d\n",
626 sw_if_index, ip4_table_index, ip6_table_index);
629 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
630 sizeof (ip6_5tuple_mask) - 1, ~0,
631 am->l2_output_classify_next_acl_ip6,
632 &ip6_table_index, 0);
633 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
634 sizeof (ip4_5tuple_mask) - 1, ~0,
635 am->l2_output_classify_next_acl_ip4,
636 &ip4_table_index, 0);
640 am->acl_ip4_output_classify_table_by_sw_if_index[sw_if_index] =
642 am->acl_ip6_output_classify_table_by_sw_if_index[sw_if_index] =
645 vnet_l2_output_classify_enable_disable (sw_if_index, 1);
647 clib_mem_set_heap (prevheap);
654 acl_interface_in_enable_disable (acl_main_t * am, u32 sw_if_index,
660 if (pool_is_free_index (am->vnet_main->interface_main.sw_interfaces,
662 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
664 acl_fa_enable_disable(sw_if_index, 1, enable_disable);
668 rv = acl_hook_l2_input_classify (am, sw_if_index);
672 rv = acl_unhook_l2_input_classify (am, sw_if_index);
679 acl_interface_out_enable_disable (acl_main_t * am, u32 sw_if_index,
685 if (pool_is_free_index (am->vnet_main->interface_main.sw_interfaces,
687 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
689 acl_fa_enable_disable(sw_if_index, 0, enable_disable);
693 rv = acl_hook_l2_output_classify (am, sw_if_index);
697 rv = acl_unhook_l2_output_classify (am, sw_if_index);
704 acl_is_not_defined(acl_main_t *am, u32 acl_list_index)
706 return (pool_is_free_index (am->acls, acl_list_index));
711 acl_interface_add_inout_acl (u32 sw_if_index, u8 is_input, u32 acl_list_index)
713 acl_main_t *am = &acl_main;
714 if (acl_is_not_defined(am, acl_list_index)) {
715 /* ACL is not defined. Can not apply */
718 void *oldheap = acl_set_heap(am);
722 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
724 u32 index = vec_search(am->input_acl_vec_by_sw_if_index[sw_if_index], acl_list_index);
725 if (index < vec_len(am->input_acl_vec_by_sw_if_index[sw_if_index])) {
726 clib_warning("ACL %d is already applied inbound on sw_if_index %d (index %d)",
727 acl_list_index, sw_if_index, index);
728 /* the entry is already there */
729 clib_mem_set_heap (oldheap);
732 /* if there was no ACL applied before, enable the ACL processing */
733 if (vec_len(am->input_acl_vec_by_sw_if_index[sw_if_index]) == 0) {
734 acl_interface_in_enable_disable (am, sw_if_index, 1);
736 vec_add (am->input_acl_vec_by_sw_if_index[sw_if_index], &acl_list_index,
738 vec_validate (am->input_sw_if_index_vec_by_acl, acl_list_index);
739 vec_add (am->input_sw_if_index_vec_by_acl[acl_list_index], &sw_if_index,
744 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
746 u32 index = vec_search(am->output_acl_vec_by_sw_if_index[sw_if_index], acl_list_index);
747 if (index < vec_len(am->output_acl_vec_by_sw_if_index[sw_if_index])) {
748 clib_warning("ACL %d is already applied outbound on sw_if_index %d (index %d)",
749 acl_list_index, sw_if_index, index);
750 /* the entry is already there */
751 clib_mem_set_heap (oldheap);
754 /* if there was no ACL applied before, enable the ACL processing */
755 if (vec_len(am->output_acl_vec_by_sw_if_index[sw_if_index]) == 0) {
756 acl_interface_out_enable_disable (am, sw_if_index, 1);
758 vec_add (am->output_acl_vec_by_sw_if_index[sw_if_index],
760 vec_validate (am->output_sw_if_index_vec_by_acl, acl_list_index);
761 vec_add (am->output_sw_if_index_vec_by_acl[acl_list_index], &sw_if_index,
764 clib_mem_set_heap (oldheap);
770 acl_interface_del_inout_acl (u32 sw_if_index, u8 is_input, u32 acl_list_index)
772 acl_main_t *am = &acl_main;
775 void *oldheap = acl_set_heap(am);
778 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
779 for (i = 0; i < vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]);
782 if (acl_list_index ==
783 am->input_acl_vec_by_sw_if_index[sw_if_index][i])
785 vec_del1 (am->input_acl_vec_by_sw_if_index[sw_if_index], i);
791 if (acl_list_index < vec_len(am->input_sw_if_index_vec_by_acl)) {
792 u32 index = vec_search(am->input_sw_if_index_vec_by_acl[acl_list_index], sw_if_index);
793 if (index < vec_len(am->input_sw_if_index_vec_by_acl[acl_list_index])) {
794 hash_acl_unapply(am, sw_if_index, is_input, acl_list_index);
795 vec_del1 (am->input_sw_if_index_vec_by_acl[acl_list_index], index);
799 /* If there is no more ACLs applied on an interface, disable ACL processing */
800 if (0 == vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]))
802 acl_interface_in_enable_disable (am, sw_if_index, 0);
807 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
809 i < vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]); i++)
811 if (acl_list_index ==
812 am->output_acl_vec_by_sw_if_index[sw_if_index][i])
814 vec_del1 (am->output_acl_vec_by_sw_if_index[sw_if_index], i);
820 if (acl_list_index < vec_len(am->output_sw_if_index_vec_by_acl)) {
821 u32 index = vec_search(am->output_sw_if_index_vec_by_acl[acl_list_index], sw_if_index);
822 if (index < vec_len(am->output_sw_if_index_vec_by_acl[acl_list_index])) {
823 hash_acl_unapply(am, sw_if_index, is_input, acl_list_index);
824 vec_del1 (am->output_sw_if_index_vec_by_acl[acl_list_index], index);
828 /* If there is no more ACLs applied on an interface, disable ACL processing */
829 if (0 == vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]))
831 acl_interface_out_enable_disable (am, sw_if_index, 0);
834 clib_mem_set_heap (oldheap);
839 acl_interface_reset_inout_acls (u32 sw_if_index, u8 is_input)
841 acl_main_t *am = &acl_main;
843 void *oldheap = acl_set_heap(am);
846 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
847 if (vec_len(am->input_acl_vec_by_sw_if_index[sw_if_index]) > 0) {
848 acl_interface_in_enable_disable (am, sw_if_index, 0);
851 for(i = vec_len(am->input_acl_vec_by_sw_if_index[sw_if_index])-1; i>=0; i--) {
852 u32 acl_list_index = am->input_acl_vec_by_sw_if_index[sw_if_index][i];
853 hash_acl_unapply(am, sw_if_index, is_input, acl_list_index);
854 if (acl_list_index < vec_len(am->input_sw_if_index_vec_by_acl)) {
855 u32 index = vec_search(am->input_sw_if_index_vec_by_acl[acl_list_index], sw_if_index);
856 if (index < vec_len(am->input_sw_if_index_vec_by_acl[acl_list_index])) {
857 vec_del1 (am->input_sw_if_index_vec_by_acl[acl_list_index], index);
862 vec_reset_length (am->input_acl_vec_by_sw_if_index[sw_if_index]);
866 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
867 if (vec_len(am->output_acl_vec_by_sw_if_index[sw_if_index]) > 0) {
868 acl_interface_out_enable_disable (am, sw_if_index, 0);
871 for(i = vec_len(am->output_acl_vec_by_sw_if_index[sw_if_index])-1; i>=0; i--) {
872 u32 acl_list_index = am->output_acl_vec_by_sw_if_index[sw_if_index][i];
873 hash_acl_unapply(am, sw_if_index, is_input, acl_list_index);
874 if (acl_list_index < vec_len(am->output_sw_if_index_vec_by_acl)) {
875 u32 index = vec_search(am->output_sw_if_index_vec_by_acl[acl_list_index], sw_if_index);
876 if (index < vec_len(am->output_sw_if_index_vec_by_acl[acl_list_index])) {
877 vec_del1 (am->output_sw_if_index_vec_by_acl[acl_list_index], index);
882 vec_reset_length (am->output_acl_vec_by_sw_if_index[sw_if_index]);
884 clib_mem_set_heap (oldheap);
888 acl_interface_add_del_inout_acl (u32 sw_if_index, u8 is_add, u8 is_input,
892 acl_main_t *am = &acl_main;
896 acl_interface_add_inout_acl (sw_if_index, is_input, acl_list_index);
899 hash_acl_apply(am, sw_if_index, is_input, acl_list_index);
904 hash_acl_unapply(am, sw_if_index, is_input, acl_list_index);
906 acl_interface_del_inout_acl (sw_if_index, is_input, acl_list_index);
920 } macip_match_type_t;
923 macip_find_match_type (macip_match_type_t * mv, u8 * mac_mask, u8 prefix_len,
929 for (i = 0; i < vec_len (mv); i++)
931 if ((mv[i].prefix_len == prefix_len) && (mv[i].is_ipv6 == is_ipv6)
932 && (0 == memcmp (mv[i].mac_mask, mac_mask, 6)))
942 /* Get metric used to sort match types.
943 The more specific and the more often seen - the bigger the metric */
945 match_type_metric (macip_match_type_t * m)
947 unsigned int mac_bits_set = 0;
948 unsigned int mac_byte;
952 mac_byte = m->mac_mask[i];
953 for (; mac_byte; mac_byte >>= 1)
954 mac_bits_set += mac_byte & 1;
957 * Attempt to place the more specific and the more used rules on top.
958 * There are obvious caveat corner cases to this, but they do not
959 * seem to be sensible in real world (e.g. specific IPv4 with wildcard MAC
960 * going with a wildcard IPv4 with a specific MAC).
962 return m->prefix_len + mac_bits_set + m->is_ipv6 + 10 * m->count;
966 match_type_compare (macip_match_type_t * m1, macip_match_type_t * m2)
968 /* Ascending sort based on the metric values */
969 return match_type_metric (m1) - match_type_metric (m2);
972 /* Get the offset of L3 source within ethernet packet */
974 get_l3_src_offset(int is6)
977 return (sizeof(ethernet_header_t) + offsetof(ip6_header_t, src_address));
979 return (sizeof(ethernet_header_t) + offsetof(ip4_header_t, src_address));
983 macip_create_classify_tables (acl_main_t * am, u32 macip_acl_index)
985 macip_match_type_t *mvec = NULL;
986 macip_match_type_t *mt;
987 macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, macip_acl_index);
989 u32 match_type_index;
992 vnet_classify_main_t *cm = &vnet_classify_main;
994 /* Count the number of different types of rules */
995 for (i = 0; i < a->count; i++)
999 macip_find_match_type (mvec, a->rules[i].src_mac_mask,
1000 a->rules[i].src_prefixlen,
1001 a->rules[i].is_ipv6)))
1003 match_type_index = vec_len (mvec);
1004 vec_validate (mvec, match_type_index);
1005 memcpy (mvec[match_type_index].mac_mask,
1006 a->rules[i].src_mac_mask, 6);
1007 mvec[match_type_index].prefix_len = a->rules[i].src_prefixlen;
1008 mvec[match_type_index].is_ipv6 = a->rules[i].is_ipv6;
1009 mvec[match_type_index].table_index = ~0;
1011 mvec[match_type_index].count++;
1013 /* Put the most frequently used tables last in the list so we can create classifier tables in reverse order */
1014 vec_sort_with_function (mvec, match_type_compare);
1015 /* Create the classifier tables */
1017 /* First add ARP tables */
1018 vec_foreach (mt, mvec)
1021 int is6 = mt->is_ipv6;
1023 mt->arp_table_index = ~0;
1026 memset (mask, 0, sizeof (mask));
1027 memcpy (&mask[6], mt->mac_mask, 6);
1028 memset (&mask[12], 0xff, 2); /* ethernet protocol */
1029 memcpy (&mask[14 + 8], mt->mac_mask, 6);
1031 for (i = 0; i < (mt->prefix_len / 8); i++)
1032 mask[14 + 14 + i] = 0xff;
1033 if (mt->prefix_len % 8)
1034 mask[14 + 14 + (mt->prefix_len / 8)] = 0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1036 mask_len = ((14 + 14 + ((mt->prefix_len+7) / 8) +
1037 (sizeof (u32x4)-1))/sizeof(u32x4)) * sizeof (u32x4);
1038 acl_classify_add_del_table_small (cm, mask, mask_len, last_table,
1039 (~0 == last_table) ? 0 : ~0, &mt->arp_table_index,
1041 last_table = mt->arp_table_index;
1044 /* Now add IP[46] tables */
1045 vec_foreach (mt, mvec)
1048 int is6 = mt->is_ipv6;
1049 int l3_src_offs = get_l3_src_offset(is6);
1050 memset (mask, 0, sizeof (mask));
1051 memcpy (&mask[6], mt->mac_mask, 6);
1052 for (i = 0; i < (mt->prefix_len / 8); i++)
1054 mask[l3_src_offs + i] = 0xff;
1056 if (mt->prefix_len % 8)
1058 mask[l3_src_offs + (mt->prefix_len / 8)] =
1059 0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1062 * Round-up the number of bytes needed to store the prefix,
1063 * and round up the number of vectors too
1065 mask_len = ((l3_src_offs + ((mt->prefix_len+7) / 8) +
1066 (sizeof (u32x4)-1))/sizeof(u32x4)) * sizeof (u32x4);
1067 acl_classify_add_del_table_small (cm, mask, mask_len, last_table,
1068 (~0 == last_table) ? 0 : ~0, &mt->table_index,
1070 last_table = mt->table_index;
1072 a->ip4_table_index = last_table;
1073 a->ip6_table_index = last_table;
1074 a->l2_table_index = last_table;
1076 /* Populate the classifier tables with rules from the MACIP ACL */
1077 for (i = 0; i < a->count; i++)
1081 int is6 = a->rules[i].is_ipv6;
1082 int l3_src_offs = get_l3_src_offset(is6);
1083 memset (mask, 0, sizeof (mask));
1084 memcpy (&mask[6], a->rules[i].src_mac, 6);
1085 memset (&mask[12], 0xff, 2); /* ethernet protocol */
1088 memcpy (&mask[l3_src_offs], &a->rules[i].src_ip_addr.ip6, 16);
1094 memcpy (&mask[l3_src_offs], &a->rules[i].src_ip_addr.ip4, 4);
1099 macip_find_match_type (mvec, a->rules[i].src_mac_mask,
1100 a->rules[i].src_prefixlen,
1101 a->rules[i].is_ipv6);
1102 ASSERT(match_type_index != ~0);
1103 /* add session to table mvec[match_type_index].table_index; */
1104 vnet_classify_add_del_session (cm, mvec[match_type_index].table_index,
1105 mask, a->rules[i].is_permit ? ~0 : 0, i,
1106 0, action, metadata, 1);
1107 /* add ARP table entry too */
1108 if (!is6 && (mvec[match_type_index].arp_table_index != ~0))
1110 memset (mask, 0, sizeof (mask));
1111 memcpy (&mask[6], a->rules[i].src_mac, 6);
1114 memcpy (&mask[14 + 8], a->rules[i].src_mac, 6);
1115 memcpy (&mask[14 + 14], &a->rules[i].src_ip_addr.ip4, 4);
1116 vnet_classify_add_del_session (cm, mvec[match_type_index].arp_table_index,
1117 mask, a->rules[i].is_permit ? ~0 : 0, i,
1118 0, action, metadata, 1);
1125 macip_destroy_classify_tables (acl_main_t * am, u32 macip_acl_index)
1127 vnet_classify_main_t *cm = &vnet_classify_main;
1128 macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1130 if (a->ip4_table_index != ~0)
1132 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0, &a->ip4_table_index, 0);
1133 a->ip4_table_index = ~0;
1135 if (a->ip6_table_index != ~0)
1137 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0, &a->ip6_table_index, 0);
1138 a->ip6_table_index = ~0;
1140 if (a->l2_table_index != ~0)
1142 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0, &a->l2_table_index, 0);
1143 a->l2_table_index = ~0;
1148 macip_acl_add_list (u32 count, vl_api_macip_acl_rule_t rules[],
1149 u32 * acl_list_index, u8 * tag)
1151 acl_main_t *am = &acl_main;
1152 macip_acl_list_t *a;
1153 macip_acl_rule_t *r;
1154 macip_acl_rule_t *acl_new_rules = 0;
1157 if (*acl_list_index != ~0)
1159 /* They supplied some number, let's see if this MACIP ACL exists */
1160 if (pool_is_free_index (am->macip_acls, *acl_list_index))
1162 /* tried to replace a non-existent ACL, no point doing anything */
1163 clib_warning("acl-plugin-error: Trying to replace nonexistent MACIP ACL %d (tag %s)", *acl_list_index, tag);
1169 clib_warning("acl-plugin-warning: Trying to create empty MACIP ACL (tag %s)", tag);
1171 void *oldheap = acl_set_heap(am);
1172 /* Create and populate the rules */
1174 vec_validate(acl_new_rules, count-1);
1176 for (i = 0; i < count; i++)
1178 r = &acl_new_rules[i];
1179 r->is_permit = rules[i].is_permit;
1180 r->is_ipv6 = rules[i].is_ipv6;
1181 memcpy (&r->src_mac, rules[i].src_mac, 6);
1182 memcpy (&r->src_mac_mask, rules[i].src_mac_mask, 6);
1183 if(rules[i].is_ipv6)
1184 memcpy (&r->src_ip_addr.ip6, rules[i].src_ip_addr, 16);
1186 memcpy (&r->src_ip_addr.ip4, rules[i].src_ip_addr, 4);
1187 r->src_prefixlen = rules[i].src_ip_prefix_len;
1190 if (~0 == *acl_list_index)
1193 pool_get_aligned (am->macip_acls, a, CLIB_CACHE_LINE_BYTES);
1194 memset (a, 0, sizeof (*a));
1195 /* Will return the newly allocated ACL index */
1196 *acl_list_index = a - am->macip_acls;
1200 a = pool_elt_at_index (am->macip_acls, *acl_list_index);
1203 vec_free (a->rules);
1205 macip_destroy_classify_tables (am, *acl_list_index);
1208 a->rules = acl_new_rules;
1210 memcpy (a->tag, tag, sizeof (a->tag));
1212 /* Create and populate the classifer tables */
1213 macip_create_classify_tables (am, *acl_list_index);
1214 clib_mem_set_heap (oldheap);
1219 /* No check for validity of sw_if_index - the callers were supposed to validate */
1222 macip_acl_interface_del_acl (acl_main_t * am, u32 sw_if_index)
1225 u32 macip_acl_index;
1226 macip_acl_list_t *a;
1227 void *oldheap = acl_set_heap(am);
1228 vec_validate_init_empty (am->macip_acl_by_sw_if_index, sw_if_index, ~0);
1229 clib_mem_set_heap (oldheap);
1230 macip_acl_index = am->macip_acl_by_sw_if_index[sw_if_index];
1231 /* No point in deleting MACIP ACL which is not applied */
1232 if (~0 == macip_acl_index)
1234 a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1235 /* remove the classifier tables off the interface L2 ACL */
1237 vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
1238 a->ip6_table_index, a->l2_table_index, 0);
1239 /* Unset the MACIP ACL index */
1240 am->macip_acl_by_sw_if_index[sw_if_index] = ~0;
1244 /* No check for validity of sw_if_index - the callers were supposed to validate */
1247 macip_acl_interface_add_acl (acl_main_t * am, u32 sw_if_index,
1248 u32 macip_acl_index)
1250 macip_acl_list_t *a;
1252 if (pool_is_free_index (am->macip_acls, macip_acl_index))
1256 void *oldheap = acl_set_heap(am);
1257 a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1258 vec_validate_init_empty (am->macip_acl_by_sw_if_index, sw_if_index, ~0);
1259 clib_mem_set_heap (oldheap);
1260 /* If there already a MACIP ACL applied, unapply it */
1261 if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
1262 macip_acl_interface_del_acl(am, sw_if_index);
1263 am->macip_acl_by_sw_if_index[sw_if_index] = macip_acl_index;
1265 /* Apply the classifier tables for L2 ACLs */
1267 vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
1268 a->ip6_table_index, a->l2_table_index, 1);
1273 macip_acl_del_list (u32 acl_list_index)
1275 acl_main_t *am = &acl_main;
1276 macip_acl_list_t *a;
1278 if (pool_is_free_index (am->macip_acls, acl_list_index))
1283 /* delete any references to the ACL */
1284 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
1286 if (am->macip_acl_by_sw_if_index[i] == acl_list_index)
1288 macip_acl_interface_del_acl (am, i);
1292 void *oldheap = acl_set_heap(am);
1293 /* Now that classifier tables are detached, clean them up */
1294 macip_destroy_classify_tables (am, acl_list_index);
1296 /* now we can delete the ACL itself */
1297 a = pool_elt_at_index (am->macip_acls, acl_list_index);
1300 vec_free (a->rules);
1302 pool_put (am->macip_acls, a);
1303 clib_mem_set_heap (oldheap);
1309 macip_acl_interface_add_del_acl (u32 sw_if_index, u8 is_add,
1312 acl_main_t *am = &acl_main;
1316 rv = macip_acl_interface_add_acl (am, sw_if_index, acl_list_index);
1320 rv = macip_acl_interface_del_acl (am, sw_if_index);
1326 * If the client does not allocate enough memory for a variable-length
1327 * message, and then proceed to use it as if the full memory allocated,
1328 * absent the check we happily consume that on the VPP side, and go
1329 * along as if nothing happened. However, the resulting
1330 * effects range from just garbage in the API decode
1331 * (because the decoder snoops too far), to potential memory
1334 * This verifies that the actual length of the message is
1335 * at least expected_len, and complains loudly if it is not.
1337 * A failing check here is 100% a software bug on the API user side,
1338 * so we might as well yell.
1341 static int verify_message_len(void *mp, u32 expected_len, char *where)
1343 u32 supplied_len = vl_msg_api_get_msg_length (mp);
1344 if (supplied_len < expected_len) {
1345 clib_warning("%s: Supplied message length %d is less than expected %d",
1346 where, supplied_len, expected_len);
1353 /* API message handler */
1355 vl_api_acl_add_replace_t_handler (vl_api_acl_add_replace_t * mp)
1357 vl_api_acl_add_replace_reply_t *rmp;
1358 acl_main_t *am = &acl_main;
1360 u32 acl_list_index = ntohl (mp->acl_index);
1361 u32 acl_count = ntohl (mp->count);
1362 u32 expected_len = sizeof(*mp) + acl_count*sizeof(mp->r[0]);
1364 if (verify_message_len(mp, expected_len, "acl_add_replace")) {
1365 rv = acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
1367 rv = VNET_API_ERROR_INVALID_VALUE;
1371 REPLY_MACRO2(VL_API_ACL_ADD_REPLACE_REPLY,
1373 rmp->acl_index = htonl(acl_list_index);
1379 vl_api_acl_del_t_handler (vl_api_acl_del_t * mp)
1381 acl_main_t *am = &acl_main;
1382 vl_api_acl_del_reply_t *rmp;
1385 rv = acl_del_list (ntohl (mp->acl_index));
1387 REPLY_MACRO (VL_API_ACL_DEL_REPLY);
1391 vl_api_acl_interface_add_del_t_handler (vl_api_acl_interface_add_del_t * mp)
1393 acl_main_t *am = &acl_main;
1394 vnet_interface_main_t *im = &am->vnet_main->interface_main;
1395 u32 sw_if_index = ntohl (mp->sw_if_index);
1396 vl_api_acl_interface_add_del_reply_t *rmp;
1399 if (pool_is_free_index(im->sw_interfaces, sw_if_index))
1400 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1403 acl_interface_add_del_inout_acl (sw_if_index, mp->is_add,
1404 mp->is_input, ntohl (mp->acl_index));
1406 REPLY_MACRO (VL_API_ACL_INTERFACE_ADD_DEL_REPLY);
1410 vl_api_acl_interface_set_acl_list_t_handler
1411 (vl_api_acl_interface_set_acl_list_t * mp)
1413 acl_main_t *am = &acl_main;
1414 vl_api_acl_interface_set_acl_list_reply_t *rmp;
1417 vnet_interface_main_t *im = &am->vnet_main->interface_main;
1418 u32 sw_if_index = ntohl (mp->sw_if_index);
1420 if (pool_is_free_index(im->sw_interfaces, sw_if_index))
1421 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1424 acl_interface_reset_inout_acls (sw_if_index, 0);
1425 acl_interface_reset_inout_acls (sw_if_index, 1);
1427 for (i = 0; i < mp->count; i++)
1429 if(acl_is_not_defined(am, ntohl (mp->acls[i]))) {
1430 /* ACL does not exist, so we can not apply it */
1435 for (i = 0; i < mp->count; i++)
1437 acl_interface_add_del_inout_acl (sw_if_index, 1, (i < mp->n_input),
1438 ntohl (mp->acls[i]));
1443 REPLY_MACRO (VL_API_ACL_INTERFACE_SET_ACL_LIST_REPLY);
1447 copy_acl_rule_to_api_rule (vl_api_acl_rule_t * api_rule, acl_rule_t * r)
1449 api_rule->is_permit = r->is_permit;
1450 api_rule->is_ipv6 = r->is_ipv6;
1453 memcpy (api_rule->src_ip_addr, &r->src, sizeof (r->src));
1454 memcpy (api_rule->dst_ip_addr, &r->dst, sizeof (r->dst));
1458 memcpy (api_rule->src_ip_addr, &r->src.ip4, sizeof (r->src.ip4));
1459 memcpy (api_rule->dst_ip_addr, &r->dst.ip4, sizeof (r->dst.ip4));
1461 api_rule->src_ip_prefix_len = r->src_prefixlen;
1462 api_rule->dst_ip_prefix_len = r->dst_prefixlen;
1463 api_rule->proto = r->proto;
1464 api_rule->srcport_or_icmptype_first = htons (r->src_port_or_type_first);
1465 api_rule->srcport_or_icmptype_last = htons (r->src_port_or_type_last);
1466 api_rule->dstport_or_icmpcode_first = htons (r->dst_port_or_code_first);
1467 api_rule->dstport_or_icmpcode_last = htons (r->dst_port_or_code_last);
1468 api_rule->tcp_flags_mask = r->tcp_flags_mask;
1469 api_rule->tcp_flags_value = r->tcp_flags_value;
1473 send_acl_details (acl_main_t * am, unix_shared_memory_queue_t * q,
1474 acl_list_t * acl, u32 context)
1476 vl_api_acl_details_t *mp;
1477 vl_api_acl_rule_t *rules;
1479 int msg_size = sizeof (*mp) + sizeof (mp->r[0]) * acl->count;
1480 void *oldheap = acl_set_heap(am);
1482 mp = vl_msg_api_alloc (msg_size);
1483 memset (mp, 0, msg_size);
1484 mp->_vl_msg_id = ntohs (VL_API_ACL_DETAILS + am->msg_id_base);
1486 /* fill in the message */
1487 mp->context = context;
1488 mp->count = htonl (acl->count);
1489 mp->acl_index = htonl (acl - am->acls);
1490 memcpy (mp->tag, acl->tag, sizeof (mp->tag));
1491 // clib_memcpy (mp->r, acl->rules, acl->count * sizeof(acl->rules[0]));
1493 for (i = 0; i < acl->count; i++)
1495 copy_acl_rule_to_api_rule (&rules[i], &acl->rules[i]);
1498 clib_mem_set_heap (oldheap);
1499 vl_msg_api_send_shmem (q, (u8 *) & mp);
1504 vl_api_acl_dump_t_handler (vl_api_acl_dump_t * mp)
1506 acl_main_t *am = &acl_main;
1511 unix_shared_memory_queue_t *q;
1513 q = vl_api_client_index_to_input_queue (mp->client_index);
1519 if (mp->acl_index == ~0)
1522 /* Just dump all ACLs */
1523 pool_foreach (acl, am->acls,
1525 send_acl_details(am, q, acl, mp->context);
1531 acl_index = ntohl (mp->acl_index);
1532 if (!pool_is_free_index (am->acls, acl_index))
1534 acl = pool_elt_at_index (am->acls, acl_index);
1535 send_acl_details (am, q, acl, mp->context);
1541 /* FIXME API: should we signal an error here at all ? */
1547 send_acl_interface_list_details (acl_main_t * am,
1548 unix_shared_memory_queue_t * q,
1549 u32 sw_if_index, u32 context)
1551 vl_api_acl_interface_list_details_t *mp;
1557 void *oldheap = acl_set_heap(am);
1559 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
1560 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
1562 n_input = vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]);
1563 n_output = vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]);
1564 count = n_input + n_output;
1566 msg_size = sizeof (*mp);
1567 msg_size += sizeof (mp->acls[0]) * count;
1569 mp = vl_msg_api_alloc (msg_size);
1570 memset (mp, 0, msg_size);
1572 ntohs (VL_API_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
1574 /* fill in the message */
1575 mp->context = context;
1576 mp->sw_if_index = htonl (sw_if_index);
1578 mp->n_input = n_input;
1579 for (i = 0; i < n_input; i++)
1581 mp->acls[i] = htonl (am->input_acl_vec_by_sw_if_index[sw_if_index][i]);
1583 for (i = 0; i < n_output; i++)
1585 mp->acls[n_input + i] =
1586 htonl (am->output_acl_vec_by_sw_if_index[sw_if_index][i]);
1588 clib_mem_set_heap (oldheap);
1589 vl_msg_api_send_shmem (q, (u8 *) & mp);
1593 vl_api_acl_interface_list_dump_t_handler (vl_api_acl_interface_list_dump_t *
1596 acl_main_t *am = &acl_main;
1597 vnet_sw_interface_t *swif;
1598 vnet_interface_main_t *im = &am->vnet_main->interface_main;
1601 unix_shared_memory_queue_t *q;
1603 q = vl_api_client_index_to_input_queue (mp->client_index);
1609 if (mp->sw_if_index == ~0)
1612 pool_foreach (swif, im->sw_interfaces,
1614 send_acl_interface_list_details(am, q, swif->sw_if_index, mp->context);
1620 sw_if_index = ntohl (mp->sw_if_index);
1621 if (!pool_is_free_index(im->sw_interfaces, sw_if_index))
1622 send_acl_interface_list_details (am, q, sw_if_index, mp->context);
1626 /* MACIP ACL API handlers */
1629 vl_api_macip_acl_add_t_handler (vl_api_macip_acl_add_t * mp)
1631 vl_api_macip_acl_add_reply_t *rmp;
1632 acl_main_t *am = &acl_main;
1634 u32 acl_list_index = ~0;
1635 u32 acl_count = ntohl (mp->count);
1636 u32 expected_len = sizeof(*mp) + acl_count*sizeof(mp->r[0]);
1638 if (verify_message_len(mp, expected_len, "macip_acl_add")) {
1639 rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
1641 rv = VNET_API_ERROR_INVALID_VALUE;
1645 REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLY,
1647 rmp->acl_index = htonl(acl_list_index);
1653 vl_api_macip_acl_add_replace_t_handler (vl_api_macip_acl_add_replace_t * mp)
1655 vl_api_macip_acl_add_replace_reply_t *rmp;
1656 acl_main_t *am = &acl_main;
1658 u32 acl_list_index = ntohl (mp->acl_index);
1659 u32 acl_count = ntohl (mp->count);
1660 u32 expected_len = sizeof(*mp) + acl_count*sizeof(mp->r[0]);
1662 if (verify_message_len(mp, expected_len, "macip_acl_add_replace")) {
1663 rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
1665 rv = VNET_API_ERROR_INVALID_VALUE;
1669 REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLACE_REPLY,
1671 rmp->acl_index = htonl(acl_list_index);
1677 vl_api_macip_acl_del_t_handler (vl_api_macip_acl_del_t * mp)
1679 acl_main_t *am = &acl_main;
1680 vl_api_macip_acl_del_reply_t *rmp;
1683 rv = macip_acl_del_list (ntohl (mp->acl_index));
1685 REPLY_MACRO (VL_API_MACIP_ACL_DEL_REPLY);
1689 vl_api_macip_acl_interface_add_del_t_handler
1690 (vl_api_macip_acl_interface_add_del_t * mp)
1692 acl_main_t *am = &acl_main;
1693 vl_api_macip_acl_interface_add_del_reply_t *rmp;
1695 vnet_interface_main_t *im = &am->vnet_main->interface_main;
1696 u32 sw_if_index = ntohl (mp->sw_if_index);
1698 if (pool_is_free_index(im->sw_interfaces, sw_if_index))
1699 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
1702 macip_acl_interface_add_del_acl (ntohl (mp->sw_if_index), mp->is_add,
1703 ntohl (mp->acl_index));
1705 REPLY_MACRO (VL_API_MACIP_ACL_INTERFACE_ADD_DEL_REPLY);
1709 send_macip_acl_details (acl_main_t * am, unix_shared_memory_queue_t * q,
1710 macip_acl_list_t * acl, u32 context)
1712 vl_api_macip_acl_details_t *mp;
1713 vl_api_macip_acl_rule_t *rules;
1714 macip_acl_rule_t *r;
1716 int msg_size = sizeof (*mp) + (acl ? sizeof (mp->r[0]) * acl->count : 0);
1718 mp = vl_msg_api_alloc (msg_size);
1719 memset (mp, 0, msg_size);
1720 mp->_vl_msg_id = ntohs (VL_API_MACIP_ACL_DETAILS + am->msg_id_base);
1722 /* fill in the message */
1723 mp->context = context;
1726 memcpy (mp->tag, acl->tag, sizeof (mp->tag));
1727 mp->count = htonl (acl->count);
1728 mp->acl_index = htonl (acl - am->macip_acls);
1730 for (i = 0; i < acl->count; i++)
1733 rules[i].is_permit = r->is_permit;
1734 rules[i].is_ipv6 = r->is_ipv6;
1735 memcpy (rules[i].src_mac, &r->src_mac, sizeof (r->src_mac));
1736 memcpy (rules[i].src_mac_mask, &r->src_mac_mask,
1737 sizeof (r->src_mac_mask));
1739 memcpy (rules[i].src_ip_addr, &r->src_ip_addr.ip6,
1740 sizeof (r->src_ip_addr.ip6));
1742 memcpy (rules[i].src_ip_addr, &r->src_ip_addr.ip4,
1743 sizeof (r->src_ip_addr.ip4));
1744 rules[i].src_ip_prefix_len = r->src_prefixlen;
1749 /* No martini, no party - no ACL applied to this interface. */
1754 vl_msg_api_send_shmem (q, (u8 *) & mp);
1759 vl_api_macip_acl_dump_t_handler (vl_api_macip_acl_dump_t * mp)
1761 acl_main_t *am = &acl_main;
1762 macip_acl_list_t *acl;
1764 unix_shared_memory_queue_t *q;
1766 q = vl_api_client_index_to_input_queue (mp->client_index);
1772 if (mp->acl_index == ~0)
1774 /* Just dump all ACLs for now, with sw_if_index = ~0 */
1775 pool_foreach (acl, am->macip_acls, (
1777 send_macip_acl_details (am, q, acl,
1785 u32 acl_index = ntohl (mp->acl_index);
1786 if (!pool_is_free_index (am->macip_acls, acl_index))
1788 acl = pool_elt_at_index (am->macip_acls, acl_index);
1789 send_macip_acl_details (am, q, acl, mp->context);
1795 vl_api_macip_acl_interface_get_t_handler (vl_api_macip_acl_interface_get_t *
1798 acl_main_t *am = &acl_main;
1799 vl_api_macip_acl_interface_get_reply_t *rmp;
1800 u32 count = vec_len (am->macip_acl_by_sw_if_index);
1801 int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]) * count;
1802 unix_shared_memory_queue_t *q;
1805 q = vl_api_client_index_to_input_queue (mp->client_index);
1811 rmp = vl_msg_api_alloc (msg_size);
1812 memset (rmp, 0, msg_size);
1814 ntohs (VL_API_MACIP_ACL_INTERFACE_GET_REPLY + am->msg_id_base);
1815 rmp->context = mp->context;
1816 rmp->count = htonl (count);
1817 for (i = 0; i < count; i++)
1819 rmp->acls[i] = htonl (am->macip_acl_by_sw_if_index[i]);
1822 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1826 send_macip_acl_interface_list_details (acl_main_t * am,
1827 unix_shared_memory_queue_t * q,
1832 vl_api_macip_acl_interface_list_details_t *rmp;
1833 /* at this time there is only ever 1 mac ip acl per interface */
1834 int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]);
1836 rmp = vl_msg_api_alloc (msg_size);
1837 memset (rmp, 0, msg_size);
1838 rmp->_vl_msg_id = ntohs (VL_API_MACIP_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
1840 /* fill in the message */
1841 rmp->context = context;
1843 rmp->sw_if_index = htonl (sw_if_index);
1844 rmp->acls[0] = htonl (acl_index);
1846 vl_msg_api_send_shmem (q, (u8 *) & rmp);
1850 vl_api_macip_acl_interface_list_dump_t_handler (vl_api_macip_acl_interface_list_dump_t *mp)
1852 unix_shared_memory_queue_t *q;
1853 acl_main_t *am = &acl_main;
1854 u32 sw_if_index = ntohl (mp->sw_if_index);
1856 q = vl_api_client_index_to_input_queue (mp->client_index);
1862 if (sw_if_index == ~0)
1864 vec_foreach_index(sw_if_index, am->macip_acl_by_sw_if_index)
1866 if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
1868 send_macip_acl_interface_list_details(am, q, sw_if_index,
1869 am->macip_acl_by_sw_if_index[sw_if_index],
1876 if (vec_len(am->macip_acl_by_sw_if_index) > sw_if_index)
1878 send_macip_acl_interface_list_details(am, q, sw_if_index,
1879 am->macip_acl_by_sw_if_index[sw_if_index],
1885 /* Set up the API message handling tables */
1886 static clib_error_t *
1887 acl_plugin_api_hookup (vlib_main_t * vm)
1889 acl_main_t *am = &acl_main;
1891 vl_msg_api_set_handlers((VL_API_##N + am->msg_id_base), \
1893 vl_api_##n##_t_handler, \
1895 vl_api_##n##_t_endian, \
1896 vl_api_##n##_t_print, \
1897 sizeof(vl_api_##n##_t), 1);
1898 foreach_acl_plugin_api_msg;
1904 #define vl_msg_name_crc_list
1905 #include <acl/acl_all_api_h.h>
1906 #undef vl_msg_name_crc_list
1909 setup_message_id_table (acl_main_t * am, api_main_t * apim)
1911 #define _(id,n,crc) \
1912 vl_msg_api_add_msg_name_crc (apim, #n "_" #crc, id + am->msg_id_base);
1913 foreach_vl_msg_name_crc_acl;
1918 acl_setup_fa_nodes (void)
1920 vlib_main_t *vm = vlib_get_main ();
1921 acl_main_t *am = &acl_main;
1922 vlib_node_t *n, *n4, *n6;
1924 n = vlib_get_node_by_name (vm, (u8 *) "l2-input-classify");
1925 n4 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-in-ip4-l2");
1926 n6 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-in-ip6-l2");
1929 am->l2_input_classify_next_acl_ip4 =
1930 vlib_node_add_next_with_slot (vm, n->index, n4->index, ~0);
1931 am->l2_input_classify_next_acl_ip6 =
1932 vlib_node_add_next_with_slot (vm, n->index, n6->index, ~0);
1934 feat_bitmap_init_next_nodes (vm, n4->index, L2INPUT_N_FEAT,
1935 l2input_get_feat_names (),
1936 am->fa_acl_in_ip4_l2_node_feat_next_node_index);
1938 feat_bitmap_init_next_nodes (vm, n6->index, L2INPUT_N_FEAT,
1939 l2input_get_feat_names (),
1940 am->fa_acl_in_ip6_l2_node_feat_next_node_index);
1943 n = vlib_get_node_by_name (vm, (u8 *) "l2-output-classify");
1944 n4 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-out-ip4-l2");
1945 n6 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-out-ip6-l2");
1947 am->l2_output_classify_next_acl_ip4 =
1948 vlib_node_add_next_with_slot (vm, n->index, n4->index, ~0);
1949 am->l2_output_classify_next_acl_ip6 =
1950 vlib_node_add_next_with_slot (vm, n->index, n6->index, ~0);
1952 feat_bitmap_init_next_nodes (vm, n4->index, L2OUTPUT_N_FEAT,
1953 l2output_get_feat_names (),
1954 am->fa_acl_out_ip4_l2_node_feat_next_node_index);
1956 feat_bitmap_init_next_nodes (vm, n6->index, L2OUTPUT_N_FEAT,
1957 l2output_get_feat_names (),
1958 am->fa_acl_out_ip6_l2_node_feat_next_node_index);
1962 acl_set_timeout_sec(int timeout_type, u32 value)
1964 acl_main_t *am = &acl_main;
1965 clib_time_t *ct = &am->vlib_main->clib_time;
1967 if (timeout_type < ACL_N_TIMEOUTS) {
1968 am->session_timeout_sec[timeout_type] = value;
1970 clib_warning("Unknown timeout type %d", timeout_type);
1973 am->session_timeout[timeout_type] = (u64)(((f64)value)/ct->seconds_per_clock);
1977 acl_set_session_max_entries(u32 value)
1979 acl_main_t *am = &acl_main;
1980 am->fa_conn_table_max_entries = value;
1984 acl_set_skip_ipv6_eh(u32 eh, u32 value)
1986 acl_main_t *am = &acl_main;
1988 if ((eh < 256) && (value < 2))
1990 am->fa_ipv6_known_eh_bitmap = clib_bitmap_set(am->fa_ipv6_known_eh_bitmap, eh, value);
1998 static clib_error_t *
1999 acl_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
2001 acl_main_t *am = &acl_main;
2002 if (0 == am->acl_mheap) {
2003 /* ACL heap is not initialized, so definitely nothing to do. */
2007 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
2008 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX, sw_if_index);
2009 /* also unapply any ACLs in case the users did not do so. */
2010 macip_acl_interface_del_acl(am, sw_if_index);
2011 acl_interface_reset_inout_acls (sw_if_index, 0);
2012 acl_interface_reset_inout_acls (sw_if_index, 1);
2017 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (acl_sw_interface_add_del);
2021 static clib_error_t *
2022 acl_set_aclplugin_fn (vlib_main_t * vm,
2023 unformat_input_t * input,
2024 vlib_cli_command_t * cmd)
2026 clib_error_t *error = 0;
2030 uword memory_size = 0;
2031 acl_main_t *am = &acl_main;
2033 if (unformat (input, "skip-ipv6-extension-header %u %u", &eh_val, &val)) {
2034 if(!acl_set_skip_ipv6_eh(eh_val, val)) {
2035 error = clib_error_return(0, "expecting eh=0..255, value=0..1");
2039 if (unformat (input, "use-hash-acl-matching %u", &val))
2041 am->use_hash_acl_matching = (val !=0);
2044 if (unformat (input, "l4-match-nonfirst-fragment %u", &val))
2046 am->l4_match_nonfirst_fragment = (val != 0);
2049 if (unformat (input, "heap"))
2051 if (unformat(input, "main"))
2053 if (unformat(input, "validate %u", &val))
2054 acl_plugin_acl_set_validate_heap(am, val);
2055 else if (unformat(input, "trace %u", &val))
2056 acl_plugin_acl_set_trace_heap(am, val);
2059 else if (unformat(input, "hash"))
2061 if (unformat(input, "validate %u", &val))
2062 acl_plugin_hash_acl_set_validate_heap(am, val);
2063 else if (unformat(input, "trace %u", &val))
2064 acl_plugin_hash_acl_set_trace_heap(am, val);
2069 if (unformat (input, "session")) {
2070 if (unformat (input, "table")) {
2071 /* The commands here are for tuning/testing. No user-serviceable parts inside */
2072 if (unformat (input, "max-entries")) {
2073 if (!unformat(input, "%u", &val)) {
2074 error = clib_error_return(0,
2075 "expecting maximum number of entries, got `%U`",
2076 format_unformat_error, input);
2079 acl_set_session_max_entries(val);
2083 if (unformat (input, "hash-table-buckets")) {
2084 if (!unformat(input, "%u", &val)) {
2085 error = clib_error_return(0,
2086 "expecting maximum number of hash table buckets, got `%U`",
2087 format_unformat_error, input);
2090 am->fa_conn_table_hash_num_buckets = val;
2094 if (unformat (input, "hash-table-memory")) {
2095 if (!unformat(input, "%U", unformat_memory_size, &memory_size)) {
2096 error = clib_error_return(0,
2097 "expecting maximum amount of hash table memory, got `%U`",
2098 format_unformat_error, input);
2101 am->fa_conn_table_hash_memory_size = memory_size;
2107 if (unformat (input, "timeout")) {
2108 if (unformat(input, "udp")) {
2109 if(unformat(input, "idle")) {
2110 if (!unformat(input, "%u", &timeout)) {
2111 error = clib_error_return(0,
2112 "expecting timeout value in seconds, got `%U`",
2113 format_unformat_error, input);
2116 acl_set_timeout_sec(ACL_TIMEOUT_UDP_IDLE, timeout);
2121 if (unformat(input, "tcp")) {
2122 if(unformat(input, "idle")) {
2123 if (!unformat(input, "%u", &timeout)) {
2124 error = clib_error_return(0,
2125 "expecting timeout value in seconds, got `%U`",
2126 format_unformat_error, input);
2129 acl_set_timeout_sec(ACL_TIMEOUT_TCP_IDLE, timeout);
2133 if(unformat(input, "transient")) {
2134 if (!unformat(input, "%u", &timeout)) {
2135 error = clib_error_return(0,
2136 "expecting timeout value in seconds, got `%U`",
2137 format_unformat_error, input);
2140 acl_set_timeout_sec(ACL_TIMEOUT_TCP_TRANSIENT, timeout);
2153 my_format_mac_address (u8 * s, va_list * args)
2155 u8 *a = va_arg (*args, u8 *);
2156 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
2157 a[0], a[1], a[2], a[3], a[4], a[5]);
2161 my_macip_acl_rule_t_pretty_format (u8 *out, va_list *args)
2163 macip_acl_rule_t *a = va_arg (*args, macip_acl_rule_t *);
2165 out = format(out, "%s action %d ip %U/%d mac %U mask %U",
2166 a->is_ipv6 ? "ipv6" : "ipv4", a->is_permit,
2167 format_ip46_address, &a->src_ip_addr,
2168 a->is_ipv6 ? IP46_TYPE_IP6: IP46_TYPE_IP4,
2170 my_format_mac_address, a->src_mac,
2171 my_format_mac_address, a->src_mac_mask);
2176 macip_acl_print(acl_main_t *am, u32 macip_acl_index)
2178 vlib_main_t * vm = am->vlib_main;
2181 /* Don't try to print someone else's memory */
2182 if (macip_acl_index > vec_len(am->macip_acls))
2185 macip_acl_list_t *a = vec_elt_at_index(am->macip_acls, macip_acl_index);
2186 int free_pool_slot = pool_is_free_index(am->macip_acls, macip_acl_index);
2188 vlib_cli_output(vm, "MACIP acl_index: %d, count: %d (true len %d) tag {%s} is free pool slot: %d\n",
2189 macip_acl_index, a->count, vec_len(a->rules), a->tag, free_pool_slot);
2190 vlib_cli_output(vm, " ip4_table_index %d, ip6_table_index %d, l2_table_index %d\n",
2191 a->ip4_table_index, a->ip6_table_index, a->l2_table_index);
2192 for(i=0; i<vec_len(a->rules); i++)
2193 vlib_cli_output(vm, " rule %d: %U\n", i, my_macip_acl_rule_t_pretty_format,
2194 vec_elt_at_index(a->rules, i));
2198 static clib_error_t *
2199 acl_show_aclplugin_macip_acl_fn (vlib_main_t * vm,
2200 unformat_input_t * input,
2201 vlib_cli_command_t * cmd)
2203 clib_error_t *error = 0;
2204 acl_main_t *am = &acl_main;
2206 for(i=0; i < vec_len(am->macip_acls); i++)
2207 macip_acl_print(am, i);
2211 static clib_error_t *
2212 acl_show_aclplugin_macip_interface_fn (vlib_main_t * vm,
2213 unformat_input_t * input,
2214 vlib_cli_command_t * cmd)
2216 clib_error_t *error = 0;
2217 acl_main_t *am = &acl_main;
2219 for(i=0; i < vec_len(am->macip_acl_by_sw_if_index); i++)
2221 vlib_cli_output(vm, " sw_if_index %d: %d\n", i, vec_elt(am->macip_acl_by_sw_if_index, i));
2226 #define PRINT_AND_RESET(vm, out0) do { vlib_cli_output(vm, "%v", out0); vec_reset_length(out0); } while(0)
2228 void acl_print_acl(vlib_main_t *vm, acl_main_t *am, int acl_index)
2231 u8 *out0 = format(0, "acl-index %u count %u tag {%s}\n", acl_index, am->acls[acl_index].count, am->acls[acl_index].tag);
2233 PRINT_AND_RESET(vm, out0);
2234 for(j=0; j<am->acls[acl_index].count; j++) {
2235 r = &am->acls[acl_index].rules[j];
2236 out0 = format(out0, " %4d: %s ", j, r->is_ipv6 ? "ipv6" : "ipv4");
2237 out0 = format_acl_action(out0, r->is_permit);
2238 out0 = format(out0, " src %U/%d", format_ip46_address, &r->src,
2239 r->is_ipv6 ? IP46_TYPE_IP6: IP46_TYPE_IP4, r->src_prefixlen);
2240 out0 = format(out0, " dst %U/%d", format_ip46_address, &r->dst,
2241 r->is_ipv6 ? IP46_TYPE_IP6: IP46_TYPE_IP4, r->dst_prefixlen);
2242 out0 = format(out0, " proto %d", r->proto);
2243 out0 = format(out0, " sport %d", r->src_port_or_type_first);
2244 if (r->src_port_or_type_first != r->src_port_or_type_last) {
2245 out0 = format(out0, "-%d", r->src_port_or_type_last);
2247 out0 = format(out0, " dport %d", r->dst_port_or_code_first);
2248 if (r->dst_port_or_code_first != r->dst_port_or_code_last) {
2249 out0 = format(out0, "-%d", r->dst_port_or_code_last);
2251 if (r->tcp_flags_mask || r->tcp_flags_value) {
2252 out0 = format(out0, " tcpflags %d mask %d", r->tcp_flags_value, r->tcp_flags_mask);
2254 out0 = format(out0, "\n");
2255 PRINT_AND_RESET(vm, out0);
2258 #undef PRINT_AND_RESET
2261 acl_plugin_show_acl(acl_main_t *am, u32 acl_index)
2264 vlib_main_t *vm = am->vlib_main;
2266 for(i=0; i<vec_len(am->acls); i++) {
2267 if (acl_is_not_defined(am, i)) {
2268 /* don't attempt to show the ACLs that do not exist */
2271 if ((acl_index != ~0) && (acl_index != i)) {
2274 acl_print_acl(vm, am, i);
2276 if (i<vec_len(am->input_sw_if_index_vec_by_acl)) {
2277 vlib_cli_output(vm, " applied inbound on sw_if_index: %U\n", format_vec32, am->input_sw_if_index_vec_by_acl[i], "%d");
2279 if (i<vec_len(am->output_sw_if_index_vec_by_acl)) {
2280 vlib_cli_output(vm, " applied outbound on sw_if_index: %U\n", format_vec32, am->output_sw_if_index_vec_by_acl[i], "%d");
2285 static clib_error_t *
2286 acl_show_aclplugin_acl_fn (vlib_main_t * vm,
2287 unformat_input_t * input,
2288 vlib_cli_command_t * cmd)
2290 clib_error_t *error = 0;
2291 acl_main_t *am = &acl_main;
2294 unformat (input, "index %u", &acl_index);
2296 acl_plugin_show_acl(am, acl_index);
2301 acl_plugin_show_interface(acl_main_t *am, u32 sw_if_index, int show_acl)
2303 vlib_main_t *vm = am->vlib_main;
2306 for(swi = 0; (swi < vec_len(am->input_acl_vec_by_sw_if_index)) ||
2307 (swi < vec_len(am->output_acl_vec_by_sw_if_index)); swi++) {
2308 /* if we need a particular interface, skip all the others */
2309 if ((sw_if_index != ~0) && (sw_if_index != swi))
2312 vlib_cli_output(vm, "sw_if_index %d:\n", swi);
2314 if ((swi < vec_len(am->input_acl_vec_by_sw_if_index)) &&
2315 (vec_len(am->input_acl_vec_by_sw_if_index[swi]) > 0)) {
2316 vlib_cli_output(vm, " input acl(s): %U", format_vec32, am->input_acl_vec_by_sw_if_index[swi], "%d");
2318 vlib_cli_output(vm, "\n");
2319 vec_foreach(pj, am->input_acl_vec_by_sw_if_index[swi]) {
2320 acl_print_acl(vm, am, *pj);
2322 vlib_cli_output(vm, "\n");
2326 if ((swi < vec_len(am->output_acl_vec_by_sw_if_index)) &&
2327 (vec_len(am->output_acl_vec_by_sw_if_index[swi]) > 0)) {
2328 vlib_cli_output(vm, " output acl(s): %U", format_vec32, am->output_acl_vec_by_sw_if_index[swi], "%d");
2330 vlib_cli_output(vm, "\n");
2331 vec_foreach(pj, am->output_acl_vec_by_sw_if_index[swi]) {
2332 acl_print_acl(vm, am, *pj);
2334 vlib_cli_output(vm, "\n");
2341 static clib_error_t *
2342 acl_show_aclplugin_interface_fn (vlib_main_t * vm,
2343 unformat_input_t * input,
2344 vlib_cli_command_t * cmd)
2346 clib_error_t *error = 0;
2347 acl_main_t *am = &acl_main;
2349 u32 sw_if_index = ~0;
2350 unformat (input, "sw_if_index %u", &sw_if_index);
2351 int show_acl = unformat(input, "acl");
2353 acl_plugin_show_interface(am, sw_if_index, show_acl);
2357 static clib_error_t *
2358 acl_show_aclplugin_memory_fn (vlib_main_t * vm,
2359 unformat_input_t * input,
2360 vlib_cli_command_t * cmd)
2362 clib_error_t *error = 0;
2363 acl_main_t *am = &acl_main;
2365 vlib_cli_output (vm, "ACL plugin main heap statistics:\n");
2366 if (am->acl_mheap) {
2367 vlib_cli_output (vm, " %U\n", format_mheap, am->acl_mheap, 1);
2369 vlib_cli_output (vm, " Not initialized\n");
2371 vlib_cli_output (vm, "ACL hash lookup support heap statistics:\n");
2372 if (am->hash_lookup_mheap) {
2373 vlib_cli_output (vm, " %U\n", format_mheap, am->hash_lookup_mheap, 1);
2375 vlib_cli_output (vm, " Not initialized\n");
2381 acl_plugin_show_sessions(acl_main_t *am,
2382 u32 show_session_thread_id, u32 show_session_session_index)
2384 vlib_main_t *vm = am->vlib_main;
2386 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2387 vnet_sw_interface_t *swif;
2390 u64 n_adds = am->fa_session_total_adds;
2391 u64 n_dels = am->fa_session_total_dels;
2392 vlib_cli_output(vm, "Sessions total: add %lu - del %lu = %lu", n_adds, n_dels, n_adds - n_dels);
2394 vlib_cli_output(vm, "\n\nPer-thread data:");
2395 for (wk = 0; wk < vec_len (am->per_worker_data); wk++) {
2396 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
2397 vlib_cli_output(vm, "Thread #%d:", wk);
2398 if (show_session_thread_id == wk && show_session_session_index < pool_len(pw->fa_sessions_pool)) {
2399 vlib_cli_output(vm, " session index %u:", show_session_session_index);
2400 fa_session_t *sess = pw->fa_sessions_pool + show_session_session_index;
2401 u64 *m = (u64 *)&sess->info;
2402 vlib_cli_output(vm, " info: %016llx %016llx %016llx %016llx %016llx %016llx", m[0], m[1], m[2], m[3], m[4], m[5]);
2403 vlib_cli_output(vm, " sw_if_index: %u", sess->sw_if_index);
2404 vlib_cli_output(vm, " tcp_flags_seen: %x", sess->tcp_flags_seen.as_u16);
2405 vlib_cli_output(vm, " last active time: %lu", sess->last_active_time);
2406 vlib_cli_output(vm, " thread index: %u", sess->thread_index);
2407 vlib_cli_output(vm, " link enqueue time: %lu", sess->link_enqueue_time);
2408 vlib_cli_output(vm, " link next index: %u", sess->link_next_idx);
2409 vlib_cli_output(vm, " link prev index: %u", sess->link_prev_idx);
2410 vlib_cli_output(vm, " link list id: %u", sess->link_list_id);
2412 vlib_cli_output(vm, " connection add/del stats:", wk);
2413 pool_foreach (swif, im->sw_interfaces,
2415 u32 sw_if_index = swif->sw_if_index;
2416 u64 n_adds = sw_if_index < vec_len(pw->fa_session_adds_by_sw_if_index) ? pw->fa_session_adds_by_sw_if_index[sw_if_index] : 0;
2417 u64 n_dels = sw_if_index < vec_len(pw->fa_session_dels_by_sw_if_index) ? pw->fa_session_dels_by_sw_if_index[sw_if_index] : 0;
2418 vlib_cli_output(vm, " sw_if_index %d: add %lu - del %lu = %lu", sw_if_index, n_adds, n_dels, n_adds - n_dels);
2421 vlib_cli_output(vm, " connection timeout type lists:", wk);
2423 for(tt = 0; tt < ACL_N_TIMEOUTS; tt++) {
2424 u32 head_session_index = pw->fa_conn_list_head[tt];
2425 vlib_cli_output(vm, " fa_conn_list_head[%d]: %d", tt, head_session_index);
2426 if (~0 != head_session_index) {
2427 fa_session_t *sess = pw->fa_sessions_pool + head_session_index;
2428 vlib_cli_output(vm, " last active time: %lu", sess->last_active_time);
2429 vlib_cli_output(vm, " link enqueue time: %lu", sess->link_enqueue_time);
2433 vlib_cli_output(vm, " Next expiry time: %lu", pw->next_expiry_time);
2434 vlib_cli_output(vm, " Requeue until time: %lu", pw->requeue_until_time);
2435 vlib_cli_output(vm, " Current time wait interval: %lu", pw->current_time_wait_interval);
2436 vlib_cli_output(vm, " Count of deleted sessions: %lu", pw->cnt_deleted_sessions);
2437 vlib_cli_output(vm, " Delete already deleted: %lu", pw->cnt_already_deleted_sessions);
2438 vlib_cli_output(vm, " Session timers restarted: %lu", pw->cnt_session_timer_restarted);
2439 vlib_cli_output(vm, " Swipe until this time: %lu", pw->swipe_end_time);
2440 vlib_cli_output(vm, " sw_if_index serviced bitmap: %U", format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
2441 vlib_cli_output(vm, " pending clear intfc bitmap : %U", format_bitmap_hex, pw->pending_clear_sw_if_index_bitmap);
2442 vlib_cli_output(vm, " clear in progress: %u", pw->clear_in_process);
2443 vlib_cli_output(vm, " interrupt is pending: %d", pw->interrupt_is_pending);
2444 vlib_cli_output(vm, " interrupt is needed: %d", pw->interrupt_is_needed);
2445 vlib_cli_output(vm, " interrupt is unwanted: %d", pw->interrupt_is_unwanted);
2446 vlib_cli_output(vm, " interrupt generation: %d", pw->interrupt_generation);
2448 vlib_cli_output(vm, "\n\nConn cleaner thread counters:");
2449 #define _(cnt, desc) vlib_cli_output(vm, " %20lu: %s", am->cnt, desc);
2450 foreach_fa_cleaner_counter;
2452 vlib_cli_output(vm, "Interrupt generation: %d", am->fa_interrupt_generation);
2453 vlib_cli_output(vm, "Sessions per interval: min %lu max %lu increment: %f ms current: %f ms",
2454 am->fa_min_deleted_sessions_per_interval, am->fa_max_deleted_sessions_per_interval,
2455 am->fa_cleaner_wait_time_increment * 1000.0, ((f64)am->fa_current_cleaner_timer_wait_interval) * 1000.0/(f64)vm->clib_time.clocks_per_second);
2458 static clib_error_t *
2459 acl_show_aclplugin_sessions_fn (vlib_main_t * vm,
2460 unformat_input_t * input,
2461 vlib_cli_command_t * cmd)
2463 clib_error_t *error = 0;
2464 acl_main_t *am = &acl_main;
2466 u32 show_bihash_verbose = 0;
2467 u32 show_session_thread_id = ~0;
2468 u32 show_session_session_index = ~0;
2469 unformat (input, "thread %u index %u", &show_session_thread_id, &show_session_session_index);
2470 unformat (input, "verbose %u", &show_bihash_verbose);
2472 acl_plugin_show_sessions(am, show_session_thread_id, show_session_session_index);
2473 show_fa_sessions_hash(vm, show_bihash_verbose);
2478 acl_plugin_show_tables_mask_type(acl_main_t *am)
2480 vlib_main_t *vm = am->vlib_main;
2481 ace_mask_type_entry_t *mte;
2483 vlib_cli_output(vm, "Mask-type entries:");
2485 pool_foreach(mte, am->ace_mask_type_pool,
2487 vlib_cli_output(vm, " %3d: %016llx %016llx %016llx %016llx %016llx %016llx refcount %d",
2488 mte - am->ace_mask_type_pool,
2489 mte->mask.kv.key[0], mte->mask.kv.key[1], mte->mask.kv.key[2],
2490 mte->mask.kv.key[3], mte->mask.kv.key[4], mte->mask.kv.value, mte->refcount);
2496 acl_plugin_show_tables_acl_hash_info(acl_main_t *am, u32 acl_index)
2498 vlib_main_t *vm = am->vlib_main;
2501 vlib_cli_output(vm, "Mask-ready ACL representations\n");
2502 for (i=0; i< vec_len(am->hash_acl_infos); i++) {
2503 if ((acl_index != ~0) && (acl_index != i)) {
2506 hash_acl_info_t *ha = &am->hash_acl_infos[i];
2507 vlib_cli_output(vm, "acl-index %u bitmask-ready layout\n", i);
2508 vlib_cli_output(vm, " applied inbound on sw_if_index list: %U\n", format_vec32, ha->inbound_sw_if_index_list, "%d");
2509 vlib_cli_output(vm, " applied outbound on sw_if_index list: %U\n", format_vec32, ha->outbound_sw_if_index_list, "%d");
2510 vlib_cli_output(vm, " mask type index bitmap: %U\n", format_bitmap_hex, ha->mask_type_index_bitmap);
2511 for(j=0; j<vec_len(ha->rules); j++) {
2512 hash_ace_info_t *pa = &ha->rules[j];
2513 m = (u64 *)&pa->match;
2514 vlib_cli_output(vm, " %4d: %016llx %016llx %016llx %016llx %016llx %016llx mask index %d acl %d rule %d action %d src/dst portrange not ^2: %d,%d\n",
2515 j, m[0], m[1], m[2], m[3], m[4], m[5], pa->mask_type_index,
2516 pa->acl_index, pa->ace_index, pa->action,
2517 pa->src_portrange_not_powerof2, pa->dst_portrange_not_powerof2);
2523 acl_plugin_print_pae(vlib_main_t *vm, int j, applied_hash_ace_entry_t *pae)
2525 vlib_cli_output(vm, " %4d: acl %d rule %d action %d bitmask-ready rule %d next %d prev %d tail %d hitcount %lld",
2526 j, pae->acl_index, pae->ace_index, pae->action, pae->hash_ace_info_index,
2527 pae->next_applied_entry_index, pae->prev_applied_entry_index, pae->tail_applied_entry_index, pae->hitcount);
2531 acl_plugin_show_tables_applied_info(acl_main_t *am, u32 sw_if_index)
2533 vlib_main_t *vm = am->vlib_main;
2535 vlib_cli_output(vm, "Applied lookup entries for interfaces");
2537 for(swi = 0; (swi < vec_len(am->input_applied_hash_acl_info_by_sw_if_index)) ||
2538 (swi < vec_len(am->output_applied_hash_acl_info_by_sw_if_index)) ||
2539 (swi < vec_len(am->input_hash_entry_vec_by_sw_if_index)) ||
2540 (swi < vec_len(am->output_hash_entry_vec_by_sw_if_index)); swi++) {
2541 if ((sw_if_index != ~0) && (sw_if_index != swi)) {
2544 vlib_cli_output(vm, "sw_if_index %d:", swi);
2545 if (swi < vec_len(am->input_applied_hash_acl_info_by_sw_if_index)) {
2546 applied_hash_acl_info_t *pal = &am->input_applied_hash_acl_info_by_sw_if_index[swi];
2547 vlib_cli_output(vm, " input lookup mask_type_index_bitmap: %U", format_bitmap_hex, pal->mask_type_index_bitmap);
2548 vlib_cli_output(vm, " input applied acls: %U", format_vec32, pal->applied_acls, "%d");
2550 if (swi < vec_len(am->input_hash_entry_vec_by_sw_if_index)) {
2551 vlib_cli_output(vm, " input lookup applied entries:");
2552 for(j=0; j<vec_len(am->input_hash_entry_vec_by_sw_if_index[swi]); j++) {
2553 acl_plugin_print_pae(vm, j, &am->input_hash_entry_vec_by_sw_if_index[swi][j]);
2557 if (swi < vec_len(am->output_applied_hash_acl_info_by_sw_if_index)) {
2558 applied_hash_acl_info_t *pal = &am->output_applied_hash_acl_info_by_sw_if_index[swi];
2559 vlib_cli_output(vm, " output lookup mask_type_index_bitmap: %U", format_bitmap_hex, pal->mask_type_index_bitmap);
2560 vlib_cli_output(vm, " output applied acls: %U", format_vec32, pal->applied_acls, "%d");
2562 if (swi < vec_len(am->output_hash_entry_vec_by_sw_if_index)) {
2563 vlib_cli_output(vm, " output lookup applied entries:");
2564 for(j=0; j<vec_len(am->output_hash_entry_vec_by_sw_if_index[swi]); j++) {
2565 acl_plugin_print_pae(vm, j, &am->output_hash_entry_vec_by_sw_if_index[swi][j]);
2572 acl_plugin_show_tables_bihash(acl_main_t *am, u32 show_bihash_verbose)
2574 vlib_main_t *vm = am->vlib_main;
2575 show_hash_acl_hash(vm, am, show_bihash_verbose);
2578 static clib_error_t *
2579 acl_show_aclplugin_tables_fn (vlib_main_t * vm,
2580 unformat_input_t * input,
2581 vlib_cli_command_t * cmd)
2583 clib_error_t *error = 0;
2584 acl_main_t *am = &acl_main;
2587 u32 sw_if_index = ~0;
2588 int show_acl_hash_info = 0;
2589 int show_applied_info = 0;
2590 int show_mask_type = 0;
2591 int show_bihash = 0;
2592 u32 show_bihash_verbose = 0;
2594 if (unformat (input, "acl")) {
2595 show_acl_hash_info = 1;
2596 /* mask-type is handy to see as well right there */
2598 unformat (input, "index %u", &acl_index);
2599 } else if (unformat (input, "applied")) {
2600 show_applied_info = 1;
2601 unformat (input, "sw_if_index %u", &sw_if_index);
2602 } else if (unformat (input, "mask")) {
2604 } else if (unformat (input, "hash")) {
2606 unformat (input, "verbose %u", &show_bihash_verbose);
2609 if ( ! (show_mask_type || show_acl_hash_info || show_applied_info || show_bihash) ) {
2610 /* if no qualifiers specified, show all */
2612 show_acl_hash_info = 1;
2613 show_applied_info = 1;
2617 acl_plugin_show_tables_mask_type(am);
2618 if (show_acl_hash_info)
2619 acl_plugin_show_tables_acl_hash_info(am, acl_index);
2620 if (show_applied_info)
2621 acl_plugin_show_tables_applied_info(am, sw_if_index);
2623 acl_plugin_show_tables_bihash(am, show_bihash_verbose);
2628 static clib_error_t *
2629 acl_clear_aclplugin_fn (vlib_main_t * vm,
2630 unformat_input_t * input,
2631 vlib_cli_command_t * cmd)
2633 clib_error_t *error = 0;
2634 acl_main_t *am = &acl_main;
2635 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
2636 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX, ~0);
2641 VLIB_CLI_COMMAND (aclplugin_set_command, static) = {
2642 .path = "set acl-plugin",
2643 .short_help = "set acl-plugin session timeout {{udp idle}|tcp {idle|transient}} <seconds>",
2644 .function = acl_set_aclplugin_fn,
2647 VLIB_CLI_COMMAND (aclplugin_show_acl_command, static) = {
2648 .path = "show acl-plugin acl",
2649 .short_help = "show acl-plugin acl [index N]",
2650 .function = acl_show_aclplugin_acl_fn,
2653 VLIB_CLI_COMMAND (aclplugin_show_interface_command, static) = {
2654 .path = "show acl-plugin interface",
2655 .short_help = "show acl-plugin interface [sw_if_index N] [acl]",
2656 .function = acl_show_aclplugin_interface_fn,
2659 VLIB_CLI_COMMAND (aclplugin_show_memory_command, static) = {
2660 .path = "show acl-plugin memory",
2661 .short_help = "show acl-plugin memory",
2662 .function = acl_show_aclplugin_memory_fn,
2665 VLIB_CLI_COMMAND (aclplugin_show_sessions_command, static) = {
2666 .path = "show acl-plugin sessions",
2667 .short_help = "show acl-plugin sessions",
2668 .function = acl_show_aclplugin_sessions_fn,
2671 VLIB_CLI_COMMAND (aclplugin_show_tables_command, static) = {
2672 .path = "show acl-plugin tables",
2673 .short_help = "show acl-plugin tables [ acl [index N] | applied [ sw_if_index N ] | mask | hash [verbose N] ]",
2674 .function = acl_show_aclplugin_tables_fn,
2677 VLIB_CLI_COMMAND (aclplugin_show_macip_acl_command, static) = {
2678 .path = "show acl-plugin macip acl",
2679 .short_help = "show acl-plugin macip acl",
2680 .function = acl_show_aclplugin_macip_acl_fn,
2683 VLIB_CLI_COMMAND (aclplugin_show_macip_interface_command, static) = {
2684 .path = "show acl-plugin macip interface",
2685 .short_help = "show acl-plugin macip interface",
2686 .function = acl_show_aclplugin_macip_interface_fn,
2689 VLIB_CLI_COMMAND (aclplugin_clear_command, static) = {
2690 .path = "clear acl-plugin sessions",
2691 .short_help = "clear acl-plugin sessions",
2692 .function = acl_clear_aclplugin_fn,
2696 static clib_error_t *
2697 acl_plugin_config (vlib_main_t * vm, unformat_input_t * input)
2699 acl_main_t *am = &acl_main;
2700 u32 conn_table_hash_buckets;
2701 u32 conn_table_hash_memory_size;
2702 u32 conn_table_max_entries;
2705 u32 hash_lookup_hash_buckets;
2706 u32 hash_lookup_hash_memory;
2708 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2710 if (unformat (input, "connection hash buckets %d", &conn_table_hash_buckets))
2711 am->fa_conn_table_hash_num_buckets = conn_table_hash_buckets;
2712 else if (unformat (input, "connection hash memory %d",
2713 &conn_table_hash_memory_size))
2714 am->fa_conn_table_hash_memory_size = conn_table_hash_memory_size;
2715 else if (unformat (input, "connection count max %d",
2716 &conn_table_max_entries))
2717 am->fa_conn_table_max_entries = conn_table_max_entries;
2718 else if (unformat (input, "main heap size %d",
2720 am->acl_mheap_size = main_heap_size;
2721 else if (unformat (input, "hash lookup heap size %d",
2723 am->hash_lookup_mheap_size = hash_heap_size;
2724 else if (unformat (input, "hash lookup hash buckets %d",
2725 &hash_lookup_hash_buckets))
2726 am->hash_lookup_hash_buckets = hash_lookup_hash_buckets;
2727 else if (unformat (input, "hash lookup hash memory %d",
2728 &hash_lookup_hash_memory))
2729 am->hash_lookup_hash_memory = hash_lookup_hash_memory;
2731 return clib_error_return (0, "unknown input '%U'",
2732 format_unformat_error, input);
2736 VLIB_CONFIG_FUNCTION (acl_plugin_config, "acl-plugin");
2738 static clib_error_t *
2739 acl_init (vlib_main_t * vm)
2741 acl_main_t *am = &acl_main;
2742 clib_error_t *error = 0;
2743 memset (am, 0, sizeof (*am));
2745 am->vnet_main = vnet_get_main ();
2747 u8 *name = format (0, "acl_%08x%c", api_version, 0);
2749 /* Ask for a correctly-sized block of API message decode slots */
2750 am->msg_id_base = vl_msg_api_get_msg_ids ((char *) name,
2751 VL_MSG_FIRST_AVAILABLE);
2753 error = acl_plugin_api_hookup (vm);
2755 /* Add our API messages to the global name_crc hash table */
2756 setup_message_id_table (am, &api_main);
2760 acl_setup_fa_nodes();
2762 am->acl_mheap_size = ACL_FA_DEFAULT_HEAP_SIZE;
2763 am->hash_lookup_mheap_size = ACL_PLUGIN_HASH_LOOKUP_HEAP_SIZE;
2765 am->hash_lookup_hash_buckets = ACL_PLUGIN_HASH_LOOKUP_HASH_BUCKETS;
2766 am->hash_lookup_hash_memory = ACL_PLUGIN_HASH_LOOKUP_HASH_MEMORY;
2768 am->session_timeout_sec[ACL_TIMEOUT_TCP_TRANSIENT] = TCP_SESSION_TRANSIENT_TIMEOUT_SEC;
2769 am->session_timeout_sec[ACL_TIMEOUT_TCP_IDLE] = TCP_SESSION_IDLE_TIMEOUT_SEC;
2770 am->session_timeout_sec[ACL_TIMEOUT_UDP_IDLE] = UDP_SESSION_IDLE_TIMEOUT_SEC;
2772 am->fa_conn_table_hash_num_buckets = ACL_FA_CONN_TABLE_DEFAULT_HASH_NUM_BUCKETS;
2773 am->fa_conn_table_hash_memory_size = ACL_FA_CONN_TABLE_DEFAULT_HASH_MEMORY_SIZE;
2774 am->fa_conn_table_max_entries = ACL_FA_CONN_TABLE_DEFAULT_MAX_ENTRIES;
2775 vlib_thread_main_t *tm = vlib_get_thread_main ();
2776 vec_validate(am->per_worker_data, tm->n_vlib_mains-1);
2780 for (wk = 0; wk < vec_len (am->per_worker_data); wk++) {
2781 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
2782 vec_validate(pw->fa_conn_list_head, ACL_N_TIMEOUTS-1);
2783 vec_validate(pw->fa_conn_list_tail, ACL_N_TIMEOUTS-1);
2784 for(tt = 0; tt < ACL_N_TIMEOUTS; tt++) {
2785 pw->fa_conn_list_head[tt] = ~0;
2786 pw->fa_conn_list_tail[tt] = ~0;
2791 am->fa_min_deleted_sessions_per_interval = ACL_FA_DEFAULT_MIN_DELETED_SESSIONS_PER_INTERVAL;
2792 am->fa_max_deleted_sessions_per_interval = ACL_FA_DEFAULT_MAX_DELETED_SESSIONS_PER_INTERVAL;
2793 am->fa_cleaner_wait_time_increment = ACL_FA_DEFAULT_CLEANER_WAIT_TIME_INCREMENT;
2795 am->fa_cleaner_cnt_delete_by_sw_index = 0;
2796 am->fa_cleaner_cnt_delete_by_sw_index_ok = 0;
2797 am->fa_cleaner_cnt_unknown_event = 0;
2798 am->fa_cleaner_cnt_timer_restarted = 0;
2799 am->fa_cleaner_cnt_wait_with_timeout = 0;
2802 #define _(N, v, s) am->fa_ipv6_known_eh_bitmap = clib_bitmap_set(am->fa_ipv6_known_eh_bitmap, v, 1);
2806 am->l4_match_nonfirst_fragment = 1;
2808 /* use the new fancy hash-based matching */
2809 am->use_hash_acl_matching = 1;
2814 VLIB_INIT_FUNCTION (acl_init);