summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat_api.c
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2020-05-13 11:35:57 +0000
committerOle Trøan <otroan@employees.org>2020-05-14 12:47:12 +0000
commit219fbb228f5274d2db740139a0d3258902370165 (patch)
treec7ca891e86c60cc7ed62c2b5efcd6f15326c0c4d /src/plugins/nat/nat_api.c
parent4ab5190eb4167ac4c06cd649ec8a860784ab1d41 (diff)
nat: "users" dump for ED-NAT
Since the removal of "users" concept in ED-NAT nat44_user_dump API returns empty array. This brings back previous behaviour at a considerable runtime cost until a better API is introduced. Type: improvement Change-Id: I5a45923cfeb6b8ebe6fc906601264d6567386991 Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'src/plugins/nat/nat_api.c')
-rw-r--r--src/plugins/nat/nat_api.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/plugins/nat/nat_api.c b/src/plugins/nat/nat_api.c
index 37af77d11c1..201c9d4730d 100644
--- a/src/plugins/nat/nat_api.c
+++ b/src/plugins/nat/nat_api.c
@@ -1586,6 +1586,62 @@ send_nat44_user_details (snat_user_t * u, vl_api_registration_t * reg,
}
static void
+nat_ed_user_create_helper (snat_main_per_thread_data_t * tsm,
+ snat_session_t * s)
+{
+ snat_user_key_t k;
+ k.addr = s->in2out.addr;
+ k.fib_index = s->in2out.fib_index;
+ clib_bihash_kv_8_8_t key, value;
+ key.key = k.as_u64;
+ snat_user_t *u;
+ if (clib_bihash_search_8_8 (&tsm->user_hash, &key, &value))
+ {
+ pool_get (tsm->users, u);
+ u->addr = k.addr;
+ u->fib_index = k.fib_index;
+ u->nsessions = 0;
+ u->nstaticsessions = 0;
+ key.value = u - tsm->users;
+ clib_bihash_add_del_8_8 (&tsm->user_hash, &key, 1);
+ }
+ else
+ {
+ u = pool_elt_at_index (tsm->users, value.value);
+ }
+ if (snat_is_session_static (s))
+ {
+ ++u->nstaticsessions;
+ }
+ else
+ {
+ ++u->nsessions;
+ }
+}
+
+static void
+nat_ed_users_create (snat_main_per_thread_data_t * tsm)
+{
+ snat_session_t *s;
+ /* *INDENT-OFF* */
+ pool_foreach (s, tsm->sessions, { nat_ed_user_create_helper (tsm, s); });
+ /* *INDENT-ON* */
+}
+
+static void
+nat_ed_users_destroy (snat_main_per_thread_data_t * tsm)
+{
+ snat_user_t *u;
+ /* *INDENT-OFF* */
+ pool_flush (u, tsm->users, { });
+ /* *INDENT-ON* */
+ clib_bihash_free_8_8 (&tsm->user_hash);
+ clib_bihash_init_8_8 (&tsm->user_hash, "users", snat_main.user_buckets,
+ snat_main.user_memory_size);
+ clib_bihash_set_kvp_format_fn_8_8 (&tsm->user_hash, format_user_kvp);
+}
+
+static void
vl_api_nat44_user_dump_t_handler (vl_api_nat44_user_dump_t * mp)
{
vl_api_registration_t *reg;
@@ -1603,10 +1659,18 @@ vl_api_nat44_user_dump_t_handler (vl_api_nat44_user_dump_t * mp)
/* *INDENT-OFF* */
vec_foreach (tsm, sm->per_thread_data)
{
+ if (sm->endpoint_dependent)
+ {
+ nat_ed_users_create (tsm);
+ }
pool_foreach (u, tsm->users,
({
send_nat44_user_details (u, reg, mp->context);
}));
+ if (sm->endpoint_dependent)
+ {
+ nat_ed_users_destroy (tsm);
+ }
}
/* *INDENT-ON* */
}