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 <vnet/pg/pg.h>
21 #include <vppinfra/error.h>
25 #include <vnet/ip/icmp46_packet.h>
27 #include <plugins/acl/fa_node.h>
28 #include <plugins/acl/acl.h>
29 #include <plugins/acl/lookup_context.h>
30 #include <plugins/acl/public_inlines.h>
31 #include <plugins/acl/session_inlines.h>
33 // #include <vppinfra/bihash_40_8.h>
37 fa_session_get_shortest_timeout (acl_main_t * am)
41 for (timeout_type = 0; timeout_type <= ACL_N_USER_TIMEOUTS; timeout_type++)
43 if (timeout > am->session_timeout_sec[timeout_type])
45 timeout = am->session_timeout_sec[timeout_type];
52 format_ip6_session_bihash_kv (u8 * s, va_list * args)
54 clib_bihash_kv_40_8_t *kv_40_8 = va_arg (*args, clib_bihash_kv_40_8_t *);
57 a5t.kv_40_8 = *kv_40_8;
58 fa_full_session_id_t *sess = (fa_full_session_id_t *) & a5t.pkt;
60 return (format (s, "l3 %U -> %U"
61 " 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",
62 format_ip6_address, &a5t.ip6_addr[0],
63 format_ip6_address, &a5t.ip6_addr[1],
64 a5t.l4.lsb_of_sw_if_index,
65 a5t.l4.proto, a5t.l4.is_input, a5t.l4.is_slowpath,
66 a5t.l4.reserved0, a5t.l4.port[0], a5t.l4.port[1],
67 sess->session_index, sess->thread_index,
68 sess->intf_policy_epoch));
72 format_ip4_session_bihash_kv (u8 * s, va_list * args)
74 clib_bihash_kv_16_8_t *kv_16_8 = va_arg (*args, clib_bihash_kv_16_8_t *);
77 a5t.kv_16_8 = *kv_16_8;
78 fa_full_session_id_t *sess = (fa_full_session_id_t *) & a5t.pkt;
80 return (format (s, "l3 %U -> %U"
81 " 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",
82 format_ip4_address, &a5t.ip4_addr[0],
83 format_ip4_address, &a5t.ip4_addr[1],
84 a5t.l4.lsb_of_sw_if_index,
85 a5t.l4.proto, a5t.l4.is_input, a5t.l4.is_slowpath,
86 a5t.l4.reserved0, a5t.l4.port[0], a5t.l4.port[1],
87 sess->session_index, sess->thread_index,
88 sess->intf_policy_epoch));
93 acl_fa_verify_init_sessions (acl_main_t * am)
95 if (!am->fa_sessions_hash_is_initialized)
98 /* Allocate the per-worker sessions pools */
99 for (wk = 0; wk < vec_len (am->per_worker_data); wk++)
101 acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
104 * // In lieu of trying to preallocate the pool and its free bitmap, rather use pool_init_fixed
105 * pool_alloc_aligned(pw->fa_sessions_pool, am->fa_conn_table_max_entries, CLIB_CACHE_LINE_BYTES);
106 * clib_bitmap_validate(pool_header(pw->fa_sessions_pool)->free_bitmap, am->fa_conn_table_max_entries);
108 pool_init_fixed (pw->fa_sessions_pool,
109 am->fa_conn_table_max_entries);
112 /* ... and the interface session hash table */
113 clib_bihash_init_40_8 (&am->fa_ip6_sessions_hash,
114 "ACL plugin FA IPv6 session bihash",
115 am->fa_conn_table_hash_num_buckets,
116 am->fa_conn_table_hash_memory_size);
117 clib_bihash_set_kvp_format_fn_40_8 (&am->fa_ip6_sessions_hash,
118 format_ip6_session_bihash_kv);
120 clib_bihash_init_16_8 (&am->fa_ip4_sessions_hash,
121 "ACL plugin FA IPv4 session bihash",
122 am->fa_conn_table_hash_num_buckets,
123 am->fa_conn_table_hash_memory_size);
124 clib_bihash_set_kvp_format_fn_16_8 (&am->fa_ip4_sessions_hash,
125 format_ip4_session_bihash_kv);
127 am->fa_sessions_hash_is_initialized = 1;
133 * Get the timeout of the session in a list since its enqueue time.
137 fa_session_get_list_timeout (acl_main_t * am, fa_session_t * sess)
139 u64 timeout = am->vlib_main->clib_time.clocks_per_second / 1000;
141 * we have the shortest possible timeout type in all the lists
142 * (see README-multicore for the rationale)
144 if (sess->link_list_id == ACL_TIMEOUT_PURGATORY)
145 timeout = fa_session_get_timeout (am, sess);
147 timeout *= fa_session_get_shortest_timeout (am);
152 acl_fa_get_list_head_expiry_time (acl_main_t * am,
153 acl_fa_per_worker_data_t * pw, u64 now,
154 u16 thread_index, int timeout_type)
156 return pw->fa_conn_list_head_expiry_time[timeout_type];
160 acl_fa_conn_time_to_check (acl_main_t * am, acl_fa_per_worker_data_t * pw,
161 u64 now, u16 thread_index, u32 session_index)
163 if (session_index == FA_SESSION_BOGUS_INDEX)
165 fa_session_t *sess = get_session_ptr (am, thread_index, session_index);
167 sess->link_enqueue_time + fa_session_get_list_timeout (am, sess);
168 return (timeout_time < now)
169 || (sess->link_enqueue_time <= pw->swipe_end_time);
173 * see if there are sessions ready to be checked,
174 * do the maintenance (requeue or delete), and
175 * return the total number of sessions reclaimed.
178 acl_fa_check_idle_sessions (acl_main_t * am, u16 thread_index, u64 now)
180 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
181 fa_full_session_id_t fsid;
182 fsid.thread_index = thread_index;
183 int total_expired = 0;
187 int n_pending_swipes = 0;
188 for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
191 while (n_expired < am->fa_max_deleted_sessions_per_interval)
193 fsid.session_index = pw->fa_conn_list_head[tt];
194 if (!acl_fa_conn_time_to_check
195 (am, pw, now, thread_index, pw->fa_conn_list_head[tt]))
199 if (am->trace_sessions > 3)
201 elog_acl_maybe_trace_X3 (am,
202 "acl_fa_check_idle_sessions: expire session %d in list %d on thread %d",
203 "i4i4i4", (u32) fsid.session_index,
204 (u32) tt, (u32) thread_index);
206 vec_add1 (pw->expired, fsid.session_index);
208 acl_fa_conn_list_delete_session (am, fsid, now);
211 for (tt = 0; tt < ACL_N_TIMEOUTS; tt++)
213 u32 session_index = pw->fa_conn_list_head[tt];
214 if (session_index == FA_SESSION_BOGUS_INDEX)
217 get_session_ptr (am, thread_index, session_index);
218 n_pending_swipes += sess->link_enqueue_time <= pw->swipe_end_time;
220 if (n_pending_swipes == 0)
222 pw->swipe_end_time = 0;
227 vec_foreach (psid, pw->expired)
229 fsid.session_index = *psid;
230 if (!pool_is_free_index (pw->fa_sessions_pool, fsid.session_index))
233 get_session_ptr (am, thread_index, fsid.session_index);
234 u32 sw_if_index = sess->sw_if_index;
235 u64 sess_timeout_time =
236 sess->last_active_time + fa_session_get_timeout (am, sess);
237 int timeout_passed = (now >= sess_timeout_time);
238 int clearing_interface =
239 clib_bitmap_get (pw->pending_clear_sw_if_index_bitmap, sw_if_index);
240 if (am->trace_sessions > 3)
242 elog_acl_maybe_trace_X4 (am,
243 "acl_fa_check_idle_sessions: session %d sw_if_index %d timeout_passed %d clearing_interface %d",
244 "i4i4i4i4", (u32) fsid.session_index,
245 (u32) sess->sw_if_index,
246 (u32) timeout_passed,
247 (u32) clearing_interface);
249 if (timeout_passed || clearing_interface)
251 if (acl_fa_two_stage_delete_session (am, sw_if_index, fsid, now))
253 if (am->trace_sessions > 3)
255 elog_acl_maybe_trace_X2 (am,
256 "acl_fa_check_idle_sessions: deleted session %d sw_if_index %d",
257 "i4i4", (u32) fsid.session_index,
258 (u32) sess->sw_if_index);
260 /* the session has been put */
261 pw->cnt_deleted_sessions++;
265 /* the connection marked as deleted and put to purgatory */
266 if (am->trace_sessions > 3)
268 elog_acl_maybe_trace_X2 (am,
269 "acl_fa_check_idle_sessions: session %d sw_if_index %d marked as deleted, put to purgatory",
270 "i4i4", (u32) fsid.session_index,
271 (u32) sess->sw_if_index);
278 if (am->trace_sessions > 3)
280 elog_acl_maybe_trace_X2 (am,
281 "acl_fa_check_idle_sessions: restart timer for session %d sw_if_index %d",
282 "i4i4", (u32) fsid.session_index,
283 (u32) sess->sw_if_index);
285 /* There was activity on the session, so the idle timeout
286 has not passed. Enqueue for another time period. */
288 acl_fa_conn_list_add_session (am, fsid, now);
289 pw->cnt_session_timer_restarted++;
294 pw->cnt_already_deleted_sessions++;
297 total_expired = vec_len (pw->expired);
298 /* zero out the vector which we have acted on */
300 _vec_len (pw->expired) = 0;
301 /* if we were advancing and reached the end
302 * (no more sessions to recycle), reset the fast-forward timestamp */
304 if (pw->swipe_end_time && 0 == total_expired)
305 pw->swipe_end_time = 0;
307 elog_acl_maybe_trace_X1 (am,
308 "acl_fa_check_idle_sessions: done, total sessions expired: %d",
309 "i4", (u32) total_expired);
310 return (total_expired);
314 * This process ensures the connection cleanup happens every so often
315 * even in absence of traffic, as well as provides general orchestration
316 * for requests like connection deletion on a given sw_if_index.
321 #define foreach_acl_fa_cleaner_error \
322 _(UNKNOWN_EVENT, "unknown event received") \
327 #define _(sym,str) ACL_FA_CLEANER_ERROR_##sym,
328 foreach_acl_fa_cleaner_error
330 ACL_FA_CLEANER_N_ERROR,
331 } acl_fa_cleaner_error_t;
333 static char *acl_fa_cleaner_error_strings[] = {
334 #define _(sym,string) string,
335 foreach_acl_fa_cleaner_error
341 static vlib_node_registration_t acl_fa_session_cleaner_process_node;
342 static vlib_node_registration_t acl_fa_worker_session_cleaner_process_node;
345 send_one_worker_interrupt (vlib_main_t * vm, acl_main_t * am,
348 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
349 if (!pw->interrupt_is_pending)
351 pw->interrupt_is_pending = 1;
352 vlib_node_set_interrupt_pending (vlib_mains[thread_index],
353 acl_fa_worker_session_cleaner_process_node.index);
354 elog_acl_maybe_trace_X1 (am,
355 "send_one_worker_interrupt: send interrupt to worker %u",
356 "i4", ((u32) thread_index));
357 /* if the interrupt was requested, mark that done. */
358 /* pw->interrupt_is_needed = 0; */
359 CLIB_MEMORY_BARRIER ();
364 purgatory_has_connections (vlib_main_t * vm, acl_main_t * am,
367 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
369 return (FA_SESSION_BOGUS_INDEX !=
370 pw->fa_conn_list_head[ACL_TIMEOUT_PURGATORY]);
376 * Per-worker thread interrupt-driven cleaner thread
377 * to clean idle connections if there are no packets
380 acl_fa_worker_conn_cleaner_process (vlib_main_t * vm,
381 vlib_node_runtime_t * rt,
384 acl_main_t *am = &acl_main;
385 u64 now = clib_cpu_time_now ();
386 u16 thread_index = os_get_thread_index ();
387 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
389 elog_acl_maybe_trace_X1 (am,
390 "acl_fa_worker_conn_cleaner interrupt: now %lu",
392 /* allow another interrupt to be queued */
393 pw->interrupt_is_pending = 0;
394 if (pw->clear_in_process)
396 if (0 == pw->swipe_end_time)
399 * Someone has just set the flag to start clearing.
400 * we do this by combing through the connections up to a "time T"
401 * which is now, and requeueing everything except the expired
402 * connections and those matching the interface(s) being cleared.
406 * first filter the sw_if_index bitmap that they want from us, by
407 * a bitmap of sw_if_index for which we actually have connections.
409 if ((pw->pending_clear_sw_if_index_bitmap == 0)
410 || (pw->serviced_sw_if_index_bitmap == 0))
412 elog_acl_maybe_trace_X1 (am,
413 "acl_fa_worker_conn_cleaner: now %lu, someone tried to call clear but one of the bitmaps are empty",
415 clib_bitmap_zero (pw->pending_clear_sw_if_index_bitmap);
419 #ifdef FA_NODE_VERBOSE_DEBUG
421 ("WORKER-CLEAR: (before and) swiping sw-if-index bitmap: %U, my serviced bitmap %U",
422 format_bitmap_hex, pw->pending_clear_sw_if_index_bitmap,
423 format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
425 pw->pending_clear_sw_if_index_bitmap =
426 clib_bitmap_and (pw->pending_clear_sw_if_index_bitmap,
427 pw->serviced_sw_if_index_bitmap);
430 if (clib_bitmap_is_zero (pw->pending_clear_sw_if_index_bitmap))
432 /* if the cross-section is a zero vector, no need to do anything. */
433 elog_acl_maybe_trace_X1 (am,
434 "acl_fa_worker_conn_cleaner: now %lu, clearing done, nothing to do",
436 pw->clear_in_process = 0;
437 pw->swipe_end_time = 0;
441 #ifdef FA_NODE_VERBOSE_DEBUG
443 ("WORKER-CLEAR: swiping sw-if-index bitmap: %U, my serviced bitmap %U",
444 format_bitmap_hex, pw->pending_clear_sw_if_index_bitmap,
445 format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
447 elog_acl_maybe_trace_X1 (am,
448 "acl_fa_worker_conn_cleaner: swiping until %lu",
450 /* swipe through the connection lists until enqueue timestamps become above "now" */
451 pw->swipe_end_time = now;
455 num_expired = acl_fa_check_idle_sessions (am, thread_index, now);
456 // clib_warning("WORKER-CLEAR: checked %d sessions (clear_in_progress: %d)", num_expired, pw->clear_in_process);
457 elog_acl_maybe_trace_X2 (am,
458 "acl_fa_worker_conn_cleaner: checked %d sessions (clear_in_process: %d)",
459 "i4i4", (u32) num_expired,
460 (u32) pw->clear_in_process);
461 if (pw->clear_in_process)
463 if (pw->swipe_end_time == 0)
465 /* we were clearing but we could not process any more connections. time to stop. */
466 clib_bitmap_zero (pw->pending_clear_sw_if_index_bitmap);
467 pw->clear_in_process = 0;
468 elog_acl_maybe_trace_X1 (am,
469 "acl_fa_worker_conn_cleaner: now %lu, clearing done - all done",
474 elog_acl_maybe_trace_X1 (am,
475 "acl_fa_worker_conn_cleaner: now %lu, more work to do - requesting interrupt",
477 /* should continue clearing.. So could they please sent an interrupt again? */
478 send_one_worker_interrupt (vm, am, thread_index);
479 // pw->interrupt_is_needed = 1;
486 /* there was too much work, we should get an interrupt ASAP */
487 // pw->interrupt_is_needed = 1;
488 send_one_worker_interrupt (vm, am, thread_index);
489 pw->interrupt_is_unwanted = 0;
493 /* the current rate of interrupts is ok */
494 pw->interrupt_is_needed = 0;
495 pw->interrupt_is_unwanted = 0;
497 elog_acl_maybe_trace_X3 (am,
498 "acl_fa_worker_conn_cleaner: now %lu, interrupt needed: %u, interrupt unwanted: %u",
499 "i8i4i4", now, ((u32) pw->interrupt_is_needed),
500 ((u32) pw->interrupt_is_unwanted));
502 /* be persistent about quickly deleting the connections from the purgatory */
503 if (purgatory_has_connections (vm, am, thread_index))
505 send_one_worker_interrupt (vm, am, thread_index);
507 pw->interrupt_generation = am->fa_interrupt_generation;
512 send_interrupts_to_workers (vlib_main_t * vm, acl_main_t * am)
515 /* Can't use vec_len(am->per_worker_data) since the threads might not have come up yet; */
516 int n_threads = vec_len (vlib_mains);
517 for (i = 0; i < n_threads; i++)
519 send_one_worker_interrupt (vm, am, i);
523 /* centralized process to drive per-worker cleaners */
525 acl_fa_session_cleaner_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
528 acl_main_t *am = &acl_main;
530 f64 cpu_cps = vm->clib_time.clocks_per_second;
532 /* We should check if there are connections to clean up - at least twice a second */
533 u64 max_timer_wait_interval = cpu_cps / 2;
534 uword event_type, *event_data = 0;
535 acl_fa_per_worker_data_t *pw0;
537 am->fa_current_cleaner_timer_wait_interval = max_timer_wait_interval;
538 am->fa_cleaner_node_index = acl_fa_session_cleaner_process_node.index;
539 am->fa_interrupt_generation = 1;
542 now = clib_cpu_time_now ();
543 next_expire = now + am->fa_current_cleaner_timer_wait_interval;
544 int has_pending_conns = 0;
549 * walk over all per-thread list heads of different timeouts,
550 * and see if there are any connections pending.
551 * If there aren't - we do not need to wake up until the
552 * worker code signals that it has added a connection.
554 * Also, while we are at it, calculate the earliest we need to wake up.
556 for (ti = 0; ti < vec_len (vlib_mains); ti++)
558 if (ti >= vec_len (am->per_worker_data))
562 acl_fa_per_worker_data_t *pw = &am->per_worker_data[ti];
563 for (tt = 0; tt < vec_len (pw->fa_conn_list_head); tt++)
566 acl_fa_get_list_head_expiry_time (am, pw, now, ti, tt);
567 if ((head_expiry < next_expire) && !pw->interrupt_is_pending)
569 elog_acl_maybe_trace_X3 (am,
570 "acl_fa_session_cleaner_process: now %lu, worker: %u tt: %u",
571 "i8i2i2", now, ti, tt);
572 elog_acl_maybe_trace_X2 (am,
573 "acl_fa_session_cleaner_process: head expiry: %lu, is earlier than curr next expire: %lu",
574 "i8i8", head_expiry, next_expire);
575 next_expire = head_expiry;
577 if (FA_SESSION_BOGUS_INDEX != pw->fa_conn_list_head[tt])
579 has_pending_conns = 1;
584 /* If no pending connections and no ACL applied then no point in timing out */
585 if (!has_pending_conns && (0 == am->fa_total_enabled_count))
587 am->fa_cleaner_cnt_wait_without_timeout++;
588 elog_acl_maybe_trace_X1 (am,
589 "acl_conn_cleaner: now %lu entering wait without timeout",
591 (void) vlib_process_wait_for_event (vm);
592 event_type = vlib_process_get_events (vm, &event_data);
596 f64 timeout = ((i64) next_expire - (i64) now) / cpu_cps;
599 /* skip waiting altogether */
604 am->fa_cleaner_cnt_wait_with_timeout++;
605 elog_acl_maybe_trace_X2 (am,
606 "acl_conn_cleaner: now %lu entering wait with timeout %.6f sec",
607 "i8f8", now, timeout);
608 (void) vlib_process_wait_for_event_or_clock (vm, timeout);
609 event_type = vlib_process_get_events (vm, &event_data);
618 case ACL_FA_CLEANER_RESCHEDULE:
621 case ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX:
623 uword *clear_sw_if_index_bitmap = 0;
626 now = clib_cpu_time_now ();
627 elog_acl_maybe_trace_X1 (am,
628 "acl_fa_session_cleaner_process: now %lu, received ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX",
630 vec_foreach (sw_if_index0, event_data)
632 am->fa_cleaner_cnt_delete_by_sw_index++;
633 elog_acl_maybe_trace_X1 (am,
634 "acl_fa_session_cleaner_process: ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX %u",
635 "i4", *sw_if_index0);
636 if (*sw_if_index0 == ~0)
642 if (!pool_is_free_index
643 (am->vnet_main->interface_main.sw_interfaces,
646 clear_sw_if_index_bitmap =
647 clib_bitmap_set (clear_sw_if_index_bitmap,
653 ("ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX bitmap: %U, clear_all: %u",
654 format_bitmap_hex, clear_sw_if_index_bitmap, clear_all);
655 vec_foreach (pw0, am->per_worker_data)
657 CLIB_MEMORY_BARRIER ();
658 while (pw0->clear_in_process)
660 CLIB_MEMORY_BARRIER ();
661 elog_acl_maybe_trace_X1 (am,
662 "ACL_FA_NODE_CLEAN: waiting previous cleaning cycle to finish on %u",
664 (u32) (pw0 - am->per_worker_data));
665 vlib_process_suspend (vm, 0.0001);
666 if (pw0->interrupt_is_needed)
668 send_one_worker_interrupt (vm, am,
669 (pw0 - am->per_worker_data));
672 if (pw0->clear_in_process)
675 ("ERROR-BUG! Could not initiate cleaning on worker because another cleanup in progress");
681 /* if we need to clear all, then just clear the interfaces that we are servicing */
682 pw0->pending_clear_sw_if_index_bitmap =
683 clib_bitmap_dup (pw0->serviced_sw_if_index_bitmap);
687 pw0->pending_clear_sw_if_index_bitmap =
688 clib_bitmap_dup (clear_sw_if_index_bitmap);
691 ("ACL_FA_CLEANER: thread %u, pending clear bitmap: %U",
692 (am->per_worker_data - pw0), format_bitmap_hex,
693 pw0->pending_clear_sw_if_index_bitmap);
694 pw0->clear_in_process = 1;
697 /* send some interrupts so they can start working */
698 send_interrupts_to_workers (vm, am);
700 /* now wait till they all complete */
701 acl_log_err ("CLEANER mains len: %u per-worker len: %d",
702 vec_len (vlib_mains), vec_len (am->per_worker_data));
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 for my 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));
721 acl_log_err ("ACL_FA_NODE_CLEAN: cleaning done");
722 clib_bitmap_free (clear_sw_if_index_bitmap);
724 am->fa_cleaner_cnt_delete_by_sw_index_ok++;
727 #ifdef FA_NODE_VERBOSE_DEBUG
728 clib_warning ("ACL plugin connection cleaner: unknown event %u",
731 vlib_node_increment_counter (vm,
732 acl_fa_session_cleaner_process_node.
734 ACL_FA_CLEANER_ERROR_UNKNOWN_EVENT, 1);
735 am->fa_cleaner_cnt_unknown_event++;
739 send_interrupts_to_workers (vm, am);
742 _vec_len (event_data) = 0;
745 * If the interrupts were not processed yet, ensure we wait a bit,
748 int need_more_wait = 0;
749 int max_wait_cycles = 100;
753 vec_foreach (pw0, am->per_worker_data)
755 if (pw0->interrupt_generation != am->fa_interrupt_generation)
762 vlib_process_suspend (vm, 0.0001);
765 while (need_more_wait && (--max_wait_cycles > 0));
767 int interrupts_needed = 0;
768 int interrupts_unwanted = 0;
770 vec_foreach (pw0, am->per_worker_data)
772 if (pw0->interrupt_is_needed)
775 /* the per-worker value is reset when sending the interrupt */
777 if (pw0->interrupt_is_unwanted)
779 interrupts_unwanted++;
780 pw0->interrupt_is_unwanted = 0;
783 if (interrupts_needed)
785 /* they need more interrupts, do less waiting around next time */
786 am->fa_current_cleaner_timer_wait_interval /= 2;
787 /* never go into zero-wait either though - we need to give the space to others */
788 am->fa_current_cleaner_timer_wait_interval += 1;
790 else if (interrupts_unwanted)
792 /* slowly increase the amount of sleep up to a limit */
793 if (am->fa_current_cleaner_timer_wait_interval <
794 max_timer_wait_interval)
795 am->fa_current_cleaner_timer_wait_interval +=
796 cpu_cps * am->fa_cleaner_wait_time_increment;
798 am->fa_cleaner_cnt_event_cycles++;
799 am->fa_interrupt_generation++;
807 acl_fa_enable_disable (u32 sw_if_index, int is_input, int enable_disable)
809 acl_main_t *am = &acl_main;
812 acl_fa_verify_init_sessions (am);
813 am->fa_total_enabled_count++;
814 void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
815 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
816 ACL_FA_CLEANER_RESCHEDULE, 0);
817 clib_mem_set_heap (oldheap);
821 am->fa_total_enabled_count--;
826 ASSERT (clib_bitmap_get (am->fa_in_acl_on_sw_if_index, sw_if_index) !=
828 void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
829 vnet_feature_enable_disable ("ip4-unicast", "acl-plugin-in-ip4-fa",
830 sw_if_index, enable_disable, 0, 0);
831 vnet_feature_enable_disable ("ip6-unicast", "acl-plugin-in-ip6-fa",
832 sw_if_index, enable_disable, 0, 0);
833 clib_mem_set_heap (oldheap);
834 am->fa_in_acl_on_sw_if_index =
835 clib_bitmap_set (am->fa_in_acl_on_sw_if_index, sw_if_index,
840 ASSERT (clib_bitmap_get (am->fa_out_acl_on_sw_if_index, sw_if_index) !=
842 void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
843 vnet_feature_enable_disable ("ip4-output", "acl-plugin-out-ip4-fa",
844 sw_if_index, enable_disable, 0, 0);
845 vnet_feature_enable_disable ("ip6-output", "acl-plugin-out-ip6-fa",
846 sw_if_index, enable_disable, 0, 0);
847 clib_mem_set_heap (oldheap);
848 am->fa_out_acl_on_sw_if_index =
849 clib_bitmap_set (am->fa_out_acl_on_sw_if_index, sw_if_index,
852 if ((!enable_disable) && (!acl_fa_ifc_has_in_acl (am, sw_if_index))
853 && (!acl_fa_ifc_has_out_acl (am, sw_if_index)))
855 #ifdef FA_NODE_VERBOSE_DEBUG
856 clib_warning ("ENABLE-DISABLE: clean the connections on interface %d",
859 void *oldheap = clib_mem_set_heap (am->vlib_main->heap_base);
860 vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
861 ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX,
863 clib_mem_set_heap (oldheap);
868 show_fa_sessions_hash (vlib_main_t * vm, u32 verbose)
870 acl_main_t *am = &acl_main;
871 if (am->fa_sessions_hash_is_initialized)
873 vlib_cli_output (vm, "\nIPv6 Session lookup hash table:\n%U\n\n",
874 format_bihash_40_8, &am->fa_ip6_sessions_hash,
877 vlib_cli_output (vm, "\nIPv4 Session lookup hash table:\n%U\n\n",
878 format_bihash_16_8, &am->fa_ip4_sessions_hash,
884 "\nSession lookup hash table is not allocated.\n\n");
891 VLIB_REGISTER_NODE (acl_fa_worker_session_cleaner_process_node, static) = {
892 .function = acl_fa_worker_conn_cleaner_process,
893 .name = "acl-plugin-fa-worker-cleaner-process",
894 .type = VLIB_NODE_TYPE_INPUT,
895 .state = VLIB_NODE_STATE_INTERRUPT,
898 VLIB_REGISTER_NODE (acl_fa_session_cleaner_process_node, static) = {
899 .function = acl_fa_session_cleaner_process,
900 .type = VLIB_NODE_TYPE_PROCESS,
901 .name = "acl-plugin-fa-cleaner-process",
902 .n_errors = ARRAY_LEN (acl_fa_cleaner_error_strings),
903 .error_strings = acl_fa_cleaner_error_strings,
912 * fd.io coding-style-patch-verification: ON
915 * eval: (c-set-style "gnu")