FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
nat64.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 implementation
18  */
19 
20 #include <nat/nat64.h>
21 #include <nat/nat64_db.h>
22 #include <nat/nat_reass.h>
23 #include <vnet/fib/ip4_fib.h>
24 #include <vppinfra/crc32.h>
25 
26 
28 
29 /* *INDENT-OFF* */
30 
31 /* Hook up input features */
32 VNET_FEATURE_INIT (nat64_in2out, static) = {
33  .arc_name = "ip6-unicast",
34  .node_name = "nat64-in2out",
35  .runs_before = VNET_FEATURES ("ip6-lookup"),
36 };
37 VNET_FEATURE_INIT (nat64_out2in, static) = {
38  .arc_name = "ip4-unicast",
39  .node_name = "nat64-out2in",
40  .runs_before = VNET_FEATURES ("ip4-lookup"),
41 };
42 VNET_FEATURE_INIT (nat64_in2out_handoff, static) = {
43  .arc_name = "ip6-unicast",
44  .node_name = "nat64-in2out-handoff",
45  .runs_before = VNET_FEATURES ("ip6-lookup"),
46 };
47 VNET_FEATURE_INIT (nat64_out2in_handoff, static) = {
48  .arc_name = "ip4-unicast",
49  .node_name = "nat64-out2in-handoff",
50  .runs_before = VNET_FEATURES ("ip4-lookup"),
51 };
52 
53 
54 static u8 well_known_prefix[] = {
55  0x00, 0x64, 0xff, 0x9b,
56  0x00, 0x00, 0x00, 0x00,
57  0x00, 0x00, 0x00, 0x00,
58  0x00, 0x00, 0x00, 0x00
59 };
60 
61 /* *INDENT-ON* */
62 
63 static void
65  u32 sw_if_index,
66  ip4_address_t * address,
67  u32 address_length,
68  u32 if_address_index, u32 is_delete)
69 {
70  nat64_main_t *nm = &nat64_main;
71  int i, j;
72 
73  for (i = 0; i < vec_len (nm->auto_add_sw_if_indices); i++)
74  {
75  if (sw_if_index == nm->auto_add_sw_if_indices[i])
76  {
77  if (!is_delete)
78  {
79  /* Don't trip over lease renewal, static config */
80  for (j = 0; j < vec_len (nm->addr_pool); j++)
81  if (nm->addr_pool[j].addr.as_u32 == address->as_u32)
82  return;
83 
84  (void) nat64_add_del_pool_addr (address, ~0, 1);
85  return;
86  }
87  else
88  {
89  (void) nat64_add_del_pool_addr (address, ~0, 0);
90  return;
91  }
92  }
93  }
94 }
95 
96 u32
98 {
99  nat64_main_t *nm = &nat64_main;
100  snat_main_t *sm = nm->sm;
101  u32 next_worker_index = nm->sm->first_worker_index;
102  u32 hash;
103 
104 #ifdef clib_crc32c_uses_intrinsics
105  hash = clib_crc32c ((u8 *) addr->as_u32, 16);
106 #else
107  u64 tmp = addr->as_u64[0] ^ addr->as_u64[1];
108  hash = clib_xxhash (tmp);
109 #endif
110 
111  if (PREDICT_TRUE (is_pow2 (_vec_len (sm->workers))))
112  next_worker_index += sm->workers[hash & (_vec_len (sm->workers) - 1)];
113  else
114  next_worker_index += sm->workers[hash % _vec_len (sm->workers)];
115 
116  return next_worker_index;
117 }
118 
119 u32
121 {
122  nat64_main_t *nm = &nat64_main;
123  snat_main_t *sm = nm->sm;
124  udp_header_t *udp;
125  u16 port;
126  u32 proto;
127 
128  proto = ip_proto_to_snat_proto (ip->protocol);
129  udp = ip4_next_header (ip);
130  port = udp->dst_port;
131 
132  /* fragments */
133  if (PREDICT_FALSE (ip4_is_fragment (ip)))
134  {
136  return vlib_get_thread_index ();
137 
139  {
140  nat_reass_ip4_t *reass;
141 
142  reass = nat_ip4_reass_find (ip->src_address, ip->dst_address,
143  ip->fragment_id, ip->protocol);
144 
145  if (reass && (reass->thread_index != (u32) ~ 0))
146  return reass->thread_index;
147  else
148  return vlib_get_thread_index ();
149  }
150  }
151 
152  /* unknown protocol */
153  if (PREDICT_FALSE (proto == ~0))
154  {
155  nat64_db_t *db;
156  ip46_address_t daddr;
157  nat64_db_bib_entry_t *bibe;
158 
159  memset (&daddr, 0, sizeof (daddr));
160  daddr.ip4.as_u32 = ip->dst_address.as_u32;
161 
162  /* *INDENT-OFF* */
163  vec_foreach (db, nm->db)
164  {
165  bibe = nat64_db_bib_entry_find (db, &daddr, 0, ip->protocol, 0, 0);
166  if (bibe)
167  return (u32) (db - nm->db);
168  }
169  /* *INDENT-ON* */
170  return vlib_get_thread_index ();
171  }
172 
173  /* ICMP */
174  if (PREDICT_FALSE (ip->protocol == IP_PROTOCOL_ICMP))
175  {
176  icmp46_header_t *icmp = (icmp46_header_t *) udp;
177  icmp_echo_header_t *echo = (icmp_echo_header_t *) (icmp + 1);
178  if (!icmp_is_error_message (icmp))
179  port = echo->identifier;
180  else
181  {
182  ip4_header_t *inner_ip = (ip4_header_t *) (echo + 1);
183  proto = ip_proto_to_snat_proto (inner_ip->protocol);
184  void *l4_header = ip4_next_header (inner_ip);
185  switch (proto)
186  {
187  case SNAT_PROTOCOL_ICMP:
188  icmp = (icmp46_header_t *) l4_header;
189  echo = (icmp_echo_header_t *) (icmp + 1);
190  port = echo->identifier;
191  break;
192  case SNAT_PROTOCOL_UDP:
193  case SNAT_PROTOCOL_TCP:
194  port = ((tcp_udp_header_t *) l4_header)->src_port;
195  break;
196  default:
197  return vlib_get_thread_index ();
198  }
199  }
200  }
201 
202  /* worker by outside port (TCP/UDP) */
203  port = clib_net_to_host_u16 (port);
204  if (port > 1024)
205  return nm->sm->first_worker_index + ((port - 1024) / sm->port_per_thread);
206 
207  return vlib_get_thread_index ();
208 }
209 
210 clib_error_t *
212 {
213  nat64_main_t *nm = &nat64_main;
216  ip4_main_t *im = &ip4_main;
217  vlib_node_t *error_drop_node =
218  vlib_get_node_by_name (vm, (u8 *) "error-drop");
219 
220  vec_validate (nm->db, tm->n_vlib_mains - 1);
221 
222  nm->sm = &snat_main;
223 
224  nm->fq_in2out_index = ~0;
225  nm->fq_out2in_index = ~0;
226  nm->error_node_index = error_drop_node->index;
227 
228  /* set session timeouts to default values */
234 
235  nm->total_enabled_count = 0;
236 
237  /* Set up the interface address add/del callback */
239  cb4.function_opaque = 0;
241  nm->ip4_main = im;
242 
243  return 0;
244 }
245 
246 static void nat64_free_out_addr_and_port (struct nat64_db_s *db,
247  ip4_address_t * addr, u16 port,
248  u8 protocol);
249 
250 void
251 nat64_set_hash (u32 bib_buckets, u32 bib_memory_size, u32 st_buckets,
252  u32 st_memory_size)
253 {
254  nat64_main_t *nm = &nat64_main;
255  nat64_db_t *db;
256 
257  nm->bib_buckets = bib_buckets;
258  nm->bib_memory_size = bib_memory_size;
259  nm->st_buckets = st_buckets;
260  nm->st_memory_size = st_memory_size;
261 
262  /* *INDENT-OFF* */
263  vec_foreach (db, nm->db)
264  {
265  if (nat64_db_init (db, bib_buckets, bib_memory_size, st_buckets,
266  st_memory_size, nat64_free_out_addr_and_port))
267  clib_warning ("NAT64 DB init failed");
268  }
269  /* *INDENT-ON* */
270 }
271 
272 int
273 nat64_add_del_pool_addr (ip4_address_t * addr, u32 vrf_id, u8 is_add)
274 {
275  nat64_main_t *nm = &nat64_main;
276  snat_address_t *a = 0;
277  snat_interface_t *interface;
278  int i;
279  nat64_db_t *db;
281 
282  /* Check if address already exists */
283  for (i = 0; i < vec_len (nm->addr_pool); i++)
284  {
285  if (nm->addr_pool[i].addr.as_u32 == addr->as_u32)
286  {
287  a = nm->addr_pool + i;
288  break;
289  }
290  }
291 
292  if (is_add)
293  {
294  if (a)
295  return VNET_API_ERROR_VALUE_EXIST;
296 
297  vec_add2 (nm->addr_pool, a, 1);
298  a->addr = *addr;
299  a->fib_index = ~0;
300  if (vrf_id != ~0)
301  a->fib_index =
304 #define _(N, id, n, s) \
305  clib_bitmap_alloc (a->busy_##n##_port_bitmap, 65535); \
306  a->busy_##n##_ports = 0; \
307  vec_validate_init_empty (a->busy_##n##_ports_per_thread, tm->n_vlib_mains - 1, 0);
309 #undef _
310  }
311  else
312  {
313  if (!a)
314  return VNET_API_ERROR_NO_SUCH_ENTRY;
315 
316  if (a->fib_index != ~0)
319  /* Delete sessions using address */
320  /* *INDENT-OFF* */
321  vec_foreach (db, nm->db)
322  nat64_db_free_out_addr (db, &a->addr);
323 #define _(N, id, n, s) \
324  clib_bitmap_free (a->busy_##n##_port_bitmap);
326 #undef _
327  /* *INDENT-ON* */
328  vec_del1 (nm->addr_pool, i);
329  }
330 
331  /* Add/del external address to FIB */
332  /* *INDENT-OFF* */
333  pool_foreach (interface, nm->interfaces,
334  ({
335  if (nat_interface_is_inside(interface))
336  continue;
337 
338  snat_add_del_addr_to_fib (addr, 32, interface->sw_if_index, is_add);
339  break;
340  }));
341  /* *INDENT-ON* */
342 
343  return 0;
344 }
345 
346 void
348 {
349  nat64_main_t *nm = &nat64_main;
350  snat_address_t *a = 0;
351 
352  /* *INDENT-OFF* */
353  vec_foreach (a, nm->addr_pool)
354  {
355  if (fn (a, ctx))
356  break;
357  };
358  /* *INDENT-ON* */
359 }
360 
361 int
362 nat64_add_interface_address (u32 sw_if_index, int is_add)
363 {
364  nat64_main_t *nm = &nat64_main;
366  ip4_address_t *first_int_addr;
367  int i;
368 
369  first_int_addr = ip4_interface_first_address (ip4_main, sw_if_index, 0);
370 
371  for (i = 0; i < vec_len (nm->auto_add_sw_if_indices); i++)
372  {
373  if (nm->auto_add_sw_if_indices[i] == sw_if_index)
374  {
375  if (is_add)
376  return VNET_API_ERROR_VALUE_EXIST;
377  else
378  {
379  /* if have address remove it */
380  if (first_int_addr)
381  (void) nat64_add_del_pool_addr (first_int_addr, ~0, 0);
382 
384  return 0;
385  }
386  }
387  }
388 
389  if (!is_add)
390  return VNET_API_ERROR_NO_SUCH_ENTRY;
391 
392  /* add to the auto-address list */
393  vec_add1 (nm->auto_add_sw_if_indices, sw_if_index);
394 
395  /* If the address is already bound - or static - add it now */
396  if (first_int_addr)
397  (void) nat64_add_del_pool_addr (first_int_addr, ~0, 1);
398 
399  return 0;
400 }
401 
402 int
403 nat64_add_del_interface (u32 sw_if_index, u8 is_inside, u8 is_add)
404 {
405  nat64_main_t *nm = &nat64_main;
406  snat_interface_t *interface = 0, *i;
407  snat_address_t *ap;
408  const char *feature_name, *arc_name;
409 
410  /* Check if interface already exists */
411  /* *INDENT-OFF* */
412  pool_foreach (i, nm->interfaces,
413  ({
414  if (i->sw_if_index == sw_if_index)
415  {
416  interface = i;
417  break;
418  }
419  }));
420  /* *INDENT-ON* */
421 
422  if (is_add)
423  {
424  if (interface)
425  goto set_flags;
426 
427  pool_get (nm->interfaces, interface);
428  interface->sw_if_index = sw_if_index;
429  interface->flags = 0;
430  set_flags:
431  if (is_inside)
432  interface->flags |= NAT_INTERFACE_FLAG_IS_INSIDE;
433  else
434  interface->flags |= NAT_INTERFACE_FLAG_IS_OUTSIDE;
435 
436  nm->total_enabled_count++;
437  vlib_process_signal_event (nm->sm->vlib_main,
438  nm->nat64_expire_walk_node_index,
440 
441  }
442  else
443  {
444  if (!interface)
445  return VNET_API_ERROR_NO_SUCH_ENTRY;
446 
447  if ((nat_interface_is_inside (interface)
448  && nat_interface_is_outside (interface)))
449  interface->flags &=
450  is_inside ? ~NAT_INTERFACE_FLAG_IS_INSIDE :
452  else
453  pool_put (nm->interfaces, interface);
454 
455  nm->total_enabled_count--;
456  }
457 
458  if (!is_inside)
459  {
460  /* *INDENT-OFF* */
461  vec_foreach (ap, nm->addr_pool)
462  snat_add_del_addr_to_fib(&ap->addr, 32, sw_if_index, is_add);
463  /* *INDENT-ON* */
464  }
465 
466  if (nm->sm->num_workers > 1)
467  {
468  feature_name =
469  is_inside ? "nat64-in2out-handoff" : "nat64-out2in-handoff";
470  if (nm->fq_in2out_index == ~0)
471  nm->fq_in2out_index =
473  if (nm->fq_out2in_index == ~0)
474  nm->fq_out2in_index =
476  }
477  else
478  feature_name = is_inside ? "nat64-in2out" : "nat64-out2in";
479 
480  arc_name = is_inside ? "ip6-unicast" : "ip4-unicast";
481 
482  return vnet_feature_enable_disable (arc_name, feature_name, sw_if_index,
483  is_add, 0, 0);
484 }
485 
486 void
488 {
489  nat64_main_t *nm = &nat64_main;
490  snat_interface_t *i = 0;
491 
492  /* *INDENT-OFF* */
493  pool_foreach (i, nm->interfaces,
494  ({
495  if (fn (i, ctx))
496  break;
497  }));
498  /* *INDENT-ON* */
499 }
500 
501 int
503  ip4_address_t * addr, u16 * port,
504  u32 thread_index)
505 {
506  nat64_main_t *nm = &nat64_main;
507  snat_main_t *sm = nm->sm;
509  u32 ai;
510  u32 worker_index = 0;
511  int rv;
512 
513  k.protocol = proto;
514 
515  if (sm->num_workers > 1)
516  worker_index = thread_index - sm->first_worker_index;
517 
518  rv =
519  sm->alloc_addr_and_port (nm->addr_pool, fib_index, thread_index, &k, &ai,
520  sm->port_per_thread, worker_index);
521 
522  if (!rv)
523  {
524  *port = k.port;
525  addr->as_u32 = k.addr.as_u32;
526  }
527 
528  return rv;
529 }
530 
531 static void
533  u16 port, u8 protocol)
534 {
535  nat64_main_t *nm = &nat64_main;
536  int i;
537  snat_address_t *a;
538  u32 thread_index = db - nm->db;
539  snat_protocol_t proto = ip_proto_to_snat_proto (protocol);
540  u16 port_host_byte_order = clib_net_to_host_u16 (port);
541 
542  for (i = 0; i < vec_len (nm->addr_pool); i++)
543  {
544  a = nm->addr_pool + i;
545  if (addr->as_u32 != a->addr.as_u32)
546  continue;
547  switch (proto)
548  {
549 #define _(N, j, n, s) \
550  case SNAT_PROTOCOL_##N: \
551  ASSERT (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \
552  port_host_byte_order) == 1); \
553  clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, port, 0); \
554  a->busy_##n##_ports--; \
555  a->busy_##n##_ports_per_thread[thread_index]--; \
556  break;
558 #undef _
559  default:
560  clib_warning ("unknown protocol");
561  return;
562  }
563  break;
564  }
565 }
566 
567 /**
568  * @brief Add/delete static BIB entry in worker thread.
569  */
570 static uword
572  vlib_frame_t * f)
573 {
574  nat64_main_t *nm = &nat64_main;
575  u32 thread_index = vlib_get_thread_index ();
576  nat64_db_t *db = &nm->db[thread_index];
577  nat64_static_bib_to_update_t *static_bib;
578  nat64_db_bib_entry_t *bibe;
579  ip46_address_t addr;
580 
581  /* *INDENT-OFF* */
582  pool_foreach (static_bib, nm->static_bibs,
583  ({
584  if ((static_bib->thread_index != thread_index) || (static_bib->done))
585  continue;
586 
587  if (static_bib->is_add)
588  (void) nat64_db_bib_entry_create (db, &static_bib->in_addr,
589  &static_bib->out_addr,
590  static_bib->in_port,
591  static_bib->out_port,
592  static_bib->fib_index,
593  static_bib->proto, 1);
594  else
595  {
596  addr.as_u64[0] = static_bib->in_addr.as_u64[0];
597  addr.as_u64[1] = static_bib->in_addr.as_u64[1];
598  bibe = nat64_db_bib_entry_find (db, &addr, static_bib->in_port,
599  static_bib->proto,
600  static_bib->fib_index, 1);
601  if (bibe)
602  nat64_db_bib_entry_free (db, bibe);
603  }
604 
605  static_bib->done = 1;
606  }));
607  /* *INDENT-ON* */
608 
609  return 0;
610 }
611 
613 
614 /* *INDENT-OFF* */
615 VLIB_REGISTER_NODE (nat64_static_bib_worker_node, static) = {
616  .function = nat64_static_bib_worker_fn,
617  .type = VLIB_NODE_TYPE_INPUT,
618  .state = VLIB_NODE_STATE_INTERRUPT,
619  .name = "nat64-static-bib-worker",
620 };
621 /* *INDENT-ON* */
622 
623 int
625  ip4_address_t * out_addr, u16 in_port,
626  u16 out_port, u8 proto, u32 vrf_id, u8 is_add)
627 {
628  nat64_main_t *nm = &nat64_main;
629  nat64_db_bib_entry_t *bibe;
633  ip46_address_t addr;
634  int i;
635  snat_address_t *a;
636  u32 thread_index = 0;
637  nat64_db_t *db;
638  nat64_static_bib_to_update_t *static_bib;
639  vlib_main_t *worker_vm;
640  u32 *to_be_free = 0, *index;
641 
642  if (nm->sm->num_workers > 1)
643  {
644  thread_index = nat64_get_worker_in2out (in_addr);
645  db = &nm->db[thread_index];
646  }
647  else
648  db = &nm->db[nm->sm->num_workers];
649 
650  addr.as_u64[0] = in_addr->as_u64[0];
651  addr.as_u64[1] = in_addr->as_u64[1];
652  bibe =
653  nat64_db_bib_entry_find (db, &addr, clib_host_to_net_u16 (in_port),
654  proto, fib_index, 1);
655 
656  if (is_add)
657  {
658  if (bibe)
659  return VNET_API_ERROR_VALUE_EXIST;
660 
661  /* outside port must be assigned to same thread as internall address */
662  if ((out_port > 1024) && (nm->sm->num_workers > 1))
663  {
664  if (thread_index != ((out_port - 1024) / nm->sm->port_per_thread))
665  return VNET_API_ERROR_INVALID_VALUE_2;
666  }
667 
668  for (i = 0; i < vec_len (nm->addr_pool); i++)
669  {
670  a = nm->addr_pool + i;
671  if (out_addr->as_u32 != a->addr.as_u32)
672  continue;
673  switch (p)
674  {
675 #define _(N, j, n, s) \
676  case SNAT_PROTOCOL_##N: \
677  if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \
678  out_port)) \
679  return VNET_API_ERROR_INVALID_VALUE; \
680  clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \
681  out_port, 1); \
682  if (out_port > 1024) \
683  { \
684  a->busy_##n##_ports++; \
685  a->busy_##n##_ports_per_thread[thread_index]++; \
686  } \
687  break;
689 #undef _
690  default:
691  memset (&addr, 0, sizeof (addr));
692  addr.ip4.as_u32 = out_addr->as_u32;
693  if (nat64_db_bib_entry_find (db, &addr, 0, proto, fib_index, 0))
694  return VNET_API_ERROR_INVALID_VALUE;
695  }
696  break;
697  }
698  if (!nm->sm->num_workers)
699  {
700  bibe =
701  nat64_db_bib_entry_create (db, in_addr, out_addr,
702  clib_host_to_net_u16 (in_port),
703  clib_host_to_net_u16 (out_port),
704  fib_index, proto, 1);
705  if (!bibe)
706  return VNET_API_ERROR_UNSPECIFIED;
707  }
708  }
709  else
710  {
711  if (!bibe)
712  return VNET_API_ERROR_NO_SUCH_ENTRY;
713 
714  if (!nm->sm->num_workers)
715  nat64_db_bib_entry_free (db, bibe);
716  }
717 
718  if (nm->sm->num_workers)
719  {
720  /* *INDENT-OFF* */
721  pool_foreach (static_bib, nm->static_bibs,
722  ({
723  if (static_bib->done)
724  vec_add1 (to_be_free, static_bib - nm->static_bibs);
725  }));
726  vec_foreach (index, to_be_free)
727  pool_put_index (nm->static_bibs, index[0]);
728  /* *INDENT-ON* */
729  vec_free (to_be_free);
730  pool_get (nm->static_bibs, static_bib);
731  static_bib->in_addr.as_u64[0] = in_addr->as_u64[0];
732  static_bib->in_addr.as_u64[1] = in_addr->as_u64[1];
733  static_bib->in_port = clib_host_to_net_u16 (in_port);
734  static_bib->out_addr.as_u32 = out_addr->as_u32;
735  static_bib->out_port = clib_host_to_net_u16 (out_port);
736  static_bib->fib_index = fib_index;
737  static_bib->proto = proto;
738  static_bib->is_add = is_add;
739  static_bib->thread_index = thread_index;
740  static_bib->done = 0;
741  worker_vm = vlib_mains[thread_index];
742  if (worker_vm)
744  nat64_static_bib_worker_node.index);
745  else
746  return VNET_API_ERROR_UNSPECIFIED;
747  }
748 
749  return 0;
750 }
751 
752 int
754 {
755  nat64_main_t *nm = &nat64_main;
756 
757  if (timeout == 0)
759  else if (timeout < SNAT_UDP_TIMEOUT_MIN)
760  return VNET_API_ERROR_INVALID_VALUE;
761  else
762  nm->udp_timeout = timeout;
763 
764  return 0;
765 }
766 
767 u32
769 {
770  nat64_main_t *nm = &nat64_main;
771 
772  return nm->udp_timeout;
773 }
774 
775 int
777 {
778  nat64_main_t *nm = &nat64_main;
779 
780  if (timeout == 0)
782  else
783  nm->icmp_timeout = timeout;
784 
785  return 0;
786 }
787 
788 u32
790 {
791  nat64_main_t *nm = &nat64_main;
792 
793  return nm->icmp_timeout;
794 }
795 
796 int
797 nat64_set_tcp_timeouts (u32 trans, u32 est, u32 incoming_syn)
798 {
799  nat64_main_t *nm = &nat64_main;
800 
801  if (trans == 0)
803  else
804  nm->tcp_trans_timeout = trans;
805 
806  if (est == 0)
808  else
809  nm->tcp_est_timeout = est;
810 
811  if (incoming_syn == 0)
813  else
814  nm->tcp_incoming_syn_timeout = incoming_syn;
815 
816  return 0;
817 }
818 
819 u32
821 {
822  nat64_main_t *nm = &nat64_main;
823 
824  return nm->tcp_trans_timeout;
825 }
826 
827 u32
829 {
830  nat64_main_t *nm = &nat64_main;
831 
832  return nm->tcp_est_timeout;
833 }
834 
835 u32
837 {
838  nat64_main_t *nm = &nat64_main;
839 
840  return nm->tcp_incoming_syn_timeout;
841 }
842 
843 void
844 nat64_session_reset_timeout (nat64_db_st_entry_t * ste, vlib_main_t * vm)
845 {
846  nat64_main_t *nm = &nat64_main;
847  u32 now = (u32) vlib_time_now (vm);
848 
849  switch (ip_proto_to_snat_proto (ste->proto))
850  {
851  case SNAT_PROTOCOL_ICMP:
852  ste->expire = now + nm->icmp_timeout;
853  return;
854  case SNAT_PROTOCOL_TCP:
855  {
856  switch (ste->tcp_state)
857  {
858  case NAT64_TCP_STATE_V4_INIT:
859  case NAT64_TCP_STATE_V6_INIT:
860  case NAT64_TCP_STATE_V4_FIN_RCV:
861  case NAT64_TCP_STATE_V6_FIN_RCV:
862  case NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV:
863  case NAT64_TCP_STATE_TRANS:
864  ste->expire = now + nm->tcp_trans_timeout;
865  return;
866  case NAT64_TCP_STATE_ESTABLISHED:
867  ste->expire = now + nm->tcp_est_timeout;
868  return;
869  default:
870  return;
871  }
872  }
873  case SNAT_PROTOCOL_UDP:
874  ste->expire = now + nm->udp_timeout;
875  return;
876  default:
877  ste->expire = now + nm->udp_timeout;
878  return;
879  }
880 }
881 
882 void
883 nat64_tcp_session_set_state (nat64_db_st_entry_t * ste, tcp_header_t * tcp,
884  u8 is_ip6)
885 {
886  switch (ste->tcp_state)
887  {
888  case NAT64_TCP_STATE_CLOSED:
889  {
890  if (tcp->flags & TCP_FLAG_SYN)
891  {
892  if (is_ip6)
893  ste->tcp_state = NAT64_TCP_STATE_V6_INIT;
894  else
895  ste->tcp_state = NAT64_TCP_STATE_V4_INIT;
896  }
897  return;
898  }
899  case NAT64_TCP_STATE_V4_INIT:
900  {
901  if (is_ip6 && (tcp->flags & TCP_FLAG_SYN))
902  ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
903  return;
904  }
905  case NAT64_TCP_STATE_V6_INIT:
906  {
907  if (!is_ip6 && (tcp->flags & TCP_FLAG_SYN))
908  ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
909  return;
910  }
911  case NAT64_TCP_STATE_ESTABLISHED:
912  {
913  if (tcp->flags & TCP_FLAG_FIN)
914  {
915  if (is_ip6)
916  ste->tcp_state = NAT64_TCP_STATE_V6_FIN_RCV;
917  else
918  ste->tcp_state = NAT64_TCP_STATE_V4_FIN_RCV;
919  }
920  else if (tcp->flags & TCP_FLAG_RST)
921  {
922  ste->tcp_state = NAT64_TCP_STATE_TRANS;
923  }
924  return;
925  }
926  case NAT64_TCP_STATE_V4_FIN_RCV:
927  {
928  if (is_ip6 && (tcp->flags & TCP_FLAG_FIN))
929  ste->tcp_state = NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV;
930  return;
931  }
932  case NAT64_TCP_STATE_V6_FIN_RCV:
933  {
934  if (!is_ip6 && (tcp->flags & TCP_FLAG_FIN))
935  ste->tcp_state = NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV;
936  return;
937  }
938  case NAT64_TCP_STATE_TRANS:
939  {
940  if (!(tcp->flags & TCP_FLAG_RST))
941  ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
942  return;
943  }
944  default:
945  return;
946  }
947 }
948 
949 int
950 nat64_add_del_prefix (ip6_address_t * prefix, u8 plen, u32 vrf_id, u8 is_add)
951 {
952  nat64_main_t *nm = &nat64_main;
953  nat64_prefix_t *p = 0;
954  int i;
955 
956  /* Verify prefix length */
957  if (plen != 32 && plen != 40 && plen != 48 && plen != 56 && plen != 64
958  && plen != 96)
959  return VNET_API_ERROR_INVALID_VALUE;
960 
961  /* Check if tenant already have prefix */
962  for (i = 0; i < vec_len (nm->pref64); i++)
963  {
964  if (nm->pref64[i].vrf_id == vrf_id)
965  {
966  p = nm->pref64 + i;
967  break;
968  }
969  }
970 
971  if (is_add)
972  {
973  if (!p)
974  {
975  vec_add2 (nm->pref64, p, 1);
976  p->fib_index =
979  p->vrf_id = vrf_id;
980  }
981 
982  p->prefix.as_u64[0] = prefix->as_u64[0];
983  p->prefix.as_u64[1] = prefix->as_u64[1];
984  p->plen = plen;
985  }
986  else
987  {
988  if (!p)
989  return VNET_API_ERROR_NO_SUCH_ENTRY;
990 
991  vec_del1 (nm->pref64, i);
992  }
993 
994  return 0;
995 }
996 
997 void
999 {
1000  nat64_main_t *nm = &nat64_main;
1001  nat64_prefix_t *p = 0;
1002 
1003  /* *INDENT-OFF* */
1004  vec_foreach (p, nm->pref64)
1005  {
1006  if (fn (p, ctx))
1007  break;
1008  };
1009  /* *INDENT-ON* */
1010 }
1011 
1012 void
1014 {
1015  nat64_main_t *nm = &nat64_main;
1016  nat64_prefix_t *p, *gp = 0, *prefix = 0;
1017 
1018  /* *INDENT-OFF* */
1019  vec_foreach (p, nm->pref64)
1020  {
1021  if (p->fib_index == fib_index)
1022  {
1023  prefix = p;
1024  break;
1025  }
1026 
1027  if (p->fib_index == 0)
1028  gp = p;
1029  };
1030  /* *INDENT-ON* */
1031 
1032  if (!prefix)
1033  prefix = gp;
1034 
1035  if (prefix)
1036  {
1037  clib_memcpy (ip6, &p->prefix, sizeof (ip6_address_t));
1038  switch (p->plen)
1039  {
1040  case 32:
1041  ip6->as_u32[1] = ip4->as_u32;
1042  break;
1043  case 40:
1044  ip6->as_u8[5] = ip4->as_u8[0];
1045  ip6->as_u8[6] = ip4->as_u8[1];
1046  ip6->as_u8[7] = ip4->as_u8[2];
1047  ip6->as_u8[9] = ip4->as_u8[3];
1048  break;
1049  case 48:
1050  ip6->as_u8[6] = ip4->as_u8[0];
1051  ip6->as_u8[7] = ip4->as_u8[1];
1052  ip6->as_u8[9] = ip4->as_u8[2];
1053  ip6->as_u8[10] = ip4->as_u8[3];
1054  break;
1055  case 56:
1056  ip6->as_u8[7] = ip4->as_u8[0];
1057  ip6->as_u8[9] = ip4->as_u8[1];
1058  ip6->as_u8[10] = ip4->as_u8[2];
1059  ip6->as_u8[11] = ip4->as_u8[3];
1060  break;
1061  case 64:
1062  ip6->as_u8[9] = ip4->as_u8[0];
1063  ip6->as_u8[10] = ip4->as_u8[1];
1064  ip6->as_u8[11] = ip4->as_u8[2];
1065  ip6->as_u8[12] = ip4->as_u8[3];
1066  break;
1067  case 96:
1068  ip6->as_u32[3] = ip4->as_u32;
1069  break;
1070  default:
1071  clib_warning ("invalid prefix length");
1072  break;
1073  }
1074  }
1075  else
1076  {
1077  clib_memcpy (ip6, well_known_prefix, sizeof (ip6_address_t));
1078  ip6->as_u32[3] = ip4->as_u32;
1079  }
1080 }
1081 
1082 void
1084 {
1085  nat64_main_t *nm = &nat64_main;
1086  nat64_prefix_t *p, *gp = 0;
1087  u8 plen = 0;
1088 
1089  /* *INDENT-OFF* */
1090  vec_foreach (p, nm->pref64)
1091  {
1092  if (p->fib_index == fib_index)
1093  {
1094  plen = p->plen;
1095  break;
1096  }
1097 
1098  if (p->vrf_id == 0)
1099  gp = p;
1100  };
1101  /* *INDENT-ON* */
1102 
1103  if (!plen)
1104  {
1105  if (gp)
1106  plen = gp->plen;
1107  else
1108  plen = 96;
1109  }
1110 
1111  switch (plen)
1112  {
1113  case 32:
1114  ip4->as_u32 = ip6->as_u32[1];
1115  break;
1116  case 40:
1117  ip4->as_u8[0] = ip6->as_u8[5];
1118  ip4->as_u8[1] = ip6->as_u8[6];
1119  ip4->as_u8[2] = ip6->as_u8[7];
1120  ip4->as_u8[3] = ip6->as_u8[9];
1121  break;
1122  case 48:
1123  ip4->as_u8[0] = ip6->as_u8[6];
1124  ip4->as_u8[1] = ip6->as_u8[7];
1125  ip4->as_u8[2] = ip6->as_u8[9];
1126  ip4->as_u8[3] = ip6->as_u8[10];
1127  break;
1128  case 56:
1129  ip4->as_u8[0] = ip6->as_u8[7];
1130  ip4->as_u8[1] = ip6->as_u8[9];
1131  ip4->as_u8[2] = ip6->as_u8[10];
1132  ip4->as_u8[3] = ip6->as_u8[11];
1133  break;
1134  case 64:
1135  ip4->as_u8[0] = ip6->as_u8[9];
1136  ip4->as_u8[1] = ip6->as_u8[10];
1137  ip4->as_u8[2] = ip6->as_u8[11];
1138  ip4->as_u8[3] = ip6->as_u8[12];
1139  break;
1140  case 96:
1141  ip4->as_u32 = ip6->as_u32[3];
1142  break;
1143  default:
1144  clib_warning ("invalid prefix length");
1145  break;
1146  }
1147 }
1148 
1149 /**
1150  * @brief Per worker process checking expire time for NAT64 sessions.
1151  */
1152 static uword
1154  vlib_frame_t * f)
1155 {
1156  nat64_main_t *nm = &nat64_main;
1157  u32 thread_index = vlib_get_thread_index ();
1158  nat64_db_t *db = &nm->db[thread_index];
1159  u32 now = (u32) vlib_time_now (vm);
1160 
1161  nad64_db_st_free_expired (db, now);
1162 
1163  return 0;
1164 }
1165 
1167 
1168 /* *INDENT-OFF* */
1169 VLIB_REGISTER_NODE (nat64_expire_worker_walk_node, static) = {
1170  .function = nat64_expire_worker_walk_fn,
1171  .type = VLIB_NODE_TYPE_INPUT,
1172  .state = VLIB_NODE_STATE_INTERRUPT,
1173  .name = "nat64-expire-worker-walk",
1174 };
1175 /* *INDENT-ON* */
1176 
1178 
1179 /**
1180  * @brief Centralized process to drive per worker expire walk.
1181  */
1182 static uword
1184  vlib_frame_t * f)
1185 {
1186  nat64_main_t *nm = &nat64_main;
1187  vlib_main_t **worker_vms = 0, *worker_vm;
1188  int i;
1189  uword event_type, *event_data = 0;
1190 
1191  nm->nat64_expire_walk_node_index = nat64_expire_walk_node.index;
1192 
1193  if (vec_len (vlib_mains) == 0)
1194  vec_add1 (worker_vms, vm);
1195  else
1196  {
1197  for (i = 0; i < vec_len (vlib_mains); i++)
1198  {
1199  worker_vm = vlib_mains[i];
1200  if (worker_vm)
1201  vec_add1 (worker_vms, worker_vm);
1202  }
1203  }
1204 
1205  while (1)
1206  {
1207  if (nm->total_enabled_count)
1208  {
1210  event_type = vlib_process_get_events (vm, &event_data);
1211  }
1212  else
1213  {
1215  event_type = vlib_process_get_events (vm, &event_data);
1216  }
1217 
1218  switch (event_type)
1219  {
1220  case ~0:
1221  break;
1223  break;
1224  default:
1225  clib_warning ("unknown event %u", event_type);
1226  break;
1227  }
1228 
1229  for (i = 0; i < vec_len (worker_vms); i++)
1230  {
1231  worker_vm = worker_vms[i];
1233  nat64_expire_worker_walk_node.index);
1234  }
1235  }
1236 
1237  return 0;
1238 }
1239 
1240 /* *INDENT-OFF* */
1241 VLIB_REGISTER_NODE (nat64_expire_walk_node, static) = {
1242  .function = nat64_expire_walk_fn,
1243  .type = VLIB_NODE_TYPE_PROCESS,
1244  .name = "nat64-expire-walk",
1245 };
1246 /* *INDENT-ON* */
1247 
1248 /*
1249  * fd.io coding-style-patch-verification: ON
1250  *
1251  * Local Variables:
1252  * eval: (c-set-style "gnu")
1253  * End:
1254  */
u32 nat64_get_icmp_timeout(void)
Get ICMP session timeout.
Definition: nat64.c:789
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:432
nat64_db_t * db
BIB and session DB per thread.
Definition: nat64.h:83
u32 icmp_timeout
Definition: nat64.h:102
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
int nat64_db_init(nat64_db_t *db, u32 bib_buckets, u32 bib_memory_size, u32 st_buckets, u32 st_memory_size, nat64_db_free_addr_port_function_t free_addr_port_cb)
Initialize NAT64 DB.
Definition: nat64_db.c:22
int nat64_set_udp_timeout(u32 timeout)
Set UDP session timeout.
Definition: nat64.c:753
ip4_add_del_interface_address_callback_t * add_del_interface_address_callbacks
Functions to call when interface address changes.
Definition: ip4.h:129
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:699
a
Definition: bitmap.h:516
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:619
ip4_address_t src_address
Definition: ip4_packet.h:164
ip6_address_t prefix
Definition: nat64.h:49
snat_address_t * addr_pool
Address pool vector.
Definition: nat64.h:74
#define TCP_FLAG_SYN
Definition: fa_node.h:8
void nat64_extract_ip4(ip6_address_t *ip6, ip4_address_t *ip4, u32 fib_index)
Extract IPv4 address from the IPv4-embedded IPv6 addresses.
Definition: nat64.c:1083
#define SNAT_TCP_ESTABLISHED_TIMEOUT
Definition: nat.h:36
#define PREDICT_TRUE(x)
Definition: clib.h:106
u8 as_u8[16]
Definition: ip6_packet.h:48
u64 as_u64[2]
Definition: ip6_packet.h:51
u32 st_buckets
Definition: nat64.h:97
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
Definition: node_funcs.h:196
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:403
u32 nat64_expire_walk_node_index
Definition: nat64.h:110
u32 index
Definition: node.h:237
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip4_forward.c:690
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:224
nat64_db_bib_entry_t * nat64_db_bib_entry_create(nat64_db_t *db, ip6_address_t *in_addr, ip4_address_t *out_addr, u16 in_port, u16 out_port, u32 fib_index, u8 proto, u8 is_static)
Create new NAT64 BIB entry.
Definition: nat64_db.c:43
u16 port_per_thread
Definition: nat.h:301
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
Definition: threads.c:1748
nat_reass_ip4_t * nat_ip4_reass_find(ip4_address_t src, ip4_address_t dst, u16 frag_id, u8 proto)
Find reassembly.
Definition: nat_reass.c:198
int nat64_add_del_pool_addr(ip4_address_t *addr, u32 vrf_id, u8 is_add)
Add/delete address to NAT64 pool.
Definition: nat64.c:273
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:518
nat64_db_bib_entry_t * nat64_db_bib_entry_find(nat64_db_t *db, ip46_address_t *addr, u16 port, u8 proto, u32 fib_index, u8 is_ip6)
Find NAT64 BIB entry.
Definition: nat64_db.c:172
u32 bib_memory_size
Definition: nat64.h:96
static u64 clib_xxhash(u64 key)
Definition: xxhash.h:58
struct _vlib_node_registration vlib_node_registration_t
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:557
#define NAT_INTERFACE_FLAG_IS_OUTSIDE
Definition: nat.h:134
void nat64_set_hash(u32 bib_buckets, u32 bib_memory_size, u32 st_buckets, u32 st_memory_size)
Set NAT64 hash tables configuration.
Definition: nat64.c:251
u32 tcp_trans_timeout
Definition: nat64.h:103
void snat_add_del_addr_to_fib(ip4_address_t *addr, u8 p_len, u32 sw_if_index, int is_add)
Add/del NAT address to FIB.
Definition: nat.c:499
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
Definition: nat.h:322
int nat64_add_interface_address(u32 sw_if_index, int is_add)
NAT64 pool address from specific (DHCP addressed) interface.
Definition: nat64.c:362
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:225
struct _tcp_header tcp_header_t
u32 * auto_add_sw_if_indices
sw_if_indices whose interface addresses should be auto-added
Definition: nat64.h:77
int nat64_set_tcp_timeouts(u32 trans, u32 est, u32 incoming_syn)
Set TCP session timeouts.
Definition: nat64.c:797
vlib_main_t ** vlib_mains
Definition: buffer.c:292
u16 identifier
Definition: nat.h:474
#define nat_interface_is_outside(i)
Definition: nat.h:465
static void nat64_ip4_add_del_interface_address_cb(ip4_main_t *im, uword opaque, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 if_address_index, u32 is_delete)
Definition: nat64.c:64
u32 nat64_get_worker_in2out(ip6_address_t *addr)
Get worker thread index for NAT64 in2out.
Definition: nat64.c:97
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:438
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:542
ip4_address_t dst_address
Definition: ip4_packet.h:164
u32 total_enabled_count
Definition: nat64.h:108
int nat64_set_icmp_timeout(u32 timeout)
Set ICMP session timeout.
Definition: nat64.c:776
A high priority source a plugin can use.
Definition: fib_entry.h:62
u32 tcp_est_timeout
Definition: nat64.h:104
unsigned long u64
Definition: types.h:89
static void * ip4_next_header(ip4_header_t *i)
Definition: ip4_packet.h:233
snat_main_t * sm
Definition: nat64.h:113
vlib_node_registration_t nat64_in2out_node
(constructor) VLIB_REGISTER_NODE (nat64_in2out_node)
void nat64_tcp_session_set_state(nat64_db_st_entry_t *ste, tcp_header_t *tcp, u8 is_ip6)
Set NAT64 TCP session state.
Definition: nat64.c:883
snat_interface_t * interfaces
Interface pool.
Definition: nat64.h:71
u32 tcp_incoming_syn_timeout
Definition: nat64.h:105
static int ip4_is_fragment(ip4_header_t *i)
Definition: ip4_packet.h:205
u32 fib_index
Definition: nat64.h:52
u32 udp_timeout
values of various timeouts
Definition: nat64.h:101
u32 nat64_get_worker_out2in(ip4_header_t *ip)
Get worker thread index for NAT64 out2in.
Definition: nat64.c:120
ip4_address_t out_addr
Definition: nat64.h:59
nat64_prefix_t * pref64
Pref64 vector.
Definition: nat64.h:80
ip6_address_t in_addr
Definition: nat64.h:57
u32 st_memory_size
Definition: nat64.h:98
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:950
void nat64_session_reset_timeout(nat64_db_st_entry_t *ste, vlib_main_t *vm)
Reset NAT64 session timeout.
Definition: nat64.c:844
void nad64_db_st_free_expired(nat64_db_t *db, u32 now)
Free expired session entries in session tables.
Definition: nat64_db.c:578
int nat64_alloc_out_addr_and_port(u32 fib_index, snat_protocol_t proto, ip4_address_t *addr, u16 *port, u32 thread_index)
Alloce IPv4 address and port pair from NAT64 pool.
Definition: nat64.c:502
u32 nat64_get_udp_timeout(void)
Get UDP session timeout.
Definition: nat64.c:768
u16 protocol
Definition: nat.h:50
#define SNAT_UDP_TIMEOUT
Definition: nat.h:33
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:271
void nat64_db_bib_entry_free(nat64_db_t *db, nat64_db_bib_entry_t *bibe)
Free NAT64 BIB entry.
Definition: nat64_db.c:104
#define PREDICT_FALSE(x)
Definition: clib.h:105
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:801
static uword nat64_expire_walk_fn(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Centralized process to drive per worker expire walk.
Definition: nat64.c:1183
#define nat_interface_is_inside(i)
Definition: nat.h:464
#define TCP_FLAG_FIN
Definition: fa_node.h:7
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:1180
void nat64_compose_ip6(ip6_address_t *ip6, ip4_address_t *ip4, u32 fib_index)
Compose IPv4-embedded IPv6 addresses.
Definition: nat64.c:1013
#define TCP_FLAG_RST
Definition: fa_node.h:9
static u8 well_known_prefix[]
Definition: nat64.c:54
snat_main_t snat_main
Definition: nat.c:33
u32 as_u32[4]
Definition: ip6_packet.h:50
u32 nat64_get_tcp_est_timeout(void)
Get TCP established timeout.
Definition: nat64.c:828
vlib_node_registration_t nat64_out2in_node
(constructor) VLIB_REGISTER_NODE (nat64_out2in_node)
Definition: nat64_out2in.c:524
void nat64_pool_addr_walk(nat64_pool_addr_walk_fn_t fn, void *ctx)
Walk NAT64 pool.
Definition: nat64.c:347
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:221
u8 nat_reass_is_drop_frag(u8 is_ip6)
Get status of virtual fragmentation reassembly.
Definition: nat_reass.c:167
vlib_main_t * vm
Definition: buffer.c:283
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
ip4_add_del_interface_address_function_t * function
Definition: ip4.h:72
int nat64_add_del_prefix(ip6_address_t *prefix, u8 plen, u32 vrf_id, u8 is_add)
Add/delete NAT64 prefix.
Definition: nat64.c:950
u32 bib_buckets
config parameters
Definition: nat64.h:95
#define clib_warning(format, args...)
Definition: error.h:59
#define clib_memcpy(a, b, c)
Definition: string.h:75
static int ip4_is_first_fragment(ip4_header_t *i)
Definition: ip4_packet.h:212
ip4_address_t addr
Definition: nat.h:48
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
nat64_main_t nat64_main
Definition: nat64.c:27
u32 fq_out2in_index
Definition: nat64.h:87
u32 vrf_id
Definition: nat64.h:51
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:294
#define NAT_INTERFACE_FLAG_IS_INSIDE
Definition: nat.h:133
u32 num_workers
Definition: nat.h:295
unsigned int u32
Definition: types.h:88
u32 first_worker_index
Definition: nat.h:296
u32 nat64_get_tcp_incoming_syn_timeout(void)
Get TCP incoming SYN timeout.
Definition: nat64.c:836
u32 fq_in2out_index
Worker handoff.
Definition: nat64.h:86
long ctx[MAX_CONNS]
Definition: main.c:122
nat64_static_bib_to_update_t * static_bibs
Pool of static BIB entries to be added/deleted in worker threads.
Definition: nat64.h:90
static u32 ip_proto_to_snat_proto(u8 ip_proto)
Definition: nat.h:479
IPv4 main type.
Definition: ip4.h:95
static void nat64_free_out_addr_and_port(struct nat64_db_s *db, ip4_address_t *addr, u16 port, u8 protocol)
Definition: nat64.c:532
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:1087
static uword nat64_expire_worker_walk_fn(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Per worker process checking expire time for NAT64 sessions.
Definition: nat64.c:1153
ip4_address_t addr
Definition: nat.h:177
#define VNET_FEATURES(...)
Definition: feature.h:368
void nat64_prefix_walk(nat64_prefix_walk_fn_t fn, void *ctx)
Walk NAT64 prefixes.
Definition: nat64.c:998
static uword is_pow2(uword x)
Definition: clib.h:280
u64 uword
Definition: types.h:112
void nat64_interfaces_walk(nat64_interface_walk_fn_t fn, void *ctx)
Walk NAT64 interfaces.
Definition: nat64.c:487
void nat64_db_free_out_addr(nat64_db_t *db, ip4_address_t *out_addr)
Free sessions using specific outside address.
Definition: nat64_db.c:610
clib_error_t * nat64_init(vlib_main_t *vm)
Initialize NAT64.
Definition: nat64.c:211
NAT64 global declarations.
ip4_main_t * ip4_main
Definition: nat64.h:112
static vlib_node_registration_t nat64_expire_walk_node
(constructor) VLIB_REGISTER_NODE (nat64_expire_walk_node)
Definition: nat64.c:1177
unsigned short u16
Definition: types.h:57
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
u32 * workers
Definition: nat.h:298
static uword nat64_static_bib_worker_fn(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Add/delete static BIB entry in worker thread.
Definition: nat64.c:571
snat_protocol_t
Definition: nat.h:104
u32 error_node_index
Definition: nat64.h:92
#define SNAT_ICMP_TIMEOUT
Definition: nat.h:38
NAT64 DB.
static vlib_node_registration_t nat64_expire_worker_walk_node
(constructor) VLIB_REGISTER_NODE (nat64_expire_worker_walk_node)
Definition: nat64.c:1166
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1181
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
#define SNAT_UDP_TIMEOUT_MIN
Definition: nat.h:34
#define vec_foreach(var, vec)
Vector iterator.
static vlib_node_registration_t nat64_static_bib_worker_node
(constructor) VLIB_REGISTER_NODE (nat64_static_bib_worker_node)
Definition: nat64.c:612
vhost_vring_addr_t addr
Definition: vhost-user.h:83
NAT plugin virtual fragmentation reassembly.
#define SNAT_TCP_INCOMING_SYN
Definition: nat.h:37
VNET_FEATURE_INIT(nat64_in2out, static)
#define SNAT_TCP_TRANSITORY_TIMEOUT
Definition: nat.h:35
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:624
int(* nat64_prefix_walk_fn_t)(nat64_prefix_t *pref64, void *ctx)
Call back function when walking addresses in NAT64 prefixes, non-zero return value stop walk...
Definition: nat64.h:322
u32 fib_index
Definition: nat.h:178
u32 nat64_get_tcp_trans_timeout(void)
Get TCP transitory timeout.
Definition: nat64.c:820
int(* nat64_interface_walk_fn_t)(snat_interface_t *i, void *ctx)
Call back function when walking interfaces with NAT64 feature, non-zero return value stop walk...
Definition: nat64.h:170
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:229
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
Definition: nat.h:569
int(* nat64_pool_addr_walk_fn_t)(snat_address_t *addr, void *ctx)
Call back function when walking addresses in NAT64 pool, non-zero return value stop walk...
Definition: nat64.h:135