26 clib_bihash_init_24_8 (&db->
bib.
in2out,
"bib-in2out",
c.bib_buckets,
29 clib_bihash_init_24_8 (&db->
bib.
out2in,
"bib-out2in",
c.bib_buckets,
32 clib_bihash_init_48_8 (&db->
st.
in2out,
"st-in2out",
c.st_buckets,
35 clib_bihash_init_48_8 (&db->
st.
out2in,
"st-out2in",
c.st_buckets,
54 clib_bihash_free_48_8 (&db->
st.
in2out);
55 clib_bihash_free_48_8 (&db->
st.
out2in);
58 #define _(N, i, n, s) \
59 pool_free (db->bib._##n##_bib); \
60 pool_free (db->st._##n##_st);
71 nat64_db_bib_entry_t *
73 ip6_address_t * in_addr,
78 nat64_db_bib_entry_t *bibe;
93 #define _(N, i, n, s) \
94 case NAT_PROTOCOL_##N: \
95 pool_get (db->bib._##n##_bib, bibe); \
96 kv.value = bibe - db->bib._##n##_bib; \
103 kv.
value = bibe - db->
bib._unk_proto_bib;
110 bibe->in_addr.as_u64[0] = in_addr->as_u64[0];
111 bibe->in_addr.as_u64[1] = in_addr->as_u64[1];
112 bibe->in_port = in_port;
113 bibe->out_addr.as_u32 = out_addr->
as_u32;
114 bibe->out_port = out_port;
115 bibe->fib_index = fib_index;
117 bibe->is_static = is_static;
120 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
121 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
123 bibe_key.
port = bibe->in_port;
124 bibe_key.
proto = bibe->proto;
129 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 1);
132 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
134 bibe_key.
port = bibe->out_port;
138 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 1);
148 nat64_db_bib_entry_t * bibe)
152 nat64_db_bib_entry_t *bib;
153 u32 *ste_to_be_free = 0, *ste_index, bibe_index;
154 nat64_db_st_entry_t *st, *ste;
159 #define _(N, i, n, s) \
160 case NAT_PROTOCOL_##N: \
161 bib = db->bib._##n##_bib; \
162 st = db->st._##n##_st; \
168 bib = db->
bib._unk_proto_bib;
169 st = db->
st._unk_proto_st;
175 bibe_index = bibe - bib;
182 if (ste->bibe_index == bibe_index)
183 vec_add1 (ste_to_be_free, ste - st);
192 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
193 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
195 bibe_key.
port = bibe->in_port;
196 bibe_key.
proto = bibe->proto;
201 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 0);
204 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
206 bibe_key.
port = bibe->out_port;
210 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 0);
217 bibe->proto, bibe->in_port, bibe->out_port,
224 nat64_db_bib_entry_t *
228 nat64_db_bib_entry_t *bibe = 0;
231 nat64_db_bib_entry_t *bib;
236 #define _(N, i, n, s) \
237 case NAT_PROTOCOL_##N: \
238 bib = db->bib._##n##_bib; \
244 bib = db->
bib._unk_proto_bib;
248 bibe_key.
addr.as_u64[0] =
addr->as_u64[0];
249 bibe_key.
addr.as_u64[1] =
addr->as_u64[1];
259 if (!clib_bihash_search_24_8
270 nat64_db_bib_entry_t *bib, *bibe;
275 #define _(N, i, n, s) \
276 bib = db->bib._##n##_bib; \
277 pool_foreach (bibe, bib) { \
278 if (fn (bibe, ctx)) \
283 bib = db->
bib._unk_proto_bib;
295 #define _(N, i, n, s) \
296 case NAT_PROTOCOL_##N: \
297 bib = db->bib._##n##_bib; \
303 bib = db->
bib._unk_proto_bib;
317 nat64_db_bib_entry_t *
320 nat64_db_bib_entry_t *bib;
325 #define _(N, i, n, s) \
326 case NAT_PROTOCOL_##N: \
327 bib = db->bib._##n##_bib; \
333 bib = db->
bib._unk_proto_bib;
344 nat64_db_st_entry_t *st, *ste;
349 #define _(N, i, n, s) \
350 st = db->st._##n##_st; \
351 pool_foreach (ste, st) { \
357 st = db->
st._unk_proto_st;
369 #define _(N, i, n, s) \
370 case NAT_PROTOCOL_##N: \
371 st = db->st._##n##_st; \
377 st = db->
st._unk_proto_st;
391 nat64_db_st_entry_t *
393 nat64_db_bib_entry_t * bibe,
394 ip6_address_t * in_r_addr,
397 nat64_db_st_entry_t *ste;
398 nat64_db_bib_entry_t *bib;
412 #define _(N, i, n, s) \
413 case NAT_PROTOCOL_##N: \
414 pool_get (db->st._##n##_st, ste); \
415 kv.value = ste - db->st._##n##_st; \
416 bib = db->bib._##n##_bib; \
423 kv.
value = ste - db->
st._unk_proto_st;
424 bib = db->
bib._unk_proto_bib;
431 ste->in_r_addr.as_u64[0] = in_r_addr->as_u64[0];
432 ste->in_r_addr.as_u64[1] = in_r_addr->as_u64[1];
433 ste->out_r_addr.as_u32 = out_r_addr->
as_u32;
434 ste->r_port = r_port;
435 ste->bibe_index = bibe - bib;
436 ste->proto = bibe->proto;
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];
448 ste_key.
l_port = bibe->in_port;
449 ste_key.
r_port = ste->r_port;
450 ste_key.
proto = ste->proto;
457 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 1);
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;
471 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 1);
475 &bibe->out_addr, bibe->proto,
476 bibe->in_port, bibe->out_port,
477 &ste->in_r_addr, &ste->out_r_addr,
481 &bibe->out_addr, bibe->out_port, &ste->out_r_addr,
482 ste->r_port, bibe->proto);
490 nat64_db_st_entry_t *st;
491 nat64_db_bib_entry_t *bib, *bibe;
498 #define _(N, i, n, s) \
499 case NAT_PROTOCOL_##N: \
500 st = db->st._##n##_st; \
501 bib = db->bib._##n##_bib; \
507 st = db->
st._unk_proto_st;
508 bib = db->
bib._unk_proto_bib;
518 ste_key.
l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
519 ste_key.
l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
520 ste_key.
r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
521 ste_key.
r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
523 ste_key.
l_port = bibe->in_port;
524 ste_key.
r_port = ste->r_port;
525 ste_key.
proto = ste->proto;
532 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 0);
535 ste_key.
l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
536 ste_key.
r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
537 ste_key.
l_port = bibe->out_port;
538 ste_key.
r_port = ste->r_port;
539 ste_key.
proto = ste->proto;
546 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 0);
550 &bibe->out_addr, bibe->proto,
551 bibe->in_port, bibe->out_port,
552 &ste->in_r_addr, &ste->out_r_addr,
556 &bibe->out_addr, bibe->out_port, &ste->out_r_addr,
557 ste->r_port, bibe->proto);
566 if (!bibe->is_static && !bibe->ses_num)
570 nat64_db_st_entry_t *
572 ip46_address_t * r_addr,
u16 l_port,
u16 r_port,
575 nat64_db_st_entry_t *ste = 0;
576 nat64_db_st_entry_t *st;
583 #define _(N, i, n, s) \
584 case NAT_PROTOCOL_##N: \
585 st = db->st._##n##_st; \
591 st = db->
st._unk_proto_st;
596 ste_key.
l_addr.as_u64[0] = l_addr->as_u64[0];
597 ste_key.
l_addr.as_u64[1] = l_addr->as_u64[1];
598 ste_key.
r_addr.as_u64[0] = r_addr->as_u64[0];
599 ste_key.
r_addr.as_u64[1] = r_addr->as_u64[1];
611 if (!clib_bihash_search_48_8
621 nat64_db_st_entry_t *st;
626 #define _(N, i, n, s) \
627 case NAT_PROTOCOL_##N: \
628 st = db->st._##n##_st; \
634 st = db->
st._unk_proto_st;
641 nat64_db_st_entry_t *
644 nat64_db_st_entry_t *st;
649 #define _(N, i, n, s) \
650 case NAT_PROTOCOL_##N: \
651 st = db->st._##n##_st; \
657 st = db->
st._unk_proto_st;
667 u32 *ste_to_be_free = 0, *ste_index;
668 nat64_db_st_entry_t *st, *ste;
671 #define _(N, i, n, s) \
672 st = db->st._##n##_st; \
673 pool_foreach (ste, st) {\
674 if (i == NAT_PROTOCOL_TCP && !ste->tcp_state) \
676 if (ste->expire < now) \
677 vec_add1 (ste_to_be_free, ste - st); \
679 vec_foreach (ste_index, ste_to_be_free) \
680 nat64_db_st_entry_free (thread_index, db, \
681 pool_elt_at_index(st, ste_index[0])); \
682 vec_free (ste_to_be_free); \
686 st = db->
st._unk_proto_st;
688 if (ste->expire <
now)
689 vec_add1 (ste_to_be_free, ste - st);
702 u32 *ste_to_be_free = 0, *ste_index;
703 nat64_db_st_entry_t *st, *ste;
704 nat64_db_bib_entry_t *bibe;
708 #define _(N, i, n, s) \
709 st = db->st._##n##_st; \
710 pool_foreach (ste, st) { \
711 bibe = pool_elt_at_index (db->bib._##n##_bib, ste->bibe_index); \
712 if (bibe->out_addr.as_u32 == out_addr->as_u32) \
713 vec_add1 (ste_to_be_free, ste - st); \
715 vec_foreach (ste_index, ste_to_be_free) \
716 nat64_db_st_entry_free (thread_index, db, \
717 pool_elt_at_index(st, ste_index[0])); \
718 vec_free (ste_to_be_free); \
722 st = db->
st._unk_proto_st;
725 if (bibe->out_addr.as_u32 == out_addr->
as_u32)
726 vec_add1 (ste_to_be_free, ste - st);