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_show_hash_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
162 vlib_cli_command_t * cmd)
164 snat_main_t *sm = &snat_main;
165 snat_main_per_thread_data_t *tsm;
169 if (unformat (input, "detail"))
171 else if (unformat (input, "verbose"))
174 vlib_cli_output (vm, "%U", format_bihash_16_8, &sm->in2out_ed, verbose);
175 vlib_cli_output (vm, "%U", format_bihash_16_8, &sm->out2in_ed, verbose);
176 vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
178 vlib_cli_output (vm, "%U",
179 format_bihash_8_8, &sm->static_mapping_by_external,
181 vec_foreach_index (i, sm->per_thread_data)
183 tsm = vec_elt_at_index (sm->per_thread_data, i);
184 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->in2out, verbose);
185 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->out2in, verbose);
186 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->user_hash, verbose);
192 static clib_error_t *
193 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
194 unformat_input_t * input,
195 vlib_cli_command_t * cmd)
197 unformat_input_t _line_input, *line_input = &_line_input;
198 snat_main_t *sm = &snat_main;
199 clib_error_t *error = 0;
200 u32 psid, psid_offset, psid_length;
202 if (sm->deterministic)
203 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
205 /* Get a line of input. */
206 if (!unformat_user (input, unformat_line_input, line_input))
209 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
211 if (unformat (line_input, "default"))
212 nat_set_alloc_addr_and_port_default ();
215 (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
216 &psid_offset, &psid_length))
217 nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
221 error = clib_error_return (0, "unknown input '%U'",
222 format_unformat_error, line_input);
228 unformat_free (line_input);
233 static clib_error_t *
234 add_address_command_fn (vlib_main_t * vm,
235 unformat_input_t * input, vlib_cli_command_t * cmd)
237 unformat_input_t _line_input, *line_input = &_line_input;
238 snat_main_t *sm = &snat_main;
239 ip4_address_t start_addr, end_addr, this_addr;
240 u32 start_host_order, end_host_order;
245 clib_error_t *error = 0;
248 if (sm->deterministic)
249 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
251 /* Get a line of input. */
252 if (!unformat_user (input, unformat_line_input, line_input))
255 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
257 if (unformat (line_input, "%U - %U",
258 unformat_ip4_address, &start_addr,
259 unformat_ip4_address, &end_addr))
261 else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
263 else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
264 end_addr = start_addr;
265 else if (unformat (line_input, "twice-nat"))
267 else if (unformat (line_input, "del"))
271 error = clib_error_return (0, "unknown input '%U'",
272 format_unformat_error, line_input);
277 if (sm->static_mapping_only)
279 error = clib_error_return (0, "static mapping only mode");
283 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
284 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
286 if (end_host_order < start_host_order)
288 error = clib_error_return (0, "end address less than start address");
292 count = (end_host_order - start_host_order) + 1;
295 clib_warning ("%U - %U, %d addresses...",
296 format_ip4_address, &start_addr,
297 format_ip4_address, &end_addr, count);
299 this_addr = start_addr;
301 for (i = 0; i < count; i++)
304 snat_add_address (sm, &this_addr, vrf_id, twice_nat);
306 rv = snat_del_address (sm, this_addr, 0, twice_nat);
310 case VNET_API_ERROR_NO_SUCH_ENTRY:
311 error = clib_error_return (0, "S-NAT address not exist.");
313 case VNET_API_ERROR_UNSPECIFIED:
315 clib_error_return (0, "S-NAT address used in static mapping.");
322 nat44_add_del_address_dpo (this_addr, is_add);
324 increment_v4_address (&this_addr);
328 unformat_free (line_input);
333 static clib_error_t *
334 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
335 vlib_cli_command_t * cmd)
337 snat_main_t *sm = &snat_main;
340 if (sm->deterministic)
341 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
343 vlib_cli_output (vm, "NAT44 pool addresses:");
345 vec_foreach (ap, sm->addresses)
347 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
348 if (ap->fib_index != ~0)
349 vlib_cli_output (vm, " tenant VRF: %u",
350 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
352 vlib_cli_output (vm, " tenant VRF independent");
353 #define _(N, i, n, s) \
354 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
355 foreach_snat_protocol
358 vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
359 vec_foreach (ap, sm->twice_nat_addresses)
361 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
362 if (ap->fib_index != ~0)
363 vlib_cli_output (vm, " tenant VRF: %u",
364 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
366 vlib_cli_output (vm, " tenant VRF independent");
367 #define _(N, i, n, s) \
368 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
369 foreach_snat_protocol
376 static clib_error_t *
377 snat_feature_command_fn (vlib_main_t * vm,
378 unformat_input_t * input, vlib_cli_command_t * cmd)
380 unformat_input_t _line_input, *line_input = &_line_input;
381 vnet_main_t *vnm = vnet_get_main ();
382 clib_error_t *error = 0;
384 u32 *inside_sw_if_indices = 0;
385 u32 *outside_sw_if_indices = 0;
386 u8 is_output_feature = 0;
392 /* Get a line of input. */
393 if (!unformat_user (input, unformat_line_input, line_input))
396 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
398 if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
400 vec_add1 (inside_sw_if_indices, sw_if_index);
401 else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
403 vec_add1 (outside_sw_if_indices, sw_if_index);
404 else if (unformat (line_input, "output-feature"))
405 is_output_feature = 1;
406 else if (unformat (line_input, "del"))
410 error = clib_error_return (0, "unknown input '%U'",
411 format_unformat_error, line_input);
416 if (vec_len (inside_sw_if_indices))
418 for (i = 0; i < vec_len (inside_sw_if_indices); i++)
420 sw_if_index = inside_sw_if_indices[i];
421 if (is_output_feature)
423 if (snat_interface_add_del_output_feature
424 (sw_if_index, 1, is_del))
426 error = clib_error_return (0, "%s %U failed",
427 is_del ? "del" : "add",
428 format_vnet_sw_if_index_name,
435 if (snat_interface_add_del (sw_if_index, 1, is_del))
437 error = clib_error_return (0, "%s %U failed",
438 is_del ? "del" : "add",
439 format_vnet_sw_if_index_name,
447 if (vec_len (outside_sw_if_indices))
449 for (i = 0; i < vec_len (outside_sw_if_indices); i++)
451 sw_if_index = outside_sw_if_indices[i];
452 if (is_output_feature)
454 if (snat_interface_add_del_output_feature
455 (sw_if_index, 0, is_del))
457 error = clib_error_return (0, "%s %U failed",
458 is_del ? "del" : "add",
459 format_vnet_sw_if_index_name,
466 if (snat_interface_add_del (sw_if_index, 0, is_del))
468 error = clib_error_return (0, "%s %U failed",
469 is_del ? "del" : "add",
470 format_vnet_sw_if_index_name,
479 unformat_free (line_input);
480 vec_free (inside_sw_if_indices);
481 vec_free (outside_sw_if_indices);
486 static clib_error_t *
487 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
488 vlib_cli_command_t * cmd)
490 snat_main_t *sm = &snat_main;
492 vnet_main_t *vnm = vnet_get_main ();
494 vlib_cli_output (vm, "NAT44 interfaces:");
496 pool_foreach (i, sm->interfaces,
498 vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
500 (nat_interface_is_inside(i) &&
501 nat_interface_is_outside(i)) ? "in out" :
502 (nat_interface_is_inside(i) ? "in" : "out"));
505 pool_foreach (i, sm->output_feature_interfaces,
507 vlib_cli_output (vm, " %U output-feature %s",
508 format_vnet_sw_if_index_name, vnm,
510 (nat_interface_is_inside(i) &&
511 nat_interface_is_outside(i)) ? "in out" :
512 (nat_interface_is_inside(i) ? "in" : "out"));
519 static clib_error_t *
520 add_static_mapping_command_fn (vlib_main_t * vm,
521 unformat_input_t * input,
522 vlib_cli_command_t * cmd)
524 unformat_input_t _line_input, *line_input = &_line_input;
525 snat_main_t *sm = &snat_main;
526 clib_error_t *error = 0;
527 ip4_address_t l_addr, e_addr;
528 u32 l_port = 0, e_port = 0, vrf_id = ~0;
531 u32 sw_if_index = ~0;
532 vnet_main_t *vnm = vnet_get_main ();
534 snat_protocol_t proto = ~0;
536 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
539 if (sm->deterministic)
540 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
542 /* Get a line of input. */
543 if (!unformat_user (input, unformat_line_input, line_input))
546 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
548 if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
552 if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
554 else if (unformat (line_input, "external %U %u", unformat_ip4_address,
557 else if (unformat (line_input, "external %U", unformat_ip4_address,
560 else if (unformat (line_input, "external %U %u",
561 unformat_vnet_sw_interface, vnm, &sw_if_index,
565 else if (unformat (line_input, "external %U",
566 unformat_vnet_sw_interface, vnm, &sw_if_index))
568 else if (unformat (line_input, "vrf %u", &vrf_id))
570 else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
572 else if (unformat (line_input, "twice-nat"))
573 twice_nat = TWICE_NAT;
574 else if (unformat (line_input, "self-twice-nat"))
575 twice_nat = TWICE_NAT_SELF;
576 else if (unformat (line_input, "out2in-only"))
578 else if (unformat (line_input, "del"))
582 error = clib_error_return (0, "unknown input: '%U'",
583 format_unformat_error, line_input);
588 if (twice_nat && addr_only)
590 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
594 if (!addr_only && !proto_set)
596 error = clib_error_return (0, "missing protocol");
600 rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
601 vrf_id, addr_only, sw_if_index, proto, is_add,
602 twice_nat, out2in_only, 0);
606 case VNET_API_ERROR_INVALID_VALUE:
607 error = clib_error_return (0, "External port already in use.");
609 case VNET_API_ERROR_NO_SUCH_ENTRY:
611 error = clib_error_return (0, "External addres must be allocated.");
613 error = clib_error_return (0, "Mapping not exist.");
615 case VNET_API_ERROR_NO_SUCH_FIB:
616 error = clib_error_return (0, "No such VRF id.");
618 case VNET_API_ERROR_VALUE_EXIST:
619 error = clib_error_return (0, "Mapping already exist.");
626 unformat_free (line_input);
631 static clib_error_t *
632 add_identity_mapping_command_fn (vlib_main_t * vm,
633 unformat_input_t * input,
634 vlib_cli_command_t * cmd)
636 unformat_input_t _line_input, *line_input = &_line_input;
637 snat_main_t *sm = &snat_main;
638 clib_error_t *error = 0;
640 u32 port = 0, vrf_id = ~0;
643 u32 sw_if_index = ~0;
644 vnet_main_t *vnm = vnet_get_main ();
646 snat_protocol_t proto;
648 if (sm->deterministic)
649 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
653 /* Get a line of input. */
654 if (!unformat_user (input, unformat_line_input, line_input))
657 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
659 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
661 else if (unformat (line_input, "external %U",
662 unformat_vnet_sw_interface, vnm, &sw_if_index))
664 else if (unformat (line_input, "vrf %u", &vrf_id))
666 else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
669 else if (unformat (line_input, "del"))
673 error = clib_error_return (0, "unknown input: '%U'",
674 format_unformat_error, line_input);
679 rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
680 vrf_id, addr_only, sw_if_index, proto, is_add,
685 case VNET_API_ERROR_INVALID_VALUE:
686 error = clib_error_return (0, "External port already in use.");
688 case VNET_API_ERROR_NO_SUCH_ENTRY:
690 error = clib_error_return (0, "External addres must be allocated.");
692 error = clib_error_return (0, "Mapping not exist.");
694 case VNET_API_ERROR_NO_SUCH_FIB:
695 error = clib_error_return (0, "No such VRF id.");
697 case VNET_API_ERROR_VALUE_EXIST:
698 error = clib_error_return (0, "Mapping already exist.");
705 unformat_free (line_input);
710 static clib_error_t *
711 add_lb_static_mapping_command_fn (vlib_main_t * vm,
712 unformat_input_t * input,
713 vlib_cli_command_t * cmd)
715 unformat_input_t _line_input, *line_input = &_line_input;
716 snat_main_t *sm = &snat_main;
717 clib_error_t *error = 0;
718 ip4_address_t l_addr, e_addr;
719 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
722 snat_protocol_t proto;
724 nat44_lb_addr_port_t *locals = 0, local;
725 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
728 if (sm->deterministic)
729 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
731 /* Get a line of input. */
732 if (!unformat_user (input, unformat_line_input, line_input))
735 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
737 if (unformat (line_input, "local %U:%u probability %u",
738 unformat_ip4_address, &l_addr, &l_port, &probability))
740 memset (&local, 0, sizeof (local));
742 local.port = (u16) l_port;
743 local.probability = (u8) probability;
744 vec_add1 (locals, local);
746 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
749 else if (unformat (line_input, "vrf %u", &vrf_id))
751 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
754 else if (unformat (line_input, "twice-nat"))
755 twice_nat = TWICE_NAT;
756 else if (unformat (line_input, "self-twice-nat"))
757 twice_nat = TWICE_NAT_SELF;
758 else if (unformat (line_input, "out2in-only"))
760 else if (unformat (line_input, "del"))
764 error = clib_error_return (0, "unknown input: '%U'",
765 format_unformat_error, line_input);
770 if (vec_len (locals) < 2)
772 error = clib_error_return (0, "at least two local must be set");
778 error = clib_error_return (0, "missing protocol");
782 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, vrf_id,
783 locals, is_add, twice_nat,
788 case VNET_API_ERROR_INVALID_VALUE:
789 error = clib_error_return (0, "External port already in use.");
791 case VNET_API_ERROR_NO_SUCH_ENTRY:
793 error = clib_error_return (0, "External addres must be allocated.");
795 error = clib_error_return (0, "Mapping not exist.");
797 case VNET_API_ERROR_VALUE_EXIST:
798 error = clib_error_return (0, "Mapping already exist.");
805 unformat_free (line_input);
811 static clib_error_t *
812 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
813 unformat_input_t * input,
814 vlib_cli_command_t * cmd)
816 snat_main_t *sm = &snat_main;
817 snat_static_mapping_t *m;
818 snat_static_map_resolve_t *rp;
820 if (sm->deterministic)
821 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
823 vlib_cli_output (vm, "NAT44 static mappings:");
825 pool_foreach (m, sm->static_mappings,
827 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
829 vec_foreach (rp, sm->to_resolve)
830 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
836 static clib_error_t *
837 snat_add_interface_address_command_fn (vlib_main_t * vm,
838 unformat_input_t * input,
839 vlib_cli_command_t * cmd)
841 snat_main_t *sm = &snat_main;
842 unformat_input_t _line_input, *line_input = &_line_input;
846 clib_error_t *error = 0;
849 if (sm->deterministic)
850 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
852 /* Get a line of input. */
853 if (!unformat_user (input, unformat_line_input, line_input))
856 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
858 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
859 sm->vnet_main, &sw_if_index))
861 else if (unformat (line_input, "twice-nat"))
863 else if (unformat (line_input, "del"))
867 error = clib_error_return (0, "unknown input '%U'",
868 format_unformat_error, line_input);
873 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
881 error = clib_error_return (0, "snat_add_interface_address returned %d",
887 unformat_free (line_input);
892 static clib_error_t *
893 nat44_show_interface_address_command_fn (vlib_main_t * vm,
894 unformat_input_t * input,
895 vlib_cli_command_t * cmd)
897 snat_main_t *sm = &snat_main;
898 vnet_main_t *vnm = vnet_get_main ();
901 if (sm->deterministic)
902 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
905 vlib_cli_output (vm, "NAT44 pool address interfaces:");
906 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
908 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
911 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
912 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
914 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
922 static clib_error_t *
923 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
924 vlib_cli_command_t * cmd)
927 snat_main_t *sm = &snat_main;
928 snat_main_per_thread_data_t *tsm;
932 if (sm->deterministic)
933 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
935 if (unformat (input, "detail"))
938 vlib_cli_output (vm, "NAT44 sessions:");
941 vec_foreach_index (i, sm->per_thread_data)
943 tsm = vec_elt_at_index (sm->per_thread_data, i);
945 pool_foreach (u, tsm->users,
947 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, verbose);
955 static clib_error_t *
956 nat44_del_session_command_fn (vlib_main_t * vm,
957 unformat_input_t * input,
958 vlib_cli_command_t * cmd)
960 snat_main_t *sm = &snat_main;
961 unformat_input_t _line_input, *line_input = &_line_input;
963 clib_error_t *error = 0;
965 u32 port = 0, vrf_id = sm->outside_vrf_id;
966 snat_protocol_t proto;
969 if (sm->deterministic)
970 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
972 /* Get a line of input. */
973 if (!unformat_user (input, unformat_line_input, line_input))
976 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
979 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
980 unformat_snat_protocol, &proto))
982 else if (unformat (line_input, "in"))
985 vrf_id = sm->inside_vrf_id;
987 else if (unformat (line_input, "vrf %u", &vrf_id))
991 error = clib_error_return (0, "unknown input '%U'",
992 format_unformat_error, line_input);
997 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
1005 error = clib_error_return (0, "nat44_del_session returned %d", rv);
1010 unformat_free (line_input);
1015 static clib_error_t *
1016 snat_forwarding_set_command_fn (vlib_main_t * vm,
1017 unformat_input_t * input,
1018 vlib_cli_command_t * cmd)
1020 snat_main_t *sm = &snat_main;
1021 unformat_input_t _line_input, *line_input = &_line_input;
1022 u8 forwarding_enable;
1023 u8 forwarding_enable_set = 0;
1024 clib_error_t *error = 0;
1026 if (sm->deterministic)
1027 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1029 /* Get a line of input. */
1030 if (!unformat_user (input, unformat_line_input, line_input))
1031 return clib_error_return (0, "'enable' or 'disable' expected");
1033 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1035 if (!forwarding_enable_set && unformat (line_input, "enable"))
1037 forwarding_enable = 1;
1038 forwarding_enable_set = 1;
1040 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1042 forwarding_enable = 0;
1043 forwarding_enable_set = 1;
1047 error = clib_error_return (0, "unknown input '%U'",
1048 format_unformat_error, line_input);
1053 if (!forwarding_enable_set)
1055 error = clib_error_return (0, "'enable' or 'disable' expected");
1059 sm->forwarding_enabled = forwarding_enable;
1062 unformat_free (line_input);
1067 static clib_error_t *
1068 snat_det_map_command_fn (vlib_main_t * vm,
1069 unformat_input_t * input, vlib_cli_command_t * cmd)
1071 snat_main_t *sm = &snat_main;
1072 unformat_input_t _line_input, *line_input = &_line_input;
1073 ip4_address_t in_addr, out_addr;
1074 u32 in_plen, out_plen;
1076 clib_error_t *error = 0;
1078 if (!sm->deterministic)
1079 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1081 /* Get a line of input. */
1082 if (!unformat_user (input, unformat_line_input, line_input))
1085 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1088 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1092 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1095 else if (unformat (line_input, "del"))
1099 error = clib_error_return (0, "unknown input '%U'",
1100 format_unformat_error, line_input);
1105 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1110 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1115 unformat_free (line_input);
1120 static clib_error_t *
1121 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1122 unformat_input_t * input,
1123 vlib_cli_command_t * cmd)
1125 snat_main_t *sm = &snat_main;
1128 if (!sm->deterministic)
1129 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1131 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1133 pool_foreach (dm, sm->det_maps,
1135 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1136 format_ip4_address, &dm->in_addr, dm->in_plen,
1137 format_ip4_address, &dm->out_addr, dm->out_plen);
1138 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1140 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1141 dm->ports_per_host);
1142 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1149 static clib_error_t *
1150 snat_det_forward_command_fn (vlib_main_t * vm,
1151 unformat_input_t * input,
1152 vlib_cli_command_t * cmd)
1154 snat_main_t *sm = &snat_main;
1155 unformat_input_t _line_input, *line_input = &_line_input;
1156 ip4_address_t in_addr, out_addr;
1159 clib_error_t *error = 0;
1161 if (!sm->deterministic)
1162 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1164 /* Get a line of input. */
1165 if (!unformat_user (input, unformat_line_input, line_input))
1168 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1170 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1174 error = clib_error_return (0, "unknown input '%U'",
1175 format_unformat_error, line_input);
1180 dm = snat_det_map_by_user (sm, &in_addr);
1182 vlib_cli_output (vm, "no match");
1185 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1186 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1187 lo_port, lo_port + dm->ports_per_host - 1);
1191 unformat_free (line_input);
1196 static clib_error_t *
1197 snat_det_reverse_command_fn (vlib_main_t * vm,
1198 unformat_input_t * input,
1199 vlib_cli_command_t * cmd)
1201 snat_main_t *sm = &snat_main;
1202 unformat_input_t _line_input, *line_input = &_line_input;
1203 ip4_address_t in_addr, out_addr;
1206 clib_error_t *error = 0;
1208 if (!sm->deterministic)
1209 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1211 /* Get a line of input. */
1212 if (!unformat_user (input, unformat_line_input, line_input))
1215 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1218 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1222 error = clib_error_return (0, "unknown input '%U'",
1223 format_unformat_error, line_input);
1228 if (out_port < 1024 || out_port > 65535)
1230 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1234 dm = snat_det_map_by_out (sm, &out_addr);
1236 vlib_cli_output (vm, "no match");
1239 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1240 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1244 unformat_free (line_input);
1249 static clib_error_t *
1250 set_timeout_command_fn (vlib_main_t * vm,
1251 unformat_input_t * input, vlib_cli_command_t * cmd)
1253 snat_main_t *sm = &snat_main;
1254 unformat_input_t _line_input, *line_input = &_line_input;
1255 clib_error_t *error = 0;
1257 if (!sm->deterministic)
1258 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1260 /* Get a line of input. */
1261 if (!unformat_user (input, unformat_line_input, line_input))
1264 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1266 if (unformat (line_input, "udp %u", &sm->udp_timeout))
1268 else if (unformat (line_input, "tcp-established %u",
1269 &sm->tcp_established_timeout))
1271 else if (unformat (line_input, "tcp-transitory %u",
1272 &sm->tcp_transitory_timeout))
1274 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1276 else if (unformat (line_input, "reset"))
1278 sm->udp_timeout = SNAT_UDP_TIMEOUT;
1279 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1280 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1281 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1285 error = clib_error_return (0, "unknown input '%U'",
1286 format_unformat_error, line_input);
1292 unformat_free (line_input);
1297 static clib_error_t *
1298 nat44_det_show_timeouts_command_fn (vlib_main_t * vm,
1299 unformat_input_t * input,
1300 vlib_cli_command_t * cmd)
1302 snat_main_t *sm = &snat_main;
1304 if (!sm->deterministic)
1305 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1307 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1308 vlib_cli_output (vm, "tcp-established timeout: %dsec",
1309 sm->tcp_established_timeout);
1310 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1311 sm->tcp_transitory_timeout);
1312 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1317 static clib_error_t *
1318 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1319 unformat_input_t * input,
1320 vlib_cli_command_t * cmd)
1322 snat_main_t *sm = &snat_main;
1324 snat_det_session_t *ses;
1327 if (!sm->deterministic)
1328 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1330 vlib_cli_output (vm, "NAT44 deterministic sessions:");
1332 pool_foreach (dm, sm->det_maps,
1334 vec_foreach_index (i, dm->sessions)
1336 ses = vec_elt_at_index (dm->sessions, i);
1338 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
1345 static clib_error_t *
1346 snat_det_close_session_out_fn (vlib_main_t * vm,
1347 unformat_input_t * input,
1348 vlib_cli_command_t * cmd)
1350 snat_main_t *sm = &snat_main;
1351 unformat_input_t _line_input, *line_input = &_line_input;
1352 ip4_address_t out_addr, ext_addr, in_addr;
1353 u32 out_port, ext_port;
1355 snat_det_session_t *ses;
1356 snat_det_out_key_t key;
1357 clib_error_t *error = 0;
1359 if (!sm->deterministic)
1360 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1362 /* Get a line of input. */
1363 if (!unformat_user (input, unformat_line_input, line_input))
1366 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1368 if (unformat (line_input, "%U:%d %U:%d",
1369 unformat_ip4_address, &out_addr, &out_port,
1370 unformat_ip4_address, &ext_addr, &ext_port))
1374 error = clib_error_return (0, "unknown input '%U'",
1375 format_unformat_error, line_input);
1380 unformat_free (line_input);
1382 dm = snat_det_map_by_out (sm, &out_addr);
1384 vlib_cli_output (vm, "no match");
1387 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
1388 key.ext_host_addr = out_addr;
1389 key.ext_host_port = ntohs ((u16) ext_port);
1390 key.out_port = ntohs ((u16) out_port);
1391 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
1393 vlib_cli_output (vm, "no match");
1395 snat_det_ses_close (dm, ses);
1399 unformat_free (line_input);
1404 static clib_error_t *
1405 snat_det_close_session_in_fn (vlib_main_t * vm,
1406 unformat_input_t * input,
1407 vlib_cli_command_t * cmd)
1409 snat_main_t *sm = &snat_main;
1410 unformat_input_t _line_input, *line_input = &_line_input;
1411 ip4_address_t in_addr, ext_addr;
1412 u32 in_port, ext_port;
1414 snat_det_session_t *ses;
1415 snat_det_out_key_t key;
1416 clib_error_t *error = 0;
1418 if (!sm->deterministic)
1419 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1421 /* Get a line of input. */
1422 if (!unformat_user (input, unformat_line_input, line_input))
1425 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1427 if (unformat (line_input, "%U:%d %U:%d",
1428 unformat_ip4_address, &in_addr, &in_port,
1429 unformat_ip4_address, &ext_addr, &ext_port))
1433 error = clib_error_return (0, "unknown input '%U'",
1434 format_unformat_error, line_input);
1439 unformat_free (line_input);
1441 dm = snat_det_map_by_user (sm, &in_addr);
1443 vlib_cli_output (vm, "no match");
1446 key.ext_host_addr = ext_addr;
1447 key.ext_host_port = ntohs ((u16) ext_port);
1449 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
1451 vlib_cli_output (vm, "no match");
1453 snat_det_ses_close (dm, ses);
1457 unformat_free (line_input);
1465 * @cliexstart{set snat workers}
1466 * Set NAT workers if 2 or more workers available, use:
1467 * vpp# set snat workers 0-2,5
1470 VLIB_CLI_COMMAND (set_workers_command, static) = {
1471 .path = "set nat workers",
1472 .function = set_workers_command_fn,
1473 .short_help = "set nat workers <workers-list>",
1478 * @cliexstart{show nat workers}
1480 * vpp# show nat workers:
1486 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
1487 .path = "show nat workers",
1488 .short_help = "show nat workers",
1489 .function = nat_show_workers_commnad_fn,
1494 * @cliexstart{snat ipfix logging}
1495 * To enable NAT IPFIX logging use:
1496 * vpp# nat ipfix logging
1497 * To set IPFIX exporter use:
1498 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
1501 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
1502 .path = "nat ipfix logging",
1503 .function = snat_ipfix_logging_enable_disable_command_fn,
1504 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
1509 * @cliexstart{nat addr-port-assignment-alg}
1510 * Set address and port assignment algorithm
1511 * For the MAP-E CE limit port choice based on PSID use:
1512 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
1513 * To set standard (default) address and port assignment algorithm use:
1514 * vpp# nat addr-port-assignment-alg default
1517 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
1518 .path = "nat addr-port-assignment-alg",
1519 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
1520 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
1525 * @cliexstart{show nat44 hash tables}
1526 * Show NAT44 hash tables
1529 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
1530 .path = "show nat44 hash tables",
1531 .short_help = "show nat44 hash tables [detail|verbose]",
1532 .function = nat44_show_hash_commnad_fn,
1537 * @cliexstart{nat44 add address}
1538 * Add/delete NAT44 pool address.
1539 * To add NAT44 pool address use:
1540 * vpp# nat44 add address 172.16.1.3
1541 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
1542 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
1543 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
1546 VLIB_CLI_COMMAND (add_address_command, static) = {
1547 .path = "nat44 add address",
1548 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
1549 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
1550 .function = add_address_command_fn,
1555 * @cliexstart{show nat44 addresses}
1556 * Show NAT44 pool addresses.
1557 * vpp# show nat44 addresses
1558 * NAT44 pool addresses:
1560 * tenant VRF independent
1569 * NAT44 twice-nat pool addresses:
1571 * tenant VRF independent
1577 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
1578 .path = "show nat44 addresses",
1579 .short_help = "show nat44 addresses",
1580 .function = nat44_show_addresses_command_fn,
1585 * @cliexstart{set interface nat44}
1586 * Enable/disable NAT44 feature on the interface.
1587 * To enable NAT44 feature with local network interface use:
1588 * vpp# set interface nat44 in GigabitEthernet0/8/0
1589 * To enable NAT44 feature with external network interface use:
1590 * vpp# set interface nat44 out GigabitEthernet0/a/0
1593 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
1594 .path = "set interface nat44",
1595 .function = snat_feature_command_fn,
1596 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
1602 * @cliexstart{show nat44 interfaces}
1603 * Show interfaces with NAT44 feature.
1604 * vpp# show nat44 interfaces
1606 * GigabitEthernet0/8/0 in
1607 * GigabitEthernet0/a/0 out
1610 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
1611 .path = "show nat44 interfaces",
1612 .short_help = "show nat44 interfaces",
1613 .function = nat44_show_interfaces_command_fn,
1618 * @cliexstart{nat44 add static mapping}
1619 * Static mapping allows hosts on the external network to initiate connection
1620 * to to the local network host.
1621 * To create static mapping between local host address 10.0.0.3 port 6303 and
1622 * external address 4.4.4.4 port 3606 for TCP protocol use:
1623 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
1624 * If not runnig "static mapping only" NAT plugin mode use before:
1625 * vpp# nat44 add address 4.4.4.4
1626 * To create static mapping between local and external address use:
1627 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
1630 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
1631 .path = "nat44 add static mapping",
1632 .function = add_static_mapping_command_fn,
1634 "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
1635 "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
1636 "[out2in-only] [del]",
1641 * @cliexstart{nat44 add identity mapping}
1642 * Identity mapping translate an IP address to itself.
1643 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
1645 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
1646 * To create identity mapping for address 10.0.0.3 use:
1647 * vpp# nat44 add identity mapping 10.0.0.3
1648 * To create identity mapping for DHCP addressed interface use:
1649 * vpp# nat44 add identity mapping GigabitEthernet0/a/0 tcp 3606
1652 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
1653 .path = "nat44 add identity mapping",
1654 .function = add_identity_mapping_command_fn,
1655 .short_help = "nat44 add identity mapping <interface>|<ip4-addr> "
1656 "[<protocol> <port>] [vrf <table-id>] [del]",
1661 * @cliexstart{nat44 add load-balancing static mapping}
1662 * Service load balancing using NAT44
1663 * To add static mapping with load balancing for service with external IP
1664 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
1665 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
1666 * 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
1669 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
1670 .path = "nat44 add load-balancing static mapping",
1671 .function = add_lb_static_mapping_command_fn,
1673 "nat44 add load-balancing static mapping protocol tcp|udp "
1674 "external <addr>:<port> local <addr>:<port> probability <n> "
1675 "[twice-nat|self-twice-nat] [vrf <table-id>] [out2in-only] [del]",
1680 * @cliexstart{show nat44 static mappings}
1681 * Show NAT44 static mappings.
1682 * vpp# show nat44 static mappings
1683 * NAT44 static mappings:
1684 * local 10.0.0.3 external 4.4.4.4 vrf 0
1685 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
1686 * tcp vrf 0 external 1.2.3.4:80 out2in-only
1687 * local 10.100.10.10:8080 probability 80
1688 * local 10.100.10.20:8080 probability 20
1689 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
1690 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
1693 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
1694 .path = "show nat44 static mappings",
1695 .short_help = "show nat44 static mappings",
1696 .function = nat44_show_static_mappings_command_fn,
1701 * @cliexstart{nat44 add interface address}
1702 * Use NAT44 pool address from specific interfce
1703 * To add NAT44 pool address from specific interface use:
1704 * vpp# nat44 add interface address GigabitEthernet0/8/0
1707 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
1708 .path = "nat44 add interface address",
1709 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
1710 .function = snat_add_interface_address_command_fn,
1715 * @cliexstart{show nat44 interface address}
1716 * Show NAT44 pool address interfaces
1717 * vpp# show nat44 interface address
1718 * NAT44 pool address interfaces:
1719 * GigabitEthernet0/a/0
1720 * NAT44 twice-nat pool address interfaces:
1721 * GigabitEthernet0/8/0
1724 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
1725 .path = "show nat44 interface address",
1726 .short_help = "show nat44 interface address",
1727 .function = nat44_show_interface_address_command_fn,
1732 * @cliexstart{show nat44 sessions}
1733 * Show NAT44 sessions.
1736 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
1737 .path = "show nat44 sessions",
1738 .short_help = "show nat44 sessions [detail]",
1739 .function = nat44_show_sessions_command_fn,
1744 * @cliexstart{nat44 del session}
1745 * To administratively delete NAT44 session by inside address and port use:
1746 * vpp# nat44 del session in 10.0.0.3:6303 tcp
1747 * To administratively delete NAT44 session by outside address and port use:
1748 * vpp# nat44 del session out 1.0.0.3:6033 udp
1751 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
1752 .path = "nat44 del session",
1753 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>]",
1754 .function = nat44_del_session_command_fn,
1759 * @cliexstart{nat44 forwarding}
1760 * Enable or disable forwarding
1761 * Forward packets which don't match existing translation
1762 * or static mapping instead of dropping them.
1763 * To enable forwarding, use:
1764 * vpp# nat44 forwarding enable
1765 * To disable forwarding, use:
1766 * vpp# nat44 forwarding disable
1769 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
1770 .path = "nat44 forwarding",
1771 .short_help = "nat44 forwarding enable|disable",
1772 .function = snat_forwarding_set_command_fn,
1777 * @cliexstart{nat44 deterministic add}
1778 * Create bijective mapping of inside address to outside address and port range
1779 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
1781 * To create deterministic mapping between inside network 10.0.0.0/18 and
1782 * outside network 1.1.1.0/30 use:
1783 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
1786 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
1787 .path = "nat44 deterministic add",
1788 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
1789 .function = snat_det_map_command_fn,
1794 * @cliexpstart{show nat44 deterministic mappings}
1795 * Show NAT44 deterministic mappings
1796 * vpp# show nat44 deterministic mappings
1797 * NAT44 deterministic mappings:
1798 * in 10.0.0.0/24 out 1.1.1.1/32
1799 * outside address sharing ratio: 256
1800 * number of ports per inside host: 252
1801 * sessions number: 0
1804 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
1805 .path = "show nat44 deterministic mappings",
1806 .short_help = "show nat44 deterministic mappings",
1807 .function = nat44_det_show_mappings_command_fn,
1812 * @cliexstart{nat44 deterministic forward}
1813 * Return outside address and port range from inside address for deterministic
1815 * To obtain outside address and port of inside host use:
1816 * vpp# nat44 deterministic forward 10.0.0.2
1817 * 1.1.1.0:<1054-1068>
1820 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
1821 .path = "nat44 deterministic forward",
1822 .short_help = "nat44 deterministic forward <addr>",
1823 .function = snat_det_forward_command_fn,
1828 * @cliexstart{nat44 deterministic reverse}
1829 * Return inside address from outside address and port for deterministic NAT.
1830 * To obtain inside host address from outside address and port use:
1831 * #vpp nat44 deterministic reverse 1.1.1.1:1276
1835 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
1836 .path = "nat44 deterministic reverse",
1837 .short_help = "nat44 deterministic reverse <addr>:<port>",
1838 .function = snat_det_reverse_command_fn,
1843 * @cliexstart{set nat44 deterministic timeout}
1844 * Set values of timeouts for deterministic NAT (in seconds), use:
1845 * vpp# set nat44 deterministic timeout udp 120 tcp-established 7500
1846 * tcp-transitory 250 icmp 90
1847 * To reset default values use:
1848 * vpp# set nat44 deterministic timeout reset
1851 VLIB_CLI_COMMAND (set_timeout_command, static) = {
1852 .path = "set nat44 deterministic timeout",
1853 .function = set_timeout_command_fn,
1855 "set nat44 deterministic timeout [udp <sec> | tcp-established <sec> "
1856 "tcp-transitory <sec> | icmp <sec> | reset]",
1861 * @cliexstart{show nat44 deterministic timeouts}
1862 * Show values of timeouts for deterministic NAT.
1863 * vpp# show nat44 deterministic timeouts
1864 * udp timeout: 300sec
1865 * tcp-established timeout: 7440sec
1866 * tcp-transitory timeout: 240sec
1867 * icmp timeout: 60sec
1870 VLIB_CLI_COMMAND (nat44_det_show_timeouts_command, static) = {
1871 .path = "show nat44 deterministic timeouts",
1872 .short_help = "show nat44 deterministic timeouts",
1873 .function = nat44_det_show_timeouts_command_fn,
1878 * @cliexstart{show nat44 deterministic sessions}
1879 * Show NAT44 deterministic sessions.
1880 * vpp# show nat44 deterministic sessions
1881 * NAT44 deterministic sessions:
1882 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
1883 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
1884 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
1887 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
1888 .path = "show nat44 deterministic sessions",
1889 .short_help = "show nat44 deterministic sessions",
1890 .function = nat44_det_show_sessions_command_fn,
1895 * @cliexstart{nat44 deterministic close session out}
1896 * Close session using outside ip address and port
1897 * and external ip address and port, use:
1898 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
1901 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
1902 .path = "nat44 deterministic close session out",
1903 .short_help = "nat44 deterministic close session out "
1904 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
1905 .function = snat_det_close_session_out_fn,
1910 * @cliexstart{nat44 deterministic close session in}
1911 * Close session using inside ip address and port
1912 * and external ip address and port, use:
1913 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
1916 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
1917 .path = "nat44 deterministic close session in",
1918 .short_help = "nat44 deterministic close session in "
1919 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
1920 .function = snat_det_close_session_in_fn,
1926 * fd.io coding-style-patch-verification: ON
1929 * eval: (c-set-style "gnu")