FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
nat64_db.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 DB
18  */
19 #include <nat/nat64_db.h>
20 
21 int
23 {
24  u32 bib_buckets = 1024;
25  u32 bib_memory_size = 128 << 20;
26  u32 st_buckets = 2048;
27  u32 st_memory_size = 256 << 20;
28 
29  clib_bihash_init_24_8 (&db->bib.in2out, "bib-in2out", bib_buckets,
30  bib_memory_size);
31 
32  clib_bihash_init_24_8 (&db->bib.out2in, "bib-out2in", bib_buckets,
33  bib_memory_size);
34 
35  clib_bihash_init_48_8 (&db->st.in2out, "st-in2out", st_buckets,
36  st_memory_size);
37 
38  clib_bihash_init_48_8 (&db->st.out2in, "st-out2in", st_buckets,
39  st_memory_size);
40 
41  return 0;
42 }
43 
44 nat64_db_bib_entry_t *
46  ip4_address_t * out_addr, u16 in_port,
47  u16 out_port, u32 fib_index, u8 proto,
48  u8 is_static)
49 {
50  nat64_db_bib_entry_t *bibe;
51  nat64_db_bib_entry_key_t bibe_key;
53 
54  /* create pool entry */
55  switch (ip_proto_to_snat_proto (proto))
56  {
57 /* *INDENT-OFF* */
58 #define _(N, i, n, s) \
59  case SNAT_PROTOCOL_##N: \
60  pool_get (db->bib._##n##_bib, bibe); \
61  kv.value = bibe - db->bib._##n##_bib; \
62  break;
64 #undef _
65 /* *INDENT-ON* */
66  default:
67  pool_get (db->bib._unk_proto_bib, bibe);
68  kv.value = bibe - db->bib._unk_proto_bib;
69  break;
70  }
71  memset (bibe, 0, sizeof (*bibe));
72  bibe->in_addr.as_u64[0] = in_addr->as_u64[0];
73  bibe->in_addr.as_u64[1] = in_addr->as_u64[1];
74  bibe->in_port = in_port;
75  bibe->out_addr.as_u32 = out_addr->as_u32;
76  bibe->out_port = out_port;
77  bibe->fib_index = fib_index;
78  bibe->proto = proto;
79  bibe->is_static = is_static;
80 
81  /* create hash lookup */
82  bibe_key.addr.as_u64[0] = bibe->in_addr.as_u64[0];
83  bibe_key.addr.as_u64[1] = bibe->in_addr.as_u64[1];
84  bibe_key.fib_index = bibe->fib_index;
85  bibe_key.port = bibe->in_port;
86  bibe_key.proto = bibe->proto;
87  bibe_key.rsvd = 0;
88  kv.key[0] = bibe_key.as_u64[0];
89  kv.key[1] = bibe_key.as_u64[1];
90  kv.key[2] = bibe_key.as_u64[2];
91  clib_bihash_add_del_24_8 (&db->bib.in2out, &kv, 1);
92 
93  memset (&bibe_key.addr, 0, sizeof (bibe_key.addr));
94  bibe_key.addr.ip4.as_u32 = bibe->out_addr.as_u32;
95  bibe_key.fib_index = 0;
96  bibe_key.port = bibe->out_port;
97  kv.key[0] = bibe_key.as_u64[0];
98  kv.key[1] = bibe_key.as_u64[1];
99  kv.key[2] = bibe_key.as_u64[2];
100  clib_bihash_add_del_24_8 (&db->bib.out2in, &kv, 1);
101 
102  return bibe;
103 }
104 
105 void
106 nat64_db_bib_entry_free (nat64_db_t * db, nat64_db_bib_entry_t * bibe)
107 {
108  nat64_db_bib_entry_key_t bibe_key;
110  nat64_db_bib_entry_t *bib;
111  u32 *ste_to_be_free = 0, *ste_index, bibe_index;
112  nat64_db_st_entry_t *st, *ste;
113 
114  switch (ip_proto_to_snat_proto (bibe->proto))
115  {
116 /* *INDENT-OFF* */
117 #define _(N, i, n, s) \
118  case SNAT_PROTOCOL_##N: \
119  bib = db->bib._##n##_bib; \
120  st = db->st._##n##_st; \
121  break;
123 #undef _
124 /* *INDENT-ON* */
125  default:
126  bib = db->bib._unk_proto_bib;
127  st = db->st._unk_proto_st;
128  break;
129  }
130 
131  bibe_index = bibe - bib;
132 
133  /* delete ST entries for static BIB entry */
134  if (bibe->is_static)
135  {
136  pool_foreach (ste, st, (
137  {
138  if (ste->bibe_index == bibe_index)
139  vec_add1 (ste_to_be_free, ste - st);}
140  ));
141  vec_foreach (ste_index, ste_to_be_free)
142  nat64_db_st_entry_free (db, pool_elt_at_index (st, ste_index[0]));
143  vec_free (ste_to_be_free);
144  }
145 
146  /* delete hash lookup */
147  bibe_key.addr.as_u64[0] = bibe->in_addr.as_u64[0];
148  bibe_key.addr.as_u64[1] = bibe->in_addr.as_u64[1];
149  bibe_key.fib_index = bibe->fib_index;
150  bibe_key.port = bibe->in_port;
151  bibe_key.proto = bibe->proto;
152  bibe_key.rsvd = 0;
153  kv.key[0] = bibe_key.as_u64[0];
154  kv.key[1] = bibe_key.as_u64[1];
155  kv.key[2] = bibe_key.as_u64[2];
156  clib_bihash_add_del_24_8 (&db->bib.in2out, &kv, 0);
157 
158  memset (&bibe_key.addr, 0, sizeof (bibe_key.addr));
159  bibe_key.addr.ip4.as_u32 = bibe->out_addr.as_u32;
160  bibe_key.fib_index = 0;
161  bibe_key.port = bibe->out_port;
162  kv.key[0] = bibe_key.as_u64[0];
163  kv.key[1] = bibe_key.as_u64[1];
164  kv.key[2] = bibe_key.as_u64[2];
165  clib_bihash_add_del_24_8 (&db->bib.out2in, &kv, 0);
166 
167  /* delete from pool */
168  pool_put (bib, bibe);
169 
170 }
171 
172 nat64_db_bib_entry_t *
173 nat64_db_bib_entry_find (nat64_db_t * db, ip46_address_t * addr, u16 port,
174  u8 proto, u32 fib_index, u8 is_ip6)
175 {
176  nat64_db_bib_entry_t *bibe = 0;
177  nat64_db_bib_entry_key_t bibe_key;
178  clib_bihash_kv_24_8_t kv, value;
179  nat64_db_bib_entry_t *bib;
180 
181  switch (ip_proto_to_snat_proto (proto))
182  {
183 /* *INDENT-OFF* */
184 #define _(N, i, n, s) \
185  case SNAT_PROTOCOL_##N: \
186  bib = db->bib._##n##_bib; \
187  break;
189 #undef _
190 /* *INDENT-ON* */
191  default:
192  bib = db->bib._unk_proto_bib;
193  break;
194  }
195 
196  bibe_key.addr.as_u64[0] = addr->as_u64[0];
197  bibe_key.addr.as_u64[1] = addr->as_u64[1];
198  bibe_key.fib_index = fib_index;
199  bibe_key.port = port;
200  bibe_key.proto = proto;
201  bibe_key.rsvd = 0;
202 
203  kv.key[0] = bibe_key.as_u64[0];
204  kv.key[1] = bibe_key.as_u64[1];
205  kv.key[2] = bibe_key.as_u64[2];
206 
207  if (!clib_bihash_search_24_8
208  (is_ip6 ? &db->bib.in2out : &db->bib.out2in, &kv, &value))
209  bibe = pool_elt_at_index (bib, value.value);
210 
211  return bibe;
212 }
213 
214 void
216  nat64_db_bib_walk_fn_t fn, void *ctx)
217 {
218  nat64_db_bib_entry_t *bib, *bibe;
219 
220  if (proto == 255)
221  {
222  /* *INDENT-OFF* */
223  #define _(N, i, n, s) \
224  bib = db->bib._##n##_bib; \
225  pool_foreach (bibe, bib, ({ \
226  if (fn (bibe, ctx)) \
227  return; \
228  }));
230  #undef _
231  bib = db->bib._unk_proto_bib;
232  pool_foreach (bibe, bib, ({
233  if (fn (bibe, ctx))
234  return;
235  }));
236  /* *INDENT-ON* */
237  }
238  else
239  {
240  switch (ip_proto_to_snat_proto (proto))
241  {
242  /* *INDENT-OFF* */
243  #define _(N, i, n, s) \
244  case SNAT_PROTOCOL_##N: \
245  bib = db->bib._##n##_bib; \
246  break;
248  #undef _
249  /* *INDENT-ON* */
250  default:
251  bib = db->bib._unk_proto_bib;
252  break;
253  }
254 
255  /* *INDENT-OFF* */
256  pool_foreach (bibe, bib,
257  ({
258  if (fn (bibe, ctx))
259  return;
260  }));
261  /* *INDENT-ON* */
262  }
263 }
264 
265 nat64_db_bib_entry_t *
266 nat64_db_bib_entry_by_index (nat64_db_t * db, u8 proto, u32 bibe_index)
267 {
268  nat64_db_bib_entry_t *bib;
269 
270  switch (ip_proto_to_snat_proto (proto))
271  {
272 /* *INDENT-OFF* */
273 #define _(N, i, n, s) \
274  case SNAT_PROTOCOL_##N: \
275  bib = db->bib._##n##_bib; \
276  break;
278 #undef _
279 /* *INDENT-ON* */
280  default:
281  bib = db->bib._unk_proto_bib;
282  break;
283  }
284 
285  return pool_elt_at_index (bib, bibe_index);
286 }
287 
288 void
290  nat64_db_st_walk_fn_t fn, void *ctx)
291 {
292  nat64_db_st_entry_t *st, *ste;
293 
294  if (proto == 255)
295  {
296  /* *INDENT-OFF* */
297  #define _(N, i, n, s) \
298  st = db->st._##n##_st; \
299  pool_foreach (ste, st, ({ \
300  if (fn (ste, ctx)) \
301  return; \
302  }));
304  #undef _
305  st = db->st._unk_proto_st;
306  pool_foreach (ste, st, ({
307  if (fn (ste, ctx))
308  return;
309  }));
310  /* *INDENT-ON* */
311  }
312  else
313  {
314  switch (ip_proto_to_snat_proto (proto))
315  {
316  /* *INDENT-OFF* */
317  #define _(N, i, n, s) \
318  case SNAT_PROTOCOL_##N: \
319  st = db->st._##n##_st; \
320  break;
322  #undef _
323  /* *INDENT-ON* */
324  default:
325  st = db->st._unk_proto_st;
326  break;
327  }
328 
329  /* *INDENT-OFF* */
330  pool_foreach (ste, st,
331  ({
332  if (fn (ste, ctx))
333  return;
334  }));
335  /* *INDENT-ON* */
336  }
337 }
338 
339 nat64_db_st_entry_t *
340 nat64_db_st_entry_create (nat64_db_t * db, nat64_db_bib_entry_t * bibe,
341  ip6_address_t * in_r_addr,
342  ip4_address_t * out_r_addr, u16 r_port)
343 {
344  nat64_db_st_entry_t *ste;
345  nat64_db_bib_entry_t *bib;
346  nat64_db_st_entry_key_t ste_key;
348 
349  /* create pool entry */
350  switch (ip_proto_to_snat_proto (bibe->proto))
351  {
352 /* *INDENT-OFF* */
353 #define _(N, i, n, s) \
354  case SNAT_PROTOCOL_##N: \
355  pool_get (db->st._##n##_st, ste); \
356  kv.value = ste - db->st._##n##_st; \
357  bib = db->bib._##n##_bib; \
358  break;
360 #undef _
361 /* *INDENT-ON* */
362  default:
363  pool_get (db->st._unk_proto_st, ste);
364  kv.value = ste - db->st._unk_proto_st;
365  bib = db->bib._unk_proto_bib;
366  break;
367  }
368  memset (ste, 0, sizeof (*ste));
369  ste->in_r_addr.as_u64[0] = in_r_addr->as_u64[0];
370  ste->in_r_addr.as_u64[1] = in_r_addr->as_u64[1];
371  ste->out_r_addr.as_u32 = out_r_addr->as_u32;
372  ste->r_port = r_port;
373  ste->bibe_index = bibe - bib;
374  ste->proto = bibe->proto;
375 
376  /* increment session number for BIB entry */
377  bibe->ses_num++;
378 
379  /* create hash lookup */
380  memset (&ste_key, 0, sizeof (ste_key));
381  ste_key.l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
382  ste_key.l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
383  ste_key.r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
384  ste_key.r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
385  ste_key.fib_index = bibe->fib_index;
386  ste_key.l_port = bibe->in_port;
387  ste_key.r_port = ste->r_port;
388  ste_key.proto = ste->proto;
389  kv.key[0] = ste_key.as_u64[0];
390  kv.key[1] = ste_key.as_u64[1];
391  kv.key[2] = ste_key.as_u64[2];
392  kv.key[3] = ste_key.as_u64[3];
393  kv.key[4] = ste_key.as_u64[4];
394  kv.key[5] = ste_key.as_u64[5];
395  clib_bihash_add_del_48_8 (&db->st.in2out, &kv, 1);
396 
397  memset (&ste_key, 0, sizeof (ste_key));
398  ste_key.l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
399  ste_key.r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
400  ste_key.l_port = bibe->out_port;
401  ste_key.r_port = ste->r_port;
402  ste_key.proto = ste->proto;
403  kv.key[0] = ste_key.as_u64[0];
404  kv.key[1] = ste_key.as_u64[1];
405  kv.key[2] = ste_key.as_u64[2];
406  kv.key[3] = ste_key.as_u64[3];
407  kv.key[4] = ste_key.as_u64[4];
408  kv.key[5] = ste_key.as_u64[5];
409  clib_bihash_add_del_48_8 (&db->st.out2in, &kv, 1);
410 
411  return ste;
412 }
413 
414 void
415 nat64_db_st_entry_free (nat64_db_t * db, nat64_db_st_entry_t * ste)
416 {
417  nat64_db_st_entry_t *st;
418  nat64_db_bib_entry_t *bib, *bibe;
419  nat64_db_st_entry_key_t ste_key;
421 
422  switch (ip_proto_to_snat_proto (ste->proto))
423  {
424 /* *INDENT-OFF* */
425 #define _(N, i, n, s) \
426  case SNAT_PROTOCOL_##N: \
427  st = db->st._##n##_st; \
428  bib = db->bib._##n##_bib; \
429  break;
431 #undef _
432 /* *INDENT-ON* */
433  default:
434  st = db->st._unk_proto_st;
435  bib = db->bib._unk_proto_bib;
436  break;
437  }
438 
439  bibe = pool_elt_at_index (bib, ste->bibe_index);
440 
441  /* delete hash lookup */
442  memset (&ste_key, 0, sizeof (ste_key));
443  ste_key.l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
444  ste_key.l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
445  ste_key.r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
446  ste_key.r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
447  ste_key.fib_index = bibe->fib_index;
448  ste_key.l_port = bibe->in_port;
449  ste_key.r_port = ste->r_port;
450  ste_key.proto = ste->proto;
451  kv.key[0] = ste_key.as_u64[0];
452  kv.key[1] = ste_key.as_u64[1];
453  kv.key[2] = ste_key.as_u64[2];
454  kv.key[3] = ste_key.as_u64[3];
455  kv.key[4] = ste_key.as_u64[4];
456  kv.key[5] = ste_key.as_u64[5];
457  clib_bihash_add_del_48_8 (&db->st.in2out, &kv, 0);
458 
459  memset (&ste_key, 0, sizeof (ste_key));
460  ste_key.l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
461  ste_key.r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
462  ste_key.l_port = bibe->out_port;
463  ste_key.r_port = ste->r_port;
464  ste_key.proto = ste->proto;
465  kv.key[0] = ste_key.as_u64[0];
466  kv.key[1] = ste_key.as_u64[1];
467  kv.key[2] = ste_key.as_u64[2];
468  kv.key[3] = ste_key.as_u64[3];
469  kv.key[4] = ste_key.as_u64[4];
470  kv.key[5] = ste_key.as_u64[5];
471  clib_bihash_add_del_48_8 (&db->st.out2in, &kv, 0);
472 
473  /* delete from pool */
474  pool_put (st, ste);
475 
476  /* decrement session number for BIB entry */
477  bibe->ses_num--;
478 
479  /* delete BIB entry if last session and dynamic */
480  if (!bibe->is_static && !bibe->ses_num)
481  nat64_db_bib_entry_free (db, bibe);
482 }
483 
484 nat64_db_st_entry_t *
485 nat64_db_st_entry_find (nat64_db_t * db, ip46_address_t * l_addr,
486  ip46_address_t * r_addr, u16 l_port, u16 r_port,
487  u8 proto, u32 fib_index, u8 is_ip6)
488 {
489  nat64_db_st_entry_t *ste = 0;
490  nat64_db_st_entry_t *st;
491  nat64_db_st_entry_key_t ste_key;
492  clib_bihash_kv_48_8_t kv, value;
493 
494  switch (ip_proto_to_snat_proto (proto))
495  {
496 /* *INDENT-OFF* */
497 #define _(N, i, n, s) \
498  case SNAT_PROTOCOL_##N: \
499  st = db->st._##n##_st; \
500  break;
502 #undef _
503 /* *INDENT-ON* */
504  default:
505  st = db->st._unk_proto_st;
506  break;
507  }
508 
509  memset (&ste_key, 0, sizeof (ste_key));
510  ste_key.l_addr.as_u64[0] = l_addr->as_u64[0];
511  ste_key.l_addr.as_u64[1] = l_addr->as_u64[1];
512  ste_key.r_addr.as_u64[0] = r_addr->as_u64[0];
513  ste_key.r_addr.as_u64[1] = r_addr->as_u64[1];
514  ste_key.fib_index = fib_index;
515  ste_key.l_port = l_port;
516  ste_key.r_port = r_port;
517  ste_key.proto = proto;
518  kv.key[0] = ste_key.as_u64[0];
519  kv.key[1] = ste_key.as_u64[1];
520  kv.key[2] = ste_key.as_u64[2];
521  kv.key[3] = ste_key.as_u64[3];
522  kv.key[4] = ste_key.as_u64[4];
523  kv.key[5] = ste_key.as_u64[5];
524 
525  if (!clib_bihash_search_48_8
526  (is_ip6 ? &db->st.in2out : &db->st.out2in, &kv, &value))
527  ste = pool_elt_at_index (st, value.value);
528 
529  return ste;
530 }
531 
532 void
534 {
535  u32 *ste_to_be_free = 0, *ste_index;
536  nat64_db_st_entry_t *st, *ste;
537 
538 /* *INDENT-OFF* */
539 #define _(N, i, n, s) \
540  st = db->st._##n##_st; \
541  pool_foreach (ste, st, ({\
542  if (i == SNAT_PROTOCOL_TCP && !ste->tcp_state) \
543  continue; \
544  if (ste->expire < now) \
545  vec_add1 (ste_to_be_free, ste - st); \
546  })); \
547  vec_foreach (ste_index, ste_to_be_free) \
548  nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0])); \
549  vec_free (ste_to_be_free); \
550  ste_to_be_free = 0;
552 #undef _
553  st = db->st._unk_proto_st;
554  pool_foreach (ste, st, ({
555  if (ste->expire < now)
556  vec_add1 (ste_to_be_free, ste - st);
557  }));
558  vec_foreach (ste_index, ste_to_be_free)
559  nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0]));
560  vec_free (ste_to_be_free);
561 /* *INDENT-ON* */
562 }
563 
564 void
566 {
567  u32 *ste_to_be_free = 0, *ste_index;
568  nat64_db_st_entry_t *st, *ste;
569  nat64_db_bib_entry_t *bibe;
570 
571 /* *INDENT-OFF* */
572 #define _(N, i, n, s) \
573  st = db->st._##n##_st; \
574  pool_foreach (ste, st, ({ \
575  bibe = pool_elt_at_index (db->bib._##n##_bib, ste->bibe_index); \
576  if (bibe->out_addr.as_u32 == out_addr->as_u32) \
577  vec_add1 (ste_to_be_free, ste - st); \
578  })); \
579  vec_foreach (ste_index, ste_to_be_free) \
580  nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0])); \
581  vec_free (ste_to_be_free); \
582  ste_to_be_free = 0;
584 #undef _
585  st = db->st._unk_proto_st;
586  pool_foreach (ste, st, ({
587  bibe = pool_elt_at_index (db->bib._unk_proto_bib, ste->bibe_index);
588  if (bibe->out_addr.as_u32 == out_addr->as_u32)
589  vec_add1 (ste_to_be_free, ste - st);
590  }));
591  vec_foreach (ste_index, ste_to_be_free)
592  nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0]));
593  vec_free (ste_to_be_free);
594 /* *INDENT-ON* */
595 }
596 
597 /*
598  * fd.io coding-style-patch-verification: ON
599  *
600  * Local Variables:
601  * eval: (c-set-style "gnu")
602  * End:
603  */
Definition: nat64_db.h:73
nat64_db_bib_t bib
Definition: nat64_db.h:122
u16 l_port
Definition: nat64_db.h:82
u64 as_u64[2]
Definition: ip6_packet.h:51
nat64_db_st_entry_t * nat64_db_st_entry_create(nat64_db_t *db, nat64_db_bib_entry_t *bibe, ip6_address_t *in_r_addr, ip4_address_t *out_r_addr, u16 r_port)
Create new NAT64 session table entry.
Definition: nat64_db.c:340
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:45
Definition: nat64_db.h:27
#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:173
u32 fib_index
Definition: nat64_db.h:81
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:225
int(* nat64_db_bib_walk_fn_t)(nat64_db_bib_entry_t *bibe, void *ctx)
Call back function when walking NAT64 BIB, non-zero return value stop walk.
Definition: nat64_db.h:168
ip46_address_t l_addr
Definition: nat64_db.h:79
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:437
u16 r_port
Definition: nat64_db.h:83
clib_bihash_48_8_t in2out
Definition: nat64_db.h:116
u16 port
Definition: nat64_db.h:35
u64 as_u64[6]
Definition: nat64_db.h:87
clib_bihash_24_8_t in2out
Definition: nat64_db.h:69
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:458
void nad64_db_st_free_expired(nat64_db_t *db, u32 now)
Free expired session entries in session tables.
Definition: nat64_db.c:533
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:270
void nat64_db_bib_entry_free(nat64_db_t *db, nat64_db_bib_entry_t *bibe)
Free NAT64 BIB entry.
Definition: nat64_db.c:106
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
ip46_address_t addr
Definition: nat64_db.h:33
u8 proto
Definition: nat64_db.h:84
nat64_db_st_entry_t * nat64_db_st_entry_find(nat64_db_t *db, ip46_address_t *l_addr, ip46_address_t *r_addr, u16 l_port, u16 r_port, u8 proto, u32 fib_index, u8 is_ip6)
Find NAT64 session table entry.
Definition: nat64_db.c:485
unsigned int u32
Definition: types.h:88
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:289
long ctx[MAX_CONNS]
Definition: main.c:95
static u32 ip_proto_to_snat_proto(u8 ip_proto)
Definition: nat.h:429
u32 fib_index
Definition: nat64_db.h:34
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:266
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:565
u8 proto
Definition: nat64_db.h:36
unsigned short u16
Definition: types.h:57
clib_bihash_24_8_t out2in
Definition: nat64_db.h:70
unsigned char u8
Definition: types.h:56
void nat64_db_st_entry_free(nat64_db_t *db, nat64_db_st_entry_t *ste)
Free NAT64 session table entry.
Definition: nat64_db.c:415
int(* nat64_db_st_walk_fn_t)(nat64_db_st_entry_t *ste, void *ctx)
Call back function when walking NAT64 session table, non-zero return value stop walk.
Definition: nat64_db.h:265
NAT64 DB.
#define vec_foreach(var, vec)
Vector iterator.
nat64_db_st_t st
Definition: nat64_db.h:123
vhost_vring_addr_t addr
Definition: vhost-user.h:83
u8 rsvd
Definition: nat64_db.h:37
int nat64_db_init(nat64_db_t *db)
Initialize NAT64 DB.
Definition: nat64_db.c:22
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:215
u64 as_u64[3]
Definition: nat64_db.h:39
ip46_address_t r_addr
Definition: nat64_db.h:80
clib_bihash_48_8_t out2in
Definition: nat64_db.h:117