summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat44
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2020-02-17 13:37:20 +0000
committerOle Trøan <otroan@employees.org>2020-02-20 08:49:28 +0000
commit8a10c7351b35ab8405c2a9b030dba74a4da28f30 (patch)
tree561ee5a55a28d641892052f0d789d786edbc9b58 /src/plugins/nat/nat44
parent855938073f4f0c377488652f4204d3869151b010 (diff)
nat: avoid running pointless session cleanups
Save the next session timeout when sweeping sessions for cleanup so that we can avoid unnecessary runs of the sweeping algorithm. Type: fix Change-Id: I736d00f2dfe242af10f963fbe34b11128f8b0613 Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'src/plugins/nat/nat44')
-rw-r--r--src/plugins/nat/nat44/inlines.h40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/plugins/nat/nat44/inlines.h b/src/plugins/nat/nat44/inlines.h
index d7c355490cc..52dd37c9321 100644
--- a/src/plugins/nat/nat44/inlines.h
+++ b/src/plugins/nat/nat44/inlines.h
@@ -65,7 +65,11 @@ nat44_user_try_cleanup (snat_user_t * u, u32 thread_index, f64 now)
(f64) nat44_session_get_timeout (sm, s);
if (now < sess_timeout_time)
- continue;
+ {
+ tsm->min_session_timeout =
+ clib_min (sess_timeout_time, tsm->min_session_timeout);
+ continue;
+ }
nat44_session_cleanup (s, thread_index);
}
@@ -93,19 +97,33 @@ nat44_session_try_cleanup (ip4_address_t * addr,
if (PREDICT_TRUE (pool_elts (tsm->sessions) < sm->max_translations))
return;
- // there is no place so we try to cleanup all users in this thread
- /* *INDENT-OFF* */
- pool_foreach (u, tsm->users,
- ({
- nat44_user_try_cleanup (u, thread_index, now);
- }));
- /* *INDENT-ON* */
+ if (now >= tsm->min_session_timeout)
+ {
+ tsm->min_session_timeout = ~0;
+ // there is no place so we try to cleanup all users in this thread
+ /* *INDENT-OFF* */
+ pool_foreach (u, tsm->users,
+ ({ nat44_user_try_cleanup (u, thread_index, now); }));
+ /* *INDENT-ON* */
+ if (~0 == tsm->min_session_timeout)
+ {
+ tsm->min_session_timeout = 0;
+ }
+ }
return;
}
- // each time user creates a new session we try to cleanup expired sessions
- nat44_user_try_cleanup (pool_elt_at_index (tsm->users, value.value),
- thread_index, now);
+ if (now >= tsm->min_session_timeout)
+ {
+ tsm->min_session_timeout = ~0;
+ // each time user creates a new session we try to cleanup expired sessions
+ nat44_user_try_cleanup (pool_elt_at_index (tsm->users, value.value),
+ thread_index, now);
+ if (~0 == tsm->min_session_timeout)
+ {
+ tsm->min_session_timeout = 0;
+ }
+ }
}
static_always_inline void