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;
125 nat44_force_users_cleanup ();
129 static clib_error_t *
130 snat_set_log_level_command_fn (vlib_main_t * vm,
131 unformat_input_t * input,
132 vlib_cli_command_t * cmd)
134 unformat_input_t _line_input, *line_input = &_line_input;
135 snat_main_t *sm = &snat_main;
136 u8 log_level = SNAT_LOG_NONE;
137 clib_error_t *error = 0;
139 /* Get a line of input. */
140 if (!unformat_user (input, unformat_line_input, line_input))
143 if (!unformat (line_input, "%d", &log_level))
145 error = clib_error_return (0, "unknown input '%U'",
146 format_unformat_error, line_input);
149 if (log_level > SNAT_LOG_DEBUG)
151 error = clib_error_return (0, "unknown logging level '%d'", log_level);
154 sm->log_level = log_level;
157 unformat_free (line_input);
162 static clib_error_t *
163 snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm,
164 unformat_input_t * input,
165 vlib_cli_command_t * cmd)
167 unformat_input_t _line_input, *line_input = &_line_input;
172 clib_error_t *error = 0;
174 /* Get a line of input. */
175 if (!unformat_user (input, unformat_line_input, line_input))
177 rv = snat_ipfix_logging_enable_disable (enable, domain_id,
180 return clib_error_return (0, "ipfix logging enable failed");
184 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
186 if (unformat (line_input, "domain %d", &domain_id))
188 else if (unformat (line_input, "src-port %d", &src_port))
190 else if (unformat (line_input, "disable"))
194 error = clib_error_return (0, "unknown input '%U'",
195 format_unformat_error, line_input);
200 rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port);
204 error = clib_error_return (0, "ipfix logging enable failed");
209 unformat_free (line_input);
214 static clib_error_t *
215 nat44_show_hash_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
216 vlib_cli_command_t * cmd)
218 snat_main_t *sm = &snat_main;
219 snat_main_per_thread_data_t *tsm;
220 nat_affinity_main_t *nam = &nat_affinity_main;
224 if (unformat (input, "detail"))
226 else if (unformat (input, "verbose"))
229 vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
231 vlib_cli_output (vm, "%U",
232 format_bihash_8_8, &sm->static_mapping_by_external,
234 vec_foreach_index (i, sm->per_thread_data)
236 tsm = vec_elt_at_index (sm->per_thread_data, i);
237 vlib_cli_output (vm, "-------- thread %d %s --------\n",
238 i, vlib_worker_threads[i].name);
239 if (sm->endpoint_dependent)
241 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->in2out_ed,
243 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->out2in_ed,
248 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->in2out, verbose);
249 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->out2in, verbose);
251 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->user_hash, verbose);
254 if (sm->endpoint_dependent)
255 vlib_cli_output (vm, "%U", format_bihash_16_8, &nam->affinity_hash,
260 static clib_error_t *
261 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
262 unformat_input_t * input,
263 vlib_cli_command_t * cmd)
265 unformat_input_t _line_input, *line_input = &_line_input;
266 snat_main_t *sm = &snat_main;
267 clib_error_t *error = 0;
268 u32 psid, psid_offset, psid_length, port_start, port_end;
270 if (sm->deterministic)
271 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
273 /* Get a line of input. */
274 if (!unformat_user (input, unformat_line_input, line_input))
277 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
279 if (unformat (line_input, "default"))
280 nat_set_alloc_addr_and_port_default ();
283 (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
284 &psid_offset, &psid_length))
285 nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
289 (line_input, "port-range %d - %d", &port_start, &port_end))
291 if (port_end <= port_start)
294 clib_error_return (0,
295 "The end-port must be greater than start-port");
298 nat_set_alloc_addr_and_port_range ((u16) port_start,
303 error = clib_error_return (0, "unknown input '%U'",
304 format_unformat_error, line_input);
310 unformat_free (line_input);
315 static clib_error_t *
316 nat44_show_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
317 unformat_input_t * input,
318 vlib_cli_command_t * cmd)
320 snat_main_t *sm = &snat_main;
322 if (sm->deterministic)
323 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
325 vlib_cli_output (vm, "NAT address and port: %U",
326 format_nat_addr_and_port_alloc_alg,
327 sm->addr_and_port_alloc_alg);
328 switch (sm->addr_and_port_alloc_alg)
330 case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
331 vlib_cli_output (vm, " psid %d psid-offset %d psid-len %d", sm->psid,
332 sm->psid_offset, sm->psid_length);
334 case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
335 vlib_cli_output (vm, " start-port %d end-port %d", sm->start_port,
345 static clib_error_t *
346 nat_set_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
347 vlib_cli_command_t * cmd)
349 unformat_input_t _line_input, *line_input = &_line_input;
350 snat_main_t *sm = &snat_main;
351 clib_error_t *error = 0;
354 /* Get a line of input. */
355 if (!unformat_user (input, unformat_line_input, line_input))
358 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
360 if (unformat (line_input, "disable"))
361 sm->mss_clamping = 0;
362 else if (unformat (line_input, "%d", &mss))
364 sm->mss_clamping = (u16) mss;
365 sm->mss_value_net = clib_host_to_net_u16 (sm->mss_clamping);
369 error = clib_error_return (0, "unknown input '%U'",
370 format_unformat_error, line_input);
376 unformat_free (line_input);
381 static clib_error_t *
382 nat_show_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
383 vlib_cli_command_t * cmd)
385 snat_main_t *sm = &snat_main;
387 if (sm->mss_clamping)
388 vlib_cli_output (vm, "mss-clamping %d", sm->mss_clamping);
390 vlib_cli_output (vm, "mss-clamping disabled");
395 static clib_error_t *
396 nat_ha_failover_command_fn (vlib_main_t * vm, unformat_input_t * input,
397 vlib_cli_command_t * cmd)
399 unformat_input_t _line_input, *line_input = &_line_input;
401 u32 port, session_refresh_interval = 10;
403 clib_error_t *error = 0;
405 /* Get a line of input. */
406 if (!unformat_user (input, unformat_line_input, line_input))
409 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
411 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
415 (line_input, "refresh-interval %u", &session_refresh_interval))
419 error = clib_error_return (0, "unknown input '%U'",
420 format_unformat_error, line_input);
425 rv = nat_ha_set_failover (&addr, (u16) port, session_refresh_interval);
427 error = clib_error_return (0, "set HA failover failed");
430 unformat_free (line_input);
435 static clib_error_t *
436 nat_ha_listener_command_fn (vlib_main_t * vm, unformat_input_t * input,
437 vlib_cli_command_t * cmd)
439 unformat_input_t _line_input, *line_input = &_line_input;
441 u32 port, path_mtu = 512;
443 clib_error_t *error = 0;
445 /* Get a line of input. */
446 if (!unformat_user (input, unformat_line_input, line_input))
449 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
451 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
453 else if (unformat (line_input, "path-mtu %u", &path_mtu))
457 error = clib_error_return (0, "unknown input '%U'",
458 format_unformat_error, line_input);
463 rv = nat_ha_set_listener (&addr, (u16) port, path_mtu);
465 error = clib_error_return (0, "set HA listener failed");
468 unformat_free (line_input);
473 static clib_error_t *
474 nat_show_ha_command_fn (vlib_main_t * vm, unformat_input_t * input,
475 vlib_cli_command_t * cmd)
479 u32 path_mtu, session_refresh_interval, resync_ack_missed;
482 nat_ha_get_listener (&addr, &port, &path_mtu);
485 vlib_cli_output (vm, "NAT HA disabled\n");
489 vlib_cli_output (vm, "LISTENER:\n");
490 vlib_cli_output (vm, " %U:%u path-mtu %u\n",
491 format_ip4_address, &addr, port, path_mtu);
493 nat_ha_get_failover (&addr, &port, &session_refresh_interval);
494 vlib_cli_output (vm, "FAILOVER:\n");
496 vlib_cli_output (vm, " %U:%u refresh-interval %usec\n",
497 format_ip4_address, &addr, port,
498 session_refresh_interval);
500 vlib_cli_output (vm, " NA\n");
502 nat_ha_get_resync_status (&in_resync, &resync_ack_missed);
503 vlib_cli_output (vm, "RESYNC:\n");
505 vlib_cli_output (vm, " in progress\n");
507 vlib_cli_output (vm, " completed (%d ACK missed)\n", resync_ack_missed);
512 static clib_error_t *
513 nat_ha_flush_command_fn (vlib_main_t * vm, unformat_input_t * input,
514 vlib_cli_command_t * cmd)
520 static clib_error_t *
521 nat_ha_resync_command_fn (vlib_main_t * vm, unformat_input_t * input,
522 vlib_cli_command_t * cmd)
524 clib_error_t *error = 0;
526 if (nat_ha_resync (0, 0, 0))
527 error = clib_error_return (0, "NAT HA resync already running");
532 static clib_error_t *
533 add_address_command_fn (vlib_main_t * vm,
534 unformat_input_t * input, vlib_cli_command_t * cmd)
536 unformat_input_t _line_input, *line_input = &_line_input;
537 snat_main_t *sm = &snat_main;
538 ip4_address_t start_addr, end_addr, this_addr;
539 u32 start_host_order, end_host_order;
544 clib_error_t *error = 0;
547 if (sm->deterministic)
548 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
550 /* Get a line of input. */
551 if (!unformat_user (input, unformat_line_input, line_input))
554 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
556 if (unformat (line_input, "%U - %U",
557 unformat_ip4_address, &start_addr,
558 unformat_ip4_address, &end_addr))
560 else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
562 else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
563 end_addr = start_addr;
564 else if (unformat (line_input, "twice-nat"))
566 else if (unformat (line_input, "del"))
570 error = clib_error_return (0, "unknown input '%U'",
571 format_unformat_error, line_input);
576 if (sm->static_mapping_only)
578 error = clib_error_return (0, "static mapping only mode");
582 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
583 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
585 if (end_host_order < start_host_order)
587 error = clib_error_return (0, "end address less than start address");
591 count = (end_host_order - start_host_order) + 1;
594 nat_log_info ("%U - %U, %d addresses...",
595 format_ip4_address, &start_addr,
596 format_ip4_address, &end_addr, count);
598 this_addr = start_addr;
600 for (i = 0; i < count; i++)
603 rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
605 rv = snat_del_address (sm, this_addr, 0, twice_nat);
609 case VNET_API_ERROR_VALUE_EXIST:
610 error = clib_error_return (0, "NAT address already in use.");
612 case VNET_API_ERROR_NO_SUCH_ENTRY:
613 error = clib_error_return (0, "NAT address not exist.");
615 case VNET_API_ERROR_UNSPECIFIED:
617 clib_error_return (0, "NAT address used in static mapping.");
619 case VNET_API_ERROR_FEATURE_DISABLED:
621 clib_error_return (0,
622 "twice NAT available only for endpoint-dependent mode.");
629 nat44_add_del_address_dpo (this_addr, is_add);
631 increment_v4_address (&this_addr);
635 unformat_free (line_input);
640 static clib_error_t *
641 nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
642 vlib_cli_command_t * cmd)
644 snat_main_per_thread_data_t *tsm;
645 snat_main_t *sm = &snat_main;
648 if (sm->deterministic || !sm->endpoint_dependent)
649 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
651 // print session configuration values
652 vlib_cli_output (vm, "max translations: %u", sm->max_translations);
653 vlib_cli_output (vm, "max translations per user: %u",
654 sm->max_translations_per_user);
658 u64 now = vlib_time_now (sm->vlib_main);
659 u64 sess_timeout_time;
661 u32 udp_sessions = 0;
662 u32 tcp_sessions = 0;
663 u32 icmp_sessions = 0;
669 if (sm->num_workers > 1)
672 vec_foreach (tsm, sm->per_thread_data)
674 pool_foreach (s, tsm->sessions,
676 sess_timeout_time = s->last_heard +
677 (f64) nat44_session_get_timeout (sm, s);
678 if (now >= sess_timeout_time)
681 switch (s->in2out.protocol)
683 case SNAT_PROTOCOL_ICMP:
686 case SNAT_PROTOCOL_TCP:
693 case SNAT_PROTOCOL_UDP:
699 count += pool_elts (tsm->sessions);
701 vlib_cli_output (vm, "tid[%u] session scavenging cleared: %u",
702 tsm->thread_index, tsm->cleared);
703 vlib_cli_output (vm, "tid[%u] session scavenging cleanup runs: %u",
704 tsm->thread_index, tsm->cleanup_runs);
706 if (now < tsm->cleanup_timeout)
707 vlib_cli_output (vm, "tid[%u] session scavenging next run in: %f",
708 tsm->thread_index, tsm->cleanup_timeout - now);
710 vlib_cli_output (vm, "tid[%u] session scavenging next run in: 0",
717 tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
719 pool_foreach (s, tsm->sessions,
721 sess_timeout_time = s->last_heard +
722 (f64) nat44_session_get_timeout (sm, s);
723 if (now >= sess_timeout_time)
726 switch (s->in2out.protocol)
728 case SNAT_PROTOCOL_ICMP:
731 case SNAT_PROTOCOL_TCP:
738 case SNAT_PROTOCOL_UDP:
745 count = pool_elts (tsm->sessions);
747 vlib_cli_output (vm, "tid[0] session scavenging cleared: %u",
749 vlib_cli_output (vm, "tid[0] session scavenging cleanup runs: %u",
752 if (now < tsm->cleanup_timeout)
753 vlib_cli_output (vm, "tid[0] session scavenging next run in: %f",
754 tsm->cleanup_timeout - now);
756 vlib_cli_output (vm, "tid[0] session scavenging next run in: 0");
759 vlib_cli_output (vm, "total timed out sessions: %u", timed_out);
760 vlib_cli_output (vm, "total sessions: %u", count);
761 vlib_cli_output (vm, "total tcp sessions: %u", tcp_sessions);
762 vlib_cli_output (vm, "total tcp established sessions: %u", established);
763 vlib_cli_output (vm, "total tcp transitory sessions: %u", transitory);
764 vlib_cli_output (vm, "total udp sessions: %u", udp_sessions);
765 vlib_cli_output (vm, "total icmp sessions: %u", icmp_sessions);
769 static clib_error_t *
770 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
771 vlib_cli_command_t * cmd)
773 snat_main_t *sm = &snat_main;
776 if (sm->deterministic)
777 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
779 vlib_cli_output (vm, "NAT44 pool addresses:");
781 vec_foreach (ap, sm->addresses)
783 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
784 if (ap->fib_index != ~0)
785 vlib_cli_output (vm, " tenant VRF: %u",
786 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
788 vlib_cli_output (vm, " tenant VRF independent");
789 #define _(N, i, n, s) \
790 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
791 foreach_snat_protocol
794 vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
795 vec_foreach (ap, sm->twice_nat_addresses)
797 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
798 if (ap->fib_index != ~0)
799 vlib_cli_output (vm, " tenant VRF: %u",
800 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
802 vlib_cli_output (vm, " tenant VRF independent");
803 #define _(N, i, n, s) \
804 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
805 foreach_snat_protocol
812 static clib_error_t *
813 snat_feature_command_fn (vlib_main_t * vm,
814 unformat_input_t * input, vlib_cli_command_t * cmd)
816 unformat_input_t _line_input, *line_input = &_line_input;
817 vnet_main_t *vnm = vnet_get_main ();
818 clib_error_t *error = 0;
820 u32 *inside_sw_if_indices = 0;
821 u32 *outside_sw_if_indices = 0;
822 u8 is_output_feature = 0;
828 /* Get a line of input. */
829 if (!unformat_user (input, unformat_line_input, line_input))
832 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
834 if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
836 vec_add1 (inside_sw_if_indices, sw_if_index);
837 else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
839 vec_add1 (outside_sw_if_indices, sw_if_index);
840 else if (unformat (line_input, "output-feature"))
841 is_output_feature = 1;
842 else if (unformat (line_input, "del"))
846 error = clib_error_return (0, "unknown input '%U'",
847 format_unformat_error, line_input);
852 if (vec_len (inside_sw_if_indices))
854 for (i = 0; i < vec_len (inside_sw_if_indices); i++)
856 sw_if_index = inside_sw_if_indices[i];
857 if (is_output_feature)
859 if (snat_interface_add_del_output_feature
860 (sw_if_index, 1, is_del))
862 error = clib_error_return (0, "%s %U failed",
863 is_del ? "del" : "add",
864 format_vnet_sw_if_index_name,
871 if (snat_interface_add_del (sw_if_index, 1, is_del))
873 error = clib_error_return (0, "%s %U failed",
874 is_del ? "del" : "add",
875 format_vnet_sw_if_index_name,
883 if (vec_len (outside_sw_if_indices))
885 for (i = 0; i < vec_len (outside_sw_if_indices); i++)
887 sw_if_index = outside_sw_if_indices[i];
888 if (is_output_feature)
890 if (snat_interface_add_del_output_feature
891 (sw_if_index, 0, is_del))
893 error = clib_error_return (0, "%s %U failed",
894 is_del ? "del" : "add",
895 format_vnet_sw_if_index_name,
902 if (snat_interface_add_del (sw_if_index, 0, is_del))
904 error = clib_error_return (0, "%s %U failed",
905 is_del ? "del" : "add",
906 format_vnet_sw_if_index_name,
915 unformat_free (line_input);
916 vec_free (inside_sw_if_indices);
917 vec_free (outside_sw_if_indices);
922 static clib_error_t *
923 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
924 vlib_cli_command_t * cmd)
926 snat_main_t *sm = &snat_main;
928 vnet_main_t *vnm = vnet_get_main ();
930 vlib_cli_output (vm, "NAT44 interfaces:");
932 pool_foreach (i, sm->interfaces,
934 vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
936 (nat_interface_is_inside(i) &&
937 nat_interface_is_outside(i)) ? "in out" :
938 (nat_interface_is_inside(i) ? "in" : "out"));
941 pool_foreach (i, sm->output_feature_interfaces,
943 vlib_cli_output (vm, " %U output-feature %s",
944 format_vnet_sw_if_index_name, vnm,
946 (nat_interface_is_inside(i) &&
947 nat_interface_is_outside(i)) ? "in out" :
948 (nat_interface_is_inside(i) ? "in" : "out"));
955 static clib_error_t *
956 add_static_mapping_command_fn (vlib_main_t * vm,
957 unformat_input_t * input,
958 vlib_cli_command_t * cmd)
960 unformat_input_t _line_input, *line_input = &_line_input;
961 snat_main_t *sm = &snat_main;
962 clib_error_t *error = 0;
963 ip4_address_t l_addr, e_addr;
964 u32 l_port = 0, e_port = 0, vrf_id = ~0;
967 u32 sw_if_index = ~0;
968 vnet_main_t *vnm = vnet_get_main ();
970 snat_protocol_t proto = ~0;
972 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
975 if (sm->deterministic)
976 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
978 /* Get a line of input. */
979 if (!unformat_user (input, unformat_line_input, line_input))
982 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
984 if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
988 if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
990 else if (unformat (line_input, "external %U %u", unformat_ip4_address,
993 else if (unformat (line_input, "external %U", unformat_ip4_address,
996 else if (unformat (line_input, "external %U %u",
997 unformat_vnet_sw_interface, vnm, &sw_if_index,
1001 else if (unformat (line_input, "external %U",
1002 unformat_vnet_sw_interface, vnm, &sw_if_index))
1004 else if (unformat (line_input, "vrf %u", &vrf_id))
1006 else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
1008 else if (unformat (line_input, "twice-nat"))
1009 twice_nat = TWICE_NAT;
1010 else if (unformat (line_input, "self-twice-nat"))
1011 twice_nat = TWICE_NAT_SELF;
1012 else if (unformat (line_input, "out2in-only"))
1014 else if (unformat (line_input, "del"))
1018 error = clib_error_return (0, "unknown input: '%U'",
1019 format_unformat_error, line_input);
1024 if (twice_nat && addr_only)
1026 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
1030 if (!addr_only && !proto_set)
1032 error = clib_error_return (0, "missing protocol");
1036 rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
1037 vrf_id, addr_only, sw_if_index, proto, is_add,
1038 twice_nat, out2in_only, 0, 0);
1042 case VNET_API_ERROR_INVALID_VALUE:
1043 error = clib_error_return (0, "External port already in use.");
1045 case VNET_API_ERROR_NO_SUCH_ENTRY:
1047 error = clib_error_return (0, "External address must be allocated.");
1049 error = clib_error_return (0, "Mapping not exist.");
1051 case VNET_API_ERROR_NO_SUCH_FIB:
1052 error = clib_error_return (0, "No such VRF id.");
1054 case VNET_API_ERROR_VALUE_EXIST:
1055 error = clib_error_return (0, "Mapping already exist.");
1057 case VNET_API_ERROR_FEATURE_DISABLED:
1059 clib_error_return (0,
1060 "twice-nat/out2in-only available only for endpoint-dependent mode.");
1067 unformat_free (line_input);
1072 static clib_error_t *
1073 add_identity_mapping_command_fn (vlib_main_t * vm,
1074 unformat_input_t * input,
1075 vlib_cli_command_t * cmd)
1077 unformat_input_t _line_input, *line_input = &_line_input;
1078 snat_main_t *sm = &snat_main;
1079 clib_error_t *error = 0;
1081 u32 port = 0, vrf_id = ~0;
1084 u32 sw_if_index = ~0;
1085 vnet_main_t *vnm = vnet_get_main ();
1087 snat_protocol_t proto;
1089 if (sm->deterministic)
1090 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1094 /* Get a line of input. */
1095 if (!unformat_user (input, unformat_line_input, line_input))
1098 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1100 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1102 else if (unformat (line_input, "external %U",
1103 unformat_vnet_sw_interface, vnm, &sw_if_index))
1105 else if (unformat (line_input, "vrf %u", &vrf_id))
1107 else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
1110 else if (unformat (line_input, "del"))
1114 error = clib_error_return (0, "unknown input: '%U'",
1115 format_unformat_error, line_input);
1120 rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
1121 vrf_id, addr_only, sw_if_index, proto, is_add,
1126 case VNET_API_ERROR_INVALID_VALUE:
1127 error = clib_error_return (0, "External port already in use.");
1129 case VNET_API_ERROR_NO_SUCH_ENTRY:
1131 error = clib_error_return (0, "External address must be allocated.");
1133 error = clib_error_return (0, "Mapping not exist.");
1135 case VNET_API_ERROR_NO_SUCH_FIB:
1136 error = clib_error_return (0, "No such VRF id.");
1138 case VNET_API_ERROR_VALUE_EXIST:
1139 error = clib_error_return (0, "Mapping already exist.");
1146 unformat_free (line_input);
1151 static clib_error_t *
1152 add_lb_static_mapping_command_fn (vlib_main_t * vm,
1153 unformat_input_t * input,
1154 vlib_cli_command_t * cmd)
1156 unformat_input_t _line_input, *line_input = &_line_input;
1157 snat_main_t *sm = &snat_main;
1158 clib_error_t *error = 0;
1159 ip4_address_t l_addr, e_addr;
1160 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
1163 snat_protocol_t proto;
1165 nat44_lb_addr_port_t *locals = 0, local;
1166 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1169 if (sm->deterministic)
1170 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1172 /* Get a line of input. */
1173 if (!unformat_user (input, unformat_line_input, line_input))
1176 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1178 if (unformat (line_input, "local %U:%u probability %u",
1179 unformat_ip4_address, &l_addr, &l_port, &probability))
1181 clib_memset (&local, 0, sizeof (local));
1182 local.addr = l_addr;
1183 local.port = (u16) l_port;
1184 local.probability = (u8) probability;
1185 vec_add1 (locals, local);
1187 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1188 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1191 clib_memset (&local, 0, sizeof (local));
1192 local.addr = l_addr;
1193 local.port = (u16) l_port;
1194 local.probability = (u8) probability;
1195 local.vrf_id = vrf_id;
1196 vec_add1 (locals, local);
1198 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1201 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
1204 else if (unformat (line_input, "twice-nat"))
1205 twice_nat = TWICE_NAT;
1206 else if (unformat (line_input, "self-twice-nat"))
1207 twice_nat = TWICE_NAT_SELF;
1208 else if (unformat (line_input, "out2in-only"))
1210 else if (unformat (line_input, "del"))
1212 else if (unformat (line_input, "affinity %u", &affinity))
1216 error = clib_error_return (0, "unknown input: '%U'",
1217 format_unformat_error, line_input);
1222 if (vec_len (locals) < 2)
1224 error = clib_error_return (0, "at least two local must be set");
1230 error = clib_error_return (0, "missing protocol");
1234 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, locals,
1235 is_add, twice_nat, out2in_only, 0,
1240 case VNET_API_ERROR_INVALID_VALUE:
1241 error = clib_error_return (0, "External port already in use.");
1243 case VNET_API_ERROR_NO_SUCH_ENTRY:
1245 error = clib_error_return (0, "External address must be allocated.");
1247 error = clib_error_return (0, "Mapping not exist.");
1249 case VNET_API_ERROR_VALUE_EXIST:
1250 error = clib_error_return (0, "Mapping already exist.");
1252 case VNET_API_ERROR_FEATURE_DISABLED:
1254 clib_error_return (0, "Available only for endpoint-dependent mode.");
1261 unformat_free (line_input);
1267 static clib_error_t *
1268 add_lb_backend_command_fn (vlib_main_t * vm,
1269 unformat_input_t * input, vlib_cli_command_t * cmd)
1271 unformat_input_t _line_input, *line_input = &_line_input;
1272 snat_main_t *sm = &snat_main;
1273 clib_error_t *error = 0;
1274 ip4_address_t l_addr, e_addr;
1275 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
1278 snat_protocol_t proto;
1281 if (sm->deterministic)
1282 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1284 /* Get a line of input. */
1285 if (!unformat_user (input, unformat_line_input, line_input))
1288 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1290 if (unformat (line_input, "local %U:%u probability %u",
1291 unformat_ip4_address, &l_addr, &l_port, &probability))
1293 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1294 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1297 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1300 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
1303 else if (unformat (line_input, "del"))
1307 error = clib_error_return (0, "unknown input: '%U'",
1308 format_unformat_error, line_input);
1313 if (!l_port || !e_port)
1315 error = clib_error_return (0, "local or external must be set");
1321 error = clib_error_return (0, "missing protocol");
1326 nat44_lb_static_mapping_add_del_local (e_addr, (u16) e_port, l_addr,
1327 l_port, proto, vrf_id, probability,
1332 case VNET_API_ERROR_INVALID_VALUE:
1333 error = clib_error_return (0, "External is not load-balancing static "
1336 case VNET_API_ERROR_NO_SUCH_ENTRY:
1337 error = clib_error_return (0, "Mapping or back-end not exist.");
1339 case VNET_API_ERROR_VALUE_EXIST:
1340 error = clib_error_return (0, "Back-end already exist.");
1342 case VNET_API_ERROR_FEATURE_DISABLED:
1344 clib_error_return (0, "Available only for endpoint-dependent mode.");
1346 case VNET_API_ERROR_UNSPECIFIED:
1347 error = clib_error_return (0, "At least two back-ends must remain");
1354 unformat_free (line_input);
1359 static clib_error_t *
1360 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
1361 unformat_input_t * input,
1362 vlib_cli_command_t * cmd)
1364 snat_main_t *sm = &snat_main;
1365 snat_static_mapping_t *m;
1366 snat_static_map_resolve_t *rp;
1368 if (sm->deterministic)
1369 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1371 vlib_cli_output (vm, "NAT44 static mappings:");
1373 pool_foreach (m, sm->static_mappings,
1375 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
1377 vec_foreach (rp, sm->to_resolve)
1378 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
1384 static clib_error_t *
1385 snat_add_interface_address_command_fn (vlib_main_t * vm,
1386 unformat_input_t * input,
1387 vlib_cli_command_t * cmd)
1389 snat_main_t *sm = &snat_main;
1390 unformat_input_t _line_input, *line_input = &_line_input;
1394 clib_error_t *error = 0;
1397 if (sm->deterministic)
1398 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1400 /* Get a line of input. */
1401 if (!unformat_user (input, unformat_line_input, line_input))
1404 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1406 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
1407 sm->vnet_main, &sw_if_index))
1409 else if (unformat (line_input, "twice-nat"))
1411 else if (unformat (line_input, "del"))
1415 error = clib_error_return (0, "unknown input '%U'",
1416 format_unformat_error, line_input);
1421 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
1429 error = clib_error_return (0, "snat_add_interface_address returned %d",
1435 unformat_free (line_input);
1440 static clib_error_t *
1441 nat44_show_interface_address_command_fn (vlib_main_t * vm,
1442 unformat_input_t * input,
1443 vlib_cli_command_t * cmd)
1445 snat_main_t *sm = &snat_main;
1446 vnet_main_t *vnm = vnet_get_main ();
1449 if (sm->deterministic)
1450 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1453 vlib_cli_output (vm, "NAT44 pool address interfaces:");
1454 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
1456 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1459 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
1460 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
1462 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1470 static clib_error_t *
1471 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
1472 vlib_cli_command_t * cmd)
1474 unformat_input_t _line_input, *line_input = &_line_input;
1475 clib_error_t *error = 0;
1476 snat_main_t *sm = &snat_main;
1477 snat_main_per_thread_data_t *tsm;
1479 int detail = 0, metrics = 0;
1483 if (sm->deterministic)
1484 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1486 if (!unformat_user (input, unformat_line_input, line_input))
1489 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1491 if (unformat (line_input, "detail"))
1493 else if (unformat (line_input, "metrics"))
1497 error = clib_error_return (0, "unknown input '%U'",
1498 format_unformat_error, line_input);
1502 unformat_free (line_input);
1505 vlib_cli_output (vm, "NAT44 sessions:");
1507 vec_foreach_index (i, sm->per_thread_data)
1509 tsm = vec_elt_at_index (sm->per_thread_data, i);
1511 vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
1512 i, vlib_worker_threads[i].name,
1513 pool_elts (tsm->sessions));
1516 u64 now = vlib_time_now (sm->vlib_main);
1517 pool_foreach (u, tsm->users,
1519 vlib_cli_output (vm, " %U", format_snat_user_v2, tsm, u, now);
1524 pool_foreach (u, tsm->users,
1526 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, detail);
1534 static clib_error_t *
1535 nat44_del_user_command_fn (vlib_main_t * vm,
1536 unformat_input_t * input, vlib_cli_command_t * cmd)
1538 snat_main_t *sm = &snat_main;
1539 unformat_input_t _line_input, *line_input = &_line_input;
1540 clib_error_t *error = 0;
1545 if (sm->deterministic)
1546 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1548 /* Get a line of input. */
1549 if (!unformat_user (input, unformat_line_input, line_input))
1552 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1554 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1556 else if (unformat (line_input, "fib %u", &fib_index))
1560 error = clib_error_return (0, "unknown input '%U'",
1561 format_unformat_error, line_input);
1566 rv = nat44_user_del (&addr, fib_index);
1570 error = clib_error_return (0, "nat44_user_del returned %d", rv);
1574 unformat_free (line_input);
1579 static clib_error_t *
1580 nat44_del_session_command_fn (vlib_main_t * vm,
1581 unformat_input_t * input,
1582 vlib_cli_command_t * cmd)
1584 snat_main_t *sm = &snat_main;
1585 unformat_input_t _line_input, *line_input = &_line_input;
1586 int is_in = 0, is_ed = 0;
1587 clib_error_t *error = 0;
1588 ip4_address_t addr, eh_addr;
1589 u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
1590 snat_protocol_t proto;
1593 if (sm->deterministic)
1594 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1596 /* Get a line of input. */
1597 if (!unformat_user (input, unformat_line_input, line_input))
1600 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1603 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1604 unformat_snat_protocol, &proto))
1606 else if (unformat (line_input, "in"))
1609 vrf_id = sm->inside_vrf_id;
1611 else if (unformat (line_input, "out"))
1614 vrf_id = sm->outside_vrf_id;
1616 else if (unformat (line_input, "vrf %u", &vrf_id))
1620 (line_input, "external-host %U:%u", unformat_ip4_address,
1621 &eh_addr, &eh_port))
1625 error = clib_error_return (0, "unknown input '%U'",
1626 format_unformat_error, line_input);
1633 nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port,
1634 snat_proto_to_ip_proto (proto), vrf_id, is_in);
1636 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
1644 error = clib_error_return (0, "nat44_del_session returned %d", rv);
1649 unformat_free (line_input);
1654 static clib_error_t *
1655 snat_forwarding_set_command_fn (vlib_main_t * vm,
1656 unformat_input_t * input,
1657 vlib_cli_command_t * cmd)
1659 snat_main_t *sm = &snat_main;
1660 unformat_input_t _line_input, *line_input = &_line_input;
1661 u8 forwarding_enable;
1662 u8 forwarding_enable_set = 0;
1663 clib_error_t *error = 0;
1665 if (sm->deterministic)
1666 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1668 /* Get a line of input. */
1669 if (!unformat_user (input, unformat_line_input, line_input))
1670 return clib_error_return (0, "'enable' or 'disable' expected");
1672 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1674 if (!forwarding_enable_set && unformat (line_input, "enable"))
1676 forwarding_enable = 1;
1677 forwarding_enable_set = 1;
1679 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1681 forwarding_enable = 0;
1682 forwarding_enable_set = 1;
1686 error = clib_error_return (0, "unknown input '%U'",
1687 format_unformat_error, line_input);
1692 if (!forwarding_enable_set)
1694 error = clib_error_return (0, "'enable' or 'disable' expected");
1698 sm->forwarding_enabled = forwarding_enable;
1701 unformat_free (line_input);
1706 static clib_error_t *
1707 snat_det_map_command_fn (vlib_main_t * vm,
1708 unformat_input_t * input, vlib_cli_command_t * cmd)
1710 snat_main_t *sm = &snat_main;
1711 unformat_input_t _line_input, *line_input = &_line_input;
1712 ip4_address_t in_addr, out_addr;
1713 u32 in_plen, out_plen;
1715 clib_error_t *error = 0;
1717 if (!sm->deterministic)
1718 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1720 /* Get a line of input. */
1721 if (!unformat_user (input, unformat_line_input, line_input))
1724 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1727 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1731 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1734 else if (unformat (line_input, "del"))
1738 error = clib_error_return (0, "unknown input '%U'",
1739 format_unformat_error, line_input);
1744 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1749 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1754 unformat_free (line_input);
1759 static clib_error_t *
1760 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1761 unformat_input_t * input,
1762 vlib_cli_command_t * cmd)
1764 snat_main_t *sm = &snat_main;
1767 if (!sm->deterministic)
1768 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1770 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1772 pool_foreach (dm, sm->det_maps,
1774 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1775 format_ip4_address, &dm->in_addr, dm->in_plen,
1776 format_ip4_address, &dm->out_addr, dm->out_plen);
1777 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1779 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1780 dm->ports_per_host);
1781 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1788 static clib_error_t *
1789 snat_det_forward_command_fn (vlib_main_t * vm,
1790 unformat_input_t * input,
1791 vlib_cli_command_t * cmd)
1793 snat_main_t *sm = &snat_main;
1794 unformat_input_t _line_input, *line_input = &_line_input;
1795 ip4_address_t in_addr, out_addr;
1798 clib_error_t *error = 0;
1800 if (!sm->deterministic)
1801 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1803 /* Get a line of input. */
1804 if (!unformat_user (input, unformat_line_input, line_input))
1807 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1809 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1813 error = clib_error_return (0, "unknown input '%U'",
1814 format_unformat_error, line_input);
1819 dm = snat_det_map_by_user (sm, &in_addr);
1821 vlib_cli_output (vm, "no match");
1824 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1825 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1826 lo_port, lo_port + dm->ports_per_host - 1);
1830 unformat_free (line_input);
1835 static clib_error_t *
1836 snat_det_reverse_command_fn (vlib_main_t * vm,
1837 unformat_input_t * input,
1838 vlib_cli_command_t * cmd)
1840 snat_main_t *sm = &snat_main;
1841 unformat_input_t _line_input, *line_input = &_line_input;
1842 ip4_address_t in_addr, out_addr;
1845 clib_error_t *error = 0;
1847 if (!sm->deterministic)
1848 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1850 /* Get a line of input. */
1851 if (!unformat_user (input, unformat_line_input, line_input))
1854 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1857 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1861 error = clib_error_return (0, "unknown input '%U'",
1862 format_unformat_error, line_input);
1867 if (out_port < 1024 || out_port > 65535)
1869 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1873 dm = snat_det_map_by_out (sm, &out_addr);
1875 vlib_cli_output (vm, "no match");
1878 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1879 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1883 unformat_free (line_input);
1888 static clib_error_t *
1889 set_timeout_command_fn (vlib_main_t * vm,
1890 unformat_input_t * input, vlib_cli_command_t * cmd)
1892 snat_main_t *sm = &snat_main;
1893 unformat_input_t _line_input, *line_input = &_line_input;
1894 clib_error_t *error = 0;
1896 /* Get a line of input. */
1897 if (!unformat_user (input, unformat_line_input, line_input))
1900 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1902 if (unformat (line_input, "udp %u", &sm->udp_timeout))
1904 if (nat64_set_udp_timeout (sm->udp_timeout))
1906 error = clib_error_return (0, "Invalid UDP timeout value");
1910 else if (unformat (line_input, "tcp-established %u",
1911 &sm->tcp_established_timeout))
1913 if (nat64_set_tcp_timeouts
1914 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1917 clib_error_return (0,
1918 "Invalid TCP established timeouts value");
1922 else if (unformat (line_input, "tcp-transitory %u",
1923 &sm->tcp_transitory_timeout))
1925 if (nat64_set_tcp_timeouts
1926 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1929 clib_error_return (0,
1930 "Invalid TCP transitory timeouts value");
1934 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1936 if (nat64_set_icmp_timeout (sm->icmp_timeout))
1938 error = clib_error_return (0, "Invalid ICMP timeout value");
1942 else if (unformat (line_input, "reset"))
1944 sm->udp_timeout = SNAT_UDP_TIMEOUT;
1945 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1946 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1947 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1948 nat64_set_udp_timeout (0);
1949 nat64_set_icmp_timeout (0);
1950 nat64_set_tcp_timeouts (0, 0);
1954 error = clib_error_return (0, "unknown input '%U'",
1955 format_unformat_error, line_input);
1960 unformat_free (line_input);
1961 sm->min_timeout = nat44_minimal_timeout (sm);
1965 static clib_error_t *
1966 nat_show_timeouts_command_fn (vlib_main_t * vm,
1967 unformat_input_t * input,
1968 vlib_cli_command_t * cmd)
1970 snat_main_t *sm = &snat_main;
1973 vlib_cli_output (vm, "min session cleanup timeout: %dsec", sm->min_timeout);
1974 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1975 vlib_cli_output (vm, "tcp-established timeout: %dsec",
1976 sm->tcp_established_timeout);
1977 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1978 sm->tcp_transitory_timeout);
1979 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1984 static clib_error_t *
1985 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1986 unformat_input_t * input,
1987 vlib_cli_command_t * cmd)
1989 snat_main_t *sm = &snat_main;
1991 snat_det_session_t *ses;
1994 if (!sm->deterministic)
1995 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1997 vlib_cli_output (vm, "NAT44 deterministic sessions:");
1999 pool_foreach (dm, sm->det_maps,
2001 vec_foreach_index (i, dm->sessions)
2003 ses = vec_elt_at_index (dm->sessions, i);
2005 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
2012 static clib_error_t *
2013 snat_det_close_session_out_fn (vlib_main_t * vm,
2014 unformat_input_t * input,
2015 vlib_cli_command_t * cmd)
2017 snat_main_t *sm = &snat_main;
2018 unformat_input_t _line_input, *line_input = &_line_input;
2019 ip4_address_t out_addr, ext_addr, in_addr;
2020 u32 out_port, ext_port;
2022 snat_det_session_t *ses;
2023 snat_det_out_key_t key;
2024 clib_error_t *error = 0;
2026 if (!sm->deterministic)
2027 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2029 /* Get a line of input. */
2030 if (!unformat_user (input, unformat_line_input, line_input))
2033 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2035 if (unformat (line_input, "%U:%d %U:%d",
2036 unformat_ip4_address, &out_addr, &out_port,
2037 unformat_ip4_address, &ext_addr, &ext_port))
2041 error = clib_error_return (0, "unknown input '%U'",
2042 format_unformat_error, line_input);
2047 unformat_free (line_input);
2049 dm = snat_det_map_by_out (sm, &out_addr);
2051 vlib_cli_output (vm, "no match");
2054 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
2055 key.ext_host_addr = out_addr;
2056 key.ext_host_port = ntohs ((u16) ext_port);
2057 key.out_port = ntohs ((u16) out_port);
2058 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
2060 vlib_cli_output (vm, "no match");
2062 snat_det_ses_close (dm, ses);
2066 unformat_free (line_input);
2071 static clib_error_t *
2072 snat_det_close_session_in_fn (vlib_main_t * vm,
2073 unformat_input_t * input,
2074 vlib_cli_command_t * cmd)
2076 snat_main_t *sm = &snat_main;
2077 unformat_input_t _line_input, *line_input = &_line_input;
2078 ip4_address_t in_addr, ext_addr;
2079 u32 in_port, ext_port;
2081 snat_det_session_t *ses;
2082 snat_det_out_key_t key;
2083 clib_error_t *error = 0;
2085 if (!sm->deterministic)
2086 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2088 /* Get a line of input. */
2089 if (!unformat_user (input, unformat_line_input, line_input))
2092 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2094 if (unformat (line_input, "%U:%d %U:%d",
2095 unformat_ip4_address, &in_addr, &in_port,
2096 unformat_ip4_address, &ext_addr, &ext_port))
2100 error = clib_error_return (0, "unknown input '%U'",
2101 format_unformat_error, line_input);
2106 unformat_free (line_input);
2108 dm = snat_det_map_by_user (sm, &in_addr);
2110 vlib_cli_output (vm, "no match");
2113 key.ext_host_addr = ext_addr;
2114 key.ext_host_port = ntohs ((u16) ext_port);
2116 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
2118 vlib_cli_output (vm, "no match");
2120 snat_det_ses_close (dm, ses);
2124 unformat_free (line_input);
2132 * @cliexstart{set snat workers}
2133 * Set NAT workers if 2 or more workers available, use:
2134 * vpp# set snat workers 0-2,5
2137 VLIB_CLI_COMMAND (set_workers_command, static) = {
2138 .path = "set nat workers",
2139 .function = set_workers_command_fn,
2140 .short_help = "set nat workers <workers-list>",
2145 * @cliexstart{show nat workers}
2147 * vpp# show nat workers:
2153 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
2154 .path = "show nat workers",
2155 .short_help = "show nat workers",
2156 .function = nat_show_workers_commnad_fn,
2161 * @cliexstart{set nat timeout}
2162 * Set values of timeouts for NAT sessions (in seconds), use:
2163 * vpp# set nat timeout udp 120 tcp-established 7500 tcp-transitory 250 icmp 90
2164 * To reset default values use:
2165 * vpp# set nat44 deterministic timeout reset
2168 VLIB_CLI_COMMAND (set_timeout_command, static) = {
2169 .path = "set nat timeout",
2170 .function = set_timeout_command_fn,
2172 "set nat timeout [udp <sec> | tcp-established <sec> "
2173 "tcp-transitory <sec> | icmp <sec> | reset]",
2178 * @cliexstart{show nat timeouts}
2179 * Show values of timeouts for NAT sessions.
2180 * vpp# show nat timeouts
2181 * udp timeout: 300sec
2182 * tcp-established timeout: 7440sec
2183 * tcp-transitory timeout: 240sec
2184 * icmp timeout: 60sec
2187 VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = {
2188 .path = "show nat timeouts",
2189 .short_help = "show nat timeouts",
2190 .function = nat_show_timeouts_command_fn,
2195 * @cliexstart{nat set logging level}
2196 * To force garbage collection of nat sessions
2197 * vpp# nat44 session cleanup
2200 VLIB_CLI_COMMAND (nat44_session_cleanup_command, static) = {
2201 .path = "nat44 session cleanup",
2202 .function = nat44_session_cleanup_command_fn,
2203 .short_help = "nat44 session cleanup",
2208 * @cliexstart{nat set logging level}
2209 * To set NAT logging level use:
2210 * Set nat logging level
2213 VLIB_CLI_COMMAND (snat_set_log_level_command, static) = {
2214 .path = "nat set logging level",
2215 .function = snat_set_log_level_command_fn,
2216 .short_help = "nat set logging level <level>",
2221 * @cliexstart{snat ipfix logging}
2222 * To enable NAT IPFIX logging use:
2223 * vpp# nat ipfix logging
2224 * To set IPFIX exporter use:
2225 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
2228 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
2229 .path = "nat ipfix logging",
2230 .function = snat_ipfix_logging_enable_disable_command_fn,
2231 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
2236 * @cliexstart{nat addr-port-assignment-alg}
2237 * Set address and port assignment algorithm
2238 * For the MAP-E CE limit port choice based on PSID use:
2239 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
2240 * For port range use:
2241 * vpp# nat addr-port-assignment-alg port-range <start-port> - <end-port>
2242 * To set standard (default) address and port assignment algorithm use:
2243 * vpp# nat addr-port-assignment-alg default
2246 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
2247 .path = "nat addr-port-assignment-alg",
2248 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
2249 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
2254 * @cliexstart{show nat addr-port-assignment-alg}
2255 * Show address and port assignment algorithm
2258 VLIB_CLI_COMMAND (nat44_show_alloc_addr_and_port_alg_command, static) = {
2259 .path = "show nat addr-port-assignment-alg",
2260 .short_help = "show nat addr-port-assignment-alg",
2261 .function = nat44_show_alloc_addr_and_port_alg_command_fn,
2266 * @cliexstart{nat mss-clamping}
2267 * Set TCP MSS rewriting configuration
2268 * To enable TCP MSS rewriting use:
2269 * vpp# nat mss-clamping 1452
2270 * To disbale TCP MSS rewriting use:
2271 * vpp# nat mss-clamping disable
2274 VLIB_CLI_COMMAND (nat_set_mss_clamping_command, static) = {
2275 .path = "nat mss-clamping",
2276 .short_help = "nat mss-clamping <mss-value>|disable",
2277 .function = nat_set_mss_clamping_command_fn,
2282 * @cliexstart{show nat mss-clamping}
2283 * Show TCP MSS rewriting configuration
2286 VLIB_CLI_COMMAND (nat_show_mss_clamping_command, static) = {
2287 .path = "show nat mss-clamping",
2288 .short_help = "show nat mss-clamping",
2289 .function = nat_show_mss_clamping_command_fn,
2294 * @cliexstart{nat ha failover}
2295 * Set HA failover (remote settings)
2298 VLIB_CLI_COMMAND (nat_ha_failover_command, static) = {
2299 .path = "nat ha failover",
2300 .short_help = "nat ha failover <ip4-address>:<port> [refresh-interval <sec>]",
2301 .function = nat_ha_failover_command_fn,
2306 * @cliexstart{nat ha listener}
2307 * Set HA listener (local settings)
2310 VLIB_CLI_COMMAND (nat_ha_listener_command, static) = {
2311 .path = "nat ha listener",
2312 .short_help = "nat ha listener <ip4-address>:<port> [path-mtu <path-mtu>]",
2313 .function = nat_ha_listener_command_fn,
2318 * @cliexstart{show nat ha}
2319 * Show HA configuration/status
2322 VLIB_CLI_COMMAND (nat_show_ha_command, static) = {
2323 .path = "show nat ha",
2324 .short_help = "show nat ha",
2325 .function = nat_show_ha_command_fn,
2330 * @cliexstart{nat ha flush}
2331 * Flush the current HA data (for testing)
2334 VLIB_CLI_COMMAND (nat_ha_flush_command, static) = {
2335 .path = "nat ha flush",
2336 .short_help = "nat ha flush",
2337 .function = nat_ha_flush_command_fn,
2342 * @cliexstart{nat ha resync}
2343 * Resync HA (resend existing sessions to new failover)
2346 VLIB_CLI_COMMAND (nat_ha_resync_command, static) = {
2347 .path = "nat ha resync",
2348 .short_help = "nat ha resync",
2349 .function = nat_ha_resync_command_fn,
2354 * @cliexstart{show nat44 hash tables}
2355 * Show NAT44 hash tables
2358 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
2359 .path = "show nat44 hash tables",
2360 .short_help = "show nat44 hash tables [detail|verbose]",
2361 .function = nat44_show_hash_commnad_fn,
2366 * @cliexstart{nat44 add address}
2367 * Add/delete NAT44 pool address.
2368 * To add NAT44 pool address use:
2369 * vpp# nat44 add address 172.16.1.3
2370 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
2371 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
2372 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
2375 VLIB_CLI_COMMAND (add_address_command, static) = {
2376 .path = "nat44 add address",
2377 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
2378 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
2379 .function = add_address_command_fn,
2384 * @cliexstart{show nat44 summary}
2385 * Show NAT44 summary
2386 * vpp# show nat44 summary
2389 VLIB_CLI_COMMAND (nat44_show_summary_command, static) = {
2390 .path = "show nat44 summary",
2391 .short_help = "show nat44 summary",
2392 .function = nat44_show_summary_command_fn,
2397 * @cliexstart{show nat44 addresses}
2398 * Show NAT44 pool addresses.
2399 * vpp# show nat44 addresses
2400 * NAT44 pool addresses:
2402 * tenant VRF independent
2411 * NAT44 twice-nat pool addresses:
2413 * tenant VRF independent
2419 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
2420 .path = "show nat44 addresses",
2421 .short_help = "show nat44 addresses",
2422 .function = nat44_show_addresses_command_fn,
2427 * @cliexstart{set interface nat44}
2428 * Enable/disable NAT44 feature on the interface.
2429 * To enable NAT44 feature with local network interface use:
2430 * vpp# set interface nat44 in GigabitEthernet0/8/0
2431 * To enable NAT44 feature with external network interface use:
2432 * vpp# set interface nat44 out GigabitEthernet0/a/0
2435 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
2436 .path = "set interface nat44",
2437 .function = snat_feature_command_fn,
2438 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
2444 * @cliexstart{show nat44 interfaces}
2445 * Show interfaces with NAT44 feature.
2446 * vpp# show nat44 interfaces
2448 * GigabitEthernet0/8/0 in
2449 * GigabitEthernet0/a/0 out
2452 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
2453 .path = "show nat44 interfaces",
2454 .short_help = "show nat44 interfaces",
2455 .function = nat44_show_interfaces_command_fn,
2460 * @cliexstart{nat44 add static mapping}
2461 * Static mapping allows hosts on the external network to initiate connection
2462 * to to the local network host.
2463 * To create static mapping between local host address 10.0.0.3 port 6303 and
2464 * external address 4.4.4.4 port 3606 for TCP protocol use:
2465 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
2466 * If not runnig "static mapping only" NAT plugin mode use before:
2467 * vpp# nat44 add address 4.4.4.4
2468 * To create static mapping between local and external address use:
2469 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
2472 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
2473 .path = "nat44 add static mapping",
2474 .function = add_static_mapping_command_fn,
2476 "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
2477 "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
2478 "[out2in-only] [del]",
2483 * @cliexstart{nat44 add identity mapping}
2484 * Identity mapping translate an IP address to itself.
2485 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
2487 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
2488 * To create identity mapping for address 10.0.0.3 use:
2489 * vpp# nat44 add identity mapping 10.0.0.3
2490 * To create identity mapping for DHCP addressed interface use:
2491 * vpp# nat44 add identity mapping external GigabitEthernet0/a/0 tcp 3606
2494 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
2495 .path = "nat44 add identity mapping",
2496 .function = add_identity_mapping_command_fn,
2497 .short_help = "nat44 add identity mapping <ip4-addr>|external <interface> "
2498 "[<protocol> <port>] [vrf <table-id>] [del]",
2503 * @cliexstart{nat44 add load-balancing static mapping}
2504 * Service load balancing using NAT44
2505 * To add static mapping with load balancing for service with external IP
2506 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
2507 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
2508 * 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
2511 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
2512 .path = "nat44 add load-balancing static mapping",
2513 .function = add_lb_static_mapping_command_fn,
2515 "nat44 add load-balancing static mapping protocol tcp|udp "
2516 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2517 "probability <n> [twice-nat|self-twice-nat] [out2in-only] "
2518 "[affinity <timeout-seconds>] [del]",
2523 * @cliexstart{nat44 add load-balancing static mapping}
2524 * Modify service load balancing using NAT44
2525 * To add new back-end server 10.100.10.30:8080 for service load balancing
2526 * static mapping with external IP address 1.2.3.4 and TCP port 80 use:
2527 * vpp# nat44 add load-balancing back-end protocol tcp external 1.2.3.4:80 local 10.100.10.30:8080 probability 25
2530 VLIB_CLI_COMMAND (add_lb_backend_command, static) = {
2531 .path = "nat44 add load-balancing back-end",
2532 .function = add_lb_backend_command_fn,
2534 "nat44 add load-balancing back-end protocol tcp|udp "
2535 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2536 "probability <n> [del]",
2541 * @cliexstart{show nat44 static mappings}
2542 * Show NAT44 static mappings.
2543 * vpp# show nat44 static mappings
2544 * NAT44 static mappings:
2545 * local 10.0.0.3 external 4.4.4.4 vrf 0
2546 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
2547 * tcp vrf 0 external 1.2.3.4:80 out2in-only
2548 * local 10.100.10.10:8080 probability 80
2549 * local 10.100.10.20:8080 probability 20
2550 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
2551 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
2554 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
2555 .path = "show nat44 static mappings",
2556 .short_help = "show nat44 static mappings",
2557 .function = nat44_show_static_mappings_command_fn,
2562 * @cliexstart{nat44 add interface address}
2563 * Use NAT44 pool address from specific interfce
2564 * To add NAT44 pool address from specific interface use:
2565 * vpp# nat44 add interface address GigabitEthernet0/8/0
2568 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
2569 .path = "nat44 add interface address",
2570 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
2571 .function = snat_add_interface_address_command_fn,
2576 * @cliexstart{show nat44 interface address}
2577 * Show NAT44 pool address interfaces
2578 * vpp# show nat44 interface address
2579 * NAT44 pool address interfaces:
2580 * GigabitEthernet0/a/0
2581 * NAT44 twice-nat pool address interfaces:
2582 * GigabitEthernet0/8/0
2585 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
2586 .path = "show nat44 interface address",
2587 .short_help = "show nat44 interface address",
2588 .function = nat44_show_interface_address_command_fn,
2593 * @cliexstart{show nat44 sessions}
2594 * Show NAT44 sessions.
2597 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
2598 .path = "show nat44 sessions",
2599 .short_help = "show nat44 sessions [detail|metrics]",
2600 .function = nat44_show_sessions_command_fn,
2605 * @cliexstart{nat44 del user}
2606 * To delete all NAT44 user sessions:
2607 * vpp# nat44 del user 10.0.0.3
2610 VLIB_CLI_COMMAND (nat44_del_user_command, static) = {
2611 .path = "nat44 del user",
2612 .short_help = "nat44 del user <addr> [fib <index>]",
2613 .function = nat44_del_user_command_fn,
2618 * @cliexstart{nat44 del session}
2619 * To administratively delete NAT44 session by inside address and port use:
2620 * vpp# nat44 del session in 10.0.0.3:6303 tcp
2621 * To administratively delete NAT44 session by outside address and port use:
2622 * vpp# nat44 del session out 1.0.0.3:6033 udp
2625 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
2626 .path = "nat44 del session",
2627 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
2628 .function = nat44_del_session_command_fn,
2633 * @cliexstart{nat44 forwarding}
2634 * Enable or disable forwarding
2635 * Forward packets which don't match existing translation
2636 * or static mapping instead of dropping them.
2637 * To enable forwarding, use:
2638 * vpp# nat44 forwarding enable
2639 * To disable forwarding, use:
2640 * vpp# nat44 forwarding disable
2643 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
2644 .path = "nat44 forwarding",
2645 .short_help = "nat44 forwarding enable|disable",
2646 .function = snat_forwarding_set_command_fn,
2651 * @cliexstart{nat44 deterministic add}
2652 * Create bijective mapping of inside address to outside address and port range
2653 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
2655 * To create deterministic mapping between inside network 10.0.0.0/18 and
2656 * outside network 1.1.1.0/30 use:
2657 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
2660 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
2661 .path = "nat44 deterministic add",
2662 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
2663 .function = snat_det_map_command_fn,
2668 * @cliexpstart{show nat44 deterministic mappings}
2669 * Show NAT44 deterministic mappings
2670 * vpp# show nat44 deterministic mappings
2671 * NAT44 deterministic mappings:
2672 * in 10.0.0.0/24 out 1.1.1.1/32
2673 * outside address sharing ratio: 256
2674 * number of ports per inside host: 252
2675 * sessions number: 0
2678 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
2679 .path = "show nat44 deterministic mappings",
2680 .short_help = "show nat44 deterministic mappings",
2681 .function = nat44_det_show_mappings_command_fn,
2686 * @cliexstart{nat44 deterministic forward}
2687 * Return outside address and port range from inside address for deterministic
2689 * To obtain outside address and port of inside host use:
2690 * vpp# nat44 deterministic forward 10.0.0.2
2691 * 1.1.1.0:<1054-1068>
2694 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
2695 .path = "nat44 deterministic forward",
2696 .short_help = "nat44 deterministic forward <addr>",
2697 .function = snat_det_forward_command_fn,
2702 * @cliexstart{nat44 deterministic reverse}
2703 * Return inside address from outside address and port for deterministic NAT.
2704 * To obtain inside host address from outside address and port use:
2705 * #vpp nat44 deterministic reverse 1.1.1.1:1276
2709 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
2710 .path = "nat44 deterministic reverse",
2711 .short_help = "nat44 deterministic reverse <addr>:<port>",
2712 .function = snat_det_reverse_command_fn,
2717 * @cliexstart{show nat44 deterministic sessions}
2718 * Show NAT44 deterministic sessions.
2719 * vpp# show nat44 deterministic sessions
2720 * NAT44 deterministic sessions:
2721 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
2722 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
2723 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
2726 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
2727 .path = "show nat44 deterministic sessions",
2728 .short_help = "show nat44 deterministic sessions",
2729 .function = nat44_det_show_sessions_command_fn,
2734 * @cliexstart{nat44 deterministic close session out}
2735 * Close session using outside ip address and port
2736 * and external ip address and port, use:
2737 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
2740 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
2741 .path = "nat44 deterministic close session out",
2742 .short_help = "nat44 deterministic close session out "
2743 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
2744 .function = snat_det_close_session_out_fn,
2749 * @cliexstart{nat44 deterministic close session in}
2750 * Close session using inside ip address and port
2751 * and external ip address and port, use:
2752 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
2755 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
2756 .path = "nat44 deterministic close session in",
2757 .short_help = "nat44 deterministic close session in "
2758 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
2759 .function = snat_det_close_session_in_fn,
2765 * fd.io coding-style-patch-verification: ON
2768 * eval: (c-set-style "gnu")