aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat44_cli.c
diff options
context:
space:
mode:
authorFilip Varga <fivarga@cisco.com>2020-04-19 19:44:49 +0200
committerOle Trøan <otroan@employees.org>2020-05-06 08:46:45 +0000
commitc611f36bbc75a7157bbec26a78178872ddc5441f (patch)
treed1ad9d56d69f7e8b6284ab5d8d25c0671cdd5f59 /src/plugins/nat/nat44_cli.c
parente4deacc4220511c5ee93eca6b059d2a64ab1d36c (diff)
nat: enable force session cleanup
Force session cleanup drops NAT db. Also fixing user specific cli/api calls. Type: improvement Change-Id: Ia3e25fcf07fe5fb9a83d55c03fe90aca727b41ac Signed-off-by: Filip Varga <fivarga@cisco.com>
Diffstat (limited to 'src/plugins/nat/nat44_cli.c')
-rw-r--r--src/plugins/nat/nat44_cli.c67
1 files changed, 53 insertions, 14 deletions
diff --git a/src/plugins/nat/nat44_cli.c b/src/plugins/nat/nat44_cli.c
index fe08832c641..ad4c1c8fdbd 100644
--- a/src/plugins/nat/nat44_cli.c
+++ b/src/plugins/nat/nat44_cli.c
@@ -27,8 +27,15 @@
#include <vnet/fib/fib_table.h>
#include <nat/nat_ha.h>
+
+#define UNSUPPORTED_IN_DET_OR_ED_MODE_STR \
+ "This command is unsupported in deterministic or endpoint dependent mode"
+#define UNSUPPORTED_IN_DET_OR_NON_ED_MODE_STR \
+ "This command is unsupported in deterministic or non endpoint dependent mode"
#define UNSUPPORTED_IN_DET_MODE_STR \
"This command is unsupported in deterministic mode"
+#define SUPPORTED_ONLY_IN_ED_MODE_STR \
+ "This command is supported only in endpoint dependent mode"
#define SUPPORTED_ONLY_IN_DET_MODE_STR \
"This command is supported only in deterministic mode"
@@ -638,7 +645,7 @@ nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
snat_session_t *s;
if (sm->deterministic || !sm->endpoint_dependent)
- return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
+ return clib_error_return (0, UNSUPPORTED_IN_DET_OR_NON_ED_MODE_STR);
// print session configuration values
vlib_cli_output (vm, "max translations: %u", sm->max_translations);
@@ -1474,11 +1481,11 @@ nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
{
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error = 0;
- snat_main_t *sm = &snat_main;
+
snat_main_per_thread_data_t *tsm;
+ snat_main_t *sm = &snat_main;
- int detail = 0, metrics = 0;
- snat_user_t *u;
+ int detail = 0;
int i = 0;
if (sm->deterministic)
@@ -1491,8 +1498,6 @@ nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
{
if (unformat (line_input, "detail"))
detail = 1;
- else if (unformat (line_input, "metrics"))
- metrics = 1;
else
{
error = clib_error_return (0, "unknown input '%U'",
@@ -1503,7 +1508,11 @@ nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
unformat_free (line_input);
print:
- vlib_cli_output (vm, "NAT44 sessions:");
+ if (!sm->endpoint_dependent)
+ vlib_cli_output (vm, "NAT44 sessions:");
+ else
+ vlib_cli_output (vm, "NAT44 ED sessions:");
+
/* *INDENT-OFF* */
vec_foreach_index (i, sm->per_thread_data)
{
@@ -1512,19 +1521,21 @@ print:
vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
i, vlib_worker_threads[i].name,
pool_elts (tsm->sessions));
- if (metrics)
+
+ if (!sm->endpoint_dependent)
{
- u64 now = vlib_time_now (sm->vlib_main);
+ snat_user_t *u;
pool_foreach (u, tsm->users,
({
- vlib_cli_output (vm, " %U", format_snat_user_v2, tsm, u, now);
+ vlib_cli_output (vm, " %U", format_snat_user, tsm, u, detail);
}));
}
else
{
- pool_foreach (u, tsm->users,
+ snat_session_t *s;
+ pool_foreach (s, tsm->sessions,
({
- vlib_cli_output (vm, " %U", format_snat_user, tsm, u, detail);
+ vlib_cli_output (vm, " %U\n", format_snat_session, tsm, s);
}));
}
}
@@ -1586,8 +1597,8 @@ nat44_del_user_command_fn (vlib_main_t * vm,
u32 fib_index = 0;
int rv;
- if (sm->deterministic)
- return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
+ if (sm->deterministic || sm->endpoint_dependent)
+ return clib_error_return (0, UNSUPPORTED_IN_DET_OR_ED_MODE_STR);
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
@@ -1621,6 +1632,21 @@ done:
}
static clib_error_t *
+nat44_clear_sessions_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ snat_main_t *sm = &snat_main;
+ clib_error_t *error = 0;
+
+ if (sm->deterministic)
+ return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
+
+ nat44_sessions_clear ();
+ return error;
+}
+
+static clib_error_t *
nat44_del_session_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
@@ -2655,6 +2681,19 @@ VLIB_CLI_COMMAND (nat44_del_user_command, static) = {
/*?
* @cliexpar
+ * @cliexstart{clear nat44 sessions}
+ * To clear all NAT44 sessions
+ * vpp# clear nat44 sessions
+ * @cliexend
+?*/
+VLIB_CLI_COMMAND (nat44_clear_sessions_command, static) = {
+ .path = "clear nat44 sessions",
+ .short_help = "clear nat44 sessions",
+ .function = nat44_clear_sessions_command_fn,
+};
+
+/*?
+ * @cliexpar
* @cliexstart{nat44 del session}
* To administratively delete NAT44 session by inside address and port use:
* vpp# nat44 del session in 10.0.0.3:6303 tcp