FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
acl.c
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #include <stddef.h>
17 
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
20 #include <acl/acl.h>
21 
22 #include <vnet/l2/l2_classify.h>
25 #include <vpp/app/version.h>
26 
27 #include <vlibapi/api.h>
28 #include <vlibmemory/api.h>
29 
30 /* define message IDs */
31 #include <acl/acl.api_enum.h>
32 #include <acl/acl.api_types.h>
33 
34 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
35 #include "manual_fns.h"
36 
37 #include "fa_node.h"
38 #include "public_inlines.h"
39 
41 
42 #define REPLY_MSG_ID_BASE am->msg_id_base
44 
45 /*
46  * The code for the bihash, used by the session management.
47  */
48 #include <vppinfra/bihash_40_8.h>
51 
52 /* *INDENT-OFF* */
54  .version = VPP_BUILD_VER,
55  .description = "Access Control Lists (ACL)",
56 };
57 /* *INDENT-ON* */
58 
59 /* methods exported from ACL-as-a-service */
61 
62 /* Format vec16. */
63 u8 *
64 format_vec16 (u8 * s, va_list * va)
65 {
66  u16 *v = va_arg (*va, u16 *);
67  char *fmt = va_arg (*va, char *);
68  uword i;
69  for (i = 0; i < vec_len (v); i++)
70  {
71  if (i > 0)
72  s = format (s, ", ");
73  s = format (s, fmt, v[i]);
74  }
75  return s;
76 }
77 
78 static void *
80 {
81  if (0 == am->acl_mheap)
82  {
83  if (0 == am->acl_mheap_size)
84  {
86  u64 per_worker_slack = 1000000LL;
87  u64 per_worker_size =
88  per_worker_slack +
89  ((u64) am->fa_conn_table_max_entries) * sizeof (fa_session_t);
90  u64 per_worker_size_with_slack = per_worker_slack + per_worker_size;
91  u64 main_slack = 2000000LL;
92  u64 bihash_size = (u64) am->fa_conn_table_hash_memory_size;
93 
94  am->acl_mheap_size =
95  per_worker_size_with_slack * tm->n_vlib_mains + bihash_size +
96  main_slack;
97  }
98  u64 max_possible = ((uword) ~ 0);
99  if (am->acl_mheap_size > max_possible)
100  {
101  clib_warning ("ACL heap size requested: %lld, max possible %lld",
102  am->acl_mheap_size, max_possible);
103  }
104 
105  am->acl_mheap = mheap_alloc_with_lock (0 /* use VM */ ,
106  am->acl_mheap_size,
107  1 /* locked */ );
108  if (0 == am->acl_mheap)
109  {
110  clib_error
111  ("ACL plugin failed to allocate main heap of %U bytes, abort",
113  }
114  }
115  void *oldheap = clib_mem_set_heap (am->acl_mheap);
116  return oldheap;
117 }
118 
119 void *
121 {
122  acl_main_t *am = &acl_main;
123  return acl_set_heap (am);
124 }
125 
126 void
128 {
130 #if USE_DLMALLOC == 0
131  mheap_t *h = mheap_header (am->acl_mheap);
132  if (on)
133  {
136  mheap_validate (h);
137  }
138  else
139  {
140  h->flags &= ~MHEAP_FLAG_VALIDATE;
142  }
143 #endif
144 }
145 
146 void
148 {
150 #if USE_DLMALLOC == 0
151  mheap_t *h = mheap_header (am->acl_mheap);
152  if (on)
153  {
154  h->flags |= MHEAP_FLAG_TRACE;
155  }
156  else
157  {
158  h->flags &= ~MHEAP_FLAG_TRACE;
159  }
160 #endif
161 }
162 
163 static void
165 {
166  acl_main_t *am = &acl_main;
168  int msg_size = sizeof (*rmp);
170 
172  if (!reg)
173  return;
174 
175  rmp = vl_msg_api_alloc (msg_size);
176  clib_memset (rmp, 0, msg_size);
177  rmp->_vl_msg_id =
178  ntohs (VL_API_ACL_PLUGIN_GET_VERSION_REPLY + am->msg_id_base);
179  rmp->context = mp->context;
180  rmp->major = htonl (ACL_PLUGIN_VERSION_MAJOR);
181  rmp->minor = htonl (ACL_PLUGIN_VERSION_MINOR);
182 
183  vl_api_send_msg (reg, (u8 *) rmp);
184 }
185 
186 static void
188  mp)
189 {
191  acl_main_t *am = &acl_main;
192  int rv = 0;
193 
194  /* *INDENT-OFF* */
195  REPLY_MACRO2 (VL_API_ACL_PLUGIN_CONTROL_PING_REPLY,
196  ({
197  rmp->vpe_pid = ntohl (getpid ());
198  }));
199  /* *INDENT-ON* */
200 }
201 
202 static void
204 {
205  clib_warning ("%v", out0);
206  vec_reset_length (out0);
207 }
208 
209 static void
211 {
212  vlib_cli_output (vm, "%v", out0);
213  vec_reset_length (out0);
214 }
215 
216 typedef void (*acl_vector_print_func_t) (vlib_main_t * vm, u8 * out0);
217 
218 static void
220  acl_main_t * am, int acl_index)
221 {
222  acl_rule_t *r;
223  acl_rule_t *acl_rules = am->acls[acl_index].rules;
224  u8 *out0 = format (0, "acl-index %u count %u tag {%s}\n", acl_index,
225  vec_len (acl_rules), am->acls[acl_index].tag);
226  int j;
227  vpr (vm, out0);
228  for (j = 0; j < vec_len (acl_rules); j++)
229  {
230  r = &acl_rules[j];
231  out0 = format (out0, " %9d: %s ", j, r->is_ipv6 ? "ipv6" : "ipv4");
232  out0 = format_acl_action (out0, r->is_permit);
233  out0 = format (out0, " src %U/%d", format_ip46_address, &r->src,
235  r->src_prefixlen);
236  out0 =
237  format (out0, " dst %U/%d", format_ip46_address, &r->dst,
238  r->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4, r->dst_prefixlen);
239  out0 = format (out0, " proto %d", r->proto);
240  out0 = format (out0, " sport %d", r->src_port_or_type_first);
242  {
243  out0 = format (out0, "-%d", r->src_port_or_type_last);
244  }
245  out0 = format (out0, " dport %d", r->dst_port_or_code_first);
247  {
248  out0 = format (out0, "-%d", r->dst_port_or_code_last);
249  }
250  if (r->tcp_flags_mask || r->tcp_flags_value)
251  {
252  out0 =
253  format (out0, " tcpflags %d mask %d", r->tcp_flags_value,
254  r->tcp_flags_mask);
255  }
256  out0 = format (out0, "\n");
257  vpr (vm, out0);
258  }
259 }
260 
261 static void
264 {
265  acl_main_t *am = &acl_main;
267  int msg_size = sizeof (*rmp);
269 
271  if (rp == 0)
272  return;
273 
274  rmp = vl_msg_api_alloc (msg_size);
275  memset (rmp, 0, msg_size);
276  rmp->_vl_msg_id =
277  ntohs (VL_API_ACL_PLUGIN_GET_CONN_TABLE_MAX_ENTRIES_REPLY +
278  am->msg_id_base);
279  rmp->context = mp->context;
280  rmp->conn_table_max_entries = __bswap_64 (am->fa_conn_table_max_entries);
281 
282  vl_api_send_msg (rp, (u8 *) rmp);
283 }
284 
285 static void
287 {
288  acl_print_acl_x (print_cli_and_reset, vm, am, acl_index);
289 }
290 
291 static void
293 {
294  acl_print_acl_x (print_clib_warning_and_reset, vm, am, acl_index);
295 }
296 
297 static void
299 {
300 
301  u32 **ppolicy_epoch_by_swi =
302  is_input ? &am->input_policy_epoch_by_sw_if_index :
304  vec_validate (*ppolicy_epoch_by_swi, sw_if_index);
305 
306  u32 *p_epoch = vec_elt_at_index ((*ppolicy_epoch_by_swi), sw_if_index);
307  *p_epoch =
308  ((1 + *p_epoch) & FA_POLICY_EPOCH_MASK) +
309  (is_input * FA_POLICY_EPOCH_IS_INPUT);
310 }
311 
312 static void
313 try_increment_acl_policy_epoch (acl_main_t * am, u32 acl_num, int is_input)
314 {
315  u32 ***p_swi_vec_by_acl = is_input ? &am->input_sw_if_index_vec_by_acl
317  if (acl_num < vec_len (*p_swi_vec_by_acl))
318  {
319  u32 *p_swi;
320  vec_foreach (p_swi, (*p_swi_vec_by_acl)[acl_num])
321  {
322  increment_policy_epoch (am, *p_swi, is_input);
323  }
324 
325  }
326 }
327 
328 static void
330 {
331  try_increment_acl_policy_epoch (am, acl_num, 0);
332  try_increment_acl_policy_epoch (am, acl_num, 1);
333 }
334 
335 
336 static void
338 {
339  int i;
340  /* counters are set as vectors [acl#] pointing to vectors of [acl rule] */
342 
343  int old_len = vec_len (am->combined_acl_counters);
344 
345  vec_validate (am->combined_acl_counters, acl_index);
346 
347  for (i = old_len; i < vec_len (am->combined_acl_counters); i++)
348  {
349  am->combined_acl_counters[i].name = 0;
350  /* filled in once only */
352  format (0, "/acl/%d/matches%c", i, 0);
353  i32 rule_count = vec_len (am->acls[i].rules);
354  /* Validate one extra so we always have at least one counter for an ACL */
356  rule_count);
358  }
359 
360  /* (re)validate for the actual ACL that is getting added/updated */
361  i32 rule_count = vec_len (am->acls[acl_index].rules);
362  /* Validate one extra so we always have at least one counter for an ACL */
364  rule_count);
367 }
368 
369 static int
370 acl_api_ip4_invalid_prefix (void *ip4_pref_raw, u8 ip4_prefix_len)
371 {
372  ip4_address_t ip4_addr;
373  ip4_address_t ip4_mask;
374  ip4_address_t ip4_masked_addr;
375 
376  memcpy (&ip4_addr, ip4_pref_raw, sizeof (ip4_addr));
377  ip4_preflen_to_mask (ip4_prefix_len, &ip4_mask);
378  ip4_masked_addr.as_u32 = ip4_addr.as_u32 & ip4_mask.as_u32;
379  int ret = (ip4_masked_addr.as_u32 != ip4_addr.as_u32);
380  if (ret)
381  {
383  ("inconsistent addr %U for prefix len %d; (%U when masked)",
384  format_ip4_address, ip4_pref_raw, ip4_prefix_len, format_ip4_address,
385  &ip4_masked_addr);
386  }
387  return ret;
388 }
389 
390 static int
391 acl_api_ip6_invalid_prefix (void *ip6_pref_raw, u8 ip6_prefix_len)
392 {
393  ip6_address_t ip6_addr;
394  ip6_address_t ip6_mask;
395  ip6_address_t ip6_masked_addr;
396 
397  memcpy (&ip6_addr, ip6_pref_raw, sizeof (ip6_addr));
398  ip6_preflen_to_mask (ip6_prefix_len, &ip6_mask);
399  ip6_masked_addr.as_u64[0] = ip6_addr.as_u64[0] & ip6_mask.as_u64[0];
400  ip6_masked_addr.as_u64[1] = ip6_addr.as_u64[1] & ip6_mask.as_u64[1];
401  int ret = ((ip6_masked_addr.as_u64[0] != ip6_addr.as_u64[0])
402  || (ip6_masked_addr.as_u64[1] != ip6_addr.as_u64[1]));
403  if (ret)
404  {
406  ("inconsistent addr %U for prefix len %d; (%U when masked)",
407  format_ip6_address, ip6_pref_raw, ip6_prefix_len, format_ip6_address,
408  &ip6_masked_addr);
409  }
410  return ret;
411 }
412 
413 static int
414 acl_add_list (u32 count, vl_api_acl_rule_t rules[],
415  u32 * acl_list_index, u8 * tag)
416 {
417  acl_main_t *am = &acl_main;
418  acl_list_t *a;
419  acl_rule_t *r;
420  acl_rule_t *acl_new_rules = 0;
421  int i;
422 
423  if (am->trace_acl > 255)
424  clib_warning ("API dbg: acl_add_list index %d tag %s", *acl_list_index,
425  tag);
426 
427  /* check if what they request is consistent */
428  for (i = 0; i < count; i++)
429  {
430  if (rules[i].is_ipv6)
431  {
432  if (rules[i].src_ip_prefix_len > 128)
433  return VNET_API_ERROR_INVALID_VALUE;
434  if (rules[i].dst_ip_prefix_len > 128)
435  return VNET_API_ERROR_INVALID_VALUE;
437  (&rules[i].src_ip_addr, rules[i].src_ip_prefix_len))
438  return VNET_API_ERROR_INVALID_SRC_ADDRESS;
440  (&rules[i].dst_ip_addr, rules[i].dst_ip_prefix_len))
441  return VNET_API_ERROR_INVALID_DST_ADDRESS;
442  }
443  else
444  {
445  if (rules[i].src_ip_prefix_len > 32)
446  return VNET_API_ERROR_INVALID_VALUE;
447  if (rules[i].dst_ip_prefix_len > 32)
448  return VNET_API_ERROR_INVALID_VALUE;
450  (&rules[i].src_ip_addr, rules[i].src_ip_prefix_len))
451  return VNET_API_ERROR_INVALID_SRC_ADDRESS;
453  (&rules[i].dst_ip_addr, rules[i].dst_ip_prefix_len))
454  return VNET_API_ERROR_INVALID_DST_ADDRESS;
455  }
456  if (ntohs (rules[i].srcport_or_icmptype_first) >
457  ntohs (rules[i].srcport_or_icmptype_last))
458  return VNET_API_ERROR_INVALID_VALUE_2;
459  if (ntohs (rules[i].dstport_or_icmpcode_first) >
460  ntohs (rules[i].dstport_or_icmpcode_last))
461  return VNET_API_ERROR_INVALID_VALUE_2;
462  }
463 
464  if (*acl_list_index != ~0)
465  {
466  /* They supplied some number, let's see if this ACL exists */
467  if (pool_is_free_index (am->acls, *acl_list_index))
468  {
469  /* tried to replace a non-existent ACL, no point doing anything */
471  ("acl-plugin-error: Trying to replace nonexistent ACL %d (tag %s)",
472  *acl_list_index, tag);
473  return VNET_API_ERROR_NO_SUCH_ENTRY;
474  }
475  }
476  if (0 == count)
477  {
479  ("acl-plugin-warning: supplied no rules for ACL %d (tag %s)",
480  *acl_list_index, tag);
481  }
482 
483  void *oldheap = acl_set_heap (am);
484 
485  /* Create and populate the rules */
486  if (count > 0)
487  vec_validate (acl_new_rules, count - 1);
488 
489  for (i = 0; i < count; i++)
490  {
491  r = vec_elt_at_index (acl_new_rules, i);
492  clib_memset (r, 0, sizeof (*r));
493  r->is_permit = rules[i].is_permit;
494  r->is_ipv6 = rules[i].is_ipv6;
495  if (r->is_ipv6)
496  {
497  memcpy (&r->src, rules[i].src_ip_addr, sizeof (r->src));
498  memcpy (&r->dst, rules[i].dst_ip_addr, sizeof (r->dst));
499  }
500  else
501  {
502  memcpy (&r->src.ip4, rules[i].src_ip_addr, sizeof (r->src.ip4));
503  memcpy (&r->dst.ip4, rules[i].dst_ip_addr, sizeof (r->dst.ip4));
504  }
505  r->src_prefixlen = rules[i].src_ip_prefix_len;
506  r->dst_prefixlen = rules[i].dst_ip_prefix_len;
507  r->proto = rules[i].proto;
509  r->src_port_or_type_last = ntohs (rules[i].srcport_or_icmptype_last);
511  r->dst_port_or_code_last = ntohs (rules[i].dstport_or_icmpcode_last);
512  r->tcp_flags_value = rules[i].tcp_flags_value;
513  r->tcp_flags_mask = rules[i].tcp_flags_mask;
514  }
515 
516  if (~0 == *acl_list_index)
517  {
518  /* Get ACL index */
520  clib_memset (a, 0, sizeof (*a));
521  /* Will return the newly allocated ACL index */
522  *acl_list_index = a - am->acls;
523  }
524  else
525  {
526  a = am->acls + *acl_list_index;
527  /* Get rid of the old rules */
528  if (a->rules)
529  vec_free (a->rules);
530  }
531  a->rules = acl_new_rules;
532  memcpy (a->tag, tag, sizeof (a->tag));
533  if (am->trace_acl > 255)
534  warning_acl_print_acl (am->vlib_main, am, *acl_list_index);
535  if (am->reclassify_sessions)
536  {
537  /* a change in an ACLs if they are applied may mean a new policy epoch */
538  policy_notify_acl_change (am, *acl_list_index);
539  }
540 
541  /* stats segment expects global heap, so restore it temporarily */
542  clib_mem_set_heap (oldheap);
543  validate_and_reset_acl_counters (am, *acl_list_index);
544  oldheap = acl_set_heap (am);
545 
546  /* notify the lookup contexts about the ACL changes */
548  clib_mem_set_heap (oldheap);
549  return 0;
550 }
551 
552 static int
553 acl_is_used_by (u32 acl_index, u32 ** foo_index_vec_by_acl)
554 {
555  if (acl_index < vec_len (foo_index_vec_by_acl))
556  {
557  if (vec_len (vec_elt (foo_index_vec_by_acl, acl_index)) > 0)
558  {
559  /* ACL is applied somewhere. */
560  return 1;
561  }
562  }
563  return 0;
564 }
565 
566 static int
567 acl_del_list (u32 acl_list_index)
568 {
569  acl_main_t *am = &acl_main;
570  acl_list_t *a;
571  if (pool_is_free_index (am->acls, acl_list_index))
572  {
573  return VNET_API_ERROR_NO_SUCH_ENTRY;
574  }
575  if (acl_is_used_by (acl_list_index, am->input_sw_if_index_vec_by_acl))
576  return VNET_API_ERROR_ACL_IN_USE_INBOUND;
577  if (acl_is_used_by (acl_list_index, am->output_sw_if_index_vec_by_acl))
578  return VNET_API_ERROR_ACL_IN_USE_OUTBOUND;
579  /* lookup contexts cover other cases, not just inbound/outbound, so check that */
580  if (acl_is_used_by (acl_list_index, am->lc_index_vec_by_acl))
581  return VNET_API_ERROR_ACL_IN_USE_BY_LOOKUP_CONTEXT;
582 
583  void *oldheap = acl_set_heap (am);
584 
585  /* now we can delete the ACL itself */
586  a = pool_elt_at_index (am->acls, acl_list_index);
587  if (a->rules)
588  vec_free (a->rules);
589  pool_put (am->acls, a);
590  /* acl_list_index is now free, notify the lookup contexts */
592  clib_mem_set_heap (oldheap);
593  return 0;
594 }
595 
596 static int
598 {
599  u64 *p64 = (u64 *) p;
600  /* Be tolerant to null pointer */
601  if (0 == p)
602  return 0;
603 
604  while ((0ULL == *p64) && ((u8 *) p64 - p) < size)
605  {
606  p64++;
607  }
608  return (p64 - (u64 *) p) / 2;
609 }
610 
611 static int
613  u32 mask_len, u32 next_table_index,
614  u32 miss_next_index, u32 * table_index,
615  int is_add)
616 {
617  u32 nbuckets = 32;
618  u32 memory_size = 2 << 22;
619  u32 skip = count_skip (mask, mask_len);
620  u32 match = (mask_len / 16) - skip;
621  u8 *skip_mask_ptr = mask + 16 * skip;
622  u32 current_data_flag = 0;
623  int current_data_offset = 0;
624 
625  if (0 == match)
626  match = 1;
627 
628  void *oldheap = clib_mem_set_heap (cm->vlib_main->heap_base);
629  int ret = vnet_classify_add_del_table (cm, skip_mask_ptr, nbuckets,
630  memory_size, skip, match,
631  next_table_index, miss_next_index,
632  table_index, current_data_flag,
633  current_data_offset, is_add,
634  1 /* delete_chain */ );
635  clib_mem_set_heap (oldheap);
636  return ret;
637 }
638 
639 static int
641 {
642  u16 **v = is_input
645  u16 *whitelist = (vec_len (v) > sw_if_index) ? vec_elt (v, sw_if_index) : 0;
646  return vec_len (whitelist) > 0;
647 }
648 
649 static void
651 {
652  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
655  sw_if_index);
656  clib_mem_set_heap (oldheap);
657 }
658 
659 
660 static int
662  int enable_disable)
663 {
664  int rv = 0;
665 
666  /* Utterly wrong? */
668  sw_if_index))
669  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
670 
671  if (clib_bitmap_get (am->in_acl_on_sw_if_index, sw_if_index) ==
672  enable_disable)
673  return 0;
674 
675  acl_fa_enable_disable (sw_if_index, 1, enable_disable);
676 
677  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
678  rv = vnet_l2_feature_enable_disable ("l2-input-ip4", "acl-plugin-in-ip4-l2",
679  sw_if_index, enable_disable, 0, 0);
680  if (rv)
681  clib_error ("Could not enable on input");
682  rv = vnet_l2_feature_enable_disable ("l2-input-ip6", "acl-plugin-in-ip6-l2",
683  sw_if_index, enable_disable, 0, 0);
684  if (rv)
685  clib_error ("Could not enable on input");
686 
687  if (intf_has_etype_whitelist (am, sw_if_index, 1))
688  vnet_l2_feature_enable_disable ("l2-input-nonip",
689  "acl-plugin-in-nonip-l2", sw_if_index,
690  enable_disable, 0, 0);
691 
692  clib_mem_set_heap (oldheap);
693 
695  clib_bitmap_set (am->in_acl_on_sw_if_index, sw_if_index, enable_disable);
696 
697  return rv;
698 }
699 
700 static int
702  int enable_disable)
703 {
704  int rv = 0;
705 
706  /* Utterly wrong? */
708  sw_if_index))
709  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
710 
711  if (clib_bitmap_get (am->out_acl_on_sw_if_index, sw_if_index) ==
712  enable_disable)
713  return 0;
714 
715  acl_fa_enable_disable (sw_if_index, 0, enable_disable);
716 
717  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
718  rv =
719  vnet_l2_feature_enable_disable ("l2-output-ip4", "acl-plugin-out-ip4-l2",
720  sw_if_index, enable_disable, 0, 0);
721  if (rv)
722  clib_error ("Could not enable on output");
723  rv =
724  vnet_l2_feature_enable_disable ("l2-output-ip6", "acl-plugin-out-ip6-l2",
725  sw_if_index, enable_disable, 0, 0);
726  if (rv)
727  clib_error ("Could not enable on output");
728  if (intf_has_etype_whitelist (am, sw_if_index, 0))
729  vnet_l2_feature_enable_disable ("l2-output-nonip",
730  "acl-plugin-out-nonip-l2", sw_if_index,
731  enable_disable, 0, 0);
732 
733 
734  clib_mem_set_heap (oldheap);
735 
737  clib_bitmap_set (am->out_acl_on_sw_if_index, sw_if_index, enable_disable);
738 
739  return rv;
740 }
741 
742 static int
744 {
745  int rv = 0;
746 
747  am->interface_acl_counters_enabled = enable_disable;
748 
749  return rv;
750 }
751 
752 static int
754  int is_input, int enable_disable)
755 {
756  if (is_input)
757  return acl_interface_in_enable_disable (am, sw_if_index, enable_disable);
758  else
759  return acl_interface_out_enable_disable (am, sw_if_index, enable_disable);
760 }
761 
762 static int
763 acl_is_not_defined (acl_main_t * am, u32 acl_list_index)
764 {
765  return (pool_is_free_index (am->acls, acl_list_index));
766 }
767 
768 static int
770  u8 is_input, u32 * vec_acl_list_index,
771  int *may_clear_sessions)
772 {
773  u32 *pacln;
774  uword *seen_acl_bitmap = 0;
775  uword *old_seen_acl_bitmap = 0;
776  uword *change_acl_bitmap = 0;
777  int acln;
778  int rv = 0;
779 
780 
781  if (am->trace_acl > 255)
783  ("API dbg: acl_interface_set_inout_acl_list: sw_if_index %d is_input %d acl_vec: [%U]",
784  sw_if_index, is_input, format_vec32, vec_acl_list_index, "%d");
785 
786  vec_foreach (pacln, vec_acl_list_index)
787  {
788  if (acl_is_not_defined (am, *pacln))
789  {
790  /* ACL is not defined. Can not apply */
791  clib_warning ("ERROR: ACL %d not defined", *pacln);
792  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
793  goto done;
794  }
795  if (clib_bitmap_get (seen_acl_bitmap, *pacln))
796  {
797  /* ACL being applied twice within the list. error. */
798  clib_warning ("ERROR: ACL %d being applied twice", *pacln);
799  rv = VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
800  goto done;
801  }
802  seen_acl_bitmap = clib_bitmap_set (seen_acl_bitmap, *pacln, 1);
803  }
804 
805 
806  u32 **pinout_lc_index_by_sw_if_index =
807  is_input ? &am->
808  input_lc_index_by_sw_if_index : &am->output_lc_index_by_sw_if_index;
809 
810  u32 ***pinout_acl_vec_by_sw_if_index =
811  is_input ? &am->
812  input_acl_vec_by_sw_if_index : &am->output_acl_vec_by_sw_if_index;
813 
814  u32 ***pinout_sw_if_index_vec_by_acl =
815  is_input ? &am->
816  input_sw_if_index_vec_by_acl : &am->output_sw_if_index_vec_by_acl;
817 
818  vec_validate ((*pinout_acl_vec_by_sw_if_index), sw_if_index);
819 
820  clib_bitmap_validate (old_seen_acl_bitmap, 1);
821 
822  vec_foreach (pacln, (*pinout_acl_vec_by_sw_if_index)[sw_if_index])
823  {
824  old_seen_acl_bitmap = clib_bitmap_set (old_seen_acl_bitmap, *pacln, 1);
825  }
826  change_acl_bitmap =
827  clib_bitmap_dup_xor (old_seen_acl_bitmap, seen_acl_bitmap);
828 
829  if (am->trace_acl > 255)
830  clib_warning ("bitmaps: old seen %U new seen %U changed %U",
831  format_bitmap_hex, old_seen_acl_bitmap, format_bitmap_hex,
832  seen_acl_bitmap, format_bitmap_hex, change_acl_bitmap);
833 
834 /* *INDENT-OFF* */
835  clib_bitmap_foreach(acln, change_acl_bitmap, ({
836  if (clib_bitmap_get(old_seen_acl_bitmap, acln)) {
837  /* ACL is being removed. */
838  if (acln < vec_len((*pinout_sw_if_index_vec_by_acl))) {
839  int index = vec_search((*pinout_sw_if_index_vec_by_acl)[acln], sw_if_index);
840  vec_del1((*pinout_sw_if_index_vec_by_acl)[acln], index);
841  }
842  } else {
843  /* ACL is being added. */
844  vec_validate((*pinout_sw_if_index_vec_by_acl), acln);
845  vec_add1((*pinout_sw_if_index_vec_by_acl)[acln], sw_if_index);
846  }
847  }));
848 /* *INDENT-ON* */
849 
850  vec_free ((*pinout_acl_vec_by_sw_if_index)[sw_if_index]);
851  (*pinout_acl_vec_by_sw_if_index)[sw_if_index] =
852  vec_dup (vec_acl_list_index);
853 
854  if (am->reclassify_sessions)
855  {
856  /* re-applying ACLs means a new policy epoch */
857  increment_policy_epoch (am, sw_if_index, is_input);
858  }
859  else
860  {
861  /* if no commonalities between the ACL# - then we should definitely clear the sessions */
862  if (may_clear_sessions && *may_clear_sessions
863  && !clib_bitmap_is_zero (change_acl_bitmap))
864  {
865  acl_clear_sessions (am, sw_if_index);
866  *may_clear_sessions = 0;
867  }
868  }
869 
870  /*
871  * prepare or delete the lookup context if necessary, and if context exists, set ACL list
872  */
873  vec_validate_init_empty ((*pinout_lc_index_by_sw_if_index), sw_if_index,
874  ~0);
875  if (vec_len (vec_acl_list_index) > 0)
876  {
877  u32 lc_index = (*pinout_lc_index_by_sw_if_index)[sw_if_index];
878  if (~0 == lc_index)
879  {
880  lc_index =
881  acl_plugin.get_lookup_context_index (am->interface_acl_user_id,
882  sw_if_index, is_input);
883  (*pinout_lc_index_by_sw_if_index)[sw_if_index] = lc_index;
884  }
885  acl_plugin.set_acl_vec_for_context (lc_index, vec_acl_list_index);
886  }
887  else
888  {
889  if (~0 != (*pinout_lc_index_by_sw_if_index)[sw_if_index])
890  {
891  acl_plugin.put_lookup_context_index ((*pinout_lc_index_by_sw_if_index)[sw_if_index]);
892  (*pinout_lc_index_by_sw_if_index)[sw_if_index] = ~0;
893  }
894  }
895 
896  /* ensure ACL processing is enabled/disabled as needed */
897  acl_interface_inout_enable_disable (am, sw_if_index, is_input,
898  vec_len (vec_acl_list_index) > 0);
899 
900 done:
901  clib_bitmap_free (change_acl_bitmap);
902  clib_bitmap_free (seen_acl_bitmap);
903  clib_bitmap_free (old_seen_acl_bitmap);
904  return rv;
905 }
906 
907 static void
909  int *may_clear_sessions)
910 {
911  acl_main_t *am = &acl_main;
912  void *oldheap = acl_set_heap (am);
913  acl_interface_set_inout_acl_list (am, sw_if_index, is_input, 0,
914  may_clear_sessions);
915  clib_mem_set_heap (oldheap);
916 }
917 
918 static int
920  u32 acl_list_index)
921 {
922 
923  acl_main_t *am = &acl_main;
924  u32 *acl_vec = 0;
925  int may_clear_sessions = 1;
926 
927  int error_already_applied = is_input ? VNET_API_ERROR_ACL_IN_USE_INBOUND
928  : VNET_API_ERROR_ACL_IN_USE_OUTBOUND;
929 
930  u32 ***pinout_acl_vec_by_sw_if_index =
931  is_input ? &am->
932  input_acl_vec_by_sw_if_index : &am->output_acl_vec_by_sw_if_index;
933  int rv = 0;
934  void *oldheap = acl_set_heap (am);
935 
936  if (is_add)
937  {
938  vec_validate ((*pinout_acl_vec_by_sw_if_index), sw_if_index);
939  u32 index = vec_search ((*pinout_acl_vec_by_sw_if_index)[sw_if_index],
940  acl_list_index);
941 
942  if (~0 != index)
943  {
944  rv = error_already_applied;
945  goto done;
946  }
947 
948  acl_vec = vec_dup ((*pinout_acl_vec_by_sw_if_index)[sw_if_index]);
949  vec_add1 (acl_vec, acl_list_index);
950  }
951  else
952  {
953  if (sw_if_index >= vec_len (*pinout_acl_vec_by_sw_if_index))
954  {
955  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
956  goto done;
957  }
958 
959  u32 index = vec_search ((*pinout_acl_vec_by_sw_if_index)[sw_if_index],
960  acl_list_index);
961 
962  if (~0 == index)
963  {
964  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
965  goto done;
966  }
967 
968  acl_vec = vec_dup ((*pinout_acl_vec_by_sw_if_index)[sw_if_index]);
969  vec_del1 (acl_vec, index);
970  }
971 
972  rv = acl_interface_set_inout_acl_list (am, sw_if_index, is_input, acl_vec,
973  &may_clear_sessions);
974 done:
975  vec_free (acl_vec);
976  clib_mem_set_heap (oldheap);
977  return rv;
978 }
979 
980 static int
982  u16 * vec_out)
983 {
986 
989 
992 
993  /*
994  * if there are already inbound/outbound ACLs applied, toggle the
995  * enable/disable - this will recreate the necessary tables.
996  */
997 
998  if (vec_len (am->input_acl_vec_by_sw_if_index) > sw_if_index)
999  {
1000  if (vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]) > 0)
1001  {
1002  acl_interface_in_enable_disable (am, sw_if_index, 0);
1003  acl_interface_in_enable_disable (am, sw_if_index, 1);
1004  }
1005  }
1006  if (vec_len (am->output_acl_vec_by_sw_if_index) > sw_if_index)
1007  {
1008  if (vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]) > 0)
1009  {
1010  acl_interface_out_enable_disable (am, sw_if_index, 0);
1011  acl_interface_out_enable_disable (am, sw_if_index, 1);
1012  }
1013  }
1014  return 0;
1015 }
1016 
1017 
1018 typedef struct
1019 {
1022  u8 mac_mask[6];
1031  /* egress tables */
1039 
1040 static u32
1041 macip_find_match_type (macip_match_type_t * mv, u8 * mac_mask, u8 prefix_len,
1042  u8 is_ipv6)
1043 {
1044  u32 i;
1045  if (mv)
1046  {
1047  for (i = 0; i < vec_len (mv); i++)
1048  {
1049  if ((mv[i].prefix_len == prefix_len) && (mv[i].is_ipv6 == is_ipv6)
1050  && (0 == memcmp (mv[i].mac_mask, mac_mask, 6)))
1051  {
1052  return i;
1053  }
1054  }
1055  }
1056  return ~0;
1057 }
1058 
1059 
1060 /* Get metric used to sort match types.
1061  The more specific and the more often seen - the bigger the metric */
1062 static int
1064 {
1065  unsigned int mac_bits_set = 0;
1066  unsigned int mac_byte;
1067  int i;
1068  for (i = 0; i < 6; i++)
1069  {
1070  mac_byte = m->mac_mask[i];
1071  for (; mac_byte; mac_byte >>= 1)
1072  mac_bits_set += mac_byte & 1;
1073  }
1074  /*
1075  * Attempt to place the more specific and the more used rules on top.
1076  * There are obvious caveat corner cases to this, but they do not
1077  * seem to be sensible in real world (e.g. specific IPv4 with wildcard MAC
1078  * going with a wildcard IPv4 with a specific MAC).
1079  */
1080  return m->prefix_len + mac_bits_set + m->is_ipv6 + 10 * m->count;
1081 }
1082 
1083 static int
1085 {
1086  /* Ascending sort based on the metric values */
1087  return match_type_metric (m1) - match_type_metric (m2);
1088 }
1089 
1090 /* Get the offset of L3 source within ethernet packet */
1091 static int
1093 {
1094  if (is6)
1095  return (sizeof (ethernet_header_t) +
1096  offsetof (ip6_header_t, src_address));
1097  else
1098  return (sizeof (ethernet_header_t) +
1099  offsetof (ip4_header_t, src_address));
1100 }
1101 
1102 static int
1104 {
1105  if (is6)
1106  return (sizeof (ethernet_header_t) +
1107  offsetof (ip6_header_t, dst_address));
1108  else
1109  return (sizeof (ethernet_header_t) +
1110  offsetof (ip4_header_t, dst_address));
1111 }
1112 
1113 /*
1114  * return if the is_permit value also requires to create the egress tables
1115  * For backwards compatibility, we keep the is_permit = 1 to only
1116  * create the ingress tables, and the new value of 3 will also
1117  * create the egress tables based on destination.
1118  */
1119 static int
1121 {
1122  return (is_permit == 3);
1123 }
1124 
1125 static int
1127 {
1128  macip_match_type_t *mvec = NULL;
1129  macip_match_type_t *mt;
1130  macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1131  int i;
1132  u32 match_type_index;
1133  u32 last_table;
1134  u32 out_last_table;
1135  u8 mask[5 * 16];
1137 
1138  /* Count the number of different types of rules */
1139  for (i = 0; i < a->count; i++)
1140  {
1141  if (~0 ==
1142  (match_type_index =
1144  a->rules[i].src_prefixlen,
1145  a->rules[i].is_ipv6)))
1146  {
1147  match_type_index = vec_len (mvec);
1148  vec_validate (mvec, match_type_index);
1149  memcpy (mvec[match_type_index].mac_mask,
1150  a->rules[i].src_mac_mask, 6);
1151  mvec[match_type_index].prefix_len = a->rules[i].src_prefixlen;
1152  mvec[match_type_index].is_ipv6 = a->rules[i].is_ipv6;
1153  mvec[match_type_index].has_egress = 0;
1154  mvec[match_type_index].table_index = ~0;
1155  mvec[match_type_index].arp_table_index = ~0;
1156  mvec[match_type_index].dot1q_table_index = ~0;
1157  mvec[match_type_index].dot1ad_table_index = ~0;
1158  mvec[match_type_index].arp_dot1q_table_index = ~0;
1159  mvec[match_type_index].arp_dot1ad_table_index = ~0;
1160  mvec[match_type_index].out_table_index = ~0;
1161  mvec[match_type_index].out_arp_table_index = ~0;
1162  mvec[match_type_index].out_dot1q_table_index = ~0;
1163  mvec[match_type_index].out_dot1ad_table_index = ~0;
1164  mvec[match_type_index].out_arp_dot1q_table_index = ~0;
1165  mvec[match_type_index].out_arp_dot1ad_table_index = ~0;
1166  }
1167  mvec[match_type_index].count++;
1168  mvec[match_type_index].has_egress |=
1170  }
1171  /* Put the most frequently used tables last in the list so we can create classifier tables in reverse order */
1173  /* Create the classifier tables */
1174  last_table = ~0;
1175  out_last_table = ~0;
1176  /* First add ARP tables */
1177  vec_foreach (mt, mvec)
1178  {
1179  int mask_len;
1180  int is6 = mt->is_ipv6;
1181  int tags;
1182  u32 *last_tag_table;
1183  u32 *out_last_tag_table;
1184  u32 l3_offset;
1185 
1186  if (!is6)
1187  {
1188  /*
1189  0 1 2 3
1190  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
1191  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1192  | Destination Address |
1193  + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1194  | | |
1195  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
1196  | Source Address |
1197  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1198  | EtherType | Hardware Type |
1199  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1200  | Protocol Type | Hw addr len | Proto addr len|
1201  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1202  | Opcode | |
1203  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
1204  | Sender Hardware Address |
1205  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1206  | Sender Protocol Address |
1207  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1208  | Target Hardware Address |
1209  + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1210  | | TargetProtocolAddress |
1211  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1212  | |
1213  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1214  */
1215  for (tags = 2; tags >= 0; tags--)
1216  {
1217  clib_memset (mask, 0, sizeof (mask));
1218  /* source MAC address */
1219  memcpy (&mask[6], mt->mac_mask, 6);
1220 
1221  switch (tags)
1222  {
1223  case 0:
1224  default:
1225  clib_memset (&mask[12], 0xff, 2); /* ethernet protocol */
1226  l3_offset = 14;
1227  last_tag_table = &mt->arp_table_index;
1228  break;
1229  case 1:
1230  clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1231  clib_memset (&mask[16], 0xff, 2); /* ethernet protocol */
1232  l3_offset = 18;
1233  last_tag_table = &mt->arp_dot1q_table_index;
1234  break;
1235  case 2:
1236  clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1237  clib_memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1238  clib_memset (&mask[20], 0xff, 2); /* ethernet protocol */
1239  l3_offset = 22;
1240  last_tag_table = &mt->arp_dot1ad_table_index;
1241  break;
1242  }
1243 
1244  /* sender hardware address within ARP */
1245  memcpy (&mask[l3_offset + 8], mt->mac_mask, 6);
1246  /* sender protocol address within ARP */
1247  for (i = 0; i < (mt->prefix_len / 8); i++)
1248  mask[l3_offset + 14 + i] = 0xff;
1249  if (mt->prefix_len % 8)
1250  mask[l3_offset + 14 + (mt->prefix_len / 8)] =
1251  0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1252 
1253  mask_len = ((l3_offset + 14 + ((mt->prefix_len + 7) / 8) +
1254  (sizeof (u32x4) -
1255  1)) / sizeof (u32x4)) * sizeof (u32x4);
1256  acl_classify_add_del_table_small (cm, mask, mask_len, last_table,
1257  (~0 == last_table) ? 0 : ~0,
1258  last_tag_table, 1);
1259  last_table = *last_tag_table;
1260  if (mt->has_egress)
1261  {
1262  /* egress ARP table */
1263  clib_memset (mask, 0, sizeof (mask));
1264 
1265  switch (tags)
1266  {
1267  case 0:
1268  default:
1269  clib_memset (&mask[12], 0xff, 2); /* ethernet protocol */
1270  l3_offset = 14;
1271  out_last_tag_table = &mt->out_arp_table_index;
1272  break;
1273  case 1:
1274  clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1275  clib_memset (&mask[16], 0xff, 2); /* ethernet protocol */
1276  l3_offset = 18;
1277  out_last_tag_table = &mt->out_arp_dot1q_table_index;
1278  break;
1279  case 2:
1280  clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1281  clib_memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1282  clib_memset (&mask[20], 0xff, 2); /* ethernet protocol */
1283  l3_offset = 22;
1284  out_last_tag_table = &mt->out_arp_dot1ad_table_index;
1285  break;
1286  }
1287 
1288  /* AYXX: FIXME here - can we tighten the ARP-related table more ? */
1289  /* mask captures just the destination and the ethertype */
1290  mask_len = ((l3_offset +
1291  (sizeof (u32x4) -
1292  1)) / sizeof (u32x4)) * sizeof (u32x4);
1293  acl_classify_add_del_table_small (cm, mask, mask_len,
1294  out_last_table,
1295  (~0 ==
1296  out_last_table) ? 0 : ~0,
1297  out_last_tag_table, 1);
1298  out_last_table = *out_last_tag_table;
1299  }
1300  }
1301  }
1302  }
1303  /* Now add IP[46] tables */
1304  vec_foreach (mt, mvec)
1305  {
1306  int mask_len;
1307  int is6 = mt->is_ipv6;
1308  int l3_src_offs;
1309  int l3_dst_offs;
1310  int tags;
1311  u32 *last_tag_table;
1312  u32 *out_last_tag_table;
1313 
1314  /*
1315  * create chained tables for VLAN (no-tags, dot1q and dot1ad) packets
1316  */
1317  for (tags = 2; tags >= 0; tags--)
1318  {
1319  clib_memset (mask, 0, sizeof (mask));
1320  memcpy (&mask[6], mt->mac_mask, 6);
1321  l3_src_offs = tags * 4 + get_l3_src_offset (is6);
1322  switch (tags)
1323  {
1324  case 0:
1325  default:
1326  clib_memset (&mask[12], 0xff, 2); /* ethernet protocol */
1327  last_tag_table = &mt->table_index;
1328  break;
1329  case 1:
1330  clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1331  clib_memset (&mask[16], 0xff, 2); /* ethernet protocol */
1332  last_tag_table = &mt->dot1q_table_index;
1333  break;
1334  case 2:
1335  clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1336  clib_memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1337  clib_memset (&mask[20], 0xff, 2); /* ethernet protocol */
1338  last_tag_table = &mt->dot1ad_table_index;
1339  break;
1340  }
1341  for (i = 0; i < (mt->prefix_len / 8); i++)
1342  {
1343  mask[l3_src_offs + i] = 0xff;
1344  }
1345  if (mt->prefix_len % 8)
1346  {
1347  mask[l3_src_offs + (mt->prefix_len / 8)] =
1348  0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1349  }
1350  /*
1351  * Round-up the number of bytes needed to store the prefix,
1352  * and round up the number of vectors too
1353  */
1354  mask_len = ((l3_src_offs + ((mt->prefix_len + 7) / 8) +
1355  (sizeof (u32x4) - 1)) / sizeof (u32x4)) * sizeof (u32x4);
1356  acl_classify_add_del_table_small (cm, mask, mask_len, last_table,
1357  (~0 == last_table) ? 0 : ~0,
1358  last_tag_table, 1);
1359  last_table = *last_tag_table;
1360  }
1361  if (mt->has_egress)
1362  {
1363  for (tags = 2; tags >= 0; tags--)
1364  {
1365  clib_memset (mask, 0, sizeof (mask));
1366  /* MAC destination */
1367  memcpy (&mask[0], mt->mac_mask, 6);
1368  l3_dst_offs = tags * 4 + get_l3_dst_offset (is6);
1369  switch (tags)
1370  {
1371  case 0:
1372  default:
1373  clib_memset (&mask[12], 0xff, 2); /* ethernet protocol */
1374  out_last_tag_table = &mt->out_table_index;
1375  break;
1376  case 1:
1377  clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1378  clib_memset (&mask[16], 0xff, 2); /* ethernet protocol */
1379  out_last_tag_table = &mt->out_dot1q_table_index;
1380  break;
1381  case 2:
1382  clib_memset (&mask[12], 0xff, 2); /* VLAN tag1 */
1383  clib_memset (&mask[16], 0xff, 2); /* VLAN tag2 */
1384  clib_memset (&mask[20], 0xff, 2); /* ethernet protocol */
1385  out_last_tag_table = &mt->out_dot1ad_table_index;
1386  break;
1387  }
1388  for (i = 0; i < (mt->prefix_len / 8); i++)
1389  {
1390  mask[l3_dst_offs + i] = 0xff;
1391  }
1392  if (mt->prefix_len % 8)
1393  {
1394  mask[l3_dst_offs + (mt->prefix_len / 8)] =
1395  0xff - ((1 << (8 - mt->prefix_len % 8)) - 1);
1396  }
1397  /*
1398  * Round-up the number of bytes needed to store the prefix,
1399  * and round up the number of vectors too
1400  */
1401  mask_len = ((l3_dst_offs + ((mt->prefix_len + 7) / 8) +
1402  (sizeof (u32x4) -
1403  1)) / sizeof (u32x4)) * sizeof (u32x4);
1404  acl_classify_add_del_table_small (cm, mask, mask_len,
1405  out_last_table,
1406  (~0 == out_last_table) ? 0 : ~0,
1407  out_last_tag_table, 1);
1408  out_last_table = *out_last_tag_table;
1409  }
1410  }
1411  }
1412  a->ip4_table_index = last_table;
1413  a->ip6_table_index = last_table;
1414  a->l2_table_index = last_table;
1415 
1416  a->out_ip4_table_index = out_last_table;
1417  a->out_ip6_table_index = out_last_table;
1418  a->out_l2_table_index = out_last_table;
1419 
1420  /* Populate the classifier tables with rules from the MACIP ACL */
1421  for (i = 0; i < a->count; i++)
1422  {
1423  u32 action = 0;
1424  u32 metadata = 0;
1425  int is6 = a->rules[i].is_ipv6;
1426  int l3_src_offs;
1427  int l3_dst_offs;
1428  u32 tag_table;
1429  int tags, eth;
1430 
1431  match_type_index =
1433  a->rules[i].src_prefixlen,
1434  a->rules[i].is_ipv6);
1435  ASSERT (match_type_index != ~0);
1436 
1437  for (tags = 2; tags >= 0; tags--)
1438  {
1439  clib_memset (mask, 0, sizeof (mask));
1440  l3_src_offs = tags * 4 + get_l3_src_offset (is6);
1441  memcpy (&mask[6], a->rules[i].src_mac, 6);
1442  switch (tags)
1443  {
1444  case 0:
1445  default:
1446  tag_table = mvec[match_type_index].table_index;
1447  eth = 12;
1448  break;
1449  case 1:
1450  tag_table = mvec[match_type_index].dot1q_table_index;
1451  mask[12] = 0x81;
1452  mask[13] = 0x00;
1453  eth = 16;
1454  break;
1455  case 2:
1456  tag_table = mvec[match_type_index].dot1ad_table_index;
1457  mask[12] = 0x88;
1458  mask[13] = 0xa8;
1459  mask[16] = 0x81;
1460  mask[17] = 0x00;
1461  eth = 20;
1462  break;
1463  }
1464  if (is6)
1465  {
1466  memcpy (&mask[l3_src_offs], &a->rules[i].src_ip_addr.ip6, 16);
1467  mask[eth] = 0x86;
1468  mask[eth + 1] = 0xdd;
1469  }
1470  else
1471  {
1472  memcpy (&mask[l3_src_offs], &a->rules[i].src_ip_addr.ip4, 4);
1473  mask[eth] = 0x08;
1474  mask[eth + 1] = 0x00;
1475  }
1476 
1477  /* add session to table mvec[match_type_index].table_index; */
1478  vnet_classify_add_del_session (cm, tag_table,
1479  mask, a->rules[i].is_permit ? ~0 : 0,
1480  i, 0, action, metadata, 1);
1481  clib_memset (&mask[12], 0, sizeof (mask) - 12);
1482  }
1483 
1484  /* add ARP table entry too */
1485  if (!is6 && (mvec[match_type_index].arp_table_index != ~0))
1486  {
1487  clib_memset (mask, 0, sizeof (mask));
1488  memcpy (&mask[6], a->rules[i].src_mac, 6);
1489 
1490  for (tags = 2; tags >= 0; tags--)
1491  {
1492  switch (tags)
1493  {
1494  case 0:
1495  default:
1496  tag_table = mvec[match_type_index].arp_table_index;
1497  mask[12] = 0x08;
1498  mask[13] = 0x06;
1499  l3_src_offs = 14;
1500  break;
1501  case 1:
1502  tag_table = mvec[match_type_index].arp_dot1q_table_index;
1503  mask[12] = 0x81;
1504  mask[13] = 0x00;
1505  mask[16] = 0x08;
1506  mask[17] = 0x06;
1507  l3_src_offs = 18;
1508  break;
1509  case 2:
1510  tag_table = mvec[match_type_index].arp_dot1ad_table_index;
1511  mask[12] = 0x88;
1512  mask[13] = 0xa8;
1513  mask[16] = 0x81;
1514  mask[17] = 0x00;
1515  mask[20] = 0x08;
1516  mask[21] = 0x06;
1517  l3_src_offs = 22;
1518  break;
1519  }
1520 
1521  memcpy (&mask[l3_src_offs + 8], a->rules[i].src_mac, 6);
1522  memcpy (&mask[l3_src_offs + 14], &a->rules[i].src_ip_addr.ip4,
1523  4);
1524  vnet_classify_add_del_session (cm, tag_table, mask,
1525  a->rules[i].is_permit ? ~0 : 0,
1526  i, 0, action, metadata, 1);
1527  }
1528  }
1530  {
1531  /* Add the egress entry with destination set */
1532  for (tags = 2; tags >= 0; tags--)
1533  {
1534  clib_memset (mask, 0, sizeof (mask));
1535  l3_dst_offs = tags * 4 + get_l3_dst_offset (is6);
1536  /* src mac in the other direction becomes dst */
1537  memcpy (&mask[0], a->rules[i].src_mac, 6);
1538  switch (tags)
1539  {
1540  case 0:
1541  default:
1542  tag_table = mvec[match_type_index].out_table_index;
1543  eth = 12;
1544  break;
1545  case 1:
1546  tag_table = mvec[match_type_index].out_dot1q_table_index;
1547  mask[12] = 0x81;
1548  mask[13] = 0x00;
1549  eth = 16;
1550  break;
1551  case 2:
1552  tag_table = mvec[match_type_index].out_dot1ad_table_index;
1553  mask[12] = 0x88;
1554  mask[13] = 0xa8;
1555  mask[16] = 0x81;
1556  mask[17] = 0x00;
1557  eth = 20;
1558  break;
1559  }
1560  if (is6)
1561  {
1562  memcpy (&mask[l3_dst_offs], &a->rules[i].src_ip_addr.ip6,
1563  16);
1564  mask[eth] = 0x86;
1565  mask[eth + 1] = 0xdd;
1566  }
1567  else
1568  {
1569  memcpy (&mask[l3_dst_offs], &a->rules[i].src_ip_addr.ip4,
1570  4);
1571  mask[eth] = 0x08;
1572  mask[eth + 1] = 0x00;
1573  }
1574 
1575  /* add session to table mvec[match_type_index].table_index; */
1576  vnet_classify_add_del_session (cm, tag_table,
1577  mask,
1578  a->rules[i].is_permit ? ~0 : 0,
1579  i, 0, action, metadata, 1);
1580  // clib_memset (&mask[12], 0, sizeof (mask) - 12);
1581  }
1582 
1583  /* add ARP table entry too */
1584  if (!is6 && (mvec[match_type_index].out_arp_table_index != ~0))
1585  {
1586  for (tags = 2; tags >= 0; tags--)
1587  {
1588  clib_memset (mask, 0, sizeof (mask));
1589  switch (tags)
1590  {
1591  case 0:
1592  default:
1593  tag_table = mvec[match_type_index].out_arp_table_index;
1594  mask[12] = 0x08;
1595  mask[13] = 0x06;
1596  break;
1597  case 1:
1598  tag_table =
1599  mvec[match_type_index].out_arp_dot1q_table_index;
1600  mask[12] = 0x81;
1601  mask[13] = 0x00;
1602  mask[16] = 0x08;
1603  mask[17] = 0x06;
1604  break;
1605  case 2:
1606  tag_table =
1607  mvec[match_type_index].out_arp_dot1ad_table_index;
1608  mask[12] = 0x88;
1609  mask[13] = 0xa8;
1610  mask[16] = 0x81;
1611  mask[17] = 0x00;
1612  mask[20] = 0x08;
1613  mask[21] = 0x06;
1614  break;
1615  }
1616 
1617  vnet_classify_add_del_session (cm, tag_table,
1618  mask,
1619  a->
1620  rules[i].is_permit ? ~0 : 0,
1621  i, 0, action, metadata, 1);
1622  }
1623  }
1624  }
1625  }
1626  return 0;
1627 }
1628 
1629 static void
1631 {
1633  macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1634 
1635  if (a->ip4_table_index != ~0)
1636  {
1637  acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1638  &a->ip4_table_index, 0);
1639  a->ip4_table_index = ~0;
1640  }
1641  if (a->ip6_table_index != ~0)
1642  {
1643  acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1644  &a->ip6_table_index, 0);
1645  a->ip6_table_index = ~0;
1646  }
1647  if (a->l2_table_index != ~0)
1648  {
1649  acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0, &a->l2_table_index,
1650  0);
1651  a->l2_table_index = ~0;
1652  }
1653  if (a->out_ip4_table_index != ~0)
1654  {
1655  acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1656  &a->out_ip4_table_index, 0);
1657  a->out_ip4_table_index = ~0;
1658  }
1659  if (a->out_ip6_table_index != ~0)
1660  {
1661  acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1662  &a->out_ip6_table_index, 0);
1663  a->out_ip6_table_index = ~0;
1664  }
1665  if (a->out_l2_table_index != ~0)
1666  {
1667  acl_classify_add_del_table_small (cm, 0, ~0, ~0, ~0,
1668  &a->out_l2_table_index, 0);
1669  a->out_l2_table_index = ~0;
1670  }
1671 }
1672 
1673 static int
1675  int is_apply)
1676 {
1677  int rv = 0;
1678  int rv0 = 0;
1679  int i;
1680  macip_acl_list_t *a = pool_elt_at_index (am->macip_acls, acl_index);
1681 
1682  for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
1683  if (vec_elt (am->macip_acl_by_sw_if_index, i) == acl_index)
1684  {
1687  is_apply);
1688  /* return the first unhappy outcome but make try to plough through. */
1689  rv = rv || rv0;
1690  rv0 =
1693  a->out_l2_table_index, is_apply);
1694  /* return the first unhappy outcome but make try to plough through. */
1695  rv = rv || rv0;
1696  }
1697  return rv;
1698 }
1699 
1700 static int
1701 macip_acl_add_list (u32 count, vl_api_macip_acl_rule_t rules[],
1702  u32 * acl_list_index, u8 * tag)
1703 {
1704  acl_main_t *am = &acl_main;
1706  macip_acl_rule_t *r;
1707  macip_acl_rule_t *acl_new_rules = 0;
1708  int i;
1709  int rv = 0;
1710 
1711  if (*acl_list_index != ~0)
1712  {
1713  /* They supplied some number, let's see if this MACIP ACL exists */
1714  if (pool_is_free_index (am->macip_acls, *acl_list_index))
1715  {
1716  /* tried to replace a non-existent ACL, no point doing anything */
1717  clib_warning
1718  ("acl-plugin-error: Trying to replace nonexistent MACIP ACL %d (tag %s)",
1719  *acl_list_index, tag);
1720  return VNET_API_ERROR_NO_SUCH_ENTRY;
1721  }
1722  }
1723 
1724  if (0 == count)
1725  {
1726  clib_warning
1727  ("acl-plugin-warning: Trying to create empty MACIP ACL (tag %s)",
1728  tag);
1729  }
1730  /* if replacing the ACL, unapply the classifier tables first - they will be gone.. */
1731  if (~0 != *acl_list_index)
1732  rv = macip_maybe_apply_unapply_classifier_tables (am, *acl_list_index, 0);
1733  void *oldheap = acl_set_heap (am);
1734  /* Create and populate the rules */
1735  if (count > 0)
1736  vec_validate (acl_new_rules, count - 1);
1737 
1738  for (i = 0; i < count; i++)
1739  {
1740  r = &acl_new_rules[i];
1741  r->is_permit = rules[i].is_permit;
1742  r->is_ipv6 = rules[i].is_ipv6;
1743  memcpy (&r->src_mac, rules[i].src_mac, 6);
1744  memcpy (&r->src_mac_mask, rules[i].src_mac_mask, 6);
1745  if (rules[i].is_ipv6)
1746  memcpy (&r->src_ip_addr.ip6, rules[i].src_ip_addr, 16);
1747  else
1748  memcpy (&r->src_ip_addr.ip4, rules[i].src_ip_addr, 4);
1749  r->src_prefixlen = rules[i].src_ip_prefix_len;
1750  }
1751 
1752  if (~0 == *acl_list_index)
1753  {
1754  /* Get ACL index */
1756  clib_memset (a, 0, sizeof (*a));
1757  /* Will return the newly allocated ACL index */
1758  *acl_list_index = a - am->macip_acls;
1759  }
1760  else
1761  {
1762  a = pool_elt_at_index (am->macip_acls, *acl_list_index);
1763  if (a->rules)
1764  {
1765  vec_free (a->rules);
1766  }
1767  macip_destroy_classify_tables (am, *acl_list_index);
1768  }
1769 
1770  a->rules = acl_new_rules;
1771  a->count = count;
1772  memcpy (a->tag, tag, sizeof (a->tag));
1773 
1774  /* Create and populate the classifier tables */
1775  macip_create_classify_tables (am, *acl_list_index);
1776  clib_mem_set_heap (oldheap);
1777  /* If the ACL was already applied somewhere, reapply the newly created tables */
1778  rv = rv
1779  || macip_maybe_apply_unapply_classifier_tables (am, *acl_list_index, 1);
1780  return rv;
1781 }
1782 
1783 /* No check that sw_if_index denotes a valid interface - the callers
1784  * were supposed to validate.
1785  *
1786  * That said, if sw_if_index corresponds to an interface that exists at all,
1787  * this function must return errors accordingly if the ACL is not applied.
1788  */
1789 
1790 static int
1792 {
1793  int rv;
1794  u32 macip_acl_index;
1796 
1797  /* The vector is too short - MACIP ACL is not applied */
1798  if (sw_if_index >= vec_len (am->macip_acl_by_sw_if_index))
1799  return VNET_API_ERROR_NO_SUCH_ENTRY;
1800 
1801  macip_acl_index = am->macip_acl_by_sw_if_index[sw_if_index];
1802  /* No point in deleting MACIP ACL which is not applied */
1803  if (~0 == macip_acl_index)
1804  return VNET_API_ERROR_NO_SUCH_ENTRY;
1805 
1806  a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1807  /* remove the classifier tables off the interface L2 ACL */
1808  rv =
1809  vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
1810  a->ip6_table_index, a->l2_table_index, 0);
1811  rv |=
1812  vnet_set_output_acl_intfc (am->vlib_main, sw_if_index,
1814  a->out_l2_table_index, 0);
1815  /* Unset the MACIP ACL index */
1817  /* macip_acl_interface_add_acl did a vec_add1() to this previously, so [sw_if_index] should be valid */
1818  u32 index = vec_search (am->sw_if_index_vec_by_macip_acl[macip_acl_index],
1819  sw_if_index);
1820  if (index != ~0)
1821  vec_del1 (am->sw_if_index_vec_by_macip_acl[macip_acl_index], index);
1822  return rv;
1823 }
1824 
1825 /* No check for validity of sw_if_index - the callers were supposed to validate */
1826 
1827 static int
1829  u32 macip_acl_index)
1830 {
1832  int rv;
1833  if (pool_is_free_index (am->macip_acls, macip_acl_index))
1834  {
1835  return VNET_API_ERROR_NO_SUCH_ENTRY;
1836  }
1837  void *oldheap = acl_set_heap (am);
1838  a = pool_elt_at_index (am->macip_acls, macip_acl_index);
1839  vec_validate_init_empty (am->macip_acl_by_sw_if_index, sw_if_index, ~0);
1840  vec_validate (am->sw_if_index_vec_by_macip_acl, macip_acl_index);
1841  vec_add1 (am->sw_if_index_vec_by_macip_acl[macip_acl_index], sw_if_index);
1842  clib_mem_set_heap (oldheap);
1843  /* If there already a MACIP ACL applied, unapply it */
1844  if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
1845  macip_acl_interface_del_acl (am, sw_if_index);
1846  am->macip_acl_by_sw_if_index[sw_if_index] = macip_acl_index;
1847 
1848  /* Apply the classifier tables for L2 ACLs */
1849  rv =
1850  vnet_set_input_acl_intfc (am->vlib_main, sw_if_index, a->ip4_table_index,
1851  a->ip6_table_index, a->l2_table_index, 1);
1852  rv |=
1853  vnet_set_output_acl_intfc (am->vlib_main, sw_if_index,
1855  a->out_l2_table_index, 1);
1856  return rv;
1857 }
1858 
1859 static int
1860 macip_acl_del_list (u32 acl_list_index)
1861 {
1862  acl_main_t *am = &acl_main;
1864  int i;
1865  if (pool_is_free_index (am->macip_acls, acl_list_index))
1866  {
1867  return VNET_API_ERROR_NO_SUCH_ENTRY;
1868  }
1869 
1870  /* delete any references to the ACL */
1871  for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
1872  {
1873  if (am->macip_acl_by_sw_if_index[i] == acl_list_index)
1874  {
1876  }
1877  }
1878 
1879  void *oldheap = acl_set_heap (am);
1880  /* Now that classifier tables are detached, clean them up */
1881  macip_destroy_classify_tables (am, acl_list_index);
1882 
1883  /* now we can delete the ACL itself */
1884  a = pool_elt_at_index (am->macip_acls, acl_list_index);
1885  if (a->rules)
1886  {
1887  vec_free (a->rules);
1888  }
1889  pool_put (am->macip_acls, a);
1890  clib_mem_set_heap (oldheap);
1891  return 0;
1892 }
1893 
1894 
1895 static int
1897  u32 acl_list_index)
1898 {
1899  acl_main_t *am = &acl_main;
1900  int rv = -1;
1901  if (is_add)
1902  {
1903  rv = macip_acl_interface_add_acl (am, sw_if_index, acl_list_index);
1904  }
1905  else
1906  {
1907  rv = macip_acl_interface_del_acl (am, sw_if_index);
1908  }
1909  return rv;
1910 }
1911 
1912 /*
1913  * If the client does not allocate enough memory for a variable-length
1914  * message, and then proceed to use it as if the full memory allocated,
1915  * absent the check we happily consume that on the VPP side, and go
1916  * along as if nothing happened. However, the resulting
1917  * effects range from just garbage in the API decode
1918  * (because the decoder snoops too far), to potential memory
1919  * corruptions.
1920  *
1921  * This verifies that the actual length of the message is
1922  * at least expected_len, and complains loudly if it is not.
1923  *
1924  * A failing check here is 100% a software bug on the API user side,
1925  * so we might as well yell.
1926  *
1927  */
1928 static int
1929 verify_message_len (void *mp, u32 expected_len, char *where)
1930 {
1931  u32 supplied_len = vl_msg_api_get_msg_length (mp);
1932  if (supplied_len < expected_len)
1933  {
1934  clib_warning ("%s: Supplied message length %d is less than expected %d",
1935  where, supplied_len, expected_len);
1936  return 0;
1937  }
1938  else
1939  {
1940  return 1;
1941  }
1942 }
1943 
1944 /* API message handler */
1945 static void
1947 {
1949  acl_main_t *am = &acl_main;
1950  int rv;
1951  u32 acl_list_index = ntohl (mp->acl_index);
1952  u32 acl_count = ntohl (mp->count);
1953  u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
1954 
1955  if (verify_message_len (mp, expected_len, "acl_add_replace"))
1956  {
1957  rv = acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
1958  }
1959  else
1960  {
1961  rv = VNET_API_ERROR_INVALID_VALUE;
1962  }
1963 
1964  /* *INDENT-OFF* */
1965  REPLY_MACRO2(VL_API_ACL_ADD_REPLACE_REPLY,
1966  ({
1967  rmp->acl_index = htonl(acl_list_index);
1968  }));
1969  /* *INDENT-ON* */
1970 }
1971 
1972 static void
1974 {
1975  acl_main_t *am = &acl_main;
1976  vl_api_acl_del_reply_t *rmp;
1977  int rv;
1978 
1979  rv = acl_del_list (ntohl (mp->acl_index));
1980 
1981  REPLY_MACRO (VL_API_ACL_DEL_REPLY);
1982 }
1983 
1984 
1985 static void
1988 {
1989  acl_main_t *am = &acl_main;
1990  vl_api_acl_stats_intf_counters_enable_reply_t *rmp;
1991  int rv;
1992 
1994 
1995  REPLY_MACRO (VL_API_ACL_DEL_REPLY);
1996 }
1997 
1998 
1999 static void
2001 {
2002  acl_main_t *am = &acl_main;
2004  u32 sw_if_index = ntohl (mp->sw_if_index);
2005  vl_api_acl_interface_add_del_reply_t *rmp;
2006  int rv = -1;
2007 
2008  if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2009  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2010  else
2011  rv =
2012  acl_interface_add_del_inout_acl (sw_if_index, mp->is_add,
2013  mp->is_input, ntohl (mp->acl_index));
2014 
2015  REPLY_MACRO (VL_API_ACL_INTERFACE_ADD_DEL_REPLY);
2016 }
2017 
2018 static void
2021 {
2022  acl_main_t *am = &acl_main;
2023  vl_api_acl_interface_set_acl_list_reply_t *rmp;
2024  int rv = 0;
2025  int i;
2027  u32 sw_if_index = ntohl (mp->sw_if_index);
2028 
2029  if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2030  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2031  else
2032  {
2033  int may_clear_sessions = 1;
2034  for (i = 0; i < mp->count; i++)
2035  {
2036  if (acl_is_not_defined (am, ntohl (mp->acls[i])))
2037  {
2038  /* ACL does not exist, so we can not apply it */
2039  rv = VNET_API_ERROR_NO_SUCH_ENTRY;
2040  }
2041  }
2042  if (0 == rv)
2043  {
2044  void *oldheap = acl_set_heap (am);
2045 
2046  u32 *in_acl_vec = 0;
2047  u32 *out_acl_vec = 0;
2048  for (i = 0; i < mp->count; i++)
2049  if (i < mp->n_input)
2050  vec_add1 (in_acl_vec, clib_net_to_host_u32 (mp->acls[i]));
2051  else
2052  vec_add1 (out_acl_vec, clib_net_to_host_u32 (mp->acls[i]));
2053 
2054  rv =
2055  acl_interface_set_inout_acl_list (am, sw_if_index, 0, out_acl_vec,
2056  &may_clear_sessions);
2057  rv = rv
2058  || acl_interface_set_inout_acl_list (am, sw_if_index, 1,
2059  in_acl_vec,
2060  &may_clear_sessions);
2061  vec_free (in_acl_vec);
2062  vec_free (out_acl_vec);
2063  clib_mem_set_heap (oldheap);
2064  }
2065  }
2066 
2067  REPLY_MACRO (VL_API_ACL_INTERFACE_SET_ACL_LIST_REPLY);
2068 }
2069 
2070 static void
2071 copy_acl_rule_to_api_rule (vl_api_acl_rule_t * api_rule, acl_rule_t * r)
2072 {
2073  api_rule->is_permit = r->is_permit;
2074  api_rule->is_ipv6 = r->is_ipv6;
2075  if (r->is_ipv6)
2076  {
2077  memcpy (api_rule->src_ip_addr, &r->src, sizeof (r->src));
2078  memcpy (api_rule->dst_ip_addr, &r->dst, sizeof (r->dst));
2079  }
2080  else
2081  {
2082  memcpy (api_rule->src_ip_addr, &r->src.ip4, sizeof (r->src.ip4));
2083  memcpy (api_rule->dst_ip_addr, &r->dst.ip4, sizeof (r->dst.ip4));
2084  }
2085  api_rule->src_ip_prefix_len = r->src_prefixlen;
2086  api_rule->dst_ip_prefix_len = r->dst_prefixlen;
2087  api_rule->proto = r->proto;
2088  api_rule->srcport_or_icmptype_first = htons (r->src_port_or_type_first);
2089  api_rule->srcport_or_icmptype_last = htons (r->src_port_or_type_last);
2090  api_rule->dstport_or_icmpcode_first = htons (r->dst_port_or_code_first);
2091  api_rule->dstport_or_icmpcode_last = htons (r->dst_port_or_code_last);
2092  api_rule->tcp_flags_mask = r->tcp_flags_mask;
2093  api_rule->tcp_flags_value = r->tcp_flags_value;
2094 }
2095 
2096 static void
2098  acl_list_t * acl, u32 context)
2099 {
2101  vl_api_acl_rule_t *rules;
2102  int i;
2103  acl_rule_t *acl_rules = acl->rules;
2104  int msg_size = sizeof (*mp) + sizeof (mp->r[0]) * vec_len (acl_rules);
2105  void *oldheap = acl_set_heap (am);
2106 
2107  mp = vl_msg_api_alloc (msg_size);
2108  clib_memset (mp, 0, msg_size);
2109  mp->_vl_msg_id = ntohs (VL_API_ACL_DETAILS + am->msg_id_base);
2110 
2111  /* fill in the message */
2112  mp->context = context;
2113  mp->count = htonl (vec_len (acl_rules));
2114  mp->acl_index = htonl (acl - am->acls);
2115  memcpy (mp->tag, acl->tag, sizeof (mp->tag));
2116  // clib_memcpy (mp->r, acl->rules, acl->count * sizeof(acl->rules[0]));
2117  rules = mp->r;
2118  for (i = 0; i < vec_len (acl_rules); i++)
2119  {
2120  copy_acl_rule_to_api_rule (&rules[i], &acl_rules[i]);
2121  }
2122 
2123  clib_mem_set_heap (oldheap);
2124  vl_api_send_msg (reg, (u8 *) mp);
2125 }
2126 
2127 
2128 static void
2130 {
2131  acl_main_t *am = &acl_main;
2132  u32 acl_index;
2133  acl_list_t *acl;
2134  int rv = -1;
2135  vl_api_registration_t *reg;
2136 
2138  if (!reg)
2139  return;
2140 
2141  if (mp->acl_index == ~0)
2142  {
2143  /* *INDENT-OFF* */
2144  /* Just dump all ACLs */
2145  pool_foreach (acl, am->acls,
2146  ({
2147  send_acl_details(am, reg, acl, mp->context);
2148  }));
2149  /* *INDENT-ON* */
2150  }
2151  else
2152  {
2153  acl_index = ntohl (mp->acl_index);
2154  if (!pool_is_free_index (am->acls, acl_index))
2155  {
2156  acl = pool_elt_at_index (am->acls, acl_index);
2157  send_acl_details (am, reg, acl, mp->context);
2158  }
2159  }
2160 
2161  if (rv == -1)
2162  {
2163  /* FIXME API: should we signal an error here at all ? */
2164  return;
2165  }
2166 }
2167 
2168 static void
2170  vl_api_registration_t * reg,
2171  u32 sw_if_index, u32 context)
2172 {
2174  int msg_size;
2175  int n_input;
2176  int n_output;
2177  int count;
2178  int i = 0;
2179  void *oldheap = acl_set_heap (am);
2180 
2181  vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
2182  vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
2183 
2184  clib_mem_set_heap (oldheap);
2185 
2186  n_input = vec_len (am->input_acl_vec_by_sw_if_index[sw_if_index]);
2187  n_output = vec_len (am->output_acl_vec_by_sw_if_index[sw_if_index]);
2188  count = n_input + n_output;
2189 
2190  msg_size = sizeof (*mp);
2191  msg_size += sizeof (mp->acls[0]) * count;
2192 
2193  mp = vl_msg_api_alloc (msg_size);
2194  clib_memset (mp, 0, msg_size);
2195  mp->_vl_msg_id =
2196  ntohs (VL_API_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
2197 
2198  /* fill in the message */
2199  mp->context = context;
2200  mp->sw_if_index = htonl (sw_if_index);
2201  mp->count = count;
2202  mp->n_input = n_input;
2203  for (i = 0; i < n_input; i++)
2204  {
2205  mp->acls[i] = htonl (am->input_acl_vec_by_sw_if_index[sw_if_index][i]);
2206  }
2207  for (i = 0; i < n_output; i++)
2208  {
2209  mp->acls[n_input + i] =
2210  htonl (am->output_acl_vec_by_sw_if_index[sw_if_index][i]);
2211  }
2212  vl_api_send_msg (reg, (u8 *) mp);
2213 }
2214 
2215 static void
2217  mp)
2218 {
2219  acl_main_t *am = &acl_main;
2220  vnet_sw_interface_t *swif;
2222 
2223  u32 sw_if_index;
2224  vl_api_registration_t *reg;
2225 
2227  if (!reg)
2228  return;
2229 
2230  if (mp->sw_if_index == ~0)
2231  {
2232  /* *INDENT-OFF* */
2233  pool_foreach (swif, im->sw_interfaces,
2234  ({
2235  send_acl_interface_list_details(am, reg, swif->sw_if_index, mp->context);
2236  }));
2237  /* *INDENT-ON* */
2238  }
2239  else
2240  {
2241  sw_if_index = ntohl (mp->sw_if_index);
2242  if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
2243  send_acl_interface_list_details (am, reg, sw_if_index, mp->context);
2244  }
2245 }
2246 
2247 /* MACIP ACL API handlers */
2248 
2249 static void
2251 {
2253  acl_main_t *am = &acl_main;
2254  int rv;
2255  u32 acl_list_index = ~0;
2256  u32 acl_count = ntohl (mp->count);
2257  u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2258 
2259  if (verify_message_len (mp, expected_len, "macip_acl_add"))
2260  {
2261  rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2262  }
2263  else
2264  {
2265  rv = VNET_API_ERROR_INVALID_VALUE;
2266  }
2267 
2268  /* *INDENT-OFF* */
2269  REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLY,
2270  ({
2271  rmp->acl_index = htonl(acl_list_index);
2272  }));
2273  /* *INDENT-ON* */
2274 }
2275 
2276 static void
2278 {
2280  acl_main_t *am = &acl_main;
2281  int rv;
2282  u32 acl_list_index = ntohl (mp->acl_index);
2283  u32 acl_count = ntohl (mp->count);
2284  u32 expected_len = sizeof (*mp) + acl_count * sizeof (mp->r[0]);
2285 
2286  if (verify_message_len (mp, expected_len, "macip_acl_add_replace"))
2287  {
2288  rv = macip_acl_add_list (acl_count, mp->r, &acl_list_index, mp->tag);
2289  }
2290  else
2291  {
2292  rv = VNET_API_ERROR_INVALID_VALUE;
2293  }
2294 
2295  /* *INDENT-OFF* */
2296  REPLY_MACRO2(VL_API_MACIP_ACL_ADD_REPLACE_REPLY,
2297  ({
2298  rmp->acl_index = htonl(acl_list_index);
2299  }));
2300  /* *INDENT-ON* */
2301 }
2302 
2303 static void
2305 {
2306  acl_main_t *am = &acl_main;
2307  vl_api_macip_acl_del_reply_t *rmp;
2308  int rv;
2309 
2310  rv = macip_acl_del_list (ntohl (mp->acl_index));
2311 
2312  REPLY_MACRO (VL_API_MACIP_ACL_DEL_REPLY);
2313 }
2314 
2315 static void
2318 {
2319  acl_main_t *am = &acl_main;
2320  vl_api_macip_acl_interface_add_del_reply_t *rmp;
2321  int rv = -1;
2323  u32 sw_if_index = ntohl (mp->sw_if_index);
2324 
2325  if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2326  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2327  else
2328  rv =
2330  ntohl (mp->acl_index));
2331 
2332  REPLY_MACRO (VL_API_MACIP_ACL_INTERFACE_ADD_DEL_REPLY);
2333 }
2334 
2335 static void
2337  macip_acl_list_t * acl, u32 context)
2338 {
2340  vl_api_macip_acl_rule_t *rules;
2341  macip_acl_rule_t *r;
2342  int i;
2343  int msg_size = sizeof (*mp) + (acl ? sizeof (mp->r[0]) * acl->count : 0);
2344 
2345  mp = vl_msg_api_alloc (msg_size);
2346  clib_memset (mp, 0, msg_size);
2347  mp->_vl_msg_id = ntohs (VL_API_MACIP_ACL_DETAILS + am->msg_id_base);
2348 
2349  /* fill in the message */
2350  mp->context = context;
2351  if (acl)
2352  {
2353  memcpy (mp->tag, acl->tag, sizeof (mp->tag));
2354  mp->count = htonl (acl->count);
2355  mp->acl_index = htonl (acl - am->macip_acls);
2356  rules = mp->r;
2357  for (i = 0; i < acl->count; i++)
2358  {
2359  r = &acl->rules[i];
2360  rules[i].is_permit = r->is_permit;
2361  rules[i].is_ipv6 = r->is_ipv6;
2362  memcpy (rules[i].src_mac, &r->src_mac, sizeof (r->src_mac));
2363  memcpy (rules[i].src_mac_mask, &r->src_mac_mask,
2364  sizeof (r->src_mac_mask));
2365  if (r->is_ipv6)
2366  memcpy (rules[i].src_ip_addr, &r->src_ip_addr.ip6,
2367  sizeof (r->src_ip_addr.ip6));
2368  else
2369  memcpy (rules[i].src_ip_addr, &r->src_ip_addr.ip4,
2370  sizeof (r->src_ip_addr.ip4));
2371  rules[i].src_ip_prefix_len = r->src_prefixlen;
2372  }
2373  }
2374  else
2375  {
2376  /* No martini, no party - no ACL applied to this interface. */
2377  mp->acl_index = ~0;
2378  mp->count = 0;
2379  }
2380 
2381  vl_api_send_msg (reg, (u8 *) mp);
2382 }
2383 
2384 
2385 static void
2387 {
2388  acl_main_t *am = &acl_main;
2389  macip_acl_list_t *acl;
2390 
2391  vl_api_registration_t *reg;
2392 
2394  if (!reg)
2395  return;
2396 
2397  if (mp->acl_index == ~0)
2398  {
2399  /* Just dump all ACLs for now, with sw_if_index = ~0 */
2400  /* *INDENT-OFF* */
2401  pool_foreach (acl, am->macip_acls,
2402  ({
2403  send_macip_acl_details (am, reg, acl, mp->context);
2404  }));
2405  /* *INDENT-ON* */
2406  }
2407  else
2408  {
2409  u32 acl_index = ntohl (mp->acl_index);
2410  if (!pool_is_free_index (am->macip_acls, acl_index))
2411  {
2412  acl = pool_elt_at_index (am->macip_acls, acl_index);
2413  send_macip_acl_details (am, reg, acl, mp->context);
2414  }
2415  }
2416 }
2417 
2418 static void
2420  mp)
2421 {
2422  acl_main_t *am = &acl_main;
2425  int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]) * count;
2426  vl_api_registration_t *reg;
2427  int i;
2428 
2430  if (!reg)
2431  return;
2432 
2433  rmp = vl_msg_api_alloc (msg_size);
2434  clib_memset (rmp, 0, msg_size);
2435  rmp->_vl_msg_id =
2436  ntohs (VL_API_MACIP_ACL_INTERFACE_GET_REPLY + am->msg_id_base);
2437  rmp->context = mp->context;
2438  rmp->count = htonl (count);
2439  for (i = 0; i < count; i++)
2440  {
2441  rmp->acls[i] = htonl (am->macip_acl_by_sw_if_index[i]);
2442  }
2443 
2444  vl_api_send_msg (reg, (u8 *) rmp);
2445 }
2446 
2447 static void
2449  vl_api_registration_t * reg,
2450  u32 sw_if_index,
2451  u32 acl_index, u32 context)
2452 {
2454  /* at this time there is only ever 1 mac ip acl per interface */
2455  int msg_size = sizeof (*rmp) + sizeof (rmp->acls[0]);
2456 
2457  rmp = vl_msg_api_alloc (msg_size);
2458  clib_memset (rmp, 0, msg_size);
2459  rmp->_vl_msg_id =
2460  ntohs (VL_API_MACIP_ACL_INTERFACE_LIST_DETAILS + am->msg_id_base);
2461 
2462  /* fill in the message */
2463  rmp->context = context;
2464  rmp->count = 1;
2465  rmp->sw_if_index = htonl (sw_if_index);
2466  rmp->acls[0] = htonl (acl_index);
2467 
2468  vl_api_send_msg (reg, (u8 *) rmp);
2469 }
2470 
2471 static void
2474 {
2475  vl_api_registration_t *reg;
2476  acl_main_t *am = &acl_main;
2477  u32 sw_if_index = ntohl (mp->sw_if_index);
2478 
2480  if (!reg)
2481  return;
2482 
2483  if (sw_if_index == ~0)
2484  {
2485  vec_foreach_index (sw_if_index, am->macip_acl_by_sw_if_index)
2486  {
2487  if (~0 != am->macip_acl_by_sw_if_index[sw_if_index])
2488  {
2489  send_macip_acl_interface_list_details (am, reg, sw_if_index,
2491  [sw_if_index],
2492  mp->context);
2493  }
2494  }
2495  }
2496  else
2497  {
2498  if (vec_len (am->macip_acl_by_sw_if_index) > sw_if_index)
2499  {
2500  send_macip_acl_interface_list_details (am, reg, sw_if_index,
2502  [sw_if_index], mp->context);
2503  }
2504  }
2505 }
2506 
2507 static void
2510 {
2511  acl_main_t *am = &acl_main;
2512  vl_api_acl_interface_set_etype_whitelist_reply_t *rmp;
2513  int rv = 0;
2514  int i;
2516  u32 sw_if_index = ntohl (mp->sw_if_index);
2517  u16 *vec_in = 0, *vec_out = 0;
2518  void *oldheap = acl_set_heap (am);
2519 
2520  if (pool_is_free_index (im->sw_interfaces, sw_if_index))
2521  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
2522  else
2523  {
2524  for (i = 0; i < mp->count; i++)
2525  {
2526  if (i < mp->n_input)
2527  vec_add1 (vec_in, ntohs (mp->whitelist[i]));
2528  else
2529  vec_add1 (vec_out, ntohs (mp->whitelist[i]));
2530  }
2531  rv = acl_set_etype_whitelists (am, sw_if_index, vec_in, vec_out);
2532  }
2533 
2534  clib_mem_set_heap (oldheap);
2535  REPLY_MACRO (VL_API_ACL_INTERFACE_SET_ETYPE_WHITELIST_REPLY);
2536 }
2537 
2538 static void
2540  vl_api_registration_t * reg,
2541  u32 sw_if_index, u32 context)
2542 {
2544  int msg_size;
2545  int n_input = 0;
2546  int n_output = 0;
2547  int count = 0;
2548  int i = 0;
2549 
2550  u16 *whitelist_in = 0;
2551  u16 *whitelist_out = 0;
2552 
2553  if (intf_has_etype_whitelist (am, sw_if_index, 0))
2554  whitelist_out =
2556 
2557  if (intf_has_etype_whitelist (am, sw_if_index, 1))
2558  whitelist_in =
2559  vec_elt (am->input_etype_whitelist_by_sw_if_index, sw_if_index);
2560 
2561  if ((0 == whitelist_in) && (0 == whitelist_out))
2562  return; /* nothing to do */
2563 
2564  void *oldheap = acl_set_heap (am);
2565 
2566  n_input = vec_len (whitelist_in);
2567  n_output = vec_len (whitelist_out);
2568  count = n_input + n_output;
2569 
2570  msg_size = sizeof (*mp);
2571  msg_size += sizeof (mp->whitelist[0]) * count;
2572 
2573  mp = vl_msg_api_alloc (msg_size);
2574  clib_memset (mp, 0, msg_size);
2575  mp->_vl_msg_id =
2576  ntohs (VL_API_ACL_INTERFACE_ETYPE_WHITELIST_DETAILS + am->msg_id_base);
2577 
2578  /* fill in the message */
2579  mp->context = context;
2580  mp->sw_if_index = htonl (sw_if_index);
2581  mp->count = count;
2582  mp->n_input = n_input;
2583  for (i = 0; i < n_input; i++)
2584  {
2585  mp->whitelist[i] = htons (whitelist_in[i]);
2586  }
2587  for (i = 0; i < n_output; i++)
2588  {
2589  mp->whitelist[n_input + i] = htons (whitelist_out[i]);
2590  }
2591  clib_mem_set_heap (oldheap);
2592  vl_api_send_msg (reg, (u8 *) mp);
2593 }
2594 
2595 
2596 static void
2599 {
2600  acl_main_t *am = &acl_main;
2601  vnet_sw_interface_t *swif;
2603 
2604  u32 sw_if_index;
2605  vl_api_registration_t *reg;
2606 
2608  if (!reg)
2609  return;
2610 
2611  if (mp->sw_if_index == ~0)
2612  {
2613  /* *INDENT-OFF* */
2614  pool_foreach (swif, im->sw_interfaces,
2615  ({
2616  send_acl_interface_etype_whitelist_details(am, reg, swif->sw_if_index, mp->context);
2617  }));
2618  /* *INDENT-ON* */
2619  }
2620  else
2621  {
2622  sw_if_index = ntohl (mp->sw_if_index);
2623  if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
2624  send_acl_interface_etype_whitelist_details (am, reg, sw_if_index,
2625  mp->context);
2626  }
2627 }
2628 
2629 static void
2630 acl_set_timeout_sec (int timeout_type, u32 value)
2631 {
2632  acl_main_t *am = &acl_main;
2633  clib_time_t *ct = &am->vlib_main->clib_time;
2634 
2635  if (timeout_type < ACL_N_TIMEOUTS)
2636  {
2637  am->session_timeout_sec[timeout_type] = value;
2638  }
2639  else
2640  {
2641  clib_warning ("Unknown timeout type %d", timeout_type);
2642  return;
2643  }
2644  am->session_timeout[timeout_type] =
2645  (u64) (((f64) value) / ct->seconds_per_clock);
2646 }
2647 
2648 static void
2650 {
2651  acl_main_t *am = &acl_main;
2653 }
2654 
2655 static int
2657 {
2658  acl_main_t *am = &acl_main;
2659 
2660  if ((eh < 256) && (value < 2))
2661  {
2663  clib_bitmap_set (am->fa_ipv6_known_eh_bitmap, eh, value);
2664  return 1;
2665  }
2666  else
2667  return 0;
2668 }
2669 
2670 
2671 static clib_error_t *
2673 {
2674  acl_main_t *am = &acl_main;
2675  if (0 == am->acl_mheap)
2676  {
2677  /* ACL heap is not initialized, so definitely nothing to do. */
2678  return 0;
2679  }
2680  if (0 == is_add)
2681  {
2682  int may_clear_sessions = 1;
2685  sw_if_index);
2686  /* also unapply any ACLs in case the users did not do so. */
2687  macip_acl_interface_del_acl (am, sw_if_index);
2688  acl_interface_reset_inout_acls (sw_if_index, 0, &may_clear_sessions);
2689  acl_interface_reset_inout_acls (sw_if_index, 1, &may_clear_sessions);
2690  }
2691  return 0;
2692 }
2693 
2695 
2696 
2697 
2698 static clib_error_t *
2700  unformat_input_t * input, vlib_cli_command_t * cmd)
2701 {
2702  clib_error_t *error = 0;
2703  u32 timeout = 0;
2704  u32 val = 0;
2705  u32 eh_val = 0;
2706  uword memory_size = 0;
2707  acl_main_t *am = &acl_main;
2708 
2709  if (unformat (input, "skip-ipv6-extension-header %u %u", &eh_val, &val))
2710  {
2711  if (!acl_set_skip_ipv6_eh (eh_val, val))
2712  {
2713  error = clib_error_return (0, "expecting eh=0..255, value=0..1");
2714  }
2715  goto done;
2716  }
2717  if (unformat (input, "use-hash-acl-matching %u", &val))
2718  {
2719  am->use_hash_acl_matching = (val != 0);
2720  goto done;
2721  }
2722  if (unformat (input, "l4-match-nonfirst-fragment %u", &val))
2723  {
2724  am->l4_match_nonfirst_fragment = (val != 0);
2725  goto done;
2726  }
2727  if (unformat (input, "reclassify-sessions %u", &val))
2728  {
2729  am->reclassify_sessions = (val != 0);
2730  goto done;
2731  }
2732  if (unformat (input, "event-trace"))
2733  {
2734  if (!unformat (input, "%u", &val))
2735  {
2736  error = clib_error_return (0,
2737  "expecting trace level, got `%U`",
2738  format_unformat_error, input);
2739  goto done;
2740  }
2741  else
2742  {
2743  am->trace_acl = val;
2744  goto done;
2745  }
2746  }
2747  if (unformat (input, "heap"))
2748  {
2749  if (unformat (input, "main"))
2750  {
2751  if (unformat (input, "validate %u", &val))
2753  else if (unformat (input, "trace %u", &val))
2755  goto done;
2756  }
2757  else if (unformat (input, "hash"))
2758  {
2759  if (unformat (input, "validate %u", &val))
2761  else if (unformat (input, "trace %u", &val))
2763  goto done;
2764  }
2765  goto done;
2766  }
2767  if (unformat (input, "session"))
2768  {
2769  if (unformat (input, "table"))
2770  {
2771  /* The commands here are for tuning/testing. No user-serviceable parts inside */
2772  if (unformat (input, "max-entries"))
2773  {
2774  if (!unformat (input, "%u", &val))
2775  {
2776  error = clib_error_return (0,
2777  "expecting maximum number of entries, got `%U`",
2778  format_unformat_error, input);
2779  goto done;
2780  }
2781  else
2782  {
2784  goto done;
2785  }
2786  }
2787  if (unformat (input, "hash-table-buckets"))
2788  {
2789  if (!unformat (input, "%u", &val))
2790  {
2791  error = clib_error_return (0,
2792  "expecting maximum number of hash table buckets, got `%U`",
2793  format_unformat_error, input);
2794  goto done;
2795  }
2796  else
2797  {
2799  goto done;
2800  }
2801  }
2802  if (unformat (input, "hash-table-memory"))
2803  {
2804  if (!unformat (input, "%U", unformat_memory_size, &memory_size))
2805  {
2806  error = clib_error_return (0,
2807  "expecting maximum amount of hash table memory, got `%U`",
2808  format_unformat_error, input);
2809  goto done;
2810  }
2811  else
2812  {
2814  goto done;
2815  }
2816  }
2817  if (unformat (input, "event-trace"))
2818  {
2819  if (!unformat (input, "%u", &val))
2820  {
2821  error = clib_error_return (0,
2822  "expecting trace level, got `%U`",
2823  format_unformat_error, input);
2824  goto done;
2825  }
2826  else
2827  {
2828  am->trace_sessions = val;
2829  goto done;
2830  }
2831  }
2832  goto done;
2833  }
2834  if (unformat (input, "timeout"))
2835  {
2836  if (unformat (input, "udp"))
2837  {
2838  if (unformat (input, "idle"))
2839  {
2840  if (!unformat (input, "%u", &timeout))
2841  {
2842  error = clib_error_return (0,
2843  "expecting timeout value in seconds, got `%U`",
2845  input);
2846  goto done;
2847  }
2848  else
2849  {
2851  goto done;
2852  }
2853  }
2854  }
2855  if (unformat (input, "tcp"))
2856  {
2857  if (unformat (input, "idle"))
2858  {
2859  if (!unformat (input, "%u", &timeout))
2860  {
2861  error = clib_error_return (0,
2862  "expecting timeout value in seconds, got `%U`",
2864  input);
2865  goto done;
2866  }
2867  else
2868  {
2870  goto done;
2871  }
2872  }
2873  if (unformat (input, "transient"))
2874  {
2875  if (!unformat (input, "%u", &timeout))
2876  {
2877  error = clib_error_return (0,
2878  "expecting timeout value in seconds, got `%U`",
2880  input);
2881  goto done;
2882  }
2883  else
2884  {
2886  timeout);
2887  goto done;
2888  }
2889  }
2890  }
2891  goto done;
2892  }
2893  }
2894 done:
2895  return error;
2896 }
2897 
2898 static u8 *
2899 my_format_mac_address (u8 * s, va_list * args)
2900 {
2901  u8 *a = va_arg (*args, u8 *);
2902  return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
2903  a[0], a[1], a[2], a[3], a[4], a[5]);
2904 }
2905 
2906 static inline u8 *
2907 my_macip_acl_rule_t_pretty_format (u8 * out, va_list * args)
2908 {
2909  macip_acl_rule_t *a = va_arg (*args, macip_acl_rule_t *);
2910 
2911  out = format (out, "%s action %d ip %U/%d mac %U mask %U",
2912  a->is_ipv6 ? "ipv6" : "ipv4", a->is_permit,
2915  a->src_prefixlen,
2918  return (out);
2919 }
2920 
2921 static void
2922 macip_acl_print (acl_main_t * am, u32 macip_acl_index)
2923 {
2924  vlib_main_t *vm = am->vlib_main;
2925  int i;
2926 
2927  /* Don't try to print someone else's memory */
2928  if (macip_acl_index >= vec_len (am->macip_acls))
2929  return;
2930 
2931  macip_acl_list_t *a = vec_elt_at_index (am->macip_acls, macip_acl_index);
2932  int free_pool_slot = pool_is_free_index (am->macip_acls, macip_acl_index);
2933 
2934  vlib_cli_output (vm,
2935  "MACIP acl_index: %d, count: %d (true len %d) tag {%s} is free pool slot: %d\n",
2936  macip_acl_index, a->count, vec_len (a->rules), a->tag,
2937  free_pool_slot);
2938  vlib_cli_output (vm,
2939  " ip4_table_index %d, ip6_table_index %d, l2_table_index %d\n",
2941  vlib_cli_output (vm,
2942  " out_ip4_table_index %d, out_ip6_table_index %d, out_l2_table_index %d\n",
2944  a->out_l2_table_index);
2945  for (i = 0; i < vec_len (a->rules); i++)
2946  vlib_cli_output (vm, " rule %d: %U\n", i,
2948  vec_elt_at_index (a->rules, i));
2949 
2950 }
2951 
2952 static clib_error_t *
2955  input, vlib_cli_command_t * cmd)
2956 {
2957  clib_error_t *error = 0;
2958  acl_main_t *am = &acl_main;
2959  int i;
2960  u32 acl_index = ~0;
2961 
2962  (void) unformat (input, "index %u", &acl_index);
2963 
2964  for (i = 0; i < vec_len (am->macip_acls); i++)
2965  {
2966  /* Don't attempt to show the ACLs that do not exist */
2967  if (pool_is_free_index (am->macip_acls, i))
2968  continue;
2969 
2970  if ((acl_index != ~0) && (acl_index != i))
2971  {
2972  continue;
2973  }
2974 
2975  macip_acl_print (am, i);
2976  if (i < vec_len (am->sw_if_index_vec_by_macip_acl))
2977  {
2978  vlib_cli_output (vm, " applied on sw_if_index(s): %U\n",
2979  format_vec32,
2981  "%d");
2982  }
2983  }
2984 
2985  return error;
2986 }
2987 
2988 static clib_error_t *
2991  input, vlib_cli_command_t * cmd)
2992 {
2993  clib_error_t *error = 0;
2994  acl_main_t *am = &acl_main;
2995  int i;
2996  for (i = 0; i < vec_len (am->macip_acl_by_sw_if_index); i++)
2997  {
2998  vlib_cli_output (vm, " sw_if_index %d: %d\n", i,
3000  }
3001  return error;
3002 }
3003 
3004 static void
3006 {
3007  u32 i;
3008  vlib_main_t *vm = am->vlib_main;
3009 
3010  for (i = 0; i < vec_len (am->acls); i++)
3011  {
3012  if (acl_is_not_defined (am, i))
3013  {
3014  /* don't attempt to show the ACLs that do not exist */
3015  continue;
3016  }
3017  if ((acl_index != ~0) && (acl_index != i))
3018  {
3019  continue;
3020  }
3021  acl_print_acl (vm, am, i);
3022 
3023  if (i < vec_len (am->input_sw_if_index_vec_by_acl))
3024  {
3025  vlib_cli_output (vm, " applied inbound on sw_if_index: %U\n",
3027  "%d");
3028  }
3029  if (i < vec_len (am->output_sw_if_index_vec_by_acl))
3030  {
3031  vlib_cli_output (vm, " applied outbound on sw_if_index: %U\n",
3033  "%d");
3034  }
3035  if (i < vec_len (am->lc_index_vec_by_acl))
3036  {
3037  vlib_cli_output (vm, " used in lookup context index: %U\n",
3038  format_vec32, am->lc_index_vec_by_acl[i], "%d");
3039  }
3040  }
3041 }
3042 
3043 static clib_error_t *
3045  unformat_input_t * input, vlib_cli_command_t * cmd)
3046 {
3047  clib_error_t *error = 0;
3048  acl_main_t *am = &acl_main;
3049 
3050  u32 acl_index = ~0;
3051  (void) unformat (input, "index %u", &acl_index);
3052 
3053  acl_plugin_show_acl (am, acl_index);
3054  return error;
3055 }
3056 
3057 static clib_error_t *
3059  unformat_input_t * input,
3060  vlib_cli_command_t * cmd)
3061 {
3062  clib_error_t *error = 0;
3063 
3064  u32 lc_index = ~0;
3065  (void) unformat (input, "index %u", &lc_index);
3066 
3067  acl_plugin_show_lookup_context (lc_index);
3068  return error;
3069 }
3070 
3071 static clib_error_t *
3073  unformat_input_t * input,
3074  vlib_cli_command_t * cmd)
3075 {
3076  clib_error_t *error = 0;
3077 
3078  u32 lc_index = ~0;
3079  (void) unformat (input, "index %u", &lc_index);
3080 
3081  acl_plugin_show_lookup_user (lc_index);
3082  return error;
3083 }
3084 
3085 
3086 static void
3088  int detail)
3089 {
3090  vlib_main_t *vm = am->vlib_main;
3091  u32 swi;
3092  u32 *pj;
3093  for (swi = 0; (swi < vec_len (am->input_acl_vec_by_sw_if_index)) ||
3094  (swi < vec_len (am->output_acl_vec_by_sw_if_index)); swi++)
3095  {
3096  /* if we need a particular interface, skip all the others */
3097  if ((sw_if_index != ~0) && (sw_if_index != swi))
3098  continue;
3099 
3100  vlib_cli_output (vm, "sw_if_index %d:\n", swi);
3102  vlib_cli_output (vm, " input policy epoch: %x\n",
3104  swi));
3106  vlib_cli_output (vm, " output policy epoch: %x\n",
3108  swi));
3109 
3110 
3111  if (intf_has_etype_whitelist (am, swi, 1))
3112  {
3113  vlib_cli_output (vm, " input etype whitelist: %U", format_vec16,
3115  "%04x");
3116  }
3117  if (intf_has_etype_whitelist (am, swi, 0))
3118  {
3119  vlib_cli_output (vm, " output etype whitelist: %U", format_vec16,
3121  "%04x");
3122  }
3123 
3124  if ((swi < vec_len (am->input_acl_vec_by_sw_if_index)) &&
3125  (vec_len (am->input_acl_vec_by_sw_if_index[swi]) > 0))
3126  {
3127  vlib_cli_output (vm, " input acl(s): %U", format_vec32,
3128  am->input_acl_vec_by_sw_if_index[swi], "%d");
3129  if (show_acl)
3130  {
3131  vlib_cli_output (vm, "\n");
3133  {
3134  acl_print_acl (vm, am, *pj);
3135  }
3136  vlib_cli_output (vm, "\n");
3137  }
3138  }
3139 
3140  if ((swi < vec_len (am->output_acl_vec_by_sw_if_index)) &&
3141  (vec_len (am->output_acl_vec_by_sw_if_index[swi]) > 0))
3142  {
3143  vlib_cli_output (vm, " output acl(s): %U", format_vec32,
3144  am->output_acl_vec_by_sw_if_index[swi], "%d");
3145  if (show_acl)
3146  {
3147  vlib_cli_output (vm, "\n");
3149  {
3150  acl_print_acl (vm, am, *pj);
3151  }
3152  vlib_cli_output (vm, "\n");
3153  }
3154  }
3155  if (detail && (swi < vec_len (am->input_lc_index_by_sw_if_index)))
3156  {
3157  vlib_cli_output (vm, " input lookup context index: %d",
3159  }
3160  if (detail && (swi < vec_len (am->output_lc_index_by_sw_if_index)))
3161  {
3162  vlib_cli_output (vm, " output lookup context index: %d",
3164  }
3165  }
3166 
3167 }
3168 
3169 
3170 static clib_error_t *
3172  unformat_input_t * input,
3173  vlib_cli_command_t * cmd)
3174 {
3175  clib_error_t *error = 0;
3176  u64 five_tuple[6] = { 0, 0, 0, 0, 0, 0 };
3177 
3178  if (unformat
3179  (input, "%llx %llx %llx %llx %llx %llx", &five_tuple[0], &five_tuple[1],
3180  &five_tuple[2], &five_tuple[3], &five_tuple[4], &five_tuple[5]))
3181  vlib_cli_output (vm, "5-tuple structure decode: %U\n\n",
3182  format_acl_plugin_5tuple, five_tuple);
3183  else
3184  error = clib_error_return (0, "expecting 6 hex integers");
3185  return error;
3186 }
3187 
3188 
3189 static clib_error_t *
3192  input, vlib_cli_command_t * cmd)
3193 {
3194  clib_error_t *error = 0;
3195  acl_main_t *am = &acl_main;
3196 
3197  u32 sw_if_index = ~0;
3198  (void) unformat (input, "sw_if_index %u", &sw_if_index);
3199  int show_acl = unformat (input, "acl");
3200  int detail = unformat (input, "detail");
3201 
3202  acl_plugin_show_interface (am, sw_if_index, show_acl, detail);
3203  return error;
3204 }
3205 
3206 static clib_error_t *
3208  unformat_input_t * input,
3209  vlib_cli_command_t * cmd)
3210 {
3211  clib_error_t *error = 0;
3212  acl_main_t *am = &acl_main;
3213 
3214  vlib_cli_output (vm, "ACL plugin main heap statistics:\n");
3215  if (am->acl_mheap)
3216  {
3217  vlib_cli_output (vm, " %U\n", format_mheap, am->acl_mheap, 1);
3218  }
3219  else
3220  {
3221  vlib_cli_output (vm, " Not initialized\n");
3222  }
3223  vlib_cli_output (vm, "ACL hash lookup support heap statistics:\n");
3224  if (am->hash_lookup_mheap)
3225  {
3226  vlib_cli_output (vm, " %U\n", format_mheap, am->hash_lookup_mheap, 1);
3227  }
3228  else
3229  {
3230  vlib_cli_output (vm, " Not initialized\n");
3231  }
3232  return error;
3233 }
3234 
3235 static void
3237  u32 show_session_thread_id,
3238  u32 show_session_session_index)
3239 {
3240  vlib_main_t *vm = am->vlib_main;
3241  u16 wk;
3243  vnet_sw_interface_t *swif;
3244  u64 now = clib_cpu_time_now ();
3245  u64 clocks_per_second = am->vlib_main->clib_time.clocks_per_second;
3246 
3247  {
3248  u64 n_adds = am->fa_session_total_adds;
3249  u64 n_dels = am->fa_session_total_dels;
3250  u64 n_deact = am->fa_session_total_deactivations;
3251  vlib_cli_output (vm, "Sessions total: add %lu - del %lu = %lu", n_adds,
3252  n_dels, n_adds - n_dels);
3253  vlib_cli_output (vm, "Sessions active: add %lu - deact %lu = %lu", n_adds,
3254  n_deact, n_adds - n_deact);
3255  vlib_cli_output (vm, "Sessions being purged: deact %lu - del %lu = %lu",
3256  n_deact, n_dels, n_deact - n_dels);
3257  }
3258  vlib_cli_output (vm, "now: %lu clocks per second: %lu", now,
3259  clocks_per_second);
3260  vlib_cli_output (vm, "\n\nPer-thread data:");
3261  for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
3262  {
3264  vlib_cli_output (vm, "Thread #%d:", wk);
3265  if (show_session_thread_id == wk
3266  && show_session_session_index < pool_len (pw->fa_sessions_pool))
3267  {
3268  vlib_cli_output (vm, " session index %u:",
3269  show_session_session_index);
3270  fa_session_t *sess =
3271  pw->fa_sessions_pool + show_session_session_index;
3272  u64 *m = (u64 *) & sess->info;
3273  vlib_cli_output (vm,
3274  " info: %016llx %016llx %016llx %016llx %016llx %016llx",
3275  m[0], m[1], m[2], m[3], m[4], m[5]);
3276  vlib_cli_output (vm, " sw_if_index: %u", sess->sw_if_index);
3277  vlib_cli_output (vm, " tcp_flags_seen: %x",
3278  sess->tcp_flags_seen.as_u16);
3279  vlib_cli_output (vm, " last active time: %lu",
3280  sess->last_active_time);
3281  vlib_cli_output (vm, " thread index: %u", sess->thread_index);
3282  vlib_cli_output (vm, " link enqueue time: %lu",
3283  sess->link_enqueue_time);
3284  vlib_cli_output (vm, " link next index: %u",
3285  sess->link_next_idx);
3286  vlib_cli_output (vm, " link prev index: %u",
3287  sess->link_prev_idx);
3288  vlib_cli_output (vm, " link list id: %u", sess->link_list_id);
3289  }
3290  vlib_cli_output (vm, " connection add/del stats:", wk);
3291  /* *INDENT-OFF* */
3292  pool_foreach (swif, im->sw_interfaces,
3293  ({
3294  u32 sw_if_index = swif->sw_if_index;
3295  u64 n_adds =
3296  (sw_if_index < vec_len (pw->fa_session_adds_by_sw_if_index) ?
3297  pw->fa_session_adds_by_sw_if_index[sw_if_index] :
3298  0);
3299  u64 n_dels =
3300  (sw_if_index < vec_len (pw->fa_session_dels_by_sw_if_index) ?
3301  pw->fa_session_dels_by_sw_if_index[sw_if_index] :
3302  0);
3303  u64 n_epoch_changes =
3304  (sw_if_index < vec_len (pw->fa_session_epoch_change_by_sw_if_index) ?
3305  pw->fa_session_epoch_change_by_sw_if_index[sw_if_index] :
3306  0);
3307  vlib_cli_output (vm,
3308  " sw_if_index %d: add %lu - del %lu = %lu; epoch chg: %lu",
3309  sw_if_index,
3310  n_adds,
3311  n_dels,
3312  n_adds -
3313  n_dels,
3314  n_epoch_changes);
3315  }));
3316  /* *INDENT-ON* */
3317 
3318  vlib_cli_output (vm, " connection timeout type lists:", wk);
3319  u8 tt = 0;
3320  for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
3321  {
3322  u32 head_session_index = pw->fa_conn_list_head[tt];
3323  vlib_cli_output (vm, " fa_conn_list_head[%d]: %d", tt,
3324  head_session_index);
3325  if (~0 != head_session_index)
3326  {
3327  fa_session_t *sess = pw->fa_sessions_pool + head_session_index;
3328  vlib_cli_output (vm, " last active time: %lu",
3329  sess->last_active_time);
3330  vlib_cli_output (vm, " link enqueue time: %lu",
3331  sess->link_enqueue_time);
3332  }
3333  }
3334 
3335  vlib_cli_output (vm, " Next expiry time: %lu", pw->next_expiry_time);
3336  vlib_cli_output (vm, " Requeue until time: %lu",
3337  pw->requeue_until_time);
3338  vlib_cli_output (vm, " Current time wait interval: %lu",
3340  vlib_cli_output (vm, " Count of deleted sessions: %lu",
3341  pw->cnt_deleted_sessions);
3342  vlib_cli_output (vm, " Delete already deleted: %lu",
3344  vlib_cli_output (vm, " Session timers restarted: %lu",
3346  vlib_cli_output (vm, " Swipe until this time: %lu",
3347  pw->swipe_end_time);
3348  vlib_cli_output (vm, " sw_if_index serviced bitmap: %U",
3349  format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
3350  vlib_cli_output (vm, " pending clear intfc bitmap : %U",
3351  format_bitmap_hex,
3353  vlib_cli_output (vm, " clear in progress: %u", pw->clear_in_process);
3354  vlib_cli_output (vm, " interrupt is pending: %d",
3355  pw->interrupt_is_pending);
3356  vlib_cli_output (vm, " interrupt is needed: %d",
3357  pw->interrupt_is_needed);
3358  vlib_cli_output (vm, " interrupt is unwanted: %d",
3359  pw->interrupt_is_unwanted);
3360  vlib_cli_output (vm, " interrupt generation: %d",
3361  pw->interrupt_generation);
3362  vlib_cli_output (vm, " received session change requests: %d",
3364  vlib_cli_output (vm, " sent session change requests: %d",
3366  }
3367  vlib_cli_output (vm, "\n\nConn cleaner thread counters:");
3368 #define _(cnt, desc) vlib_cli_output(vm, " %20lu: %s", am->cnt, desc);
3370 #undef _
3371  vlib_cli_output (vm, "Interrupt generation: %d",
3373  vlib_cli_output (vm,
3374  "Sessions per interval: min %lu max %lu increment: %f ms current: %f ms",
3377  am->fa_cleaner_wait_time_increment * 1000.0,
3379  1000.0 / (f64) vm->clib_time.clocks_per_second);
3380  vlib_cli_output (vm, "Reclassify sessions: %d", am->reclassify_sessions);
3381 }
3382 
3383 static clib_error_t *
3385  unformat_input_t * input,
3386  vlib_cli_command_t * cmd)
3387 {
3388  clib_error_t *error = 0;
3389  acl_main_t *am = &acl_main;
3390 
3391  u32 show_bihash_verbose = 0;
3392  u32 show_session_thread_id = ~0;
3393  u32 show_session_session_index = ~0;
3394  (void) unformat (input, "thread %u index %u", &show_session_thread_id,
3395  &show_session_session_index);
3396  (void) unformat (input, "verbose %u", &show_bihash_verbose);
3397 
3398  acl_plugin_show_sessions (am, show_session_thread_id,
3399  show_session_session_index);
3400  show_fa_sessions_hash (vm, show_bihash_verbose);
3401  return error;
3402 }
3403 
3404 static clib_error_t *
3406  unformat_input_t * input,
3407  vlib_cli_command_t * cmd)
3408 {
3409  clib_error_t *error = 0;
3410 
3411  u32 acl_index = ~0;
3412  u32 lc_index = ~0;
3413  int show_acl_hash_info = 0;
3414  int show_applied_info = 0;
3415  int show_mask_type = 0;
3416  int show_bihash = 0;
3417  u32 show_bihash_verbose = 0;
3418 
3419  if (unformat (input, "acl"))
3420  {
3421  show_acl_hash_info = 1;
3422  /* mask-type is handy to see as well right there */
3423  show_mask_type = 1;
3424  unformat (input, "index %u", &acl_index);
3425  }
3426  else if (unformat (input, "applied"))
3427  {
3428  show_applied_info = 1;
3429  unformat (input, "lc_index %u", &lc_index);
3430  }
3431  else if (unformat (input, "mask"))
3432  {
3433  show_mask_type = 1;
3434  }
3435  else if (unformat (input, "hash"))
3436  {
3437  show_bihash = 1;
3438  unformat (input, "verbose %u", &show_bihash_verbose);
3439  }
3440 
3441  if (!
3442  (show_mask_type || show_acl_hash_info || show_applied_info
3443  || show_bihash))
3444  {
3445  /* if no qualifiers specified, show all */
3446  show_mask_type = 1;
3447  show_acl_hash_info = 1;
3448  show_applied_info = 1;
3449  show_bihash = 1;
3450  }
3451  vlib_cli_output (vm, "Stats counters enabled for interface ACLs: %d",
3453  if (show_mask_type)
3455  if (show_acl_hash_info)
3457  if (show_applied_info)
3459  if (show_bihash)
3460  acl_plugin_show_tables_bihash (show_bihash_verbose);
3461 
3462  return error;
3463 }
3464 
3465 static clib_error_t *
3467  unformat_input_t * input, vlib_cli_command_t * cmd)
3468 {
3469  clib_error_t *error = 0;
3470  acl_main_t *am = &acl_main;
3473  return error;
3474 }
3475 
3476  /* *INDENT-OFF* */
3477 VLIB_CLI_COMMAND (aclplugin_set_command, static) = {
3478  .path = "set acl-plugin",
3479  .short_help = "set acl-plugin session timeout {{udp idle}|tcp {idle|transient}} <seconds>",
3480  .function = acl_set_aclplugin_fn,
3481 };
3482 
3483 VLIB_CLI_COMMAND (aclplugin_show_acl_command, static) = {
3484  .path = "show acl-plugin acl",
3485  .short_help = "show acl-plugin acl [index N]",
3486  .function = acl_show_aclplugin_acl_fn,
3487 };
3488 
3489 VLIB_CLI_COMMAND (aclplugin_show_lookup_context_command, static) = {
3490  .path = "show acl-plugin lookup context",
3491  .short_help = "show acl-plugin lookup context [index N]",
3493 };
3494 
3495 VLIB_CLI_COMMAND (aclplugin_show_lookup_user_command, static) = {
3496  .path = "show acl-plugin lookup user",
3497  .short_help = "show acl-plugin lookup user [index N]",
3499 };
3500 
3501 VLIB_CLI_COMMAND (aclplugin_show_decode_5tuple_command, static) = {
3502  .path = "show acl-plugin decode 5tuple",
3503  .short_help = "show acl-plugin decode 5tuple XXXX XXXX XXXX XXXX XXXX XXXX",
3505 };
3506 
3507 VLIB_CLI_COMMAND (aclplugin_show_interface_command, static) = {
3508  .path = "show acl-plugin interface",
3509  .short_help = "show acl-plugin interface [sw_if_index N] [acl]",
3510  .function = acl_show_aclplugin_interface_fn,
3511 };
3512 
3513 VLIB_CLI_COMMAND (aclplugin_show_memory_command, static) = {
3514  .path = "show acl-plugin memory",
3515  .short_help = "show acl-plugin memory",
3516  .function = acl_show_aclplugin_memory_fn,
3517 };
3518 
3519 VLIB_CLI_COMMAND (aclplugin_show_sessions_command, static) = {
3520  .path = "show acl-plugin sessions",
3521  .short_help = "show acl-plugin sessions",
3522  .function = acl_show_aclplugin_sessions_fn,
3523 };
3524 
3525 VLIB_CLI_COMMAND (aclplugin_show_tables_command, static) = {
3526  .path = "show acl-plugin tables",
3527  .short_help = "show acl-plugin tables [ acl [index N] | applied [ lc_index N ] | mask | hash [verbose N] ]",
3528  .function = acl_show_aclplugin_tables_fn,
3529 };
3530 
3531 VLIB_CLI_COMMAND (aclplugin_show_macip_acl_command, static) = {
3532  .path = "show acl-plugin macip acl",
3533  .short_help = "show acl-plugin macip acl [index N]",
3534  .function = acl_show_aclplugin_macip_acl_fn,
3535 };
3536 
3537 VLIB_CLI_COMMAND (aclplugin_show_macip_interface_command, static) = {
3538  .path = "show acl-plugin macip interface",
3539  .short_help = "show acl-plugin macip interface",
3541 };
3542 
3543 VLIB_CLI_COMMAND (aclplugin_clear_command, static) = {
3544  .path = "clear acl-plugin sessions",
3545  .short_help = "clear acl-plugin sessions",
3546  .function = acl_clear_aclplugin_fn,
3547 };
3548 /* *INDENT-ON* */
3549 
3550 static clib_error_t *
3552 {
3553  acl_main_t *am = &acl_main;
3554  u32 conn_table_hash_buckets;
3555  uword conn_table_hash_memory_size;
3556  u32 conn_table_max_entries;
3557  uword main_heap_size;
3558  uword hash_heap_size;
3559  u32 hash_lookup_hash_buckets;
3560  uword hash_lookup_hash_memory;
3561  u32 reclassify_sessions;
3562  u32 use_tuple_merge;
3563  u32 tuple_merge_split_threshold;
3564 
3565  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3566  {
3567  if (unformat
3568  (input, "connection hash buckets %d", &conn_table_hash_buckets))
3569  am->fa_conn_table_hash_num_buckets = conn_table_hash_buckets;
3570  else
3571  if (unformat
3572  (input, "connection hash memory %U", unformat_memory_size,
3573  &conn_table_hash_memory_size))
3574  am->fa_conn_table_hash_memory_size = conn_table_hash_memory_size;
3575  else if (unformat (input, "connection count max %d",
3576  &conn_table_max_entries))
3577  am->fa_conn_table_max_entries = conn_table_max_entries;
3578  else
3579  if (unformat
3580  (input, "main heap size %U", unformat_memory_size,
3581  &main_heap_size))
3582  am->acl_mheap_size = main_heap_size;
3583  else
3584  if (unformat
3585  (input, "hash lookup heap size %U", unformat_memory_size,
3586  &hash_heap_size))
3587  am->hash_lookup_mheap_size = hash_heap_size;
3588  else if (unformat (input, "hash lookup hash buckets %d",
3589  &hash_lookup_hash_buckets))
3590  am->hash_lookup_hash_buckets = hash_lookup_hash_buckets;
3591  else
3592  if (unformat
3593  (input, "hash lookup hash memory %U", unformat_memory_size,
3594  &hash_lookup_hash_memory))
3595  am->hash_lookup_hash_memory = hash_lookup_hash_memory;
3596  else if (unformat (input, "use tuple merge %d", &use_tuple_merge))
3597  am->use_tuple_merge = use_tuple_merge;
3598  else
3599  if (unformat
3600  (input, "tuple merge split threshold %d",
3601  &tuple_merge_split_threshold))
3602  am->tuple_merge_split_threshold = tuple_merge_split_threshold;
3603 
3604  else if (unformat (input, "reclassify sessions %d",
3605  &reclassify_sessions))
3606  am->reclassify_sessions = reclassify_sessions;
3607 
3608  else
3609  return clib_error_return (0, "unknown input '%U'",
3610  format_unformat_error, input);
3611  }
3612  return 0;
3613 }
3614 
3615 VLIB_CONFIG_FUNCTION (acl_plugin_config, "acl-plugin");
3616 
3617 /* Set up the API message handling tables */
3618 #include <vnet/format_fns.h>
3619 #include <acl/acl.api.c>
3620 
3621 static clib_error_t *
3623 {
3624  acl_main_t *am = &acl_main;
3625  clib_error_t *error = 0;
3626  clib_memset (am, 0, sizeof (*am));
3627  am->vlib_main = vm;
3628  am->vnet_main = vnet_get_main ();
3629  am->log_default = vlib_log_register_class ("acl_plugin", 0);
3630 
3631  /* Ask for a correctly-sized block of API message decode slots */
3633 
3634  error = acl_plugin_exports_init (&acl_plugin);
3635 
3636  if (error)
3637  return error;
3638 
3639  am->acl_mheap_size = 0; /* auto size when initializing */
3641 
3644 
3651 
3657  am->reclassify_sessions = 0;
3659 
3666 
3667  vec_validate (am->per_worker_data, tm->n_vlib_mains - 1);
3668  {
3669  u16 wk;
3670  for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
3671  {
3673  if (tm->n_vlib_mains > 1)
3674  {
3676  }
3677  vec_validate (pw->expired,
3678  ACL_N_TIMEOUTS *
3680  _vec_len (pw->expired) = 0;
3686  ACL_N_TIMEOUTS - 1, ~0ULL);
3687  }
3688  }
3689 
3690  am->fa_cleaner_cnt_delete_by_sw_index = 0;
3691  am->fa_cleaner_cnt_delete_by_sw_index_ok = 0;
3692  am->fa_cleaner_cnt_unknown_event = 0;
3693  am->fa_cleaner_cnt_timer_restarted = 0;
3694  am->fa_cleaner_cnt_wait_with_timeout = 0;
3695 
3696 
3697 #define _(N, v, s) am->fa_ipv6_known_eh_bitmap = clib_bitmap_set(am->fa_ipv6_known_eh_bitmap, v, 1);
3699 #undef _
3701 
3702  /* use the new fancy hash-based matching */
3703  am->use_hash_acl_matching = 1;
3704  /* use tuplemerge by default */
3705  am->use_tuple_merge = 1;
3706  /* Set the default threshold */
3708 
3709  am->interface_acl_user_id =
3710  acl_plugin.register_user_module ("interface ACL", "sw_if_index",
3711  "is_input");
3712 
3715  am->acl_counter_lock[0] = 0; /* should be no need */
3716 
3717  return error;
3718 }
3719 
3721 
3722 
3723 /*
3724  * fd.io coding-style-patch-verification: ON
3725  *
3726  * Local Variables:
3727  * eval: (c-set-style "gnu")
3728  * End:
3729  */
static void vl_api_acl_stats_intf_counters_enable_t_handler(vl_api_acl_stats_intf_counters_enable_t *mp)
Definition: acl.c:1987
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:176
acl_rule_t * rules
Definition: acl.h:84
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:440
u32 * input_policy_epoch_by_sw_if_index
Definition: acl.h:173
u8 * format_vec16(u8 *s, va_list *va)
Definition: acl.c:64
macip_acl_rule_t * rules
Definition: acl.h:93
u8 count
Definition: dhcp.api:208
static int macip_acl_interface_add_acl(acl_main_t *am, u32 sw_if_index, u32 macip_acl_index)
Definition: acl.c:1828
u8 src_mac[6]
Definition: acl.h:70
u32 fa_cleaner_node_index
Definition: acl.h:234
u32 session_timeout_sec[ACL_N_TIMEOUTS]
Definition: acl.h:236
Use acl_interface_set_acl_list instead Append/remove an ACL index to/from the list of ACLs checked fo...
Definition: acl.api:153
#define vec_foreach_index(var, v)
Iterate over vector indices.
static int macip_acl_interface_add_del_acl(u32 sw_if_index, u8 is_add, u32 acl_list_index)
Definition: acl.c:1896
static void vl_api_acl_plugin_get_conn_table_max_entries_t_handler(vl_api_acl_plugin_get_conn_table_max_entries_t *mp)
Definition: acl.c:263
static clib_error_t * acl_clear_aclplugin_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:3466
static int acl_set_skip_ipv6_eh(u32 eh, u32 value)
Definition: acl.c:2656
static clib_error_t * acl_show_aclplugin_lookup_user_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:3072
static int verify_message_len(void *mp, u32 expected_len, char *where)
Definition: acl.c:1929
void ip6_preflen_to_mask(u8 pref_len, ip6_address_t *mask)
Definition: ip.c:223
void ip4_preflen_to_mask(u8 pref_len, ip4_address_t *ip)
Definition: ip.c:197
#define UDP_SESSION_IDLE_TIMEOUT_SEC
Definition: acl.h:40
static clib_error_t * acl_init(vlib_main_t *vm)
Definition: acl.c:3622
u32 acl_index
Definition: abf.api:58
u8 is_ipv6
Definition: types.h:24
#define FA_SESSION_BOGUS_INDEX
Definition: fa_node.h:166
uword * pending_clear_sw_if_index_bitmap
Definition: fa_node.h:206
static void acl_plugin_counter_lock(acl_main_t *am)
Definition: acl.h:325
void acl_plugin_show_tables_mask_type(void)
Definition: hash_lookup.c:1224
vlib_combined_counter_main_t * combined_acl_counters
Definition: acl.h:309
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
Definition: counter.c:94
static void vl_api_acl_plugin_get_version_t_handler(vl_api_acl_plugin_get_version_t *mp)
Definition: acl.c:164
a
Definition: bitmap.h:538
u64 fa_current_cleaner_timer_wait_interval
Definition: acl.h:276
Set the vector of input/output ACLs checked for an interface.
Definition: acl.api:177
char * stat_segment_name
Name in stat segment directory.
Definition: counter.h:194
Set the ethertype whitelists on an interface.
Definition: acl.api:444
u32 ** input_acl_vec_by_sw_if_index
Definition: acl.h:158
u16 msg_id_base
Definition: acl.h:123
void acl_plugin_hash_acl_set_trace_heap(int on)
Definition: hash_lookup.c:635
void acl_plugin_show_tables_applied_info(u32 lc_index)
Definition: hash_lookup.c:1302
Dump the list(s) of ACL applied to specific or all interfaces.
Definition: acl.api:230
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:269
u32 out_l2_table_index
Definition: acl.h:101
static int count_skip(u8 *p, u32 size)
Definition: acl.c:597
vnet_interface_main_t interface_main
Definition: vnet.h:56
static void vl_api_acl_add_replace_t_handler(vl_api_acl_add_replace_t *mp)
Definition: acl.c:1946
static void vl_api_macip_acl_dump_t_handler(vl_api_macip_acl_dump_t *mp)
Definition: acl.c:2386
#define clib_error(format, args...)
Definition: error.h:62
u64 as_u64[2]
Definition: ip6_packet.h:51
unsigned long u64
Definition: types.h:89
int l4_match_nonfirst_fragment
Definition: acl.h:247
Control ping from the client to the server response.
Definition: acl.api:66
#define ACL_FA_CONN_TABLE_DEFAULT_HASH_NUM_BUCKETS
Definition: fa_node.h:23
#define ACL_PLUGIN_VERSION_MINOR
Definition: acl.h:38
static clib_error_t * acl_plugin_config(vlib_main_t *vm, unformat_input_t *input)
Definition: acl.c:3551
#define ACL_PLUGIN_HASH_LOOKUP_HASH_MEMORY
Definition: acl.h:48
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void vl_api_macip_acl_add_t_handler(vl_api_macip_acl_add_t *mp)
Definition: acl.c:2250
static void vl_api_acl_interface_etype_whitelist_dump_t_handler(vl_api_acl_interface_list_dump_t *mp)
Definition: acl.c:2598
Details about ethertype whitelist on a single interface.
Definition: acl.api:477
f64 clocks_per_second
Definition: time.h:53
u8 dst_prefixlen
Definition: types.h:28
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
static int acl_api_ip4_invalid_prefix(void *ip4_pref_raw, u8 ip4_prefix_len)
Definition: acl.c:370
fa_5tuple_t info
Definition: fa_node.h:106
Reply to get connection table max entries.
Definition: acl.api:89
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
static u64 clib_cpu_time_now(void)
Definition: time.h:75
u32 l2_table_index
Definition: acl.h:97
static void acl_clear_sessions(acl_main_t *am, u32 sw_if_index)
Definition: acl.c:650
static int get_l3_dst_offset(int is6)
Definition: acl.c:1103
int i
static mheap_t * mheap_header(u8 *v)
u16 srcport_or_icmptype_last
Definition: acl_types.api:58
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap. ...
Definition: bitmap.h:167
u64 session_timeout[ACL_N_TIMEOUTS]
Definition: acl.h:284
fa_session_t * fa_sessions_pool
Definition: fa_node.h:170
u16 srcport_or_icmptype_first
Definition: acl_types.api:57
u32 * output_policy_epoch_by_sw_if_index
Definition: acl.h:174
u32 out_dot1q_table_index
Definition: acl.c:1034
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
void(* acl_vector_print_func_t)(vlib_main_t *vm, u8 *out0)
Definition: acl.c:216
clib_time_t clib_time
Definition: main.h:87
u32 dot1ad_table_index
Definition: acl.c:1028
u8 link_list_id
Definition: fa_node.h:117
static void validate_and_reset_acl_counters(acl_main_t *am, u32 acl_index)
Definition: acl.c:337
void * vl_msg_api_alloc(int nbytes)
Delete a MACIP ACL.
Definition: acl.api:325
unsigned char u8
Definition: types.h:56
u8 src_mac_mask[6]
Definition: acl_types.api:94
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
static u32 macip_find_match_type(macip_match_type_t *mv, u8 *mac_mask, u8 prefix_len, u8 is_ipv6)
Definition: acl.c:1041
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
vlib_log_class_t log_default
Definition: acl.h:306
double f64
Definition: types.h:142
Details about one MACIP ACL.
Definition: acl.api:374
void acl_plugin_lookup_context_notify_acl_change(u32 acl_num)
f64 fa_cleaner_wait_time_increment
Definition: acl.h:274
u32 arp_dot1q_table_index
Definition: acl.c:1029
#define clib_bitmap_validate(v, n_bits)
Definition: bitmap.h:115
u32 interface_acl_user_id
Definition: acl.h:153
u32 ** lc_index_vec_by_acl
Definition: acl.h:170
uword fa_conn_table_hash_memory_size
Definition: acl.h:251
u16 dst_port_or_code_last
Definition: types.h:33
u8 src_mac[6]
Definition: acl_types.api:93
static int acl_interface_in_enable_disable(acl_main_t *am, u32 sw_if_index, int enable_disable)
Definition: acl.c:661
static clib_error_t * acl_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: acl.c:2672
format_function_t format_ip4_address
Definition: format.h:73
u8 src_mac_mask[6]
Definition: acl.h:71
u8 src_prefixlen
Definition: types.h:26
ip46_address_t src_ip_addr
Definition: acl.h:72
void mv(vnet_classify_table_t *t)
Definition: vnet_classify.c:76
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Clear a collection of combined counters.
Definition: counter.c:61
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:498
u32 link_prev_idx
Definition: fa_node.h:115
vl_api_interface_index_t sw_if_index
Definition: gre.api:59
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
static int acl_is_not_defined(acl_main_t *am, u32 acl_list_index)
Definition: acl.c:763
static clib_error_t * acl_show_aclplugin_acl_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:3044
volatile u32 * acl_counter_lock
Definition: acl.h:308
u64 fa_conn_table_max_entries
Definition: acl.h:252
static uword clib_bitmap_is_zero(uword *ai)
predicate function; is an entire bitmap empty?
Definition: bitmap.h:57
static int acl_is_used_by(u32 acl_index, u32 **foo_index_vec_by_acl)
Definition: acl.c:553
vnet_main_t * vnet_main
Definition: acl.h:304
ip46_address_t src
Definition: types.h:25
u8 * format_memory_size(u8 *s, va_list *va)
Definition: std-formats.c:209
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Add or delete a MACIP ACL to/from interface.
Definition: acl.api:341
static void increment_policy_epoch(acl_main_t *am, u32 sw_if_index, int is_input)
Definition: acl.c:298
static clib_error_t * acl_show_aclplugin_interface_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:3190
#define clib_error_return(e, args...)
Definition: error.h:99
static u8 * format_acl_action(u8 *s, u8 action)
Definition: manual_fns.h:109
u8 src_prefixlen
Definition: acl.h:73
u8 is_permit
Definition: types.h:23
u8 src_ip_addr[16]
Definition: acl_types.api:39
#define ACL_FA_CONN_TABLE_DEFAULT_MAX_ENTRIES
Definition: fa_node.h:25
uword * in_acl_on_sw_if_index
Definition: acl.h:166
static void acl_print_acl(vlib_main_t *vm, acl_main_t *am, int acl_index)
Definition: acl.c:286
u8 mac_mask[6]
Definition: acl.c:1022
u32 out_arp_dot1q_table_index
Definition: acl.c:1036
unsigned int u32
Definition: types.h:88
#define vec_search(v, E)
Search a vector for the index of the entry that matches.
Definition: vec.h:943
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(acl_sw_interface_add_del)
static clib_error_t * acl_show_aclplugin_decode_5tuple_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:3171
u32 ip4_table_index
Definition: acl.h:95
Get Connection table max entries.
Definition: acl.api:79
Reply to add/replace MACIP ACL.
Definition: acl.api:312
static u8 * my_macip_acl_rule_t_pretty_format(u8 *out, va_list *args)
Definition: acl.c:2907
ip46_address_t dst
Definition: types.h:27
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:63
int vnet_classify_add_del_session(vnet_classify_main_t *cm, u32 table_index, u8 *match, u32 hit_next_index, u32 opaque_index, i32 advance, u8 action, u32 metadata, int is_add)
u8 * format_mheap(u8 *s, va_list *va)
Definition: mem_dlmalloc.c:357
vnet_crypto_main_t * cm
Definition: quic_crypto.c:41
static clib_error_t * acl_show_aclplugin_memory_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:3207
Reply to add MACIP ACL.
Definition: acl.api:279
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:519
static void acl_plugin_show_interface(acl_main_t *am, u32 sw_if_index, int show_acl, int detail)
Definition: acl.c:3087
Details about a single MACIP ACL contents.
Definition: acl.api:427
static void acl_set_session_max_entries(u32 value)
Definition: acl.c:2649
Control ping from client to api server request.
Definition: acl.api:54
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
VLIB_PLUGIN_REGISTER()
#define ACL_FA_DEFAULT_CLEANER_WAIT_TIME_INCREMENT
Definition: acl.h:273
u16 dst_port_or_code_first
Definition: types.h:32
static int acl_api_ip6_invalid_prefix(void *ip6_pref_raw, u8 ip6_prefix_len)
Definition: acl.c:391
#define TCP_SESSION_IDLE_TIMEOUT_SEC
Definition: acl.h:41
static void warning_acl_print_acl(vlib_main_t *vm, acl_main_t *am, int acl_index)
Definition: acl.c:292
static void vl_api_acl_dump_t_handler(vl_api_acl_dump_t *mp)
Definition: acl.c:2129
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
uword * fa_ipv6_known_eh_bitmap
Definition: acl.h:244
u64 memory_size
Definition: vhost_user.h:141
Replace an existing ACL in-place or create a new ACL.
Definition: acl.api:104
#define ACL_FA_DEFAULT_MIN_DELETED_SESSIONS_PER_INTERVAL
Definition: acl.h:270
u64 size
Definition: vhost_user.h:140
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:287
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:376
u32 * output_lc_index_by_sw_if_index
Definition: acl.h:151
void acl_plugin_acl_set_validate_heap(acl_main_t *am, int on)
Definition: acl.c:127
Details about a single ACL contents.
Definition: acl.api:246
static clib_error_t * acl_show_aclplugin_tables_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:3405
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:182
#define REPLY_MACRO(t)
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:806
vl_api_acl_rule_t r[count]
Definition: acl.api:111
static void send_acl_details(acl_main_t *am, vl_api_registration_t *reg, acl_list_t *acl, u32 context)
Definition: acl.c:2097
vl_api_address_union_t src_address
Definition: ip_types.api:98
static int get_l3_src_offset(int is6)
Definition: acl.c:1092
f64 seconds_per_clock
Definition: time.h:57
int vnet_set_input_acl_intfc(vlib_main_t *vm, u32 sw_if_index, u32 ip4_table_index, u32 ip6_table_index, u32 l2_table_index, u32 is_add)
Definition: in_out_acl.c:129
u64 last_active_time
Definition: fa_node.h:107
static int macip_maybe_apply_unapply_classifier_tables(acl_main_t *am, u32 acl_index, int is_apply)
Definition: acl.c:1674
static void send_acl_interface_etype_whitelist_details(acl_main_t *am, vl_api_registration_t *reg, u32 sw_if_index, u32 context)
Definition: acl.c:2539
u32 interface_acl_counters_enabled
Definition: acl.h:311
void acl_plugin_hash_acl_set_validate_heap(int on)
Definition: hash_lookup.c:617
u8 proto
Definition: types.h:29
static u8 * my_format_mac_address(u8 *s, va_list *args)
Definition: acl.c:2899
u64 * fa_conn_list_head_expiry_time
Definition: fa_node.h:181
vlib_main_t * vm
Definition: in2out_ed.c:1810
u32 out_arp_dot1ad_table_index
Definition: acl.c:1037
#define FA_POLICY_EPOCH_IS_INPUT
Definition: fa_node.h:126
u16 src_port_or_type_first
Definition: types.h:30
u64 fa_min_deleted_sessions_per_interval
Definition: acl.h:271
static int match_type_compare(macip_match_type_t *m1, macip_match_type_t *m2)
Definition: acl.c:1084
static void acl_print_acl_x(acl_vector_print_func_t vpr, vlib_main_t *vm, acl_main_t *am, int acl_index)
Definition: acl.c:219
format_function_t format_ip46_address
Definition: ip46_address.h:50
void acl_plugin_show_tables_bihash(u32 show_bihash_verbose)
Definition: hash_lookup.c:1352
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:231
union fa_session_t::@16 tcp_flags_seen
vl_api_acl_rule_t r[count]
Definition: acl.api:221
An API client registration, only in vpp/vlib.
Definition: api_common.h:46
Dump the list(s) of MACIP ACLs applied to specific or all interfaces.
Definition: acl.api:413
static void vl_api_acl_interface_set_etype_whitelist_t_handler(vl_api_acl_interface_set_etype_whitelist_t *mp)
Definition: acl.c:2509
int vnet_l2_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
static int match_type_metric(macip_match_type_t *m)
Definition: acl.c:1063
static int macip_acl_del_list(u32 acl_list_index)
Definition: acl.c:1860
Dump one or all defined MACIP ACLs.
Definition: acl.api:358
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
static int acl_classify_add_del_table_small(vnet_classify_main_t *cm, u8 *mask, u32 mask_len, u32 next_table_index, u32 miss_next_index, u32 *table_index, int is_add)
Definition: acl.c:612
u8 src_ip_prefix_len
Definition: acl_types.api:40
format_function_t format_ip6_address
Definition: format.h:91
static void acl_plugin_show_acl(acl_main_t *am, u32 acl_index)
Definition: acl.c:3005
static uword * clib_bitmap_dup_xor(uword *ai, uword *bi)
Logical operator across two bitmaps which duplicates the first bitmap.
u64 fa_session_total_adds
Definition: acl.h:238
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:342
void acl_plugin_acl_set_trace_heap(acl_main_t *am, int on)
Definition: acl.c:147
void * heap_base
Definition: main.h:143
u32 dot1q_table_index
Definition: acl.c:1027
void acl_fa_enable_disable(u32 sw_if_index, int is_input, int enable_disable)
static int acl_stats_intf_counters_enable_disable(acl_main_t *am, int enable_disable)
Definition: acl.c:743
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:283
Reply to add/replace ACL.
Definition: acl.api:121
#define clib_warning(format, args...)
Definition: error.h:59
Reply with the vector of MACIP ACLs by sw_if_index.
Definition: acl.api:400
static void acl_plugin_counter_unlock(acl_main_t *am)
Definition: acl.h:333
u8 * format_vec32(u8 *s, va_list *va)
Definition: std-formats.c:43
void acl_plugin_show_lookup_user(u32 user_index)
u32 sw_if_index
Definition: fa_node.h:108
int use_hash_acl_matching
Definition: acl.h:185
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:284
static clib_error_t * acl_plugin_exports_init(acl_plugin_methods_t *m)
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
uword hash_lookup_hash_memory
Definition: acl.h:134
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:57
#define foreach_fa_cleaner_counter
Definition: acl.h:289
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:302
static int acl_interface_out_enable_disable(acl_main_t *am, u32 sw_if_index, int enable_disable)
Definition: acl.c:701
int tuple_merge_split_threshold
Definition: acl.h:192
u8 is_ipv6
Definition: acl.h:69
u32 out_arp_table_index
Definition: acl.c:1033
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
struct _vnet_classify_main vnet_classify_main_t
Definition: vnet_classify.h:55
vl_api_gbp_rule_t rules[n_rules]
Definition: gbp.api:315
int trace_acl
Definition: acl.h:255
static clib_error_t * acl_show_aclplugin_macip_acl_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:2953
#define ACL_PLUGIN_HASH_LOOKUP_HASH_BUCKETS
Definition: acl.h:47
signed int i32
Definition: types.h:77
u32 hash_lookup_hash_buckets
Definition: acl.h:133
static void vl_api_acl_interface_add_del_t_handler(vl_api_acl_interface_add_del_t *mp)
Definition: acl.c:2000
u8 value
Definition: qos.api:54
#define ASSERT(truth)
static int macip_acl_interface_del_acl(acl_main_t *am, u32 sw_if_index)
Definition: acl.c:1791
int trace_sessions
Definition: acl.h:254
u32 out_ip6_table_index
Definition: acl.h:100
u8 tag[64]
Definition: acl.h:83
static void vl_api_macip_acl_del_t_handler(vl_api_macip_acl_del_t *mp)
Definition: acl.c:2304
static int acl_interface_inout_enable_disable(acl_main_t *am, u32 sw_if_index, int is_input, int enable_disable)
Definition: acl.c:753
u16 src_port_or_type_last
Definition: types.h:31
static int macip_create_classify_tables(acl_main_t *am, u32 macip_acl_index)
Definition: acl.c:1126
static void acl_set_timeout_sec(int timeout_type, u32 value)
Definition: acl.c:2630
void * mheap_alloc_with_lock(void *memory, uword size, int locked)
Definition: mem_dlmalloc.c:460
uword * out_acl_on_sw_if_index
Definition: acl.h:167
u8 dst_ip_prefix_len
Definition: acl_types.api:42
void acl_plugin_show_lookup_context(u32 lc_index)
u32 ** sw_if_index_vec_by_macip_acl
Definition: acl.h:224
#define MHEAP_FLAG_VALIDATE
static int macip_permit_also_egress(u8 is_permit)
Definition: acl.c:1120
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
acl_main_t acl_main
Definition: acl.c:40
vnet_classify_main_t vnet_classify_main
Definition: vnet_classify.c:29
static void vl_api_macip_acl_add_replace_t_handler(vl_api_macip_acl_add_replace_t *mp)
Definition: acl.c:2277
Delete an ACL.
Definition: acl.api:134
Reply to get the plugin version.
Definition: acl.api:43
static int macip_acl_add_list(u32 count, vl_api_macip_acl_rule_t rules[], u32 *acl_list_index, u8 *tag)
Definition: acl.c:1701
uword * serviced_sw_if_index_bitmap
Definition: fa_node.h:204
u32 count
Definition: acl.h:92
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:380
Reply to set the ACL list on an interface.
Definition: acl.api:199
u32 link_next_idx
Definition: fa_node.h:116
uword acl_mheap_size
Definition: acl.h:120
int vnet_classify_add_del_table(vnet_classify_main_t *cm, u8 *mask, u32 nbuckets, u32 memory_size, u32 skip, u32 match, u32 next_table_index, u32 miss_next_index, u32 *table_index, u8 current_data_flag, i16 current_data_offset, int is_add, int del_chain)
#define MHEAP_FLAG_TRACE
#define vec_elt(v, i)
Get vector value at index i.
#define MHEAP_FLAG_SMALL_OBJECT_CACHE
static void macip_acl_print(acl_main_t *am, u32 macip_acl_index)
Definition: acl.c:2922
u32 * macip_acl_by_sw_if_index
Definition: acl.h:221
Get the vector of MACIP ACL IDs applied to the interfaces.
Definition: acl.api:388
static void vl_api_acl_interface_list_dump_t_handler(vl_api_acl_interface_list_dump_t *mp)
Definition: acl.c:2216
u16 as_u16
Definition: fa_node.h:111
static void acl_interface_reset_inout_acls(u32 sw_if_index, u8 is_input, int *may_clear_sessions)
Definition: acl.c:908
Add/Replace a MACIP ACL.
Definition: acl.api:295
static int acl_add_list(u32 count, vl_api_acl_rule_t rules[], u32 *acl_list_index, u8 *tag)
Definition: acl.c:414
static void print_clib_warning_and_reset(vlib_main_t *vm, u8 *out0)
Definition: acl.c:203
static int acl_set_etype_whitelists(acl_main_t *am, u32 sw_if_index, u16 *vec_in, u16 *vec_out)
Definition: acl.c:981
u32 out_table_index
Definition: acl.c:1032
u32 arp_dot1ad_table_index
Definition: acl.c:1030
static void vl_api_acl_del_t_handler(vl_api_acl_del_t *mp)
Definition: acl.c:1973
u8 action
Definition: l2.api:173
static void send_macip_acl_details(acl_main_t *am, vl_api_registration_t *reg, macip_acl_list_t *acl, u32 context)
Definition: acl.c:2336
macip_acl_list_t * macip_acls
Definition: acl.h:155
static clib_error_t * acl_show_aclplugin_sessions_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:3384
static acl_plugin_methods_t acl_plugin
Definition: acl.c:60
static void send_macip_acl_interface_list_details(acl_main_t *am, vl_api_registration_t *reg, u32 sw_if_index, u32 acl_index, u32 context)
Definition: acl.c:2448
uword hash_lookup_mheap_size
Definition: acl.h:138
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Details about a single ACL contents.
Definition: acl.api:215
u32 ip6_table_index
Definition: acl.h:96
static void vl_api_macip_acl_interface_list_dump_t_handler(vl_api_macip_acl_interface_list_dump_t *mp)
Definition: acl.c:2473
u8 tcp_flags_mask
Definition: types.h:35
acl_fa_per_worker_data_t * per_worker_data
Definition: acl.h:281
u64 uword
Definition: types.h:112
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:983
u16 dstport_or_icmpcode_first
Definition: acl_types.api:59
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:854
int fa_interrupt_generation
Definition: acl.h:278
u32 ** input_sw_if_index_vec_by_acl
Definition: acl.h:162
char * name
The counter collection&#39;s name.
Definition: counter.h:193
int use_tuple_merge
Definition: acl.h:188
u16 ** output_etype_whitelist_by_sw_if_index
Definition: acl.h:218
static void vl_api_acl_interface_set_acl_list_t_handler(vl_api_acl_interface_set_acl_list_t *mp)
Definition: acl.c:2020
u64 fa_max_deleted_sessions_per_interval
Definition: acl.h:263
void * acl_mheap
Definition: acl.h:119
void * acl_plugin_set_heap()
Definition: acl.c:120
static clib_error_t * acl_set_aclplugin_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:2699
u16 thread_index
Definition: fa_node.h:112
unformat_function_t unformat_memory_size
Definition: format.h:296
static void try_increment_acl_policy_epoch(acl_main_t *am, u32 acl_num, int is_input)
Definition: acl.c:313
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:161
static int acl_interface_add_del_inout_acl(u32 sw_if_index, u8 is_add, u8 is_input, u32 acl_list_index)
Definition: acl.c:919
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
static void policy_notify_acl_change(acl_main_t *am, u32 acl_num)
Definition: acl.c:329
u8 tcp_flags_value
Definition: types.h:34
Get the plugin version.
Definition: acl.api:31
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
static void acl_plugin_show_sessions(acl_main_t *am, u32 show_session_thread_id, u32 show_session_session_index)
Definition: acl.c:3236
static void copy_acl_rule_to_api_rule(vl_api_acl_rule_t *api_rule, acl_rule_t *r)
Definition: acl.c:2071
u16 ** input_etype_whitelist_by_sw_if_index
Definition: acl.h:217
void mheap_validate(void *v)
Definition: mheap.c:1378
#define vec_foreach(var, vec)
Vector iterator.
static void * acl_set_heap(acl_main_t *am)
Definition: acl.c:79
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: nat_api.c:3410
clib_spinlock_t pending_session_change_request_lock
Definition: fa_node.h:172
unsigned long long u32x4
Definition: ixge.c:28
void * hash_lookup_mheap
Definition: acl.h:137
u64 fa_session_total_deactivations
Definition: acl.h:241
static void print_cli_and_reset(vlib_main_t *vm, u8 *out0)
Definition: acl.c:210
Add a MACIP ACL.
Definition: acl.api:263
int reclassify_sessions
Definition: acl.h:177
void show_fa_sessions_hash(vlib_main_t *vm, u32 verbose)
u8 * format_acl_plugin_5tuple(u8 *s, va_list *args)
u32 * input_lc_index_by_sw_if_index
Definition: acl.h:150
u32 vl_msg_api_get_msg_length(void *msg_arg)
Definition: api_shared.c:742
Definition: acl.h:79
u32 out_ip4_table_index
Definition: acl.h:99
u32 client_index
Definition: acl.api:201
u16 dstport_or_icmpcode_last
Definition: acl_types.api:60
u32 ** output_sw_if_index_vec_by_acl
Definition: acl.h:163
u8 dst_ip_addr[16]
Definition: acl_types.api:41
#define ACL_PLUGIN_VERSION_MAJOR
Definition: acl.h:37
u8 tag[64]
Definition: acl.h:91
static clib_error_t * acl_show_aclplugin_macip_interface_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:2989
#define FA_POLICY_EPOCH_MASK
Definition: fa_node.h:124
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:487
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
#define ACL_PLUGIN_HASH_LOOKUP_HEAP_SIZE
Definition: acl.h:46
static int intf_has_etype_whitelist(acl_main_t *am, u32 sw_if_index, int is_input)
Definition: acl.c:640
void acl_plugin_show_tables_acl_hash_info(u32 acl_index)
Definition: hash_lookup.c:1243
#define TM_SPLIT_THRESHOLD
Definition: acl.h:191
static int acl_interface_set_inout_acl_list(acl_main_t *am, u32 sw_if_index, u8 is_input, u32 *vec_acl_list_index, int *may_clear_sessions)
Definition: acl.c:769
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
#define ACL_FA_DEFAULT_MAX_DELETED_SESSIONS_PER_INTERVAL
Definition: acl.h:262
static void vl_api_acl_plugin_control_ping_t_handler(vl_api_acl_plugin_control_ping_t *mp)
Definition: acl.c:187
acl_list_t * acls
Definition: acl.h:130
int vnet_set_output_acl_intfc(vlib_main_t *vm, u32 sw_if_index, u32 ip4_table_index, u32 ip6_table_index, u32 l2_table_index, u32 is_add)
Definition: in_out_acl.c:139
u32 ** output_acl_vec_by_sw_if_index
Definition: acl.h:159
static clib_error_t * acl_show_aclplugin_lookup_context_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: acl.c:3058
u32 out_dot1ad_table_index
Definition: acl.c:1035
#define TCP_SESSION_TRANSIENT_TIMEOUT_SEC
Definition: acl.h:42
u8 is_permit
Definition: acl.h:68
static void vl_api_macip_acl_interface_add_del_t_handler(vl_api_macip_acl_interface_add_del_t *mp)
Definition: acl.c:2317
u32 arp_table_index
Definition: acl.c:1026
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
u64 link_enqueue_time
Definition: fa_node.h:114
u32 fa_conn_table_hash_num_buckets
Definition: acl.h:250
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
#define ACL_FA_CONN_TABLE_DEFAULT_HASH_MEMORY_SIZE
Definition: fa_node.h:24
u64 fa_session_total_dels
Definition: acl.h:239
static int acl_del_list(u32 acl_list_index)
Definition: acl.c:567
static void send_acl_interface_list_details(acl_main_t *am, vl_api_registration_t *reg, u32 sw_if_index, u32 context)
Definition: acl.c:2169
static void macip_destroy_classify_tables(acl_main_t *am, u32 macip_acl_index)
Definition: acl.c:1630
Enable or disable incrementing ACL counters in stats segment by interface processing.
Definition: acl.api:492
static void vl_api_macip_acl_interface_get_t_handler(vl_api_macip_acl_interface_get_t *mp)
Definition: acl.c:2419
u8 is_ipv6
Definition: acl_types.api:38
foreach_fa_cleaner_counter vlib_main_t * vlib_main
Definition: acl.h:303