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