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/nat_affinity.h>
26 #include <vnet/fib/fib_table.h>
28 #define UNSUPPORTED_IN_DET_MODE_STR \
29 "This command is unsupported in deterministic mode"
30 #define SUPPORTED_ONLY_IN_DET_MODE_STR \
31 "This command is supported only in deterministic mode"
34 set_workers_command_fn (vlib_main_t * vm,
35 unformat_input_t * input, vlib_cli_command_t * cmd)
37 unformat_input_t _line_input, *line_input = &_line_input;
38 snat_main_t *sm = &snat_main;
41 clib_error_t *error = 0;
43 if (sm->deterministic)
44 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
46 /* Get a line of input. */
47 if (!unformat_user (input, unformat_line_input, line_input))
50 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
52 if (unformat (line_input, "%U", unformat_bitmap_list, &bitmap))
56 error = clib_error_return (0, "unknown input '%U'",
57 format_unformat_error, line_input);
64 error = clib_error_return (0, "List of workers must be specified.");
68 rv = snat_set_workers (bitmap);
70 clib_bitmap_free (bitmap);
74 case VNET_API_ERROR_INVALID_WORKER:
75 error = clib_error_return (0, "Invalid worker(s).");
77 case VNET_API_ERROR_FEATURE_DISABLED:
78 error = clib_error_return (0,
79 "Supported only if 2 or more workes available.");
86 unformat_free (line_input);
92 nat_show_workers_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
93 vlib_cli_command_t * cmd)
95 snat_main_t *sm = &snat_main;
98 if (sm->deterministic)
99 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
101 if (sm->num_workers > 1)
103 vlib_cli_output (vm, "%d workers", vec_len (sm->workers));
105 vec_foreach (worker, sm->workers)
107 vlib_worker_thread_t *w =
108 vlib_worker_threads + *worker + sm->first_worker_index;
109 vlib_cli_output (vm, " %s", w->name);
117 static clib_error_t *
118 snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm,
119 unformat_input_t * input,
120 vlib_cli_command_t * cmd)
122 unformat_input_t _line_input, *line_input = &_line_input;
127 clib_error_t *error = 0;
129 /* Get a line of input. */
130 if (!unformat_user (input, unformat_line_input, line_input))
133 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
135 if (unformat (line_input, "domain %d", &domain_id))
137 else if (unformat (line_input, "src-port %d", &src_port))
139 else if (unformat (line_input, "disable"))
143 error = clib_error_return (0, "unknown input '%U'",
144 format_unformat_error, line_input);
149 rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port);
153 error = clib_error_return (0, "ipfix logging enable failed");
158 unformat_free (line_input);
163 static clib_error_t *
164 nat44_show_hash_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
165 vlib_cli_command_t * cmd)
167 snat_main_t *sm = &snat_main;
168 snat_main_per_thread_data_t *tsm;
169 nat_affinity_main_t *nam = &nat_affinity_main;
173 if (unformat (input, "detail"))
175 else if (unformat (input, "verbose"))
178 vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
180 vlib_cli_output (vm, "%U",
181 format_bihash_8_8, &sm->static_mapping_by_external,
183 vec_foreach_index (i, sm->per_thread_data)
185 tsm = vec_elt_at_index (sm->per_thread_data, i);
186 vlib_cli_output (vm, "-------- thread %d %s --------\n",
187 i, vlib_worker_threads[i].name);
188 if (sm->endpoint_dependent)
190 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->in2out_ed,
192 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->out2in_ed,
197 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->in2out, verbose);
198 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->out2in, verbose);
200 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->user_hash, verbose);
203 if (sm->endpoint_dependent)
204 vlib_cli_output (vm, "%U", format_bihash_16_8, &nam->affinity_hash,
209 static clib_error_t *
210 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
211 unformat_input_t * input,
212 vlib_cli_command_t * cmd)
214 unformat_input_t _line_input, *line_input = &_line_input;
215 snat_main_t *sm = &snat_main;
216 clib_error_t *error = 0;
217 u32 psid, psid_offset, psid_length;
219 if (sm->deterministic)
220 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
222 /* Get a line of input. */
223 if (!unformat_user (input, unformat_line_input, line_input))
226 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
228 if (unformat (line_input, "default"))
229 nat_set_alloc_addr_and_port_default ();
232 (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
233 &psid_offset, &psid_length))
234 nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
238 error = clib_error_return (0, "unknown input '%U'",
239 format_unformat_error, line_input);
245 unformat_free (line_input);
250 static clib_error_t *
251 add_address_command_fn (vlib_main_t * vm,
252 unformat_input_t * input, vlib_cli_command_t * cmd)
254 unformat_input_t _line_input, *line_input = &_line_input;
255 snat_main_t *sm = &snat_main;
256 ip4_address_t start_addr, end_addr, this_addr;
257 u32 start_host_order, end_host_order;
262 clib_error_t *error = 0;
265 if (sm->deterministic)
266 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
268 /* Get a line of input. */
269 if (!unformat_user (input, unformat_line_input, line_input))
272 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
274 if (unformat (line_input, "%U - %U",
275 unformat_ip4_address, &start_addr,
276 unformat_ip4_address, &end_addr))
278 else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
280 else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
281 end_addr = start_addr;
282 else if (unformat (line_input, "twice-nat"))
284 else if (unformat (line_input, "del"))
288 error = clib_error_return (0, "unknown input '%U'",
289 format_unformat_error, line_input);
294 if (sm->static_mapping_only)
296 error = clib_error_return (0, "static mapping only mode");
300 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
301 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
303 if (end_host_order < start_host_order)
305 error = clib_error_return (0, "end address less than start address");
309 count = (end_host_order - start_host_order) + 1;
312 nat_log_info ("%U - %U, %d addresses...",
313 format_ip4_address, &start_addr,
314 format_ip4_address, &end_addr, count);
316 this_addr = start_addr;
318 for (i = 0; i < count; i++)
321 rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
323 rv = snat_del_address (sm, this_addr, 0, twice_nat);
327 case VNET_API_ERROR_VALUE_EXIST:
328 error = clib_error_return (0, "NAT address already in use.");
330 case VNET_API_ERROR_NO_SUCH_ENTRY:
331 error = clib_error_return (0, "NAT address not exist.");
333 case VNET_API_ERROR_UNSPECIFIED:
335 clib_error_return (0, "NAT address used in static mapping.");
337 case VNET_API_ERROR_FEATURE_DISABLED:
339 clib_error_return (0,
340 "twice NAT available only for endpoint-dependent mode.");
347 nat44_add_del_address_dpo (this_addr, is_add);
349 increment_v4_address (&this_addr);
353 unformat_free (line_input);
358 static clib_error_t *
359 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
360 vlib_cli_command_t * cmd)
362 snat_main_t *sm = &snat_main;
365 if (sm->deterministic)
366 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
368 vlib_cli_output (vm, "NAT44 pool addresses:");
370 vec_foreach (ap, sm->addresses)
372 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
373 if (ap->fib_index != ~0)
374 vlib_cli_output (vm, " tenant VRF: %u",
375 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
377 vlib_cli_output (vm, " tenant VRF independent");
378 #define _(N, i, n, s) \
379 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
380 foreach_snat_protocol
383 vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
384 vec_foreach (ap, sm->twice_nat_addresses)
386 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
387 if (ap->fib_index != ~0)
388 vlib_cli_output (vm, " tenant VRF: %u",
389 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
391 vlib_cli_output (vm, " tenant VRF independent");
392 #define _(N, i, n, s) \
393 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
394 foreach_snat_protocol
401 static clib_error_t *
402 snat_feature_command_fn (vlib_main_t * vm,
403 unformat_input_t * input, vlib_cli_command_t * cmd)
405 unformat_input_t _line_input, *line_input = &_line_input;
406 vnet_main_t *vnm = vnet_get_main ();
407 clib_error_t *error = 0;
409 u32 *inside_sw_if_indices = 0;
410 u32 *outside_sw_if_indices = 0;
411 u8 is_output_feature = 0;
417 /* Get a line of input. */
418 if (!unformat_user (input, unformat_line_input, line_input))
421 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
423 if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
425 vec_add1 (inside_sw_if_indices, sw_if_index);
426 else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
428 vec_add1 (outside_sw_if_indices, sw_if_index);
429 else if (unformat (line_input, "output-feature"))
430 is_output_feature = 1;
431 else if (unformat (line_input, "del"))
435 error = clib_error_return (0, "unknown input '%U'",
436 format_unformat_error, line_input);
441 if (vec_len (inside_sw_if_indices))
443 for (i = 0; i < vec_len (inside_sw_if_indices); i++)
445 sw_if_index = inside_sw_if_indices[i];
446 if (is_output_feature)
448 if (snat_interface_add_del_output_feature
449 (sw_if_index, 1, is_del))
451 error = clib_error_return (0, "%s %U failed",
452 is_del ? "del" : "add",
453 format_vnet_sw_if_index_name,
460 if (snat_interface_add_del (sw_if_index, 1, is_del))
462 error = clib_error_return (0, "%s %U failed",
463 is_del ? "del" : "add",
464 format_vnet_sw_if_index_name,
472 if (vec_len (outside_sw_if_indices))
474 for (i = 0; i < vec_len (outside_sw_if_indices); i++)
476 sw_if_index = outside_sw_if_indices[i];
477 if (is_output_feature)
479 if (snat_interface_add_del_output_feature
480 (sw_if_index, 0, is_del))
482 error = clib_error_return (0, "%s %U failed",
483 is_del ? "del" : "add",
484 format_vnet_sw_if_index_name,
491 if (snat_interface_add_del (sw_if_index, 0, is_del))
493 error = clib_error_return (0, "%s %U failed",
494 is_del ? "del" : "add",
495 format_vnet_sw_if_index_name,
504 unformat_free (line_input);
505 vec_free (inside_sw_if_indices);
506 vec_free (outside_sw_if_indices);
511 static clib_error_t *
512 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
513 vlib_cli_command_t * cmd)
515 snat_main_t *sm = &snat_main;
517 vnet_main_t *vnm = vnet_get_main ();
519 vlib_cli_output (vm, "NAT44 interfaces:");
521 pool_foreach (i, sm->interfaces,
523 vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
525 (nat_interface_is_inside(i) &&
526 nat_interface_is_outside(i)) ? "in out" :
527 (nat_interface_is_inside(i) ? "in" : "out"));
530 pool_foreach (i, sm->output_feature_interfaces,
532 vlib_cli_output (vm, " %U output-feature %s",
533 format_vnet_sw_if_index_name, vnm,
535 (nat_interface_is_inside(i) &&
536 nat_interface_is_outside(i)) ? "in out" :
537 (nat_interface_is_inside(i) ? "in" : "out"));
544 static clib_error_t *
545 add_static_mapping_command_fn (vlib_main_t * vm,
546 unformat_input_t * input,
547 vlib_cli_command_t * cmd)
549 unformat_input_t _line_input, *line_input = &_line_input;
550 snat_main_t *sm = &snat_main;
551 clib_error_t *error = 0;
552 ip4_address_t l_addr, e_addr;
553 u32 l_port = 0, e_port = 0, vrf_id = ~0;
556 u32 sw_if_index = ~0;
557 vnet_main_t *vnm = vnet_get_main ();
559 snat_protocol_t proto = ~0;
561 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
564 if (sm->deterministic)
565 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
567 /* Get a line of input. */
568 if (!unformat_user (input, unformat_line_input, line_input))
571 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
573 if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
577 if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
579 else if (unformat (line_input, "external %U %u", unformat_ip4_address,
582 else if (unformat (line_input, "external %U", unformat_ip4_address,
585 else if (unformat (line_input, "external %U %u",
586 unformat_vnet_sw_interface, vnm, &sw_if_index,
590 else if (unformat (line_input, "external %U",
591 unformat_vnet_sw_interface, vnm, &sw_if_index))
593 else if (unformat (line_input, "vrf %u", &vrf_id))
595 else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
597 else if (unformat (line_input, "twice-nat"))
598 twice_nat = TWICE_NAT;
599 else if (unformat (line_input, "self-twice-nat"))
600 twice_nat = TWICE_NAT_SELF;
601 else if (unformat (line_input, "out2in-only"))
603 else if (unformat (line_input, "del"))
607 error = clib_error_return (0, "unknown input: '%U'",
608 format_unformat_error, line_input);
613 if (twice_nat && addr_only)
615 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
619 if (!addr_only && !proto_set)
621 error = clib_error_return (0, "missing protocol");
625 rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
626 vrf_id, addr_only, sw_if_index, proto, is_add,
627 twice_nat, out2in_only, 0);
631 case VNET_API_ERROR_INVALID_VALUE:
632 error = clib_error_return (0, "External port already in use.");
634 case VNET_API_ERROR_NO_SUCH_ENTRY:
636 error = clib_error_return (0, "External addres must be allocated.");
638 error = clib_error_return (0, "Mapping not exist.");
640 case VNET_API_ERROR_NO_SUCH_FIB:
641 error = clib_error_return (0, "No such VRF id.");
643 case VNET_API_ERROR_VALUE_EXIST:
644 error = clib_error_return (0, "Mapping already exist.");
646 case VNET_API_ERROR_FEATURE_DISABLED:
648 clib_error_return (0,
649 "twice-nat/out2in-only available only for endpoint-dependent mode.");
656 unformat_free (line_input);
661 static clib_error_t *
662 add_identity_mapping_command_fn (vlib_main_t * vm,
663 unformat_input_t * input,
664 vlib_cli_command_t * cmd)
666 unformat_input_t _line_input, *line_input = &_line_input;
667 snat_main_t *sm = &snat_main;
668 clib_error_t *error = 0;
670 u32 port = 0, vrf_id = ~0;
673 u32 sw_if_index = ~0;
674 vnet_main_t *vnm = vnet_get_main ();
676 snat_protocol_t proto;
678 if (sm->deterministic)
679 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
683 /* Get a line of input. */
684 if (!unformat_user (input, unformat_line_input, line_input))
687 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
689 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
691 else if (unformat (line_input, "external %U",
692 unformat_vnet_sw_interface, vnm, &sw_if_index))
694 else if (unformat (line_input, "vrf %u", &vrf_id))
696 else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
699 else if (unformat (line_input, "del"))
703 error = clib_error_return (0, "unknown input: '%U'",
704 format_unformat_error, line_input);
709 rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
710 vrf_id, addr_only, sw_if_index, proto, is_add,
715 case VNET_API_ERROR_INVALID_VALUE:
716 error = clib_error_return (0, "External port already in use.");
718 case VNET_API_ERROR_NO_SUCH_ENTRY:
720 error = clib_error_return (0, "External addres must be allocated.");
722 error = clib_error_return (0, "Mapping not exist.");
724 case VNET_API_ERROR_NO_SUCH_FIB:
725 error = clib_error_return (0, "No such VRF id.");
727 case VNET_API_ERROR_VALUE_EXIST:
728 error = clib_error_return (0, "Mapping already exist.");
735 unformat_free (line_input);
740 static clib_error_t *
741 add_lb_static_mapping_command_fn (vlib_main_t * vm,
742 unformat_input_t * input,
743 vlib_cli_command_t * cmd)
745 unformat_input_t _line_input, *line_input = &_line_input;
746 snat_main_t *sm = &snat_main;
747 clib_error_t *error = 0;
748 ip4_address_t l_addr, e_addr;
749 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
752 snat_protocol_t proto;
754 nat44_lb_addr_port_t *locals = 0, local;
755 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
758 if (sm->deterministic)
759 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
761 /* Get a line of input. */
762 if (!unformat_user (input, unformat_line_input, line_input))
765 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
767 if (unformat (line_input, "local %U:%u probability %u",
768 unformat_ip4_address, &l_addr, &l_port, &probability))
770 memset (&local, 0, sizeof (local));
772 local.port = (u16) l_port;
773 local.probability = (u8) probability;
774 vec_add1 (locals, local);
776 else if (unformat (line_input, "local %U:%u vrf %u probability %u",
777 unformat_ip4_address, &l_addr, &l_port, &vrf_id,
780 memset (&local, 0, sizeof (local));
782 local.port = (u16) l_port;
783 local.probability = (u8) probability;
784 local.vrf_id = vrf_id;
785 vec_add1 (locals, local);
787 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
790 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
793 else if (unformat (line_input, "twice-nat"))
794 twice_nat = TWICE_NAT;
795 else if (unformat (line_input, "self-twice-nat"))
796 twice_nat = TWICE_NAT_SELF;
797 else if (unformat (line_input, "out2in-only"))
799 else if (unformat (line_input, "del"))
801 else if (unformat (line_input, "affinity %u", &affinity))
805 error = clib_error_return (0, "unknown input: '%U'",
806 format_unformat_error, line_input);
811 if (vec_len (locals) < 2)
813 error = clib_error_return (0, "at least two local must be set");
819 error = clib_error_return (0, "missing protocol");
823 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, locals,
824 is_add, twice_nat, out2in_only, 0,
829 case VNET_API_ERROR_INVALID_VALUE:
830 error = clib_error_return (0, "External port already in use.");
832 case VNET_API_ERROR_NO_SUCH_ENTRY:
834 error = clib_error_return (0, "External addres must be allocated.");
836 error = clib_error_return (0, "Mapping not exist.");
838 case VNET_API_ERROR_VALUE_EXIST:
839 error = clib_error_return (0, "Mapping already exist.");
841 case VNET_API_ERROR_FEATURE_DISABLED:
843 clib_error_return (0, "Available only for endpoint-dependent mode.");
850 unformat_free (line_input);
856 static clib_error_t *
857 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
858 unformat_input_t * input,
859 vlib_cli_command_t * cmd)
861 snat_main_t *sm = &snat_main;
862 snat_static_mapping_t *m;
863 snat_static_map_resolve_t *rp;
865 if (sm->deterministic)
866 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
868 vlib_cli_output (vm, "NAT44 static mappings:");
870 pool_foreach (m, sm->static_mappings,
872 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
874 vec_foreach (rp, sm->to_resolve)
875 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
881 static clib_error_t *
882 snat_add_interface_address_command_fn (vlib_main_t * vm,
883 unformat_input_t * input,
884 vlib_cli_command_t * cmd)
886 snat_main_t *sm = &snat_main;
887 unformat_input_t _line_input, *line_input = &_line_input;
891 clib_error_t *error = 0;
894 if (sm->deterministic)
895 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
897 /* Get a line of input. */
898 if (!unformat_user (input, unformat_line_input, line_input))
901 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
903 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
904 sm->vnet_main, &sw_if_index))
906 else if (unformat (line_input, "twice-nat"))
908 else if (unformat (line_input, "del"))
912 error = clib_error_return (0, "unknown input '%U'",
913 format_unformat_error, line_input);
918 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
926 error = clib_error_return (0, "snat_add_interface_address returned %d",
932 unformat_free (line_input);
937 static clib_error_t *
938 nat44_show_interface_address_command_fn (vlib_main_t * vm,
939 unformat_input_t * input,
940 vlib_cli_command_t * cmd)
942 snat_main_t *sm = &snat_main;
943 vnet_main_t *vnm = vnet_get_main ();
946 if (sm->deterministic)
947 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
950 vlib_cli_output (vm, "NAT44 pool address interfaces:");
951 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
953 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
956 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
957 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
959 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
967 static clib_error_t *
968 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
969 vlib_cli_command_t * cmd)
972 snat_main_t *sm = &snat_main;
973 snat_main_per_thread_data_t *tsm;
977 if (sm->deterministic)
978 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
980 if (unformat (input, "detail"))
983 vlib_cli_output (vm, "NAT44 sessions:");
986 vec_foreach_index (i, sm->per_thread_data)
988 tsm = vec_elt_at_index (sm->per_thread_data, i);
990 vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
991 i, vlib_worker_threads[i].name,
992 pool_elts (tsm->sessions));
993 pool_foreach (u, tsm->users,
995 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, verbose);
1003 static clib_error_t *
1004 nat44_del_session_command_fn (vlib_main_t * vm,
1005 unformat_input_t * input,
1006 vlib_cli_command_t * cmd)
1008 snat_main_t *sm = &snat_main;
1009 unformat_input_t _line_input, *line_input = &_line_input;
1010 int is_in = 0, is_ed = 0;
1011 clib_error_t *error = 0;
1012 ip4_address_t addr, eh_addr;
1013 u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
1014 snat_protocol_t proto;
1017 if (sm->deterministic)
1018 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1020 /* Get a line of input. */
1021 if (!unformat_user (input, unformat_line_input, line_input))
1024 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1027 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1028 unformat_snat_protocol, &proto))
1030 else if (unformat (line_input, "in"))
1033 vrf_id = sm->inside_vrf_id;
1035 else if (unformat (line_input, "out"))
1038 vrf_id = sm->outside_vrf_id;
1040 else if (unformat (line_input, "vrf %u", &vrf_id))
1044 (line_input, "external-host %U:%u", unformat_ip4_address,
1045 &eh_addr, &eh_port))
1049 error = clib_error_return (0, "unknown input '%U'",
1050 format_unformat_error, line_input);
1057 nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port,
1058 snat_proto_to_ip_proto (proto), vrf_id, is_in);
1060 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
1068 error = clib_error_return (0, "nat44_del_session returned %d", rv);
1073 unformat_free (line_input);
1078 static clib_error_t *
1079 snat_forwarding_set_command_fn (vlib_main_t * vm,
1080 unformat_input_t * input,
1081 vlib_cli_command_t * cmd)
1083 snat_main_t *sm = &snat_main;
1084 unformat_input_t _line_input, *line_input = &_line_input;
1085 u8 forwarding_enable;
1086 u8 forwarding_enable_set = 0;
1087 clib_error_t *error = 0;
1089 if (sm->deterministic)
1090 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1092 /* Get a line of input. */
1093 if (!unformat_user (input, unformat_line_input, line_input))
1094 return clib_error_return (0, "'enable' or 'disable' expected");
1096 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1098 if (!forwarding_enable_set && unformat (line_input, "enable"))
1100 forwarding_enable = 1;
1101 forwarding_enable_set = 1;
1103 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1105 forwarding_enable = 0;
1106 forwarding_enable_set = 1;
1110 error = clib_error_return (0, "unknown input '%U'",
1111 format_unformat_error, line_input);
1116 if (!forwarding_enable_set)
1118 error = clib_error_return (0, "'enable' or 'disable' expected");
1122 sm->forwarding_enabled = forwarding_enable;
1125 unformat_free (line_input);
1130 static clib_error_t *
1131 snat_det_map_command_fn (vlib_main_t * vm,
1132 unformat_input_t * input, vlib_cli_command_t * cmd)
1134 snat_main_t *sm = &snat_main;
1135 unformat_input_t _line_input, *line_input = &_line_input;
1136 ip4_address_t in_addr, out_addr;
1137 u32 in_plen, out_plen;
1139 clib_error_t *error = 0;
1141 if (!sm->deterministic)
1142 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1144 /* Get a line of input. */
1145 if (!unformat_user (input, unformat_line_input, line_input))
1148 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1151 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1155 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1158 else if (unformat (line_input, "del"))
1162 error = clib_error_return (0, "unknown input '%U'",
1163 format_unformat_error, line_input);
1168 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1173 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1178 unformat_free (line_input);
1183 static clib_error_t *
1184 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1185 unformat_input_t * input,
1186 vlib_cli_command_t * cmd)
1188 snat_main_t *sm = &snat_main;
1191 if (!sm->deterministic)
1192 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1194 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1196 pool_foreach (dm, sm->det_maps,
1198 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1199 format_ip4_address, &dm->in_addr, dm->in_plen,
1200 format_ip4_address, &dm->out_addr, dm->out_plen);
1201 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1203 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1204 dm->ports_per_host);
1205 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1212 static clib_error_t *
1213 snat_det_forward_command_fn (vlib_main_t * vm,
1214 unformat_input_t * input,
1215 vlib_cli_command_t * cmd)
1217 snat_main_t *sm = &snat_main;
1218 unformat_input_t _line_input, *line_input = &_line_input;
1219 ip4_address_t in_addr, out_addr;
1222 clib_error_t *error = 0;
1224 if (!sm->deterministic)
1225 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1227 /* Get a line of input. */
1228 if (!unformat_user (input, unformat_line_input, line_input))
1231 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1233 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1237 error = clib_error_return (0, "unknown input '%U'",
1238 format_unformat_error, line_input);
1243 dm = snat_det_map_by_user (sm, &in_addr);
1245 vlib_cli_output (vm, "no match");
1248 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1249 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1250 lo_port, lo_port + dm->ports_per_host - 1);
1254 unformat_free (line_input);
1259 static clib_error_t *
1260 snat_det_reverse_command_fn (vlib_main_t * vm,
1261 unformat_input_t * input,
1262 vlib_cli_command_t * cmd)
1264 snat_main_t *sm = &snat_main;
1265 unformat_input_t _line_input, *line_input = &_line_input;
1266 ip4_address_t in_addr, out_addr;
1269 clib_error_t *error = 0;
1271 if (!sm->deterministic)
1272 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1274 /* Get a line of input. */
1275 if (!unformat_user (input, unformat_line_input, line_input))
1278 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1281 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1285 error = clib_error_return (0, "unknown input '%U'",
1286 format_unformat_error, line_input);
1291 if (out_port < 1024 || out_port > 65535)
1293 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1297 dm = snat_det_map_by_out (sm, &out_addr);
1299 vlib_cli_output (vm, "no match");
1302 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1303 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1307 unformat_free (line_input);
1312 static clib_error_t *
1313 set_timeout_command_fn (vlib_main_t * vm,
1314 unformat_input_t * input, vlib_cli_command_t * cmd)
1316 snat_main_t *sm = &snat_main;
1317 unformat_input_t _line_input, *line_input = &_line_input;
1318 clib_error_t *error = 0;
1320 /* Get a line of input. */
1321 if (!unformat_user (input, unformat_line_input, line_input))
1324 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1326 if (unformat (line_input, "udp %u", &sm->udp_timeout))
1328 if (nat64_set_udp_timeout (sm->udp_timeout))
1330 error = clib_error_return (0, "Invalid UDP timeout value");
1334 else if (unformat (line_input, "tcp-established %u",
1335 &sm->tcp_established_timeout))
1337 if (nat64_set_tcp_timeouts
1338 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1341 clib_error_return (0,
1342 "Invalid TCP established timeouts value");
1346 else if (unformat (line_input, "tcp-transitory %u",
1347 &sm->tcp_transitory_timeout))
1349 if (nat64_set_tcp_timeouts
1350 (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1353 clib_error_return (0,
1354 "Invalid TCP transitory timeouts value");
1358 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1360 if (nat64_set_icmp_timeout (sm->icmp_timeout))
1362 error = clib_error_return (0, "Invalid ICMP timeout value");
1366 else if (unformat (line_input, "reset"))
1368 sm->udp_timeout = SNAT_UDP_TIMEOUT;
1369 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1370 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1371 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1372 nat64_set_udp_timeout (0);
1373 nat64_set_icmp_timeout (0);
1374 nat64_set_tcp_timeouts (0, 0);
1378 error = clib_error_return (0, "unknown input '%U'",
1379 format_unformat_error, line_input);
1385 unformat_free (line_input);
1390 static clib_error_t *
1391 nat_show_timeouts_command_fn (vlib_main_t * vm,
1392 unformat_input_t * input,
1393 vlib_cli_command_t * cmd)
1395 snat_main_t *sm = &snat_main;
1397 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1398 vlib_cli_output (vm, "tcp-established timeout: %dsec",
1399 sm->tcp_established_timeout);
1400 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1401 sm->tcp_transitory_timeout);
1402 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1407 static clib_error_t *
1408 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1409 unformat_input_t * input,
1410 vlib_cli_command_t * cmd)
1412 snat_main_t *sm = &snat_main;
1414 snat_det_session_t *ses;
1417 if (!sm->deterministic)
1418 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1420 vlib_cli_output (vm, "NAT44 deterministic sessions:");
1422 pool_foreach (dm, sm->det_maps,
1424 vec_foreach_index (i, dm->sessions)
1426 ses = vec_elt_at_index (dm->sessions, i);
1428 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
1435 static clib_error_t *
1436 snat_det_close_session_out_fn (vlib_main_t * vm,
1437 unformat_input_t * input,
1438 vlib_cli_command_t * cmd)
1440 snat_main_t *sm = &snat_main;
1441 unformat_input_t _line_input, *line_input = &_line_input;
1442 ip4_address_t out_addr, ext_addr, in_addr;
1443 u32 out_port, ext_port;
1445 snat_det_session_t *ses;
1446 snat_det_out_key_t key;
1447 clib_error_t *error = 0;
1449 if (!sm->deterministic)
1450 return clib_error_return (0, SUPPORTED_ONLY_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:%d %U:%d",
1459 unformat_ip4_address, &out_addr, &out_port,
1460 unformat_ip4_address, &ext_addr, &ext_port))
1464 error = clib_error_return (0, "unknown input '%U'",
1465 format_unformat_error, line_input);
1470 unformat_free (line_input);
1472 dm = snat_det_map_by_out (sm, &out_addr);
1474 vlib_cli_output (vm, "no match");
1477 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
1478 key.ext_host_addr = out_addr;
1479 key.ext_host_port = ntohs ((u16) ext_port);
1480 key.out_port = ntohs ((u16) out_port);
1481 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
1483 vlib_cli_output (vm, "no match");
1485 snat_det_ses_close (dm, ses);
1489 unformat_free (line_input);
1494 static clib_error_t *
1495 snat_det_close_session_in_fn (vlib_main_t * vm,
1496 unformat_input_t * input,
1497 vlib_cli_command_t * cmd)
1499 snat_main_t *sm = &snat_main;
1500 unformat_input_t _line_input, *line_input = &_line_input;
1501 ip4_address_t in_addr, ext_addr;
1502 u32 in_port, ext_port;
1504 snat_det_session_t *ses;
1505 snat_det_out_key_t key;
1506 clib_error_t *error = 0;
1508 if (!sm->deterministic)
1509 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1511 /* Get a line of input. */
1512 if (!unformat_user (input, unformat_line_input, line_input))
1515 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1517 if (unformat (line_input, "%U:%d %U:%d",
1518 unformat_ip4_address, &in_addr, &in_port,
1519 unformat_ip4_address, &ext_addr, &ext_port))
1523 error = clib_error_return (0, "unknown input '%U'",
1524 format_unformat_error, line_input);
1529 unformat_free (line_input);
1531 dm = snat_det_map_by_user (sm, &in_addr);
1533 vlib_cli_output (vm, "no match");
1536 key.ext_host_addr = ext_addr;
1537 key.ext_host_port = ntohs ((u16) ext_port);
1539 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
1541 vlib_cli_output (vm, "no match");
1543 snat_det_ses_close (dm, ses);
1547 unformat_free (line_input);
1555 * @cliexstart{set snat workers}
1556 * Set NAT workers if 2 or more workers available, use:
1557 * vpp# set snat workers 0-2,5
1560 VLIB_CLI_COMMAND (set_workers_command, static) = {
1561 .path = "set nat workers",
1562 .function = set_workers_command_fn,
1563 .short_help = "set nat workers <workers-list>",
1568 * @cliexstart{show nat workers}
1570 * vpp# show nat workers:
1576 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
1577 .path = "show nat workers",
1578 .short_help = "show nat workers",
1579 .function = nat_show_workers_commnad_fn,
1584 * @cliexstart{set nat timeout}
1585 * Set values of timeouts for NAT sessions (in seconds), use:
1586 * vpp# set nat timeout udp 120 tcp-established 7500 tcp-transitory 250 icmp 90
1587 * To reset default values use:
1588 * vpp# set nat44 deterministic timeout reset
1591 VLIB_CLI_COMMAND (set_timeout_command, static) = {
1592 .path = "set nat timeout",
1593 .function = set_timeout_command_fn,
1595 "set nat timeout [udp <sec> | tcp-established <sec> "
1596 "tcp-transitory <sec> | icmp <sec> | reset]",
1601 * @cliexstart{show nat timeouts}
1602 * Show values of timeouts for NAT sessions.
1603 * vpp# show nat timeouts
1604 * udp timeout: 300sec
1605 * tcp-established timeout: 7440sec
1606 * tcp-transitory timeout: 240sec
1607 * icmp timeout: 60sec
1610 VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = {
1611 .path = "show nat timeouts",
1612 .short_help = "show nat timeouts",
1613 .function = nat_show_timeouts_command_fn,
1618 * @cliexstart{snat ipfix logging}
1619 * To enable NAT IPFIX logging use:
1620 * vpp# nat ipfix logging
1621 * To set IPFIX exporter use:
1622 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
1625 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
1626 .path = "nat ipfix logging",
1627 .function = snat_ipfix_logging_enable_disable_command_fn,
1628 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
1633 * @cliexstart{nat addr-port-assignment-alg}
1634 * Set address and port assignment algorithm
1635 * For the MAP-E CE limit port choice based on PSID use:
1636 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
1637 * To set standard (default) address and port assignment algorithm use:
1638 * vpp# nat addr-port-assignment-alg default
1641 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
1642 .path = "nat addr-port-assignment-alg",
1643 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
1644 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
1649 * @cliexstart{show nat44 hash tables}
1650 * Show NAT44 hash tables
1653 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
1654 .path = "show nat44 hash tables",
1655 .short_help = "show nat44 hash tables [detail|verbose]",
1656 .function = nat44_show_hash_commnad_fn,
1661 * @cliexstart{nat44 add address}
1662 * Add/delete NAT44 pool address.
1663 * To add NAT44 pool address use:
1664 * vpp# nat44 add address 172.16.1.3
1665 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
1666 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
1667 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
1670 VLIB_CLI_COMMAND (add_address_command, static) = {
1671 .path = "nat44 add address",
1672 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
1673 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
1674 .function = add_address_command_fn,
1679 * @cliexstart{show nat44 addresses}
1680 * Show NAT44 pool addresses.
1681 * vpp# show nat44 addresses
1682 * NAT44 pool addresses:
1684 * tenant VRF independent
1693 * NAT44 twice-nat pool addresses:
1695 * tenant VRF independent
1701 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
1702 .path = "show nat44 addresses",
1703 .short_help = "show nat44 addresses",
1704 .function = nat44_show_addresses_command_fn,
1709 * @cliexstart{set interface nat44}
1710 * Enable/disable NAT44 feature on the interface.
1711 * To enable NAT44 feature with local network interface use:
1712 * vpp# set interface nat44 in GigabitEthernet0/8/0
1713 * To enable NAT44 feature with external network interface use:
1714 * vpp# set interface nat44 out GigabitEthernet0/a/0
1717 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
1718 .path = "set interface nat44",
1719 .function = snat_feature_command_fn,
1720 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
1726 * @cliexstart{show nat44 interfaces}
1727 * Show interfaces with NAT44 feature.
1728 * vpp# show nat44 interfaces
1730 * GigabitEthernet0/8/0 in
1731 * GigabitEthernet0/a/0 out
1734 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
1735 .path = "show nat44 interfaces",
1736 .short_help = "show nat44 interfaces",
1737 .function = nat44_show_interfaces_command_fn,
1742 * @cliexstart{nat44 add static mapping}
1743 * Static mapping allows hosts on the external network to initiate connection
1744 * to to the local network host.
1745 * To create static mapping between local host address 10.0.0.3 port 6303 and
1746 * external address 4.4.4.4 port 3606 for TCP protocol use:
1747 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
1748 * If not runnig "static mapping only" NAT plugin mode use before:
1749 * vpp# nat44 add address 4.4.4.4
1750 * To create static mapping between local and external address use:
1751 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
1754 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
1755 .path = "nat44 add static mapping",
1756 .function = add_static_mapping_command_fn,
1758 "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
1759 "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
1760 "[out2in-only] [del]",
1765 * @cliexstart{nat44 add identity mapping}
1766 * Identity mapping translate an IP address to itself.
1767 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
1769 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
1770 * To create identity mapping for address 10.0.0.3 use:
1771 * vpp# nat44 add identity mapping 10.0.0.3
1772 * To create identity mapping for DHCP addressed interface use:
1773 * vpp# nat44 add identity mapping GigabitEthernet0/a/0 tcp 3606
1776 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
1777 .path = "nat44 add identity mapping",
1778 .function = add_identity_mapping_command_fn,
1779 .short_help = "nat44 add identity mapping <interface>|<ip4-addr> "
1780 "[<protocol> <port>] [vrf <table-id>] [del]",
1785 * @cliexstart{nat44 add load-balancing static mapping}
1786 * Service load balancing using NAT44
1787 * To add static mapping with load balancing for service with external IP
1788 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
1789 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
1790 * 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
1793 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
1794 .path = "nat44 add load-balancing static mapping",
1795 .function = add_lb_static_mapping_command_fn,
1797 "nat44 add load-balancing static mapping protocol tcp|udp "
1798 "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
1799 "probability <n> [twice-nat|self-twice-nat] [out2in-only] "
1800 "[affinity <timeout-seconds>] [del]",
1805 * @cliexstart{show nat44 static mappings}
1806 * Show NAT44 static mappings.
1807 * vpp# show nat44 static mappings
1808 * NAT44 static mappings:
1809 * local 10.0.0.3 external 4.4.4.4 vrf 0
1810 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
1811 * tcp vrf 0 external 1.2.3.4:80 out2in-only
1812 * local 10.100.10.10:8080 probability 80
1813 * local 10.100.10.20:8080 probability 20
1814 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
1815 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
1818 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
1819 .path = "show nat44 static mappings",
1820 .short_help = "show nat44 static mappings",
1821 .function = nat44_show_static_mappings_command_fn,
1826 * @cliexstart{nat44 add interface address}
1827 * Use NAT44 pool address from specific interfce
1828 * To add NAT44 pool address from specific interface use:
1829 * vpp# nat44 add interface address GigabitEthernet0/8/0
1832 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
1833 .path = "nat44 add interface address",
1834 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
1835 .function = snat_add_interface_address_command_fn,
1840 * @cliexstart{show nat44 interface address}
1841 * Show NAT44 pool address interfaces
1842 * vpp# show nat44 interface address
1843 * NAT44 pool address interfaces:
1844 * GigabitEthernet0/a/0
1845 * NAT44 twice-nat pool address interfaces:
1846 * GigabitEthernet0/8/0
1849 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
1850 .path = "show nat44 interface address",
1851 .short_help = "show nat44 interface address",
1852 .function = nat44_show_interface_address_command_fn,
1857 * @cliexstart{show nat44 sessions}
1858 * Show NAT44 sessions.
1861 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
1862 .path = "show nat44 sessions",
1863 .short_help = "show nat44 sessions [detail]",
1864 .function = nat44_show_sessions_command_fn,
1869 * @cliexstart{nat44 del session}
1870 * To administratively delete NAT44 session by inside address and port use:
1871 * vpp# nat44 del session in 10.0.0.3:6303 tcp
1872 * To administratively delete NAT44 session by outside address and port use:
1873 * vpp# nat44 del session out 1.0.0.3:6033 udp
1876 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
1877 .path = "nat44 del session",
1878 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
1879 .function = nat44_del_session_command_fn,
1884 * @cliexstart{nat44 forwarding}
1885 * Enable or disable forwarding
1886 * Forward packets which don't match existing translation
1887 * or static mapping instead of dropping them.
1888 * To enable forwarding, use:
1889 * vpp# nat44 forwarding enable
1890 * To disable forwarding, use:
1891 * vpp# nat44 forwarding disable
1894 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
1895 .path = "nat44 forwarding",
1896 .short_help = "nat44 forwarding enable|disable",
1897 .function = snat_forwarding_set_command_fn,
1902 * @cliexstart{nat44 deterministic add}
1903 * Create bijective mapping of inside address to outside address and port range
1904 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
1906 * To create deterministic mapping between inside network 10.0.0.0/18 and
1907 * outside network 1.1.1.0/30 use:
1908 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
1911 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
1912 .path = "nat44 deterministic add",
1913 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
1914 .function = snat_det_map_command_fn,
1919 * @cliexpstart{show nat44 deterministic mappings}
1920 * Show NAT44 deterministic mappings
1921 * vpp# show nat44 deterministic mappings
1922 * NAT44 deterministic mappings:
1923 * in 10.0.0.0/24 out 1.1.1.1/32
1924 * outside address sharing ratio: 256
1925 * number of ports per inside host: 252
1926 * sessions number: 0
1929 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
1930 .path = "show nat44 deterministic mappings",
1931 .short_help = "show nat44 deterministic mappings",
1932 .function = nat44_det_show_mappings_command_fn,
1937 * @cliexstart{nat44 deterministic forward}
1938 * Return outside address and port range from inside address for deterministic
1940 * To obtain outside address and port of inside host use:
1941 * vpp# nat44 deterministic forward 10.0.0.2
1942 * 1.1.1.0:<1054-1068>
1945 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
1946 .path = "nat44 deterministic forward",
1947 .short_help = "nat44 deterministic forward <addr>",
1948 .function = snat_det_forward_command_fn,
1953 * @cliexstart{nat44 deterministic reverse}
1954 * Return inside address from outside address and port for deterministic NAT.
1955 * To obtain inside host address from outside address and port use:
1956 * #vpp nat44 deterministic reverse 1.1.1.1:1276
1960 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
1961 .path = "nat44 deterministic reverse",
1962 .short_help = "nat44 deterministic reverse <addr>:<port>",
1963 .function = snat_det_reverse_command_fn,
1968 * @cliexstart{show nat44 deterministic sessions}
1969 * Show NAT44 deterministic sessions.
1970 * vpp# show nat44 deterministic sessions
1971 * NAT44 deterministic sessions:
1972 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
1973 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
1974 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
1977 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
1978 .path = "show nat44 deterministic sessions",
1979 .short_help = "show nat44 deterministic sessions",
1980 .function = nat44_det_show_sessions_command_fn,
1985 * @cliexstart{nat44 deterministic close session out}
1986 * Close session using outside ip address and port
1987 * and external ip address and port, use:
1988 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
1991 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
1992 .path = "nat44 deterministic close session out",
1993 .short_help = "nat44 deterministic close session out "
1994 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
1995 .function = snat_det_close_session_out_fn,
2000 * @cliexstart{nat44 deterministic close session in}
2001 * Close session using inside ip address and port
2002 * and external ip address and port, use:
2003 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
2006 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
2007 .path = "nat44 deterministic close session in",
2008 .short_help = "nat44 deterministic close session in "
2009 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
2010 .function = snat_det_close_session_in_fn,
2016 * fd.io coding-style-patch-verification: ON
2019 * eval: (c-set-style "gnu")