27 u32 st_buckets,
u32 st_memory_size,
30 clib_bihash_init_24_8 (&db->
bib.
in2out,
"bib-in2out", bib_buckets,
33 clib_bihash_init_24_8 (&db->
bib.
out2in,
"bib-out2in", bib_buckets,
36 clib_bihash_init_48_8 (&db->
st.
in2out,
"st-in2out", st_buckets,
39 clib_bihash_init_48_8 (&db->
st.
out2in,
"st-out2in", st_buckets,
52 nat64_db_bib_entry_t *
55 u16 out_port,
u32 fib_index,
u8 proto,
58 nat64_db_bib_entry_t *bibe;
74 #define _(N, i, n, s) \ 75 case SNAT_PROTOCOL_##N: \ 76 pool_get (db->bib._##n##_bib, bibe); \ 77 kv.value = bibe - db->bib._##n##_bib; \ 84 kv.
value = bibe - db->
bib._unk_proto_bib;
91 bibe->in_addr.as_u64[0] = in_addr->
as_u64[0];
92 bibe->in_addr.as_u64[1] = in_addr->
as_u64[1];
93 bibe->in_port = in_port;
94 bibe->out_addr.as_u32 = out_addr->
as_u32;
95 bibe->out_port = out_port;
96 bibe->fib_index = fib_index;
98 bibe->is_static = is_static;
101 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
102 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
104 bibe_key.
port = bibe->in_port;
105 bibe_key.
proto = bibe->proto;
110 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 1);
113 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
115 bibe_key.
port = bibe->out_port;
119 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 1);
132 nat64_db_bib_entry_t *bib;
133 u32 *ste_to_be_free = 0, *ste_index, bibe_index;
134 nat64_db_st_entry_t *st, *ste;
140 #define _(N, i, n, s) \ 141 case SNAT_PROTOCOL_##N: \ 142 bib = db->bib._##n##_bib; \ 143 st = db->st._##n##_st; \ 149 bib = db->
bib._unk_proto_bib;
150 st = db->
st._unk_proto_st;
156 bibe_index = bibe - bib;
163 if (ste->bibe_index == bibe_index)
164 vec_add1 (ste_to_be_free, ste - st);}
172 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
173 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
175 bibe_key.
port = bibe->in_port;
176 bibe_key.
proto = bibe->proto;
181 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 0);
184 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
186 bibe_key.
port = bibe->out_port;
190 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 0);
197 bibe->in_port, bibe->out_port,
205 nat64_db_bib_entry_t *
207 u8 proto,
u32 fib_index,
u8 is_ip6)
209 nat64_db_bib_entry_t *bibe = 0;
212 nat64_db_bib_entry_t *bib;
217 #define _(N, i, n, s) \ 218 case SNAT_PROTOCOL_##N: \ 219 bib = db->bib._##n##_bib; \ 225 bib = db->
bib._unk_proto_bib;
229 bibe_key.
addr.as_u64[0] = addr->as_u64[0];
230 bibe_key.
addr.as_u64[1] = addr->as_u64[1];
232 bibe_key.
port = port;
233 bibe_key.
proto = proto;
240 if (!clib_bihash_search_24_8
251 nat64_db_bib_entry_t *bib, *bibe;
256 #define _(N, i, n, s) \ 257 bib = db->bib._##n##_bib; \ 258 pool_foreach (bibe, bib, ({ \ 259 if (fn (bibe, ctx)) \ 264 bib = db->
bib._unk_proto_bib;
276 #define _(N, i, n, s) \ 277 case SNAT_PROTOCOL_##N: \ 278 bib = db->bib._##n##_bib; \ 284 bib = db->
bib._unk_proto_bib;
298 nat64_db_bib_entry_t *
301 nat64_db_bib_entry_t *bib;
306 #define _(N, i, n, s) \ 307 case SNAT_PROTOCOL_##N: \ 308 bib = db->bib._##n##_bib; \ 314 bib = db->
bib._unk_proto_bib;
325 nat64_db_st_entry_t *st, *ste;
330 #define _(N, i, n, s) \ 331 st = db->st._##n##_st; \ 332 pool_foreach (ste, st, ({ \ 338 st = db->
st._unk_proto_st;
350 #define _(N, i, n, s) \ 351 case SNAT_PROTOCOL_##N: \ 352 st = db->st._##n##_st; \ 358 st = db->
st._unk_proto_st;
372 nat64_db_st_entry_t *
377 nat64_db_st_entry_t *ste;
378 nat64_db_bib_entry_t *bib;
393 #define _(N, i, n, s) \ 394 case SNAT_PROTOCOL_##N: \ 395 pool_get (db->st._##n##_st, ste); \ 396 kv.value = ste - db->st._##n##_st; \ 397 bib = db->bib._##n##_bib; \ 404 kv.
value = ste - db->
st._unk_proto_st;
405 bib = db->
bib._unk_proto_bib;
412 ste->in_r_addr.as_u64[0] = in_r_addr->
as_u64[0];
413 ste->in_r_addr.as_u64[1] = in_r_addr->
as_u64[1];
414 ste->out_r_addr.as_u32 = out_r_addr->
as_u32;
415 ste->r_port = r_port;
416 ste->bibe_index = bibe - bib;
417 ste->proto = bibe->proto;
424 ste_key.
l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
425 ste_key.
l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
426 ste_key.
r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
427 ste_key.
r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
429 ste_key.
l_port = bibe->in_port;
430 ste_key.
r_port = ste->r_port;
431 ste_key.
proto = ste->proto;
438 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 1);
441 ste_key.
l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
442 ste_key.
r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
443 ste_key.
l_port = bibe->out_port;
444 ste_key.
r_port = ste->r_port;
445 ste_key.
proto = ste->proto;
452 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 1);
456 bibe->proto, bibe->in_port, bibe->out_port,
457 &ste->in_r_addr, &ste->out_r_addr,
461 &bibe->out_addr, bibe->out_port, &ste->out_r_addr,
462 ste->r_port, bibe->proto);
469 nat64_db_st_entry_t *st;
470 nat64_db_bib_entry_t *bib, *bibe;
478 #define _(N, i, n, s) \ 479 case SNAT_PROTOCOL_##N: \ 480 st = db->st._##n##_st; \ 481 bib = db->bib._##n##_bib; \ 487 st = db->
st._unk_proto_st;
488 bib = db->
bib._unk_proto_bib;
498 ste_key.
l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
499 ste_key.
l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
500 ste_key.
r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
501 ste_key.
r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
503 ste_key.
l_port = bibe->in_port;
504 ste_key.
r_port = ste->r_port;
505 ste_key.
proto = ste->proto;
512 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 0);
515 ste_key.
l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
516 ste_key.
r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
517 ste_key.
l_port = bibe->out_port;
518 ste_key.
r_port = ste->r_port;
519 ste_key.
proto = ste->proto;
526 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 0);
530 bibe->proto, bibe->in_port, bibe->out_port,
531 &ste->in_r_addr, &ste->out_r_addr,
535 &bibe->out_addr, bibe->out_port, &ste->out_r_addr,
536 ste->r_port, bibe->proto);
545 if (!bibe->is_static && !bibe->ses_num)
549 nat64_db_st_entry_t *
551 ip46_address_t * r_addr,
u16 l_port,
u16 r_port,
552 u8 proto,
u32 fib_index,
u8 is_ip6)
554 nat64_db_st_entry_t *ste = 0;
555 nat64_db_st_entry_t *st;
562 #define _(N, i, n, s) \ 563 case SNAT_PROTOCOL_##N: \ 564 st = db->st._##n##_st; \ 570 st = db->
st._unk_proto_st;
575 ste_key.
l_addr.as_u64[0] = l_addr->as_u64[0];
576 ste_key.
l_addr.as_u64[1] = l_addr->as_u64[1];
577 ste_key.
r_addr.as_u64[0] = r_addr->as_u64[0];
578 ste_key.
r_addr.as_u64[1] = r_addr->as_u64[1];
582 ste_key.
proto = proto;
590 if (!clib_bihash_search_48_8
600 nat64_db_st_entry_t *st;
605 #define _(N, i, n, s) \ 606 case SNAT_PROTOCOL_##N: \ 607 st = db->st._##n##_st; \ 613 st = db->
st._unk_proto_st;
620 nat64_db_st_entry_t *
623 nat64_db_st_entry_t *st;
628 #define _(N, i, n, s) \ 629 case SNAT_PROTOCOL_##N: \ 630 st = db->st._##n##_st; \ 636 st = db->
st._unk_proto_st;
646 u32 *ste_to_be_free = 0, *ste_index;
647 nat64_db_st_entry_t *st, *ste;
650 #define _(N, i, n, s) \ 651 st = db->st._##n##_st; \ 652 pool_foreach (ste, st, ({\ 653 if (i == SNAT_PROTOCOL_TCP && !ste->tcp_state) \ 655 if (ste->expire < now) \ 656 vec_add1 (ste_to_be_free, ste - st); \ 658 vec_foreach (ste_index, ste_to_be_free) \ 659 nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0])); \ 660 vec_free (ste_to_be_free); \ 664 st = db->
st._unk_proto_st;
666 if (ste->expire < now)
667 vec_add1 (ste_to_be_free, ste - st);
678 u32 *ste_to_be_free = 0, *ste_index;
679 nat64_db_st_entry_t *st, *ste;
680 nat64_db_bib_entry_t *bibe;
684 #define _(N, i, n, s) \ 685 st = db->st._##n##_st; \ 686 pool_foreach (ste, st, ({ \ 687 bibe = pool_elt_at_index (db->bib._##n##_bib, ste->bibe_index); \ 688 if (bibe->out_addr.as_u32 == out_addr->as_u32) \ 689 vec_add1 (ste_to_be_free, ste - st); \ 691 vec_foreach (ste_index, ste_to_be_free) \ 692 nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0])); \ 693 vec_free (ste_to_be_free); \ 697 st = db->
st._unk_proto_st;
700 if (bibe->out_addr.as_u32 == out_addr->
as_u32)
701 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.
void nat_syslog_nat64_sdel(u32 sfibix, ip6_address_t *isaddr, u16 isport, ip4_address_t *xsaddr, u16 xsport, ip4_address_t *xdaddr, u16 xdport, snat_protocol_t proto)
#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.
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
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_syslog_nat64_sadd(u32 sfibix, ip6_address_t *isaddr, u16 isport, ip4_address_t *xsaddr, u16 xsport, ip4_address_t *xdaddr, u16 xdport, snat_protocol_t proto)
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)
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
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
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.