diff options
author | 2021-02-25 12:06:11 +0100 | |
---|---|---|
committer | 2021-02-26 01:55:07 +0000 | |
commit | cc9a1a0d39f22f653801f5d08bfe4892325254b5 (patch) | |
tree | c19e3ebea400c7cba3009d8e31097e2c40dfad88 /src/plugins/cnat/cnat_snat.c | |
parent | 4d237874e5c9922330c62ac1b003a9a171c1bc3b (diff) |
cnat: add input feature node
This allows to configure nat on a per-interface basis. Special care must
be taken to ensure the configuration remains consistent.
Type: feature
Change-Id: I352b2dce182e09d30813ce958333bb1ff37d9b4e
Signed-off-by: Aloys Augustin <aloaugus@cisco.com>
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src/plugins/cnat/cnat_snat.c')
-rw-r--r-- | src/plugins/cnat/cnat_snat.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/plugins/cnat/cnat_snat.c b/src/plugins/cnat/cnat_snat.c index 68b2f2b11bf..b063715d585 100644 --- a/src/plugins/cnat/cnat_snat.c +++ b/src/plugins/cnat/cnat_snat.c @@ -17,6 +17,59 @@ #include <cnat/cnat_snat.h> #include <cnat/cnat_translation.h> +cnat_snat_policy_main_t cnat_snat_policy_main; + +void +cnat_set_snat_policy (cnat_snat_policy_t fp) +{ + cnat_snat_policy_main.snat_policy = fp; +} + +static clib_error_t * +cnat_snat_policy_cmd (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) +{ + cnat_snat_policy_t fp = NULL; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "none")) + ; + else + return clib_error_return (0, "unknown input '%U'", + format_unformat_error, input); + } + + cnat_set_snat_policy (fp); + return NULL; +} + +VLIB_CLI_COMMAND (cnat_snat_policy_command, static) = { + .path = "cnat set snat policy", + .short_help = "cnat set snat policy {none,k8s}", + .function = cnat_snat_policy_cmd, +}; + +static clib_error_t * +show_cnat_snat_policy_cmd (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) +{ + u8 *s = format (NULL, "snat policy: "); + if (cnat_snat_policy_main.snat_policy == NULL) + s = format (s, "none"); + else + s = format (s, "unknown (%x)", cnat_snat_policy_main.snat_policy); + + vlib_cli_output (vm, (char *) s); + return NULL; +} + +VLIB_CLI_COMMAND (show_cnat_snat_policy_command, static) = { + .path = "show cnat snat policy", + .short_help = "show cnat snat policy", + .function = show_cnat_snat_policy_cmd, +}; + static void cnat_compute_prefix_lengths_in_search_order (cnat_snat_pfx_table_t * table, ip_address_family_t af) |