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 snat_set_log_level_command_fn (vlib_main_t * vm,
121 unformat_input_t * input,
122 vlib_cli_command_t * cmd)
124 unformat_input_t _line_input, *line_input = &_line_input;
125 snat_main_t *sm = &snat_main;
126 u8 log_level = SNAT_LOG_NONE;
127 clib_error_t *error = 0;
129 /* Get a line of input. */
130 if (!unformat_user (input, unformat_line_input, line_input))
133 if (!unformat (line_input, "%d", &log_level))
135 error = clib_error_return (0, "unknown input '%U'",
136 format_unformat_error, line_input);
139 if (log_level > SNAT_LOG_DEBUG)
141 error = clib_error_return (0, "unknown logging level '%d'", log_level);
144 sm->log_level = log_level;
147 unformat_free (line_input);
152 static clib_error_t *
153 snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm,
154 unformat_input_t * input,
155 vlib_cli_command_t * cmd)
157 unformat_input_t _line_input, *line_input = &_line_input;
162 clib_error_t *error = 0;
164 /* Get a line of input. */
165 if (!unformat_user (input, unformat_line_input, line_input))
167 rv = snat_ipfix_logging_enable_disable (enable, domain_id,
170 return clib_error_return (0, "ipfix logging enable failed");
174 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
176 if (unformat (line_input, "domain %d", &domain_id))
178 else if (unformat (line_input, "src-port %d", &src_port))
180 else if (unformat (line_input, "disable"))
184 error = clib_error_return (0, "unknown input '%U'",
185 format_unformat_error, line_input);
190 rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port);
194 error = clib_error_return (0, "ipfix logging enable failed");
199 unformat_free (line_input);
204 static clib_error_t *
205 nat44_show_hash_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
206 vlib_cli_command_t * cmd)
208 snat_main_t *sm = &snat_main;
209 snat_main_per_thread_data_t *tsm;
210 nat_affinity_main_t *nam = &nat_affinity_main;
214 if (unformat (input, "detail"))
216 else if (unformat (input, "verbose"))
219 vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
221 vlib_cli_output (vm, "%U",
222 format_bihash_8_8, &sm->static_mapping_by_external,
224 vec_foreach_index (i, sm->per_thread_data)
226 tsm = vec_elt_at_index (sm->per_thread_data, i);
227 vlib_cli_output (vm, "-------- thread %d %s --------\n",
228 i, vlib_worker_threads[i].name);
229 if (sm->endpoint_dependent)
231 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->in2out_ed,
233 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->out2in_ed,
238 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->in2out, verbose);
239 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->out2in, verbose);
241 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->user_hash, verbose);
244 if (sm->endpoint_dependent)
246 vlib_cli_output (vm, "%U", format_bihash_16_8, &nam->affinity_hash,
248 vlib_cli_output (vm, "%U", format_bihash_16_8, &sm->ed_ext_ports, 0);
253 static clib_error_t *
254 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
255 unformat_input_t * input,
256 vlib_cli_command_t * cmd)
258 unformat_input_t _line_input, *line_input = &_line_input;
259 snat_main_t *sm = &snat_main;
260 clib_error_t *error = 0;
261 u32 psid, psid_offset, psid_length, port_start, port_end;
263 if (sm->deterministic)
264 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
266 /* Get a line of input. */
267 if (!unformat_user (input, unformat_line_input, line_input))
270 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
272 if (unformat (line_input, "default"))
273 nat_set_alloc_addr_and_port_default ();
276 (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
277 &psid_offset, &psid_length))
278 nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
282 (line_input, "port-range %d - %d", &port_start, &port_end))
284 if (port_end <= port_start)
287 clib_error_return (0,
288 "The end-port must be greater than start-port");
291 nat_set_alloc_addr_and_port_range ((u16) port_start,
296 error = clib_error_return (0, "unknown input '%U'",
297 format_unformat_error, line_input);
303 unformat_free (line_input);
308 static clib_error_t *
309 nat44_show_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
310 unformat_input_t * input,
311 vlib_cli_command_t * cmd)
313 snat_main_t *sm = &snat_main;
315 if (sm->deterministic)
316 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
318 vlib_cli_output (vm, "NAT address and port: %U",
319 format_nat_addr_and_port_alloc_alg,
320 sm->addr_and_port_alloc_alg);
321 switch (sm->addr_and_port_alloc_alg)
323 case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
324 vlib_cli_output (vm, " psid %d psid-offset %d psid-len %d", sm->psid,
325 sm->psid_offset, sm->psid_length);
327 case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
328 vlib_cli_output (vm, " start-port %d end-port %d", sm->start_port,
338 static clib_error_t *
339 nat_set_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
340 vlib_cli_command_t * cmd)
342 unformat_input_t _line_input, *line_input = &_line_input;
343 snat_main_t *sm = &snat_main;
344 clib_error_t *error = 0;
347 /* Get a line of input. */
348 if (!unformat_user (input, unformat_line_input, line_input))
351 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
353 if (unformat (line_input, "disable"))
354 sm->mss_clamping = 0;
355 else if (unformat (line_input, "%d", &mss))
357 sm->mss_clamping = (u16) mss;
358 sm->mss_value_net = clib_host_to_net_u16 (sm->mss_clamping);
362 error = clib_error_return (0, "unknown input '%U'",
363 format_unformat_error, line_input);
369 unformat_free (line_input);
374 static clib_error_t *
375 nat_show_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
376 vlib_cli_command_t * cmd)
378 snat_main_t *sm = &snat_main;
380 if (sm->mss_clamping)
381 vlib_cli_output (vm, "mss-clamping %d", sm->mss_clamping);
383 vlib_cli_output (vm, "mss-clamping disabled");
388 static clib_error_t *
389 nat_ha_failover_command_fn (vlib_main_t * vm, unformat_input_t * input,
390 vlib_cli_command_t * cmd)
392 unformat_input_t _line_input, *line_input = &_line_input;
394 u32 port, session_refresh_interval = 10;
396 clib_error_t *error = 0;
398 /* Get a line of input. */
399 if (!unformat_user (input, unformat_line_input, line_input))
402 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
404 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
408 (line_input, "refresh-interval %u", &session_refresh_interval))
412 error = clib_error_return (0, "unknown input '%U'",
413 format_unformat_error, line_input);
418 rv = nat_ha_set_failover (&addr, (u16) port, session_refresh_interval);
420 error = clib_error_return (0, "set HA failover failed");
423 unformat_free (line_input);
428 static clib_error_t *
429 nat_ha_listener_command_fn (vlib_main_t * vm, unformat_input_t * input,
430 vlib_cli_command_t * cmd)
432 unformat_input_t _line_input, *line_input = &_line_input;
434 u32 port, path_mtu = 512;
436 clib_error_t *error = 0;
438 /* Get a line of input. */
439 if (!unformat_user (input, unformat_line_input, line_input))
442 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
444 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
446 else if (unformat (line_input, "path-mtu %u", &path_mtu))
450 error = clib_error_return (0, "unknown input '%U'",
451 format_unformat_error, line_input);
456 rv = nat_ha_set_listener (&addr, (u16) port, path_mtu);
458 error = clib_error_return (0, "set HA listener failed");
461 unformat_free (line_input);
466 static clib_error_t *
467 nat_show_ha_command_fn (vlib_main_t * vm, unformat_input_t * input,
468 vlib_cli_command_t * cmd)
472 u32 path_mtu, session_refresh_interval, resync_ack_missed;
475 nat_ha_get_listener (&addr, &port, &path_mtu);
478 vlib_cli_output (vm, "NAT HA disabled\n");
482 vlib_cli_output (vm, "LISTENER:\n");
483 vlib_cli_output (vm, " %U:%u path-mtu %u\n",
484 format_ip4_address, &addr, port, path_mtu);
486 nat_ha_get_failover (&addr, &port, &session_refresh_interval);
487 vlib_cli_output (vm, "FAILOVER:\n");
489 vlib_cli_output (vm, " %U:%u refresh-interval %usec\n",
490 format_ip4_address, &addr, port,
491 session_refresh_interval);
493 vlib_cli_output (vm, " NA\n");
495 nat_ha_get_resync_status (&in_resync, &resync_ack_missed);
496 vlib_cli_output (vm, "RESYNC:\n");
498 vlib_cli_output (vm, " in progress\n");
500 vlib_cli_output (vm, " completed (%d ACK missed)\n", resync_ack_missed);
505 static clib_error_t *
506 nat_ha_flush_command_fn (vlib_main_t * vm, unformat_input_t * input,
507 vlib_cli_command_t * cmd)
513 static clib_error_t *
514 nat_ha_resync_command_fn (vlib_main_t * vm, unformat_input_t * input,
515 vlib_cli_command_t * cmd)
517 clib_error_t *error = 0;
519 if (nat_ha_resync (0, 0, 0))
520 error = clib_error_return (0, "NAT HA resync already running");
525 static clib_error_t *
526 add_address_command_fn (vlib_main_t * vm,
527 unformat_input_t * input, vlib_cli_command_t * cmd)
529 unformat_input_t _line_input, *line_input = &_line_input;
530 snat_main_t *sm = &snat_main;
531 ip4_address_t start_addr, end_addr, this_addr;
532 u32 start_host_order, end_host_order;
537 clib_error_t *error = 0;
540 if (sm->deterministic)
541 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
543 /* Get a line of input. */
544 if (!unformat_user (input, unformat_line_input, line_input))
547 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
549 if (unformat (line_input, "%U - %U",
550 unformat_ip4_address, &start_addr,
551 unformat_ip4_address, &end_addr))
553 else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
555 else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
556 end_addr = start_addr;
557 else if (unformat (line_input, "twice-nat"))
559 else if (unformat (line_input, "del"))
563 error = clib_error_return (0, "unknown input '%U'",
564 format_unformat_error, line_input);
569 if (sm->static_mapping_only)
571 error = clib_error_return (0, "static mapping only mode");
575 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
576 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
578 if (end_host_order < start_host_order)
580 error = clib_error_return (0, "end address less than start address");
584 count = (end_host_order - start_host_order) + 1;
587 nat_log_info ("%U - %U, %d addresses...",
588 format_ip4_address, &start_addr,
589 format_ip4_address, &end_addr, count);
591 this_addr = start_addr;
593 for (i = 0; i < count; i++)
596 rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
598 rv = snat_del_address (sm, this_addr, 0, twice_nat);
602 case VNET_API_ERROR_VALUE_EXIST:
603 error = clib_error_return (0, "NAT address already in use.");
605 case VNET_API_ERROR_NO_SUCH_ENTRY:
606 error = clib_error_return (0, "NAT address not exist.");
608 case VNET_API_ERROR_UNSPECIFIED:
610 clib_error_return (0, "NAT address used in static mapping.");
612 case VNET_API_ERROR_FEATURE_DISABLED:
614 clib_error_return (0,
615 "twice NAT available only for endpoint-dependent mode.");
622 nat44_add_del_address_dpo (this_addr, is_add);
624 increment_v4_address (&this_addr);
628 unformat_free (line_input);
633 static clib_error_t *
634 nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
635 vlib_cli_command_t * cmd)
637 snat_main_per_thread_data_t *tsm;
638 snat_main_t *sm = &snat_main;
641 if (sm->deterministic || !sm->endpoint_dependent)
642 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
644 // print session configuration values
645 vlib_cli_output (vm, "max translations: %u", sm->max_translations);
646 vlib_cli_output (vm, "max translations per user: %u",
647 sm->max_translations_per_user);
651 u64 now = vlib_time_now (sm->vlib_main);
652 u64 sess_timeout_time;
654 u32 udp_sessions = 0;
655 u32 tcp_sessions = 0;
656 u32 icmp_sessions = 0;
660 u32 transitory_wait_closed = 0;
661 u32 transitory_closed = 0;
664 if (sm->num_workers > 1)
667 vec_foreach (tsm, sm->per_thread_data)
669 pool_foreach (s, tsm->sessions,
671 sess_timeout_time = s->last_heard +
672 (f64) nat44_session_get_timeout (sm, s);
673 if (now >= sess_timeout_time)
676 switch (s->in2out.protocol)
678 case SNAT_PROTOCOL_ICMP:
681 case SNAT_PROTOCOL_TCP:
685 if (s->tcp_close_timestamp)
687 if (now >= s->tcp_close_timestamp)
693 ++transitory_wait_closed;
701 case SNAT_PROTOCOL_UDP:
707 count += pool_elts (tsm->sessions);
713 tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
715 pool_foreach (s, tsm->sessions,
717 sess_timeout_time = s->last_heard +
718 (f64) nat44_session_get_timeout (sm, s);
719 if (now >= sess_timeout_time)
722 switch (s->in2out.protocol)
724 case SNAT_PROTOCOL_ICMP:
727 case SNAT_PROTOCOL_TCP:
731 if (s->tcp_close_timestamp)
733 if (now >= s->tcp_close_timestamp)
739 ++transitory_wait_closed;
747 case SNAT_PROTOCOL_UDP:
754 count = pool_elts (tsm->sessions);
757 vlib_cli_output (vm, "total timed out sessions: %u", timed_out);
758 vlib_cli_output (vm, "total sessions: %u", count);
759 vlib_cli_output (vm, "total tcp sessions: %u", tcp_sessions);
760 vlib_cli_output (vm, "total tcp established sessions: %u", established);
761 vlib_cli_output (vm, "total tcp transitory sessions: %u", transitory);
762 vlib_cli_output (vm, "total tcp transitory (WAIT-CLOSED) sessions: %u",
763 transitory_wait_closed);
764 vlib_cli_output (vm, "total tcp transitory (CLOSED) sessions: %u",
766 vlib_cli_output (vm, "total udp sessions: %u", udp_sessions);
767 vlib_cli_output (vm, "total icmp sessions: %u", icmp_sessions);
771 static clib_error_t *
772 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
773 vlib_cli_command_t * cmd)
775 snat_main_t *sm = &snat_main;
778 if (sm->deterministic)
779 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
781 vlib_cli_output (vm, "NAT44 pool addresses:");
783 vec_foreach (ap, sm->addresses)
785 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
786 if (ap->fib_index != ~0)
787 vlib_cli_output (vm, " tenant VRF: %u",
788 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
790 vlib_cli_output (vm, " tenant VRF independent");
791 #define _(N, i, n, s) \
792 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
793 foreach_snat_protocol
796 vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
797 vec_foreach (ap, sm->twice_nat_addresses)
799 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
800 if (ap->fib_index != ~0)
801 vlib_cli_output (vm, " tenant VRF: %u",
802 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
804 vlib_cli_output (vm, " tenant VRF independent");
805 #define _(N, i, n, s) \
806 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
807 foreach_snat_protocol
814 static clib_error_t *
815 snat_feature_command_fn (vlib_main_t * vm,
816 unformat_input_t * input, vlib_cli_command_t * cmd)
818 unformat_input_t _line_input, *line_input = &_line_input;
819 vnet_main_t *vnm = vnet_get_main ();
820 clib_error_t *error = 0;
822 u32 *inside_sw_if_indices = 0;
823 u32 *outside_sw_if_indices = 0;
824 u8 is_output_feature = 0;
830 /* Get a line of input. */
831 if (!unformat_user (input, unformat_line_input, line_input))
834 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
836 if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
838 vec_add1 (inside_sw_if_indices, sw_if_index);
839 else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
841 vec_add1 (outside_sw_if_indices, sw_if_index);
842 else if (unformat (line_input, "output-feature"))
843 is_output_feature = 1;
844 else if (unformat (line_input, "del"))
848 error = clib_error_return (0, "unknown input '%U'",
849 format_unformat_error, line_input);
854 if (vec_len (inside_sw_if_indices))
856 for (i = 0; i < vec_len (inside_sw_if_indices); i++)
858 sw_if_index = inside_sw_if_indices[i];
859 if (is_output_feature)
861 if (snat_interface_add_del_output_feature
862 (sw_if_index, 1, is_del))
864 error = clib_error_return (0, "%s %U failed",
865 is_del ? "del" : "add",
866 format_vnet_sw_if_index_name,
873 if (snat_interface_add_del (sw_if_index, 1, is_del))
875 error = clib_error_return (0, "%s %U failed",
876 is_del ? "del" : "add",
877 format_vnet_sw_if_index_name,
885 if (vec_len (outside_sw_if_indices))
887 for (i = 0; i < vec_len (outside_sw_if_indices); i++)
889 sw_if_index = outside_sw_if_indices[i];
890 if (is_output_feature)
892 if (snat_interface_add_del_output_feature
893 (sw_if_index, 0, is_del))
895 error = clib_error_return (0, "%s %U failed",
896 is_del ? "del" : "add",
897 format_vnet_sw_if_index_name,
904 if (snat_interface_add_del (sw_if_index, 0, is_del))
906 error = clib_error_return (0, "%s %U failed",
907 is_del ? "del" : "add",
908 format_vnet_sw_if_index_name,
917 unformat_free (line_input);
918 vec_free (inside_sw_if_indices);
919 vec_free (outside_sw_if_indices);
924 static clib_error_t *
925 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
926 vlib_cli_command_t * cmd)
928 snat_main_t *sm = &snat_main;
930 vnet_main_t *vnm = vnet_get_main ();
932 vlib_cli_output (vm, "NAT44 interfaces:");
934 pool_foreach (i, sm->interfaces,
936 vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
938 (nat_interface_is_inside(i) &&
939 nat_interface_is_outside(i)) ? "in out" :
940 (nat_interface_is_inside(i) ? "in" : "out"));
943 pool_foreach (i, sm->output_feature_interfaces,
945 vlib_cli_output (vm, " %U output-feature %s",
946 format_vnet_sw_if_index_name, vnm,
948 (nat_interface_is_inside(i) &&
949 nat_interface_is_outside(i)) ? "in out" :
950 (nat_interface_is_inside(i) ? "in" : "out"));
957 static clib_error_t *
958 add_static_mapping_command_fn (vlib_main_t * vm,
959 unformat_input_t * input,
960 vlib_cli_command_t * cmd)
962 unformat_input_t _line_input, *line_input = &_line_input;
963 snat_main_t *sm = &snat_main;
964 clib_error_t *error = 0;
965 ip4_address_t l_addr, e_addr;
966 u32 l_port = 0, e_port = 0, vrf_id = ~0;
969 u32 sw_if_index = ~0;
970 vnet_main_t *vnm = vnet_get_main ();
972 snat_protocol_t proto = ~0;
974 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
977 if (sm->deterministic)
978 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
980 /* Get a line of input. */
981 if (!unformat_user (input, unformat_line_input, line_input))
984 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
986 if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
990 if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
992 else if (unformat (line_input, "external %U %u", unformat_ip4_address,
995 else if (unformat (line_input, "external %U", unformat_ip4_address,
998 else if (unformat (line_input, "external %U %u",
999 unformat_vnet_sw_interface, vnm, &sw_if_index,
1003 else if (unformat (line_input, "external %U",
1004 unformat_vnet_sw_interface, vnm, &sw_if_index))
1006 else if (unformat (line_input, "vrf %u", &vrf_id))
1008 else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
1010 else if (unformat (line_input, "twice-nat"))
1011 twice_nat = TWICE_NAT;
1012 else if (unformat (line_input, "self-twice-nat"))
1013 twice_nat = TWICE_NAT_SELF;
1014 else if (unformat (line_input, "out2in-only"))
1016 else if (unformat (line_input, "del"))
1020 error = clib_error_return (0, "unknown input: '%U'",
1021 format_unformat_error, line_input);
1026 if (twice_nat && addr_only)
1028 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
1032 if (!addr_only && !proto_set)
1034 error = clib_error_return (0, "missing protocol");
1038 rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
1039 vrf_id, addr_only, sw_if_index, proto, is_add,
1040 twice_nat, out2in_only, 0, 0);
1044 case VNET_API_ERROR_INVALID_VALUE:
1045 error = clib_error_return (0, "External port already in use.");
1047 case VNET_API_ERROR_NO_SUCH_ENTRY:
1049 error = clib_error_return (0, "External address must be allocated.");
1051 error = clib_error_return (0, "Mapping not exist.");
1053 case VNET_API_ERROR_NO_SUCH_FIB:
1054 error = clib_error_return (0, "No such VRF id.");
1056 case VNET_API_ERROR_VALUE_EXIST:
1057 error = clib_error_return (0, "Mapping already exist.");
1059 case VNET_API_ERROR_FEATURE_DISABLED:
1061 clib_error_return (0,
1062 "twice-nat/out2in-only available only for endpoint-dependent mode.");
1069 unformat_free (line_input);
1074 static clib_error_t *
1075 add_identity_mapping_command_fn (vlib_main_t * vm,
1076 unformat_input_t * input,
1077 vlib_cli_command_t * cmd)
1079 unformat_input_t _line_input, *line_input = &_line_input;
1080 snat_main_t *sm = &snat_main;
1081 clib_error_t *error = 0;
1083 u32 port = 0, vrf_id = ~0;
1086 u32 sw_if_index = ~0;
1087 vnet_main_t *vnm = vnet_get_main ();
1089 snat_protocol_t proto;
1091 if (sm->deterministic)
1092 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1096 /* Get a line of input. */
1097 if (!unformat_user (input, unformat_line_input, line_input))
1100 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1102 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1104 else if (unformat (line_input, "external %U",
1105 unformat_vnet_sw_interface, vnm, &sw_if_index))
1107 else if (unformat (line_input, "vrf %u", &vrf_id))
1109 else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
1112 else if (unformat (line_input, "del"))
1116 error = clib_error_return (0, "unknown input: '%U'",
1117 format_unformat_error, line_input);
1122 rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
1123 vrf_id, addr_only, sw_if_index, proto, is_add,
1128 case VNET_API_ERROR_INVALID_VALUE:
1129 error = clib_error_return (0, "External port already in use.");
1131 case VNET_API_ERROR_NO_SUCH_ENTRY:
1133 error = clib_error_return (0, "External address must be allocated.");
1135 error = clib_error_return (0, "Mapping not exist.");
1137 case VNET_API_ERROR_NO_SUCH_FIB:
1138 error = clib_error_return (0, "No such VRF id.");
1140 case VNET_API_ERROR_VALUE_EXIST:
1141 error = clib_error_return (0, "Mapping already exist.");
1148 unformat_free (line_input);
1153 static clib_error_t *
1154 add_lb_static_mapping_command_fn (vlib_main_t * vm,
1155 unformat_input_t * input,
1156 vlib_cli_command_t * cmd)
1158 unformat_input_t _line_input, *line_input = &_line_input;
1159 snat_main_t *sm = &snat_main;
1160 clib_error_t *error = 0;
1161 ip4_address_t l_addr, e_addr;
1162 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
1165 snat_protocol_t proto;
1167 nat44_lb_addr_port_t *locals = 0, local;
1168 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1171 if (sm->deterministic)
1172 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1174 /* Get a line of input. */
1175 if (!unformat_user (input, unformat_line_input, line_input))
1178 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1180 if (unformat (line_input, "local %U:%u probability %u",
1181 unformat_ip4_address, &l_addr, &l_port, &probability))
1183 clib_memset (&local, 0, sizeof (local));
1184 local.addr = l_addr;
1185 local.port = (u16) l_port;
1186 local.probability = (u8) probability;
1187 vec_add1 (locals, local);
1189 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1190 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1193 clib_memset (&local, 0, sizeof (local));
1194 local.addr = l_addr;
1195 local.port = (u16) l_port;
1196 local.probability = (u8) probability;
1197 local.vrf_id = vrf_id;
1198 vec_add1 (locals, local);
1200 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1203 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
1206 else if (unformat (line_input, "twice-nat"))
1207 twice_nat = TWICE_NAT;
1208 else if (unformat (line_input, "self-twice-nat"))
1209 twice_nat = TWICE_NAT_SELF;
1210 else if (unformat (line_input, "out2in-only"))
1212 else if (unformat (line_input, "del"))
1214 else if (unformat (line_input, "affinity %u", &affinity))
1218 error = clib_error_return (0, "unknown input: '%U'",
1219 format_unformat_error, line_input);
1224 if (vec_len (locals) < 2)
1226 error = clib_error_return (0, "at least two local must be set");
1232 error = clib_error_return (0, "missing protocol");
1236 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, locals,
1237 is_add, twice_nat, out2in_only, 0,
1242 case VNET_API_ERROR_INVALID_VALUE:
1243 error = clib_error_return (0, "External port already in use.");
1245 case VNET_API_ERROR_NO_SUCH_ENTRY:
1247 error = clib_error_return (0, "External address must be allocated.");
1249 error = clib_error_return (0, "Mapping not exist.");
1251 case VNET_API_ERROR_VALUE_EXIST:
1252 error = clib_error_return (0, "Mapping already exist.");
1254 case VNET_API_ERROR_FEATURE_DISABLED:
1256 clib_error_return (0, "Available only for endpoint-dependent mode.");
1263 unformat_free (line_input);
1269 static clib_error_t *
1270 add_lb_backend_command_fn (vlib_main_t * vm,
1271 unformat_input_t * input, vlib_cli_command_t * cmd)
1273 unformat_input_t _line_input, *line_input = &_line_input;
1274 snat_main_t *sm = &snat_main;
1275 clib_error_t *error = 0;
1276 ip4_address_t l_addr, e_addr;
1277 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
1280 snat_protocol_t proto;
1283 if (sm->deterministic)
1284 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1286 /* Get a line of input. */
1287 if (!unformat_user (input, unformat_line_input, line_input))
1290 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1292 if (unformat (line_input, "local %U:%u probability %u",
1293 unformat_ip4_address, &l_addr, &l_port, &probability))
1295 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1296 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1299 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1302 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
1305 else if (unformat (line_input, "del"))
1309 error = clib_error_return (0, "unknown input: '%U'",
1310 format_unformat_error, line_input);
1315 if (!l_port || !e_port)
1317 error = clib_error_return (0, "local or external must be set");
1323 error = clib_error_return (0, "missing protocol");
1328 nat44_lb_static_mapping_add_del_local (e_addr, (u16) e_port, l_addr,
1329 l_port, proto, vrf_id, probability,
1334 case VNET_API_ERROR_INVALID_VALUE:
1335 error = clib_error_return (0, "External is not load-balancing static "
1338 case VNET_API_ERROR_NO_SUCH_ENTRY:
1339 error = clib_error_return (0, "Mapping or back-end not exist.");
1341 case VNET_API_ERROR_VALUE_EXIST:
1342 error = clib_error_return (0, "Back-end already exist.");
1344 case VNET_API_ERROR_FEATURE_DISABLED:
1346 clib_error_return (0, "Available only for endpoint-dependent mode.");
1348 case VNET_API_ERROR_UNSPECIFIED:
1349 error = clib_error_return (0, "At least two back-ends must remain");
1356 unformat_free (line_input);
1361 static clib_error_t *
1362 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
1363 unformat_input_t * input,
1364 vlib_cli_command_t * cmd)
1366 snat_main_t *sm = &snat_main;
1367 snat_static_mapping_t *m;
1368 snat_static_map_resolve_t *rp;
1370 if (sm->deterministic)
1371 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1373 vlib_cli_output (vm, "NAT44 static mappings:");
1375 pool_foreach (m, sm->static_mappings,
1377 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
1379 vec_foreach (rp, sm->to_resolve)
1380 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
1386 static clib_error_t *
1387 snat_add_interface_address_command_fn (vlib_main_t * vm,
1388 unformat_input_t * input,
1389 vlib_cli_command_t * cmd)
1391 snat_main_t *sm = &snat_main;
1392 unformat_input_t _line_input, *line_input = &_line_input;
1396 clib_error_t *error = 0;
1399 if (sm->deterministic)
1400 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1402 /* Get a line of input. */
1403 if (!unformat_user (input, unformat_line_input, line_input))
1406 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1408 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
1409 sm->vnet_main, &sw_if_index))
1411 else if (unformat (line_input, "twice-nat"))
1413 else if (unformat (line_input, "del"))
1417 error = clib_error_return (0, "unknown input '%U'",
1418 format_unformat_error, line_input);
1423 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
1431 error = clib_error_return (0, "snat_add_interface_address returned %d",
1437 unformat_free (line_input);
1442 static clib_error_t *
1443 nat44_show_interface_address_command_fn (vlib_main_t * vm,
1444 unformat_input_t * input,
1445 vlib_cli_command_t * cmd)
1447 snat_main_t *sm = &snat_main;
1448 vnet_main_t *vnm = vnet_get_main ();
1451 if (sm->deterministic)
1452 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1455 vlib_cli_output (vm, "NAT44 pool address interfaces:");
1456 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
1458 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1461 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
1462 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
1464 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1472 static clib_error_t *
1473 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
1474 vlib_cli_command_t * cmd)
1476 unformat_input_t _line_input, *line_input = &_line_input;
1477 clib_error_t *error = 0;
1478 snat_main_t *sm = &snat_main;
1479 snat_main_per_thread_data_t *tsm;
1481 int detail = 0, metrics = 0;
1485 if (sm->deterministic)
1486 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1488 if (!unformat_user (input, unformat_line_input, line_input))
1491 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1493 if (unformat (line_input, "detail"))
1495 else if (unformat (line_input, "metrics"))
1499 error = clib_error_return (0, "unknown input '%U'",
1500 format_unformat_error, line_input);
1504 unformat_free (line_input);
1507 vlib_cli_output (vm, "NAT44 sessions:");
1509 vec_foreach_index (i, sm->per_thread_data)
1511 tsm = vec_elt_at_index (sm->per_thread_data, i);
1513 vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
1514 i, vlib_worker_threads[i].name,
1515 pool_elts (tsm->sessions));
1518 u64 now = vlib_time_now (sm->vlib_main);
1519 pool_foreach (u, tsm->users,
1521 vlib_cli_output (vm, " %U", format_snat_user_v2, tsm, u, now);
1526 pool_foreach (u, tsm->users,
1528 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, detail);
1536 static clib_error_t *
1537 nat44_del_user_command_fn (vlib_main_t * vm,
1538 unformat_input_t * input, vlib_cli_command_t * cmd)
1540 snat_main_t *sm = &snat_main;
1541 unformat_input_t _line_input, *line_input = &_line_input;
1542 clib_error_t *error = 0;
1547 if (sm->deterministic)
1548 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1550 /* Get a line of input. */
1551 if (!unformat_user (input, unformat_line_input, line_input))
1554 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1556 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1558 else if (unformat (line_input, "fib %u", &fib_index))
1562 error = clib_error_return (0, "unknown input '%U'",
1563 format_unformat_error, line_input);
1568 rv = nat44_user_del (&addr, fib_index);
1572 error = clib_error_return (0, "nat44_user_del returned %d", rv);
1576 unformat_free (line_input);
1581 static clib_error_t *
1582 nat44_del_session_command_fn (vlib_main_t * vm,
1583 unformat_input_t * input,
1584 vlib_cli_command_t * cmd)
1586 snat_main_t *sm = &snat_main;
1587 unformat_input_t _line_input, *line_input = &_line_input;
1588 int is_in = 0, is_ed = 0;
1589 clib_error_t *error = 0;
1590 ip4_address_t addr, eh_addr;
1591 u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
1592 snat_protocol_t proto;
1595 if (sm->deterministic)
1596 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1598 /* Get a line of input. */
1599 if (!unformat_user (input, unformat_line_input, line_input))
1602 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1605 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1606 unformat_snat_protocol, &proto))
1608 else if (unformat (line_input, "in"))
1611 vrf_id = sm->inside_vrf_id;
1613 else if (unformat (line_input, "out"))
1616 vrf_id = sm->outside_vrf_id;
1618 else if (unformat (line_input, "vrf %u", &vrf_id))
1622 (line_input, "external-host %U:%u", unformat_ip4_address,
1623 &eh_addr, &eh_port))
1627 error = clib_error_return (0, "unknown input '%U'",
1628 format_unformat_error, line_input);
1635 nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port,
1636 snat_proto_to_ip_proto (proto), vrf_id, is_in);
1638 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
1646 error = clib_error_return (0, "nat44_del_session returned %d", rv);
1651 unformat_free (line_input);
1656 static clib_error_t *
1657 snat_forwarding_set_command_fn (vlib_main_t * vm,
1658 unformat_input_t * input,
1659 vlib_cli_command_t * cmd)
1661 snat_main_t *sm = &snat_main;
1662 unformat_input_t _line_input, *line_input = &_line_input;
1663 u8 forwarding_enable;
1664 u8 forwarding_enable_set = 0;
1665 clib_error_t *error = 0;
1667 if (sm->deterministic)
1668 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1670 /* Get a line of input. */
1671 if (!unformat_user (input, unformat_line_input, line_input))
1672 return clib_error_return (0, "'enable' or 'disable' expected");
1674 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1676 if (!forwarding_enable_set && unformat (line_input, "enable"))
1678 forwarding_enable = 1;
1679 forwarding_enable_set = 1;
1681 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1683 forwarding_enable = 0;
1684 forwarding_enable_set = 1;
1688 error = clib_error_return (0, "unknown input '%U'",
1689 format_unformat_error, line_input);
1694 if (!forwarding_enable_set)
1696 error = clib_error_return (0, "'enable' or 'disable' expected");
1700 sm->forwarding_enabled = forwarding_enable;
1703 unformat_free (line_input);
1708 static clib_error_t *
1709 snat_det_map_command_fn (vlib_main_t * vm,
1710 unformat_input_t * input, vlib_cli_command_t * cmd)
1712 snat_main_t *sm = &snat_main;
1713 unformat_input_t _line_input, *line_input = &_line_input;
1714 ip4_address_t in_addr, out_addr;
1715 u32 in_plen, out_plen;
1717 clib_error_t *error = 0;
1719 if (!sm->deterministic)
1720 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1722 /* Get a line of input. */
1723 if (!unformat_user (input, unformat_line_input, line_input))
1726 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1729 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1733 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1736 else if (unformat (line_input, "del"))
1740 error = clib_error_return (0, "unknown input '%U'",
1741 format_unformat_error, line_input);
1746 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1751 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1756 unformat_free (line_input);
1761 static clib_error_t *
1762 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1763 unformat_input_t * input,
1764 vlib_cli_command_t * cmd)
1766 snat_main_t *sm = &snat_main;
1769 if (!sm->deterministic)
1770 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1772 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1774 pool_foreach (dm, sm->det_maps,
1776 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1777 format_ip4_address, &dm->in_addr, dm->in_plen,
1778 format_ip4_address, &dm->out_addr, dm->out_plen);
1779 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1781 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1782 dm->ports_per_host);
1783 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1790 static clib_error_t *
1791 snat_det_forward_command_fn (vlib_main_t * vm,
1792 unformat_input_t * input,
1793 vlib_cli_command_t * cmd)
1795 snat_main_t *sm = &snat_main;
1796 unformat_input_t _line_input, *line_input = &_line_input;
1797 ip4_address_t in_addr, out_addr;
1800 clib_error_t *error = 0;
1802 if (!sm->deterministic)
1803 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1805 /* Get a line of input. */
1806 if (!unformat_user (input, unformat_line_input, line_input))
1809 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1811 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1815 error = clib_error_return (0, "unknown input '%U'",
1816 format_unformat_error, line_input);
1821 dm = snat_det_map_by_user (sm, &in_addr);
1823 vlib_cli_output (vm, "no match");
1826 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1827 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1828 lo_port, lo_port + dm->ports_per_host - 1);
1832 unformat_free (line_input);
1837 static clib_error_t *
1838 snat_det_reverse_command_fn (vlib_main_t * vm,
1839 unformat_input_t * input,
1840 vlib_cli_command_t * cmd)
1842 snat_main_t *sm = &snat_main;
1843 unformat_input_t _line_input, *line_input = &_line_input;
1844 ip4_address_t in_addr, out_addr;
1847 clib_error_t *error = 0;
1849 if (!sm->deterministic)
1850 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1852 /* Get a line of input. */
1853 if (!unformat_user (input, unformat_line_input, line_input))
1856 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1859 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1863 error = clib_error_return (0, "unknown input '%U'",
1864 format_unformat_error, line_input);
1869 if (out_port < 1024 || out_port > 65535)
1871 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1875 dm = snat_det_map_by_out (sm, &out_addr);
1877 vlib_cli_output (vm, "no match");
1880 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1881 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1885 unformat_free (line_input);
1890 static clib_error_t *
1891 set_timeout_command_fn (vlib_main_t * vm,
1892 unformat_input_t * input, vlib_cli_command_t * cmd)
1894 snat_main_t *sm = &snat_main;
1895 unformat_input_t _line_input, *line_input = &_line_input;
1896 clib_error_t *error = 0;
1898 /* Get a line of input. */
1899 if (!unformat_user (input, unformat_line_input, line_input))
1902 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1904 if (unformat (line_input, "udp %u", &sm->udp_timeout))
1906 if (nat64_set_udp_timeout (sm->udp_timeout))
1908 error = clib_error_return (0, "Invalid UDP timeout value");
1912 else if (unformat (line_input, "tcp-established %u",
1913 &sm->tcp_established_timeout))
1915 if (nat64_set_tcp_timeouts
1916 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1919 clib_error_return (0,
1920 "Invalid TCP established timeouts value");
1924 else if (unformat (line_input, "tcp-transitory %u",
1925 &sm->tcp_transitory_timeout))
1927 if (nat64_set_tcp_timeouts
1928 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1931 clib_error_return (0,
1932 "Invalid TCP transitory timeouts value");
1936 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1938 if (nat64_set_icmp_timeout (sm->icmp_timeout))
1940 error = clib_error_return (0, "Invalid ICMP timeout value");
1944 else if (unformat (line_input, "reset"))
1946 sm->udp_timeout = SNAT_UDP_TIMEOUT;
1947 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1948 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1949 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1950 nat64_set_udp_timeout (0);
1951 nat64_set_icmp_timeout (0);
1952 nat64_set_tcp_timeouts (0, 0);
1956 error = clib_error_return (0, "unknown input '%U'",
1957 format_unformat_error, line_input);
1962 unformat_free (line_input);
1966 static clib_error_t *
1967 nat_show_timeouts_command_fn (vlib_main_t * vm,
1968 unformat_input_t * input,
1969 vlib_cli_command_t * cmd)
1971 snat_main_t *sm = &snat_main;
1973 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1974 vlib_cli_output (vm, "tcp-established timeout: %dsec",
1975 sm->tcp_established_timeout);
1976 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1977 sm->tcp_transitory_timeout);
1978 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1983 static clib_error_t *
1984 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1985 unformat_input_t * input,
1986 vlib_cli_command_t * cmd)
1988 snat_main_t *sm = &snat_main;
1990 snat_det_session_t *ses;
1993 if (!sm->deterministic)
1994 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1996 vlib_cli_output (vm, "NAT44 deterministic sessions:");
1998 pool_foreach (dm, sm->det_maps,
2000 vec_foreach_index (i, dm->sessions)
2002 ses = vec_elt_at_index (dm->sessions, i);
2004 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
2011 static clib_error_t *
2012 snat_det_close_session_out_fn (vlib_main_t * vm,
2013 unformat_input_t * input,
2014 vlib_cli_command_t * cmd)
2016 snat_main_t *sm = &snat_main;
2017 unformat_input_t _line_input, *line_input = &_line_input;
2018 ip4_address_t out_addr, ext_addr, in_addr;
2019 u32 out_port, ext_port;
2021 snat_det_session_t *ses;
2022 snat_det_out_key_t key;
2023 clib_error_t *error = 0;
2025 if (!sm->deterministic)
2026 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2028 /* Get a line of input. */
2029 if (!unformat_user (input, unformat_line_input, line_input))
2032 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2034 if (unformat (line_input, "%U:%d %U:%d",
2035 unformat_ip4_address, &out_addr, &out_port,
2036 unformat_ip4_address, &ext_addr, &ext_port))
2040 error = clib_error_return (0, "unknown input '%U'",
2041 format_unformat_error, line_input);
2046 unformat_free (line_input);
2048 dm = snat_det_map_by_out (sm, &out_addr);
2050 vlib_cli_output (vm, "no match");
2053 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
2054 key.ext_host_addr = out_addr;
2055 key.ext_host_port = ntohs ((u16) ext_port);
2056 key.out_port = ntohs ((u16) out_port);
2057 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
2059 vlib_cli_output (vm, "no match");
2061 snat_det_ses_close (dm, ses);
2065 unformat_free (line_input);
2070 static clib_error_t *
2071 snat_det_close_session_in_fn (vlib_main_t * vm,
2072 unformat_input_t * input,
2073 vlib_cli_command_t * cmd)
2075 snat_main_t *sm = &snat_main;
2076 unformat_input_t _line_input, *line_input = &_line_input;
2077 ip4_address_t in_addr, ext_addr;
2078 u32 in_port, ext_port;
2080 snat_det_session_t *ses;
2081 snat_det_out_key_t key;
2082 clib_error_t *error = 0;
2084 if (!sm->deterministic)
2085 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2087 /* Get a line of input. */
2088 if (!unformat_user (input, unformat_line_input, line_input))
2091 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2093 if (unformat (line_input, "%U:%d %U:%d",
2094 unformat_ip4_address, &in_addr, &in_port,
2095 unformat_ip4_address, &ext_addr, &ext_port))
2099 error = clib_error_return (0, "unknown input '%U'",
2100 format_unformat_error, line_input);
2105 unformat_free (line_input);
2107 dm = snat_det_map_by_user (sm, &in_addr);
2109 vlib_cli_output (vm, "no match");
2112 key.ext_host_addr = ext_addr;
2113 key.ext_host_port = ntohs ((u16) ext_port);
2115 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
2117 vlib_cli_output (vm, "no match");
2119 snat_det_ses_close (dm, ses);
2123 unformat_free (line_input);
2131 * @cliexstart{set snat workers}
2132 * Set NAT workers if 2 or more workers available, use:
2133 * vpp# set snat workers 0-2,5
2136 VLIB_CLI_COMMAND (set_workers_command, static) = {
2137 .path = "set nat workers",
2138 .function = set_workers_command_fn,
2139 .short_help = "set nat workers <workers-list>",
2144 * @cliexstart{show nat workers}
2146 * vpp# show nat workers:
2152 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
2153 .path = "show nat workers",
2154 .short_help = "show nat workers",
2155 .function = nat_show_workers_commnad_fn,
2160 * @cliexstart{set nat timeout}
2161 * Set values of timeouts for NAT sessions (in seconds), use:
2162 * vpp# set nat timeout udp 120 tcp-established 7500 tcp-transitory 250 icmp 90
2163 * To reset default values use:
2164 * vpp# set nat44 deterministic timeout reset
2167 VLIB_CLI_COMMAND (set_timeout_command, static) = {
2168 .path = "set nat timeout",
2169 .function = set_timeout_command_fn,
2171 "set nat timeout [udp <sec> | tcp-established <sec> "
2172 "tcp-transitory <sec> | icmp <sec> | reset]",
2177 * @cliexstart{show nat timeouts}
2178 * Show values of timeouts for NAT sessions.
2179 * vpp# show nat timeouts
2180 * udp timeout: 300sec
2181 * tcp-established timeout: 7440sec
2182 * tcp-transitory timeout: 240sec
2183 * icmp timeout: 60sec
2186 VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = {
2187 .path = "show nat timeouts",
2188 .short_help = "show nat timeouts",
2189 .function = nat_show_timeouts_command_fn,
2194 * @cliexstart{nat set logging level}
2195 * To set NAT logging level use:
2196 * Set nat logging level
2199 VLIB_CLI_COMMAND (snat_set_log_level_command, static) = {
2200 .path = "nat set logging level",
2201 .function = snat_set_log_level_command_fn,
2202 .short_help = "nat set logging level <level>",
2207 * @cliexstart{snat ipfix logging}
2208 * To enable NAT IPFIX logging use:
2209 * vpp# nat ipfix logging
2210 * To set IPFIX exporter use:
2211 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
2214 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
2215 .path = "nat ipfix logging",
2216 .function = snat_ipfix_logging_enable_disable_command_fn,
2217 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
2222 * @cliexstart{nat addr-port-assignment-alg}
2223 * Set address and port assignment algorithm
2224 * For the MAP-E CE limit port choice based on PSID use:
2225 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
2226 * For port range use:
2227 * vpp# nat addr-port-assignment-alg port-range <start-port> - <end-port>
2228 * To set standard (default) address and port assignment algorithm use:
2229 * vpp# nat addr-port-assignment-alg default
2232 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
2233 .path = "nat addr-port-assignment-alg",
2234 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
2235 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
2240 * @cliexstart{show nat addr-port-assignment-alg}
2241 * Show address and port assignment algorithm
2244 VLIB_CLI_COMMAND (nat44_show_alloc_addr_and_port_alg_command, static) = {
2245 .path = "show nat addr-port-assignment-alg",
2246 .short_help = "show nat addr-port-assignment-alg",
2247 .function = nat44_show_alloc_addr_and_port_alg_command_fn,
2252 * @cliexstart{nat mss-clamping}
2253 * Set TCP MSS rewriting configuration
2254 * To enable TCP MSS rewriting use:
2255 * vpp# nat mss-clamping 1452
2256 * To disbale TCP MSS rewriting use:
2257 * vpp# nat mss-clamping disable
2260 VLIB_CLI_COMMAND (nat_set_mss_clamping_command, static) = {
2261 .path = "nat mss-clamping",
2262 .short_help = "nat mss-clamping <mss-value>|disable",
2263 .function = nat_set_mss_clamping_command_fn,
2268 * @cliexstart{show nat mss-clamping}
2269 * Show TCP MSS rewriting configuration
2272 VLIB_CLI_COMMAND (nat_show_mss_clamping_command, static) = {
2273 .path = "show nat mss-clamping",
2274 .short_help = "show nat mss-clamping",
2275 .function = nat_show_mss_clamping_command_fn,
2280 * @cliexstart{nat ha failover}
2281 * Set HA failover (remote settings)
2284 VLIB_CLI_COMMAND (nat_ha_failover_command, static) = {
2285 .path = "nat ha failover",
2286 .short_help = "nat ha failover <ip4-address>:<port> [refresh-interval <sec>]",
2287 .function = nat_ha_failover_command_fn,
2292 * @cliexstart{nat ha listener}
2293 * Set HA listener (local settings)
2296 VLIB_CLI_COMMAND (nat_ha_listener_command, static) = {
2297 .path = "nat ha listener",
2298 .short_help = "nat ha listener <ip4-address>:<port> [path-mtu <path-mtu>]",
2299 .function = nat_ha_listener_command_fn,
2304 * @cliexstart{show nat ha}
2305 * Show HA configuration/status
2308 VLIB_CLI_COMMAND (nat_show_ha_command, static) = {
2309 .path = "show nat ha",
2310 .short_help = "show nat ha",
2311 .function = nat_show_ha_command_fn,
2316 * @cliexstart{nat ha flush}
2317 * Flush the current HA data (for testing)
2320 VLIB_CLI_COMMAND (nat_ha_flush_command, static) = {
2321 .path = "nat ha flush",
2322 .short_help = "nat ha flush",
2323 .function = nat_ha_flush_command_fn,
2328 * @cliexstart{nat ha resync}
2329 * Resync HA (resend existing sessions to new failover)
2332 VLIB_CLI_COMMAND (nat_ha_resync_command, static) = {
2333 .path = "nat ha resync",
2334 .short_help = "nat ha resync",
2335 .function = nat_ha_resync_command_fn,
2340 * @cliexstart{show nat44 hash tables}
2341 * Show NAT44 hash tables
2344 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
2345 .path = "show nat44 hash tables",
2346 .short_help = "show nat44 hash tables [detail|verbose]",
2347 .function = nat44_show_hash_commnad_fn,
2352 * @cliexstart{nat44 add address}
2353 * Add/delete NAT44 pool address.
2354 * To add NAT44 pool address use:
2355 * vpp# nat44 add address 172.16.1.3
2356 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
2357 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
2358 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
2361 VLIB_CLI_COMMAND (add_address_command, static) = {
2362 .path = "nat44 add address",
2363 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
2364 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
2365 .function = add_address_command_fn,
2370 * @cliexstart{show nat44 summary}
2371 * Show NAT44 summary
2372 * vpp# show nat44 summary
2375 VLIB_CLI_COMMAND (nat44_show_summary_command, static) = {
2376 .path = "show nat44 summary",
2377 .short_help = "show nat44 summary",
2378 .function = nat44_show_summary_command_fn,
2383 * @cliexstart{show nat44 addresses}
2384 * Show NAT44 pool addresses.
2385 * vpp# show nat44 addresses
2386 * NAT44 pool addresses:
2388 * tenant VRF independent
2397 * NAT44 twice-nat pool addresses:
2399 * tenant VRF independent
2405 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
2406 .path = "show nat44 addresses",
2407 .short_help = "show nat44 addresses",
2408 .function = nat44_show_addresses_command_fn,
2413 * @cliexstart{set interface nat44}
2414 * Enable/disable NAT44 feature on the interface.
2415 * To enable NAT44 feature with local network interface use:
2416 * vpp# set interface nat44 in GigabitEthernet0/8/0
2417 * To enable NAT44 feature with external network interface use:
2418 * vpp# set interface nat44 out GigabitEthernet0/a/0
2421 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
2422 .path = "set interface nat44",
2423 .function = snat_feature_command_fn,
2424 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
2430 * @cliexstart{show nat44 interfaces}
2431 * Show interfaces with NAT44 feature.
2432 * vpp# show nat44 interfaces
2434 * GigabitEthernet0/8/0 in
2435 * GigabitEthernet0/a/0 out
2438 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
2439 .path = "show nat44 interfaces",
2440 .short_help = "show nat44 interfaces",
2441 .function = nat44_show_interfaces_command_fn,
2446 * @cliexstart{nat44 add static mapping}
2447 * Static mapping allows hosts on the external network to initiate connection
2448 * to to the local network host.
2449 * To create static mapping between local host address 10.0.0.3 port 6303 and
2450 * external address 4.4.4.4 port 3606 for TCP protocol use:
2451 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
2452 * If not runnig "static mapping only" NAT plugin mode use before:
2453 * vpp# nat44 add address 4.4.4.4
2454 * To create static mapping between local and external address use:
2455 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
2458 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
2459 .path = "nat44 add static mapping",
2460 .function = add_static_mapping_command_fn,
2462 "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
2463 "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
2464 "[out2in-only] [del]",
2469 * @cliexstart{nat44 add identity mapping}
2470 * Identity mapping translate an IP address to itself.
2471 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
2473 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
2474 * To create identity mapping for address 10.0.0.3 use:
2475 * vpp# nat44 add identity mapping 10.0.0.3
2476 * To create identity mapping for DHCP addressed interface use:
2477 * vpp# nat44 add identity mapping external GigabitEthernet0/a/0 tcp 3606
2480 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
2481 .path = "nat44 add identity mapping",
2482 .function = add_identity_mapping_command_fn,
2483 .short_help = "nat44 add identity mapping <ip4-addr>|external <interface> "
2484 "[<protocol> <port>] [vrf <table-id>] [del]",
2489 * @cliexstart{nat44 add load-balancing static mapping}
2490 * Service load balancing using NAT44
2491 * To add static mapping with load balancing for service with external IP
2492 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
2493 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
2494 * 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
2497 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
2498 .path = "nat44 add load-balancing static mapping",
2499 .function = add_lb_static_mapping_command_fn,
2501 "nat44 add load-balancing static mapping protocol tcp|udp "
2502 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2503 "probability <n> [twice-nat|self-twice-nat] [out2in-only] "
2504 "[affinity <timeout-seconds>] [del]",
2509 * @cliexstart{nat44 add load-balancing static mapping}
2510 * Modify service load balancing using NAT44
2511 * To add new back-end server 10.100.10.30:8080 for service load balancing
2512 * static mapping with external IP address 1.2.3.4 and TCP port 80 use:
2513 * vpp# nat44 add load-balancing back-end protocol tcp external 1.2.3.4:80 local 10.100.10.30:8080 probability 25
2516 VLIB_CLI_COMMAND (add_lb_backend_command, static) = {
2517 .path = "nat44 add load-balancing back-end",
2518 .function = add_lb_backend_command_fn,
2520 "nat44 add load-balancing back-end protocol tcp|udp "
2521 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2522 "probability <n> [del]",
2527 * @cliexstart{show nat44 static mappings}
2528 * Show NAT44 static mappings.
2529 * vpp# show nat44 static mappings
2530 * NAT44 static mappings:
2531 * local 10.0.0.3 external 4.4.4.4 vrf 0
2532 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
2533 * tcp vrf 0 external 1.2.3.4:80 out2in-only
2534 * local 10.100.10.10:8080 probability 80
2535 * local 10.100.10.20:8080 probability 20
2536 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
2537 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
2540 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
2541 .path = "show nat44 static mappings",
2542 .short_help = "show nat44 static mappings",
2543 .function = nat44_show_static_mappings_command_fn,
2548 * @cliexstart{nat44 add interface address}
2549 * Use NAT44 pool address from specific interfce
2550 * To add NAT44 pool address from specific interface use:
2551 * vpp# nat44 add interface address GigabitEthernet0/8/0
2554 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
2555 .path = "nat44 add interface address",
2556 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
2557 .function = snat_add_interface_address_command_fn,
2562 * @cliexstart{show nat44 interface address}
2563 * Show NAT44 pool address interfaces
2564 * vpp# show nat44 interface address
2565 * NAT44 pool address interfaces:
2566 * GigabitEthernet0/a/0
2567 * NAT44 twice-nat pool address interfaces:
2568 * GigabitEthernet0/8/0
2571 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
2572 .path = "show nat44 interface address",
2573 .short_help = "show nat44 interface address",
2574 .function = nat44_show_interface_address_command_fn,
2579 * @cliexstart{show nat44 sessions}
2580 * Show NAT44 sessions.
2583 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
2584 .path = "show nat44 sessions",
2585 .short_help = "show nat44 sessions [detail|metrics]",
2586 .function = nat44_show_sessions_command_fn,
2591 * @cliexstart{nat44 del user}
2592 * To delete all NAT44 user sessions:
2593 * vpp# nat44 del user 10.0.0.3
2596 VLIB_CLI_COMMAND (nat44_del_user_command, static) = {
2597 .path = "nat44 del user",
2598 .short_help = "nat44 del user <addr> [fib <index>]",
2599 .function = nat44_del_user_command_fn,
2604 * @cliexstart{nat44 del session}
2605 * To administratively delete NAT44 session by inside address and port use:
2606 * vpp# nat44 del session in 10.0.0.3:6303 tcp
2607 * To administratively delete NAT44 session by outside address and port use:
2608 * vpp# nat44 del session out 1.0.0.3:6033 udp
2611 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
2612 .path = "nat44 del session",
2613 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
2614 .function = nat44_del_session_command_fn,
2619 * @cliexstart{nat44 forwarding}
2620 * Enable or disable forwarding
2621 * Forward packets which don't match existing translation
2622 * or static mapping instead of dropping them.
2623 * To enable forwarding, use:
2624 * vpp# nat44 forwarding enable
2625 * To disable forwarding, use:
2626 * vpp# nat44 forwarding disable
2629 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
2630 .path = "nat44 forwarding",
2631 .short_help = "nat44 forwarding enable|disable",
2632 .function = snat_forwarding_set_command_fn,
2637 * @cliexstart{nat44 deterministic add}
2638 * Create bijective mapping of inside address to outside address and port range
2639 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
2641 * To create deterministic mapping between inside network 10.0.0.0/18 and
2642 * outside network 1.1.1.0/30 use:
2643 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
2646 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
2647 .path = "nat44 deterministic add",
2648 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
2649 .function = snat_det_map_command_fn,
2654 * @cliexpstart{show nat44 deterministic mappings}
2655 * Show NAT44 deterministic mappings
2656 * vpp# show nat44 deterministic mappings
2657 * NAT44 deterministic mappings:
2658 * in 10.0.0.0/24 out 1.1.1.1/32
2659 * outside address sharing ratio: 256
2660 * number of ports per inside host: 252
2661 * sessions number: 0
2664 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
2665 .path = "show nat44 deterministic mappings",
2666 .short_help = "show nat44 deterministic mappings",
2667 .function = nat44_det_show_mappings_command_fn,
2672 * @cliexstart{nat44 deterministic forward}
2673 * Return outside address and port range from inside address for deterministic
2675 * To obtain outside address and port of inside host use:
2676 * vpp# nat44 deterministic forward 10.0.0.2
2677 * 1.1.1.0:<1054-1068>
2680 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
2681 .path = "nat44 deterministic forward",
2682 .short_help = "nat44 deterministic forward <addr>",
2683 .function = snat_det_forward_command_fn,
2688 * @cliexstart{nat44 deterministic reverse}
2689 * Return inside address from outside address and port for deterministic NAT.
2690 * To obtain inside host address from outside address and port use:
2691 * #vpp nat44 deterministic reverse 1.1.1.1:1276
2695 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
2696 .path = "nat44 deterministic reverse",
2697 .short_help = "nat44 deterministic reverse <addr>:<port>",
2698 .function = snat_det_reverse_command_fn,
2703 * @cliexstart{show nat44 deterministic sessions}
2704 * Show NAT44 deterministic sessions.
2705 * vpp# show nat44 deterministic sessions
2706 * NAT44 deterministic sessions:
2707 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
2708 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
2709 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
2712 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
2713 .path = "show nat44 deterministic sessions",
2714 .short_help = "show nat44 deterministic sessions",
2715 .function = nat44_det_show_sessions_command_fn,
2720 * @cliexstart{nat44 deterministic close session out}
2721 * Close session using outside ip address and port
2722 * and external ip address and port, use:
2723 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
2726 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
2727 .path = "nat44 deterministic close session out",
2728 .short_help = "nat44 deterministic close session out "
2729 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
2730 .function = snat_det_close_session_out_fn,
2735 * @cliexstart{nat44 deterministic close session in}
2736 * Close session using inside ip address and port
2737 * and external ip address and port, use:
2738 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
2741 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
2742 .path = "nat44 deterministic close session in",
2743 .short_help = "nat44 deterministic close session in "
2744 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
2745 .function = snat_det_close_session_in_fn,
2751 * fd.io coding-style-patch-verification: ON
2754 * eval: (c-set-style "gnu")