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