25 u32 st_buckets,
u32 st_memory_size,
28 clib_bihash_init_24_8 (&db->
bib.
in2out,
"bib-in2out", bib_buckets,
31 clib_bihash_init_24_8 (&db->
bib.
out2in,
"bib-out2in", bib_buckets,
34 clib_bihash_init_48_8 (&db->
st.
in2out,
"st-in2out", st_buckets,
37 clib_bihash_init_48_8 (&db->
st.
out2in,
"st-out2in", st_buckets,
50 nat64_db_bib_entry_t *
53 u16 out_port,
u32 fib_index,
u8 proto,
56 nat64_db_bib_entry_t *bibe;
72 #define _(N, i, n, s) \ 73 case SNAT_PROTOCOL_##N: \ 74 pool_get (db->bib._##n##_bib, bibe); \ 75 kv.value = bibe - db->bib._##n##_bib; \ 82 kv.
value = bibe - db->
bib._unk_proto_bib;
88 memset (bibe, 0,
sizeof (*bibe));
89 bibe->in_addr.as_u64[0] = in_addr->
as_u64[0];
90 bibe->in_addr.as_u64[1] = in_addr->
as_u64[1];
91 bibe->in_port = in_port;
92 bibe->out_addr.as_u32 = out_addr->
as_u32;
93 bibe->out_port = out_port;
94 bibe->fib_index = fib_index;
96 bibe->is_static = is_static;
99 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
100 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
102 bibe_key.
port = bibe->in_port;
103 bibe_key.
proto = bibe->proto;
108 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 1);
110 memset (&bibe_key.
addr, 0, sizeof (bibe_key.
addr));
111 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
113 bibe_key.
port = bibe->out_port;
117 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 1);
130 nat64_db_bib_entry_t *bib;
131 u32 *ste_to_be_free = 0, *ste_index, bibe_index;
132 nat64_db_st_entry_t *st, *ste;
138 #define _(N, i, n, s) \ 139 case SNAT_PROTOCOL_##N: \ 140 bib = db->bib._##n##_bib; \ 141 st = db->st._##n##_st; \ 147 bib = db->
bib._unk_proto_bib;
148 st = db->
st._unk_proto_st;
154 bibe_index = bibe - bib;
161 if (ste->bibe_index == bibe_index)
162 vec_add1 (ste_to_be_free, ste - st);}
170 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
171 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
173 bibe_key.
port = bibe->in_port;
174 bibe_key.
proto = bibe->proto;
179 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 0);
181 memset (&bibe_key.
addr, 0, sizeof (bibe_key.
addr));
182 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
184 bibe_key.
port = bibe->out_port;
188 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 0);
195 bibe->in_port, bibe->out_port,
203 nat64_db_bib_entry_t *
205 u8 proto,
u32 fib_index,
u8 is_ip6)
207 nat64_db_bib_entry_t *bibe = 0;
210 nat64_db_bib_entry_t *bib;
215 #define _(N, i, n, s) \ 216 case SNAT_PROTOCOL_##N: \ 217 bib = db->bib._##n##_bib; \ 223 bib = db->
bib._unk_proto_bib;
227 bibe_key.
addr.as_u64[0] = addr->as_u64[0];
228 bibe_key.
addr.as_u64[1] = addr->as_u64[1];
230 bibe_key.
port = port;
231 bibe_key.
proto = proto;
238 if (!clib_bihash_search_24_8
249 nat64_db_bib_entry_t *bib, *bibe;
254 #define _(N, i, n, s) \ 255 bib = db->bib._##n##_bib; \ 256 pool_foreach (bibe, bib, ({ \ 257 if (fn (bibe, ctx)) \ 262 bib = db->
bib._unk_proto_bib;
274 #define _(N, i, n, s) \ 275 case SNAT_PROTOCOL_##N: \ 276 bib = db->bib._##n##_bib; \ 282 bib = db->
bib._unk_proto_bib;
296 nat64_db_bib_entry_t *
299 nat64_db_bib_entry_t *bib;
304 #define _(N, i, n, s) \ 305 case SNAT_PROTOCOL_##N: \ 306 bib = db->bib._##n##_bib; \ 312 bib = db->
bib._unk_proto_bib;
323 nat64_db_st_entry_t *st, *ste;
328 #define _(N, i, n, s) \ 329 st = db->st._##n##_st; \ 330 pool_foreach (ste, st, ({ \ 336 st = db->
st._unk_proto_st;
348 #define _(N, i, n, s) \ 349 case SNAT_PROTOCOL_##N: \ 350 st = db->st._##n##_st; \ 356 st = db->
st._unk_proto_st;
370 nat64_db_st_entry_t *
375 nat64_db_st_entry_t *ste;
376 nat64_db_bib_entry_t *bib;
391 #define _(N, i, n, s) \ 392 case SNAT_PROTOCOL_##N: \ 393 pool_get (db->st._##n##_st, ste); \ 394 kv.value = ste - db->st._##n##_st; \ 395 bib = db->bib._##n##_bib; \ 402 kv.
value = ste - db->
st._unk_proto_st;
403 bib = db->
bib._unk_proto_bib;
409 memset (ste, 0,
sizeof (*ste));
410 ste->in_r_addr.as_u64[0] = in_r_addr->
as_u64[0];
411 ste->in_r_addr.as_u64[1] = in_r_addr->
as_u64[1];
412 ste->out_r_addr.as_u32 = out_r_addr->
as_u32;
413 ste->r_port = r_port;
414 ste->bibe_index = bibe - bib;
415 ste->proto = bibe->proto;
421 memset (&ste_key, 0,
sizeof (ste_key));
422 ste_key.
l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
423 ste_key.
l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
424 ste_key.
r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
425 ste_key.
r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
427 ste_key.
l_port = bibe->in_port;
428 ste_key.
r_port = ste->r_port;
429 ste_key.
proto = ste->proto;
436 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 1);
438 memset (&ste_key, 0,
sizeof (ste_key));
439 ste_key.
l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
440 ste_key.
r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
441 ste_key.
l_port = bibe->out_port;
442 ste_key.
r_port = ste->r_port;
443 ste_key.
proto = ste->proto;
450 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 1);
454 bibe->proto, bibe->in_port, bibe->out_port,
455 &ste->in_r_addr, &ste->out_r_addr,
465 nat64_db_st_entry_t *st;
466 nat64_db_bib_entry_t *bib, *bibe;
474 #define _(N, i, n, s) \ 475 case SNAT_PROTOCOL_##N: \ 476 st = db->st._##n##_st; \ 477 bib = db->bib._##n##_bib; \ 483 st = db->
st._unk_proto_st;
484 bib = db->
bib._unk_proto_bib;
493 memset (&ste_key, 0,
sizeof (ste_key));
494 ste_key.
l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
495 ste_key.
l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
496 ste_key.
r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
497 ste_key.
r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
499 ste_key.
l_port = bibe->in_port;
500 ste_key.
r_port = ste->r_port;
501 ste_key.
proto = ste->proto;
508 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 0);
510 memset (&ste_key, 0,
sizeof (ste_key));
511 ste_key.
l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
512 ste_key.
r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
513 ste_key.
l_port = bibe->out_port;
514 ste_key.
r_port = ste->r_port;
515 ste_key.
proto = ste->proto;
522 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 0);
526 bibe->proto, bibe->in_port, bibe->out_port,
527 &ste->in_r_addr, &ste->out_r_addr,
538 if (!bibe->is_static && !bibe->ses_num)
542 nat64_db_st_entry_t *
544 ip46_address_t * r_addr,
u16 l_port,
u16 r_port,
545 u8 proto,
u32 fib_index,
u8 is_ip6)
547 nat64_db_st_entry_t *ste = 0;
548 nat64_db_st_entry_t *st;
555 #define _(N, i, n, s) \ 556 case SNAT_PROTOCOL_##N: \ 557 st = db->st._##n##_st; \ 563 st = db->
st._unk_proto_st;
567 memset (&ste_key, 0,
sizeof (ste_key));
568 ste_key.
l_addr.as_u64[0] = l_addr->as_u64[0];
569 ste_key.
l_addr.as_u64[1] = l_addr->as_u64[1];
570 ste_key.
r_addr.as_u64[0] = r_addr->as_u64[0];
571 ste_key.
r_addr.as_u64[1] = r_addr->as_u64[1];
575 ste_key.
proto = proto;
583 if (!clib_bihash_search_48_8
593 nat64_db_st_entry_t *st;
598 #define _(N, i, n, s) \ 599 case SNAT_PROTOCOL_##N: \ 600 st = db->st._##n##_st; \ 606 st = db->
st._unk_proto_st;
613 nat64_db_st_entry_t *
616 nat64_db_st_entry_t *st;
621 #define _(N, i, n, s) \ 622 case SNAT_PROTOCOL_##N: \ 623 st = db->st._##n##_st; \ 629 st = db->
st._unk_proto_st;
639 u32 *ste_to_be_free = 0, *ste_index;
640 nat64_db_st_entry_t *st, *ste;
643 #define _(N, i, n, s) \ 644 st = db->st._##n##_st; \ 645 pool_foreach (ste, st, ({\ 646 if (i == SNAT_PROTOCOL_TCP && !ste->tcp_state) \ 648 if (ste->expire < now) \ 649 vec_add1 (ste_to_be_free, ste - st); \ 651 vec_foreach (ste_index, ste_to_be_free) \ 652 nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0])); \ 653 vec_free (ste_to_be_free); \ 657 st = db->
st._unk_proto_st;
659 if (ste->expire < now)
660 vec_add1 (ste_to_be_free, ste - st);
671 u32 *ste_to_be_free = 0, *ste_index;
672 nat64_db_st_entry_t *st, *ste;
673 nat64_db_bib_entry_t *bibe;
677 #define _(N, i, n, s) \ 678 st = db->st._##n##_st; \ 679 pool_foreach (ste, st, ({ \ 680 bibe = pool_elt_at_index (db->bib._##n##_bib, ste->bibe_index); \ 681 if (bibe->out_addr.as_u32 == out_addr->as_u32) \ 682 vec_add1 (ste_to_be_free, ste - st); \ 684 vec_foreach (ste_index, ste_to_be_free) \ 685 nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0])); \ 686 vec_free (ste_to_be_free); \ 690 st = db->
st._unk_proto_st;
693 if (bibe->out_addr.as_u32 == out_addr->
as_u32)
694 vec_add1 (ste_to_be_free, ste - st);
void nat_ipfix_logging_max_sessions(u32 limit)
Generate maximum session entries exceeded event.
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.
nat64_db_free_addr_port_function_t free_addr_port_cb
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.
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.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
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.
nat64_db_st_entry_t * nat64_db_st_entry_by_index(nat64_db_t *db, u8 proto, u32 ste_index)
Get ST entry by index and protocol.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
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.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
void nat_ipfix_logging_nat64_bib(ip6_address_t *src_ip, ip4_address_t *nat_src_ip, u8 proto, u16 src_port, u16 nat_src_port, u32 vrf_id, u8 is_create)
Generate NAT64 BIB create and delete events.
clib_bihash_48_8_t in2out
clib_bihash_24_8_t in2out
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
void nad64_db_st_free_expired(nat64_db_t *db, u32 now)
Free expired session entries in session tables.
#define pool_put(P, E)
Free an object E in pool P.
void nat64_db_bib_entry_free(nat64_db_t *db, nat64_db_bib_entry_t *bibe)
Free NAT64 BIB entry.
void nat_ipfix_logging_max_bibs(u32 limit)
Generate maximum BIB entries exceeded event.
u32 ft_table_id
Table ID (hash key) for this FIB.
#define vec_free(V)
Free vector's memory (no header).
void(* nat64_db_free_addr_port_function_t)(struct nat64_db_s *db, ip4_address_t *addr, u16 port, u8 proto)
Call back function to free NAT64 pool address and port when BIB entry is deleted. ...
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.
void nat64_db_st_walk(nat64_db_t *db, u8 proto, nat64_db_st_walk_fn_t fn, void *ctx)
Walk NAT64 session table.
u32 nat64_db_st_entry_get_index(nat64_db_t *db, nat64_db_st_entry_t *ste)
static u32 ip_proto_to_snat_proto(u8 ip_proto)
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.
void nat64_db_free_out_addr(nat64_db_t *db, ip4_address_t *out_addr)
Free sessions using specific outside address.
clib_bihash_24_8_t out2in
fib_table_t * fib_table_get(fib_node_index_t index, fib_protocol_t proto)
Get a pointer to a FIB table.
void nat64_db_st_entry_free(nat64_db_t *db, nat64_db_st_entry_t *ste)
Free NAT64 session table entry.
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.
#define vec_foreach(var, vec)
Vector iterator.
void nat64_db_bib_walk(nat64_db_t *db, u8 proto, nat64_db_bib_walk_fn_t fn, void *ctx)
Walk NAT64 BIB.
A protocol Independent FIB table.
clib_bihash_48_8_t out2in
void nat_ipfix_logging_nat64_session(ip6_address_t *src_ip, ip4_address_t *nat_src_ip, u8 proto, u16 src_port, u16 nat_src_port, ip6_address_t *dst_ip, ip4_address_t *nat_dst_ip, u16 dst_port, u16 nat_dst_port, u32 vrf_id, u8 is_create)
Generate NAT64 session create and delete events.