FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
sess_mgmt_node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2018 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 <vppinfra/error.h>
21 
22 
23 #include <acl/acl.h>
24 #include <vnet/ip/icmp46_packet.h>
25 
26 #include <plugins/acl/fa_node.h>
27 #include <plugins/acl/acl.h>
31 
32 
33 
35 format_ip46_session_bihash_kv (u8 * s, va_list * args, int is_ip6)
36 {
37  fa_5tuple_t a5t;
38  void *paddr0;
39  void *paddr1;
40  void *format_addr_func;
41 
42  if (is_ip6)
43  {
44  clib_bihash_kv_40_8_t *kv_40_8 =
45  va_arg (*args, clib_bihash_kv_40_8_t *);
46  a5t.kv_40_8 = *kv_40_8;
47  paddr0 = &a5t.ip6_addr[0];
48  paddr1 = &a5t.ip6_addr[1];
49  format_addr_func = format_ip6_address;
50  }
51  else
52  {
53  clib_bihash_kv_16_8_t *kv_16_8 =
54  va_arg (*args, clib_bihash_kv_16_8_t *);
55  a5t.kv_16_8 = *kv_16_8;
56  paddr0 = &a5t.ip4_addr[0];
57  paddr1 = &a5t.ip4_addr[1];
58  format_addr_func = format_ip4_address;
59  }
60 
62 
63  return (format (s, "l3 %U -> %U %U | sess id %d thread id %d epoch %04x",
64  format_addr_func, paddr0,
65  format_addr_func, paddr1,
67  sess->session_index, sess->thread_index,
68  sess->intf_policy_epoch));
69 }
70 
71 static u8 *
72 format_ip6_session_bihash_kv (u8 * s, va_list * args)
73 {
74  return format_ip46_session_bihash_kv (s, args, 1);
75 }
76 
77 static u8 *
78 format_ip4_session_bihash_kv (u8 * s, va_list * args)
79 {
80  return format_ip46_session_bihash_kv (s, args, 0);
81 }
82 
83 
84 static void
86 {
87  if (!am->fa_sessions_hash_is_initialized)
88  {
89  u16 wk;
90  /* Allocate the per-worker sessions pools */
91  for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
92  {
93  acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
94 
95  /*
96  * // In lieu of trying to preallocate the pool and its free bitmap, rather use pool_init_fixed
97  * pool_alloc_aligned(pw->fa_sessions_pool, am->fa_conn_table_max_entries, CLIB_CACHE_LINE_BYTES);
98  * clib_bitmap_validate(pool_header(pw->fa_sessions_pool)->free_bitmap, am->fa_conn_table_max_entries);
99  */
101  am->fa_conn_table_max_entries);
102  }
103 
104  /* ... and the interface session hash table */
105  clib_bihash_init_40_8 (&am->fa_ip6_sessions_hash,
106  "ACL plugin FA IPv6 session bihash",
107  am->fa_conn_table_hash_num_buckets,
108  am->fa_conn_table_hash_memory_size);
109  clib_bihash_set_kvp_format_fn_40_8 (&am->fa_ip6_sessions_hash,
111 
112  clib_bihash_init_16_8 (&am->fa_ip4_sessions_hash,
113  "ACL plugin FA IPv4 session bihash",
114  am->fa_conn_table_hash_num_buckets,
115  am->fa_conn_table_hash_memory_size);
116  clib_bihash_set_kvp_format_fn_16_8 (&am->fa_ip4_sessions_hash,
118 
119  am->fa_sessions_hash_is_initialized = 1;
120  }
121 }
122 
123 
124 /*
125  * Get the timeout of the session in a list since its enqueue time.
126  */
127 
128 static u64
130 {
131  u64 timeout = am->vlib_main->clib_time.clocks_per_second / 1000;
132  timeout = fa_session_get_timeout (am, sess);
133  /* for all user lists, check them twice per timeout */
134  timeout >>= (sess->link_list_id != ACL_TIMEOUT_PURGATORY);
135  return timeout;
136 }
137 
138 static u64
141  u16 thread_index, int timeout_type)
142 {
143  return pw->fa_conn_list_head_expiry_time[timeout_type];
144 }
145 
146 static int
148  u64 now, u16 thread_index, u32 session_index)
149 {
150  if (session_index == FA_SESSION_BOGUS_INDEX)
151  return 0;
152  fa_session_t *sess = get_session_ptr (am, thread_index, session_index);
153  u64 timeout_time =
155  return (timeout_time < now)
156  || (sess->link_enqueue_time <= pw->swipe_end_time);
157 }
158 
159 /*
160  * see if there are sessions ready to be checked,
161  * do the maintenance (requeue or delete), and
162  * return the total number of sessions reclaimed.
163  */
164 static int
166 {
167  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
169  fsid.thread_index = thread_index;
170  int total_expired = 0;
171 
172  /* let the other threads enqueue more requests while we process, if they like */
174  u64 *psr = NULL;
175 
177  {
178  acl_fa_sess_req_t op = *psr >> 32;
179  fsid.session_index = *psr & 0xffffffff;
180  switch (op)
181  {
184  break;
185  default:
186  /* do nothing */
187  break;
188  }
189  }
191  _vec_len (pw->wip_session_change_requests) = 0;
192 
193 
194  {
195  u8 tt = 0;
196  int n_pending_swipes = 0;
197  for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
198  {
199  int n_expired = 0;
200  while (n_expired < am->fa_max_deleted_sessions_per_interval)
201  {
202  fsid.session_index = pw->fa_conn_list_head[tt];
204  (am, pw, now, thread_index, pw->fa_conn_list_head[tt]))
205  {
206  break;
207  }
208  if (am->trace_sessions > 3)
209  {
211  "acl_fa_check_idle_sessions: expire session %d in list %d on thread %d",
212  "i4i4i4", (u32) fsid.session_index,
213  (u32) tt, (u32) thread_index);
214  }
215  vec_add1 (pw->expired, fsid.session_index);
216  n_expired++;
218  }
219  }
220  for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
221  {
222  u32 session_index = pw->fa_conn_list_head[tt];
223  if (session_index == FA_SESSION_BOGUS_INDEX)
224  break;
225  fa_session_t *sess =
226  get_session_ptr (am, thread_index, session_index);
227  n_pending_swipes += sess->link_enqueue_time <= pw->swipe_end_time;
228  }
229  if (n_pending_swipes == 0)
230  {
231  pw->swipe_end_time = 0;
232  }
233  }
234 
235  u32 *psid = NULL;
236  vec_foreach (psid, pw->expired)
237  {
238  fsid.session_index = *psid;
240  {
241  fa_session_t *sess =
243  u32 sw_if_index = sess->sw_if_index;
244  u64 sess_timeout_time =
246  int timeout_passed = (now >= sess_timeout_time);
247  int clearing_interface =
249  if (am->trace_sessions > 3)
250  {
252  "acl_fa_check_idle_sessions: now %lu sess_timeout_time %lu",
253  "i8i8", now, sess_timeout_time);
255  "acl_fa_check_idle_sessions: session %d sw_if_index %d timeout_passed %d clearing_interface %d",
256  "i4i4i4i4", (u32) fsid.session_index,
257  (u32) sess->sw_if_index,
258  (u32) timeout_passed,
259  (u32) clearing_interface);
260  }
261  if (timeout_passed || clearing_interface)
262  {
264  {
265  if (am->trace_sessions > 3)
266  {
268  "acl_fa_check_idle_sessions: deleted session %d sw_if_index %d",
269  "i4i4", (u32) fsid.session_index,
270  (u32) sess->sw_if_index);
271  }
272  /* the session has been put */
273  pw->cnt_deleted_sessions++;
274  }
275  else
276  {
277  /* the connection marked as deleted and put to purgatory */
278  if (am->trace_sessions > 3)
279  {
281  "acl_fa_check_idle_sessions: session %d sw_if_index %d marked as deleted, put to purgatory",
282  "i4i4", (u32) fsid.session_index,
283  (u32) sess->sw_if_index);
284  }
285  }
286  }
287  else
288 
289  {
290  if (am->trace_sessions > 3)
291  {
293  "acl_fa_check_idle_sessions: restart timer for session %d sw_if_index %d",
294  "i4i4", (u32) fsid.session_index,
295  (u32) sess->sw_if_index);
296  }
297  /* There was activity on the session, so the idle timeout
298  has not passed. Enqueue for another time period. */
299 
302  }
303  }
304  else
305  {
307  }
308  }
309  total_expired = vec_len (pw->expired);
310  /* zero out the vector which we have acted on */
311  if (pw->expired)
312  _vec_len (pw->expired) = 0;
313  /* if we were advancing and reached the end
314  * (no more sessions to recycle), reset the fast-forward timestamp */
315 
316  if (pw->swipe_end_time && 0 == total_expired)
317  pw->swipe_end_time = 0;
318 
320  "acl_fa_check_idle_sessions: done, total sessions expired: %d",
321  "i4", (u32) total_expired);
322  return (total_expired);
323 }
324 
325 /*
326  * This process ensures the connection cleanup happens every so often
327  * even in absence of traffic, as well as provides general orchestration
328  * for requests like connection deletion on a given sw_if_index.
329  */
330 
331 
332 /* *INDENT-OFF* */
333 #define foreach_acl_fa_cleaner_error \
334 _(UNKNOWN_EVENT, "unknown event received") \
335 /* end of errors */
336 
337 typedef enum
338 {
339 #define _(sym,str) ACL_FA_CLEANER_ERROR_##sym,
341 #undef _
344 
346 #define _(sym,string) string,
348 #undef _
349 };
350 
351 /* *INDENT-ON* */
352 
355 
356 static void
358  int thread_index)
359 {
360  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
361  if (!pw->interrupt_is_pending)
362  {
363  pw->interrupt_is_pending = 1;
368  "send_one_worker_interrupt: send interrupt to worker %u",
369  "i4", ((u32) thread_index));
370  /* if the interrupt was requested, mark that done. */
371  /* pw->interrupt_is_needed = 0; */
373  }
374 }
375 
376 void
378  u32 target_session, u32 request_type)
379 {
380  acl_fa_per_worker_data_t *pw_me =
381  &am->per_worker_data[os_get_thread_index ()];
382  acl_fa_per_worker_data_t *pw = &am->per_worker_data[target_thread];
384  /* vec_add1 might cause a reallocation */
386  (((u64) request_type) << 32) | target_session);
390  {
391  /* ensure the requests get processed */
392  send_one_worker_interrupt (am->vlib_main, am, target_thread);
393  }
395 }
396 
397 void
399  u32 target_thread)
400 {
401  acl_fa_per_worker_data_t *pw = &am->per_worker_data[target_thread];
402  u64 *tmp;
408 }
409 
410 
411 static int
413  int thread_index)
414 {
415  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
416 
417  return (FA_SESSION_BOGUS_INDEX !=
419 
420 }
421 
422 
423 /*
424  * Per-worker thread interrupt-driven cleaner thread
425  * to clean idle connections if there are no packets
426  */
427 static uword
430  vlib_frame_t * f)
431 {
432  acl_main_t *am = &acl_main;
435  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
436  int num_expired;
438  "acl_fa_worker_conn_cleaner interrupt: now %lu",
439  "i8", now);
440  /* allow another interrupt to be queued */
441  pw->interrupt_is_pending = 0;
442  if (pw->clear_in_process)
443  {
444  if (0 == pw->swipe_end_time)
445  {
446  /*
447  * Someone has just set the flag to start clearing.
448  * we do this by combing through the connections up to a "time T"
449  * which is now, and requeueing everything except the expired
450  * connections and those matching the interface(s) being cleared.
451  */
452 
453  /*
454  * first filter the sw_if_index bitmap that they want from us, by
455  * a bitmap of sw_if_index for which we actually have connections.
456  */
457  if ((pw->pending_clear_sw_if_index_bitmap == 0)
458  || (pw->serviced_sw_if_index_bitmap == 0))
459  {
461  "acl_fa_worker_conn_cleaner: now %lu, someone tried to call clear but one of the bitmaps are empty",
462  "i8", now);
464  }
465  else
466  {
467 #ifdef FA_NODE_VERBOSE_DEBUG
469  ("WORKER-CLEAR: (before and) swiping sw-if-index bitmap: %U, my serviced bitmap %U",
472 #endif
476  }
477 
479  {
480  /* if the cross-section is a zero vector, no need to do anything. */
482  "acl_fa_worker_conn_cleaner: now %lu, clearing done, nothing to do",
483  "i8", now);
484  pw->clear_in_process = 0;
485  pw->swipe_end_time = 0;
486  }
487  else
488  {
489 #ifdef FA_NODE_VERBOSE_DEBUG
491  ("WORKER-CLEAR: swiping sw-if-index bitmap: %U, my serviced bitmap %U",
494 #endif
496  "acl_fa_worker_conn_cleaner: swiping until %lu",
497  "i8", now);
498  /* swipe through the connection lists until enqueue timestamps become above "now" */
499  pw->swipe_end_time = now;
500  }
501  }
502  }
503  num_expired = acl_fa_check_idle_sessions (am, thread_index, now);
504  // clib_warning("WORKER-CLEAR: checked %d sessions (clear_in_progress: %d)", num_expired, pw->clear_in_process);
506  "acl_fa_worker_conn_cleaner: checked %d sessions (clear_in_process: %d)",
507  "i4i4", (u32) num_expired,
508  (u32) pw->clear_in_process);
509  if (pw->clear_in_process)
510  {
511  if (pw->swipe_end_time == 0)
512  {
513  /* we were clearing but we could not process any more connections. time to stop. */
515  pw->clear_in_process = 0;
517  "acl_fa_worker_conn_cleaner: now %lu, clearing done - all done",
518  "i8", now);
519  }
520  else
521  {
523  "acl_fa_worker_conn_cleaner: now %lu, more work to do - requesting interrupt",
524  "i8", now);
525  /* should continue clearing.. So could they please sent an interrupt again? */
527  // pw->interrupt_is_needed = 1;
528  }
529  }
530  else
531  {
532  if (num_expired > 0)
533  {
534  /* there was too much work, we should get an interrupt ASAP */
535  // pw->interrupt_is_needed = 1;
537  pw->interrupt_is_unwanted = 0;
538  }
539  else
540  {
541  /* the current rate of interrupts is ok */
542  pw->interrupt_is_needed = 0;
543  pw->interrupt_is_unwanted = 0;
544  }
546  "acl_fa_worker_conn_cleaner: now %lu, interrupt needed: %u, interrupt unwanted: %u",
547  "i8i4i4", now, ((u32) pw->interrupt_is_needed),
548  ((u32) pw->interrupt_is_unwanted));
549  }
550  /* be persistent about quickly deleting the connections from the purgatory */
552  {
554  }
555  pw->interrupt_generation = am->fa_interrupt_generation;
556  return 0;
557 }
558 
559 static void
561 {
562  int i;
563  /* Can't use vec_len(am->per_worker_data) since the threads might not have come up yet; */
564  int n_threads = vlib_get_n_threads ();
565  for (i = 0; i < n_threads; i++)
566  {
568  }
569 }
570 
571 /* centralized process to drive per-worker cleaners */
572 static uword
574  vlib_frame_t * f)
575 {
576  acl_main_t *am = &acl_main;
577  u64 now;
578  f64 cpu_cps = vm->clib_time.clocks_per_second;
579  u64 next_expire;
580  /* We should check if there are connections to clean up - at least twice a second */
581  u64 max_timer_wait_interval = cpu_cps / 2;
582  uword event_type, *event_data = 0;
584 
585  am->fa_current_cleaner_timer_wait_interval = max_timer_wait_interval;
586  am->fa_cleaner_node_index = acl_fa_session_cleaner_process_node.index;
587  am->fa_interrupt_generation = 1;
588  while (1)
589  {
590  now = clib_cpu_time_now ();
591  next_expire = now + am->fa_current_cleaner_timer_wait_interval;
592  int has_pending_conns = 0;
593  u16 ti;
594  u8 tt;
595 
596  /*
597  * walk over all per-thread list heads of different timeouts,
598  * and see if there are any connections pending.
599  * If there aren't - we do not need to wake up until the
600  * worker code signals that it has added a connection.
601  *
602  * Also, while we are at it, calculate the earliest we need to wake up.
603  */
604  for (ti = 0; ti < vlib_get_n_threads (); ti++)
605  {
606  if (ti >= vec_len (am->per_worker_data))
607  {
608  continue;
609  }
610  acl_fa_per_worker_data_t *pw = &am->per_worker_data[ti];
611  for (tt = 0; tt < vec_len (pw->fa_conn_list_head); tt++)
612  {
613  u64 head_expiry =
615  if ((head_expiry < next_expire) && !pw->interrupt_is_pending)
616  {
618  "acl_fa_session_cleaner_process: now %lu, worker: %u tt: %u",
619  "i8i2i2", now, ti, tt);
621  "acl_fa_session_cleaner_process: head expiry: %lu, is earlier than curr next expire: %lu",
622  "i8i8", head_expiry, next_expire);
623  next_expire = head_expiry;
624  }
626  {
627  has_pending_conns = 1;
628  }
629  }
630  }
631 
632  /* If no pending connections and no ACL applied then no point in timing out */
633  if (!has_pending_conns && (0 == am->fa_total_enabled_count))
634  {
635  am->fa_cleaner_cnt_wait_without_timeout++;
637  "acl_conn_cleaner: now %lu entering wait without timeout",
638  "i8", now);
640  event_type = vlib_process_get_events (vm, &event_data);
641  }
642  else
643  {
644  f64 timeout = ((i64) next_expire - (i64) now) / cpu_cps;
645  if (timeout <= 0)
646  {
647  /* skip waiting altogether */
648  event_type = ~0;
649  }
650  else
651  {
652  am->fa_cleaner_cnt_wait_with_timeout++;
654  "acl_conn_cleaner: now %lu entering wait with timeout %.6f sec",
655  "i8f8", now, timeout);
656  (void) vlib_process_wait_for_event_or_clock (vm, timeout);
657  event_type = vlib_process_get_events (vm, &event_data);
658  }
659  }
660 
661  switch (event_type)
662  {
663  case ~0:
664  /* nothing to do */
665  break;
667  /* Nothing to do. */
668  break;
670  {
671  uword *clear_sw_if_index_bitmap = 0;
672  uword *sw_if_index0;
673  int clear_all = 0;
674  now = clib_cpu_time_now ();
676  "acl_fa_session_cleaner_process: now %lu, received ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX",
677  "i8", now);
678  vec_foreach (sw_if_index0, event_data)
679  {
680  am->fa_cleaner_cnt_delete_by_sw_index++;
682  "acl_fa_session_cleaner_process: ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX %u",
683  "i4", *sw_if_index0);
684  if (*sw_if_index0 == ~0)
685  {
686  clear_all = 1;
687  }
688  else
689  {
690  if (!pool_is_free_index
691  (am->vnet_main->interface_main.sw_interfaces,
692  *sw_if_index0))
693  {
694  clear_sw_if_index_bitmap =
695  clib_bitmap_set (clear_sw_if_index_bitmap,
696  *sw_if_index0, 1);
697  }
698  }
699  }
701  ("ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX bitmap: %U, clear_all: %u",
702  format_bitmap_hex, clear_sw_if_index_bitmap, clear_all);
703  vec_foreach (pw0, am->per_worker_data)
704  {
706  while (pw0->clear_in_process)
707  {
710  "ACL_FA_NODE_CLEAN: waiting previous cleaning cycle to finish on %u",
711  "i4",
712  (u32) (pw0 - am->per_worker_data));
713  vlib_process_suspend (vm, 0.0001);
714  if (pw0->interrupt_is_needed)
715  {
717  (pw0 - am->per_worker_data));
718  }
719  }
720  if (pw0->clear_in_process)
721  {
723  ("ERROR-BUG! Could not initiate cleaning on worker because another cleanup in progress");
724  }
725  else
726  {
727  if (clear_all)
728  {
729  /* if we need to clear all, then just clear the interfaces that we are servicing */
732  }
733  else
734  {
736  clib_bitmap_dup (clear_sw_if_index_bitmap);
737  }
739  ("ACL_FA_CLEANER: thread %u, pending clear bitmap: %U",
740  (am->per_worker_data - pw0), format_bitmap_hex,
742  pw0->clear_in_process = 1;
743  }
744  }
745  /* send some interrupts so they can start working */
747 
748  /* now wait till they all complete */
749  acl_log_info ("CLEANER mains len: %u per-worker len: %d",
751  vec_len (am->per_worker_data));
752  vec_foreach (pw0, am->per_worker_data)
753  {
755  while (pw0->clear_in_process)
756  {
759  "ACL_FA_NODE_CLEAN: waiting for my cleaning cycle to finish on %u",
760  "i4",
761  (u32) (pw0 - am->per_worker_data));
762  vlib_process_suspend (vm, 0.0001);
763  if (pw0->interrupt_is_needed)
764  {
766  (pw0 - am->per_worker_data));
767  }
768  }
769  }
770  acl_log_info ("ACL_FA_NODE_CLEAN: cleaning done");
771  clib_bitmap_free (clear_sw_if_index_bitmap);
772  }
773  am->fa_cleaner_cnt_delete_by_sw_index_ok++;
774  break;
775  default:
776 #ifdef FA_NODE_VERBOSE_DEBUG
777  clib_warning ("ACL plugin connection cleaner: unknown event %u",
778  event_type);
779 #endif
782  index,
783  ACL_FA_CLEANER_ERROR_UNKNOWN_EVENT, 1);
784  am->fa_cleaner_cnt_unknown_event++;
785  break;
786  }
787 
789 
790  if (event_data)
791  _vec_len (event_data) = 0;
792 
793  /*
794  * If the interrupts were not processed yet, ensure we wait a bit,
795  * but up to a point.
796  */
797  int need_more_wait = 0;
798  int max_wait_cycles = 100;
799  do
800  {
801  need_more_wait = 0;
802  vec_foreach (pw0, am->per_worker_data)
803  {
804  if (pw0->interrupt_generation != am->fa_interrupt_generation)
805  {
806  need_more_wait = 1;
807  }
808  }
809  if (need_more_wait)
810  {
811  vlib_process_suspend (vm, 0.0001);
812  }
813  }
814  while (need_more_wait && (--max_wait_cycles > 0));
815 
816  int interrupts_needed = 0;
817  int interrupts_unwanted = 0;
818 
819  vec_foreach (pw0, am->per_worker_data)
820  {
821  if (pw0->interrupt_is_needed)
822  {
823  interrupts_needed++;
824  /* the per-worker value is reset when sending the interrupt */
825  }
826  if (pw0->interrupt_is_unwanted)
827  {
828  interrupts_unwanted++;
829  pw0->interrupt_is_unwanted = 0;
830  }
831  }
832  if (interrupts_needed)
833  {
834  /* they need more interrupts, do less waiting around next time */
835  am->fa_current_cleaner_timer_wait_interval /= 2;
836  /* never go into zero-wait either though - we need to give the space to others */
837  am->fa_current_cleaner_timer_wait_interval += 1;
838  }
839  else if (interrupts_unwanted)
840  {
841  /* slowly increase the amount of sleep up to a limit */
842  if (am->fa_current_cleaner_timer_wait_interval <
843  max_timer_wait_interval)
844  am->fa_current_cleaner_timer_wait_interval +=
845  cpu_cps * am->fa_cleaner_wait_time_increment;
846  }
847  am->fa_cleaner_cnt_event_cycles++;
848  am->fa_interrupt_generation++;
849  }
850  /* NOT REACHED */
851  return 0;
852 }
853 
854 
855 void
856 acl_fa_enable_disable (u32 sw_if_index, int is_input, int enable_disable)
857 {
858  acl_main_t *am = &acl_main;
859  if (enable_disable)
860  {
862  am->fa_total_enabled_count++;
863  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
864  vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
866  clib_mem_set_heap (oldheap);
867  }
868  else
869  {
870  am->fa_total_enabled_count--;
871  }
872 
873  if (is_input)
874  {
875  ASSERT (clib_bitmap_get (am->fa_in_acl_on_sw_if_index, sw_if_index) !=
876  enable_disable);
877  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
878  vnet_feature_enable_disable ("ip4-unicast", "acl-plugin-in-ip4-fa",
879  sw_if_index, enable_disable, 0, 0);
880  vnet_feature_enable_disable ("ip6-unicast", "acl-plugin-in-ip6-fa",
881  sw_if_index, enable_disable, 0, 0);
882  clib_mem_set_heap (oldheap);
883  am->fa_in_acl_on_sw_if_index =
884  clib_bitmap_set (am->fa_in_acl_on_sw_if_index, sw_if_index,
885  enable_disable);
886  }
887  else
888  {
889  ASSERT (clib_bitmap_get (am->fa_out_acl_on_sw_if_index, sw_if_index) !=
890  enable_disable);
891  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
892  vnet_feature_enable_disable ("ip4-output", "acl-plugin-out-ip4-fa",
893  sw_if_index, enable_disable, 0, 0);
894  vnet_feature_enable_disable ("ip6-output", "acl-plugin-out-ip6-fa",
895  sw_if_index, enable_disable, 0, 0);
896  clib_mem_set_heap (oldheap);
897  am->fa_out_acl_on_sw_if_index =
898  clib_bitmap_set (am->fa_out_acl_on_sw_if_index, sw_if_index,
899  enable_disable);
900  }
901  if ((!enable_disable) && (!acl_fa_ifc_has_in_acl (am, sw_if_index))
903  {
904 #ifdef FA_NODE_VERBOSE_DEBUG
905  clib_warning ("ENABLE-DISABLE: clean the connections on interface %d",
906  sw_if_index);
907 #endif
908  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
909  vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
911  sw_if_index);
912  clib_mem_set_heap (oldheap);
913  }
914 }
915 
916 void
918 {
919  acl_main_t *am = &acl_main;
920  if (am->fa_sessions_hash_is_initialized)
921  {
922  vlib_cli_output (vm, "\nIPv6 Session lookup hash table:\n%U\n\n",
923  format_bihash_40_8, &am->fa_ip6_sessions_hash,
924  verbose);
925 
926  vlib_cli_output (vm, "\nIPv4 Session lookup hash table:\n%U\n\n",
927  format_bihash_16_8, &am->fa_ip4_sessions_hash,
928  verbose);
929  }
930  else
931  {
933  "\nSession lookup hash table is not allocated.\n\n");
934  }
935 }
936 
937 
938 /* *INDENT-OFF* */
939 
942  .name = "acl-plugin-fa-worker-cleaner-process",
943  .type = VLIB_NODE_TYPE_INPUT,
944  .state = VLIB_NODE_STATE_INTERRUPT,
945 };
946 
948  .function = acl_fa_session_cleaner_process,
949  .type = VLIB_NODE_TYPE_PROCESS,
950  .name = "acl-plugin-fa-cleaner-process",
952  .error_strings = acl_fa_cleaner_error_strings,
953  .n_next_nodes = 0,
954  .next_nodes = {},
955 };
956 
957 
958 /* *INDENT-ON* */
959 
960 /*
961  * fd.io coding-style-patch-verification: ON
962  *
963  * Local Variables:
964  * eval: (c-set-style "gnu")
965  * End:
966  */
vlib.h
tmp
u32 * tmp
Definition: interface_output.c:1096
elog_acl_maybe_trace_X2
#define elog_acl_maybe_trace_X2(am, acl_elog_trace_format_label, acl_elog_trace_format_args, acl_elog_val1, acl_elog_val2)
Definition: fa_node.h:283
acl_fa_per_worker_data_t::fa_sessions_pool
fa_session_t * fa_sessions_pool
Definition: fa_node.h:170
acl_fa_per_worker_data_t::clear_in_process
u32 clear_in_process
Definition: fa_node.h:208
fa_session_t::sw_if_index
u32 sw_if_index
Definition: fa_node.h:108
fa_session_t::last_active_time
u64 last_active_time
Definition: fa_node.h:107
acl_log_info
#define acl_log_info(...)
Definition: acl.h:312
public_inlines.h
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
ACL_N_TIMEOUTS
@ ACL_N_TIMEOUTS
Definition: acl.h:62
show_fa_sessions_hash
void show_fa_sessions_hash(vlib_main_t *vm, u32 verbose)
Definition: sess_mgmt_node.c:917
acl_fa_get_list_head_expiry_time
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: sess_mgmt_node.c:139
format_ip46_session_bihash_kv
static_always_inline u8 * format_ip46_session_bihash_kv(u8 *s, va_list *args, int is_ip6)
Definition: sess_mgmt_node.c:35
acl_fa_cleaner_error_t
acl_fa_cleaner_error_t
Definition: sess_mgmt_node.c:337
vlib_main_t::clib_time
clib_time_t clib_time
Definition: main.h:106
format_ip4_address
format_function_t format_ip4_address
Definition: format.h:73
fa_5tuple_t
Definition: fa_node.h:68
clib_spinlock_lock_if_init
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:106
fa_session_get_timeout
static u64 fa_session_get_timeout(acl_main_t *am, fa_session_t *sess)
Definition: session_inlines.h:102
fa_5tuple_t::ip4_addr
ip4_address_t ip4_addr[2]
Definition: fa_node.h:77
fa_full_session_id_t::intf_policy_epoch
u16 intf_policy_epoch
Definition: fa_node.h:137
vlib_process_wait_for_event
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:660
f
vlib_frame_t * f
Definition: interface_output.c:1098
acl_fa_per_worker_data_t
Definition: fa_node.h:168
acl_fa_per_worker_data_t::pending_session_change_request_lock
clib_spinlock_t pending_session_change_request_lock
Definition: fa_node.h:172
format_fa_session_l4_key
static_always_inline u8 * format_fa_session_l4_key(u8 *s, va_list *args)
Definition: fa_node.h:93
acl_fa_cleaner_error_strings
static char * acl_fa_cleaner_error_strings[]
Definition: sess_mgmt_node.c:345
acl_fa_check_idle_sessions
static int acl_fa_check_idle_sessions(acl_main_t *am, u16 thread_index, u64 now)
Definition: sess_mgmt_node.c:165
acl_fa_per_worker_data_t::fa_conn_list_head_expiry_time
u64 * fa_conn_list_head_expiry_time
Definition: fa_node.h:181
ACL_FA_CLEANER_RESCHEDULE
@ ACL_FA_CLEANER_RESCHEDULE
Definition: fa_node.h:246
acl_fa_session_cleaner_process
static uword acl_fa_session_cleaner_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: sess_mgmt_node.c:573
acl_fa_per_worker_data_t::serviced_sw_if_index_bitmap
uword * serviced_sw_if_index_bitmap
Definition: fa_node.h:204
VLIB_NODE_TYPE_INPUT
@ VLIB_NODE_TYPE_INPUT
Definition: node.h:76
u16
unsigned short u16
Definition: types.h:57
ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX
@ ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX
Definition: fa_node.h:247
am
app_main_t * am
Definition: application.c:489
purgatory_has_connections
static int purgatory_has_connections(vlib_main_t *vm, acl_main_t *am, int thread_index)
Definition: sess_mgmt_node.c:412
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
clib_bihash_kv_40_8_t
Definition: bihash_40_8.h:41
acl_fa_restart_timer_for_session
static int acl_fa_restart_timer_for_session(acl_main_t *am, u64 now, fa_full_session_id_t sess_id)
Definition: session_inlines.h:247
acl_fa_per_worker_data_t::fa_conn_list_head
u32 * fa_conn_list_head
Definition: fa_node.h:178
acl_fa_per_worker_data_t::sent_session_change_requests
u64 sent_session_change_requests
Definition: fa_node.h:176
vlib_frame_t
Definition: node.h:372
acl_fa_conn_list_add_session
static void acl_fa_conn_list_add_session(acl_main_t *am, fa_full_session_id_t sess_id, u64 now)
Definition: session_inlines.h:147
vlib_process_signal_event
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1019
acl_fa_per_worker_data_t::cnt_session_timer_restarted
u64 cnt_session_timer_restarted
Definition: fa_node.h:200
acl_fa_enable_disable
void acl_fa_enable_disable(u32 sw_if_index, int is_input, int enable_disable)
Definition: sess_mgmt_node.c:856
fa_session_t::link_enqueue_time
u64 link_enqueue_time
Definition: fa_node.h:114
ACL_TIMEOUT_PURGATORY
@ ACL_TIMEOUT_PURGATORY
Definition: acl.h:61
i64
signed long i64
Definition: types.h:78
acl_main
acl_main_t acl_main
Definition: acl.c:44
acl_fa_per_worker_data_t::interrupt_is_needed
int interrupt_is_needed
Definition: fa_node.h:216
ACL_FA_CLEANER_N_ERROR
@ ACL_FA_CLEANER_N_ERROR
Definition: sess_mgmt_node.c:342
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
elog_acl_maybe_trace_X3
#define elog_acl_maybe_trace_X3(am, acl_elog_trace_format_label, acl_elog_trace_format_args, acl_elog_val1, acl_elog_val2, acl_elog_val3)
Definition: fa_node.h:311
vlib_process_get_events
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:583
acl_fa_per_worker_data_t::interrupt_is_unwanted
int interrupt_is_unwanted
Definition: fa_node.h:221
ti
u32 ti
Definition: interface_output.c:425
pool_init_fixed
#define pool_init_fixed(pool, max_elts)
initialize a fixed-size, preallocated pool
Definition: pool.h:85
session_inlines.h
fa_5tuple_t::kv_16_8
clib_bihash_kv_16_8_t kv_16_8
Definition: fa_node.h:88
fa_session_t::link_list_id
u8 link_list_id
Definition: fa_node.h:117
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
clib_bitmap_get
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
error.h
acl.h
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
acl_fa_ifc_has_in_acl
static int acl_fa_ifc_has_in_acl(acl_main_t *am, int sw_if_index0)
Definition: session_inlines.h:57
acl_fa_session_cleaner_process_node
static vlib_node_registration_t acl_fa_session_cleaner_process_node
(constructor) VLIB_REGISTER_NODE (acl_fa_session_cleaner_process_node)
Definition: sess_mgmt_node.c:353
acl_fa_worker_session_cleaner_process_node
static vlib_node_registration_t acl_fa_worker_session_cleaner_process_node
(constructor) VLIB_REGISTER_NODE (acl_fa_worker_session_cleaner_process_node)
Definition: sess_mgmt_node.c:354
foreach_acl_fa_cleaner_error
#define foreach_acl_fa_cleaner_error
Definition: sess_mgmt_node.c:333
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
static_always_inline
#define static_always_inline
Definition: clib.h:112
acl_fa_conn_time_to_check
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: sess_mgmt_node.c:147
acl_fa_two_stage_delete_session
static int acl_fa_two_stage_delete_session(acl_main_t *am, u32 sw_if_index, fa_full_session_id_t sess_id, u64 now)
Definition: session_inlines.h:446
clib_bitmap_free
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
uword
u64 uword
Definition: types.h:112
fa_5tuple_t::l4
fa_session_l4_key_t l4
Definition: fa_node.h:81
acl_fa_sess_req_t
acl_fa_sess_req_t
Definition: acl.h:374
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
f64
double f64
Definition: types.h:142
acl_fa_per_worker_data_t::interrupt_generation
int interrupt_generation
Definition: fa_node.h:225
fa_full_session_id_t::session_index
u32 session_index
Definition: fa_node.h:135
FA_SESSION_BOGUS_INDEX
#define FA_SESSION_BOGUS_INDEX
Definition: fa_node.h:166
acl_log_err
#define acl_log_err(...)
Definition: acl.h:306
CLIB_MEMORY_BARRIER
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:137
clib_bitmap_set
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
send_interrupts_to_workers
static void send_interrupts_to_workers(vlib_main_t *vm, acl_main_t *am)
Definition: sess_mgmt_node.c:560
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
os_get_thread_index
static_always_inline uword os_get_thread_index(void)
Definition: os.h:63
format_ip4_session_bihash_kv
static u8 * format_ip4_session_bihash_kv(u8 *s, va_list *args)
Definition: sess_mgmt_node.c:78
format_ip6_session_bihash_kv
static u8 * format_ip6_session_bihash_kv(u8 *s, va_list *args)
Definition: sess_mgmt_node.c:72
clib_bitmap_and
static uword * clib_bitmap_and(uword *ai, uword *bi)
Logical operator across two bitmaps.
fa_full_session_id_t
Definition: fa_node.h:131
acl_fa_worker_conn_cleaner_process
static uword acl_fa_worker_conn_cleaner_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: sess_mgmt_node.c:428
clib_time_t::clocks_per_second
f64 clocks_per_second
Definition: time.h:54
acl_fa_per_worker_data_t::interrupt_is_pending
int interrupt_is_pending
Definition: fa_node.h:210
lookup_context.h
is_ip6
bool is_ip6
Definition: ip.api:43
elog_acl_maybe_trace_X4
#define elog_acl_maybe_trace_X4(am, acl_elog_trace_format_label, acl_elog_trace_format_args, acl_elog_val1, acl_elog_val2, acl_elog_val3, acl_elog_val4)
Definition: fa_node.h:342
acl_fa_per_worker_data_t::cnt_already_deleted_sessions
u64 cnt_already_deleted_sessions
Definition: fa_node.h:198
index
u32 index
Definition: flow_types.api:221
get_session_ptr
static fa_session_t * get_session_ptr(acl_main_t *am, u16 thread_index, u32 session_index)
Definition: session_inlines.h:127
clib_bihash_kv_16_8_t
Definition: bihash_16_8.h:40
acl_fa_conn_list_delete_session
static int acl_fa_conn_list_delete_session(acl_main_t *am, fa_full_session_id_t sess_id, u64 now)
Definition: session_inlines.h:193
u64
unsigned long u64
Definition: types.h:89
vlib_process_wait_for_event_or_clock
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:755
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
fa_5tuple_t::pkt
fa_packet_info_t pkt
Definition: fa_node.h:83
vlib_process_suspend
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:486
u32
unsigned int u32
Definition: types.h:88
fa_session_get_list_timeout
static u64 fa_session_get_list_timeout(acl_main_t *am, fa_session_t *sess)
Definition: sess_mgmt_node.c:129
vlib_node_set_interrupt_pending
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
Definition: node_funcs.h:249
ACL_FA_REQ_SESS_RESCHEDULE
@ ACL_FA_REQ_SESS_RESCHEDULE
Definition: acl.h:375
acl_fa_verify_init_sessions
static void acl_fa_verify_init_sessions(acl_main_t *am)
Definition: sess_mgmt_node.c:85
acl_main_t
Definition: acl.h:116
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
VLIB_NODE_TYPE_PROCESS
@ VLIB_NODE_TYPE_PROCESS
Definition: node.h:84
vlib_get_main_by_index
static vlib_main_t * vlib_get_main_by_index(u32 thread_index)
Definition: global_funcs.h:29
vnet_feature_enable_disable
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: pnat_test_stubs.h:50
aclp_post_session_change_request
void aclp_post_session_change_request(acl_main_t *am, u32 target_thread, u32 target_session, u32 request_type)
Definition: sess_mgmt_node.c:377
acl_fa_per_worker_data_t::cnt_deleted_sessions
u64 cnt_deleted_sessions
Definition: fa_node.h:196
now
f64 now
Definition: nat44_ei_out2in.c:710
fa_5tuple_t::ip6_addr
ip6_address_t ip6_addr[2]
Definition: fa_node.h:79
vlib_main_t
Definition: main.h:102
vlib_get_n_threads
static u32 vlib_get_n_threads()
Definition: global_funcs.h:23
acl_fa_per_worker_data_t::pending_session_change_requests
u64 * pending_session_change_requests
Definition: fa_node.h:173
u8
unsigned char u8
Definition: types.h:56
fa_node.h
rt
vnet_interface_output_runtime_t * rt
Definition: interface_output.c:419
icmp46_packet.h
format_ip6_address
format_function_t format_ip6_address
Definition: format.h:91
i
int i
Definition: flowhash_template.h:376
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
format_bitmap_hex
__clib_export u8 * format_bitmap_hex(u8 *s, va_list *args)
Format a bitmap as a string of hex bytes.
Definition: bitmap.c:107
acl_fa_per_worker_data_t::pending_clear_sw_if_index_bitmap
uword * pending_clear_sw_if_index_bitmap
Definition: fa_node.h:206
acl_fa_ifc_has_out_acl
static int acl_fa_ifc_has_out_acl(acl_main_t *am, int sw_if_index0)
Definition: session_inlines.h:64
aclp_swap_wip_and_pending_session_change_requests
void aclp_swap_wip_and_pending_session_change_requests(acl_main_t *am, u32 target_thread)
Definition: sess_mgmt_node.c:398
clib_bitmap_zero
#define clib_bitmap_zero(v)
Clear a bitmap.
Definition: bitmap.h:102
vnet.h
vlib_node_runtime_t
Definition: node.h:454
clib_spinlock_unlock_if_init
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:129
acl_fa_per_worker_data_t::swipe_end_time
u64 swipe_end_time
Definition: fa_node.h:202
elog_acl_maybe_trace_X1
#define elog_acl_maybe_trace_X1(am, acl_elog_trace_format_label, acl_elog_trace_format_args, acl_elog_val1)
Definition: fa_node.h:258
clib_cpu_time_now
static u64 clib_cpu_time_now(void)
Definition: time.h:81
acl_fa_per_worker_data_t::rcvd_session_change_requests
u64 rcvd_session_change_requests
Definition: fa_node.h:175
fa_session_t
Definition: fa_node.h:105
fa_5tuple_t::kv_40_8
clib_bihash_kv_40_8_t kv_40_8
Definition: fa_node.h:85
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
clib_mem_set_heap
static clib_mem_heap_t * clib_mem_set_heap(clib_mem_heap_t *heap)
Definition: mem.h:368
acl_fa_per_worker_data_t::wip_session_change_requests
u64 * wip_session_change_requests
Definition: fa_node.h:174
clib_bitmap_is_zero
static uword clib_bitmap_is_zero(uword *ai)
predicate function; is an entire bitmap empty?
Definition: bitmap.h:57
acl_fa_per_worker_data_t::expired
u32 * expired
Definition: fa_node.h:188
send_one_worker_interrupt
static void send_one_worker_interrupt(vlib_main_t *vm, acl_main_t *am, int thread_index)
Definition: sess_mgmt_node.c:357
fa_full_session_id_t::thread_index
u16 thread_index
Definition: fa_node.h:136
clib_bitmap_dup
#define clib_bitmap_dup(v)
Duplicate a bitmap.
Definition: bitmap.h:87
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169