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