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/in_out_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) \
79 _(ACL_INTERFACE_SET_ETYPE_WHITELIST, acl_interface_set_etype_whitelist)
83 VLIB_PLUGIN_REGISTER () = {
84 .version = VPP_BUILD_VER,
85 .description = "Access Control Lists",
91 format_vec16 (u8 * s, va_list * va)
93 u16 *v = va_arg (*va, u16 *);
94 char *fmt = va_arg (*va, char *);
96 for (i = 0; i < vec_len (v); i++)
100 s = format (s, fmt, v[i]);
109 acl_set_heap (acl_main_t * am)
111 if (0 == am->acl_mheap)
113 am->acl_mheap = mheap_alloc (0 /* use VM */ , am->acl_mheap_size);
114 mheap_t *h = mheap_header (am->acl_mheap);
115 h->flags |= MHEAP_FLAG_THREAD_SAFE;
117 void *oldheap = clib_mem_set_heap (am->acl_mheap);
122 acl_plugin_acl_set_validate_heap (acl_main_t * am, int on)
124 clib_mem_set_heap (acl_set_heap (am));
125 mheap_t *h = mheap_header (am->acl_mheap);
128 h->flags |= MHEAP_FLAG_VALIDATE;
129 h->flags &= ~MHEAP_FLAG_SMALL_OBJECT_CACHE;
134 h->flags &= ~MHEAP_FLAG_VALIDATE;
135 h->flags |= MHEAP_FLAG_SMALL_OBJECT_CACHE;
140 acl_plugin_acl_set_trace_heap (acl_main_t * am, int on)
142 clib_mem_set_heap (acl_set_heap (am));
143 mheap_t *h = mheap_header (am->acl_mheap);
146 h->flags |= MHEAP_FLAG_TRACE;
150 h->flags &= ~MHEAP_FLAG_TRACE;
155 vl_api_acl_plugin_get_version_t_handler (vl_api_acl_plugin_get_version_t * mp)
157 acl_main_t *am = &acl_main;
158 vl_api_acl_plugin_get_version_reply_t *rmp;
159 int msg_size = sizeof (*rmp);
160 vl_api_registration_t *reg;
162 reg = vl_api_client_index_to_registration (mp->client_index);
166 rmp = vl_msg_api_alloc (msg_size);
167 memset (rmp, 0, msg_size);
169 ntohs (VL_API_ACL_PLUGIN_GET_VERSION_REPLY + am->msg_id_base);
170 rmp->context = mp->context;
171 rmp->major = htonl (ACL_PLUGIN_VERSION_MAJOR);
172 rmp->minor = htonl (ACL_PLUGIN_VERSION_MINOR);
174 vl_api_send_msg (reg, (u8 *) rmp);
178 vl_api_acl_plugin_control_ping_t_handler (vl_api_acl_plugin_control_ping_t *
181 vl_api_acl_plugin_control_ping_reply_t *rmp;
182 acl_main_t *am = &acl_main;
186 REPLY_MACRO2 (VL_API_ACL_PLUGIN_CONTROL_PING_REPLY,
188 rmp->vpe_pid = ntohl (getpid ());
194 acl_add_list (u32 count, vl_api_acl_rule_t rules[],
195 u32 * acl_list_index, u8 * tag)
197 acl_main_t *am = &acl_main;
200 acl_rule_t *acl_new_rules = 0;
203 if (*acl_list_index != ~0)
205 /* They supplied some number, let's see if this ACL exists */
206 if (pool_is_free_index (am->acls, *acl_list_index))
208 /* tried to replace a non-existent ACL, no point doing anything */
210 ("acl-plugin-error: Trying to replace nonexistent ACL %d (tag %s)",
211 *acl_list_index, tag);
212 return VNET_API_ERROR_NO_SUCH_ENTRY;
218 ("acl-plugin-warning: supplied no rules for ACL %d (tag %s)",
219 *acl_list_index, tag);
222 void *oldheap = acl_set_heap (am);
224 /* Create and populate the rules */
226 vec_validate (acl_new_rules, count - 1);
228 for (i = 0; i < count; i++)
230 r = vec_elt_at_index (acl_new_rules, i);
231 memset (r, 0, sizeof (*r));
232 r->is_permit = rules[i].is_permit;
233 r->is_ipv6 = rules[i].is_ipv6;
236 memcpy (&r->src, rules[i].src_ip_addr, sizeof (r->src));
237 memcpy (&r->dst, rules[i].dst_ip_addr, sizeof (r->dst));
241 memcpy (&r->src.ip4, rules[i].src_ip_addr, sizeof (r->src.ip4));
242 memcpy (&r->dst.ip4, rules[i].dst_ip_addr, sizeof (r->dst.ip4));
244 r->src_prefixlen = rules[i].src_ip_prefix_len;
245 r->dst_prefixlen = rules[i].dst_ip_prefix_len;
246 r->proto = rules[i].proto;
247 r->src_port_or_type_first = ntohs (rules[i].srcport_or_icmptype_first);
248 r->src_port_or_type_last = ntohs (rules[i].srcport_or_icmptype_last);
249 r->dst_port_or_code_first = ntohs (rules[i].dstport_or_icmpcode_first);
250 r->dst_port_or_code_last = ntohs (rules[i].dstport_or_icmpcode_last);
251 r->tcp_flags_value = rules[i].tcp_flags_value;
252 r->tcp_flags_mask = rules[i].tcp_flags_mask;
255 if (~0 == *acl_list_index)
258 pool_get_aligned (am->acls, a, CLIB_CACHE_LINE_BYTES);
259 memset (a, 0, sizeof (*a));
260 /* Will return the newly allocated ACL index */
261 *acl_list_index = a - am->acls;
265 a = am->acls + *acl_list_index;
266 hash_acl_delete (am, *acl_list_index);
267 /* Get rid of the old rules */
271 a->rules = acl_new_rules;
273 memcpy (a->tag, tag, sizeof (a->tag));
274 hash_acl_add (am, *acl_list_index);
275 clib_mem_set_heap (oldheap);
280 acl_del_list (u32 acl_list_index)
282 acl_main_t *am = &acl_main;
285 if (pool_is_free_index (am->acls, acl_list_index))
287 return VNET_API_ERROR_NO_SUCH_ENTRY;
290 if (acl_list_index < vec_len (am->input_sw_if_index_vec_by_acl))
292 if (vec_len (vec_elt (am->input_sw_if_index_vec_by_acl, acl_list_index))
295 /* ACL is applied somewhere inbound. Refuse to delete */
296 return VNET_API_ERROR_ACL_IN_USE_INBOUND;
299 if (acl_list_index < vec_len (am->output_sw_if_index_vec_by_acl))
302 (vec_elt (am->output_sw_if_index_vec_by_acl, acl_list_index)) > 0)
304 /* ACL is applied somewhere outbound. Refuse to delete */
305 return VNET_API_ERROR_ACL_IN_USE_OUTBOUND;
309 void *oldheap = acl_set_heap (am);
310 /* delete any references to the ACL */
311 for (i = 0; i < vec_len (am->output_acl_vec_by_sw_if_index); i++)
313 for (ii = 0; ii < vec_len (am->output_acl_vec_by_sw_if_index[i]);
316 if (acl_list_index == am->output_acl_vec_by_sw_if_index[i][ii])
318 vec_del1 (am->output_acl_vec_by_sw_if_index[i], ii);
326 for (i = 0; i < vec_len (am->input_acl_vec_by_sw_if_index); i++)
328 for (ii = 0; ii < vec_len (am->input_acl_vec_by_sw_if_index[i]);
331 if (acl_list_index == am->input_acl_vec_by_sw_if_index[i][ii])
333 vec_del1 (am->input_acl_vec_by_sw_if_index[i], ii);
341 /* delete the hash table data */
343 hash_acl_delete (am, acl_list_index);
344 /* now we can delete the ACL itself */
345 a = pool_elt_at_index (am->acls, acl_list_index);
349 pool_put (am->acls, a);
350 clib_mem_set_heap (oldheap);
354 /* Some aids in ASCII graphing the content */
361 u8 ip4_5tuple_mask[] =
362 _(" dmac smac etype ")
363 _(ether) __ __ __ __ __ __ v __ __ __ __ __ __ v __ __ v
370 _(" ttl pr checksum ")
379 _("L4 T/U sport dport ")
389 u8 ip6_5tuple_mask[] =
390 _(" dmac smac etype ")
391 _(ether) __ __ __ __ __ __ v __ __ __ __ __ __ v __ __ v
393 _(0x0000) __ __ __ __
395 _(0x0004) __ __ XX __
397 _(0x0008) XX XX XX XX
398 _(0x000C) XX XX XX XX
399 _(0x0010) XX XX XX XX
400 _(0x0014) XX XX XX XX
402 _(0x0018) XX XX XX XX
403 _(0x001C) XX XX XX XX
404 _(0x0020) XX XX XX XX
405 _(0x0024) XX XX XX XX
406 _("L4T/U sport dport ")
407 _(tcpudp) XX XX XX XX _(padpad) __ __ __ __ _(padeth) __ __;
409 u8 dot1q_5tuple_mask[] =
410 _(" dmac smac dot1q etype ")
411 _(ether) __ __ __ __ __ __ v __ __ __ __ __ __ v XX XX __ __ v XX XX v
412 _(padpad) __ __ __ __
413 _(padpad) __ __ __ __
414 _(padpad) __ __ __ __
417 u8 dot1ad_5tuple_mask[] =
418 _(" dmac smac dot1ad dot1q etype ")
419 _(ether) __ __ __ __ __ __ v __ __ __ __ __ __ v XX XX __ __ XX XX __ __ v XX XX v
420 _(padpad) __ __ __ __
421 _(padpad) __ __ __ __
424 u8 ethertype_mask[] =
425 _(" dmac smac etype ")
426 _(ether) __ __ __ __ __ __ v __ __ __ __ __ __ v XX XX __ __;
435 count_skip (u8 * p, u32 size)
437 u64 *p64 = (u64 *) p;
438 /* Be tolerant to null pointer */
442 while ((0ULL == *p64) && ((u8 *) p64 - p) < size)
446 return (p64 - (u64 *) p) / 2;
450 acl_classify_add_del_table_tiny (vnet_classify_main_t * cm, u8 * mask,
451 u32 mask_len, u32 next_table_index,
452 u32 miss_next_index, u32 * table_index,
456 u32 memory_size = 2 << 13;
457 u32 skip = count_skip (mask, mask_len);
458 u32 match = (mask_len / 16) - skip;
459 u8 *skip_mask_ptr = mask + 16 * skip;
460 u32 current_data_flag = 0;
461 int current_data_offset = 0;
465 void *oldheap = clib_mem_set_heap (cm->vlib_main->heap_base);
466 int ret = vnet_classify_add_del_table (cm, skip_mask_ptr, nbuckets,
467 memory_size, skip, match,
468 next_table_index, miss_next_index,
469 table_index, current_data_flag,
470 current_data_offset, is_add,
471 1 /* delete_chain */ );
472 clib_mem_set_heap (oldheap);
477 acl_classify_add_del_table_small (vnet_classify_main_t * cm, u8 * mask,
478 u32 mask_len, u32 next_table_index,
479 u32 miss_next_index, u32 * table_index,
483 u32 memory_size = 2 << 22;
484 u32 skip = count_skip (mask, mask_len);
485 u32 match = (mask_len / 16) - skip;
486 u8 *skip_mask_ptr = mask + 16 * skip;
487 u32 current_data_flag = 0;
488 int current_data_offset = 0;
493 void *oldheap = clib_mem_set_heap (cm->vlib_main->heap_base);
494 int ret = vnet_classify_add_del_table (cm, skip_mask_ptr, nbuckets,
495 memory_size, skip, match,
496 next_table_index, miss_next_index,
497 table_index, current_data_flag,
498 current_data_offset, is_add,
499 1 /* delete_chain */ );
500 clib_mem_set_heap (oldheap);
505 acl_unhook_l2_input_classify (acl_main_t * am, u32 sw_if_index)
507 vnet_classify_main_t *cm = &vnet_classify_main;
508 u32 ip4_table_index = ~0;
509 u32 ip6_table_index = ~0;
510 u32 dot1q_table_index = ~0;
511 u32 dot1ad_table_index = ~0;
512 u32 etype_table_index = ~0;
513 void *oldheap = acl_set_heap (am);
515 vec_validate_init_empty (am->acl_ip4_input_classify_table_by_sw_if_index,
517 vec_validate_init_empty (am->acl_ip6_input_classify_table_by_sw_if_index,
519 vec_validate_init_empty (am->acl_dot1q_input_classify_table_by_sw_if_index,
521 vec_validate_init_empty (am->acl_dot1ad_input_classify_table_by_sw_if_index,
523 vec_validate_init_empty (am->acl_etype_input_classify_table_by_sw_if_index,
526 /* switch to global heap while calling vnet_* functions */
527 clib_mem_set_heap (cm->vlib_main->heap_base);
528 vnet_l2_input_classify_enable_disable (sw_if_index, 0);
530 if (am->acl_ip4_input_classify_table_by_sw_if_index[sw_if_index] != ~0)
533 am->acl_ip4_input_classify_table_by_sw_if_index[sw_if_index];
534 am->acl_ip4_input_classify_table_by_sw_if_index[sw_if_index] = ~0;
535 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
536 sizeof (ip4_5tuple_mask) - 1, ~0,
537 am->l2_input_classify_next_acl_ip4,
538 &ip4_table_index, 0);
540 if (am->acl_ip6_input_classify_table_by_sw_if_index[sw_if_index] != ~0)
543 am->acl_ip6_input_classify_table_by_sw_if_index[sw_if_index];
544 am->acl_ip6_input_classify_table_by_sw_if_index[sw_if_index] = ~0;
545 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
546 sizeof (ip6_5tuple_mask) - 1, ~0,
547 am->l2_input_classify_next_acl_ip6,
548 &ip6_table_index, 0);
550 if (am->acl_dot1q_input_classify_table_by_sw_if_index[sw_if_index] != ~0)
553 am->acl_dot1q_input_classify_table_by_sw_if_index[sw_if_index];
554 am->acl_dot1q_input_classify_table_by_sw_if_index[sw_if_index] = ~0;
555 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
556 sizeof (ip6_5tuple_mask) - 1, ~0,
557 ~0, &dot1q_table_index, 0);
559 if (am->acl_dot1ad_input_classify_table_by_sw_if_index[sw_if_index] != ~0)
562 am->acl_dot1ad_input_classify_table_by_sw_if_index[sw_if_index];
563 am->acl_dot1ad_input_classify_table_by_sw_if_index[sw_if_index] = ~0;
564 acl_classify_add_del_table_tiny (cm, dot1ad_5tuple_mask,
565 sizeof (dot1ad_5tuple_mask) - 1, ~0,
566 ~0, &dot1ad_table_index, 0);
568 if (am->acl_etype_input_classify_table_by_sw_if_index[sw_if_index] != ~0)
571 am->acl_etype_input_classify_table_by_sw_if_index[sw_if_index];
572 am->acl_etype_input_classify_table_by_sw_if_index[sw_if_index] = ~0;
573 acl_classify_add_del_table_tiny (cm, ethertype_mask,
574 sizeof (ethertype_mask) - 1, ~0,
575 ~0, &etype_table_index, 0);
577 clib_mem_set_heap (oldheap);
582 acl_unhook_l2_output_classify (acl_main_t * am, u32 sw_if_index)
584 vnet_classify_main_t *cm = &vnet_classify_main;
585 u32 ip4_table_index = ~0;
586 u32 ip6_table_index = ~0;
587 u32 dot1q_table_index = ~0;
588 u32 dot1ad_table_index = ~0;
589 u32 etype_table_index = ~0;
590 void *oldheap = acl_set_heap (am);
592 vec_validate_init_empty (am->acl_ip4_output_classify_table_by_sw_if_index,
594 vec_validate_init_empty (am->acl_ip6_output_classify_table_by_sw_if_index,
596 vec_validate_init_empty (am->acl_dot1q_output_classify_table_by_sw_if_index,
598 vec_validate_init_empty
599 (am->acl_dot1ad_output_classify_table_by_sw_if_index, sw_if_index, ~0);
600 vec_validate_init_empty (am->acl_etype_output_classify_table_by_sw_if_index,
603 /* switch to global heap while calling vnet_* functions */
604 clib_mem_set_heap (cm->vlib_main->heap_base);
606 vnet_l2_output_classify_enable_disable (sw_if_index, 0);
608 if (am->acl_ip4_output_classify_table_by_sw_if_index[sw_if_index] != ~0)
611 am->acl_ip4_output_classify_table_by_sw_if_index[sw_if_index];
612 am->acl_ip4_output_classify_table_by_sw_if_index[sw_if_index] = ~0;
613 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
614 sizeof (ip4_5tuple_mask) - 1, ~0,
615 am->l2_output_classify_next_acl_ip4,
616 &ip4_table_index, 0);
618 if (am->acl_ip6_output_classify_table_by_sw_if_index[sw_if_index] != ~0)
621 am->acl_ip6_output_classify_table_by_sw_if_index[sw_if_index];
622 am->acl_ip6_output_classify_table_by_sw_if_index[sw_if_index] = ~0;
623 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
624 sizeof (ip6_5tuple_mask) - 1, ~0,
625 am->l2_output_classify_next_acl_ip6,
626 &ip6_table_index, 0);
628 if (am->acl_dot1q_output_classify_table_by_sw_if_index[sw_if_index] != ~0)
631 am->acl_dot1q_output_classify_table_by_sw_if_index[sw_if_index];
632 am->acl_dot1q_output_classify_table_by_sw_if_index[sw_if_index] = ~0;
633 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
634 sizeof (ip6_5tuple_mask) - 1, ~0,
635 ~0, &dot1q_table_index, 0);
637 if (am->acl_dot1ad_output_classify_table_by_sw_if_index[sw_if_index] != ~0)
640 am->acl_dot1ad_output_classify_table_by_sw_if_index[sw_if_index];
641 am->acl_dot1ad_output_classify_table_by_sw_if_index[sw_if_index] = ~0;
642 acl_classify_add_del_table_tiny (cm, dot1ad_5tuple_mask,
643 sizeof (dot1ad_5tuple_mask) - 1, ~0,
644 ~0, &dot1ad_table_index, 0);
646 if (am->acl_etype_output_classify_table_by_sw_if_index[sw_if_index] != ~0)
649 am->acl_etype_output_classify_table_by_sw_if_index[sw_if_index];
650 am->acl_etype_output_classify_table_by_sw_if_index[sw_if_index] = ~0;
651 acl_classify_add_del_table_tiny (cm, ethertype_mask,
652 sizeof (ethertype_mask) - 1, ~0,
653 ~0, &etype_table_index, 0);
655 clib_mem_set_heap (oldheap);
660 acl_add_vlan_session (acl_main_t * am, u32 table_index, u8 is_output,
661 u8 is_dot1ad, u8 is_ip6)
663 vnet_classify_main_t *cm = &vnet_classify_main;
673 l2_output_classify_next_acl_ip6 : am->l2_input_classify_next_acl_ip6;
679 l2_output_classify_next_acl_ip4 : am->l2_input_classify_next_acl_ip4;
681 match = (is_dot1ad) ? dot1ad_5tuple_mask : dot1q_5tuple_mask;
682 idx = (is_dot1ad) ? 20 : 16;
685 /* 802.1ad ethertype */
688 /* 802.1q ethertype */
694 /* 802.1q ethertype */
699 /* add sessions to vlan tables per ethernet_type */
703 match[idx + 1] = 0xdd;
709 match[idx + 1] = 0x00;
712 vnet_classify_add_del_session (cm, table_index, match, next_acl,
713 session_idx, 0, 0, 0, 1);
714 /* reset the mask back to being a mask */
716 match[idx + 1] = 0xff;
727 intf_has_etype_whitelist (acl_main_t * am, u32 sw_if_index, int is_input)
730 ? am->input_etype_whitelist_by_sw_if_index
731 : am->output_etype_whitelist_by_sw_if_index;
732 return ((vec_len (v) > sw_if_index) && vec_elt (v, sw_if_index));
736 etype_whitelist_add_sessions (acl_main_t * am, u32 sw_if_index, int is_input,
737 u32 etype_table_index)
739 vnet_classify_main_t *cm = &vnet_classify_main;
741 ? am->input_etype_whitelist_by_sw_if_index
742 : am->output_etype_whitelist_by_sw_if_index;
743 u8 *match = ethertype_mask;
747 u16 *whitelist = vec_elt (v, sw_if_index);
748 u32 next = ~0; /* permit */
749 for (i = 0; i < vec_len (whitelist); i++)
752 match[12] = (whitelist[i] >> 8) & 0xff;
753 match[13] = whitelist[i] & 0xff;
755 || vnet_classify_add_del_session (cm, etype_table_index, match, next,
756 whitelist[i], 0, 0, 0, 1);
759 /* restore the mask */
766 acl_hook_l2_input_classify (acl_main_t * am, u32 sw_if_index)
768 vnet_classify_main_t *cm = &vnet_classify_main;
769 u32 ip4_table_index = ~0;
770 u32 ip6_table_index = ~0;
771 u32 dot1q_table_index = ~0;
772 u32 dot1ad_table_index = ~0;
773 u32 etype_table_index = ~0;
776 void *prevheap = clib_mem_set_heap (cm->vlib_main->heap_base);
778 /* in case there were previous tables attached */
779 acl_unhook_l2_input_classify (am, sw_if_index);
781 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
782 sizeof (ip4_5tuple_mask) - 1, ~0,
783 am->l2_input_classify_next_acl_ip4,
784 &ip4_table_index, 1);
789 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
790 sizeof (ip6_5tuple_mask) - 1, ~0,
791 am->l2_input_classify_next_acl_ip6,
792 &ip6_table_index, 1);
795 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
796 sizeof (ip4_5tuple_mask) - 1, ~0,
797 am->l2_input_classify_next_acl_ip4,
798 &ip4_table_index, 0);
802 if (intf_has_etype_whitelist (am, sw_if_index, 1))
804 acl_classify_add_del_table_tiny (cm, ethertype_mask, sizeof (ethertype_mask) - 1, ~0, 0, /* drop if no match */
805 &etype_table_index, 1);
806 etype_whitelist_add_sessions (am, sw_if_index, 1, etype_table_index);
810 acl_classify_add_del_table_tiny (cm, dot1ad_5tuple_mask,
811 sizeof (dot1ad_5tuple_mask) - 1,
812 etype_table_index, ~0,
813 &dot1ad_table_index, 1);
815 acl_classify_add_del_table_tiny (cm, dot1q_5tuple_mask,
816 sizeof (dot1q_5tuple_mask) - 1,
817 dot1ad_table_index, ~0,
818 &dot1q_table_index, 1);
821 acl_classify_add_del_table_tiny (cm, dot1ad_5tuple_mask,
822 sizeof (dot1ad_5tuple_mask) - 1, ~0,
823 ~0, &dot1ad_table_index, 0);
824 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
825 sizeof (ip6_5tuple_mask) - 1, ~0,
826 am->l2_input_classify_next_acl_ip6,
827 &ip6_table_index, 0);
828 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
829 sizeof (ip4_5tuple_mask) - 1, ~0,
830 am->l2_input_classify_next_acl_ip4,
831 &ip4_table_index, 0);
836 vnet_l2_input_classify_set_tables (sw_if_index, ip4_table_index,
837 ip6_table_index, dot1q_table_index);
841 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
842 sizeof (ip4_5tuple_mask) - 1, ~0,
843 am->l2_input_classify_next_acl_ip4,
844 &ip4_table_index, 0);
845 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
846 sizeof (ip6_5tuple_mask) - 1, ~0,
847 am->l2_input_classify_next_acl_ip6,
848 &ip6_table_index, 0);
849 acl_classify_add_del_table_tiny (cm, dot1q_5tuple_mask,
850 sizeof (dot1q_5tuple_mask) - 1, ~0,
851 ~0, &dot1q_table_index, 0);
852 acl_classify_add_del_table_tiny (cm, dot1ad_5tuple_mask,
853 sizeof (dot1ad_5tuple_mask) - 1, ~0,
854 ~0, &dot1ad_table_index, 0);
858 /* add sessions to vlan tables per ethernet_type */
859 acl_add_vlan_session (am, dot1q_table_index, 0, 0, 0);
860 acl_add_vlan_session (am, dot1q_table_index, 0, 0, 1);
861 acl_add_vlan_session (am, dot1ad_table_index, 0, 1, 0);
862 acl_add_vlan_session (am, dot1ad_table_index, 0, 1, 1);
864 am->acl_ip4_input_classify_table_by_sw_if_index[sw_if_index] =
866 am->acl_ip6_input_classify_table_by_sw_if_index[sw_if_index] =
868 am->acl_dot1q_input_classify_table_by_sw_if_index[sw_if_index] =
870 am->acl_dot1ad_input_classify_table_by_sw_if_index[sw_if_index] =
872 am->acl_dot1ad_input_classify_table_by_sw_if_index[sw_if_index] =
874 am->acl_etype_input_classify_table_by_sw_if_index[sw_if_index] =
877 vnet_l2_input_classify_enable_disable (sw_if_index, 1);
879 clib_mem_set_heap (prevheap);
884 acl_hook_l2_output_classify (acl_main_t * am, u32 sw_if_index)
886 vnet_classify_main_t *cm = &vnet_classify_main;
887 u32 ip4_table_index = ~0;
888 u32 ip6_table_index = ~0;
889 u32 dot1q_table_index = ~0;
890 u32 dot1ad_table_index = ~0;
891 u32 etype_table_index = ~0;
894 void *prevheap = clib_mem_set_heap (cm->vlib_main->heap_base);
896 /* in case there were previous tables attached */
897 acl_unhook_l2_output_classify (am, sw_if_index);
899 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
900 sizeof (ip4_5tuple_mask) - 1, ~0,
901 am->l2_output_classify_next_acl_ip4,
902 &ip4_table_index, 1);
906 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
907 sizeof (ip6_5tuple_mask) - 1, ~0,
908 am->l2_output_classify_next_acl_ip6,
909 &ip6_table_index, 1);
912 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
913 sizeof (ip4_5tuple_mask) - 1, ~0,
914 am->l2_output_classify_next_acl_ip4,
915 &ip4_table_index, 0);
919 if (intf_has_etype_whitelist (am, sw_if_index, 0))
921 acl_classify_add_del_table_tiny (cm, ethertype_mask, sizeof (ethertype_mask) - 1, ~0, 0, /* drop if no match */
922 &etype_table_index, 1);
923 etype_whitelist_add_sessions (am, sw_if_index, 0, etype_table_index);
928 acl_classify_add_del_table_tiny (cm, dot1ad_5tuple_mask,
929 sizeof (dot1ad_5tuple_mask) - 1,
930 etype_table_index, ~0,
931 &dot1ad_table_index, 1);
933 acl_classify_add_del_table_tiny (cm, dot1q_5tuple_mask,
934 sizeof (dot1q_5tuple_mask) - 1,
935 dot1ad_table_index, ~0,
936 &dot1q_table_index, 1);
939 acl_classify_add_del_table_tiny (cm, dot1ad_5tuple_mask,
940 sizeof (dot1ad_5tuple_mask) - 1, ~0,
941 ~0, &dot1ad_table_index, 0);
942 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
943 sizeof (ip6_5tuple_mask) - 1, ~0,
944 am->l2_output_classify_next_acl_ip6,
945 &ip6_table_index, 0);
946 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
947 sizeof (ip4_5tuple_mask) - 1, ~0,
948 am->l2_output_classify_next_acl_ip4,
949 &ip4_table_index, 0);
954 vnet_l2_output_classify_set_tables (sw_if_index, ip4_table_index,
955 ip6_table_index, dot1q_table_index);
958 ("ACL enabling on interface sw_if_index %d, setting tables to the following: ip4: %d ip6: %d\n",
959 sw_if_index, ip4_table_index, ip6_table_index);
962 acl_classify_add_del_table_tiny (cm, ip6_5tuple_mask,
963 sizeof (ip6_5tuple_mask) - 1, ~0,
964 am->l2_output_classify_next_acl_ip6,
965 &ip6_table_index, 0);
966 acl_classify_add_del_table_tiny (cm, ip4_5tuple_mask,
967 sizeof (ip4_5tuple_mask) - 1, ~0,
968 am->l2_output_classify_next_acl_ip4,
969 &ip4_table_index, 0);
970 acl_classify_add_del_table_tiny (cm, dot1q_5tuple_mask,
971 sizeof (dot1q_5tuple_mask) - 1, ~0,
972 ~0, &dot1q_table_index, 0);
973 acl_classify_add_del_table_tiny (cm, dot1ad_5tuple_mask,
974 sizeof (dot1ad_5tuple_mask) - 1, ~0,
975 ~0, &dot1ad_table_index, 0);
979 /* add sessions to vlan tables per ethernet_type */
980 acl_add_vlan_session (am, dot1q_table_index, 1, 0, 0);
981 acl_add_vlan_session (am, dot1q_table_index, 1, 0, 1);
982 acl_add_vlan_session (am, dot1ad_table_index, 1, 1, 0);
983 acl_add_vlan_session (am, dot1ad_table_index, 1, 1, 1);
985 am->acl_ip4_output_classify_table_by_sw_if_index[sw_if_index] =
987 am->acl_ip6_output_classify_table_by_sw_if_index[sw_if_index] =
989 am->acl_dot1q_output_classify_table_by_sw_if_index[sw_if_index] =
991 am->acl_dot1ad_output_classify_table_by_sw_if_index[sw_if_index] =
993 am->acl_etype_output_classify_table_by_sw_if_index[sw_if_index] =
996 vnet_l2_output_classify_enable_disable (sw_if_index, 1);
998 clib_mem_set_heap (prevheap);
1003 acl_interface_in_enable_disable (acl_main_t * am, u32 sw_if_index,
1008 /* Utterly wrong? */
1009 if (pool_is_free_index (am->vnet_main->interface_main.sw_interfaces,
1011 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
1013 acl_fa_enable_disable (sw_if_index, 1, enable_disable);
1017 rv = acl_hook_l2_input_classify (am, sw_if_index);
1021 rv = acl_unhook_l2_input_classify (am, sw_if_index);
1028 acl_interface_out_enable_disable (acl_main_t * am, u32 sw_if_index,
1033 /* Utterly wrong? */
1034 if (pool_is_free_index (am->vnet_main->interface_main.sw_interfaces,
1036 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
1038 acl_fa_enable_disable (sw_if_index, 0, enable_disable);
1042 rv = acl_hook_l2_output_classify (am, sw_if_index);
1046 rv = acl_unhook_l2_output_classify (am, sw_if_index);
1053 acl_is_not_defined (acl_main_t * am, u32 acl_list_index)
1055 return (pool_is_free_index (am->acls, acl_list_index));
1060 acl_interface_add_inout_acl (u32 sw_if_index, u8 is_input, u32 acl_list_index)
1062 acl_main_t *am = &acl_main;
1063 if (acl_is_not_defined (am, acl_list_index))
1065 /* ACL is not defined. Can not apply */
1066 return VNET_API_ERROR_NO_SUCH_ENTRY;
1068 void *oldheap = acl_set_heap (am);
1072 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
1074 u32 index = vec_search (am->input_acl_vec_by_sw_if_index[sw_if_index],
1076 if (index < vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]))
1079 ("ACL %d is already applied inbound on sw_if_index %d (index %d)",
1080 acl_list_index, sw_if_index, index);
1081 /* the entry is already there */
1082 clib_mem_set_heap (oldheap);
1083 return VNET_API_ERROR_ACL_IN_USE_INBOUND;
1085 /* if there was no ACL applied before, enable the ACL processing */
1086 if (vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]) == 0)
1088 acl_interface_in_enable_disable (am, sw_if_index, 1);
1090 vec_add (am->input_acl_vec_by_sw_if_index[sw_if_index], &acl_list_index,
1092 vec_validate (am->input_sw_if_index_vec_by_acl, acl_list_index);
1093 vec_add (am->input_sw_if_index_vec_by_acl[acl_list_index], &sw_if_index,
1098 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
1100 u32 index = vec_search (am->output_acl_vec_by_sw_if_index[sw_if_index],
1102 if (index < vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]))
1105 ("ACL %d is already applied outbound on sw_if_index %d (index %d)",
1106 acl_list_index, sw_if_index, index);
1107 /* the entry is already there */
1108 clib_mem_set_heap (oldheap);
1109 return VNET_API_ERROR_ACL_IN_USE_OUTBOUND;
1111 /* if there was no ACL applied before, enable the ACL processing */
1112 if (vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]) == 0)
1114 acl_interface_out_enable_disable (am, sw_if_index, 1);
1116 vec_add (am->output_acl_vec_by_sw_if_index[sw_if_index],
1117 &acl_list_index, 1);
1118 vec_validate (am->output_sw_if_index_vec_by_acl, acl_list_index);
1119 vec_add (am->output_sw_if_index_vec_by_acl[acl_list_index],
1122 clib_mem_set_heap (oldheap);
1128 acl_interface_del_inout_acl (u32 sw_if_index, u8 is_input, u32 acl_list_index)
1130 acl_main_t *am = &acl_main;
1132 int rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1133 void *oldheap = acl_set_heap (am);
1136 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
1137 for (i = 0; i < vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]);
1140 if (acl_list_index ==
1141 am->input_acl_vec_by_sw_if_index[sw_if_index][i])
1143 vec_del1 (am->input_acl_vec_by_sw_if_index[sw_if_index], i);
1149 if (acl_list_index < vec_len (am->input_sw_if_index_vec_by_acl))
1152 vec_search (am->input_sw_if_index_vec_by_acl[acl_list_index],
1155 vec_len (am->input_sw_if_index_vec_by_acl[acl_list_index]))
1157 hash_acl_unapply (am, sw_if_index, is_input, acl_list_index);
1158 vec_del1 (am->input_sw_if_index_vec_by_acl[acl_list_index],
1163 /* If there is no more ACLs applied on an interface, disable ACL processing */
1164 if (0 == vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]))
1166 acl_interface_in_enable_disable (am, sw_if_index, 0);
1171 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
1173 i < vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]); i++)
1175 if (acl_list_index ==
1176 am->output_acl_vec_by_sw_if_index[sw_if_index][i])
1178 vec_del1 (am->output_acl_vec_by_sw_if_index[sw_if_index], i);
1184 if (acl_list_index < vec_len (am->output_sw_if_index_vec_by_acl))
1187 vec_search (am->output_sw_if_index_vec_by_acl[acl_list_index],
1190 vec_len (am->output_sw_if_index_vec_by_acl[acl_list_index]))
1192 hash_acl_unapply (am, sw_if_index, is_input, acl_list_index);
1193 vec_del1 (am->output_sw_if_index_vec_by_acl[acl_list_index],
1198 /* If there is no more ACLs applied on an interface, disable ACL processing */
1199 if (0 == vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]))
1201 acl_interface_out_enable_disable (am, sw_if_index, 0);
1204 clib_mem_set_heap (oldheap);
1209 acl_interface_reset_inout_acls (u32 sw_if_index, u8 is_input)
1211 acl_main_t *am = &acl_main;
1213 void *oldheap = acl_set_heap (am);
1216 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
1217 if (vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]) > 0)
1219 acl_interface_in_enable_disable (am, sw_if_index, 0);
1222 for (i = vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]) - 1;
1225 u32 acl_list_index =
1226 am->input_acl_vec_by_sw_if_index[sw_if_index][i];
1227 hash_acl_unapply (am, sw_if_index, is_input, acl_list_index);
1228 if (acl_list_index < vec_len (am->input_sw_if_index_vec_by_acl))
1231 vec_search (am->input_sw_if_index_vec_by_acl[acl_list_index],
1234 vec_len (am->input_sw_if_index_vec_by_acl[acl_list_index]))
1236 vec_del1 (am->input_sw_if_index_vec_by_acl[acl_list_index],
1242 vec_reset_length (am->input_acl_vec_by_sw_if_index[sw_if_index]);
1246 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
1247 if (vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]) > 0)
1249 acl_interface_out_enable_disable (am, sw_if_index, 0);
1252 for (i = vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]) - 1;
1255 u32 acl_list_index =
1256 am->output_acl_vec_by_sw_if_index[sw_if_index][i];
1257 hash_acl_unapply (am, sw_if_index, is_input, acl_list_index);
1258 if (acl_list_index < vec_len (am->output_sw_if_index_vec_by_acl))
1261 vec_search (am->output_sw_if_index_vec_by_acl[acl_list_index],
1264 vec_len (am->output_sw_if_index_vec_by_acl[acl_list_index]))
1266 vec_del1 (am->output_sw_if_index_vec_by_acl[acl_list_index],
1272 vec_reset_length (am->output_acl_vec_by_sw_if_index[sw_if_index]);
1274 clib_mem_set_heap (oldheap);
1278 acl_interface_add_del_inout_acl (u32 sw_if_index, u8 is_add, u8 is_input,
1281 int rv = VNET_API_ERROR_NO_SUCH_ENTRY;
1282 acl_main_t *am = &acl_main;
1286 acl_interface_add_inout_acl (sw_if_index, is_input, acl_list_index);
1289 hash_acl_apply (am, sw_if_index, is_input, acl_list_index);
1294 hash_acl_unapply (am, sw_if_index, is_input, acl_list_index);
1296 acl_interface_del_inout_acl (sw_if_index, is_input, acl_list_index);
1302 acl_set_etype_whitelists (acl_main_t * am, u32 sw_if_index, u16 * vec_in,
1305 vec_validate (am->input_etype_whitelist_by_sw_if_index, sw_if_index);
1306 vec_validate (am->output_etype_whitelist_by_sw_if_index, sw_if_index);
1308 vec_free (am->input_etype_whitelist_by_sw_if_index[sw_if_index]);
1309 vec_free (am->output_etype_whitelist_by_sw_if_index[sw_if_index]);
1311 am->input_etype_whitelist_by_sw_if_index[sw_if_index] = vec_in;
1312 am->output_etype_whitelist_by_sw_if_index[sw_if_index] = vec_out;
1315 * if there are already inbound/outbound ACLs applied, toggle the
1316 * enable/disable - this will recreate the necessary tables.
1319 if (vec_len (am->input_acl_vec_by_sw_if_index) > sw_if_index)
1321 if (vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]) > 0)
1323 acl_interface_in_enable_disable (am, sw_if_index, 0);
1324 acl_interface_in_enable_disable (am, sw_if_index, 1);
1327 if (vec_len (am->output_acl_vec_by_sw_if_index) > sw_if_index)
1329 if (vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]) > 0)
1331 acl_interface_out_enable_disable (am, sw_if_index, 0);
1332 acl_interface_out_enable_disable (am, sw_if_index, 1);
1347 u32 arp_table_index;
1348 u32 dot1q_table_index;
1349 u32 dot1ad_table_index;
1351 u32 out_table_index;
1352 u32 out_arp_table_index;
1353 u32 out_dot1q_table_index;
1354 u32 out_dot1ad_table_index;
1355 } macip_match_type_t;
1358 macip_find_match_type (macip_match_type_t * mv, u8 * mac_mask, u8 prefix_len,
1364 for (i = 0; i < vec_len (mv); i++)
1366 if ((mv[i].prefix_len == prefix_len) && (mv[i].is_ipv6 == is_ipv6)
1367 && (0 == memcmp (mv[i].mac_mask, mac_mask, 6)))
1377 /* Get metric used to sort match types.
1378 The more specific and the more often seen - the bigger the metric */
1380 match_type_metric (macip_match_type_t * m)
1382 unsigned int mac_bits_set = 0;
1383 unsigned int mac_byte;
1385 for (i = 0; i < 6; i++)
1387 mac_byte = m->mac_mask[i];
1388 for (; mac_byte; mac_byte >>= 1)
1389 mac_bits_set += mac_byte & 1;
1392 * Attempt to place the more specific and the more used rules on top.
1393 * There are obvious caveat corner cases to this, but they do not
1394 * seem to be sensible in real world (e.g. specific IPv4 with wildcard MAC
1395 * going with a wildcard IPv4 with a specific MAC).
1397 return m->prefix_len + mac_bits_set + m->is_ipv6 + 10 * m->count;
1401 match_type_compare (macip_match_type_t * m1, macip_match_type_t * m2)
1403 /* Ascending sort based on the metric values */
1404 return match_type_metric (m1) - match_type_metric (m2);
1407 /* Get the offset of L3 source within ethernet packet */
1409 get_l3_src_offset (int is6)
1412 return (sizeof (ethernet_header_t) +
1413 offsetof (ip6_header_t, src_address));
1415 return (sizeof (ethernet_header_t) +
1416 offsetof (ip4_header_t, src_address));
1420 get_l3_dst_offset (int is6)
1423 return (sizeof (ethernet_header_t) +
1424 offsetof (ip6_header_t, dst_address));
1426 return (sizeof (ethernet_header_t) +
1427 offsetof (ip4_header_t, dst_address));
1431 * return if the is_permit value also requires to create the egress tables
1432 * For backwards compatibility, we keep the is_permit = 1 to only
1433 * create the ingress tables, and the new value of 3 will also
1434 * create the egress tables based on destination.
1437 macip_permit_also_egress (u8 is_permit)
1439 return (is_permit == 3);
1443 macip_create_classify_tables (acl_main_t * am, u32 macip_acl_index)
1445 macip_match_type_t *mvec = NULL;
1446 macip_match_type_t *mt;
1447 macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1449 u32 match_type_index;
1453 vnet_classify_main_t *cm = &vnet_classify_main;
1455 /* Count the number of different types of rules */
1456 for (i = 0; i < a->count; i++)
1460 macip_find_match_type (mvec, a->rules[i].src_mac_mask,
1461 a->rules[i].src_prefixlen,
1462 a->rules[i].is_ipv6)))
1464 match_type_index = vec_len (mvec);
1465 vec_validate (mvec, match_type_index);
1466 memcpy (mvec[match_type_index].mac_mask,
1467 a->rules[i].src_mac_mask, 6);
1468 mvec[match_type_index].prefix_len = a->rules[i].src_prefixlen;
1469 mvec[match_type_index].is_ipv6 = a->rules[i].is_ipv6;
1470 mvec[match_type_index].has_egress = 0;
1471 mvec[match_type_index].table_index = ~0;
1472 mvec[match_type_index].arp_table_index = ~0;
1473 mvec[match_type_index].dot1q_table_index = ~0;
1474 mvec[match_type_index].dot1ad_table_index = ~0;
1475 mvec[match_type_index].out_table_index = ~0;
1476 mvec[match_type_index].out_arp_table_index = ~0;
1477 mvec[match_type_index].out_dot1q_table_index = ~0;
1478 mvec[match_type_index].out_dot1ad_table_index = ~0;
1480 mvec[match_type_index].count++;
1481 mvec[match_type_index].has_egress |=
1482 macip_permit_also_egress (a->rules[i].is_permit);
1484 /* Put the most frequently used tables last in the list so we can create classifier tables in reverse order */
1485 vec_sort_with_function (mvec, match_type_compare);
1486 /* Create the classifier tables */
1488 out_last_table = ~0;
1489 /* First add ARP tables */
1490 vec_foreach (mt, mvec)
1493 int is6 = mt->is_ipv6;
1499 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
1500 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1501 | Destination Address |
1502 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1504 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
1506 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1507 | EtherType | Hardware Type |
1508 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1509 | Protocol Type | Hw addr len | Proto addr len|
1510 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1512 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
1513 | Sender Hardware Address |
1514 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1515 | Sender Protocol Address |
1516 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1517 | Target Hardware Address |
1518 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1519 | | TargetProtocolAddress |
1520 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1522 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1524 memset (mask, 0, sizeof (mask));
1525 /* source MAC address */
1526 memcpy (&mask[6], mt->mac_mask, 6);
1527 memset (&mask[12], 0xff, 2); /* ethernet protocol */
1528 /* sender hardware address within ARP */
1529 memcpy (&mask[14 + 8], mt->mac_mask, 6);
1530 /* sender protocol address within ARP */
1531 for (i = 0; i < (mt->prefix_len / 8); i++)
1532 mask[14 + 14 + i] = 0xff;
1533 if (mt->prefix_len % 8)
1534 mask[14 + 14 + (mt->prefix_len / 8)] =
1535 0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1537 mask_len = ((14 + 14 + ((mt->prefix_len + 7) / 8) +
1538 (sizeof (u32x4) - 1)) / sizeof (u32x4)) * sizeof (u32x4);
1539 acl_classify_add_del_table_small (cm, mask, mask_len, last_table,
1540 (~0 == last_table) ? 0 : ~0,
1541 &mt->arp_table_index, 1);
1542 last_table = mt->arp_table_index;
1545 /* egress ARP table */
1546 memset (mask, 0, sizeof (mask));
1547 // memcpy (&mask[0], mt->mac_mask, 6);
1548 memset (&mask[12], 0xff, 2); /* ethernet protocol */
1549 /* AYXX: FIXME here - can we tighten the ARP-related table more ? */
1550 /* mask captures just the destination and the ethertype */
1553 1)) / sizeof (u32x4)) * sizeof (u32x4);
1554 acl_classify_add_del_table_small (cm, mask, mask_len,
1556 (~0 == out_last_table) ? 0 : ~0,
1557 &mt->out_arp_table_index, 1);
1558 out_last_table = mt->out_arp_table_index;
1562 /* Now add IP[46] tables */
1563 vec_foreach (mt, mvec)
1566 int is6 = mt->is_ipv6;
1570 u32 *last_tag_table;
1571 u32 *out_last_tag_table;
1574 * create chained tables for VLAN (no-tags, dot1q and dot1ad) packets
1576 for (tags = 2; tags >= 0; tags--)
1578 memset (mask, 0, sizeof (mask));
1579 memcpy (&mask[6], mt->mac_mask, 6);
1580 l3_src_offs = tags * 4 + get_l3_src_offset (is6);
1585 memset (&mask[12], 0xff, 2); /* ethernet protocol */
1586 last_tag_table = &mt->table_index;
1589 memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1590 memset (&mask[16], 0xff, 2); /* ethernet protocol */
1591 last_tag_table = &mt->dot1q_table_index;
1594 memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1595 memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1596 memset (&mask[20], 0xff, 2); /* ethernet protocol */
1597 last_tag_table = &mt->dot1ad_table_index;
1600 for (i = 0; i < (mt->prefix_len / 8); i++)
1602 mask[l3_src_offs + i] = 0xff;
1604 if (mt->prefix_len % 8)
1606 mask[l3_src_offs + (mt->prefix_len / 8)] =
1607 0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1610 * Round-up the number of bytes needed to store the prefix,
1611 * and round up the number of vectors too
1613 mask_len = ((l3_src_offs + ((mt->prefix_len + 7) / 8) +
1614 (sizeof (u32x4) - 1)) / sizeof (u32x4)) * sizeof (u32x4);
1615 acl_classify_add_del_table_small (cm, mask, mask_len, last_table,
1616 (~0 == last_table) ? 0 : ~0,
1618 last_table = *last_tag_table;
1622 for (tags = 2; tags >= 0; tags--)
1624 memset (mask, 0, sizeof (mask));
1625 /* MAC destination */
1626 memcpy (&mask[0], mt->mac_mask, 6);
1627 l3_dst_offs = tags * 4 + get_l3_dst_offset (is6);
1632 memset (&mask[12], 0xff, 2); /* ethernet protocol */
1633 out_last_tag_table = &mt->out_table_index;
1636 memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1637 memset (&mask[16], 0xff, 2); /* ethernet protocol */
1638 out_last_tag_table = &mt->out_dot1q_table_index;
1641 memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1642 memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1643 memset (&mask[20], 0xff, 2); /* ethernet protocol */
1644 out_last_tag_table = &mt->out_dot1ad_table_index;
1647 for (i = 0; i < (mt->prefix_len / 8); i++)
1649 mask[l3_dst_offs + i] = 0xff;
1651 if (mt->prefix_len % 8)
1653 mask[l3_dst_offs + (mt->prefix_len / 8)] =
1654 0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1657 * Round-up the number of bytes needed to store the prefix,
1658 * and round up the number of vectors too
1660 mask_len = ((l3_dst_offs + ((mt->prefix_len + 7) / 8) +
1662 1)) / sizeof (u32x4)) * sizeof (u32x4);
1663 acl_classify_add_del_table_small (cm, mask, mask_len,
1665 (~0 == out_last_table) ? 0 : ~0,
1666 out_last_tag_table, 1);
1667 out_last_table = *out_last_tag_table;
1671 a->ip4_table_index = last_table;
1672 a->ip6_table_index = last_table;
1673 a->l2_table_index = last_table;
1675 a->out_ip4_table_index = out_last_table;
1676 a->out_ip6_table_index = out_last_table;
1677 a->out_l2_table_index = out_last_table;
1679 /* Populate the classifier tables with rules from the MACIP ACL */
1680 for (i = 0; i < a->count; i++)
1684 int is6 = a->rules[i].is_ipv6;
1691 macip_find_match_type (mvec, a->rules[i].src_mac_mask,
1692 a->rules[i].src_prefixlen,
1693 a->rules[i].is_ipv6);
1694 ASSERT (match_type_index != ~0);
1696 for (tags = 2; tags >= 0; tags--)
1698 memset (mask, 0, sizeof (mask));
1699 l3_src_offs = tags * 4 + get_l3_src_offset (is6);
1700 memcpy (&mask[6], a->rules[i].src_mac, 6);
1705 tag_table = mvec[match_type_index].table_index;
1709 tag_table = mvec[match_type_index].dot1q_table_index;
1715 tag_table = mvec[match_type_index].dot1ad_table_index;
1725 memcpy (&mask[l3_src_offs], &a->rules[i].src_ip_addr.ip6, 16);
1727 mask[eth + 1] = 0xdd;
1731 memcpy (&mask[l3_src_offs], &a->rules[i].src_ip_addr.ip4, 4);
1733 mask[eth + 1] = 0x00;
1736 /* add session to table mvec[match_type_index].table_index; */
1737 vnet_classify_add_del_session (cm, tag_table,
1738 mask, a->rules[i].is_permit ? ~0 : 0,
1739 i, 0, action, metadata, 1);
1740 memset (&mask[12], 0, sizeof (mask) - 12);
1743 /* add ARP table entry too */
1744 if (!is6 && (mvec[match_type_index].arp_table_index != ~0))
1746 memset (mask, 0, sizeof (mask));
1747 memcpy (&mask[6], a->rules[i].src_mac, 6);
1750 memcpy (&mask[14 + 8], a->rules[i].src_mac, 6);
1751 memcpy (&mask[14 + 14], &a->rules[i].src_ip_addr.ip4, 4);
1752 vnet_classify_add_del_session (cm,
1754 [match_type_index].arp_table_index,
1755 mask, a->rules[i].is_permit ? ~0 : 0,
1756 i, 0, action, metadata, 1);
1758 if (macip_permit_also_egress (a->rules[i].is_permit))
1760 /* Add the egress entry with destination set */
1761 for (tags = 2; tags >= 0; tags--)
1763 memset (mask, 0, sizeof (mask));
1764 l3_dst_offs = tags * 4 + get_l3_dst_offset (is6);
1765 /* src mac in the other direction becomes dst */
1766 memcpy (&mask[0], a->rules[i].src_mac, 6);
1771 tag_table = mvec[match_type_index].out_table_index;
1775 tag_table = mvec[match_type_index].out_dot1q_table_index;
1781 tag_table = mvec[match_type_index].out_dot1ad_table_index;
1791 memcpy (&mask[l3_dst_offs], &a->rules[i].src_ip_addr.ip6,
1794 mask[eth + 1] = 0xdd;
1798 memcpy (&mask[l3_dst_offs], &a->rules[i].src_ip_addr.ip4,
1801 mask[eth + 1] = 0x00;
1804 /* add session to table mvec[match_type_index].table_index; */
1805 vnet_classify_add_del_session (cm, tag_table,
1807 a->rules[i].is_permit ? ~0 : 0,
1808 i, 0, action, metadata, 1);
1809 // memset (&mask[12], 0, sizeof (mask) - 12);
1812 /* add ARP table entry too */
1813 if (!is6 && (mvec[match_type_index].out_arp_table_index != ~0))
1815 memset (mask, 0, sizeof (mask));
1816 memcpy (&mask[0], a->rules[i].src_mac, 6);
1819 vnet_classify_add_del_session (cm,
1821 [match_type_index].out_arp_table_index,
1823 a->rules[i].is_permit ? ~0 : 0,
1824 i, 0, action, metadata, 1);
1832 macip_destroy_classify_tables (acl_main_t * am, u32 macip_acl_index)
1834 vnet_classify_main_t *cm = &vnet_classify_main;
1835 macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1837 if (a->ip4_table_index != ~0)
1839 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1840 &a->ip4_table_index, 0);
1841 a->ip4_table_index = ~0;
1843 if (a->ip6_table_index != ~0)
1845 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1846 &a->ip6_table_index, 0);
1847 a->ip6_table_index = ~0;
1849 if (a->l2_table_index != ~0)
1851 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0, &a->l2_table_index,
1853 a->l2_table_index = ~0;
1858 macip_maybe_apply_unapply_classifier_tables (acl_main_t * am, u32 acl_index,
1864 macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, acl_index);
1866 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
1867 if (vec_elt (am->macip_acl_by_sw_if_index, i) == acl_index)
1869 rv0 = vnet_set_input_acl_intfc (am->vlib_main, i, a->ip4_table_index,
1870 a->ip6_table_index, a->l2_table_index,
1872 /* return the first unhappy outcome but make try to plough through. */
1875 vnet_set_output_acl_intfc (am->vlib_main, i, a->out_ip4_table_index,
1876 a->out_ip6_table_index,
1877 a->out_l2_table_index, is_apply);
1878 /* return the first unhappy outcome but make try to plough through. */
1885 macip_acl_add_list (u32 count, vl_api_macip_acl_rule_t rules[],
1886 u32 * acl_list_index, u8 * tag)
1888 acl_main_t *am = &acl_main;
1889 macip_acl_list_t *a;
1890 macip_acl_rule_t *r;
1891 macip_acl_rule_t *acl_new_rules = 0;
1895 if (*acl_list_index != ~0)
1897 /* They supplied some number, let's see if this MACIP ACL exists */
1898 if (pool_is_free_index (am->macip_acls, *acl_list_index))
1900 /* tried to replace a non-existent ACL, no point doing anything */
1902 ("acl-plugin-error: Trying to replace nonexistent MACIP ACL %d (tag %s)",
1903 *acl_list_index, tag);
1904 return VNET_API_ERROR_NO_SUCH_ENTRY;
1911 ("acl-plugin-warning: Trying to create empty MACIP ACL (tag %s)",
1914 /* if replacing the ACL, unapply the classifier tables first - they will be gone.. */
1915 if (~0 != *acl_list_index)
1916 rv = macip_maybe_apply_unapply_classifier_tables (am, *acl_list_index, 0);
1917 void *oldheap = acl_set_heap (am);
1918 /* Create and populate the rules */
1920 vec_validate (acl_new_rules, count - 1);
1922 for (i = 0; i < count; i++)
1924 r = &acl_new_rules[i];
1925 r->is_permit = rules[i].is_permit;
1926 r->is_ipv6 = rules[i].is_ipv6;
1927 memcpy (&r->src_mac, rules[i].src_mac, 6);
1928 memcpy (&r->src_mac_mask, rules[i].src_mac_mask, 6);
1929 if (rules[i].is_ipv6)
1930 memcpy (&r->src_ip_addr.ip6, rules[i].src_ip_addr, 16);
1932 memcpy (&r->src_ip_addr.ip4, rules[i].src_ip_addr, 4);
1933 r->src_prefixlen = rules[i].src_ip_prefix_len;
1936 if (~0 == *acl_list_index)
1939 pool_get_aligned (am->macip_acls, a, CLIB_CACHE_LINE_BYTES);
1940 memset (a, 0, sizeof (*a));
1941 /* Will return the newly allocated ACL index */
1942 *acl_list_index = a - am->macip_acls;
1946 a = pool_elt_at_index (am->macip_acls, *acl_list_index);
1949 vec_free (a->rules);
1951 macip_destroy_classify_tables (am, *acl_list_index);
1954 a->rules = acl_new_rules;
1956 memcpy (a->tag, tag, sizeof (a->tag));
1958 /* Create and populate the classifer tables */
1959 macip_create_classify_tables (am, *acl_list_index);
1960 clib_mem_set_heap (oldheap);
1961 /* If the ACL was already applied somewhere, reapply the newly created tables */
1963 || macip_maybe_apply_unapply_classifier_tables (am, *acl_list_index, 1);
1968 /* No check for validity of sw_if_index - the callers were supposed to validate */
1971 macip_acl_interface_del_acl (acl_main_t * am, u32 sw_if_index)
1974 u32 macip_acl_index;
1975 macip_acl_list_t *a;
1976 void *oldheap = acl_set_heap (am);
1977 vec_validate_init_empty (am->macip_acl_by_sw_if_index, sw_if_index, ~0);
1978 clib_mem_set_heap (oldheap);
1979 macip_acl_index = am->macip_acl_by_sw_if_index[sw_if_index];
1980 /* No point in deleting MACIP ACL which is not applied */
1981 if (~0 == macip_acl_index)
1982 return VNET_API_ERROR_NO_SUCH_ENTRY;
1983 a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1984 /* remove the classifier tables off the interface L2 ACL */
1986 vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
1987 a->ip6_table_index, a->l2_table_index, 0);
1989 vnet_set_output_acl_intfc (am->vlib_main, sw_if_index,
1990 a->out_ip4_table_index, a->out_ip6_table_index,
1991 a->out_l2_table_index, 0);
1992 /* Unset the MACIP ACL index */
1993 am->macip_acl_by_sw_if_index[sw_if_index] = ~0;
1997 /* No check for validity of sw_if_index - the callers were supposed to validate */
2000 macip_acl_interface_add_acl (acl_main_t * am, u32 sw_if_index,
2001 u32 macip_acl_index)
2003 macip_acl_list_t *a;
2005 if (pool_is_free_index (am->macip_acls, macip_acl_index))
2007 return VNET_API_ERROR_NO_SUCH_ENTRY;
2009 void *oldheap = acl_set_heap (am);
2010 a = pool_elt_at_index (am->macip_acls, macip_acl_index);
2011 vec_validate_init_empty (am->macip_acl_by_sw_if_index, sw_if_index, ~0);
2012 clib_mem_set_heap (oldheap);
2013 /* If there already a MACIP ACL applied, unapply it */
2014 if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
2015 macip_acl_interface_del_acl (am, sw_if_index);
2016 am->macip_acl_by_sw_if_index[sw_if_index] = macip_acl_index;
2018 /* Apply the classifier tables for L2 ACLs */
2020 vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
2021 a->ip6_table_index, a->l2_table_index, 1);
2023 vnet_set_output_acl_intfc (am->vlib_main, sw_if_index,
2024 a->out_ip4_table_index, a->out_ip6_table_index,
2025 a->out_l2_table_index, 1);
2030 macip_acl_del_list (u32 acl_list_index)
2032 acl_main_t *am = &acl_main;
2033 macip_acl_list_t *a;
2035 if (pool_is_free_index (am->macip_acls, acl_list_index))
2037 return VNET_API_ERROR_NO_SUCH_ENTRY;
2040 /* delete any references to the ACL */
2041 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
2043 if (am->macip_acl_by_sw_if_index[i] == acl_list_index)
2045 macip_acl_interface_del_acl (am, i);
2049 void *oldheap = acl_set_heap (am);
2050 /* Now that classifier tables are detached, clean them up */
2051 macip_destroy_classify_tables (am, acl_list_index);
2053 /* now we can delete the ACL itself */
2054 a = pool_elt_at_index (am->macip_acls, acl_list_index);
2057 vec_free (a->rules);
2059 pool_put (am->macip_acls, a);
2060 clib_mem_set_heap (oldheap);
2066 macip_acl_interface_add_del_acl (u32 sw_if_index, u8 is_add,
2069 acl_main_t *am = &acl_main;
2073 rv = macip_acl_interface_add_acl (am, sw_if_index, acl_list_index);
2077 rv = macip_acl_interface_del_acl (am, sw_if_index);
2083 * If the client does not allocate enough memory for a variable-length
2084 * message, and then proceed to use it as if the full memory allocated,
2085 * absent the check we happily consume that on the VPP side, and go
2086 * along as if nothing happened. However, the resulting
2087 * effects range from just garbage in the API decode
2088 * (because the decoder snoops too far), to potential memory
2091 * This verifies that the actual length of the message is
2092 * at least expected_len, and complains loudly if it is not.
2094 * A failing check here is 100% a software bug on the API user side,
2095 * so we might as well yell.
2099 verify_message_len (void *mp, u32 expected_len, char *where)
2101 u32 supplied_len = vl_msg_api_get_msg_length (mp);
2102 if (supplied_len < expected_len)
2104 clib_warning ("%s: Supplied message length %d is less than expected %d",
2105 where, supplied_len, expected_len);
2114 /* API message handler */
2116 vl_api_acl_add_replace_t_handler (vl_api_acl_add_replace_t * mp)
2118 vl_api_acl_add_replace_reply_t *rmp;
2119 acl_main_t *am = &acl_main;
2121 u32 acl_list_index = ntohl (mp->acl_index);
2122 u32 acl_count = ntohl (mp->count);
2123 u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2125 if (verify_message_len (mp, expected_len, "acl_add_replace"))
2127 rv = acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2131 rv = VNET_API_ERROR_INVALID_VALUE;
2135 REPLY_MACRO2(VL_API_ACL_ADD_REPLACE_REPLY,
2137 rmp->acl_index = htonl(acl_list_index);
2143 vl_api_acl_del_t_handler (vl_api_acl_del_t * mp)
2145 acl_main_t *am = &acl_main;
2146 vl_api_acl_del_reply_t *rmp;
2149 rv = acl_del_list (ntohl (mp->acl_index));
2151 REPLY_MACRO (VL_API_ACL_DEL_REPLY);
2155 vl_api_acl_interface_add_del_t_handler (vl_api_acl_interface_add_del_t * mp)
2157 acl_main_t *am = &acl_main;
2158 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2159 u32 sw_if_index = ntohl (mp->sw_if_index);
2160 vl_api_acl_interface_add_del_reply_t *rmp;
2163 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2164 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2167 acl_interface_add_del_inout_acl (sw_if_index, mp->is_add,
2168 mp->is_input, ntohl (mp->acl_index));
2170 REPLY_MACRO (VL_API_ACL_INTERFACE_ADD_DEL_REPLY);
2174 vl_api_acl_interface_set_acl_list_t_handler
2175 (vl_api_acl_interface_set_acl_list_t * mp)
2177 acl_main_t *am = &acl_main;
2178 vl_api_acl_interface_set_acl_list_reply_t *rmp;
2181 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2182 u32 sw_if_index = ntohl (mp->sw_if_index);
2184 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2185 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2188 acl_interface_reset_inout_acls (sw_if_index, 0);
2189 acl_interface_reset_inout_acls (sw_if_index, 1);
2191 for (i = 0; i < mp->count; i++)
2193 if (acl_is_not_defined (am, ntohl (mp->acls[i])))
2195 /* ACL does not exist, so we can not apply it */
2196 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2201 for (i = 0; i < mp->count; i++)
2203 acl_interface_add_del_inout_acl (sw_if_index, 1,
2205 ntohl (mp->acls[i]));
2210 REPLY_MACRO (VL_API_ACL_INTERFACE_SET_ACL_LIST_REPLY);
2214 copy_acl_rule_to_api_rule (vl_api_acl_rule_t * api_rule, acl_rule_t * r)
2216 api_rule->is_permit = r->is_permit;
2217 api_rule->is_ipv6 = r->is_ipv6;
2220 memcpy (api_rule->src_ip_addr, &r->src, sizeof (r->src));
2221 memcpy (api_rule->dst_ip_addr, &r->dst, sizeof (r->dst));
2225 memcpy (api_rule->src_ip_addr, &r->src.ip4, sizeof (r->src.ip4));
2226 memcpy (api_rule->dst_ip_addr, &r->dst.ip4, sizeof (r->dst.ip4));
2228 api_rule->src_ip_prefix_len = r->src_prefixlen;
2229 api_rule->dst_ip_prefix_len = r->dst_prefixlen;
2230 api_rule->proto = r->proto;
2231 api_rule->srcport_or_icmptype_first = htons (r->src_port_or_type_first);
2232 api_rule->srcport_or_icmptype_last = htons (r->src_port_or_type_last);
2233 api_rule->dstport_or_icmpcode_first = htons (r->dst_port_or_code_first);
2234 api_rule->dstport_or_icmpcode_last = htons (r->dst_port_or_code_last);
2235 api_rule->tcp_flags_mask = r->tcp_flags_mask;
2236 api_rule->tcp_flags_value = r->tcp_flags_value;
2240 send_acl_details (acl_main_t * am, vl_api_registration_t * reg,
2241 acl_list_t * acl, u32 context)
2243 vl_api_acl_details_t *mp;
2244 vl_api_acl_rule_t *rules;
2246 int msg_size = sizeof (*mp) + sizeof (mp->r[0]) * acl->count;
2247 void *oldheap = acl_set_heap (am);
2249 mp = vl_msg_api_alloc (msg_size);
2250 memset (mp, 0, msg_size);
2251 mp->_vl_msg_id = ntohs (VL_API_ACL_DETAILS + am->msg_id_base);
2253 /* fill in the message */
2254 mp->context = context;
2255 mp->count = htonl (acl->count);
2256 mp->acl_index = htonl (acl - am->acls);
2257 memcpy (mp->tag, acl->tag, sizeof (mp->tag));
2258 // clib_memcpy (mp->r, acl->rules, acl->count * sizeof(acl->rules[0]));
2260 for (i = 0; i < acl->count; i++)
2262 copy_acl_rule_to_api_rule (&rules[i], &acl->rules[i]);
2265 clib_mem_set_heap (oldheap);
2266 vl_api_send_msg (reg, (u8 *) mp);
2271 vl_api_acl_dump_t_handler (vl_api_acl_dump_t * mp)
2273 acl_main_t *am = &acl_main;
2277 vl_api_registration_t *reg;
2279 reg = vl_api_client_index_to_registration (mp->client_index);
2283 if (mp->acl_index == ~0)
2286 /* Just dump all ACLs */
2287 pool_foreach (acl, am->acls,
2289 send_acl_details(am, reg, acl, mp->context);
2295 acl_index = ntohl (mp->acl_index);
2296 if (!pool_is_free_index (am->acls, acl_index))
2298 acl = pool_elt_at_index (am->acls, acl_index);
2299 send_acl_details (am, reg, acl, mp->context);
2305 /* FIXME API: should we signal an error here at all ? */
2311 send_acl_interface_list_details (acl_main_t * am,
2312 vl_api_registration_t * reg,
2313 u32 sw_if_index, u32 context)
2315 vl_api_acl_interface_list_details_t *mp;
2321 void *oldheap = acl_set_heap (am);
2323 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
2324 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
2326 n_input = vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]);
2327 n_output = vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]);
2328 count = n_input + n_output;
2330 msg_size = sizeof (*mp);
2331 msg_size += sizeof (mp->acls[0]) * count;
2333 mp = vl_msg_api_alloc (msg_size);
2334 memset (mp, 0, msg_size);
2336 ntohs (VL_API_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
2338 /* fill in the message */
2339 mp->context = context;
2340 mp->sw_if_index = htonl (sw_if_index);
2342 mp->n_input = n_input;
2343 for (i = 0; i < n_input; i++)
2345 mp->acls[i] = htonl (am->input_acl_vec_by_sw_if_index[sw_if_index][i]);
2347 for (i = 0; i < n_output; i++)
2349 mp->acls[n_input + i] =
2350 htonl (am->output_acl_vec_by_sw_if_index[sw_if_index][i]);
2352 clib_mem_set_heap (oldheap);
2353 vl_api_send_msg (reg, (u8 *) mp);
2357 vl_api_acl_interface_list_dump_t_handler (vl_api_acl_interface_list_dump_t *
2360 acl_main_t *am = &acl_main;
2361 vnet_sw_interface_t *swif;
2362 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2365 vl_api_registration_t *reg;
2367 reg = vl_api_client_index_to_registration (mp->client_index);
2371 if (mp->sw_if_index == ~0)
2374 pool_foreach (swif, im->sw_interfaces,
2376 send_acl_interface_list_details(am, reg, swif->sw_if_index, mp->context);
2382 sw_if_index = ntohl (mp->sw_if_index);
2383 if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
2384 send_acl_interface_list_details (am, reg, sw_if_index, mp->context);
2388 /* MACIP ACL API handlers */
2391 vl_api_macip_acl_add_t_handler (vl_api_macip_acl_add_t * mp)
2393 vl_api_macip_acl_add_reply_t *rmp;
2394 acl_main_t *am = &acl_main;
2396 u32 acl_list_index = ~0;
2397 u32 acl_count = ntohl (mp->count);
2398 u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2400 if (verify_message_len (mp, expected_len, "macip_acl_add"))
2402 rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2406 rv = VNET_API_ERROR_INVALID_VALUE;
2410 REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLY,
2412 rmp->acl_index = htonl(acl_list_index);
2418 vl_api_macip_acl_add_replace_t_handler (vl_api_macip_acl_add_replace_t * mp)
2420 vl_api_macip_acl_add_replace_reply_t *rmp;
2421 acl_main_t *am = &acl_main;
2423 u32 acl_list_index = ntohl (mp->acl_index);
2424 u32 acl_count = ntohl (mp->count);
2425 u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2427 if (verify_message_len (mp, expected_len, "macip_acl_add_replace"))
2429 rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2433 rv = VNET_API_ERROR_INVALID_VALUE;
2437 REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLACE_REPLY,
2439 rmp->acl_index = htonl(acl_list_index);
2445 vl_api_macip_acl_del_t_handler (vl_api_macip_acl_del_t * mp)
2447 acl_main_t *am = &acl_main;
2448 vl_api_macip_acl_del_reply_t *rmp;
2451 rv = macip_acl_del_list (ntohl (mp->acl_index));
2453 REPLY_MACRO (VL_API_MACIP_ACL_DEL_REPLY);
2457 vl_api_macip_acl_interface_add_del_t_handler
2458 (vl_api_macip_acl_interface_add_del_t * mp)
2460 acl_main_t *am = &acl_main;
2461 vl_api_macip_acl_interface_add_del_reply_t *rmp;
2463 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2464 u32 sw_if_index = ntohl (mp->sw_if_index);
2466 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2467 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2470 macip_acl_interface_add_del_acl (ntohl (mp->sw_if_index), mp->is_add,
2471 ntohl (mp->acl_index));
2473 REPLY_MACRO (VL_API_MACIP_ACL_INTERFACE_ADD_DEL_REPLY);
2477 send_macip_acl_details (acl_main_t * am, vl_api_registration_t * reg,
2478 macip_acl_list_t * acl, u32 context)
2480 vl_api_macip_acl_details_t *mp;
2481 vl_api_macip_acl_rule_t *rules;
2482 macip_acl_rule_t *r;
2484 int msg_size = sizeof (*mp) + (acl ? sizeof (mp->r[0]) * acl->count : 0);
2486 mp = vl_msg_api_alloc (msg_size);
2487 memset (mp, 0, msg_size);
2488 mp->_vl_msg_id = ntohs (VL_API_MACIP_ACL_DETAILS + am->msg_id_base);
2490 /* fill in the message */
2491 mp->context = context;
2494 memcpy (mp->tag, acl->tag, sizeof (mp->tag));
2495 mp->count = htonl (acl->count);
2496 mp->acl_index = htonl (acl - am->macip_acls);
2498 for (i = 0; i < acl->count; i++)
2501 rules[i].is_permit = r->is_permit;
2502 rules[i].is_ipv6 = r->is_ipv6;
2503 memcpy (rules[i].src_mac, &r->src_mac, sizeof (r->src_mac));
2504 memcpy (rules[i].src_mac_mask, &r->src_mac_mask,
2505 sizeof (r->src_mac_mask));
2507 memcpy (rules[i].src_ip_addr, &r->src_ip_addr.ip6,
2508 sizeof (r->src_ip_addr.ip6));
2510 memcpy (rules[i].src_ip_addr, &r->src_ip_addr.ip4,
2511 sizeof (r->src_ip_addr.ip4));
2512 rules[i].src_ip_prefix_len = r->src_prefixlen;
2517 /* No martini, no party - no ACL applied to this interface. */
2522 vl_api_send_msg (reg, (u8 *) mp);
2527 vl_api_macip_acl_dump_t_handler (vl_api_macip_acl_dump_t * mp)
2529 acl_main_t *am = &acl_main;
2530 macip_acl_list_t *acl;
2532 vl_api_registration_t *reg;
2534 reg = vl_api_client_index_to_registration (mp->client_index);
2538 if (mp->acl_index == ~0)
2540 /* Just dump all ACLs for now, with sw_if_index = ~0 */
2541 pool_foreach (acl, am->macip_acls, (
2543 send_macip_acl_details (am, reg,
2552 u32 acl_index = ntohl (mp->acl_index);
2553 if (!pool_is_free_index (am->macip_acls, acl_index))
2555 acl = pool_elt_at_index (am->macip_acls, acl_index);
2556 send_macip_acl_details (am, reg, acl, mp->context);
2562 vl_api_macip_acl_interface_get_t_handler (vl_api_macip_acl_interface_get_t *
2565 acl_main_t *am = &acl_main;
2566 vl_api_macip_acl_interface_get_reply_t *rmp;
2567 u32 count = vec_len (am->macip_acl_by_sw_if_index);
2568 int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]) * count;
2569 vl_api_registration_t *reg;
2572 reg = vl_api_client_index_to_registration (mp->client_index);
2576 rmp = vl_msg_api_alloc (msg_size);
2577 memset (rmp, 0, msg_size);
2579 ntohs (VL_API_MACIP_ACL_INTERFACE_GET_REPLY + am->msg_id_base);
2580 rmp->context = mp->context;
2581 rmp->count = htonl (count);
2582 for (i = 0; i < count; i++)
2584 rmp->acls[i] = htonl (am->macip_acl_by_sw_if_index[i]);
2587 vl_api_send_msg (reg, (u8 *) rmp);
2591 send_macip_acl_interface_list_details (acl_main_t * am,
2592 vl_api_registration_t * reg,
2594 u32 acl_index, u32 context)
2596 vl_api_macip_acl_interface_list_details_t *rmp;
2597 /* at this time there is only ever 1 mac ip acl per interface */
2598 int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]);
2600 rmp = vl_msg_api_alloc (msg_size);
2601 memset (rmp, 0, msg_size);
2603 ntohs (VL_API_MACIP_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
2605 /* fill in the message */
2606 rmp->context = context;
2608 rmp->sw_if_index = htonl (sw_if_index);
2609 rmp->acls[0] = htonl (acl_index);
2611 vl_api_send_msg (reg, (u8 *) rmp);
2615 vl_api_macip_acl_interface_list_dump_t_handler
2616 (vl_api_macip_acl_interface_list_dump_t * mp)
2618 vl_api_registration_t *reg;
2619 acl_main_t *am = &acl_main;
2620 u32 sw_if_index = ntohl (mp->sw_if_index);
2622 reg = vl_api_client_index_to_registration (mp->client_index);
2626 if (sw_if_index == ~0)
2628 vec_foreach_index (sw_if_index, am->macip_acl_by_sw_if_index)
2630 if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
2632 send_macip_acl_interface_list_details (am, reg, sw_if_index,
2633 am->macip_acl_by_sw_if_index
2641 if (vec_len (am->macip_acl_by_sw_if_index) > sw_if_index)
2643 send_macip_acl_interface_list_details (am, reg, sw_if_index,
2644 am->macip_acl_by_sw_if_index
2645 [sw_if_index], mp->context);
2651 vl_api_acl_interface_set_etype_whitelist_t_handler
2652 (vl_api_acl_interface_set_etype_whitelist_t * mp)
2654 acl_main_t *am = &acl_main;
2655 vl_api_acl_interface_set_etype_whitelist_reply_t *rmp;
2658 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2659 u32 sw_if_index = ntohl (mp->sw_if_index);
2660 u16 *vec_in = 0, *vec_out = 0;
2661 void *oldheap = acl_set_heap (am);
2663 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2664 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2667 for (i = 0; i < mp->count; i++)
2669 if (i < mp->n_input)
2670 vec_add1 (vec_in, ntohs (mp->whitelist[i]));
2672 vec_add1 (vec_out, ntohs (mp->whitelist[i]));
2674 rv = acl_set_etype_whitelists (am, sw_if_index, vec_in, vec_out);
2677 clib_mem_set_heap (oldheap);
2678 REPLY_MACRO (VL_API_ACL_INTERFACE_SET_ETYPE_WHITELIST_REPLY);
2682 /* Set up the API message handling tables */
2683 static clib_error_t *
2684 acl_plugin_api_hookup (vlib_main_t * vm)
2686 acl_main_t *am = &acl_main;
2688 vl_msg_api_set_handlers((VL_API_##N + am->msg_id_base), \
2690 vl_api_##n##_t_handler, \
2692 vl_api_##n##_t_endian, \
2693 vl_api_##n##_t_print, \
2694 sizeof(vl_api_##n##_t), 1);
2695 foreach_acl_plugin_api_msg;
2701 #define vl_msg_name_crc_list
2702 #include <acl/acl_all_api_h.h>
2703 #undef vl_msg_name_crc_list
2706 setup_message_id_table (acl_main_t * am, api_main_t * apim)
2708 #define _(id,n,crc) \
2709 vl_msg_api_add_msg_name_crc (apim, #n "_" #crc, id + am->msg_id_base);
2710 foreach_vl_msg_name_crc_acl;
2715 acl_setup_fa_nodes (void)
2717 vlib_main_t *vm = vlib_get_main ();
2718 acl_main_t *am = &acl_main;
2719 vlib_node_t *n, *n4, *n6;
2721 n = vlib_get_node_by_name (vm, (u8 *) "l2-input-classify");
2722 n4 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-in-ip4-l2");
2723 n6 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-in-ip6-l2");
2726 am->l2_input_classify_next_acl_ip4 =
2727 vlib_node_add_next_with_slot (vm, n->index, n4->index, ~0);
2728 am->l2_input_classify_next_acl_ip6 =
2729 vlib_node_add_next_with_slot (vm, n->index, n6->index, ~0);
2731 feat_bitmap_init_next_nodes (vm, n4->index, L2INPUT_N_FEAT,
2732 l2input_get_feat_names (),
2733 am->fa_acl_in_ip4_l2_node_feat_next_node_index);
2735 feat_bitmap_init_next_nodes (vm, n6->index, L2INPUT_N_FEAT,
2736 l2input_get_feat_names (),
2737 am->fa_acl_in_ip6_l2_node_feat_next_node_index);
2740 n = vlib_get_node_by_name (vm, (u8 *) "l2-output-classify");
2741 n4 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-out-ip4-l2");
2742 n6 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-out-ip6-l2");
2744 am->l2_output_classify_next_acl_ip4 =
2745 vlib_node_add_next_with_slot (vm, n->index, n4->index, ~0);
2746 am->l2_output_classify_next_acl_ip6 =
2747 vlib_node_add_next_with_slot (vm, n->index, n6->index, ~0);
2749 feat_bitmap_init_next_nodes (vm, n4->index, L2OUTPUT_N_FEAT,
2750 l2output_get_feat_names (),
2751 am->fa_acl_out_ip4_l2_node_feat_next_node_index);
2753 feat_bitmap_init_next_nodes (vm, n6->index, L2OUTPUT_N_FEAT,
2754 l2output_get_feat_names (),
2755 am->fa_acl_out_ip6_l2_node_feat_next_node_index);
2759 acl_set_timeout_sec (int timeout_type, u32 value)
2761 acl_main_t *am = &acl_main;
2762 clib_time_t *ct = &am->vlib_main->clib_time;
2764 if (timeout_type < ACL_N_TIMEOUTS)
2766 am->session_timeout_sec[timeout_type] = value;
2770 clib_warning ("Unknown timeout type %d", timeout_type);
2773 am->session_timeout[timeout_type] =
2774 (u64) (((f64) value) / ct->seconds_per_clock);
2778 acl_set_session_max_entries (u32 value)
2780 acl_main_t *am = &acl_main;
2781 am->fa_conn_table_max_entries = value;
2785 acl_set_skip_ipv6_eh (u32 eh, u32 value)
2787 acl_main_t *am = &acl_main;
2789 if ((eh < 256) && (value < 2))
2791 am->fa_ipv6_known_eh_bitmap =
2792 clib_bitmap_set (am->fa_ipv6_known_eh_bitmap, eh, value);
2800 static clib_error_t *
2801 acl_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
2803 acl_main_t *am = &acl_main;
2804 if (0 == am->acl_mheap)
2806 /* ACL heap is not initialized, so definitely nothing to do. */
2811 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
2812 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX,
2814 /* also unapply any ACLs in case the users did not do so. */
2815 macip_acl_interface_del_acl (am, sw_if_index);
2816 acl_interface_reset_inout_acls (sw_if_index, 0);
2817 acl_interface_reset_inout_acls (sw_if_index, 1);
2822 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (acl_sw_interface_add_del);
2826 static clib_error_t *
2827 acl_set_aclplugin_fn (vlib_main_t * vm,
2828 unformat_input_t * input, vlib_cli_command_t * cmd)
2830 clib_error_t *error = 0;
2834 uword memory_size = 0;
2835 acl_main_t *am = &acl_main;
2837 if (unformat (input, "skip-ipv6-extension-header %u %u", &eh_val, &val))
2839 if (!acl_set_skip_ipv6_eh (eh_val, val))
2841 error = clib_error_return (0, "expecting eh=0..255, value=0..1");
2845 if (unformat (input, "use-hash-acl-matching %u", &val))
2847 am->use_hash_acl_matching = (val != 0);
2850 if (unformat (input, "l4-match-nonfirst-fragment %u", &val))
2852 am->l4_match_nonfirst_fragment = (val != 0);
2855 if (unformat (input, "heap"))
2857 if (unformat (input, "main"))
2859 if (unformat (input, "validate %u", &val))
2860 acl_plugin_acl_set_validate_heap (am, val);
2861 else if (unformat (input, "trace %u", &val))
2862 acl_plugin_acl_set_trace_heap (am, val);
2865 else if (unformat (input, "hash"))
2867 if (unformat (input, "validate %u", &val))
2868 acl_plugin_hash_acl_set_validate_heap (am, val);
2869 else if (unformat (input, "trace %u", &val))
2870 acl_plugin_hash_acl_set_trace_heap (am, val);
2875 if (unformat (input, "session"))
2877 if (unformat (input, "table"))
2879 /* The commands here are for tuning/testing. No user-serviceable parts inside */
2880 if (unformat (input, "max-entries"))
2882 if (!unformat (input, "%u", &val))
2884 error = clib_error_return (0,
2885 "expecting maximum number of entries, got `%U`",
2886 format_unformat_error, input);
2891 acl_set_session_max_entries (val);
2895 if (unformat (input, "hash-table-buckets"))
2897 if (!unformat (input, "%u", &val))
2899 error = clib_error_return (0,
2900 "expecting maximum number of hash table buckets, got `%U`",
2901 format_unformat_error, input);
2906 am->fa_conn_table_hash_num_buckets = val;
2910 if (unformat (input, "hash-table-memory"))
2912 if (!unformat (input, "%U", unformat_memory_size, &memory_size))
2914 error = clib_error_return (0,
2915 "expecting maximum amount of hash table memory, got `%U`",
2916 format_unformat_error, input);
2921 am->fa_conn_table_hash_memory_size = memory_size;
2925 if (unformat (input, "event-trace"))
2927 if (!unformat (input, "%u", &val))
2929 error = clib_error_return (0,
2930 "expecting trace level, got `%U`",
2931 format_unformat_error, input);
2936 am->trace_sessions = val;
2942 if (unformat (input, "timeout"))
2944 if (unformat (input, "udp"))
2946 if (unformat (input, "idle"))
2948 if (!unformat (input, "%u", &timeout))
2950 error = clib_error_return (0,
2951 "expecting timeout value in seconds, got `%U`",
2952 format_unformat_error,
2958 acl_set_timeout_sec (ACL_TIMEOUT_UDP_IDLE, timeout);
2963 if (unformat (input, "tcp"))
2965 if (unformat (input, "idle"))
2967 if (!unformat (input, "%u", &timeout))
2969 error = clib_error_return (0,
2970 "expecting timeout value in seconds, got `%U`",
2971 format_unformat_error,
2977 acl_set_timeout_sec (ACL_TIMEOUT_TCP_IDLE, timeout);
2981 if (unformat (input, "transient"))
2983 if (!unformat (input, "%u", &timeout))
2985 error = clib_error_return (0,
2986 "expecting timeout value in seconds, got `%U`",
2987 format_unformat_error,
2993 acl_set_timeout_sec (ACL_TIMEOUT_TCP_TRANSIENT,
3007 my_format_mac_address (u8 * s, va_list * args)
3009 u8 *a = va_arg (*args, u8 *);
3010 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
3011 a[0], a[1], a[2], a[3], a[4], a[5]);
3015 my_macip_acl_rule_t_pretty_format (u8 * out, va_list * args)
3017 macip_acl_rule_t *a = va_arg (*args, macip_acl_rule_t *);
3019 out = format (out, "%s action %d ip %U/%d mac %U mask %U",
3020 a->is_ipv6 ? "ipv6" : "ipv4", a->is_permit,
3021 format_ip46_address, &a->src_ip_addr,
3022 a->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
3024 my_format_mac_address, a->src_mac,
3025 my_format_mac_address, a->src_mac_mask);
3030 macip_acl_print (acl_main_t * am, u32 macip_acl_index)
3032 vlib_main_t *vm = am->vlib_main;
3035 /* Don't try to print someone else's memory */
3036 if (macip_acl_index > vec_len (am->macip_acls))
3039 macip_acl_list_t *a = vec_elt_at_index (am->macip_acls, macip_acl_index);
3040 int free_pool_slot = pool_is_free_index (am->macip_acls, macip_acl_index);
3042 vlib_cli_output (vm,
3043 "MACIP acl_index: %d, count: %d (true len %d) tag {%s} is free pool slot: %d\n",
3044 macip_acl_index, a->count, vec_len (a->rules), a->tag,
3046 vlib_cli_output (vm,
3047 " ip4_table_index %d, ip6_table_index %d, l2_table_index %d\n",
3048 a->ip4_table_index, a->ip6_table_index, a->l2_table_index);
3049 vlib_cli_output (vm,
3050 " out_ip4_table_index %d, out_ip6_table_index %d, out_l2_table_index %d\n",
3051 a->out_ip4_table_index, a->out_ip6_table_index,
3052 a->out_l2_table_index);
3053 for (i = 0; i < vec_len (a->rules); i++)
3054 vlib_cli_output (vm, " rule %d: %U\n", i,
3055 my_macip_acl_rule_t_pretty_format,
3056 vec_elt_at_index (a->rules, i));
3060 static clib_error_t *
3061 acl_show_aclplugin_macip_acl_fn (vlib_main_t * vm,
3063 input, vlib_cli_command_t * cmd)
3065 clib_error_t *error = 0;
3066 acl_main_t *am = &acl_main;
3068 for (i = 0; i < vec_len (am->macip_acls); i++)
3069 macip_acl_print (am, i);
3073 static clib_error_t *
3074 acl_show_aclplugin_macip_interface_fn (vlib_main_t * vm,
3076 input, vlib_cli_command_t * cmd)
3078 clib_error_t *error = 0;
3079 acl_main_t *am = &acl_main;
3081 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
3083 vlib_cli_output (vm, " sw_if_index %d: %d\n", i,
3084 vec_elt (am->macip_acl_by_sw_if_index, i));
3089 #define PRINT_AND_RESET(vm, out0) do { vlib_cli_output(vm, "%v", out0); vec_reset_length(out0); } while(0)
3091 acl_print_acl (vlib_main_t * vm, acl_main_t * am, int acl_index)
3094 u8 *out0 = format (0, "acl-index %u count %u tag {%s}\n", acl_index,
3095 am->acls[acl_index].count, am->acls[acl_index].tag);
3097 PRINT_AND_RESET (vm, out0);
3098 for (j = 0; j < am->acls[acl_index].count; j++)
3100 r = &am->acls[acl_index].rules[j];
3101 out0 = format (out0, " %4d: %s ", j, r->is_ipv6 ? "ipv6" : "ipv4");
3102 out0 = format_acl_action (out0, r->is_permit);
3103 out0 = format (out0, " src %U/%d", format_ip46_address, &r->src,
3104 r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
3107 format (out0, " dst %U/%d", format_ip46_address, &r->dst,
3108 r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4, r->dst_prefixlen);
3109 out0 = format (out0, " proto %d", r->proto);
3110 out0 = format (out0, " sport %d", r->src_port_or_type_first);
3111 if (r->src_port_or_type_first != r->src_port_or_type_last)
3113 out0 = format (out0, "-%d", r->src_port_or_type_last);
3115 out0 = format (out0, " dport %d", r->dst_port_or_code_first);
3116 if (r->dst_port_or_code_first != r->dst_port_or_code_last)
3118 out0 = format (out0, "-%d", r->dst_port_or_code_last);
3120 if (r->tcp_flags_mask || r->tcp_flags_value)
3123 format (out0, " tcpflags %d mask %d", r->tcp_flags_value,
3126 out0 = format (out0, "\n");
3127 PRINT_AND_RESET (vm, out0);
3131 #undef PRINT_AND_RESET
3134 acl_plugin_show_acl (acl_main_t * am, u32 acl_index)
3137 vlib_main_t *vm = am->vlib_main;
3139 for (i = 0; i < vec_len (am->acls); i++)
3141 if (acl_is_not_defined (am, i))
3143 /* don't attempt to show the ACLs that do not exist */
3146 if ((acl_index != ~0) && (acl_index != i))
3150 acl_print_acl (vm, am, i);
3152 if (i < vec_len (am->input_sw_if_index_vec_by_acl))
3154 vlib_cli_output (vm, " applied inbound on sw_if_index: %U\n",
3155 format_vec32, am->input_sw_if_index_vec_by_acl[i],
3158 if (i < vec_len (am->output_sw_if_index_vec_by_acl))
3160 vlib_cli_output (vm, " applied outbound on sw_if_index: %U\n",
3161 format_vec32, am->output_sw_if_index_vec_by_acl[i],
3167 static clib_error_t *
3168 acl_show_aclplugin_acl_fn (vlib_main_t * vm,
3169 unformat_input_t * input, vlib_cli_command_t * cmd)
3171 clib_error_t *error = 0;
3172 acl_main_t *am = &acl_main;
3175 (void) unformat (input, "index %u", &acl_index);
3177 acl_plugin_show_acl (am, acl_index);
3182 acl_plugin_show_interface (acl_main_t * am, u32 sw_if_index, int show_acl)
3184 vlib_main_t *vm = am->vlib_main;
3187 for (swi = 0; (swi < vec_len (am->input_acl_vec_by_sw_if_index)) ||
3188 (swi < vec_len (am->output_acl_vec_by_sw_if_index)); swi++)
3190 /* if we need a particular interface, skip all the others */
3191 if ((sw_if_index != ~0) && (sw_if_index != swi))
3194 vlib_cli_output (vm, "sw_if_index %d:\n", swi);
3196 if (intf_has_etype_whitelist (am, swi, 1))
3198 vlib_cli_output (vm, " input etype whitelist: %U", format_vec16,
3199 am->input_etype_whitelist_by_sw_if_index[swi],
3202 if (intf_has_etype_whitelist (am, swi, 0))
3204 vlib_cli_output (vm, " output etype whitelist: %U", format_vec16,
3205 am->output_etype_whitelist_by_sw_if_index[swi],
3209 if ((swi < vec_len (am->input_acl_vec_by_sw_if_index)) &&
3210 (vec_len (am->input_acl_vec_by_sw_if_index[swi]) > 0))
3212 vlib_cli_output (vm, " input acl(s): %U", format_vec32,
3213 am->input_acl_vec_by_sw_if_index[swi], "%d");
3216 vlib_cli_output (vm, "\n");
3217 vec_foreach (pj, am->input_acl_vec_by_sw_if_index[swi])
3219 acl_print_acl (vm, am, *pj);
3221 vlib_cli_output (vm, "\n");
3225 if ((swi < vec_len (am->output_acl_vec_by_sw_if_index)) &&
3226 (vec_len (am->output_acl_vec_by_sw_if_index[swi]) > 0))
3228 vlib_cli_output (vm, " output acl(s): %U", format_vec32,
3229 am->output_acl_vec_by_sw_if_index[swi], "%d");
3232 vlib_cli_output (vm, "\n");
3233 vec_foreach (pj, am->output_acl_vec_by_sw_if_index[swi])
3235 acl_print_acl (vm, am, *pj);
3237 vlib_cli_output (vm, "\n");
3245 static clib_error_t *
3246 acl_show_aclplugin_decode_5tuple_fn (vlib_main_t * vm,
3247 unformat_input_t * input,
3248 vlib_cli_command_t * cmd)
3250 clib_error_t *error = 0;
3251 u64 five_tuple[6] = { 0, 0, 0, 0, 0, 0 };
3254 (input, "%llx %llx %llx %llx %llx %llx", &five_tuple[0], &five_tuple[1],
3255 &five_tuple[2], &five_tuple[3], &five_tuple[4], &five_tuple[5]))
3256 vlib_cli_output (vm, "5-tuple structure decode: %U\n\n",
3257 format_acl_plugin_5tuple, five_tuple);
3259 error = clib_error_return (0, "expecting 6 hex integers");
3264 static clib_error_t *
3265 acl_show_aclplugin_interface_fn (vlib_main_t * vm,
3267 input, vlib_cli_command_t * cmd)
3269 clib_error_t *error = 0;
3270 acl_main_t *am = &acl_main;
3272 u32 sw_if_index = ~0;
3273 (void) unformat (input, "sw_if_index %u", &sw_if_index);
3274 int show_acl = unformat (input, "acl");
3276 acl_plugin_show_interface (am, sw_if_index, show_acl);
3280 static clib_error_t *
3281 acl_show_aclplugin_memory_fn (vlib_main_t * vm,
3282 unformat_input_t * input,
3283 vlib_cli_command_t * cmd)
3285 clib_error_t *error = 0;
3286 acl_main_t *am = &acl_main;
3288 vlib_cli_output (vm, "ACL plugin main heap statistics:\n");
3291 vlib_cli_output (vm, " %U\n", format_mheap, am->acl_mheap, 1);
3295 vlib_cli_output (vm, " Not initialized\n");
3297 vlib_cli_output (vm, "ACL hash lookup support heap statistics:\n");
3298 if (am->hash_lookup_mheap)
3300 vlib_cli_output (vm, " %U\n", format_mheap, am->hash_lookup_mheap, 1);
3304 vlib_cli_output (vm, " Not initialized\n");
3310 acl_plugin_show_sessions (acl_main_t * am,
3311 u32 show_session_thread_id,
3312 u32 show_session_session_index)
3314 vlib_main_t *vm = am->vlib_main;
3316 vnet_interface_main_t *im = &am->vnet_main->interface_main;
3317 vnet_sw_interface_t *swif;
3320 u64 n_adds = am->fa_session_total_adds;
3321 u64 n_dels = am->fa_session_total_dels;
3322 vlib_cli_output (vm, "Sessions total: add %lu - del %lu = %lu", n_adds,
3323 n_dels, n_adds - n_dels);
3325 vlib_cli_output (vm, "\n\nPer-thread data:");
3326 for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
3328 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
3329 vlib_cli_output (vm, "Thread #%d:", wk);
3330 if (show_session_thread_id == wk
3331 && show_session_session_index < pool_len (pw->fa_sessions_pool))
3333 vlib_cli_output (vm, " session index %u:",
3334 show_session_session_index);
3335 fa_session_t *sess =
3336 pw->fa_sessions_pool + show_session_session_index;
3337 u64 *m = (u64 *) & sess->info;
3338 vlib_cli_output (vm,
3339 " info: %016llx %016llx %016llx %016llx %016llx %016llx",
3340 m[0], m[1], m[2], m[3], m[4], m[5]);
3341 vlib_cli_output (vm, " sw_if_index: %u", sess->sw_if_index);
3342 vlib_cli_output (vm, " tcp_flags_seen: %x",
3343 sess->tcp_flags_seen.as_u16);
3344 vlib_cli_output (vm, " last active time: %lu",
3345 sess->last_active_time);
3346 vlib_cli_output (vm, " thread index: %u", sess->thread_index);
3347 vlib_cli_output (vm, " link enqueue time: %lu",
3348 sess->link_enqueue_time);
3349 vlib_cli_output (vm, " link next index: %u",
3350 sess->link_next_idx);
3351 vlib_cli_output (vm, " link prev index: %u",
3352 sess->link_prev_idx);
3353 vlib_cli_output (vm, " link list id: %u", sess->link_list_id);
3355 vlib_cli_output (vm, " connection add/del stats:", wk);
3356 pool_foreach (swif, im->sw_interfaces, (
3363 (pw->fa_session_adds_by_sw_if_index)
3365 pw->fa_session_adds_by_sw_if_index
3370 (pw->fa_session_dels_by_sw_if_index)
3372 pw->fa_session_dels_by_sw_if_index
3374 vlib_cli_output (vm,
3375 " sw_if_index %d: add %lu - del %lu = %lu",
3384 vlib_cli_output (vm, " connection timeout type lists:", wk);
3386 for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
3388 u32 head_session_index = pw->fa_conn_list_head[tt];
3389 vlib_cli_output (vm, " fa_conn_list_head[%d]: %d", tt,
3390 head_session_index);
3391 if (~0 != head_session_index)
3393 fa_session_t *sess = pw->fa_sessions_pool + head_session_index;
3394 vlib_cli_output (vm, " last active time: %lu",
3395 sess->last_active_time);
3396 vlib_cli_output (vm, " link enqueue time: %lu",
3397 sess->link_enqueue_time);
3401 vlib_cli_output (vm, " Next expiry time: %lu", pw->next_expiry_time);
3402 vlib_cli_output (vm, " Requeue until time: %lu",
3403 pw->requeue_until_time);
3404 vlib_cli_output (vm, " Current time wait interval: %lu",
3405 pw->current_time_wait_interval);
3406 vlib_cli_output (vm, " Count of deleted sessions: %lu",
3407 pw->cnt_deleted_sessions);
3408 vlib_cli_output (vm, " Delete already deleted: %lu",
3409 pw->cnt_already_deleted_sessions);
3410 vlib_cli_output (vm, " Session timers restarted: %lu",
3411 pw->cnt_session_timer_restarted);
3412 vlib_cli_output (vm, " Swipe until this time: %lu",
3413 pw->swipe_end_time);
3414 vlib_cli_output (vm, " sw_if_index serviced bitmap: %U",
3415 format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
3416 vlib_cli_output (vm, " pending clear intfc bitmap : %U",
3418 pw->pending_clear_sw_if_index_bitmap);
3419 vlib_cli_output (vm, " clear in progress: %u", pw->clear_in_process);
3420 vlib_cli_output (vm, " interrupt is pending: %d",
3421 pw->interrupt_is_pending);
3422 vlib_cli_output (vm, " interrupt is needed: %d",
3423 pw->interrupt_is_needed);
3424 vlib_cli_output (vm, " interrupt is unwanted: %d",
3425 pw->interrupt_is_unwanted);
3426 vlib_cli_output (vm, " interrupt generation: %d",
3427 pw->interrupt_generation);
3429 vlib_cli_output (vm, "\n\nConn cleaner thread counters:");
3430 #define _(cnt, desc) vlib_cli_output(vm, " %20lu: %s", am->cnt, desc);
3431 foreach_fa_cleaner_counter;
3433 vlib_cli_output (vm, "Interrupt generation: %d",
3434 am->fa_interrupt_generation);
3435 vlib_cli_output (vm,
3436 "Sessions per interval: min %lu max %lu increment: %f ms current: %f ms",
3437 am->fa_min_deleted_sessions_per_interval,
3438 am->fa_max_deleted_sessions_per_interval,
3439 am->fa_cleaner_wait_time_increment * 1000.0,
3440 ((f64) am->fa_current_cleaner_timer_wait_interval) *
3441 1000.0 / (f64) vm->clib_time.clocks_per_second);
3444 static clib_error_t *
3445 acl_show_aclplugin_sessions_fn (vlib_main_t * vm,
3446 unformat_input_t * input,
3447 vlib_cli_command_t * cmd)
3449 clib_error_t *error = 0;
3450 acl_main_t *am = &acl_main;
3452 u32 show_bihash_verbose = 0;
3453 u32 show_session_thread_id = ~0;
3454 u32 show_session_session_index = ~0;
3455 (void) unformat (input, "thread %u index %u", &show_session_thread_id,
3456 &show_session_session_index);
3457 (void) unformat (input, "verbose %u", &show_bihash_verbose);
3459 acl_plugin_show_sessions (am, show_session_thread_id,
3460 show_session_session_index);
3461 show_fa_sessions_hash (vm, show_bihash_verbose);
3466 acl_plugin_show_tables_mask_type (acl_main_t * am)
3468 vlib_main_t *vm = am->vlib_main;
3469 ace_mask_type_entry_t *mte;
3471 vlib_cli_output (vm, "Mask-type entries:");
3473 pool_foreach(mte, am->ace_mask_type_pool,
3475 vlib_cli_output(vm, " %3d: %016llx %016llx %016llx %016llx %016llx %016llx refcount %d",
3476 mte - am->ace_mask_type_pool,
3477 mte->mask.kv.key[0], mte->mask.kv.key[1], mte->mask.kv.key[2],
3478 mte->mask.kv.key[3], mte->mask.kv.key[4], mte->mask.kv.value, mte->refcount);
3484 acl_plugin_show_tables_acl_hash_info (acl_main_t * am, u32 acl_index)
3486 vlib_main_t *vm = am->vlib_main;
3489 vlib_cli_output (vm, "Mask-ready ACL representations\n");
3490 for (i = 0; i < vec_len (am->hash_acl_infos); i++)
3492 if ((acl_index != ~0) && (acl_index != i))
3496 hash_acl_info_t *ha = &am->hash_acl_infos[i];
3497 vlib_cli_output (vm, "acl-index %u bitmask-ready layout\n", i);
3498 vlib_cli_output (vm, " applied inbound on sw_if_index list: %U\n",
3499 format_vec32, ha->inbound_sw_if_index_list, "%d");
3500 vlib_cli_output (vm, " applied outbound on sw_if_index list: %U\n",
3501 format_vec32, ha->outbound_sw_if_index_list, "%d");
3502 vlib_cli_output (vm, " mask type index bitmap: %U\n",
3503 format_bitmap_hex, ha->mask_type_index_bitmap);
3504 for (j = 0; j < vec_len (ha->rules); j++)
3506 hash_ace_info_t *pa = &ha->rules[j];
3507 m = (u64 *) & pa->match;
3508 vlib_cli_output (vm,
3509 " %4d: %016llx %016llx %016llx %016llx %016llx %016llx mask index %d acl %d rule %d action %d src/dst portrange not ^2: %d,%d\n",
3510 j, m[0], m[1], m[2], m[3], m[4], m[5],
3511 pa->mask_type_index, pa->acl_index, pa->ace_index,
3512 pa->action, pa->src_portrange_not_powerof2,
3513 pa->dst_portrange_not_powerof2);
3519 acl_plugin_print_pae (vlib_main_t * vm, int j, applied_hash_ace_entry_t * pae)
3521 vlib_cli_output (vm,
3522 " %4d: acl %d rule %d action %d bitmask-ready rule %d next %d prev %d tail %d hitcount %lld",
3523 j, pae->acl_index, pae->ace_index, pae->action,
3524 pae->hash_ace_info_index, pae->next_applied_entry_index,
3525 pae->prev_applied_entry_index,
3526 pae->tail_applied_entry_index, pae->hitcount);
3530 acl_plugin_show_tables_applied_info (acl_main_t * am, u32 sw_if_index)
3532 vlib_main_t *vm = am->vlib_main;
3534 vlib_cli_output (vm, "Applied lookup entries for interfaces");
3537 (swi < vec_len (am->input_applied_hash_acl_info_by_sw_if_index))
3538 || (swi < vec_len (am->output_applied_hash_acl_info_by_sw_if_index))
3539 || (swi < vec_len (am->input_hash_entry_vec_by_sw_if_index))
3540 || (swi < vec_len (am->output_hash_entry_vec_by_sw_if_index)); swi++)
3542 if ((sw_if_index != ~0) && (sw_if_index != swi))
3546 vlib_cli_output (vm, "sw_if_index %d:", swi);
3547 if (swi < vec_len (am->input_applied_hash_acl_info_by_sw_if_index))
3549 applied_hash_acl_info_t *pal =
3550 &am->input_applied_hash_acl_info_by_sw_if_index[swi];
3551 vlib_cli_output (vm, " input lookup mask_type_index_bitmap: %U",
3552 format_bitmap_hex, pal->mask_type_index_bitmap);
3553 vlib_cli_output (vm, " input applied acls: %U", format_vec32,
3554 pal->applied_acls, "%d");
3556 if (swi < vec_len (am->input_hash_entry_vec_by_sw_if_index))
3558 vlib_cli_output (vm, " input lookup applied entries:");
3560 j < vec_len (am->input_hash_entry_vec_by_sw_if_index[swi]);
3563 acl_plugin_print_pae (vm, j,
3564 &am->input_hash_entry_vec_by_sw_if_index
3569 if (swi < vec_len (am->output_applied_hash_acl_info_by_sw_if_index))
3571 applied_hash_acl_info_t *pal =
3572 &am->output_applied_hash_acl_info_by_sw_if_index[swi];
3573 vlib_cli_output (vm, " output lookup mask_type_index_bitmap: %U",
3574 format_bitmap_hex, pal->mask_type_index_bitmap);
3575 vlib_cli_output (vm, " output applied acls: %U", format_vec32,
3576 pal->applied_acls, "%d");
3578 if (swi < vec_len (am->output_hash_entry_vec_by_sw_if_index))
3580 vlib_cli_output (vm, " output lookup applied entries:");
3582 j < vec_len (am->output_hash_entry_vec_by_sw_if_index[swi]);
3585 acl_plugin_print_pae (vm, j,
3586 &am->output_hash_entry_vec_by_sw_if_index
3594 acl_plugin_show_tables_bihash (acl_main_t * am, u32 show_bihash_verbose)
3596 vlib_main_t *vm = am->vlib_main;
3597 show_hash_acl_hash (vm, am, show_bihash_verbose);
3600 static clib_error_t *
3601 acl_show_aclplugin_tables_fn (vlib_main_t * vm,
3602 unformat_input_t * input,
3603 vlib_cli_command_t * cmd)
3605 clib_error_t *error = 0;
3606 acl_main_t *am = &acl_main;
3609 u32 sw_if_index = ~0;
3610 int show_acl_hash_info = 0;
3611 int show_applied_info = 0;
3612 int show_mask_type = 0;
3613 int show_bihash = 0;
3614 u32 show_bihash_verbose = 0;
3616 if (unformat (input, "acl"))
3618 show_acl_hash_info = 1;
3619 /* mask-type is handy to see as well right there */
3621 unformat (input, "index %u", &acl_index);
3623 else if (unformat (input, "applied"))
3625 show_applied_info = 1;
3626 unformat (input, "sw_if_index %u", &sw_if_index);
3628 else if (unformat (input, "mask"))
3632 else if (unformat (input, "hash"))
3635 unformat (input, "verbose %u", &show_bihash_verbose);
3639 (show_mask_type || show_acl_hash_info || show_applied_info
3642 /* if no qualifiers specified, show all */
3644 show_acl_hash_info = 1;
3645 show_applied_info = 1;
3649 acl_plugin_show_tables_mask_type (am);
3650 if (show_acl_hash_info)
3651 acl_plugin_show_tables_acl_hash_info (am, acl_index);
3652 if (show_applied_info)
3653 acl_plugin_show_tables_applied_info (am, sw_if_index);
3655 acl_plugin_show_tables_bihash (am, show_bihash_verbose);
3660 static clib_error_t *
3661 acl_clear_aclplugin_fn (vlib_main_t * vm,
3662 unformat_input_t * input, vlib_cli_command_t * cmd)
3664 clib_error_t *error = 0;
3665 acl_main_t *am = &acl_main;
3666 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
3667 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX, ~0);
3672 VLIB_CLI_COMMAND (aclplugin_set_command, static) = {
3673 .path = "set acl-plugin",
3674 .short_help = "set acl-plugin session timeout {{udp idle}|tcp {idle|transient}} <seconds>",
3675 .function = acl_set_aclplugin_fn,
3678 VLIB_CLI_COMMAND (aclplugin_show_acl_command, static) = {
3679 .path = "show acl-plugin acl",
3680 .short_help = "show acl-plugin acl [index N]",
3681 .function = acl_show_aclplugin_acl_fn,
3684 VLIB_CLI_COMMAND (aclplugin_show_decode_5tuple_command, static) = {
3685 .path = "show acl-plugin decode 5tuple",
3686 .short_help = "show acl-plugin decode 5tuple XXXX XXXX XXXX XXXX XXXX XXXX",
3687 .function = acl_show_aclplugin_decode_5tuple_fn,
3690 VLIB_CLI_COMMAND (aclplugin_show_interface_command, static) = {
3691 .path = "show acl-plugin interface",
3692 .short_help = "show acl-plugin interface [sw_if_index N] [acl]",
3693 .function = acl_show_aclplugin_interface_fn,
3696 VLIB_CLI_COMMAND (aclplugin_show_memory_command, static) = {
3697 .path = "show acl-plugin memory",
3698 .short_help = "show acl-plugin memory",
3699 .function = acl_show_aclplugin_memory_fn,
3702 VLIB_CLI_COMMAND (aclplugin_show_sessions_command, static) = {
3703 .path = "show acl-plugin sessions",
3704 .short_help = "show acl-plugin sessions",
3705 .function = acl_show_aclplugin_sessions_fn,
3708 VLIB_CLI_COMMAND (aclplugin_show_tables_command, static) = {
3709 .path = "show acl-plugin tables",
3710 .short_help = "show acl-plugin tables [ acl [index N] | applied [ sw_if_index N ] | mask | hash [verbose N] ]",
3711 .function = acl_show_aclplugin_tables_fn,
3714 VLIB_CLI_COMMAND (aclplugin_show_macip_acl_command, static) = {
3715 .path = "show acl-plugin macip acl",
3716 .short_help = "show acl-plugin macip acl",
3717 .function = acl_show_aclplugin_macip_acl_fn,
3720 VLIB_CLI_COMMAND (aclplugin_show_macip_interface_command, static) = {
3721 .path = "show acl-plugin macip interface",
3722 .short_help = "show acl-plugin macip interface",
3723 .function = acl_show_aclplugin_macip_interface_fn,
3726 VLIB_CLI_COMMAND (aclplugin_clear_command, static) = {
3727 .path = "clear acl-plugin sessions",
3728 .short_help = "clear acl-plugin sessions",
3729 .function = acl_clear_aclplugin_fn,
3733 static clib_error_t *
3734 acl_plugin_config (vlib_main_t * vm, unformat_input_t * input)
3736 acl_main_t *am = &acl_main;
3737 u32 conn_table_hash_buckets;
3738 u32 conn_table_hash_memory_size;
3739 u32 conn_table_max_entries;
3742 u32 hash_lookup_hash_buckets;
3743 u32 hash_lookup_hash_memory;
3745 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3748 (input, "connection hash buckets %d", &conn_table_hash_buckets))
3749 am->fa_conn_table_hash_num_buckets = conn_table_hash_buckets;
3750 else if (unformat (input, "connection hash memory %d",
3751 &conn_table_hash_memory_size))
3752 am->fa_conn_table_hash_memory_size = conn_table_hash_memory_size;
3753 else if (unformat (input, "connection count max %d",
3754 &conn_table_max_entries))
3755 am->fa_conn_table_max_entries = conn_table_max_entries;
3756 else if (unformat (input, "main heap size %d", &main_heap_size))
3757 am->acl_mheap_size = main_heap_size;
3758 else if (unformat (input, "hash lookup heap size %d", &hash_heap_size))
3759 am->hash_lookup_mheap_size = hash_heap_size;
3760 else if (unformat (input, "hash lookup hash buckets %d",
3761 &hash_lookup_hash_buckets))
3762 am->hash_lookup_hash_buckets = hash_lookup_hash_buckets;
3763 else if (unformat (input, "hash lookup hash memory %d",
3764 &hash_lookup_hash_memory))
3765 am->hash_lookup_hash_memory = hash_lookup_hash_memory;
3767 return clib_error_return (0, "unknown input '%U'",
3768 format_unformat_error, input);
3773 VLIB_CONFIG_FUNCTION (acl_plugin_config, "acl-plugin");
3775 static clib_error_t *
3776 acl_init (vlib_main_t * vm)
3778 acl_main_t *am = &acl_main;
3779 clib_error_t *error = 0;
3780 memset (am, 0, sizeof (*am));
3782 am->vnet_main = vnet_get_main ();
3784 u8 *name = format (0, "acl_%08x%c", api_version, 0);
3786 /* Ask for a correctly-sized block of API message decode slots */
3787 am->msg_id_base = vl_msg_api_get_msg_ids ((char *) name,
3788 VL_MSG_FIRST_AVAILABLE);
3790 error = acl_plugin_api_hookup (vm);
3792 /* Add our API messages to the global name_crc hash table */
3793 setup_message_id_table (am, &api_main);
3797 acl_setup_fa_nodes ();
3799 am->acl_mheap_size = ACL_FA_DEFAULT_HEAP_SIZE;
3800 am->hash_lookup_mheap_size = ACL_PLUGIN_HASH_LOOKUP_HEAP_SIZE;
3802 am->hash_lookup_hash_buckets = ACL_PLUGIN_HASH_LOOKUP_HASH_BUCKETS;
3803 am->hash_lookup_hash_memory = ACL_PLUGIN_HASH_LOOKUP_HASH_MEMORY;
3805 am->session_timeout_sec[ACL_TIMEOUT_TCP_TRANSIENT] =
3806 TCP_SESSION_TRANSIENT_TIMEOUT_SEC;
3807 am->session_timeout_sec[ACL_TIMEOUT_TCP_IDLE] =
3808 TCP_SESSION_IDLE_TIMEOUT_SEC;
3809 am->session_timeout_sec[ACL_TIMEOUT_UDP_IDLE] =
3810 UDP_SESSION_IDLE_TIMEOUT_SEC;
3812 am->fa_conn_table_hash_num_buckets =
3813 ACL_FA_CONN_TABLE_DEFAULT_HASH_NUM_BUCKETS;
3814 am->fa_conn_table_hash_memory_size =
3815 ACL_FA_CONN_TABLE_DEFAULT_HASH_MEMORY_SIZE;
3816 am->fa_conn_table_max_entries = ACL_FA_CONN_TABLE_DEFAULT_MAX_ENTRIES;
3817 vlib_thread_main_t *tm = vlib_get_thread_main ();
3818 vec_validate (am->per_worker_data, tm->n_vlib_mains - 1);
3822 for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
3824 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
3825 vec_validate (pw->fa_conn_list_head, ACL_N_TIMEOUTS - 1);
3826 vec_validate (pw->fa_conn_list_tail, ACL_N_TIMEOUTS - 1);
3827 for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
3829 pw->fa_conn_list_head[tt] = ~0;
3830 pw->fa_conn_list_tail[tt] = ~0;
3835 am->fa_min_deleted_sessions_per_interval =
3836 ACL_FA_DEFAULT_MIN_DELETED_SESSIONS_PER_INTERVAL;
3837 am->fa_max_deleted_sessions_per_interval =
3838 ACL_FA_DEFAULT_MAX_DELETED_SESSIONS_PER_INTERVAL;
3839 am->fa_cleaner_wait_time_increment =
3840 ACL_FA_DEFAULT_CLEANER_WAIT_TIME_INCREMENT;
3842 am->fa_cleaner_cnt_delete_by_sw_index = 0;
3843 am->fa_cleaner_cnt_delete_by_sw_index_ok = 0;
3844 am->fa_cleaner_cnt_unknown_event = 0;
3845 am->fa_cleaner_cnt_timer_restarted = 0;
3846 am->fa_cleaner_cnt_wait_with_timeout = 0;
3849 #define _(N, v, s) am->fa_ipv6_known_eh_bitmap = clib_bitmap_set(am->fa_ipv6_known_eh_bitmap, v, 1);
3852 am->l4_match_nonfirst_fragment = 1;
3854 /* use the new fancy hash-based matching */
3855 am->use_hash_acl_matching = 1;
3860 VLIB_INIT_FUNCTION (acl_init);
3864 * fd.io coding-style-patch-verification: ON
3867 * eval: (c-set-style "gnu")