-static clib_error_t *
-nat44_det_show_sessions_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- snat_main_t *sm = &snat_main;
- snat_det_map_t *dm;
- snat_det_session_t *ses;
- int i;
-
- if (!sm->deterministic)
- return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
-
- vlib_cli_output (vm, "NAT44 deterministic sessions:");
- /* *INDENT-OFF* */
- pool_foreach (dm, sm->det_maps,
- ({
- vec_foreach_index (i, dm->sessions)
- {
- ses = vec_elt_at_index (dm->sessions, i);
- if (ses->in_port)
- vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
- }
- }));
- /* *INDENT-ON* */
- return 0;
-}
-
-static clib_error_t *
-snat_det_close_session_out_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 out_addr, ext_addr, in_addr;
- u32 out_port, ext_port;
- snat_det_map_t *dm;
- snat_det_session_t *ses;
- snat_det_out_key_t key;
- clib_error_t *error = 0;
-
- if (!sm->deterministic)
- return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
-
- /* 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 %U:%d",
- unformat_ip4_address, &out_addr, &out_port,
- unformat_ip4_address, &ext_addr, &ext_port))
- ;
- else
- {
- error = clib_error_return (0, "unknown input '%U'",
- format_unformat_error, line_input);
- goto done;
- }
- }
-
- unformat_free (line_input);
-
- dm = snat_det_map_by_out (sm, &out_addr);
- if (!dm)
- vlib_cli_output (vm, "no match");
- else
- {
- snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
- key.ext_host_addr = out_addr;
- key.ext_host_port = ntohs ((u16) ext_port);
- key.out_port = ntohs ((u16) out_port);
- ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
- if (!ses)
- vlib_cli_output (vm, "no match");
- else
- snat_det_ses_close (dm, ses);
- }
-
-done:
- unformat_free (line_input);
-
- return error;
-}
-
-static clib_error_t *
-snat_det_close_session_in_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, ext_addr;
- u32 in_port, ext_port;
- snat_det_map_t *dm;
- snat_det_session_t *ses;
- snat_det_out_key_t key;
- clib_error_t *error = 0;
-
- if (!sm->deterministic)
- return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
-
- /* 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 %U:%d",
- unformat_ip4_address, &in_addr, &in_port,
- unformat_ip4_address, &ext_addr, &ext_port))
- ;
- else
- {
- error = clib_error_return (0, "unknown input '%U'",
- format_unformat_error, line_input);
- goto done;
- }
- }
-
- unformat_free (line_input);
-
- dm = snat_det_map_by_user (sm, &in_addr);
- if (!dm)
- vlib_cli_output (vm, "no match");
- else
- {
- key.ext_host_addr = ext_addr;
- key.ext_host_port = ntohs ((u16) ext_port);
- ses =
- snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
- if (!ses)
- vlib_cli_output (vm, "no match");
- else
- snat_det_ses_close (dm, ses);
- }
-
-done:
- unformat_free (line_input);
-
- return error;
-}