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 <vnet/fib/fib_table.h>
25 #define UNSUPPORTED_IN_DET_MODE_STR \
26 "This command is unsupported in deterministic mode"
27 #define SUPPORTED_ONLY_IN_DET_MODE_STR \
28 "This command is supported only in deterministic mode"
31 set_workers_command_fn (vlib_main_t * vm,
32 unformat_input_t * input, vlib_cli_command_t * cmd)
34 unformat_input_t _line_input, *line_input = &_line_input;
35 snat_main_t *sm = &snat_main;
38 clib_error_t *error = 0;
40 if (sm->deterministic)
41 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
43 /* Get a line of input. */
44 if (!unformat_user (input, unformat_line_input, line_input))
47 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
49 if (unformat (line_input, "%U", unformat_bitmap_list, &bitmap))
53 error = clib_error_return (0, "unknown input '%U'",
54 format_unformat_error, line_input);
61 error = clib_error_return (0, "List of workers must be specified.");
65 rv = snat_set_workers (bitmap);
67 clib_bitmap_free (bitmap);
71 case VNET_API_ERROR_INVALID_WORKER:
72 error = clib_error_return (0, "Invalid worker(s).");
74 case VNET_API_ERROR_FEATURE_DISABLED:
75 error = clib_error_return (0,
76 "Supported only if 2 or more workes available.");
83 unformat_free (line_input);
89 nat_show_workers_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
90 vlib_cli_command_t * cmd)
92 snat_main_t *sm = &snat_main;
95 if (sm->deterministic)
96 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
98 if (sm->num_workers > 1)
100 vlib_cli_output (vm, "%d workers", vec_len (sm->workers));
102 vec_foreach (worker, sm->workers)
104 vlib_worker_thread_t *w =
105 vlib_worker_threads + *worker + sm->first_worker_index;
106 vlib_cli_output (vm, " %s", w->name);
114 static clib_error_t *
115 snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm,
116 unformat_input_t * input,
117 vlib_cli_command_t * cmd)
119 unformat_input_t _line_input, *line_input = &_line_input;
124 clib_error_t *error = 0;
126 /* Get a line of input. */
127 if (!unformat_user (input, unformat_line_input, line_input))
130 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
132 if (unformat (line_input, "domain %d", &domain_id))
134 else if (unformat (line_input, "src-port %d", &src_port))
136 else if (unformat (line_input, "disable"))
140 error = clib_error_return (0, "unknown input '%U'",
141 format_unformat_error, line_input);
146 rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port);
150 error = clib_error_return (0, "ipfix logging enable failed");
155 unformat_free (line_input);
160 static clib_error_t *
161 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
162 unformat_input_t * input,
163 vlib_cli_command_t * cmd)
165 unformat_input_t _line_input, *line_input = &_line_input;
166 snat_main_t *sm = &snat_main;
167 clib_error_t *error = 0;
168 u32 psid, psid_offset, psid_length;
170 if (sm->deterministic)
171 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
173 /* Get a line of input. */
174 if (!unformat_user (input, unformat_line_input, line_input))
177 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
179 if (unformat (line_input, "default"))
180 nat_set_alloc_addr_and_port_default ();
183 (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
184 &psid_offset, &psid_length))
185 nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
189 error = clib_error_return (0, "unknown input '%U'",
190 format_unformat_error, line_input);
196 unformat_free (line_input);
201 static clib_error_t *
202 add_address_command_fn (vlib_main_t * vm,
203 unformat_input_t * input, vlib_cli_command_t * cmd)
205 unformat_input_t _line_input, *line_input = &_line_input;
206 snat_main_t *sm = &snat_main;
207 ip4_address_t start_addr, end_addr, this_addr;
208 u32 start_host_order, end_host_order;
213 clib_error_t *error = 0;
216 if (sm->deterministic)
217 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
219 /* Get a line of input. */
220 if (!unformat_user (input, unformat_line_input, line_input))
223 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
225 if (unformat (line_input, "%U - %U",
226 unformat_ip4_address, &start_addr,
227 unformat_ip4_address, &end_addr))
229 else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
231 else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
232 end_addr = start_addr;
233 else if (unformat (line_input, "twice-nat"))
235 else if (unformat (line_input, "del"))
239 error = clib_error_return (0, "unknown input '%U'",
240 format_unformat_error, line_input);
245 if (sm->static_mapping_only)
247 error = clib_error_return (0, "static mapping only mode");
251 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
252 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
254 if (end_host_order < start_host_order)
256 error = clib_error_return (0, "end address less than start address");
260 count = (end_host_order - start_host_order) + 1;
263 clib_warning ("%U - %U, %d addresses...",
264 format_ip4_address, &start_addr,
265 format_ip4_address, &end_addr, count);
267 this_addr = start_addr;
269 for (i = 0; i < count; i++)
272 snat_add_address (sm, &this_addr, vrf_id, twice_nat);
274 rv = snat_del_address (sm, this_addr, 0, twice_nat);
278 case VNET_API_ERROR_NO_SUCH_ENTRY:
279 error = clib_error_return (0, "S-NAT address not exist.");
281 case VNET_API_ERROR_UNSPECIFIED:
283 clib_error_return (0, "S-NAT address used in static mapping.");
290 nat44_add_del_address_dpo (this_addr, is_add);
292 increment_v4_address (&this_addr);
296 unformat_free (line_input);
301 static clib_error_t *
302 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
303 vlib_cli_command_t * cmd)
305 snat_main_t *sm = &snat_main;
308 if (sm->deterministic)
309 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
311 vlib_cli_output (vm, "NAT44 pool addresses:");
313 vec_foreach (ap, sm->addresses)
315 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
316 if (ap->fib_index != ~0)
317 vlib_cli_output (vm, " tenant VRF: %u",
318 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
320 vlib_cli_output (vm, " tenant VRF independent");
321 #define _(N, i, n, s) \
322 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
323 foreach_snat_protocol
326 vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
327 vec_foreach (ap, sm->twice_nat_addresses)
329 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
330 if (ap->fib_index != ~0)
331 vlib_cli_output (vm, " tenant VRF: %u",
332 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
334 vlib_cli_output (vm, " tenant VRF independent");
335 #define _(N, i, n, s) \
336 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
337 foreach_snat_protocol
344 static clib_error_t *
345 snat_feature_command_fn (vlib_main_t * vm,
346 unformat_input_t * input, vlib_cli_command_t * cmd)
348 unformat_input_t _line_input, *line_input = &_line_input;
349 vnet_main_t *vnm = vnet_get_main ();
350 clib_error_t *error = 0;
352 u32 *inside_sw_if_indices = 0;
353 u32 *outside_sw_if_indices = 0;
354 u8 is_output_feature = 0;
360 /* Get a line of input. */
361 if (!unformat_user (input, unformat_line_input, line_input))
364 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
366 if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
368 vec_add1 (inside_sw_if_indices, sw_if_index);
369 else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
371 vec_add1 (outside_sw_if_indices, sw_if_index);
372 else if (unformat (line_input, "output-feature"))
373 is_output_feature = 1;
374 else if (unformat (line_input, "del"))
378 error = clib_error_return (0, "unknown input '%U'",
379 format_unformat_error, line_input);
384 if (vec_len (inside_sw_if_indices))
386 for (i = 0; i < vec_len (inside_sw_if_indices); i++)
388 sw_if_index = inside_sw_if_indices[i];
389 if (is_output_feature)
391 if (snat_interface_add_del_output_feature
392 (sw_if_index, 1, is_del))
394 error = clib_error_return (0, "%s %U failed",
395 is_del ? "del" : "add",
396 format_vnet_sw_if_index_name,
403 if (snat_interface_add_del (sw_if_index, 1, is_del))
405 error = clib_error_return (0, "%s %U failed",
406 is_del ? "del" : "add",
407 format_vnet_sw_if_index_name,
415 if (vec_len (outside_sw_if_indices))
417 for (i = 0; i < vec_len (outside_sw_if_indices); i++)
419 sw_if_index = outside_sw_if_indices[i];
420 if (is_output_feature)
422 if (snat_interface_add_del_output_feature
423 (sw_if_index, 0, is_del))
425 error = clib_error_return (0, "%s %U failed",
426 is_del ? "del" : "add",
427 format_vnet_sw_if_index_name,
434 if (snat_interface_add_del (sw_if_index, 0, is_del))
436 error = clib_error_return (0, "%s %U failed",
437 is_del ? "del" : "add",
438 format_vnet_sw_if_index_name,
447 unformat_free (line_input);
448 vec_free (inside_sw_if_indices);
449 vec_free (outside_sw_if_indices);
454 static clib_error_t *
455 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
456 vlib_cli_command_t * cmd)
458 snat_main_t *sm = &snat_main;
460 vnet_main_t *vnm = vnet_get_main ();
462 vlib_cli_output (vm, "NAT44 interfaces:");
464 pool_foreach (i, sm->interfaces,
466 vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
468 (nat_interface_is_inside(i) &&
469 nat_interface_is_outside(i)) ? "in out" :
470 (nat_interface_is_inside(i) ? "in" : "out"));
473 pool_foreach (i, sm->output_feature_interfaces,
475 vlib_cli_output (vm, " %U output-feature %s",
476 format_vnet_sw_if_index_name, vnm,
478 (nat_interface_is_inside(i) &&
479 nat_interface_is_outside(i)) ? "in out" :
480 (nat_interface_is_inside(i) ? "in" : "out"));
487 static clib_error_t *
488 add_static_mapping_command_fn (vlib_main_t * vm,
489 unformat_input_t * input,
490 vlib_cli_command_t * cmd)
492 unformat_input_t _line_input, *line_input = &_line_input;
493 snat_main_t *sm = &snat_main;
494 clib_error_t *error = 0;
495 ip4_address_t l_addr, e_addr;
496 u32 l_port = 0, e_port = 0, vrf_id = ~0;
499 u32 sw_if_index = ~0;
500 vnet_main_t *vnm = vnet_get_main ();
502 snat_protocol_t proto = ~0;
507 if (sm->deterministic)
508 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
510 /* Get a line of input. */
511 if (!unformat_user (input, unformat_line_input, line_input))
514 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
516 if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
520 if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
522 else if (unformat (line_input, "external %U %u", unformat_ip4_address,
525 else if (unformat (line_input, "external %U", unformat_ip4_address,
528 else if (unformat (line_input, "external %U %u",
529 unformat_vnet_sw_interface, vnm, &sw_if_index,
533 else if (unformat (line_input, "external %U",
534 unformat_vnet_sw_interface, vnm, &sw_if_index))
536 else if (unformat (line_input, "vrf %u", &vrf_id))
538 else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
540 else if (unformat (line_input, "twice-nat"))
542 else if (unformat (line_input, "out2in-only"))
544 else if (unformat (line_input, "del"))
548 error = clib_error_return (0, "unknown input: '%U'",
549 format_unformat_error, line_input);
554 if (twice_nat && addr_only)
556 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
560 if (!addr_only && !proto_set)
562 error = clib_error_return (0, "missing protocol");
566 rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
567 vrf_id, addr_only, sw_if_index, proto, is_add,
568 twice_nat, out2in_only, 0);
572 case VNET_API_ERROR_INVALID_VALUE:
573 error = clib_error_return (0, "External port already in use.");
575 case VNET_API_ERROR_NO_SUCH_ENTRY:
577 error = clib_error_return (0, "External addres must be allocated.");
579 error = clib_error_return (0, "Mapping not exist.");
581 case VNET_API_ERROR_NO_SUCH_FIB:
582 error = clib_error_return (0, "No such VRF id.");
584 case VNET_API_ERROR_VALUE_EXIST:
585 error = clib_error_return (0, "Mapping already exist.");
592 unformat_free (line_input);
597 static clib_error_t *
598 add_identity_mapping_command_fn (vlib_main_t * vm,
599 unformat_input_t * input,
600 vlib_cli_command_t * cmd)
602 unformat_input_t _line_input, *line_input = &_line_input;
603 snat_main_t *sm = &snat_main;
604 clib_error_t *error = 0;
606 u32 port = 0, vrf_id = ~0;
609 u32 sw_if_index = ~0;
610 vnet_main_t *vnm = vnet_get_main ();
612 snat_protocol_t proto;
614 if (sm->deterministic)
615 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
619 /* Get a line of input. */
620 if (!unformat_user (input, unformat_line_input, line_input))
623 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
625 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
627 else if (unformat (line_input, "external %U",
628 unformat_vnet_sw_interface, vnm, &sw_if_index))
630 else if (unformat (line_input, "vrf %u", &vrf_id))
632 else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
635 else if (unformat (line_input, "del"))
639 error = clib_error_return (0, "unknown input: '%U'",
640 format_unformat_error, line_input);
645 rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
646 vrf_id, addr_only, sw_if_index, proto, is_add,
651 case VNET_API_ERROR_INVALID_VALUE:
652 error = clib_error_return (0, "External port already in use.");
654 case VNET_API_ERROR_NO_SUCH_ENTRY:
656 error = clib_error_return (0, "External addres must be allocated.");
658 error = clib_error_return (0, "Mapping not exist.");
660 case VNET_API_ERROR_NO_SUCH_FIB:
661 error = clib_error_return (0, "No such VRF id.");
663 case VNET_API_ERROR_VALUE_EXIST:
664 error = clib_error_return (0, "Mapping already exist.");
671 unformat_free (line_input);
676 static clib_error_t *
677 add_lb_static_mapping_command_fn (vlib_main_t * vm,
678 unformat_input_t * input,
679 vlib_cli_command_t * cmd)
681 unformat_input_t _line_input, *line_input = &_line_input;
682 snat_main_t *sm = &snat_main;
683 clib_error_t *error = 0;
684 ip4_address_t l_addr, e_addr;
685 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
688 snat_protocol_t proto;
690 nat44_lb_addr_port_t *locals = 0, local;
694 if (sm->deterministic)
695 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
697 /* Get a line of input. */
698 if (!unformat_user (input, unformat_line_input, line_input))
701 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
703 if (unformat (line_input, "local %U:%u probability %u",
704 unformat_ip4_address, &l_addr, &l_port, &probability))
706 memset (&local, 0, sizeof (local));
708 local.port = (u16) l_port;
709 local.probability = (u8) probability;
710 vec_add1 (locals, local);
712 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
715 else if (unformat (line_input, "vrf %u", &vrf_id))
717 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
720 else if (unformat (line_input, "twice-nat"))
722 else if (unformat (line_input, "out2in-only"))
724 else if (unformat (line_input, "del"))
728 error = clib_error_return (0, "unknown input: '%U'",
729 format_unformat_error, line_input);
734 if (vec_len (locals) < 2)
736 error = clib_error_return (0, "at least two local must be set");
742 error = clib_error_return (0, "missing protocol");
746 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, vrf_id,
747 locals, is_add, twice_nat,
752 case VNET_API_ERROR_INVALID_VALUE:
753 error = clib_error_return (0, "External port already in use.");
755 case VNET_API_ERROR_NO_SUCH_ENTRY:
757 error = clib_error_return (0, "External addres must be allocated.");
759 error = clib_error_return (0, "Mapping not exist.");
761 case VNET_API_ERROR_VALUE_EXIST:
762 error = clib_error_return (0, "Mapping already exist.");
769 unformat_free (line_input);
775 static clib_error_t *
776 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
777 unformat_input_t * input,
778 vlib_cli_command_t * cmd)
780 snat_main_t *sm = &snat_main;
781 snat_static_mapping_t *m;
782 snat_static_map_resolve_t *rp;
784 if (sm->deterministic)
785 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
787 vlib_cli_output (vm, "NAT44 static mappings:");
789 pool_foreach (m, sm->static_mappings,
791 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
793 vec_foreach (rp, sm->to_resolve)
794 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
800 static clib_error_t *
801 snat_add_interface_address_command_fn (vlib_main_t * vm,
802 unformat_input_t * input,
803 vlib_cli_command_t * cmd)
805 snat_main_t *sm = &snat_main;
806 unformat_input_t _line_input, *line_input = &_line_input;
810 clib_error_t *error = 0;
813 if (sm->deterministic)
814 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
816 /* Get a line of input. */
817 if (!unformat_user (input, unformat_line_input, line_input))
820 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
822 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
823 sm->vnet_main, &sw_if_index))
825 else if (unformat (line_input, "twice-nat"))
827 else if (unformat (line_input, "del"))
831 error = clib_error_return (0, "unknown input '%U'",
832 format_unformat_error, line_input);
837 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
845 error = clib_error_return (0, "snat_add_interface_address returned %d",
851 unformat_free (line_input);
856 static clib_error_t *
857 nat44_show_interface_address_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 vnet_main_t *vnm = vnet_get_main ();
865 if (sm->deterministic)
866 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
869 vlib_cli_output (vm, "NAT44 pool address interfaces:");
870 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
872 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
875 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
876 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
878 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
886 static clib_error_t *
887 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
888 vlib_cli_command_t * cmd)
891 snat_main_t *sm = &snat_main;
892 snat_main_per_thread_data_t *tsm;
896 if (sm->deterministic)
897 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
899 if (unformat (input, "detail"))
902 vlib_cli_output (vm, "NAT44 sessions:");
905 vec_foreach_index (i, sm->per_thread_data)
907 tsm = vec_elt_at_index (sm->per_thread_data, i);
909 pool_foreach (u, tsm->users,
911 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, verbose);
919 static clib_error_t *
920 nat44_del_session_command_fn (vlib_main_t * vm,
921 unformat_input_t * input,
922 vlib_cli_command_t * cmd)
924 snat_main_t *sm = &snat_main;
925 unformat_input_t _line_input, *line_input = &_line_input;
927 clib_error_t *error = 0;
929 u32 port = 0, vrf_id = sm->outside_vrf_id;
930 snat_protocol_t proto;
933 if (sm->deterministic)
934 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
936 /* Get a line of input. */
937 if (!unformat_user (input, unformat_line_input, line_input))
940 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
943 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
944 unformat_snat_protocol, &proto))
946 else if (unformat (line_input, "in"))
949 vrf_id = sm->inside_vrf_id;
951 else if (unformat (line_input, "vrf %u", &vrf_id))
955 error = clib_error_return (0, "unknown input '%U'",
956 format_unformat_error, line_input);
961 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
969 error = clib_error_return (0, "nat44_del_session returned %d", rv);
974 unformat_free (line_input);
979 static clib_error_t *
980 snat_forwarding_set_command_fn (vlib_main_t * vm,
981 unformat_input_t * input,
982 vlib_cli_command_t * cmd)
984 snat_main_t *sm = &snat_main;
985 unformat_input_t _line_input, *line_input = &_line_input;
986 u8 forwarding_enable;
987 u8 forwarding_enable_set = 0;
988 clib_error_t *error = 0;
990 if (sm->deterministic)
991 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
993 /* Get a line of input. */
994 if (!unformat_user (input, unformat_line_input, line_input))
995 return clib_error_return (0, "'enable' or 'disable' expected");
997 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
999 if (!forwarding_enable_set && unformat (line_input, "enable"))
1001 forwarding_enable = 1;
1002 forwarding_enable_set = 1;
1004 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1006 forwarding_enable = 0;
1007 forwarding_enable_set = 1;
1011 error = clib_error_return (0, "unknown input '%U'",
1012 format_unformat_error, line_input);
1017 if (!forwarding_enable_set)
1019 error = clib_error_return (0, "'enable' or 'disable' expected");
1023 sm->forwarding_enabled = forwarding_enable;
1026 unformat_free (line_input);
1031 static clib_error_t *
1032 snat_det_map_command_fn (vlib_main_t * vm,
1033 unformat_input_t * input, vlib_cli_command_t * cmd)
1035 snat_main_t *sm = &snat_main;
1036 unformat_input_t _line_input, *line_input = &_line_input;
1037 ip4_address_t in_addr, out_addr;
1038 u32 in_plen, out_plen;
1040 clib_error_t *error = 0;
1042 if (!sm->deterministic)
1043 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1045 /* Get a line of input. */
1046 if (!unformat_user (input, unformat_line_input, line_input))
1049 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1052 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1056 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1059 else if (unformat (line_input, "del"))
1063 error = clib_error_return (0, "unknown input '%U'",
1064 format_unformat_error, line_input);
1069 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1074 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1079 unformat_free (line_input);
1084 static clib_error_t *
1085 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1086 unformat_input_t * input,
1087 vlib_cli_command_t * cmd)
1089 snat_main_t *sm = &snat_main;
1092 if (!sm->deterministic)
1093 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1095 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1097 pool_foreach (dm, sm->det_maps,
1099 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1100 format_ip4_address, &dm->in_addr, dm->in_plen,
1101 format_ip4_address, &dm->out_addr, dm->out_plen);
1102 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1104 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1105 dm->ports_per_host);
1106 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1113 static clib_error_t *
1114 snat_det_forward_command_fn (vlib_main_t * vm,
1115 unformat_input_t * input,
1116 vlib_cli_command_t * cmd)
1118 snat_main_t *sm = &snat_main;
1119 unformat_input_t _line_input, *line_input = &_line_input;
1120 ip4_address_t in_addr, out_addr;
1123 clib_error_t *error = 0;
1125 if (!sm->deterministic)
1126 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1128 /* Get a line of input. */
1129 if (!unformat_user (input, unformat_line_input, line_input))
1132 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1134 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1138 error = clib_error_return (0, "unknown input '%U'",
1139 format_unformat_error, line_input);
1144 dm = snat_det_map_by_user (sm, &in_addr);
1146 vlib_cli_output (vm, "no match");
1149 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1150 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1151 lo_port, lo_port + dm->ports_per_host - 1);
1155 unformat_free (line_input);
1160 static clib_error_t *
1161 snat_det_reverse_command_fn (vlib_main_t * vm,
1162 unformat_input_t * input,
1163 vlib_cli_command_t * cmd)
1165 snat_main_t *sm = &snat_main;
1166 unformat_input_t _line_input, *line_input = &_line_input;
1167 ip4_address_t in_addr, out_addr;
1170 clib_error_t *error = 0;
1172 if (!sm->deterministic)
1173 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1175 /* Get a line of input. */
1176 if (!unformat_user (input, unformat_line_input, line_input))
1179 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1182 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1186 error = clib_error_return (0, "unknown input '%U'",
1187 format_unformat_error, line_input);
1192 if (out_port < 1024 || out_port > 65535)
1194 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1198 dm = snat_det_map_by_out (sm, &out_addr);
1200 vlib_cli_output (vm, "no match");
1203 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1204 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1208 unformat_free (line_input);
1213 static clib_error_t *
1214 set_timeout_command_fn (vlib_main_t * vm,
1215 unformat_input_t * input, vlib_cli_command_t * cmd)
1217 snat_main_t *sm = &snat_main;
1218 unformat_input_t _line_input, *line_input = &_line_input;
1219 clib_error_t *error = 0;
1221 if (!sm->deterministic)
1222 return clib_error_return (0, SUPPORTED_ONLY_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, "udp %u", &sm->udp_timeout))
1232 else if (unformat (line_input, "tcp-established %u",
1233 &sm->tcp_established_timeout))
1235 else if (unformat (line_input, "tcp-transitory %u",
1236 &sm->tcp_transitory_timeout))
1238 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1240 else if (unformat (line_input, "reset"))
1242 sm->udp_timeout = SNAT_UDP_TIMEOUT;
1243 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1244 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1245 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1249 error = clib_error_return (0, "unknown input '%U'",
1250 format_unformat_error, line_input);
1256 unformat_free (line_input);
1261 static clib_error_t *
1262 nat44_det_show_timeouts_command_fn (vlib_main_t * vm,
1263 unformat_input_t * input,
1264 vlib_cli_command_t * cmd)
1266 snat_main_t *sm = &snat_main;
1268 if (!sm->deterministic)
1269 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1271 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1272 vlib_cli_output (vm, "tcp-established timeout: %dsec",
1273 sm->tcp_established_timeout);
1274 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1275 sm->tcp_transitory_timeout);
1276 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1281 static clib_error_t *
1282 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1283 unformat_input_t * input,
1284 vlib_cli_command_t * cmd)
1286 snat_main_t *sm = &snat_main;
1288 snat_det_session_t *ses;
1291 if (!sm->deterministic)
1292 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1294 vlib_cli_output (vm, "NAT44 deterministic sessions:");
1296 pool_foreach (dm, sm->det_maps,
1298 vec_foreach_index (i, dm->sessions)
1300 ses = vec_elt_at_index (dm->sessions, i);
1302 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
1309 static clib_error_t *
1310 snat_det_close_session_out_fn (vlib_main_t * vm,
1311 unformat_input_t * input,
1312 vlib_cli_command_t * cmd)
1314 snat_main_t *sm = &snat_main;
1315 unformat_input_t _line_input, *line_input = &_line_input;
1316 ip4_address_t out_addr, ext_addr, in_addr;
1317 u32 out_port, ext_port;
1319 snat_det_session_t *ses;
1320 snat_det_out_key_t key;
1321 clib_error_t *error = 0;
1323 if (!sm->deterministic)
1324 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1326 /* Get a line of input. */
1327 if (!unformat_user (input, unformat_line_input, line_input))
1330 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1332 if (unformat (line_input, "%U:%d %U:%d",
1333 unformat_ip4_address, &out_addr, &out_port,
1334 unformat_ip4_address, &ext_addr, &ext_port))
1338 error = clib_error_return (0, "unknown input '%U'",
1339 format_unformat_error, line_input);
1344 unformat_free (line_input);
1346 dm = snat_det_map_by_out (sm, &out_addr);
1348 vlib_cli_output (vm, "no match");
1351 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
1352 key.ext_host_addr = out_addr;
1353 key.ext_host_port = ntohs ((u16) ext_port);
1354 key.out_port = ntohs ((u16) out_port);
1355 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
1357 vlib_cli_output (vm, "no match");
1359 snat_det_ses_close (dm, ses);
1363 unformat_free (line_input);
1368 static clib_error_t *
1369 snat_det_close_session_in_fn (vlib_main_t * vm,
1370 unformat_input_t * input,
1371 vlib_cli_command_t * cmd)
1373 snat_main_t *sm = &snat_main;
1374 unformat_input_t _line_input, *line_input = &_line_input;
1375 ip4_address_t in_addr, ext_addr;
1376 u32 in_port, ext_port;
1378 snat_det_session_t *ses;
1379 snat_det_out_key_t key;
1380 clib_error_t *error = 0;
1382 if (!sm->deterministic)
1383 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1385 /* Get a line of input. */
1386 if (!unformat_user (input, unformat_line_input, line_input))
1389 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1391 if (unformat (line_input, "%U:%d %U:%d",
1392 unformat_ip4_address, &in_addr, &in_port,
1393 unformat_ip4_address, &ext_addr, &ext_port))
1397 error = clib_error_return (0, "unknown input '%U'",
1398 format_unformat_error, line_input);
1403 unformat_free (line_input);
1405 dm = snat_det_map_by_user (sm, &in_addr);
1407 vlib_cli_output (vm, "no match");
1410 key.ext_host_addr = ext_addr;
1411 key.ext_host_port = ntohs ((u16) ext_port);
1413 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
1415 vlib_cli_output (vm, "no match");
1417 snat_det_ses_close (dm, ses);
1421 unformat_free (line_input);
1429 * @cliexstart{set snat workers}
1430 * Set NAT workers if 2 or more workers available, use:
1431 * vpp# set snat workers 0-2,5
1434 VLIB_CLI_COMMAND (set_workers_command, static) = {
1435 .path = "set nat workers",
1436 .function = set_workers_command_fn,
1437 .short_help = "set nat workers <workers-list>",
1442 * @cliexstart{show nat workers}
1444 * vpp# show nat workers:
1450 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
1451 .path = "show nat workers",
1452 .short_help = "show nat workers",
1453 .function = nat_show_workers_commnad_fn,
1458 * @cliexstart{snat ipfix logging}
1459 * To enable NAT IPFIX logging use:
1460 * vpp# nat ipfix logging
1461 * To set IPFIX exporter use:
1462 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
1465 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
1466 .path = "nat ipfix logging",
1467 .function = snat_ipfix_logging_enable_disable_command_fn,
1468 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
1473 * @cliexstart{nat addr-port-assignment-alg}
1474 * Set address and port assignment algorithm
1475 * For the MAP-E CE limit port choice based on PSID use:
1476 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
1477 * To set standard (default) address and port assignment algorithm use:
1478 * vpp# nat addr-port-assignment-alg default
1481 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
1482 .path = "nat addr-port-assignment-alg",
1483 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
1484 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
1489 * @cliexstart{nat44 add address}
1490 * Add/delete NAT44 pool address.
1491 * To add NAT44 pool address use:
1492 * vpp# nat44 add address 172.16.1.3
1493 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
1494 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
1495 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
1498 VLIB_CLI_COMMAND (add_address_command, static) = {
1499 .path = "nat44 add address",
1500 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
1501 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
1502 .function = add_address_command_fn,
1507 * @cliexstart{show nat44 addresses}
1508 * Show NAT44 pool addresses.
1509 * vpp# show nat44 addresses
1510 * NAT44 pool addresses:
1512 * tenant VRF independent
1521 * NAT44 twice-nat pool addresses:
1523 * tenant VRF independent
1529 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
1530 .path = "show nat44 addresses",
1531 .short_help = "show nat44 addresses",
1532 .function = nat44_show_addresses_command_fn,
1537 * @cliexstart{set interface nat44}
1538 * Enable/disable NAT44 feature on the interface.
1539 * To enable NAT44 feature with local network interface use:
1540 * vpp# set interface nat44 in GigabitEthernet0/8/0
1541 * To enable NAT44 feature with external network interface use:
1542 * vpp# set interface nat44 out GigabitEthernet0/a/0
1545 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
1546 .path = "set interface nat44",
1547 .function = snat_feature_command_fn,
1548 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
1554 * @cliexstart{show nat44 interfaces}
1555 * Show interfaces with NAT44 feature.
1556 * vpp# show nat44 interfaces
1558 * GigabitEthernet0/8/0 in
1559 * GigabitEthernet0/a/0 out
1562 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
1563 .path = "show nat44 interfaces",
1564 .short_help = "show nat44 interfaces",
1565 .function = nat44_show_interfaces_command_fn,
1570 * @cliexstart{nat44 add static mapping}
1571 * Static mapping allows hosts on the external network to initiate connection
1572 * to to the local network host.
1573 * To create static mapping between local host address 10.0.0.3 port 6303 and
1574 * external address 4.4.4.4 port 3606 for TCP protocol use:
1575 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
1576 * If not runnig "static mapping only" NAT plugin mode use before:
1577 * vpp# nat44 add address 4.4.4.4
1578 * To create static mapping between local and external address use:
1579 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
1582 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
1583 .path = "nat44 add static mapping",
1584 .function = add_static_mapping_command_fn,
1586 "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
1587 "external <addr> [<port>] [vrf <table-id>] [twice-nat] [out2in-only] [del]",
1592 * @cliexstart{nat44 add identity mapping}
1593 * Identity mapping translate an IP address to itself.
1594 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
1596 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
1597 * To create identity mapping for address 10.0.0.3 use:
1598 * vpp# nat44 add identity mapping 10.0.0.3
1599 * To create identity mapping for DHCP addressed interface use:
1600 * vpp# nat44 add identity mapping GigabitEthernet0/a/0 tcp 3606
1603 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
1604 .path = "nat44 add identity mapping",
1605 .function = add_identity_mapping_command_fn,
1606 .short_help = "nat44 add identity mapping <interface>|<ip4-addr> "
1607 "[<protocol> <port>] [vrf <table-id>] [del]",
1612 * @cliexstart{nat44 add load-balancing static mapping}
1613 * Service load balancing using NAT44
1614 * To add static mapping with load balancing for service with external IP
1615 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
1616 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
1617 * 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
1620 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
1621 .path = "nat44 add load-balancing static mapping",
1622 .function = add_lb_static_mapping_command_fn,
1624 "nat44 add load-balancing static mapping protocol tcp|udp "
1625 "external <addr>:<port> local <addr>:<port> probability <n> [twice-nat] "
1626 "[vrf <table-id>] [out2in-only] [del]",
1631 * @cliexstart{show nat44 static mappings}
1632 * Show NAT44 static mappings.
1633 * vpp# show nat44 static mappings
1634 * NAT44 static mappings:
1635 * local 10.0.0.3 external 4.4.4.4 vrf 0
1636 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
1637 * tcp vrf 0 external 1.2.3.4:80 out2in-only
1638 * local 10.100.10.10:8080 probability 80
1639 * local 10.100.10.20:8080 probability 20
1640 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
1641 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
1644 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
1645 .path = "show nat44 static mappings",
1646 .short_help = "show nat44 static mappings",
1647 .function = nat44_show_static_mappings_command_fn,
1652 * @cliexstart{nat44 add interface address}
1653 * Use NAT44 pool address from specific interfce
1654 * To add NAT44 pool address from specific interface use:
1655 * vpp# nat44 add interface address GigabitEthernet0/8/0
1658 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
1659 .path = "nat44 add interface address",
1660 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
1661 .function = snat_add_interface_address_command_fn,
1666 * @cliexstart{show nat44 interface address}
1667 * Show NAT44 pool address interfaces
1668 * vpp# show nat44 interface address
1669 * NAT44 pool address interfaces:
1670 * GigabitEthernet0/a/0
1671 * NAT44 twice-nat pool address interfaces:
1672 * GigabitEthernet0/8/0
1675 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
1676 .path = "show nat44 interface address",
1677 .short_help = "show nat44 interface address",
1678 .function = nat44_show_interface_address_command_fn,
1683 * @cliexstart{show nat44 sessions}
1684 * Show NAT44 sessions.
1687 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
1688 .path = "show nat44 sessions",
1689 .short_help = "show nat44 sessions [detail]",
1690 .function = nat44_show_sessions_command_fn,
1695 * @cliexstart{nat44 del session}
1696 * To administratively delete NAT44 session by inside address and port use:
1697 * vpp# nat44 del session in 10.0.0.3:6303 tcp
1698 * To administratively delete NAT44 session by outside address and port use:
1699 * vpp# nat44 del session out 1.0.0.3:6033 udp
1702 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
1703 .path = "nat44 del session",
1704 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>]",
1705 .function = nat44_del_session_command_fn,
1710 * @cliexstart{nat44 forwarding}
1711 * Enable or disable forwarding
1712 * Forward packets which don't match existing translation
1713 * or static mapping instead of dropping them.
1714 * To enable forwarding, use:
1715 * vpp# nat44 forwarding enable
1716 * To disable forwarding, use:
1717 * vpp# nat44 forwarding disable
1720 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
1721 .path = "nat44 forwarding",
1722 .short_help = "nat44 forwarding enable|disable",
1723 .function = snat_forwarding_set_command_fn,
1728 * @cliexstart{nat44 deterministic add}
1729 * Create bijective mapping of inside address to outside address and port range
1730 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
1732 * To create deterministic mapping between inside network 10.0.0.0/18 and
1733 * outside network 1.1.1.0/30 use:
1734 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
1737 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
1738 .path = "nat44 deterministic add",
1739 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
1740 .function = snat_det_map_command_fn,
1745 * @cliexpstart{show nat44 deterministic mappings}
1746 * Show NAT44 deterministic mappings
1747 * vpp# show nat44 deterministic mappings
1748 * NAT44 deterministic mappings:
1749 * in 10.0.0.0/24 out 1.1.1.1/32
1750 * outside address sharing ratio: 256
1751 * number of ports per inside host: 252
1752 * sessions number: 0
1755 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
1756 .path = "show nat44 deterministic mappings",
1757 .short_help = "show nat44 deterministic mappings",
1758 .function = nat44_det_show_mappings_command_fn,
1763 * @cliexstart{nat44 deterministic forward}
1764 * Return outside address and port range from inside address for deterministic
1766 * To obtain outside address and port of inside host use:
1767 * vpp# nat44 deterministic forward 10.0.0.2
1768 * 1.1.1.0:<1054-1068>
1771 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
1772 .path = "nat44 deterministic forward",
1773 .short_help = "nat44 deterministic forward <addr>",
1774 .function = snat_det_forward_command_fn,
1779 * @cliexstart{nat44 deterministic reverse}
1780 * Return inside address from outside address and port for deterministic NAT.
1781 * To obtain inside host address from outside address and port use:
1782 * #vpp nat44 deterministic reverse 1.1.1.1:1276
1786 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
1787 .path = "nat44 deterministic reverse",
1788 .short_help = "nat44 deterministic reverse <addr>:<port>",
1789 .function = snat_det_reverse_command_fn,
1794 * @cliexstart{set nat44 deterministic timeout}
1795 * Set values of timeouts for deterministic NAT (in seconds), use:
1796 * vpp# set nat44 deterministic timeout udp 120 tcp-established 7500
1797 * tcp-transitory 250 icmp 90
1798 * To reset default values use:
1799 * vpp# set nat44 deterministic timeout reset
1802 VLIB_CLI_COMMAND (set_timeout_command, static) = {
1803 .path = "set nat44 deterministic timeout",
1804 .function = set_timeout_command_fn,
1806 "set nat44 deterministic timeout [udp <sec> | tcp-established <sec> "
1807 "tcp-transitory <sec> | icmp <sec> | reset]",
1812 * @cliexstart{show nat44 deterministic timeouts}
1813 * Show values of timeouts for deterministic NAT.
1814 * vpp# show nat44 deterministic timeouts
1815 * udp timeout: 300sec
1816 * tcp-established timeout: 7440sec
1817 * tcp-transitory timeout: 240sec
1818 * icmp timeout: 60sec
1821 VLIB_CLI_COMMAND (nat44_det_show_timeouts_command, static) = {
1822 .path = "show nat44 deterministic timeouts",
1823 .short_help = "show nat44 deterministic timeouts",
1824 .function = nat44_det_show_timeouts_command_fn,
1829 * @cliexstart{show nat44 deterministic sessions}
1830 * Show NAT44 deterministic sessions.
1831 * vpp# show nat44 deterministic sessions
1832 * NAT44 deterministic sessions:
1833 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
1834 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
1835 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
1838 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
1839 .path = "show nat44 deterministic sessions",
1840 .short_help = "show nat44 deterministic sessions",
1841 .function = nat44_det_show_sessions_command_fn,
1846 * @cliexstart{nat44 deterministic close session out}
1847 * Close session using outside ip address and port
1848 * and external ip address and port, use:
1849 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
1852 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
1853 .path = "nat44 deterministic close session out",
1854 .short_help = "nat44 deterministic close session out "
1855 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
1856 .function = snat_det_close_session_out_fn,
1861 * @cliexstart{nat44 deterministic close session in}
1862 * Close session using inside ip address and port
1863 * and external ip address and port, use:
1864 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
1867 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
1868 .path = "nat44 deterministic close session in",
1869 .short_help = "nat44 deterministic close session in "
1870 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
1871 .function = snat_det_close_session_in_fn,
1877 * fd.io coding-style-patch-verification: ON
1880 * eval: (c-set-style "gnu")