FD.io VPP  v18.10-34-gcce845e
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 static u8 *
34 format_ip6_session_bihash_kv (u8 * s, va_list * args)
35 {
36  clib_bihash_kv_40_8_t *kv_40_8 = va_arg (*args, clib_bihash_kv_40_8_t *);
37  fa_5tuple_t a5t;
38 
39  a5t.kv_40_8 = *kv_40_8;
41 
42  return (format (s, "l3 %U -> %U"
43  " l4 lsb_of_sw_if_index %d proto %d l4_is_input %d l4_slow_path %d l4_reserved0 %d port %d -> %d | sess id %d thread id %d epoch %04x",
47  a5t.l4.proto, a5t.l4.is_input, a5t.l4.is_slowpath,
48  a5t.l4.reserved0, a5t.l4.port[0], a5t.l4.port[1],
49  sess->session_index, sess->thread_index,
50  sess->intf_policy_epoch));
51 }
52 
53 static u8 *
54 format_ip4_session_bihash_kv (u8 * s, va_list * args)
55 {
56  clib_bihash_kv_16_8_t *kv_16_8 = va_arg (*args, clib_bihash_kv_16_8_t *);
57  fa_5tuple_t a5t;
58 
59  a5t.kv_16_8 = *kv_16_8;
61 
62  return (format (s, "l3 %U -> %U"
63  " l4 lsb_of_sw_if_index %d proto %d l4_is_input %d l4_slow_path %d l4_reserved0 %d port %d -> %d | sess id %d thread id %d epoch %04x",
67  a5t.l4.proto, a5t.l4.is_input, a5t.l4.is_slowpath,
68  a5t.l4.reserved0, a5t.l4.port[0], a5t.l4.port[1],
69  sess->session_index, sess->thread_index,
70  sess->intf_policy_epoch));
71 }
72 
73 
74 static void
76 {
78  {
79  u16 wk;
80  /* Allocate the per-worker sessions pools */
81  for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
82  {
84 
85  /*
86  * // In lieu of trying to preallocate the pool and its free bitmap, rather use pool_init_fixed
87  * pool_alloc_aligned(pw->fa_sessions_pool, am->fa_conn_table_max_entries, CLIB_CACHE_LINE_BYTES);
88  * clib_bitmap_validate(pool_header(pw->fa_sessions_pool)->free_bitmap, am->fa_conn_table_max_entries);
89  */
92  }
93 
94  /* ... and the interface session hash table */
95  clib_bihash_init_40_8 (&am->fa_ip6_sessions_hash,
96  "ACL plugin FA IPv6 session bihash",
99  clib_bihash_set_kvp_format_fn_40_8 (&am->fa_ip6_sessions_hash,
101 
102  clib_bihash_init_16_8 (&am->fa_ip4_sessions_hash,
103  "ACL plugin FA IPv4 session bihash",
106  clib_bihash_set_kvp_format_fn_16_8 (&am->fa_ip4_sessions_hash,
108 
110  }
111 }
112 
113 
114 /*
115  * Get the timeout of the session in a list since its enqueue time.
116  */
117 
118 static u64
120 {
121  u64 timeout = am->vlib_main->clib_time.clocks_per_second / 1000;
122  timeout = fa_session_get_timeout (am, sess);
123  /* for all user lists, check them twice per timeout */
124  timeout >>= (sess->link_list_id != ACL_TIMEOUT_PURGATORY);
125  return timeout;
126 }
127 
128 static u64
130  acl_fa_per_worker_data_t * pw, u64 now,
131  u16 thread_index, int timeout_type)
132 {
133  return pw->fa_conn_list_head_expiry_time[timeout_type];
134 }
135 
136 static int
138  u64 now, u16 thread_index, u32 session_index)
139 {
140  if (session_index == FA_SESSION_BOGUS_INDEX)
141  return 0;
142  fa_session_t *sess = get_session_ptr (am, thread_index, session_index);
143  u64 timeout_time =
145  return (timeout_time < now)
146  || (sess->link_enqueue_time <= pw->swipe_end_time);
147 }
148 
149 /*
150  * see if there are sessions ready to be checked,
151  * do the maintenance (requeue or delete), and
152  * return the total number of sessions reclaimed.
153  */
154 static int
155 acl_fa_check_idle_sessions (acl_main_t * am, u16 thread_index, u64 now)
156 {
157  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
159  fsid.thread_index = thread_index;
160  int total_expired = 0;
161 
162  /* let the other threads enqueue more requests while we process, if they like */
164  u64 *psr = NULL;
165 
167  {
168  acl_fa_sess_req_t op = *psr >> 32;
169  fsid.session_index = *psr & 0xffffffff;
170  switch (op)
171  {
173  acl_fa_restart_timer_for_session (am, now, fsid);
174  break;
175  default:
176  /* do nothing */
177  break;
178  }
179  }
181  _vec_len (pw->wip_session_change_requests) = 0;
182 
183 
184  {
185  u8 tt = 0;
186  int n_pending_swipes = 0;
187  for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
188  {
189  int n_expired = 0;
190  while (n_expired < am->fa_max_deleted_sessions_per_interval)
191  {
192  fsid.session_index = pw->fa_conn_list_head[tt];
194  (am, pw, now, thread_index, pw->fa_conn_list_head[tt]))
195  {
196  break;
197  }
198  if (am->trace_sessions > 3)
199  {
201  "acl_fa_check_idle_sessions: expire session %d in list %d on thread %d",
202  "i4i4i4", (u32) fsid.session_index,
203  (u32) tt, (u32) thread_index);
204  }
205  vec_add1 (pw->expired, fsid.session_index);
206  n_expired++;
207  acl_fa_conn_list_delete_session (am, fsid, now);
208  }
209  }
210  for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
211  {
212  u32 session_index = pw->fa_conn_list_head[tt];
213  if (session_index == FA_SESSION_BOGUS_INDEX)
214  break;
215  fa_session_t *sess =
216  get_session_ptr (am, thread_index, session_index);
217  n_pending_swipes += sess->link_enqueue_time <= pw->swipe_end_time;
218  }
219  if (n_pending_swipes == 0)
220  {
221  pw->swipe_end_time = 0;
222  }
223  }
224 
225  u32 *psid = NULL;
226  vec_foreach (psid, pw->expired)
227  {
228  fsid.session_index = *psid;
230  {
231  fa_session_t *sess =
232  get_session_ptr (am, thread_index, fsid.session_index);
233  u32 sw_if_index = sess->sw_if_index;
234  u64 sess_timeout_time =
235  sess->last_active_time + fa_session_get_timeout (am, sess);
236  int timeout_passed = (now >= sess_timeout_time);
237  int clearing_interface =
239  if (am->trace_sessions > 3)
240  {
242  "acl_fa_check_idle_sessions: now %lu sess_timeout_time %lu",
243  "i8i8", now, sess_timeout_time);
245  "acl_fa_check_idle_sessions: session %d sw_if_index %d timeout_passed %d clearing_interface %d",
246  "i4i4i4i4", (u32) fsid.session_index,
247  (u32) sess->sw_if_index,
248  (u32) timeout_passed,
249  (u32) clearing_interface);
250  }
251  if (timeout_passed || clearing_interface)
252  {
253  if (acl_fa_two_stage_delete_session (am, sw_if_index, fsid, now))
254  {
255  if (am->trace_sessions > 3)
256  {
258  "acl_fa_check_idle_sessions: deleted session %d sw_if_index %d",
259  "i4i4", (u32) fsid.session_index,
260  (u32) sess->sw_if_index);
261  }
262  /* the session has been put */
263  pw->cnt_deleted_sessions++;
264  }
265  else
266  {
267  /* the connection marked as deleted and put to purgatory */
268  if (am->trace_sessions > 3)
269  {
271  "acl_fa_check_idle_sessions: session %d sw_if_index %d marked as deleted, put to purgatory",
272  "i4i4", (u32) fsid.session_index,
273  (u32) sess->sw_if_index);
274  }
275  }
276  }
277  else
278 
279  {
280  if (am->trace_sessions > 3)
281  {
283  "acl_fa_check_idle_sessions: restart timer for session %d sw_if_index %d",
284  "i4i4", (u32) fsid.session_index,
285  (u32) sess->sw_if_index);
286  }
287  /* There was activity on the session, so the idle timeout
288  has not passed. Enqueue for another time period. */
289 
290  acl_fa_conn_list_add_session (am, fsid, now);
292  }
293  }
294  else
295  {
297  }
298  }
299  total_expired = vec_len (pw->expired);
300  /* zero out the vector which we have acted on */
301  if (pw->expired)
302  _vec_len (pw->expired) = 0;
303  /* if we were advancing and reached the end
304  * (no more sessions to recycle), reset the fast-forward timestamp */
305 
306  if (pw->swipe_end_time && 0 == total_expired)
307  pw->swipe_end_time = 0;
308 
310  "acl_fa_check_idle_sessions: done, total sessions expired: %d",
311  "i4", (u32) total_expired);
312  return (total_expired);
313 }
314 
315 /*
316  * This process ensures the connection cleanup happens every so often
317  * even in absence of traffic, as well as provides general orchestration
318  * for requests like connection deletion on a given sw_if_index.
319  */
320 
321 
322 /* *INDENT-OFF* */
323 #define foreach_acl_fa_cleaner_error \
324 _(UNKNOWN_EVENT, "unknown event received") \
325 /* end of errors */
326 
327 typedef enum
328 {
329 #define _(sym,str) ACL_FA_CLEANER_ERROR_##sym,
331 #undef _
334 
336 #define _(sym,string) string,
338 #undef _
339 };
340 
341 /* *INDENT-ON* */
342 
345 
346 static void
348  int thread_index)
349 {
350  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
351  if (!pw->interrupt_is_pending)
352  {
353  pw->interrupt_is_pending = 1;
357  "send_one_worker_interrupt: send interrupt to worker %u",
358  "i4", ((u32) thread_index));
359  /* if the interrupt was requested, mark that done. */
360  /* pw->interrupt_is_needed = 0; */
362  }
363 }
364 
365 void
367  u32 target_session, u32 request_type)
368 {
369  acl_fa_per_worker_data_t *pw_me =
371  acl_fa_per_worker_data_t *pw = &am->per_worker_data[target_thread];
373  /* vec_add1 might cause a reallocation, change the heap just in case */
374  void *oldheap = clib_mem_set_heap (am->acl_mheap);
376  (((u64) request_type) << 32) | target_session);
377  clib_mem_set_heap (oldheap);
378 
382  {
383  /* ensure the requests get processed */
384  send_one_worker_interrupt (am->vlib_main, am, target_thread);
385  }
387 }
388 
389 void
391  u32 target_thread)
392 {
393  acl_fa_per_worker_data_t *pw = &am->per_worker_data[target_thread];
394  u64 *tmp;
398  pw->wip_session_change_requests = tmp;
400 }
401 
402 
403 static int
405  int thread_index)
406 {
407  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
408 
409  return (FA_SESSION_BOGUS_INDEX !=
411 
412 }
413 
414 
415 /*
416  * Per-worker thread interrupt-driven cleaner thread
417  * to clean idle connections if there are no packets
418  */
419 static uword
421  vlib_node_runtime_t * rt,
422  vlib_frame_t * f)
423 {
424  acl_main_t *am = &acl_main;
425  u64 now = clib_cpu_time_now ();
426  u16 thread_index = os_get_thread_index ();
427  acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
428  int num_expired;
430  "acl_fa_worker_conn_cleaner interrupt: now %lu",
431  "i8", now);
432  /* allow another interrupt to be queued */
433  pw->interrupt_is_pending = 0;
434  if (pw->clear_in_process)
435  {
436  if (0 == pw->swipe_end_time)
437  {
438  /*
439  * Someone has just set the flag to start clearing.
440  * we do this by combing through the connections up to a "time T"
441  * which is now, and requeueing everything except the expired
442  * connections and those matching the interface(s) being cleared.
443  */
444 
445  /*
446  * first filter the sw_if_index bitmap that they want from us, by
447  * a bitmap of sw_if_index for which we actually have connections.
448  */
449  if ((pw->pending_clear_sw_if_index_bitmap == 0)
450  || (pw->serviced_sw_if_index_bitmap == 0))
451  {
453  "acl_fa_worker_conn_cleaner: now %lu, someone tried to call clear but one of the bitmaps are empty",
454  "i8", now);
456  }
457  else
458  {
459 #ifdef FA_NODE_VERBOSE_DEBUG
461  ("WORKER-CLEAR: (before and) swiping sw-if-index bitmap: %U, my serviced bitmap %U",
462  format_bitmap_hex, pw->pending_clear_sw_if_index_bitmap,
463  format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
464 #endif
468  }
469 
471  {
472  /* if the cross-section is a zero vector, no need to do anything. */
474  "acl_fa_worker_conn_cleaner: now %lu, clearing done, nothing to do",
475  "i8", now);
476  pw->clear_in_process = 0;
477  pw->swipe_end_time = 0;
478  }
479  else
480  {
481 #ifdef FA_NODE_VERBOSE_DEBUG
483  ("WORKER-CLEAR: swiping sw-if-index bitmap: %U, my serviced bitmap %U",
484  format_bitmap_hex, pw->pending_clear_sw_if_index_bitmap,
485  format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
486 #endif
488  "acl_fa_worker_conn_cleaner: swiping until %lu",
489  "i8", now);
490  /* swipe through the connection lists until enqueue timestamps become above "now" */
491  pw->swipe_end_time = now;
492  }
493  }
494  }
495  num_expired = acl_fa_check_idle_sessions (am, thread_index, now);
496  // clib_warning("WORKER-CLEAR: checked %d sessions (clear_in_progress: %d)", num_expired, pw->clear_in_process);
498  "acl_fa_worker_conn_cleaner: checked %d sessions (clear_in_process: %d)",
499  "i4i4", (u32) num_expired,
500  (u32) pw->clear_in_process);
501  if (pw->clear_in_process)
502  {
503  if (pw->swipe_end_time == 0)
504  {
505  /* we were clearing but we could not process any more connections. time to stop. */
507  pw->clear_in_process = 0;
509  "acl_fa_worker_conn_cleaner: now %lu, clearing done - all done",
510  "i8", now);
511  }
512  else
513  {
515  "acl_fa_worker_conn_cleaner: now %lu, more work to do - requesting interrupt",
516  "i8", now);
517  /* should continue clearing.. So could they please sent an interrupt again? */
518  send_one_worker_interrupt (vm, am, thread_index);
519  // pw->interrupt_is_needed = 1;
520  }
521  }
522  else
523  {
524  if (num_expired > 0)
525  {
526  /* there was too much work, we should get an interrupt ASAP */
527  // pw->interrupt_is_needed = 1;
528  send_one_worker_interrupt (vm, am, thread_index);
529  pw->interrupt_is_unwanted = 0;
530  }
531  else
532  {
533  /* the current rate of interrupts is ok */
534  pw->interrupt_is_needed = 0;
535  pw->interrupt_is_unwanted = 0;
536  }
538  "acl_fa_worker_conn_cleaner: now %lu, interrupt needed: %u, interrupt unwanted: %u",
539  "i8i4i4", now, ((u32) pw->interrupt_is_needed),
540  ((u32) pw->interrupt_is_unwanted));
541  }
542  /* be persistent about quickly deleting the connections from the purgatory */
543  if (purgatory_has_connections (vm, am, thread_index))
544  {
545  send_one_worker_interrupt (vm, am, thread_index);
546  }
548  return 0;
549 }
550 
551 static void
553 {
554  int i;
555  /* Can't use vec_len(am->per_worker_data) since the threads might not have come up yet; */
556  int n_threads = vec_len (vlib_mains);
557  for (i = 0; i < n_threads; i++)
558  {
559  send_one_worker_interrupt (vm, am, i);
560  }
561 }
562 
563 /* centralized process to drive per-worker cleaners */
564 static uword
566  vlib_frame_t * f)
567 {
568  acl_main_t *am = &acl_main;
569  u64 now;
570  f64 cpu_cps = vm->clib_time.clocks_per_second;
571  u64 next_expire;
572  /* We should check if there are connections to clean up - at least twice a second */
573  u64 max_timer_wait_interval = cpu_cps / 2;
574  uword event_type, *event_data = 0;
576 
577  am->fa_current_cleaner_timer_wait_interval = max_timer_wait_interval;
579  am->fa_interrupt_generation = 1;
580  while (1)
581  {
582  now = clib_cpu_time_now ();
583  next_expire = now + am->fa_current_cleaner_timer_wait_interval;
584  int has_pending_conns = 0;
585  u16 ti;
586  u8 tt;
587 
588  /*
589  * walk over all per-thread list heads of different timeouts,
590  * and see if there are any connections pending.
591  * If there aren't - we do not need to wake up until the
592  * worker code signals that it has added a connection.
593  *
594  * Also, while we are at it, calculate the earliest we need to wake up.
595  */
596  for (ti = 0; ti < vec_len (vlib_mains); ti++)
597  {
598  if (ti >= vec_len (am->per_worker_data))
599  {
600  continue;
601  }
603  for (tt = 0; tt < vec_len (pw->fa_conn_list_head); tt++)
604  {
605  u64 head_expiry =
606  acl_fa_get_list_head_expiry_time (am, pw, now, ti, tt);
607  if ((head_expiry < next_expire) && !pw->interrupt_is_pending)
608  {
610  "acl_fa_session_cleaner_process: now %lu, worker: %u tt: %u",
611  "i8i2i2", now, ti, tt);
613  "acl_fa_session_cleaner_process: head expiry: %lu, is earlier than curr next expire: %lu",
614  "i8i8", head_expiry, next_expire);
615  next_expire = head_expiry;
616  }
618  {
619  has_pending_conns = 1;
620  }
621  }
622  }
623 
624  /* If no pending connections and no ACL applied then no point in timing out */
625  if (!has_pending_conns && (0 == am->fa_total_enabled_count))
626  {
627  am->fa_cleaner_cnt_wait_without_timeout++;
629  "acl_conn_cleaner: now %lu entering wait without timeout",
630  "i8", now);
631  (void) vlib_process_wait_for_event (vm);
632  event_type = vlib_process_get_events (vm, &event_data);
633  }
634  else
635  {
636  f64 timeout = ((i64) next_expire - (i64) now) / cpu_cps;
637  if (timeout <= 0)
638  {
639  /* skip waiting altogether */
640  event_type = ~0;
641  }
642  else
643  {
644  am->fa_cleaner_cnt_wait_with_timeout++;
646  "acl_conn_cleaner: now %lu entering wait with timeout %.6f sec",
647  "i8f8", now, timeout);
648  (void) vlib_process_wait_for_event_or_clock (vm, timeout);
649  event_type = vlib_process_get_events (vm, &event_data);
650  }
651  }
652 
653  switch (event_type)
654  {
655  case ~0:
656  /* nothing to do */
657  break;
659  /* Nothing to do. */
660  break;
662  {
663  uword *clear_sw_if_index_bitmap = 0;
664  uword *sw_if_index0;
665  int clear_all = 0;
666  now = clib_cpu_time_now ();
668  "acl_fa_session_cleaner_process: now %lu, received ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX",
669  "i8", now);
670  vec_foreach (sw_if_index0, event_data)
671  {
672  am->fa_cleaner_cnt_delete_by_sw_index++;
674  "acl_fa_session_cleaner_process: ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX %u",
675  "i4", *sw_if_index0);
676  if (*sw_if_index0 == ~0)
677  {
678  clear_all = 1;
679  }
680  else
681  {
682  if (!pool_is_free_index
684  *sw_if_index0))
685  {
686  clear_sw_if_index_bitmap =
687  clib_bitmap_set (clear_sw_if_index_bitmap,
688  *sw_if_index0, 1);
689  }
690  }
691  }
693  ("ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX bitmap: %U, clear_all: %u",
694  format_bitmap_hex, clear_sw_if_index_bitmap, clear_all);
695  vec_foreach (pw0, am->per_worker_data)
696  {
698  while (pw0->clear_in_process)
699  {
702  "ACL_FA_NODE_CLEAN: waiting previous cleaning cycle to finish on %u",
703  "i4",
704  (u32) (pw0 - am->per_worker_data));
705  vlib_process_suspend (vm, 0.0001);
706  if (pw0->interrupt_is_needed)
707  {
709  (pw0 - am->per_worker_data));
710  }
711  }
712  if (pw0->clear_in_process)
713  {
715  ("ERROR-BUG! Could not initiate cleaning on worker because another cleanup in progress");
716  }
717  else
718  {
719  if (clear_all)
720  {
721  /* if we need to clear all, then just clear the interfaces that we are servicing */
724  }
725  else
726  {
728  clib_bitmap_dup (clear_sw_if_index_bitmap);
729  }
731  ("ACL_FA_CLEANER: thread %u, pending clear bitmap: %U",
732  (am->per_worker_data - pw0), format_bitmap_hex,
734  pw0->clear_in_process = 1;
735  }
736  }
737  /* send some interrupts so they can start working */
739 
740  /* now wait till they all complete */
741  acl_log_info ("CLEANER mains len: %u per-worker len: %d",
742  vec_len (vlib_mains),
743  vec_len (am->per_worker_data));
744  vec_foreach (pw0, am->per_worker_data)
745  {
747  while (pw0->clear_in_process)
748  {
751  "ACL_FA_NODE_CLEAN: waiting for my cleaning cycle to finish on %u",
752  "i4",
753  (u32) (pw0 - am->per_worker_data));
754  vlib_process_suspend (vm, 0.0001);
755  if (pw0->interrupt_is_needed)
756  {
758  (pw0 - am->per_worker_data));
759  }
760  }
761  }
762  acl_log_info ("ACL_FA_NODE_CLEAN: cleaning done");
763  clib_bitmap_free (clear_sw_if_index_bitmap);
764  }
765  am->fa_cleaner_cnt_delete_by_sw_index_ok++;
766  break;
767  default:
768 #ifdef FA_NODE_VERBOSE_DEBUG
769  clib_warning ("ACL plugin connection cleaner: unknown event %u",
770  event_type);
771 #endif
774  index,
775  ACL_FA_CLEANER_ERROR_UNKNOWN_EVENT, 1);
776  am->fa_cleaner_cnt_unknown_event++;
777  break;
778  }
779 
781 
782  if (event_data)
783  _vec_len (event_data) = 0;
784 
785  /*
786  * If the interrupts were not processed yet, ensure we wait a bit,
787  * but up to a point.
788  */
789  int need_more_wait = 0;
790  int max_wait_cycles = 100;
791  do
792  {
793  need_more_wait = 0;
794  vec_foreach (pw0, am->per_worker_data)
795  {
797  {
798  need_more_wait = 1;
799  }
800  }
801  if (need_more_wait)
802  {
803  vlib_process_suspend (vm, 0.0001);
804  }
805  }
806  while (need_more_wait && (--max_wait_cycles > 0));
807 
808  int interrupts_needed = 0;
809  int interrupts_unwanted = 0;
810 
811  vec_foreach (pw0, am->per_worker_data)
812  {
813  if (pw0->interrupt_is_needed)
814  {
815  interrupts_needed++;
816  /* the per-worker value is reset when sending the interrupt */
817  }
818  if (pw0->interrupt_is_unwanted)
819  {
820  interrupts_unwanted++;
821  pw0->interrupt_is_unwanted = 0;
822  }
823  }
824  if (interrupts_needed)
825  {
826  /* they need more interrupts, do less waiting around next time */
828  /* never go into zero-wait either though - we need to give the space to others */
830  }
831  else if (interrupts_unwanted)
832  {
833  /* slowly increase the amount of sleep up to a limit */
835  max_timer_wait_interval)
837  cpu_cps * am->fa_cleaner_wait_time_increment;
838  }
839  am->fa_cleaner_cnt_event_cycles++;
841  }
842  /* NOT REACHED */
843  return 0;
844 }
845 
846 
847 void
848 acl_fa_enable_disable (u32 sw_if_index, int is_input, int enable_disable)
849 {
850  acl_main_t *am = &acl_main;
851  if (enable_disable)
852  {
855  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
858  clib_mem_set_heap (oldheap);
859  }
860  else
861  {
863  }
864 
865  if (is_input)
866  {
867  ASSERT (clib_bitmap_get (am->fa_in_acl_on_sw_if_index, sw_if_index) !=
868  enable_disable);
869  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
870  vnet_feature_enable_disable ("ip4-unicast", "acl-plugin-in-ip4-fa",
871  sw_if_index, enable_disable, 0, 0);
872  vnet_feature_enable_disable ("ip6-unicast", "acl-plugin-in-ip6-fa",
873  sw_if_index, enable_disable, 0, 0);
874  clib_mem_set_heap (oldheap);
876  clib_bitmap_set (am->fa_in_acl_on_sw_if_index, sw_if_index,
877  enable_disable);
878  }
879  else
880  {
881  ASSERT (clib_bitmap_get (am->fa_out_acl_on_sw_if_index, sw_if_index) !=
882  enable_disable);
883  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
884  vnet_feature_enable_disable ("ip4-output", "acl-plugin-out-ip4-fa",
885  sw_if_index, enable_disable, 0, 0);
886  vnet_feature_enable_disable ("ip6-output", "acl-plugin-out-ip6-fa",
887  sw_if_index, enable_disable, 0, 0);
888  clib_mem_set_heap (oldheap);
890  clib_bitmap_set (am->fa_out_acl_on_sw_if_index, sw_if_index,
891  enable_disable);
892  }
893  if ((!enable_disable) && (!acl_fa_ifc_has_in_acl (am, sw_if_index))
894  && (!acl_fa_ifc_has_out_acl (am, sw_if_index)))
895  {
896 #ifdef FA_NODE_VERBOSE_DEBUG
897  clib_warning ("ENABLE-DISABLE: clean the connections on interface %d",
898  sw_if_index);
899 #endif
900  void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
903  sw_if_index);
904  clib_mem_set_heap (oldheap);
905  }
906 }
907 
908 void
910 {
911  acl_main_t *am = &acl_main;
913  {
914  vlib_cli_output (vm, "\nIPv6 Session lookup hash table:\n%U\n\n",
915  format_bihash_40_8, &am->fa_ip6_sessions_hash,
916  verbose);
917 
918  vlib_cli_output (vm, "\nIPv4 Session lookup hash table:\n%U\n\n",
919  format_bihash_16_8, &am->fa_ip4_sessions_hash,
920  verbose);
921  }
922  else
923  {
924  vlib_cli_output (vm,
925  "\nSession lookup hash table is not allocated.\n\n");
926  }
927 }
928 
929 
930 /* *INDENT-OFF* */
931 
934  .name = "acl-plugin-fa-worker-cleaner-process",
935  .type = VLIB_NODE_TYPE_INPUT,
936  .state = VLIB_NODE_STATE_INTERRUPT,
937 };
938 
940  .function = acl_fa_session_cleaner_process,
941  .type = VLIB_NODE_TYPE_PROCESS,
942  .name = "acl-plugin-fa-cleaner-process",
944  .error_strings = acl_fa_cleaner_error_strings,
945  .n_next_nodes = 0,
946  .next_nodes = {},
947 };
948 
949 
950 /* *INDENT-ON* */
951 
952 /*
953  * fd.io coding-style-patch-verification: ON
954  *
955  * Local Variables:
956  * eval: (c-set-style "gnu")
957  * End:
958  */
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
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:143
uword * pending_clear_sw_if_index_bitmap
Definition: fa_node.h:183
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:699
u64 fa_current_cleaner_timer_wait_interval
Definition: acl.h:300
fa_session_l4_key_t l4
Definition: fa_node.h:71
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:619
clib_bihash_40_8_t fa_ip6_sessions_hash
Definition: acl.h:242
fa_packet_info_t pkt
Definition: fa_node.h:73
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:151
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
Definition: node_funcs.h:196
#define NULL
Definition: clib.h:57
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:98
#define foreach_acl_fa_cleaner_error
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
static u64 clib_cpu_time_now(void)
Definition: time.h:73
#define acl_log_err(...)
Definition: acl.h:333
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:147
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
clib_time_t clib_time
Definition: main.h:63
u8 link_list_id
Definition: fa_node.h:94
acl_fa_sess_req_t
Definition: acl.h:388
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:303
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:298
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:448
u16 lsb_of_sw_if_index
Definition: fa_node.h:51
uword fa_conn_table_hash_memory_size
Definition: acl.h:275
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)
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
u32 sw_if_index
Definition: vxlan_gbp.api:39
u64 fa_conn_table_max_entries
Definition: acl.h:276
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:328
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:960
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:310
static int acl_fa_check_idle_sessions(acl_main_t *am, u16 thread_index, u64 now)
u64 last_active_time
Definition: fa_node.h:84
u32 fa_total_enabled_count
Definition: acl.h:193
u64 * fa_conn_list_head_expiry_time
Definition: fa_node.h:158
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1176
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:155
format_function_t format_ip6_address
Definition: format.h:93
vlib_main_t * vm
Definition: buffer.c:294
#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:279
void * heap_base
Definition: main.h:104
clib_bihash_kv_40_8_t kv_40_8
Definition: fa_node.h:75
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:261
#define clib_warning(format, args...)
Definition: error.h:59
u32 sw_if_index
Definition: fa_node.h:85
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:271
#define ARRAY_LEN(x)
Definition: clib.h:61
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:339
#define ASSERT(truth)
int trace_sessions
Definition: acl.h:278
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
acl_main_t acl_main
Definition: acl.c:56
clib_bihash_kv_16_8_t kv_16_8
Definition: fa_node.h:78
uword * serviced_sw_if_index_bitmap
Definition: fa_node.h:181
#define elog_acl_maybe_trace_X1(am, acl_elog_trace_format_label, acl_elog_trace_format_args, acl_elog_val1)
Definition: fa_node.h:226
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:305
u64 uword
Definition: types.h:112
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:846
int fa_interrupt_generation
Definition: acl.h:302
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:251
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:149
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:111
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:67
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:725
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:82
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:150
u64 link_enqueue_time
Definition: fa_node.h:91
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:233
u32 fa_conn_table_hash_num_buckets
Definition: acl.h:274
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:69
foreach_fa_cleaner_counter vlib_main_t * vlib_main
Definition: acl.h:327