acl_fill_5tuple (acl_main_t * am, vlib_buffer_t * b0, int is_ip6,
int is_input, int is_l2_path, fa_5tuple_t * p5tuple_pkt)
{
- int l3_offset = 14;
+ int l3_offset = ethernet_buffer_header_size(b0);
int l4_offset;
u16 ports[2];
u16 proto;
}
static void
-acl_fa_ifc_init_sessions (acl_main_t * am, int sw_if_index0)
+acl_fa_verify_init_sessions (acl_main_t * am)
{
- /// FIXME-MULTICORE: lock around this function
-#ifdef FA_NODE_VERBOSE_DEBUG
- clib_warning
- ("Initializing bihash for sw_if_index %d num buckets %lu memory size %llu",
- sw_if_index0, am->fa_conn_table_hash_num_buckets,
- am->fa_conn_table_hash_memory_size);
-#endif
- BV (clib_bihash_init) (&am->fa_sessions_hash,
+ if (!am->fa_sessions_hash_is_initialized) {
+ u16 wk;
+ /* Allocate the per-worker sessions pools */
+ for (wk = 0; wk < vec_len (am->per_worker_data); wk++) {
+ acl_fa_per_worker_data_t *pw = &am->per_worker_data[wk];
+ pool_alloc_aligned(pw->fa_sessions_pool, am->fa_conn_table_max_entries, CLIB_CACHE_LINE_BYTES);
+ }
+
+ /* ... and the interface session hash table */
+ BV (clib_bihash_init) (&am->fa_sessions_hash,
"ACL plugin FA session bihash",
am->fa_conn_table_hash_num_buckets,
am->fa_conn_table_hash_memory_size);
- am->fa_sessions_hash_is_initialized = 1;
+ am->fa_sessions_hash_is_initialized = 1;
+ }
}
static inline fa_session_t *get_session_ptr(acl_main_t *am, u16 thread_index, u32 session_index)
return sess;
}
+static inline int is_valid_session_ptr(acl_main_t *am, u16 thread_index, fa_session_t *sess)
+{
+ acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
+ return ((sess - pw->fa_sessions_pool) < pool_len(pw->fa_sessions_pool));
+}
+
static void
acl_fa_conn_list_add_session (acl_main_t * am, fa_full_session_id_t sess_id, u64 now)
{
if (~0 == pw->fa_conn_list_head[list_id]) {
pw->fa_conn_list_head[list_id] = sess_id.session_index;
- /* If it is a first conn in any list, kick the cleaner */
- vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
- ACL_FA_CLEANER_RESCHEDULE, 0);
}
}
pool_put_index (pw->fa_sessions_pool, sess_id.session_index);
/* Deleting from timer structures not needed,
as the caller must have dealt with the timers. */
- vec_validate (am->fa_session_dels_by_sw_if_index, sw_if_index);
- am->fa_session_dels_by_sw_if_index[sw_if_index]++;
+ vec_validate (pw->fa_session_dels_by_sw_if_index, sw_if_index);
+ pw->fa_session_dels_by_sw_if_index[sw_if_index]++;
clib_smp_atomic_add(&am->fa_session_total_dels, 1);
}
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)
{
- if (~0 == pw->fa_conn_list_head[timeout_type]) {
+ fa_session_t *sess = get_session_ptr(am, thread_index, pw->fa_conn_list_head[timeout_type]);
+ /*
+ * We can not check just the index here because inbetween the worker thread might
+ * dequeue the connection from the head just as we are about to check it.
+ */
+ if (!is_valid_session_ptr(am, thread_index, sess)) {
return ~0LL; // infinity.
} else {
- fa_session_t *sess = get_session_ptr(am, thread_index, pw->fa_conn_list_head[timeout_type]);
u64 timeout_time =
sess->link_enqueue_time + fa_session_get_list_timeout (am, sess);
return timeout_time;
- if (!acl_fa_ifc_has_sessions (am, sw_if_index))
- {
- acl_fa_ifc_init_sessions (am, sw_if_index);
- }
-
+ ASSERT(am->fa_sessions_hash_is_initialized == 1);
BV (clib_bihash_add_del) (&am->fa_sessions_hash,
&kv, 1);
acl_fa_conn_list_add_session(am, f_sess_id, now);
- vec_validate (am->fa_session_adds_by_sw_if_index, sw_if_index);
- am->fa_session_adds_by_sw_if_index[sw_if_index]++;
+ vec_validate (pw->fa_session_adds_by_sw_if_index, sw_if_index);
+ pw->fa_session_adds_by_sw_if_index[sw_if_index]++;
clib_smp_atomic_add(&am->fa_session_total_adds, 1);
}
u32 pkts_acl_permit = 0;
u32 pkts_restart_session_timer = 0;
u32 trace_bitmap = 0;
- u32 feature_bitmap0;
acl_main_t *am = &acl_main;
fa_5tuple_t fa_5tuple, kv_sess;
clib_bihash_kv_40_8_t value_sess;
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
else
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
- if (is_l2_path)
- feature_bitmap0 = vnet_buffer (b0)->l2.feature_bitmap;
/*
* Extract the L3/L4 matching info into a 5-tuple structure,
if (action > 0)
{
if (is_l2_path)
- next0 =
- feat_bitmap_get_next_node_index (l2_feat_next_node_index,
- feature_bitmap0);
+ next0 = vnet_l2_feature_next (b0, l2_feat_next_node_index, 0);
else
vnet_feature_next (sw_if_index0, &next0, b0);
}
if (num_expired >= am->fa_max_deleted_sessions_per_interval) {
/* there was too much work, we should get an interrupt ASAP */
pw->interrupt_is_needed = 1;
+ pw->interrupt_is_unwanted = 0;
} else if (num_expired <= am->fa_min_deleted_sessions_per_interval) {
/* signal that they should trigger us less */
+ pw->interrupt_is_needed = 0;
pw->interrupt_is_unwanted = 1;
} else {
/* the current rate of interrupts is ok */
{
acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
if (!pw->interrupt_is_pending) {
+ pw->interrupt_is_pending = 1;
vlib_node_set_interrupt_pending (vlib_mains[thread_index],
acl_fa_worker_session_cleaner_process_node.index);
- pw->interrupt_is_pending = 1;
/* if the interrupt was requested, mark that done. */
- pw->interrupt_is_needed = 0;
+ /* pw->interrupt_is_needed = 0; */
}
}
vlib_frame_t * f)
{
acl_main_t *am = &acl_main;
- u64 now = clib_cpu_time_now ();
+ u64 now;
f64 cpu_cps = vm->clib_time.clocks_per_second;
u64 next_expire;
/* We should check if there are connections to clean up - at least twice a second */
}
}
- /* If no pending connections then no point in timing out */
- if (!has_pending_conns)
+ /* If no pending connections and no ACL applied then no point in timing out */
+ if (!has_pending_conns && (0 == am->fa_total_enabled_count))
{
am->fa_cleaner_cnt_wait_without_timeout++;
(void) vlib_process_wait_for_event (vm);
}
}
- now = clib_cpu_time_now ();
switch (event_type)
{
case ~0:
{
uword *clear_sw_if_index_bitmap = 0;
uword *sw_if_index0;
+ int clear_all = 0;
#ifdef FA_NODE_VERBOSE_DEBUG
clib_warning("ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX received");
#endif
("ACL_FA_NODE_CLEAN: ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX: %d",
*sw_if_index0);
#endif
- clear_sw_if_index_bitmap = clib_bitmap_set(clear_sw_if_index_bitmap, *sw_if_index0, 1);
+ if (*sw_if_index0 == ~0)
+ {
+ clear_all = 1;
+ }
+ else
+ {
+ if (!pool_is_free_index (am->vnet_main->interface_main.sw_interfaces, *sw_if_index0))
+ {
+ clear_sw_if_index_bitmap = clib_bitmap_set(clear_sw_if_index_bitmap, *sw_if_index0, 1);
+ }
+ }
}
#ifdef FA_NODE_VERBOSE_DEBUG
clib_warning("ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX bitmap: %U", format_bitmap_hex, clear_sw_if_index_bitmap);
#endif
vec_foreach(pw0, am->per_worker_data) {
+ if ((pw0 == am->per_worker_data) && (vec_len(vlib_mains) > 1)) {
+ /* thread 0 in multithreaded scenario is not used */
+ continue;
+ }
CLIB_MEMORY_BARRIER ();
while (pw0->clear_in_process) {
CLIB_MEMORY_BARRIER ();
if (pw0->clear_in_process) {
clib_warning("ERROR-BUG! Could not initiate cleaning on worker because another cleanup in progress");
} else {
- pw0->pending_clear_sw_if_index_bitmap = clib_bitmap_dup(clear_sw_if_index_bitmap);
+ if (clear_all)
+ {
+ /* if we need to clear all, then just clear the interfaces that we are servicing */
+ pw0->pending_clear_sw_if_index_bitmap = clib_bitmap_dup(pw0->serviced_sw_if_index_bitmap);
+ }
+ else
+ {
+ pw0->pending_clear_sw_if_index_bitmap = clib_bitmap_dup(clear_sw_if_index_bitmap);
+ }
pw0->clear_in_process = 1;
}
}
clib_warning("CLEANER mains len: %d per-worker len: %d", vec_len(vlib_mains), vec_len(am->per_worker_data));
#endif
vec_foreach(pw0, am->per_worker_data) {
+ if ((pw0 == am->per_worker_data) && (vec_len(vlib_mains) > 1)) {
+ /* thread 0 in multithreaded scenario is not used */
+ continue;
+ }
CLIB_MEMORY_BARRIER ();
while (pw0->clear_in_process) {
CLIB_MEMORY_BARRIER ();
int interrupts_unwanted = 0;
vec_foreach(pw0, am->per_worker_data) {
+ if ((pw0 == am->per_worker_data) && (vec_len(vlib_mains) > 1)) {
+ /* thread 0 in multithreaded scenario is not used */
+ continue;
+ }
if (pw0->interrupt_is_needed) {
interrupts_needed++;
/* the per-worker value is reset when sending the interrupt */
if (interrupts_needed) {
/* they need more interrupts, do less waiting around next time */
am->fa_current_cleaner_timer_wait_interval /= 2;
+ /* never go into zero-wait either though - we need to give the space to others */
+ am->fa_current_cleaner_timer_wait_interval += 1;
} else if (interrupts_unwanted) {
/* slowly increase the amount of sleep up to a limit */
if (am->fa_current_cleaner_timer_wait_interval < max_timer_wait_interval)
acl_fa_enable_disable (u32 sw_if_index, int is_input, int enable_disable)
{
acl_main_t *am = &acl_main;
+ if (enable_disable) {
+ acl_fa_verify_init_sessions(am);
+ am->fa_total_enabled_count++;
+ vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
+ ACL_FA_CLEANER_RESCHEDULE, 0);
+ } else {
+ am->fa_total_enabled_count--;
+ }
+
if (is_input)
{
+ ASSERT(clib_bitmap_get(am->fa_in_acl_on_sw_if_index, sw_if_index) != enable_disable);
vnet_feature_enable_disable ("ip4-unicast", "acl-plugin-in-ip4-fa",
sw_if_index, enable_disable, 0, 0);
vnet_feature_enable_disable ("ip6-unicast", "acl-plugin-in-ip6-fa",
}
else
{
+ ASSERT(clib_bitmap_get(am->fa_out_acl_on_sw_if_index, sw_if_index) != enable_disable);
vnet_feature_enable_disable ("ip4-output", "acl-plugin-out-ip4-fa",
sw_if_index, enable_disable, 0, 0);
vnet_feature_enable_disable ("ip6-output", "acl-plugin-out-ip6-fa",