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>
31 #define UNSUPPORTED_IN_DET_OR_ED_MODE_STR \
32 "This command is unsupported in deterministic or endpoint dependent mode"
33 #define UNSUPPORTED_IN_DET_OR_NON_ED_MODE_STR \
34 "This command is unsupported in deterministic or non endpoint dependent mode"
35 #define UNSUPPORTED_IN_DET_MODE_STR \
36 "This command is unsupported in deterministic mode"
37 #define SUPPORTED_ONLY_IN_ED_MODE_STR \
38 "This command is supported only in endpoint dependent mode"
39 #define SUPPORTED_ONLY_IN_DET_MODE_STR \
40 "This command is supported only in deterministic mode"
43 set_workers_command_fn (vlib_main_t * vm,
44 unformat_input_t * input, vlib_cli_command_t * cmd)
46 unformat_input_t _line_input, *line_input = &_line_input;
47 snat_main_t *sm = &snat_main;
50 clib_error_t *error = 0;
52 if (sm->deterministic)
53 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
55 /* Get a line of input. */
56 if (!unformat_user (input, unformat_line_input, line_input))
59 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
61 if (unformat (line_input, "%U", unformat_bitmap_list, &bitmap))
65 error = clib_error_return (0, "unknown input '%U'",
66 format_unformat_error, line_input);
73 error = clib_error_return (0, "List of workers must be specified.");
77 rv = snat_set_workers (bitmap);
79 clib_bitmap_free (bitmap);
83 case VNET_API_ERROR_INVALID_WORKER:
84 error = clib_error_return (0, "Invalid worker(s).");
86 case VNET_API_ERROR_FEATURE_DISABLED:
87 error = clib_error_return (0,
88 "Supported only if 2 or more workes available.");
95 unformat_free (line_input);
100 static clib_error_t *
101 nat_show_workers_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
102 vlib_cli_command_t * cmd)
104 snat_main_t *sm = &snat_main;
107 if (sm->deterministic)
108 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
110 if (sm->num_workers > 1)
112 vlib_cli_output (vm, "%d workers", vec_len (sm->workers));
114 vec_foreach (worker, sm->workers)
116 vlib_worker_thread_t *w =
117 vlib_worker_threads + *worker + sm->first_worker_index;
118 vlib_cli_output (vm, " %s", w->name);
126 static clib_error_t *
127 snat_set_log_level_command_fn (vlib_main_t * vm,
128 unformat_input_t * input,
129 vlib_cli_command_t * cmd)
131 unformat_input_t _line_input, *line_input = &_line_input;
132 snat_main_t *sm = &snat_main;
133 u8 log_level = SNAT_LOG_NONE;
134 clib_error_t *error = 0;
136 /* Get a line of input. */
137 if (!unformat_user (input, unformat_line_input, line_input))
140 if (!unformat (line_input, "%d", &log_level))
142 error = clib_error_return (0, "unknown input '%U'",
143 format_unformat_error, line_input);
146 if (log_level > SNAT_LOG_DEBUG)
148 error = clib_error_return (0, "unknown logging level '%d'", log_level);
151 sm->log_level = log_level;
154 unformat_free (line_input);
159 static clib_error_t *
160 snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm,
161 unformat_input_t * input,
162 vlib_cli_command_t * cmd)
164 unformat_input_t _line_input, *line_input = &_line_input;
169 clib_error_t *error = 0;
171 /* Get a line of input. */
172 if (!unformat_user (input, unformat_line_input, line_input))
174 rv = snat_ipfix_logging_enable_disable (enable, domain_id,
177 return clib_error_return (0, "ipfix logging enable failed");
181 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
183 if (unformat (line_input, "domain %d", &domain_id))
185 else if (unformat (line_input, "src-port %d", &src_port))
187 else if (unformat (line_input, "disable"))
191 error = clib_error_return (0, "unknown input '%U'",
192 format_unformat_error, line_input);
197 rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port);
201 error = clib_error_return (0, "ipfix logging enable failed");
206 unformat_free (line_input);
211 static clib_error_t *
212 nat44_show_hash_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
213 vlib_cli_command_t * cmd)
215 snat_main_t *sm = &snat_main;
216 snat_main_per_thread_data_t *tsm;
217 nat_affinity_main_t *nam = &nat_affinity_main;
221 if (unformat (input, "detail"))
223 else if (unformat (input, "verbose"))
226 vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
228 vlib_cli_output (vm, "%U",
229 format_bihash_8_8, &sm->static_mapping_by_external,
231 vlib_cli_output (vm, "%U", format_bihash_16_8, &sm->out2in_ed, verbose);
232 vec_foreach_index (i, sm->per_thread_data)
234 tsm = vec_elt_at_index (sm->per_thread_data, i);
235 vlib_cli_output (vm, "-------- thread %d %s --------\n",
236 i, vlib_worker_threads[i].name);
237 if (sm->endpoint_dependent)
239 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->in2out_ed,
244 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->in2out, verbose);
245 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->out2in, verbose);
247 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->user_hash, verbose);
250 if (sm->endpoint_dependent)
252 vlib_cli_output (vm, "%U", format_bihash_16_8, &nam->affinity_hash,
258 static clib_error_t *
259 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
260 unformat_input_t * input,
261 vlib_cli_command_t * cmd)
263 unformat_input_t _line_input, *line_input = &_line_input;
264 snat_main_t *sm = &snat_main;
265 clib_error_t *error = 0;
266 u32 psid, psid_offset, psid_length, port_start, port_end;
268 if (sm->deterministic)
269 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
271 /* Get a line of input. */
272 if (!unformat_user (input, unformat_line_input, line_input))
275 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
277 if (unformat (line_input, "default"))
278 nat_set_alloc_addr_and_port_default ();
281 (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
282 &psid_offset, &psid_length))
283 nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
287 (line_input, "port-range %d - %d", &port_start, &port_end))
289 if (port_end <= port_start)
292 clib_error_return (0,
293 "The end-port must be greater than start-port");
296 nat_set_alloc_addr_and_port_range ((u16) port_start,
301 error = clib_error_return (0, "unknown input '%U'",
302 format_unformat_error, line_input);
308 unformat_free (line_input);
313 static clib_error_t *
314 nat44_show_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
315 unformat_input_t * input,
316 vlib_cli_command_t * cmd)
318 snat_main_t *sm = &snat_main;
320 if (sm->deterministic)
321 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
323 vlib_cli_output (vm, "NAT address and port: %U",
324 format_nat_addr_and_port_alloc_alg,
325 sm->addr_and_port_alloc_alg);
326 switch (sm->addr_and_port_alloc_alg)
328 case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
329 vlib_cli_output (vm, " psid %d psid-offset %d psid-len %d", sm->psid,
330 sm->psid_offset, sm->psid_length);
332 case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
333 vlib_cli_output (vm, " start-port %d end-port %d", sm->start_port,
343 static clib_error_t *
344 nat_set_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
345 vlib_cli_command_t * cmd)
347 unformat_input_t _line_input, *line_input = &_line_input;
348 snat_main_t *sm = &snat_main;
349 clib_error_t *error = 0;
352 /* Get a line of input. */
353 if (!unformat_user (input, unformat_line_input, line_input))
356 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
358 if (unformat (line_input, "disable"))
359 sm->mss_clamping = 0;
360 else if (unformat (line_input, "%d", &mss))
362 sm->mss_clamping = (u16) mss;
363 sm->mss_value_net = clib_host_to_net_u16 (sm->mss_clamping);
367 error = clib_error_return (0, "unknown input '%U'",
368 format_unformat_error, line_input);
374 unformat_free (line_input);
379 static clib_error_t *
380 nat_show_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
381 vlib_cli_command_t * cmd)
383 snat_main_t *sm = &snat_main;
385 if (sm->mss_clamping)
386 vlib_cli_output (vm, "mss-clamping %d", sm->mss_clamping);
388 vlib_cli_output (vm, "mss-clamping disabled");
393 static clib_error_t *
394 nat_ha_failover_command_fn (vlib_main_t * vm, unformat_input_t * input,
395 vlib_cli_command_t * cmd)
397 unformat_input_t _line_input, *line_input = &_line_input;
399 u32 port, session_refresh_interval = 10;
401 clib_error_t *error = 0;
403 /* Get a line of input. */
404 if (!unformat_user (input, unformat_line_input, line_input))
407 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
409 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
413 (line_input, "refresh-interval %u", &session_refresh_interval))
417 error = clib_error_return (0, "unknown input '%U'",
418 format_unformat_error, line_input);
423 rv = nat_ha_set_failover (&addr, (u16) port, session_refresh_interval);
425 error = clib_error_return (0, "set HA failover failed");
428 unformat_free (line_input);
433 static clib_error_t *
434 nat_ha_listener_command_fn (vlib_main_t * vm, unformat_input_t * input,
435 vlib_cli_command_t * cmd)
437 unformat_input_t _line_input, *line_input = &_line_input;
439 u32 port, path_mtu = 512;
441 clib_error_t *error = 0;
443 /* Get a line of input. */
444 if (!unformat_user (input, unformat_line_input, line_input))
447 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
449 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
451 else if (unformat (line_input, "path-mtu %u", &path_mtu))
455 error = clib_error_return (0, "unknown input '%U'",
456 format_unformat_error, line_input);
461 rv = nat_ha_set_listener (&addr, (u16) port, path_mtu);
463 error = clib_error_return (0, "set HA listener failed");
466 unformat_free (line_input);
471 static clib_error_t *
472 nat_show_ha_command_fn (vlib_main_t * vm, unformat_input_t * input,
473 vlib_cli_command_t * cmd)
477 u32 path_mtu, session_refresh_interval, resync_ack_missed;
480 nat_ha_get_listener (&addr, &port, &path_mtu);
483 vlib_cli_output (vm, "NAT HA disabled\n");
487 vlib_cli_output (vm, "LISTENER:\n");
488 vlib_cli_output (vm, " %U:%u path-mtu %u\n",
489 format_ip4_address, &addr, port, path_mtu);
491 nat_ha_get_failover (&addr, &port, &session_refresh_interval);
492 vlib_cli_output (vm, "FAILOVER:\n");
494 vlib_cli_output (vm, " %U:%u refresh-interval %usec\n",
495 format_ip4_address, &addr, port,
496 session_refresh_interval);
498 vlib_cli_output (vm, " NA\n");
500 nat_ha_get_resync_status (&in_resync, &resync_ack_missed);
501 vlib_cli_output (vm, "RESYNC:\n");
503 vlib_cli_output (vm, " in progress\n");
505 vlib_cli_output (vm, " completed (%d ACK missed)\n", resync_ack_missed);
510 static clib_error_t *
511 nat_ha_flush_command_fn (vlib_main_t * vm, unformat_input_t * input,
512 vlib_cli_command_t * cmd)
518 static clib_error_t *
519 nat_ha_resync_command_fn (vlib_main_t * vm, unformat_input_t * input,
520 vlib_cli_command_t * cmd)
522 clib_error_t *error = 0;
524 if (nat_ha_resync (0, 0, 0))
525 error = clib_error_return (0, "NAT HA resync already running");
530 static clib_error_t *
531 add_address_command_fn (vlib_main_t * vm,
532 unformat_input_t * input, vlib_cli_command_t * cmd)
534 unformat_input_t _line_input, *line_input = &_line_input;
535 snat_main_t *sm = &snat_main;
536 ip4_address_t start_addr, end_addr, this_addr;
537 u32 start_host_order, end_host_order;
542 clib_error_t *error = 0;
545 if (sm->deterministic)
546 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
548 /* Get a line of input. */
549 if (!unformat_user (input, unformat_line_input, line_input))
552 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
554 if (unformat (line_input, "%U - %U",
555 unformat_ip4_address, &start_addr,
556 unformat_ip4_address, &end_addr))
558 else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
560 else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
561 end_addr = start_addr;
562 else if (unformat (line_input, "twice-nat"))
564 else if (unformat (line_input, "del"))
568 error = clib_error_return (0, "unknown input '%U'",
569 format_unformat_error, line_input);
574 if (sm->static_mapping_only)
576 error = clib_error_return (0, "static mapping only mode");
580 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
581 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
583 if (end_host_order < start_host_order)
585 error = clib_error_return (0, "end address less than start address");
589 count = (end_host_order - start_host_order) + 1;
592 nat_log_info ("%U - %U, %d addresses...",
593 format_ip4_address, &start_addr,
594 format_ip4_address, &end_addr, count);
596 this_addr = start_addr;
598 for (i = 0; i < count; i++)
601 rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
603 rv = snat_del_address (sm, this_addr, 0, twice_nat);
607 case VNET_API_ERROR_VALUE_EXIST:
608 error = clib_error_return (0, "NAT address already in use.");
610 case VNET_API_ERROR_NO_SUCH_ENTRY:
611 error = clib_error_return (0, "NAT address not exist.");
613 case VNET_API_ERROR_UNSPECIFIED:
615 clib_error_return (0, "NAT address used in static mapping.");
617 case VNET_API_ERROR_FEATURE_DISABLED:
619 clib_error_return (0,
620 "twice NAT available only for endpoint-dependent mode.");
627 nat44_add_del_address_dpo (this_addr, is_add);
629 increment_v4_address (&this_addr);
633 unformat_free (line_input);
638 static clib_error_t *
639 nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
640 vlib_cli_command_t * cmd)
642 snat_main_per_thread_data_t *tsm;
643 snat_main_t *sm = &snat_main;
646 if (sm->deterministic || !sm->endpoint_dependent)
647 return clib_error_return (0, UNSUPPORTED_IN_DET_OR_NON_ED_MODE_STR);
649 // print session configuration values
650 vlib_cli_output (vm, "max translations: %u", sm->max_translations);
651 vlib_cli_output (vm, "max translations per user: %u",
652 sm->max_translations_per_user);
656 u64 now = vlib_time_now (vm);
657 u64 sess_timeout_time;
659 u32 udp_sessions = 0;
660 u32 tcp_sessions = 0;
661 u32 icmp_sessions = 0;
665 u32 transitory_wait_closed = 0;
666 u32 transitory_closed = 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 NAT_PROTOCOL_ICMP:
686 case NAT_PROTOCOL_TCP:
690 if (s->tcp_closed_timestamp)
692 if (now >= s->tcp_closed_timestamp)
698 ++transitory_wait_closed;
706 case NAT_PROTOCOL_UDP:
712 count += pool_elts (tsm->sessions);
718 tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
720 pool_foreach (s, tsm->sessions,
722 sess_timeout_time = s->last_heard +
723 (f64) nat44_session_get_timeout (sm, s);
724 if (now >= sess_timeout_time)
727 switch (s->in2out.protocol)
729 case NAT_PROTOCOL_ICMP:
732 case NAT_PROTOCOL_TCP:
736 if (s->tcp_closed_timestamp)
738 if (now >= s->tcp_closed_timestamp)
744 ++transitory_wait_closed;
752 case NAT_PROTOCOL_UDP:
759 count = pool_elts (tsm->sessions);
760 if (sm->endpoint_dependent)
762 dlist_elt_t *oldest_elt;
766 clib_dlist_remove_head (tsm->lru_pool, tsm->n##_lru_head_index); \
767 if (~0 != oldest_index) \
769 oldest_elt = pool_elt_at_index (tsm->lru_pool, oldest_index); \
770 s = pool_elt_at_index (tsm->sessions, oldest_elt->value); \
771 sess_timeout_time = \
772 s->last_heard + (f64)nat44_session_get_timeout (sm, s); \
773 vlib_cli_output (vm, d " LRU min session timeout %llu (now %llu)", \
774 sess_timeout_time, now); \
775 clib_dlist_addhead (tsm->lru_pool, tsm->n##_lru_head_index, \
778 _(tcp_estab, "established tcp");
779 _(tcp_trans, "transitory tcp");
781 _(unk_proto, "unknown protocol");
787 vlib_cli_output (vm, "total timed out sessions: %u", timed_out);
788 vlib_cli_output (vm, "total sessions: %u", count);
789 vlib_cli_output (vm, "total tcp sessions: %u", tcp_sessions);
790 vlib_cli_output (vm, "total tcp established sessions: %u", established);
791 vlib_cli_output (vm, "total tcp transitory sessions: %u", transitory);
792 vlib_cli_output (vm, "total tcp transitory (WAIT-CLOSED) sessions: %u",
793 transitory_wait_closed);
794 vlib_cli_output (vm, "total tcp transitory (CLOSED) sessions: %u",
796 vlib_cli_output (vm, "total udp sessions: %u", udp_sessions);
797 vlib_cli_output (vm, "total icmp sessions: %u", icmp_sessions);
801 static clib_error_t *
802 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
803 vlib_cli_command_t * cmd)
805 snat_main_t *sm = &snat_main;
808 if (sm->deterministic)
809 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
811 vlib_cli_output (vm, "NAT44 pool addresses:");
813 vec_foreach (ap, sm->addresses)
815 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
816 if (ap->fib_index != ~0)
817 vlib_cli_output (vm, " tenant VRF: %u",
818 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
820 vlib_cli_output (vm, " tenant VRF independent");
821 #define _(N, i, n, s) \
822 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
826 vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
827 vec_foreach (ap, sm->twice_nat_addresses)
829 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
830 if (ap->fib_index != ~0)
831 vlib_cli_output (vm, " tenant VRF: %u",
832 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
834 vlib_cli_output (vm, " tenant VRF independent");
835 #define _(N, i, n, s) \
836 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
844 static clib_error_t *
845 snat_feature_command_fn (vlib_main_t * vm,
846 unformat_input_t * input, vlib_cli_command_t * cmd)
848 unformat_input_t _line_input, *line_input = &_line_input;
849 vnet_main_t *vnm = vnet_get_main ();
850 clib_error_t *error = 0;
852 u32 *inside_sw_if_indices = 0;
853 u32 *outside_sw_if_indices = 0;
854 u8 is_output_feature = 0;
860 /* Get a line of input. */
861 if (!unformat_user (input, unformat_line_input, line_input))
864 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
866 if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
868 vec_add1 (inside_sw_if_indices, sw_if_index);
869 else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
871 vec_add1 (outside_sw_if_indices, sw_if_index);
872 else if (unformat (line_input, "output-feature"))
873 is_output_feature = 1;
874 else if (unformat (line_input, "del"))
878 error = clib_error_return (0, "unknown input '%U'",
879 format_unformat_error, line_input);
884 if (vec_len (inside_sw_if_indices))
886 for (i = 0; i < vec_len (inside_sw_if_indices); i++)
888 sw_if_index = inside_sw_if_indices[i];
889 if (is_output_feature)
891 if (snat_interface_add_del_output_feature
892 (sw_if_index, 1, is_del))
894 error = clib_error_return (0, "%s %U failed",
895 is_del ? "del" : "add",
896 format_vnet_sw_if_index_name,
903 if (snat_interface_add_del (sw_if_index, 1, is_del))
905 error = clib_error_return (0, "%s %U failed",
906 is_del ? "del" : "add",
907 format_vnet_sw_if_index_name,
915 if (vec_len (outside_sw_if_indices))
917 for (i = 0; i < vec_len (outside_sw_if_indices); i++)
919 sw_if_index = outside_sw_if_indices[i];
920 if (is_output_feature)
922 if (snat_interface_add_del_output_feature
923 (sw_if_index, 0, is_del))
925 error = clib_error_return (0, "%s %U failed",
926 is_del ? "del" : "add",
927 format_vnet_sw_if_index_name,
934 if (snat_interface_add_del (sw_if_index, 0, is_del))
936 error = clib_error_return (0, "%s %U failed",
937 is_del ? "del" : "add",
938 format_vnet_sw_if_index_name,
947 unformat_free (line_input);
948 vec_free (inside_sw_if_indices);
949 vec_free (outside_sw_if_indices);
954 static clib_error_t *
955 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
956 vlib_cli_command_t * cmd)
958 snat_main_t *sm = &snat_main;
960 vnet_main_t *vnm = vnet_get_main ();
962 vlib_cli_output (vm, "NAT44 interfaces:");
964 pool_foreach (i, sm->interfaces,
966 vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
968 (nat_interface_is_inside(i) &&
969 nat_interface_is_outside(i)) ? "in out" :
970 (nat_interface_is_inside(i) ? "in" : "out"));
973 pool_foreach (i, sm->output_feature_interfaces,
975 vlib_cli_output (vm, " %U output-feature %s",
976 format_vnet_sw_if_index_name, vnm,
978 (nat_interface_is_inside(i) &&
979 nat_interface_is_outside(i)) ? "in out" :
980 (nat_interface_is_inside(i) ? "in" : "out"));
987 static clib_error_t *
988 add_static_mapping_command_fn (vlib_main_t * vm,
989 unformat_input_t * input,
990 vlib_cli_command_t * cmd)
992 unformat_input_t _line_input, *line_input = &_line_input;
993 snat_main_t *sm = &snat_main;
994 clib_error_t *error = 0;
995 ip4_address_t l_addr, e_addr;
996 u32 l_port = 0, e_port = 0, vrf_id = ~0;
999 u32 sw_if_index = ~0;
1000 vnet_main_t *vnm = vnet_get_main ();
1002 nat_protocol_t proto = NAT_PROTOCOL_OTHER;
1004 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1007 if (sm->deterministic)
1008 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1010 /* Get a line of input. */
1011 if (!unformat_user (input, unformat_line_input, line_input))
1014 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1016 if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
1020 if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
1022 else if (unformat (line_input, "external %U %u", unformat_ip4_address,
1025 else if (unformat (line_input, "external %U", unformat_ip4_address,
1028 else if (unformat (line_input, "external %U %u",
1029 unformat_vnet_sw_interface, vnm, &sw_if_index,
1033 else if (unformat (line_input, "external %U",
1034 unformat_vnet_sw_interface, vnm, &sw_if_index))
1036 else if (unformat (line_input, "vrf %u", &vrf_id))
1038 else if (unformat (line_input, "%U", unformat_nat_protocol, &proto))
1040 else if (unformat (line_input, "twice-nat"))
1041 twice_nat = TWICE_NAT;
1042 else if (unformat (line_input, "self-twice-nat"))
1043 twice_nat = TWICE_NAT_SELF;
1044 else if (unformat (line_input, "out2in-only"))
1046 else if (unformat (line_input, "del"))
1050 error = clib_error_return (0, "unknown input: '%U'",
1051 format_unformat_error, line_input);
1056 if (twice_nat && addr_only)
1058 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
1062 if (!addr_only && !proto_set)
1064 error = clib_error_return (0, "missing protocol");
1068 rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
1069 vrf_id, addr_only, sw_if_index, proto, is_add,
1070 twice_nat, out2in_only, 0, 0);
1074 case VNET_API_ERROR_INVALID_VALUE:
1075 error = clib_error_return (0, "External port already in use.");
1077 case VNET_API_ERROR_NO_SUCH_ENTRY:
1079 error = clib_error_return (0, "External address must be allocated.");
1081 error = clib_error_return (0, "Mapping not exist.");
1083 case VNET_API_ERROR_NO_SUCH_FIB:
1084 error = clib_error_return (0, "No such VRF id.");
1086 case VNET_API_ERROR_VALUE_EXIST:
1087 error = clib_error_return (0, "Mapping already exist.");
1089 case VNET_API_ERROR_FEATURE_DISABLED:
1091 clib_error_return (0,
1092 "twice-nat/out2in-only available only for endpoint-dependent mode.");
1099 unformat_free (line_input);
1104 static clib_error_t *
1105 add_identity_mapping_command_fn (vlib_main_t * vm,
1106 unformat_input_t * input,
1107 vlib_cli_command_t * cmd)
1109 unformat_input_t _line_input, *line_input = &_line_input;
1110 snat_main_t *sm = &snat_main;
1111 clib_error_t *error = 0;
1113 u32 port = 0, vrf_id = ~0;
1116 u32 sw_if_index = ~0;
1117 vnet_main_t *vnm = vnet_get_main ();
1119 nat_protocol_t proto;
1121 if (sm->deterministic)
1122 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1126 /* Get a line of input. */
1127 if (!unformat_user (input, unformat_line_input, line_input))
1130 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1132 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1134 else if (unformat (line_input, "external %U",
1135 unformat_vnet_sw_interface, vnm, &sw_if_index))
1137 else if (unformat (line_input, "vrf %u", &vrf_id))
1139 else if (unformat (line_input, "%U %u", unformat_nat_protocol, &proto,
1142 else if (unformat (line_input, "del"))
1146 error = clib_error_return (0, "unknown input: '%U'",
1147 format_unformat_error, line_input);
1152 rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
1153 vrf_id, addr_only, sw_if_index, proto, is_add,
1158 case VNET_API_ERROR_INVALID_VALUE:
1159 error = clib_error_return (0, "External port already in use.");
1161 case VNET_API_ERROR_NO_SUCH_ENTRY:
1163 error = clib_error_return (0, "External address must be allocated.");
1165 error = clib_error_return (0, "Mapping not exist.");
1167 case VNET_API_ERROR_NO_SUCH_FIB:
1168 error = clib_error_return (0, "No such VRF id.");
1170 case VNET_API_ERROR_VALUE_EXIST:
1171 error = clib_error_return (0, "Mapping already exist.");
1178 unformat_free (line_input);
1183 static clib_error_t *
1184 add_lb_static_mapping_command_fn (vlib_main_t * vm,
1185 unformat_input_t * input,
1186 vlib_cli_command_t * cmd)
1188 unformat_input_t _line_input, *line_input = &_line_input;
1189 snat_main_t *sm = &snat_main;
1190 clib_error_t *error = 0;
1191 ip4_address_t l_addr, e_addr;
1192 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
1195 nat_protocol_t proto;
1197 nat44_lb_addr_port_t *locals = 0, local;
1198 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1201 if (sm->deterministic)
1202 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1204 /* Get a line of input. */
1205 if (!unformat_user (input, unformat_line_input, line_input))
1208 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1210 if (unformat (line_input, "local %U:%u probability %u",
1211 unformat_ip4_address, &l_addr, &l_port, &probability))
1213 clib_memset (&local, 0, sizeof (local));
1214 local.addr = l_addr;
1215 local.port = (u16) l_port;
1216 local.probability = (u8) probability;
1217 vec_add1 (locals, local);
1219 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1220 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1223 clib_memset (&local, 0, sizeof (local));
1224 local.addr = l_addr;
1225 local.port = (u16) l_port;
1226 local.probability = (u8) probability;
1227 local.vrf_id = vrf_id;
1228 vec_add1 (locals, local);
1230 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1233 else if (unformat (line_input, "protocol %U", unformat_nat_protocol,
1236 else if (unformat (line_input, "twice-nat"))
1237 twice_nat = TWICE_NAT;
1238 else if (unformat (line_input, "self-twice-nat"))
1239 twice_nat = TWICE_NAT_SELF;
1240 else if (unformat (line_input, "out2in-only"))
1242 else if (unformat (line_input, "del"))
1244 else if (unformat (line_input, "affinity %u", &affinity))
1248 error = clib_error_return (0, "unknown input: '%U'",
1249 format_unformat_error, line_input);
1254 if (vec_len (locals) < 2)
1256 error = clib_error_return (0, "at least two local must be set");
1262 error = clib_error_return (0, "missing protocol");
1266 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, locals,
1267 is_add, twice_nat, out2in_only, 0,
1272 case VNET_API_ERROR_INVALID_VALUE:
1273 error = clib_error_return (0, "External port already in use.");
1275 case VNET_API_ERROR_NO_SUCH_ENTRY:
1277 error = clib_error_return (0, "External address must be allocated.");
1279 error = clib_error_return (0, "Mapping not exist.");
1281 case VNET_API_ERROR_VALUE_EXIST:
1282 error = clib_error_return (0, "Mapping already exist.");
1284 case VNET_API_ERROR_FEATURE_DISABLED:
1286 clib_error_return (0, "Available only for endpoint-dependent mode.");
1293 unformat_free (line_input);
1299 static clib_error_t *
1300 add_lb_backend_command_fn (vlib_main_t * vm,
1301 unformat_input_t * input, vlib_cli_command_t * cmd)
1303 unformat_input_t _line_input, *line_input = &_line_input;
1304 snat_main_t *sm = &snat_main;
1305 clib_error_t *error = 0;
1306 ip4_address_t l_addr, e_addr;
1307 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
1310 nat_protocol_t proto;
1313 if (sm->deterministic)
1314 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1316 /* Get a line of input. */
1317 if (!unformat_user (input, unformat_line_input, line_input))
1320 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1322 if (unformat (line_input, "local %U:%u probability %u",
1323 unformat_ip4_address, &l_addr, &l_port, &probability))
1325 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1326 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1329 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1332 else if (unformat (line_input, "protocol %U", unformat_nat_protocol,
1335 else if (unformat (line_input, "del"))
1339 error = clib_error_return (0, "unknown input: '%U'",
1340 format_unformat_error, line_input);
1345 if (!l_port || !e_port)
1347 error = clib_error_return (0, "local or external must be set");
1353 error = clib_error_return (0, "missing protocol");
1358 nat44_lb_static_mapping_add_del_local (e_addr, (u16) e_port, l_addr,
1359 l_port, proto, vrf_id, probability,
1364 case VNET_API_ERROR_INVALID_VALUE:
1365 error = clib_error_return (0, "External is not load-balancing static "
1368 case VNET_API_ERROR_NO_SUCH_ENTRY:
1369 error = clib_error_return (0, "Mapping or back-end not exist.");
1371 case VNET_API_ERROR_VALUE_EXIST:
1372 error = clib_error_return (0, "Back-end already exist.");
1374 case VNET_API_ERROR_FEATURE_DISABLED:
1376 clib_error_return (0, "Available only for endpoint-dependent mode.");
1378 case VNET_API_ERROR_UNSPECIFIED:
1379 error = clib_error_return (0, "At least two back-ends must remain");
1386 unformat_free (line_input);
1391 static clib_error_t *
1392 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
1393 unformat_input_t * input,
1394 vlib_cli_command_t * cmd)
1396 snat_main_t *sm = &snat_main;
1397 snat_static_mapping_t *m;
1398 snat_static_map_resolve_t *rp;
1400 if (sm->deterministic)
1401 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1403 vlib_cli_output (vm, "NAT44 static mappings:");
1405 pool_foreach (m, sm->static_mappings,
1407 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
1409 vec_foreach (rp, sm->to_resolve)
1410 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
1416 static clib_error_t *
1417 snat_add_interface_address_command_fn (vlib_main_t * vm,
1418 unformat_input_t * input,
1419 vlib_cli_command_t * cmd)
1421 snat_main_t *sm = &snat_main;
1422 unformat_input_t _line_input, *line_input = &_line_input;
1426 clib_error_t *error = 0;
1429 if (sm->deterministic)
1430 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1432 /* Get a line of input. */
1433 if (!unformat_user (input, unformat_line_input, line_input))
1436 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1438 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
1439 sm->vnet_main, &sw_if_index))
1441 else if (unformat (line_input, "twice-nat"))
1443 else if (unformat (line_input, "del"))
1447 error = clib_error_return (0, "unknown input '%U'",
1448 format_unformat_error, line_input);
1453 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
1461 error = clib_error_return (0, "snat_add_interface_address returned %d",
1467 unformat_free (line_input);
1472 static clib_error_t *
1473 nat44_show_interface_address_command_fn (vlib_main_t * vm,
1474 unformat_input_t * input,
1475 vlib_cli_command_t * cmd)
1477 snat_main_t *sm = &snat_main;
1478 vnet_main_t *vnm = vnet_get_main ();
1481 if (sm->deterministic)
1482 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1485 vlib_cli_output (vm, "NAT44 pool address interfaces:");
1486 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
1488 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1491 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
1492 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
1494 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1502 static clib_error_t *
1503 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
1504 vlib_cli_command_t * cmd)
1506 unformat_input_t _line_input, *line_input = &_line_input;
1507 clib_error_t *error = 0;
1509 snat_main_per_thread_data_t *tsm;
1510 snat_main_t *sm = &snat_main;
1515 if (sm->deterministic)
1516 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1518 if (!unformat_user (input, unformat_line_input, line_input))
1521 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1523 if (unformat (line_input, "detail"))
1527 error = clib_error_return (0, "unknown input '%U'",
1528 format_unformat_error, line_input);
1532 unformat_free (line_input);
1535 if (!sm->endpoint_dependent)
1536 vlib_cli_output (vm, "NAT44 sessions:");
1538 vlib_cli_output (vm, "NAT44 ED sessions:");
1541 vec_foreach_index (i, sm->per_thread_data)
1543 tsm = vec_elt_at_index (sm->per_thread_data, i);
1545 vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
1546 i, vlib_worker_threads[i].name,
1547 pool_elts (tsm->sessions));
1549 if (!sm->endpoint_dependent)
1552 pool_foreach (u, tsm->users,
1554 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, detail);
1560 pool_foreach (s, tsm->sessions,
1562 vlib_cli_output (vm, " %U\n", format_snat_session, tsm, s);
1570 static clib_error_t *
1571 nat44_set_session_limit_command_fn (vlib_main_t * vm,
1572 unformat_input_t * input,
1573 vlib_cli_command_t * cmd)
1575 snat_main_t *sm = &snat_main;
1576 unformat_input_t _line_input, *line_input = &_line_input;
1577 clib_error_t *error = 0;
1579 u32 session_limit = 0, vrf_id = 0;
1581 if (sm->deterministic)
1582 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1584 /* Get a line of input. */
1585 if (!unformat_user (input, unformat_line_input, line_input))
1588 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1590 if (unformat (line_input, "%u", &session_limit))
1592 else if (unformat (line_input, "vrf %u", &vrf_id))
1596 error = clib_error_return (0, "unknown input '%U'",
1597 format_unformat_error, line_input);
1603 error = clib_error_return (0, "missing value of session limit");
1604 else if (nat44_set_session_limit (session_limit, vrf_id))
1605 error = clib_error_return (0, "nat44_set_session_limit failed");
1608 unformat_free (line_input);
1613 static clib_error_t *
1614 nat44_del_user_command_fn (vlib_main_t * vm,
1615 unformat_input_t * input, vlib_cli_command_t * cmd)
1617 snat_main_t *sm = &snat_main;
1618 unformat_input_t _line_input, *line_input = &_line_input;
1619 clib_error_t *error = 0;
1624 if (sm->deterministic || sm->endpoint_dependent)
1625 return clib_error_return (0, UNSUPPORTED_IN_DET_OR_ED_MODE_STR);
1627 /* Get a line of input. */
1628 if (!unformat_user (input, unformat_line_input, line_input))
1631 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1633 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1635 else if (unformat (line_input, "fib %u", &fib_index))
1639 error = clib_error_return (0, "unknown input '%U'",
1640 format_unformat_error, line_input);
1645 rv = nat44_user_del (&addr, fib_index);
1649 error = clib_error_return (0, "nat44_user_del returned %d", rv);
1653 unformat_free (line_input);
1658 static clib_error_t *
1659 nat44_clear_sessions_command_fn (vlib_main_t * vm,
1660 unformat_input_t * input,
1661 vlib_cli_command_t * cmd)
1663 snat_main_t *sm = &snat_main;
1664 clib_error_t *error = 0;
1666 if (sm->deterministic)
1667 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1669 nat44_sessions_clear ();
1673 static clib_error_t *
1674 nat44_del_session_command_fn (vlib_main_t * vm,
1675 unformat_input_t * input,
1676 vlib_cli_command_t * cmd)
1678 snat_main_t *sm = &snat_main;
1679 unformat_input_t _line_input, *line_input = &_line_input;
1680 int is_in = 0, is_ed = 0;
1681 clib_error_t *error = 0;
1682 ip4_address_t addr, eh_addr;
1683 u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
1684 nat_protocol_t proto;
1687 if (sm->deterministic)
1688 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1690 /* Get a line of input. */
1691 if (!unformat_user (input, unformat_line_input, line_input))
1694 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1697 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1698 unformat_nat_protocol, &proto))
1700 else if (unformat (line_input, "in"))
1703 vrf_id = sm->inside_vrf_id;
1705 else if (unformat (line_input, "out"))
1708 vrf_id = sm->outside_vrf_id;
1710 else if (unformat (line_input, "vrf %u", &vrf_id))
1714 (line_input, "external-host %U:%u", unformat_ip4_address,
1715 &eh_addr, &eh_port))
1719 error = clib_error_return (0, "unknown input '%U'",
1720 format_unformat_error, line_input);
1727 nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port,
1728 nat_proto_to_ip_proto (proto), vrf_id, is_in);
1730 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
1738 error = clib_error_return (0, "nat44_del_session returned %d", rv);
1743 unformat_free (line_input);
1748 static clib_error_t *
1749 snat_forwarding_set_command_fn (vlib_main_t * vm,
1750 unformat_input_t * input,
1751 vlib_cli_command_t * cmd)
1753 snat_main_t *sm = &snat_main;
1754 unformat_input_t _line_input, *line_input = &_line_input;
1755 u8 forwarding_enable;
1756 u8 forwarding_enable_set = 0;
1757 clib_error_t *error = 0;
1759 if (sm->deterministic)
1760 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1762 /* Get a line of input. */
1763 if (!unformat_user (input, unformat_line_input, line_input))
1764 return clib_error_return (0, "'enable' or 'disable' expected");
1766 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1768 if (!forwarding_enable_set && unformat (line_input, "enable"))
1770 forwarding_enable = 1;
1771 forwarding_enable_set = 1;
1773 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1775 forwarding_enable = 0;
1776 forwarding_enable_set = 1;
1780 error = clib_error_return (0, "unknown input '%U'",
1781 format_unformat_error, line_input);
1786 if (!forwarding_enable_set)
1788 error = clib_error_return (0, "'enable' or 'disable' expected");
1792 sm->forwarding_enabled = forwarding_enable;
1795 unformat_free (line_input);
1800 static clib_error_t *
1801 snat_det_map_command_fn (vlib_main_t * vm,
1802 unformat_input_t * input, vlib_cli_command_t * cmd)
1804 snat_main_t *sm = &snat_main;
1805 unformat_input_t _line_input, *line_input = &_line_input;
1806 ip4_address_t in_addr, out_addr;
1807 u32 in_plen, out_plen;
1809 clib_error_t *error = 0;
1811 if (!sm->deterministic)
1812 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1814 /* Get a line of input. */
1815 if (!unformat_user (input, unformat_line_input, line_input))
1818 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1821 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1825 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1828 else if (unformat (line_input, "del"))
1832 error = clib_error_return (0, "unknown input '%U'",
1833 format_unformat_error, line_input);
1838 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1843 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1848 unformat_free (line_input);
1853 static clib_error_t *
1854 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1855 unformat_input_t * input,
1856 vlib_cli_command_t * cmd)
1858 snat_main_t *sm = &snat_main;
1861 if (!sm->deterministic)
1862 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1864 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1866 pool_foreach (dm, sm->det_maps,
1868 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1869 format_ip4_address, &dm->in_addr, dm->in_plen,
1870 format_ip4_address, &dm->out_addr, dm->out_plen);
1871 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1873 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1874 dm->ports_per_host);
1875 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1882 static clib_error_t *
1883 snat_det_forward_command_fn (vlib_main_t * vm,
1884 unformat_input_t * input,
1885 vlib_cli_command_t * cmd)
1887 snat_main_t *sm = &snat_main;
1888 unformat_input_t _line_input, *line_input = &_line_input;
1889 ip4_address_t in_addr, out_addr;
1892 clib_error_t *error = 0;
1894 if (!sm->deterministic)
1895 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1897 /* Get a line of input. */
1898 if (!unformat_user (input, unformat_line_input, line_input))
1901 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1903 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1907 error = clib_error_return (0, "unknown input '%U'",
1908 format_unformat_error, line_input);
1913 dm = snat_det_map_by_user (sm, &in_addr);
1915 vlib_cli_output (vm, "no match");
1918 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1919 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1920 lo_port, lo_port + dm->ports_per_host - 1);
1924 unformat_free (line_input);
1929 static clib_error_t *
1930 snat_det_reverse_command_fn (vlib_main_t * vm,
1931 unformat_input_t * input,
1932 vlib_cli_command_t * cmd)
1934 snat_main_t *sm = &snat_main;
1935 unformat_input_t _line_input, *line_input = &_line_input;
1936 ip4_address_t in_addr, out_addr;
1939 clib_error_t *error = 0;
1941 if (!sm->deterministic)
1942 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1944 /* Get a line of input. */
1945 if (!unformat_user (input, unformat_line_input, line_input))
1948 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1951 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1955 error = clib_error_return (0, "unknown input '%U'",
1956 format_unformat_error, line_input);
1961 if (out_port < 1024 || out_port > 65535)
1963 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1967 dm = snat_det_map_by_out (sm, &out_addr);
1969 vlib_cli_output (vm, "no match");
1972 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1973 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1977 unformat_free (line_input);
1982 static clib_error_t *
1983 set_timeout_command_fn (vlib_main_t * vm,
1984 unformat_input_t * input, vlib_cli_command_t * cmd)
1986 snat_main_t *sm = &snat_main;
1987 unformat_input_t _line_input, *line_input = &_line_input;
1988 clib_error_t *error = 0;
1990 /* Get a line of input. */
1991 if (!unformat_user (input, unformat_line_input, line_input))
1994 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1996 if (unformat (line_input, "udp %u", &sm->udp_timeout))
1998 if (nat64_set_udp_timeout (sm->udp_timeout))
2000 error = clib_error_return (0, "Invalid UDP timeout value");
2004 else if (unformat (line_input, "tcp-established %u",
2005 &sm->tcp_established_timeout))
2007 if (nat64_set_tcp_timeouts
2008 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
2011 clib_error_return (0,
2012 "Invalid TCP established timeouts value");
2016 else if (unformat (line_input, "tcp-transitory %u",
2017 &sm->tcp_transitory_timeout))
2019 if (nat64_set_tcp_timeouts
2020 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
2023 clib_error_return (0,
2024 "Invalid TCP transitory timeouts value");
2028 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
2030 if (nat64_set_icmp_timeout (sm->icmp_timeout))
2032 error = clib_error_return (0, "Invalid ICMP timeout value");
2036 else if (unformat (line_input, "reset"))
2038 sm->udp_timeout = SNAT_UDP_TIMEOUT;
2039 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
2040 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
2041 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
2042 nat64_set_udp_timeout (0);
2043 nat64_set_icmp_timeout (0);
2044 nat64_set_tcp_timeouts (0, 0);
2048 error = clib_error_return (0, "unknown input '%U'",
2049 format_unformat_error, line_input);
2054 unformat_free (line_input);
2058 static clib_error_t *
2059 nat_show_timeouts_command_fn (vlib_main_t * vm,
2060 unformat_input_t * input,
2061 vlib_cli_command_t * cmd)
2063 snat_main_t *sm = &snat_main;
2065 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
2066 vlib_cli_output (vm, "tcp-established timeout: %dsec",
2067 sm->tcp_established_timeout);
2068 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
2069 sm->tcp_transitory_timeout);
2070 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
2075 static clib_error_t *
2076 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
2077 unformat_input_t * input,
2078 vlib_cli_command_t * cmd)
2080 snat_main_t *sm = &snat_main;
2082 snat_det_session_t *ses;
2085 if (!sm->deterministic)
2086 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2088 vlib_cli_output (vm, "NAT44 deterministic sessions:");
2090 pool_foreach (dm, sm->det_maps,
2092 vec_foreach_index (i, dm->sessions)
2094 ses = vec_elt_at_index (dm->sessions, i);
2096 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
2103 static clib_error_t *
2104 snat_det_close_session_out_fn (vlib_main_t * vm,
2105 unformat_input_t * input,
2106 vlib_cli_command_t * cmd)
2108 snat_main_t *sm = &snat_main;
2109 unformat_input_t _line_input, *line_input = &_line_input;
2110 ip4_address_t out_addr, ext_addr, in_addr;
2111 u32 out_port, ext_port;
2113 snat_det_session_t *ses;
2114 snat_det_out_key_t key;
2115 clib_error_t *error = 0;
2117 if (!sm->deterministic)
2118 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2120 /* Get a line of input. */
2121 if (!unformat_user (input, unformat_line_input, line_input))
2124 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2126 if (unformat (line_input, "%U:%d %U:%d",
2127 unformat_ip4_address, &out_addr, &out_port,
2128 unformat_ip4_address, &ext_addr, &ext_port))
2132 error = clib_error_return (0, "unknown input '%U'",
2133 format_unformat_error, line_input);
2138 unformat_free (line_input);
2140 dm = snat_det_map_by_out (sm, &out_addr);
2142 vlib_cli_output (vm, "no match");
2145 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
2146 key.ext_host_addr = out_addr;
2147 key.ext_host_port = ntohs ((u16) ext_port);
2148 key.out_port = ntohs ((u16) out_port);
2149 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
2151 vlib_cli_output (vm, "no match");
2153 snat_det_ses_close (dm, ses);
2157 unformat_free (line_input);
2162 static clib_error_t *
2163 snat_det_close_session_in_fn (vlib_main_t * vm,
2164 unformat_input_t * input,
2165 vlib_cli_command_t * cmd)
2167 snat_main_t *sm = &snat_main;
2168 unformat_input_t _line_input, *line_input = &_line_input;
2169 ip4_address_t in_addr, ext_addr;
2170 u32 in_port, ext_port;
2172 snat_det_session_t *ses;
2173 snat_det_out_key_t key;
2174 clib_error_t *error = 0;
2176 if (!sm->deterministic)
2177 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2179 /* Get a line of input. */
2180 if (!unformat_user (input, unformat_line_input, line_input))
2183 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2185 if (unformat (line_input, "%U:%d %U:%d",
2186 unformat_ip4_address, &in_addr, &in_port,
2187 unformat_ip4_address, &ext_addr, &ext_port))
2191 error = clib_error_return (0, "unknown input '%U'",
2192 format_unformat_error, line_input);
2197 unformat_free (line_input);
2199 dm = snat_det_map_by_user (sm, &in_addr);
2201 vlib_cli_output (vm, "no match");
2204 key.ext_host_addr = ext_addr;
2205 key.ext_host_port = ntohs ((u16) ext_port);
2207 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
2209 vlib_cli_output (vm, "no match");
2211 snat_det_ses_close (dm, ses);
2215 unformat_free (line_input);
2223 * @cliexstart{set snat workers}
2224 * Set NAT workers if 2 or more workers available, use:
2225 * vpp# set snat workers 0-2,5
2228 VLIB_CLI_COMMAND (set_workers_command, static) = {
2229 .path = "set nat workers",
2230 .function = set_workers_command_fn,
2231 .short_help = "set nat workers <workers-list>",
2236 * @cliexstart{show nat workers}
2238 * vpp# show nat workers:
2244 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
2245 .path = "show nat workers",
2246 .short_help = "show nat workers",
2247 .function = nat_show_workers_commnad_fn,
2252 * @cliexstart{set nat timeout}
2253 * Set values of timeouts for NAT sessions (in seconds), use:
2254 * vpp# set nat timeout udp 120 tcp-established 7500 tcp-transitory 250 icmp 90
2255 * To reset default values use:
2256 * vpp# set nat44 deterministic timeout reset
2259 VLIB_CLI_COMMAND (set_timeout_command, static) = {
2260 .path = "set nat timeout",
2261 .function = set_timeout_command_fn,
2263 "set nat timeout [udp <sec> | tcp-established <sec> "
2264 "tcp-transitory <sec> | icmp <sec> | reset]",
2269 * @cliexstart{show nat timeouts}
2270 * Show values of timeouts for NAT sessions.
2271 * vpp# show nat timeouts
2272 * udp timeout: 300sec
2273 * tcp-established timeout: 7440sec
2274 * tcp-transitory timeout: 240sec
2275 * icmp timeout: 60sec
2278 VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = {
2279 .path = "show nat timeouts",
2280 .short_help = "show nat timeouts",
2281 .function = nat_show_timeouts_command_fn,
2286 * @cliexstart{nat set logging level}
2287 * To set NAT logging level use:
2288 * Set nat logging level
2291 VLIB_CLI_COMMAND (snat_set_log_level_command, static) = {
2292 .path = "nat set logging level",
2293 .function = snat_set_log_level_command_fn,
2294 .short_help = "nat set logging level <level>",
2299 * @cliexstart{snat ipfix logging}
2300 * To enable NAT IPFIX logging use:
2301 * vpp# nat ipfix logging
2302 * To set IPFIX exporter use:
2303 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
2306 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
2307 .path = "nat ipfix logging",
2308 .function = snat_ipfix_logging_enable_disable_command_fn,
2309 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
2314 * @cliexstart{nat addr-port-assignment-alg}
2315 * Set address and port assignment algorithm
2316 * For the MAP-E CE limit port choice based on PSID use:
2317 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
2318 * For port range use:
2319 * vpp# nat addr-port-assignment-alg port-range <start-port> - <end-port>
2320 * To set standard (default) address and port assignment algorithm use:
2321 * vpp# nat addr-port-assignment-alg default
2324 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
2325 .path = "nat addr-port-assignment-alg",
2326 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
2327 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
2332 * @cliexstart{show nat addr-port-assignment-alg}
2333 * Show address and port assignment algorithm
2336 VLIB_CLI_COMMAND (nat44_show_alloc_addr_and_port_alg_command, static) = {
2337 .path = "show nat addr-port-assignment-alg",
2338 .short_help = "show nat addr-port-assignment-alg",
2339 .function = nat44_show_alloc_addr_and_port_alg_command_fn,
2344 * @cliexstart{nat mss-clamping}
2345 * Set TCP MSS rewriting configuration
2346 * To enable TCP MSS rewriting use:
2347 * vpp# nat mss-clamping 1452
2348 * To disbale TCP MSS rewriting use:
2349 * vpp# nat mss-clamping disable
2352 VLIB_CLI_COMMAND (nat_set_mss_clamping_command, static) = {
2353 .path = "nat mss-clamping",
2354 .short_help = "nat mss-clamping <mss-value>|disable",
2355 .function = nat_set_mss_clamping_command_fn,
2360 * @cliexstart{show nat mss-clamping}
2361 * Show TCP MSS rewriting configuration
2364 VLIB_CLI_COMMAND (nat_show_mss_clamping_command, static) = {
2365 .path = "show nat mss-clamping",
2366 .short_help = "show nat mss-clamping",
2367 .function = nat_show_mss_clamping_command_fn,
2372 * @cliexstart{nat ha failover}
2373 * Set HA failover (remote settings)
2376 VLIB_CLI_COMMAND (nat_ha_failover_command, static) = {
2377 .path = "nat ha failover",
2378 .short_help = "nat ha failover <ip4-address>:<port> [refresh-interval <sec>]",
2379 .function = nat_ha_failover_command_fn,
2384 * @cliexstart{nat ha listener}
2385 * Set HA listener (local settings)
2388 VLIB_CLI_COMMAND (nat_ha_listener_command, static) = {
2389 .path = "nat ha listener",
2390 .short_help = "nat ha listener <ip4-address>:<port> [path-mtu <path-mtu>]",
2391 .function = nat_ha_listener_command_fn,
2396 * @cliexstart{show nat ha}
2397 * Show HA configuration/status
2400 VLIB_CLI_COMMAND (nat_show_ha_command, static) = {
2401 .path = "show nat ha",
2402 .short_help = "show nat ha",
2403 .function = nat_show_ha_command_fn,
2408 * @cliexstart{nat ha flush}
2409 * Flush the current HA data (for testing)
2412 VLIB_CLI_COMMAND (nat_ha_flush_command, static) = {
2413 .path = "nat ha flush",
2414 .short_help = "nat ha flush",
2415 .function = nat_ha_flush_command_fn,
2420 * @cliexstart{nat ha resync}
2421 * Resync HA (resend existing sessions to new failover)
2424 VLIB_CLI_COMMAND (nat_ha_resync_command, static) = {
2425 .path = "nat ha resync",
2426 .short_help = "nat ha resync",
2427 .function = nat_ha_resync_command_fn,
2432 * @cliexstart{show nat44 hash tables}
2433 * Show NAT44 hash tables
2436 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
2437 .path = "show nat44 hash tables",
2438 .short_help = "show nat44 hash tables [detail|verbose]",
2439 .function = nat44_show_hash_commnad_fn,
2444 * @cliexstart{nat44 add address}
2445 * Add/delete NAT44 pool address.
2446 * To add NAT44 pool address use:
2447 * vpp# nat44 add address 172.16.1.3
2448 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
2449 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
2450 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
2453 VLIB_CLI_COMMAND (add_address_command, static) = {
2454 .path = "nat44 add address",
2455 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
2456 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
2457 .function = add_address_command_fn,
2462 * @cliexstart{show nat44 summary}
2463 * Show NAT44 summary
2464 * vpp# show nat44 summary
2467 VLIB_CLI_COMMAND (nat44_show_summary_command, static) = {
2468 .path = "show nat44 summary",
2469 .short_help = "show nat44 summary",
2470 .function = nat44_show_summary_command_fn,
2475 * @cliexstart{show nat44 addresses}
2476 * Show NAT44 pool addresses.
2477 * vpp# show nat44 addresses
2478 * NAT44 pool addresses:
2480 * tenant VRF independent
2489 * NAT44 twice-nat pool addresses:
2491 * tenant VRF independent
2497 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
2498 .path = "show nat44 addresses",
2499 .short_help = "show nat44 addresses",
2500 .function = nat44_show_addresses_command_fn,
2505 * @cliexstart{set interface nat44}
2506 * Enable/disable NAT44 feature on the interface.
2507 * To enable NAT44 feature with local network interface use:
2508 * vpp# set interface nat44 in GigabitEthernet0/8/0
2509 * To enable NAT44 feature with external network interface use:
2510 * vpp# set interface nat44 out GigabitEthernet0/a/0
2513 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
2514 .path = "set interface nat44",
2515 .function = snat_feature_command_fn,
2516 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
2522 * @cliexstart{show nat44 interfaces}
2523 * Show interfaces with NAT44 feature.
2524 * vpp# show nat44 interfaces
2526 * GigabitEthernet0/8/0 in
2527 * GigabitEthernet0/a/0 out
2530 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
2531 .path = "show nat44 interfaces",
2532 .short_help = "show nat44 interfaces",
2533 .function = nat44_show_interfaces_command_fn,
2538 * @cliexstart{nat44 add static mapping}
2539 * Static mapping allows hosts on the external network to initiate connection
2540 * to to the local network host.
2541 * To create static mapping between local host address 10.0.0.3 port 6303 and
2542 * external address 4.4.4.4 port 3606 for TCP protocol use:
2543 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
2544 * If not runnig "static mapping only" NAT plugin mode use before:
2545 * vpp# nat44 add address 4.4.4.4
2546 * To create static mapping between local and external address use:
2547 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
2550 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
2551 .path = "nat44 add static mapping",
2552 .function = add_static_mapping_command_fn,
2554 "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
2555 "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
2556 "[out2in-only] [del]",
2561 * @cliexstart{nat44 add identity mapping}
2562 * Identity mapping translate an IP address to itself.
2563 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
2565 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
2566 * To create identity mapping for address 10.0.0.3 use:
2567 * vpp# nat44 add identity mapping 10.0.0.3
2568 * To create identity mapping for DHCP addressed interface use:
2569 * vpp# nat44 add identity mapping external GigabitEthernet0/a/0 tcp 3606
2572 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
2573 .path = "nat44 add identity mapping",
2574 .function = add_identity_mapping_command_fn,
2575 .short_help = "nat44 add identity mapping <ip4-addr>|external <interface> "
2576 "[<protocol> <port>] [vrf <table-id>] [del]",
2581 * @cliexstart{nat44 add load-balancing static mapping}
2582 * Service load balancing using NAT44
2583 * To add static mapping with load balancing for service with external IP
2584 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
2585 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
2586 * 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
2589 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
2590 .path = "nat44 add load-balancing static mapping",
2591 .function = add_lb_static_mapping_command_fn,
2593 "nat44 add load-balancing static mapping protocol tcp|udp "
2594 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2595 "probability <n> [twice-nat|self-twice-nat] [out2in-only] "
2596 "[affinity <timeout-seconds>] [del]",
2601 * @cliexstart{nat44 add load-balancing static mapping}
2602 * Modify service load balancing using NAT44
2603 * To add new back-end server 10.100.10.30:8080 for service load balancing
2604 * static mapping with external IP address 1.2.3.4 and TCP port 80 use:
2605 * vpp# nat44 add load-balancing back-end protocol tcp external 1.2.3.4:80 local 10.100.10.30:8080 probability 25
2608 VLIB_CLI_COMMAND (add_lb_backend_command, static) = {
2609 .path = "nat44 add load-balancing back-end",
2610 .function = add_lb_backend_command_fn,
2612 "nat44 add load-balancing back-end protocol tcp|udp "
2613 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2614 "probability <n> [del]",
2619 * @cliexstart{show nat44 static mappings}
2620 * Show NAT44 static mappings.
2621 * vpp# show nat44 static mappings
2622 * NAT44 static mappings:
2623 * local 10.0.0.3 external 4.4.4.4 vrf 0
2624 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
2625 * tcp vrf 0 external 1.2.3.4:80 out2in-only
2626 * local 10.100.10.10:8080 probability 80
2627 * local 10.100.10.20:8080 probability 20
2628 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
2629 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
2632 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
2633 .path = "show nat44 static mappings",
2634 .short_help = "show nat44 static mappings",
2635 .function = nat44_show_static_mappings_command_fn,
2640 * @cliexstart{nat44 add interface address}
2641 * Use NAT44 pool address from specific interfce
2642 * To add NAT44 pool address from specific interface use:
2643 * vpp# nat44 add interface address GigabitEthernet0/8/0
2646 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
2647 .path = "nat44 add interface address",
2648 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
2649 .function = snat_add_interface_address_command_fn,
2654 * @cliexstart{show nat44 interface address}
2655 * Show NAT44 pool address interfaces
2656 * vpp# show nat44 interface address
2657 * NAT44 pool address interfaces:
2658 * GigabitEthernet0/a/0
2659 * NAT44 twice-nat pool address interfaces:
2660 * GigabitEthernet0/8/0
2663 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
2664 .path = "show nat44 interface address",
2665 .short_help = "show nat44 interface address",
2666 .function = nat44_show_interface_address_command_fn,
2671 * @cliexstart{show nat44 sessions}
2672 * Show NAT44 sessions.
2675 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
2676 .path = "show nat44 sessions",
2677 .short_help = "show nat44 sessions [detail|metrics]",
2678 .function = nat44_show_sessions_command_fn,
2683 * @cliexstart{set nat44 session limit}
2684 * Set NAT44 session limit.
2687 VLIB_CLI_COMMAND (nat44_set_session_limit_command, static) = {
2688 .path = "set nat44 session limit",
2689 .short_help = "set nat44 session limit <limit> [vrf <table-id>]",
2690 .function = nat44_set_session_limit_command_fn,
2695 * @cliexstart{nat44 del user}
2696 * To delete all NAT44 user sessions:
2697 * vpp# nat44 del user 10.0.0.3
2700 VLIB_CLI_COMMAND (nat44_del_user_command, static) = {
2701 .path = "nat44 del user",
2702 .short_help = "nat44 del user <addr> [fib <index>]",
2703 .function = nat44_del_user_command_fn,
2708 * @cliexstart{clear nat44 sessions}
2709 * To clear all NAT44 sessions
2710 * vpp# clear nat44 sessions
2713 VLIB_CLI_COMMAND (nat44_clear_sessions_command, static) = {
2714 .path = "clear nat44 sessions",
2715 .short_help = "clear nat44 sessions",
2716 .function = nat44_clear_sessions_command_fn,
2721 * @cliexstart{nat44 del session}
2722 * To administratively delete NAT44 session by inside address and port use:
2723 * vpp# nat44 del session in 10.0.0.3:6303 tcp
2724 * To administratively delete NAT44 session by outside address and port use:
2725 * vpp# nat44 del session out 1.0.0.3:6033 udp
2728 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
2729 .path = "nat44 del session",
2730 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
2731 .function = nat44_del_session_command_fn,
2736 * @cliexstart{nat44 forwarding}
2737 * Enable or disable forwarding
2738 * Forward packets which don't match existing translation
2739 * or static mapping instead of dropping them.
2740 * To enable forwarding, use:
2741 * vpp# nat44 forwarding enable
2742 * To disable forwarding, use:
2743 * vpp# nat44 forwarding disable
2746 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
2747 .path = "nat44 forwarding",
2748 .short_help = "nat44 forwarding enable|disable",
2749 .function = snat_forwarding_set_command_fn,
2754 * @cliexstart{nat44 deterministic add}
2755 * Create bijective mapping of inside address to outside address and port range
2756 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
2758 * To create deterministic mapping between inside network 10.0.0.0/18 and
2759 * outside network 1.1.1.0/30 use:
2760 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
2763 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
2764 .path = "nat44 deterministic add",
2765 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
2766 .function = snat_det_map_command_fn,
2771 * @cliexpstart{show nat44 deterministic mappings}
2772 * Show NAT44 deterministic mappings
2773 * vpp# show nat44 deterministic mappings
2774 * NAT44 deterministic mappings:
2775 * in 10.0.0.0/24 out 1.1.1.1/32
2776 * outside address sharing ratio: 256
2777 * number of ports per inside host: 252
2778 * sessions number: 0
2781 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
2782 .path = "show nat44 deterministic mappings",
2783 .short_help = "show nat44 deterministic mappings",
2784 .function = nat44_det_show_mappings_command_fn,
2789 * @cliexstart{nat44 deterministic forward}
2790 * Return outside address and port range from inside address for deterministic
2792 * To obtain outside address and port of inside host use:
2793 * vpp# nat44 deterministic forward 10.0.0.2
2794 * 1.1.1.0:<1054-1068>
2797 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
2798 .path = "nat44 deterministic forward",
2799 .short_help = "nat44 deterministic forward <addr>",
2800 .function = snat_det_forward_command_fn,
2805 * @cliexstart{nat44 deterministic reverse}
2806 * Return inside address from outside address and port for deterministic NAT.
2807 * To obtain inside host address from outside address and port use:
2808 * #vpp nat44 deterministic reverse 1.1.1.1:1276
2812 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
2813 .path = "nat44 deterministic reverse",
2814 .short_help = "nat44 deterministic reverse <addr>:<port>",
2815 .function = snat_det_reverse_command_fn,
2820 * @cliexstart{show nat44 deterministic sessions}
2821 * Show NAT44 deterministic sessions.
2822 * vpp# show nat44 deterministic sessions
2823 * NAT44 deterministic sessions:
2824 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
2825 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
2826 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
2829 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
2830 .path = "show nat44 deterministic sessions",
2831 .short_help = "show nat44 deterministic sessions",
2832 .function = nat44_det_show_sessions_command_fn,
2837 * @cliexstart{nat44 deterministic close session out}
2838 * Close session using outside ip address and port
2839 * and external ip address and port, use:
2840 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
2843 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
2844 .path = "nat44 deterministic close session out",
2845 .short_help = "nat44 deterministic close session out "
2846 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
2847 .function = snat_det_close_session_out_fn,
2852 * @cliexstart{nat44 deterministic close session in}
2853 * Close session using inside ip address and port
2854 * and external ip address and port, use:
2855 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
2858 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
2859 .path = "nat44 deterministic close session in",
2860 .short_help = "nat44 deterministic close session in "
2861 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
2862 .function = snat_det_close_session_in_fn,
2868 * fd.io coding-style-patch-verification: ON
2871 * eval: (c-set-style "gnu")