FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
nat64_cli.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @file
17  * @brief NAT64 CLI
18  */
19 
20 #include <nat/nat64.h>
21 #include <nat/nat.h>
22 #include <nat/nat_inlines.h>
23 #include <vnet/fib/fib_table.h>
24 
25 static clib_error_t *
27  unformat_input_t * input,
28  vlib_cli_command_t * cmd)
29 {
30  unformat_input_t _line_input, *line_input = &_line_input;
31  ip4_address_t start_addr, end_addr, this_addr;
32  u32 start_host_order, end_host_order;
33  int i, count, rv;
34  u32 vrf_id = ~0;
35  u8 is_add = 1;
36  clib_error_t *error = 0;
37 
38  /* Get a line of input. */
39  if (!unformat_user (input, unformat_line_input, line_input))
40  return 0;
41 
42  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
43  {
44  if (unformat (line_input, "%U - %U",
45  unformat_ip4_address, &start_addr,
46  unformat_ip4_address, &end_addr))
47  ;
48  else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
49  ;
50  else if (unformat (line_input, "%U", unformat_ip4_address, &start_addr))
51  end_addr = start_addr;
52  else if (unformat (line_input, "del"))
53  is_add = 0;
54  else
55  {
56  error = clib_error_return (0, "unknown input '%U'",
57  format_unformat_error, line_input);
58  goto done;
59  }
60  }
61 
62  start_host_order = clib_host_to_net_u32 (start_addr.as_u32);
63  end_host_order = clib_host_to_net_u32 (end_addr.as_u32);
64 
65  if (end_host_order < start_host_order)
66  {
67  error = clib_error_return (0, "end address less than start address");
68  goto done;
69  }
70 
71  count = (end_host_order - start_host_order) + 1;
72  this_addr = start_addr;
73 
74  for (i = 0; i < count; i++)
75  {
76  rv = nat64_add_del_pool_addr (0, &this_addr, vrf_id, is_add);
77 
78  switch (rv)
79  {
80  case VNET_API_ERROR_NO_SUCH_ENTRY:
81  error =
82  clib_error_return (0, "NAT64 pool address %U not exist.",
83  format_ip4_address, &this_addr);
84  goto done;
85  case VNET_API_ERROR_VALUE_EXIST:
86  error =
87  clib_error_return (0, "NAT64 pool address %U exist.",
88  format_ip4_address, &this_addr);
89  goto done;
90  default:
91  break;
92 
93  }
94  increment_v4_address (&this_addr);
95  }
96 
97 done:
98  unformat_free (line_input);
99 
100  return error;
101 }
102 
103 static int
105 {
106  vlib_main_t *vm = ctx;
107 
108  if (ap->fib_index != ~0)
109  {
110  fib_table_t *fib;
112  if (!fib)
113  return -1;
114  vlib_cli_output (vm, " %U tenant VRF: %u", format_ip4_address,
115  &ap->addr, fib->ft_table_id);
116  }
117  else
118  vlib_cli_output (vm, " %U", format_ip4_address, &ap->addr);
119 
120 #define _(N, i, n, s) \
121  vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
123 #undef _
124  return 0;
125 }
126 
127 static clib_error_t *
129  unformat_input_t * input,
130  vlib_cli_command_t * cmd)
131 {
132  vlib_cli_output (vm, "NAT64 pool:");
134 
135  return 0;
136 }
137 
138 static clib_error_t *
141  input, vlib_cli_command_t * cmd)
142 {
143  unformat_input_t _line_input, *line_input = &_line_input;
144  vnet_main_t *vnm = vnet_get_main ();
145  clib_error_t *error = 0;
147  u32 *inside_sw_if_indices = 0;
148  u32 *outside_sw_if_indices = 0;
149  u8 is_add = 1;
150  int i, rv;
151 
152  /* Get a line of input. */
153  if (!unformat_user (input, unformat_line_input, line_input))
154  return 0;
155 
156  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
157  {
158  if (unformat (line_input, "in %U", unformat_vnet_sw_interface,
159  vnm, &sw_if_index))
160  vec_add1 (inside_sw_if_indices, sw_if_index);
161  else if (unformat (line_input, "out %U", unformat_vnet_sw_interface,
162  vnm, &sw_if_index))
163  vec_add1 (outside_sw_if_indices, sw_if_index);
164  else if (unformat (line_input, "del"))
165  is_add = 0;
166  else
167  {
168  error = clib_error_return (0, "unknown input '%U'",
169  format_unformat_error, line_input);
170  goto done;
171  }
172  }
173 
174  if (vec_len (inside_sw_if_indices))
175  {
176  for (i = 0; i < vec_len (inside_sw_if_indices); i++)
177  {
178  sw_if_index = inside_sw_if_indices[i];
179  rv = nat64_add_del_interface (sw_if_index, 1, is_add);
180  switch (rv)
181  {
182  case VNET_API_ERROR_NO_SUCH_ENTRY:
183  error =
184  clib_error_return (0, "%U NAT64 feature not enabled.",
186  sw_if_index);
187  goto done;
188  case VNET_API_ERROR_VALUE_EXIST:
189  error =
190  clib_error_return (0, "%U NAT64 feature already enabled.",
192  vnm, sw_if_index);
193  goto done;
194  case VNET_API_ERROR_INVALID_VALUE:
195  case VNET_API_ERROR_INVALID_VALUE_2:
196  error =
198  "%U NAT64 feature enable/disable failed.",
200  sw_if_index);
201  goto done;
202  default:
203  break;
204 
205  }
206  }
207  }
208 
209  if (vec_len (outside_sw_if_indices))
210  {
211  for (i = 0; i < vec_len (outside_sw_if_indices); i++)
212  {
213  sw_if_index = outside_sw_if_indices[i];
214  rv = nat64_add_del_interface (sw_if_index, 0, is_add);
215  switch (rv)
216  {
217  case VNET_API_ERROR_NO_SUCH_ENTRY:
218  error =
219  clib_error_return (0, "%U NAT64 feature not enabled.",
221  sw_if_index);
222  goto done;
223  case VNET_API_ERROR_VALUE_EXIST:
224  error =
225  clib_error_return (0, "%U NAT64 feature already enabled.",
227  sw_if_index);
228  goto done;
229  case VNET_API_ERROR_INVALID_VALUE:
230  case VNET_API_ERROR_INVALID_VALUE_2:
231  error =
233  "%U NAT64 feature enable/disable failed.",
235  sw_if_index);
236  goto done;
237  default:
238  break;
239 
240  }
241  }
242  }
243 
244 done:
245  unformat_free (line_input);
246  vec_free (inside_sw_if_indices);
247  vec_free (outside_sw_if_indices);
248 
249  return error;
250 }
251 
252 static int
254 {
255  vlib_main_t *vm = ctx;
256  vnet_main_t *vnm = vnet_get_main ();
257 
258  vlib_cli_output (vm, " %U %s", format_vnet_sw_if_index_name, vnm,
259  i->sw_if_index,
261  && nat_interface_is_outside (i)) ? "in out" :
262  nat_interface_is_inside (i) ? "in" : "out");
263  return 0;
264 }
265 
266 static clib_error_t *
269  input, vlib_cli_command_t * cmd)
270 {
271  vlib_cli_output (vm, "NAT64 interfaces:");
273 
274  return 0;
275 }
276 
277 static clib_error_t *
279  vm,
281  * input, vlib_cli_command_t * cmd)
282 {
283  unformat_input_t _line_input, *line_input = &_line_input;
284  clib_error_t *error = 0;
285  u8 is_add = 1;
286  ip6_address_t in_addr;
287  ip4_address_t out_addr;
288  u32 in_port = 0;
289  u32 out_port = 0;
290  u32 vrf_id = 0, protocol;
292  u8 p = 0;
293  int rv;
294 
295  if (!unformat_user (input, unformat_line_input, line_input))
296  return 0;
297 
298  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
299  {
300  if (unformat (line_input, "%U %u", unformat_ip6_address,
301  &in_addr, &in_port))
302  ;
303  else if (unformat (line_input, "%U %u", unformat_ip4_address,
304  &out_addr, &out_port))
305  ;
306  else if (unformat (line_input, "vrf %u", &vrf_id))
307  ;
308  else if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
309  ;
310  else
311  if (unformat
312  (line_input, "%U %U %u", unformat_ip6_address, &in_addr,
313  unformat_ip4_address, &out_addr, &protocol))
314  p = (u8) protocol;
315  else if (unformat (line_input, "del"))
316  is_add = 0;
317  else
318  {
319  error = clib_error_return (0, "unknown input: '%U'",
320  format_unformat_error, line_input);
321  goto done;
322  }
323  }
324 
325  if (!p)
326  {
327  if (!in_port)
328  {
329  error =
330  clib_error_return (0, "inside port and address must be set");
331  goto done;
332  }
333 
334  if (!out_port)
335  {
336  error =
337  clib_error_return (0, "outside port and address must be set");
338  goto done;
339  }
340 
341  p = snat_proto_to_ip_proto (proto);
342  }
343 
344  rv =
345  nat64_add_del_static_bib_entry (&in_addr, &out_addr, (u16) in_port,
346  (u16) out_port, p, vrf_id, is_add);
347 
348  switch (rv)
349  {
350  case VNET_API_ERROR_NO_SUCH_ENTRY:
351  error = clib_error_return (0, "NAT64 BIB entry not exist.");
352  goto done;
353  case VNET_API_ERROR_VALUE_EXIST:
354  error = clib_error_return (0, "NAT64 BIB entry exist.");
355  goto done;
356  case VNET_API_ERROR_UNSPECIFIED:
357  error = clib_error_return (0, "Crerate NAT64 BIB entry failed.");
358  goto done;
359  case VNET_API_ERROR_INVALID_VALUE:
360  error =
362  "Outside address %U and port %u already in use.",
363  format_ip4_address, &out_addr, out_port);
364  goto done;
365  case VNET_API_ERROR_INVALID_VALUE_2:
366  error = clib_error_return (0, "Invalid outside port.");
367  default:
368  break;
369  }
370 
371 done:
372  unformat_free (line_input);
373 
374  return error;
375 }
376 
377 static int
378 nat64_cli_bib_walk (nat64_db_bib_entry_t * bibe, void *ctx)
379 {
380  vlib_main_t *vm = ctx;
381  fib_table_t *fib;
382 
383  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
384  if (!fib)
385  return -1;
386 
387  switch (bibe->proto)
388  {
389  case IP_PROTOCOL_ICMP:
390  case IP_PROTOCOL_TCP:
391  case IP_PROTOCOL_UDP:
392  vlib_cli_output (vm, " %U %u %U %u protocol %U vrf %u %s %u sessions",
393  format_ip6_address, &bibe->in_addr,
394  clib_net_to_host_u16 (bibe->in_port),
395  format_ip4_address, &bibe->out_addr,
396  clib_net_to_host_u16 (bibe->out_port),
398  ip_proto_to_snat_proto (bibe->proto), fib->ft_table_id,
399  bibe->is_static ? "static" : "dynamic", bibe->ses_num);
400  break;
401  default:
402  vlib_cli_output (vm, " %U %U protocol %u vrf %u %s %u sessions",
403  format_ip6_address, &bibe->in_addr,
404  format_ip4_address, &bibe->out_addr,
405  bibe->proto, fib->ft_table_id,
406  bibe->is_static ? "static" : "dynamic", bibe->ses_num);
407  }
408  return 0;
409 }
410 
411 static clib_error_t *
413  unformat_input_t * input, vlib_cli_command_t * cmd)
414 {
415  nat64_main_t *nm = &nat64_main;
416  unformat_input_t _line_input, *line_input = &_line_input;
417  clib_error_t *error = 0;
418  u32 proto = ~0;
419  u8 p = 255;
420  nat64_db_t *db;
421 
422  if (!unformat_user (input, unformat_line_input, line_input))
423  return 0;
424 
425  if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
426  p = snat_proto_to_ip_proto (proto);
427  else if (unformat (line_input, "unknown"))
428  p = 0;
429  else if (unformat (line_input, "all"))
430  ;
431  else
432  {
433  error = clib_error_return (0, "unknown input: '%U'",
434  format_unformat_error, line_input);
435  goto done;
436  }
437 
438  if (p == 255)
439  vlib_cli_output (vm, "NAT64 BIB entries:");
440  else
441  vlib_cli_output (vm, "NAT64 %U BIB entries:", format_snat_protocol,
442  proto);
443 
444  /* *INDENT-OFF* */
445  vec_foreach (db, nm->db)
447  /* *INDENT-ON* */
448 
449 done:
450  unformat_free (line_input);
451 
452  return error;
453 }
454 
456 {
460 
461 static int
462 nat64_cli_st_walk (nat64_db_st_entry_t * ste, void *arg)
463 {
465  vlib_main_t *vm = ctx->vm;
466  nat64_db_bib_entry_t *bibe;
467  fib_table_t *fib;
468 
469  bibe = nat64_db_bib_entry_by_index (ctx->db, ste->proto, ste->bibe_index);
470  if (!bibe)
471  return -1;
472 
473  fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
474  if (!fib)
475  return -1;
476 
477  u32 vrf_id = fib->ft_table_id;
478 
479  if (ste->proto == IP_PROTOCOL_ICMP)
480  vlib_cli_output (vm, " %U %U %u %U %U %u protocol %U vrf %u",
481  format_ip6_address, &bibe->in_addr,
482  format_ip6_address, &ste->in_r_addr,
483  clib_net_to_host_u16 (bibe->in_port),
484  format_ip4_address, &bibe->out_addr,
485  format_ip4_address, &ste->out_r_addr,
486  clib_net_to_host_u16 (bibe->out_port),
488  ip_proto_to_snat_proto (bibe->proto), vrf_id);
489  else if (ste->proto == IP_PROTOCOL_TCP || ste->proto == IP_PROTOCOL_UDP)
490  vlib_cli_output (vm, " %U %u %U %u %U %u %U %u protcol %U vrf %u",
491  format_ip6_address, &bibe->in_addr,
492  clib_net_to_host_u16 (bibe->in_port),
493  format_ip6_address, &ste->in_r_addr,
494  clib_net_to_host_u16 (ste->r_port),
495  format_ip4_address, &bibe->out_addr,
496  clib_net_to_host_u16 (bibe->out_port),
497  format_ip4_address, &ste->out_r_addr,
498  clib_net_to_host_u16 (ste->r_port),
500  ip_proto_to_snat_proto (bibe->proto), vrf_id);
501  else
502  vlib_cli_output (vm, " %U %U %U %U protocol %u vrf %u",
503  format_ip6_address, &bibe->in_addr,
504  format_ip6_address, &ste->in_r_addr,
505  format_ip4_address, &bibe->out_addr,
506  format_ip4_address, &ste->out_r_addr,
507  bibe->proto, vrf_id);
508 
509  return 0;
510 }
511 
512 static clib_error_t *
514  unformat_input_t * input, vlib_cli_command_t * cmd)
515 {
516  nat64_main_t *nm = &nat64_main;
517  unformat_input_t _line_input, *line_input = &_line_input;
518  clib_error_t *error = 0;
519  u32 proto = ~0;
520  u8 p = 255;
521  nat64_db_t *db;
523  .vm = vm,
524  };
525 
526  if (!unformat_user (input, unformat_line_input, line_input))
527  return 0;
528 
529  if (unformat (line_input, "%U", unformat_snat_protocol, &proto))
530  p = snat_proto_to_ip_proto (proto);
531  else if (unformat (line_input, "unknown"))
532  p = 0;
533  else if (unformat (line_input, "all"))
534  ;
535  else
536  {
537  error = clib_error_return (0, "unknown input: '%U'",
538  format_unformat_error, line_input);
539  goto done;
540  }
541 
542  if (p == 255)
543  vlib_cli_output (vm, "NAT64 sessions:");
544  else
545  vlib_cli_output (vm, "NAT64 %U sessions:", format_snat_protocol, proto);
546  /* *INDENT-OFF* */
547  vec_foreach (db, nm->db)
548  {
549  ctx.db = db;
550  nat64_db_st_walk (db, p, nat64_cli_st_walk, &ctx);
551  }
552  /* *INDENT-ON* */
553 
554 done:
555  unformat_free (line_input);
556 
557  return error;
558 }
559 
560 static clib_error_t *
562  vlib_cli_command_t * cmd)
563 {
564  vnet_main_t *vnm = vnet_get_main ();
565  clib_error_t *error = 0;
566  unformat_input_t _line_input, *line_input = &_line_input;
567  u8 is_add = 1;
568  u32 vrf_id = 0, sw_if_index = ~0;
570  u32 plen = 0;
571  int rv;
572 
573  if (!unformat_user (input, unformat_line_input, line_input))
574  return 0;
575 
576  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
577  {
578  if (unformat
579  (line_input, "%U/%u", unformat_ip6_address, &prefix, &plen))
580  ;
581  else if (unformat (line_input, "tenant-vrf %u", &vrf_id))
582  ;
583  else if (unformat (line_input, "del"))
584  is_add = 0;
585  else
586  if (unformat
587  (line_input, "interface %U", unformat_vnet_sw_interface, vnm,
588  &sw_if_index))
589  ;
590  else
591  {
592  error = clib_error_return (0, "unknown input: '%U'",
593  format_unformat_error, line_input);
594  goto done;
595  }
596  }
597 
598  if (!plen)
599  {
600  error = clib_error_return (0, "NAT64 prefix must be set.");
601  goto done;
602  }
603 
604  rv = nat64_add_del_prefix (&prefix, (u8) plen, vrf_id, is_add);
605 
606  switch (rv)
607  {
608  case VNET_API_ERROR_NO_SUCH_ENTRY:
609  error = clib_error_return (0, "NAT64 prefix not exist.");
610  goto done;
611  case VNET_API_ERROR_INVALID_VALUE:
612  error = clib_error_return (0, "Invalid prefix length.");
613  goto done;
614  default:
615  break;
616  }
617 
618  /*
619  * Add RX interface route, whenNAT isn't running on the real input
620  * interface
621  */
622  if (sw_if_index != ~0)
623  {
624  u32 fib_index;
625  fib_prefix_t fibpfx = {
626  .fp_len = plen,
627  .fp_proto = FIB_PROTOCOL_IP6,
628  .fp_addr = {
629  .ip6 = prefix}
630  };
631 
632  if (is_add)
633  {
634  fib_index =
636  vrf_id, nat_fib_src_hi);
637  fib_table_entry_update_one_path (fib_index, &fibpfx,
641  sw_if_index, ~0, 0,
643  }
644  else
645  {
646  fib_index = fib_table_find (FIB_PROTOCOL_IP6, vrf_id);
647  fib_table_entry_path_remove (fib_index, &fibpfx,
650  sw_if_index, ~0, 1,
653  }
654  }
655 
656 done:
657  unformat_free (line_input);
658 
659  return error;
660 }
661 
662 static int
664 {
665  vlib_main_t *vm = ctx;
666 
667  vlib_cli_output (vm, " %U/%u tenant-vrf %u",
668  format_ip6_address, &p->prefix, p->plen, p->vrf_id);
669 
670  return 0;
671 }
672 
673 static clib_error_t *
675  unformat_input_t * input,
676  vlib_cli_command_t * cmd)
677 {
678  vlib_cli_output (vm, "NAT64 prefix:");
680 
681  return 0;
682 }
683 
684 static clib_error_t *
686  unformat_input_t * input,
687  vlib_cli_command_t * cmd)
688 {
689  vnet_main_t *vnm = vnet_get_main ();
690  unformat_input_t _line_input, *line_input = &_line_input;
692  int rv;
693  int is_add = 1;
694  clib_error_t *error = 0;
695 
696  /* Get a line of input. */
697  if (!unformat_user (input, unformat_line_input, line_input))
698  return 0;
699 
700  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
701  {
702  if (unformat
703  (line_input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
704  else if (unformat (line_input, "del"))
705  is_add = 0;
706  else
707  {
708  error = clib_error_return (0, "unknown input '%U'",
709  format_unformat_error, line_input);
710  goto done;
711  }
712  }
713 
714  rv = nat64_add_interface_address (sw_if_index, is_add);
715 
716  switch (rv)
717  {
718  case VNET_API_ERROR_NO_SUCH_ENTRY:
719  error = clib_error_return (0, "entry not exist");
720  break;
721  case VNET_API_ERROR_VALUE_EXIST:
722  error = clib_error_return (0, "entry exist");
723  break;
724  default:
725  break;
726  }
727 
728 done:
729  unformat_free (line_input);
730 
731  return error;
732 }
733 
734 /* *INDENT-OFF* */
735 
736 /*?
737  * @cliexpar
738  * @cliexstart{nat64 add pool address}
739  * Add/delete NAT64 pool address.
740  * To add single NAT64 pool address use:
741  * vpp# nat64 add pool address 10.1.1.10
742  * To add NAT64 pool address range use:
743  * vpp# nat64 add pool address 10.1.1.2 - 10.1.1.5
744  * To add NAT64 pool address for specific tenant use:
745  * vpp# nat64 add pool address 10.1.1.100 tenant-vrf 100
746  * @cliexend
747 ?*/
748 VLIB_CLI_COMMAND (nat64_add_pool_address_command, static) = {
749  .path = "nat64 add pool address",
750  .short_help = "nat64 add pool address <ip4-range-start> [- <ip4-range-end>] "
751  "[tenant-vrf <vrf-id>] [del]",
753 };
754 
755 /*?
756  * @cliexpar
757  * @cliexstart{show nat64 pool}
758  * Show NAT64 pool.
759  * vpp# show nat64 pool
760  * NAT64 pool:
761  * 10.1.1.3 tenant VRF: 0
762  * 10.1.1.10 tenant VRF: 10
763  * @cliexend
764 ?*/
765 VLIB_CLI_COMMAND (show_nat64_pool_command, static) = {
766  .path = "show nat64 pool",
767  .short_help = "show nat64 pool",
768  .function = nat64_show_pool_command_fn,
769 };
770 
771 /*?
772  * @cliexpar
773  * @cliexstart{set interface nat64}
774  * Enable/disable NAT64 feature on the interface.
775  * To enable NAT64 feature with local (IPv6) network interface
776  * GigabitEthernet0/8/0 and external (IPv4) network interface
777  * GigabitEthernet0/a/0 use:
778  * vpp# set interface nat64 in GigabitEthernet0/8/0 out GigabitEthernet0/a/0
779  * @cliexend
780 ?*/
781 VLIB_CLI_COMMAND (set_interface_nat64_command, static) = {
782  .path = "set interface nat64",
783  .short_help = "set interface nat64 in|out <intfc> [del]",
785 };
786 
787 /*?
788  * @cliexpar
789  * @cliexstart{show nat64 interfaces}
790  * Show interfaces with NAT64 feature.
791  * To show interfaces with NAT64 feature use:
792  * vpp# show nat64 interfaces
793  * NAT64 interfaces:
794  * GigabitEthernet0/8/0 in
795  * GigabitEthernet0/a/0 out
796  * @cliexend
797 ?*/
798 VLIB_CLI_COMMAND (show_nat64_interfaces_command, static) = {
799  .path = "show nat64 interfaces",
800  .short_help = "show nat64 interfaces",
802 };
803 
804 /*?
805  * @cliexpar
806  * @cliexstart{nat64 add static bib}
807  * Add/delete NAT64 static BIB entry.
808  * To create NAT64 satatic BIB entry use:
809  * vpp# nat64 add static bib 2001:db8:c000:221:: 1234 10.1.1.3 5678 tcp
810  * vpp# nat64 add static bib 2001:db8:c000:221:: 1234 10.1.1.3 5678 udp vrf 10
811  * @cliexend
812 ?*/
813 VLIB_CLI_COMMAND (nat64_add_del_static_bib_command, static) = {
814  .path = "nat64 add static bib",
815  .short_help = "nat64 add static bib <ip6-addr> <port> <ip4-addr> <port> "
816  "tcp|udp|icmp [vfr <table-id>] [del]",
818 };
819 
820 /*?
821  * @cliexpar
822  * @cliexstart{show nat64 bib}
823  * Show NAT64 BIB entries.
824  * To show NAT64 TCP BIB entries use:
825  * vpp# show nat64 bib tcp
826  * NAT64 tcp BIB:
827  * fd01:1::2 6303 10.0.0.3 62303 tcp vrf 0 dynamic 1 sessions
828  * 2001:db8:c000:221:: 1234 10.1.1.3 5678 tcp vrf 0 static 2 sessions
829  * To show NAT64 UDP BIB entries use:
830  * vpp# show nat64 bib udp
831  * NAT64 udp BIB:
832  * fd01:1::2 6304 10.0.0.3 10546 udp vrf 0 dynamic 10 sessions
833  * 2001:db8:c000:221:: 1234 10.1.1.3 5678 udp vrf 10 static 0 sessions
834  * To show NAT64 ICMP BIB entries use:
835  * vpp# show nat64 bib icmp
836  * NAT64 icmp BIB:
837  * fd01:1::2 6305 10.0.0.3 63209 icmp vrf 10 dynamic 1 sessions
838  * @cliexend
839 ?*/
840 VLIB_CLI_COMMAND (show_nat64_bib_command, static) = {
841  .path = "show nat64 bib",
842  .short_help = "show nat64 bib all|tcp|udp|icmp|unknown",
843  .function = nat64_show_bib_command_fn,
844 };
845 
846 /*?
847  * @cliexpar
848  * @cliexstart{show nat64 session table}
849  * Show NAT64 session table.
850  * To show NAT64 TCP session table use:
851  * vpp# show nat64 session table tcp
852  * NAT64 tcp session table:
853  * fd01:1::2 6303 64:ff9b::ac10:202 20 10.0.0.3 62303 172.16.2.2 20 tcp vrf 0
854  * fd01:3::2 6303 64:ff9b::ac10:202 20 10.0.10.3 21300 172.16.2.2 20 tcp vrf 10
855  * To show NAT64 UDP session table use:
856  * #vpp show nat64 session table udp
857  * NAT64 udp session table:
858  * fd01:1::2 6304 64:ff9b::ac10:202 20 10.0.0.3 10546 172.16.2.2 20 udp vrf 0
859  * fd01:3::2 6304 64:ff9b::ac10:202 20 10.0.10.3 58627 172.16.2.2 20 udp vrf 10
860  * fd01:1::2 1235 64:ff9b::a00:3 4023 10.0.0.3 24488 10.0.0.3 4023 udp vrf 0
861  * fd01:1::3 23 64:ff9b::a00:3 24488 10.0.0.3 4023 10.0.0.3 24488 udp vrf 0
862  * To show NAT64 ICMP session table use:
863  * #vpp show nat64 session table icmp
864  * NAT64 icmp session table:
865  * fd01:1::2 64:ff9b::ac10:202 6305 10.0.0.3 172.16.2.2 63209 icmp vrf 0
866  * @cliexend
867 ?*/
868 VLIB_CLI_COMMAND (show_nat64_st_command, static) = {
869  .path = "show nat64 session table",
870  .short_help = "show nat64 session table all|tcp|udp|icmp|unknown",
871  .function = nat64_show_st_command_fn,
872 };
873 
874 /*?
875  * @cliexpar
876  * @cliexstart{nat64 add prefix}
877  * Set NAT64 prefix for generating IPv6 representations of IPv4 addresses.
878  * To set NAT64 global prefix use:
879  * vpp# nat64 add prefix 2001:db8::/32
880  * To set NAT64 prefix for specific tenant use:
881  * vpp# nat64 add prefix 2001:db8:122:300::/56 tenant-vrf 10
882  * @cliexend
883 ?*/
884 VLIB_CLI_COMMAND (nat64_add_del_prefix_command, static) = {
885  .path = "nat64 add prefix",
886  .short_help = "nat64 add prefix <ip6-prefix>/<plen> [tenant-vrf <vrf-id>] "
887  "[del] [interface <interface]",
889 };
890 
891 /*?
892  * @cliexpar
893  * @cliexstart{show nat64 prefix}
894  * Show NAT64 prefix.
895  * To show NAT64 prefix use:
896  * vpp# show nat64 prefix
897  * NAT64 prefix:
898  * 2001:db8::/32 tenant-vrf 0
899  * 2001:db8:122:300::/56 tenant-vrf 10
900  * @cliexend
901 ?*/
902 VLIB_CLI_COMMAND (show_nat64_prefix_command, static) = {
903  .path = "show nat64 prefix",
904  .short_help = "show nat64 prefix",
905  .function = nat64_show_prefix_command_fn,
906 };
907 
908 /*?
909  * @cliexpar
910  * @cliexstart{nat64 add interface address}
911  * Add/delete NAT64 pool address from specific (DHCP addressed) interface.
912  * To add NAT64 pool address from specific interface use:
913  * vpp# nat64 add interface address GigabitEthernet0/8/0
914  * @cliexend
915 ?*/
916 VLIB_CLI_COMMAND (nat64_add_interface_address_command, static) = {
917  .path = "nat64 add interface address",
918  .short_help = "nat64 add interface address <interface> [del]",
920 };
921 /* *INDENT-ON* */
922 
923 /*
924  * fd.io coding-style-patch-verification: ON
925  *
926  * Local Variables:
927  * eval: (c-set-style "gnu")
928  * End:
929  */
u8 count
Definition: dhcp.api:208
static clib_error_t * nat64_show_bib_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:412
nat64_db_t * db
BIB and session DB per thread.
Definition: nat64.h:83
u8 proto
Definition: acl_types.api:47
static int nat64_cli_pool_walk(snat_address_t *ap, void *ctx)
Definition: nat64_cli.c:104
ip6_address_t prefix
Definition: nat64.h:49
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static int nat64_cli_interface_walk(snat_interface_t *i, void *ctx)
Definition: nat64_cli.c:253
int nat64_add_del_interface(u32 sw_if_index, u8 is_inside, u8 is_add)
Enable/disable NAT64 feature on the interface.
Definition: nat64.c:418
#define NULL
Definition: clib.h:58
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
int i
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
unformat_function_t unformat_vnet_sw_interface
vl_api_prefix_t prefix
Definition: ip.api:144
A path that result in received traffic being recieved/recirculated so that it appears to have arrived...
Definition: fib_types.h:355
int nat64_add_interface_address(u32 sw_if_index, int is_add)
NAT64 pool address from specific (DHCP addressed) interface.
Definition: nat64.c:376
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
#define nat_interface_is_outside(i)
Check if NAT interface is outside.
Definition: nat.h:813
fib_node_index_t fib_table_entry_update_one_path(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Update the entry to have just one path.
Definition: fib_table.c:805
static clib_error_t * nat64_add_del_pool_addr_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:26
vl_api_ip_proto_t protocol
Definition: lb_types.api:71
static clib_error_t * nat64_add_del_static_bib_command_fn(vlib_main_t *vm, unformat_input_t() *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:278
format_function_t format_ip4_address
Definition: format.h:73
unformat_function_t unformat_ip4_address
Definition: format.h:68
vl_api_interface_index_t sw_if_index
Definition: gre.api:59
Aggregate type for a prefix.
Definition: fib_types.h:203
#define clib_error_return(e, args...)
Definition: error.h:99
static int nat64_cli_bib_walk(nat64_db_bib_entry_t *bibe, void *ctx)
Definition: nat64_cli.c:378
unsigned int u32
Definition: types.h:88
static clib_error_t * nat64_add_interface_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:685
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1097
u16 fp_len
The mask length.
Definition: fib_types.h:207
Definition: fib_entry.h:112
unformat_function_t unformat_line_input
Definition: format.h:283
static clib_error_t * nat64_show_pool_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:128
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
#define nat_interface_is_inside(i)
Check if NAT interface is inside.
Definition: nat.h:807
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
Definition: fib_table.c:1291
unformat_function_t unformat_ip6_address
Definition: format.h:89
struct nat64_cli_st_walk_ctx_t_ nat64_cli_st_walk_ctx_t
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
Definition: nat_inlines.h:162
void nat64_pool_addr_walk(nat64_pool_addr_walk_fn_t fn, void *ctx)
Walk NAT64 pool.
Definition: nat64.c:361
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:92
format_function_t format_ip6_address
Definition: format.h:91
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:342
int nat64_add_del_prefix(ip6_address_t *prefix, u8 plen, u32 vrf_id, u8 is_add)
Add/delete NAT64 prefix.
Definition: nat64.c:980
u32 sw_if_index
Definition: nat.h:471
fib_source_t nat_fib_src_hi
Definition: nat.c:41
nat64_main_t nat64_main
Definition: nat64.c:29
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
u32 vrf_id
Definition: nat64.h:51
unformat_function_t unformat_snat_protocol
Definition: nat.h:759
void nat64_db_st_walk(nat64_db_t *db, u8 proto, nat64_db_st_walk_fn_t fn, void *ctx)
Walk NAT64 session table.
Definition: nat64_db.c:325
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1156
nat64_db_bib_entry_t * nat64_db_bib_entry_by_index(nat64_db_t *db, u8 proto, u32 bibe_index)
Get BIB entry by index and protocol.
Definition: nat64_db.c:302
format_function_t format_snat_protocol
Definition: nat.h:756
int nat64_add_del_pool_addr(u32 thread_index, ip4_address_t *addr, u32 vrf_id, u8 is_add)
Add/delete address to NAT64 pool.
Definition: nat64.c:281
void fib_table_entry_path_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_route_path_flags_t path_flags)
remove one path to an entry (aka route) in the FIB.
Definition: fib_table.c:722
ip4_address_t addr
Definition: nat.h:356
void nat64_prefix_walk(nat64_prefix_walk_fn_t fn, void *ctx)
Walk NAT64 prefixes.
Definition: nat64.c:1028
void nat64_interfaces_walk(nat64_interface_walk_fn_t fn, void *ctx)
Walk NAT64 interfaces.
Definition: nat64.c:515
static clib_error_t * nat64_interface_feature_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:139
NAT64 global declarations.
void increment_v4_address(ip4_address_t *a)
Increment IPv4 address.
Definition: nat.c:642
static u32 ip_proto_to_snat_proto(u8 ip_proto)
Definition: nat_inlines.h:147
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void unformat_free(unformat_input_t *i)
Definition: format.h:163
static int nat64_cli_st_walk(nat64_db_st_entry_t *ste, void *arg)
Definition: nat64_cli.c:462
snat_protocol_t
Definition: nat.h:189
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
static clib_error_t * nat64_show_st_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:513
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
#define vec_foreach(var, vec)
Vector iterator.
static clib_error_t * nat64_add_del_prefix_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:561
u32 vrf_id
Definition: nat.api:821
static int nat64_cli_prefix_walk(nat64_prefix_t *p, void *ctx)
Definition: nat64_cli.c:663
static clib_error_t * nat64_show_prefix_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:674
void nat64_db_bib_walk(nat64_db_t *db, u8 proto, nat64_db_bib_walk_fn_t fn, void *ctx)
Walk NAT64 BIB.
Definition: nat64_db.c:251
int nat64_add_del_static_bib_entry(ip6_address_t *in_addr, ip4_address_t *out_addr, u16 in_port, u16 out_port, u8 proto, u32 vrf_id, u8 is_add)
Add/delete static NAT64 BIB entry.
Definition: nat64.c:662
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
u32 fib_index
Definition: nat.h:357
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static clib_error_t * nat64_show_interfaces_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nat64_cli.c:267
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
A protocol Independent FIB table.
Definition: fib_table.h:71