NAT: add support for configurable port range (VPP-1346)
[vpp.git] / src / plugins / nat / nat44_cli.c
1 /*
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 /**
16  * @file
17  * @brief NAT44 CLI
18  */
19
20 #include <nat/nat.h>
21 #include <nat/nat_ipfix_logging.h>
22 #include <nat/nat_det.h>
23 #include <nat/nat64.h>
24 #include <nat/nat_inlines.h>
25 #include <nat/nat_affinity.h>
26 #include <vnet/fib/fib_table.h>
27
28 #define UNSUPPORTED_IN_DET_MODE_STR \
29   "This command is unsupported in deterministic mode"
30 #define SUPPORTED_ONLY_IN_DET_MODE_STR \
31   "This command is supported only in deterministic mode"
32
33 static clib_error_t *
34 set_workers_command_fn (vlib_main_t * vm,
35                         unformat_input_t * input, vlib_cli_command_t * cmd)
36 {
37   unformat_input_t _line_input, *line_input = &_line_input;
38   snat_main_t *sm = &snat_main;
39   uword *bitmap = 0;
40   int rv = 0;
41   clib_error_t *error = 0;
42
43   if (sm->deterministic)
44     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
45
46   /* Get a line of input. */
47   if (!unformat_user (input, unformat_line_input, line_input))
48     return 0;
49
50   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
51     {
52       if (unformat (line_input, "%U", unformat_bitmap_list, &bitmap))
53         ;
54       else
55         {
56           error = clib_error_return (0, "unknown input '%U'",
57                                      format_unformat_error, line_input);
58           goto done;
59         }
60     }
61
62   if (bitmap == 0)
63     {
64       error = clib_error_return (0, "List of workers must be specified.");
65       goto done;
66     }
67
68   rv = snat_set_workers (bitmap);
69
70   clib_bitmap_free (bitmap);
71
72   switch (rv)
73     {
74     case VNET_API_ERROR_INVALID_WORKER:
75       error = clib_error_return (0, "Invalid worker(s).");
76       goto done;
77     case VNET_API_ERROR_FEATURE_DISABLED:
78       error = clib_error_return (0,
79                                  "Supported only if 2 or more workes available.");
80       goto done;
81     default:
82       break;
83     }
84
85 done:
86   unformat_free (line_input);
87
88   return error;
89 }
90
91 static clib_error_t *
92 nat_show_workers_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
93                              vlib_cli_command_t * cmd)
94 {
95   snat_main_t *sm = &snat_main;
96   u32 *worker;
97
98   if (sm->deterministic)
99     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
100
101   if (sm->num_workers > 1)
102     {
103       vlib_cli_output (vm, "%d workers", vec_len (sm->workers));
104       /* *INDENT-OFF* */
105       vec_foreach (worker, sm->workers)
106         {
107           vlib_worker_thread_t *w =
108             vlib_worker_threads + *worker + sm->first_worker_index;
109           vlib_cli_output (vm, "  %s", w->name);
110         }
111       /* *INDENT-ON* */
112     }
113
114   return 0;
115 }
116
117 static clib_error_t *
118 snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm,
119                                               unformat_input_t * input,
120                                               vlib_cli_command_t * cmd)
121 {
122   unformat_input_t _line_input, *line_input = &_line_input;
123   u32 domain_id = 0;
124   u32 src_port = 0;
125   u8 enable = 1;
126   int rv = 0;
127   clib_error_t *error = 0;
128
129   /* Get a line of input. */
130   if (!unformat_user (input, unformat_line_input, line_input))
131     return 0;
132
133   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
134     {
135       if (unformat (line_input, "domain %d", &domain_id))
136         ;
137       else if (unformat (line_input, "src-port %d", &src_port))
138         ;
139       else if (unformat (line_input, "disable"))
140         enable = 0;
141       else
142         {
143           error = clib_error_return (0, "unknown input '%U'",
144                                      format_unformat_error, line_input);
145           goto done;
146         }
147     }
148
149   rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port);
150
151   if (rv)
152     {
153       error = clib_error_return (0, "ipfix logging enable failed");
154       goto done;
155     }
156
157 done:
158   unformat_free (line_input);
159
160   return error;
161 }
162
163 static clib_error_t *
164 nat44_show_hash_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
165                             vlib_cli_command_t * cmd)
166 {
167   snat_main_t *sm = &snat_main;
168   snat_main_per_thread_data_t *tsm;
169   nat_affinity_main_t *nam = &nat_affinity_main;
170   int i;
171   int verbose = 0;
172
173   if (unformat (input, "detail"))
174     verbose = 1;
175   else if (unformat (input, "verbose"))
176     verbose = 2;
177
178   vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
179                    verbose);
180   vlib_cli_output (vm, "%U",
181                    format_bihash_8_8, &sm->static_mapping_by_external,
182                    verbose);
183   vec_foreach_index (i, sm->per_thread_data)
184   {
185     tsm = vec_elt_at_index (sm->per_thread_data, i);
186     vlib_cli_output (vm, "-------- thread %d %s --------\n",
187                      i, vlib_worker_threads[i].name);
188     if (sm->endpoint_dependent)
189       {
190         vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->in2out_ed,
191                          verbose);
192         vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->out2in_ed,
193                          verbose);
194       }
195     else
196       {
197         vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->in2out, verbose);
198         vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->out2in, verbose);
199       }
200     vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->user_hash, verbose);
201   }
202
203   if (sm->endpoint_dependent)
204     vlib_cli_output (vm, "%U", format_bihash_16_8, &nam->affinity_hash,
205                      verbose);
206   return 0;
207 }
208
209 static clib_error_t *
210 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
211                                               unformat_input_t * input,
212                                               vlib_cli_command_t * cmd)
213 {
214   unformat_input_t _line_input, *line_input = &_line_input;
215   snat_main_t *sm = &snat_main;
216   clib_error_t *error = 0;
217   u32 psid, psid_offset, psid_length, port_start, port_end;
218
219   if (sm->deterministic)
220     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
221
222   /* Get a line of input. */
223   if (!unformat_user (input, unformat_line_input, line_input))
224     return 0;
225
226   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
227     {
228       if (unformat (line_input, "default"))
229         nat_set_alloc_addr_and_port_default ();
230       else
231         if (unformat
232             (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
233              &psid_offset, &psid_length))
234         nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
235                                           (u16) psid_length);
236       else
237         if (unformat
238             (line_input, "port-range %d - %d", &port_start, &port_end))
239         {
240           if (port_end <= port_start)
241             {
242               error =
243                 clib_error_return (0,
244                                    "The end-port must be greater than start-port");
245               goto done;
246             }
247           nat_set_alloc_addr_and_port_range ((u16) port_start,
248                                              (u16) port_end);
249         }
250       else
251         {
252           error = clib_error_return (0, "unknown input '%U'",
253                                      format_unformat_error, line_input);
254           goto done;
255         }
256     }
257
258 done:
259   unformat_free (line_input);
260
261   return error;
262 };
263
264 static clib_error_t *
265 nat44_show_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
266                                                unformat_input_t * input,
267                                                vlib_cli_command_t * cmd)
268 {
269   snat_main_t *sm = &snat_main;
270
271   if (sm->deterministic)
272     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
273
274   vlib_cli_output (vm, "NAT address and port: %U",
275                    format_nat_addr_and_port_alloc_alg,
276                    sm->addr_and_port_alloc_alg);
277   switch (sm->addr_and_port_alloc_alg)
278     {
279     case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
280       vlib_cli_output (vm, "  psid %d psid-offset %d psid-len %d", sm->psid,
281                        sm->psid_offset, sm->psid_length);
282       break;
283     case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
284       vlib_cli_output (vm, "  start-port %d end-port %d", sm->start_port,
285                        sm->end_port);
286       break;
287     default:
288       break;
289     }
290
291   return 0;
292 }
293
294 static clib_error_t *
295 add_address_command_fn (vlib_main_t * vm,
296                         unformat_input_t * input, vlib_cli_command_t * cmd)
297 {
298   unformat_input_t _line_input, *line_input = &_line_input;
299   snat_main_t *sm = &snat_main;
300   ip4_address_t start_addr, end_addr, this_addr;
301   u32 start_host_order, end_host_order;
302   u32 vrf_id = ~0;
303   int i, count;
304   int is_add = 1;
305   int rv = 0;
306   clib_error_t *error = 0;
307   u8 twice_nat = 0;
308
309   if (sm->deterministic)
310     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
311
312   /* Get a line of input. */
313   if (!unformat_user (input, unformat_line_input, line_input))
314     return 0;
315
316   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
317     {
318       if (unformat (line_input, "%U - %U",
319                     unformat_ip4_address, &start_addr,
320                     unformat_ip4_address, &end_addr))
321         ;
322       else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
323         ;
324       else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
325         end_addr = start_addr;
326       else if (unformat (line_input, "twice-nat"))
327         twice_nat = 1;
328       else if (unformat (line_input, "del"))
329         is_add = 0;
330       else
331         {
332           error = clib_error_return (0, "unknown input '%U'",
333                                      format_unformat_error, line_input);
334           goto done;
335         }
336     }
337
338   if (sm->static_mapping_only)
339     {
340       error = clib_error_return (0, "static mapping only mode");
341       goto done;
342     }
343
344   start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
345   end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
346
347   if (end_host_order < start_host_order)
348     {
349       error = clib_error_return (0, "end address less than start address");
350       goto done;
351     }
352
353   count = (end_host_order - start_host_order) + 1;
354
355   if (count > 1024)
356     nat_log_info ("%U - %U, %d addresses...",
357                   format_ip4_address, &start_addr,
358                   format_ip4_address, &end_addr, count);
359
360   this_addr = start_addr;
361
362   for (i = 0; i < count; i++)
363     {
364       if (is_add)
365         rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
366       else
367         rv = snat_del_address (sm, this_addr, 0, twice_nat);
368
369       switch (rv)
370         {
371         case VNET_API_ERROR_VALUE_EXIST:
372           error = clib_error_return (0, "NAT address already in use.");
373           goto done;
374         case VNET_API_ERROR_NO_SUCH_ENTRY:
375           error = clib_error_return (0, "NAT address not exist.");
376           goto done;
377         case VNET_API_ERROR_UNSPECIFIED:
378           error =
379             clib_error_return (0, "NAT address used in static mapping.");
380           goto done;
381         case VNET_API_ERROR_FEATURE_DISABLED:
382           error =
383             clib_error_return (0,
384                                "twice NAT available only for endpoint-dependent mode.");
385           goto done;
386         default:
387           break;
388         }
389
390       if (sm->out2in_dpo)
391         nat44_add_del_address_dpo (this_addr, is_add);
392
393       increment_v4_address (&this_addr);
394     }
395
396 done:
397   unformat_free (line_input);
398
399   return error;
400 }
401
402 static clib_error_t *
403 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
404                                  vlib_cli_command_t * cmd)
405 {
406   snat_main_t *sm = &snat_main;
407   snat_address_t *ap;
408
409   if (sm->deterministic)
410     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
411
412   vlib_cli_output (vm, "NAT44 pool addresses:");
413   /* *INDENT-OFF* */
414   vec_foreach (ap, sm->addresses)
415     {
416       vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
417       if (ap->fib_index != ~0)
418           vlib_cli_output (vm, "  tenant VRF: %u",
419             fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
420       else
421         vlib_cli_output (vm, "  tenant VRF independent");
422     #define _(N, i, n, s) \
423       vlib_cli_output (vm, "  %d busy %s ports", ap->busy_##n##_ports, s);
424       foreach_snat_protocol
425     #undef _
426     }
427   vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
428   vec_foreach (ap, sm->twice_nat_addresses)
429     {
430       vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
431       if (ap->fib_index != ~0)
432           vlib_cli_output (vm, "  tenant VRF: %u",
433             fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
434       else
435         vlib_cli_output (vm, "  tenant VRF independent");
436     #define _(N, i, n, s) \
437       vlib_cli_output (vm, "  %d busy %s ports", ap->busy_##n##_ports, s);
438       foreach_snat_protocol
439     #undef _
440     }
441   /* *INDENT-ON* */
442   return 0;
443 }
444
445 static clib_error_t *
446 snat_feature_command_fn (vlib_main_t * vm,
447                          unformat_input_t * input, vlib_cli_command_t * cmd)
448 {
449   unformat_input_t _line_input, *line_input = &_line_input;
450   vnet_main_t *vnm = vnet_get_main ();
451   clib_error_t *error = 0;
452   u32 sw_if_index;
453   u32 *inside_sw_if_indices = 0;
454   u32 *outside_sw_if_indices = 0;
455   u8 is_output_feature = 0;
456   int is_del = 0;
457   int i;
458
459   sw_if_index = ~0;
460
461   /* Get a line of input. */
462   if (!unformat_user (input, unformat_line_input, line_input))
463     return 0;
464
465   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
466     {
467       if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
468                     vnm, &sw_if_index))
469         vec_add1 (inside_sw_if_indices, sw_if_index);
470       else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
471                          vnm, &sw_if_index))
472         vec_add1 (outside_sw_if_indices, sw_if_index);
473       else if (unformat (line_input, "output-feature"))
474         is_output_feature = 1;
475       else if (unformat (line_input, "del"))
476         is_del = 1;
477       else
478         {
479           error = clib_error_return (0, "unknown input '%U'",
480                                      format_unformat_error, line_input);
481           goto done;
482         }
483     }
484
485   if (vec_len (inside_sw_if_indices))
486     {
487       for (i = 0; i < vec_len (inside_sw_if_indices); i++)
488         {
489           sw_if_index = inside_sw_if_indices[i];
490           if (is_output_feature)
491             {
492               if (snat_interface_add_del_output_feature
493                   (sw_if_index, 1, is_del))
494                 {
495                   error = clib_error_return (0, "%s %U failed",
496                                              is_del ? "del" : "add",
497                                              format_vnet_sw_if_index_name,
498                                              vnm, sw_if_index);
499                   goto done;
500                 }
501             }
502           else
503             {
504               if (snat_interface_add_del (sw_if_index, 1, is_del))
505                 {
506                   error = clib_error_return (0, "%s %U failed",
507                                              is_del ? "del" : "add",
508                                              format_vnet_sw_if_index_name,
509                                              vnm, sw_if_index);
510                   goto done;
511                 }
512             }
513         }
514     }
515
516   if (vec_len (outside_sw_if_indices))
517     {
518       for (i = 0; i < vec_len (outside_sw_if_indices); i++)
519         {
520           sw_if_index = outside_sw_if_indices[i];
521           if (is_output_feature)
522             {
523               if (snat_interface_add_del_output_feature
524                   (sw_if_index, 0, is_del))
525                 {
526                   error = clib_error_return (0, "%s %U failed",
527                                              is_del ? "del" : "add",
528                                              format_vnet_sw_if_index_name,
529                                              vnm, sw_if_index);
530                   goto done;
531                 }
532             }
533           else
534             {
535               if (snat_interface_add_del (sw_if_index, 0, is_del))
536                 {
537                   error = clib_error_return (0, "%s %U failed",
538                                              is_del ? "del" : "add",
539                                              format_vnet_sw_if_index_name,
540                                              vnm, sw_if_index);
541                   goto done;
542                 }
543             }
544         }
545     }
546
547 done:
548   unformat_free (line_input);
549   vec_free (inside_sw_if_indices);
550   vec_free (outside_sw_if_indices);
551
552   return error;
553 }
554
555 static clib_error_t *
556 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
557                                   vlib_cli_command_t * cmd)
558 {
559   snat_main_t *sm = &snat_main;
560   snat_interface_t *i;
561   vnet_main_t *vnm = vnet_get_main ();
562
563   vlib_cli_output (vm, "NAT44 interfaces:");
564   /* *INDENT-OFF* */
565   pool_foreach (i, sm->interfaces,
566   ({
567     vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
568                      i->sw_if_index,
569                      (nat_interface_is_inside(i) &&
570                       nat_interface_is_outside(i)) ? "in out" :
571                      (nat_interface_is_inside(i) ? "in" : "out"));
572   }));
573
574   pool_foreach (i, sm->output_feature_interfaces,
575   ({
576     vlib_cli_output (vm, " %U output-feature %s",
577                      format_vnet_sw_if_index_name, vnm,
578                      i->sw_if_index,
579                      (nat_interface_is_inside(i) &&
580                       nat_interface_is_outside(i)) ? "in out" :
581                      (nat_interface_is_inside(i) ? "in" : "out"));
582   }));
583   /* *INDENT-ON* */
584
585   return 0;
586 }
587
588 static clib_error_t *
589 add_static_mapping_command_fn (vlib_main_t * vm,
590                                unformat_input_t * input,
591                                vlib_cli_command_t * cmd)
592 {
593   unformat_input_t _line_input, *line_input = &_line_input;
594   snat_main_t *sm = &snat_main;
595   clib_error_t *error = 0;
596   ip4_address_t l_addr, e_addr;
597   u32 l_port = 0, e_port = 0, vrf_id = ~0;
598   int is_add = 1;
599   int addr_only = 1;
600   u32 sw_if_index = ~0;
601   vnet_main_t *vnm = vnet_get_main ();
602   int rv;
603   snat_protocol_t proto = ~0;
604   u8 proto_set = 0;
605   twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
606   u8 out2in_only = 0;
607
608   if (sm->deterministic)
609     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
610
611   /* Get a line of input. */
612   if (!unformat_user (input, unformat_line_input, line_input))
613     return 0;
614
615   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
616     {
617       if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
618                     &l_port))
619         addr_only = 0;
620       else
621         if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
622         ;
623       else if (unformat (line_input, "external %U %u", unformat_ip4_address,
624                          &e_addr, &e_port))
625         addr_only = 0;
626       else if (unformat (line_input, "external %U", unformat_ip4_address,
627                          &e_addr))
628         ;
629       else if (unformat (line_input, "external %U %u",
630                          unformat_vnet_sw_interface, vnm, &sw_if_index,
631                          &e_port))
632         addr_only = 0;
633
634       else if (unformat (line_input, "external %U",
635                          unformat_vnet_sw_interface, vnm, &sw_if_index))
636         ;
637       else if (unformat (line_input, "vrf %u", &vrf_id))
638         ;
639       else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
640         proto_set = 1;
641       else if (unformat (line_input, "twice-nat"))
642         twice_nat = TWICE_NAT;
643       else if (unformat (line_input, "self-twice-nat"))
644         twice_nat = TWICE_NAT_SELF;
645       else if (unformat (line_input, "out2in-only"))
646         out2in_only = 1;
647       else if (unformat (line_input, "del"))
648         is_add = 0;
649       else
650         {
651           error = clib_error_return (0, "unknown input: '%U'",
652                                      format_unformat_error, line_input);
653           goto done;
654         }
655     }
656
657   if (twice_nat && addr_only)
658     {
659       error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
660       goto done;
661     }
662
663   if (!addr_only && !proto_set)
664     {
665       error = clib_error_return (0, "missing protocol");
666       goto done;
667     }
668
669   rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
670                                 vrf_id, addr_only, sw_if_index, proto, is_add,
671                                 twice_nat, out2in_only, 0);
672
673   switch (rv)
674     {
675     case VNET_API_ERROR_INVALID_VALUE:
676       error = clib_error_return (0, "External port already in use.");
677       goto done;
678     case VNET_API_ERROR_NO_SUCH_ENTRY:
679       if (is_add)
680         error = clib_error_return (0, "External addres must be allocated.");
681       else
682         error = clib_error_return (0, "Mapping not exist.");
683       goto done;
684     case VNET_API_ERROR_NO_SUCH_FIB:
685       error = clib_error_return (0, "No such VRF id.");
686       goto done;
687     case VNET_API_ERROR_VALUE_EXIST:
688       error = clib_error_return (0, "Mapping already exist.");
689       goto done;
690     case VNET_API_ERROR_FEATURE_DISABLED:
691       error =
692         clib_error_return (0,
693                            "twice-nat/out2in-only available only for endpoint-dependent mode.");
694       goto done;
695     default:
696       break;
697     }
698
699 done:
700   unformat_free (line_input);
701
702   return error;
703 }
704
705 static clib_error_t *
706 add_identity_mapping_command_fn (vlib_main_t * vm,
707                                  unformat_input_t * input,
708                                  vlib_cli_command_t * cmd)
709 {
710   unformat_input_t _line_input, *line_input = &_line_input;
711   snat_main_t *sm = &snat_main;
712   clib_error_t *error = 0;
713   ip4_address_t addr;
714   u32 port = 0, vrf_id = ~0;
715   int is_add = 1;
716   int addr_only = 1;
717   u32 sw_if_index = ~0;
718   vnet_main_t *vnm = vnet_get_main ();
719   int rv;
720   snat_protocol_t proto;
721
722   if (sm->deterministic)
723     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
724
725   addr.as_u32 = 0;
726
727   /* Get a line of input. */
728   if (!unformat_user (input, unformat_line_input, line_input))
729     return 0;
730
731   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
732     {
733       if (unformat (line_input, "%U", unformat_ip4_address, &addr))
734         ;
735       else if (unformat (line_input, "external %U",
736                          unformat_vnet_sw_interface, vnm, &sw_if_index))
737         ;
738       else if (unformat (line_input, "vrf %u", &vrf_id))
739         ;
740       else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
741                          &port))
742         addr_only = 0;
743       else if (unformat (line_input, "del"))
744         is_add = 0;
745       else
746         {
747           error = clib_error_return (0, "unknown input: '%U'",
748                                      format_unformat_error, line_input);
749           goto done;
750         }
751     }
752
753   rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
754                                 vrf_id, addr_only, sw_if_index, proto, is_add,
755                                 0, 0, 0);
756
757   switch (rv)
758     {
759     case VNET_API_ERROR_INVALID_VALUE:
760       error = clib_error_return (0, "External port already in use.");
761       goto done;
762     case VNET_API_ERROR_NO_SUCH_ENTRY:
763       if (is_add)
764         error = clib_error_return (0, "External addres must be allocated.");
765       else
766         error = clib_error_return (0, "Mapping not exist.");
767       goto done;
768     case VNET_API_ERROR_NO_SUCH_FIB:
769       error = clib_error_return (0, "No such VRF id.");
770       goto done;
771     case VNET_API_ERROR_VALUE_EXIST:
772       error = clib_error_return (0, "Mapping already exist.");
773       goto done;
774     default:
775       break;
776     }
777
778 done:
779   unformat_free (line_input);
780
781   return error;
782 }
783
784 static clib_error_t *
785 add_lb_static_mapping_command_fn (vlib_main_t * vm,
786                                   unformat_input_t * input,
787                                   vlib_cli_command_t * cmd)
788 {
789   unformat_input_t _line_input, *line_input = &_line_input;
790   snat_main_t *sm = &snat_main;
791   clib_error_t *error = 0;
792   ip4_address_t l_addr, e_addr;
793   u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
794   int is_add = 1;
795   int rv;
796   snat_protocol_t proto;
797   u8 proto_set = 0;
798   nat44_lb_addr_port_t *locals = 0, local;
799   twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
800   u8 out2in_only = 0;
801
802   if (sm->deterministic)
803     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
804
805   /* Get a line of input. */
806   if (!unformat_user (input, unformat_line_input, line_input))
807     return 0;
808
809   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
810     {
811       if (unformat (line_input, "local %U:%u probability %u",
812                     unformat_ip4_address, &l_addr, &l_port, &probability))
813         {
814           memset (&local, 0, sizeof (local));
815           local.addr = l_addr;
816           local.port = (u16) l_port;
817           local.probability = (u8) probability;
818           vec_add1 (locals, local);
819         }
820       else if (unformat (line_input, "local %U:%u vrf %u probability %u",
821                          unformat_ip4_address, &l_addr, &l_port, &vrf_id,
822                          &probability))
823         {
824           memset (&local, 0, sizeof (local));
825           local.addr = l_addr;
826           local.port = (u16) l_port;
827           local.probability = (u8) probability;
828           local.vrf_id = vrf_id;
829           vec_add1 (locals, local);
830         }
831       else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
832                          &e_addr, &e_port))
833         ;
834       else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
835                          &proto))
836         proto_set = 1;
837       else if (unformat (line_input, "twice-nat"))
838         twice_nat = TWICE_NAT;
839       else if (unformat (line_input, "self-twice-nat"))
840         twice_nat = TWICE_NAT_SELF;
841       else if (unformat (line_input, "out2in-only"))
842         out2in_only = 1;
843       else if (unformat (line_input, "del"))
844         is_add = 0;
845       else if (unformat (line_input, "affinity %u", &affinity))
846         ;
847       else
848         {
849           error = clib_error_return (0, "unknown input: '%U'",
850                                      format_unformat_error, line_input);
851           goto done;
852         }
853     }
854
855   if (vec_len (locals) < 2)
856     {
857       error = clib_error_return (0, "at least two local must be set");
858       goto done;
859     }
860
861   if (!proto_set)
862     {
863       error = clib_error_return (0, "missing protocol");
864       goto done;
865     }
866
867   rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, locals,
868                                         is_add, twice_nat, out2in_only, 0,
869                                         affinity);
870
871   switch (rv)
872     {
873     case VNET_API_ERROR_INVALID_VALUE:
874       error = clib_error_return (0, "External port already in use.");
875       goto done;
876     case VNET_API_ERROR_NO_SUCH_ENTRY:
877       if (is_add)
878         error = clib_error_return (0, "External addres must be allocated.");
879       else
880         error = clib_error_return (0, "Mapping not exist.");
881       goto done;
882     case VNET_API_ERROR_VALUE_EXIST:
883       error = clib_error_return (0, "Mapping already exist.");
884       goto done;
885     case VNET_API_ERROR_FEATURE_DISABLED:
886       error =
887         clib_error_return (0, "Available only for endpoint-dependent mode.");
888       goto done;
889     default:
890       break;
891     }
892
893 done:
894   unformat_free (line_input);
895   vec_free (locals);
896
897   return error;
898 }
899
900 static clib_error_t *
901 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
902                                        unformat_input_t * input,
903                                        vlib_cli_command_t * cmd)
904 {
905   snat_main_t *sm = &snat_main;
906   snat_static_mapping_t *m;
907   snat_static_map_resolve_t *rp;
908
909   if (sm->deterministic)
910     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
911
912   vlib_cli_output (vm, "NAT44 static mappings:");
913   /* *INDENT-OFF* */
914   pool_foreach (m, sm->static_mappings,
915   ({
916     vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
917   }));
918   vec_foreach (rp, sm->to_resolve)
919     vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
920   /* *INDENT-ON* */
921
922   return 0;
923 }
924
925 static clib_error_t *
926 snat_add_interface_address_command_fn (vlib_main_t * vm,
927                                        unformat_input_t * input,
928                                        vlib_cli_command_t * cmd)
929 {
930   snat_main_t *sm = &snat_main;
931   unformat_input_t _line_input, *line_input = &_line_input;
932   u32 sw_if_index;
933   int rv;
934   int is_del = 0;
935   clib_error_t *error = 0;
936   u8 twice_nat = 0;
937
938   if (sm->deterministic)
939     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
940
941   /* Get a line of input. */
942   if (!unformat_user (input, unformat_line_input, line_input))
943     return 0;
944
945   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
946     {
947       if (unformat (line_input, "%U", unformat_vnet_sw_interface,
948                     sm->vnet_main, &sw_if_index))
949         ;
950       else if (unformat (line_input, "twice-nat"))
951         twice_nat = 1;
952       else if (unformat (line_input, "del"))
953         is_del = 1;
954       else
955         {
956           error = clib_error_return (0, "unknown input '%U'",
957                                      format_unformat_error, line_input);
958           goto done;
959         }
960     }
961
962   rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
963
964   switch (rv)
965     {
966     case 0:
967       break;
968
969     default:
970       error = clib_error_return (0, "snat_add_interface_address returned %d",
971                                  rv);
972       goto done;
973     }
974
975 done:
976   unformat_free (line_input);
977
978   return error;
979 }
980
981 static clib_error_t *
982 nat44_show_interface_address_command_fn (vlib_main_t * vm,
983                                          unformat_input_t * input,
984                                          vlib_cli_command_t * cmd)
985 {
986   snat_main_t *sm = &snat_main;
987   vnet_main_t *vnm = vnet_get_main ();
988   u32 *sw_if_index;
989
990   if (sm->deterministic)
991     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
992
993   /* *INDENT-OFF* */
994   vlib_cli_output (vm, "NAT44 pool address interfaces:");
995   vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
996     {
997       vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
998                        *sw_if_index);
999     }
1000   vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
1001   vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
1002     {
1003       vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1004                        *sw_if_index);
1005     }
1006   /* *INDENT-ON* */
1007
1008   return 0;
1009 }
1010
1011 static clib_error_t *
1012 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
1013                                 vlib_cli_command_t * cmd)
1014 {
1015   int verbose = 0;
1016   snat_main_t *sm = &snat_main;
1017   snat_main_per_thread_data_t *tsm;
1018   snat_user_t *u;
1019   int i = 0;
1020
1021   if (sm->deterministic)
1022     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1023
1024   if (unformat (input, "detail"))
1025     verbose = 1;
1026
1027   vlib_cli_output (vm, "NAT44 sessions:");
1028
1029   /* *INDENT-OFF* */
1030   vec_foreach_index (i, sm->per_thread_data)
1031     {
1032       tsm = vec_elt_at_index (sm->per_thread_data, i);
1033
1034       vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
1035                        i, vlib_worker_threads[i].name,
1036                        pool_elts (tsm->sessions));
1037       pool_foreach (u, tsm->users,
1038       ({
1039         vlib_cli_output (vm, "  %U", format_snat_user, tsm, u, verbose);
1040       }));
1041     }
1042   /* *INDENT-ON* */
1043
1044   return 0;
1045 }
1046
1047 static clib_error_t *
1048 nat44_del_session_command_fn (vlib_main_t * vm,
1049                               unformat_input_t * input,
1050                               vlib_cli_command_t * cmd)
1051 {
1052   snat_main_t *sm = &snat_main;
1053   unformat_input_t _line_input, *line_input = &_line_input;
1054   int is_in = 0, is_ed = 0;
1055   clib_error_t *error = 0;
1056   ip4_address_t addr, eh_addr;
1057   u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
1058   snat_protocol_t proto;
1059   int rv;
1060
1061   if (sm->deterministic)
1062     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1063
1064   /* Get a line of input. */
1065   if (!unformat_user (input, unformat_line_input, line_input))
1066     return 0;
1067
1068   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1069     {
1070       if (unformat
1071           (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1072            unformat_snat_protocol, &proto))
1073         ;
1074       else if (unformat (line_input, "in"))
1075         {
1076           is_in = 1;
1077           vrf_id = sm->inside_vrf_id;
1078         }
1079       else if (unformat (line_input, "out"))
1080         {
1081           is_in = 0;
1082           vrf_id = sm->outside_vrf_id;
1083         }
1084       else if (unformat (line_input, "vrf %u", &vrf_id))
1085         ;
1086       else
1087         if (unformat
1088             (line_input, "external-host %U:%u", unformat_ip4_address,
1089              &eh_addr, &eh_port))
1090         is_ed = 1;
1091       else
1092         {
1093           error = clib_error_return (0, "unknown input '%U'",
1094                                      format_unformat_error, line_input);
1095           goto done;
1096         }
1097     }
1098
1099   if (is_ed)
1100     rv =
1101       nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port,
1102                             snat_proto_to_ip_proto (proto), vrf_id, is_in);
1103   else
1104     rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
1105
1106   switch (rv)
1107     {
1108     case 0:
1109       break;
1110
1111     default:
1112       error = clib_error_return (0, "nat44_del_session returned %d", rv);
1113       goto done;
1114     }
1115
1116 done:
1117   unformat_free (line_input);
1118
1119   return error;
1120 }
1121
1122 static clib_error_t *
1123 snat_forwarding_set_command_fn (vlib_main_t * vm,
1124                                 unformat_input_t * input,
1125                                 vlib_cli_command_t * cmd)
1126 {
1127   snat_main_t *sm = &snat_main;
1128   unformat_input_t _line_input, *line_input = &_line_input;
1129   u8 forwarding_enable;
1130   u8 forwarding_enable_set = 0;
1131   clib_error_t *error = 0;
1132
1133   if (sm->deterministic)
1134     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1135
1136   /* Get a line of input. */
1137   if (!unformat_user (input, unformat_line_input, line_input))
1138     return clib_error_return (0, "'enable' or 'disable' expected");
1139
1140   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1141     {
1142       if (!forwarding_enable_set && unformat (line_input, "enable"))
1143         {
1144           forwarding_enable = 1;
1145           forwarding_enable_set = 1;
1146         }
1147       else if (!forwarding_enable_set && unformat (line_input, "disable"))
1148         {
1149           forwarding_enable = 0;
1150           forwarding_enable_set = 1;
1151         }
1152       else
1153         {
1154           error = clib_error_return (0, "unknown input '%U'",
1155                                      format_unformat_error, line_input);
1156           goto done;
1157         }
1158     }
1159
1160   if (!forwarding_enable_set)
1161     {
1162       error = clib_error_return (0, "'enable' or 'disable' expected");
1163       goto done;
1164     }
1165
1166   sm->forwarding_enabled = forwarding_enable;
1167
1168 done:
1169   unformat_free (line_input);
1170
1171   return error;
1172 }
1173
1174 static clib_error_t *
1175 snat_det_map_command_fn (vlib_main_t * vm,
1176                          unformat_input_t * input, vlib_cli_command_t * cmd)
1177 {
1178   snat_main_t *sm = &snat_main;
1179   unformat_input_t _line_input, *line_input = &_line_input;
1180   ip4_address_t in_addr, out_addr;
1181   u32 in_plen, out_plen;
1182   int is_add = 1, rv;
1183   clib_error_t *error = 0;
1184
1185   if (!sm->deterministic)
1186     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1187
1188   /* Get a line of input. */
1189   if (!unformat_user (input, unformat_line_input, line_input))
1190     return 0;
1191
1192   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1193     {
1194       if (unformat
1195           (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1196         ;
1197       else
1198         if (unformat
1199             (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1200              &out_plen))
1201         ;
1202       else if (unformat (line_input, "del"))
1203         is_add = 0;
1204       else
1205         {
1206           error = clib_error_return (0, "unknown input '%U'",
1207                                      format_unformat_error, line_input);
1208           goto done;
1209         }
1210     }
1211
1212   rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1213                          is_add);
1214
1215   if (rv)
1216     {
1217       error = clib_error_return (0, "snat_det_add_map return %d", rv);
1218       goto done;
1219     }
1220
1221 done:
1222   unformat_free (line_input);
1223
1224   return error;
1225 }
1226
1227 static clib_error_t *
1228 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1229                                     unformat_input_t * input,
1230                                     vlib_cli_command_t * cmd)
1231 {
1232   snat_main_t *sm = &snat_main;
1233   snat_det_map_t *dm;
1234
1235   if (!sm->deterministic)
1236     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1237
1238   vlib_cli_output (vm, "NAT44 deterministic mappings:");
1239   /* *INDENT-OFF* */
1240   pool_foreach (dm, sm->det_maps,
1241   ({
1242     vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1243                      format_ip4_address, &dm->in_addr, dm->in_plen,
1244                      format_ip4_address, &dm->out_addr, dm->out_plen);
1245     vlib_cli_output (vm, "  outside address sharing ratio: %d\n",
1246                      dm->sharing_ratio);
1247     vlib_cli_output (vm, "  number of ports per inside host: %d\n",
1248                      dm->ports_per_host);
1249     vlib_cli_output (vm, "  sessions number: %d\n", dm->ses_num);
1250   }));
1251   /* *INDENT-ON* */
1252
1253   return 0;
1254 }
1255
1256 static clib_error_t *
1257 snat_det_forward_command_fn (vlib_main_t * vm,
1258                              unformat_input_t * input,
1259                              vlib_cli_command_t * cmd)
1260 {
1261   snat_main_t *sm = &snat_main;
1262   unformat_input_t _line_input, *line_input = &_line_input;
1263   ip4_address_t in_addr, out_addr;
1264   u16 lo_port;
1265   snat_det_map_t *dm;
1266   clib_error_t *error = 0;
1267
1268   if (!sm->deterministic)
1269     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1270
1271   /* Get a line of input. */
1272   if (!unformat_user (input, unformat_line_input, line_input))
1273     return 0;
1274
1275   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1276     {
1277       if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1278         ;
1279       else
1280         {
1281           error = clib_error_return (0, "unknown input '%U'",
1282                                      format_unformat_error, line_input);
1283           goto done;
1284         }
1285     }
1286
1287   dm = snat_det_map_by_user (sm, &in_addr);
1288   if (!dm)
1289     vlib_cli_output (vm, "no match");
1290   else
1291     {
1292       snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1293       vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1294                        lo_port, lo_port + dm->ports_per_host - 1);
1295     }
1296
1297 done:
1298   unformat_free (line_input);
1299
1300   return error;
1301 }
1302
1303 static clib_error_t *
1304 snat_det_reverse_command_fn (vlib_main_t * vm,
1305                              unformat_input_t * input,
1306                              vlib_cli_command_t * cmd)
1307 {
1308   snat_main_t *sm = &snat_main;
1309   unformat_input_t _line_input, *line_input = &_line_input;
1310   ip4_address_t in_addr, out_addr;
1311   u32 out_port;
1312   snat_det_map_t *dm;
1313   clib_error_t *error = 0;
1314
1315   if (!sm->deterministic)
1316     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1317
1318   /* Get a line of input. */
1319   if (!unformat_user (input, unformat_line_input, line_input))
1320     return 0;
1321
1322   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1323     {
1324       if (unformat
1325           (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1326         ;
1327       else
1328         {
1329           error = clib_error_return (0, "unknown input '%U'",
1330                                      format_unformat_error, line_input);
1331           goto done;
1332         }
1333     }
1334
1335   if (out_port < 1024 || out_port > 65535)
1336     {
1337       error = clib_error_return (0, "wrong port, must be <1024-65535>");
1338       goto done;
1339     }
1340
1341   dm = snat_det_map_by_out (sm, &out_addr);
1342   if (!dm)
1343     vlib_cli_output (vm, "no match");
1344   else
1345     {
1346       snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1347       vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1348     }
1349
1350 done:
1351   unformat_free (line_input);
1352
1353   return error;
1354 }
1355
1356 static clib_error_t *
1357 set_timeout_command_fn (vlib_main_t * vm,
1358                         unformat_input_t * input, vlib_cli_command_t * cmd)
1359 {
1360   snat_main_t *sm = &snat_main;
1361   unformat_input_t _line_input, *line_input = &_line_input;
1362   clib_error_t *error = 0;
1363
1364   /* Get a line of input. */
1365   if (!unformat_user (input, unformat_line_input, line_input))
1366     return 0;
1367
1368   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1369     {
1370       if (unformat (line_input, "udp %u", &sm->udp_timeout))
1371         {
1372           if (nat64_set_udp_timeout (sm->udp_timeout))
1373             {
1374               error = clib_error_return (0, "Invalid UDP timeout value");
1375               goto done;
1376             }
1377         }
1378       else if (unformat (line_input, "tcp-established %u",
1379                          &sm->tcp_established_timeout))
1380         {
1381           if (nat64_set_tcp_timeouts
1382               (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1383             {
1384               error =
1385                 clib_error_return (0,
1386                                    "Invalid TCP established timeouts value");
1387               goto done;
1388             }
1389         }
1390       else if (unformat (line_input, "tcp-transitory %u",
1391                          &sm->tcp_transitory_timeout))
1392         {
1393           if (nat64_set_tcp_timeouts
1394               (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1395             {
1396               error =
1397                 clib_error_return (0,
1398                                    "Invalid TCP transitory timeouts value");
1399               goto done;
1400             }
1401         }
1402       else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1403         {
1404           if (nat64_set_icmp_timeout (sm->icmp_timeout))
1405             {
1406               error = clib_error_return (0, "Invalid ICMP timeout value");
1407               goto done;
1408             }
1409         }
1410       else if (unformat (line_input, "reset"))
1411         {
1412           sm->udp_timeout = SNAT_UDP_TIMEOUT;
1413           sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1414           sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1415           sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1416           nat64_set_udp_timeout (0);
1417           nat64_set_icmp_timeout (0);
1418           nat64_set_tcp_timeouts (0, 0);
1419         }
1420       else
1421         {
1422           error = clib_error_return (0, "unknown input '%U'",
1423                                      format_unformat_error, line_input);
1424           goto done;
1425         }
1426     }
1427
1428 done:
1429   unformat_free (line_input);
1430
1431   return error;
1432 }
1433
1434 static clib_error_t *
1435 nat_show_timeouts_command_fn (vlib_main_t * vm,
1436                               unformat_input_t * input,
1437                               vlib_cli_command_t * cmd)
1438 {
1439   snat_main_t *sm = &snat_main;
1440
1441   vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1442   vlib_cli_output (vm, "tcp-established timeout: %dsec",
1443                    sm->tcp_established_timeout);
1444   vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1445                    sm->tcp_transitory_timeout);
1446   vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1447
1448   return 0;
1449 }
1450
1451 static clib_error_t *
1452 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1453                                     unformat_input_t * input,
1454                                     vlib_cli_command_t * cmd)
1455 {
1456   snat_main_t *sm = &snat_main;
1457   snat_det_map_t *dm;
1458   snat_det_session_t *ses;
1459   int i;
1460
1461   if (!sm->deterministic)
1462     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1463
1464   vlib_cli_output (vm, "NAT44 deterministic sessions:");
1465   /* *INDENT-OFF* */
1466   pool_foreach (dm, sm->det_maps,
1467   ({
1468     vec_foreach_index (i, dm->sessions)
1469       {
1470         ses = vec_elt_at_index (dm->sessions, i);
1471         if (ses->in_port)
1472           vlib_cli_output (vm, "  %U", format_det_map_ses, dm, ses, &i);
1473       }
1474   }));
1475   /* *INDENT-ON* */
1476   return 0;
1477 }
1478
1479 static clib_error_t *
1480 snat_det_close_session_out_fn (vlib_main_t * vm,
1481                                unformat_input_t * input,
1482                                vlib_cli_command_t * cmd)
1483 {
1484   snat_main_t *sm = &snat_main;
1485   unformat_input_t _line_input, *line_input = &_line_input;
1486   ip4_address_t out_addr, ext_addr, in_addr;
1487   u32 out_port, ext_port;
1488   snat_det_map_t *dm;
1489   snat_det_session_t *ses;
1490   snat_det_out_key_t key;
1491   clib_error_t *error = 0;
1492
1493   if (!sm->deterministic)
1494     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1495
1496   /* Get a line of input. */
1497   if (!unformat_user (input, unformat_line_input, line_input))
1498     return 0;
1499
1500   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1501     {
1502       if (unformat (line_input, "%U:%d %U:%d",
1503                     unformat_ip4_address, &out_addr, &out_port,
1504                     unformat_ip4_address, &ext_addr, &ext_port))
1505         ;
1506       else
1507         {
1508           error = clib_error_return (0, "unknown input '%U'",
1509                                      format_unformat_error, line_input);
1510           goto done;
1511         }
1512     }
1513
1514   unformat_free (line_input);
1515
1516   dm = snat_det_map_by_out (sm, &out_addr);
1517   if (!dm)
1518     vlib_cli_output (vm, "no match");
1519   else
1520     {
1521       snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
1522       key.ext_host_addr = out_addr;
1523       key.ext_host_port = ntohs ((u16) ext_port);
1524       key.out_port = ntohs ((u16) out_port);
1525       ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
1526       if (!ses)
1527         vlib_cli_output (vm, "no match");
1528       else
1529         snat_det_ses_close (dm, ses);
1530     }
1531
1532 done:
1533   unformat_free (line_input);
1534
1535   return error;
1536 }
1537
1538 static clib_error_t *
1539 snat_det_close_session_in_fn (vlib_main_t * vm,
1540                               unformat_input_t * input,
1541                               vlib_cli_command_t * cmd)
1542 {
1543   snat_main_t *sm = &snat_main;
1544   unformat_input_t _line_input, *line_input = &_line_input;
1545   ip4_address_t in_addr, ext_addr;
1546   u32 in_port, ext_port;
1547   snat_det_map_t *dm;
1548   snat_det_session_t *ses;
1549   snat_det_out_key_t key;
1550   clib_error_t *error = 0;
1551
1552   if (!sm->deterministic)
1553     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1554
1555   /* Get a line of input. */
1556   if (!unformat_user (input, unformat_line_input, line_input))
1557     return 0;
1558
1559   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1560     {
1561       if (unformat (line_input, "%U:%d %U:%d",
1562                     unformat_ip4_address, &in_addr, &in_port,
1563                     unformat_ip4_address, &ext_addr, &ext_port))
1564         ;
1565       else
1566         {
1567           error = clib_error_return (0, "unknown input '%U'",
1568                                      format_unformat_error, line_input);
1569           goto done;
1570         }
1571     }
1572
1573   unformat_free (line_input);
1574
1575   dm = snat_det_map_by_user (sm, &in_addr);
1576   if (!dm)
1577     vlib_cli_output (vm, "no match");
1578   else
1579     {
1580       key.ext_host_addr = ext_addr;
1581       key.ext_host_port = ntohs ((u16) ext_port);
1582       ses =
1583         snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
1584       if (!ses)
1585         vlib_cli_output (vm, "no match");
1586       else
1587         snat_det_ses_close (dm, ses);
1588     }
1589
1590 done:
1591   unformat_free (line_input);
1592
1593   return error;
1594 }
1595 /* *INDENT-OFF* */
1596
1597 /*?
1598  * @cliexpar
1599  * @cliexstart{set snat workers}
1600  * Set NAT workers if 2 or more workers available, use:
1601  *  vpp# set snat workers 0-2,5
1602  * @cliexend
1603 ?*/
1604 VLIB_CLI_COMMAND (set_workers_command, static) = {
1605   .path = "set nat workers",
1606   .function = set_workers_command_fn,
1607   .short_help = "set nat workers <workers-list>",
1608 };
1609
1610 /*?
1611  * @cliexpar
1612  * @cliexstart{show nat workers}
1613  * Show NAT workers.
1614  *  vpp# show nat workers:
1615  *  2 workers
1616  *    vpp_wk_0
1617  *    vpp_wk_1
1618  * @cliexend
1619 ?*/
1620 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
1621   .path = "show nat workers",
1622   .short_help = "show nat workers",
1623   .function = nat_show_workers_commnad_fn,
1624 };
1625
1626 /*?
1627  * @cliexpar
1628  * @cliexstart{set nat timeout}
1629  * Set values of timeouts for NAT sessions (in seconds), use:
1630  *  vpp# set nat timeout udp 120 tcp-established 7500 tcp-transitory 250 icmp 90
1631  * To reset default values use:
1632  *  vpp# set nat44 deterministic timeout reset
1633  * @cliexend
1634 ?*/
1635 VLIB_CLI_COMMAND (set_timeout_command, static) = {
1636   .path = "set nat timeout",
1637   .function = set_timeout_command_fn,
1638   .short_help =
1639     "set nat timeout [udp <sec> | tcp-established <sec> "
1640     "tcp-transitory <sec> | icmp <sec> | reset]",
1641 };
1642
1643 /*?
1644  * @cliexpar
1645  * @cliexstart{show nat timeouts}
1646  * Show values of timeouts for NAT sessions.
1647  * vpp# show nat timeouts
1648  * udp timeout: 300sec
1649  * tcp-established timeout: 7440sec
1650  * tcp-transitory timeout: 240sec
1651  * icmp timeout: 60sec
1652  * @cliexend
1653 ?*/
1654 VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = {
1655   .path = "show nat timeouts",
1656   .short_help = "show nat timeouts",
1657   .function = nat_show_timeouts_command_fn,
1658 };
1659
1660 /*?
1661  * @cliexpar
1662  * @cliexstart{snat ipfix logging}
1663  * To enable NAT IPFIX logging use:
1664  *  vpp# nat ipfix logging
1665  * To set IPFIX exporter use:
1666  *  vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
1667  * @cliexend
1668 ?*/
1669 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
1670   .path = "nat ipfix logging",
1671   .function = snat_ipfix_logging_enable_disable_command_fn,
1672   .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
1673 };
1674
1675 /*?
1676  * @cliexpar
1677  * @cliexstart{nat addr-port-assignment-alg}
1678  * Set address and port assignment algorithm
1679  * For the MAP-E CE limit port choice based on PSID use:
1680  *  vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
1681  * For port range use:
1682  *  vpp# nat addr-port-assignment-alg port-range <start-port> - <end-port>
1683  * To set standard (default) address and port assignment algorithm use:
1684  *  vpp# nat addr-port-assignment-alg default
1685  * @cliexend
1686 ?*/
1687 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
1688     .path = "nat addr-port-assignment-alg",
1689     .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
1690     .function = nat44_set_alloc_addr_and_port_alg_command_fn,
1691 };
1692
1693 /*?
1694  * @cliexpar
1695  * @cliexstart{show nat addr-port-assignment-alg}
1696  * Show address and port assignment algorithm
1697  * @cliexend
1698 ?*/
1699 VLIB_CLI_COMMAND (nat44_show_alloc_addr_and_port_alg_command, static) = {
1700     .path = "show nat addr-port-assignment-alg",
1701     .short_help = "show nat addr-port-assignment-alg",
1702     .function = nat44_show_alloc_addr_and_port_alg_command_fn,
1703 };
1704
1705 /*?
1706  * @cliexpar
1707  * @cliexstart{show nat44 hash tables}
1708  * Show NAT44 hash tables
1709  * @cliexend
1710 ?*/
1711 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
1712   .path = "show nat44 hash tables",
1713   .short_help = "show nat44 hash tables [detail|verbose]",
1714   .function = nat44_show_hash_commnad_fn,
1715 };
1716
1717 /*?
1718  * @cliexpar
1719  * @cliexstart{nat44 add address}
1720  * Add/delete NAT44 pool address.
1721  * To add NAT44 pool address use:
1722  *  vpp# nat44 add address 172.16.1.3
1723  *  vpp# nat44 add address 172.16.2.2 - 172.16.2.24
1724  * To add NAT44 pool address for specific tenant (identified by VRF id) use:
1725  *  vpp# nat44 add address 172.16.1.3 tenant-vrf 10
1726  * @cliexend
1727 ?*/
1728 VLIB_CLI_COMMAND (add_address_command, static) = {
1729   .path = "nat44 add address",
1730   .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
1731                 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
1732   .function = add_address_command_fn,
1733 };
1734
1735 /*?
1736  * @cliexpar
1737  * @cliexstart{show nat44 addresses}
1738  * Show NAT44 pool addresses.
1739  * vpp# show nat44 addresses
1740  * NAT44 pool addresses:
1741  * 172.16.2.2
1742  *   tenant VRF independent
1743  *   10 busy udp ports
1744  *   0 busy tcp ports
1745  *   0 busy icmp ports
1746  * 172.16.1.3
1747  *   tenant VRF: 10
1748  *   0 busy udp ports
1749  *   2 busy tcp ports
1750  *   0 busy icmp ports
1751  * NAT44 twice-nat pool addresses:
1752  * 10.20.30.72
1753  *   tenant VRF independent
1754  *   0 busy udp ports
1755  *   0 busy tcp ports
1756  *   0 busy icmp ports
1757  * @cliexend
1758 ?*/
1759 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
1760   .path = "show nat44 addresses",
1761   .short_help = "show nat44 addresses",
1762   .function = nat44_show_addresses_command_fn,
1763 };
1764
1765 /*?
1766  * @cliexpar
1767  * @cliexstart{set interface nat44}
1768  * Enable/disable NAT44 feature on the interface.
1769  * To enable NAT44 feature with local network interface use:
1770  *  vpp# set interface nat44 in GigabitEthernet0/8/0
1771  * To enable NAT44 feature with external network interface use:
1772  *  vpp# set interface nat44 out GigabitEthernet0/a/0
1773  * @cliexend
1774 ?*/
1775 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
1776   .path = "set interface nat44",
1777   .function = snat_feature_command_fn,
1778   .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
1779                 "[del]",
1780 };
1781
1782 /*?
1783  * @cliexpar
1784  * @cliexstart{show nat44 interfaces}
1785  * Show interfaces with NAT44 feature.
1786  * vpp# show nat44 interfaces
1787  * NAT44 interfaces:
1788  *  GigabitEthernet0/8/0 in
1789  *  GigabitEthernet0/a/0 out
1790  * @cliexend
1791 ?*/
1792 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
1793   .path = "show nat44 interfaces",
1794   .short_help = "show nat44 interfaces",
1795   .function = nat44_show_interfaces_command_fn,
1796 };
1797
1798 /*?
1799  * @cliexpar
1800  * @cliexstart{nat44 add static mapping}
1801  * Static mapping allows hosts on the external network to initiate connection
1802  * to to the local network host.
1803  * To create static mapping between local host address 10.0.0.3 port 6303 and
1804  * external address 4.4.4.4 port 3606 for TCP protocol use:
1805  *  vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
1806  * If not runnig "static mapping only" NAT plugin mode use before:
1807  *  vpp# nat44 add address 4.4.4.4
1808  * To create static mapping between local and external address use:
1809  *  vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
1810  * @cliexend
1811 ?*/
1812 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
1813   .path = "nat44 add static mapping",
1814   .function = add_static_mapping_command_fn,
1815   .short_help =
1816     "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
1817     "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
1818     "[out2in-only] [del]",
1819 };
1820
1821 /*?
1822  * @cliexpar
1823  * @cliexstart{nat44 add identity mapping}
1824  * Identity mapping translate an IP address to itself.
1825  * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
1826  * use:
1827  *  vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
1828  * To create identity mapping for address 10.0.0.3 use:
1829  *  vpp# nat44 add identity mapping 10.0.0.3
1830  * To create identity mapping for DHCP addressed interface use:
1831  *  vpp# nat44 add identity mapping GigabitEthernet0/a/0 tcp 3606
1832  * @cliexend
1833 ?*/
1834 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
1835   .path = "nat44 add identity mapping",
1836   .function = add_identity_mapping_command_fn,
1837   .short_help = "nat44 add identity mapping <interface>|<ip4-addr> "
1838     "[<protocol> <port>] [vrf <table-id>] [del]",
1839 };
1840
1841 /*?
1842  * @cliexpar
1843  * @cliexstart{nat44 add load-balancing static mapping}
1844  * Service load balancing using NAT44
1845  * To add static mapping with load balancing for service with external IP
1846  * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
1847  * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
1848  *  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
1849  * @cliexend
1850 ?*/
1851 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
1852   .path = "nat44 add load-balancing static mapping",
1853   .function = add_lb_static_mapping_command_fn,
1854   .short_help =
1855     "nat44 add load-balancing static mapping protocol tcp|udp "
1856     "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
1857     "probability <n> [twice-nat|self-twice-nat] [out2in-only] "
1858     "[affinity <timeout-seconds>] [del]",
1859 };
1860
1861 /*?
1862  * @cliexpar
1863  * @cliexstart{show nat44 static mappings}
1864  * Show NAT44 static mappings.
1865  * vpp# show nat44 static mappings
1866  * NAT44 static mappings:
1867  *  local 10.0.0.3 external 4.4.4.4 vrf 0
1868  *  tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
1869  *  tcp vrf 0 external 1.2.3.4:80  out2in-only
1870  *   local 10.100.10.10:8080 probability 80
1871  *   local 10.100.10.20:8080 probability 20
1872  *  tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
1873  *  tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
1874  * @cliexend
1875 ?*/
1876 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
1877   .path = "show nat44 static mappings",
1878   .short_help = "show nat44 static mappings",
1879   .function = nat44_show_static_mappings_command_fn,
1880 };
1881
1882 /*?
1883  * @cliexpar
1884  * @cliexstart{nat44 add interface address}
1885  * Use NAT44 pool address from specific interfce
1886  * To add NAT44 pool address from specific interface use:
1887  *  vpp# nat44 add interface address GigabitEthernet0/8/0
1888  * @cliexend
1889 ?*/
1890 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
1891     .path = "nat44 add interface address",
1892     .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
1893     .function = snat_add_interface_address_command_fn,
1894 };
1895
1896 /*?
1897  * @cliexpar
1898  * @cliexstart{show nat44 interface address}
1899  * Show NAT44 pool address interfaces
1900  * vpp# show nat44 interface address
1901  * NAT44 pool address interfaces:
1902  *  GigabitEthernet0/a/0
1903  * NAT44 twice-nat pool address interfaces:
1904  *  GigabitEthernet0/8/0
1905  * @cliexend
1906 ?*/
1907 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
1908   .path = "show nat44 interface address",
1909   .short_help = "show nat44 interface address",
1910   .function = nat44_show_interface_address_command_fn,
1911 };
1912
1913 /*?
1914  * @cliexpar
1915  * @cliexstart{show nat44 sessions}
1916  * Show NAT44 sessions.
1917  * @cliexend
1918 ?*/
1919 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
1920   .path = "show nat44 sessions",
1921   .short_help = "show nat44 sessions [detail]",
1922   .function = nat44_show_sessions_command_fn,
1923 };
1924
1925 /*?
1926  * @cliexpar
1927  * @cliexstart{nat44 del session}
1928  * To administratively delete NAT44 session by inside address and port use:
1929  *  vpp# nat44 del session in 10.0.0.3:6303 tcp
1930  * To administratively delete NAT44 session by outside address and port use:
1931  *  vpp# nat44 del session out 1.0.0.3:6033 udp
1932  * @cliexend
1933 ?*/
1934 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
1935     .path = "nat44 del session",
1936     .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
1937     .function = nat44_del_session_command_fn,
1938 };
1939
1940 /*?
1941  * @cliexpar
1942  * @cliexstart{nat44 forwarding}
1943  * Enable or disable forwarding
1944  * Forward packets which don't match existing translation
1945  * or static mapping instead of dropping them.
1946  * To enable forwarding, use:
1947  *  vpp# nat44 forwarding enable
1948  * To disable forwarding, use:
1949  *  vpp# nat44 forwarding disable
1950  * @cliexend
1951 ?*/
1952 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
1953   .path = "nat44 forwarding",
1954   .short_help = "nat44 forwarding enable|disable",
1955   .function = snat_forwarding_set_command_fn,
1956 };
1957
1958 /*?
1959  * @cliexpar
1960  * @cliexstart{nat44 deterministic add}
1961  * Create bijective mapping of inside address to outside address and port range
1962  * pairs, with the purpose of enabling deterministic NAT to reduce logging in
1963  * CGN deployments.
1964  * To create deterministic mapping between inside network 10.0.0.0/18 and
1965  * outside network 1.1.1.0/30 use:
1966  * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
1967  * @cliexend
1968 ?*/
1969 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
1970     .path = "nat44 deterministic add",
1971     .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
1972     .function = snat_det_map_command_fn,
1973 };
1974
1975 /*?
1976  * @cliexpar
1977  * @cliexpstart{show nat44 deterministic mappings}
1978  * Show NAT44 deterministic mappings
1979  * vpp# show nat44 deterministic mappings
1980  * NAT44 deterministic mappings:
1981  *  in 10.0.0.0/24 out 1.1.1.1/32
1982  *   outside address sharing ratio: 256
1983  *   number of ports per inside host: 252
1984  *   sessions number: 0
1985  * @cliexend
1986 ?*/
1987 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
1988     .path = "show nat44 deterministic mappings",
1989     .short_help = "show nat44 deterministic mappings",
1990     .function = nat44_det_show_mappings_command_fn,
1991 };
1992
1993 /*?
1994  * @cliexpar
1995  * @cliexstart{nat44 deterministic forward}
1996  * Return outside address and port range from inside address for deterministic
1997  * NAT.
1998  * To obtain outside address and port of inside host use:
1999  *  vpp# nat44 deterministic forward 10.0.0.2
2000  *  1.1.1.0:<1054-1068>
2001  * @cliexend
2002 ?*/
2003 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
2004     .path = "nat44 deterministic forward",
2005     .short_help = "nat44 deterministic forward <addr>",
2006     .function = snat_det_forward_command_fn,
2007 };
2008
2009 /*?
2010  * @cliexpar
2011  * @cliexstart{nat44 deterministic reverse}
2012  * Return inside address from outside address and port for deterministic NAT.
2013  * To obtain inside host address from outside address and port use:
2014  *  #vpp nat44 deterministic reverse 1.1.1.1:1276
2015  *  10.0.16.16
2016  * @cliexend
2017 ?*/
2018 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
2019     .path = "nat44 deterministic reverse",
2020     .short_help = "nat44 deterministic reverse <addr>:<port>",
2021     .function = snat_det_reverse_command_fn,
2022 };
2023
2024 /*?
2025  * @cliexpar
2026  * @cliexstart{show nat44 deterministic sessions}
2027  * Show NAT44 deterministic sessions.
2028  * vpp# show nat44 deterministic sessions
2029  * NAT44 deterministic sessions:
2030  *   in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
2031  *   in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
2032  *   in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
2033  * @cliexend
2034 ?*/
2035 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
2036   .path = "show nat44 deterministic sessions",
2037   .short_help = "show nat44 deterministic sessions",
2038   .function = nat44_det_show_sessions_command_fn,
2039 };
2040
2041 /*?
2042  * @cliexpar
2043  * @cliexstart{nat44 deterministic close session out}
2044  * Close session using outside ip address and port
2045  * and external ip address and port, use:
2046  *  vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
2047  * @cliexend
2048 ?*/
2049 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
2050   .path = "nat44 deterministic close session out",
2051   .short_help = "nat44 deterministic close session out "
2052                 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
2053   .function = snat_det_close_session_out_fn,
2054 };
2055
2056 /*?
2057  * @cliexpar
2058  * @cliexstart{nat44 deterministic close session in}
2059  * Close session using inside ip address and port
2060  * and external ip address and port, use:
2061  *  vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
2062  * @cliexend
2063 ?*/
2064 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
2065   .path = "nat44 deterministic close session in",
2066   .short_help = "nat44 deterministic close session in "
2067                 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
2068   .function = snat_det_close_session_in_fn,
2069 };
2070
2071 /* *INDENT-ON* */
2072
2073 /*
2074  * fd.io coding-style-patch-verification: ON
2075  *
2076  * Local Variables:
2077  * eval: (c-set-style "gnu")
2078  * End:
2079  */