-static clib_error_t *
-nat44_del_session_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- snat_main_t *sm = &snat_main;
- unformat_input_t _line_input, *line_input = &_line_input;
- int is_in = 0;
- clib_error_t *error = 0;
- ip4_address_t addr;
- u32 port = 0, vrf_id = sm->outside_vrf_id;
- snat_protocol_t proto;
- int rv;
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
- unformat_snat_protocol, &proto))
- ;
- else if (unformat (line_input, "in"))
- {
- is_in = 1;
- vrf_id = sm->inside_vrf_id;
- }
- else if (unformat (line_input, "vrf %u", &vrf_id))
- ;
- else
- {
- error = clib_error_return (0, "unknown input '%U'",
- format_unformat_error, line_input);
- goto done;
- }
- }
-
- rv = nat44_del_session(sm, &addr, port, proto, vrf_id, is_in);
-
- switch (rv)
- {
- case 0:
- break;
-
- default:
- error = clib_error_return (0, "nat44_del_session returned %d", rv);
- goto done;
- }
-
-done:
- unformat_free (line_input);
-
- return error;
-}
-
-VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
- .path = "nat44 del session",
- .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>]",
- .function = nat44_del_session_command_fn,
-};
-
-static clib_error_t *
-nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- snat_main_t *sm = &snat_main;
- unformat_input_t _line_input, *line_input = &_line_input;
- clib_error_t *error = 0;
- u32 psid, psid_offset, psid_length;
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "default"))
- sm->alloc_addr_and_port = nat_alloc_addr_and_port_default;
- else if (unformat (line_input, "map-e psid %d psid-offset %d psid-len %d",
- &psid, &psid_offset, &psid_length))
- {
- sm->alloc_addr_and_port = nat_alloc_addr_and_port_mape;
- sm->psid = (u16) psid;
- sm->psid_offset = (u16) psid_offset;
- sm->psid_length = (u16) psid_length;
- }
- else
- {
- error = clib_error_return (0, "unknown input '%U'",
- format_unformat_error, line_input);
- goto done;
- }
- }
-
-done:
- unformat_free (line_input);
-
- return error;
-};
-
-VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
- .path = "nat addr-port-assignment-alg",
- .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
- .function = nat44_set_alloc_addr_and_port_alg_command_fn,
-};
-
-static clib_error_t *
-snat_det_map_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- snat_main_t *sm = &snat_main;
- unformat_input_t _line_input, *line_input = &_line_input;
- ip4_address_t in_addr, out_addr;
- u32 in_plen, out_plen;
- int is_add = 1, rv;
- clib_error_t *error = 0;
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
- ;
- else if (unformat (line_input, "out %U/%u", unformat_ip4_address, &out_addr, &out_plen))
- ;
- else if (unformat (line_input, "del"))
- is_add = 0;
- else
- {
- error = clib_error_return (0, "unknown input '%U'",
- format_unformat_error, line_input);
- goto done;
- }
- }
-
- rv = snat_det_add_map(sm, &in_addr, (u8) in_plen, &out_addr, (u8)out_plen,
- is_add);
-
- if (rv)
- {
- error = clib_error_return (0, "snat_det_add_map return %d", rv);
- goto done;
- }
-
-done:
- unformat_free (line_input);
-
- return error;
-}
-
-/*?
- * @cliexpar
- * @cliexstart{snat deterministic add}
- * Create bijective mapping of inside address to outside address and port range
- * pairs, with the purpose of enabling deterministic NAT to reduce logging in
- * CGN deployments.
- * To create deterministic mapping between inside network 10.0.0.0/18 and
- * outside network 1.1.1.0/30 use:
- * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
- * @cliexend
-?*/
-VLIB_CLI_COMMAND (snat_det_map_command, static) = {
- .path = "nat44 deterministic add",
- .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
- .function = snat_det_map_command_fn,
-};
-
-static clib_error_t *
-snat_det_forward_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- snat_main_t *sm = &snat_main;
- unformat_input_t _line_input, *line_input = &_line_input;
- ip4_address_t in_addr, out_addr;
- u16 lo_port;
- snat_det_map_t * dm;
- clib_error_t *error = 0;
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
- ;
- else
- {
- error = clib_error_return (0, "unknown input '%U'",
- format_unformat_error, line_input);
- goto done;
- }
- }
-
- dm = snat_det_map_by_user(sm, &in_addr);
- if (!dm)
- vlib_cli_output (vm, "no match");
- else
- {
- snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
- vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
- lo_port, lo_port + dm->ports_per_host - 1);
- }
-
-done:
- unformat_free (line_input);
-
- return error;
-}
-
-/*?
- * @cliexpar
- * @cliexstart{snat deterministic forward}
- * Return outside address and port range from inside address for deterministic
- * NAT.
- * To obtain outside address and port of inside host use:
- * vpp# nat44 deterministic forward 10.0.0.2
- * 1.1.1.0:<1054-1068>
- * @cliexend
-?*/
-VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
- .path = "nat44 deterministic forward",
- .short_help = "nat44 deterministic forward <addr>",
- .function = snat_det_forward_command_fn,
-};
-
-static clib_error_t *
-snat_det_reverse_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- snat_main_t *sm = &snat_main;
- unformat_input_t _line_input, *line_input = &_line_input;
- ip4_address_t in_addr, out_addr;
- u32 out_port;
- snat_det_map_t * dm;
- clib_error_t *error = 0;
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
- ;
- else
- {
- error = clib_error_return (0, "unknown input '%U'",
- format_unformat_error, line_input);
- }
- }
-
- if (out_port < 1024 || out_port > 65535)
- {
- error = clib_error_return (0, "wrong port, must be <1024-65535>");
- goto done;
- }
-
- dm = snat_det_map_by_out(sm, &out_addr);
- if (!dm)
- vlib_cli_output (vm, "no match");
- else
- {
- snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
- vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
- }
-
-done:
- unformat_free (line_input);
-
- return error;
-}
-
-/*?
- * @cliexpar
- * @cliexstart{snat deterministic reverse}
- * Return inside address from outside address and port for deterministic NAT.
- * To obtain inside host address from outside address and port use:
- * #vpp nat44 deterministic reverse 1.1.1.1:1276
- * 10.0.16.16
- * @cliexend
-?*/
-VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
- .path = "nat44 deterministic reverse",
- .short_help = "nat44 deterministic reverse <addr>:<port>",
- .function = snat_det_reverse_command_fn,
-};
-
-static clib_error_t *
-set_timeout_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- snat_main_t *sm = &snat_main;
- unformat_input_t _line_input, *line_input = &_line_input;
- clib_error_t *error = 0;
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "udp %u", &sm->udp_timeout))
- ;
- else if (unformat (line_input, "tcp-established %u",
- &sm->tcp_established_timeout))
- ;
- else if (unformat (line_input, "tcp-transitory %u",
- &sm->tcp_transitory_timeout))
- ;
- else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
- ;
- else if (unformat (line_input, "reset"))
- {
- sm->udp_timeout = SNAT_UDP_TIMEOUT;
- sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
- sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
- sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
- }
- else
- {
- error = clib_error_return (0, "unknown input '%U'",
- format_unformat_error, line_input);
- goto done;
- }
- }
-
-done:
- unformat_free (line_input);
-
- return error;
-}
-
-/*?
- * @cliexpar
- * @cliexstart{set snat deterministic timeout}
- * Set values of timeouts for deterministic NAT (in seconds), use:
- * vpp# set nat44 deterministic timeout udp 120 tcp-established 7500
- * tcp-transitory 250 icmp 90
- * To reset default values use:
- * vpp# set nat44 deterministic timeout reset
- * @cliexend
-?*/
-VLIB_CLI_COMMAND (set_timeout_command, static) = {
- .path = "set nat44 deterministic timeout",
- .function = set_timeout_command_fn,
- .short_help =
- "set nat44 deterministic timeout [udp <sec> | tcp-established <sec> "
- "tcp-transitory <sec> | icmp <sec> | reset]",
-};
-
-static clib_error_t *
-snat_det_close_session_out_fn (vlib_main_t *vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)