return 0;
}
+static void nat64_free_out_addr_and_port (struct nat64_db_s *db,
+ ip4_address_t * addr, u16 port,
+ u8 protocol);
+
void
nat64_set_hash (u32 bib_buckets, u32 bib_memory_size, u32 st_buckets,
u32 st_memory_size)
vec_foreach (db, nm->db)
{
if (nat64_db_init (db, bib_buckets, bib_memory_size, st_buckets,
- st_memory_size))
+ st_memory_size, nat64_free_out_addr_and_port))
clib_warning ("NAT64 DB init failed");
}
/* *INDENT-ON* */
if (a->fib_index != ~0)
fib_table_unlock (a->fib_index, FIB_PROTOCOL_IP6,
FIB_SOURCE_PLUGIN_HI);
+ /* Delete sessions using address */
+ /* *INDENT-OFF* */
+ vec_foreach (db, nm->db)
+ nat64_db_free_out_addr (db, &a->addr);
#define _(N, id, n, s) \
clib_bitmap_free (a->busy_##n##_port_bitmap);
foreach_snat_protocol
#undef _
- /* Delete sessions using address */
- /* *INDENT-OFF* */
- vec_foreach (db, nm->db)
- nat64_db_free_out_addr (db, &a->addr);
/* *INDENT-ON* */
- vec_del1 (nm->addr_pool, i);
+ vec_del1 (nm->addr_pool, i);
}
/* Add/del external address to FIB */
return rv;
}
-void
-nat64_free_out_addr_and_port (ip4_address_t * addr, u16 port,
- snat_protocol_t proto, u32 thread_index)
+static void
+nat64_free_out_addr_and_port (struct nat64_db_s *db, ip4_address_t * addr,
+ u16 port, u8 protocol)
{
nat64_main_t *nm = &nat64_main;
int i;
snat_address_t *a;
+ u32 thread_index = db - nm->db;
+ snat_protocol_t proto = ip_proto_to_snat_proto (protocol);
+ u16 port_host_byte_order = clib_net_to_host_u16 (port);
for (i = 0; i < vec_len (nm->addr_pool); i++)
{
#define _(N, j, n, s) \
case SNAT_PROTOCOL_##N: \
ASSERT (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \
- port) == 1); \
+ port_host_byte_order) == 1); \
clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, port, 0); \
a->busy_##n##_ports--; \
a->busy_##n##_ports_per_thread[thread_index]--; \
return VNET_API_ERROR_NO_SUCH_ENTRY;
if (!nm->sm->num_workers)
- {
- nat64_free_out_addr_and_port (out_addr, out_port, p, thread_index);
- nat64_db_bib_entry_free (db, bibe);
- }
+ nat64_db_bib_entry_free (db, bibe);
}
if (nm->sm->num_workers)
ip4_address_t * addr, u16 * port,
u32 thread_index);
-/**
- * @brief Free IPv4 address and port pair from NAT64 pool.
- *
- * @param addr IPv4 address to free.
- * @param port Port number to free.
- * @param proto L4 protocol.
- * @param thread_index Thread index.
- *
- * @returns 0 on success, non-zero value otherwise.
- */
-void nat64_free_out_addr_and_port (ip4_address_t * addr, u16 port,
- snat_protocol_t proto, u32 thread_index);
-
/**
* @brief Set UDP session timeout.
*
else
vlib_cli_output (vm, " %U", format_ip4_address, &ap->addr);
- return 0;
+#define _(N, i, n, s) \
+ vlib_cli_output (vm, " %d busy %s ports", ap->busy_##n##_ports, s);
+ foreach_snat_protocol
+#undef _
+ return 0;
}
static clib_error_t *
int
nat64_db_init (nat64_db_t * db, u32 bib_buckets, u32 bib_memory_size,
- u32 st_buckets, u32 st_memory_size)
+ u32 st_buckets, u32 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,
bib_memory_size);
clib_bihash_init_48_8 (&db->st.out2in, "st-out2in", st_buckets,
st_memory_size);
+ db->free_addr_port_cb = free_addr_port_cb;
return 0;
}
kv.key[2] = bibe_key.as_u64[2];
clib_bihash_add_del_24_8 (&db->bib.out2in, &kv, 0);
+ db->free_addr_port_cb (db, &bibe->out_addr, bibe->out_port, bibe->proto);
/* delete from pool */
pool_put (bib, bibe);
clib_bihash_48_8_t out2in;
} nat64_db_st_t;
-typedef struct
+struct nat64_db_s;
+
+/**
+ * @brief Call back function to free NAT64 pool address and port when BIB
+ * entry is deleted.
+ */
+typedef void (*nat64_db_free_addr_port_function_t) (struct nat64_db_s * db,
+ ip4_address_t * addr,
+ u16 port, u8 proto);
+
+typedef struct nat64_db_s
{
nat64_db_bib_t bib;
nat64_db_st_t st;
+ nat64_db_free_addr_port_function_t free_addr_port_cb;
} nat64_db_t;
/**
* @param bib_memory_size Memory size of BIB hash.
* @param st_buckets Number of session table hash buckets.
* @param st_memory_size Memory size of session table hash.
+ * @param free_addr_port_cb Call back function to free address and port.
*
* @returns 0 on success, non-zero value otherwise.
*/
int nat64_db_init (nat64_db_t * db, u32 bib_buckets, u32 bib_memory_size,
- u32 st_buckets, u32 st_memory_size);
+ u32 st_buckets, u32 st_memory_size,
+ nat64_db_free_addr_port_function_t free_addr_port_cb);
/**
* @brief Create new NAT64 BIB entry.
bibe =
nat64_db_bib_entry_create (db, &ip6->src_address, &out_addr,
- sport, clib_host_to_net_u16 (out_port),
- fib_index, proto, 0);
+ sport, out_port, fib_index, proto, 0);
if (!bibe)
return -1;
}
bibe =
nat64_db_bib_entry_create (db, &ip6->src_address,
- &out_addr, in_id,
- clib_host_to_net_u16 (out_id),
+ &out_addr, in_id, out_id,
fib_index, IP_PROTOCOL_ICMP, 0);
if (!bibe)
return -1;
bibe =
nat64_db_bib_entry_create (db, &ip6->src_address, &out_addr,
- sport, clib_host_to_net_u16 (out_port),
- fib_index, proto, 0);
+ sport, out_port, fib_index, proto, 0);
if (!bibe)
return -1;
}
nat64_db_bib_entry_create (db,
&ip60->src_address,
&out_addr0, udp0->src_port,
- clib_host_to_net_u16
- (out_port0), fib_index0,
+ out_port0, fib_index0,
l4_protocol0, 0);
if (!bibe0)
{