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);
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, nat_protocol_t proto)
void nat64_db_free_out_addr(u32 thread_index, nat64_db_t *db, ip4_address_t *out_addr)
Free sessions using specific outside address.
nat64_db_free_addr_port_function_t free_addr_port_cb
int nat64_db_free(nat64_db_t *db)
Free NAT64 DB.
#define pool_foreach(VAR, POOL)
Iterate through pool.
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
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.
#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.
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
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.
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(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, nat_protocol_t proto)
#define pool_free(p)
Free a pool.
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_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
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.
int nat64_db_init(nat64_db_t *db, nat64_config_t c, nat64_db_free_addr_port_function_t free_addr_port_cb)
Initialize NAT64 DB.
void nat64_db_bib_walk(nat64_db_t *db, u8 proto, nat64_db_bib_walk_fn_t fn, void *ctx)
Walk NAT64 BIB.
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.
A protocol Independent FIB table.
clib_bihash_48_8_t out2in