nat: scavenging functionality removed
[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/nat44/inlines.h>
26 #include <nat/nat_affinity.h>
27 #include <vnet/fib/fib_table.h>
28 #include <nat/nat_ha.h>
29
30 #define UNSUPPORTED_IN_DET_MODE_STR \
31   "This command is unsupported in deterministic mode"
32 #define SUPPORTED_ONLY_IN_DET_MODE_STR \
33   "This command is supported only in deterministic mode"
34
35 static clib_error_t *
36 set_workers_command_fn (vlib_main_t * vm,
37                         unformat_input_t * input, vlib_cli_command_t * cmd)
38 {
39   unformat_input_t _line_input, *line_input = &_line_input;
40   snat_main_t *sm = &snat_main;
41   uword *bitmap = 0;
42   int rv = 0;
43   clib_error_t *error = 0;
44
45   if (sm->deterministic)
46     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
47
48   /* Get a line of input. */
49   if (!unformat_user (input, unformat_line_input, line_input))
50     return 0;
51
52   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
53     {
54       if (unformat (line_input, "%U", unformat_bitmap_list, &bitmap))
55         ;
56       else
57         {
58           error = clib_error_return (0, "unknown input '%U'",
59                                      format_unformat_error, line_input);
60           goto done;
61         }
62     }
63
64   if (bitmap == 0)
65     {
66       error = clib_error_return (0, "List of workers must be specified.");
67       goto done;
68     }
69
70   rv = snat_set_workers (bitmap);
71
72   clib_bitmap_free (bitmap);
73
74   switch (rv)
75     {
76     case VNET_API_ERROR_INVALID_WORKER:
77       error = clib_error_return (0, "Invalid worker(s).");
78       goto done;
79     case VNET_API_ERROR_FEATURE_DISABLED:
80       error = clib_error_return (0,
81                                  "Supported only if 2 or more workes available.");
82       goto done;
83     default:
84       break;
85     }
86
87 done:
88   unformat_free (line_input);
89
90   return error;
91 }
92
93 static clib_error_t *
94 nat_show_workers_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
95                              vlib_cli_command_t * cmd)
96 {
97   snat_main_t *sm = &snat_main;
98   u32 *worker;
99
100   if (sm->deterministic)
101     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
102
103   if (sm->num_workers > 1)
104     {
105       vlib_cli_output (vm, "%d workers", vec_len (sm->workers));
106       /* *INDENT-OFF* */
107       vec_foreach (worker, sm->workers)
108         {
109           vlib_worker_thread_t *w =
110             vlib_worker_threads + *worker + sm->first_worker_index;
111           vlib_cli_output (vm, "  %s", w->name);
112         }
113       /* *INDENT-ON* */
114     }
115
116   return 0;
117 }
118
119 static clib_error_t *
120 snat_set_log_level_command_fn (vlib_main_t * vm,
121                                unformat_input_t * input,
122                                vlib_cli_command_t * cmd)
123 {
124   unformat_input_t _line_input, *line_input = &_line_input;
125   snat_main_t *sm = &snat_main;
126   u8 log_level = SNAT_LOG_NONE;
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   if (!unformat (line_input, "%d", &log_level))
134     {
135       error = clib_error_return (0, "unknown input '%U'",
136                                  format_unformat_error, line_input);
137       goto done;
138     }
139   if (log_level > SNAT_LOG_DEBUG)
140     {
141       error = clib_error_return (0, "unknown logging level '%d'", log_level);
142       goto done;
143     }
144   sm->log_level = log_level;
145
146 done:
147   unformat_free (line_input);
148
149   return error;
150 }
151
152 static clib_error_t *
153 snat_ipfix_logging_enable_disable_command_fn (vlib_main_t * vm,
154                                               unformat_input_t * input,
155                                               vlib_cli_command_t * cmd)
156 {
157   unformat_input_t _line_input, *line_input = &_line_input;
158   u32 domain_id = 0;
159   u32 src_port = 0;
160   u8 enable = 1;
161   int rv = 0;
162   clib_error_t *error = 0;
163
164   /* Get a line of input. */
165   if (!unformat_user (input, unformat_line_input, line_input))
166     {
167       rv = snat_ipfix_logging_enable_disable (enable, domain_id,
168                                               (u16) src_port);
169       if (rv)
170         return clib_error_return (0, "ipfix logging enable failed");
171       return 0;
172     }
173
174   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
175     {
176       if (unformat (line_input, "domain %d", &domain_id))
177         ;
178       else if (unformat (line_input, "src-port %d", &src_port))
179         ;
180       else if (unformat (line_input, "disable"))
181         enable = 0;
182       else
183         {
184           error = clib_error_return (0, "unknown input '%U'",
185                                      format_unformat_error, line_input);
186           goto done;
187         }
188     }
189
190   rv = snat_ipfix_logging_enable_disable (enable, domain_id, (u16) src_port);
191
192   if (rv)
193     {
194       error = clib_error_return (0, "ipfix logging enable failed");
195       goto done;
196     }
197
198 done:
199   unformat_free (line_input);
200
201   return error;
202 }
203
204 static clib_error_t *
205 nat44_show_hash_commnad_fn (vlib_main_t * vm, unformat_input_t * input,
206                             vlib_cli_command_t * cmd)
207 {
208   snat_main_t *sm = &snat_main;
209   snat_main_per_thread_data_t *tsm;
210   nat_affinity_main_t *nam = &nat_affinity_main;
211   int i;
212   int verbose = 0;
213
214   if (unformat (input, "detail"))
215     verbose = 1;
216   else if (unformat (input, "verbose"))
217     verbose = 2;
218
219   vlib_cli_output (vm, "%U", format_bihash_8_8, &sm->static_mapping_by_local,
220                    verbose);
221   vlib_cli_output (vm, "%U",
222                    format_bihash_8_8, &sm->static_mapping_by_external,
223                    verbose);
224   vec_foreach_index (i, sm->per_thread_data)
225   {
226     tsm = vec_elt_at_index (sm->per_thread_data, i);
227     vlib_cli_output (vm, "-------- thread %d %s --------\n",
228                      i, vlib_worker_threads[i].name);
229     if (sm->endpoint_dependent)
230       {
231         vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->in2out_ed,
232                          verbose);
233         vlib_cli_output (vm, "%U", format_bihash_16_8, &tsm->out2in_ed,
234                          verbose);
235       }
236     else
237       {
238         vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->in2out, verbose);
239         vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->out2in, verbose);
240       }
241     vlib_cli_output (vm, "%U", format_bihash_8_8, &tsm->user_hash, verbose);
242   }
243
244   if (sm->endpoint_dependent)
245     {
246       vlib_cli_output (vm, "%U", format_bihash_16_8, &nam->affinity_hash,
247                        verbose);
248       vlib_cli_output (vm, "%U", format_bihash_16_8, &sm->ed_ext_ports, 0);
249     }
250   return 0;
251 }
252
253 static clib_error_t *
254 nat44_set_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
255                                               unformat_input_t * input,
256                                               vlib_cli_command_t * cmd)
257 {
258   unformat_input_t _line_input, *line_input = &_line_input;
259   snat_main_t *sm = &snat_main;
260   clib_error_t *error = 0;
261   u32 psid, psid_offset, psid_length, port_start, port_end;
262
263   if (sm->deterministic)
264     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
265
266   /* Get a line of input. */
267   if (!unformat_user (input, unformat_line_input, line_input))
268     return 0;
269
270   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
271     {
272       if (unformat (line_input, "default"))
273         nat_set_alloc_addr_and_port_default ();
274       else
275         if (unformat
276             (line_input, "map-e psid %d psid-offset %d psid-len %d", &psid,
277              &psid_offset, &psid_length))
278         nat_set_alloc_addr_and_port_mape ((u16) psid, (u16) psid_offset,
279                                           (u16) psid_length);
280       else
281         if (unformat
282             (line_input, "port-range %d - %d", &port_start, &port_end))
283         {
284           if (port_end <= port_start)
285             {
286               error =
287                 clib_error_return (0,
288                                    "The end-port must be greater than start-port");
289               goto done;
290             }
291           nat_set_alloc_addr_and_port_range ((u16) port_start,
292                                              (u16) port_end);
293         }
294       else
295         {
296           error = clib_error_return (0, "unknown input '%U'",
297                                      format_unformat_error, line_input);
298           goto done;
299         }
300     }
301
302 done:
303   unformat_free (line_input);
304
305   return error;
306 };
307
308 static clib_error_t *
309 nat44_show_alloc_addr_and_port_alg_command_fn (vlib_main_t * vm,
310                                                unformat_input_t * input,
311                                                vlib_cli_command_t * cmd)
312 {
313   snat_main_t *sm = &snat_main;
314
315   if (sm->deterministic)
316     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
317
318   vlib_cli_output (vm, "NAT address and port: %U",
319                    format_nat_addr_and_port_alloc_alg,
320                    sm->addr_and_port_alloc_alg);
321   switch (sm->addr_and_port_alloc_alg)
322     {
323     case NAT_ADDR_AND_PORT_ALLOC_ALG_MAPE:
324       vlib_cli_output (vm, "  psid %d psid-offset %d psid-len %d", sm->psid,
325                        sm->psid_offset, sm->psid_length);
326       break;
327     case NAT_ADDR_AND_PORT_ALLOC_ALG_RANGE:
328       vlib_cli_output (vm, "  start-port %d end-port %d", sm->start_port,
329                        sm->end_port);
330       break;
331     default:
332       break;
333     }
334
335   return 0;
336 }
337
338 static clib_error_t *
339 nat_set_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
340                                  vlib_cli_command_t * cmd)
341 {
342   unformat_input_t _line_input, *line_input = &_line_input;
343   snat_main_t *sm = &snat_main;
344   clib_error_t *error = 0;
345   u32 mss;
346
347   /* Get a line of input. */
348   if (!unformat_user (input, unformat_line_input, line_input))
349     return 0;
350
351   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
352     {
353       if (unformat (line_input, "disable"))
354         sm->mss_clamping = 0;
355       else if (unformat (line_input, "%d", &mss))
356         {
357           sm->mss_clamping = (u16) mss;
358           sm->mss_value_net = clib_host_to_net_u16 (sm->mss_clamping);
359         }
360       else
361         {
362           error = clib_error_return (0, "unknown input '%U'",
363                                      format_unformat_error, line_input);
364           goto done;
365         }
366     }
367
368 done:
369   unformat_free (line_input);
370
371   return error;
372 }
373
374 static clib_error_t *
375 nat_show_mss_clamping_command_fn (vlib_main_t * vm, unformat_input_t * input,
376                                   vlib_cli_command_t * cmd)
377 {
378   snat_main_t *sm = &snat_main;
379
380   if (sm->mss_clamping)
381     vlib_cli_output (vm, "mss-clamping %d", sm->mss_clamping);
382   else
383     vlib_cli_output (vm, "mss-clamping disabled");
384
385   return 0;
386 }
387
388 static clib_error_t *
389 nat_ha_failover_command_fn (vlib_main_t * vm, unformat_input_t * input,
390                             vlib_cli_command_t * cmd)
391 {
392   unformat_input_t _line_input, *line_input = &_line_input;
393   ip4_address_t addr;
394   u32 port, session_refresh_interval = 10;
395   int rv;
396   clib_error_t *error = 0;
397
398   /* Get a line of input. */
399   if (!unformat_user (input, unformat_line_input, line_input))
400     return 0;
401
402   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
403     {
404       if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
405         ;
406       else
407         if (unformat
408             (line_input, "refresh-interval %u", &session_refresh_interval))
409         ;
410       else
411         {
412           error = clib_error_return (0, "unknown input '%U'",
413                                      format_unformat_error, line_input);
414           goto done;
415         }
416     }
417
418   rv = nat_ha_set_failover (&addr, (u16) port, session_refresh_interval);
419   if (rv)
420     error = clib_error_return (0, "set HA failover failed");
421
422 done:
423   unformat_free (line_input);
424
425   return error;
426 }
427
428 static clib_error_t *
429 nat_ha_listener_command_fn (vlib_main_t * vm, unformat_input_t * input,
430                             vlib_cli_command_t * cmd)
431 {
432   unformat_input_t _line_input, *line_input = &_line_input;
433   ip4_address_t addr;
434   u32 port, path_mtu = 512;
435   int rv;
436   clib_error_t *error = 0;
437
438   /* Get a line of input. */
439   if (!unformat_user (input, unformat_line_input, line_input))
440     return 0;
441
442   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
443     {
444       if (unformat (line_input, "%U:%u", unformat_ip4_address, &addr, &port))
445         ;
446       else if (unformat (line_input, "path-mtu %u", &path_mtu))
447         ;
448       else
449         {
450           error = clib_error_return (0, "unknown input '%U'",
451                                      format_unformat_error, line_input);
452           goto done;
453         }
454     }
455
456   rv = nat_ha_set_listener (&addr, (u16) port, path_mtu);
457   if (rv)
458     error = clib_error_return (0, "set HA listener failed");
459
460 done:
461   unformat_free (line_input);
462
463   return error;
464 }
465
466 static clib_error_t *
467 nat_show_ha_command_fn (vlib_main_t * vm, unformat_input_t * input,
468                         vlib_cli_command_t * cmd)
469 {
470   ip4_address_t addr;
471   u16 port;
472   u32 path_mtu, session_refresh_interval, resync_ack_missed;
473   u8 in_resync;
474
475   nat_ha_get_listener (&addr, &port, &path_mtu);
476   if (!port)
477     {
478       vlib_cli_output (vm, "NAT HA disabled\n");
479       return 0;
480     }
481
482   vlib_cli_output (vm, "LISTENER:\n");
483   vlib_cli_output (vm, "  %U:%u path-mtu %u\n",
484                    format_ip4_address, &addr, port, path_mtu);
485
486   nat_ha_get_failover (&addr, &port, &session_refresh_interval);
487   vlib_cli_output (vm, "FAILOVER:\n");
488   if (port)
489     vlib_cli_output (vm, "  %U:%u refresh-interval %usec\n",
490                      format_ip4_address, &addr, port,
491                      session_refresh_interval);
492   else
493     vlib_cli_output (vm, "  NA\n");
494
495   nat_ha_get_resync_status (&in_resync, &resync_ack_missed);
496   vlib_cli_output (vm, "RESYNC:\n");
497   if (in_resync)
498     vlib_cli_output (vm, "  in progress\n");
499   else
500     vlib_cli_output (vm, "  completed (%d ACK missed)\n", resync_ack_missed);
501
502   return 0;
503 }
504
505 static clib_error_t *
506 nat_ha_flush_command_fn (vlib_main_t * vm, unformat_input_t * input,
507                          vlib_cli_command_t * cmd)
508 {
509   nat_ha_flush (0);
510   return 0;
511 }
512
513 static clib_error_t *
514 nat_ha_resync_command_fn (vlib_main_t * vm, unformat_input_t * input,
515                           vlib_cli_command_t * cmd)
516 {
517   clib_error_t *error = 0;
518
519   if (nat_ha_resync (0, 0, 0))
520     error = clib_error_return (0, "NAT HA resync already running");
521
522   return error;
523 }
524
525 static clib_error_t *
526 add_address_command_fn (vlib_main_t * vm,
527                         unformat_input_t * input, vlib_cli_command_t * cmd)
528 {
529   unformat_input_t _line_input, *line_input = &_line_input;
530   snat_main_t *sm = &snat_main;
531   ip4_address_t start_addr, end_addr, this_addr;
532   u32 start_host_order, end_host_order;
533   u32 vrf_id = ~0;
534   int i, count;
535   int is_add = 1;
536   int rv = 0;
537   clib_error_t *error = 0;
538   u8 twice_nat = 0;
539
540   if (sm->deterministic)
541     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
542
543   /* Get a line of input. */
544   if (!unformat_user (input, unformat_line_input, line_input))
545     return 0;
546
547   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
548     {
549       if (unformat (line_input, "%U - %U",
550                     unformat_ip4_address, &start_addr,
551                     unformat_ip4_address, &end_addr))
552         ;
553       else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
554         ;
555       else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
556         end_addr = start_addr;
557       else if (unformat (line_input, "twice-nat"))
558         twice_nat = 1;
559       else if (unformat (line_input, "del"))
560         is_add = 0;
561       else
562         {
563           error = clib_error_return (0, "unknown input '%U'",
564                                      format_unformat_error, line_input);
565           goto done;
566         }
567     }
568
569   if (sm->static_mapping_only)
570     {
571       error = clib_error_return (0, "static mapping only mode");
572       goto done;
573     }
574
575   start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
576   end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
577
578   if (end_host_order < start_host_order)
579     {
580       error = clib_error_return (0, "end address less than start address");
581       goto done;
582     }
583
584   count = (end_host_order - start_host_order) + 1;
585
586   if (count > 1024)
587     nat_log_info ("%U - %U, %d addresses...",
588                   format_ip4_address, &start_addr,
589                   format_ip4_address, &end_addr, count);
590
591   this_addr = start_addr;
592
593   for (i = 0; i < count; i++)
594     {
595       if (is_add)
596         rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat);
597       else
598         rv = snat_del_address (sm, this_addr, 0, twice_nat);
599
600       switch (rv)
601         {
602         case VNET_API_ERROR_VALUE_EXIST:
603           error = clib_error_return (0, "NAT address already in use.");
604           goto done;
605         case VNET_API_ERROR_NO_SUCH_ENTRY:
606           error = clib_error_return (0, "NAT address not exist.");
607           goto done;
608         case VNET_API_ERROR_UNSPECIFIED:
609           error =
610             clib_error_return (0, "NAT address used in static mapping.");
611           goto done;
612         case VNET_API_ERROR_FEATURE_DISABLED:
613           error =
614             clib_error_return (0,
615                                "twice NAT available only for endpoint-dependent mode.");
616           goto done;
617         default:
618           break;
619         }
620
621       if (sm->out2in_dpo)
622         nat44_add_del_address_dpo (this_addr, is_add);
623
624       increment_v4_address (&this_addr);
625     }
626
627 done:
628   unformat_free (line_input);
629
630   return error;
631 }
632
633 static clib_error_t *
634 nat44_show_summary_command_fn (vlib_main_t * vm, unformat_input_t * input,
635                                vlib_cli_command_t * cmd)
636 {
637   snat_main_per_thread_data_t *tsm;
638   snat_main_t *sm = &snat_main;
639   snat_session_t *s;
640
641   if (sm->deterministic || !sm->endpoint_dependent)
642     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
643
644   // print session configuration values
645   vlib_cli_output (vm, "max translations: %u", sm->max_translations);
646   vlib_cli_output (vm, "max translations per user: %u",
647                    sm->max_translations_per_user);
648
649   u32 count = 0;
650
651   u64 now = vlib_time_now (sm->vlib_main);
652   u64 sess_timeout_time;
653
654   u32 udp_sessions = 0;
655   u32 tcp_sessions = 0;
656   u32 icmp_sessions = 0;
657
658   u32 timed_out = 0;
659   u32 transitory = 0;
660   u32 transitory_wait_closed = 0;
661   u32 transitory_closed = 0;
662   u32 established = 0;
663
664   if (sm->num_workers > 1)
665     {
666       /* *INDENT-OFF* */
667       vec_foreach (tsm, sm->per_thread_data)
668         {
669           pool_foreach (s, tsm->sessions,
670           ({
671             sess_timeout_time = s->last_heard +
672               (f64) nat44_session_get_timeout (sm, s);
673             if (now >= sess_timeout_time)
674               timed_out++;
675
676             switch (s->in2out.protocol)
677               {
678               case SNAT_PROTOCOL_ICMP:
679                 icmp_sessions++;
680                 break;
681               case SNAT_PROTOCOL_TCP:
682                 tcp_sessions++;
683                 if (s->state)
684                   {
685                     if (s->tcp_close_timestamp)
686                       {
687                         if (now >= s->tcp_close_timestamp)
688                           {
689                             ++transitory_closed;
690                           }
691                         else
692                           {
693                             ++transitory_wait_closed;
694                           }
695                       }
696                     transitory++;
697                   }
698                 else
699                   established++;
700                 break;
701               case SNAT_PROTOCOL_UDP:
702               default:
703                 udp_sessions++;
704                 break;
705               }
706           }));
707           count += pool_elts (tsm->sessions);
708         }
709       /* *INDENT-ON* */
710     }
711   else
712     {
713       tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
714       /* *INDENT-OFF* */
715       pool_foreach (s, tsm->sessions,
716       ({
717         sess_timeout_time = s->last_heard +
718             (f64) nat44_session_get_timeout (sm, s);
719         if (now >= sess_timeout_time)
720           timed_out++;
721
722         switch (s->in2out.protocol)
723           {
724           case SNAT_PROTOCOL_ICMP:
725             icmp_sessions++;
726             break;
727           case SNAT_PROTOCOL_TCP:
728             tcp_sessions++;
729             if (s->state)
730               {
731                 if (s->tcp_close_timestamp)
732                   {
733                     if (now >= s->tcp_close_timestamp)
734                       {
735                         ++transitory_closed;
736                       }
737                     else
738                       {
739                         ++transitory_wait_closed;
740                       }
741                   }
742                 transitory++;
743               }
744             else
745               established++;
746             break;
747           case SNAT_PROTOCOL_UDP:
748           default:
749             udp_sessions++;
750             break;
751           }
752       }));
753       /* *INDENT-ON* */
754       count = pool_elts (tsm->sessions);
755     }
756
757   vlib_cli_output (vm, "total timed out sessions: %u", timed_out);
758   vlib_cli_output (vm, "total sessions: %u", count);
759   vlib_cli_output (vm, "total tcp sessions: %u", tcp_sessions);
760   vlib_cli_output (vm, "total tcp established sessions: %u", established);
761   vlib_cli_output (vm, "total tcp transitory sessions: %u", transitory);
762   vlib_cli_output (vm, "total tcp transitory (WAIT-CLOSED) sessions: %u",
763                    transitory_wait_closed);
764   vlib_cli_output (vm, "total tcp transitory (CLOSED) sessions: %u",
765                    transitory_closed);
766   vlib_cli_output (vm, "total udp sessions: %u", udp_sessions);
767   vlib_cli_output (vm, "total icmp sessions: %u", icmp_sessions);
768   return 0;
769 }
770
771 static clib_error_t *
772 nat44_show_addresses_command_fn (vlib_main_t * vm, unformat_input_t * input,
773                                  vlib_cli_command_t * cmd)
774 {
775   snat_main_t *sm = &snat_main;
776   snat_address_t *ap;
777
778   if (sm->deterministic)
779     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
780
781   vlib_cli_output (vm, "NAT44 pool addresses:");
782   /* *INDENT-OFF* */
783   vec_foreach (ap, sm->addresses)
784     {
785       vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
786       if (ap->fib_index != ~0)
787           vlib_cli_output (vm, "  tenant VRF: %u",
788             fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
789       else
790         vlib_cli_output (vm, "  tenant VRF independent");
791     #define _(N, i, n, s) \
792       vlib_cli_output (vm, "  %d busy %s ports", ap->busy_##n##_ports, s);
793       foreach_snat_protocol
794     #undef _
795     }
796   vlib_cli_output (vm, "NAT44 twice-nat pool addresses:");
797   vec_foreach (ap, sm->twice_nat_addresses)
798     {
799       vlib_cli_output (vm, "%U", format_ip4_address, &ap->addr);
800       if (ap->fib_index != ~0)
801           vlib_cli_output (vm, "  tenant VRF: %u",
802             fib_table_get(ap->fib_index, FIB_PROTOCOL_IP4)->ft_table_id);
803       else
804         vlib_cli_output (vm, "  tenant VRF independent");
805     #define _(N, i, n, s) \
806       vlib_cli_output (vm, "  %d busy %s ports", ap->busy_##n##_ports, s);
807       foreach_snat_protocol
808     #undef _
809     }
810   /* *INDENT-ON* */
811   return 0;
812 }
813
814 static clib_error_t *
815 snat_feature_command_fn (vlib_main_t * vm,
816                          unformat_input_t * input, vlib_cli_command_t * cmd)
817 {
818   unformat_input_t _line_input, *line_input = &_line_input;
819   vnet_main_t *vnm = vnet_get_main ();
820   clib_error_t *error = 0;
821   u32 sw_if_index;
822   u32 *inside_sw_if_indices = 0;
823   u32 *outside_sw_if_indices = 0;
824   u8 is_output_feature = 0;
825   int is_del = 0;
826   int i;
827
828   sw_if_index = ~0;
829
830   /* Get a line of input. */
831   if (!unformat_user (input, unformat_line_input, line_input))
832     return 0;
833
834   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
835     {
836       if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
837                     vnm, &sw_if_index))
838         vec_add1 (inside_sw_if_indices, sw_if_index);
839       else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
840                          vnm, &sw_if_index))
841         vec_add1 (outside_sw_if_indices, sw_if_index);
842       else if (unformat (line_input, "output-feature"))
843         is_output_feature = 1;
844       else if (unformat (line_input, "del"))
845         is_del = 1;
846       else
847         {
848           error = clib_error_return (0, "unknown input '%U'",
849                                      format_unformat_error, line_input);
850           goto done;
851         }
852     }
853
854   if (vec_len (inside_sw_if_indices))
855     {
856       for (i = 0; i < vec_len (inside_sw_if_indices); i++)
857         {
858           sw_if_index = inside_sw_if_indices[i];
859           if (is_output_feature)
860             {
861               if (snat_interface_add_del_output_feature
862                   (sw_if_index, 1, is_del))
863                 {
864                   error = clib_error_return (0, "%s %U failed",
865                                              is_del ? "del" : "add",
866                                              format_vnet_sw_if_index_name,
867                                              vnm, sw_if_index);
868                   goto done;
869                 }
870             }
871           else
872             {
873               if (snat_interface_add_del (sw_if_index, 1, is_del))
874                 {
875                   error = clib_error_return (0, "%s %U failed",
876                                              is_del ? "del" : "add",
877                                              format_vnet_sw_if_index_name,
878                                              vnm, sw_if_index);
879                   goto done;
880                 }
881             }
882         }
883     }
884
885   if (vec_len (outside_sw_if_indices))
886     {
887       for (i = 0; i < vec_len (outside_sw_if_indices); i++)
888         {
889           sw_if_index = outside_sw_if_indices[i];
890           if (is_output_feature)
891             {
892               if (snat_interface_add_del_output_feature
893                   (sw_if_index, 0, is_del))
894                 {
895                   error = clib_error_return (0, "%s %U failed",
896                                              is_del ? "del" : "add",
897                                              format_vnet_sw_if_index_name,
898                                              vnm, sw_if_index);
899                   goto done;
900                 }
901             }
902           else
903             {
904               if (snat_interface_add_del (sw_if_index, 0, is_del))
905                 {
906                   error = clib_error_return (0, "%s %U failed",
907                                              is_del ? "del" : "add",
908                                              format_vnet_sw_if_index_name,
909                                              vnm, sw_if_index);
910                   goto done;
911                 }
912             }
913         }
914     }
915
916 done:
917   unformat_free (line_input);
918   vec_free (inside_sw_if_indices);
919   vec_free (outside_sw_if_indices);
920
921   return error;
922 }
923
924 static clib_error_t *
925 nat44_show_interfaces_command_fn (vlib_main_t * vm, unformat_input_t * input,
926                                   vlib_cli_command_t * cmd)
927 {
928   snat_main_t *sm = &snat_main;
929   snat_interface_t *i;
930   vnet_main_t *vnm = vnet_get_main ();
931
932   vlib_cli_output (vm, "NAT44 interfaces:");
933   /* *INDENT-OFF* */
934   pool_foreach (i, sm->interfaces,
935   ({
936     vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
937                      i->sw_if_index,
938                      (nat_interface_is_inside(i) &&
939                       nat_interface_is_outside(i)) ? "in out" :
940                      (nat_interface_is_inside(i) ? "in" : "out"));
941   }));
942
943   pool_foreach (i, sm->output_feature_interfaces,
944   ({
945     vlib_cli_output (vm, " %U output-feature %s",
946                      format_vnet_sw_if_index_name, vnm,
947                      i->sw_if_index,
948                      (nat_interface_is_inside(i) &&
949                       nat_interface_is_outside(i)) ? "in out" :
950                      (nat_interface_is_inside(i) ? "in" : "out"));
951   }));
952   /* *INDENT-ON* */
953
954   return 0;
955 }
956
957 static clib_error_t *
958 add_static_mapping_command_fn (vlib_main_t * vm,
959                                unformat_input_t * input,
960                                vlib_cli_command_t * cmd)
961 {
962   unformat_input_t _line_input, *line_input = &_line_input;
963   snat_main_t *sm = &snat_main;
964   clib_error_t *error = 0;
965   ip4_address_t l_addr, e_addr;
966   u32 l_port = 0, e_port = 0, vrf_id = ~0;
967   int is_add = 1;
968   int addr_only = 1;
969   u32 sw_if_index = ~0;
970   vnet_main_t *vnm = vnet_get_main ();
971   int rv;
972   snat_protocol_t proto = ~0;
973   u8 proto_set = 0;
974   twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
975   u8 out2in_only = 0;
976
977   if (sm->deterministic)
978     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
979
980   /* Get a line of input. */
981   if (!unformat_user (input, unformat_line_input, line_input))
982     return 0;
983
984   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
985     {
986       if (unformat (line_input, "local %U %u", unformat_ip4_address, &l_addr,
987                     &l_port))
988         addr_only = 0;
989       else
990         if (unformat (line_input, "local %U", unformat_ip4_address, &l_addr))
991         ;
992       else if (unformat (line_input, "external %U %u", unformat_ip4_address,
993                          &e_addr, &e_port))
994         addr_only = 0;
995       else if (unformat (line_input, "external %U", unformat_ip4_address,
996                          &e_addr))
997         ;
998       else if (unformat (line_input, "external %U %u",
999                          unformat_vnet_sw_interface, vnm, &sw_if_index,
1000                          &e_port))
1001         addr_only = 0;
1002
1003       else if (unformat (line_input, "external %U",
1004                          unformat_vnet_sw_interface, vnm, &sw_if_index))
1005         ;
1006       else if (unformat (line_input, "vrf %u", &vrf_id))
1007         ;
1008       else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
1009         proto_set = 1;
1010       else if (unformat (line_input, "twice-nat"))
1011         twice_nat = TWICE_NAT;
1012       else if (unformat (line_input, "self-twice-nat"))
1013         twice_nat = TWICE_NAT_SELF;
1014       else if (unformat (line_input, "out2in-only"))
1015         out2in_only = 1;
1016       else if (unformat (line_input, "del"))
1017         is_add = 0;
1018       else
1019         {
1020           error = clib_error_return (0, "unknown input: '%U'",
1021                                      format_unformat_error, line_input);
1022           goto done;
1023         }
1024     }
1025
1026   if (twice_nat && addr_only)
1027     {
1028       error = clib_error_return (0, "twice NAT only for 1:1 NAPT");
1029       goto done;
1030     }
1031
1032   if (!addr_only && !proto_set)
1033     {
1034       error = clib_error_return (0, "missing protocol");
1035       goto done;
1036     }
1037
1038   rv = snat_add_static_mapping (l_addr, e_addr, (u16) l_port, (u16) e_port,
1039                                 vrf_id, addr_only, sw_if_index, proto, is_add,
1040                                 twice_nat, out2in_only, 0, 0);
1041
1042   switch (rv)
1043     {
1044     case VNET_API_ERROR_INVALID_VALUE:
1045       error = clib_error_return (0, "External port already in use.");
1046       goto done;
1047     case VNET_API_ERROR_NO_SUCH_ENTRY:
1048       if (is_add)
1049         error = clib_error_return (0, "External address must be allocated.");
1050       else
1051         error = clib_error_return (0, "Mapping not exist.");
1052       goto done;
1053     case VNET_API_ERROR_NO_SUCH_FIB:
1054       error = clib_error_return (0, "No such VRF id.");
1055       goto done;
1056     case VNET_API_ERROR_VALUE_EXIST:
1057       error = clib_error_return (0, "Mapping already exist.");
1058       goto done;
1059     case VNET_API_ERROR_FEATURE_DISABLED:
1060       error =
1061         clib_error_return (0,
1062                            "twice-nat/out2in-only available only for endpoint-dependent mode.");
1063       goto done;
1064     default:
1065       break;
1066     }
1067
1068 done:
1069   unformat_free (line_input);
1070
1071   return error;
1072 }
1073
1074 static clib_error_t *
1075 add_identity_mapping_command_fn (vlib_main_t * vm,
1076                                  unformat_input_t * input,
1077                                  vlib_cli_command_t * cmd)
1078 {
1079   unformat_input_t _line_input, *line_input = &_line_input;
1080   snat_main_t *sm = &snat_main;
1081   clib_error_t *error = 0;
1082   ip4_address_t addr;
1083   u32 port = 0, vrf_id = ~0;
1084   int is_add = 1;
1085   int addr_only = 1;
1086   u32 sw_if_index = ~0;
1087   vnet_main_t *vnm = vnet_get_main ();
1088   int rv;
1089   snat_protocol_t proto;
1090
1091   if (sm->deterministic)
1092     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1093
1094   addr.as_u32 = 0;
1095
1096   /* Get a line of input. */
1097   if (!unformat_user (input, unformat_line_input, line_input))
1098     return 0;
1099
1100   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1101     {
1102       if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1103         ;
1104       else if (unformat (line_input, "external %U",
1105                          unformat_vnet_sw_interface, vnm, &sw_if_index))
1106         ;
1107       else if (unformat (line_input, "vrf %u", &vrf_id))
1108         ;
1109       else if (unformat (line_input, "%U %u", unformat_snat_protocol, &proto,
1110                          &port))
1111         addr_only = 0;
1112       else if (unformat (line_input, "del"))
1113         is_add = 0;
1114       else
1115         {
1116           error = clib_error_return (0, "unknown input: '%U'",
1117                                      format_unformat_error, line_input);
1118           goto done;
1119         }
1120     }
1121
1122   rv = snat_add_static_mapping (addr, addr, (u16) port, (u16) port,
1123                                 vrf_id, addr_only, sw_if_index, proto, is_add,
1124                                 0, 0, 0, 1);
1125
1126   switch (rv)
1127     {
1128     case VNET_API_ERROR_INVALID_VALUE:
1129       error = clib_error_return (0, "External port already in use.");
1130       goto done;
1131     case VNET_API_ERROR_NO_SUCH_ENTRY:
1132       if (is_add)
1133         error = clib_error_return (0, "External address must be allocated.");
1134       else
1135         error = clib_error_return (0, "Mapping not exist.");
1136       goto done;
1137     case VNET_API_ERROR_NO_SUCH_FIB:
1138       error = clib_error_return (0, "No such VRF id.");
1139       goto done;
1140     case VNET_API_ERROR_VALUE_EXIST:
1141       error = clib_error_return (0, "Mapping already exist.");
1142       goto done;
1143     default:
1144       break;
1145     }
1146
1147 done:
1148   unformat_free (line_input);
1149
1150   return error;
1151 }
1152
1153 static clib_error_t *
1154 add_lb_static_mapping_command_fn (vlib_main_t * vm,
1155                                   unformat_input_t * input,
1156                                   vlib_cli_command_t * cmd)
1157 {
1158   unformat_input_t _line_input, *line_input = &_line_input;
1159   snat_main_t *sm = &snat_main;
1160   clib_error_t *error = 0;
1161   ip4_address_t l_addr, e_addr;
1162   u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0, affinity = 0;
1163   int is_add = 1;
1164   int rv;
1165   snat_protocol_t proto;
1166   u8 proto_set = 0;
1167   nat44_lb_addr_port_t *locals = 0, local;
1168   twice_nat_type_t twice_nat = TWICE_NAT_DISABLED;
1169   u8 out2in_only = 0;
1170
1171   if (sm->deterministic)
1172     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1173
1174   /* Get a line of input. */
1175   if (!unformat_user (input, unformat_line_input, line_input))
1176     return 0;
1177
1178   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1179     {
1180       if (unformat (line_input, "local %U:%u probability %u",
1181                     unformat_ip4_address, &l_addr, &l_port, &probability))
1182         {
1183           clib_memset (&local, 0, sizeof (local));
1184           local.addr = l_addr;
1185           local.port = (u16) l_port;
1186           local.probability = (u8) probability;
1187           vec_add1 (locals, local);
1188         }
1189       else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1190                          unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1191                          &probability))
1192         {
1193           clib_memset (&local, 0, sizeof (local));
1194           local.addr = l_addr;
1195           local.port = (u16) l_port;
1196           local.probability = (u8) probability;
1197           local.vrf_id = vrf_id;
1198           vec_add1 (locals, local);
1199         }
1200       else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1201                          &e_addr, &e_port))
1202         ;
1203       else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
1204                          &proto))
1205         proto_set = 1;
1206       else if (unformat (line_input, "twice-nat"))
1207         twice_nat = TWICE_NAT;
1208       else if (unformat (line_input, "self-twice-nat"))
1209         twice_nat = TWICE_NAT_SELF;
1210       else if (unformat (line_input, "out2in-only"))
1211         out2in_only = 1;
1212       else if (unformat (line_input, "del"))
1213         is_add = 0;
1214       else if (unformat (line_input, "affinity %u", &affinity))
1215         ;
1216       else
1217         {
1218           error = clib_error_return (0, "unknown input: '%U'",
1219                                      format_unformat_error, line_input);
1220           goto done;
1221         }
1222     }
1223
1224   if (vec_len (locals) < 2)
1225     {
1226       error = clib_error_return (0, "at least two local must be set");
1227       goto done;
1228     }
1229
1230   if (!proto_set)
1231     {
1232       error = clib_error_return (0, "missing protocol");
1233       goto done;
1234     }
1235
1236   rv = nat44_add_del_lb_static_mapping (e_addr, (u16) e_port, proto, locals,
1237                                         is_add, twice_nat, out2in_only, 0,
1238                                         affinity);
1239
1240   switch (rv)
1241     {
1242     case VNET_API_ERROR_INVALID_VALUE:
1243       error = clib_error_return (0, "External port already in use.");
1244       goto done;
1245     case VNET_API_ERROR_NO_SUCH_ENTRY:
1246       if (is_add)
1247         error = clib_error_return (0, "External address must be allocated.");
1248       else
1249         error = clib_error_return (0, "Mapping not exist.");
1250       goto done;
1251     case VNET_API_ERROR_VALUE_EXIST:
1252       error = clib_error_return (0, "Mapping already exist.");
1253       goto done;
1254     case VNET_API_ERROR_FEATURE_DISABLED:
1255       error =
1256         clib_error_return (0, "Available only for endpoint-dependent mode.");
1257       goto done;
1258     default:
1259       break;
1260     }
1261
1262 done:
1263   unformat_free (line_input);
1264   vec_free (locals);
1265
1266   return error;
1267 }
1268
1269 static clib_error_t *
1270 add_lb_backend_command_fn (vlib_main_t * vm,
1271                            unformat_input_t * input, vlib_cli_command_t * cmd)
1272 {
1273   unformat_input_t _line_input, *line_input = &_line_input;
1274   snat_main_t *sm = &snat_main;
1275   clib_error_t *error = 0;
1276   ip4_address_t l_addr, e_addr;
1277   u32 l_port = 0, e_port = 0, vrf_id = 0, probability = 0;
1278   int is_add = 1;
1279   int rv;
1280   snat_protocol_t proto;
1281   u8 proto_set = 0;
1282
1283   if (sm->deterministic)
1284     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1285
1286   /* Get a line of input. */
1287   if (!unformat_user (input, unformat_line_input, line_input))
1288     return 0;
1289
1290   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1291     {
1292       if (unformat (line_input, "local %U:%u probability %u",
1293                     unformat_ip4_address, &l_addr, &l_port, &probability))
1294         ;
1295       else if (unformat (line_input, "local %U:%u vrf %u probability %u",
1296                          unformat_ip4_address, &l_addr, &l_port, &vrf_id,
1297                          &probability))
1298         ;
1299       else if (unformat (line_input, "external %U:%u", unformat_ip4_address,
1300                          &e_addr, &e_port))
1301         ;
1302       else if (unformat (line_input, "protocol %U", unformat_snat_protocol,
1303                          &proto))
1304         proto_set = 1;
1305       else if (unformat (line_input, "del"))
1306         is_add = 0;
1307       else
1308         {
1309           error = clib_error_return (0, "unknown input: '%U'",
1310                                      format_unformat_error, line_input);
1311           goto done;
1312         }
1313     }
1314
1315   if (!l_port || !e_port)
1316     {
1317       error = clib_error_return (0, "local or external must be set");
1318       goto done;
1319     }
1320
1321   if (!proto_set)
1322     {
1323       error = clib_error_return (0, "missing protocol");
1324       goto done;
1325     }
1326
1327   rv =
1328     nat44_lb_static_mapping_add_del_local (e_addr, (u16) e_port, l_addr,
1329                                            l_port, proto, vrf_id, probability,
1330                                            is_add);
1331
1332   switch (rv)
1333     {
1334     case VNET_API_ERROR_INVALID_VALUE:
1335       error = clib_error_return (0, "External is not load-balancing static "
1336                                  "mapping.");
1337       goto done;
1338     case VNET_API_ERROR_NO_SUCH_ENTRY:
1339       error = clib_error_return (0, "Mapping or back-end not exist.");
1340       goto done;
1341     case VNET_API_ERROR_VALUE_EXIST:
1342       error = clib_error_return (0, "Back-end already exist.");
1343       goto done;
1344     case VNET_API_ERROR_FEATURE_DISABLED:
1345       error =
1346         clib_error_return (0, "Available only for endpoint-dependent mode.");
1347       goto done;
1348     case VNET_API_ERROR_UNSPECIFIED:
1349       error = clib_error_return (0, "At least two back-ends must remain");
1350       goto done;
1351     default:
1352       break;
1353     }
1354
1355 done:
1356   unformat_free (line_input);
1357
1358   return error;
1359 }
1360
1361 static clib_error_t *
1362 nat44_show_static_mappings_command_fn (vlib_main_t * vm,
1363                                        unformat_input_t * input,
1364                                        vlib_cli_command_t * cmd)
1365 {
1366   snat_main_t *sm = &snat_main;
1367   snat_static_mapping_t *m;
1368   snat_static_map_resolve_t *rp;
1369
1370   if (sm->deterministic)
1371     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1372
1373   vlib_cli_output (vm, "NAT44 static mappings:");
1374   /* *INDENT-OFF* */
1375   pool_foreach (m, sm->static_mappings,
1376   ({
1377     vlib_cli_output (vm, " %U", format_snat_static_mapping, m);
1378   }));
1379   vec_foreach (rp, sm->to_resolve)
1380     vlib_cli_output (vm, " %U", format_snat_static_map_to_resolve, rp);
1381   /* *INDENT-ON* */
1382
1383   return 0;
1384 }
1385
1386 static clib_error_t *
1387 snat_add_interface_address_command_fn (vlib_main_t * vm,
1388                                        unformat_input_t * input,
1389                                        vlib_cli_command_t * cmd)
1390 {
1391   snat_main_t *sm = &snat_main;
1392   unformat_input_t _line_input, *line_input = &_line_input;
1393   u32 sw_if_index;
1394   int rv;
1395   int is_del = 0;
1396   clib_error_t *error = 0;
1397   u8 twice_nat = 0;
1398
1399   if (sm->deterministic)
1400     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1401
1402   /* Get a line of input. */
1403   if (!unformat_user (input, unformat_line_input, line_input))
1404     return 0;
1405
1406   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1407     {
1408       if (unformat (line_input, "%U", unformat_vnet_sw_interface,
1409                     sm->vnet_main, &sw_if_index))
1410         ;
1411       else if (unformat (line_input, "twice-nat"))
1412         twice_nat = 1;
1413       else if (unformat (line_input, "del"))
1414         is_del = 1;
1415       else
1416         {
1417           error = clib_error_return (0, "unknown input '%U'",
1418                                      format_unformat_error, line_input);
1419           goto done;
1420         }
1421     }
1422
1423   rv = snat_add_interface_address (sm, sw_if_index, is_del, twice_nat);
1424
1425   switch (rv)
1426     {
1427     case 0:
1428       break;
1429
1430     default:
1431       error = clib_error_return (0, "snat_add_interface_address returned %d",
1432                                  rv);
1433       goto done;
1434     }
1435
1436 done:
1437   unformat_free (line_input);
1438
1439   return error;
1440 }
1441
1442 static clib_error_t *
1443 nat44_show_interface_address_command_fn (vlib_main_t * vm,
1444                                          unformat_input_t * input,
1445                                          vlib_cli_command_t * cmd)
1446 {
1447   snat_main_t *sm = &snat_main;
1448   vnet_main_t *vnm = vnet_get_main ();
1449   u32 *sw_if_index;
1450
1451   if (sm->deterministic)
1452     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1453
1454   /* *INDENT-OFF* */
1455   vlib_cli_output (vm, "NAT44 pool address interfaces:");
1456   vec_foreach (sw_if_index, sm->auto_add_sw_if_indices)
1457     {
1458       vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1459                        *sw_if_index);
1460     }
1461   vlib_cli_output (vm, "NAT44 twice-nat pool address interfaces:");
1462   vec_foreach (sw_if_index, sm->auto_add_sw_if_indices_twice_nat)
1463     {
1464       vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm,
1465                        *sw_if_index);
1466     }
1467   /* *INDENT-ON* */
1468
1469   return 0;
1470 }
1471
1472 static clib_error_t *
1473 nat44_show_sessions_command_fn (vlib_main_t * vm, unformat_input_t * input,
1474                                 vlib_cli_command_t * cmd)
1475 {
1476   unformat_input_t _line_input, *line_input = &_line_input;
1477   clib_error_t *error = 0;
1478   snat_main_t *sm = &snat_main;
1479   snat_main_per_thread_data_t *tsm;
1480
1481   int detail = 0, metrics = 0;
1482   snat_user_t *u;
1483   int i = 0;
1484
1485   if (sm->deterministic)
1486     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1487
1488   if (!unformat_user (input, unformat_line_input, line_input))
1489     goto print;
1490
1491   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1492     {
1493       if (unformat (line_input, "detail"))
1494         detail = 1;
1495       else if (unformat (line_input, "metrics"))
1496         metrics = 1;
1497       else
1498         {
1499           error = clib_error_return (0, "unknown input '%U'",
1500                                      format_unformat_error, line_input);
1501           break;
1502         }
1503     }
1504   unformat_free (line_input);
1505
1506 print:
1507   vlib_cli_output (vm, "NAT44 sessions:");
1508   /* *INDENT-OFF* */
1509   vec_foreach_index (i, sm->per_thread_data)
1510     {
1511       tsm = vec_elt_at_index (sm->per_thread_data, i);
1512
1513       vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n",
1514                        i, vlib_worker_threads[i].name,
1515                        pool_elts (tsm->sessions));
1516       if (metrics)
1517         {
1518           u64 now = vlib_time_now (sm->vlib_main);
1519           pool_foreach (u, tsm->users,
1520           ({
1521             vlib_cli_output (vm, "  %U", format_snat_user_v2, tsm, u, now);
1522           }));
1523         }
1524       else
1525         {
1526           pool_foreach (u, tsm->users,
1527           ({
1528             vlib_cli_output (vm, "  %U", format_snat_user, tsm, u, detail);
1529           }));
1530         }
1531     }
1532   /* *INDENT-ON* */
1533   return error;
1534 }
1535
1536 static clib_error_t *
1537 nat44_del_user_command_fn (vlib_main_t * vm,
1538                            unformat_input_t * input, vlib_cli_command_t * cmd)
1539 {
1540   snat_main_t *sm = &snat_main;
1541   unformat_input_t _line_input, *line_input = &_line_input;
1542   clib_error_t *error = 0;
1543   ip4_address_t addr;
1544   u32 fib_index = 0;
1545   int rv;
1546
1547   if (sm->deterministic)
1548     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1549
1550   /* Get a line of input. */
1551   if (!unformat_user (input, unformat_line_input, line_input))
1552     return 0;
1553
1554   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1555     {
1556       if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1557         ;
1558       else if (unformat (line_input, "fib %u", &fib_index))
1559         ;
1560       else
1561         {
1562           error = clib_error_return (0, "unknown input '%U'",
1563                                      format_unformat_error, line_input);
1564           goto done;
1565         }
1566     }
1567
1568   rv = nat44_user_del (&addr, fib_index);
1569
1570   if (!rv)
1571     {
1572       error = clib_error_return (0, "nat44_user_del returned %d", rv);
1573     }
1574
1575 done:
1576   unformat_free (line_input);
1577
1578   return error;
1579 }
1580
1581 static clib_error_t *
1582 nat44_del_session_command_fn (vlib_main_t * vm,
1583                               unformat_input_t * input,
1584                               vlib_cli_command_t * cmd)
1585 {
1586   snat_main_t *sm = &snat_main;
1587   unformat_input_t _line_input, *line_input = &_line_input;
1588   int is_in = 0, is_ed = 0;
1589   clib_error_t *error = 0;
1590   ip4_address_t addr, eh_addr;
1591   u32 port = 0, eh_port = 0, vrf_id = sm->outside_vrf_id;
1592   snat_protocol_t proto;
1593   int rv;
1594
1595   if (sm->deterministic)
1596     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1597
1598   /* Get a line of input. */
1599   if (!unformat_user (input, unformat_line_input, line_input))
1600     return 0;
1601
1602   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1603     {
1604       if (unformat
1605           (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1606            unformat_snat_protocol, &proto))
1607         ;
1608       else if (unformat (line_input, "in"))
1609         {
1610           is_in = 1;
1611           vrf_id = sm->inside_vrf_id;
1612         }
1613       else if (unformat (line_input, "out"))
1614         {
1615           is_in = 0;
1616           vrf_id = sm->outside_vrf_id;
1617         }
1618       else if (unformat (line_input, "vrf %u", &vrf_id))
1619         ;
1620       else
1621         if (unformat
1622             (line_input, "external-host %U:%u", unformat_ip4_address,
1623              &eh_addr, &eh_port))
1624         is_ed = 1;
1625       else
1626         {
1627           error = clib_error_return (0, "unknown input '%U'",
1628                                      format_unformat_error, line_input);
1629           goto done;
1630         }
1631     }
1632
1633   if (is_ed)
1634     rv =
1635       nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port,
1636                             snat_proto_to_ip_proto (proto), vrf_id, is_in);
1637   else
1638     rv = nat44_del_session (sm, &addr, port, proto, vrf_id, is_in);
1639
1640   switch (rv)
1641     {
1642     case 0:
1643       break;
1644
1645     default:
1646       error = clib_error_return (0, "nat44_del_session returned %d", rv);
1647       goto done;
1648     }
1649
1650 done:
1651   unformat_free (line_input);
1652
1653   return error;
1654 }
1655
1656 static clib_error_t *
1657 snat_forwarding_set_command_fn (vlib_main_t * vm,
1658                                 unformat_input_t * input,
1659                                 vlib_cli_command_t * cmd)
1660 {
1661   snat_main_t *sm = &snat_main;
1662   unformat_input_t _line_input, *line_input = &_line_input;
1663   u8 forwarding_enable;
1664   u8 forwarding_enable_set = 0;
1665   clib_error_t *error = 0;
1666
1667   if (sm->deterministic)
1668     return clib_error_return (0, UNSUPPORTED_IN_DET_MODE_STR);
1669
1670   /* Get a line of input. */
1671   if (!unformat_user (input, unformat_line_input, line_input))
1672     return clib_error_return (0, "'enable' or 'disable' expected");
1673
1674   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1675     {
1676       if (!forwarding_enable_set && unformat (line_input, "enable"))
1677         {
1678           forwarding_enable = 1;
1679           forwarding_enable_set = 1;
1680         }
1681       else if (!forwarding_enable_set && unformat (line_input, "disable"))
1682         {
1683           forwarding_enable = 0;
1684           forwarding_enable_set = 1;
1685         }
1686       else
1687         {
1688           error = clib_error_return (0, "unknown input '%U'",
1689                                      format_unformat_error, line_input);
1690           goto done;
1691         }
1692     }
1693
1694   if (!forwarding_enable_set)
1695     {
1696       error = clib_error_return (0, "'enable' or 'disable' expected");
1697       goto done;
1698     }
1699
1700   sm->forwarding_enabled = forwarding_enable;
1701
1702 done:
1703   unformat_free (line_input);
1704
1705   return error;
1706 }
1707
1708 static clib_error_t *
1709 snat_det_map_command_fn (vlib_main_t * vm,
1710                          unformat_input_t * input, vlib_cli_command_t * cmd)
1711 {
1712   snat_main_t *sm = &snat_main;
1713   unformat_input_t _line_input, *line_input = &_line_input;
1714   ip4_address_t in_addr, out_addr;
1715   u32 in_plen, out_plen;
1716   int is_add = 1, rv;
1717   clib_error_t *error = 0;
1718
1719   if (!sm->deterministic)
1720     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1721
1722   /* Get a line of input. */
1723   if (!unformat_user (input, unformat_line_input, line_input))
1724     return 0;
1725
1726   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1727     {
1728       if (unformat
1729           (line_input, "in %U/%u", unformat_ip4_address, &in_addr, &in_plen))
1730         ;
1731       else
1732         if (unformat
1733             (line_input, "out %U/%u", unformat_ip4_address, &out_addr,
1734              &out_plen))
1735         ;
1736       else if (unformat (line_input, "del"))
1737         is_add = 0;
1738       else
1739         {
1740           error = clib_error_return (0, "unknown input '%U'",
1741                                      format_unformat_error, line_input);
1742           goto done;
1743         }
1744     }
1745
1746   rv = snat_det_add_map (sm, &in_addr, (u8) in_plen, &out_addr, (u8) out_plen,
1747                          is_add);
1748
1749   if (rv)
1750     {
1751       error = clib_error_return (0, "snat_det_add_map return %d", rv);
1752       goto done;
1753     }
1754
1755 done:
1756   unformat_free (line_input);
1757
1758   return error;
1759 }
1760
1761 static clib_error_t *
1762 nat44_det_show_mappings_command_fn (vlib_main_t * vm,
1763                                     unformat_input_t * input,
1764                                     vlib_cli_command_t * cmd)
1765 {
1766   snat_main_t *sm = &snat_main;
1767   snat_det_map_t *dm;
1768
1769   if (!sm->deterministic)
1770     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1771
1772   vlib_cli_output (vm, "NAT44 deterministic mappings:");
1773   /* *INDENT-OFF* */
1774   pool_foreach (dm, sm->det_maps,
1775   ({
1776     vlib_cli_output (vm, " in %U/%d out %U/%d\n",
1777                      format_ip4_address, &dm->in_addr, dm->in_plen,
1778                      format_ip4_address, &dm->out_addr, dm->out_plen);
1779     vlib_cli_output (vm, "  outside address sharing ratio: %d\n",
1780                      dm->sharing_ratio);
1781     vlib_cli_output (vm, "  number of ports per inside host: %d\n",
1782                      dm->ports_per_host);
1783     vlib_cli_output (vm, "  sessions number: %d\n", dm->ses_num);
1784   }));
1785   /* *INDENT-ON* */
1786
1787   return 0;
1788 }
1789
1790 static clib_error_t *
1791 snat_det_forward_command_fn (vlib_main_t * vm,
1792                              unformat_input_t * input,
1793                              vlib_cli_command_t * cmd)
1794 {
1795   snat_main_t *sm = &snat_main;
1796   unformat_input_t _line_input, *line_input = &_line_input;
1797   ip4_address_t in_addr, out_addr;
1798   u16 lo_port;
1799   snat_det_map_t *dm;
1800   clib_error_t *error = 0;
1801
1802   if (!sm->deterministic)
1803     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1804
1805   /* Get a line of input. */
1806   if (!unformat_user (input, unformat_line_input, line_input))
1807     return 0;
1808
1809   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1810     {
1811       if (unformat (line_input, "%U", unformat_ip4_address, &in_addr))
1812         ;
1813       else
1814         {
1815           error = clib_error_return (0, "unknown input '%U'",
1816                                      format_unformat_error, line_input);
1817           goto done;
1818         }
1819     }
1820
1821   dm = snat_det_map_by_user (sm, &in_addr);
1822   if (!dm)
1823     vlib_cli_output (vm, "no match");
1824   else
1825     {
1826       snat_det_forward (dm, &in_addr, &out_addr, &lo_port);
1827       vlib_cli_output (vm, "%U:<%d-%d>", format_ip4_address, &out_addr,
1828                        lo_port, lo_port + dm->ports_per_host - 1);
1829     }
1830
1831 done:
1832   unformat_free (line_input);
1833
1834   return error;
1835 }
1836
1837 static clib_error_t *
1838 snat_det_reverse_command_fn (vlib_main_t * vm,
1839                              unformat_input_t * input,
1840                              vlib_cli_command_t * cmd)
1841 {
1842   snat_main_t *sm = &snat_main;
1843   unformat_input_t _line_input, *line_input = &_line_input;
1844   ip4_address_t in_addr, out_addr;
1845   u32 out_port;
1846   snat_det_map_t *dm;
1847   clib_error_t *error = 0;
1848
1849   if (!sm->deterministic)
1850     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1851
1852   /* Get a line of input. */
1853   if (!unformat_user (input, unformat_line_input, line_input))
1854     return 0;
1855
1856   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1857     {
1858       if (unformat
1859           (line_input, "%U:%d", unformat_ip4_address, &out_addr, &out_port))
1860         ;
1861       else
1862         {
1863           error = clib_error_return (0, "unknown input '%U'",
1864                                      format_unformat_error, line_input);
1865           goto done;
1866         }
1867     }
1868
1869   if (out_port < 1024 || out_port > 65535)
1870     {
1871       error = clib_error_return (0, "wrong port, must be <1024-65535>");
1872       goto done;
1873     }
1874
1875   dm = snat_det_map_by_out (sm, &out_addr);
1876   if (!dm)
1877     vlib_cli_output (vm, "no match");
1878   else
1879     {
1880       snat_det_reverse (dm, &out_addr, (u16) out_port, &in_addr);
1881       vlib_cli_output (vm, "%U", format_ip4_address, &in_addr);
1882     }
1883
1884 done:
1885   unformat_free (line_input);
1886
1887   return error;
1888 }
1889
1890 static clib_error_t *
1891 set_timeout_command_fn (vlib_main_t * vm,
1892                         unformat_input_t * input, vlib_cli_command_t * cmd)
1893 {
1894   snat_main_t *sm = &snat_main;
1895   unformat_input_t _line_input, *line_input = &_line_input;
1896   clib_error_t *error = 0;
1897
1898   /* Get a line of input. */
1899   if (!unformat_user (input, unformat_line_input, line_input))
1900     return 0;
1901
1902   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1903     {
1904       if (unformat (line_input, "udp %u", &sm->udp_timeout))
1905         {
1906           if (nat64_set_udp_timeout (sm->udp_timeout))
1907             {
1908               error = clib_error_return (0, "Invalid UDP timeout value");
1909               goto done;
1910             }
1911         }
1912       else if (unformat (line_input, "tcp-established %u",
1913                          &sm->tcp_established_timeout))
1914         {
1915           if (nat64_set_tcp_timeouts
1916               (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1917             {
1918               error =
1919                 clib_error_return (0,
1920                                    "Invalid TCP established timeouts value");
1921               goto done;
1922             }
1923         }
1924       else if (unformat (line_input, "tcp-transitory %u",
1925                          &sm->tcp_transitory_timeout))
1926         {
1927           if (nat64_set_tcp_timeouts
1928               (sm->tcp_transitory_timeout, sm->tcp_established_timeout))
1929             {
1930               error =
1931                 clib_error_return (0,
1932                                    "Invalid TCP transitory timeouts value");
1933               goto done;
1934             }
1935         }
1936       else if (unformat (line_input, "icmp %u", &sm->icmp_timeout))
1937         {
1938           if (nat64_set_icmp_timeout (sm->icmp_timeout))
1939             {
1940               error = clib_error_return (0, "Invalid ICMP timeout value");
1941               goto done;
1942             }
1943         }
1944       else if (unformat (line_input, "reset"))
1945         {
1946           sm->udp_timeout = SNAT_UDP_TIMEOUT;
1947           sm->tcp_established_timeout = SNAT_TCP_ESTABLISHED_TIMEOUT;
1948           sm->tcp_transitory_timeout = SNAT_TCP_TRANSITORY_TIMEOUT;
1949           sm->icmp_timeout = SNAT_ICMP_TIMEOUT;
1950           nat64_set_udp_timeout (0);
1951           nat64_set_icmp_timeout (0);
1952           nat64_set_tcp_timeouts (0, 0);
1953         }
1954       else
1955         {
1956           error = clib_error_return (0, "unknown input '%U'",
1957                                      format_unformat_error, line_input);
1958           goto done;
1959         }
1960     }
1961 done:
1962   unformat_free (line_input);
1963   return error;
1964 }
1965
1966 static clib_error_t *
1967 nat_show_timeouts_command_fn (vlib_main_t * vm,
1968                               unformat_input_t * input,
1969                               vlib_cli_command_t * cmd)
1970 {
1971   snat_main_t *sm = &snat_main;
1972
1973   vlib_cli_output (vm, "udp timeout: %dsec", sm->udp_timeout);
1974   vlib_cli_output (vm, "tcp-established timeout: %dsec",
1975                    sm->tcp_established_timeout);
1976   vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1977                    sm->tcp_transitory_timeout);
1978   vlib_cli_output (vm, "icmp timeout: %dsec", sm->icmp_timeout);
1979
1980   return 0;
1981 }
1982
1983 static clib_error_t *
1984 nat44_det_show_sessions_command_fn (vlib_main_t * vm,
1985                                     unformat_input_t * input,
1986                                     vlib_cli_command_t * cmd)
1987 {
1988   snat_main_t *sm = &snat_main;
1989   snat_det_map_t *dm;
1990   snat_det_session_t *ses;
1991   int i;
1992
1993   if (!sm->deterministic)
1994     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
1995
1996   vlib_cli_output (vm, "NAT44 deterministic sessions:");
1997   /* *INDENT-OFF* */
1998   pool_foreach (dm, sm->det_maps,
1999   ({
2000     vec_foreach_index (i, dm->sessions)
2001       {
2002         ses = vec_elt_at_index (dm->sessions, i);
2003         if (ses->in_port)
2004           vlib_cli_output (vm, "  %U", format_det_map_ses, dm, ses, &i);
2005       }
2006   }));
2007   /* *INDENT-ON* */
2008   return 0;
2009 }
2010
2011 static clib_error_t *
2012 snat_det_close_session_out_fn (vlib_main_t * vm,
2013                                unformat_input_t * input,
2014                                vlib_cli_command_t * cmd)
2015 {
2016   snat_main_t *sm = &snat_main;
2017   unformat_input_t _line_input, *line_input = &_line_input;
2018   ip4_address_t out_addr, ext_addr, in_addr;
2019   u32 out_port, ext_port;
2020   snat_det_map_t *dm;
2021   snat_det_session_t *ses;
2022   snat_det_out_key_t key;
2023   clib_error_t *error = 0;
2024
2025   if (!sm->deterministic)
2026     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2027
2028   /* Get a line of input. */
2029   if (!unformat_user (input, unformat_line_input, line_input))
2030     return 0;
2031
2032   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2033     {
2034       if (unformat (line_input, "%U:%d %U:%d",
2035                     unformat_ip4_address, &out_addr, &out_port,
2036                     unformat_ip4_address, &ext_addr, &ext_port))
2037         ;
2038       else
2039         {
2040           error = clib_error_return (0, "unknown input '%U'",
2041                                      format_unformat_error, line_input);
2042           goto done;
2043         }
2044     }
2045
2046   unformat_free (line_input);
2047
2048   dm = snat_det_map_by_out (sm, &out_addr);
2049   if (!dm)
2050     vlib_cli_output (vm, "no match");
2051   else
2052     {
2053       snat_det_reverse (dm, &ext_addr, (u16) out_port, &in_addr);
2054       key.ext_host_addr = out_addr;
2055       key.ext_host_port = ntohs ((u16) ext_port);
2056       key.out_port = ntohs ((u16) out_port);
2057       ses = snat_det_get_ses_by_out (dm, &out_addr, key.as_u64);
2058       if (!ses)
2059         vlib_cli_output (vm, "no match");
2060       else
2061         snat_det_ses_close (dm, ses);
2062     }
2063
2064 done:
2065   unformat_free (line_input);
2066
2067   return error;
2068 }
2069
2070 static clib_error_t *
2071 snat_det_close_session_in_fn (vlib_main_t * vm,
2072                               unformat_input_t * input,
2073                               vlib_cli_command_t * cmd)
2074 {
2075   snat_main_t *sm = &snat_main;
2076   unformat_input_t _line_input, *line_input = &_line_input;
2077   ip4_address_t in_addr, ext_addr;
2078   u32 in_port, ext_port;
2079   snat_det_map_t *dm;
2080   snat_det_session_t *ses;
2081   snat_det_out_key_t key;
2082   clib_error_t *error = 0;
2083
2084   if (!sm->deterministic)
2085     return clib_error_return (0, SUPPORTED_ONLY_IN_DET_MODE_STR);
2086
2087   /* Get a line of input. */
2088   if (!unformat_user (input, unformat_line_input, line_input))
2089     return 0;
2090
2091   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2092     {
2093       if (unformat (line_input, "%U:%d %U:%d",
2094                     unformat_ip4_address, &in_addr, &in_port,
2095                     unformat_ip4_address, &ext_addr, &ext_port))
2096         ;
2097       else
2098         {
2099           error = clib_error_return (0, "unknown input '%U'",
2100                                      format_unformat_error, line_input);
2101           goto done;
2102         }
2103     }
2104
2105   unformat_free (line_input);
2106
2107   dm = snat_det_map_by_user (sm, &in_addr);
2108   if (!dm)
2109     vlib_cli_output (vm, "no match");
2110   else
2111     {
2112       key.ext_host_addr = ext_addr;
2113       key.ext_host_port = ntohs ((u16) ext_port);
2114       ses =
2115         snat_det_find_ses_by_in (dm, &in_addr, ntohs ((u16) in_port), key);
2116       if (!ses)
2117         vlib_cli_output (vm, "no match");
2118       else
2119         snat_det_ses_close (dm, ses);
2120     }
2121
2122 done:
2123   unformat_free (line_input);
2124
2125   return error;
2126 }
2127 /* *INDENT-OFF* */
2128
2129 /*?
2130  * @cliexpar
2131  * @cliexstart{set snat workers}
2132  * Set NAT workers if 2 or more workers available, use:
2133  *  vpp# set snat workers 0-2,5
2134  * @cliexend
2135 ?*/
2136 VLIB_CLI_COMMAND (set_workers_command, static) = {
2137   .path = "set nat workers",
2138   .function = set_workers_command_fn,
2139   .short_help = "set nat workers <workers-list>",
2140 };
2141
2142 /*?
2143  * @cliexpar
2144  * @cliexstart{show nat workers}
2145  * Show NAT workers.
2146  *  vpp# show nat workers:
2147  *  2 workers
2148  *    vpp_wk_0
2149  *    vpp_wk_1
2150  * @cliexend
2151 ?*/
2152 VLIB_CLI_COMMAND (nat_show_workers_command, static) = {
2153   .path = "show nat workers",
2154   .short_help = "show nat workers",
2155   .function = nat_show_workers_commnad_fn,
2156 };
2157
2158 /*?
2159  * @cliexpar
2160  * @cliexstart{set nat timeout}
2161  * Set values of timeouts for NAT sessions (in seconds), use:
2162  *  vpp# set nat timeout udp 120 tcp-established 7500 tcp-transitory 250 icmp 90
2163  * To reset default values use:
2164  *  vpp# set nat44 deterministic timeout reset
2165  * @cliexend
2166 ?*/
2167 VLIB_CLI_COMMAND (set_timeout_command, static) = {
2168   .path = "set nat timeout",
2169   .function = set_timeout_command_fn,
2170   .short_help =
2171     "set nat timeout [udp <sec> | tcp-established <sec> "
2172     "tcp-transitory <sec> | icmp <sec> | reset]",
2173 };
2174
2175 /*?
2176  * @cliexpar
2177  * @cliexstart{show nat timeouts}
2178  * Show values of timeouts for NAT sessions.
2179  * vpp# show nat timeouts
2180  * udp timeout: 300sec
2181  * tcp-established timeout: 7440sec
2182  * tcp-transitory timeout: 240sec
2183  * icmp timeout: 60sec
2184  * @cliexend
2185 ?*/
2186 VLIB_CLI_COMMAND (nat_show_timeouts_command, static) = {
2187   .path = "show nat timeouts",
2188   .short_help = "show nat timeouts",
2189   .function = nat_show_timeouts_command_fn,
2190 };
2191
2192 /*?
2193  * @cliexpar
2194  * @cliexstart{nat set logging level}
2195  * To set NAT logging level use:
2196  * Set nat logging level
2197  * @cliexend
2198 ?*/
2199 VLIB_CLI_COMMAND (snat_set_log_level_command, static) = {
2200   .path = "nat set logging level",
2201   .function = snat_set_log_level_command_fn,
2202   .short_help = "nat set logging level <level>",
2203 };
2204
2205 /*?
2206  * @cliexpar
2207  * @cliexstart{snat ipfix logging}
2208  * To enable NAT IPFIX logging use:
2209  *  vpp# nat ipfix logging
2210  * To set IPFIX exporter use:
2211  *  vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
2212  * @cliexend
2213 ?*/
2214 VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command, static) = {
2215   .path = "nat ipfix logging",
2216   .function = snat_ipfix_logging_enable_disable_command_fn,
2217   .short_help = "nat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
2218 };
2219
2220 /*?
2221  * @cliexpar
2222  * @cliexstart{nat addr-port-assignment-alg}
2223  * Set address and port assignment algorithm
2224  * For the MAP-E CE limit port choice based on PSID use:
2225  *  vpp# nat addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len 6
2226  * For port range use:
2227  *  vpp# nat addr-port-assignment-alg port-range <start-port> - <end-port>
2228  * To set standard (default) address and port assignment algorithm use:
2229  *  vpp# nat addr-port-assignment-alg default
2230  * @cliexend
2231 ?*/
2232 VLIB_CLI_COMMAND (nat44_set_alloc_addr_and_port_alg_command, static) = {
2233     .path = "nat addr-port-assignment-alg",
2234     .short_help = "nat addr-port-assignment-alg <alg-name> [<alg-params>]",
2235     .function = nat44_set_alloc_addr_and_port_alg_command_fn,
2236 };
2237
2238 /*?
2239  * @cliexpar
2240  * @cliexstart{show nat addr-port-assignment-alg}
2241  * Show address and port assignment algorithm
2242  * @cliexend
2243 ?*/
2244 VLIB_CLI_COMMAND (nat44_show_alloc_addr_and_port_alg_command, static) = {
2245     .path = "show nat addr-port-assignment-alg",
2246     .short_help = "show nat addr-port-assignment-alg",
2247     .function = nat44_show_alloc_addr_and_port_alg_command_fn,
2248 };
2249
2250 /*?
2251  * @cliexpar
2252  * @cliexstart{nat mss-clamping}
2253  * Set TCP MSS rewriting configuration
2254  * To enable TCP MSS rewriting use:
2255  *  vpp# nat mss-clamping 1452
2256  * To disbale TCP MSS rewriting use:
2257  *  vpp# nat mss-clamping disable
2258  * @cliexend
2259 ?*/
2260 VLIB_CLI_COMMAND (nat_set_mss_clamping_command, static) = {
2261     .path = "nat mss-clamping",
2262     .short_help = "nat mss-clamping <mss-value>|disable",
2263     .function = nat_set_mss_clamping_command_fn,
2264 };
2265
2266 /*?
2267  * @cliexpar
2268  * @cliexstart{show nat mss-clamping}
2269  * Show TCP MSS rewriting configuration
2270  * @cliexend
2271 ?*/
2272 VLIB_CLI_COMMAND (nat_show_mss_clamping_command, static) = {
2273     .path = "show nat mss-clamping",
2274     .short_help = "show nat mss-clamping",
2275     .function = nat_show_mss_clamping_command_fn,
2276 };
2277
2278 /*?
2279  * @cliexpar
2280  * @cliexstart{nat ha failover}
2281  * Set HA failover (remote settings)
2282  * @cliexend
2283 ?*/
2284 VLIB_CLI_COMMAND (nat_ha_failover_command, static) = {
2285     .path = "nat ha failover",
2286     .short_help = "nat ha failover <ip4-address>:<port> [refresh-interval <sec>]",
2287     .function = nat_ha_failover_command_fn,
2288 };
2289
2290 /*?
2291  * @cliexpar
2292  * @cliexstart{nat ha listener}
2293  * Set HA listener (local settings)
2294  * @cliexend
2295 ?*/
2296 VLIB_CLI_COMMAND (nat_ha_listener_command, static) = {
2297     .path = "nat ha listener",
2298     .short_help = "nat ha listener <ip4-address>:<port> [path-mtu <path-mtu>]",
2299     .function = nat_ha_listener_command_fn,
2300 };
2301
2302 /*?
2303  * @cliexpar
2304  * @cliexstart{show nat ha}
2305  * Show HA configuration/status
2306  * @cliexend
2307 ?*/
2308 VLIB_CLI_COMMAND (nat_show_ha_command, static) = {
2309     .path = "show nat ha",
2310     .short_help = "show nat ha",
2311     .function = nat_show_ha_command_fn,
2312 };
2313
2314 /*?
2315  * @cliexpar
2316  * @cliexstart{nat ha flush}
2317  * Flush the current HA data (for testing)
2318  * @cliexend
2319 ?*/
2320 VLIB_CLI_COMMAND (nat_ha_flush_command, static) = {
2321     .path = "nat ha flush",
2322     .short_help = "nat ha flush",
2323     .function = nat_ha_flush_command_fn,
2324 };
2325
2326 /*?
2327  * @cliexpar
2328  * @cliexstart{nat ha resync}
2329  * Resync HA (resend existing sessions to new failover)
2330  * @cliexend
2331 ?*/
2332 VLIB_CLI_COMMAND (nat_ha_resync_command, static) = {
2333     .path = "nat ha resync",
2334     .short_help = "nat ha resync",
2335     .function = nat_ha_resync_command_fn,
2336 };
2337
2338 /*?
2339  * @cliexpar
2340  * @cliexstart{show nat44 hash tables}
2341  * Show NAT44 hash tables
2342  * @cliexend
2343 ?*/
2344 VLIB_CLI_COMMAND (nat44_show_hash, static) = {
2345   .path = "show nat44 hash tables",
2346   .short_help = "show nat44 hash tables [detail|verbose]",
2347   .function = nat44_show_hash_commnad_fn,
2348 };
2349
2350 /*?
2351  * @cliexpar
2352  * @cliexstart{nat44 add address}
2353  * Add/delete NAT44 pool address.
2354  * To add NAT44 pool address use:
2355  *  vpp# nat44 add address 172.16.1.3
2356  *  vpp# nat44 add address 172.16.2.2 - 172.16.2.24
2357  * To add NAT44 pool address for specific tenant (identified by VRF id) use:
2358  *  vpp# nat44 add address 172.16.1.3 tenant-vrf 10
2359  * @cliexend
2360 ?*/
2361 VLIB_CLI_COMMAND (add_address_command, static) = {
2362   .path = "nat44 add address",
2363   .short_help = "nat44 add address <ip4-range-start> [- <ip4-range-end>] "
2364                 "[tenant-vrf <vrf-id>] [twice-nat] [del]",
2365   .function = add_address_command_fn,
2366 };
2367
2368 /*?
2369  * @cliexpar
2370  * @cliexstart{show nat44 summary}
2371  * Show NAT44 summary
2372  * vpp# show nat44 summary
2373  * @cliexend
2374 ?*/
2375 VLIB_CLI_COMMAND (nat44_show_summary_command, static) = {
2376   .path = "show nat44 summary",
2377   .short_help = "show nat44 summary",
2378   .function = nat44_show_summary_command_fn,
2379 };
2380
2381 /*?
2382  * @cliexpar
2383  * @cliexstart{show nat44 addresses}
2384  * Show NAT44 pool addresses.
2385  * vpp# show nat44 addresses
2386  * NAT44 pool addresses:
2387  * 172.16.2.2
2388  *   tenant VRF independent
2389  *   10 busy udp ports
2390  *   0 busy tcp ports
2391  *   0 busy icmp ports
2392  * 172.16.1.3
2393  *   tenant VRF: 10
2394  *   0 busy udp ports
2395  *   2 busy tcp ports
2396  *   0 busy icmp ports
2397  * NAT44 twice-nat pool addresses:
2398  * 10.20.30.72
2399  *   tenant VRF independent
2400  *   0 busy udp ports
2401  *   0 busy tcp ports
2402  *   0 busy icmp ports
2403  * @cliexend
2404 ?*/
2405 VLIB_CLI_COMMAND (nat44_show_addresses_command, static) = {
2406   .path = "show nat44 addresses",
2407   .short_help = "show nat44 addresses",
2408   .function = nat44_show_addresses_command_fn,
2409 };
2410
2411 /*?
2412  * @cliexpar
2413  * @cliexstart{set interface nat44}
2414  * Enable/disable NAT44 feature on the interface.
2415  * To enable NAT44 feature with local network interface use:
2416  *  vpp# set interface nat44 in GigabitEthernet0/8/0
2417  * To enable NAT44 feature with external network interface use:
2418  *  vpp# set interface nat44 out GigabitEthernet0/a/0
2419  * @cliexend
2420 ?*/
2421 VLIB_CLI_COMMAND (set_interface_snat_command, static) = {
2422   .path = "set interface nat44",
2423   .function = snat_feature_command_fn,
2424   .short_help = "set interface nat44 in <intfc> out <intfc> [output-feature] "
2425                 "[del]",
2426 };
2427
2428 /*?
2429  * @cliexpar
2430  * @cliexstart{show nat44 interfaces}
2431  * Show interfaces with NAT44 feature.
2432  * vpp# show nat44 interfaces
2433  * NAT44 interfaces:
2434  *  GigabitEthernet0/8/0 in
2435  *  GigabitEthernet0/a/0 out
2436  * @cliexend
2437 ?*/
2438 VLIB_CLI_COMMAND (nat44_show_interfaces_command, static) = {
2439   .path = "show nat44 interfaces",
2440   .short_help = "show nat44 interfaces",
2441   .function = nat44_show_interfaces_command_fn,
2442 };
2443
2444 /*?
2445  * @cliexpar
2446  * @cliexstart{nat44 add static mapping}
2447  * Static mapping allows hosts on the external network to initiate connection
2448  * to to the local network host.
2449  * To create static mapping between local host address 10.0.0.3 port 6303 and
2450  * external address 4.4.4.4 port 3606 for TCP protocol use:
2451  *  vpp# nat44 add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4 3606
2452  * If not runnig "static mapping only" NAT plugin mode use before:
2453  *  vpp# nat44 add address 4.4.4.4
2454  * To create static mapping between local and external address use:
2455  *  vpp# nat44 add static mapping local 10.0.0.3 external 4.4.4.4
2456  * @cliexend
2457 ?*/
2458 VLIB_CLI_COMMAND (add_static_mapping_command, static) = {
2459   .path = "nat44 add static mapping",
2460   .function = add_static_mapping_command_fn,
2461   .short_help =
2462     "nat44 add static mapping tcp|udp|icmp local <addr> [<port>] "
2463     "external <addr> [<port>] [vrf <table-id>] [twice-nat|self-twice-nat] "
2464     "[out2in-only] [del]",
2465 };
2466
2467 /*?
2468  * @cliexpar
2469  * @cliexstart{nat44 add identity mapping}
2470  * Identity mapping translate an IP address to itself.
2471  * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
2472  * use:
2473  *  vpp# nat44 add identity mapping 10.0.0.3 tcp 6303
2474  * To create identity mapping for address 10.0.0.3 use:
2475  *  vpp# nat44 add identity mapping 10.0.0.3
2476  * To create identity mapping for DHCP addressed interface use:
2477  *  vpp# nat44 add identity mapping external GigabitEthernet0/a/0 tcp 3606
2478  * @cliexend
2479 ?*/
2480 VLIB_CLI_COMMAND (add_identity_mapping_command, static) = {
2481   .path = "nat44 add identity mapping",
2482   .function = add_identity_mapping_command_fn,
2483   .short_help = "nat44 add identity mapping <ip4-addr>|external <interface> "
2484     "[<protocol> <port>] [vrf <table-id>] [del]",
2485 };
2486
2487 /*?
2488  * @cliexpar
2489  * @cliexstart{nat44 add load-balancing static mapping}
2490  * Service load balancing using NAT44
2491  * To add static mapping with load balancing for service with external IP
2492  * address 1.2.3.4 and TCP port 80 and mapped to 2 local servers
2493  * 10.100.10.10:8080 and 10.100.10.20:8080 with probability 80% resp. 20% use:
2494  *  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
2495  * @cliexend
2496 ?*/
2497 VLIB_CLI_COMMAND (add_lb_static_mapping_command, static) = {
2498   .path = "nat44 add load-balancing static mapping",
2499   .function = add_lb_static_mapping_command_fn,
2500   .short_help =
2501     "nat44 add load-balancing static mapping protocol tcp|udp "
2502     "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2503     "probability <n> [twice-nat|self-twice-nat] [out2in-only] "
2504     "[affinity <timeout-seconds>] [del]",
2505 };
2506
2507 /*?
2508  * @cliexpar
2509  * @cliexstart{nat44 add load-balancing static mapping}
2510  * Modify service load balancing using NAT44
2511  * To add new back-end server 10.100.10.30:8080 for service load balancing
2512  * static mapping with external IP address 1.2.3.4 and TCP port 80 use:
2513  *  vpp# nat44 add load-balancing back-end protocol tcp external 1.2.3.4:80 local 10.100.10.30:8080 probability 25
2514  * @cliexend
2515 ?*/
2516 VLIB_CLI_COMMAND (add_lb_backend_command, static) = {
2517   .path = "nat44 add load-balancing back-end",
2518   .function = add_lb_backend_command_fn,
2519   .short_help =
2520     "nat44 add load-balancing back-end protocol tcp|udp "
2521     "external <addr>:<port> local <addr>:<port> [vrf <table-id>] "
2522     "probability <n> [del]",
2523 };
2524
2525 /*?
2526  * @cliexpar
2527  * @cliexstart{show nat44 static mappings}
2528  * Show NAT44 static mappings.
2529  * vpp# show nat44 static mappings
2530  * NAT44 static mappings:
2531  *  local 10.0.0.3 external 4.4.4.4 vrf 0
2532  *  tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
2533  *  tcp vrf 0 external 1.2.3.4:80  out2in-only
2534  *   local 10.100.10.10:8080 probability 80
2535  *   local 10.100.10.20:8080 probability 20
2536  *  tcp local 10.100.3.8:8080 external 169.10.10.1:80 vrf 0 twice-nat
2537  *  tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
2538  * @cliexend
2539 ?*/
2540 VLIB_CLI_COMMAND (nat44_show_static_mappings_command, static) = {
2541   .path = "show nat44 static mappings",
2542   .short_help = "show nat44 static mappings",
2543   .function = nat44_show_static_mappings_command_fn,
2544 };
2545
2546 /*?
2547  * @cliexpar
2548  * @cliexstart{nat44 add interface address}
2549  * Use NAT44 pool address from specific interfce
2550  * To add NAT44 pool address from specific interface use:
2551  *  vpp# nat44 add interface address GigabitEthernet0/8/0
2552  * @cliexend
2553 ?*/
2554 VLIB_CLI_COMMAND (snat_add_interface_address_command, static) = {
2555     .path = "nat44 add interface address",
2556     .short_help = "nat44 add interface address <interface> [twice-nat] [del]",
2557     .function = snat_add_interface_address_command_fn,
2558 };
2559
2560 /*?
2561  * @cliexpar
2562  * @cliexstart{show nat44 interface address}
2563  * Show NAT44 pool address interfaces
2564  * vpp# show nat44 interface address
2565  * NAT44 pool address interfaces:
2566  *  GigabitEthernet0/a/0
2567  * NAT44 twice-nat pool address interfaces:
2568  *  GigabitEthernet0/8/0
2569  * @cliexend
2570 ?*/
2571 VLIB_CLI_COMMAND (nat44_show_interface_address_command, static) = {
2572   .path = "show nat44 interface address",
2573   .short_help = "show nat44 interface address",
2574   .function = nat44_show_interface_address_command_fn,
2575 };
2576
2577 /*?
2578  * @cliexpar
2579  * @cliexstart{show nat44 sessions}
2580  * Show NAT44 sessions.
2581  * @cliexend
2582 ?*/
2583 VLIB_CLI_COMMAND (nat44_show_sessions_command, static) = {
2584   .path = "show nat44 sessions",
2585   .short_help = "show nat44 sessions [detail|metrics]",
2586   .function = nat44_show_sessions_command_fn,
2587 };
2588
2589 /*?
2590  * @cliexpar
2591  * @cliexstart{nat44 del user}
2592  * To delete all NAT44 user sessions:
2593  *  vpp# nat44 del user 10.0.0.3
2594  * @cliexend
2595 ?*/
2596 VLIB_CLI_COMMAND (nat44_del_user_command, static) = {
2597     .path = "nat44 del user",
2598     .short_help = "nat44 del user <addr> [fib <index>]",
2599     .function = nat44_del_user_command_fn,
2600 };
2601
2602 /*?
2603  * @cliexpar
2604  * @cliexstart{nat44 del session}
2605  * To administratively delete NAT44 session by inside address and port use:
2606  *  vpp# nat44 del session in 10.0.0.3:6303 tcp
2607  * To administratively delete NAT44 session by outside address and port use:
2608  *  vpp# nat44 del session out 1.0.0.3:6033 udp
2609  * @cliexend
2610 ?*/
2611 VLIB_CLI_COMMAND (nat44_del_session_command, static) = {
2612     .path = "nat44 del session",
2613     .short_help = "nat44 del session in|out <addr>:<port> tcp|udp|icmp [vrf <id>] [external-host <addr>:<port>]",
2614     .function = nat44_del_session_command_fn,
2615 };
2616
2617 /*?
2618  * @cliexpar
2619  * @cliexstart{nat44 forwarding}
2620  * Enable or disable forwarding
2621  * Forward packets which don't match existing translation
2622  * or static mapping instead of dropping them.
2623  * To enable forwarding, use:
2624  *  vpp# nat44 forwarding enable
2625  * To disable forwarding, use:
2626  *  vpp# nat44 forwarding disable
2627  * @cliexend
2628 ?*/
2629 VLIB_CLI_COMMAND (snat_forwarding_set_command, static) = {
2630   .path = "nat44 forwarding",
2631   .short_help = "nat44 forwarding enable|disable",
2632   .function = snat_forwarding_set_command_fn,
2633 };
2634
2635 /*?
2636  * @cliexpar
2637  * @cliexstart{nat44 deterministic add}
2638  * Create bijective mapping of inside address to outside address and port range
2639  * pairs, with the purpose of enabling deterministic NAT to reduce logging in
2640  * CGN deployments.
2641  * To create deterministic mapping between inside network 10.0.0.0/18 and
2642  * outside network 1.1.1.0/30 use:
2643  * # vpp# nat44 deterministic add in 10.0.0.0/18 out 1.1.1.0/30
2644  * @cliexend
2645 ?*/
2646 VLIB_CLI_COMMAND (snat_det_map_command, static) = {
2647     .path = "nat44 deterministic add",
2648     .short_help = "nat44 deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
2649     .function = snat_det_map_command_fn,
2650 };
2651
2652 /*?
2653  * @cliexpar
2654  * @cliexpstart{show nat44 deterministic mappings}
2655  * Show NAT44 deterministic mappings
2656  * vpp# show nat44 deterministic mappings
2657  * NAT44 deterministic mappings:
2658  *  in 10.0.0.0/24 out 1.1.1.1/32
2659  *   outside address sharing ratio: 256
2660  *   number of ports per inside host: 252
2661  *   sessions number: 0
2662  * @cliexend
2663 ?*/
2664 VLIB_CLI_COMMAND (nat44_det_show_mappings_command, static) = {
2665     .path = "show nat44 deterministic mappings",
2666     .short_help = "show nat44 deterministic mappings",
2667     .function = nat44_det_show_mappings_command_fn,
2668 };
2669
2670 /*?
2671  * @cliexpar
2672  * @cliexstart{nat44 deterministic forward}
2673  * Return outside address and port range from inside address for deterministic
2674  * NAT.
2675  * To obtain outside address and port of inside host use:
2676  *  vpp# nat44 deterministic forward 10.0.0.2
2677  *  1.1.1.0:<1054-1068>
2678  * @cliexend
2679 ?*/
2680 VLIB_CLI_COMMAND (snat_det_forward_command, static) = {
2681     .path = "nat44 deterministic forward",
2682     .short_help = "nat44 deterministic forward <addr>",
2683     .function = snat_det_forward_command_fn,
2684 };
2685
2686 /*?
2687  * @cliexpar
2688  * @cliexstart{nat44 deterministic reverse}
2689  * Return inside address from outside address and port for deterministic NAT.
2690  * To obtain inside host address from outside address and port use:
2691  *  #vpp nat44 deterministic reverse 1.1.1.1:1276
2692  *  10.0.16.16
2693  * @cliexend
2694 ?*/
2695 VLIB_CLI_COMMAND (snat_det_reverse_command, static) = {
2696     .path = "nat44 deterministic reverse",
2697     .short_help = "nat44 deterministic reverse <addr>:<port>",
2698     .function = snat_det_reverse_command_fn,
2699 };
2700
2701 /*?
2702  * @cliexpar
2703  * @cliexstart{show nat44 deterministic sessions}
2704  * Show NAT44 deterministic sessions.
2705  * vpp# show nat44 deterministic sessions
2706  * NAT44 deterministic sessions:
2707  *   in 10.0.0.3:3005 out 1.1.1.2:1146 external host 172.16.1.2:3006 state: udp-active expire: 306
2708  *   in 10.0.0.3:3000 out 1.1.1.2:1141 external host 172.16.1.2:3001 state: udp-active expire: 306
2709  *   in 10.0.0.4:3005 out 1.1.1.2:1177 external host 172.16.1.2:3006 state: udp-active expire: 306
2710  * @cliexend
2711 ?*/
2712 VLIB_CLI_COMMAND (nat44_det_show_sessions_command, static) = {
2713   .path = "show nat44 deterministic sessions",
2714   .short_help = "show nat44 deterministic sessions",
2715   .function = nat44_det_show_sessions_command_fn,
2716 };
2717
2718 /*?
2719  * @cliexpar
2720  * @cliexstart{nat44 deterministic close session out}
2721  * Close session using outside ip address and port
2722  * and external ip address and port, use:
2723  *  vpp# nat44 deterministic close session out 1.1.1.1:1276 2.2.2.2:2387
2724  * @cliexend
2725 ?*/
2726 VLIB_CLI_COMMAND (snat_det_close_sesion_out_command, static) = {
2727   .path = "nat44 deterministic close session out",
2728   .short_help = "nat44 deterministic close session out "
2729                 "<out_addr>:<out_port> <ext_addr>:<ext_port>",
2730   .function = snat_det_close_session_out_fn,
2731 };
2732
2733 /*?
2734  * @cliexpar
2735  * @cliexstart{nat44 deterministic close session in}
2736  * Close session using inside ip address and port
2737  * and external ip address and port, use:
2738  *  vpp# nat44 deterministic close session in 3.3.3.3:3487 2.2.2.2:2387
2739  * @cliexend
2740 ?*/
2741 VLIB_CLI_COMMAND (snat_det_close_session_in_command, static) = {
2742   .path = "nat44 deterministic close session in",
2743   .short_help = "nat44 deterministic close session in "
2744                 "<in_addr>:<in_port> <ext_addr>:<ext_port>",
2745   .function = snat_det_close_session_in_fn,
2746 };
2747
2748 /* *INDENT-ON* */
2749
2750 /*
2751  * fd.io coding-style-patch-verification: ON
2752  *
2753  * Local Variables:
2754  * eval: (c-set-style "gnu")
2755  * End:
2756  */