#include <nat/nat64_db.h>
#include <nat/nat_ipfix_logging.h>
#include <nat/nat_inlines.h>
+#include <nat/nat_syslog.h>
#include <vnet/fib/fib_table.h>
int
-nat64_db_init (nat64_db_t * db, u32 bib_buckets, u32 bib_memory_size,
- u32 st_buckets, u32 st_memory_size,
+nat64_db_init (nat64_db_t * db, u32 bib_buckets, uword bib_memory_size,
+ u32 st_buckets, uword st_memory_size,
nat64_db_free_addr_port_function_t free_addr_port_cb)
{
clib_bihash_init_24_8 (&db->bib.in2out, "bib-in2out", bib_buckets,
}
nat64_db_bib_entry_t *
-nat64_db_bib_entry_create (nat64_db_t * db, ip6_address_t * in_addr,
+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)
if (db->bib.bib_entries_num >= db->bib.limit)
{
db->free_addr_port_cb (db, out_addr, out_port, proto);
- nat_ipfix_logging_max_bibs (db->bib.limit);
+ nat_ipfix_logging_max_bibs (thread_index, db->bib.limit);
return 0;
}
/* create pool entry */
- switch (ip_proto_to_snat_proto (proto))
+ switch (ip_proto_to_nat_proto (proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
pool_get (db->bib._##n##_bib, bibe); \
kv.value = bibe - db->bib._##n##_bib; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
clib_bihash_add_del_24_8 (&db->bib.out2in, &kv, 1);
fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
- nat_ipfix_logging_nat64_bib (in_addr, out_addr, proto, in_port, out_port,
- fib->ft_table_id, 1);
+ nat_ipfix_logging_nat64_bib (thread_index, in_addr, out_addr, proto,
+ in_port, out_port, fib->ft_table_id, 1);
return bibe;
}
void
-nat64_db_bib_entry_free (nat64_db_t * db, nat64_db_bib_entry_t * bibe)
+nat64_db_bib_entry_free (u32 thread_index, nat64_db_t * db,
+ nat64_db_bib_entry_t * bibe)
{
nat64_db_bib_entry_key_t bibe_key;
clib_bihash_kv_24_8_t kv;
nat64_db_st_entry_t *st, *ste;
fib_table_t *fib;
- switch (ip_proto_to_snat_proto (bibe->proto))
+ switch (ip_proto_to_nat_proto (bibe->proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
bib = db->bib._##n##_bib; \
st = db->st._##n##_st; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
vec_add1 (ste_to_be_free, ste - st);}
));
vec_foreach (ste_index, ste_to_be_free)
- nat64_db_st_entry_free (db, pool_elt_at_index (st, ste_index[0]));
+ nat64_db_st_entry_free (thread_index, db,
+ pool_elt_at_index (st, ste_index[0]));
vec_free (ste_to_be_free);
}
db->free_addr_port_cb (db, &bibe->out_addr, bibe->out_port, bibe->proto);
fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
- nat_ipfix_logging_nat64_bib (&bibe->in_addr, &bibe->out_addr, bibe->proto,
- bibe->in_port, bibe->out_port,
+ nat_ipfix_logging_nat64_bib (thread_index, &bibe->in_addr, &bibe->out_addr,
+ bibe->proto, bibe->in_port, bibe->out_port,
fib->ft_table_id, 0);
/* delete from pool */
clib_bihash_kv_24_8_t kv, value;
nat64_db_bib_entry_t *bib;
- switch (ip_proto_to_snat_proto (proto))
+ switch (ip_proto_to_nat_proto (proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
bib = db->bib._##n##_bib; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
if (fn (bibe, ctx)) \
return; \
}));
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
bib = db->bib._unk_proto_bib;
pool_foreach (bibe, bib, ({
}
else
{
- switch (ip_proto_to_snat_proto (proto))
+ switch (ip_proto_to_nat_proto (proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
bib = db->bib._##n##_bib; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
{
nat64_db_bib_entry_t *bib;
- switch (ip_proto_to_snat_proto (proto))
+ switch (ip_proto_to_nat_proto (proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
bib = db->bib._##n##_bib; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
if (fn (ste, ctx)) \
return; \
}));
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
st = db->st._unk_proto_st;
pool_foreach (ste, st, ({
}
else
{
- switch (ip_proto_to_snat_proto (proto))
+ switch (ip_proto_to_nat_proto (proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
st = db->st._##n##_st; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
}
nat64_db_st_entry_t *
-nat64_db_st_entry_create (nat64_db_t * db, nat64_db_bib_entry_t * bibe,
+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)
{
if (db->st.st_entries_num >= db->st.limit)
{
- nat_ipfix_logging_max_sessions (db->st.limit);
+ nat_ipfix_logging_max_sessions (thread_index, db->st.limit);
return 0;
}
/* create pool entry */
- switch (ip_proto_to_snat_proto (bibe->proto))
+ switch (ip_proto_to_nat_proto (bibe->proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
pool_get (db->st._##n##_st, ste); \
kv.value = ste - db->st._##n##_st; \
bib = db->bib._##n##_bib; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
clib_bihash_add_del_48_8 (&db->st.out2in, &kv, 1);
fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
- nat_ipfix_logging_nat64_session (&bibe->in_addr, &bibe->out_addr,
- bibe->proto, bibe->in_port, bibe->out_port,
+ nat_ipfix_logging_nat64_session (thread_index, &bibe->in_addr,
+ &bibe->out_addr, bibe->proto,
+ bibe->in_port, bibe->out_port,
&ste->in_r_addr, &ste->out_r_addr,
ste->r_port, ste->r_port, fib->ft_table_id,
1);
-
+ nat_syslog_nat64_sadd (bibe->fib_index, &bibe->in_addr, bibe->in_port,
+ &bibe->out_addr, bibe->out_port, &ste->out_r_addr,
+ ste->r_port, bibe->proto);
return ste;
}
void
-nat64_db_st_entry_free (nat64_db_t * db, nat64_db_st_entry_t * ste)
+nat64_db_st_entry_free (u32 thread_index,
+ nat64_db_t * db, nat64_db_st_entry_t * ste)
{
nat64_db_st_entry_t *st;
nat64_db_bib_entry_t *bib, *bibe;
clib_bihash_kv_48_8_t kv;
fib_table_t *fib;
- switch (ip_proto_to_snat_proto (ste->proto))
+ switch (ip_proto_to_nat_proto (ste->proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
st = db->st._##n##_st; \
bib = db->bib._##n##_bib; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
clib_bihash_add_del_48_8 (&db->st.out2in, &kv, 0);
fib = fib_table_get (bibe->fib_index, FIB_PROTOCOL_IP6);
- nat_ipfix_logging_nat64_session (&bibe->in_addr, &bibe->out_addr,
- bibe->proto, bibe->in_port, bibe->out_port,
+ nat_ipfix_logging_nat64_session (thread_index, &bibe->in_addr,
+ &bibe->out_addr, bibe->proto,
+ bibe->in_port, bibe->out_port,
&ste->in_r_addr, &ste->out_r_addr,
ste->r_port, ste->r_port, fib->ft_table_id,
0);
+ nat_syslog_nat64_sdel (bibe->fib_index, &bibe->in_addr, bibe->in_port,
+ &bibe->out_addr, bibe->out_port, &ste->out_r_addr,
+ ste->r_port, bibe->proto);
/* delete from pool */
pool_put (st, ste);
/* delete BIB entry if last session and dynamic */
if (!bibe->is_static && !bibe->ses_num)
- nat64_db_bib_entry_free (db, bibe);
+ nat64_db_bib_entry_free (thread_index, db, bibe);
}
nat64_db_st_entry_t *
nat64_db_st_entry_key_t ste_key;
clib_bihash_kv_48_8_t kv, value;
- switch (ip_proto_to_snat_proto (proto))
+ switch (ip_proto_to_nat_proto (proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
st = db->st._##n##_st; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
{
nat64_db_st_entry_t *st;
- switch (ip_proto_to_snat_proto (ste->proto))
+ switch (ip_proto_to_nat_proto (ste->proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
st = db->st._##n##_st; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
{
nat64_db_st_entry_t *st;
- switch (ip_proto_to_snat_proto (proto))
+ switch (ip_proto_to_nat_proto (proto))
{
/* *INDENT-OFF* */
#define _(N, i, n, s) \
- case SNAT_PROTOCOL_##N: \
+ case NAT_PROTOCOL_##N: \
st = db->st._##n##_st; \
break;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
/* *INDENT-ON* */
default:
}
void
-nad64_db_st_free_expired (nat64_db_t * db, u32 now)
+nad64_db_st_free_expired (u32 thread_index, nat64_db_t * db, u32 now)
{
u32 *ste_to_be_free = 0, *ste_index;
nat64_db_st_entry_t *st, *ste;
#define _(N, i, n, s) \
st = db->st._##n##_st; \
pool_foreach (ste, st, ({\
- if (i == SNAT_PROTOCOL_TCP && !ste->tcp_state) \
+ if (i == NAT_PROTOCOL_TCP && !ste->tcp_state) \
continue; \
if (ste->expire < now) \
vec_add1 (ste_to_be_free, ste - st); \
})); \
vec_foreach (ste_index, ste_to_be_free) \
- nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0])); \
+ nat64_db_st_entry_free (thread_index, db, \
+ pool_elt_at_index(st, ste_index[0])); \
vec_free (ste_to_be_free); \
ste_to_be_free = 0;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
st = db->st._unk_proto_st;
pool_foreach (ste, st, ({
vec_add1 (ste_to_be_free, ste - st);
}));
vec_foreach (ste_index, ste_to_be_free)
- nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0]));
+ nat64_db_st_entry_free (thread_index, db,
+ pool_elt_at_index(st, ste_index[0]));
vec_free (ste_to_be_free);
/* *INDENT-ON* */
}
void
-nat64_db_free_out_addr (nat64_db_t * db, ip4_address_t * out_addr)
+nat64_db_free_out_addr (u32 thread_index,
+ nat64_db_t * db, ip4_address_t * out_addr)
{
u32 *ste_to_be_free = 0, *ste_index;
nat64_db_st_entry_t *st, *ste;
vec_add1 (ste_to_be_free, ste - st); \
})); \
vec_foreach (ste_index, ste_to_be_free) \
- nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0])); \
+ nat64_db_st_entry_free (thread_index, db, \
+ pool_elt_at_index(st, ste_index[0])); \
vec_free (ste_to_be_free); \
ste_to_be_free = 0;
- foreach_snat_protocol
+ foreach_nat_protocol
#undef _
st = db->st._unk_proto_st;
pool_foreach (ste, st, ({
vec_add1 (ste_to_be_free, ste - st);
}));
vec_foreach (ste_index, ste_to_be_free)
- nat64_db_st_entry_free (db, pool_elt_at_index(st, ste_index[0]));
+ nat64_db_st_entry_free (thread_index, db,
+ pool_elt_at_index(st, ste_index[0]));
vec_free (ste_to_be_free);
db->addr_free = 0;
/* *INDENT-ON* */