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 *
56 u16 out_port,
u32 fib_index,
u8 proto,
59 nat64_db_bib_entry_t *bibe;
75 #define _(N, i, n, s) \ 76 case SNAT_PROTOCOL_##N: \ 77 pool_get (db->bib._##n##_bib, bibe); \ 78 kv.value = bibe - db->bib._##n##_bib; \ 85 kv.
value = bibe - db->
bib._unk_proto_bib;
92 bibe->in_addr.as_u64[0] = in_addr->
as_u64[0];
93 bibe->in_addr.as_u64[1] = in_addr->
as_u64[1];
94 bibe->in_port = in_port;
95 bibe->out_addr.as_u32 = out_addr->
as_u32;
96 bibe->out_port = out_port;
97 bibe->fib_index = fib_index;
99 bibe->is_static = is_static;
102 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
103 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
105 bibe_key.
port = bibe->in_port;
106 bibe_key.
proto = bibe->proto;
111 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 1);
114 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
116 bibe_key.
port = bibe->out_port;
120 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 1);
130 nat64_db_bib_entry_t * bibe)
134 nat64_db_bib_entry_t *bib;
135 u32 *ste_to_be_free = 0, *ste_index, bibe_index;
136 nat64_db_st_entry_t *st, *ste;
142 #define _(N, i, n, s) \ 143 case SNAT_PROTOCOL_##N: \ 144 bib = db->bib._##n##_bib; \ 145 st = db->st._##n##_st; \ 151 bib = db->
bib._unk_proto_bib;
152 st = db->
st._unk_proto_st;
158 bibe_index = bibe - bib;
165 if (ste->bibe_index == bibe_index)
166 vec_add1 (ste_to_be_free, ste - st);}
175 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
176 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
178 bibe_key.
port = bibe->in_port;
179 bibe_key.
proto = bibe->proto;
184 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 0);
187 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
189 bibe_key.
port = bibe->out_port;
193 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 0);
200 bibe->proto, bibe->in_port, bibe->out_port,
208 nat64_db_bib_entry_t *
210 u8 proto,
u32 fib_index,
u8 is_ip6)
212 nat64_db_bib_entry_t *bibe = 0;
215 nat64_db_bib_entry_t *bib;
220 #define _(N, i, n, s) \ 221 case SNAT_PROTOCOL_##N: \ 222 bib = db->bib._##n##_bib; \ 228 bib = db->
bib._unk_proto_bib;
232 bibe_key.
addr.as_u64[0] = addr->as_u64[0];
233 bibe_key.
addr.as_u64[1] = addr->as_u64[1];
235 bibe_key.
port = port;
236 bibe_key.
proto = proto;
243 if (!clib_bihash_search_24_8
254 nat64_db_bib_entry_t *bib, *bibe;
259 #define _(N, i, n, s) \ 260 bib = db->bib._##n##_bib; \ 261 pool_foreach (bibe, bib, ({ \ 262 if (fn (bibe, ctx)) \ 267 bib = db->
bib._unk_proto_bib;
279 #define _(N, i, n, s) \ 280 case SNAT_PROTOCOL_##N: \ 281 bib = db->bib._##n##_bib; \ 287 bib = db->
bib._unk_proto_bib;
301 nat64_db_bib_entry_t *
304 nat64_db_bib_entry_t *bib;
309 #define _(N, i, n, s) \ 310 case SNAT_PROTOCOL_##N: \ 311 bib = db->bib._##n##_bib; \ 317 bib = db->
bib._unk_proto_bib;
328 nat64_db_st_entry_t *st, *ste;
333 #define _(N, i, n, s) \ 334 st = db->st._##n##_st; \ 335 pool_foreach (ste, st, ({ \ 341 st = db->
st._unk_proto_st;
353 #define _(N, i, n, s) \ 354 case SNAT_PROTOCOL_##N: \ 355 st = db->st._##n##_st; \ 361 st = db->
st._unk_proto_st;
375 nat64_db_st_entry_t *
377 nat64_db_bib_entry_t * bibe,
381 nat64_db_st_entry_t *ste;
382 nat64_db_bib_entry_t *bib;
397 #define _(N, i, n, s) \ 398 case SNAT_PROTOCOL_##N: \ 399 pool_get (db->st._##n##_st, ste); \ 400 kv.value = ste - db->st._##n##_st; \ 401 bib = db->bib._##n##_bib; \ 408 kv.
value = ste - db->
st._unk_proto_st;
409 bib = db->
bib._unk_proto_bib;
416 ste->in_r_addr.as_u64[0] = in_r_addr->
as_u64[0];
417 ste->in_r_addr.as_u64[1] = in_r_addr->
as_u64[1];
418 ste->out_r_addr.as_u32 = out_r_addr->
as_u32;
419 ste->r_port = r_port;
420 ste->bibe_index = bibe - bib;
421 ste->proto = bibe->proto;
428 ste_key.
l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
429 ste_key.
l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
430 ste_key.
r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
431 ste_key.
r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
433 ste_key.
l_port = bibe->in_port;
434 ste_key.
r_port = ste->r_port;
435 ste_key.
proto = ste->proto;
442 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 1);
445 ste_key.
l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
446 ste_key.
r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
447 ste_key.
l_port = bibe->out_port;
448 ste_key.
r_port = ste->r_port;
449 ste_key.
proto = ste->proto;
456 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 1);
460 &bibe->out_addr, bibe->proto,
461 bibe->in_port, bibe->out_port,
462 &ste->in_r_addr, &ste->out_r_addr,
466 &bibe->out_addr, bibe->out_port, &ste->out_r_addr,
467 ste->r_port, bibe->proto);
475 nat64_db_st_entry_t *st;
476 nat64_db_bib_entry_t *bib, *bibe;
484 #define _(N, i, n, s) \ 485 case SNAT_PROTOCOL_##N: \ 486 st = db->st._##n##_st; \ 487 bib = db->bib._##n##_bib; \ 493 st = db->
st._unk_proto_st;
494 bib = db->
bib._unk_proto_bib;
504 ste_key.
l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
505 ste_key.
l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
506 ste_key.
r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
507 ste_key.
r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
509 ste_key.
l_port = bibe->in_port;
510 ste_key.
r_port = ste->r_port;
511 ste_key.
proto = ste->proto;
518 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 0);
521 ste_key.
l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
522 ste_key.
r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
523 ste_key.
l_port = bibe->out_port;
524 ste_key.
r_port = ste->r_port;
525 ste_key.
proto = ste->proto;
532 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 0);
536 &bibe->out_addr, bibe->proto,
537 bibe->in_port, bibe->out_port,
538 &ste->in_r_addr, &ste->out_r_addr,
542 &bibe->out_addr, bibe->out_port, &ste->out_r_addr,
543 ste->r_port, bibe->proto);
552 if (!bibe->is_static && !bibe->ses_num)
556 nat64_db_st_entry_t *
558 ip46_address_t * r_addr,
u16 l_port,
u16 r_port,
559 u8 proto,
u32 fib_index,
u8 is_ip6)
561 nat64_db_st_entry_t *ste = 0;
562 nat64_db_st_entry_t *st;
569 #define _(N, i, n, s) \ 570 case SNAT_PROTOCOL_##N: \ 571 st = db->st._##n##_st; \ 577 st = db->
st._unk_proto_st;
582 ste_key.
l_addr.as_u64[0] = l_addr->as_u64[0];
583 ste_key.
l_addr.as_u64[1] = l_addr->as_u64[1];
584 ste_key.
r_addr.as_u64[0] = r_addr->as_u64[0];
585 ste_key.
r_addr.as_u64[1] = r_addr->as_u64[1];
589 ste_key.
proto = proto;
597 if (!clib_bihash_search_48_8
607 nat64_db_st_entry_t *st;
612 #define _(N, i, n, s) \ 613 case SNAT_PROTOCOL_##N: \ 614 st = db->st._##n##_st; \ 620 st = db->
st._unk_proto_st;
627 nat64_db_st_entry_t *
630 nat64_db_st_entry_t *st;
635 #define _(N, i, n, s) \ 636 case SNAT_PROTOCOL_##N: \ 637 st = db->st._##n##_st; \ 643 st = db->
st._unk_proto_st;
653 u32 *ste_to_be_free = 0, *ste_index;
654 nat64_db_st_entry_t *st, *ste;
657 #define _(N, i, n, s) \ 658 st = db->st._##n##_st; \ 659 pool_foreach (ste, st, ({\ 660 if (i == SNAT_PROTOCOL_TCP && !ste->tcp_state) \ 662 if (ste->expire < now) \ 663 vec_add1 (ste_to_be_free, ste - st); \ 665 vec_foreach (ste_index, ste_to_be_free) \ 666 nat64_db_st_entry_free (thread_index, db, \ 667 pool_elt_at_index(st, ste_index[0])); \ 668 vec_free (ste_to_be_free); \ 672 st = db->
st._unk_proto_st;
674 if (ste->expire < now)
675 vec_add1 (ste_to_be_free, ste - st);
688 u32 *ste_to_be_free = 0, *ste_index;
689 nat64_db_st_entry_t *st, *ste;
690 nat64_db_bib_entry_t *bibe;
694 #define _(N, i, n, s) \ 695 st = db->st._##n##_st; \ 696 pool_foreach (ste, st, ({ \ 697 bibe = pool_elt_at_index (db->bib._##n##_bib, ste->bibe_index); \ 698 if (bibe->out_addr.as_u32 == out_addr->as_u32) \ 699 vec_add1 (ste_to_be_free, ste - st); \ 701 vec_foreach (ste_index, ste_to_be_free) \ 702 nat64_db_st_entry_free (thread_index, db, \ 703 pool_elt_at_index(st, ste_index[0])); \ 704 vec_free (ste_to_be_free); \ 708 st = db->
st._unk_proto_st;
711 if (bibe->out_addr.as_u32 == out_addr->
as_u32)
712 vec_add1 (ste_to_be_free, ste - st);
void nat64_db_free_out_addr(u32 thread_index, nat64_db_t *db, ip4_address_t *out_addr)
Free sessions using specific outside address.
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
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.
nat64_db_st_entry_t * nat64_db_st_entry_create(u32 thread_index, 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.
void nat_ipfix_logging_max_bibs(u32 thread_index, u32 limit)
Generate maximum BIB entries exceeded event.
clib_bihash_48_8_t in2out
void nat_ipfix_logging_max_sessions(u32 thread_index, u32 limit)
Generate maximum session entries exceeded event.
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(u32 thread_index, 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 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_nat64_bib(u32 thread_index, 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.
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. ...
void nat_ipfix_logging_nat64_session(u32 thread_index, 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.
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.
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.
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_bib_entry_free(u32 thread_index, nat64_db_t *db, nat64_db_bib_entry_t *bibe)
Free NAT64 BIB entry.
void nat64_db_st_entry_free(u32 thread_index, 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