crypto: Add prefetching for src and dst
[vpp.git] / src / vnet / session / session_table.c
index 1f586f8..dbbe771 100644 (file)
@@ -60,6 +60,31 @@ session_table_get (u32 table_index)
   _(v6,halfopen,buckets,20000)                  \
   _(v6,halfopen,memory,(64<<20))
 
+void
+session_table_free (session_table_t *slt, u8 fib_proto)
+{
+  u8 all = fib_proto > FIB_PROTOCOL_IP6 ? 1 : 0;
+  int i;
+
+  for (i = 0; i < TRANSPORT_N_PROTOS; i++)
+    session_rules_table_free (&slt->session_rules[i]);
+
+  vec_free (slt->session_rules);
+
+  if (fib_proto == FIB_PROTOCOL_IP4 || all)
+    {
+      clib_bihash_free_16_8 (&slt->v4_session_hash);
+      clib_bihash_free_16_8 (&slt->v4_half_open_hash);
+    }
+  if (fib_proto == FIB_PROTOCOL_IP6 || all)
+    {
+      clib_bihash_free_48_8 (&slt->v6_session_hash);
+      clib_bihash_free_48_8 (&slt->v6_half_open_hash);
+    }
+
+  pool_put (lookup_tables, slt);
+}
+
 /**
  * Initialize session table hash tables
  *
@@ -129,7 +154,8 @@ session_table_init (session_table_t * slt, u8 fib_proto)
       clib_bihash_init2_48_8 (a);
     }
 
-  for (i = 0; i < TRANSPORT_N_PROTO; i++)
+  vec_validate (slt->session_rules, TRANSPORT_N_PROTOS - 1);
+  for (i = 0; i < TRANSPORT_N_PROTOS; i++)
     session_rules_table_init (&slt->session_rules[i]);
 }
 
@@ -139,11 +165,12 @@ typedef struct _ip4_session_table_walk_ctx_t
   void *ctx;
 } ip4_session_table_walk_ctx_t;
 
-void
+static int
 ip4_session_table_walk_cb (clib_bihash_kv_16_8_t * kvp, void *arg)
 {
   ip4_session_table_walk_ctx_t *ctx = arg;
   ctx->fn (kvp, ctx->ctx);
+  return (BIHASH_WALK_CONTINUE);
 }
 
 void
@@ -158,7 +185,66 @@ ip4_session_table_walk (clib_bihash_16_8_t * hash,
                                           &ctx);
 }
 
-/* *INDENT-ON* */
+u32
+session_table_memory_size (session_table_t *st)
+{
+  u64 total_size = 0;
+
+  if (clib_bihash_is_initialised_16_8 (&st->v4_session_hash))
+    {
+      clib_bihash_alloc_chunk_16_8_t *c = st->v4_session_hash.chunks;
+      while (c)
+       {
+         total_size += c->size;
+         c = c->next;
+       }
+      c = st->v4_half_open_hash.chunks;
+      while (c)
+       {
+         total_size += c->size;
+         c = c->next;
+       }
+    }
+
+  if (clib_bihash_is_initialised_48_8 (&st->v6_session_hash))
+    {
+      clib_bihash_alloc_chunk_48_8_t *c = st->v6_session_hash.chunks;
+      while (c)
+       {
+         total_size += c->size;
+         c = c->next;
+       }
+      c = st->v6_half_open_hash.chunks;
+      while (c)
+       {
+         total_size += c->size;
+         c = c->next;
+       }
+    }
+
+  return total_size;
+}
+
+u8 *
+format_session_table (u8 *s, va_list *args)
+{
+  session_table_t *st = va_arg (*args, session_table_t *);
+
+  if (clib_bihash_is_initialised_16_8 (&st->v4_session_hash))
+    {
+      s = format (s, "%U", format_bihash_16_8, &st->v4_session_hash, 0);
+      s = format (s, "%U", format_bihash_16_8, &st->v4_half_open_hash, 0);
+    }
+
+  if (clib_bihash_is_initialised_48_8 (&st->v6_session_hash))
+    {
+      s = format (s, "%U", format_bihash_48_8, &st->v6_session_hash, 0);
+      s = format (s, "%U", format_bihash_48_8, &st->v6_half_open_hash, 0);
+    }
+
+  return s;
+}
+
 /*
  * fd.io coding-style-patch-verification: ON
  *