1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright(c) 2023 Cisco Systems, Inc.
6 #include <vnet/feature/feature.h>
7 #include <vnet/ip/ip.h>
8 #include <vppinfra/clib_error.h>
12 set_npt66_binding_command_fn (vlib_main_t *vm, unformat_input_t *input,
13 vlib_cli_command_t *cmd)
15 unformat_input_t _line_input, *line_input = &_line_input;
16 clib_error_t *error = 0;
17 bool internal_set = false, external_set = false;
20 ip6_address_t internal, external;
21 int internal_plen = 0, external_plen = 0;
23 /* Get a line of input. */
24 if (!unformat_user (input, unformat_line_input, line_input))
27 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
29 if (unformat (line_input, "internal %U/%d", unformat_ip6_address,
30 &internal, &internal_plen))
32 else if (unformat (line_input, "external %U/%d", unformat_ip6_address,
33 &external, &external_plen))
35 else if (unformat (line_input, "interface %U",
36 unformat_vnet_sw_interface, vnet_get_main (),
39 else if (unformat (line_input, "del"))
45 error = clib_error_return (0, "unknown input `%U'",
46 format_unformat_error, line_input);
50 if (sw_if_index == ~0)
52 error = clib_error_return (0, "interface is required `%U'",
53 format_unformat_error, line_input);
58 error = clib_error_return (0, "missing parameter: internal `%U'",
59 format_unformat_error, line_input);
64 error = clib_error_return (0, "missing parameter: external `%U'",
65 format_unformat_error, line_input);
69 int rv = npt66_binding_add_del (sw_if_index, &internal, internal_plen,
70 &external, external_plen, add);
73 error = clib_error_return (0, "Adding binding failed %d", rv);
78 unformat_free (line_input);
83 VLIB_CLI_COMMAND (set_npt66_binding_command, static) = {
84 .path = "set npt66 binding",
85 .short_help = "set npt66 binding interface <name> internal <pfx> "
86 "external <pfx> [del]",
87 .function = set_npt66_binding_command_fn,
91 format_npt66_binding (u8 *s, va_list *args)
93 u32 index = va_arg (*args, u32);
94 npt66_binding_t *b = va_arg (*args, npt66_binding_t *);
95 s = format (s, "[%d] internal: %U/%d external: %U/%d", index,
96 format_ip6_address, &b->internal, b->internal_plen,
97 format_ip6_address, &b->external, b->external_plen);
101 static clib_error_t *
102 show_npt66_bindings_command_fn (vlib_main_t *vm, unformat_input_t *input,
103 vlib_cli_command_t *cmd)
105 npt66_main_t *nm = &npt66_main;
107 clib_error_t *error = 0;
109 /* Get a line of input. */
110 pool_foreach (b, nm->bindings)
112 vlib_cli_output (vm, "%U", format_npt66_binding, b - nm->bindings, b);
117 VLIB_CLI_COMMAND (show_npt66_bindings_command, static) = {
118 .path = "show npt66 bindings",
119 .short_help = "show npt66 bindings",
120 .function = show_npt66_bindings_command_fn,