2 * Copyright (c) 2018 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 #include <nat/nat_ipfix_logging.h>
22 #include <nat/nat_det.h>
23 #include <nat/nat_inlines.h>
24 #include <vnet/fib/fib_table.h>
26 #define UNSUPPORTED_IN_DET_MODE_STR \
27 "This command is unsupported in deterministic mode"
28 #define SUPPORTED_ONLY_IN_DET_MODE_STR \
29 "This command is supported only in deterministic mode"
32 set_workers_command_fn (vlib_main_t * vm,
33 unformat_input_t * input, vlib_cli_command_t * cmd)
35 unformat_input_t _line_input, *line_input = &_line_input;
36 snat_main_t *sm = &snat_main;
39 clib_error_t *error = 0;
41 if (sm->deterministic)
42 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
44 /* Get a line of input. */
45 if (!unformat_user (input, unformat_line_input, line_input))
48 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
50 if (unformat (line_input, "%U", unformat_bitmap_list, &bitmap))
54 error = clib_error_return (0, "unknown input '%U'",
55 format_unformat_error, line_input);
62 error = clib_error_return (0, "List of workers must be specified.");
66 rv = snat_set_workers (bitmap);
68 clib_bitmap_free (bitmap);
72 case VNET_API_ERROR_INVALID_WORKER:
73 error = clib_error_return (0, "Invalid worker(s).");
75 case VNET_API_ERROR_FEATURE_DISABLED:
76 error = clib_error_return (0,
77 "Supported only if 2 or more workes available.");
84 unformat_free (line_input);
90 nat_show_workers_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
91 vlib_cli_command_t * cmd)
93 snat_main_t *sm = &snat_main;
96 if (sm->deterministic)
97 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
99 if (sm->num_workers > 1)
101 vlib_cli_output (vm, "%d workers", vec_len (sm->workers));
103 vec_foreach (worker, sm->workers)
105 vlib_worker_thread_t *w =
106 vlib_worker_threads + *worker + sm->first_worker_index;
107 vlib_cli_output (vm, " %s", w->name);
115 static clib_error_t *
116 snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm,
117 unformat_input_t * input,
118 vlib_cli_command_t * cmd)
120 unformat_input_t _line_input, *line_input = &_line_input;
125 clib_error_t *error = 0;
127 /* Get a line of input. */
128 if (!unformat_user (input, unformat_line_input, line_input))
131 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
133 if (unformat (line_input, "domain %d", &domain_id))
135 else if (unformat (line_input, "src-port %d", &src_port))
137 else if (unformat (line_input, "disable"))
141 error = clib_error_return (0, "unknown input '%U'",
142 format_unformat_error, line_input);
147 rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port);
151 error = clib_error_return (0, "ipfix logging enable failed");
156 unformat_free (line_input);
161 static clib_error_t *
162 nat44_show_hash_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
163 vlib_cli_command_t * cmd)
165 snat_main_t *sm = &snat_main;
166 snat_main_per_thread_data_t *tsm;
170 if (unformat (input, "detail"))
172 else if (unformat (input, "verbose"))
175 vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
177 vlib_cli_output (vm, "%U",
178 format_bihash_8_8, &sm->static_mapping_by_external,
180 vec_foreach_index (i, sm->per_thread_data)
182 tsm = vec_elt_at_index (sm->per_thread_data, i);
183 vlib_cli_output (vm, "-------- thread %d %s --------\n",
184 i, vlib_worker_threads[i].name);
185 if (sm->endpoint_dependent)
187 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->in2out_ed,
189 vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->out2in_ed,
194 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->in2out, verbose);
195 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->out2in, verbose);
197 vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->user_hash, verbose);
203 static clib_error_t *
204 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
205 unformat_input_t * input,
206 vlib_cli_command_t * cmd)
208 unformat_input_t _line_input, *line_input = &_line_input;
209 snat_main_t *sm = &snat_main;
210 clib_error_t *error = 0;
211 u32 psid, psid_offset, psid_length;
213 if (sm->deterministic)
214 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
216 /* Get a line of input. */
217 if (!unformat_user (input, unformat_line_input, line_input))
220 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
222 if (unformat (line_input, "default"))
223 nat_set_alloc_addr_and_port_default ();
226 (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
227 &psid_offset, &psid_length))
228 nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
232 error = clib_error_return (0, "unknown input '%U'",
233 format_unformat_error, line_input);
239 unformat_free (line_input);
244 static clib_error_t *
245 add_address_command_fn (vlib_main_t * vm,
246 unformat_input_t * input, vlib_cli_command_t * cmd)
248 unformat_input_t _line_input, *line_input = &_line_input;
249 snat_main_t *sm = &snat_main;
250 ip4_address_t start_addr, end_addr, this_addr;
251 u32 start_host_order, end_host_order;
256 clib_error_t *error = 0;
259 if (sm->deterministic)
260 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
262 /* Get a line of input. */
263 if (!unformat_user (input, unformat_line_input, line_input))
266 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
268 if (unformat (line_input, "%U - %U",
269 unformat_ip4_address, &start_addr,
270 unformat_ip4_address, &end_addr))
272 else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
274 else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
275 end_addr = start_addr;
276 else if (unformat (line_input, "twice-nat"))
278 else if (unformat (line_input, "del"))
282 error = clib_error_return (0, "unknown input '%U'",
283 format_unformat_error, line_input);
288 if (sm->static_mapping_only)
290 error = clib_error_return (0, "static mapping only mode");
294 start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
295 end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
297 if (end_host_order < start_host_order)
299 error = clib_error_return (0, "end address less than start address");
303 count = (end_host_order - start_host_order) + 1;
306 nat_log_info ("%U - %U, %d addresses...",
307 format_ip4_address, &start_addr,
308 format_ip4_address, &end_addr, count);
310 this_addr = start_addr;
312 for (i = 0; i < count; i++)
315 rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
317 rv = snat_del_address (sm, this_addr, 0, twice_nat);
321 case VNET_API_ERROR_VALUE_EXIST:
322 error = clib_error_return (0, "NAT address already in use.");
324 case VNET_API_ERROR_NO_SUCH_ENTRY:
325 error = clib_error_return (0, "NAT address not exist.");
327 case VNET_API_ERROR_UNSPECIFIED:
329 clib_error_return (0, "NAT address used in static mapping.");
331 case VNET_API_ERROR_FEATURE_DISABLED:
333 clib_error_return (0,
334 "twice NAT available only for endpoint-dependent mode.");
341 nat44_add_del_address_dpo (this_addr, is_add);
343 increment_v4_address (&this_addr);
347 unformat_free (line_input);
352 static clib_error_t *
353 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
354 vlib_cli_command_t * cmd)
356 snat_main_t *sm = &snat_main;
359 if (sm->deterministic)
360 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
362 vlib_cli_output (vm, "NAT44 pool addresses:");
364 vec_foreach (ap, sm->addresses)
366 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
367 if (ap->fib_index != ~0)
368 vlib_cli_output (vm, " tenant VRF: %u",
369 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
371 vlib_cli_output (vm, " tenant VRF independent");
372 #define _(N, i, n, s) \
373 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
374 foreach_snat_protocol
377 vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
378 vec_foreach (ap, sm->twice_nat_addresses)
380 vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
381 if (ap->fib_index != ~0)
382 vlib_cli_output (vm, " tenant VRF: %u",
383 fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
385 vlib_cli_output (vm, " tenant VRF independent");
386 #define _(N, i, n, s) \
387 vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
388 foreach_snat_protocol
395 static clib_error_t *
396 snat_feature_command_fn (vlib_main_t * vm,
397 unformat_input_t * input, vlib_cli_command_t * cmd)
399 unformat_input_t _line_input, *line_input = &_line_input;
400 vnet_main_t *vnm = vnet_get_main ();
401 clib_error_t *error = 0;
403 u32 *inside_sw_if_indices = 0;
404 u32 *outside_sw_if_indices = 0;
405 u8 is_output_feature = 0;
411 /* Get a line of input. */
412 if (!unformat_user (input, unformat_line_input, line_input))
415 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
417 if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
419 vec_add1 (inside_sw_if_indices, sw_if_index);
420 else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
422 vec_add1 (outside_sw_if_indices, sw_if_index);
423 else if (unformat (line_input, "output-feature"))
424 is_output_feature = 1;
425 else if (unformat (line_input, "del"))
429 error = clib_error_return (0, "unknown input '%U'",
430 format_unformat_error, line_input);
435 if (vec_len (inside_sw_if_indices))
437 for (i = 0; i < vec_len (inside_sw_if_indices); i++)
439 sw_if_index = inside_sw_if_indices[i];
440 if (is_output_feature)
442 if (snat_interface_add_del_output_feature
443 (sw_if_index, 1, is_del))
445 error = clib_error_return (0, "%s %U failed",
446 is_del ? "del" : "add",
447 format_vnet_sw_if_index_name,
454 if (snat_interface_add_del (sw_if_index, 1, is_del))
456 error = clib_error_return (0, "%s %U failed",
457 is_del ? "del" : "add",
458 format_vnet_sw_if_index_name,
466 if (vec_len (outside_sw_if_indices))
468 for (i = 0; i < vec_len (outside_sw_if_indices); i++)
470 sw_if_index = outside_sw_if_indices[i];
471 if (is_output_feature)
473 if (snat_interface_add_del_output_feature
474 (sw_if_index, 0, is_del))
476 error = clib_error_return (0, "%s %U failed",
477 is_del ? "del" : "add",
478 format_vnet_sw_if_index_name,
485 if (snat_interface_add_del (sw_if_index, 0, is_del))
487 error = clib_error_return (0, "%s %U failed",
488 is_del ? "del" : "add",
489 format_vnet_sw_if_index_name,
498 unformat_free (line_input);
499 vec_free (inside_sw_if_indices);
500 vec_free (outside_sw_if_indices);
505 static clib_error_t *
506 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
507 vlib_cli_command_t * cmd)
509 snat_main_t *sm = &snat_main;
511 vnet_main_t *vnm = vnet_get_main ();
513 vlib_cli_output (vm, "NAT44 interfaces:");
515 pool_foreach (i, sm->interfaces,
517 vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
519 (nat_interface_is_inside(i) &&
520 nat_interface_is_outside(i)) ? "in out" :
521 (nat_interface_is_inside(i) ? "in" : "out"));
524 pool_foreach (i, sm->output_feature_interfaces,
526 vlib_cli_output (vm, " %U output-feature %s",
527 format_vnet_sw_if_index_name, vnm,
529 (nat_interface_is_inside(i) &&
530 nat_interface_is_outside(i)) ? "in out" :
531 (nat_interface_is_inside(i) ? "in" : "out"));
538 static clib_error_t *
539 add_static_mapping_command_fn (vlib_main_t * vm,
540 unformat_input_t * input,
541 vlib_cli_command_t * cmd)
543 unformat_input_t _line_input, *line_input = &_line_input;
544 snat_main_t *sm = &snat_main;
545 clib_error_t *error = 0;
546 ip4_address_t l_addr, e_addr;
547 u32 l_port = 0, e_port = 0, vrf_id = ~0;
550 u32 sw_if_index = ~0;
551 vnet_main_t *vnm = vnet_get_main ();
553 snat_protocol_t proto = ~0;
555 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
558 if (sm->deterministic)
559 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
561 /* Get a line of input. */
562 if (!unformat_user (input, unformat_line_input, line_input))
565 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
567 if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
571 if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
573 else if (unformat (line_input, "external %U %u", unformat_ip4_address,
576 else if (unformat (line_input, "external %U", unformat_ip4_address,
579 else if (unformat (line_input, "external %U %u",
580 unformat_vnet_sw_interface, vnm, &sw_if_index,
584 else if (unformat (line_input, "external %U",
585 unformat_vnet_sw_interface, vnm, &sw_if_index))
587 else if (unformat (line_input, "vrf %u", &vrf_id))
589 else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
591 else if (unformat (line_input, "twice-nat"))
592 twice_nat = TWICE_NAT;
593 else if (unformat (line_input, "self-twice-nat"))
594 twice_nat = TWICE_NAT_SELF;
595 else if (unformat (line_input, "out2in-only"))
597 else if (unformat (line_input, "del"))
601 error = clib_error_return (0, "unknown input: '%U'",
602 format_unformat_error, line_input);
607 if (twice_nat && addr_only)
609 error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
613 if (!addr_only && !proto_set)
615 error = clib_error_return (0, "missing protocol");
619 rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
620 vrf_id, addr_only, sw_if_index, proto, is_add,
621 twice_nat, out2in_only, 0);
625 case VNET_API_ERROR_INVALID_VALUE:
626 error = clib_error_return (0, "External port already in use.");
628 case VNET_API_ERROR_NO_SUCH_ENTRY:
630 error = clib_error_return (0, "External addres must be allocated.");
632 error = clib_error_return (0, "Mapping not exist.");
634 case VNET_API_ERROR_NO_SUCH_FIB:
635 error = clib_error_return (0, "No such VRF id.");
637 case VNET_API_ERROR_VALUE_EXIST:
638 error = clib_error_return (0, "Mapping already exist.");
640 case VNET_API_ERROR_FEATURE_DISABLED:
642 clib_error_return (0,
643 "twice-nat/out2in-only available only for endpoint-dependent mode.");
650 unformat_free (line_input);
655 static clib_error_t *
656 add_identity_mapping_command_fn (vlib_main_t * vm,
657 unformat_input_t * input,
658 vlib_cli_command_t * cmd)
660 unformat_input_t _line_input, *line_input = &_line_input;
661 snat_main_t *sm = &snat_main;
662 clib_error_t *error = 0;
664 u32 port = 0, vrf_id = ~0;
667 u32 sw_if_index = ~0;
668 vnet_main_t *vnm = vnet_get_main ();
670 snat_protocol_t proto;
672 if (sm->deterministic)
673 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
677 /* Get a line of input. */
678 if (!unformat_user (input, unformat_line_input, line_input))
681 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
683 if (unformat (line_input, "%U", unformat_ip4_address, &addr))
685 else if (unformat (line_input, "external %U",
686 unformat_vnet_sw_interface, vnm, &sw_if_index))
688 else if (unformat (line_input, "vrf %u", &vrf_id))
690 else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
693 else if (unformat (line_input, "del"))
697 error = clib_error_return (0, "unknown input: '%U'",
698 format_unformat_error, line_input);
703 rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
704 vrf_id, addr_only, sw_if_index, proto, is_add,
709 case VNET_API_ERROR_INVALID_VALUE:
710 error = clib_error_return (0, "External port already in use.");
712 case VNET_API_ERROR_NO_SUCH_ENTRY:
714 error = clib_error_return (0, "External addres must be allocated.");
716 error = clib_error_return (0, "Mapping not exist.");
718 case VNET_API_ERROR_NO_SUCH_FIB:
719 error = clib_error_return (0, "No such VRF id.");
721 case VNET_API_ERROR_VALUE_EXIST:
722 error = clib_error_return (0, "Mapping already exist.");
729 unformat_free (line_input);
734 static clib_error_t *
735 add_lb_static_mapping_command_fn (vlib_main_t * vm,
736 unformat_input_t * input,
737 vlib_cli_command_t * cmd)
739 unformat_input_t _line_input, *line_input = &_line_input;
740 snat_main_t *sm = &snat_main;
741 clib_error_t *error = 0;
742 ip4_address_t l_addr, e_addr;
743 u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
746 snat_protocol_t proto;
748 nat44_lb_addr_port_t *locals = 0, local;
749 twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
752 if (sm->deterministic)
753 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
755 /* Get a line of input. */
756 if (!unformat_user (input, unformat_line_input, line_input))
759 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
761 if (unformat (line_input, "local %U:%u probability %u",
762 unformat_ip4_address, &l_addr, &l_port, &probability))
764 memset (&local, 0, sizeof (local));
766 local.port = (u16) l_port;
767 local.probability = (u8) probability;
768 vec_add1 (locals, local);
770 else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
773 else if (unformat (line_input, "vrf %u", &vrf_id))
775 else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
778 else if (unformat (line_input, "twice-nat"))
779 twice_nat = TWICE_NAT;
780 else if (unformat (line_input, "self-twice-nat"))
781 twice_nat = TWICE_NAT_SELF;
782 else if (unformat (line_input, "out2in-only"))
784 else if (unformat (line_input, "del"))
788 error = clib_error_return (0, "unknown input: '%U'",
789 format_unformat_error, line_input);
794 if (vec_len (locals) < 2)
796 error = clib_error_return (0, "at least two local must be set");
802 error = clib_error_return (0, "missing protocol");
806 rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, vrf_id,
807 locals, is_add, twice_nat,
812 case VNET_API_ERROR_INVALID_VALUE:
813 error = clib_error_return (0, "External port already in use.");
815 case VNET_API_ERROR_NO_SUCH_ENTRY:
817 error = clib_error_return (0, "External addres must be allocated.");
819 error = clib_error_return (0, "Mapping not exist.");
821 case VNET_API_ERROR_VALUE_EXIST:
822 error = clib_error_return (0, "Mapping already exist.");
824 case VNET_API_ERROR_FEATURE_DISABLED:
826 clib_error_return (0, "Available only for endpoint-dependent mode.");
833 unformat_free (line_input);
839 static clib_error_t *
840 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
841 unformat_input_t * input,
842 vlib_cli_command_t * cmd)
844 snat_main_t *sm = &snat_main;
845 snat_static_mapping_t *m;
846 snat_static_map_resolve_t *rp;
848 if (sm->deterministic)
849 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
851 vlib_cli_output (vm, "NAT44 static mappings:");
853 pool_foreach (m, sm->static_mappings,
855 vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
857 vec_foreach (rp, sm->to_resolve)
858 vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
864 static clib_error_t *
865 snat_add_interface_address_command_fn (vlib_main_t * vm,
866 unformat_input_t * input,
867 vlib_cli_command_t * cmd)
869 snat_main_t *sm = &snat_main;
870 unformat_input_t _line_input, *line_input = &_line_input;
874 clib_error_t *error = 0;
877 if (sm->deterministic)
878 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
880 /* Get a line of input. */
881 if (!unformat_user (input, unformat_line_input, line_input))
884 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
886 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
887 sm->vnet_main, &sw_if_index))
889 else if (unformat (line_input, "twice-nat"))
891 else if (unformat (line_input, "del"))
895 error = clib_error_return (0, "unknown input '%U'",
896 format_unformat_error, line_input);
901 rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
909 error = clib_error_return (0, "snat_add_interface_address returned %d",
915 unformat_free (line_input);
920 static clib_error_t *
921 nat44_show_interface_address_command_fn (vlib_main_t * vm,
922 unformat_input_t * input,
923 vlib_cli_command_t * cmd)
925 snat_main_t *sm = &snat_main;
926 vnet_main_t *vnm = vnet_get_main ();
929 if (sm->deterministic)
930 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
933 vlib_cli_output (vm, "NAT44 pool address interfaces:");
934 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
936 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
939 vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
940 vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
942 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
950 static clib_error_t *
951 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
952 vlib_cli_command_t * cmd)
955 snat_main_t *sm = &snat_main;
956 snat_main_per_thread_data_t *tsm;
960 if (sm->deterministic)
961 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
963 if (unformat (input, "detail"))
966 vlib_cli_output (vm, "NAT44 sessions:");
969 vec_foreach_index (i, sm->per_thread_data)
971 tsm = vec_elt_at_index (sm->per_thread_data, i);
973 vlib_cli_output (vm, "-------- thread %d %s --------\n",
974 i, vlib_worker_threads[i].name);
975 pool_foreach (u, tsm->users,
977 vlib_cli_output (vm, " %U", format_snat_user, tsm, u, verbose);
985 static clib_error_t *
986 nat44_del_session_command_fn (vlib_main_t * vm,
987 unformat_input_t * input,
988 vlib_cli_command_t * cmd)
990 snat_main_t *sm = &snat_main;
991 unformat_input_t _line_input, *line_input = &_line_input;
992 int is_in = 0, is_ed = 0;
993 clib_error_t *error = 0;
994 ip4_address_t addr, eh_addr;
995 u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
996 snat_protocol_t proto;
999 if (sm->deterministic)
1000 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1002 /* Get a line of input. */
1003 if (!unformat_user (input, unformat_line_input, line_input))
1006 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1009 (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1010 unformat_snat_protocol, &proto))
1012 else if (unformat (line_input, "in"))
1015 vrf_id = sm->inside_vrf_id;
1017 else if (unformat (line_input, "out"))
1020 vrf_id = sm->outside_vrf_id;
1022 else if (unformat (line_input, "vrf %u", &vrf_id))
1026 (line_input, "external-host %U:%u", unformat_ip4_address,
1027 &eh_addr, &eh_port))
1031 error = clib_error_return (0, "unknown input '%U'",
1032 format_unformat_error, line_input);
1039 nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port,
1040 snat_proto_to_ip_proto (proto), vrf_id, is_in);
1042 rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
1050 error = clib_error_return (0, "nat44_del_session returned %d", rv);
1055 unformat_free (line_input);
1060 static clib_error_t *
1061 snat_forwarding_set_command_fn (vlib_main_t * vm,
1062 unformat_input_t * input,
1063 vlib_cli_command_t * cmd)
1065 snat_main_t *sm = &snat_main;
1066 unformat_input_t _line_input, *line_input = &_line_input;
1067 u8 forwarding_enable;
1068 u8 forwarding_enable_set = 0;
1069 clib_error_t *error = 0;
1071 if (sm->deterministic)
1072 return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1074 /* Get a line of input. */
1075 if (!unformat_user (input, unformat_line_input, line_input))
1076 return clib_error_return (0, "'enable' or 'disable' expected");
1078 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1080 if (!forwarding_enable_set && unformat (line_input, "enable"))
1082 forwarding_enable = 1;
1083 forwarding_enable_set = 1;
1085 else if (!forwarding_enable_set && unformat (line_input, "disable"))
1087 forwarding_enable = 0;
1088 forwarding_enable_set = 1;
1092 error = clib_error_return (0, "unknown input '%U'",
1093 format_unformat_error, line_input);
1098 if (!forwarding_enable_set)
1100 error = clib_error_return (0, "'enable' or 'disable' expected");
1104 sm->forwarding_enabled = forwarding_enable;
1107 unformat_free (line_input);
1112 static clib_error_t *
1113 snat_det_map_command_fn (vlib_main_t * vm,
1114 unformat_input_t * input, vlib_cli_command_t * cmd)
1116 snat_main_t *sm = &snat_main;
1117 unformat_input_t _line_input, *line_input = &_line_input;
1118 ip4_address_t in_addr, out_addr;
1119 u32 in_plen, out_plen;
1121 clib_error_t *error = 0;
1123 if (!sm->deterministic)
1124 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1126 /* Get a line of input. */
1127 if (!unformat_user (input, unformat_line_input, line_input))
1130 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1133 (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1137 (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1140 else if (unformat (line_input, "del"))
1144 error = clib_error_return (0, "unknown input '%U'",
1145 format_unformat_error, line_input);
1150 rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1155 error = clib_error_return (0, "snat_det_add_map return %d", rv);
1160 unformat_free (line_input);
1165 static clib_error_t *
1166 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1167 unformat_input_t * input,
1168 vlib_cli_command_t * cmd)
1170 snat_main_t *sm = &snat_main;
1173 if (!sm->deterministic)
1174 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1176 vlib_cli_output (vm, "NAT44 deterministic mappings:");
1178 pool_foreach (dm, sm->det_maps,
1180 vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1181 format_ip4_address, &dm->in_addr, dm->in_plen,
1182 format_ip4_address, &dm->out_addr, dm->out_plen);
1183 vlib_cli_output (vm, " outside address sharing ratio: %d\n",
1185 vlib_cli_output (vm, " number of ports per inside host: %d\n",
1186 dm->ports_per_host);
1187 vlib_cli_output (vm, " sessions number: %d\n", dm->ses_num);
1194 static clib_error_t *
1195 snat_det_forward_command_fn (vlib_main_t * vm,
1196 unformat_input_t * input,
1197 vlib_cli_command_t * cmd)
1199 snat_main_t *sm = &snat_main;
1200 unformat_input_t _line_input, *line_input = &_line_input;
1201 ip4_address_t in_addr, out_addr;
1204 clib_error_t *error = 0;
1206 if (!sm->deterministic)
1207 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1209 /* Get a line of input. */
1210 if (!unformat_user (input, unformat_line_input, line_input))
1213 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1215 if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1219 error = clib_error_return (0, "unknown input '%U'",
1220 format_unformat_error, line_input);
1225 dm = snat_det_map_by_user (sm, &in_addr);
1227 vlib_cli_output (vm, "no match");
1230 snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1231 vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1232 lo_port, lo_port + dm->ports_per_host - 1);
1236 unformat_free (line_input);
1241 static clib_error_t *
1242 snat_det_reverse_command_fn (vlib_main_t * vm,
1243 unformat_input_t * input,
1244 vlib_cli_command_t * cmd)
1246 snat_main_t *sm = &snat_main;
1247 unformat_input_t _line_input, *line_input = &_line_input;
1248 ip4_address_t in_addr, out_addr;
1251 clib_error_t *error = 0;
1253 if (!sm->deterministic)
1254 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1256 /* Get a line of input. */
1257 if (!unformat_user (input, unformat_line_input, line_input))
1260 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1263 (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1267 error = clib_error_return (0, "unknown input '%U'",
1268 format_unformat_error, line_input);
1273 if (out_port < 1024 || out_port > 65535)
1275 error = clib_error_return (0, "wrong port, must be <1024-65535>");
1279 dm = snat_det_map_by_out (sm, &out_addr);
1281 vlib_cli_output (vm, "no match");
1284 snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1285 vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1289 unformat_free (line_input);
1294 static clib_error_t *
1295 set_timeout_command_fn (vlib_main_t * vm,
1296 unformat_input_t * input, vlib_cli_command_t * cmd)
1298 snat_main_t *sm = &snat_main;
1299 unformat_input_t _line_input, *line_input = &_line_input;
1300 clib_error_t *error = 0;
1302 if (!sm->deterministic)
1303 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1305 /* Get a line of input. */
1306 if (!unformat_user (input, unformat_line_input, line_input))
1309 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1311 if (unformat (line_input, "udp %u", &sm->udp_timeout))
1313 else if (unformat (line_input, "tcp-established %u",
1314 &sm->tcp_established_timeout))
1316 else if (unformat (line_input, "tcp-transitory %u",
1317 &sm->tcp_transitory_timeout))
1319 else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1321 else if (unformat (line_input, "reset"))
1323 sm->udp_timeout = SNAT_UDP_TIMEOUT;
1324 sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1325 sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1326 sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1330 error = clib_error_return (0, "unknown input '%U'",
1331 format_unformat_error, line_input);
1337 unformat_free (line_input);
1342 static clib_error_t *
1343 nat44_det_show_timeouts_command_fn (vlib_main_t * vm,
1344 unformat_input_t * input,
1345 vlib_cli_command_t * cmd)
1347 snat_main_t *sm = &snat_main;
1349 if (!sm->deterministic)
1350 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1352 vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1353 vlib_cli_output (vm, "tcp-established timeout: %dsec",
1354 sm->tcp_established_timeout);
1355 vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1356 sm->tcp_transitory_timeout);
1357 vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1362 static clib_error_t *
1363 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1364 unformat_input_t * input,
1365 vlib_cli_command_t * cmd)
1367 snat_main_t *sm = &snat_main;
1369 snat_det_session_t *ses;
1372 if (!sm->deterministic)
1373 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1375 vlib_cli_output (vm, "NAT44 deterministic sessions:");
1377 pool_foreach (dm, sm->det_maps,
1379 vec_foreach_index (i, dm->sessions)
1381 ses = vec_elt_at_index (dm->sessions, i);
1383 vlib_cli_output (vm, " %U", format_det_map_ses, dm, ses, &i);
1390 static clib_error_t *
1391 snat_det_close_session_out_fn (vlib_main_t * vm,
1392 unformat_input_t * input,
1393 vlib_cli_command_t * cmd)
1395 snat_main_t *sm = &snat_main;
1396 unformat_input_t _line_input, *line_input = &_line_input;
1397 ip4_address_t out_addr, ext_addr, in_addr;
1398 u32 out_port, ext_port;
1400 snat_det_session_t *ses;
1401 snat_det_out_key_t key;
1402 clib_error_t *error = 0;
1404 if (!sm->deterministic)
1405 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1407 /* Get a line of input. */
1408 if (!unformat_user (input, unformat_line_input, line_input))
1411 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1413 if (unformat (line_input, "%U:%d %U:%d",
1414 unformat_ip4_address, &out_addr, &out_port,
1415 unformat_ip4_address, &ext_addr, &ext_port))
1419 error = clib_error_return (0, "unknown input '%U'",
1420 format_unformat_error, line_input);
1425 unformat_free (line_input);
1427 dm = snat_det_map_by_out (sm, &out_addr);
1429 vlib_cli_output (vm, "no match");
1432 snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
1433 key.ext_host_addr = out_addr;
1434 key.ext_host_port = ntohs ((u16) ext_port);
1435 key.out_port = ntohs ((u16) out_port);
1436 ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
1438 vlib_cli_output (vm, "no match");
1440 snat_det_ses_close (dm, ses);
1444 unformat_free (line_input);
1449 static clib_error_t *
1450 snat_det_close_session_in_fn (vlib_main_t * vm,
1451 unformat_input_t * input,
1452 vlib_cli_command_t * cmd)
1454 snat_main_t *sm = &snat_main;
1455 unformat_input_t _line_input, *line_input = &_line_input;
1456 ip4_address_t in_addr, ext_addr;
1457 u32 in_port, ext_port;
1459 snat_det_session_t *ses;
1460 snat_det_out_key_t key;
1461 clib_error_t *error = 0;
1463 if (!sm->deterministic)
1464 return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1466 /* Get a line of input. */
1467 if (!unformat_user (input, unformat_line_input, line_input))
1470 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1472 if (unformat (line_input, "%U:%d %U:%d",
1473 unformat_ip4_address, &in_addr, &in_port,
1474 unformat_ip4_address, &ext_addr, &ext_port))
1478 error = clib_error_return (0, "unknown input '%U'",
1479 format_unformat_error, line_input);
1484 unformat_free (line_input);
1486 dm = snat_det_map_by_user (sm, &in_addr);
1488 vlib_cli_output (vm, "no match");
1491 key.ext_host_addr = ext_addr;
1492 key.ext_host_port = ntohs ((u16) ext_port);
1494 snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
1496 vlib_cli_output (vm, "no match");
1498 snat_det_ses_close (dm, ses);
1502 unformat_free (line_input);
1510 * @cliexstart{set snat workers}
1511 * Set NAT workers if 2 or more workers available, use:
1512 * vpp# set snat workers 0-2,5
1515 VLIB_CLI_COMMAND (set_workers_command, static) = {
1516 .path = "set nat workers",
1517 .function = set_workers_command_fn,
1518 .short_help = "set nat workers <workers-list>",
1523 * @cliexstart{show nat workers}
1525 * vpp# show nat workers:
1531 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
1532 .path = "show nat workers",
1533 .short_help = "show nat workers",
1534 .function = nat_show_workers_commnad_fn,
1539 * @cliexstart{snat ipfix logging}
1540 * To enable NAT IPFIX logging use:
1541 * vpp# nat ipfix logging
1542 * To set IPFIX exporter use:
1543 * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
1546 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
1547 .path = "nat ipfix logging",
1548 .function = snat_ipfix_logging_enable_disable_command_fn,
1549 .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
1554 * @cliexstart{nat addr-port-assignment-alg}
1555 * Set address and port assignment algorithm
1556 * For the MAP-E CE limit port choice based on PSID use:
1557 * vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
1558 * To set standard (default) address and port assignment algorithm use:
1559 * vpp# nat addr-port-assignment-alg default
1562 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
1563 .path = "nat addr-port-assignment-alg",
1564 .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
1565 .function = nat44_set_alloc_addr_and_port_alg_command_fn,
1570 * @cliexstart{show nat44 hash tables}
1571 * Show NAT44 hash tables
1574 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
1575 .path = "show nat44 hash tables",
1576 .short_help = "show nat44 hash tables [detail|verbose]",
1577 .function = nat44_show_hash_commnad_fn,
1582 * @cliexstart{nat44 add address}
1583 * Add/delete NAT44 pool address.
1584 * To add NAT44 pool address use:
1585 * vpp# nat44 add address 172.16.1.3
1586 * vpp# nat44 add address 172.16.2.2 - 172.16.2.24
1587 * To add NAT44 pool address for specific tenant (identified by VRF id) use:
1588 * vpp# nat44 add address 172.16.1.3 tenant-vrf 10
1591 VLIB_CLI_COMMAND (add_address_command, static) = {
1592 .path = "nat44 add address",
1593 .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
1594 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
1595 .function = add_address_command_fn,
1600 * @cliexstart{show nat44 addresses}
1601 * Show NAT44 pool addresses.
1602 * vpp# show nat44 addresses
1603 * NAT44 pool addresses:
1605 * tenant VRF independent
1614 * NAT44 twice-nat pool addresses:
1616 * tenant VRF independent
1622 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
1623 .path = "show nat44 addresses",
1624 .short_help = "show nat44 addresses",
1625 .function = nat44_show_addresses_command_fn,
1630 * @cliexstart{set interface nat44}
1631 * Enable/disable NAT44 feature on the interface.
1632 * To enable NAT44 feature with local network interface use:
1633 * vpp# set interface nat44 in GigabitEthernet0/8/0
1634 * To enable NAT44 feature with external network interface use:
1635 * vpp# set interface nat44 out GigabitEthernet0/a/0
1638 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
1639 .path = "set interface nat44",
1640 .function = snat_feature_command_fn,
1641 .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
1647 * @cliexstart{show nat44 interfaces}
1648 * Show interfaces with NAT44 feature.
1649 * vpp# show nat44 interfaces
1651 * GigabitEthernet0/8/0 in
1652 * GigabitEthernet0/a/0 out
1655 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
1656 .path = "show nat44 interfaces",
1657 .short_help = "show nat44 interfaces",
1658 .function = nat44_show_interfaces_command_fn,
1663 * @cliexstart{nat44 add static mapping}
1664 * Static mapping allows hosts on the external network to initiate connection
1665 * to to the local network host.
1666 * To create static mapping between local host address 10.0.0.3 port 6303 and
1667 * external address 4.4.4.4 port 3606 for TCP protocol use:
1668 * vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
1669 * If not runnig "static mapping only" NAT plugin mode use before:
1670 * vpp# nat44 add address 4.4.4.4
1671 * To create static mapping between local and external address use:
1672 * vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
1675 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
1676 .path = "nat44 add static mapping",
1677 .function = add_static_mapping_command_fn,
1679 "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
1680 "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
1681 "[out2in-only] [del]",
1686 * @cliexstart{nat44 add identity mapping}
1687 * Identity mapping translate an IP address to itself.
1688 * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
1690 * vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
1691 * To create identity mapping for address 10.0.0.3 use:
1692 * vpp# nat44 add identity mapping 10.0.0.3
1693 * To create identity mapping for DHCP addressed interface use:
1694 * vpp# nat44 add identity mapping GigabitEthernet0/a/0 tcp 3606
1697 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
1698 .path = "nat44 add identity mapping",
1699 .function = add_identity_mapping_command_fn,
1700 .short_help = "nat44 add identity mapping <interface>|<ip4-addr> "
1701 "[<protocol> <port>] [vrf <table-id>] [del]",
1706 * @cliexstart{nat44 add load-balancing static mapping}
1707 * Service load balancing using NAT44
1708 * To add static mapping with load balancing for service with external IP
1709 * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
1710 * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
1711 * 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
1714 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
1715 .path = "nat44 add load-balancing static mapping",
1716 .function = add_lb_static_mapping_command_fn,
1718 "nat44 add load-balancing static mapping protocol tcp|udp "
1719 "external <addr>:<port> local <addr>:<port> probability <n> "
1720 "[twice-nat|self-twice-nat] [vrf <table-id>] [out2in-only] [del]",
1725 * @cliexstart{show nat44 static mappings}
1726 * Show NAT44 static mappings.
1727 * vpp# show nat44 static mappings
1728 * NAT44 static mappings:
1729 * local 10.0.0.3 external 4.4.4.4 vrf 0
1730 * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
1731 * tcp vrf 0 external 1.2.3.4:80 out2in-only
1732 * local 10.100.10.10:8080 probability 80
1733 * local 10.100.10.20:8080 probability 20
1734 * tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
1735 * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
1738 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
1739 .path = "show nat44 static mappings",
1740 .short_help = "show nat44 static mappings",
1741 .function = nat44_show_static_mappings_command_fn,
1746 * @cliexstart{nat44 add interface address}
1747 * Use NAT44 pool address from specific interfce
1748 * To add NAT44 pool address from specific interface use:
1749 * vpp# nat44 add interface address GigabitEthernet0/8/0
1752 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
1753 .path = "nat44 add interface address",
1754 .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
1755 .function = snat_add_interface_address_command_fn,
1760 * @cliexstart{show nat44 interface address}
1761 * Show NAT44 pool address interfaces
1762 * vpp# show nat44 interface address
1763 * NAT44 pool address interfaces:
1764 * GigabitEthernet0/a/0
1765 * NAT44 twice-nat pool address interfaces:
1766 * GigabitEthernet0/8/0
1769 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
1770 .path = "show nat44 interface address",
1771 .short_help = "show nat44 interface address",
1772 .function = nat44_show_interface_address_command_fn,
1777 * @cliexstart{show nat44 sessions}
1778 * Show NAT44 sessions.
1781 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
1782 .path = "show nat44 sessions",
1783 .short_help = "show nat44 sessions [detail]",
1784 .function = nat44_show_sessions_command_fn,
1789 * @cliexstart{nat44 del session}
1790 * To administratively delete NAT44 session by inside address and port use:
1791 * vpp# nat44 del session in 10.0.0.3:6303 tcp
1792 * To administratively delete NAT44 session by outside address and port use:
1793 * vpp# nat44 del session out 1.0.0.3:6033 udp
1796 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
1797 .path = "nat44 del session",
1798 .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
1799 .function = nat44_del_session_command_fn,
1804 * @cliexstart{nat44 forwarding}
1805 * Enable or disable forwarding
1806 * Forward packets which don't match existing translation
1807 * or static mapping instead of dropping them.
1808 * To enable forwarding, use:
1809 * vpp# nat44 forwarding enable
1810 * To disable forwarding, use:
1811 * vpp# nat44 forwarding disable
1814 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
1815 .path = "nat44 forwarding",
1816 .short_help = "nat44 forwarding enable|disable",
1817 .function = snat_forwarding_set_command_fn,
1822 * @cliexstart{nat44 deterministic add}
1823 * Create bijective mapping of inside address to outside address and port range
1824 * pairs, with the purpose of enabling deterministic NAT to reduce logging in
1826 * To create deterministic mapping between inside network 10.0.0.0/18 and
1827 * outside network 1.1.1.0/30 use:
1828 * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
1831 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
1832 .path = "nat44 deterministic add",
1833 .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
1834 .function = snat_det_map_command_fn,
1839 * @cliexpstart{show nat44 deterministic mappings}
1840 * Show NAT44 deterministic mappings
1841 * vpp# show nat44 deterministic mappings
1842 * NAT44 deterministic mappings:
1843 * in 10.0.0.0/24 out 1.1.1.1/32
1844 * outside address sharing ratio: 256
1845 * number of ports per inside host: 252
1846 * sessions number: 0
1849 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
1850 .path = "show nat44 deterministic mappings",
1851 .short_help = "show nat44 deterministic mappings",
1852 .function = nat44_det_show_mappings_command_fn,
1857 * @cliexstart{nat44 deterministic forward}
1858 * Return outside address and port range from inside address for deterministic
1860 * To obtain outside address and port of inside host use:
1861 * vpp# nat44 deterministic forward 10.0.0.2
1862 * 1.1.1.0:<1054-1068>
1865 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
1866 .path = "nat44 deterministic forward",
1867 .short_help = "nat44 deterministic forward <addr>",
1868 .function = snat_det_forward_command_fn,
1873 * @cliexstart{nat44 deterministic reverse}
1874 * Return inside address from outside address and port for deterministic NAT.
1875 * To obtain inside host address from outside address and port use:
1876 * #vpp nat44 deterministic reverse 1.1.1.1:1276
1880 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
1881 .path = "nat44 deterministic reverse",
1882 .short_help = "nat44 deterministic reverse <addr>:<port>",
1883 .function = snat_det_reverse_command_fn,
1888 * @cliexstart{set nat44 deterministic timeout}
1889 * Set values of timeouts for deterministic NAT (in seconds), use:
1890 * vpp# set nat44 deterministic timeout udp 120 tcp-established 7500
1891 * tcp-transitory 250 icmp 90
1892 * To reset default values use:
1893 * vpp# set nat44 deterministic timeout reset
1896 VLIB_CLI_COMMAND (set_timeout_command, static) = {
1897 .path = "set nat44 deterministic timeout",
1898 .function = set_timeout_command_fn,
1900 "set nat44 deterministic timeout [udp <sec> | tcp-established <sec> "
1901 "tcp-transitory <sec> | icmp <sec> | reset]",
1906 * @cliexstart{show nat44 deterministic timeouts}
1907 * Show values of timeouts for deterministic NAT.
1908 * vpp# show nat44 deterministic timeouts
1909 * udp timeout: 300sec
1910 * tcp-established timeout: 7440sec
1911 * tcp-transitory timeout: 240sec
1912 * icmp timeout: 60sec
1915 VLIB_CLI_COMMAND (nat44_det_show_timeouts_command, static) = {
1916 .path = "show nat44 deterministic timeouts",
1917 .short_help = "show nat44 deterministic timeouts",
1918 .function = nat44_det_show_timeouts_command_fn,
1923 * @cliexstart{show nat44 deterministic sessions}
1924 * Show NAT44 deterministic sessions.
1925 * vpp# show nat44 deterministic sessions
1926 * NAT44 deterministic sessions:
1927 * in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
1928 * in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
1929 * in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
1932 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
1933 .path = "show nat44 deterministic sessions",
1934 .short_help = "show nat44 deterministic sessions",
1935 .function = nat44_det_show_sessions_command_fn,
1940 * @cliexstart{nat44 deterministic close session out}
1941 * Close session using outside ip address and port
1942 * and external ip address and port, use:
1943 * vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
1946 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
1947 .path = "nat44 deterministic close session out",
1948 .short_help = "nat44 deterministic close session out "
1949 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
1950 .function = snat_det_close_session_out_fn,
1955 * @cliexstart{nat44 deterministic close session in}
1956 * Close session using inside ip address and port
1957 * and external ip address and port, use:
1958 * vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
1961 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
1962 .path = "nat44 deterministic close session in",
1963 .short_help = "nat44 deterministic close session in "
1964 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
1965 .function = snat_det_close_session_in_fn,
1971 * fd.io coding-style-patch-verification: ON
1974 * eval: (c-set-style "gnu")