24 u32 bib_buckets = 1024;
25 u32 bib_memory_size = 128 << 20;
26 u32 st_buckets = 2048;
27 u32 st_memory_size = 256 << 20;
29 clib_bihash_init_24_8 (&db->
bib.
in2out,
"bib-in2out", bib_buckets,
32 clib_bihash_init_24_8 (&db->
bib.
out2in,
"bib-out2in", bib_buckets,
35 clib_bihash_init_48_8 (&db->
st.
in2out,
"st-in2out", st_buckets,
38 clib_bihash_init_48_8 (&db->
st.
out2in,
"st-out2in", st_buckets,
44 nat64_db_bib_entry_t *
50 nat64_db_bib_entry_t *bibe;
58 #define _(N, i, n, s) \ 59 case SNAT_PROTOCOL_##N: \ 60 pool_get (db->bib._##n##_bib, bibe); \ 61 kv.value = bibe - db->bib._##n##_bib; \ 70 memset (bibe, 0,
sizeof (*bibe));
71 bibe->in_addr.as_u64[0] = in_addr->
as_u64[0];
72 bibe->in_addr.as_u64[1] = in_addr->
as_u64[1];
73 bibe->in_port = in_port;
74 bibe->out_addr.as_u32 = out_addr->
as_u32;
75 bibe->out_port = out_port;
76 bibe->fib_index = fib_index;
78 bibe->is_static = is_static;
81 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
82 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
84 bibe_key.
port = bibe->in_port;
85 bibe_key.
proto = bibe->proto;
90 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 1);
92 memset (&bibe_key.
addr, 0, sizeof (bibe_key.
addr));
93 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
95 bibe_key.
port = bibe->out_port;
99 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 1);
109 nat64_db_bib_entry_t *bib;
110 u32 *ste_to_be_free = 0, *ste_index, bibe_index;
111 nat64_db_st_entry_t *st, *ste;
116 #define _(N, i, n, s) \ 117 case SNAT_PROTOCOL_##N: \ 118 bib = db->bib._##n##_bib; \ 119 st = db->st._##n##_st; \ 129 bibe_index = bibe - bib;
136 if (ste->bibe_index == bibe_index)
137 vec_add1 (ste_to_be_free, ste - st);}
145 bibe_key.
addr.as_u64[0] = bibe->in_addr.as_u64[0];
146 bibe_key.
addr.as_u64[1] = bibe->in_addr.as_u64[1];
148 bibe_key.
port = bibe->in_port;
149 bibe_key.
proto = bibe->proto;
154 clib_bihash_add_del_24_8 (&db->
bib.
in2out, &kv, 0);
156 memset (&bibe_key.
addr, 0, sizeof (bibe_key.
addr));
157 bibe_key.
addr.ip4.as_u32 = bibe->out_addr.as_u32;
159 bibe_key.
port = bibe->out_port;
163 clib_bihash_add_del_24_8 (&db->
bib.
out2in, &kv, 0);
170 nat64_db_bib_entry_t *
174 nat64_db_bib_entry_t *bibe = 0;
177 nat64_db_bib_entry_t *bib;
182 #define _(N, i, n, s) \ 183 case SNAT_PROTOCOL_##N: \ 184 bib = db->bib._##n##_bib; \ 194 bibe_key.
addr.as_u64[0] = addr->as_u64[0];
195 bibe_key.
addr.as_u64[1] = addr->as_u64[1];
197 bibe_key.
port = port;
198 bibe_key.
proto = proto;
205 if (!clib_bihash_search_24_8
216 nat64_db_bib_entry_t *bib, *bibe;
221 #define _(N, i, n, s) \ 222 case SNAT_PROTOCOL_##N: \ 223 bib = db->bib._##n##_bib; \ 242 nat64_db_bib_entry_t *
246 nat64_db_bib_entry_t *bib;
251 #define _(N, i, n, s) \ 252 case SNAT_PROTOCOL_##N: \ 253 bib = db->bib._##n##_bib; \ 270 nat64_db_st_entry_t *st, *ste;
275 #define _(N, i, n, s) \ 276 case SNAT_PROTOCOL_##N: \ 277 st = db->st._##n##_st; \ 296 nat64_db_st_entry_t *
301 nat64_db_st_entry_t *ste;
302 nat64_db_bib_entry_t *bib;
310 #define _(N, i, n, s) \ 311 case SNAT_PROTOCOL_##N: \ 312 pool_get (db->st._##n##_st, ste); \ 313 kv.value = ste - db->st._##n##_st; \ 314 bib = db->bib._##n##_bib; \ 323 memset (ste, 0,
sizeof (*ste));
324 ste->in_r_addr.as_u64[0] = in_r_addr->
as_u64[0];
325 ste->in_r_addr.as_u64[1] = in_r_addr->
as_u64[1];
326 ste->out_r_addr.as_u32 = out_r_addr->
as_u32;
327 ste->r_port = r_port;
328 ste->bibe_index = bibe - bib;
329 ste->proto = bibe->proto;
335 memset (&ste_key, 0,
sizeof (ste_key));
336 ste_key.
l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
337 ste_key.
l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
338 ste_key.
r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
339 ste_key.
r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
341 ste_key.
l_port = bibe->in_port;
342 ste_key.
r_port = ste->r_port;
343 ste_key.
proto = ste->proto;
350 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 1);
352 memset (&ste_key, 0,
sizeof (ste_key));
353 ste_key.
l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
354 ste_key.
r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
355 ste_key.
l_port = bibe->out_port;
356 ste_key.
r_port = ste->r_port;
357 ste_key.
proto = ste->proto;
364 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 1);
372 nat64_db_st_entry_t *st;
373 nat64_db_bib_entry_t *bib, *bibe;
380 #define _(N, i, n, s) \ 381 case SNAT_PROTOCOL_##N: \ 382 st = db->st._##n##_st; \ 383 bib = db->bib._##n##_bib; \ 396 memset (&ste_key, 0,
sizeof (ste_key));
397 ste_key.
l_addr.as_u64[0] = bibe->in_addr.as_u64[0];
398 ste_key.
l_addr.as_u64[1] = bibe->in_addr.as_u64[1];
399 ste_key.
r_addr.as_u64[0] = ste->in_r_addr.as_u64[0];
400 ste_key.
r_addr.as_u64[1] = ste->in_r_addr.as_u64[1];
402 ste_key.
l_port = bibe->in_port;
403 ste_key.
r_port = ste->r_port;
404 ste_key.
proto = ste->proto;
411 clib_bihash_add_del_48_8 (&db->
st.
in2out, &kv, 0);
413 memset (&ste_key, 0,
sizeof (ste_key));
414 ste_key.
l_addr.ip4.as_u32 = bibe->out_addr.as_u32;
415 ste_key.
r_addr.ip4.as_u32 = ste->out_r_addr.as_u32;
416 ste_key.
l_port = bibe->out_port;
417 ste_key.
r_port = ste->r_port;
418 ste_key.
proto = ste->proto;
425 clib_bihash_add_del_48_8 (&db->
st.
out2in, &kv, 0);
434 if (!bibe->is_static && !bibe->ses_num)
438 nat64_db_st_entry_t *
440 ip46_address_t * r_addr,
u16 l_port,
u16 r_port,
443 nat64_db_st_entry_t *ste = 0;
444 nat64_db_st_entry_t *st;
451 #define _(N, i, n, s) \ 452 case SNAT_PROTOCOL_##N: \ 453 st = db->st._##n##_st; \ 463 memset (&ste_key, 0,
sizeof (ste_key));
464 ste_key.
l_addr.as_u64[0] = l_addr->as_u64[0];
465 ste_key.
l_addr.as_u64[1] = l_addr->as_u64[1];
466 ste_key.
r_addr.as_u64[0] = r_addr->as_u64[0];
467 ste_key.
r_addr.as_u64[1] = r_addr->as_u64[1];
471 ste_key.
proto = proto;
479 if (!clib_bihash_search_48_8
489 u32 *ste_to_be_free = 0, *ste_index;
490 nat64_db_st_entry_t *st, *ste;
493 #define _(N, i, n, s) \ 494 st = db->st._##n##_st; \ 495 pool_foreach (ste, st, ({\ 496 if (i == SNAT_PROTOCOL_TCP && !ste->tcp_state) \ 498 if (ste->expire < now) \ 499 vec_add1 (ste_to_be_free, ste - st); \ 501 vec_foreach (ste_index, ste_to_be_free) \ 502 nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0])); \ 503 vec_free (ste_to_be_free); \
void nat64_db_st_walk(nat64_db_t *db, snat_protocol_t proto, nat64_db_st_walk_fn_t fn, void *ctx)
Walk NAT64 session table.
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, snat_protocol_t proto, u8 is_static)
Create new NAT64 BIB entry.
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.
#define vec_add1(V, E)
Add 1 element to end of vector (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.
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, snat_protocol_t proto, u32 fib_index, u8 is_ip6)
Find NAT64 session table entry.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
foreach_snat_protocol clib_bihash_48_8_t in2out
nat64_db_bib_entry_t * nat64_db_bib_entry_find(nat64_db_t *db, ip46_address_t *addr, u16 port, snat_protocol_t proto, u32 fib_index, u8 is_ip6)
Find NAT64 BIB entry.
#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.
void nat64_db_bib_walk(nat64_db_t *db, snat_protocol_t proto, nat64_db_bib_walk_fn_t fn, void *ctx)
Walk NAT64 BIB.
#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.
foreach_snat_protocol clib_bihash_24_8_t in2out
nat64_db_bib_entry_t * nat64_db_bib_entry_by_index(nat64_db_t *db, snat_protocol_t proto, u32 bibe_index)
Get BIB entry by index and protocol.
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
clib_bihash_24_8_t out2in
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.
int nat64_db_init(nat64_db_t *db)
Initialize NAT64 DB.
clib_bihash_48_8_t out2in