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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <netinet/in.h>
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
20 #include <vppinfra/error.h>
24 #include <vnet/ip/icmp46_packet.h>
26 #include <plugins/acl/fa_node.h>
27 #include <plugins/acl/acl.h>
28 #include <plugins/acl/lookup_context.h>
29 #include <plugins/acl/public_inlines.h>
30 #include <plugins/acl/session_inlines.h>
34 static_always_inline u8 *
35 format_ip46_session_bihash_kv (u8 * s, va_list * args, int is_ip6)
40 void *format_addr_func;
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;
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;
61 fa_full_session_id_t *sess = (fa_full_session_id_t *) & a5t.pkt;
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,
66 format_fa_session_l4_key, &a5t.l4,
67 sess->session_index, sess->thread_index,
68 sess->intf_policy_epoch));
72 format_ip6_session_bihash_kv (u8 * s, va_list * args)
74 return format_ip46_session_bihash_kv (s, args, 1);
78 format_ip4_session_bihash_kv (u8 * s, va_list * args)
80 return format_ip46_session_bihash_kv (s, args, 0);
85 acl_fa_verify_init_sessions (acl_main_t * am)
87 if (!am->fa_sessions_hash_is_initialized)
90 /* Allocate the per-worker sessions pools */
91 for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
93 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
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);
100 pool_init_fixed (pw->fa_sessions_pool,
101 am->fa_conn_table_max_entries);
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,
110 format_ip6_session_bihash_kv);
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,
117 format_ip4_session_bihash_kv);
119 am->fa_sessions_hash_is_initialized = 1;
125 * Get the timeout of the session in a list since its enqueue time.
129 fa_session_get_list_timeout (acl_main_t * am, fa_session_t * sess)
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);
139 acl_fa_get_list_head_expiry_time (acl_main_t * am,
140 acl_fa_per_worker_data_t * pw, u64 now,
141 u16 thread_index, int timeout_type)
143 return pw->fa_conn_list_head_expiry_time[timeout_type];
147 acl_fa_conn_time_to_check (acl_main_t * am, acl_fa_per_worker_data_t * pw,
148 u64 now, u16 thread_index, u32 session_index)
150 if (session_index == FA_SESSION_BOGUS_INDEX)
152 fa_session_t *sess = get_session_ptr (am, thread_index, session_index);
154 sess->link_enqueue_time + fa_session_get_list_timeout (am, sess);
155 return (timeout_time < now)
156 || (sess->link_enqueue_time <= pw->swipe_end_time);
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.
165 acl_fa_check_idle_sessions (acl_main_t * am, u16 thread_index, u64 now)
167 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
168 fa_full_session_id_t fsid;
169 fsid.thread_index = thread_index;
170 int total_expired = 0;
172 /* let the other threads enqueue more requests while we process, if they like */
173 aclp_swap_wip_and_pending_session_change_requests (am, thread_index);
176 vec_foreach (psr, pw->wip_session_change_requests)
178 acl_fa_sess_req_t op = *psr >> 32;
179 fsid.session_index = *psr & 0xffffffff;
182 case ACL_FA_REQ_SESS_RESCHEDULE:
183 acl_fa_restart_timer_for_session (am, now, fsid);
190 if (pw->wip_session_change_requests)
191 _vec_len (pw->wip_session_change_requests) = 0;
196 int n_pending_swipes = 0;
197 for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
200 while (n_expired < am->fa_max_deleted_sessions_per_interval)
202 fsid.session_index = pw->fa_conn_list_head[tt];
203 if (!acl_fa_conn_time_to_check
204 (am, pw, now, thread_index, pw->fa_conn_list_head[tt]))
208 if (am->trace_sessions > 3)
210 elog_acl_maybe_trace_X3 (am,
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);
215 vec_add1 (pw->expired, fsid.session_index);
217 acl_fa_conn_list_delete_session (am, fsid, now);
220 for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
222 u32 session_index = pw->fa_conn_list_head[tt];
223 if (session_index == FA_SESSION_BOGUS_INDEX)
226 get_session_ptr (am, thread_index, session_index);
227 n_pending_swipes += sess->link_enqueue_time <= pw->swipe_end_time;
229 if (n_pending_swipes == 0)
231 pw->swipe_end_time = 0;
236 vec_foreach (psid, pw->expired)
238 fsid.session_index = *psid;
239 if (!pool_is_free_index (pw->fa_sessions_pool, fsid.session_index))
242 get_session_ptr (am, thread_index, fsid.session_index);
243 u32 sw_if_index = sess->sw_if_index;
244 u64 sess_timeout_time =
245 sess->last_active_time + fa_session_get_timeout (am, sess);
246 int timeout_passed = (now >= sess_timeout_time);
247 int clearing_interface =
248 clib_bitmap_get (pw->pending_clear_sw_if_index_bitmap, sw_if_index);
249 if (am->trace_sessions > 3)
251 elog_acl_maybe_trace_X2 (am,
252 "acl_fa_check_idle_sessions: now %lu sess_timeout_time %lu",
253 "i8i8", now, sess_timeout_time);
254 elog_acl_maybe_trace_X4 (am,
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);
261 if (timeout_passed || clearing_interface)
263 if (acl_fa_two_stage_delete_session (am, sw_if_index, fsid, now))
265 if (am->trace_sessions > 3)
267 elog_acl_maybe_trace_X2 (am,
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);
272 /* the session has been put */
273 pw->cnt_deleted_sessions++;
277 /* the connection marked as deleted and put to purgatory */
278 if (am->trace_sessions > 3)
280 elog_acl_maybe_trace_X2 (am,
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);
290 if (am->trace_sessions > 3)
292 elog_acl_maybe_trace_X2 (am,
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);
297 /* There was activity on the session, so the idle timeout
298 has not passed. Enqueue for another time period. */
300 acl_fa_conn_list_add_session (am, fsid, now);
301 pw->cnt_session_timer_restarted++;
306 pw->cnt_already_deleted_sessions++;
309 total_expired = vec_len (pw->expired);
310 /* zero out the vector which we have acted on */
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 */
316 if (pw->swipe_end_time && 0 == total_expired)
317 pw->swipe_end_time = 0;
319 elog_acl_maybe_trace_X1 (am,
320 "acl_fa_check_idle_sessions: done, total sessions expired: %d",
321 "i4", (u32) total_expired);
322 return (total_expired);
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.
333 #define foreach_acl_fa_cleaner_error \
334 _(UNKNOWN_EVENT, "unknown event received") \
339 #define _(sym,str) ACL_FA_CLEANER_ERROR_##sym,
340 foreach_acl_fa_cleaner_error
342 ACL_FA_CLEANER_N_ERROR,
343 } acl_fa_cleaner_error_t;
345 static char *acl_fa_cleaner_error_strings[] = {
346 #define _(sym,string) string,
347 foreach_acl_fa_cleaner_error
353 static vlib_node_registration_t acl_fa_session_cleaner_process_node;
354 static vlib_node_registration_t acl_fa_worker_session_cleaner_process_node;
357 send_one_worker_interrupt (vlib_main_t * vm, acl_main_t * am,
360 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
361 if (!pw->interrupt_is_pending)
363 pw->interrupt_is_pending = 1;
364 vlib_node_set_interrupt_pending (
365 vlib_get_main_by_index (thread_index),
366 acl_fa_worker_session_cleaner_process_node.index);
367 elog_acl_maybe_trace_X1 (am,
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; */
372 CLIB_MEMORY_BARRIER ();
377 aclp_post_session_change_request (acl_main_t * am, u32 target_thread,
378 u32 target_session, u32 request_type)
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];
383 clib_spinlock_lock_if_init (&pw->pending_session_change_request_lock);
384 /* vec_add1 might cause a reallocation */
385 vec_add1 (pw->pending_session_change_requests,
386 (((u64) request_type) << 32) | target_session);
387 pw->rcvd_session_change_requests++;
388 pw_me->sent_session_change_requests++;
389 if (vec_len (pw->pending_session_change_requests) == 1)
391 /* ensure the requests get processed */
392 send_one_worker_interrupt (am->vlib_main, am, target_thread);
394 clib_spinlock_unlock_if_init (&pw->pending_session_change_request_lock);
398 aclp_swap_wip_and_pending_session_change_requests (acl_main_t * am,
401 acl_fa_per_worker_data_t *pw = &am->per_worker_data[target_thread];
403 clib_spinlock_lock_if_init (&pw->pending_session_change_request_lock);
404 tmp = pw->pending_session_change_requests;
405 pw->pending_session_change_requests = pw->wip_session_change_requests;
406 pw->wip_session_change_requests = tmp;
407 clib_spinlock_unlock_if_init (&pw->pending_session_change_request_lock);
412 purgatory_has_connections (vlib_main_t * vm, acl_main_t * am,
415 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
417 return (FA_SESSION_BOGUS_INDEX !=
418 pw->fa_conn_list_head[ACL_TIMEOUT_PURGATORY]);
424 * Per-worker thread interrupt-driven cleaner thread
425 * to clean idle connections if there are no packets
428 acl_fa_worker_conn_cleaner_process (vlib_main_t * vm,
429 vlib_node_runtime_t * rt,
432 acl_main_t *am = &acl_main;
433 u64 now = clib_cpu_time_now ();
434 u16 thread_index = os_get_thread_index ();
435 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
437 elog_acl_maybe_trace_X1 (am,
438 "acl_fa_worker_conn_cleaner interrupt: now %lu",
440 /* allow another interrupt to be queued */
441 pw->interrupt_is_pending = 0;
442 if (pw->clear_in_process)
444 if (0 == pw->swipe_end_time)
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.
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.
457 if ((pw->pending_clear_sw_if_index_bitmap == 0)
458 || (pw->serviced_sw_if_index_bitmap == 0))
460 elog_acl_maybe_trace_X1 (am,
461 "acl_fa_worker_conn_cleaner: now %lu, someone tried to call clear but one of the bitmaps are empty",
463 clib_bitmap_zero (pw->pending_clear_sw_if_index_bitmap);
467 #ifdef FA_NODE_VERBOSE_DEBUG
469 ("WORKER-CLEAR: (before and) swiping sw-if-index bitmap: %U, my serviced bitmap %U",
470 format_bitmap_hex, pw->pending_clear_sw_if_index_bitmap,
471 format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
473 pw->pending_clear_sw_if_index_bitmap =
474 clib_bitmap_and (pw->pending_clear_sw_if_index_bitmap,
475 pw->serviced_sw_if_index_bitmap);
478 if (clib_bitmap_is_zero (pw->pending_clear_sw_if_index_bitmap))
480 /* if the cross-section is a zero vector, no need to do anything. */
481 elog_acl_maybe_trace_X1 (am,
482 "acl_fa_worker_conn_cleaner: now %lu, clearing done, nothing to do",
484 pw->clear_in_process = 0;
485 pw->swipe_end_time = 0;
489 #ifdef FA_NODE_VERBOSE_DEBUG
491 ("WORKER-CLEAR: swiping sw-if-index bitmap: %U, my serviced bitmap %U",
492 format_bitmap_hex, pw->pending_clear_sw_if_index_bitmap,
493 format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
495 elog_acl_maybe_trace_X1 (am,
496 "acl_fa_worker_conn_cleaner: swiping until %lu",
498 /* swipe through the connection lists until enqueue timestamps become above "now" */
499 pw->swipe_end_time = now;
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);
505 elog_acl_maybe_trace_X2 (am,
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)
511 if (pw->swipe_end_time == 0)
513 /* we were clearing but we could not process any more connections. time to stop. */
514 clib_bitmap_zero (pw->pending_clear_sw_if_index_bitmap);
515 pw->clear_in_process = 0;
516 elog_acl_maybe_trace_X1 (am,
517 "acl_fa_worker_conn_cleaner: now %lu, clearing done - all done",
522 elog_acl_maybe_trace_X1 (am,
523 "acl_fa_worker_conn_cleaner: now %lu, more work to do - requesting interrupt",
525 /* should continue clearing.. So could they please sent an interrupt again? */
526 send_one_worker_interrupt (vm, am, thread_index);
527 // pw->interrupt_is_needed = 1;
534 /* there was too much work, we should get an interrupt ASAP */
535 // pw->interrupt_is_needed = 1;
536 send_one_worker_interrupt (vm, am, thread_index);
537 pw->interrupt_is_unwanted = 0;
541 /* the current rate of interrupts is ok */
542 pw->interrupt_is_needed = 0;
543 pw->interrupt_is_unwanted = 0;
545 elog_acl_maybe_trace_X3 (am,
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));
550 /* be persistent about quickly deleting the connections from the purgatory */
551 if (purgatory_has_connections (vm, am, thread_index))
553 send_one_worker_interrupt (vm, am, thread_index);
555 pw->interrupt_generation = am->fa_interrupt_generation;
560 send_interrupts_to_workers (vlib_main_t * vm, acl_main_t * am)
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++)
567 send_one_worker_interrupt (vm, am, i);
571 /* centralized process to drive per-worker cleaners */
573 acl_fa_session_cleaner_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
576 acl_main_t *am = &acl_main;
578 f64 cpu_cps = vm->clib_time.clocks_per_second;
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;
583 acl_fa_per_worker_data_t *pw0;
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;
590 now = clib_cpu_time_now ();
591 next_expire = now + am->fa_current_cleaner_timer_wait_interval;
592 int has_pending_conns = 0;
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.
602 * Also, while we are at it, calculate the earliest we need to wake up.
604 for (ti = 0; ti < vlib_get_n_threads (); ti++)
606 if (ti >= vec_len (am->per_worker_data))
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++)
614 acl_fa_get_list_head_expiry_time (am, pw, now, ti, tt);
615 if ((head_expiry < next_expire) && !pw->interrupt_is_pending)
617 elog_acl_maybe_trace_X3 (am,
618 "acl_fa_session_cleaner_process: now %lu, worker: %u tt: %u",
619 "i8i2i2", now, ti, tt);
620 elog_acl_maybe_trace_X2 (am,
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;
625 if (FA_SESSION_BOGUS_INDEX != pw->fa_conn_list_head[tt])
627 has_pending_conns = 1;
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))
635 am->fa_cleaner_cnt_wait_without_timeout++;
636 elog_acl_maybe_trace_X1 (am,
637 "acl_conn_cleaner: now %lu entering wait without timeout",
639 (void) vlib_process_wait_for_event (vm);
640 event_type = vlib_process_get_events (vm, &event_data);
644 f64 timeout = ((i64) next_expire - (i64) now) / cpu_cps;
647 /* skip waiting altogether */
652 am->fa_cleaner_cnt_wait_with_timeout++;
653 elog_acl_maybe_trace_X2 (am,
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);
666 case ACL_FA_CLEANER_RESCHEDULE:
669 case ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX:
671 uword *clear_sw_if_index_bitmap = 0;
674 now = clib_cpu_time_now ();
675 elog_acl_maybe_trace_X1 (am,
676 "acl_fa_session_cleaner_process: now %lu, received ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX",
678 vec_foreach (sw_if_index0, event_data)
680 am->fa_cleaner_cnt_delete_by_sw_index++;
681 elog_acl_maybe_trace_X1 (am,
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)
690 if (!pool_is_free_index
691 (am->vnet_main->interface_main.sw_interfaces,
694 clear_sw_if_index_bitmap =
695 clib_bitmap_set (clear_sw_if_index_bitmap,
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)
705 CLIB_MEMORY_BARRIER ();
706 while (pw0->clear_in_process)
708 CLIB_MEMORY_BARRIER ();
709 elog_acl_maybe_trace_X1 (am,
710 "ACL_FA_NODE_CLEAN: waiting previous cleaning cycle to finish on %u",
712 (u32) (pw0 - am->per_worker_data));
713 vlib_process_suspend (vm, 0.0001);
714 if (pw0->interrupt_is_needed)
716 send_one_worker_interrupt (vm, am,
717 (pw0 - am->per_worker_data));
720 if (pw0->clear_in_process)
723 ("ERROR-BUG! Could not initiate cleaning on worker because another cleanup in progress");
729 /* if we need to clear all, then just clear the interfaces that we are servicing */
730 pw0->pending_clear_sw_if_index_bitmap =
731 clib_bitmap_dup (pw0->serviced_sw_if_index_bitmap);
735 pw0->pending_clear_sw_if_index_bitmap =
736 clib_bitmap_dup (clear_sw_if_index_bitmap);
739 ("ACL_FA_CLEANER: thread %u, pending clear bitmap: %U",
740 (am->per_worker_data - pw0), format_bitmap_hex,
741 pw0->pending_clear_sw_if_index_bitmap);
742 pw0->clear_in_process = 1;
745 /* send some interrupts so they can start working */
746 send_interrupts_to_workers (vm, am);
748 /* now wait till they all complete */
749 acl_log_info ("CLEANER mains len: %u per-worker len: %d",
750 vlib_get_n_threads (),
751 vec_len (am->per_worker_data));
752 vec_foreach (pw0, am->per_worker_data)
754 CLIB_MEMORY_BARRIER ();
755 while (pw0->clear_in_process)
757 CLIB_MEMORY_BARRIER ();
758 elog_acl_maybe_trace_X1 (am,
759 "ACL_FA_NODE_CLEAN: waiting for my cleaning cycle to finish on %u",
761 (u32) (pw0 - am->per_worker_data));
762 vlib_process_suspend (vm, 0.0001);
763 if (pw0->interrupt_is_needed)
765 send_one_worker_interrupt (vm, am,
766 (pw0 - am->per_worker_data));
770 acl_log_info ("ACL_FA_NODE_CLEAN: cleaning done");
771 clib_bitmap_free (clear_sw_if_index_bitmap);
773 am->fa_cleaner_cnt_delete_by_sw_index_ok++;
776 #ifdef FA_NODE_VERBOSE_DEBUG
777 clib_warning ("ACL plugin connection cleaner: unknown event %u",
780 vlib_node_increment_counter (vm,
781 acl_fa_session_cleaner_process_node.
783 ACL_FA_CLEANER_ERROR_UNKNOWN_EVENT, 1);
784 am->fa_cleaner_cnt_unknown_event++;
788 send_interrupts_to_workers (vm, am);
791 _vec_len (event_data) = 0;
794 * If the interrupts were not processed yet, ensure we wait a bit,
797 int need_more_wait = 0;
798 int max_wait_cycles = 100;
802 vec_foreach (pw0, am->per_worker_data)
804 if (pw0->interrupt_generation != am->fa_interrupt_generation)
811 vlib_process_suspend (vm, 0.0001);
814 while (need_more_wait && (--max_wait_cycles > 0));
816 int interrupts_needed = 0;
817 int interrupts_unwanted = 0;
819 vec_foreach (pw0, am->per_worker_data)
821 if (pw0->interrupt_is_needed)
824 /* the per-worker value is reset when sending the interrupt */
826 if (pw0->interrupt_is_unwanted)
828 interrupts_unwanted++;
829 pw0->interrupt_is_unwanted = 0;
832 if (interrupts_needed)
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;
839 else if (interrupts_unwanted)
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;
847 am->fa_cleaner_cnt_event_cycles++;
848 am->fa_interrupt_generation++;
856 acl_fa_enable_disable (u32 sw_if_index, int is_input, int enable_disable)
858 acl_main_t *am = &acl_main;
861 acl_fa_verify_init_sessions (am);
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,
865 ACL_FA_CLEANER_RESCHEDULE, 0);
866 clib_mem_set_heap (oldheap);
870 am->fa_total_enabled_count--;
875 ASSERT (clib_bitmap_get (am->fa_in_acl_on_sw_if_index, sw_if_index) !=
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,
889 ASSERT (clib_bitmap_get (am->fa_out_acl_on_sw_if_index, sw_if_index) !=
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,
901 if ((!enable_disable) && (!acl_fa_ifc_has_in_acl (am, sw_if_index))
902 && (!acl_fa_ifc_has_out_acl (am, sw_if_index)))
904 #ifdef FA_NODE_VERBOSE_DEBUG
905 clib_warning ("ENABLE-DISABLE: clean the connections on interface %d",
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,
910 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX,
912 clib_mem_set_heap (oldheap);
917 show_fa_sessions_hash (vlib_main_t * vm, u32 verbose)
919 acl_main_t *am = &acl_main;
920 if (am->fa_sessions_hash_is_initialized)
922 vlib_cli_output (vm, "\nIPv6 Session lookup hash table:\n%U\n\n",
923 format_bihash_40_8, &am->fa_ip6_sessions_hash,
926 vlib_cli_output (vm, "\nIPv4 Session lookup hash table:\n%U\n\n",
927 format_bihash_16_8, &am->fa_ip4_sessions_hash,
933 "\nSession lookup hash table is not allocated.\n\n");
940 VLIB_REGISTER_NODE (acl_fa_worker_session_cleaner_process_node, static) = {
941 .function = acl_fa_worker_conn_cleaner_process,
942 .name = "acl-plugin-fa-worker-cleaner-process",
943 .type = VLIB_NODE_TYPE_INPUT,
944 .state = VLIB_NODE_STATE_INTERRUPT,
947 VLIB_REGISTER_NODE (acl_fa_session_cleaner_process_node, static) = {
948 .function = acl_fa_session_cleaner_process,
949 .type = VLIB_NODE_TYPE_PROCESS,
950 .name = "acl-plugin-fa-cleaner-process",
951 .n_errors = ARRAY_LEN (acl_fa_cleaner_error_strings),
952 .error_strings = acl_fa_cleaner_error_strings,
961 * fd.io coding-style-patch-verification: ON
964 * eval: (c-set-style "gnu")