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