summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat_inlines.h
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2020-04-05 10:22:47 +0200
committerKlement Sekera <ksekera@cisco.com>2020-04-08 11:07:49 +0200
commitba5f9bc7534bcf58225b0658993728b1f4d47a67 (patch)
treea3ca0cea8eea85910e050808c8df37bf802cd393 /src/plugins/nat/nat_inlines.h
parent248ce43c6d79b79597e28f19615e83d2bb0a9276 (diff)
nat: ED: global session LRU list
Maintain a global session LRU allowing reuse of expired session instead of relying on a scavenging mechanism to periodically walk sessions. Whenever a new session is being allocated in slow path, also attempt to free an expired session from global LRU list. Type: improvement Signed-off-by: Klement Sekera <ksekera@cisco.com> Change-Id: I9edde9ec138de67c9a4888e915b0490ec16415fa
Diffstat (limited to 'src/plugins/nat/nat_inlines.h')
-rw-r--r--src/plugins/nat/nat_inlines.h46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/plugins/nat/nat_inlines.h b/src/plugins/nat/nat_inlines.h
index bdcfd39dfb7..e5f2d96b33f 100644
--- a/src/plugins/nat/nat_inlines.h
+++ b/src/plugins/nat/nat_inlines.h
@@ -286,8 +286,9 @@ nat44_delete_user_with_no_session (snat_main_t * sm, snat_user_t * u,
}
always_inline void
-nat44_delete_session (snat_main_t * sm, snat_session_t * ses,
- u32 thread_index)
+nat44_delete_session_internal (snat_main_t * sm, snat_session_t * ses,
+ u32 thread_index, int global_lru_delete
+ /* delete from global LRU list */ )
{
snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
thread_index);
@@ -301,6 +302,11 @@ nat44_delete_session (snat_main_t * sm, snat_session_t * ses,
clib_dlist_remove (tsm->list_pool, ses->per_user_index);
pool_put_index (tsm->list_pool, ses->per_user_index);
+ if (global_lru_delete)
+ {
+ clib_dlist_remove (tsm->global_lru_pool, ses->global_lru_index);
+ }
+ pool_put_index (tsm->global_lru_pool, ses->global_lru_index);
pool_put (tsm->sessions, ses);
vlib_set_simple_counter (&sm->total_sessions, thread_index, 0,
pool_elts (tsm->sessions));
@@ -318,6 +324,22 @@ nat44_delete_session (snat_main_t * sm, snat_session_t * ses,
}
}
+always_inline void
+nat44_delete_session (snat_main_t * sm, snat_session_t * ses,
+ u32 thread_index)
+{
+ return nat44_delete_session_internal (sm, ses, thread_index, 1);
+}
+
+always_inline void
+nat44_ed_delete_session (snat_main_t * sm, snat_session_t * ses,
+ u32 thread_index, int global_lru_delete
+ /* delete from global LRU list */ )
+{
+ return nat44_delete_session_internal (sm, ses, thread_index,
+ global_lru_delete);
+}
+
/** \brief Set TCP session state.
@return 1 if session was closed, otherwise 0
*/
@@ -430,10 +452,22 @@ always_inline void
nat44_session_update_lru (snat_main_t * sm, snat_session_t * s,
u32 thread_index)
{
- clib_dlist_remove (sm->per_thread_data[thread_index].list_pool,
- s->per_user_index);
- clib_dlist_addtail (sm->per_thread_data[thread_index].list_pool,
- s->per_user_list_head_index, s->per_user_index);
+ /* don't update too often - timeout is in a magnitude of seconds anyway */
+ if (s->last_heard > s->last_lru_update + 1)
+ {
+ clib_dlist_remove (sm->per_thread_data[thread_index].list_pool,
+ s->per_user_index);
+ clib_dlist_addtail (sm->per_thread_data[thread_index].list_pool,
+ s->per_user_list_head_index, s->per_user_index);
+
+ clib_dlist_remove (sm->per_thread_data[thread_index].global_lru_pool,
+ s->global_lru_index);
+ clib_dlist_addtail (sm->per_thread_data[thread_index].global_lru_pool,
+ sm->
+ per_thread_data[thread_index].global_lru_head_index,
+ s->global_lru_index);
+ s->last_lru_update = s->last_heard;
+ }
}
always_inline void