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_command_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,
256 vlib_cli_output (vm, "-------- hash table parameters --------\n");
257 vlib_cli_output (vm, "translation buckets: %u", sm->translation_buckets);
258 vlib_cli_output (vm, "translation memory size: %U",
259 format_memory_size, sm->translation_memory_size);
260 if (!sm->endpoint_dependent)
262 vlib_cli_output (vm, "user buckets: %u", sm->user_buckets);
263 vlib_cli_output (vm, "user memory size: %U",
264 format_memory_size, sm->user_memory_size);
269 static clib_error_t *
270 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
271 unformat_input_t * input,
272 vlib_cli_command_t * cmd)
274 unformat_input_t _line_input, *line_input = &_line_input;
275 snat_main_t *sm = &snat_main;
276 clib_error_t *error = 0;
277 u32 psid, psid_offset, psid_length, port_start, port_end;
279 if (sm->deterministic)
280 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
282 /* Get a line of input. */
283 if (!unformat_user (input, unformat_line_input, line_input))
286 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
288 if (unformat (line_input, "default"))
289 nat_set_alloc_addr_and_port_default ();
292 (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
293 &psid_offset, &psid_length))
294 nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
298 (line_input, "port-range %d - %d", &port_start, &port_end))
300 if (port_end <= port_start)
303 clib_error_return (0,
304 "The end-port must be greater than start-port");
307 nat_set_alloc_addr_and_port_range ((u16) port_start,
312 error = clib_error_return (0, "unknown input '%U'",
313 format_unformat_error, line_input);
319 unformat_free (line_input);
324 static clib_error_t *
325 nat44_show_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
326 unformat_input_t * input,
327 vlib_cli_command_t * cmd)
329 snat_main_t *sm = &snat_main;
331 if (sm->deterministic)
332 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
334 vlib_cli_output (vm, "NAT address and port: %U",
335 format_nat_addr_and_port_alloc_alg,
336 sm->addr_and_port_alloc_alg);
337 switch (sm->addr_and_port_alloc_alg)
339 case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
340 vlib_cli_output (vm, " psid %d psid-offset %d psid-len %d", sm->psid,
341 sm->psid_offset, sm->psid_length);
343 case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
344 vlib_cli_output (vm, " start-port %d end-port %d", sm->start_port,
354 static clib_error_t *
355 nat_set_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
356 vlib_cli_command_t * cmd)
358 unformat_input_t _line_input, *line_input = &_line_input;
359 snat_main_t *sm = &snat_main;
360 clib_error_t *error = 0;
363 /* Get a line of input. */
364 if (!unformat_user (input, unformat_line_input, line_input))
367 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
369 if (unformat (line_input, "disable"))
370 sm->mss_clamping = 0;
371 else if (unformat (line_input, "%d", &mss))
372 sm->mss_clamping = (u16) mss;
375 error = clib_error_return (0, "unknown input '%U'",
376 format_unformat_error, line_input);
382 unformat_free (line_input);
387 static clib_error_t *
388 nat_show_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
389 vlib_cli_command_t * cmd)
391 snat_main_t *sm = &snat_main;
393 if (sm->mss_clamping)
394 vlib_cli_output (vm, "mss-clamping %d", sm->mss_clamping);
396 vlib_cli_output (vm, "mss-clamping disabled");
401 static clib_error_t *
402 nat_ha_failover_command_fn (vlib_main_t * vm, unformat_input_t * input,
403 vlib_cli_command_t * cmd)
405 unformat_input_t _line_input, *line_input = &_line_input;
407 u32 port, session_refresh_interval = 10;
409 clib_error_t *error = 0;
411 /* Get a line of input. */
412 if (!unformat_user (input, unformat_line_input, line_input))
415 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
417 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
421 (line_input, "refresh-interval %u", &session_refresh_interval))
425 error = clib_error_return (0, "unknown input '%U'",
426 format_unformat_error, line_input);
431 rv = nat_ha_set_failover (&addr, (u16) port, session_refresh_interval);
433 error = clib_error_return (0, "set HA failover failed");
436 unformat_free (line_input);
441 static clib_error_t *
442 nat_ha_listener_command_fn (vlib_main_t * vm, unformat_input_t * input,
443 vlib_cli_command_t * cmd)
445 unformat_input_t _line_input, *line_input = &_line_input;
447 u32 port, path_mtu = 512;
449 clib_error_t *error = 0;
451 /* Get a line of input. */
452 if (!unformat_user (input, unformat_line_input, line_input))
455 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
457 if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
459 else if (unformat (line_input, "path-mtu %u", &path_mtu))
463 error = clib_error_return (0, "unknown input '%U'",
464 format_unformat_error, line_input);
469 rv = nat_ha_set_listener (&addr, (u16) port, path_mtu);
471 error = clib_error_return (0, "set HA listener failed");
474 unformat_free (line_input);
479 static clib_error_t *
480 nat_show_ha_command_fn (vlib_main_t * vm, unformat_input_t * input,
481 vlib_cli_command_t * cmd)
485 u32 path_mtu, session_refresh_interval, resync_ack_missed;
488 nat_ha_get_listener (&addr, &port, &path_mtu);
491 vlib_cli_output (vm, "NAT HA disabled\n");
495 vlib_cli_output (vm, "LISTENER:\n");
496 vlib_cli_output (vm, " %U:%u path-mtu %u\n",
497 format_ip4_address, &addr, port, path_mtu);
499 nat_ha_get_failover (&addr, &port, &session_refresh_interval);
500 vlib_cli_output (vm, "FAILOVER:\n");
502 vlib_cli_output (vm, " %U:%u refresh-interval %usec\n",
503 format_ip4_address, &addr, port,
504 session_refresh_interval);
506 vlib_cli_output (vm, " NA\n");
508 nat_ha_get_resync_status (&in_resync, &resync_ack_missed);
509 vlib_cli_output (vm, "RESYNC:\n");
511 vlib_cli_output (vm, " in progress\n");
513 vlib_cli_output (vm, " completed (%d ACK missed)\n", resync_ack_missed);
518 static clib_error_t *
519 nat_ha_flush_command_fn (vlib_main_t * vm, unformat_input_t * input,
520 vlib_cli_command_t * cmd)
526 static clib_error_t *
527 nat_ha_resync_command_fn (vlib_main_t * vm, unformat_input_t * input,
528 vlib_cli_command_t * cmd)
530 clib_error_t *error = 0;
532 if (nat_ha_resync (0, 0, 0))
533 error = clib_error_return (0, "NAT HA resync already running");
538 static clib_error_t *
539 add_address_command_fn (vlib_main_t * vm,
540 unformat_input_t * input, vlib_cli_command_t * cmd)
542 unformat_input_t _line_input, *line_input = &_line_input;
543 snat_main_t *sm = &snat_main;
544 ip4_address_t start_addr, end_addr, this_addr;
545 u32 start_host_order, end_host_order;
550 clib_error_t *error = 0;
553 if (sm->deterministic)
554 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
556 /* Get a line of input. */
557 if (!unformat_user (input, unformat_line_input, line_input))
560 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
562 if (unformat (line_input, "%U - %U",
563 unformat_ip4_address, &start_addr,
564 unformat_ip4_address, &end_addr))
566 else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
568 else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
569 end_addr = start_addr;
570 else if (unformat (line_input, "twice-nat"))
572 else if (unformat (line_input, "del"))
576 error = clib_error_return (0, "unknown input '%U'",
577 format_unformat_error, line_input);
582 if (sm->static_mapping_only)
584 error = clib_error_return (0, "static mapping only mode");
588 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
589 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
591 if (end_host_order < start_host_order)
593 error = clib_error_return (0, "end address less than start address");
597 count = (end_host_order - start_host_order) + 1;
600 nat_log_info ("%U - %U, %d addresses...",
601 format_ip4_address, &start_addr,
602 format_ip4_address, &end_addr, count);
604 this_addr = start_addr;
606 for (i = 0; i < count; i++)
609 rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
611 rv = snat_del_address (sm, this_addr, 0, twice_nat);
615 case VNET_API_ERROR_VALUE_EXIST:
616 error = clib_error_return (0, "NAT address already in use.");
618 case VNET_API_ERROR_NO_SUCH_ENTRY:
619 error = clib_error_return (0, "NAT address not exist.");
621 case VNET_API_ERROR_UNSPECIFIED:
623 clib_error_return (0, "NAT address used in static mapping.");
625 case VNET_API_ERROR_FEATURE_DISABLED:
627 clib_error_return (0,
628 "twice NAT available only for endpoint-dependent mode.");
635 nat44_add_del_address_dpo (this_addr, is_add);
637 increment_v4_address (&this_addr);
641 unformat_free (line_input);
646 static clib_error_t *
647 nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
648 vlib_cli_command_t * cmd)
650 snat_main_per_thread_data_t *tsm;
651 snat_main_t *sm = &snat_main;
654 if (sm->deterministic || !sm->endpoint_dependent)
655 return clib_error_return (0, UNSUPPORTED_IN_DET_OR_NON_ED_MODE_STR);
657 vlib_cli_output (vm, "max translations per thread: %u",
658 sm->max_translations_per_thread);
659 vlib_cli_output (vm, "max translations per user: %u",
660 sm->max_translations_per_user);
664 u64 now = vlib_time_now (vm);
665 u64 sess_timeout_time;
667 u32 udp_sessions = 0;
668 u32 tcp_sessions = 0;
669 u32 icmp_sessions = 0;
673 u32 transitory_wait_closed = 0;
674 u32 transitory_closed = 0;
677 if (sm->num_workers > 1)
680 vec_foreach (tsm, sm->per_thread_data)
682 pool_foreach (s, tsm->sessions,
684 sess_timeout_time = s->last_heard +
685 (f64) nat44_session_get_timeout (sm, s);
686 if (now >= sess_timeout_time)
689 switch (s->nat_proto)
691 case NAT_PROTOCOL_ICMP:
694 case NAT_PROTOCOL_TCP:
698 if (s->tcp_closed_timestamp)
700 if (now >= s->tcp_closed_timestamp)
706 ++transitory_wait_closed;
714 case NAT_PROTOCOL_UDP:
720 count += pool_elts (tsm->sessions);
726 tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
728 pool_foreach (s, tsm->sessions,
730 sess_timeout_time = s->last_heard +
731 (f64) nat44_session_get_timeout (sm, s);
732 if (now >= sess_timeout_time)
735 switch (s->nat_proto)
737 case NAT_PROTOCOL_ICMP:
740 case NAT_PROTOCOL_TCP:
744 if (s->tcp_closed_timestamp)
746 if (now >= s->tcp_closed_timestamp)
752 ++transitory_wait_closed;
760 case NAT_PROTOCOL_UDP:
767 count = pool_elts (tsm->sessions);
768 if (sm->endpoint_dependent)
770 dlist_elt_t *oldest_elt;
774 clib_dlist_remove_head (tsm->lru_pool, tsm->n##_lru_head_index); \
775 if (~0 != oldest_index) \
777 oldest_elt = pool_elt_at_index (tsm->lru_pool, oldest_index); \
778 s = pool_elt_at_index (tsm->sessions, oldest_elt->value); \
779 sess_timeout_time = \
780 s->last_heard + (f64)nat44_session_get_timeout (sm, s); \
781 vlib_cli_output (vm, d " LRU min session timeout %llu (now %llu)", \
782 sess_timeout_time, now); \
783 clib_dlist_addhead (tsm->lru_pool, tsm->n##_lru_head_index, \
786 _(tcp_estab, "established tcp");
787 _(tcp_trans, "transitory tcp");
789 _(unk_proto, "unknown protocol");
795 vlib_cli_output (vm, "total timed out sessions: %u", timed_out);
796 vlib_cli_output (vm, "total sessions: %u", count);
797 vlib_cli_output (vm, "total tcp sessions: %u", tcp_sessions);
798 vlib_cli_output (vm, "total tcp established sessions: %u", established);
799 vlib_cli_output (vm, "total tcp transitory sessions: %u", transitory);
800 vlib_cli_output (vm, "total tcp transitory (WAIT-CLOSED) sessions: %u",
801 transitory_wait_closed);
802 vlib_cli_output (vm, "total tcp transitory (CLOSED) sessions: %u",
804 vlib_cli_output (vm, "total udp sessions: %u", udp_sessions);
805 vlib_cli_output (vm, "total icmp sessions: %u", icmp_sessions);
809 static clib_error_t *
810 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
811 vlib_cli_command_t * cmd)
813 snat_main_t *sm = &snat_main;
816 if (sm->deterministic)
817 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
819 vlib_cli_output (vm, "NAT44 pool addresses:");
821 vec_foreach (ap, sm->addresses)
823 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
824 if (ap->fib_index != ~0)
825 vlib_cli_output (vm, " tenant VRF: %u",
826 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
828 vlib_cli_output (vm, " tenant VRF independent");
829 #define _(N, i, n, s) \
830 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
834 vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
835 vec_foreach (ap, sm->twice_nat_addresses)
837 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
838 if (ap->fib_index != ~0)
839 vlib_cli_output (vm, " tenant VRF: %u",
840 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
842 vlib_cli_output (vm, " tenant VRF independent");
843 #define _(N, i, n, s) \
844 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
852 static clib_error_t *
853 snat_feature_command_fn (vlib_main_t * vm,
854 unformat_input_t * input, vlib_cli_command_t * cmd)
856 unformat_input_t _line_input, *line_input = &_line_input;
857 vnet_main_t *vnm = vnet_get_main ();
858 clib_error_t *error = 0;
860 u32 *inside_sw_if_indices = 0;
861 u32 *outside_sw_if_indices = 0;
862 u8 is_output_feature = 0;
868 /* Get a line of input. */
869 if (!unformat_user (input, unformat_line_input, line_input))
872 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
874 if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
876 vec_add1 (inside_sw_if_indices, sw_if_index);
877 else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
879 vec_add1 (outside_sw_if_indices, sw_if_index);
880 else if (unformat (line_input, "output-feature"))
881 is_output_feature = 1;
882 else if (unformat (line_input, "del"))
886 error = clib_error_return (0, "unknown input '%U'",
887 format_unformat_error, line_input);
892 if (vec_len (inside_sw_if_indices))
894 for (i = 0; i < vec_len (inside_sw_if_indices); i++)
896 sw_if_index = inside_sw_if_indices[i];
897 if (is_output_feature)
899 if (snat_interface_add_del_output_feature
900 (sw_if_index, 1, is_del))
902 error = clib_error_return (0, "%s %U failed",
903 is_del ? "del" : "add",
904 format_vnet_sw_if_index_name,
911 if (snat_interface_add_del (sw_if_index, 1, is_del))
913 error = clib_error_return (0, "%s %U failed",
914 is_del ? "del" : "add",
915 format_vnet_sw_if_index_name,
923 if (vec_len (outside_sw_if_indices))
925 for (i = 0; i < vec_len (outside_sw_if_indices); i++)
927 sw_if_index = outside_sw_if_indices[i];
928 if (is_output_feature)
930 if (snat_interface_add_del_output_feature
931 (sw_if_index, 0, is_del))
933 error = clib_error_return (0, "%s %U failed",
934 is_del ? "del" : "add",
935 format_vnet_sw_if_index_name,
942 if (snat_interface_add_del (sw_if_index, 0, is_del))
944 error = clib_error_return (0, "%s %U failed",
945 is_del ? "del" : "add",
946 format_vnet_sw_if_index_name,
955 unformat_free (line_input);
956 vec_free (inside_sw_if_indices);
957 vec_free (outside_sw_if_indices);
962 static clib_error_t *
963 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
964 vlib_cli_command_t * cmd)
966 snat_main_t *sm = &snat_main;
968 vnet_main_t *vnm = vnet_get_main ();
970 vlib_cli_output (vm, "NAT44 interfaces:");
972 pool_foreach (i, sm->interfaces,
974 vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
976 (nat_interface_is_inside(i) &&
977 nat_interface_is_outside(i)) ? "in out" :
978 (nat_interface_is_inside(i) ? "in" : "out"));
981 pool_foreach (i, sm->output_feature_interfaces,
983 vlib_cli_output (vm, " %U output-feature %s",
984 format_vnet_sw_if_index_name, vnm,
986 (nat_interface_is_inside(i) &&
987 nat_interface_is_outside(i)) ? "in out" :
988 (nat_interface_is_inside(i) ? "in" : "out"));
995 static clib_error_t *
996 add_static_mapping_command_fn (vlib_main_t * vm,
997 unformat_input_t * input,
998 vlib_cli_command_t * cmd)
1000 unformat_input_t _line_input, *line_input = &_line_input;
1001 snat_main_t *sm = &snat_main;
1002 clib_error_t *error = 0;
1003 ip4_address_t l_addr, e_addr;
1004 u32 l_port = 0, e_port = 0, vrf_id = ~0;
1007 u32 sw_if_index = ~0;
1008 vnet_main_t *vnm = vnet_get_main ();
1010 nat_protocol_t proto = NAT_PROTOCOL_OTHER;
1012 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1015 if (sm->deterministic)
1016 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1018 /* Get a line of input. */
1019 if (!unformat_user (input, unformat_line_input, line_input))
1022 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1024 if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
1028 if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
1030 else if (unformat (line_input, "external %U %u", unformat_ip4_address,
1033 else if (unformat (line_input, "external %U", unformat_ip4_address,
1036 else if (unformat (line_input, "external %U %u",
1037 unformat_vnet_sw_interface, vnm, &sw_if_index,
1041 else if (unformat (line_input, "external %U",
1042 unformat_vnet_sw_interface, vnm, &sw_if_index))
1044 else if (unformat (line_input, "vrf %u", &vrf_id))
1046 else if (unformat (line_input, "%U", unformat_nat_protocol, &proto))
1048 else if (unformat (line_input, "twice-nat"))
1049 twice_nat = TWICE_NAT;
1050 else if (unformat (line_input, "self-twice-nat"))
1051 twice_nat = TWICE_NAT_SELF;
1052 else if (unformat (line_input, "out2in-only"))
1054 else if (unformat (line_input, "del"))
1058 error = clib_error_return (0, "unknown input: '%U'",
1059 format_unformat_error, line_input);
1064 if (twice_nat && addr_only)
1066 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
1075 clib_error_return (0,
1076 "address only mapping doesn't support protocol");
1080 else if (!proto_set)
1082 error = clib_error_return (0, "protocol is required");
1086 rv = snat_add_static_mapping (l_addr, e_addr, clib_host_to_net_u16 (l_port),
1087 clib_host_to_net_u16 (e_port),
1088 vrf_id, addr_only, sw_if_index, proto, is_add,
1089 twice_nat, out2in_only, 0, 0);
1093 case VNET_API_ERROR_INVALID_VALUE:
1094 error = clib_error_return (0, "External port already in use.");
1096 case VNET_API_ERROR_NO_SUCH_ENTRY:
1098 error = clib_error_return (0, "External address must be allocated.");
1100 error = clib_error_return (0, "Mapping not exist.");
1102 case VNET_API_ERROR_NO_SUCH_FIB:
1103 error = clib_error_return (0, "No such VRF id.");
1105 case VNET_API_ERROR_VALUE_EXIST:
1106 error = clib_error_return (0, "Mapping already exist.");
1108 case VNET_API_ERROR_FEATURE_DISABLED:
1110 clib_error_return (0,
1111 "twice-nat/out2in-only available only for endpoint-dependent mode.");
1118 unformat_free (line_input);
1123 static clib_error_t *
1124 add_identity_mapping_command_fn (vlib_main_t * vm,
1125 unformat_input_t * input,
1126 vlib_cli_command_t * cmd)
1128 unformat_input_t _line_input, *line_input = &_line_input;
1129 snat_main_t *sm = &snat_main;
1130 clib_error_t *error = 0;
1132 u32 port = 0, vrf_id = ~0;
1135 u32 sw_if_index = ~0;
1136 vnet_main_t *vnm = vnet_get_main ();
1138 nat_protocol_t proto;
1140 if (sm->deterministic)
1141 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1145 /* Get a line of input. */
1146 if (!unformat_user (input, unformat_line_input, line_input))
1149 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1151 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1153 else if (unformat (line_input, "external %U",
1154 unformat_vnet_sw_interface, vnm, &sw_if_index))
1156 else if (unformat (line_input, "vrf %u", &vrf_id))
1158 else if (unformat (line_input, "%U %u", unformat_nat_protocol, &proto,
1161 else if (unformat (line_input, "del"))
1165 error = clib_error_return (0, "unknown input: '%U'",
1166 format_unformat_error, line_input);
1172 snat_add_static_mapping (addr, addr, clib_host_to_net_u16 (port),
1173 clib_host_to_net_u16 (port), vrf_id, addr_only,
1174 sw_if_index, proto, is_add, 0, 0, 0, 1);
1178 case VNET_API_ERROR_INVALID_VALUE:
1179 error = clib_error_return (0, "External port already in use.");
1181 case VNET_API_ERROR_NO_SUCH_ENTRY:
1183 error = clib_error_return (0, "External address must be allocated.");
1185 error = clib_error_return (0, "Mapping not exist.");
1187 case VNET_API_ERROR_NO_SUCH_FIB:
1188 error = clib_error_return (0, "No such VRF id.");
1190 case VNET_API_ERROR_VALUE_EXIST:
1191 error = clib_error_return (0, "Mapping already exist.");
1198 unformat_free (line_input);
1203 static clib_error_t *
1204 add_lb_static_mapping_command_fn (vlib_main_t * vm,
1205 unformat_input_t * input,
1206 vlib_cli_command_t * cmd)
1208 unformat_input_t _line_input, *line_input = &_line_input;
1209 snat_main_t *sm = &snat_main;
1210 clib_error_t *error = 0;
1211 ip4_address_t l_addr, e_addr;
1212 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
1215 nat_protocol_t proto;
1217 nat44_lb_addr_port_t *locals = 0, local;
1218 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1221 if (sm->deterministic)
1222 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1224 /* Get a line of input. */
1225 if (!unformat_user (input, unformat_line_input, line_input))
1228 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1230 if (unformat (line_input, "local %U:%u probability %u",
1231 unformat_ip4_address, &l_addr, &l_port, &probability))
1233 clib_memset (&local, 0, sizeof (local));
1234 local.addr = l_addr;
1235 local.port = (u16) l_port;
1236 local.probability = (u8) probability;
1237 vec_add1 (locals, local);
1239 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1240 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1243 clib_memset (&local, 0, sizeof (local));
1244 local.addr = l_addr;
1245 local.port = (u16) l_port;
1246 local.probability = (u8) probability;
1247 local.vrf_id = vrf_id;
1248 vec_add1 (locals, local);
1250 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1253 else if (unformat (line_input, "protocol %U", unformat_nat_protocol,
1256 else if (unformat (line_input, "twice-nat"))
1257 twice_nat = TWICE_NAT;
1258 else if (unformat (line_input, "self-twice-nat"))
1259 twice_nat = TWICE_NAT_SELF;
1260 else if (unformat (line_input, "out2in-only"))
1262 else if (unformat (line_input, "del"))
1264 else if (unformat (line_input, "affinity %u", &affinity))
1268 error = clib_error_return (0, "unknown input: '%U'",
1269 format_unformat_error, line_input);
1274 if (vec_len (locals) < 2)
1276 error = clib_error_return (0, "at least two local must be set");
1282 error = clib_error_return (0, "missing protocol");
1286 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, locals,
1287 is_add, twice_nat, out2in_only, 0,
1292 case VNET_API_ERROR_INVALID_VALUE:
1293 error = clib_error_return (0, "External port already in use.");
1295 case VNET_API_ERROR_NO_SUCH_ENTRY:
1297 error = clib_error_return (0, "External address must be allocated.");
1299 error = clib_error_return (0, "Mapping not exist.");
1301 case VNET_API_ERROR_VALUE_EXIST:
1302 error = clib_error_return (0, "Mapping already exist.");
1304 case VNET_API_ERROR_FEATURE_DISABLED:
1306 clib_error_return (0, "Available only for endpoint-dependent mode.");
1313 unformat_free (line_input);
1319 static clib_error_t *
1320 add_lb_backend_command_fn (vlib_main_t * vm,
1321 unformat_input_t * input, vlib_cli_command_t * cmd)
1323 unformat_input_t _line_input, *line_input = &_line_input;
1324 snat_main_t *sm = &snat_main;
1325 clib_error_t *error = 0;
1326 ip4_address_t l_addr, e_addr;
1327 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
1330 nat_protocol_t proto;
1333 if (sm->deterministic)
1334 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1336 /* Get a line of input. */
1337 if (!unformat_user (input, unformat_line_input, line_input))
1340 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1342 if (unformat (line_input, "local %U:%u probability %u",
1343 unformat_ip4_address, &l_addr, &l_port, &probability))
1345 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1346 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1349 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1352 else if (unformat (line_input, "protocol %U", unformat_nat_protocol,
1355 else if (unformat (line_input, "del"))
1359 error = clib_error_return (0, "unknown input: '%U'",
1360 format_unformat_error, line_input);
1365 if (!l_port || !e_port)
1367 error = clib_error_return (0, "local or external must be set");
1373 error = clib_error_return (0, "missing protocol");
1378 nat44_lb_static_mapping_add_del_local (e_addr, (u16) e_port, l_addr,
1379 l_port, proto, vrf_id, probability,
1384 case VNET_API_ERROR_INVALID_VALUE:
1385 error = clib_error_return (0, "External is not load-balancing static "
1388 case VNET_API_ERROR_NO_SUCH_ENTRY:
1389 error = clib_error_return (0, "Mapping or back-end not exist.");
1391 case VNET_API_ERROR_VALUE_EXIST:
1392 error = clib_error_return (0, "Back-end already exist.");
1394 case VNET_API_ERROR_FEATURE_DISABLED:
1396 clib_error_return (0, "Available only for endpoint-dependent mode.");
1398 case VNET_API_ERROR_UNSPECIFIED:
1399 error = clib_error_return (0, "At least two back-ends must remain");
1406 unformat_free (line_input);
1411 static clib_error_t *
1412 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
1413 unformat_input_t * input,
1414 vlib_cli_command_t * cmd)
1416 snat_main_t *sm = &snat_main;
1417 snat_static_mapping_t *m;
1418 snat_static_map_resolve_t *rp;
1420 if (sm->deterministic)
1421 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1423 vlib_cli_output (vm, "NAT44 static mappings:");
1425 pool_foreach (m, sm->static_mappings,
1427 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
1429 vec_foreach (rp, sm->to_resolve)
1430 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
1436 static clib_error_t *
1437 snat_add_interface_address_command_fn (vlib_main_t * vm,
1438 unformat_input_t * input,
1439 vlib_cli_command_t * cmd)
1441 snat_main_t *sm = &snat_main;
1442 unformat_input_t _line_input, *line_input = &_line_input;
1446 clib_error_t *error = 0;
1449 if (sm->deterministic)
1450 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1452 /* Get a line of input. */
1453 if (!unformat_user (input, unformat_line_input, line_input))
1456 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1458 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
1459 sm->vnet_main, &sw_if_index))
1461 else if (unformat (line_input, "twice-nat"))
1463 else if (unformat (line_input, "del"))
1467 error = clib_error_return (0, "unknown input '%U'",
1468 format_unformat_error, line_input);
1473 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
1481 error = clib_error_return (0, "snat_add_interface_address returned %d",
1487 unformat_free (line_input);
1492 static clib_error_t *
1493 nat44_show_interface_address_command_fn (vlib_main_t * vm,
1494 unformat_input_t * input,
1495 vlib_cli_command_t * cmd)
1497 snat_main_t *sm = &snat_main;
1498 vnet_main_t *vnm = vnet_get_main ();
1501 if (sm->deterministic)
1502 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1505 vlib_cli_output (vm, "NAT44 pool address interfaces:");
1506 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
1508 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1511 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
1512 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
1514 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1522 static clib_error_t *
1523 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
1524 vlib_cli_command_t * cmd)
1526 unformat_input_t _line_input, *line_input = &_line_input;
1527 clib_error_t *error = 0;
1529 snat_main_per_thread_data_t *tsm;
1530 snat_main_t *sm = &snat_main;
1535 if (sm->deterministic)
1536 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1538 if (!unformat_user (input, unformat_line_input, line_input))
1541 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1543 if (unformat (line_input, "detail"))
1547 error = clib_error_return (0, "unknown input '%U'",
1548 format_unformat_error, line_input);
1552 unformat_free (line_input);
1555 if (!sm->endpoint_dependent)
1556 vlib_cli_output (vm, "NAT44 sessions:");
1558 vlib_cli_output (vm, "NAT44 ED sessions:");
1561 vec_foreach_index (i, sm->per_thread_data)
1563 tsm = vec_elt_at_index (sm->per_thread_data, i);
1565 vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
1566 i, vlib_worker_threads[i].name,
1567 pool_elts (tsm->sessions));
1569 if (!sm->endpoint_dependent)
1572 pool_foreach (u, tsm->users,
1574 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, detail);
1580 pool_foreach (s, tsm->sessions,
1582 vlib_cli_output (vm, " %U\n", format_snat_session, tsm, s);
1590 static clib_error_t *
1591 nat44_set_session_limit_command_fn (vlib_main_t * vm,
1592 unformat_input_t * input,
1593 vlib_cli_command_t * cmd)
1595 snat_main_t *sm = &snat_main;
1596 unformat_input_t _line_input, *line_input = &_line_input;
1597 clib_error_t *error = 0;
1599 u32 session_limit = 0, vrf_id = 0;
1601 if (sm->deterministic)
1602 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1604 /* Get a line of input. */
1605 if (!unformat_user (input, unformat_line_input, line_input))
1608 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1610 if (unformat (line_input, "%u", &session_limit))
1612 else if (unformat (line_input, "vrf %u", &vrf_id))
1616 error = clib_error_return (0, "unknown input '%U'",
1617 format_unformat_error, line_input);
1623 error = clib_error_return (0, "missing value of session limit");
1624 else if (nat44_set_session_limit (session_limit, vrf_id))
1625 error = clib_error_return (0, "nat44_set_session_limit failed");
1628 unformat_free (line_input);
1633 static clib_error_t *
1634 nat44_del_user_command_fn (vlib_main_t * vm,
1635 unformat_input_t * input, vlib_cli_command_t * cmd)
1637 snat_main_t *sm = &snat_main;
1638 unformat_input_t _line_input, *line_input = &_line_input;
1639 clib_error_t *error = 0;
1644 if (sm->deterministic || sm->endpoint_dependent)
1645 return clib_error_return (0, UNSUPPORTED_IN_DET_OR_ED_MODE_STR);
1647 /* Get a line of input. */
1648 if (!unformat_user (input, unformat_line_input, line_input))
1651 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1653 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1655 else if (unformat (line_input, "fib %u", &fib_index))
1659 error = clib_error_return (0, "unknown input '%U'",
1660 format_unformat_error, line_input);
1665 rv = nat44_user_del (&addr, fib_index);
1669 error = clib_error_return (0, "nat44_user_del returned %d", rv);
1673 unformat_free (line_input);
1678 static clib_error_t *
1679 nat44_clear_sessions_command_fn (vlib_main_t * vm,
1680 unformat_input_t * input,
1681 vlib_cli_command_t * cmd)
1683 snat_main_t *sm = &snat_main;
1684 clib_error_t *error = 0;
1686 if (sm->deterministic)
1687 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1689 nat44_sessions_clear ();
1693 static clib_error_t *
1694 nat44_del_session_command_fn (vlib_main_t * vm,
1695 unformat_input_t * input,
1696 vlib_cli_command_t * cmd)
1698 snat_main_t *sm = &snat_main;
1699 unformat_input_t _line_input, *line_input = &_line_input;
1700 int is_in = 0, is_ed = 0;
1701 clib_error_t *error = 0;
1702 ip4_address_t addr, eh_addr;
1703 u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
1704 nat_protocol_t proto;
1707 if (sm->deterministic)
1708 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1710 /* Get a line of input. */
1711 if (!unformat_user (input, unformat_line_input, line_input))
1714 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1717 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1718 unformat_nat_protocol, &proto))
1720 else if (unformat (line_input, "in"))
1723 vrf_id = sm->inside_vrf_id;
1725 else if (unformat (line_input, "out"))
1728 vrf_id = sm->outside_vrf_id;
1730 else if (unformat (line_input, "vrf %u", &vrf_id))
1734 (line_input, "external-host %U:%u", unformat_ip4_address,
1735 &eh_addr, &eh_port))
1739 error = clib_error_return (0, "unknown input '%U'",
1740 format_unformat_error, line_input);
1747 nat44_del_ed_session (sm, &addr, clib_host_to_net_u16 (port), &eh_addr,
1748 clib_host_to_net_u16 (eh_port),
1749 nat_proto_to_ip_proto (proto), vrf_id, is_in);
1752 nat44_del_session (sm, &addr, clib_host_to_net_u16 (port), proto,
1761 error = clib_error_return (0, "nat44_del_session returned %d", rv);
1766 unformat_free (line_input);
1771 static clib_error_t *
1772 snat_forwarding_set_command_fn (vlib_main_t * vm,
1773 unformat_input_t * input,
1774 vlib_cli_command_t * cmd)
1776 snat_main_t *sm = &snat_main;
1777 unformat_input_t _line_input, *line_input = &_line_input;
1778 u8 forwarding_enable;
1779 u8 forwarding_enable_set = 0;
1780 clib_error_t *error = 0;
1782 if (sm->deterministic)
1783 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1785 /* Get a line of input. */
1786 if (!unformat_user (input, unformat_line_input, line_input))
1787 return clib_error_return (0, "'enable' or 'disable' expected");
1789 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1791 if (!forwarding_enable_set && unformat (line_input, "enable"))
1793 forwarding_enable = 1;
1794 forwarding_enable_set = 1;
1796 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1798 forwarding_enable = 0;
1799 forwarding_enable_set = 1;
1803 error = clib_error_return (0, "unknown input '%U'",
1804 format_unformat_error, line_input);
1809 if (!forwarding_enable_set)
1811 error = clib_error_return (0, "'enable' or 'disable' expected");
1815 sm->forwarding_enabled = forwarding_enable;
1818 unformat_free (line_input);
1823 static clib_error_t *
1824 snat_det_map_command_fn (vlib_main_t * vm,
1825 unformat_input_t * input, vlib_cli_command_t * cmd)
1827 snat_main_t *sm = &snat_main;
1828 unformat_input_t _line_input, *line_input = &_line_input;
1829 ip4_address_t in_addr, out_addr;
1830 u32 in_plen, out_plen;
1832 clib_error_t *error = 0;
1834 if (!sm->deterministic)
1835 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1837 /* Get a line of input. */
1838 if (!unformat_user (input, unformat_line_input, line_input))
1841 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1844 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1848 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1851 else if (unformat (line_input, "del"))
1855 error = clib_error_return (0, "unknown input '%U'",
1856 format_unformat_error, line_input);
1861 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1866 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1871 unformat_free (line_input);
1876 static clib_error_t *
1877 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1878 unformat_input_t * input,
1879 vlib_cli_command_t * cmd)
1881 snat_main_t *sm = &snat_main;
1884 if (!sm->deterministic)
1885 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1887 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1889 pool_foreach (dm, sm->det_maps,
1891 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1892 format_ip4_address, &dm->in_addr, dm->in_plen,
1893 format_ip4_address, &dm->out_addr, dm->out_plen);
1894 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1896 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1897 dm->ports_per_host);
1898 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1905 static clib_error_t *
1906 snat_det_forward_command_fn (vlib_main_t * vm,
1907 unformat_input_t * input,
1908 vlib_cli_command_t * cmd)
1910 snat_main_t *sm = &snat_main;
1911 unformat_input_t _line_input, *line_input = &_line_input;
1912 ip4_address_t in_addr, out_addr;
1915 clib_error_t *error = 0;
1917 if (!sm->deterministic)
1918 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1920 /* Get a line of input. */
1921 if (!unformat_user (input, unformat_line_input, line_input))
1924 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1926 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1930 error = clib_error_return (0, "unknown input '%U'",
1931 format_unformat_error, line_input);
1936 dm = snat_det_map_by_user (sm, &in_addr);
1938 vlib_cli_output (vm, "no match");
1941 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1942 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1943 lo_port, lo_port + dm->ports_per_host - 1);
1947 unformat_free (line_input);
1952 static clib_error_t *
1953 snat_det_reverse_command_fn (vlib_main_t * vm,
1954 unformat_input_t * input,
1955 vlib_cli_command_t * cmd)
1957 snat_main_t *sm = &snat_main;
1958 unformat_input_t _line_input, *line_input = &_line_input;
1959 ip4_address_t in_addr, out_addr;
1962 clib_error_t *error = 0;
1964 if (!sm->deterministic)
1965 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1967 /* Get a line of input. */
1968 if (!unformat_user (input, unformat_line_input, line_input))
1971 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1974 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1978 error = clib_error_return (0, "unknown input '%U'",
1979 format_unformat_error, line_input);
1984 if (out_port < 1024 || out_port > 65535)
1986 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1990 dm = snat_det_map_by_out (sm, &out_addr);
1992 vlib_cli_output (vm, "no match");
1995 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1996 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
2000 unformat_free (line_input);
2005 static clib_error_t *
2006 set_timeout_command_fn (vlib_main_t * vm,
2007 unformat_input_t * input, vlib_cli_command_t * cmd)
2009 snat_main_t *sm = &snat_main;
2010 unformat_input_t _line_input, *line_input = &_line_input;
2011 clib_error_t *error = 0;
2013 /* Get a line of input. */
2014 if (!unformat_user (input, unformat_line_input, line_input))
2017 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2019 if (unformat (line_input, "udp %u", &sm->udp_timeout))
2021 if (nat64_set_udp_timeout (sm->udp_timeout))
2023 error = clib_error_return (0, "Invalid UDP timeout value");
2027 else if (unformat (line_input, "tcp-established %u",
2028 &sm->tcp_established_timeout))
2030 if (nat64_set_tcp_timeouts
2031 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
2034 clib_error_return (0,
2035 "Invalid TCP established timeouts value");
2039 else if (unformat (line_input, "tcp-transitory %u",
2040 &sm->tcp_transitory_timeout))
2042 if (nat64_set_tcp_timeouts
2043 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
2046 clib_error_return (0,
2047 "Invalid TCP transitory timeouts value");
2051 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
2053 if (nat64_set_icmp_timeout (sm->icmp_timeout))
2055 error = clib_error_return (0, "Invalid ICMP timeout value");
2059 else if (unformat (line_input, "reset"))
2061 sm->udp_timeout = SNAT_UDP_TIMEOUT;
2062 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
2063 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
2064 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
2065 nat64_set_udp_timeout (0);
2066 nat64_set_icmp_timeout (0);
2067 nat64_set_tcp_timeouts (0, 0);
2071 error = clib_error_return (0, "unknown input '%U'",
2072 format_unformat_error, line_input);
2077 unformat_free (line_input);
2081 static clib_error_t *
2082 nat_show_timeouts_command_fn (vlib_main_t * vm,
2083 unformat_input_t * input,
2084 vlib_cli_command_t * cmd)
2086 snat_main_t *sm = &snat_main;
2088 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
2089 vlib_cli_output (vm, "tcp-established timeout: %dsec",
2090 sm->tcp_established_timeout);
2091 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
2092 sm->tcp_transitory_timeout);
2093 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
2098 static clib_error_t *
2099 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
2100 unformat_input_t * input,
2101 vlib_cli_command_t * cmd)
2103 snat_main_t *sm = &snat_main;
2105 snat_det_session_t *ses;
2108 if (!sm->deterministic)
2109 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2111 vlib_cli_output (vm, "NAT44 deterministic sessions:");
2113 pool_foreach (dm, sm->det_maps,
2115 vec_foreach_index (i, dm->sessions)
2117 ses = vec_elt_at_index (dm->sessions, i);
2119 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
2126 static clib_error_t *
2127 snat_det_close_session_out_fn (vlib_main_t * vm,
2128 unformat_input_t * input,
2129 vlib_cli_command_t * cmd)
2131 snat_main_t *sm = &snat_main;
2132 unformat_input_t _line_input, *line_input = &_line_input;
2133 ip4_address_t out_addr, ext_addr, in_addr;
2134 u32 out_port, ext_port;
2136 snat_det_session_t *ses;
2137 snat_det_out_key_t key;
2138 clib_error_t *error = 0;
2140 if (!sm->deterministic)
2141 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2143 /* Get a line of input. */
2144 if (!unformat_user (input, unformat_line_input, line_input))
2147 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2149 if (unformat (line_input, "%U:%d %U:%d",
2150 unformat_ip4_address, &out_addr, &out_port,
2151 unformat_ip4_address, &ext_addr, &ext_port))
2155 error = clib_error_return (0, "unknown input '%U'",
2156 format_unformat_error, line_input);
2161 unformat_free (line_input);
2163 dm = snat_det_map_by_out (sm, &out_addr);
2165 vlib_cli_output (vm, "no match");
2168 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
2169 key.ext_host_addr = out_addr;
2170 key.ext_host_port = ntohs ((u16) ext_port);
2171 key.out_port = ntohs ((u16) out_port);
2172 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
2174 vlib_cli_output (vm, "no match");
2176 snat_det_ses_close (dm, ses);
2180 unformat_free (line_input);
2185 static clib_error_t *
2186 snat_det_close_session_in_fn (vlib_main_t * vm,
2187 unformat_input_t * input,
2188 vlib_cli_command_t * cmd)
2190 snat_main_t *sm = &snat_main;
2191 unformat_input_t _line_input, *line_input = &_line_input;
2192 ip4_address_t in_addr, ext_addr;
2193 u32 in_port, ext_port;
2195 snat_det_session_t *ses;
2196 snat_det_out_key_t key;
2197 clib_error_t *error = 0;
2199 if (!sm->deterministic)
2200 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2202 /* Get a line of input. */
2203 if (!unformat_user (input, unformat_line_input, line_input))
2206 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2208 if (unformat (line_input, "%U:%d %U:%d",
2209 unformat_ip4_address, &in_addr, &in_port,
2210 unformat_ip4_address, &ext_addr, &ext_port))
2214 error = clib_error_return (0, "unknown input '%U'",
2215 format_unformat_error, line_input);
2220 unformat_free (line_input);
2222 dm = snat_det_map_by_user (sm, &in_addr);
2224 vlib_cli_output (vm, "no match");
2227 key.ext_host_addr = ext_addr;
2228 key.ext_host_port = ntohs ((u16) ext_port);
2230 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
2232 vlib_cli_output (vm, "no match");
2234 snat_det_ses_close (dm, ses);
2238 unformat_free (line_input);
2246 * @cliexstart{set snat workers}
2247 * Set NAT workers if 2 or more workers available, use:
2248 * vpp# set snat workers 0-2,5
2251 VLIB_CLI_COMMAND (set_workers_command, static) = {
2252 .path = "set nat workers",
2253 .function = set_workers_command_fn,
2254 .short_help = "set nat workers <workers-list>",
2259 * @cliexstart{show nat workers}
2261 * vpp# show nat workers:
2267 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
2268 .path = "show nat workers",
2269 .short_help = "show nat workers",
2270 .function = nat_show_workers_commnad_fn,
2275 * @cliexstart{set nat timeout}
2276 * Set values of timeouts for NAT sessions (in seconds), use:
2277 * vpp# set nat timeout udp 120 tcp-established 7500 tcp-transitory 250 icmp 90
2278 * To reset default values use:
2279 * vpp# set nat44 deterministic timeout reset
2282 VLIB_CLI_COMMAND (set_timeout_command, static) = {
2283 .path = "set nat timeout",
2284 .function = set_timeout_command_fn,
2286 "set nat timeout [udp <sec> | tcp-established <sec> "
2287 "tcp-transitory <sec> | icmp <sec> | reset]",
2292 * @cliexstart{show nat timeouts}
2293 * Show values of timeouts for NAT sessions.
2294 * vpp# show nat timeouts
2295 * udp timeout: 300sec
2296 * tcp-established timeout: 7440sec
2297 * tcp-transitory timeout: 240sec
2298 * icmp timeout: 60sec
2301 VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = {
2302 .path = "show nat timeouts",
2303 .short_help = "show nat timeouts",
2304 .function = nat_show_timeouts_command_fn,
2309 * @cliexstart{nat set logging level}
2310 * To set NAT logging level use:
2311 * Set nat logging level
2314 VLIB_CLI_COMMAND (snat_set_log_level_command, static) = {
2315 .path = "nat set logging level",
2316 .function = snat_set_log_level_command_fn,
2317 .short_help = "nat set logging level <level>",
2322 * @cliexstart{snat ipfix logging}
2323 * To enable NAT IPFIX logging use:
2324 * vpp# nat ipfix logging
2325 * To set IPFIX exporter use:
2326 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
2329 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
2330 .path = "nat ipfix logging",
2331 .function = snat_ipfix_logging_enable_disable_command_fn,
2332 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
2337 * @cliexstart{nat addr-port-assignment-alg}
2338 * Set address and port assignment algorithm
2339 * For the MAP-E CE limit port choice based on PSID use:
2340 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
2341 * For port range use:
2342 * vpp# nat addr-port-assignment-alg port-range <start-port> - <end-port>
2343 * To set standard (default) address and port assignment algorithm use:
2344 * vpp# nat addr-port-assignment-alg default
2347 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
2348 .path = "nat addr-port-assignment-alg",
2349 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
2350 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
2355 * @cliexstart{show nat addr-port-assignment-alg}
2356 * Show address and port assignment algorithm
2359 VLIB_CLI_COMMAND (nat44_show_alloc_addr_and_port_alg_command, static) = {
2360 .path = "show nat addr-port-assignment-alg",
2361 .short_help = "show nat addr-port-assignment-alg",
2362 .function = nat44_show_alloc_addr_and_port_alg_command_fn,
2367 * @cliexstart{nat mss-clamping}
2368 * Set TCP MSS rewriting configuration
2369 * To enable TCP MSS rewriting use:
2370 * vpp# nat mss-clamping 1452
2371 * To disbale TCP MSS rewriting use:
2372 * vpp# nat mss-clamping disable
2375 VLIB_CLI_COMMAND (nat_set_mss_clamping_command, static) = {
2376 .path = "nat mss-clamping",
2377 .short_help = "nat mss-clamping <mss-value>|disable",
2378 .function = nat_set_mss_clamping_command_fn,
2383 * @cliexstart{show nat mss-clamping}
2384 * Show TCP MSS rewriting configuration
2387 VLIB_CLI_COMMAND (nat_show_mss_clamping_command, static) = {
2388 .path = "show nat mss-clamping",
2389 .short_help = "show nat mss-clamping",
2390 .function = nat_show_mss_clamping_command_fn,
2395 * @cliexstart{nat ha failover}
2396 * Set HA failover (remote settings)
2399 VLIB_CLI_COMMAND (nat_ha_failover_command, static) = {
2400 .path = "nat ha failover",
2401 .short_help = "nat ha failover <ip4-address>:<port> [refresh-interval <sec>]",
2402 .function = nat_ha_failover_command_fn,
2407 * @cliexstart{nat ha listener}
2408 * Set HA listener (local settings)
2411 VLIB_CLI_COMMAND (nat_ha_listener_command, static) = {
2412 .path = "nat ha listener",
2413 .short_help = "nat ha listener <ip4-address>:<port> [path-mtu <path-mtu>]",
2414 .function = nat_ha_listener_command_fn,
2419 * @cliexstart{show nat ha}
2420 * Show HA configuration/status
2423 VLIB_CLI_COMMAND (nat_show_ha_command, static) = {
2424 .path = "show nat ha",
2425 .short_help = "show nat ha",
2426 .function = nat_show_ha_command_fn,
2431 * @cliexstart{nat ha flush}
2432 * Flush the current HA data (for testing)
2435 VLIB_CLI_COMMAND (nat_ha_flush_command, static) = {
2436 .path = "nat ha flush",
2437 .short_help = "nat ha flush",
2438 .function = nat_ha_flush_command_fn,
2443 * @cliexstart{nat ha resync}
2444 * Resync HA (resend existing sessions to new failover)
2447 VLIB_CLI_COMMAND (nat_ha_resync_command, static) = {
2448 .path = "nat ha resync",
2449 .short_help = "nat ha resync",
2450 .function = nat_ha_resync_command_fn,
2455 * @cliexstart{show nat44 hash tables}
2456 * Show NAT44 hash tables
2459 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
2460 .path = "show nat44 hash tables",
2461 .short_help = "show nat44 hash tables [detail|verbose]",
2462 .function = nat44_show_hash_command_fn,
2467 * @cliexstart{nat44 add address}
2468 * Add/delete NAT44 pool address.
2469 * To add NAT44 pool address use:
2470 * vpp# nat44 add address 172.16.1.3
2471 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
2472 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
2473 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
2476 VLIB_CLI_COMMAND (add_address_command, static) = {
2477 .path = "nat44 add address",
2478 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
2479 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
2480 .function = add_address_command_fn,
2485 * @cliexstart{show nat44 summary}
2486 * Show NAT44 summary
2487 * vpp# show nat44 summary
2490 VLIB_CLI_COMMAND (nat44_show_summary_command, static) = {
2491 .path = "show nat44 summary",
2492 .short_help = "show nat44 summary",
2493 .function = nat44_show_summary_command_fn,
2498 * @cliexstart{show nat44 addresses}
2499 * Show NAT44 pool addresses.
2500 * vpp# show nat44 addresses
2501 * NAT44 pool addresses:
2503 * tenant VRF independent
2512 * NAT44 twice-nat pool addresses:
2514 * tenant VRF independent
2520 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
2521 .path = "show nat44 addresses",
2522 .short_help = "show nat44 addresses",
2523 .function = nat44_show_addresses_command_fn,
2528 * @cliexstart{set interface nat44}
2529 * Enable/disable NAT44 feature on the interface.
2530 * To enable NAT44 feature with local network interface use:
2531 * vpp# set interface nat44 in GigabitEthernet0/8/0
2532 * To enable NAT44 feature with external network interface use:
2533 * vpp# set interface nat44 out GigabitEthernet0/a/0
2536 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
2537 .path = "set interface nat44",
2538 .function = snat_feature_command_fn,
2539 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
2545 * @cliexstart{show nat44 interfaces}
2546 * Show interfaces with NAT44 feature.
2547 * vpp# show nat44 interfaces
2549 * GigabitEthernet0/8/0 in
2550 * GigabitEthernet0/a/0 out
2553 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
2554 .path = "show nat44 interfaces",
2555 .short_help = "show nat44 interfaces",
2556 .function = nat44_show_interfaces_command_fn,
2561 * @cliexstart{nat44 add static mapping}
2562 * Static mapping allows hosts on the external network to initiate connection
2563 * to to the local network host.
2564 * To create static mapping between local host address 10.0.0.3 port 6303 and
2565 * external address 4.4.4.4 port 3606 for TCP protocol use:
2566 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
2567 * If not runnig "static mapping only" NAT plugin mode use before:
2568 * vpp# nat44 add address 4.4.4.4
2569 * To create address only static mapping between local and external address use:
2570 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
2571 * To create ICMP static mapping between local and external with ICMP echo
2572 * identifier 10 use:
2573 * vpp# nat44 add static mapping icmp local 10.0.0.3 10 external 4.4.4.4 10
2576 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
2577 .path = "nat44 add static mapping",
2578 .function = add_static_mapping_command_fn,
2580 "nat44 add static mapping tcp|udp|icmp local <addr> [<port|icmp-echo-id>] "
2581 "external <addr> [<port|icmp-echo-id>] [vrf <table-id>] [twice-nat|self-twice-nat] "
2582 "[out2in-only] [del]",
2587 * @cliexstart{nat44 add identity mapping}
2588 * Identity mapping translate an IP address to itself.
2589 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
2591 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
2592 * To create identity mapping for address 10.0.0.3 use:
2593 * vpp# nat44 add identity mapping 10.0.0.3
2594 * To create identity mapping for DHCP addressed interface use:
2595 * vpp# nat44 add identity mapping external GigabitEthernet0/a/0 tcp 3606
2598 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
2599 .path = "nat44 add identity mapping",
2600 .function = add_identity_mapping_command_fn,
2601 .short_help = "nat44 add identity mapping <ip4-addr>|external <interface> "
2602 "[<protocol> <port>] [vrf <table-id>] [del]",
2607 * @cliexstart{nat44 add load-balancing static mapping}
2608 * Service load balancing using NAT44
2609 * To add static mapping with load balancing for service with external IP
2610 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
2611 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
2612 * 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
2615 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
2616 .path = "nat44 add load-balancing static mapping",
2617 .function = add_lb_static_mapping_command_fn,
2619 "nat44 add load-balancing static mapping protocol tcp|udp "
2620 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2621 "probability <n> [twice-nat|self-twice-nat] [out2in-only] "
2622 "[affinity <timeout-seconds>] [del]",
2627 * @cliexstart{nat44 add load-balancing static mapping}
2628 * Modify service load balancing using NAT44
2629 * To add new back-end server 10.100.10.30:8080 for service load balancing
2630 * static mapping with external IP address 1.2.3.4 and TCP port 80 use:
2631 * vpp# nat44 add load-balancing back-end protocol tcp external 1.2.3.4:80 local 10.100.10.30:8080 probability 25
2634 VLIB_CLI_COMMAND (add_lb_backend_command, static) = {
2635 .path = "nat44 add load-balancing back-end",
2636 .function = add_lb_backend_command_fn,
2638 "nat44 add load-balancing back-end protocol tcp|udp "
2639 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2640 "probability <n> [del]",
2645 * @cliexstart{show nat44 static mappings}
2646 * Show NAT44 static mappings.
2647 * vpp# show nat44 static mappings
2648 * NAT44 static mappings:
2649 * local 10.0.0.3 external 4.4.4.4 vrf 0
2650 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
2651 * tcp vrf 0 external 1.2.3.4:80 out2in-only
2652 * local 10.100.10.10:8080 probability 80
2653 * local 10.100.10.20:8080 probability 20
2654 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
2655 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
2658 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
2659 .path = "show nat44 static mappings",
2660 .short_help = "show nat44 static mappings",
2661 .function = nat44_show_static_mappings_command_fn,
2666 * @cliexstart{nat44 add interface address}
2667 * Use NAT44 pool address from specific interfce
2668 * To add NAT44 pool address from specific interface use:
2669 * vpp# nat44 add interface address GigabitEthernet0/8/0
2672 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
2673 .path = "nat44 add interface address",
2674 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
2675 .function = snat_add_interface_address_command_fn,
2680 * @cliexstart{show nat44 interface address}
2681 * Show NAT44 pool address interfaces
2682 * vpp# show nat44 interface address
2683 * NAT44 pool address interfaces:
2684 * GigabitEthernet0/a/0
2685 * NAT44 twice-nat pool address interfaces:
2686 * GigabitEthernet0/8/0
2689 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
2690 .path = "show nat44 interface address",
2691 .short_help = "show nat44 interface address",
2692 .function = nat44_show_interface_address_command_fn,
2697 * @cliexstart{show nat44 sessions}
2698 * Show NAT44 sessions.
2701 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
2702 .path = "show nat44 sessions",
2703 .short_help = "show nat44 sessions [detail|metrics]",
2704 .function = nat44_show_sessions_command_fn,
2709 * @cliexstart{set nat44 session limit}
2710 * Set NAT44 session limit.
2713 VLIB_CLI_COMMAND (nat44_set_session_limit_command, static) = {
2714 .path = "set nat44 session limit",
2715 .short_help = "set nat44 session limit <limit> [vrf <table-id>]",
2716 .function = nat44_set_session_limit_command_fn,
2721 * @cliexstart{nat44 del user}
2722 * To delete all NAT44 user sessions:
2723 * vpp# nat44 del user 10.0.0.3
2726 VLIB_CLI_COMMAND (nat44_del_user_command, static) = {
2727 .path = "nat44 del user",
2728 .short_help = "nat44 del user <addr> [fib <index>]",
2729 .function = nat44_del_user_command_fn,
2734 * @cliexstart{clear nat44 sessions}
2735 * To clear all NAT44 sessions
2736 * vpp# clear nat44 sessions
2739 VLIB_CLI_COMMAND (nat44_clear_sessions_command, static) = {
2740 .path = "clear nat44 sessions",
2741 .short_help = "clear nat44 sessions",
2742 .function = nat44_clear_sessions_command_fn,
2747 * @cliexstart{nat44 del session}
2748 * To administratively delete NAT44 session by inside address and port use:
2749 * vpp# nat44 del session in 10.0.0.3:6303 tcp
2750 * To administratively delete NAT44 session by outside address and port use:
2751 * vpp# nat44 del session out 1.0.0.3:6033 udp
2754 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
2755 .path = "nat44 del session",
2756 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
2757 .function = nat44_del_session_command_fn,
2762 * @cliexstart{nat44 forwarding}
2763 * Enable or disable forwarding
2764 * Forward packets which don't match existing translation
2765 * or static mapping instead of dropping them.
2766 * To enable forwarding, use:
2767 * vpp# nat44 forwarding enable
2768 * To disable forwarding, use:
2769 * vpp# nat44 forwarding disable
2772 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
2773 .path = "nat44 forwarding",
2774 .short_help = "nat44 forwarding enable|disable",
2775 .function = snat_forwarding_set_command_fn,
2780 * @cliexstart{nat44 deterministic add}
2781 * Create bijective mapping of inside address to outside address and port range
2782 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
2784 * To create deterministic mapping between inside network 10.0.0.0/18 and
2785 * outside network 1.1.1.0/30 use:
2786 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
2789 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
2790 .path = "nat44 deterministic add",
2791 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
2792 .function = snat_det_map_command_fn,
2797 * @cliexpstart{show nat44 deterministic mappings}
2798 * Show NAT44 deterministic mappings
2799 * vpp# show nat44 deterministic mappings
2800 * NAT44 deterministic mappings:
2801 * in 10.0.0.0/24 out 1.1.1.1/32
2802 * outside address sharing ratio: 256
2803 * number of ports per inside host: 252
2804 * sessions number: 0
2807 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
2808 .path = "show nat44 deterministic mappings",
2809 .short_help = "show nat44 deterministic mappings",
2810 .function = nat44_det_show_mappings_command_fn,
2815 * @cliexstart{nat44 deterministic forward}
2816 * Return outside address and port range from inside address for deterministic
2818 * To obtain outside address and port of inside host use:
2819 * vpp# nat44 deterministic forward 10.0.0.2
2820 * 1.1.1.0:<1054-1068>
2823 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
2824 .path = "nat44 deterministic forward",
2825 .short_help = "nat44 deterministic forward <addr>",
2826 .function = snat_det_forward_command_fn,
2831 * @cliexstart{nat44 deterministic reverse}
2832 * Return inside address from outside address and port for deterministic NAT.
2833 * To obtain inside host address from outside address and port use:
2834 * #vpp nat44 deterministic reverse 1.1.1.1:1276
2838 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
2839 .path = "nat44 deterministic reverse",
2840 .short_help = "nat44 deterministic reverse <addr>:<port>",
2841 .function = snat_det_reverse_command_fn,
2846 * @cliexstart{show nat44 deterministic sessions}
2847 * Show NAT44 deterministic sessions.
2848 * vpp# show nat44 deterministic sessions
2849 * NAT44 deterministic sessions:
2850 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
2851 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
2852 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
2855 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
2856 .path = "show nat44 deterministic sessions",
2857 .short_help = "show nat44 deterministic sessions",
2858 .function = nat44_det_show_sessions_command_fn,
2863 * @cliexstart{nat44 deterministic close session out}
2864 * Close session using outside ip address and port
2865 * and external ip address and port, use:
2866 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
2869 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
2870 .path = "nat44 deterministic close session out",
2871 .short_help = "nat44 deterministic close session out "
2872 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
2873 .function = snat_det_close_session_out_fn,
2878 * @cliexstart{nat44 deterministic close session in}
2879 * Close session using inside ip address and port
2880 * and external ip address and port, use:
2881 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
2884 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
2885 .path = "nat44 deterministic close session in",
2886 .short_help = "nat44 deterministic close session in "
2887 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
2888 .function = snat_det_close_session_in_fn,
2894 * fd.io coding-style-patch-verification: ON
2897 * eval: (c-set-style "gnu")