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;
504 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
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"))
541 twice_nat = TWICE_NAT;
542 else if (unformat (line_input, "self-twice-nat"))
543 twice_nat = TWICE_NAT_SELF;
544 else if (unformat (line_input, "out2in-only"))
546 else if (unformat (line_input, "del"))
550 error = clib_error_return (0, "unknown input: '%U'",
551 format_unformat_error, line_input);
556 if (twice_nat && addr_only)
558 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
562 if (!addr_only && !proto_set)
564 error = clib_error_return (0, "missing protocol");
568 rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
569 vrf_id, addr_only, sw_if_index, proto, is_add,
570 twice_nat, out2in_only, 0);
574 case VNET_API_ERROR_INVALID_VALUE:
575 error = clib_error_return (0, "External port already in use.");
577 case VNET_API_ERROR_NO_SUCH_ENTRY:
579 error = clib_error_return (0, "External addres must be allocated.");
581 error = clib_error_return (0, "Mapping not exist.");
583 case VNET_API_ERROR_NO_SUCH_FIB:
584 error = clib_error_return (0, "No such VRF id.");
586 case VNET_API_ERROR_VALUE_EXIST:
587 error = clib_error_return (0, "Mapping already exist.");
594 unformat_free (line_input);
599 static clib_error_t *
600 add_identity_mapping_command_fn (vlib_main_t * vm,
601 unformat_input_t * input,
602 vlib_cli_command_t * cmd)
604 unformat_input_t _line_input, *line_input = &_line_input;
605 snat_main_t *sm = &snat_main;
606 clib_error_t *error = 0;
608 u32 port = 0, vrf_id = ~0;
611 u32 sw_if_index = ~0;
612 vnet_main_t *vnm = vnet_get_main ();
614 snat_protocol_t proto;
616 if (sm->deterministic)
617 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
621 /* Get a line of input. */
622 if (!unformat_user (input, unformat_line_input, line_input))
625 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
627 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
629 else if (unformat (line_input, "external %U",
630 unformat_vnet_sw_interface, vnm, &sw_if_index))
632 else if (unformat (line_input, "vrf %u", &vrf_id))
634 else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
637 else if (unformat (line_input, "del"))
641 error = clib_error_return (0, "unknown input: '%U'",
642 format_unformat_error, line_input);
647 rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
648 vrf_id, addr_only, sw_if_index, proto, is_add,
653 case VNET_API_ERROR_INVALID_VALUE:
654 error = clib_error_return (0, "External port already in use.");
656 case VNET_API_ERROR_NO_SUCH_ENTRY:
658 error = clib_error_return (0, "External addres must be allocated.");
660 error = clib_error_return (0, "Mapping not exist.");
662 case VNET_API_ERROR_NO_SUCH_FIB:
663 error = clib_error_return (0, "No such VRF id.");
665 case VNET_API_ERROR_VALUE_EXIST:
666 error = clib_error_return (0, "Mapping already exist.");
673 unformat_free (line_input);
678 static clib_error_t *
679 add_lb_static_mapping_command_fn (vlib_main_t * vm,
680 unformat_input_t * input,
681 vlib_cli_command_t * cmd)
683 unformat_input_t _line_input, *line_input = &_line_input;
684 snat_main_t *sm = &snat_main;
685 clib_error_t *error = 0;
686 ip4_address_t l_addr, e_addr;
687 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
690 snat_protocol_t proto;
692 nat44_lb_addr_port_t *locals = 0, local;
693 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
696 if (sm->deterministic)
697 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
699 /* Get a line of input. */
700 if (!unformat_user (input, unformat_line_input, line_input))
703 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
705 if (unformat (line_input, "local %U:%u probability %u",
706 unformat_ip4_address, &l_addr, &l_port, &probability))
708 memset (&local, 0, sizeof (local));
710 local.port = (u16) l_port;
711 local.probability = (u8) probability;
712 vec_add1 (locals, local);
714 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
717 else if (unformat (line_input, "vrf %u", &vrf_id))
719 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
722 else if (unformat (line_input, "twice-nat"))
723 twice_nat = TWICE_NAT;
724 else if (unformat (line_input, "self-twice-nat"))
725 twice_nat = TWICE_NAT_SELF;
726 else if (unformat (line_input, "out2in-only"))
728 else if (unformat (line_input, "del"))
732 error = clib_error_return (0, "unknown input: '%U'",
733 format_unformat_error, line_input);
738 if (vec_len (locals) < 2)
740 error = clib_error_return (0, "at least two local must be set");
746 error = clib_error_return (0, "missing protocol");
750 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, vrf_id,
751 locals, is_add, twice_nat,
756 case VNET_API_ERROR_INVALID_VALUE:
757 error = clib_error_return (0, "External port already in use.");
759 case VNET_API_ERROR_NO_SUCH_ENTRY:
761 error = clib_error_return (0, "External addres must be allocated.");
763 error = clib_error_return (0, "Mapping not exist.");
765 case VNET_API_ERROR_VALUE_EXIST:
766 error = clib_error_return (0, "Mapping already exist.");
773 unformat_free (line_input);
779 static clib_error_t *
780 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
781 unformat_input_t * input,
782 vlib_cli_command_t * cmd)
784 snat_main_t *sm = &snat_main;
785 snat_static_mapping_t *m;
786 snat_static_map_resolve_t *rp;
788 if (sm->deterministic)
789 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
791 vlib_cli_output (vm, "NAT44 static mappings:");
793 pool_foreach (m, sm->static_mappings,
795 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
797 vec_foreach (rp, sm->to_resolve)
798 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
804 static clib_error_t *
805 snat_add_interface_address_command_fn (vlib_main_t * vm,
806 unformat_input_t * input,
807 vlib_cli_command_t * cmd)
809 snat_main_t *sm = &snat_main;
810 unformat_input_t _line_input, *line_input = &_line_input;
814 clib_error_t *error = 0;
817 if (sm->deterministic)
818 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
820 /* Get a line of input. */
821 if (!unformat_user (input, unformat_line_input, line_input))
824 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
826 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
827 sm->vnet_main, &sw_if_index))
829 else if (unformat (line_input, "twice-nat"))
831 else if (unformat (line_input, "del"))
835 error = clib_error_return (0, "unknown input '%U'",
836 format_unformat_error, line_input);
841 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
849 error = clib_error_return (0, "snat_add_interface_address returned %d",
855 unformat_free (line_input);
860 static clib_error_t *
861 nat44_show_interface_address_command_fn (vlib_main_t * vm,
862 unformat_input_t * input,
863 vlib_cli_command_t * cmd)
865 snat_main_t *sm = &snat_main;
866 vnet_main_t *vnm = vnet_get_main ();
869 if (sm->deterministic)
870 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
873 vlib_cli_output (vm, "NAT44 pool address interfaces:");
874 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
876 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
879 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
880 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
882 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
890 static clib_error_t *
891 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
892 vlib_cli_command_t * cmd)
895 snat_main_t *sm = &snat_main;
896 snat_main_per_thread_data_t *tsm;
900 if (sm->deterministic)
901 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
903 if (unformat (input, "detail"))
906 vlib_cli_output (vm, "NAT44 sessions:");
909 vec_foreach_index (i, sm->per_thread_data)
911 tsm = vec_elt_at_index (sm->per_thread_data, i);
913 pool_foreach (u, tsm->users,
915 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, verbose);
923 static clib_error_t *
924 nat44_del_session_command_fn (vlib_main_t * vm,
925 unformat_input_t * input,
926 vlib_cli_command_t * cmd)
928 snat_main_t *sm = &snat_main;
929 unformat_input_t _line_input, *line_input = &_line_input;
931 clib_error_t *error = 0;
933 u32 port = 0, vrf_id = sm->outside_vrf_id;
934 snat_protocol_t proto;
937 if (sm->deterministic)
938 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
940 /* Get a line of input. */
941 if (!unformat_user (input, unformat_line_input, line_input))
944 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
947 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
948 unformat_snat_protocol, &proto))
950 else if (unformat (line_input, "in"))
953 vrf_id = sm->inside_vrf_id;
955 else if (unformat (line_input, "vrf %u", &vrf_id))
959 error = clib_error_return (0, "unknown input '%U'",
960 format_unformat_error, line_input);
965 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
973 error = clib_error_return (0, "nat44_del_session returned %d", rv);
978 unformat_free (line_input);
983 static clib_error_t *
984 snat_forwarding_set_command_fn (vlib_main_t * vm,
985 unformat_input_t * input,
986 vlib_cli_command_t * cmd)
988 snat_main_t *sm = &snat_main;
989 unformat_input_t _line_input, *line_input = &_line_input;
990 u8 forwarding_enable;
991 u8 forwarding_enable_set = 0;
992 clib_error_t *error = 0;
994 if (sm->deterministic)
995 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
997 /* Get a line of input. */
998 if (!unformat_user (input, unformat_line_input, line_input))
999 return clib_error_return (0, "'enable' or 'disable' expected");
1001 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1003 if (!forwarding_enable_set && unformat (line_input, "enable"))
1005 forwarding_enable = 1;
1006 forwarding_enable_set = 1;
1008 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1010 forwarding_enable = 0;
1011 forwarding_enable_set = 1;
1015 error = clib_error_return (0, "unknown input '%U'",
1016 format_unformat_error, line_input);
1021 if (!forwarding_enable_set)
1023 error = clib_error_return (0, "'enable' or 'disable' expected");
1027 sm->forwarding_enabled = forwarding_enable;
1030 unformat_free (line_input);
1035 static clib_error_t *
1036 snat_det_map_command_fn (vlib_main_t * vm,
1037 unformat_input_t * input, vlib_cli_command_t * cmd)
1039 snat_main_t *sm = &snat_main;
1040 unformat_input_t _line_input, *line_input = &_line_input;
1041 ip4_address_t in_addr, out_addr;
1042 u32 in_plen, out_plen;
1044 clib_error_t *error = 0;
1046 if (!sm->deterministic)
1047 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1049 /* Get a line of input. */
1050 if (!unformat_user (input, unformat_line_input, line_input))
1053 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1056 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1060 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1063 else if (unformat (line_input, "del"))
1067 error = clib_error_return (0, "unknown input '%U'",
1068 format_unformat_error, line_input);
1073 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1078 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1083 unformat_free (line_input);
1088 static clib_error_t *
1089 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1090 unformat_input_t * input,
1091 vlib_cli_command_t * cmd)
1093 snat_main_t *sm = &snat_main;
1096 if (!sm->deterministic)
1097 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1099 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1101 pool_foreach (dm, sm->det_maps,
1103 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1104 format_ip4_address, &dm->in_addr, dm->in_plen,
1105 format_ip4_address, &dm->out_addr, dm->out_plen);
1106 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1108 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1109 dm->ports_per_host);
1110 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1117 static clib_error_t *
1118 snat_det_forward_command_fn (vlib_main_t * vm,
1119 unformat_input_t * input,
1120 vlib_cli_command_t * cmd)
1122 snat_main_t *sm = &snat_main;
1123 unformat_input_t _line_input, *line_input = &_line_input;
1124 ip4_address_t in_addr, out_addr;
1127 clib_error_t *error = 0;
1129 if (!sm->deterministic)
1130 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1132 /* Get a line of input. */
1133 if (!unformat_user (input, unformat_line_input, line_input))
1136 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1138 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1142 error = clib_error_return (0, "unknown input '%U'",
1143 format_unformat_error, line_input);
1148 dm = snat_det_map_by_user (sm, &in_addr);
1150 vlib_cli_output (vm, "no match");
1153 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1154 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1155 lo_port, lo_port + dm->ports_per_host - 1);
1159 unformat_free (line_input);
1164 static clib_error_t *
1165 snat_det_reverse_command_fn (vlib_main_t * vm,
1166 unformat_input_t * input,
1167 vlib_cli_command_t * cmd)
1169 snat_main_t *sm = &snat_main;
1170 unformat_input_t _line_input, *line_input = &_line_input;
1171 ip4_address_t in_addr, out_addr;
1174 clib_error_t *error = 0;
1176 if (!sm->deterministic)
1177 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1179 /* Get a line of input. */
1180 if (!unformat_user (input, unformat_line_input, line_input))
1183 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1186 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1190 error = clib_error_return (0, "unknown input '%U'",
1191 format_unformat_error, line_input);
1196 if (out_port < 1024 || out_port > 65535)
1198 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1202 dm = snat_det_map_by_out (sm, &out_addr);
1204 vlib_cli_output (vm, "no match");
1207 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1208 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1212 unformat_free (line_input);
1217 static clib_error_t *
1218 set_timeout_command_fn (vlib_main_t * vm,
1219 unformat_input_t * input, vlib_cli_command_t * cmd)
1221 snat_main_t *sm = &snat_main;
1222 unformat_input_t _line_input, *line_input = &_line_input;
1223 clib_error_t *error = 0;
1225 if (!sm->deterministic)
1226 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1228 /* Get a line of input. */
1229 if (!unformat_user (input, unformat_line_input, line_input))
1232 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1234 if (unformat (line_input, "udp %u", &sm->udp_timeout))
1236 else if (unformat (line_input, "tcp-established %u",
1237 &sm->tcp_established_timeout))
1239 else if (unformat (line_input, "tcp-transitory %u",
1240 &sm->tcp_transitory_timeout))
1242 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1244 else if (unformat (line_input, "reset"))
1246 sm->udp_timeout = SNAT_UDP_TIMEOUT;
1247 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1248 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1249 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1253 error = clib_error_return (0, "unknown input '%U'",
1254 format_unformat_error, line_input);
1260 unformat_free (line_input);
1265 static clib_error_t *
1266 nat44_det_show_timeouts_command_fn (vlib_main_t * vm,
1267 unformat_input_t * input,
1268 vlib_cli_command_t * cmd)
1270 snat_main_t *sm = &snat_main;
1272 if (!sm->deterministic)
1273 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1275 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1276 vlib_cli_output (vm, "tcp-established timeout: %dsec",
1277 sm->tcp_established_timeout);
1278 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1279 sm->tcp_transitory_timeout);
1280 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1285 static clib_error_t *
1286 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1287 unformat_input_t * input,
1288 vlib_cli_command_t * cmd)
1290 snat_main_t *sm = &snat_main;
1292 snat_det_session_t *ses;
1295 if (!sm->deterministic)
1296 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1298 vlib_cli_output (vm, "NAT44 deterministic sessions:");
1300 pool_foreach (dm, sm->det_maps,
1302 vec_foreach_index (i, dm->sessions)
1304 ses = vec_elt_at_index (dm->sessions, i);
1306 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
1313 static clib_error_t *
1314 snat_det_close_session_out_fn (vlib_main_t * vm,
1315 unformat_input_t * input,
1316 vlib_cli_command_t * cmd)
1318 snat_main_t *sm = &snat_main;
1319 unformat_input_t _line_input, *line_input = &_line_input;
1320 ip4_address_t out_addr, ext_addr, in_addr;
1321 u32 out_port, ext_port;
1323 snat_det_session_t *ses;
1324 snat_det_out_key_t key;
1325 clib_error_t *error = 0;
1327 if (!sm->deterministic)
1328 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1330 /* Get a line of input. */
1331 if (!unformat_user (input, unformat_line_input, line_input))
1334 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1336 if (unformat (line_input, "%U:%d %U:%d",
1337 unformat_ip4_address, &out_addr, &out_port,
1338 unformat_ip4_address, &ext_addr, &ext_port))
1342 error = clib_error_return (0, "unknown input '%U'",
1343 format_unformat_error, line_input);
1348 unformat_free (line_input);
1350 dm = snat_det_map_by_out (sm, &out_addr);
1352 vlib_cli_output (vm, "no match");
1355 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
1356 key.ext_host_addr = out_addr;
1357 key.ext_host_port = ntohs ((u16) ext_port);
1358 key.out_port = ntohs ((u16) out_port);
1359 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
1361 vlib_cli_output (vm, "no match");
1363 snat_det_ses_close (dm, ses);
1367 unformat_free (line_input);
1372 static clib_error_t *
1373 snat_det_close_session_in_fn (vlib_main_t * vm,
1374 unformat_input_t * input,
1375 vlib_cli_command_t * cmd)
1377 snat_main_t *sm = &snat_main;
1378 unformat_input_t _line_input, *line_input = &_line_input;
1379 ip4_address_t in_addr, ext_addr;
1380 u32 in_port, ext_port;
1382 snat_det_session_t *ses;
1383 snat_det_out_key_t key;
1384 clib_error_t *error = 0;
1386 if (!sm->deterministic)
1387 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1389 /* Get a line of input. */
1390 if (!unformat_user (input, unformat_line_input, line_input))
1393 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1395 if (unformat (line_input, "%U:%d %U:%d",
1396 unformat_ip4_address, &in_addr, &in_port,
1397 unformat_ip4_address, &ext_addr, &ext_port))
1401 error = clib_error_return (0, "unknown input '%U'",
1402 format_unformat_error, line_input);
1407 unformat_free (line_input);
1409 dm = snat_det_map_by_user (sm, &in_addr);
1411 vlib_cli_output (vm, "no match");
1414 key.ext_host_addr = ext_addr;
1415 key.ext_host_port = ntohs ((u16) ext_port);
1417 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
1419 vlib_cli_output (vm, "no match");
1421 snat_det_ses_close (dm, ses);
1425 unformat_free (line_input);
1433 * @cliexstart{set snat workers}
1434 * Set NAT workers if 2 or more workers available, use:
1435 * vpp# set snat workers 0-2,5
1438 VLIB_CLI_COMMAND (set_workers_command, static) = {
1439 .path = "set nat workers",
1440 .function = set_workers_command_fn,
1441 .short_help = "set nat workers <workers-list>",
1446 * @cliexstart{show nat workers}
1448 * vpp# show nat workers:
1454 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
1455 .path = "show nat workers",
1456 .short_help = "show nat workers",
1457 .function = nat_show_workers_commnad_fn,
1462 * @cliexstart{snat ipfix logging}
1463 * To enable NAT IPFIX logging use:
1464 * vpp# nat ipfix logging
1465 * To set IPFIX exporter use:
1466 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
1469 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
1470 .path = "nat ipfix logging",
1471 .function = snat_ipfix_logging_enable_disable_command_fn,
1472 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
1477 * @cliexstart{nat addr-port-assignment-alg}
1478 * Set address and port assignment algorithm
1479 * For the MAP-E CE limit port choice based on PSID use:
1480 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
1481 * To set standard (default) address and port assignment algorithm use:
1482 * vpp# nat addr-port-assignment-alg default
1485 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
1486 .path = "nat addr-port-assignment-alg",
1487 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
1488 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
1493 * @cliexstart{nat44 add address}
1494 * Add/delete NAT44 pool address.
1495 * To add NAT44 pool address use:
1496 * vpp# nat44 add address 172.16.1.3
1497 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
1498 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
1499 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
1502 VLIB_CLI_COMMAND (add_address_command, static) = {
1503 .path = "nat44 add address",
1504 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
1505 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
1506 .function = add_address_command_fn,
1511 * @cliexstart{show nat44 addresses}
1512 * Show NAT44 pool addresses.
1513 * vpp# show nat44 addresses
1514 * NAT44 pool addresses:
1516 * tenant VRF independent
1525 * NAT44 twice-nat pool addresses:
1527 * tenant VRF independent
1533 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
1534 .path = "show nat44 addresses",
1535 .short_help = "show nat44 addresses",
1536 .function = nat44_show_addresses_command_fn,
1541 * @cliexstart{set interface nat44}
1542 * Enable/disable NAT44 feature on the interface.
1543 * To enable NAT44 feature with local network interface use:
1544 * vpp# set interface nat44 in GigabitEthernet0/8/0
1545 * To enable NAT44 feature with external network interface use:
1546 * vpp# set interface nat44 out GigabitEthernet0/a/0
1549 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
1550 .path = "set interface nat44",
1551 .function = snat_feature_command_fn,
1552 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
1558 * @cliexstart{show nat44 interfaces}
1559 * Show interfaces with NAT44 feature.
1560 * vpp# show nat44 interfaces
1562 * GigabitEthernet0/8/0 in
1563 * GigabitEthernet0/a/0 out
1566 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
1567 .path = "show nat44 interfaces",
1568 .short_help = "show nat44 interfaces",
1569 .function = nat44_show_interfaces_command_fn,
1574 * @cliexstart{nat44 add static mapping}
1575 * Static mapping allows hosts on the external network to initiate connection
1576 * to to the local network host.
1577 * To create static mapping between local host address 10.0.0.3 port 6303 and
1578 * external address 4.4.4.4 port 3606 for TCP protocol use:
1579 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
1580 * If not runnig "static mapping only" NAT plugin mode use before:
1581 * vpp# nat44 add address 4.4.4.4
1582 * To create static mapping between local and external address use:
1583 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
1586 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
1587 .path = "nat44 add static mapping",
1588 .function = add_static_mapping_command_fn,
1590 "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
1591 "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
1592 "[out2in-only] [del]",
1597 * @cliexstart{nat44 add identity mapping}
1598 * Identity mapping translate an IP address to itself.
1599 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
1601 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
1602 * To create identity mapping for address 10.0.0.3 use:
1603 * vpp# nat44 add identity mapping 10.0.0.3
1604 * To create identity mapping for DHCP addressed interface use:
1605 * vpp# nat44 add identity mapping GigabitEthernet0/a/0 tcp 3606
1608 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
1609 .path = "nat44 add identity mapping",
1610 .function = add_identity_mapping_command_fn,
1611 .short_help = "nat44 add identity mapping <interface>|<ip4-addr> "
1612 "[<protocol> <port>] [vrf <table-id>] [del]",
1617 * @cliexstart{nat44 add load-balancing static mapping}
1618 * Service load balancing using NAT44
1619 * To add static mapping with load balancing for service with external IP
1620 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
1621 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
1622 * 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
1625 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
1626 .path = "nat44 add load-balancing static mapping",
1627 .function = add_lb_static_mapping_command_fn,
1629 "nat44 add load-balancing static mapping protocol tcp|udp "
1630 "external <addr>:<port> local <addr>:<port> probability <n> "
1631 "[twice-nat|self-twice-nat] [vrf <table-id>] [out2in-only] [del]",
1636 * @cliexstart{show nat44 static mappings}
1637 * Show NAT44 static mappings.
1638 * vpp# show nat44 static mappings
1639 * NAT44 static mappings:
1640 * local 10.0.0.3 external 4.4.4.4 vrf 0
1641 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
1642 * tcp vrf 0 external 1.2.3.4:80 out2in-only
1643 * local 10.100.10.10:8080 probability 80
1644 * local 10.100.10.20:8080 probability 20
1645 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
1646 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
1649 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
1650 .path = "show nat44 static mappings",
1651 .short_help = "show nat44 static mappings",
1652 .function = nat44_show_static_mappings_command_fn,
1657 * @cliexstart{nat44 add interface address}
1658 * Use NAT44 pool address from specific interfce
1659 * To add NAT44 pool address from specific interface use:
1660 * vpp# nat44 add interface address GigabitEthernet0/8/0
1663 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
1664 .path = "nat44 add interface address",
1665 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
1666 .function = snat_add_interface_address_command_fn,
1671 * @cliexstart{show nat44 interface address}
1672 * Show NAT44 pool address interfaces
1673 * vpp# show nat44 interface address
1674 * NAT44 pool address interfaces:
1675 * GigabitEthernet0/a/0
1676 * NAT44 twice-nat pool address interfaces:
1677 * GigabitEthernet0/8/0
1680 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
1681 .path = "show nat44 interface address",
1682 .short_help = "show nat44 interface address",
1683 .function = nat44_show_interface_address_command_fn,
1688 * @cliexstart{show nat44 sessions}
1689 * Show NAT44 sessions.
1692 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
1693 .path = "show nat44 sessions",
1694 .short_help = "show nat44 sessions [detail]",
1695 .function = nat44_show_sessions_command_fn,
1700 * @cliexstart{nat44 del session}
1701 * To administratively delete NAT44 session by inside address and port use:
1702 * vpp# nat44 del session in 10.0.0.3:6303 tcp
1703 * To administratively delete NAT44 session by outside address and port use:
1704 * vpp# nat44 del session out 1.0.0.3:6033 udp
1707 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
1708 .path = "nat44 del session",
1709 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>]",
1710 .function = nat44_del_session_command_fn,
1715 * @cliexstart{nat44 forwarding}
1716 * Enable or disable forwarding
1717 * Forward packets which don't match existing translation
1718 * or static mapping instead of dropping them.
1719 * To enable forwarding, use:
1720 * vpp# nat44 forwarding enable
1721 * To disable forwarding, use:
1722 * vpp# nat44 forwarding disable
1725 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
1726 .path = "nat44 forwarding",
1727 .short_help = "nat44 forwarding enable|disable",
1728 .function = snat_forwarding_set_command_fn,
1733 * @cliexstart{nat44 deterministic add}
1734 * Create bijective mapping of inside address to outside address and port range
1735 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
1737 * To create deterministic mapping between inside network 10.0.0.0/18 and
1738 * outside network 1.1.1.0/30 use:
1739 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
1742 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
1743 .path = "nat44 deterministic add",
1744 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
1745 .function = snat_det_map_command_fn,
1750 * @cliexpstart{show nat44 deterministic mappings}
1751 * Show NAT44 deterministic mappings
1752 * vpp# show nat44 deterministic mappings
1753 * NAT44 deterministic mappings:
1754 * in 10.0.0.0/24 out 1.1.1.1/32
1755 * outside address sharing ratio: 256
1756 * number of ports per inside host: 252
1757 * sessions number: 0
1760 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
1761 .path = "show nat44 deterministic mappings",
1762 .short_help = "show nat44 deterministic mappings",
1763 .function = nat44_det_show_mappings_command_fn,
1768 * @cliexstart{nat44 deterministic forward}
1769 * Return outside address and port range from inside address for deterministic
1771 * To obtain outside address and port of inside host use:
1772 * vpp# nat44 deterministic forward 10.0.0.2
1773 * 1.1.1.0:<1054-1068>
1776 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
1777 .path = "nat44 deterministic forward",
1778 .short_help = "nat44 deterministic forward <addr>",
1779 .function = snat_det_forward_command_fn,
1784 * @cliexstart{nat44 deterministic reverse}
1785 * Return inside address from outside address and port for deterministic NAT.
1786 * To obtain inside host address from outside address and port use:
1787 * #vpp nat44 deterministic reverse 1.1.1.1:1276
1791 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
1792 .path = "nat44 deterministic reverse",
1793 .short_help = "nat44 deterministic reverse <addr>:<port>",
1794 .function = snat_det_reverse_command_fn,
1799 * @cliexstart{set nat44 deterministic timeout}
1800 * Set values of timeouts for deterministic NAT (in seconds), use:
1801 * vpp# set nat44 deterministic timeout udp 120 tcp-established 7500
1802 * tcp-transitory 250 icmp 90
1803 * To reset default values use:
1804 * vpp# set nat44 deterministic timeout reset
1807 VLIB_CLI_COMMAND (set_timeout_command, static) = {
1808 .path = "set nat44 deterministic timeout",
1809 .function = set_timeout_command_fn,
1811 "set nat44 deterministic timeout [udp <sec> | tcp-established <sec> "
1812 "tcp-transitory <sec> | icmp <sec> | reset]",
1817 * @cliexstart{show nat44 deterministic timeouts}
1818 * Show values of timeouts for deterministic NAT.
1819 * vpp# show nat44 deterministic timeouts
1820 * udp timeout: 300sec
1821 * tcp-established timeout: 7440sec
1822 * tcp-transitory timeout: 240sec
1823 * icmp timeout: 60sec
1826 VLIB_CLI_COMMAND (nat44_det_show_timeouts_command, static) = {
1827 .path = "show nat44 deterministic timeouts",
1828 .short_help = "show nat44 deterministic timeouts",
1829 .function = nat44_det_show_timeouts_command_fn,
1834 * @cliexstart{show nat44 deterministic sessions}
1835 * Show NAT44 deterministic sessions.
1836 * vpp# show nat44 deterministic sessions
1837 * NAT44 deterministic sessions:
1838 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
1839 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
1840 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
1843 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
1844 .path = "show nat44 deterministic sessions",
1845 .short_help = "show nat44 deterministic sessions",
1846 .function = nat44_det_show_sessions_command_fn,
1851 * @cliexstart{nat44 deterministic close session out}
1852 * Close session using outside ip address and port
1853 * and external ip address and port, use:
1854 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
1857 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
1858 .path = "nat44 deterministic close session out",
1859 .short_help = "nat44 deterministic close session out "
1860 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
1861 .function = snat_det_close_session_out_fn,
1866 * @cliexstart{nat44 deterministic close session in}
1867 * Close session using inside ip address and port
1868 * and external ip address and port, use:
1869 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
1872 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
1873 .path = "nat44 deterministic close session in",
1874 .short_help = "nat44 deterministic close session in "
1875 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
1876 .function = snat_det_close_session_in_fn,
1882 * fd.io coding-style-patch-verification: ON
1885 * eval: (c-set-style "gnu")