2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 #include <nat/nat_ipfix_logging.h>
22 #include <nat/nat_det.h>
23 #include <nat/nat64.h>
24 #include <nat/nat_inlines.h>
25 #include <nat/nat44/inlines.h>
26 #include <nat/nat_affinity.h>
27 #include <vnet/fib/fib_table.h>
28 #include <nat/nat_ha.h>
30 #define UNSUPPORTED_IN_DET_MODE_STR \
31 "This command is unsupported in deterministic mode"
32 #define SUPPORTED_ONLY_IN_DET_MODE_STR \
33 "This command is supported only in deterministic mode"
36 set_workers_command_fn (vlib_main_t * vm,
37 unformat_input_t * input, vlib_cli_command_t * cmd)
39 unformat_input_t _line_input, *line_input = &_line_input;
40 snat_main_t *sm = &snat_main;
43 clib_error_t *error = 0;
45 if (sm->deterministic)
46 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
48 /* Get a line of input. */
49 if (!unformat_user (input, unformat_line_input, line_input))
52 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
54 if (unformat (line_input, "%U", unformat_bitmap_list, &bitmap))
58 error = clib_error_return (0, "unknown input '%U'",
59 format_unformat_error, line_input);
66 error = clib_error_return (0, "List of workers must be specified.");
70 rv = snat_set_workers (bitmap);
72 clib_bitmap_free (bitmap);
76 case VNET_API_ERROR_INVALID_WORKER:
77 error = clib_error_return (0, "Invalid worker(s).");
79 case VNET_API_ERROR_FEATURE_DISABLED:
80 error = clib_error_return (0,
81 "Supported only if 2 or more workes available.");
88 unformat_free (line_input);
94 nat_show_workers_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
95 vlib_cli_command_t * cmd)
97 snat_main_t *sm = &snat_main;
100 if (sm->deterministic)
101 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
103 if (sm->num_workers > 1)
105 vlib_cli_output (vm, "%d workers", vec_len (sm->workers));
107 vec_foreach (worker, sm->workers)
109 vlib_worker_thread_t *w =
110 vlib_worker_threads + *worker + sm->first_worker_index;
111 vlib_cli_output (vm, " %s", w->name);
119 static clib_error_t *
120 nat44_session_cleanup_command_fn (vlib_main_t * vm,
121 unformat_input_t * input,
122 vlib_cli_command_t * cmd)
124 clib_error_t *error = 0;
126 nat44_force_session_cleanup ();
131 static clib_error_t *
132 snat_set_log_level_command_fn (vlib_main_t * vm,
133 unformat_input_t * input,
134 vlib_cli_command_t * cmd)
136 unformat_input_t _line_input, *line_input = &_line_input;
137 snat_main_t *sm = &snat_main;
138 u8 log_level = SNAT_LOG_NONE;
139 clib_error_t *error = 0;
141 /* Get a line of input. */
142 if (!unformat_user (input, unformat_line_input, line_input))
145 if (!unformat (line_input, "%d", &log_level))
147 error = clib_error_return (0, "unknown input '%U'",
148 format_unformat_error, line_input);
151 if (log_level > SNAT_LOG_DEBUG)
153 error = clib_error_return (0, "unknown logging level '%d'", log_level);
156 sm->log_level = log_level;
159 unformat_free (line_input);
164 static clib_error_t *
165 snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm,
166 unformat_input_t * input,
167 vlib_cli_command_t * cmd)
169 unformat_input_t _line_input, *line_input = &_line_input;
174 clib_error_t *error = 0;
176 /* Get a line of input. */
177 if (!unformat_user (input, unformat_line_input, line_input))
179 rv = snat_ipfix_logging_enable_disable (enable, domain_id,
182 return clib_error_return (0, "ipfix logging enable failed");
186 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
188 if (unformat (line_input, "domain %d", &domain_id))
190 else if (unformat (line_input, "src-port %d", &src_port))
192 else if (unformat (line_input, "disable"))
196 error = clib_error_return (0, "unknown input '%U'",
197 format_unformat_error, line_input);
202 rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port);
206 error = clib_error_return (0, "ipfix logging enable failed");
211 unformat_free (line_input);
216 static clib_error_t *
217 nat44_show_hash_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
218 vlib_cli_command_t * cmd)
220 snat_main_t *sm = &snat_main;
221 snat_main_per_thread_data_t *tsm;
222 nat_affinity_main_t *nam = &nat_affinity_main;
226 if (unformat (input, "detail"))
228 else if (unformat (input, "verbose"))
231 vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
233 vlib_cli_output (vm, "%U",
234 format_bihash_8_8, &sm->static_mapping_by_external,
236 vec_foreach_index (i, sm->per_thread_data)
238 tsm = vec_elt_at_index (sm->per_thread_data, i);
239 vlib_cli_output (vm, "-------- thread %d %s --------\n",
240 i, vlib_worker_threads[i].name);
241 if (sm->endpoint_dependent)
243 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->in2out_ed,
245 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->out2in_ed,
250 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->in2out, verbose);
251 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->out2in, verbose);
253 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->user_hash, verbose);
256 if (sm->endpoint_dependent)
257 vlib_cli_output (vm, "%U", format_bihash_16_8, &nam->affinity_hash,
262 static clib_error_t *
263 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
264 unformat_input_t * input,
265 vlib_cli_command_t * cmd)
267 unformat_input_t _line_input, *line_input = &_line_input;
268 snat_main_t *sm = &snat_main;
269 clib_error_t *error = 0;
270 u32 psid, psid_offset, psid_length, port_start, port_end;
272 if (sm->deterministic)
273 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
275 /* Get a line of input. */
276 if (!unformat_user (input, unformat_line_input, line_input))
279 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
281 if (unformat (line_input, "default"))
282 nat_set_alloc_addr_and_port_default ();
285 (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
286 &psid_offset, &psid_length))
287 nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
291 (line_input, "port-range %d - %d", &port_start, &port_end))
293 if (port_end <= port_start)
296 clib_error_return (0,
297 "The end-port must be greater than start-port");
300 nat_set_alloc_addr_and_port_range ((u16) port_start,
305 error = clib_error_return (0, "unknown input '%U'",
306 format_unformat_error, line_input);
312 unformat_free (line_input);
317 static clib_error_t *
318 nat44_show_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
319 unformat_input_t * input,
320 vlib_cli_command_t * cmd)
322 snat_main_t *sm = &snat_main;
324 if (sm->deterministic)
325 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
327 vlib_cli_output (vm, "NAT address and port: %U",
328 format_nat_addr_and_port_alloc_alg,
329 sm->addr_and_port_alloc_alg);
330 switch (sm->addr_and_port_alloc_alg)
332 case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
333 vlib_cli_output (vm, " psid %d psid-offset %d psid-len %d", sm->psid,
334 sm->psid_offset, sm->psid_length);
336 case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
337 vlib_cli_output (vm, " start-port %d end-port %d", sm->start_port,
347 static clib_error_t *
348 nat_set_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
349 vlib_cli_command_t * cmd)
351 unformat_input_t _line_input, *line_input = &_line_input;
352 snat_main_t *sm = &snat_main;
353 clib_error_t *error = 0;
356 /* Get a line of input. */
357 if (!unformat_user (input, unformat_line_input, line_input))
360 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
362 if (unformat (line_input, "disable"))
363 sm->mss_clamping = 0;
364 else if (unformat (line_input, "%d", &mss))
366 sm->mss_clamping = (u16) mss;
367 sm->mss_value_net = clib_host_to_net_u16 (sm->mss_clamping);
371 error = clib_error_return (0, "unknown input '%U'",
372 format_unformat_error, line_input);
378 unformat_free (line_input);
383 static clib_error_t *
384 nat_show_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
385 vlib_cli_command_t * cmd)
387 snat_main_t *sm = &snat_main;
389 if (sm->mss_clamping)
390 vlib_cli_output (vm, "mss-clamping %d", sm->mss_clamping);
392 vlib_cli_output (vm, "mss-clamping disabled");
397 static clib_error_t *
398 nat_ha_failover_command_fn (vlib_main_t * vm, unformat_input_t * input,
399 vlib_cli_command_t * cmd)
401 unformat_input_t _line_input, *line_input = &_line_input;
403 u32 port, session_refresh_interval = 10;
405 clib_error_t *error = 0;
407 /* Get a line of input. */
408 if (!unformat_user (input, unformat_line_input, line_input))
411 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
413 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
417 (line_input, "refresh-interval %u", &session_refresh_interval))
421 error = clib_error_return (0, "unknown input '%U'",
422 format_unformat_error, line_input);
427 rv = nat_ha_set_failover (&addr, (u16) port, session_refresh_interval);
429 error = clib_error_return (0, "set HA failover failed");
432 unformat_free (line_input);
437 static clib_error_t *
438 nat_ha_listener_command_fn (vlib_main_t * vm, unformat_input_t * input,
439 vlib_cli_command_t * cmd)
441 unformat_input_t _line_input, *line_input = &_line_input;
443 u32 port, path_mtu = 512;
445 clib_error_t *error = 0;
447 /* Get a line of input. */
448 if (!unformat_user (input, unformat_line_input, line_input))
451 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
453 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
455 else if (unformat (line_input, "path-mtu %u", &path_mtu))
459 error = clib_error_return (0, "unknown input '%U'",
460 format_unformat_error, line_input);
465 rv = nat_ha_set_listener (&addr, (u16) port, path_mtu);
467 error = clib_error_return (0, "set HA listener failed");
470 unformat_free (line_input);
475 static clib_error_t *
476 nat_show_ha_command_fn (vlib_main_t * vm, unformat_input_t * input,
477 vlib_cli_command_t * cmd)
481 u32 path_mtu, session_refresh_interval, resync_ack_missed;
484 nat_ha_get_listener (&addr, &port, &path_mtu);
487 vlib_cli_output (vm, "NAT HA disabled\n");
491 vlib_cli_output (vm, "LISTENER:\n");
492 vlib_cli_output (vm, " %U:%u path-mtu %u\n",
493 format_ip4_address, &addr, port, path_mtu);
495 nat_ha_get_failover (&addr, &port, &session_refresh_interval);
496 vlib_cli_output (vm, "FAILOVER:\n");
498 vlib_cli_output (vm, " %U:%u refresh-interval %usec\n",
499 format_ip4_address, &addr, port,
500 session_refresh_interval);
502 vlib_cli_output (vm, " NA\n");
504 nat_ha_get_resync_status (&in_resync, &resync_ack_missed);
505 vlib_cli_output (vm, "RESYNC:\n");
507 vlib_cli_output (vm, " in progress\n");
509 vlib_cli_output (vm, " completed (%d ACK missed)\n", resync_ack_missed);
514 static clib_error_t *
515 nat_ha_flush_command_fn (vlib_main_t * vm, unformat_input_t * input,
516 vlib_cli_command_t * cmd)
522 static clib_error_t *
523 nat_ha_resync_command_fn (vlib_main_t * vm, unformat_input_t * input,
524 vlib_cli_command_t * cmd)
526 clib_error_t *error = 0;
528 if (nat_ha_resync (0, 0, 0))
529 error = clib_error_return (0, "NAT HA resync already running");
534 static clib_error_t *
535 add_address_command_fn (vlib_main_t * vm,
536 unformat_input_t * input, vlib_cli_command_t * cmd)
538 unformat_input_t _line_input, *line_input = &_line_input;
539 snat_main_t *sm = &snat_main;
540 ip4_address_t start_addr, end_addr, this_addr;
541 u32 start_host_order, end_host_order;
546 clib_error_t *error = 0;
549 if (sm->deterministic)
550 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
552 /* Get a line of input. */
553 if (!unformat_user (input, unformat_line_input, line_input))
556 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
558 if (unformat (line_input, "%U - %U",
559 unformat_ip4_address, &start_addr,
560 unformat_ip4_address, &end_addr))
562 else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
564 else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
565 end_addr = start_addr;
566 else if (unformat (line_input, "twice-nat"))
568 else if (unformat (line_input, "del"))
572 error = clib_error_return (0, "unknown input '%U'",
573 format_unformat_error, line_input);
578 if (sm->static_mapping_only)
580 error = clib_error_return (0, "static mapping only mode");
584 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
585 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
587 if (end_host_order < start_host_order)
589 error = clib_error_return (0, "end address less than start address");
593 count = (end_host_order - start_host_order) + 1;
596 nat_log_info ("%U - %U, %d addresses...",
597 format_ip4_address, &start_addr,
598 format_ip4_address, &end_addr, count);
600 this_addr = start_addr;
602 for (i = 0; i < count; i++)
605 rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
607 rv = snat_del_address (sm, this_addr, 0, twice_nat);
611 case VNET_API_ERROR_VALUE_EXIST:
612 error = clib_error_return (0, "NAT address already in use.");
614 case VNET_API_ERROR_NO_SUCH_ENTRY:
615 error = clib_error_return (0, "NAT address not exist.");
617 case VNET_API_ERROR_UNSPECIFIED:
619 clib_error_return (0, "NAT address used in static mapping.");
621 case VNET_API_ERROR_FEATURE_DISABLED:
623 clib_error_return (0,
624 "twice NAT available only for endpoint-dependent mode.");
631 nat44_add_del_address_dpo (this_addr, is_add);
633 increment_v4_address (&this_addr);
637 unformat_free (line_input);
642 static clib_error_t *
643 nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
644 vlib_cli_command_t * cmd)
646 snat_main_per_thread_data_t *tsm;
647 snat_main_t *sm = &snat_main;
650 u32 free_ports, free_ports_addr;
652 if (sm->deterministic)
653 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
655 if (sm->endpoint_dependent)
656 vlib_cli_output (vm, "mode: endpoint-depenent");
659 vlib_cli_output (vm, "icmp timeout: %u", sm->icmp_timeout);
660 vlib_cli_output (vm, "udp timeout: %u", sm->udp_timeout);
662 vlib_cli_output (vm, "tcp established timeout: %u",
663 sm->tcp_established_timeout);
664 vlib_cli_output (vm, "tcp transitory timeout: %u",
665 sm->tcp_transitory_timeout);
667 // print session configuration values
668 vlib_cli_output (vm, "max translations: %u", sm->max_translations);
669 vlib_cli_output (vm, "max translations per user: %u",
670 sm->max_translations_per_user);
672 // do we need also twice-nat addresses ??
673 if (vec_len (sm->addresses))
677 vec_foreach (a, sm->addresses)
679 free_ports_addr = sm->port_per_thread;
681 #define _(N, i, n, s) \
682 free_ports_addr -= a->busy_##n##_ports;
683 foreach_snat_protocol
686 vlib_cli_output (vm, "addr: %U free ports: %u out of: %u",
687 format_ip4_address, &a->addr, free_ports_addr, sm->port_per_thread);
689 free_ports += free_ports_addr;
692 vlib_cli_output (vm, "free ports overall: %u out of: %u",
694 vec_len (sm->addresses) * sm->port_per_thread);
701 if (sm->num_workers > 1)
704 vec_foreach (tsm, sm->per_thread_data)
706 count += vec_len (tsm->sessions);
707 pool_foreach (s, tsm->sessions,
719 tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
721 pool_foreach (s, tsm->sessions,
729 count = vec_len (tsm->sessions);
731 vlib_cli_output (vm, "established sessions: %u", established);
732 vlib_cli_output (vm, "transitory sessions: %u", transitory);
733 vlib_cli_output (vm, "sessions: %u", count);
737 static clib_error_t *
738 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
739 vlib_cli_command_t * cmd)
741 snat_main_t *sm = &snat_main;
744 if (sm->deterministic)
745 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
747 vlib_cli_output (vm, "NAT44 pool addresses:");
749 vec_foreach (ap, sm->addresses)
751 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
752 if (ap->fib_index != ~0)
753 vlib_cli_output (vm, " tenant VRF: %u",
754 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
756 vlib_cli_output (vm, " tenant VRF independent");
757 #define _(N, i, n, s) \
758 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
759 foreach_snat_protocol
762 vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
763 vec_foreach (ap, sm->twice_nat_addresses)
765 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
766 if (ap->fib_index != ~0)
767 vlib_cli_output (vm, " tenant VRF: %u",
768 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
770 vlib_cli_output (vm, " tenant VRF independent");
771 #define _(N, i, n, s) \
772 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
773 foreach_snat_protocol
780 static clib_error_t *
781 snat_feature_command_fn (vlib_main_t * vm,
782 unformat_input_t * input, vlib_cli_command_t * cmd)
784 unformat_input_t _line_input, *line_input = &_line_input;
785 vnet_main_t *vnm = vnet_get_main ();
786 clib_error_t *error = 0;
788 u32 *inside_sw_if_indices = 0;
789 u32 *outside_sw_if_indices = 0;
790 u8 is_output_feature = 0;
796 /* Get a line of input. */
797 if (!unformat_user (input, unformat_line_input, line_input))
800 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
802 if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
804 vec_add1 (inside_sw_if_indices, sw_if_index);
805 else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
807 vec_add1 (outside_sw_if_indices, sw_if_index);
808 else if (unformat (line_input, "output-feature"))
809 is_output_feature = 1;
810 else if (unformat (line_input, "del"))
814 error = clib_error_return (0, "unknown input '%U'",
815 format_unformat_error, line_input);
820 if (vec_len (inside_sw_if_indices))
822 for (i = 0; i < vec_len (inside_sw_if_indices); i++)
824 sw_if_index = inside_sw_if_indices[i];
825 if (is_output_feature)
827 if (snat_interface_add_del_output_feature
828 (sw_if_index, 1, is_del))
830 error = clib_error_return (0, "%s %U failed",
831 is_del ? "del" : "add",
832 format_vnet_sw_if_index_name,
839 if (snat_interface_add_del (sw_if_index, 1, is_del))
841 error = clib_error_return (0, "%s %U failed",
842 is_del ? "del" : "add",
843 format_vnet_sw_if_index_name,
851 if (vec_len (outside_sw_if_indices))
853 for (i = 0; i < vec_len (outside_sw_if_indices); i++)
855 sw_if_index = outside_sw_if_indices[i];
856 if (is_output_feature)
858 if (snat_interface_add_del_output_feature
859 (sw_if_index, 0, is_del))
861 error = clib_error_return (0, "%s %U failed",
862 is_del ? "del" : "add",
863 format_vnet_sw_if_index_name,
870 if (snat_interface_add_del (sw_if_index, 0, is_del))
872 error = clib_error_return (0, "%s %U failed",
873 is_del ? "del" : "add",
874 format_vnet_sw_if_index_name,
883 unformat_free (line_input);
884 vec_free (inside_sw_if_indices);
885 vec_free (outside_sw_if_indices);
890 static clib_error_t *
891 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
892 vlib_cli_command_t * cmd)
894 snat_main_t *sm = &snat_main;
896 vnet_main_t *vnm = vnet_get_main ();
898 vlib_cli_output (vm, "NAT44 interfaces:");
900 pool_foreach (i, sm->interfaces,
902 vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
904 (nat_interface_is_inside(i) &&
905 nat_interface_is_outside(i)) ? "in out" :
906 (nat_interface_is_inside(i) ? "in" : "out"));
909 pool_foreach (i, sm->output_feature_interfaces,
911 vlib_cli_output (vm, " %U output-feature %s",
912 format_vnet_sw_if_index_name, vnm,
914 (nat_interface_is_inside(i) &&
915 nat_interface_is_outside(i)) ? "in out" :
916 (nat_interface_is_inside(i) ? "in" : "out"));
923 static clib_error_t *
924 add_static_mapping_command_fn (vlib_main_t * vm,
925 unformat_input_t * input,
926 vlib_cli_command_t * cmd)
928 unformat_input_t _line_input, *line_input = &_line_input;
929 snat_main_t *sm = &snat_main;
930 clib_error_t *error = 0;
931 ip4_address_t l_addr, e_addr;
932 u32 l_port = 0, e_port = 0, vrf_id = ~0;
935 u32 sw_if_index = ~0;
936 vnet_main_t *vnm = vnet_get_main ();
938 snat_protocol_t proto = ~0;
940 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
943 if (sm->deterministic)
944 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
946 /* Get a line of input. */
947 if (!unformat_user (input, unformat_line_input, line_input))
950 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
952 if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
956 if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
958 else if (unformat (line_input, "external %U %u", unformat_ip4_address,
961 else if (unformat (line_input, "external %U", unformat_ip4_address,
964 else if (unformat (line_input, "external %U %u",
965 unformat_vnet_sw_interface, vnm, &sw_if_index,
969 else if (unformat (line_input, "external %U",
970 unformat_vnet_sw_interface, vnm, &sw_if_index))
972 else if (unformat (line_input, "vrf %u", &vrf_id))
974 else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
976 else if (unformat (line_input, "twice-nat"))
977 twice_nat = TWICE_NAT;
978 else if (unformat (line_input, "self-twice-nat"))
979 twice_nat = TWICE_NAT_SELF;
980 else if (unformat (line_input, "out2in-only"))
982 else if (unformat (line_input, "del"))
986 error = clib_error_return (0, "unknown input: '%U'",
987 format_unformat_error, line_input);
992 if (twice_nat && addr_only)
994 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
998 if (!addr_only && !proto_set)
1000 error = clib_error_return (0, "missing protocol");
1004 rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
1005 vrf_id, addr_only, sw_if_index, proto, is_add,
1006 twice_nat, out2in_only, 0, 0);
1010 case VNET_API_ERROR_INVALID_VALUE:
1011 error = clib_error_return (0, "External port already in use.");
1013 case VNET_API_ERROR_NO_SUCH_ENTRY:
1015 error = clib_error_return (0, "External address must be allocated.");
1017 error = clib_error_return (0, "Mapping not exist.");
1019 case VNET_API_ERROR_NO_SUCH_FIB:
1020 error = clib_error_return (0, "No such VRF id.");
1022 case VNET_API_ERROR_VALUE_EXIST:
1023 error = clib_error_return (0, "Mapping already exist.");
1025 case VNET_API_ERROR_FEATURE_DISABLED:
1027 clib_error_return (0,
1028 "twice-nat/out2in-only available only for endpoint-dependent mode.");
1035 unformat_free (line_input);
1040 static clib_error_t *
1041 add_identity_mapping_command_fn (vlib_main_t * vm,
1042 unformat_input_t * input,
1043 vlib_cli_command_t * cmd)
1045 unformat_input_t _line_input, *line_input = &_line_input;
1046 snat_main_t *sm = &snat_main;
1047 clib_error_t *error = 0;
1049 u32 port = 0, vrf_id = ~0;
1052 u32 sw_if_index = ~0;
1053 vnet_main_t *vnm = vnet_get_main ();
1055 snat_protocol_t proto;
1057 if (sm->deterministic)
1058 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1062 /* Get a line of input. */
1063 if (!unformat_user (input, unformat_line_input, line_input))
1066 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1068 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1070 else if (unformat (line_input, "external %U",
1071 unformat_vnet_sw_interface, vnm, &sw_if_index))
1073 else if (unformat (line_input, "vrf %u", &vrf_id))
1075 else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
1078 else if (unformat (line_input, "del"))
1082 error = clib_error_return (0, "unknown input: '%U'",
1083 format_unformat_error, line_input);
1088 rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
1089 vrf_id, addr_only, sw_if_index, proto, is_add,
1094 case VNET_API_ERROR_INVALID_VALUE:
1095 error = clib_error_return (0, "External port already in use.");
1097 case VNET_API_ERROR_NO_SUCH_ENTRY:
1099 error = clib_error_return (0, "External address must be allocated.");
1101 error = clib_error_return (0, "Mapping not exist.");
1103 case VNET_API_ERROR_NO_SUCH_FIB:
1104 error = clib_error_return (0, "No such VRF id.");
1106 case VNET_API_ERROR_VALUE_EXIST:
1107 error = clib_error_return (0, "Mapping already exist.");
1114 unformat_free (line_input);
1119 static clib_error_t *
1120 add_lb_static_mapping_command_fn (vlib_main_t * vm,
1121 unformat_input_t * input,
1122 vlib_cli_command_t * cmd)
1124 unformat_input_t _line_input, *line_input = &_line_input;
1125 snat_main_t *sm = &snat_main;
1126 clib_error_t *error = 0;
1127 ip4_address_t l_addr, e_addr;
1128 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
1131 snat_protocol_t proto;
1133 nat44_lb_addr_port_t *locals = 0, local;
1134 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1137 if (sm->deterministic)
1138 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1140 /* Get a line of input. */
1141 if (!unformat_user (input, unformat_line_input, line_input))
1144 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1146 if (unformat (line_input, "local %U:%u probability %u",
1147 unformat_ip4_address, &l_addr, &l_port, &probability))
1149 clib_memset (&local, 0, sizeof (local));
1150 local.addr = l_addr;
1151 local.port = (u16) l_port;
1152 local.probability = (u8) probability;
1153 vec_add1 (locals, local);
1155 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1156 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1159 clib_memset (&local, 0, sizeof (local));
1160 local.addr = l_addr;
1161 local.port = (u16) l_port;
1162 local.probability = (u8) probability;
1163 local.vrf_id = vrf_id;
1164 vec_add1 (locals, local);
1166 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1169 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
1172 else if (unformat (line_input, "twice-nat"))
1173 twice_nat = TWICE_NAT;
1174 else if (unformat (line_input, "self-twice-nat"))
1175 twice_nat = TWICE_NAT_SELF;
1176 else if (unformat (line_input, "out2in-only"))
1178 else if (unformat (line_input, "del"))
1180 else if (unformat (line_input, "affinity %u", &affinity))
1184 error = clib_error_return (0, "unknown input: '%U'",
1185 format_unformat_error, line_input);
1190 if (vec_len (locals) < 2)
1192 error = clib_error_return (0, "at least two local must be set");
1198 error = clib_error_return (0, "missing protocol");
1202 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, locals,
1203 is_add, twice_nat, out2in_only, 0,
1208 case VNET_API_ERROR_INVALID_VALUE:
1209 error = clib_error_return (0, "External port already in use.");
1211 case VNET_API_ERROR_NO_SUCH_ENTRY:
1213 error = clib_error_return (0, "External address must be allocated.");
1215 error = clib_error_return (0, "Mapping not exist.");
1217 case VNET_API_ERROR_VALUE_EXIST:
1218 error = clib_error_return (0, "Mapping already exist.");
1220 case VNET_API_ERROR_FEATURE_DISABLED:
1222 clib_error_return (0, "Available only for endpoint-dependent mode.");
1229 unformat_free (line_input);
1235 static clib_error_t *
1236 add_lb_backend_command_fn (vlib_main_t * vm,
1237 unformat_input_t * input, vlib_cli_command_t * cmd)
1239 unformat_input_t _line_input, *line_input = &_line_input;
1240 snat_main_t *sm = &snat_main;
1241 clib_error_t *error = 0;
1242 ip4_address_t l_addr, e_addr;
1243 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
1246 snat_protocol_t proto;
1249 if (sm->deterministic)
1250 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1252 /* Get a line of input. */
1253 if (!unformat_user (input, unformat_line_input, line_input))
1256 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1258 if (unformat (line_input, "local %U:%u probability %u",
1259 unformat_ip4_address, &l_addr, &l_port, &probability))
1261 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1262 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1265 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1268 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
1271 else if (unformat (line_input, "del"))
1275 error = clib_error_return (0, "unknown input: '%U'",
1276 format_unformat_error, line_input);
1281 if (!l_port || !e_port)
1283 error = clib_error_return (0, "local or external must be set");
1289 error = clib_error_return (0, "missing protocol");
1294 nat44_lb_static_mapping_add_del_local (e_addr, (u16) e_port, l_addr,
1295 l_port, proto, vrf_id, probability,
1300 case VNET_API_ERROR_INVALID_VALUE:
1301 error = clib_error_return (0, "External is not load-balancing static "
1304 case VNET_API_ERROR_NO_SUCH_ENTRY:
1305 error = clib_error_return (0, "Mapping or back-end not exist.");
1307 case VNET_API_ERROR_VALUE_EXIST:
1308 error = clib_error_return (0, "Back-end already exist.");
1310 case VNET_API_ERROR_FEATURE_DISABLED:
1312 clib_error_return (0, "Available only for endpoint-dependent mode.");
1314 case VNET_API_ERROR_UNSPECIFIED:
1315 error = clib_error_return (0, "At least two back-ends must remain");
1322 unformat_free (line_input);
1327 static clib_error_t *
1328 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
1329 unformat_input_t * input,
1330 vlib_cli_command_t * cmd)
1332 snat_main_t *sm = &snat_main;
1333 snat_static_mapping_t *m;
1334 snat_static_map_resolve_t *rp;
1336 if (sm->deterministic)
1337 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1339 vlib_cli_output (vm, "NAT44 static mappings:");
1341 pool_foreach (m, sm->static_mappings,
1343 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
1345 vec_foreach (rp, sm->to_resolve)
1346 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
1352 static clib_error_t *
1353 snat_add_interface_address_command_fn (vlib_main_t * vm,
1354 unformat_input_t * input,
1355 vlib_cli_command_t * cmd)
1357 snat_main_t *sm = &snat_main;
1358 unformat_input_t _line_input, *line_input = &_line_input;
1362 clib_error_t *error = 0;
1365 if (sm->deterministic)
1366 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1368 /* Get a line of input. */
1369 if (!unformat_user (input, unformat_line_input, line_input))
1372 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1374 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
1375 sm->vnet_main, &sw_if_index))
1377 else if (unformat (line_input, "twice-nat"))
1379 else if (unformat (line_input, "del"))
1383 error = clib_error_return (0, "unknown input '%U'",
1384 format_unformat_error, line_input);
1389 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
1397 error = clib_error_return (0, "snat_add_interface_address returned %d",
1403 unformat_free (line_input);
1408 static clib_error_t *
1409 nat44_show_interface_address_command_fn (vlib_main_t * vm,
1410 unformat_input_t * input,
1411 vlib_cli_command_t * cmd)
1413 snat_main_t *sm = &snat_main;
1414 vnet_main_t *vnm = vnet_get_main ();
1417 if (sm->deterministic)
1418 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1421 vlib_cli_output (vm, "NAT44 pool address interfaces:");
1422 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
1424 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1427 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
1428 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
1430 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1438 static clib_error_t *
1439 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
1440 vlib_cli_command_t * cmd)
1443 snat_main_t *sm = &snat_main;
1444 snat_main_per_thread_data_t *tsm;
1448 if (sm->deterministic)
1449 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1451 if (unformat (input, "detail"))
1454 vlib_cli_output (vm, "NAT44 sessions:");
1457 vec_foreach_index (i, sm->per_thread_data)
1459 tsm = vec_elt_at_index (sm->per_thread_data, i);
1461 vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
1462 i, vlib_worker_threads[i].name,
1463 pool_elts (tsm->sessions));
1464 pool_foreach (u, tsm->users,
1466 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, verbose);
1474 static clib_error_t *
1475 nat44_del_user_command_fn (vlib_main_t * vm,
1476 unformat_input_t * input, vlib_cli_command_t * cmd)
1478 snat_main_t *sm = &snat_main;
1479 unformat_input_t _line_input, *line_input = &_line_input;
1480 clib_error_t *error = 0;
1485 if (sm->deterministic)
1486 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1488 /* Get a line of input. */
1489 if (!unformat_user (input, unformat_line_input, line_input))
1492 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1494 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1496 else if (unformat (line_input, "fib %u", &fib_index))
1500 error = clib_error_return (0, "unknown input '%U'",
1501 format_unformat_error, line_input);
1506 rv = nat44_user_del (&addr, fib_index);
1510 error = clib_error_return (0, "nat44_user_del returned %d", rv);
1514 unformat_free (line_input);
1519 static clib_error_t *
1520 nat44_del_session_command_fn (vlib_main_t * vm,
1521 unformat_input_t * input,
1522 vlib_cli_command_t * cmd)
1524 snat_main_t *sm = &snat_main;
1525 unformat_input_t _line_input, *line_input = &_line_input;
1526 int is_in = 0, is_ed = 0;
1527 clib_error_t *error = 0;
1528 ip4_address_t addr, eh_addr;
1529 u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
1530 snat_protocol_t proto;
1533 if (sm->deterministic)
1534 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1536 /* Get a line of input. */
1537 if (!unformat_user (input, unformat_line_input, line_input))
1540 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1543 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1544 unformat_snat_protocol, &proto))
1546 else if (unformat (line_input, "in"))
1549 vrf_id = sm->inside_vrf_id;
1551 else if (unformat (line_input, "out"))
1554 vrf_id = sm->outside_vrf_id;
1556 else if (unformat (line_input, "vrf %u", &vrf_id))
1560 (line_input, "external-host %U:%u", unformat_ip4_address,
1561 &eh_addr, &eh_port))
1565 error = clib_error_return (0, "unknown input '%U'",
1566 format_unformat_error, line_input);
1573 nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port,
1574 snat_proto_to_ip_proto (proto), vrf_id, is_in);
1576 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
1584 error = clib_error_return (0, "nat44_del_session returned %d", rv);
1589 unformat_free (line_input);
1594 static clib_error_t *
1595 snat_forwarding_set_command_fn (vlib_main_t * vm,
1596 unformat_input_t * input,
1597 vlib_cli_command_t * cmd)
1599 snat_main_t *sm = &snat_main;
1600 unformat_input_t _line_input, *line_input = &_line_input;
1601 u8 forwarding_enable;
1602 u8 forwarding_enable_set = 0;
1603 clib_error_t *error = 0;
1605 if (sm->deterministic)
1606 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1608 /* Get a line of input. */
1609 if (!unformat_user (input, unformat_line_input, line_input))
1610 return clib_error_return (0, "'enable' or 'disable' expected");
1612 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1614 if (!forwarding_enable_set && unformat (line_input, "enable"))
1616 forwarding_enable = 1;
1617 forwarding_enable_set = 1;
1619 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1621 forwarding_enable = 0;
1622 forwarding_enable_set = 1;
1626 error = clib_error_return (0, "unknown input '%U'",
1627 format_unformat_error, line_input);
1632 if (!forwarding_enable_set)
1634 error = clib_error_return (0, "'enable' or 'disable' expected");
1638 sm->forwarding_enabled = forwarding_enable;
1641 unformat_free (line_input);
1646 static clib_error_t *
1647 snat_det_map_command_fn (vlib_main_t * vm,
1648 unformat_input_t * input, vlib_cli_command_t * cmd)
1650 snat_main_t *sm = &snat_main;
1651 unformat_input_t _line_input, *line_input = &_line_input;
1652 ip4_address_t in_addr, out_addr;
1653 u32 in_plen, out_plen;
1655 clib_error_t *error = 0;
1657 if (!sm->deterministic)
1658 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1660 /* Get a line of input. */
1661 if (!unformat_user (input, unformat_line_input, line_input))
1664 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1667 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1671 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1674 else if (unformat (line_input, "del"))
1678 error = clib_error_return (0, "unknown input '%U'",
1679 format_unformat_error, line_input);
1684 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1689 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1694 unformat_free (line_input);
1699 static clib_error_t *
1700 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1701 unformat_input_t * input,
1702 vlib_cli_command_t * cmd)
1704 snat_main_t *sm = &snat_main;
1707 if (!sm->deterministic)
1708 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1710 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1712 pool_foreach (dm, sm->det_maps,
1714 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1715 format_ip4_address, &dm->in_addr, dm->in_plen,
1716 format_ip4_address, &dm->out_addr, dm->out_plen);
1717 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1719 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1720 dm->ports_per_host);
1721 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1728 static clib_error_t *
1729 snat_det_forward_command_fn (vlib_main_t * vm,
1730 unformat_input_t * input,
1731 vlib_cli_command_t * cmd)
1733 snat_main_t *sm = &snat_main;
1734 unformat_input_t _line_input, *line_input = &_line_input;
1735 ip4_address_t in_addr, out_addr;
1738 clib_error_t *error = 0;
1740 if (!sm->deterministic)
1741 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1743 /* Get a line of input. */
1744 if (!unformat_user (input, unformat_line_input, line_input))
1747 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1749 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1753 error = clib_error_return (0, "unknown input '%U'",
1754 format_unformat_error, line_input);
1759 dm = snat_det_map_by_user (sm, &in_addr);
1761 vlib_cli_output (vm, "no match");
1764 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1765 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1766 lo_port, lo_port + dm->ports_per_host - 1);
1770 unformat_free (line_input);
1775 static clib_error_t *
1776 snat_det_reverse_command_fn (vlib_main_t * vm,
1777 unformat_input_t * input,
1778 vlib_cli_command_t * cmd)
1780 snat_main_t *sm = &snat_main;
1781 unformat_input_t _line_input, *line_input = &_line_input;
1782 ip4_address_t in_addr, out_addr;
1785 clib_error_t *error = 0;
1787 if (!sm->deterministic)
1788 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1790 /* Get a line of input. */
1791 if (!unformat_user (input, unformat_line_input, line_input))
1794 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1797 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1801 error = clib_error_return (0, "unknown input '%U'",
1802 format_unformat_error, line_input);
1807 if (out_port < 1024 || out_port > 65535)
1809 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1813 dm = snat_det_map_by_out (sm, &out_addr);
1815 vlib_cli_output (vm, "no match");
1818 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1819 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1823 unformat_free (line_input);
1828 static clib_error_t *
1829 set_timeout_command_fn (vlib_main_t * vm,
1830 unformat_input_t * input, vlib_cli_command_t * cmd)
1832 snat_main_t *sm = &snat_main;
1833 unformat_input_t _line_input, *line_input = &_line_input;
1834 clib_error_t *error = 0;
1836 /* Get a line of input. */
1837 if (!unformat_user (input, unformat_line_input, line_input))
1840 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1842 if (unformat (line_input, "udp %u", &sm->udp_timeout))
1844 if (nat64_set_udp_timeout (sm->udp_timeout))
1846 error = clib_error_return (0, "Invalid UDP timeout value");
1850 else if (unformat (line_input, "tcp-established %u",
1851 &sm->tcp_established_timeout))
1853 if (nat64_set_tcp_timeouts
1854 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1857 clib_error_return (0,
1858 "Invalid TCP established timeouts value");
1862 else if (unformat (line_input, "tcp-transitory %u",
1863 &sm->tcp_transitory_timeout))
1865 if (nat64_set_tcp_timeouts
1866 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1869 clib_error_return (0,
1870 "Invalid TCP transitory timeouts value");
1874 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1876 if (nat64_set_icmp_timeout (sm->icmp_timeout))
1878 error = clib_error_return (0, "Invalid ICMP timeout value");
1882 else if (unformat (line_input, "reset"))
1884 sm->udp_timeout = SNAT_UDP_TIMEOUT;
1885 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1886 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1887 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1888 nat64_set_udp_timeout (0);
1889 nat64_set_icmp_timeout (0);
1890 nat64_set_tcp_timeouts (0, 0);
1894 error = clib_error_return (0, "unknown input '%U'",
1895 format_unformat_error, line_input);
1901 unformat_free (line_input);
1906 static clib_error_t *
1907 nat_show_timeouts_command_fn (vlib_main_t * vm,
1908 unformat_input_t * input,
1909 vlib_cli_command_t * cmd)
1911 snat_main_t *sm = &snat_main;
1913 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1914 vlib_cli_output (vm, "tcp-established timeout: %dsec",
1915 sm->tcp_established_timeout);
1916 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1917 sm->tcp_transitory_timeout);
1918 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1923 static clib_error_t *
1924 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1925 unformat_input_t * input,
1926 vlib_cli_command_t * cmd)
1928 snat_main_t *sm = &snat_main;
1930 snat_det_session_t *ses;
1933 if (!sm->deterministic)
1934 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1936 vlib_cli_output (vm, "NAT44 deterministic sessions:");
1938 pool_foreach (dm, sm->det_maps,
1940 vec_foreach_index (i, dm->sessions)
1942 ses = vec_elt_at_index (dm->sessions, i);
1944 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
1951 static clib_error_t *
1952 snat_det_close_session_out_fn (vlib_main_t * vm,
1953 unformat_input_t * input,
1954 vlib_cli_command_t * cmd)
1956 snat_main_t *sm = &snat_main;
1957 unformat_input_t _line_input, *line_input = &_line_input;
1958 ip4_address_t out_addr, ext_addr, in_addr;
1959 u32 out_port, ext_port;
1961 snat_det_session_t *ses;
1962 snat_det_out_key_t key;
1963 clib_error_t *error = 0;
1965 if (!sm->deterministic)
1966 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1968 /* Get a line of input. */
1969 if (!unformat_user (input, unformat_line_input, line_input))
1972 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1974 if (unformat (line_input, "%U:%d %U:%d",
1975 unformat_ip4_address, &out_addr, &out_port,
1976 unformat_ip4_address, &ext_addr, &ext_port))
1980 error = clib_error_return (0, "unknown input '%U'",
1981 format_unformat_error, line_input);
1986 unformat_free (line_input);
1988 dm = snat_det_map_by_out (sm, &out_addr);
1990 vlib_cli_output (vm, "no match");
1993 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
1994 key.ext_host_addr = out_addr;
1995 key.ext_host_port = ntohs ((u16) ext_port);
1996 key.out_port = ntohs ((u16) out_port);
1997 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
1999 vlib_cli_output (vm, "no match");
2001 snat_det_ses_close (dm, ses);
2005 unformat_free (line_input);
2010 static clib_error_t *
2011 snat_det_close_session_in_fn (vlib_main_t * vm,
2012 unformat_input_t * input,
2013 vlib_cli_command_t * cmd)
2015 snat_main_t *sm = &snat_main;
2016 unformat_input_t _line_input, *line_input = &_line_input;
2017 ip4_address_t in_addr, ext_addr;
2018 u32 in_port, ext_port;
2020 snat_det_session_t *ses;
2021 snat_det_out_key_t key;
2022 clib_error_t *error = 0;
2024 if (!sm->deterministic)
2025 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2027 /* Get a line of input. */
2028 if (!unformat_user (input, unformat_line_input, line_input))
2031 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2033 if (unformat (line_input, "%U:%d %U:%d",
2034 unformat_ip4_address, &in_addr, &in_port,
2035 unformat_ip4_address, &ext_addr, &ext_port))
2039 error = clib_error_return (0, "unknown input '%U'",
2040 format_unformat_error, line_input);
2045 unformat_free (line_input);
2047 dm = snat_det_map_by_user (sm, &in_addr);
2049 vlib_cli_output (vm, "no match");
2052 key.ext_host_addr = ext_addr;
2053 key.ext_host_port = ntohs ((u16) ext_port);
2055 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
2057 vlib_cli_output (vm, "no match");
2059 snat_det_ses_close (dm, ses);
2063 unformat_free (line_input);
2071 * @cliexstart{set snat workers}
2072 * Set NAT workers if 2 or more workers available, use:
2073 * vpp# set snat workers 0-2,5
2076 VLIB_CLI_COMMAND (set_workers_command, static) = {
2077 .path = "set nat workers",
2078 .function = set_workers_command_fn,
2079 .short_help = "set nat workers <workers-list>",
2084 * @cliexstart{show nat workers}
2086 * vpp# show nat workers:
2092 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
2093 .path = "show nat workers",
2094 .short_help = "show nat workers",
2095 .function = nat_show_workers_commnad_fn,
2100 * @cliexstart{set nat timeout}
2101 * Set values of timeouts for NAT sessions (in seconds), use:
2102 * vpp# set nat timeout udp 120 tcp-established 7500 tcp-transitory 250 icmp 90
2103 * To reset default values use:
2104 * vpp# set nat44 deterministic timeout reset
2107 VLIB_CLI_COMMAND (set_timeout_command, static) = {
2108 .path = "set nat timeout",
2109 .function = set_timeout_command_fn,
2111 "set nat timeout [udp <sec> | tcp-established <sec> "
2112 "tcp-transitory <sec> | icmp <sec> | reset]",
2117 * @cliexstart{show nat timeouts}
2118 * Show values of timeouts for NAT sessions.
2119 * vpp# show nat timeouts
2120 * udp timeout: 300sec
2121 * tcp-established timeout: 7440sec
2122 * tcp-transitory timeout: 240sec
2123 * icmp timeout: 60sec
2126 VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = {
2127 .path = "show nat timeouts",
2128 .short_help = "show nat timeouts",
2129 .function = nat_show_timeouts_command_fn,
2134 * @cliexstart{nat set logging level}
2135 * To force garbage collection of nat sessions
2136 * vpp# nat44 session cleanup
2139 VLIB_CLI_COMMAND (nat44_session_cleanup_command, static) = {
2140 .path = "nat44 session cleanup",
2141 .function = nat44_session_cleanup_command_fn,
2142 .short_help = "nat44 session cleanup",
2147 * @cliexstart{nat set logging level}
2148 * To set NAT logging level use:
2149 * Set nat logging level
2152 VLIB_CLI_COMMAND (snat_set_log_level_command, static) = {
2153 .path = "nat set logging level",
2154 .function = snat_set_log_level_command_fn,
2155 .short_help = "nat set logging level <level>",
2160 * @cliexstart{snat ipfix logging}
2161 * To enable NAT IPFIX logging use:
2162 * vpp# nat ipfix logging
2163 * To set IPFIX exporter use:
2164 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
2167 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
2168 .path = "nat ipfix logging",
2169 .function = snat_ipfix_logging_enable_disable_command_fn,
2170 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
2175 * @cliexstart{nat addr-port-assignment-alg}
2176 * Set address and port assignment algorithm
2177 * For the MAP-E CE limit port choice based on PSID use:
2178 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
2179 * For port range use:
2180 * vpp# nat addr-port-assignment-alg port-range <start-port> - <end-port>
2181 * To set standard (default) address and port assignment algorithm use:
2182 * vpp# nat addr-port-assignment-alg default
2185 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
2186 .path = "nat addr-port-assignment-alg",
2187 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
2188 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
2193 * @cliexstart{show nat addr-port-assignment-alg}
2194 * Show address and port assignment algorithm
2197 VLIB_CLI_COMMAND (nat44_show_alloc_addr_and_port_alg_command, static) = {
2198 .path = "show nat addr-port-assignment-alg",
2199 .short_help = "show nat addr-port-assignment-alg",
2200 .function = nat44_show_alloc_addr_and_port_alg_command_fn,
2205 * @cliexstart{nat mss-clamping}
2206 * Set TCP MSS rewriting configuration
2207 * To enable TCP MSS rewriting use:
2208 * vpp# nat mss-clamping 1452
2209 * To disbale TCP MSS rewriting use:
2210 * vpp# nat mss-clamping disable
2213 VLIB_CLI_COMMAND (nat_set_mss_clamping_command, static) = {
2214 .path = "nat mss-clamping",
2215 .short_help = "nat mss-clamping <mss-value>|disable",
2216 .function = nat_set_mss_clamping_command_fn,
2221 * @cliexstart{show nat mss-clamping}
2222 * Show TCP MSS rewriting configuration
2225 VLIB_CLI_COMMAND (nat_show_mss_clamping_command, static) = {
2226 .path = "show nat mss-clamping",
2227 .short_help = "show nat mss-clamping",
2228 .function = nat_show_mss_clamping_command_fn,
2233 * @cliexstart{nat ha failover}
2234 * Set HA failover (remote settings)
2237 VLIB_CLI_COMMAND (nat_ha_failover_command, static) = {
2238 .path = "nat ha failover",
2239 .short_help = "nat ha failover <ip4-address>:<port> [refresh-interval <sec>]",
2240 .function = nat_ha_failover_command_fn,
2245 * @cliexstart{nat ha listener}
2246 * Set HA listener (local settings)
2249 VLIB_CLI_COMMAND (nat_ha_listener_command, static) = {
2250 .path = "nat ha listener",
2251 .short_help = "nat ha listener <ip4-address>:<port> [path-mtu <path-mtu>]",
2252 .function = nat_ha_listener_command_fn,
2257 * @cliexstart{show nat ha}
2258 * Show HA configuration/status
2261 VLIB_CLI_COMMAND (nat_show_ha_command, static) = {
2262 .path = "show nat ha",
2263 .short_help = "show nat ha",
2264 .function = nat_show_ha_command_fn,
2269 * @cliexstart{nat ha flush}
2270 * Flush the current HA data (for testing)
2273 VLIB_CLI_COMMAND (nat_ha_flush_command, static) = {
2274 .path = "nat ha flush",
2275 .short_help = "nat ha flush",
2276 .function = nat_ha_flush_command_fn,
2281 * @cliexstart{nat ha resync}
2282 * Resync HA (resend existing sessions to new failover)
2285 VLIB_CLI_COMMAND (nat_ha_resync_command, static) = {
2286 .path = "nat ha resync",
2287 .short_help = "nat ha resync",
2288 .function = nat_ha_resync_command_fn,
2293 * @cliexstart{show nat44 hash tables}
2294 * Show NAT44 hash tables
2297 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
2298 .path = "show nat44 hash tables",
2299 .short_help = "show nat44 hash tables [detail|verbose]",
2300 .function = nat44_show_hash_commnad_fn,
2305 * @cliexstart{nat44 add address}
2306 * Add/delete NAT44 pool address.
2307 * To add NAT44 pool address use:
2308 * vpp# nat44 add address 172.16.1.3
2309 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
2310 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
2311 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
2314 VLIB_CLI_COMMAND (add_address_command, static) = {
2315 .path = "nat44 add address",
2316 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
2317 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
2318 .function = add_address_command_fn,
2323 * @cliexstart{show nat44 summary}
2324 * Show NAT44 summary
2325 * vpp# show nat44 summary
2328 VLIB_CLI_COMMAND (nat44_show_summary_command, static) = {
2329 .path = "show nat44 summary",
2330 .short_help = "show nat44 summary",
2331 .function = nat44_show_summary_command_fn,
2336 * @cliexstart{show nat44 addresses}
2337 * Show NAT44 pool addresses.
2338 * vpp# show nat44 addresses
2339 * NAT44 pool addresses:
2341 * tenant VRF independent
2350 * NAT44 twice-nat pool addresses:
2352 * tenant VRF independent
2358 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
2359 .path = "show nat44 addresses",
2360 .short_help = "show nat44 addresses",
2361 .function = nat44_show_addresses_command_fn,
2366 * @cliexstart{set interface nat44}
2367 * Enable/disable NAT44 feature on the interface.
2368 * To enable NAT44 feature with local network interface use:
2369 * vpp# set interface nat44 in GigabitEthernet0/8/0
2370 * To enable NAT44 feature with external network interface use:
2371 * vpp# set interface nat44 out GigabitEthernet0/a/0
2374 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
2375 .path = "set interface nat44",
2376 .function = snat_feature_command_fn,
2377 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
2383 * @cliexstart{show nat44 interfaces}
2384 * Show interfaces with NAT44 feature.
2385 * vpp# show nat44 interfaces
2387 * GigabitEthernet0/8/0 in
2388 * GigabitEthernet0/a/0 out
2391 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
2392 .path = "show nat44 interfaces",
2393 .short_help = "show nat44 interfaces",
2394 .function = nat44_show_interfaces_command_fn,
2399 * @cliexstart{nat44 add static mapping}
2400 * Static mapping allows hosts on the external network to initiate connection
2401 * to to the local network host.
2402 * To create static mapping between local host address 10.0.0.3 port 6303 and
2403 * external address 4.4.4.4 port 3606 for TCP protocol use:
2404 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
2405 * If not runnig "static mapping only" NAT plugin mode use before:
2406 * vpp# nat44 add address 4.4.4.4
2407 * To create static mapping between local and external address use:
2408 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
2411 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
2412 .path = "nat44 add static mapping",
2413 .function = add_static_mapping_command_fn,
2415 "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
2416 "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
2417 "[out2in-only] [del]",
2422 * @cliexstart{nat44 add identity mapping}
2423 * Identity mapping translate an IP address to itself.
2424 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
2426 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
2427 * To create identity mapping for address 10.0.0.3 use:
2428 * vpp# nat44 add identity mapping 10.0.0.3
2429 * To create identity mapping for DHCP addressed interface use:
2430 * vpp# nat44 add identity mapping external GigabitEthernet0/a/0 tcp 3606
2433 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
2434 .path = "nat44 add identity mapping",
2435 .function = add_identity_mapping_command_fn,
2436 .short_help = "nat44 add identity mapping <ip4-addr>|external <interface> "
2437 "[<protocol> <port>] [vrf <table-id>] [del]",
2442 * @cliexstart{nat44 add load-balancing static mapping}
2443 * Service load balancing using NAT44
2444 * To add static mapping with load balancing for service with external IP
2445 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
2446 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
2447 * vpp# nat44 add load-balancing static mapping protocol tcp external 1.2.3.4:80 local 10.100.10.10:8080 probability 80 local 10.100.10.20:8080 probability 20
2450 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
2451 .path = "nat44 add load-balancing static mapping",
2452 .function = add_lb_static_mapping_command_fn,
2454 "nat44 add load-balancing static mapping protocol tcp|udp "
2455 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2456 "probability <n> [twice-nat|self-twice-nat] [out2in-only] "
2457 "[affinity <timeout-seconds>] [del]",
2462 * @cliexstart{nat44 add load-balancing static mapping}
2463 * Modify service load balancing using NAT44
2464 * To add new back-end server 10.100.10.30:8080 for service load balancing
2465 * static mapping with external IP address 1.2.3.4 and TCP port 80 use:
2466 * vpp# nat44 add load-balancing back-end protocol tcp external 1.2.3.4:80 local 10.100.10.30:8080 probability 25
2469 VLIB_CLI_COMMAND (add_lb_backend_command, static) = {
2470 .path = "nat44 add load-balancing back-end",
2471 .function = add_lb_backend_command_fn,
2473 "nat44 add load-balancing back-end protocol tcp|udp "
2474 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2475 "probability <n> [del]",
2480 * @cliexstart{show nat44 static mappings}
2481 * Show NAT44 static mappings.
2482 * vpp# show nat44 static mappings
2483 * NAT44 static mappings:
2484 * local 10.0.0.3 external 4.4.4.4 vrf 0
2485 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
2486 * tcp vrf 0 external 1.2.3.4:80 out2in-only
2487 * local 10.100.10.10:8080 probability 80
2488 * local 10.100.10.20:8080 probability 20
2489 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
2490 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
2493 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
2494 .path = "show nat44 static mappings",
2495 .short_help = "show nat44 static mappings",
2496 .function = nat44_show_static_mappings_command_fn,
2501 * @cliexstart{nat44 add interface address}
2502 * Use NAT44 pool address from specific interfce
2503 * To add NAT44 pool address from specific interface use:
2504 * vpp# nat44 add interface address GigabitEthernet0/8/0
2507 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
2508 .path = "nat44 add interface address",
2509 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
2510 .function = snat_add_interface_address_command_fn,
2515 * @cliexstart{show nat44 interface address}
2516 * Show NAT44 pool address interfaces
2517 * vpp# show nat44 interface address
2518 * NAT44 pool address interfaces:
2519 * GigabitEthernet0/a/0
2520 * NAT44 twice-nat pool address interfaces:
2521 * GigabitEthernet0/8/0
2524 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
2525 .path = "show nat44 interface address",
2526 .short_help = "show nat44 interface address",
2527 .function = nat44_show_interface_address_command_fn,
2532 * @cliexstart{show nat44 sessions}
2533 * Show NAT44 sessions.
2536 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
2537 .path = "show nat44 sessions",
2538 .short_help = "show nat44 sessions [detail]",
2539 .function = nat44_show_sessions_command_fn,
2544 * @cliexstart{nat44 del user}
2545 * To delete all NAT44 user sessions:
2546 * vpp# nat44 del user 10.0.0.3
2549 VLIB_CLI_COMMAND (nat44_del_user_command, static) = {
2550 .path = "nat44 del user",
2551 .short_help = "nat44 del user <addr> [fib <index>]",
2552 .function = nat44_del_user_command_fn,
2557 * @cliexstart{nat44 del session}
2558 * To administratively delete NAT44 session by inside address and port use:
2559 * vpp# nat44 del session in 10.0.0.3:6303 tcp
2560 * To administratively delete NAT44 session by outside address and port use:
2561 * vpp# nat44 del session out 1.0.0.3:6033 udp
2564 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
2565 .path = "nat44 del session",
2566 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
2567 .function = nat44_del_session_command_fn,
2572 * @cliexstart{nat44 forwarding}
2573 * Enable or disable forwarding
2574 * Forward packets which don't match existing translation
2575 * or static mapping instead of dropping them.
2576 * To enable forwarding, use:
2577 * vpp# nat44 forwarding enable
2578 * To disable forwarding, use:
2579 * vpp# nat44 forwarding disable
2582 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
2583 .path = "nat44 forwarding",
2584 .short_help = "nat44 forwarding enable|disable",
2585 .function = snat_forwarding_set_command_fn,
2590 * @cliexstart{nat44 deterministic add}
2591 * Create bijective mapping of inside address to outside address and port range
2592 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
2594 * To create deterministic mapping between inside network 10.0.0.0/18 and
2595 * outside network 1.1.1.0/30 use:
2596 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
2599 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
2600 .path = "nat44 deterministic add",
2601 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
2602 .function = snat_det_map_command_fn,
2607 * @cliexpstart{show nat44 deterministic mappings}
2608 * Show NAT44 deterministic mappings
2609 * vpp# show nat44 deterministic mappings
2610 * NAT44 deterministic mappings:
2611 * in 10.0.0.0/24 out 1.1.1.1/32
2612 * outside address sharing ratio: 256
2613 * number of ports per inside host: 252
2614 * sessions number: 0
2617 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
2618 .path = "show nat44 deterministic mappings",
2619 .short_help = "show nat44 deterministic mappings",
2620 .function = nat44_det_show_mappings_command_fn,
2625 * @cliexstart{nat44 deterministic forward}
2626 * Return outside address and port range from inside address for deterministic
2628 * To obtain outside address and port of inside host use:
2629 * vpp# nat44 deterministic forward 10.0.0.2
2630 * 1.1.1.0:<1054-1068>
2633 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
2634 .path = "nat44 deterministic forward",
2635 .short_help = "nat44 deterministic forward <addr>",
2636 .function = snat_det_forward_command_fn,
2641 * @cliexstart{nat44 deterministic reverse}
2642 * Return inside address from outside address and port for deterministic NAT.
2643 * To obtain inside host address from outside address and port use:
2644 * #vpp nat44 deterministic reverse 1.1.1.1:1276
2648 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
2649 .path = "nat44 deterministic reverse",
2650 .short_help = "nat44 deterministic reverse <addr>:<port>",
2651 .function = snat_det_reverse_command_fn,
2656 * @cliexstart{show nat44 deterministic sessions}
2657 * Show NAT44 deterministic sessions.
2658 * vpp# show nat44 deterministic sessions
2659 * NAT44 deterministic sessions:
2660 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
2661 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
2662 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
2665 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
2666 .path = "show nat44 deterministic sessions",
2667 .short_help = "show nat44 deterministic sessions",
2668 .function = nat44_det_show_sessions_command_fn,
2673 * @cliexstart{nat44 deterministic close session out}
2674 * Close session using outside ip address and port
2675 * and external ip address and port, use:
2676 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
2679 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
2680 .path = "nat44 deterministic close session out",
2681 .short_help = "nat44 deterministic close session out "
2682 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
2683 .function = snat_det_close_session_out_fn,
2688 * @cliexstart{nat44 deterministic close session in}
2689 * Close session using inside ip address and port
2690 * and external ip address and port, use:
2691 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
2694 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
2695 .path = "nat44 deterministic close session in",
2696 .short_help = "nat44 deterministic close session in "
2697 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
2698 .function = snat_det_close_session_in_fn,
2704 * fd.io coding-style-patch-verification: ON
2707 * eval: (c-set-style "gnu")