diff options
author | Filip Varga <fivarga@cisco.com> | 2020-02-06 15:25:27 +0100 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2020-02-07 07:37:05 +0000 |
commit | edf777272b211de3d54f5dc7b211ee84cdb31373 (patch) | |
tree | ac18fd5190adb5d7090fdae80a9a296f048d8d80 /src/plugins | |
parent | b71ef86c7429e81921997e54a526bf666a2e4089 (diff) |
nat: api & cli command for forcing session cleanup
Ticket: VPP-1836
Type: feature
Signed-off-by: Filip Varga <fivarga@cisco.com>
Change-Id: I8f7fc011bac435445a8916a4948d130ca9162f67
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/nat/nat.api | 9 | ||||
-rw-r--r-- | src/plugins/nat/nat44/inlines.h | 37 | ||||
-rw-r--r-- | src/plugins/nat/nat44_cli.c | 26 | ||||
-rw-r--r-- | src/plugins/nat/nat_api.c | 26 |
4 files changed, 98 insertions, 0 deletions
diff --git a/src/plugins/nat/nat.api b/src/plugins/nat/nat.api index 58eee45d47d..0294d400966 100644 --- a/src/plugins/nat/nat.api +++ b/src/plugins/nat/nat.api @@ -130,6 +130,15 @@ enum nat_log_level : u8 NAT_LOG_DEBUG = 0x05, }; +/** \brief Run nat44 garbage collection + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +autoreply define nat44_session_cleanup { + u32 client_index; + u32 context; +}; + /** \brief Set NAT logging level @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request diff --git a/src/plugins/nat/nat44/inlines.h b/src/plugins/nat/nat44/inlines.h index a7bb469b464..d7c355490cc 100644 --- a/src/plugins/nat/nat44/inlines.h +++ b/src/plugins/nat/nat44/inlines.h @@ -108,6 +108,43 @@ nat44_session_try_cleanup (ip4_address_t * addr, thread_index, now); } +static_always_inline void +nat44_force_session_cleanup (void) +{ + snat_user_t *u = 0; + + snat_main_t *sm = &snat_main; + snat_main_per_thread_data_t *tsm; + + vlib_main_t *vm = vlib_get_main (); + f64 now = vlib_time_now (vm); + + // TODO: consider own timeouts + + if (sm->num_workers > 1) + { + /* *INDENT-OFF* */ + vec_foreach (tsm, sm->per_thread_data) + { + pool_foreach (u, tsm->users, + ({ + nat44_user_try_cleanup (u, tsm->thread_index, now); + })); + } + /* *INDENT-ON* */ + } + else + { + tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers); + /* *INDENT-OFF* */ + pool_foreach (u, tsm->users, + ({ + nat44_user_try_cleanup (u, tsm->thread_index, now); + })); + /* *INDENT-ON* */ + } +} + #endif /* included_nat44_inlines_h__ */ /* diff --git a/src/plugins/nat/nat44_cli.c b/src/plugins/nat/nat44_cli.c index e9d3ff5426f..659dbb2247e 100644 --- a/src/plugins/nat/nat44_cli.c +++ b/src/plugins/nat/nat44_cli.c @@ -22,6 +22,7 @@ #include <nat/nat_det.h> #include <nat/nat64.h> #include <nat/nat_inlines.h> +#include <nat/nat44/inlines.h> #include <nat/nat_affinity.h> #include <vnet/fib/fib_table.h> #include <nat/nat_ha.h> @@ -116,6 +117,18 @@ nat_show_workers_commnad_fn (vlib_main_t * vm, unformat_input_t * input, } static clib_error_t * +nat44_session_cleanup_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + + nat44_force_session_cleanup (); + + return error; +} + +static clib_error_t * snat_set_log_level_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) @@ -1979,6 +1992,19 @@ VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = { /*? * @cliexpar * @cliexstart{nat set logging level} + * To force garbage collection of nat sessions + * vpp# nat44 session cleanup + * @cliexend +?*/ +VLIB_CLI_COMMAND (nat44_session_cleanup_command, static) = { + .path = "nat44 session cleanup", + .function = nat44_session_cleanup_command_fn, + .short_help = "nat44 session cleanup", +}; + +/*? + * @cliexpar + * @cliexstart{nat set logging level} * To set NAT logging level use: * Set nat logging level * @cliexend diff --git a/src/plugins/nat/nat_api.c b/src/plugins/nat/nat_api.c index d73a0337d2a..4c162b7433c 100644 --- a/src/plugins/nat/nat_api.c +++ b/src/plugins/nat/nat_api.c @@ -23,6 +23,7 @@ #include <nat/nat64.h> #include <nat/nat66.h> #include <nat/nat_inlines.h> +#include <nat/nat44/inlines.h> #include <nat/nat_ha.h> #include <vlibapi/api.h> #include <vlibmemory/api.h> @@ -241,6 +242,30 @@ vl_api_nat_worker_dump_t_print (vl_api_nat_worker_dump_t * mp, void *handle) } static void +vl_api_nat44_session_cleanup_t_handler (vl_api_nat44_session_cleanup_t * mp) +{ + snat_main_t *sm = &snat_main; + vl_api_nat44_session_cleanup_reply_t *rmp; + int rv = 0; + + nat44_force_session_cleanup (); + + REPLY_MACRO (VL_API_NAT44_SESSION_CLEANUP_REPLY); +} + +static void * +vl_api_nat44_session_cleanup_t_print (vl_api_nat44_session_cleanup_t * mp, + void *handle) +{ + u8 *s; + + s = format (0, "SCRIPT: nat44_session_cleanup"); + + FINISH; +} + + +static void vl_api_nat_set_log_level_t_handler (vl_api_nat_set_log_level_t * mp) { snat_main_t *sm = &snat_main; @@ -3094,6 +3119,7 @@ _(NAT_CONTROL_PING, nat_control_ping) \ _(NAT_SHOW_CONFIG, nat_show_config) \ _(NAT_SET_WORKERS, nat_set_workers) \ _(NAT_WORKER_DUMP, nat_worker_dump) \ +_(NAT44_SESSION_CLEANUP, nat44_session_cleanup) \ _(NAT_SET_LOG_LEVEL, nat_set_log_level) \ _(NAT_IPFIX_ENABLE_DISABLE, nat_ipfix_enable_disable) \ _(NAT_SET_TIMEOUTS, nat_set_timeouts) \ |