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