FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
fa_node.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 #include <stddef.h>
16 #include <netinet/in.h>
17 
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
20 #include <vnet/pg/pg.h>
21 #include <vppinfra/error.h>
22 #include <acl/acl.h>
23 #include "bihash_40_8.h"
24 
27 
28 #include "fa_node.h"
29 #include "hash_lookup.h"
30 
31 typedef struct
32 {
37  u64 packet_info[6];
41 
42 /* packet trace format function */
43 static u8 *
44 format_acl_fa_trace (u8 * s, va_list * args)
45 {
46  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
47  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
48  acl_fa_trace_t *t = va_arg (*args, acl_fa_trace_t *);
49 
50  s =
51  format (s,
52  "acl-plugin: sw_if_index %d, next index %d, action: %d, match: acl %d rule %d trace_bits %08x\n"
53  " pkt info %016llx %016llx %016llx %016llx %016llx %016llx",
56  t->packet_info[0], t->packet_info[1], t->packet_info[2],
57  t->packet_info[3], t->packet_info[4], t->packet_info[5]);
58  return s;
59 }
60 
61 /* *INDENT-OFF* */
62 #define foreach_acl_fa_error \
63 _(ACL_DROP, "ACL deny packets") \
64 _(ACL_PERMIT, "ACL permit packets") \
65 _(ACL_NEW_SESSION, "new sessions added") \
66 _(ACL_EXIST_SESSION, "existing session packets") \
67 _(ACL_CHECK, "checked packets") \
68 _(ACL_RESTART_SESSION_TIMER, "restart session timer") \
69 _(ACL_TOO_MANY_SESSIONS, "too many sessions to add new") \
70 /* end of errors */
71 
72 typedef enum
73 {
74 #define _(sym,str) ACL_FA_ERROR_##sym,
76 #undef _
79 
80 static char *acl_fa_error_strings[] = {
81 #define _(sym,string) string,
83 #undef _
84 };
85 /* *INDENT-ON* */
86 
87 static void *
89 {
90  u8 *p = vlib_buffer_get_current (b0) + offset;
91  return p;
92 }
93 
94 
95 static int
96 fa_acl_match_addr (ip46_address_t * addr1, ip46_address_t * addr2,
97  int prefixlen, int is_ip6)
98 {
99  if (prefixlen == 0)
100  {
101  /* match any always succeeds */
102  return 1;
103  }
104  if (is_ip6)
105  {
106  if (memcmp (addr1, addr2, prefixlen / 8))
107  {
108  /* If the starting full bytes do not match, no point in bittwidling the thumbs further */
109  return 0;
110  }
111  if (prefixlen % 8)
112  {
113  u8 b1 = *((u8 *) addr1 + 1 + prefixlen / 8);
114  u8 b2 = *((u8 *) addr2 + 1 + prefixlen / 8);
115  u8 mask0 = (0xff - ((1 << (8 - (prefixlen % 8))) - 1));
116  return (b1 & mask0) == b2;
117  }
118  else
119  {
120  /* The prefix fits into integer number of bytes, so nothing left to do */
121  return 1;
122  }
123  }
124  else
125  {
126  uint32_t a1 = ntohl (addr1->ip4.as_u32);
127  uint32_t a2 = ntohl (addr2->ip4.as_u32);
128  uint32_t mask0 = 0xffffffff - ((1 << (32 - prefixlen)) - 1);
129  return (a1 & mask0) == a2;
130  }
131 }
132 
133 static int
134 fa_acl_match_port (u16 port, u16 port_first, u16 port_last, int is_ip6)
135 {
136  return ((port >= port_first) && (port <= port_last));
137 }
138 
139 int
140 single_acl_match_5tuple (acl_main_t * am, u32 acl_index, fa_5tuple_t * pkt_5tuple,
141  int is_ip6, u8 * r_action, u32 * r_acl_match_p,
142  u32 * r_rule_match_p, u32 * trace_bitmap)
143 {
144  int i;
145  acl_list_t *a;
146  acl_rule_t *r;
147 
148  if (pool_is_free_index (am->acls, acl_index))
149  {
150  if (r_acl_match_p)
151  *r_acl_match_p = acl_index;
152  if (r_rule_match_p)
153  *r_rule_match_p = -1;
154  /* the ACL does not exist but is used for policy. Block traffic. */
155  return 0;
156  }
157  a = am->acls + acl_index;
158  for (i = 0; i < a->count; i++)
159  {
160  r = a->rules + i;
161  if (is_ip6 != r->is_ipv6)
162  {
163  continue;
164  }
165  if (!fa_acl_match_addr
166  (&pkt_5tuple->addr[1], &r->dst, r->dst_prefixlen, is_ip6))
167  continue;
168 
169 #ifdef FA_NODE_VERBOSE_DEBUG
171  ("ACL_FA_NODE_DBG acl %d rule %d pkt dst addr %U match rule addr %U/%d",
172  acl_index, i, format_ip46_address, &pkt_5tuple->addr[1],
174  r->dst_prefixlen);
175 #endif
176 
177  if (!fa_acl_match_addr
178  (&pkt_5tuple->addr[0], &r->src, r->src_prefixlen, is_ip6))
179  continue;
180 
181 #ifdef FA_NODE_VERBOSE_DEBUG
183  ("ACL_FA_NODE_DBG acl %d rule %d pkt src addr %U match rule addr %U/%d",
184  acl_index, i, format_ip46_address, &pkt_5tuple->addr[0],
186  r->src_prefixlen);
188  ("ACL_FA_NODE_DBG acl %d rule %d trying to match pkt proto %d with rule %d",
189  acl_index, i, pkt_5tuple->l4.proto, r->proto);
190 #endif
191  if (r->proto)
192  {
193  if (pkt_5tuple->l4.proto != r->proto)
194  continue;
195 
196  if (PREDICT_FALSE (pkt_5tuple->pkt.is_nonfirst_fragment &&
198  {
199  /* non-initial fragment with frag match configured - match this rule */
200  *trace_bitmap |= 0x80000000;
201  *r_action = r->is_permit;
202  if (r_acl_match_p)
203  *r_acl_match_p = acl_index;
204  if (r_rule_match_p)
205  *r_rule_match_p = i;
206  return 1;
207  }
208 
209  /* A sanity check just to ensure we are about to match the ports extracted from the packet */
210  if (PREDICT_FALSE (!pkt_5tuple->pkt.l4_valid))
211  continue;
212 
213 #ifdef FA_NODE_VERBOSE_DEBUG
215  ("ACL_FA_NODE_DBG acl %d rule %d pkt proto %d match rule %d",
216  acl_index, i, pkt_5tuple->l4.proto, r->proto);
217 #endif
218 
219  if (!fa_acl_match_port
220  (pkt_5tuple->l4.port[0], r->src_port_or_type_first,
221  r->src_port_or_type_last, is_ip6))
222  continue;
223 
224 #ifdef FA_NODE_VERBOSE_DEBUG
226  ("ACL_FA_NODE_DBG acl %d rule %d pkt sport %d match rule [%d..%d]",
227  acl_index, i, pkt_5tuple->l4.port[0], r->src_port_or_type_first,
229 #endif
230 
231  if (!fa_acl_match_port
232  (pkt_5tuple->l4.port[1], r->dst_port_or_code_first,
233  r->dst_port_or_code_last, is_ip6))
234  continue;
235 
236 #ifdef FA_NODE_VERBOSE_DEBUG
238  ("ACL_FA_NODE_DBG acl %d rule %d pkt dport %d match rule [%d..%d]",
239  acl_index, i, pkt_5tuple->l4.port[1], r->dst_port_or_code_first,
241 #endif
242  if (pkt_5tuple->pkt.tcp_flags_valid
243  && ((pkt_5tuple->pkt.tcp_flags & r->tcp_flags_mask) !=
244  r->tcp_flags_value))
245  continue;
246  }
247  /* everything matches! */
248 #ifdef FA_NODE_VERBOSE_DEBUG
249  clib_warning ("ACL_FA_NODE_DBG acl %d rule %d FULL-MATCH, action %d",
250  acl_index, i, r->is_permit);
251 #endif
252  *r_action = r->is_permit;
253  if (r_acl_match_p)
254  *r_acl_match_p = acl_index;
255  if (r_rule_match_p)
256  *r_rule_match_p = i;
257  return 1;
258  }
259  return 0;
260 }
261 
262 static u8
263 linear_multi_acl_match_5tuple (u32 sw_if_index, fa_5tuple_t * pkt_5tuple, int is_l2,
264  int is_ip6, int is_input, u32 * acl_match_p,
265  u32 * rule_match_p, u32 * trace_bitmap)
266 {
267  acl_main_t *am = &acl_main;
268  int i;
269  u32 *acl_vector;
270  u8 action = 0;
271 
272  if (is_input)
273  {
274  vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
275  acl_vector = am->input_acl_vec_by_sw_if_index[sw_if_index];
276  }
277  else
278  {
279  vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
280  acl_vector = am->output_acl_vec_by_sw_if_index[sw_if_index];
281  }
282  for (i = 0; i < vec_len (acl_vector); i++)
283  {
284 #ifdef FA_NODE_VERBOSE_DEBUG
285  clib_warning ("ACL_FA_NODE_DBG: Trying to match ACL: %d",
286  acl_vector[i]);
287 #endif
289  (am, acl_vector[i], pkt_5tuple, is_ip6, &action,
290  acl_match_p, rule_match_p, trace_bitmap))
291  {
292  return action;
293  }
294  }
295  if (vec_len (acl_vector) > 0)
296  {
297  /* If there are ACLs and none matched, deny by default */
298  return 0;
299  }
300 #ifdef FA_NODE_VERBOSE_DEBUG
301  clib_warning ("ACL_FA_NODE_DBG: No ACL on sw_if_index %d", sw_if_index);
302 #endif
303  /* Deny by default. If there are no ACLs defined we should not be here. */
304  return 0;
305 }
306 
307 static u8
308 multi_acl_match_5tuple (u32 sw_if_index, fa_5tuple_t * pkt_5tuple, int is_l2,
309  int is_ip6, int is_input, u32 * acl_match_p,
310  u32 * rule_match_p, u32 * trace_bitmap)
311 {
312  acl_main_t *am = &acl_main;
313  if (am->use_hash_acl_matching) {
314  return hash_multi_acl_match_5tuple(sw_if_index, pkt_5tuple, is_l2, is_ip6,
315  is_input, acl_match_p, rule_match_p, trace_bitmap);
316  } else {
317  return linear_multi_acl_match_5tuple(sw_if_index, pkt_5tuple, is_l2, is_ip6,
318  is_input, acl_match_p, rule_match_p, trace_bitmap);
319  }
320 }
321 
322 static int
324 {
325  /* For the purposes of this code, "within" means we have at least 8 bytes after it */
326  return (offset <= (b0->current_length - 8));
327 }
328 
329 static void
330 acl_fill_5tuple (acl_main_t * am, vlib_buffer_t * b0, int is_ip6,
331  int is_input, int is_l2_path, fa_5tuple_t * p5tuple_pkt)
332 {
333  int l3_offset = ethernet_buffer_header_size(b0);
334  int l4_offset;
335  u16 ports[2];
336  u16 proto;
337  /* IP4 and IP6 protocol numbers of ICMP */
338  static u8 icmp_protos[] = { IP_PROTOCOL_ICMP, IP_PROTOCOL_ICMP6 };
339 
340  if (is_input && !(is_l2_path))
341  {
342  l3_offset = 0;
343  }
344 
345  /* key[0..3] contains src/dst address and is cleared/set below */
346  /* Remainder of the key and per-packet non-key data */
347  p5tuple_pkt->kv.key[4] = 0;
348  p5tuple_pkt->kv.value = 0;
349 
350  if (is_ip6)
351  {
352  clib_memcpy (&p5tuple_pkt->addr,
353  get_ptr_to_offset (b0,
354  offsetof (ip6_header_t,
355  src_address) + l3_offset),
356  sizeof (p5tuple_pkt->addr));
357  proto =
358  *(u8 *) get_ptr_to_offset (b0,
359  offsetof (ip6_header_t,
360  protocol) + l3_offset);
361  l4_offset = l3_offset + sizeof (ip6_header_t);
362 #ifdef FA_NODE_VERBOSE_DEBUG
363  clib_warning ("ACL_FA_NODE_DBG: proto: %d, l4_offset: %d", proto,
364  l4_offset);
365 #endif
366  /* IP6 EH handling is here, increment l4_offset if needs to, update the proto */
367  int need_skip_eh = clib_bitmap_get (am->fa_ipv6_known_eh_bitmap, proto);
368  if (PREDICT_FALSE (need_skip_eh))
369  {
370  while (need_skip_eh && offset_within_packet (b0, l4_offset))
371  {
372  /* Fragment header needs special handling */
373  if (PREDICT_FALSE(ACL_EH_FRAGMENT == proto))
374  {
375  proto = *(u8 *) get_ptr_to_offset (b0, l4_offset);
376  u16 frag_offset;
377  clib_memcpy (&frag_offset, get_ptr_to_offset (b0, 2 + l4_offset), sizeof(frag_offset));
378  frag_offset = ntohs(frag_offset) >> 3;
379  if (frag_offset)
380  {
381  p5tuple_pkt->pkt.is_nonfirst_fragment = 1;
382  /* invalidate L4 offset so we don't try to find L4 info */
383  l4_offset += b0->current_length;
384  }
385  else
386  {
387  /* First fragment: skip the frag header and move on. */
388  l4_offset += 8;
389  }
390  }
391  else
392  {
393  u8 nwords = *(u8 *) get_ptr_to_offset (b0, 1 + l4_offset);
394  proto = *(u8 *) get_ptr_to_offset (b0, l4_offset);
395  l4_offset += 8 * (1 + (u16) nwords);
396  }
397 #ifdef FA_NODE_VERBOSE_DEBUG
398  clib_warning ("ACL_FA_NODE_DBG: new proto: %d, new offset: %d",
399  proto, l4_offset);
400 #endif
401  need_skip_eh =
403  }
404  }
405  }
406  else
407  {
408  p5tuple_pkt->kv.key[0] = 0;
409  p5tuple_pkt->kv.key[1] = 0;
410  p5tuple_pkt->kv.key[2] = 0;
411  p5tuple_pkt->kv.key[3] = 0;
412  clib_memcpy (&p5tuple_pkt->addr[0].ip4,
413  get_ptr_to_offset (b0,
414  offsetof (ip4_header_t,
415  src_address) + l3_offset),
416  sizeof (p5tuple_pkt->addr[0].ip4));
417  clib_memcpy (&p5tuple_pkt->addr[1].ip4,
418  get_ptr_to_offset (b0,
419  offsetof (ip4_header_t,
420  dst_address) + l3_offset),
421  sizeof (p5tuple_pkt->addr[1].ip4));
422  proto =
423  *(u8 *) get_ptr_to_offset (b0,
424  offsetof (ip4_header_t,
425  protocol) + l3_offset);
426  l4_offset = l3_offset + sizeof (ip4_header_t);
427  u16 flags_and_fragment_offset;
428  clib_memcpy (&flags_and_fragment_offset,
429  get_ptr_to_offset (b0,
430  offsetof (ip4_header_t,
431  flags_and_fragment_offset)) + l3_offset,
432  sizeof(flags_and_fragment_offset));
433  flags_and_fragment_offset = ntohs (flags_and_fragment_offset);
434 
435  /* non-initial fragments have non-zero offset */
436  if ((PREDICT_FALSE(0xfff & flags_and_fragment_offset)))
437  {
438  p5tuple_pkt->pkt.is_nonfirst_fragment = 1;
439  /* invalidate L4 offset so we don't try to find L4 info */
440  l4_offset += b0->current_length;
441  }
442 
443  }
444  p5tuple_pkt->l4.proto = proto;
445  if (PREDICT_TRUE (offset_within_packet (b0, l4_offset)))
446  {
447  p5tuple_pkt->pkt.l4_valid = 1;
448  if (icmp_protos[is_ip6] == proto)
449  {
450  /* type */
451  p5tuple_pkt->l4.port[0] =
452  *(u8 *) get_ptr_to_offset (b0,
453  l4_offset + offsetof (icmp46_header_t,
454  type));
455  /* code */
456  p5tuple_pkt->l4.port[1] =
457  *(u8 *) get_ptr_to_offset (b0,
458  l4_offset + offsetof (icmp46_header_t,
459  code));
460  }
461  else if ((IPPROTO_TCP == proto) || (IPPROTO_UDP == proto))
462  {
463  clib_memcpy (&ports,
464  get_ptr_to_offset (b0,
465  l4_offset + offsetof (tcp_header_t,
466  src_port)),
467  sizeof (ports));
468  p5tuple_pkt->l4.port[0] = ntohs (ports[0]);
469  p5tuple_pkt->l4.port[1] = ntohs (ports[1]);
470 
471  p5tuple_pkt->pkt.tcp_flags =
472  *(u8 *) get_ptr_to_offset (b0,
473  l4_offset + offsetof (tcp_header_t,
474  flags));
475  p5tuple_pkt->pkt.tcp_flags_valid = (proto == IPPROTO_TCP);
476  }
477  /*
478  * FIXME: rather than the above conditional, here could
479  * be a nice generic mechanism to extract two L4 values:
480  *
481  * have a per-protocol array of 4 elements like this:
482  * u8 offset; to take the byte from, off L4 header
483  * u8 mask; to mask it with, before storing
484  *
485  * this way we can describe UDP, TCP and ICMP[46] semantics,
486  * and add a sort of FPM-type behavior for other protocols.
487  *
488  * Of course, is it faster ? and is it needed ?
489  *
490  */
491  }
492 }
493 
494 
495 /* Session keys match the packets received, and mirror the packets sent */
496 static void
497 acl_make_5tuple_session_key (int is_input, fa_5tuple_t * p5tuple_pkt,
498  fa_5tuple_t * p5tuple_sess)
499 {
500  int src_index = is_input ? 0 : 1;
501  int dst_index = is_input ? 1 : 0;
502  p5tuple_sess->addr[src_index] = p5tuple_pkt->addr[0];
503  p5tuple_sess->addr[dst_index] = p5tuple_pkt->addr[1];
504  p5tuple_sess->l4.as_u64 = p5tuple_pkt->l4.as_u64;
505  p5tuple_sess->l4.port[src_index] = p5tuple_pkt->l4.port[0];
506  p5tuple_sess->l4.port[dst_index] = p5tuple_pkt->l4.port[1];
507 }
508 
509 
510 static int
511 acl_fa_ifc_has_sessions (acl_main_t * am, int sw_if_index0)
512 {
514 }
515 
516 static int
517 acl_fa_ifc_has_in_acl (acl_main_t * am, int sw_if_index0)
518 {
519  int it_has = clib_bitmap_get (am->fa_in_acl_on_sw_if_index, sw_if_index0);
520  return it_has;
521 }
522 
523 static int
524 acl_fa_ifc_has_out_acl (acl_main_t * am, int sw_if_index0)
525 {
526  int it_has = clib_bitmap_get (am->fa_out_acl_on_sw_if_index, sw_if_index0);
527  return it_has;
528 }
529 
530 
531 static int
533 {
534  /* seen both SYNs and ACKs but not FINs means we are in establshed state */
535  u16 masked_flags =
538  switch (sess->info.l4.proto)
539  {
540  case IPPROTO_TCP:
541  if (((TCP_FLAGS_ACKSYN << 8) + TCP_FLAGS_ACKSYN) == masked_flags)
542  {
543  return ACL_TIMEOUT_TCP_IDLE;
544  }
545  else
546  {
548  }
549  break;
550  case IPPROTO_UDP:
551  return ACL_TIMEOUT_UDP_IDLE;
552  break;
553  default:
554  return ACL_TIMEOUT_UDP_IDLE;
555  }
556 }
557 
558 
559 static u64
561 {
562  int timeout_type;
563  u64 timeout = ~0LL;
564  for(timeout_type = 0; timeout_type < ACL_N_TIMEOUTS; timeout_type++) {
565  if (timeout > am->session_timeout_sec[timeout_type]) {
566  timeout = am->session_timeout_sec[timeout_type];
567  }
568  }
569  return timeout;
570 }
571 
572 /*
573  * Get the timeout of the session in a list since its enqueue time.
574  */
575 
576 static u64
578 {
579  u64 timeout = am->vlib_main->clib_time.clocks_per_second;
580  /*
581  * we have the shortest possible timeout type in all the lists
582  * (see README-multicore for the rationale)
583  */
584  timeout *= fa_session_get_shortest_timeout(am);
585  return timeout;
586 }
587 
588 /*
589  * Get the idle timeout of a session.
590  */
591 
592 static u64
594 {
595  u64 timeout = am->vlib_main->clib_time.clocks_per_second;
596  int timeout_type = fa_session_get_timeout_type (am, sess);
597  timeout *= am->session_timeout_sec[timeout_type];
598  return timeout;
599 }
600 
601 static void
603 {
605  u16 wk;
606  /* Allocate the per-worker sessions pools */
607  for (wk = 0; wk < vec_len (am->per_worker_data); wk++) {
610  }
611 
612  /* ... and the interface session hash table */
614  "ACL plugin FA session bihash",
618  }
619 }
620 
621 static inline fa_session_t *get_session_ptr(acl_main_t *am, u16 thread_index, u32 session_index)
622 {
623  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
624  fa_session_t *sess = pool_is_free_index (pw->fa_sessions_pool, session_index) ? 0 : pool_elt_at_index(pw->fa_sessions_pool, session_index);
625  return sess;
626 }
627 
628 static inline int is_valid_session_ptr(acl_main_t *am, u16 thread_index, fa_session_t *sess)
629 {
630  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
631  return ((sess != 0) && ((sess - pw->fa_sessions_pool) < pool_len(pw->fa_sessions_pool)));
632 }
633 
634 static void
636 {
637  fa_session_t *sess = get_session_ptr(am, sess_id.thread_index, sess_id.session_index);
638  u8 list_id = fa_session_get_timeout_type(am, sess);
639  uword thread_index = os_get_thread_index ();
640  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
641  /* the retrieved session thread index must be necessarily the same as the one in the key */
642  ASSERT (sess->thread_index == sess_id.thread_index);
643  /* the retrieved session thread index must be the same as current thread */
644  ASSERT (sess->thread_index == thread_index);
645  sess->link_enqueue_time = now;
646  sess->link_list_id = list_id;
647  sess->link_next_idx = ~0;
648  sess->link_prev_idx = pw->fa_conn_list_tail[list_id];
649  if (~0 != pw->fa_conn_list_tail[list_id]) {
650  fa_session_t *prev_sess = get_session_ptr(am, thread_index, pw->fa_conn_list_tail[list_id]);
651  prev_sess->link_next_idx = sess_id.session_index;
652  /* We should never try to link with a session on another thread */
653  ASSERT(prev_sess->thread_index == sess->thread_index);
654  }
655  pw->fa_conn_list_tail[list_id] = sess_id.session_index;
657 
658  if (~0 == pw->fa_conn_list_head[list_id]) {
659  pw->fa_conn_list_head[list_id] = sess_id.session_index;
660  }
661 }
662 
663 static int
665 {
666  uword thread_index = os_get_thread_index ();
667  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
668  if (thread_index != sess_id.thread_index) {
669  /* If another thread attempts to delete the session, fail it. */
670 #ifdef FA_NODE_VERBOSE_DEBUG
671  clib_warning("thread id in key %d != curr thread index, not deleting");
672 #endif
673  return 0;
674  }
675  fa_session_t *sess = get_session_ptr(am, sess_id.thread_index, sess_id.session_index);
676  /* we should never try to delete the session with another thread index */
677  ASSERT(sess->thread_index == thread_index);
678  if (~0 != sess->link_prev_idx) {
679  fa_session_t *prev_sess = get_session_ptr(am, thread_index, sess->link_prev_idx);
680  /* the previous session must be in the same list as this one */
681  ASSERT(prev_sess->link_list_id == sess->link_list_id);
682  prev_sess->link_next_idx = sess->link_next_idx;
683  }
684  if (~0 != sess->link_next_idx) {
685  fa_session_t *next_sess = get_session_ptr(am, thread_index, sess->link_next_idx);
686  /* The next session must be in the same list as the one we are deleting */
687  ASSERT(next_sess->link_list_id == sess->link_list_id);
688  next_sess->link_prev_idx = sess->link_prev_idx;
689  }
690  if (pw->fa_conn_list_head[sess->link_list_id] == sess_id.session_index) {
691  pw->fa_conn_list_head[sess->link_list_id] = sess->link_next_idx;
692  }
693  if (pw->fa_conn_list_tail[sess->link_list_id] == sess_id.session_index) {
694  pw->fa_conn_list_tail[sess->link_list_id] = sess->link_prev_idx;
695  }
696  return 1;
697 }
698 
699 static int
701 {
702  if (acl_fa_conn_list_delete_session(am, sess_id)) {
703  acl_fa_conn_list_add_session(am, sess_id, now);
704  return 1;
705  } else {
706  /*
707  * Our thread does not own this connection, so we can not delete
708  * The session. To avoid the complicated signaling, we simply
709  * pick the list waiting time to be the shortest of the timeouts.
710  * This way we do not have to do anything special, and let
711  * the regular requeue check take care of everything.
712  */
713  return 0;
714  }
715 }
716 
717 
718 static u8
719 acl_fa_track_session (acl_main_t * am, int is_input, u32 sw_if_index, u64 now,
720  fa_session_t * sess, fa_5tuple_t * pkt_5tuple)
721 {
722  sess->last_active_time = now;
723  if (pkt_5tuple->pkt.tcp_flags_valid)
724  {
725  sess->tcp_flags_seen.as_u8[is_input] |= pkt_5tuple->pkt.tcp_flags;
726  }
727  return 3;
728 }
729 
730 
731 static void
733 {
734  void *oldheap = clib_mem_set_heap(am->acl_mheap);
735  fa_session_t *sess = get_session_ptr(am, sess_id.thread_index, sess_id.session_index);
738  &sess->info.kv, 0);
741  /* Deleting from timer structures not needed,
742  as the caller must have dealt with the timers. */
743  vec_validate (pw->fa_session_dels_by_sw_if_index, sw_if_index);
744  clib_mem_set_heap (oldheap);
745  pw->fa_session_dels_by_sw_if_index[sw_if_index]++;
747 }
748 
749 static int
750 acl_fa_can_add_session (acl_main_t * am, int is_input, u32 sw_if_index)
751 {
752  u64 curr_sess_count;
753  curr_sess_count = am->fa_session_total_adds - am->fa_session_total_dels;
754  return (curr_sess_count < am->fa_conn_table_max_entries);
755 }
756 
757 static u64
758 acl_fa_get_list_head_expiry_time(acl_main_t *am, acl_fa_per_worker_data_t *pw, u64 now, u16 thread_index, int timeout_type)
759 {
760  fa_session_t *sess = get_session_ptr(am, thread_index, pw->fa_conn_list_head[timeout_type]);
761  /*
762  * We can not check just the index here because inbetween the worker thread might
763  * dequeue the connection from the head just as we are about to check it.
764  */
765  if (!is_valid_session_ptr(am, thread_index, sess)) {
766  return ~0LL; // infinity.
767  } else {
768  u64 timeout_time =
770  return timeout_time;
771  }
772 }
773 
774 static int
775 acl_fa_conn_time_to_check (acl_main_t *am, acl_fa_per_worker_data_t *pw, u64 now, u16 thread_index, u32 session_index)
776 {
777  fa_session_t *sess = get_session_ptr(am, thread_index, session_index);
778  u64 timeout_time =
780  return (timeout_time < now) || (sess->link_enqueue_time <= pw->swipe_end_time);
781 }
782 
783 /*
784  * see if there are sessions ready to be checked,
785  * do the maintenance (requeue or delete), and
786  * return the total number of sessions reclaimed.
787  */
788 static int
790 {
791  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
793  fsid.thread_index = thread_index;
794  int total_expired = 0;
795 
796  {
797  u8 tt = 0;
798  for(tt = 0; tt < ACL_N_TIMEOUTS; tt++) {
800  && (~0 != pw->fa_conn_list_head[tt])
801  && (acl_fa_conn_time_to_check(am, pw, now, thread_index,
802  pw->fa_conn_list_head[tt]))) {
803  fsid.session_index = pw->fa_conn_list_head[tt];
804  vec_add1(pw->expired, fsid.session_index);
806  }
807  }
808  }
809 
810  u32 *psid = NULL;
811  vec_foreach (psid, pw->expired)
812  {
813  fsid.session_index = *psid;
815  {
816  fa_session_t *sess = get_session_ptr(am, thread_index, fsid.session_index);
817  u32 sw_if_index = sess->sw_if_index;
818  u64 sess_timeout_time =
819  sess->last_active_time + fa_session_get_timeout (am, sess);
820  if ((now < sess_timeout_time) && (0 == clib_bitmap_get(pw->pending_clear_sw_if_index_bitmap, sw_if_index)))
821  {
822 #ifdef FA_NODE_VERBOSE_DEBUG
823  clib_warning ("ACL_FA_NODE_CLEAN: Restarting timer for session %d",
824  (int) session_index);
825 #endif
826  /* There was activity on the session, so the idle timeout
827  has not passed. Enqueue for another time period. */
828 
829  acl_fa_conn_list_add_session(am, fsid, now);
831  }
832  else
833  {
834 #ifdef FA_NODE_VERBOSE_DEBUG
835  clib_warning ("ACL_FA_NODE_CLEAN: Deleting session %d",
836  (int) session_index);
837 #endif
838  acl_fa_delete_session (am, sw_if_index, fsid);
839  pw->cnt_deleted_sessions++;
840  }
841  }
842  else
843  {
845  }
846  }
847  total_expired = vec_len(pw->expired);
848  /* zero out the vector which we have acted on */
849  if (pw->expired)
850  _vec_len (pw->expired) = 0;
851  /* if we were advancing and reached the end
852  * (no more sessions to recycle), reset the fast-forward timestamp */
853 
854  if (pw->swipe_end_time && 0 == total_expired)
855  pw->swipe_end_time = 0;
856  return (total_expired);
857 }
858 
859 always_inline void
860 acl_fa_try_recycle_session (acl_main_t * am, int is_input, u16 thread_index, u32 sw_if_index)
861 {
862  /* try to recycle a TCP transient session */
863  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
864  u8 timeout_type = ACL_TIMEOUT_TCP_TRANSIENT;
865  fa_full_session_id_t sess_id;
866  sess_id.session_index = pw->fa_conn_list_head[timeout_type];
867  if (~0 != sess_id.session_index) {
868  sess_id.thread_index = thread_index;
869  acl_fa_conn_list_delete_session(am, sess_id);
870  acl_fa_delete_session(am, sw_if_index, sess_id);
871  }
872 }
873 
874 static fa_session_t *
875 acl_fa_add_session (acl_main_t * am, int is_input, u32 sw_if_index, u64 now,
876  fa_5tuple_t * p5tuple)
877 {
878  clib_bihash_kv_40_8_t *pkv = &p5tuple->kv;
880  fa_full_session_id_t f_sess_id;
881  uword thread_index = os_get_thread_index();
882  void *oldheap = clib_mem_set_heap(am->acl_mheap);
883  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
884 
885  f_sess_id.thread_index = thread_index;
886  fa_session_t *sess;
887 
889  f_sess_id.session_index = sess - pw->fa_sessions_pool;
890 
891  kv.key[0] = pkv->key[0];
892  kv.key[1] = pkv->key[1];
893  kv.key[2] = pkv->key[2];
894  kv.key[3] = pkv->key[3];
895  kv.key[4] = pkv->key[4];
896  kv.value = f_sess_id.as_u64;
897 
898  memcpy (sess, pkv, sizeof (pkv->key));
899  sess->last_active_time = now;
900  sess->sw_if_index = sw_if_index;
901  sess->tcp_flags_seen.as_u16 = 0;
902  sess->thread_index = thread_index;
903  sess->link_list_id = ~0;
904  sess->link_prev_idx = ~0;
905  sess->link_next_idx = ~0;
906 
907 
908 
911  &kv, 1);
912  acl_fa_conn_list_add_session(am, f_sess_id, now);
913 
914  vec_validate (pw->fa_session_adds_by_sw_if_index, sw_if_index);
915  clib_mem_set_heap (oldheap);
916  pw->fa_session_adds_by_sw_if_index[sw_if_index]++;
918  return sess;
919 }
920 
921 static int
922 acl_fa_find_session (acl_main_t * am, u32 sw_if_index0, fa_5tuple_t * p5tuple,
923  clib_bihash_kv_40_8_t * pvalue_sess)
924 {
925  return (BV (clib_bihash_search)
926  (&am->fa_sessions_hash, &p5tuple->kv,
927  pvalue_sess) == 0);
928 }
929 
930 
933  vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip6,
934  int is_input, int is_l2_path, u32 * l2_feat_next_node_index,
935  vlib_node_registration_t * acl_fa_node)
936 {
937  u32 n_left_from, *from, *to_next;
938  acl_fa_next_t next_index;
939  u32 pkts_acl_checked = 0;
940  u32 pkts_new_session = 0;
941  u32 pkts_exist_session = 0;
942  u32 pkts_acl_permit = 0;
943  u32 pkts_restart_session_timer = 0;
944  u32 trace_bitmap = 0;
945  u32 feature_bitmap0;
946  acl_main_t *am = &acl_main;
947  fa_5tuple_t fa_5tuple, kv_sess;
948  clib_bihash_kv_40_8_t value_sess;
949  vlib_node_runtime_t *error_node;
950  u64 now = clib_cpu_time_now ();
951  uword thread_index = os_get_thread_index ();
952 
953  from = vlib_frame_vector_args (frame);
954  n_left_from = frame->n_vectors;
955  next_index = node->cached_next_index;
956 
957  error_node = vlib_node_get_runtime (vm, acl_fa_node->index);
958 
959  while (n_left_from > 0)
960  {
961  u32 n_left_to_next;
962 
963  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
964 
965  while (n_left_from > 0 && n_left_to_next > 0)
966  {
967  u32 bi0;
968  vlib_buffer_t *b0;
969  u32 next0 = 0;
970  u8 action = 0;
971  u32 sw_if_index0;
972  int acl_check_needed = 1;
973  u32 match_acl_in_index = ~0;
974  u32 match_rule_index = ~0;
975  u8 error0 = 0;
976 
977  /* speculatively enqueue b0 to the current next frame */
978  bi0 = from[0];
979  to_next[0] = bi0;
980  from += 1;
981  to_next += 1;
982  n_left_from -= 1;
983  n_left_to_next -= 1;
984 
985  b0 = vlib_get_buffer (vm, bi0);
986 
987  if (is_input)
988  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
989  else
990  sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
991  if (is_l2_path)
992  feature_bitmap0 = vnet_buffer (b0)->l2.feature_bitmap;
993 
994  /*
995  * Extract the L3/L4 matching info into a 5-tuple structure,
996  * then create a session key whose layout is independent on forward or reverse
997  * direction of the packet.
998  */
999 
1000  acl_fill_5tuple (am, b0, is_ip6, is_input, is_l2_path, &fa_5tuple);
1001  fa_5tuple.l4.lsb_of_sw_if_index = sw_if_index0 & 0xffff;
1002  acl_make_5tuple_session_key (is_input, &fa_5tuple, &kv_sess);
1003  fa_5tuple.pkt.sw_if_index = sw_if_index0;
1004  fa_5tuple.pkt.is_ip6 = is_ip6;
1005  fa_5tuple.pkt.is_input = is_input;
1006  fa_5tuple.pkt.mask_type_index_lsb = ~0;
1007 #ifdef FA_NODE_VERBOSE_DEBUG
1008  clib_warning
1009  ("ACL_FA_NODE_DBG: session 5-tuple %016llx %016llx %016llx %016llx %016llx : %016llx",
1010  kv_sess.kv.key[0], kv_sess.kv.key[1], kv_sess.kv.key[2],
1011  kv_sess.kv.key[3], kv_sess.kv.key[4], kv_sess.kv.value);
1012  clib_warning
1013  ("ACL_FA_NODE_DBG: packet 5-tuple %016llx %016llx %016llx %016llx %016llx : %016llx",
1014  fa_5tuple.kv.key[0], fa_5tuple.kv.key[1], fa_5tuple.kv.key[2],
1015  fa_5tuple.kv.key[3], fa_5tuple.kv.key[4], fa_5tuple.kv.value);
1016 #endif
1017 
1018  /* Try to match an existing session first */
1019 
1020  if (acl_fa_ifc_has_sessions (am, sw_if_index0))
1021  {
1023  (am, sw_if_index0, &kv_sess, &value_sess))
1024  {
1025  trace_bitmap |= 0x80000000;
1026  error0 = ACL_FA_ERROR_ACL_EXIST_SESSION;
1027  fa_full_session_id_t f_sess_id;
1028 
1029  f_sess_id.as_u64 = value_sess.value;
1030  ASSERT(f_sess_id.thread_index < vec_len(vlib_mains));
1031 
1032  fa_session_t *sess = get_session_ptr(am, f_sess_id.thread_index, f_sess_id.session_index);
1033  int old_timeout_type =
1034  fa_session_get_timeout_type (am, sess);
1035  action =
1036  acl_fa_track_session (am, is_input, sw_if_index0, now,
1037  sess, &fa_5tuple);
1038  /* expose the session id to the tracer */
1039  match_rule_index = f_sess_id.session_index;
1040  int new_timeout_type =
1041  fa_session_get_timeout_type (am, sess);
1042  acl_check_needed = 0;
1043  pkts_exist_session += 1;
1044  /* Tracking might have changed the session timeout type, e.g. from transient to established */
1045  if (PREDICT_FALSE (old_timeout_type != new_timeout_type))
1046  {
1047  acl_fa_restart_timer_for_session (am, now, f_sess_id);
1048  pkts_restart_session_timer++;
1049  trace_bitmap |=
1050  0x00010000 + ((0xff & old_timeout_type) << 8) +
1051  (0xff & new_timeout_type);
1052  }
1053  /*
1054  * I estimate the likelihood to be very low - the VPP needs
1055  * to have >64K interfaces to start with and then on
1056  * exactly 64K indices apart needs to be exactly the same
1057  * 5-tuple... Anyway, since this probability is nonzero -
1058  * print an error and drop the unlucky packet.
1059  * If this shows up in real world, we would need to bump
1060  * the hash key length.
1061  */
1062  if (PREDICT_FALSE(sess->sw_if_index != sw_if_index0)) {
1063  clib_warning("BUG: session LSB16(sw_if_index) and 5-tuple collision!");
1064  acl_check_needed = 0;
1065  action = 0;
1066  }
1067  }
1068  }
1069 
1070  if (acl_check_needed)
1071  {
1072  action =
1073  multi_acl_match_5tuple (sw_if_index0, &fa_5tuple, is_l2_path,
1074  is_ip6, is_input, &match_acl_in_index,
1075  &match_rule_index, &trace_bitmap);
1076  error0 = action;
1077  if (1 == action)
1078  pkts_acl_permit += 1;
1079  if (2 == action)
1080  {
1081  if (!acl_fa_can_add_session (am, is_input, sw_if_index0))
1082  acl_fa_try_recycle_session (am, is_input, thread_index, sw_if_index0);
1083 
1084  if (acl_fa_can_add_session (am, is_input, sw_if_index0))
1085  {
1086  fa_session_t *sess = acl_fa_add_session (am, is_input, sw_if_index0, now,
1087  &kv_sess);
1088  acl_fa_track_session (am, is_input, sw_if_index0, now,
1089  sess, &fa_5tuple);
1090  pkts_new_session += 1;
1091  }
1092  else
1093  {
1094  action = 0;
1095  error0 = ACL_FA_ERROR_ACL_TOO_MANY_SESSIONS;
1096  }
1097  }
1098  }
1099 
1100 
1101 
1102  if (action > 0)
1103  {
1104  if (is_l2_path)
1105  next0 =
1106  feat_bitmap_get_next_node_index (l2_feat_next_node_index,
1107  feature_bitmap0);
1108  else
1109  vnet_feature_next (sw_if_index0, &next0, b0);
1110  }
1111 
1113  && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1114  {
1115  acl_fa_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
1116  t->sw_if_index = sw_if_index0;
1117  t->next_index = next0;
1118  t->match_acl_in_index = match_acl_in_index;
1119  t->match_rule_index = match_rule_index;
1120  t->packet_info[0] = fa_5tuple.kv.key[0];
1121  t->packet_info[1] = fa_5tuple.kv.key[1];
1122  t->packet_info[2] = fa_5tuple.kv.key[2];
1123  t->packet_info[3] = fa_5tuple.kv.key[3];
1124  t->packet_info[4] = fa_5tuple.kv.key[4];
1125  t->packet_info[5] = fa_5tuple.kv.value;
1126  t->action = action;
1127  t->trace_bitmap = trace_bitmap;
1128  }
1129 
1130  next0 = next0 < node->n_next_nodes ? next0 : 0;
1131  if (0 == next0)
1132  b0->error = error_node->errors[error0];
1133 
1134  pkts_acl_checked += 1;
1135 
1136  /* verify speculative enqueue, maybe switch current next frame */
1137  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1138  to_next, n_left_to_next, bi0,
1139  next0);
1140  }
1141 
1142  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1143  }
1144 
1145  vlib_node_increment_counter (vm, acl_fa_node->index,
1146  ACL_FA_ERROR_ACL_CHECK, pkts_acl_checked);
1147  vlib_node_increment_counter (vm, acl_fa_node->index,
1148  ACL_FA_ERROR_ACL_PERMIT, pkts_acl_permit);
1149  vlib_node_increment_counter (vm, acl_fa_node->index,
1150  ACL_FA_ERROR_ACL_NEW_SESSION,
1151  pkts_new_session);
1152  vlib_node_increment_counter (vm, acl_fa_node->index,
1153  ACL_FA_ERROR_ACL_EXIST_SESSION,
1154  pkts_exist_session);
1155  vlib_node_increment_counter (vm, acl_fa_node->index,
1156  ACL_FA_ERROR_ACL_RESTART_SESSION_TIMER,
1157  pkts_restart_session_timer);
1158  return frame->n_vectors;
1159 }
1160 
1161 
1163 static uword
1165  vlib_node_runtime_t * node, vlib_frame_t * frame)
1166 {
1167  acl_main_t *am = &acl_main;
1168  return acl_fa_node_fn (vm, node, frame, 1, 1, 1,
1171 }
1172 
1174 static uword
1176  vlib_node_runtime_t * node, vlib_frame_t * frame)
1177 {
1178  acl_main_t *am = &acl_main;
1179  return acl_fa_node_fn (vm, node, frame, 0, 1, 1,
1182 }
1183 
1185 static uword
1187  vlib_node_runtime_t * node, vlib_frame_t * frame)
1188 {
1189  acl_main_t *am = &acl_main;
1190  return acl_fa_node_fn (vm, node, frame, 1, 0, 1,
1193 }
1194 
1196 static uword
1198  vlib_node_runtime_t * node, vlib_frame_t * frame)
1199 {
1200  acl_main_t *am = &acl_main;
1201  return acl_fa_node_fn (vm, node, frame, 0, 0, 1,
1204 }
1205 
1206 
1207 /**** L3 processing path nodes ****/
1208 
1209 
1211 static uword
1213  vlib_node_runtime_t * node, vlib_frame_t * frame)
1214 {
1215  return acl_fa_node_fn (vm, node, frame, 1, 1, 0, 0, &acl_in_fa_ip6_node);
1216 }
1217 
1219 static uword
1221  vlib_node_runtime_t * node, vlib_frame_t * frame)
1222 {
1223  return acl_fa_node_fn (vm, node, frame, 0, 1, 0, 0, &acl_in_fa_ip4_node);
1224 }
1225 
1227 static uword
1229  vlib_node_runtime_t * node, vlib_frame_t * frame)
1230 {
1231  return acl_fa_node_fn (vm, node, frame, 1, 0, 0, 0, &acl_out_fa_ip6_node);
1232 }
1233 
1235 static uword
1237  vlib_node_runtime_t * node, vlib_frame_t * frame)
1238 {
1239  return acl_fa_node_fn (vm, node, frame, 0, 0, 0, 0, &acl_out_fa_ip4_node);
1240 }
1241 
1242 /*
1243  * This process ensures the connection cleanup happens every so often
1244  * even in absence of traffic, as well as provides general orchestration
1245  * for requests like connection deletion on a given sw_if_index.
1246  */
1247 
1248 
1249 /* *INDENT-OFF* */
1250 #define foreach_acl_fa_cleaner_error \
1251 _(UNKNOWN_EVENT, "unknown event received") \
1252 /* end of errors */
1253 
1254 typedef enum
1255 {
1256 #define _(sym,str) ACL_FA_CLEANER_ERROR_##sym,
1258 #undef _
1261 
1263 #define _(sym,string) string,
1265 #undef _
1266 };
1267 
1268 /* *INDENT-ON* */
1269 
1272 
1273 /*
1274  * Per-worker thread interrupt-driven cleaner thread
1275  * to clean idle connections if there are no packets
1276  */
1277 static uword
1280 {
1281  acl_main_t *am = &acl_main;
1282  u64 now = clib_cpu_time_now ();
1283  u16 thread_index = os_get_thread_index ();
1284  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
1285  int num_expired;
1286 #ifdef FA_NODE_VERBOSE_DEBUG
1287  clib_warning("\nacl_fa_worker_conn_cleaner: thread index %d now %lu\n\n", thread_index, now);
1288 #endif
1289  /* allow another interrupt to be queued */
1290  pw->interrupt_is_pending = 0;
1291  if (pw->clear_in_process) {
1292  if (0 == pw->swipe_end_time) {
1293  /*
1294  * Someone has just set the flag to start clearing.
1295  * we do this by combing through the connections up to a "time T"
1296  * which is now, and requeueing everything except the expired
1297  * connections and those matching the interface(s) being cleared.
1298  */
1299 
1300  /*
1301  * first filter the sw_if_index bitmap that they want from us, by
1302  * a bitmap of sw_if_index for which we actually have connections.
1303  */
1304  if ((pw->pending_clear_sw_if_index_bitmap == 0)
1305  || (pw->serviced_sw_if_index_bitmap == 0)) {
1306 #ifdef FA_NODE_VERBOSE_DEBUG
1307  clib_warning("WORKER-CLEAR: someone tried to call clear, but one of the bitmaps are empty");
1308 #endif
1310  } else {
1311 #ifdef FA_NODE_VERBOSE_DEBUG
1312  clib_warning("WORKER-CLEAR: (before and) swiping sw-if-index bitmap: %U, my serviced bitmap %U",
1315 #endif
1318  }
1319 
1321  /* if the cross-section is a zero vector, no need to do anything. */
1322 #ifdef FA_NODE_VERBOSE_DEBUG
1323  clib_warning("WORKER: clearing done - nothing to do");
1324 #endif
1325  pw->clear_in_process = 0;
1326  } else {
1327 #ifdef FA_NODE_VERBOSE_DEBUG
1328  clib_warning("WORKER-CLEAR: swiping sw-if-index bitmap: %U, my serviced bitmap %U",
1331 #endif
1332  /* swipe through the connection lists until enqueue timestamps become above "now" */
1333  pw->swipe_end_time = now;
1334  }
1335  }
1336  }
1337  num_expired = acl_fa_check_idle_sessions(am, thread_index, now);
1338  // clib_warning("WORKER-CLEAR: checked %d sessions (clear_in_progress: %d)", num_expired, pw->clear_in_process);
1339  if (pw->clear_in_process) {
1340  if (0 == num_expired) {
1341  /* we were clearing but we could not process any more connections. time to stop. */
1343  pw->clear_in_process = 0;
1344 #ifdef FA_NODE_VERBOSE_DEBUG
1345  clib_warning("WORKER: clearing done, all done");
1346 #endif
1347  } else {
1348 #ifdef FA_NODE_VERBOSE_DEBUG
1349  clib_warning("WORKER-CLEAR: more work to do, raising interrupt");
1350 #endif
1351  /* should continue clearing.. So could they please sent an interrupt again? */
1352  pw->interrupt_is_needed = 1;
1353  }
1354  } else {
1355  if (num_expired >= am->fa_max_deleted_sessions_per_interval) {
1356  /* there was too much work, we should get an interrupt ASAP */
1357  pw->interrupt_is_needed = 1;
1358  pw->interrupt_is_unwanted = 0;
1359  } else if (num_expired <= am->fa_min_deleted_sessions_per_interval) {
1360  /* signal that they should trigger us less */
1361  pw->interrupt_is_needed = 0;
1362  pw->interrupt_is_unwanted = 1;
1363  } else {
1364  /* the current rate of interrupts is ok */
1365  pw->interrupt_is_needed = 0;
1366  pw->interrupt_is_unwanted = 0;
1367  }
1368  }
1370  return 0;
1371 }
1372 
1373 static void
1374 send_one_worker_interrupt (vlib_main_t * vm, acl_main_t *am, int thread_index)
1375 {
1376  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
1377  if (!pw->interrupt_is_pending) {
1378  pw->interrupt_is_pending = 1;
1381  /* if the interrupt was requested, mark that done. */
1382  /* pw->interrupt_is_needed = 0; */
1383  }
1384 }
1385 
1386 static void
1388 {
1389  int i;
1390  /* Can't use vec_len(am->per_worker_data) since the threads might not have come up yet; */
1391  int n_threads = vec_len(vlib_mains);
1392  for (i = n_threads > 1 ? 1 : 0; i < n_threads; i++) {
1393  send_one_worker_interrupt(vm, am, i);
1394  }
1395 }
1396 
1397 /* centralized process to drive per-worker cleaners */
1398 static uword
1400  vlib_frame_t * f)
1401 {
1402  acl_main_t *am = &acl_main;
1403  u64 now;
1404  f64 cpu_cps = vm->clib_time.clocks_per_second;
1405  u64 next_expire;
1406  /* We should check if there are connections to clean up - at least twice a second */
1407  u64 max_timer_wait_interval = cpu_cps / 2;
1408  uword event_type, *event_data = 0;
1410 
1411  am->fa_current_cleaner_timer_wait_interval = max_timer_wait_interval;
1413  am->fa_interrupt_generation = 1;
1414  while (1)
1415  {
1416  now = clib_cpu_time_now ();
1417  next_expire = now + am->fa_current_cleaner_timer_wait_interval;
1418  int has_pending_conns = 0;
1419  u16 ti;
1420  u8 tt;
1421 
1422  /*
1423  * walk over all per-thread list heads of different timeouts,
1424  * and see if there are any connections pending.
1425  * If there aren't - we do not need to wake up until the
1426  * worker code signals that it has added a connection.
1427  *
1428  * Also, while we are at it, calculate the earliest we need to wake up.
1429  */
1430  for(ti = 0; ti < vec_len(vlib_mains); ti++) {
1431  if (ti >= vec_len(am->per_worker_data)) {
1432  continue;
1433  }
1435  for(tt = 0; tt < vec_len(pw->fa_conn_list_head); tt++) {
1436  u64 head_expiry = acl_fa_get_list_head_expiry_time(am, pw, now, ti, tt);
1437  if ((head_expiry < next_expire) && !pw->interrupt_is_pending) {
1438 #ifdef FA_NODE_VERBOSE_DEBUG
1439  clib_warning("Head expiry: %lu, now: %lu, next_expire: %lu (worker: %d, tt: %d)", head_expiry, now, next_expire, ti, tt);
1440 #endif
1441  next_expire = head_expiry;
1442  }
1443  if (~0 != pw->fa_conn_list_head[tt]) {
1444  has_pending_conns = 1;
1445  }
1446  }
1447  }
1448 
1449  /* If no pending connections and no ACL applied then no point in timing out */
1450  if (!has_pending_conns && (0 == am->fa_total_enabled_count))
1451  {
1452  am->fa_cleaner_cnt_wait_without_timeout++;
1453  (void) vlib_process_wait_for_event (vm);
1454  event_type = vlib_process_get_events (vm, &event_data);
1455  }
1456  else
1457  {
1458  f64 timeout = ((i64) next_expire - (i64) now) / cpu_cps;
1459  if (timeout <= 0)
1460  {
1461  /* skip waiting altogether */
1462  event_type = ~0;
1463  }
1464  else
1465  {
1466  am->fa_cleaner_cnt_wait_with_timeout++;
1467  (void) vlib_process_wait_for_event_or_clock (vm, timeout);
1468  event_type = vlib_process_get_events (vm, &event_data);
1469  }
1470  }
1471 
1472  switch (event_type)
1473  {
1474  case ~0:
1475  /* nothing to do */
1476  break;
1478  /* Nothing to do. */
1479  break;
1481  {
1482  uword *clear_sw_if_index_bitmap = 0;
1483  uword *sw_if_index0;
1484  int clear_all = 0;
1485 #ifdef FA_NODE_VERBOSE_DEBUG
1486  clib_warning("ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX received");
1487 #endif
1488  vec_foreach (sw_if_index0, event_data)
1489  {
1490  am->fa_cleaner_cnt_delete_by_sw_index++;
1491 #ifdef FA_NODE_VERBOSE_DEBUG
1492  clib_warning
1493  ("ACL_FA_NODE_CLEAN: ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX: %d",
1494  *sw_if_index0);
1495 #endif
1496  if (*sw_if_index0 == ~0)
1497  {
1498  clear_all = 1;
1499  }
1500  else
1501  {
1502  if (!pool_is_free_index (am->vnet_main->interface_main.sw_interfaces, *sw_if_index0))
1503  {
1504  clear_sw_if_index_bitmap = clib_bitmap_set(clear_sw_if_index_bitmap, *sw_if_index0, 1);
1505  }
1506  }
1507  }
1508 #ifdef FA_NODE_VERBOSE_DEBUG
1509  clib_warning("ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX bitmap: %U", format_bitmap_hex, clear_sw_if_index_bitmap);
1510 #endif
1511  vec_foreach(pw0, am->per_worker_data) {
1513  while (pw0->clear_in_process) {
1515 #ifdef FA_NODE_VERBOSE_DEBUG
1516  clib_warning("ACL_FA_NODE_CLEAN: waiting previous cleaning cycle to finish on %d...", pw0 - am->per_worker_data);
1517 #endif
1518  vlib_process_suspend(vm, 0.0001);
1519  if (pw0->interrupt_is_needed) {
1520  send_one_worker_interrupt(vm, am, (pw0 - am->per_worker_data));
1521  }
1522  }
1523  if (pw0->clear_in_process) {
1524  clib_warning("ERROR-BUG! Could not initiate cleaning on worker because another cleanup in progress");
1525  } else {
1526  if (clear_all)
1527  {
1528  /* if we need to clear all, then just clear the interfaces that we are servicing */
1530  }
1531  else
1532  {
1533  pw0->pending_clear_sw_if_index_bitmap = clib_bitmap_dup(clear_sw_if_index_bitmap);
1534  }
1535  pw0->clear_in_process = 1;
1536  }
1537  }
1538  /* send some interrupts so they can start working */
1540 
1541  /* now wait till they all complete */
1542 #ifdef FA_NODE_VERBOSE_DEBUG
1543  clib_warning("CLEANER mains len: %d per-worker len: %d", vec_len(vlib_mains), vec_len(am->per_worker_data));
1544 #endif
1545  vec_foreach(pw0, am->per_worker_data) {
1547  while (pw0->clear_in_process) {
1549 #ifdef FA_NODE_VERBOSE_DEBUG
1550  clib_warning("ACL_FA_NODE_CLEAN: waiting for my cleaning cycle to finish on %d...", pw0 - am->per_worker_data);
1551 #endif
1552  vlib_process_suspend(vm, 0.0001);
1553  if (pw0->interrupt_is_needed) {
1554  send_one_worker_interrupt(vm, am, (pw0 - am->per_worker_data));
1555  }
1556  }
1557  }
1558 #ifdef FA_NODE_VERBOSE_DEBUG
1559  clib_warning("ACL_FA_NODE_CLEAN: cleaning done");
1560 #endif
1561  clib_bitmap_free(clear_sw_if_index_bitmap);
1562  }
1563  break;
1564  default:
1565 #ifdef FA_NODE_VERBOSE_DEBUG
1566  clib_warning ("ACL plugin connection cleaner: unknown event %u",
1567  event_type);
1568 #endif
1571  index,
1572  ACL_FA_CLEANER_ERROR_UNKNOWN_EVENT, 1);
1573  am->fa_cleaner_cnt_unknown_event++;
1574  break;
1575  }
1576 
1578 
1579  if (event_data)
1580  _vec_len (event_data) = 0;
1581 
1582  /*
1583  * If the interrupts were not processed yet, ensure we wait a bit,
1584  * but up to a point.
1585  */
1586  int need_more_wait = 0;
1587  int max_wait_cycles = 100;
1588  do {
1589  need_more_wait = 0;
1590  vec_foreach(pw0, am->per_worker_data) {
1592  need_more_wait = 1;
1593  }
1594  }
1595  if (need_more_wait) {
1596  vlib_process_suspend(vm, 0.0001);
1597  }
1598  } while (need_more_wait && (--max_wait_cycles > 0));
1599 
1600  int interrupts_needed = 0;
1601  int interrupts_unwanted = 0;
1602 
1603  vec_foreach(pw0, am->per_worker_data) {
1604  if (pw0->interrupt_is_needed) {
1605  interrupts_needed++;
1606  /* the per-worker value is reset when sending the interrupt */
1607  }
1608  if (pw0->interrupt_is_unwanted) {
1609  interrupts_unwanted++;
1610  pw0->interrupt_is_unwanted = 0;
1611  }
1612  }
1613  if (interrupts_needed) {
1614  /* they need more interrupts, do less waiting around next time */
1616  /* never go into zero-wait either though - we need to give the space to others */
1618  } else if (interrupts_unwanted) {
1619  /* slowly increase the amount of sleep up to a limit */
1620  if (am->fa_current_cleaner_timer_wait_interval < max_timer_wait_interval)
1622  }
1623  am->fa_cleaner_cnt_event_cycles++;
1625  }
1626  /* NOT REACHED */
1627  return 0;
1628 }
1629 
1630 
1631 void
1632 acl_fa_enable_disable (u32 sw_if_index, int is_input, int enable_disable)
1633 {
1634  acl_main_t *am = &acl_main;
1635  if (enable_disable) {
1637  am->fa_total_enabled_count++;
1638  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
1641  clib_mem_set_heap (oldheap);
1642  } else {
1643  am->fa_total_enabled_count--;
1644  }
1645 
1646  if (is_input)
1647  {
1648  ASSERT(clib_bitmap_get(am->fa_in_acl_on_sw_if_index, sw_if_index) != enable_disable);
1649  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
1650  vnet_feature_enable_disable ("ip4-unicast", "acl-plugin-in-ip4-fa",
1651  sw_if_index, enable_disable, 0, 0);
1652  vnet_feature_enable_disable ("ip6-unicast", "acl-plugin-in-ip6-fa",
1653  sw_if_index, enable_disable, 0, 0);
1654  clib_mem_set_heap (oldheap);
1656  clib_bitmap_set (am->fa_in_acl_on_sw_if_index, sw_if_index,
1657  enable_disable);
1658  }
1659  else
1660  {
1661  ASSERT(clib_bitmap_get(am->fa_out_acl_on_sw_if_index, sw_if_index) != enable_disable);
1662  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
1663  vnet_feature_enable_disable ("ip4-output", "acl-plugin-out-ip4-fa",
1664  sw_if_index, enable_disable, 0, 0);
1665  vnet_feature_enable_disable ("ip6-output", "acl-plugin-out-ip6-fa",
1666  sw_if_index, enable_disable, 0, 0);
1667  clib_mem_set_heap (oldheap);
1669  clib_bitmap_set (am->fa_out_acl_on_sw_if_index, sw_if_index,
1670  enable_disable);
1671  }
1672  if ((!enable_disable) && (!acl_fa_ifc_has_in_acl (am, sw_if_index))
1673  && (!acl_fa_ifc_has_out_acl (am, sw_if_index)))
1674  {
1675 #ifdef FA_NODE_VERBOSE_DEBUG
1676  clib_warning("ENABLE-DISABLE: clean the connections on interface %d", sw_if_index);
1677 #endif
1678  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
1681  sw_if_index);
1682  clib_mem_set_heap (oldheap);
1683  }
1684 }
1685 
1686 void
1688 {
1689  acl_main_t *am = &acl_main;
1691  vlib_cli_output(vm, "\nSession lookup hash table:\n%U\n\n",
1692  BV (format_bihash), &am->fa_sessions_hash, verbose);
1693  } else {
1694  vlib_cli_output(vm, "\nSession lookup hash table is not allocated.\n\n");
1695  }
1696 }
1697 
1698 
1699 /* *INDENT-OFF* */
1700 
1703  .name = "acl-plugin-fa-worker-cleaner-process",
1704  .type = VLIB_NODE_TYPE_INPUT,
1705  .state = VLIB_NODE_STATE_INTERRUPT,
1706 };
1707 
1709  .function = acl_fa_session_cleaner_process,
1710  .type = VLIB_NODE_TYPE_PROCESS,
1711  .name = "acl-plugin-fa-cleaner-process",
1713  .error_strings = acl_fa_cleaner_error_strings,
1714  .n_next_nodes = 0,
1715  .next_nodes = {},
1716 };
1717 
1718 
1720 {
1721  .function = acl_in_ip6_l2_node_fn,
1722  .name = "acl-plugin-in-ip6-l2",
1723  .vector_size = sizeof (u32),
1724  .format_trace = format_acl_fa_trace,
1725  .type = VLIB_NODE_TYPE_INTERNAL,
1726  .n_errors = ARRAY_LEN (acl_fa_error_strings),
1727  .error_strings = acl_fa_error_strings,
1728  .n_next_nodes = ACL_FA_N_NEXT,
1729  .next_nodes =
1730  {
1731  [ACL_FA_ERROR_DROP] = "error-drop",
1732  }
1733 };
1734 
1736 {
1737  .function = acl_in_ip4_l2_node_fn,
1738  .name = "acl-plugin-in-ip4-l2",
1739  .vector_size = sizeof (u32),
1740  .format_trace = format_acl_fa_trace,
1741  .type = VLIB_NODE_TYPE_INTERNAL,
1742  .n_errors = ARRAY_LEN (acl_fa_error_strings),
1743  .error_strings = acl_fa_error_strings,
1744  .n_next_nodes = ACL_FA_N_NEXT,
1745  .next_nodes =
1746  {
1747  [ACL_FA_ERROR_DROP] = "error-drop",
1748  }
1749 };
1750 
1752 {
1753  .function = acl_out_ip6_l2_node_fn,
1754  .name = "acl-plugin-out-ip6-l2",
1755  .vector_size = sizeof (u32),
1756  .format_trace = format_acl_fa_trace,
1757  .type = VLIB_NODE_TYPE_INTERNAL,
1758  .n_errors = ARRAY_LEN (acl_fa_error_strings),
1759  .error_strings = acl_fa_error_strings,
1760  .n_next_nodes = ACL_FA_N_NEXT,
1761  .next_nodes =
1762  {
1763  [ACL_FA_ERROR_DROP] = "error-drop",
1764  }
1765 };
1766 
1768 {
1769  .function = acl_out_ip4_l2_node_fn,
1770  .name = "acl-plugin-out-ip4-l2",
1771  .vector_size = sizeof (u32),
1772  .format_trace = format_acl_fa_trace,
1773  .type = VLIB_NODE_TYPE_INTERNAL,
1774  .n_errors = ARRAY_LEN (acl_fa_error_strings),
1775  .error_strings = acl_fa_error_strings,
1776  .n_next_nodes = ACL_FA_N_NEXT,
1777  .next_nodes =
1778  {
1779  [ACL_FA_ERROR_DROP] = "error-drop",
1780  }
1781 };
1782 
1783 
1785 {
1786  .function = acl_in_ip6_fa_node_fn,
1787  .name = "acl-plugin-in-ip6-fa",
1788  .vector_size = sizeof (u32),
1789  .format_trace = format_acl_fa_trace,
1790  .type = VLIB_NODE_TYPE_INTERNAL,
1791  .n_errors = ARRAY_LEN (acl_fa_error_strings),
1792  .error_strings = acl_fa_error_strings,
1793  .n_next_nodes = ACL_FA_N_NEXT,
1794  .next_nodes =
1795  {
1796  [ACL_FA_ERROR_DROP] = "error-drop",
1797  }
1798 };
1799 
1800 VNET_FEATURE_INIT (acl_in_ip6_fa_feature, static) =
1801 {
1802  .arc_name = "ip6-unicast",
1803  .node_name = "acl-plugin-in-ip6-fa",
1804  .runs_before = VNET_FEATURES ("ip6-flow-classify"),
1805 };
1806 
1808 {
1809  .function = acl_in_ip4_fa_node_fn,
1810  .name = "acl-plugin-in-ip4-fa",
1811  .vector_size = sizeof (u32),
1812  .format_trace = format_acl_fa_trace,
1813  .type = VLIB_NODE_TYPE_INTERNAL,
1814  .n_errors = ARRAY_LEN (acl_fa_error_strings),
1815  .error_strings = acl_fa_error_strings,
1816  .n_next_nodes = ACL_FA_N_NEXT,
1817  .next_nodes =
1818  {
1819  [ACL_FA_ERROR_DROP] = "error-drop",
1820  }
1821 };
1822 
1823 VNET_FEATURE_INIT (acl_in_ip4_fa_feature, static) =
1824 {
1825  .arc_name = "ip4-unicast",
1826  .node_name = "acl-plugin-in-ip4-fa",
1827  .runs_before = VNET_FEATURES ("ip4-flow-classify"),
1828 };
1829 
1830 
1832 {
1833  .function = acl_out_ip6_fa_node_fn,
1834  .name = "acl-plugin-out-ip6-fa",
1835  .vector_size = sizeof (u32),
1836  .format_trace = format_acl_fa_trace,
1837  .type = VLIB_NODE_TYPE_INTERNAL,
1838  .n_errors = ARRAY_LEN (acl_fa_error_strings),
1839  .error_strings = acl_fa_error_strings,
1840  .n_next_nodes = ACL_FA_N_NEXT,
1841  .next_nodes =
1842  {
1843  [ACL_FA_ERROR_DROP] = "error-drop",
1844  }
1845 };
1846 
1847 VNET_FEATURE_INIT (acl_out_ip6_fa_feature, static) =
1848 {
1849  .arc_name = "ip6-output",
1850  .node_name = "acl-plugin-out-ip6-fa",
1851  .runs_before = VNET_FEATURES ("interface-output"),
1852 };
1853 
1855 {
1856  .function = acl_out_ip4_fa_node_fn,
1857  .name = "acl-plugin-out-ip4-fa",
1858  .vector_size = sizeof (u32),
1859  .format_trace = format_acl_fa_trace,
1860  .type = VLIB_NODE_TYPE_INTERNAL,
1861  .n_errors = ARRAY_LEN (acl_fa_error_strings),
1862  .error_strings = acl_fa_error_strings,
1863  .n_next_nodes = ACL_FA_N_NEXT,
1864  /* edit / add dispositions here */
1865  .next_nodes =
1866  {
1867  [ACL_FA_ERROR_DROP] = "error-drop",
1868  }
1869 };
1870 
1871 VNET_FEATURE_INIT (acl_out_ip4_fa_feature, static) =
1872 {
1873  .arc_name = "ip4-output",
1874  .node_name = "acl-plugin-out-ip4-fa",
1875  .runs_before = VNET_FEATURES ("interface-output"),
1876 };
1877 
1878 
1879 /* *INDENT-ON* */
static uword acl_in_ip4_l2_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: fa_node.c:1175
acl_rule_t * rules
Definition: acl.h:100
static int acl_fa_restart_timer_for_session(acl_main_t *am, u64 now, fa_full_session_id_t sess_id)
Definition: fa_node.c:700
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:436
static int acl_fa_ifc_has_in_acl(acl_main_t *am, int sw_if_index0)
Definition: fa_node.c:517
#define TCP_FLAGS_ACKSYN
Definition: fa_node.h:16
u32 fa_cleaner_node_index
Definition: acl.h:181
static void acl_fa_conn_list_add_session(acl_main_t *am, fa_full_session_id_t sess_id, u64 now)
Definition: fa_node.c:635
u32 session_timeout_sec[ACL_N_TIMEOUTS]
Definition: acl.h:183
static u8 * format_bitmap_hex(u8 *s, va_list *args)
Format a bitmap as a string of hex bytes.
Definition: bitmap.h:744
u32 fa_acl_in_ip4_l2_node_feat_next_node_index[32]
Definition: acl.h:196
static int acl_fa_can_add_session(acl_main_t *am, int is_input, u32 sw_if_index)
Definition: fa_node.c:750
static int is_valid_session_ptr(acl_main_t *am, u16 thread_index, fa_session_t *sess)
Definition: fa_node.c:628
static char * acl_fa_cleaner_error_strings[]
Definition: fa_node.c:1262
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
void show_fa_sessions_hash(vlib_main_t *vm, u32 verbose)
Definition: fa_node.c:1687
uword * fa_out_acl_on_sw_if_index
Definition: acl.h:176
#define CLIB_UNUSED(x)
Definition: clib.h:79
u8 is_ipv6
Definition: acl.h:69
uword * pending_clear_sw_if_index_bitmap
Definition: fa_node.h:134
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:699
a
Definition: bitmap.h:516
u64 fa_current_cleaner_timer_wait_interval
Definition: acl.h:231
fa_session_l4_key_t l4
Definition: fa_node.h:49
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:619
fa_packet_info_t pkt
Definition: fa_node.h:51
u32 ** input_acl_vec_by_sw_if_index
Definition: acl.h:146
vnet_interface_main_t interface_main
Definition: vnet.h:56
#define PREDICT_TRUE(x)
Definition: clib.h:98
uword * fa_in_acl_on_sw_if_index
Definition: acl.h:175
static uword acl_fa_worker_conn_cleaner_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: fa_node.c:1278
int l4_match_nonfirst_fragment
Definition: acl.h:205
vlib_node_registration_t acl_out_fa_ip6_node
(constructor) VLIB_REGISTER_NODE (acl_out_fa_ip6_node)
Definition: fa_node.c:1226
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
Definition: node_funcs.h:195
static void send_interrupts_to_workers(vlib_main_t *vm, acl_main_t *am)
Definition: fa_node.c:1387
#define NULL
Definition: clib.h:55
static int fa_acl_match_port(u16 port, u16 port_first, u16 port_last, int is_ip6)
Definition: fa_node.c:134
static void acl_fa_verify_init_sessions(acl_main_t *am)
Definition: fa_node.c:602
f64 clocks_per_second
Definition: time.h:53
u8 dst_prefixlen
Definition: acl.h:73
vlib_node_registration_t acl_out_l2_ip4_node
(constructor) VLIB_REGISTER_NODE (acl_out_l2_ip4_node)
Definition: fa_node.c:1195
#define ethernet_buffer_header_size(b)
Determine the size of the Ethernet headers of the current frame in the buffer.
Definition: ethernet.h:390
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:459
#define TCP_FLAGS_RSTFINACKSYN
Definition: fa_node.h:15
fa_5tuple_t info
Definition: fa_node.h:58
u32 count
Definition: acl.h:99
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
static u64 clib_cpu_time_now(void)
Definition: time.h:73
struct _vlib_node_registration vlib_node_registration_t
static int acl_fa_find_session(acl_main_t *am, u32 sw_if_index0, fa_5tuple_t *p5tuple, clib_bihash_kv_40_8_t *pvalue_sess)
Definition: fa_node.c:922
static uword acl_out_ip4_fa_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: fa_node.c:1236
acl_main_t acl_main
Definition: jvpp_acl.h:39
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
format_function_t format_ip46_address
Definition: format.h:61
fa_session_t * fa_sessions_pool
Definition: fa_node.h:108
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define foreach_acl_fa_error
Definition: fa_node.c:62
clib_time_t clib_time
Definition: main.h:62
u8 link_list_id
Definition: fa_node.h:69
static void acl_fa_try_recycle_session(acl_main_t *am, int is_input, u16 thread_index, u32 sw_if_index)
Definition: fa_node.c:860
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:419
int single_acl_match_5tuple(acl_main_t *am, u32 acl_index, fa_5tuple_t *pkt_5tuple, int is_ip6, u8 *r_action, u32 *r_acl_match_p, u32 *r_rule_match_p, u32 *trace_bitmap)
Definition: fa_node.c:140
struct _tcp_header tcp_header_t
u32 next_index
Definition: fa_node.c:33
static u8 * format_acl_fa_trace(u8 *s, va_list *args)
Definition: fa_node.c:44
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:121
static uword acl_fa_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ip6, int is_input, int is_l2_path, u32 *l2_feat_next_node_index, vlib_node_registration_t *acl_fa_node)
Definition: fa_node.c:932
#define clib_bitmap_zero(v)
Clear a bitmap.
Definition: bitmap.h:102
#define clib_bitmap_dup(v)
Duplicate a bitmap.
Definition: bitmap.h:87
u32 fa_acl_out_ip4_l2_node_feat_next_node_index[32]
Definition: acl.h:198
f64 fa_cleaner_wait_time_increment
Definition: acl.h:229
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
Definition: node_funcs.h:448
static int acl_fa_check_idle_sessions(acl_main_t *am, u16 thread_index, u64 now)
Definition: fa_node.c:789
u16 lsb_of_sw_if_index
Definition: fa_node.h:42
uword fa_conn_table_hash_memory_size
Definition: acl.h:209
u16 dst_port_or_code_last
Definition: acl.h:78
u8 src_prefixlen
Definition: acl.h:71
#define clib_smp_atomic_add(addr, increment)
Definition: smp.h:46
u32 link_prev_idx
Definition: fa_node.h:67
vlib_node_registration_t acl_in_fa_ip6_node
(constructor) VLIB_REGISTER_NODE (acl_in_fa_ip6_node)
Definition: fa_node.c:1210
int clib_bihash_add_del(clib_bihash *h, clib_bihash_kv *add_v, int is_add)
Add or delete a (key,value) pair from a bi-hash table.
ip46_address_t addr[2]
Definition: fa_node.h:48
#define pool_alloc_aligned(P, N, A)
Allocate N more free elements to pool (general version).
Definition: pool.h:262
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:542
#define always_inline
Definition: clib.h:84
u32 trace_bitmap
Definition: fa_node.c:38
u64 fa_conn_table_max_entries
Definition: acl.h:210
static uword clib_bitmap_is_zero(uword *ai)
predicate function; is an entire bitmap empty?
Definition: bitmap.h:57
u32 sw_if_index
Definition: fa_node.c:34
vnet_main_t * vnet_main
Definition: acl.h:259
ip46_address_t src
Definition: acl.h:70
#define foreach_acl_fa_cleaner_error
Definition: fa_node.c:1250
static uword acl_in_ip6_l2_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: fa_node.c:1164
u8 is_permit
Definition: acl.h:68
unsigned long u64
Definition: types.h:89
static int acl_fa_conn_list_delete_session(acl_main_t *am, fa_full_session_id_t sess_id)
Definition: fa_node.c:664
static fa_session_t * get_session_ptr(acl_main_t *am, u16 thread_index, u32 session_index)
Definition: fa_node.c:621
clib_bihash_40_8_t fa_sessions_hash
Definition: acl.h:179
u32 fa_acl_out_ip6_l2_node_feat_next_node_index[32]
Definition: acl.h:199
ip46_address_t dst
Definition: acl.h:72
static fa_session_t * acl_fa_add_session(acl_main_t *am, int is_input, u32 sw_if_index, u64 now, fa_5tuple_t *p5tuple)
Definition: fa_node.c:875
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:397
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:71
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:946
u16 dst_port_or_code_first
Definition: acl.h:77
static void acl_fill_5tuple(acl_main_t *am, vlib_buffer_t *b0, int is_ip6, int is_input, int is_l2_path, fa_5tuple_t *p5tuple_pkt)
Definition: fa_node.c:330
static uword acl_out_ip6_fa_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: fa_node.c:1228
uword * fa_ipv6_known_eh_bitmap
Definition: acl.h:202
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:188
static u64 fa_session_get_list_timeout(acl_main_t *am, fa_session_t *sess)
Definition: fa_node.c:577
static uword acl_out_ip6_l2_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: fa_node.c:1186
clib_bihash_kv_40_8_t kv
Definition: fa_node.h:53
static int fa_session_get_timeout_type(acl_main_t *am, fa_session_t *sess)
Definition: fa_node.c:532
#define PREDICT_FALSE(x)
Definition: clib.h:97
static int acl_fa_ifc_has_out_acl(acl_main_t *am, int sw_if_index0)
Definition: fa_node.c:524
static_always_inline void vnet_feature_next(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:221
u64 last_active_time
Definition: fa_node.h:59
static u32 feat_bitmap_get_next_node_index(u32 *next_nodes, u32 bitmap)
Return the graph node index for the feature corresponding to the first set bit in the bitmap...
Definition: feat_bitmap.h:79
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:216
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:366
u32 fa_total_enabled_count
Definition: acl.h:154
u8 proto
Definition: acl.h:74
long i64
Definition: types.h:82
void clib_bihash_init(clib_bihash *h, char *name, u32 nbuckets, uword memory_size)
initialize a bounded index extensible hash table
u8 hash_multi_acl_match_5tuple(u32 sw_if_index, fa_5tuple_t *pkt_5tuple, int is_l2, int is_ip6, int is_input, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap)
Definition: hash_lookup.c:870
u64 * fa_session_adds_by_sw_if_index
Definition: fa_node.h:114
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:113
u16 src_port_or_type_first
Definition: acl.h:75
u64 * fa_session_dels_by_sw_if_index
Definition: fa_node.h:113
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1131
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:169
static uword acl_in_ip6_fa_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: fa_node.c:1212
u32 match_rule_index
Definition: fa_node.c:36
u16 n_vectors
Definition: node.h:345
static int offset_within_packet(vlib_buffer_t *b0, int offset)
Definition: fa_node.c:323
u64 fa_session_total_adds
Definition: acl.h:185
void * heap_base
Definition: main.h:101
u64 packet_info[6]
Definition: fa_node.c:37
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:223
static int acl_fa_conn_time_to_check(acl_main_t *am, acl_fa_per_worker_data_t *pw, u64 now, u16 thread_index, u32 session_index)
Definition: fa_node.c:775
#define clib_warning(format, args...)
Definition: error.h:59
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:85
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
Definition: node_funcs.h:88
acl_fa_next_t
Definition: fa_node.h:157
Definition: acl.h:66
#define clib_memcpy(a, b, c)
Definition: string.h:69
u32 sw_if_index
Definition: fa_node.h:60
int use_hash_acl_matching
Definition: acl.h:157
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:238
#define ARRAY_LEN(x)
Definition: clib.h:59
static u8 multi_acl_match_5tuple(u32 sw_if_index, fa_5tuple_t *pkt_5tuple, int is_l2, int is_ip6, int is_input, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap)
Definition: fa_node.c:308
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
void acl_fa_enable_disable(u32 sw_if_index, int is_input, int enable_disable)
Definition: fa_node.c:1632
static vlib_node_registration_t acl_fa_session_cleaner_process_node
(constructor) VLIB_REGISTER_NODE (acl_fa_session_cleaner_process_node)
Definition: fa_node.c:1270
acl_fa_error_t
Definition: fa_node.c:72
VNET_FEATURE_INIT(acl_in_ip6_fa_feature, static)
u8 as_u8[2]
Definition: fa_node.h:62
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:460
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:255
#define ASSERT(truth)
acl_fa_cleaner_error_t
Definition: fa_node.c:1254
static uword acl_out_ip4_l2_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: fa_node.c:1197
unsigned int u32
Definition: types.h:88
static u64 fa_session_get_timeout(acl_main_t *am, fa_session_t *sess)
Definition: fa_node.c:593
static u64 acl_fa_get_list_head_expiry_time(acl_main_t *am, acl_fa_per_worker_data_t *pw, u64 now, u16 thread_index, int timeout_type)
Definition: fa_node.c:758
int clib_bihash_search(clib_bihash *h, clib_bihash_kv *search_v, clib_bihash_kv *return_v)
Search a bi-hash table.
u8 tcp_flags_valid
Definition: fa_node.h:28
static int acl_fa_ifc_has_sessions(acl_main_t *am, int sw_if_index0)
Definition: fa_node.c:511
u16 src_port_or_type_last
Definition: acl.h:76
static u8 acl_fa_track_session(acl_main_t *am, int is_input, u32 sw_if_index, u64 now, fa_session_t *sess, fa_5tuple_t *pkt_5tuple)
Definition: fa_node.c:719
static void * get_ptr_to_offset(vlib_buffer_t *b0, int offset)
Definition: fa_node.c:88
static uword acl_in_ip4_fa_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: fa_node.c:1220
static uword acl_fa_session_cleaner_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: fa_node.c:1399
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:260
vlib_node_registration_t acl_in_l2_ip4_node
(constructor) VLIB_REGISTER_NODE (acl_in_l2_ip4_node)
Definition: fa_node.c:1173
union fa_session_t::@283 tcp_flags_seen
uword * serviced_sw_if_index_bitmap
Definition: fa_node.h:132
vlib_node_registration_t acl_in_l2_ip6_node
(constructor) VLIB_REGISTER_NODE (acl_in_l2_ip6_node)
Definition: fa_node.c:1162
#define VNET_FEATURES(...)
Definition: feature.h:368
u32 fa_acl_in_ip6_l2_node_feat_next_node_index[32]
Definition: acl.h:197
u32 link_next_idx
Definition: fa_node.h:68
u64 uword
Definition: types.h:112
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
template key/value backing page structure
Definition: bihash_doc.h:44
u16 as_u16
Definition: fa_node.h:63
u8 is_nonfirst_fragment
Definition: fa_node.h:31
Definition: defs.h:47
unsigned short u16
Definition: types.h:57
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
u8 tcp_flags_mask
Definition: acl.h:80
acl_fa_per_worker_data_t * per_worker_data
Definition: acl.h:236
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:644
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:269
vlib_main_t ** vlib_mains
int fa_interrupt_generation
Definition: acl.h:233
static_always_inline uword os_get_thread_index(void)
Definition: os.h:62
u64 fa_max_deleted_sessions_per_interval
Definition: acl.h:218
void * acl_mheap
Definition: acl.h:126
static void acl_make_5tuple_session_key(int is_input, fa_5tuple_t *p5tuple_pkt, fa_5tuple_t *p5tuple_sess)
Definition: fa_node.c:497
u16 thread_index
Definition: fa_node.h:64
struct clib_bihash_value offset
template key/value backing page structure
vlib_node_registration_t acl_out_l2_ip6_node
(constructor) VLIB_REGISTER_NODE (acl_out_l2_ip6_node)
Definition: fa_node.c:1184
static char * acl_fa_error_strings[]
Definition: fa_node.c:80
#define vnet_buffer(b)
Definition: buffer.h:304
u8 tcp_flags_value
Definition: acl.h:79
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:144
vlib_node_registration_t acl_out_fa_ip4_node
(constructor) VLIB_REGISTER_NODE (acl_out_fa_ip4_node)
Definition: fa_node.c:1234
#define vec_foreach(var, vec)
Vector iterator.
u16 flags
Copy of main node flags.
Definition: node.h:454
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:101
u16 mask_type_index_lsb
Definition: fa_node.h:26
Definition: acl.h:96
static int fa_acl_match_addr(ip46_address_t *addr1, ip46_address_t *addr2, int prefixlen, int is_ip6)
Definition: fa_node.c:96
u32 flags
Definition: vhost-user.h:76
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:74
u32 match_acl_in_index
Definition: fa_node.c:35
static u64 fa_session_get_shortest_timeout(acl_main_t *am)
Definition: fa_node.c:560
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
int fa_sessions_hash_is_initialized
Definition: acl.h:178
static vlib_node_registration_t acl_fa_worker_session_cleaner_process_node
(constructor) VLIB_REGISTER_NODE (acl_fa_worker_session_cleaner_process_node)
Definition: fa_node.c:1271
static uword * clib_bitmap_and(uword *ai, uword *bi)
Logical operator across two bitmaps.
acl_list_t * acls
Definition: acl.h:131
static u8 linear_multi_acl_match_5tuple(u32 sw_if_index, fa_5tuple_t *pkt_5tuple, int is_l2, int is_ip6, int is_input, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap)
Definition: fa_node.c:263
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
u32 ** output_acl_vec_by_sw_if_index
Definition: acl.h:147
static void send_one_worker_interrupt(vlib_main_t *vm, acl_main_t *am, int thread_index)
Definition: fa_node.c:1374
vlib_node_registration_t acl_in_fa_ip4_node
(constructor) VLIB_REGISTER_NODE (acl_in_fa_ip4_node)
Definition: fa_node.c:1218
u64 link_enqueue_time
Definition: fa_node.h:66
Definition: defs.h:46
int vnet_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)
Definition: feature.c:225
u32 fa_conn_table_hash_num_buckets
Definition: acl.h:208
u64 fa_session_total_dels
Definition: acl.h:186
static void acl_fa_delete_session(acl_main_t *am, u32 sw_if_index, fa_full_session_id_t sess_id)
Definition: fa_node.c:732
foreach_fa_cleaner_counter vlib_main_t * vlib_main
Definition: acl.h:258