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;
1855 if (a->out_ip4_table_index != ~0)
1857 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1858 &a->out_ip4_table_index, 0);
1859 a->out_ip4_table_index = ~0;
1861 if (a->out_ip6_table_index != ~0)
1863 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1864 &a->out_ip6_table_index, 0);
1865 a->out_ip6_table_index = ~0;
1867 if (a->out_l2_table_index != ~0)
1869 acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1870 &a->out_l2_table_index, 0);
1871 a->out_l2_table_index = ~0;
1876 macip_maybe_apply_unapply_classifier_tables (acl_main_t * am, u32 acl_index,
1882 macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, acl_index);
1884 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
1885 if (vec_elt (am->macip_acl_by_sw_if_index, i) == acl_index)
1887 rv0 = vnet_set_input_acl_intfc (am->vlib_main, i, a->ip4_table_index,
1888 a->ip6_table_index, a->l2_table_index,
1890 /* return the first unhappy outcome but make try to plough through. */
1893 vnet_set_output_acl_intfc (am->vlib_main, i, a->out_ip4_table_index,
1894 a->out_ip6_table_index,
1895 a->out_l2_table_index, is_apply);
1896 /* return the first unhappy outcome but make try to plough through. */
1903 macip_acl_add_list (u32 count, vl_api_macip_acl_rule_t rules[],
1904 u32 * acl_list_index, u8 * tag)
1906 acl_main_t *am = &acl_main;
1907 macip_acl_list_t *a;
1908 macip_acl_rule_t *r;
1909 macip_acl_rule_t *acl_new_rules = 0;
1913 if (*acl_list_index != ~0)
1915 /* They supplied some number, let's see if this MACIP ACL exists */
1916 if (pool_is_free_index (am->macip_acls, *acl_list_index))
1918 /* tried to replace a non-existent ACL, no point doing anything */
1920 ("acl-plugin-error: Trying to replace nonexistent MACIP ACL %d (tag %s)",
1921 *acl_list_index, tag);
1922 return VNET_API_ERROR_NO_SUCH_ENTRY;
1929 ("acl-plugin-warning: Trying to create empty MACIP ACL (tag %s)",
1932 /* if replacing the ACL, unapply the classifier tables first - they will be gone.. */
1933 if (~0 != *acl_list_index)
1934 rv = macip_maybe_apply_unapply_classifier_tables (am, *acl_list_index, 0);
1935 void *oldheap = acl_set_heap (am);
1936 /* Create and populate the rules */
1938 vec_validate (acl_new_rules, count - 1);
1940 for (i = 0; i < count; i++)
1942 r = &acl_new_rules[i];
1943 r->is_permit = rules[i].is_permit;
1944 r->is_ipv6 = rules[i].is_ipv6;
1945 memcpy (&r->src_mac, rules[i].src_mac, 6);
1946 memcpy (&r->src_mac_mask, rules[i].src_mac_mask, 6);
1947 if (rules[i].is_ipv6)
1948 memcpy (&r->src_ip_addr.ip6, rules[i].src_ip_addr, 16);
1950 memcpy (&r->src_ip_addr.ip4, rules[i].src_ip_addr, 4);
1951 r->src_prefixlen = rules[i].src_ip_prefix_len;
1954 if (~0 == *acl_list_index)
1957 pool_get_aligned (am->macip_acls, a, CLIB_CACHE_LINE_BYTES);
1958 memset (a, 0, sizeof (*a));
1959 /* Will return the newly allocated ACL index */
1960 *acl_list_index = a - am->macip_acls;
1964 a = pool_elt_at_index (am->macip_acls, *acl_list_index);
1967 vec_free (a->rules);
1969 macip_destroy_classify_tables (am, *acl_list_index);
1972 a->rules = acl_new_rules;
1974 memcpy (a->tag, tag, sizeof (a->tag));
1976 /* Create and populate the classifer tables */
1977 macip_create_classify_tables (am, *acl_list_index);
1978 clib_mem_set_heap (oldheap);
1979 /* If the ACL was already applied somewhere, reapply the newly created tables */
1981 || macip_maybe_apply_unapply_classifier_tables (am, *acl_list_index, 1);
1986 /* No check for validity of sw_if_index - the callers were supposed to validate */
1989 macip_acl_interface_del_acl (acl_main_t * am, u32 sw_if_index)
1992 u32 macip_acl_index;
1993 macip_acl_list_t *a;
1994 void *oldheap = acl_set_heap (am);
1995 vec_validate_init_empty (am->macip_acl_by_sw_if_index, sw_if_index, ~0);
1996 clib_mem_set_heap (oldheap);
1997 macip_acl_index = am->macip_acl_by_sw_if_index[sw_if_index];
1998 /* No point in deleting MACIP ACL which is not applied */
1999 if (~0 == macip_acl_index)
2000 return VNET_API_ERROR_NO_SUCH_ENTRY;
2001 a = pool_elt_at_index (am->macip_acls, macip_acl_index);
2002 /* remove the classifier tables off the interface L2 ACL */
2004 vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
2005 a->ip6_table_index, a->l2_table_index, 0);
2007 vnet_set_output_acl_intfc (am->vlib_main, sw_if_index,
2008 a->out_ip4_table_index, a->out_ip6_table_index,
2009 a->out_l2_table_index, 0);
2010 /* Unset the MACIP ACL index */
2011 am->macip_acl_by_sw_if_index[sw_if_index] = ~0;
2015 /* No check for validity of sw_if_index - the callers were supposed to validate */
2018 macip_acl_interface_add_acl (acl_main_t * am, u32 sw_if_index,
2019 u32 macip_acl_index)
2021 macip_acl_list_t *a;
2023 if (pool_is_free_index (am->macip_acls, macip_acl_index))
2025 return VNET_API_ERROR_NO_SUCH_ENTRY;
2027 void *oldheap = acl_set_heap (am);
2028 a = pool_elt_at_index (am->macip_acls, macip_acl_index);
2029 vec_validate_init_empty (am->macip_acl_by_sw_if_index, sw_if_index, ~0);
2030 clib_mem_set_heap (oldheap);
2031 /* If there already a MACIP ACL applied, unapply it */
2032 if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
2033 macip_acl_interface_del_acl (am, sw_if_index);
2034 am->macip_acl_by_sw_if_index[sw_if_index] = macip_acl_index;
2036 /* Apply the classifier tables for L2 ACLs */
2038 vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
2039 a->ip6_table_index, a->l2_table_index, 1);
2041 vnet_set_output_acl_intfc (am->vlib_main, sw_if_index,
2042 a->out_ip4_table_index, a->out_ip6_table_index,
2043 a->out_l2_table_index, 1);
2048 macip_acl_del_list (u32 acl_list_index)
2050 acl_main_t *am = &acl_main;
2051 macip_acl_list_t *a;
2053 if (pool_is_free_index (am->macip_acls, acl_list_index))
2055 return VNET_API_ERROR_NO_SUCH_ENTRY;
2058 /* delete any references to the ACL */
2059 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
2061 if (am->macip_acl_by_sw_if_index[i] == acl_list_index)
2063 macip_acl_interface_del_acl (am, i);
2067 void *oldheap = acl_set_heap (am);
2068 /* Now that classifier tables are detached, clean them up */
2069 macip_destroy_classify_tables (am, acl_list_index);
2071 /* now we can delete the ACL itself */
2072 a = pool_elt_at_index (am->macip_acls, acl_list_index);
2075 vec_free (a->rules);
2077 pool_put (am->macip_acls, a);
2078 clib_mem_set_heap (oldheap);
2084 macip_acl_interface_add_del_acl (u32 sw_if_index, u8 is_add,
2087 acl_main_t *am = &acl_main;
2091 rv = macip_acl_interface_add_acl (am, sw_if_index, acl_list_index);
2095 rv = macip_acl_interface_del_acl (am, sw_if_index);
2101 * If the client does not allocate enough memory for a variable-length
2102 * message, and then proceed to use it as if the full memory allocated,
2103 * absent the check we happily consume that on the VPP side, and go
2104 * along as if nothing happened. However, the resulting
2105 * effects range from just garbage in the API decode
2106 * (because the decoder snoops too far), to potential memory
2109 * This verifies that the actual length of the message is
2110 * at least expected_len, and complains loudly if it is not.
2112 * A failing check here is 100% a software bug on the API user side,
2113 * so we might as well yell.
2117 verify_message_len (void *mp, u32 expected_len, char *where)
2119 u32 supplied_len = vl_msg_api_get_msg_length (mp);
2120 if (supplied_len < expected_len)
2122 clib_warning ("%s: Supplied message length %d is less than expected %d",
2123 where, supplied_len, expected_len);
2132 /* API message handler */
2134 vl_api_acl_add_replace_t_handler (vl_api_acl_add_replace_t * mp)
2136 vl_api_acl_add_replace_reply_t *rmp;
2137 acl_main_t *am = &acl_main;
2139 u32 acl_list_index = ntohl (mp->acl_index);
2140 u32 acl_count = ntohl (mp->count);
2141 u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2143 if (verify_message_len (mp, expected_len, "acl_add_replace"))
2145 rv = acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2149 rv = VNET_API_ERROR_INVALID_VALUE;
2153 REPLY_MACRO2(VL_API_ACL_ADD_REPLACE_REPLY,
2155 rmp->acl_index = htonl(acl_list_index);
2161 vl_api_acl_del_t_handler (vl_api_acl_del_t * mp)
2163 acl_main_t *am = &acl_main;
2164 vl_api_acl_del_reply_t *rmp;
2167 rv = acl_del_list (ntohl (mp->acl_index));
2169 REPLY_MACRO (VL_API_ACL_DEL_REPLY);
2173 vl_api_acl_interface_add_del_t_handler (vl_api_acl_interface_add_del_t * mp)
2175 acl_main_t *am = &acl_main;
2176 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2177 u32 sw_if_index = ntohl (mp->sw_if_index);
2178 vl_api_acl_interface_add_del_reply_t *rmp;
2181 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2182 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2185 acl_interface_add_del_inout_acl (sw_if_index, mp->is_add,
2186 mp->is_input, ntohl (mp->acl_index));
2188 REPLY_MACRO (VL_API_ACL_INTERFACE_ADD_DEL_REPLY);
2192 vl_api_acl_interface_set_acl_list_t_handler
2193 (vl_api_acl_interface_set_acl_list_t * mp)
2195 acl_main_t *am = &acl_main;
2196 vl_api_acl_interface_set_acl_list_reply_t *rmp;
2199 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2200 u32 sw_if_index = ntohl (mp->sw_if_index);
2202 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2203 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2206 acl_interface_reset_inout_acls (sw_if_index, 0);
2207 acl_interface_reset_inout_acls (sw_if_index, 1);
2209 for (i = 0; i < mp->count; i++)
2211 if (acl_is_not_defined (am, ntohl (mp->acls[i])))
2213 /* ACL does not exist, so we can not apply it */
2214 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2219 for (i = 0; i < mp->count; i++)
2221 acl_interface_add_del_inout_acl (sw_if_index, 1,
2223 ntohl (mp->acls[i]));
2228 REPLY_MACRO (VL_API_ACL_INTERFACE_SET_ACL_LIST_REPLY);
2232 copy_acl_rule_to_api_rule (vl_api_acl_rule_t * api_rule, acl_rule_t * r)
2234 api_rule->is_permit = r->is_permit;
2235 api_rule->is_ipv6 = r->is_ipv6;
2238 memcpy (api_rule->src_ip_addr, &r->src, sizeof (r->src));
2239 memcpy (api_rule->dst_ip_addr, &r->dst, sizeof (r->dst));
2243 memcpy (api_rule->src_ip_addr, &r->src.ip4, sizeof (r->src.ip4));
2244 memcpy (api_rule->dst_ip_addr, &r->dst.ip4, sizeof (r->dst.ip4));
2246 api_rule->src_ip_prefix_len = r->src_prefixlen;
2247 api_rule->dst_ip_prefix_len = r->dst_prefixlen;
2248 api_rule->proto = r->proto;
2249 api_rule->srcport_or_icmptype_first = htons (r->src_port_or_type_first);
2250 api_rule->srcport_or_icmptype_last = htons (r->src_port_or_type_last);
2251 api_rule->dstport_or_icmpcode_first = htons (r->dst_port_or_code_first);
2252 api_rule->dstport_or_icmpcode_last = htons (r->dst_port_or_code_last);
2253 api_rule->tcp_flags_mask = r->tcp_flags_mask;
2254 api_rule->tcp_flags_value = r->tcp_flags_value;
2258 send_acl_details (acl_main_t * am, vl_api_registration_t * reg,
2259 acl_list_t * acl, u32 context)
2261 vl_api_acl_details_t *mp;
2262 vl_api_acl_rule_t *rules;
2264 int msg_size = sizeof (*mp) + sizeof (mp->r[0]) * acl->count;
2265 void *oldheap = acl_set_heap (am);
2267 mp = vl_msg_api_alloc (msg_size);
2268 memset (mp, 0, msg_size);
2269 mp->_vl_msg_id = ntohs (VL_API_ACL_DETAILS + am->msg_id_base);
2271 /* fill in the message */
2272 mp->context = context;
2273 mp->count = htonl (acl->count);
2274 mp->acl_index = htonl (acl - am->acls);
2275 memcpy (mp->tag, acl->tag, sizeof (mp->tag));
2276 // clib_memcpy (mp->r, acl->rules, acl->count * sizeof(acl->rules[0]));
2278 for (i = 0; i < acl->count; i++)
2280 copy_acl_rule_to_api_rule (&rules[i], &acl->rules[i]);
2283 clib_mem_set_heap (oldheap);
2284 vl_api_send_msg (reg, (u8 *) mp);
2289 vl_api_acl_dump_t_handler (vl_api_acl_dump_t * mp)
2291 acl_main_t *am = &acl_main;
2295 vl_api_registration_t *reg;
2297 reg = vl_api_client_index_to_registration (mp->client_index);
2301 if (mp->acl_index == ~0)
2304 /* Just dump all ACLs */
2305 pool_foreach (acl, am->acls,
2307 send_acl_details(am, reg, acl, mp->context);
2313 acl_index = ntohl (mp->acl_index);
2314 if (!pool_is_free_index (am->acls, acl_index))
2316 acl = pool_elt_at_index (am->acls, acl_index);
2317 send_acl_details (am, reg, acl, mp->context);
2323 /* FIXME API: should we signal an error here at all ? */
2329 send_acl_interface_list_details (acl_main_t * am,
2330 vl_api_registration_t * reg,
2331 u32 sw_if_index, u32 context)
2333 vl_api_acl_interface_list_details_t *mp;
2339 void *oldheap = acl_set_heap (am);
2341 vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
2342 vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
2344 n_input = vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]);
2345 n_output = vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]);
2346 count = n_input + n_output;
2348 msg_size = sizeof (*mp);
2349 msg_size += sizeof (mp->acls[0]) * count;
2351 mp = vl_msg_api_alloc (msg_size);
2352 memset (mp, 0, msg_size);
2354 ntohs (VL_API_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
2356 /* fill in the message */
2357 mp->context = context;
2358 mp->sw_if_index = htonl (sw_if_index);
2360 mp->n_input = n_input;
2361 for (i = 0; i < n_input; i++)
2363 mp->acls[i] = htonl (am->input_acl_vec_by_sw_if_index[sw_if_index][i]);
2365 for (i = 0; i < n_output; i++)
2367 mp->acls[n_input + i] =
2368 htonl (am->output_acl_vec_by_sw_if_index[sw_if_index][i]);
2370 clib_mem_set_heap (oldheap);
2371 vl_api_send_msg (reg, (u8 *) mp);
2375 vl_api_acl_interface_list_dump_t_handler (vl_api_acl_interface_list_dump_t *
2378 acl_main_t *am = &acl_main;
2379 vnet_sw_interface_t *swif;
2380 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2383 vl_api_registration_t *reg;
2385 reg = vl_api_client_index_to_registration (mp->client_index);
2389 if (mp->sw_if_index == ~0)
2392 pool_foreach (swif, im->sw_interfaces,
2394 send_acl_interface_list_details(am, reg, swif->sw_if_index, mp->context);
2400 sw_if_index = ntohl (mp->sw_if_index);
2401 if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
2402 send_acl_interface_list_details (am, reg, sw_if_index, mp->context);
2406 /* MACIP ACL API handlers */
2409 vl_api_macip_acl_add_t_handler (vl_api_macip_acl_add_t * mp)
2411 vl_api_macip_acl_add_reply_t *rmp;
2412 acl_main_t *am = &acl_main;
2414 u32 acl_list_index = ~0;
2415 u32 acl_count = ntohl (mp->count);
2416 u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2418 if (verify_message_len (mp, expected_len, "macip_acl_add"))
2420 rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2424 rv = VNET_API_ERROR_INVALID_VALUE;
2428 REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLY,
2430 rmp->acl_index = htonl(acl_list_index);
2436 vl_api_macip_acl_add_replace_t_handler (vl_api_macip_acl_add_replace_t * mp)
2438 vl_api_macip_acl_add_replace_reply_t *rmp;
2439 acl_main_t *am = &acl_main;
2441 u32 acl_list_index = ntohl (mp->acl_index);
2442 u32 acl_count = ntohl (mp->count);
2443 u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2445 if (verify_message_len (mp, expected_len, "macip_acl_add_replace"))
2447 rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2451 rv = VNET_API_ERROR_INVALID_VALUE;
2455 REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLACE_REPLY,
2457 rmp->acl_index = htonl(acl_list_index);
2463 vl_api_macip_acl_del_t_handler (vl_api_macip_acl_del_t * mp)
2465 acl_main_t *am = &acl_main;
2466 vl_api_macip_acl_del_reply_t *rmp;
2469 rv = macip_acl_del_list (ntohl (mp->acl_index));
2471 REPLY_MACRO (VL_API_MACIP_ACL_DEL_REPLY);
2475 vl_api_macip_acl_interface_add_del_t_handler
2476 (vl_api_macip_acl_interface_add_del_t * mp)
2478 acl_main_t *am = &acl_main;
2479 vl_api_macip_acl_interface_add_del_reply_t *rmp;
2481 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2482 u32 sw_if_index = ntohl (mp->sw_if_index);
2484 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2485 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2488 macip_acl_interface_add_del_acl (ntohl (mp->sw_if_index), mp->is_add,
2489 ntohl (mp->acl_index));
2491 REPLY_MACRO (VL_API_MACIP_ACL_INTERFACE_ADD_DEL_REPLY);
2495 send_macip_acl_details (acl_main_t * am, vl_api_registration_t * reg,
2496 macip_acl_list_t * acl, u32 context)
2498 vl_api_macip_acl_details_t *mp;
2499 vl_api_macip_acl_rule_t *rules;
2500 macip_acl_rule_t *r;
2502 int msg_size = sizeof (*mp) + (acl ? sizeof (mp->r[0]) * acl->count : 0);
2504 mp = vl_msg_api_alloc (msg_size);
2505 memset (mp, 0, msg_size);
2506 mp->_vl_msg_id = ntohs (VL_API_MACIP_ACL_DETAILS + am->msg_id_base);
2508 /* fill in the message */
2509 mp->context = context;
2512 memcpy (mp->tag, acl->tag, sizeof (mp->tag));
2513 mp->count = htonl (acl->count);
2514 mp->acl_index = htonl (acl - am->macip_acls);
2516 for (i = 0; i < acl->count; i++)
2519 rules[i].is_permit = r->is_permit;
2520 rules[i].is_ipv6 = r->is_ipv6;
2521 memcpy (rules[i].src_mac, &r->src_mac, sizeof (r->src_mac));
2522 memcpy (rules[i].src_mac_mask, &r->src_mac_mask,
2523 sizeof (r->src_mac_mask));
2525 memcpy (rules[i].src_ip_addr, &r->src_ip_addr.ip6,
2526 sizeof (r->src_ip_addr.ip6));
2528 memcpy (rules[i].src_ip_addr, &r->src_ip_addr.ip4,
2529 sizeof (r->src_ip_addr.ip4));
2530 rules[i].src_ip_prefix_len = r->src_prefixlen;
2535 /* No martini, no party - no ACL applied to this interface. */
2540 vl_api_send_msg (reg, (u8 *) mp);
2545 vl_api_macip_acl_dump_t_handler (vl_api_macip_acl_dump_t * mp)
2547 acl_main_t *am = &acl_main;
2548 macip_acl_list_t *acl;
2550 vl_api_registration_t *reg;
2552 reg = vl_api_client_index_to_registration (mp->client_index);
2556 if (mp->acl_index == ~0)
2558 /* Just dump all ACLs for now, with sw_if_index = ~0 */
2559 pool_foreach (acl, am->macip_acls, (
2561 send_macip_acl_details (am, reg,
2570 u32 acl_index = ntohl (mp->acl_index);
2571 if (!pool_is_free_index (am->macip_acls, acl_index))
2573 acl = pool_elt_at_index (am->macip_acls, acl_index);
2574 send_macip_acl_details (am, reg, acl, mp->context);
2580 vl_api_macip_acl_interface_get_t_handler (vl_api_macip_acl_interface_get_t *
2583 acl_main_t *am = &acl_main;
2584 vl_api_macip_acl_interface_get_reply_t *rmp;
2585 u32 count = vec_len (am->macip_acl_by_sw_if_index);
2586 int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]) * count;
2587 vl_api_registration_t *reg;
2590 reg = vl_api_client_index_to_registration (mp->client_index);
2594 rmp = vl_msg_api_alloc (msg_size);
2595 memset (rmp, 0, msg_size);
2597 ntohs (VL_API_MACIP_ACL_INTERFACE_GET_REPLY + am->msg_id_base);
2598 rmp->context = mp->context;
2599 rmp->count = htonl (count);
2600 for (i = 0; i < count; i++)
2602 rmp->acls[i] = htonl (am->macip_acl_by_sw_if_index[i]);
2605 vl_api_send_msg (reg, (u8 *) rmp);
2609 send_macip_acl_interface_list_details (acl_main_t * am,
2610 vl_api_registration_t * reg,
2612 u32 acl_index, u32 context)
2614 vl_api_macip_acl_interface_list_details_t *rmp;
2615 /* at this time there is only ever 1 mac ip acl per interface */
2616 int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]);
2618 rmp = vl_msg_api_alloc (msg_size);
2619 memset (rmp, 0, msg_size);
2621 ntohs (VL_API_MACIP_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
2623 /* fill in the message */
2624 rmp->context = context;
2626 rmp->sw_if_index = htonl (sw_if_index);
2627 rmp->acls[0] = htonl (acl_index);
2629 vl_api_send_msg (reg, (u8 *) rmp);
2633 vl_api_macip_acl_interface_list_dump_t_handler
2634 (vl_api_macip_acl_interface_list_dump_t * mp)
2636 vl_api_registration_t *reg;
2637 acl_main_t *am = &acl_main;
2638 u32 sw_if_index = ntohl (mp->sw_if_index);
2640 reg = vl_api_client_index_to_registration (mp->client_index);
2644 if (sw_if_index == ~0)
2646 vec_foreach_index (sw_if_index, am->macip_acl_by_sw_if_index)
2648 if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
2650 send_macip_acl_interface_list_details (am, reg, sw_if_index,
2651 am->macip_acl_by_sw_if_index
2659 if (vec_len (am->macip_acl_by_sw_if_index) > sw_if_index)
2661 send_macip_acl_interface_list_details (am, reg, sw_if_index,
2662 am->macip_acl_by_sw_if_index
2663 [sw_if_index], mp->context);
2669 vl_api_acl_interface_set_etype_whitelist_t_handler
2670 (vl_api_acl_interface_set_etype_whitelist_t * mp)
2672 acl_main_t *am = &acl_main;
2673 vl_api_acl_interface_set_etype_whitelist_reply_t *rmp;
2676 vnet_interface_main_t *im = &am->vnet_main->interface_main;
2677 u32 sw_if_index = ntohl (mp->sw_if_index);
2678 u16 *vec_in = 0, *vec_out = 0;
2679 void *oldheap = acl_set_heap (am);
2681 if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2682 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2685 for (i = 0; i < mp->count; i++)
2687 if (i < mp->n_input)
2688 vec_add1 (vec_in, ntohs (mp->whitelist[i]));
2690 vec_add1 (vec_out, ntohs (mp->whitelist[i]));
2692 rv = acl_set_etype_whitelists (am, sw_if_index, vec_in, vec_out);
2695 clib_mem_set_heap (oldheap);
2696 REPLY_MACRO (VL_API_ACL_INTERFACE_SET_ETYPE_WHITELIST_REPLY);
2700 /* Set up the API message handling tables */
2701 static clib_error_t *
2702 acl_plugin_api_hookup (vlib_main_t * vm)
2704 acl_main_t *am = &acl_main;
2706 vl_msg_api_set_handlers((VL_API_##N + am->msg_id_base), \
2708 vl_api_##n##_t_handler, \
2710 vl_api_##n##_t_endian, \
2711 vl_api_##n##_t_print, \
2712 sizeof(vl_api_##n##_t), 1);
2713 foreach_acl_plugin_api_msg;
2719 #define vl_msg_name_crc_list
2720 #include <acl/acl_all_api_h.h>
2721 #undef vl_msg_name_crc_list
2724 setup_message_id_table (acl_main_t * am, api_main_t * apim)
2726 #define _(id,n,crc) \
2727 vl_msg_api_add_msg_name_crc (apim, #n "_" #crc, id + am->msg_id_base);
2728 foreach_vl_msg_name_crc_acl;
2733 acl_setup_fa_nodes (void)
2735 vlib_main_t *vm = vlib_get_main ();
2736 acl_main_t *am = &acl_main;
2737 vlib_node_t *n, *n4, *n6;
2739 n = vlib_get_node_by_name (vm, (u8 *) "l2-input-classify");
2740 n4 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-in-ip4-l2");
2741 n6 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-in-ip6-l2");
2744 am->l2_input_classify_next_acl_ip4 =
2745 vlib_node_add_next_with_slot (vm, n->index, n4->index, ~0);
2746 am->l2_input_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, L2INPUT_N_FEAT,
2750 l2input_get_feat_names (),
2751 am->fa_acl_in_ip4_l2_node_feat_next_node_index);
2753 feat_bitmap_init_next_nodes (vm, n6->index, L2INPUT_N_FEAT,
2754 l2input_get_feat_names (),
2755 am->fa_acl_in_ip6_l2_node_feat_next_node_index);
2758 n = vlib_get_node_by_name (vm, (u8 *) "l2-output-classify");
2759 n4 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-out-ip4-l2");
2760 n6 = vlib_get_node_by_name (vm, (u8 *) "acl-plugin-out-ip6-l2");
2762 am->l2_output_classify_next_acl_ip4 =
2763 vlib_node_add_next_with_slot (vm, n->index, n4->index, ~0);
2764 am->l2_output_classify_next_acl_ip6 =
2765 vlib_node_add_next_with_slot (vm, n->index, n6->index, ~0);
2767 feat_bitmap_init_next_nodes (vm, n4->index, L2OUTPUT_N_FEAT,
2768 l2output_get_feat_names (),
2769 am->fa_acl_out_ip4_l2_node_feat_next_node_index);
2771 feat_bitmap_init_next_nodes (vm, n6->index, L2OUTPUT_N_FEAT,
2772 l2output_get_feat_names (),
2773 am->fa_acl_out_ip6_l2_node_feat_next_node_index);
2777 acl_set_timeout_sec (int timeout_type, u32 value)
2779 acl_main_t *am = &acl_main;
2780 clib_time_t *ct = &am->vlib_main->clib_time;
2782 if (timeout_type < ACL_N_TIMEOUTS)
2784 am->session_timeout_sec[timeout_type] = value;
2788 clib_warning ("Unknown timeout type %d", timeout_type);
2791 am->session_timeout[timeout_type] =
2792 (u64) (((f64) value) / ct->seconds_per_clock);
2796 acl_set_session_max_entries (u32 value)
2798 acl_main_t *am = &acl_main;
2799 am->fa_conn_table_max_entries = value;
2803 acl_set_skip_ipv6_eh (u32 eh, u32 value)
2805 acl_main_t *am = &acl_main;
2807 if ((eh < 256) && (value < 2))
2809 am->fa_ipv6_known_eh_bitmap =
2810 clib_bitmap_set (am->fa_ipv6_known_eh_bitmap, eh, value);
2818 static clib_error_t *
2819 acl_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
2821 acl_main_t *am = &acl_main;
2822 if (0 == am->acl_mheap)
2824 /* ACL heap is not initialized, so definitely nothing to do. */
2829 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
2830 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX,
2832 /* also unapply any ACLs in case the users did not do so. */
2833 macip_acl_interface_del_acl (am, sw_if_index);
2834 acl_interface_reset_inout_acls (sw_if_index, 0);
2835 acl_interface_reset_inout_acls (sw_if_index, 1);
2840 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (acl_sw_interface_add_del);
2844 static clib_error_t *
2845 acl_set_aclplugin_fn (vlib_main_t * vm,
2846 unformat_input_t * input, vlib_cli_command_t * cmd)
2848 clib_error_t *error = 0;
2852 uword memory_size = 0;
2853 acl_main_t *am = &acl_main;
2855 if (unformat (input, "skip-ipv6-extension-header %u %u", &eh_val, &val))
2857 if (!acl_set_skip_ipv6_eh (eh_val, val))
2859 error = clib_error_return (0, "expecting eh=0..255, value=0..1");
2863 if (unformat (input, "use-hash-acl-matching %u", &val))
2865 am->use_hash_acl_matching = (val != 0);
2868 if (unformat (input, "l4-match-nonfirst-fragment %u", &val))
2870 am->l4_match_nonfirst_fragment = (val != 0);
2873 if (unformat (input, "heap"))
2875 if (unformat (input, "main"))
2877 if (unformat (input, "validate %u", &val))
2878 acl_plugin_acl_set_validate_heap (am, val);
2879 else if (unformat (input, "trace %u", &val))
2880 acl_plugin_acl_set_trace_heap (am, val);
2883 else if (unformat (input, "hash"))
2885 if (unformat (input, "validate %u", &val))
2886 acl_plugin_hash_acl_set_validate_heap (am, val);
2887 else if (unformat (input, "trace %u", &val))
2888 acl_plugin_hash_acl_set_trace_heap (am, val);
2893 if (unformat (input, "session"))
2895 if (unformat (input, "table"))
2897 /* The commands here are for tuning/testing. No user-serviceable parts inside */
2898 if (unformat (input, "max-entries"))
2900 if (!unformat (input, "%u", &val))
2902 error = clib_error_return (0,
2903 "expecting maximum number of entries, got `%U`",
2904 format_unformat_error, input);
2909 acl_set_session_max_entries (val);
2913 if (unformat (input, "hash-table-buckets"))
2915 if (!unformat (input, "%u", &val))
2917 error = clib_error_return (0,
2918 "expecting maximum number of hash table buckets, got `%U`",
2919 format_unformat_error, input);
2924 am->fa_conn_table_hash_num_buckets = val;
2928 if (unformat (input, "hash-table-memory"))
2930 if (!unformat (input, "%U", unformat_memory_size, &memory_size))
2932 error = clib_error_return (0,
2933 "expecting maximum amount of hash table memory, got `%U`",
2934 format_unformat_error, input);
2939 am->fa_conn_table_hash_memory_size = memory_size;
2943 if (unformat (input, "event-trace"))
2945 if (!unformat (input, "%u", &val))
2947 error = clib_error_return (0,
2948 "expecting trace level, got `%U`",
2949 format_unformat_error, input);
2954 am->trace_sessions = val;
2960 if (unformat (input, "timeout"))
2962 if (unformat (input, "udp"))
2964 if (unformat (input, "idle"))
2966 if (!unformat (input, "%u", &timeout))
2968 error = clib_error_return (0,
2969 "expecting timeout value in seconds, got `%U`",
2970 format_unformat_error,
2976 acl_set_timeout_sec (ACL_TIMEOUT_UDP_IDLE, timeout);
2981 if (unformat (input, "tcp"))
2983 if (unformat (input, "idle"))
2985 if (!unformat (input, "%u", &timeout))
2987 error = clib_error_return (0,
2988 "expecting timeout value in seconds, got `%U`",
2989 format_unformat_error,
2995 acl_set_timeout_sec (ACL_TIMEOUT_TCP_IDLE, timeout);
2999 if (unformat (input, "transient"))
3001 if (!unformat (input, "%u", &timeout))
3003 error = clib_error_return (0,
3004 "expecting timeout value in seconds, got `%U`",
3005 format_unformat_error,
3011 acl_set_timeout_sec (ACL_TIMEOUT_TCP_TRANSIENT,
3025 my_format_mac_address (u8 * s, va_list * args)
3027 u8 *a = va_arg (*args, u8 *);
3028 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
3029 a[0], a[1], a[2], a[3], a[4], a[5]);
3033 my_macip_acl_rule_t_pretty_format (u8 * out, va_list * args)
3035 macip_acl_rule_t *a = va_arg (*args, macip_acl_rule_t *);
3037 out = format (out, "%s action %d ip %U/%d mac %U mask %U",
3038 a->is_ipv6 ? "ipv6" : "ipv4", a->is_permit,
3039 format_ip46_address, &a->src_ip_addr,
3040 a->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
3042 my_format_mac_address, a->src_mac,
3043 my_format_mac_address, a->src_mac_mask);
3048 macip_acl_print (acl_main_t * am, u32 macip_acl_index)
3050 vlib_main_t *vm = am->vlib_main;
3053 /* Don't attempt to show the ACLs that do not exist */
3054 if (pool_is_free_index (am->macip_acls, macip_acl_index))
3057 /* Don't try to print someone else's memory */
3058 if (macip_acl_index > vec_len (am->macip_acls))
3061 macip_acl_list_t *a = vec_elt_at_index (am->macip_acls, macip_acl_index);
3062 int free_pool_slot = pool_is_free_index (am->macip_acls, macip_acl_index);
3064 vlib_cli_output (vm,
3065 "MACIP acl_index: %d, count: %d (true len %d) tag {%s} is free pool slot: %d\n",
3066 macip_acl_index, a->count, vec_len (a->rules), a->tag,
3068 vlib_cli_output (vm,
3069 " ip4_table_index %d, ip6_table_index %d, l2_table_index %d\n",
3070 a->ip4_table_index, a->ip6_table_index, a->l2_table_index);
3071 vlib_cli_output (vm,
3072 " out_ip4_table_index %d, out_ip6_table_index %d, out_l2_table_index %d\n",
3073 a->out_ip4_table_index, a->out_ip6_table_index,
3074 a->out_l2_table_index);
3075 for (i = 0; i < vec_len (a->rules); i++)
3076 vlib_cli_output (vm, " rule %d: %U\n", i,
3077 my_macip_acl_rule_t_pretty_format,
3078 vec_elt_at_index (a->rules, i));
3082 static clib_error_t *
3083 acl_show_aclplugin_macip_acl_fn (vlib_main_t * vm,
3085 input, vlib_cli_command_t * cmd)
3087 clib_error_t *error = 0;
3088 acl_main_t *am = &acl_main;
3090 for (i = 0; i < vec_len (am->macip_acls); i++)
3091 macip_acl_print (am, i);
3095 static clib_error_t *
3096 acl_show_aclplugin_macip_interface_fn (vlib_main_t * vm,
3098 input, vlib_cli_command_t * cmd)
3100 clib_error_t *error = 0;
3101 acl_main_t *am = &acl_main;
3103 for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
3105 vlib_cli_output (vm, " sw_if_index %d: %d\n", i,
3106 vec_elt (am->macip_acl_by_sw_if_index, i));
3111 #define PRINT_AND_RESET(vm, out0) do { vlib_cli_output(vm, "%v", out0); vec_reset_length(out0); } while(0)
3113 acl_print_acl (vlib_main_t * vm, acl_main_t * am, int acl_index)
3116 u8 *out0 = format (0, "acl-index %u count %u tag {%s}\n", acl_index,
3117 am->acls[acl_index].count, am->acls[acl_index].tag);
3119 PRINT_AND_RESET (vm, out0);
3120 for (j = 0; j < am->acls[acl_index].count; j++)
3122 r = &am->acls[acl_index].rules[j];
3123 out0 = format (out0, " %4d: %s ", j, r->is_ipv6 ? "ipv6" : "ipv4");
3124 out0 = format_acl_action (out0, r->is_permit);
3125 out0 = format (out0, " src %U/%d", format_ip46_address, &r->src,
3126 r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
3129 format (out0, " dst %U/%d", format_ip46_address, &r->dst,
3130 r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4, r->dst_prefixlen);
3131 out0 = format (out0, " proto %d", r->proto);
3132 out0 = format (out0, " sport %d", r->src_port_or_type_first);
3133 if (r->src_port_or_type_first != r->src_port_or_type_last)
3135 out0 = format (out0, "-%d", r->src_port_or_type_last);
3137 out0 = format (out0, " dport %d", r->dst_port_or_code_first);
3138 if (r->dst_port_or_code_first != r->dst_port_or_code_last)
3140 out0 = format (out0, "-%d", r->dst_port_or_code_last);
3142 if (r->tcp_flags_mask || r->tcp_flags_value)
3145 format (out0, " tcpflags %d mask %d", r->tcp_flags_value,
3148 out0 = format (out0, "\n");
3149 PRINT_AND_RESET (vm, out0);
3153 #undef PRINT_AND_RESET
3156 acl_plugin_show_acl (acl_main_t * am, u32 acl_index)
3159 vlib_main_t *vm = am->vlib_main;
3161 for (i = 0; i < vec_len (am->acls); i++)
3163 if (acl_is_not_defined (am, i))
3165 /* don't attempt to show the ACLs that do not exist */
3168 if ((acl_index != ~0) && (acl_index != i))
3172 acl_print_acl (vm, am, i);
3174 if (i < vec_len (am->input_sw_if_index_vec_by_acl))
3176 vlib_cli_output (vm, " applied inbound on sw_if_index: %U\n",
3177 format_vec32, am->input_sw_if_index_vec_by_acl[i],
3180 if (i < vec_len (am->output_sw_if_index_vec_by_acl))
3182 vlib_cli_output (vm, " applied outbound on sw_if_index: %U\n",
3183 format_vec32, am->output_sw_if_index_vec_by_acl[i],
3189 static clib_error_t *
3190 acl_show_aclplugin_acl_fn (vlib_main_t * vm,
3191 unformat_input_t * input, vlib_cli_command_t * cmd)
3193 clib_error_t *error = 0;
3194 acl_main_t *am = &acl_main;
3197 (void) unformat (input, "index %u", &acl_index);
3199 acl_plugin_show_acl (am, acl_index);
3204 acl_plugin_show_interface (acl_main_t * am, u32 sw_if_index, int show_acl)
3206 vlib_main_t *vm = am->vlib_main;
3209 for (swi = 0; (swi < vec_len (am->input_acl_vec_by_sw_if_index)) ||
3210 (swi < vec_len (am->output_acl_vec_by_sw_if_index)); swi++)
3212 /* if we need a particular interface, skip all the others */
3213 if ((sw_if_index != ~0) && (sw_if_index != swi))
3216 vlib_cli_output (vm, "sw_if_index %d:\n", swi);
3218 if (intf_has_etype_whitelist (am, swi, 1))
3220 vlib_cli_output (vm, " input etype whitelist: %U", format_vec16,
3221 am->input_etype_whitelist_by_sw_if_index[swi],
3224 if (intf_has_etype_whitelist (am, swi, 0))
3226 vlib_cli_output (vm, " output etype whitelist: %U", format_vec16,
3227 am->output_etype_whitelist_by_sw_if_index[swi],
3231 if ((swi < vec_len (am->input_acl_vec_by_sw_if_index)) &&
3232 (vec_len (am->input_acl_vec_by_sw_if_index[swi]) > 0))
3234 vlib_cli_output (vm, " input acl(s): %U", format_vec32,
3235 am->input_acl_vec_by_sw_if_index[swi], "%d");
3238 vlib_cli_output (vm, "\n");
3239 vec_foreach (pj, am->input_acl_vec_by_sw_if_index[swi])
3241 acl_print_acl (vm, am, *pj);
3243 vlib_cli_output (vm, "\n");
3247 if ((swi < vec_len (am->output_acl_vec_by_sw_if_index)) &&
3248 (vec_len (am->output_acl_vec_by_sw_if_index[swi]) > 0))
3250 vlib_cli_output (vm, " output acl(s): %U", format_vec32,
3251 am->output_acl_vec_by_sw_if_index[swi], "%d");
3254 vlib_cli_output (vm, "\n");
3255 vec_foreach (pj, am->output_acl_vec_by_sw_if_index[swi])
3257 acl_print_acl (vm, am, *pj);
3259 vlib_cli_output (vm, "\n");
3267 static clib_error_t *
3268 acl_show_aclplugin_decode_5tuple_fn (vlib_main_t * vm,
3269 unformat_input_t * input,
3270 vlib_cli_command_t * cmd)
3272 clib_error_t *error = 0;
3273 u64 five_tuple[6] = { 0, 0, 0, 0, 0, 0 };
3276 (input, "%llx %llx %llx %llx %llx %llx", &five_tuple[0], &five_tuple[1],
3277 &five_tuple[2], &five_tuple[3], &five_tuple[4], &five_tuple[5]))
3278 vlib_cli_output (vm, "5-tuple structure decode: %U\n\n",
3279 format_acl_plugin_5tuple, five_tuple);
3281 error = clib_error_return (0, "expecting 6 hex integers");
3286 static clib_error_t *
3287 acl_show_aclplugin_interface_fn (vlib_main_t * vm,
3289 input, vlib_cli_command_t * cmd)
3291 clib_error_t *error = 0;
3292 acl_main_t *am = &acl_main;
3294 u32 sw_if_index = ~0;
3295 (void) unformat (input, "sw_if_index %u", &sw_if_index);
3296 int show_acl = unformat (input, "acl");
3298 acl_plugin_show_interface (am, sw_if_index, show_acl);
3302 static clib_error_t *
3303 acl_show_aclplugin_memory_fn (vlib_main_t * vm,
3304 unformat_input_t * input,
3305 vlib_cli_command_t * cmd)
3307 clib_error_t *error = 0;
3308 acl_main_t *am = &acl_main;
3310 vlib_cli_output (vm, "ACL plugin main heap statistics:\n");
3313 vlib_cli_output (vm, " %U\n", format_mheap, am->acl_mheap, 1);
3317 vlib_cli_output (vm, " Not initialized\n");
3319 vlib_cli_output (vm, "ACL hash lookup support heap statistics:\n");
3320 if (am->hash_lookup_mheap)
3322 vlib_cli_output (vm, " %U\n", format_mheap, am->hash_lookup_mheap, 1);
3326 vlib_cli_output (vm, " Not initialized\n");
3332 acl_plugin_show_sessions (acl_main_t * am,
3333 u32 show_session_thread_id,
3334 u32 show_session_session_index)
3336 vlib_main_t *vm = am->vlib_main;
3338 vnet_interface_main_t *im = &am->vnet_main->interface_main;
3339 vnet_sw_interface_t *swif;
3342 u64 n_adds = am->fa_session_total_adds;
3343 u64 n_dels = am->fa_session_total_dels;
3344 vlib_cli_output (vm, "Sessions total: add %lu - del %lu = %lu", n_adds,
3345 n_dels, n_adds - n_dels);
3347 vlib_cli_output (vm, "\n\nPer-thread data:");
3348 for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
3350 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
3351 vlib_cli_output (vm, "Thread #%d:", wk);
3352 if (show_session_thread_id == wk
3353 && show_session_session_index < pool_len (pw->fa_sessions_pool))
3355 vlib_cli_output (vm, " session index %u:",
3356 show_session_session_index);
3357 fa_session_t *sess =
3358 pw->fa_sessions_pool + show_session_session_index;
3359 u64 *m = (u64 *) & sess->info;
3360 vlib_cli_output (vm,
3361 " info: %016llx %016llx %016llx %016llx %016llx %016llx",
3362 m[0], m[1], m[2], m[3], m[4], m[5]);
3363 vlib_cli_output (vm, " sw_if_index: %u", sess->sw_if_index);
3364 vlib_cli_output (vm, " tcp_flags_seen: %x",
3365 sess->tcp_flags_seen.as_u16);
3366 vlib_cli_output (vm, " last active time: %lu",
3367 sess->last_active_time);
3368 vlib_cli_output (vm, " thread index: %u", sess->thread_index);
3369 vlib_cli_output (vm, " link enqueue time: %lu",
3370 sess->link_enqueue_time);
3371 vlib_cli_output (vm, " link next index: %u",
3372 sess->link_next_idx);
3373 vlib_cli_output (vm, " link prev index: %u",
3374 sess->link_prev_idx);
3375 vlib_cli_output (vm, " link list id: %u", sess->link_list_id);
3377 vlib_cli_output (vm, " connection add/del stats:", wk);
3378 pool_foreach (swif, im->sw_interfaces, (
3385 (pw->fa_session_adds_by_sw_if_index)
3387 pw->fa_session_adds_by_sw_if_index
3392 (pw->fa_session_dels_by_sw_if_index)
3394 pw->fa_session_dels_by_sw_if_index
3396 vlib_cli_output (vm,
3397 " sw_if_index %d: add %lu - del %lu = %lu",
3406 vlib_cli_output (vm, " connection timeout type lists:", wk);
3408 for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
3410 u32 head_session_index = pw->fa_conn_list_head[tt];
3411 vlib_cli_output (vm, " fa_conn_list_head[%d]: %d", tt,
3412 head_session_index);
3413 if (~0 != head_session_index)
3415 fa_session_t *sess = pw->fa_sessions_pool + head_session_index;
3416 vlib_cli_output (vm, " last active time: %lu",
3417 sess->last_active_time);
3418 vlib_cli_output (vm, " link enqueue time: %lu",
3419 sess->link_enqueue_time);
3423 vlib_cli_output (vm, " Next expiry time: %lu", pw->next_expiry_time);
3424 vlib_cli_output (vm, " Requeue until time: %lu",
3425 pw->requeue_until_time);
3426 vlib_cli_output (vm, " Current time wait interval: %lu",
3427 pw->current_time_wait_interval);
3428 vlib_cli_output (vm, " Count of deleted sessions: %lu",
3429 pw->cnt_deleted_sessions);
3430 vlib_cli_output (vm, " Delete already deleted: %lu",
3431 pw->cnt_already_deleted_sessions);
3432 vlib_cli_output (vm, " Session timers restarted: %lu",
3433 pw->cnt_session_timer_restarted);
3434 vlib_cli_output (vm, " Swipe until this time: %lu",
3435 pw->swipe_end_time);
3436 vlib_cli_output (vm, " sw_if_index serviced bitmap: %U",
3437 format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
3438 vlib_cli_output (vm, " pending clear intfc bitmap : %U",
3440 pw->pending_clear_sw_if_index_bitmap);
3441 vlib_cli_output (vm, " clear in progress: %u", pw->clear_in_process);
3442 vlib_cli_output (vm, " interrupt is pending: %d",
3443 pw->interrupt_is_pending);
3444 vlib_cli_output (vm, " interrupt is needed: %d",
3445 pw->interrupt_is_needed);
3446 vlib_cli_output (vm, " interrupt is unwanted: %d",
3447 pw->interrupt_is_unwanted);
3448 vlib_cli_output (vm, " interrupt generation: %d",
3449 pw->interrupt_generation);
3451 vlib_cli_output (vm, "\n\nConn cleaner thread counters:");
3452 #define _(cnt, desc) vlib_cli_output(vm, " %20lu: %s", am->cnt, desc);
3453 foreach_fa_cleaner_counter;
3455 vlib_cli_output (vm, "Interrupt generation: %d",
3456 am->fa_interrupt_generation);
3457 vlib_cli_output (vm,
3458 "Sessions per interval: min %lu max %lu increment: %f ms current: %f ms",
3459 am->fa_min_deleted_sessions_per_interval,
3460 am->fa_max_deleted_sessions_per_interval,
3461 am->fa_cleaner_wait_time_increment * 1000.0,
3462 ((f64) am->fa_current_cleaner_timer_wait_interval) *
3463 1000.0 / (f64) vm->clib_time.clocks_per_second);
3466 static clib_error_t *
3467 acl_show_aclplugin_sessions_fn (vlib_main_t * vm,
3468 unformat_input_t * input,
3469 vlib_cli_command_t * cmd)
3471 clib_error_t *error = 0;
3472 acl_main_t *am = &acl_main;
3474 u32 show_bihash_verbose = 0;
3475 u32 show_session_thread_id = ~0;
3476 u32 show_session_session_index = ~0;
3477 (void) unformat (input, "thread %u index %u", &show_session_thread_id,
3478 &show_session_session_index);
3479 (void) unformat (input, "verbose %u", &show_bihash_verbose);
3481 acl_plugin_show_sessions (am, show_session_thread_id,
3482 show_session_session_index);
3483 show_fa_sessions_hash (vm, show_bihash_verbose);
3488 acl_plugin_show_tables_mask_type (acl_main_t * am)
3490 vlib_main_t *vm = am->vlib_main;
3491 ace_mask_type_entry_t *mte;
3493 vlib_cli_output (vm, "Mask-type entries:");
3495 pool_foreach(mte, am->ace_mask_type_pool,
3497 vlib_cli_output(vm, " %3d: %016llx %016llx %016llx %016llx %016llx %016llx refcount %d",
3498 mte - am->ace_mask_type_pool,
3499 mte->mask.kv.key[0], mte->mask.kv.key[1], mte->mask.kv.key[2],
3500 mte->mask.kv.key[3], mte->mask.kv.key[4], mte->mask.kv.value, mte->refcount);
3506 acl_plugin_show_tables_acl_hash_info (acl_main_t * am, u32 acl_index)
3508 vlib_main_t *vm = am->vlib_main;
3511 vlib_cli_output (vm, "Mask-ready ACL representations\n");
3512 for (i = 0; i < vec_len (am->hash_acl_infos); i++)
3514 if ((acl_index != ~0) && (acl_index != i))
3518 hash_acl_info_t *ha = &am->hash_acl_infos[i];
3519 vlib_cli_output (vm, "acl-index %u bitmask-ready layout\n", i);
3520 vlib_cli_output (vm, " applied inbound on sw_if_index list: %U\n",
3521 format_vec32, ha->inbound_sw_if_index_list, "%d");
3522 vlib_cli_output (vm, " applied outbound on sw_if_index list: %U\n",
3523 format_vec32, ha->outbound_sw_if_index_list, "%d");
3524 vlib_cli_output (vm, " mask type index bitmap: %U\n",
3525 format_bitmap_hex, ha->mask_type_index_bitmap);
3526 for (j = 0; j < vec_len (ha->rules); j++)
3528 hash_ace_info_t *pa = &ha->rules[j];
3529 m = (u64 *) & pa->match;
3530 vlib_cli_output (vm,
3531 " %4d: %016llx %016llx %016llx %016llx %016llx %016llx mask index %d acl %d rule %d action %d src/dst portrange not ^2: %d,%d\n",
3532 j, m[0], m[1], m[2], m[3], m[4], m[5],
3533 pa->mask_type_index, pa->acl_index, pa->ace_index,
3534 pa->action, pa->src_portrange_not_powerof2,
3535 pa->dst_portrange_not_powerof2);
3541 acl_plugin_print_pae (vlib_main_t * vm, int j, applied_hash_ace_entry_t * pae)
3543 vlib_cli_output (vm,
3544 " %4d: acl %d rule %d action %d bitmask-ready rule %d next %d prev %d tail %d hitcount %lld",
3545 j, pae->acl_index, pae->ace_index, pae->action,
3546 pae->hash_ace_info_index, pae->next_applied_entry_index,
3547 pae->prev_applied_entry_index,
3548 pae->tail_applied_entry_index, pae->hitcount);
3552 acl_plugin_show_tables_applied_info (acl_main_t * am, u32 sw_if_index)
3554 vlib_main_t *vm = am->vlib_main;
3556 vlib_cli_output (vm, "Applied lookup entries for interfaces");
3559 (swi < vec_len (am->input_applied_hash_acl_info_by_sw_if_index))
3560 || (swi < vec_len (am->output_applied_hash_acl_info_by_sw_if_index))
3561 || (swi < vec_len (am->input_hash_entry_vec_by_sw_if_index))
3562 || (swi < vec_len (am->output_hash_entry_vec_by_sw_if_index)); swi++)
3564 if ((sw_if_index != ~0) && (sw_if_index != swi))
3568 vlib_cli_output (vm, "sw_if_index %d:", swi);
3569 if (swi < vec_len (am->input_applied_hash_acl_info_by_sw_if_index))
3571 applied_hash_acl_info_t *pal =
3572 &am->input_applied_hash_acl_info_by_sw_if_index[swi];
3573 vlib_cli_output (vm, " input lookup mask_type_index_bitmap: %U",
3574 format_bitmap_hex, pal->mask_type_index_bitmap);
3575 vlib_cli_output (vm, " input applied acls: %U", format_vec32,
3576 pal->applied_acls, "%d");
3578 if (swi < vec_len (am->input_hash_entry_vec_by_sw_if_index))
3580 vlib_cli_output (vm, " input lookup applied entries:");
3582 j < vec_len (am->input_hash_entry_vec_by_sw_if_index[swi]);
3585 acl_plugin_print_pae (vm, j,
3586 &am->input_hash_entry_vec_by_sw_if_index
3591 if (swi < vec_len (am->output_applied_hash_acl_info_by_sw_if_index))
3593 applied_hash_acl_info_t *pal =
3594 &am->output_applied_hash_acl_info_by_sw_if_index[swi];
3595 vlib_cli_output (vm, " output lookup mask_type_index_bitmap: %U",
3596 format_bitmap_hex, pal->mask_type_index_bitmap);
3597 vlib_cli_output (vm, " output applied acls: %U", format_vec32,
3598 pal->applied_acls, "%d");
3600 if (swi < vec_len (am->output_hash_entry_vec_by_sw_if_index))
3602 vlib_cli_output (vm, " output lookup applied entries:");
3604 j < vec_len (am->output_hash_entry_vec_by_sw_if_index[swi]);
3607 acl_plugin_print_pae (vm, j,
3608 &am->output_hash_entry_vec_by_sw_if_index
3616 acl_plugin_show_tables_bihash (acl_main_t * am, u32 show_bihash_verbose)
3618 vlib_main_t *vm = am->vlib_main;
3619 show_hash_acl_hash (vm, am, show_bihash_verbose);
3622 static clib_error_t *
3623 acl_show_aclplugin_tables_fn (vlib_main_t * vm,
3624 unformat_input_t * input,
3625 vlib_cli_command_t * cmd)
3627 clib_error_t *error = 0;
3628 acl_main_t *am = &acl_main;
3631 u32 sw_if_index = ~0;
3632 int show_acl_hash_info = 0;
3633 int show_applied_info = 0;
3634 int show_mask_type = 0;
3635 int show_bihash = 0;
3636 u32 show_bihash_verbose = 0;
3638 if (unformat (input, "acl"))
3640 show_acl_hash_info = 1;
3641 /* mask-type is handy to see as well right there */
3643 unformat (input, "index %u", &acl_index);
3645 else if (unformat (input, "applied"))
3647 show_applied_info = 1;
3648 unformat (input, "sw_if_index %u", &sw_if_index);
3650 else if (unformat (input, "mask"))
3654 else if (unformat (input, "hash"))
3657 unformat (input, "verbose %u", &show_bihash_verbose);
3661 (show_mask_type || show_acl_hash_info || show_applied_info
3664 /* if no qualifiers specified, show all */
3666 show_acl_hash_info = 1;
3667 show_applied_info = 1;
3671 acl_plugin_show_tables_mask_type (am);
3672 if (show_acl_hash_info)
3673 acl_plugin_show_tables_acl_hash_info (am, acl_index);
3674 if (show_applied_info)
3675 acl_plugin_show_tables_applied_info (am, sw_if_index);
3677 acl_plugin_show_tables_bihash (am, show_bihash_verbose);
3682 static clib_error_t *
3683 acl_clear_aclplugin_fn (vlib_main_t * vm,
3684 unformat_input_t * input, vlib_cli_command_t * cmd)
3686 clib_error_t *error = 0;
3687 acl_main_t *am = &acl_main;
3688 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
3689 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX, ~0);
3694 VLIB_CLI_COMMAND (aclplugin_set_command, static) = {
3695 .path = "set acl-plugin",
3696 .short_help = "set acl-plugin session timeout {{udp idle}|tcp {idle|transient}} <seconds>",
3697 .function = acl_set_aclplugin_fn,
3700 VLIB_CLI_COMMAND (aclplugin_show_acl_command, static) = {
3701 .path = "show acl-plugin acl",
3702 .short_help = "show acl-plugin acl [index N]",
3703 .function = acl_show_aclplugin_acl_fn,
3706 VLIB_CLI_COMMAND (aclplugin_show_decode_5tuple_command, static) = {
3707 .path = "show acl-plugin decode 5tuple",
3708 .short_help = "show acl-plugin decode 5tuple XXXX XXXX XXXX XXXX XXXX XXXX",
3709 .function = acl_show_aclplugin_decode_5tuple_fn,
3712 VLIB_CLI_COMMAND (aclplugin_show_interface_command, static) = {
3713 .path = "show acl-plugin interface",
3714 .short_help = "show acl-plugin interface [sw_if_index N] [acl]",
3715 .function = acl_show_aclplugin_interface_fn,
3718 VLIB_CLI_COMMAND (aclplugin_show_memory_command, static) = {
3719 .path = "show acl-plugin memory",
3720 .short_help = "show acl-plugin memory",
3721 .function = acl_show_aclplugin_memory_fn,
3724 VLIB_CLI_COMMAND (aclplugin_show_sessions_command, static) = {
3725 .path = "show acl-plugin sessions",
3726 .short_help = "show acl-plugin sessions",
3727 .function = acl_show_aclplugin_sessions_fn,
3730 VLIB_CLI_COMMAND (aclplugin_show_tables_command, static) = {
3731 .path = "show acl-plugin tables",
3732 .short_help = "show acl-plugin tables [ acl [index N] | applied [ sw_if_index N ] | mask | hash [verbose N] ]",
3733 .function = acl_show_aclplugin_tables_fn,
3736 VLIB_CLI_COMMAND (aclplugin_show_macip_acl_command, static) = {
3737 .path = "show acl-plugin macip acl",
3738 .short_help = "show acl-plugin macip acl",
3739 .function = acl_show_aclplugin_macip_acl_fn,
3742 VLIB_CLI_COMMAND (aclplugin_show_macip_interface_command, static) = {
3743 .path = "show acl-plugin macip interface",
3744 .short_help = "show acl-plugin macip interface",
3745 .function = acl_show_aclplugin_macip_interface_fn,
3748 VLIB_CLI_COMMAND (aclplugin_clear_command, static) = {
3749 .path = "clear acl-plugin sessions",
3750 .short_help = "clear acl-plugin sessions",
3751 .function = acl_clear_aclplugin_fn,
3755 static clib_error_t *
3756 acl_plugin_config (vlib_main_t * vm, unformat_input_t * input)
3758 acl_main_t *am = &acl_main;
3759 u32 conn_table_hash_buckets;
3760 u32 conn_table_hash_memory_size;
3761 u32 conn_table_max_entries;
3764 u32 hash_lookup_hash_buckets;
3765 u32 hash_lookup_hash_memory;
3767 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3770 (input, "connection hash buckets %d", &conn_table_hash_buckets))
3771 am->fa_conn_table_hash_num_buckets = conn_table_hash_buckets;
3772 else if (unformat (input, "connection hash memory %d",
3773 &conn_table_hash_memory_size))
3774 am->fa_conn_table_hash_memory_size = conn_table_hash_memory_size;
3775 else if (unformat (input, "connection count max %d",
3776 &conn_table_max_entries))
3777 am->fa_conn_table_max_entries = conn_table_max_entries;
3778 else if (unformat (input, "main heap size %d", &main_heap_size))
3779 am->acl_mheap_size = main_heap_size;
3780 else if (unformat (input, "hash lookup heap size %d", &hash_heap_size))
3781 am->hash_lookup_mheap_size = hash_heap_size;
3782 else if (unformat (input, "hash lookup hash buckets %d",
3783 &hash_lookup_hash_buckets))
3784 am->hash_lookup_hash_buckets = hash_lookup_hash_buckets;
3785 else if (unformat (input, "hash lookup hash memory %d",
3786 &hash_lookup_hash_memory))
3787 am->hash_lookup_hash_memory = hash_lookup_hash_memory;
3789 return clib_error_return (0, "unknown input '%U'",
3790 format_unformat_error, input);
3795 VLIB_CONFIG_FUNCTION (acl_plugin_config, "acl-plugin");
3797 static clib_error_t *
3798 acl_init (vlib_main_t * vm)
3800 acl_main_t *am = &acl_main;
3801 clib_error_t *error = 0;
3802 memset (am, 0, sizeof (*am));
3804 am->vnet_main = vnet_get_main ();
3806 u8 *name = format (0, "acl_%08x%c", api_version, 0);
3808 /* Ask for a correctly-sized block of API message decode slots */
3809 am->msg_id_base = vl_msg_api_get_msg_ids ((char *) name,
3810 VL_MSG_FIRST_AVAILABLE);
3812 error = acl_plugin_api_hookup (vm);
3814 /* Add our API messages to the global name_crc hash table */
3815 setup_message_id_table (am, &api_main);
3819 acl_setup_fa_nodes ();
3821 am->acl_mheap_size = ACL_FA_DEFAULT_HEAP_SIZE;
3822 am->hash_lookup_mheap_size = ACL_PLUGIN_HASH_LOOKUP_HEAP_SIZE;
3824 am->hash_lookup_hash_buckets = ACL_PLUGIN_HASH_LOOKUP_HASH_BUCKETS;
3825 am->hash_lookup_hash_memory = ACL_PLUGIN_HASH_LOOKUP_HASH_MEMORY;
3827 am->session_timeout_sec[ACL_TIMEOUT_TCP_TRANSIENT] =
3828 TCP_SESSION_TRANSIENT_TIMEOUT_SEC;
3829 am->session_timeout_sec[ACL_TIMEOUT_TCP_IDLE] =
3830 TCP_SESSION_IDLE_TIMEOUT_SEC;
3831 am->session_timeout_sec[ACL_TIMEOUT_UDP_IDLE] =
3832 UDP_SESSION_IDLE_TIMEOUT_SEC;
3834 am->fa_conn_table_hash_num_buckets =
3835 ACL_FA_CONN_TABLE_DEFAULT_HASH_NUM_BUCKETS;
3836 am->fa_conn_table_hash_memory_size =
3837 ACL_FA_CONN_TABLE_DEFAULT_HASH_MEMORY_SIZE;
3838 am->fa_conn_table_max_entries = ACL_FA_CONN_TABLE_DEFAULT_MAX_ENTRIES;
3839 vlib_thread_main_t *tm = vlib_get_thread_main ();
3840 vec_validate (am->per_worker_data, tm->n_vlib_mains - 1);
3844 for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
3846 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
3847 vec_validate (pw->fa_conn_list_head, ACL_N_TIMEOUTS - 1);
3848 vec_validate (pw->fa_conn_list_tail, ACL_N_TIMEOUTS - 1);
3849 for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
3851 pw->fa_conn_list_head[tt] = ~0;
3852 pw->fa_conn_list_tail[tt] = ~0;
3857 am->fa_min_deleted_sessions_per_interval =
3858 ACL_FA_DEFAULT_MIN_DELETED_SESSIONS_PER_INTERVAL;
3859 am->fa_max_deleted_sessions_per_interval =
3860 ACL_FA_DEFAULT_MAX_DELETED_SESSIONS_PER_INTERVAL;
3861 am->fa_cleaner_wait_time_increment =
3862 ACL_FA_DEFAULT_CLEANER_WAIT_TIME_INCREMENT;
3864 am->fa_cleaner_cnt_delete_by_sw_index = 0;
3865 am->fa_cleaner_cnt_delete_by_sw_index_ok = 0;
3866 am->fa_cleaner_cnt_unknown_event = 0;
3867 am->fa_cleaner_cnt_timer_restarted = 0;
3868 am->fa_cleaner_cnt_wait_with_timeout = 0;
3871 #define _(N, v, s) am->fa_ipv6_known_eh_bitmap = clib_bitmap_set(am->fa_ipv6_known_eh_bitmap, v, 1);
3874 am->l4_match_nonfirst_fragment = 1;
3876 /* use the new fancy hash-based matching */
3877 am->use_hash_acl_matching = 1;
3882 VLIB_INIT_FUNCTION (acl_init);
3886 * fd.io coding-style-patch-verification: ON
3889 * eval: (c-set-style "gnu")