FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
nat44_ei_cli.c
Go to the documentation of this file.
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>
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 {
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 
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 {
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 *
111 {
114 
116  {
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,
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 
134  {
135  s = format (s, "local %U external %U vrf %d", format_ip4_address,
137  m->vrf_id);
138  }
139  else
140  {
141  s = format (s, "%U local %U:%d external %U:%d vrf %d",
143  &m->local_addr, clib_net_to_host_u16 (m->local_port),
145  clib_net_to_host_u16 (m->external_port), m->vrf_id);
146  }
147  return s;
148 }
149 
150 u8 *
152 {
154  va_arg (*args, nat44_ei_static_map_resolve_t *);
155  vnet_main_t *vnm = vnet_get_main ();
156 
157  if (m->addr_only)
158  s =
159  format (s, "local %U external %U vrf %d", format_ip4_address, &m->l_addr,
161  else
162  s = format (s, "%U local %U:%d external %U:%d vrf %d", format_nat_protocol,
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 *
173  vlib_cli_command_t *cmd)
174 {
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))
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 *
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))
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 *
316  vlib_cli_command_t *cmd)
317 {
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  {
328  vlib_cli_output (vm, " %s", w->name);
329  }
330  }
331 
332  return 0;
333 }
334 
335 static clib_error_t *
337  vlib_cli_command_t *cmd)
338 {
339  unformat_input_t _line_input, *line_input = &_line_input;
342  clib_error_t *error = 0;
343 
344  if (!unformat_user (input, unformat_line_input, line_input))
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  }
359 
360 done:
361  unformat_free (line_input);
362 
363  return error;
364 }
365 
366 static clib_error_t *
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))
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 *
424  vlib_cli_command_t *cmd)
425 {
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);
441  {
443  vlib_cli_output (vm, "-------- thread %d %s --------\n", i,
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 *
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))
468 
469  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
470  {
471  if (unformat (line_input, "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  {
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 *
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;
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 *
526  unformat_input_t *input,
527  vlib_cli_command_t *cmd)
528 {
530 
531  vlib_cli_output (vm, "NAT address and port: %U",
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,
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 *
553  vlib_cli_command_t *cmd)
554 {
555  unformat_input_t _line_input, *line_input = &_line_input;
557  clib_error_t *error = 0;
558  u32 mss;
559 
560  if (!unformat_user (input, unformat_line_input, line_input))
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 *
585  vlib_cli_command_t *cmd)
586 {
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 *
599  vlib_cli_command_t *cmd)
600 {
601  unformat_input_t _line_input, *line_input = &_line_input;
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))
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 *
637  vlib_cli_command_t *cmd)
638 {
639  unformat_input_t _line_input, *line_input = &_line_input;
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))
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 
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 *
674  vlib_cli_command_t *cmd)
675 {
677  u16 port;
678  u32 path_mtu, session_refresh_interval, resync_ack_missed;
679  u8 in_resync;
680 
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",
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 *
713  vlib_cli_command_t *cmd)
714 {
715  nat_ha_flush (0);
716  return 0;
717 }
718 
719 static clib_error_t *
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 *
733  vlib_cli_command_t *cmd)
734 {
735  unformat_input_t _line_input, *line_input = &_line_input;
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))
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,
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))
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,
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 (nm, &this_addr, vrf_id);
794  else
795  rv = nat44_ei_del_address (nm, 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 *
828  vlib_cli_command_t *cmd)
829 {
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)
839  vm, " tenant VRF: %u",
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);
846 #undef _
847  }
848  return 0;
849 }
850 
851 static clib_error_t *
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;
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))
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  {
898  is_del))
899  {
901  0, "%s %U failed", is_del ? "del" : "add",
903  goto done;
904  }
905  }
906  else
907  {
908  if (nat44_ei_interface_add_del (sw_if_index, 1, is_del))
909  {
911  0, "%s %U failed", is_del ? "del" : "add",
913  goto done;
914  }
915  }
916  }
917  }
918 
919  if (vec_len (outside_sw_if_indices))
920  {
921  for (i = 0; i < vec_len (outside_sw_if_indices); i++)
922  {
923  sw_if_index = outside_sw_if_indices[i];
924  if (is_output_feature)
925  {
927  is_del))
928  {
930  0, "%s %U failed", is_del ? "del" : "add",
932  goto done;
933  }
934  }
935  else
936  {
937  if (nat44_ei_interface_add_del (sw_if_index, 0, is_del))
938  {
940  0, "%s %U failed", is_del ? "del" : "add",
942  goto done;
943  }
944  }
945  }
946  }
947 
948 done:
949  unformat_free (line_input);
950  vec_free (inside_sw_if_indices);
951  vec_free (outside_sw_if_indices);
952 
953  return error;
954 }
955 
956 static clib_error_t *
958  vlib_cli_command_t *cmd)
959 {
962  vnet_main_t *vnm = vnet_get_main ();
963 
964  vlib_cli_output (vm, "NAT44 interfaces:");
966  {
968  i->sw_if_index,
971  "in out" :
972  (nat44_ei_interface_is_inside (i) ? "in" : "out"));
973  }
974 
976  {
977  vlib_cli_output (vm, " %U output-feature %s",
978  format_vnet_sw_if_index_name, vnm, i->sw_if_index,
981  "in out" :
982  (nat44_ei_interface_is_inside (i) ? "in" : "out"));
983  }
984 
985  return 0;
986 }
987 
988 static clib_error_t *
990  vlib_cli_command_t *cmd)
991 {
992  unformat_input_t _line_input, *line_input = &_line_input;
993  clib_error_t *error = 0;
994  ip4_address_t l_addr, e_addr;
995  u32 l_port = 0, e_port = 0, vrf_id = ~0;
996  int is_add = 1, addr_only = 1, rv;
997  u32 sw_if_index = ~0;
998  vnet_main_t *vnm = vnet_get_main ();
999  nat_protocol_t proto = NAT_PROTOCOL_OTHER;
1000  u8 proto_set = 0;
1001 
1002  if (!unformat_user (input, unformat_line_input, line_input))
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  addr_only = 0;
1010  else if (unformat (line_input, "local %U", unformat_ip4_address,
1011  &l_addr))
1012  ;
1013  else if (unformat (line_input, "external %U %u", unformat_ip4_address,
1014  &e_addr, &e_port))
1015  addr_only = 0;
1016  else if (unformat (line_input, "external %U", unformat_ip4_address,
1017  &e_addr))
1018  ;
1019  else if (unformat (line_input, "external %U %u",
1021  &e_port))
1022  addr_only = 0;
1023  else if (unformat (line_input, "external %U", unformat_vnet_sw_interface,
1024  vnm, &sw_if_index))
1025  ;
1026  else if (unformat (line_input, "vrf %u", &vrf_id))
1027  ;
1028  else if (unformat (line_input, "%U", unformat_nat_protocol, &proto))
1029  proto_set = 1;
1030  else if (unformat (line_input, "del"))
1031  is_add = 0;
1032  else
1033  {
1034  error = clib_error_return (0, "unknown input: '%U'",
1035  format_unformat_error, line_input);
1036  goto done;
1037  }
1038  }
1039 
1040  if (addr_only)
1041  {
1042  if (proto_set)
1043  {
1045  0, "address only mapping doesn't support protocol");
1046  goto done;
1047  }
1048  }
1049  else if (!proto_set)
1050  {
1051  error = clib_error_return (0, "protocol is required");
1052  goto done;
1053  }
1054 
1056  l_addr, e_addr, clib_host_to_net_u16 (l_port),
1057  clib_host_to_net_u16 (e_port), proto, sw_if_index, vrf_id, addr_only, 0, 0,
1058  is_add);
1059 
1060  switch (rv)
1061  {
1062  case VNET_API_ERROR_INVALID_VALUE:
1063  error = clib_error_return (0, "External port already in use.");
1064  goto done;
1065  case VNET_API_ERROR_NO_SUCH_ENTRY:
1066  if (is_add)
1067  error = clib_error_return (0, "External address must be allocated.");
1068  else
1069  error = clib_error_return (0, "Mapping not exist.");
1070  goto done;
1071  case VNET_API_ERROR_NO_SUCH_FIB:
1072  error = clib_error_return (0, "No such VRF id.");
1073  goto done;
1074  case VNET_API_ERROR_VALUE_EXIST:
1075  error = clib_error_return (0, "Mapping already exist.");
1076  goto done;
1077  case VNET_API_ERROR_FEATURE_DISABLED:
1078  goto done;
1079  default:
1080  break;
1081  }
1082 
1083 done:
1084  unformat_free (line_input);
1085 
1086  return error;
1087 }
1088 
1089 static clib_error_t *
1091  vlib_cli_command_t *cmd)
1092 {
1093  unformat_input_t _line_input, *line_input = &_line_input;
1094  clib_error_t *error = 0;
1095  u32 port = 0, vrf_id = ~0;
1097  int is_add = 1;
1098  int addr_only = 1;
1099  u32 sw_if_index = ~0;
1100  vnet_main_t *vnm = vnet_get_main ();
1101  int rv;
1103 
1104  addr.as_u32 = 0;
1105 
1106  if (!unformat_user (input, unformat_line_input, line_input))
1108 
1109  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1110  {
1111  if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1112  ;
1113  else if (unformat (line_input, "external %U", unformat_vnet_sw_interface,
1114  vnm, &sw_if_index))
1115  ;
1116  else if (unformat (line_input, "vrf %u", &vrf_id))
1117  ;
1118  else if (unformat (line_input, "%U %u", unformat_nat_protocol, &proto,
1119  &port))
1120  addr_only = 0;
1121  else if (unformat (line_input, "del"))
1122  is_add = 0;
1123  else
1124  {
1125  error = clib_error_return (0, "unknown input: '%U'",
1126  format_unformat_error, line_input);
1127  goto done;
1128  }
1129  }
1130 
1132  addr, addr, clib_host_to_net_u16 (port), clib_host_to_net_u16 (port),
1133  proto, sw_if_index, vrf_id, addr_only, 1, 0, is_add);
1134 
1135  switch (rv)
1136  {
1137  case VNET_API_ERROR_INVALID_VALUE:
1138  error = clib_error_return (0, "External port already in use.");
1139  goto done;
1140  case VNET_API_ERROR_NO_SUCH_ENTRY:
1141  if (is_add)
1142  error = clib_error_return (0, "External address must be allocated.");
1143  else
1144  error = clib_error_return (0, "Mapping not exist.");
1145  goto done;
1146  case VNET_API_ERROR_NO_SUCH_FIB:
1147  error = clib_error_return (0, "No such VRF id.");
1148  goto done;
1149  case VNET_API_ERROR_VALUE_EXIST:
1150  error = clib_error_return (0, "Mapping already exist.");
1151  goto done;
1152  default:
1153  break;
1154  }
1155 
1156 done:
1157  unformat_free (line_input);
1158 
1159  return error;
1160 }
1161 
1162 static clib_error_t *
1164  unformat_input_t *input,
1165  vlib_cli_command_t *cmd)
1166 {
1170 
1171  vlib_cli_output (vm, "NAT44 static mappings:");
1173  {
1175  }
1176  vec_foreach (rp, nm->to_resolve)
1178 
1179  return 0;
1180 }
1181 
1182 static clib_error_t *
1184  unformat_input_t *input,
1185  vlib_cli_command_t *cmd)
1186 {
1188  unformat_input_t _line_input, *line_input = &_line_input;
1189  u32 sw_if_index;
1190  int rv;
1191  int is_del = 0;
1192  clib_error_t *error = 0;
1193 
1194  if (!unformat_user (input, unformat_line_input, line_input))
1196 
1197  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1198  {
1199  if (unformat (line_input, "%U", unformat_vnet_sw_interface,
1200  nm->vnet_main, &sw_if_index))
1201  ;
1202  else if (unformat (line_input, "del"))
1203  is_del = 1;
1204  else
1205  {
1206  error = clib_error_return (0, "unknown input '%U'",
1207  format_unformat_error, line_input);
1208  goto done;
1209  }
1210  }
1211 
1213 
1214  switch (rv)
1215  {
1216  case 0:
1217  break;
1218 
1219  default:
1221  0, "nat44_ei_add_interface_address returned %d", rv);
1222  goto done;
1223  }
1224 
1225 done:
1226  unformat_free (line_input);
1227 
1228  return error;
1229 }
1230 
1231 static clib_error_t *
1233  unformat_input_t *input,
1234  vlib_cli_command_t *cmd)
1235 {
1237  vnet_main_t *vnm = vnet_get_main ();
1238  u32 *sw_if_index;
1239 
1240  vlib_cli_output (vm, "NAT44 pool address interfaces:");
1242  {
1244  *sw_if_index);
1245  }
1246  return 0;
1247 }
1248 
1249 static clib_error_t *
1251  vlib_cli_command_t *cmd)
1252 {
1253  unformat_input_t _line_input, *line_input = &_line_input;
1254  clib_error_t *error = 0;
1255 
1258 
1259  int detail = 0;
1260  int i = 0;
1261 
1262  if (!unformat_user (input, unformat_line_input, line_input))
1263  goto print;
1264 
1265  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1266  {
1267  if (unformat (line_input, "detail"))
1268  detail = 1;
1269  else
1270  {
1271  error = clib_error_return (0, "unknown input '%U'",
1272  format_unformat_error, line_input);
1273  break;
1274  }
1275  }
1276  unformat_free (line_input);
1277 
1278 print:
1279  vlib_cli_output (vm, "NAT44 sessions:");
1280 
1282  {
1284 
1285  vlib_cli_output (vm, "-------- thread %d %s: %d sessions --------\n", i,
1287 
1288  nat44_ei_user_t *u;
1289  pool_foreach (u, tnm->users)
1290  {
1291  vlib_cli_output (vm, " %U", format_nat44_ei_user, tnm, u, detail);
1292  }
1293  }
1294  return error;
1295 }
1296 
1297 static clib_error_t *
1299  vlib_cli_command_t *cmd)
1300 {
1301  unformat_input_t _line_input, *line_input = &_line_input;
1302  clib_error_t *error = 0;
1304  u32 fib_index = 0;
1305  int rv;
1306 
1307  if (!unformat_user (input, unformat_line_input, line_input))
1309 
1310  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1311  {
1312  if (unformat (line_input, "%U", unformat_ip4_address, &addr))
1313  ;
1314  else if (unformat (line_input, "fib %u", &fib_index))
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  rv = nat44_ei_user_del (&addr, fib_index);
1325 
1326  if (!rv)
1327  {
1328  error = clib_error_return (0, "nat44_ei_user_del returned %d", rv);
1329  }
1330 
1331 done:
1332  unformat_free (line_input);
1333 
1334  return error;
1335 }
1336 
1337 static clib_error_t *
1339  vlib_cli_command_t *cmd)
1340 {
1341  clib_error_t *error = 0;
1343  return error;
1344 }
1345 
1346 static clib_error_t *
1348  vlib_cli_command_t *cmd)
1349 {
1351  unformat_input_t _line_input, *line_input = &_line_input;
1352  u32 port = 0, vrf_id = nm->outside_vrf_id;
1353  clib_error_t *error = 0;
1356  int rv, is_in = 0;
1357 
1358  if (!unformat_user (input, unformat_line_input, line_input))
1360 
1361  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1362  {
1363  if (unformat (line_input, "%U:%u %U", unformat_ip4_address, &addr, &port,
1365  ;
1366  else if (unformat (line_input, "in"))
1367  {
1368  is_in = 1;
1369  vrf_id = nm->inside_vrf_id;
1370  }
1371  else if (unformat (line_input, "out"))
1372  {
1373  is_in = 0;
1375  }
1376  else if (unformat (line_input, "vrf %u", &vrf_id))
1377  ;
1378  else
1379  {
1380  error = clib_error_return (0, "unknown input '%U'",
1381  format_unformat_error, line_input);
1382  goto done;
1383  }
1384  }
1385 
1386  rv = nat44_ei_del_session (nm, &addr, clib_host_to_net_u16 (port), proto,
1387  vrf_id, is_in);
1388 
1389  switch (rv)
1390  {
1391  case 0:
1392  break;
1393 
1394  default:
1395  error = clib_error_return (0, "nat44_ei_del_session returned %d", rv);
1396  goto done;
1397  }
1398 
1399 done:
1400  unformat_free (line_input);
1401 
1402  return error;
1403 }
1404 
1405 static clib_error_t *
1407  vlib_cli_command_t *cmd)
1408 {
1410  unformat_input_t _line_input, *line_input = &_line_input;
1411  clib_error_t *error = 0;
1412 
1413  u8 enable_set = 0, enable = 0;
1414 
1415  if (!unformat_user (input, unformat_line_input, line_input))
1417 
1418  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1419  {
1420  if (!enable_set)
1421  {
1422  enable_set = 1;
1423  if (unformat (line_input, "disable"))
1424  ;
1425  else if (unformat (line_input, "enable"))
1426  enable = 1;
1427  }
1428  else
1429  {
1430  error = clib_error_return (0, "unknown input '%U'",
1431  format_unformat_error, line_input);
1432  goto done;
1433  }
1434  }
1435 
1436  if (!enable_set)
1437  error = clib_error_return (0, "expected enable | disable");
1438  else
1439  nm->forwarding_enabled = enable;
1440 
1441 done:
1442  unformat_free (line_input);
1443  return error;
1444 }
1445 
1446 static clib_error_t *
1448  vlib_cli_command_t *cmd)
1449 {
1451  unformat_input_t _line_input, *line_input = &_line_input;
1452  clib_error_t *error = 0;
1453 
1454  if (!unformat_user (input, unformat_line_input, line_input))
1456 
1457  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1458  {
1459  if (unformat (line_input, "udp %u", &nm->timeouts.udp))
1460  ;
1461  else if (unformat (line_input, "tcp-established %u",
1463  ;
1464  else if (unformat (line_input, "tcp-transitory %u",
1466  ;
1467  else if (unformat (line_input, "icmp %u", &nm->timeouts.icmp))
1468  ;
1469  else if (unformat (line_input, "reset"))
1471  else
1472  {
1473  error = clib_error_return (0, "unknown input '%U'",
1474  format_unformat_error, line_input);
1475  goto done;
1476  }
1477  }
1478 done:
1479  unformat_free (line_input);
1480  return error;
1481 }
1482 
1483 static clib_error_t *
1485  vlib_cli_command_t *cmd)
1486 {
1488 
1489  // TODO: make format timeout function
1490  vlib_cli_output (vm, "udp timeout: %dsec", nm->timeouts.udp);
1491  vlib_cli_output (vm, "tcp-established timeout: %dsec",
1493  vlib_cli_output (vm, "tcp-transitory timeout: %dsec",
1495  vlib_cli_output (vm, "icmp timeout: %dsec", nm->timeouts.icmp);
1496 
1497  return 0;
1498 }
1499 
1500 /*?
1501  * @cliexpar
1502  * @cliexstart{nat44 ei}
1503  * Enable nat44 ei plugin
1504  * To enable nat44-ei, use:
1505  * vpp# nat44 ei enable
1506  * To disable nat44-ei, use:
1507  * vpp# nat44 ei disable
1508  * To enable nat44 ei static mapping only, use:
1509  * vpp# nat44 ei enable static-mapping
1510  * To enable nat44 ei static mapping with connection tracking, use:
1511  * vpp# nat44 ei enable static-mapping connection-tracking
1512  * To enable nat44 ei out2in dpo, use:
1513  * vpp# nat44 ei enable out2in-dpo
1514  * To set inside-vrf outside-vrf, use:
1515  * vpp# nat44 ei enable inside-vrf <id> outside-vrf <id>
1516  * @cliexend
1517 ?*/
1519  .path = "nat44 ei",
1520  .short_help =
1521  "nat44 ei <enable [sessions <max-number>] [users <max-number>] "
1522  "[static-mappig-only [connection-tracking]|out2in-dpo] [inside-vrf "
1523  "<vrf-id>] [outside-vrf <vrf-id>] [user-sessions <max-number>]>|disable",
1525 };
1526 
1527 /*?
1528  * @cliexpar
1529  * @cliexstart{set snat44 ei workers}
1530  * Set NAT workers if 2 or more workers available, use:
1531  * vpp# set snat44 ei workers 0-2,5
1532  * @cliexend
1533 ?*/
1535  .path = "set nat44 ei workers",
1536  .function = set_workers_command_fn,
1537  .short_help = "set nat44 ei workers <workers-list>",
1538 };
1539 
1540 /*?
1541  * @cliexpar
1542  * @cliexstart{show nat44 ei workers}
1543  * Show NAT workers.
1544  * vpp# show nat44 ei workers:
1545  * 2 workers
1546  * vpp_wk_0
1547  * vpp_wk_1
1548  * @cliexend
1549 ?*/
1551  .path = "show nat44 ei workers",
1552  .short_help = "show nat44 ei workers",
1553  .function = nat_show_workers_commnad_fn,
1554 };
1555 
1556 /*?
1557  * @cliexpar
1558  * @cliexstart{set nat44 ei timeout}
1559  * Set values of timeouts for NAT sessions (in seconds), use:
1560  * vpp# set nat44 ei timeout udp 120 tcp-established 7500 tcp-transitory 250
1561 icmp 90
1562  * To reset default values use:
1563  * vpp# set nat44 ei timeout reset
1564  * @cliexend
1565 ?*/
1567  .path = "set nat44 ei timeout",
1568  .function = set_timeout_command_fn,
1569  .short_help = "set nat44 ei timeout [udp <sec> | tcp-established <sec> "
1570  "tcp-transitory <sec> | icmp <sec> | reset]",
1571 };
1572 
1573 /*?
1574  * @cliexpar
1575  * @cliexstart{show nat44 ei timeouts}
1576  * Show values of timeouts for NAT sessions.
1577  * vpp# show nat44 ei timeouts
1578  * udp timeout: 300sec
1579  * tcp-established timeout: 7440sec
1580  * tcp-transitory timeout: 240sec
1581  * icmp timeout: 60sec
1582  * @cliexend
1583 ?*/
1585  .path = "show nat44 ei timeouts",
1586  .short_help = "show nat44 ei timeouts",
1587  .function = nat_show_timeouts_command_fn,
1588 };
1589 
1590 /*?
1591  * @cliexpar
1592  * @cliexstart{nat44 ei set logging level}
1593  * To set NAT logging level use:
1594  * Set nat44 ei logging level
1595  * @cliexend
1596 ?*/
1598  .path = "nat44 ei set logging level",
1600  .short_help = "nat44 ei set logging level <level>",
1601 };
1602 
1603 /*?
1604  * @cliexpar
1605  * @cliexstart{snat44 ei ipfix logging}
1606  * To enable NAT IPFIX logging use:
1607  * vpp# nat44 ei ipfix logging
1608  * To set IPFIX exporter use:
1609  * vpp# set ipfix exporter collector 10.10.10.3 src 10.10.10.1
1610  * @cliexend
1611 ?*/
1613  .path = "nat44 ei ipfix logging",
1615  .short_help = "nat44 ei ipfix logging <enable [domain <domain-id>] "
1616  "[src-port <port>]>|disable",
1617 };
1618 
1619 /*?
1620  * @cliexpar
1621  * @cliexstart{nat44 ei addr-port-assignment-alg}
1622  * Set address and port assignment algorithm
1623  * For the MAP-E CE limit port choice based on PSID use:
1624  * vpp# nat44 ei addr-port-assignment-alg map-e psid 10 psid-offset 6 psid-len
1625 6
1626  * For port range use:
1627  * vpp# nat44 ei addr-port-assignment-alg port-range <start-port> - <end-port>
1628  * To set standard (default) address and port assignment algorithm use:
1629  * vpp# nat44 ei addr-port-assignment-alg default
1630  * @cliexend
1631 ?*/
1633  .path = "nat44 ei addr-port-assignment-alg",
1634  .short_help = "nat44 ei addr-port-assignment-alg <alg-name> [<alg-params>]",
1636 };
1637 
1638 /*?
1639  * @cliexpar
1640  * @cliexstart{show nat44 ei addr-port-assignment-alg}
1641  * Show address and port assignment algorithm
1642  * @cliexend
1643 ?*/
1645  .path = "show nat44 ei addr-port-assignment-alg",
1646  .short_help = "show nat44 ei addr-port-assignment-alg",
1648 };
1649 
1650 /*?
1651  * @cliexpar
1652  * @cliexstart{nat44 ei mss-clamping}
1653  * Set TCP MSS rewriting configuration
1654  * To enable TCP MSS rewriting use:
1655  * vpp# nat44 ei mss-clamping 1452
1656  * To disbale TCP MSS rewriting use:
1657  * vpp# nat44 ei mss-clamping disable
1658  * @cliexend
1659 ?*/
1661  .path = "nat44 ei mss-clamping",
1662  .short_help = "nat44 ei mss-clamping <mss-value>|disable",
1663  .function = nat_set_mss_clamping_command_fn,
1664 };
1665 
1666 /*?
1667  * @cliexpar
1668  * @cliexstart{show nat44 ei mss-clamping}
1669  * Show TCP MSS rewriting configuration
1670  * @cliexend
1671 ?*/
1673  .path = "show nat44 ei mss-clamping",
1674  .short_help = "show nat44 ei mss-clamping",
1676 };
1677 
1678 /*?
1679  * @cliexpar
1680  * @cliexstart{nat44 ei ha failover}
1681  * Set HA failover (remote settings)
1682  * @cliexend
1683 ?*/
1685  .path = "nat44 ei ha failover",
1686  .short_help =
1687  "nat44 ei ha failover <ip4-address>:<port> [refresh-interval <sec>]",
1688  .function = nat_ha_failover_command_fn,
1689 };
1690 
1691 /*?
1692  * @cliexpar
1693  * @cliexstart{nat44 ei ha listener}
1694  * Set HA listener (local settings)
1695  * @cliexend
1696 ?*/
1698  .path = "nat44 ei ha listener",
1699  .short_help =
1700  "nat44 ei ha listener <ip4-address>:<port> [path-mtu <path-mtu>]",
1701  .function = nat_ha_listener_command_fn,
1702 };
1703 
1704 /*?
1705  * @cliexpar
1706  * @cliexstart{show nat44 ei ha}
1707  * Show HA configuration/status
1708  * @cliexend
1709 ?*/
1711  .path = "show nat44 ei ha",
1712  .short_help = "show nat44 ei ha",
1713  .function = nat_show_ha_command_fn,
1714 };
1715 
1716 /*?
1717  * @cliexpar
1718  * @cliexstart{nat44 ei ha flush}
1719  * Flush the current HA data (for testing)
1720  * @cliexend
1721 ?*/
1723  .path = "nat44 ei ha flush",
1724  .short_help = "nat44 ei ha flush",
1725  .function = nat_ha_flush_command_fn,
1726 };
1727 
1728 /*?
1729  * @cliexpar
1730  * @cliexstart{nat44 ei ha resync}
1731  * Resync HA (resend existing sessions to new failover)
1732  * @cliexend
1733 ?*/
1735  .path = "nat44 ei ha resync",
1736  .short_help = "nat44 ei ha resync",
1737  .function = nat_ha_resync_command_fn,
1738 };
1739 
1740 /*?
1741  * @cliexpar
1742  * @cliexstart{show nat44 ei hash tables}
1743  * Show NAT44 hash tables
1744  * @cliexend
1745 ?*/
1747  .path = "show nat44 ei hash tables",
1748  .short_help = "show nat44 ei hash tables [detail|verbose]",
1749  .function = nat44_ei_show_hash_command_fn,
1750 };
1751 
1752 /*?
1753  * @cliexpar
1754  * @cliexstart{nat44 ei add address}
1755  * Add/delete NAT44 pool address.
1756  * To add NAT44 pool address use:
1757  * vpp# nat44 ei add address 172.16.1.3
1758  * vpp# nat44 ei add address 172.16.2.2 - 172.16.2.24
1759  * To add NAT44 pool address for specific tenant (identified by VRF id) use:
1760  * vpp# nat44 ei add address 172.16.1.3 tenant-vrf 10
1761  * @cliexend
1762 ?*/
1764  .path = "nat44 ei add address",
1765  .short_help = "nat44 ei add address <ip4-range-start> [- <ip4-range-end>] "
1766  "[tenant-vrf <vrf-id>] [del]",
1767  .function = add_address_command_fn,
1768 };
1769 
1770 /*?
1771  * @cliexpar
1772  * @cliexstart{show nat44 ei addresses}
1773  * Show NAT44 pool addresses.
1774  * vpp# show nat44 ei addresses
1775  * NAT44 pool addresses:
1776  * 172.16.2.2
1777  * tenant VRF independent
1778  * 10 busy udp ports
1779  * 0 busy tcp ports
1780  * 0 busy icmp ports
1781  * 172.16.1.3
1782  * tenant VRF: 10
1783  * 0 busy udp ports
1784  * 2 busy tcp ports
1785  * 0 busy icmp ports
1786  * @cliexend
1787 ?*/
1789  .path = "show nat44 ei addresses",
1790  .short_help = "show nat44 ei addresses",
1792 };
1793 
1794 /*?
1795  * @cliexpar
1796  * @cliexstart{set interface nat44}
1797  * Enable/disable NAT44 feature on the interface.
1798  * To enable NAT44 feature with local network interface use:
1799  * vpp# set interface nat44 ei in GigabitEthernet0/8/0
1800  * To enable NAT44 feature with external network interface use:
1801  * vpp# set interface nat44 ei out GigabitEthernet0/a/0
1802  * @cliexend
1803 ?*/
1805  .path = "set interface nat44 ei",
1806  .function = nat44_ei_feature_command_fn,
1807  .short_help =
1808  "set interface nat44 ei in <intfc> out <intfc> [output-feature] "
1809  "[del]",
1810 };
1811 
1812 /*?
1813  * @cliexpar
1814  * @cliexstart{show nat44 ei interfaces}
1815  * Show interfaces with NAT44 feature.
1816  * vpp# show nat44 ei interfaces
1817  * NAT44 interfaces:
1818  * GigabitEthernet0/8/0 in
1819  * GigabitEthernet0/a/0 out
1820  * @cliexend
1821 ?*/
1823  .path = "show nat44 ei interfaces",
1824  .short_help = "show nat44 ei interfaces",
1826 };
1827 
1828 /*?
1829  * @cliexpar
1830  * @cliexstart{nat44 ei add static mapping}
1831  * Static mapping allows hosts on the external network to initiate connection
1832  * to to the local network host.
1833  * To create static mapping between local host address 10.0.0.3 port 6303 and
1834  * external address 4.4.4.4 port 3606 for TCP protocol use:
1835  * vpp# nat44 ei add static mapping tcp local 10.0.0.3 6303 external 4.4.4.4
1836 3606
1837  * If not runnig "static mapping only" NAT plugin mode use before:
1838  * vpp# nat44 ei add address 4.4.4.4
1839  * To create address only static mapping between local and external address
1840 use:
1841  * vpp# nat44 ei add static mapping local 10.0.0.3 external 4.4.4.4
1842  * To create ICMP static mapping between local and external with ICMP echo
1843  * identifier 10 use:
1844  * vpp# nat44 ei add static mapping icmp local 10.0.0.3 10 external 4.4.4.4 10
1845  * @cliexend
1846 ?*/
1848  .path = "nat44 ei add static mapping",
1849  .function = add_static_mapping_command_fn,
1850  .short_help = "nat44 ei add static mapping tcp|udp|icmp local <addr> "
1851  "[<port|icmp-echo-id>] "
1852  "external <addr> [<port|icmp-echo-id>] [vrf <table-id>] [del]",
1853 };
1854 
1855 /*?
1856  * @cliexpar
1857  * @cliexstart{nat44 ei add identity mapping}
1858  * Identity mapping translate an IP address to itself.
1859  * To create identity mapping for address 10.0.0.3 port 6303 for TCP protocol
1860  * use:
1861  * vpp# nat44 ei add identity mapping 10.0.0.3 tcp 6303
1862  * To create identity mapping for address 10.0.0.3 use:
1863  * vpp# nat44 ei add identity mapping 10.0.0.3
1864  * To create identity mapping for DHCP addressed interface use:
1865  * vpp# nat44 ei add identity mapping external GigabitEthernet0/a/0 tcp 3606
1866  * @cliexend
1867 ?*/
1869  .path = "nat44 ei add identity mapping",
1870  .function = add_identity_mapping_command_fn,
1871  .short_help =
1872  "nat44 ei add identity mapping <ip4-addr>|external <interface> "
1873  "[<protocol> <port>] [vrf <table-id>] [del]",
1874 };
1875 
1876 /*?
1877  * @cliexpar
1878  * @cliexstart{show nat44 ei static mappings}
1879  * Show NAT44 static mappings.
1880  * vpp# show nat44 ei static mappings
1881  * NAT44 static mappings:
1882  * local 10.0.0.3 external 4.4.4.4 vrf 0
1883  * tcp local 192.168.0.4:6303 external 4.4.4.3:3606 vrf 0
1884  * tcp vrf 0 external 1.2.3.4:80
1885  * local 10.100.10.10:8080 probability 80
1886  * local 10.100.10.20:8080 probability 20
1887  * tcp local 10.0.0.10:3603 external GigabitEthernet0/a/0:6306 vrf 10
1888  * @cliexend
1889 ?*/
1891  .path = "show nat44 ei static mappings",
1892  .short_help = "show nat44 ei static mappings",
1894 };
1895 
1896 /*?
1897  * @cliexpar
1898  * @cliexstart{nat44 ei add interface address}
1899  * Use NAT44 pool address from specific interfce
1900  * To add NAT44 pool address from specific interface use:
1901  * vpp# nat44 ei add interface address GigabitEthernet0/8/0
1902  * @cliexend
1903 ?*/
1905  .path = "nat44 ei add interface address",
1906  .short_help = "nat44 ei add interface address <interface> [del]",
1908 };
1909 
1910 /*?
1911  * @cliexpar
1912  * @cliexstart{show nat44 ei interface address}
1913  * Show NAT44 pool address interfaces
1914  * vpp# show nat44 ei interface address
1915  * NAT44 pool address interfaces:
1916  * GigabitEthernet0/a/0
1917  * @cliexend
1918 ?*/
1920  .path = "show nat44 ei interface address",
1921  .short_help = "show nat44 ei interface address",
1923 };
1924 
1925 /*?
1926  * @cliexpar
1927  * @cliexstart{show nat44 ei sessions}
1928  * Show NAT44 sessions.
1929  * @cliexend
1930 ?*/
1932  .path = "show nat44 ei sessions",
1933  .short_help = "show nat44 ei sessions [detail]",
1935 };
1936 
1937 /*?
1938  * @cliexpar
1939  * @cliexstart{nat44 ei del user}
1940  * To delete all NAT44 user sessions:
1941  * vpp# nat44 ei del user 10.0.0.3
1942  * @cliexend
1943 ?*/
1945  .path = "nat44 ei del user",
1946  .short_help = "nat44 ei del user <addr> [fib <index>]",
1947  .function = nat44_ei_del_user_command_fn,
1948 };
1949 
1950 /*?
1951  * @cliexpar
1952  * @cliexstart{clear nat44 ei sessions}
1953  * To clear all NAT44 sessions
1954  * vpp# clear nat44 ei sessions
1955  * @cliexend
1956 ?*/
1958  .path = "clear nat44 ei sessions",
1959  .short_help = "clear nat44 ei sessions",
1961 };
1962 
1963 /*?
1964  * @cliexpar
1965  * @cliexstart{nat44 ei del session}
1966  * To administratively delete NAT44 session by inside address and port use:
1967  * vpp# nat44 ei del session in 10.0.0.3:6303 tcp
1968  * To administratively delete NAT44 session by outside address and port use:
1969  * vpp# nat44 ei del session out 1.0.0.3:6033 udp
1970  * @cliexend
1971 ?*/
1973  .path = "nat44 ei del session",
1974  .short_help = "nat44 ei del session in|out <addr>:<port> tcp|udp|icmp [vrf "
1975  "<id>] [external-host <addr>:<port>]",
1976  .function = nat44_ei_del_session_command_fn,
1977 };
1978 
1979 /*?
1980  * @cliexpar
1981  * @cliexstart{nat44 ei forwarding}
1982  * Enable or disable forwarding
1983  * Forward packets which don't match existing translation
1984  * or static mapping instead of dropping them.
1985  * To enable forwarding, use:
1986  * vpp# nat44 ei forwarding enable
1987  * To disable forwarding, use:
1988  * vpp# nat44 ei forwarding disable
1989  * @cliexend
1990 ?*/
1992  .path = "nat44 ei forwarding",
1993  .short_help = "nat44 ei forwarding enable|disable",
1995 };
1996 
1997 /*
1998  * fd.io coding-style-patch-verification: ON
1999  *
2000  * Local Variables:
2001  * eval: (c-set-style "gnu")
2002  * End:
2003  */
nat44_ei_main_s::timeouts
nat_timeouts_t timeouts
Definition: nat44_ei.h:405
nat44_ei_add_del_address_dpo
void nat44_ei_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Definition: nat44_ei.c:1019
set_timeout_command_fn
static clib_error_t * set_timeout_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1447
tnm
nat44_ei_main_per_thread_data_t * tnm
Definition: nat44_ei_out2in.c:712
nat44_ei_main_s::psid_offset
u8 psid_offset
Definition: nat44_ei.h:375
nat_timeouts_t::udp
u32 udp
Definition: lib.h:84
nat_timeouts_t::icmp
u32 icmp
Definition: lib.h:85
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
end_addr
vl_api_address_t end_addr
Definition: ikev2_types.api:38
nat_show_ha_command_fn
static clib_error_t * nat_show_ha_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:673
format_nat44_ei_session
u8 * format_nat44_ei_session(u8 *s, va_list *args)
Definition: nat44_ei_cli.c:28
nat44_ei_address_t
Definition: nat44_ei.h:67
app_rx_mq_elt_::next
struct app_rx_mq_elt_ * next
Definition: application.h:100
nat44_ei_show_addresses_command_fn
static clib_error_t * nat44_ei_show_addresses_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:827
nat44_ei_static_mapping_t::external_port
u16 external_port
Definition: nat44_ei.h:172
format_ip4_address
format_function_t format_ip4_address
Definition: format.h:73
add_identity_mapping_command
static vlib_cli_command_t add_identity_mapping_command
(constructor) VLIB_CLI_COMMAND (add_identity_mapping_command)
Definition: nat44_ei_cli.c:1868
nat_timeouts_t::tcp
struct nat_timeouts_t::@732 tcp
nat44_ei_main_s::user_buckets
u32 user_buckets
Definition: nat44_ei.h:320
nat_inlines.h
nat44_ei_del_user_command
static vlib_cli_command_t nat44_ei_del_user_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_del_user_command)
Definition: nat44_ei_cli.c:1944
format_nat44_ei_user
u8 * format_nat44_ei_user(u8 *s, va_list *args)
Definition: nat44_ei_cli.c:68
nat44_ei_main_s::static_mappings
nat44_ei_static_mapping_t * static_mappings
Definition: nat44_ei.h:336
nat_ha_get_listener
void nat_ha_get_listener(ip4_address_t *addr, u16 *port, u32 *path_mtu)
Get HA listener/local configuration.
Definition: nat44_ei_ha.c:530
nat44_ei_main_s::end_port
u16 end_port
Definition: nat44_ei.h:380
nat_ha_flush
void nat_ha_flush(u8 is_resync)
Flush the current HA data (for testing)
Definition: nat44_ei_ha.c:827
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
name
string name[64]
Definition: fib.api:25
unformat_nat_protocol
unformat_function_t unformat_nat_protocol
Definition: nat64.h:507
nat44_ei_main_s::interfaces
nat44_ei_interface_t * interfaces
Definition: nat44_ei.h:339
foreach_nat44_ei_addr_and_port_alloc_alg
@ foreach_nat44_ei_addr_and_port_alloc_alg
Definition: nat44_ei.h:51
nat_protocol_t
nat_protocol_t
Definition: lib.h:63
nat44_ei_interface_is_outside
#define nat44_ei_interface_is_outside(ip)
Definition: nat44_ei.h:673
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
nat44_ei_show_sessions_command
static vlib_cli_command_t nat44_ei_show_sessions_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_show_sessions_command)
Definition: nat44_ei_cli.c:1931
nat44_ei_add_interface_address_command
static vlib_cli_command_t nat44_ei_add_interface_address_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_add_interface_address_command)
Definition: nat44_ei_cli.c:1904
fib_table.h
nat44_ei_feature_command_fn
static clib_error_t * nat44_ei_feature_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:852
u16
unsigned short u16
Definition: types.h:57
nat44_ei_main_s::psid_length
u8 psid_length
Definition: nat44_ei.h:376
nat44_ei_enable_disable_command_fn
static clib_error_t * nat44_ei_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:172
nat44_ei_plugin_enable
int nat44_ei_plugin_enable(nat44_ei_config_t c)
Definition: nat44_ei.c:419
nat44_ei_show_interfaces_command
static vlib_cli_command_t nat44_ei_show_interfaces_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_show_interfaces_command)
Definition: nat44_ei_cli.c:1822
nat44_ei_interface_t
Definition: nat44_ei.h:188
nat44_ei_enable_disable_command
static vlib_cli_command_t nat44_ei_enable_disable_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_enable_disable_command)
Definition: nat44_ei_cli.c:1518
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
nat44_ei_main_per_thread_data_t::list_pool
dlist_elt_t * list_pool
Definition: nat44_ei.h:286
port
u16 port
Definition: lb_types.api:73
nat44_ei_show_interface_address_command_fn
static clib_error_t * nat44_ei_show_interface_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1232
log.h
NAT port/address allocation lib.
set_workers_command
static vlib_cli_command_t set_workers_command
(constructor) VLIB_CLI_COMMAND (set_workers_command)
Definition: nat44_ei_cli.c:1534
nat_ha_listener_command
static vlib_cli_command_t nat_ha_listener_command
(constructor) VLIB_CLI_COMMAND (nat_ha_listener_command)
Definition: nat44_ei_cli.c:1697
nat44_ei_lb_addr_port_t
Definition: nat44_ei.h:147
nat44_ei_main_s::addr_and_port_alloc_alg
nat44_ei_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
Definition: nat44_ei.h:373
nat44_ei_main_s::addresses
nat44_ei_address_t * addresses
Definition: nat44_ei.h:369
nat_timeouts_t::transitory
u32 transitory
Definition: lib.h:81
unformat_input_t
struct _unformat_input_t unformat_input_t
start_addr
vl_api_address_t start_addr
Definition: ikev2_types.api:37
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
vlib_worker_threads
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:35
format_nat44_ei_static_map_to_resolve
u8 * format_nat44_ei_static_map_to_resolve(u8 *s, va_list *args)
Definition: nat44_ei_cli.c:151
error
Definition: cJSON.c:88
nat_ha_failover_command_fn
static clib_error_t * nat_ha_failover_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:598
log_level
log_level
Definition: vpe_types.api:33
nat44_ei_main_per_thread_data_t::sessions
nat44_ei_session_t * sessions
Definition: nat44_ei.h:283
nat44_ei_main_s
Definition: nat44_ei.h:316
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
nat44_ei_main_s::inside_vrf_id
u32 inside_vrf_id
Definition: nat44_ei.h:349
nat44_ei_show_static_mappings_command_fn
static clib_error_t * nat44_ei_show_static_mappings_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1163
foreach_nat_protocol
@ foreach_nat_protocol
Definition: lib.h:66
add_identity_mapping_command_fn
static clib_error_t * add_identity_mapping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1090
nat44_ei_forwarding_set_command
static vlib_cli_command_t nat44_ei_forwarding_set_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_forwarding_set_command)
Definition: nat44_ei_cli.c:1991
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
nat44_ei_is_session_static
#define nat44_ei_is_session_static(sp)
Definition: nat44_ei.h:666
count
u8 count
Definition: dhcp.api:208
nat44_ei_main_s::to_resolve
nat44_ei_static_map_resolve_t * to_resolve
Definition: nat44_ei.h:392
nat44_ei_show_interface_address_command
static vlib_cli_command_t nat44_ei_show_interface_address_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_show_interface_address_command)
Definition: nat44_ei_cli.c:1919
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
add_address_command
static vlib_cli_command_t add_address_command
(constructor) VLIB_CLI_COMMAND (add_address_command)
Definition: nat44_ei_cli.c:1763
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
nat_timeouts_t::established
u32 established
Definition: lib.h:80
nat44_ei_main_s::enabled
u8 enabled
Definition: nat44_ei.h:470
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
nat44_ei_add_address
int nat44_ei_add_address(nat44_ei_main_t *nm, ip4_address_t *addr, u32 vrf_id)
Definition: nat44_ei.c:2575
nat44_ei_main
nat44_ei_main_t nat44_ei_main
Definition: nat44_ei.c:40
nat44_ei_main_s::static_mapping_only
u8 static_mapping_only
Definition: nat44_ei.h:324
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
fib_table_t_::ft_table_id
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:92
nat_show_ha_command
static vlib_cli_command_t nat_show_ha_command
(constructor) VLIB_CLI_COMMAND (nat_show_ha_command)
Definition: nat44_ei_cli.c:1710
format_nat44_ei_static_mapping
u8 * format_nat44_ei_static_mapping(u8 *s, va_list *args)
Definition: nat44_ei_cli.c:110
nat44_ei_show_interfaces_command_fn
static clib_error_t * nat44_ei_show_interfaces_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:957
nat44_ei_set_log_level_command
static vlib_cli_command_t nat44_ei_set_log_level_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_set_log_level_command)
Definition: nat44_ei_cli.c:1597
nat44_ei_static_map_resolve_t::proto
nat_protocol_t proto
Definition: nat44_ei.h:139
nat44_ei_show_sessions_command_fn
static clib_error_t * nat44_ei_show_sessions_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1250
nat_show_mss_clamping_command
static vlib_cli_command_t nat_show_mss_clamping_command
(constructor) VLIB_CLI_COMMAND (nat_show_mss_clamping_command)
Definition: nat44_ei_cli.c:1672
nat44_ei_del_session_command_fn
static clib_error_t * nat44_ei_del_session_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1347
nat44_ei_user_del
int nat44_ei_user_del(ip4_address_t *addr, u32 fib_index)
Delete specific NAT44 EI user and his sessions.
Definition: nat44_ei.c:1314
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
set_workers_command_fn
static clib_error_t * set_workers_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:262
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
nat44_ei_forwarding_set_command_fn
static clib_error_t * nat44_ei_forwarding_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1406
print
static unsigned char * print(const cJSON *const item, cJSON_bool format, const internal_hooks *const hooks)
Definition: cJSON.c:1183
nat44_ei_main_s::translation_buckets
u32 translation_buckets
Definition: nat44_ei.h:319
add_address_command_fn
static clib_error_t * add_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:732
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
clib_bitmap_free
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
uword
u64 uword
Definition: types.h:112
nat44_ei_main_s::vnet_main
vnet_main_t * vnet_main
Definition: nat44_ei.h:479
nat44_ei_add_del_static_mapping
int nat44_ei_add_del_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, nat_protocol_t proto, u32 sw_if_index, u32 vrf_id, u8 addr_only, u8 identity_nat, u8 *tag, u8 is_add)
Add/delete NAT44-EI static mapping.
Definition: nat44_ei.c:1853
ipfix_logging.h
src_port
vl_api_ip_port_and_mask_t src_port
Definition: flow_types.api:91
nat44_ei_add_interface_address
int nat44_ei_add_interface_address(nat44_ei_main_t *nm, u32 sw_if_index, int is_del)
Definition: nat44_ei.c:2632
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
nat44_ei_main_s::workers
u32 * workers
Definition: nat44_ei.h:358
NAT_LOG_NONE
@ NAT_LOG_NONE
Definition: nat_types.api:28
nat44_ei_main_s::per_thread_data
nat44_ei_main_per_thread_data_t * per_thread_data
Definition: nat44_ei.h:366
NAT44_EI_EXPECTED_ARGUMENT
#define NAT44_EI_EXPECTED_ARGUMENT
Definition: nat44_ei_cli.c:25
dlist_elt_t::next
u32 next
Definition: dlist.h:30
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
dlist_elt_t
Definition: dlist.h:28
nat_show_workers_command
static vlib_cli_command_t nat_show_workers_command
(constructor) VLIB_CLI_COMMAND (nat_show_workers_command)
Definition: nat44_ei_cli.c:1550
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
nat44_ei_static_mapping_t
Definition: nat44_ei.h:161
nat44_ei_set_alloc_mape
void nat44_ei_set_alloc_mape(u16 psid, u16 psid_offset, u16 psid_length)
Set address and port assignment algorithm for MAP-E CE.
Definition: nat44_ei.c:1717
nat_show_mss_clamping_command_fn
static clib_error_t * nat_show_mss_clamping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:584
nat_ha_resync_command
static vlib_cli_command_t nat_ha_resync_command
(constructor) VLIB_CLI_COMMAND (nat_ha_resync_command)
Definition: nat44_ei_cli.c:1734
nat_ha_listener_command_fn
static clib_error_t * nat_ha_listener_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:636
nat_show_workers_commnad_fn
static clib_error_t * nat_show_workers_commnad_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:315
ip4_address_t
Definition: ip4_packet.h:50
nat44_ei_set_alloc_range
void nat44_ei_set_alloc_range(u16 start_port, u16 end_port)
Set address and port assignment algorithm for port range.
Definition: nat44_ei.c:1706
nat44_ei_ipfix_logging_enable_disable_command
static vlib_cli_command_t nat44_ei_ipfix_logging_enable_disable_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_ipfix_logging_enable_disable_command)
Definition: nat44_ei_cli.c:1612
NAT_LOG_DEBUG
@ NAT_LOG_DEBUG
Definition: nat_types.api:33
nat44_ei_del_session
int nat44_ei_del_session(nat44_ei_main_t *nm, ip4_address_t *addr, u16 port, nat_protocol_t proto, u32 vrf_id, int is_in)
Delete NAT44-EI session.
Definition: nat44_ei.c:1785
nat44_ei_static_mapping_t::external_addr
ip4_address_t external_addr
Definition: nat44_ei.h:168
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
nat44_ei_main_s::static_mapping_by_external
clib_bihash_8_8_t static_mapping_by_external
Definition: nat44_ei.h:333
set_timeout_command
static vlib_cli_command_t set_timeout_command
(constructor) VLIB_CLI_COMMAND (set_timeout_command)
Definition: nat44_ei_cli.c:1566
nat44_ei_interface_is_inside
#define nat44_ei_interface_is_inside(ip)
Definition: nat44_ei.h:671
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
nat44_ei_address_t::addr
ip4_address_t addr
Definition: nat44_ei.h:69
nat44_ei_config_t
Definition: nat44_ei.h:111
nat44_ei_show_hash_command_fn
static clib_error_t * nat44_ei_show_hash_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:423
nat44_ei_main_s::output_feature_interfaces
nat44_ei_interface_t * output_feature_interfaces
Definition: nat44_ei.h:340
increment_v4_address
static void increment_v4_address(ip4_address_t *a)
Definition: nat_inlines.h:23
nat44_ei_main_s::outside_vrf_id
u32 outside_vrf_id
Definition: nat44_ei.h:352
nat44_ei.h
nat44_ei_static_mapping_t::local_addr
ip4_address_t local_addr
Definition: nat44_ei.h:166
nat44_ei_address_t::fib_index
u32 fib_index
Definition: nat44_ei.h:70
nat44_ei_static_map_resolve_t::e_port
u16 e_port
Definition: nat44_ei.h:135
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
nat44_ei_set_alloc_addr_and_port_alg_command_fn
static clib_error_t * nat44_ei_set_alloc_addr_and_port_alg_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:458
nat44_ei_main_s::first_worker_index
u32 first_worker_index
Definition: nat44_ei.h:357
nat44_ei_main_per_thread_data_t::user_hash
clib_bihash_8_8_t user_hash
Definition: nat44_ei.h:277
nat_ipfix_logging_enable_disable
int nat_ipfix_logging_enable_disable(int enable, u32 domain_id, u16 src_port)
Enable/disable NAT plugin IPFIX logging.
Definition: ipfix_logging.c:1524
nat44_ei_show_static_mappings_command
static vlib_cli_command_t nat44_ei_show_static_mappings_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_show_static_mappings_command)
Definition: nat44_ei_cli.c:1890
nat44_ei_plugin_disable
int nat44_ei_plugin_disable()
Definition: nat44_ei.c:920
format_nat_protocol
format_function_t format_nat_protocol
Definition: nat64.h:506
nat44_ei_main_s::static_mapping_by_local
clib_bihash_8_8_t static_mapping_by_local
Definition: nat44_ei.h:330
nat_ha_flush_command
static vlib_cli_command_t nat_ha_flush_command
(constructor) VLIB_CLI_COMMAND (nat_ha_flush_command)
Definition: nat44_ei_cli.c:1722
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:455
nat44_ei_main_per_thread_data_t::users
nat44_ei_user_t * users
Definition: nat44_ei.h:280
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:459
format
description fragment has unexpected format
Definition: map.api:433
nat_reset_timeouts
static_always_inline void nat_reset_timeouts(nat_timeouts_t *timeouts)
Definition: lib.h:90
nat44_ei_interface_add_del
int nat44_ei_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Definition: nat44_ei.c:496
fib_table_get
fib_table_t * fib_table_get(fib_node_index_t index, fib_protocol_t proto)
Get a pointer to a FIB table.
Definition: fib_table.c:29
nat44_ei_ipfix_logging_enable_disable_command_fn
static clib_error_t * nat44_ei_ipfix_logging_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:367
nat_ha_flush_command_fn
static clib_error_t * nat_ha_flush_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:712
u32
unsigned int u32
Definition: types.h:88
nat44_ei_clear_sessions_command
static vlib_cli_command_t nat44_ei_clear_sessions_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_clear_sessions_command)
Definition: nat44_ei_cli.c:1957
nat_set_mss_clamping_command
static vlib_cli_command_t nat_set_mss_clamping_command
(constructor) VLIB_CLI_COMMAND (nat_set_mss_clamping_command)
Definition: nat44_ei_cli.c:1660
nat44_ei_main_s::start_port
u16 start_port
Definition: nat44_ei.h:379
add_static_mapping_command_fn
static clib_error_t * add_static_mapping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:989
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
nat44_ei_interface_add_del_output_feature
int nat44_ei_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
Definition: nat44_ei.c:747
nat44_ei_add_interface_address_command_fn
static clib_error_t * nat44_ei_add_interface_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1183
vlib_worker_thread_t
Definition: threads.h:85
nat44_ei_main_s::in2out
clib_bihash_8_8_t in2out
Definition: nat44_ei.h:363
nat44_ei_static_mapping_t::proto
nat_protocol_t proto
Definition: nat44_ei.h:177
nat44_ei_set_workers
int nat44_ei_set_workers(uword *bitmap)
Definition: nat44_ei.c:252
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
nat44_ei_static_mapping_t::vrf_id
u32 vrf_id
Definition: nat44_ei.h:174
nat44_ei_show_hash
static vlib_cli_command_t nat44_ei_show_hash
(constructor) VLIB_CLI_COMMAND (nat44_ei_show_hash)
Definition: nat44_ei_cli.c:1746
nm
nat44_ei_main_t * nm
Definition: nat44_ei_hairpinning.c:413
nat_ha_resync_command_fn
static clib_error_t * nat_ha_resync_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:720
elt
app_rx_mq_elt_t * elt
Definition: application.c:488
nat_show_timeouts_command
static vlib_cli_command_t nat_show_timeouts_command
(constructor) VLIB_CLI_COMMAND (nat_show_timeouts_command)
Definition: nat44_ei_cli.c:1584
nat44_ei_clear_sessions_command_fn
static clib_error_t * nat44_ei_clear_sessions_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1338
vlib_main_t
Definition: main.h:102
nat44_ei_main_s::out2in_dpo
u8 out2in_dpo
Definition: nat44_ei.h:322
nat44_ei_is_identity_static_mapping
#define nat44_ei_is_identity_static_mapping(mp)
Definition: nat44_ei.h:678
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
nat_ha_set_failover
int nat_ha_set_failover(vlib_main_t *vm, ip4_address_t *addr, u16 port, u32 session_refresh_interval)
Set HA failover (remote settings)
Definition: nat44_ei_ha.c:540
nat_ha_resync
int nat_ha_resync(u32 client_index, u32 pid, nat_ha_resync_event_cb_t event_callback)
Resync HA (resend existing sessions to new failover)
Definition: nat44_ei_ha.c:1283
nat44_ei_main_s::log_level
u8 log_level
Definition: nat44_ei.h:452
nat_show_timeouts_command_fn
static clib_error_t * nat_show_timeouts_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1484
nat_ha_failover_command
static vlib_cli_command_t nat_ha_failover_command
(constructor) VLIB_CLI_COMMAND (nat_ha_failover_command)
Definition: nat44_ei_cli.c:1684
nat44_ei_main_s::out2in
clib_bihash_8_8_t out2in
Definition: nat44_ei.h:362
format_nat44_ei_addr_and_port_alloc_alg
u8 * format_nat44_ei_addr_and_port_alloc_alg(u8 *s, va_list *args)
Definition: nat44_ei_cli.c:504
vlib_worker_thread_t::name
u8 * name
Definition: threads.h:102
nat44_ei_static_map_resolve_t
Definition: nat44_ei.h:130
nat_ha_set_listener
int nat_ha_set_listener(vlib_main_t *vm, ip4_address_t *addr, u16 port, u32 path_mtu)
Set HA listener (local settings)
Definition: nat44_ei_ha.c:495
nat44_ei_del_session_command
static vlib_cli_command_t nat44_ei_del_session_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_del_session_command)
Definition: nat44_ei_cli.c:1972
nat44_ei_main_s::psid
u16 psid
Definition: nat44_ei.h:377
nat44_ei_static_map_resolve_t::l_port
u16 l_port
Definition: nat44_ei.h:134
nat44_ei_main_s::auto_add_sw_if_indices
u32 * auto_add_sw_if_indices
Definition: nat44_ei.h:389
rv
int __clib_unused rv
Definition: application.c:491
unformat_ip4_address
unformat_function_t unformat_ip4_address
Definition: format.h:68
nat44_ei_log_info
#define nat44_ei_log_info(...)
Definition: nat44_ei.h:688
vrf_id
u32 vrf_id
Definition: nat44_ed.api:1053
nat44_ei_set_log_level_command_fn
static clib_error_t * nat44_ei_set_log_level_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:336
nat44_ei_is_unk_proto_session
#define nat44_ei_is_unk_proto_session(sp)
Definition: nat44_ei.h:668
nat44_ei_main_s::mss_clamping
u16 mss_clamping
Definition: nat44_ei.h:327
nat44_ei_static_map_resolve_t::addr_only
u8 addr_only
Definition: nat44_ei.h:140
nat44_ei_main_s::forwarding_enabled
u8 forwarding_enabled
Definition: nat44_ei.h:323
nat44_ei_is_addr_only_static_mapping
#define nat44_ei_is_addr_only_static_mapping(mp)
Definition: nat44_ei.h:676
nat44_ei_show_addresses_command
static vlib_cli_command_t nat44_ei_show_addresses_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_show_addresses_command)
Definition: nat44_ei_cli.c:1788
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
nat44_ei_lb_addr_port_t::vrf_id
u32 vrf_id
Definition: nat44_ei.h:157
nat44_ei_sessions_clear
void nat44_ei_sessions_clear()
Clear all active NAT44-EI sessions.
Definition: nat44_ei.c:2478
nat44_ei_del_user_command_fn
static clib_error_t * nat44_ei_del_user_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:1298
vlib_cli_command_t
Definition: cli.h:92
path_mtu
u16 path_mtu
Definition: ip.api:783
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
nat44_ei_del_address
int nat44_ei_del_address(nat44_ei_main_t *nm, ip4_address_t addr, u8 delete_sm)
Definition: nat44_ei.c:2708
nat_ha_get_failover
void nat_ha_get_failover(ip4_address_t *addr, u16 *port, u32 *session_refresh_interval)
Get HA failover/remote settings.
Definition: nat44_ei_ha.c:555
nat44_ei_static_map_resolve_t::vrf_id
u32 vrf_id
Definition: nat44_ei.h:137
nat44_ei_set_alloc_default
void nat44_ei_set_alloc_default()
Set address and port assignment algorithm to default/standard.
Definition: nat44_ei.c:1697
nat44_ei_static_mapping_t::local_port
u16 local_port
Definition: nat44_ei.h:170
nat44_ei_static_map_resolve_t::sw_if_index
u32 sw_if_index
Definition: nat44_ei.h:136
nat44_ei_show_alloc_addr_and_port_alg_command
static vlib_cli_command_t nat44_ei_show_alloc_addr_and_port_alg_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_show_alloc_addr_and_port_alg_command)
Definition: nat44_ei_cli.c:1644
nat44_ei_main_s::num_workers
u32 num_workers
Definition: nat44_ei.h:356
unformat_bitmap_list
__clib_export uword unformat_bitmap_list(unformat_input_t *input, va_list *va)
unformat a list of bit ranges into a bitmap (eg "0-3,5-7,11" )
Definition: bitmap.c:55
nat44_ei_set_alloc_addr_and_port_alg_command
static vlib_cli_command_t nat44_ei_set_alloc_addr_and_port_alg_command
(constructor) VLIB_CLI_COMMAND (nat44_ei_set_alloc_addr_and_port_alg_command)
Definition: nat44_ei_cli.c:1632
nat_ha_get_resync_status
void nat_ha_get_resync_status(u8 *in_resync, u32 *resync_ack_missed)
Get resync status.
Definition: nat44_ei_ha.c:981
set_interface_nat44_ei_command
static vlib_cli_command_t set_interface_nat44_ei_command
(constructor) VLIB_CLI_COMMAND (set_interface_nat44_ei_command)
Definition: nat44_ei_cli.c:1804
nat44_ei_ha.h
NAT active-passive HA.
nat44_ei_static_map_resolve_t::l_addr
ip4_address_t l_addr
Definition: nat44_ei.h:132
nat44_ei_static_mapping_t::locals
nat44_ei_lb_addr_port_t * locals
Definition: nat44_ei.h:183
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
add_static_mapping_command
static vlib_cli_command_t add_static_mapping_command
(constructor) VLIB_CLI_COMMAND (add_static_mapping_command)
Definition: nat44_ei_cli.c:1847
nat44_ei_main_per_thread_data_t
Definition: nat44_ei.h:274
nat_set_mss_clamping_command_fn
static clib_error_t * nat_set_mss_clamping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:552
nat44_ei_show_alloc_addr_and_port_alg_command_fn
static clib_error_t * nat44_ei_show_alloc_addr_and_port_alg_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat44_ei_cli.c:525