aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/nat/det44/det44_cli.c28
-rw-r--r--src/plugins/nat/dslite/dslite_cli.c8
-rw-r--r--src/plugins/nat/nat64/nat64_cli.c18
-rw-r--r--src/plugins/nat/nat66/nat66_cli.c131
4 files changed, 92 insertions, 93 deletions
diff --git a/src/plugins/nat/det44/det44_cli.c b/src/plugins/nat/det44/det44_cli.c
index 28569c7b82d..5bd81d306f4 100644
--- a/src/plugins/nat/det44/det44_cli.c
+++ b/src/plugins/nat/det44/det44_cli.c
@@ -18,6 +18,8 @@
*/
#include <nat/det44/det44.h>
+#define DET44_EXPECTED_ARGUMENT "expected required argument(s)"
+
static clib_error_t *
det44_map_command_fn (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_command_t * cmd)
@@ -29,7 +31,7 @@ det44_map_command_fn (vlib_main_t * vm, unformat_input_t * input,
clib_error_t *error = 0;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DET44_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -74,7 +76,6 @@ det44_show_mappings_command_fn (vlib_main_t * vm,
det44_main_t *dm = &det44_main;
snat_det_map_t *mp;
vlib_cli_output (vm, "NAT44 deterministic mappings:");
- /* *INDENT-OFF* */
pool_foreach (mp, dm->det_maps)
{
vlib_cli_output (vm, " in %U/%d out %U/%d\n",
@@ -86,7 +87,6 @@ det44_show_mappings_command_fn (vlib_main_t * vm,
mp->ports_per_host);
vlib_cli_output (vm, " sessions number: %d\n", mp->ses_num);
}
- /* *INDENT-ON* */
return 0;
}
@@ -101,7 +101,7 @@ det44_forward_command_fn (vlib_main_t * vm,
clib_error_t *error = 0;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DET44_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -142,7 +142,7 @@ det44_reverse_command_fn (vlib_main_t * vm,
u32 out_port;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DET44_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -187,7 +187,6 @@ det44_show_sessions_command_fn (vlib_main_t * vm,
snat_det_session_t *ses;
snat_det_map_t *mp;
vlib_cli_output (vm, "NAT44 deterministic sessions:");
- /* *INDENT-OFF* */
pool_foreach (mp, dm->det_maps)
{
int i;
@@ -198,7 +197,6 @@ det44_show_sessions_command_fn (vlib_main_t * vm,
vlib_cli_output (vm, " %U", format_det_map_ses, mp, ses, &i);
}
}
- /* *INDENT-ON* */
return 0;
}
@@ -216,7 +214,7 @@ det44_close_session_out_fn (vlib_main_t * vm,
clib_error_t *error = 0;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DET44_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -269,7 +267,7 @@ det44_close_session_in_fn (vlib_main_t * vm,
clib_error_t *error = 0;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DET44_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -319,7 +317,7 @@ det44_set_timeouts_command_fn (vlib_main_t * vm,
u8 reset = 0;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DET44_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -380,7 +378,7 @@ det44_plugin_enable_disable_command_fn (vlib_main_t * vm,
det44_config_t c = { 0 };
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DET44_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -432,7 +430,7 @@ det44_feature_command_fn (vlib_main_t * vm,
u8 is_del = 0;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DET44_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -458,7 +456,6 @@ det44_feature_command_fn (vlib_main_t * vm,
}
}
- /* *INDENT-OFF* */
vec_foreach (p, sw_if_indices)
{
if (det44_interface_add_del (p->sw_if_index, p->is_inside, is_del))
@@ -471,7 +468,6 @@ det44_feature_command_fn (vlib_main_t * vm,
break;
}
}
- /* *INDENT-ON* */
done:
unformat_free (line_input);
vec_free (sw_if_indices);
@@ -486,7 +482,6 @@ det44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
det44_main_t *dm = &det44_main;
det44_interface_t *i;
vlib_cli_output (vm, "DET44 interfaces:");
- /* *INDENT-OFF* */
pool_foreach (i, dm->interfaces)
{
vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
@@ -495,11 +490,9 @@ det44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
det44_interface_is_outside(i)) ? "in out" :
(det44_interface_is_inside(i) ? "in" : "out"));
}
- /* *INDENT-ON* */
return 0;
}
-/* *INDENT-OFF* */
/*?
* @cliexpar
* @cliexstart{det44 add}
@@ -693,7 +686,6 @@ VLIB_CLI_COMMAND (det44_show_interfaces_command, static) =
.short_help = "show det44 interfaces",
.function = det44_show_interfaces_command_fn,
};
-/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
diff --git a/src/plugins/nat/dslite/dslite_cli.c b/src/plugins/nat/dslite/dslite_cli.c
index 0537957930c..193cb3fe248 100644
--- a/src/plugins/nat/dslite/dslite_cli.c
+++ b/src/plugins/nat/dslite/dslite_cli.c
@@ -14,6 +14,8 @@
*/
#include <nat/dslite/dslite.h>
+#define DSLITE_EXPECTED_ARGUMENT "expected required argument(s)"
+
static clib_error_t *
dslite_add_del_pool_addr_command_fn (vlib_main_t * vm,
unformat_input_t * input,
@@ -29,7 +31,7 @@ dslite_add_del_pool_addr_command_fn (vlib_main_t * vm,
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DSLITE_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -115,7 +117,7 @@ dslite_set_aftr_tunnel_addr_command_fn (vlib_main_t * vm,
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DSLITE_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -166,7 +168,7 @@ dslite_set_b4_tunnel_addr_command_fn (vlib_main_t * vm,
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, DSLITE_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
diff --git a/src/plugins/nat/nat64/nat64_cli.c b/src/plugins/nat/nat64/nat64_cli.c
index a7dd9ab9147..3af715c2457 100644
--- a/src/plugins/nat/nat64/nat64_cli.c
+++ b/src/plugins/nat/nat64/nat64_cli.c
@@ -16,6 +16,8 @@
#include <vnet/fib/fib_table.h>
#include <nat/nat64/nat64.h>
+#define NAT64_EXPECTED_ARGUMENT "expected required argument(s)"
+
static clib_error_t *
nat64_plugin_enable_disable_command_fn (vlib_main_t * vm,
unformat_input_t * input,
@@ -27,7 +29,7 @@ nat64_plugin_enable_disable_command_fn (vlib_main_t * vm,
nat64_config_t c = { 0 };
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT64_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -79,7 +81,7 @@ nat64_add_del_pool_addr_command_fn (vlib_main_t * vm,
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT64_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -193,7 +195,7 @@ nat64_interface_feature_command_fn (vlib_main_t * vm,
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT64_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -335,7 +337,7 @@ nat64_add_del_static_bib_command_fn (vlib_main_t *
int rv;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT64_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -462,7 +464,7 @@ nat64_show_bib_command_fn (vlib_main_t * vm,
nat64_db_t *db;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT64_EXPECTED_ARGUMENT);
if (unformat (line_input, "%U", unformat_nat_protocol, &proto))
p = nat_proto_to_ip_proto (proto);
@@ -565,7 +567,7 @@ nat64_show_st_command_fn (vlib_main_t * vm,
};
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT64_EXPECTED_ARGUMENT);
if (unformat (line_input, "%U", unformat_nat_protocol, &proto))
p = nat_proto_to_ip_proto (proto);
@@ -613,7 +615,7 @@ nat64_add_del_prefix_command_fn (vlib_main_t * vm, unformat_input_t * input,
int rv;
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT64_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -737,7 +739,7 @@ nat64_add_interface_address_command_fn (vlib_main_t * vm,
/* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT64_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
diff --git a/src/plugins/nat/nat66/nat66_cli.c b/src/plugins/nat/nat66/nat66_cli.c
index 4ba46cb0b75..0ca40875584 100644
--- a/src/plugins/nat/nat66/nat66_cli.c
+++ b/src/plugins/nat/nat66/nat66_cli.c
@@ -20,30 +20,45 @@
#include <nat/nat66/nat66.h>
#include <vnet/fib/fib_table.h>
+#define NAT66_EXPECTED_ARGUMENT "expected required argument(s)"
+#define NAT66_PLUGIN_DISABLED "error plugin disabled"
+
+#define CHECK_ENABLED() \
+ do \
+ { \
+ if (PREDICT_FALSE (!nat66_main.enabled)) \
+ { \
+ return clib_error_return (0, NAT66_PLUGIN_DISABLED); \
+ } \
+ } \
+ while (0)
+
static clib_error_t *
-nat66_enable_command_fn (vlib_main_t *vm, unformat_input_t *input,
- vlib_cli_command_t *cmd)
+nat66_enable_disable_command_fn (vlib_main_t *vm, unformat_input_t *input,
+ vlib_cli_command_t *cmd)
{
nat66_main_t *nm = &nat66_main;
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error = 0;
- u32 outside_vrf = 0;
- if (nm->enabled)
- return clib_error_return (0, "nat66 already enabled");
+ u32 outside_vrf = 0;
+ u8 enable_set = 0, enable = 0;
- /* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- {
- if (nat66_plugin_enable (outside_vrf) != 0)
- return clib_error_return (0, "nat66 enable failed");
- return 0;
- }
+ return clib_error_return (0, NAT66_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "outside-vrf %u", &outside_vrf))
;
+ else if (!enable_set)
+ {
+ enable_set = 1;
+ if (unformat (line_input, "disable"))
+ ;
+ else if (unformat (line_input, "enable"))
+ enable = 1;
+ }
else
{
error = clib_error_return (0, "unknown input '%U'",
@@ -52,26 +67,37 @@ nat66_enable_command_fn (vlib_main_t *vm, unformat_input_t *input,
}
}
- if (nat66_plugin_enable (outside_vrf) != 0)
- error = clib_error_return (0, "nat66 enable failed");
-done:
- unformat_free (line_input);
- return error;
-}
+ if (!enable_set)
+ {
+ error = clib_error_return (0, "expected enable | disable");
+ goto done;
+ }
-static clib_error_t *
-nat66_disable_command_fn (vlib_main_t *vm, unformat_input_t *input,
- vlib_cli_command_t *cmd)
-{
- nat66_main_t *nm = &nat66_main;
- clib_error_t *error = 0;
+ if (enable)
+ {
+ if (nm->enabled)
+ {
+ error = clib_error_return (0, "already enabled");
+ goto done;
+ }
- if (!nm->enabled)
- return clib_error_return (0, "nat66 already disabled");
+ if (nat66_plugin_enable (outside_vrf) != 0)
+ error = clib_error_return (0, "enable failed");
+ }
+ else
+ {
+ if (!nm->enabled)
+ {
+ error = clib_error_return (0, "already disabled");
+ goto done;
+ }
- if (nat66_plugin_disable () != 0)
- error = clib_error_return (0, "nat66 disable failed");
+ if (nat66_plugin_disable () != 0)
+ error = clib_error_return (0, "disable failed");
+ }
+done:
+ unformat_free (line_input);
return error;
}
@@ -82,7 +108,6 @@ nat66_interface_feature_command_fn (vlib_main_t * vm,
{
unformat_input_t _line_input, *line_input = &_line_input;
vnet_main_t *vnm = vnet_get_main ();
- nat66_main_t *nm = &nat66_main;
clib_error_t *error = 0;
u32 sw_if_index;
u32 *inside_sw_if_indices = 0;
@@ -90,12 +115,10 @@ nat66_interface_feature_command_fn (vlib_main_t * vm,
u8 is_add = 1;
int i, rv;
- if (!nm->enabled)
- return clib_error_return (0, "nat66 disabled");
+ CHECK_ENABLED ();
- /* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT66_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -208,9 +231,7 @@ static clib_error_t *
nat66_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_command_t * cmd)
{
- nat66_main_t *nm = &nat66_main;
- if (!nm->enabled)
- return clib_error_return (0, "nat66 disabled");
+ CHECK_ENABLED ();
vlib_cli_output (vm, "NAT66 interfaces:");
nat66_interfaces_walk (nat66_cli_interface_walk, vm);
return 0;
@@ -221,20 +242,17 @@ nat66_add_del_static_mapping_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
- nat66_main_t *nm = &nat66_main;
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error = 0;
- u8 is_add = 1;
ip6_address_t l_addr, e_addr;
u32 vrf_id = 0;
+ u8 is_add = 1;
int rv;
- if (!nm->enabled)
- return clib_error_return (0, "nat66 disabled");
+ CHECK_ENABLED ();
- /* Get a line of input. */
if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
+ return clib_error_return (0, NAT66_EXPECTED_ARGUMENT);
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
@@ -302,9 +320,7 @@ nat66_show_static_mappings_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
- nat66_main_t *nm = &nat66_main;
- if (!nm->enabled)
- return clib_error_return (0, "nat66 disabled");
+ CHECK_ENABLED ();
vlib_cli_output (vm, "NAT66 static mappings:");
nat66_static_mappings_walk (nat66_cli_static_mapping_walk, vm);
return 0;
@@ -312,32 +328,19 @@ nat66_show_static_mappings_command_fn (vlib_main_t * vm,
/*?
* @cliexpar
- * @cliexstart{nat66 enable}
- * Enable NAT66 plugin
+ * @cliexstart{nat66}
* To enable NAT66 plugin
* vpp# nat66 enable
- * To enable NAT66 plugin with outside-vrf id 10
- * vpp# nat66 enable outside-vrf 10
- * @cliexend
-?*/
-VLIB_CLI_COMMAND (nat66_enable_command, static) = {
- .path = "nat66 enable",
- .short_help = "nat66 enable [outside-vrf <vrf-id>]",
- .function = nat66_enable_command_fn,
-};
-
-/*?
- * @cliexpar
- * @cliexstart{nat66 disable}
- * Disable NAT66 plugin
* To disable NAT66 plugin
* vpp# nat66 disable
+ * To enable NAT66 plugin with outside-vrf id 10
+ * vpp# nat66 enable outside-vrf 10
* @cliexend
?*/
-VLIB_CLI_COMMAND (nat66_disable_command, static) = {
- .path = "nat66 disable",
- .short_help = "nat66 disable",
- .function = nat66_disable_command_fn,
+VLIB_CLI_COMMAND (nat66_enable_disable_command, static) = {
+ .path = "nat66",
+ .short_help = "nat66 <enable [outside-vrf <vrf-id>]>|disable",
+ .function = nat66_enable_disable_command_fn,
};
/*?