session: cleanup/rename functions
[vpp.git] / src / vnet / session / session_table.c
index cd8502a..3722e0f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  */
 static session_table_t *lookup_tables;
 
+session_table_t *
+_get_session_tables (void)
+{
+  return lookup_tables;
+}
+
 session_table_t *
 session_table_alloc (void)
 {
   session_table_t *slt;
   pool_get_aligned (lookup_tables, slt, CLIB_CACHE_LINE_BYTES);
-  memset (slt, 0, sizeof (*slt));
+  clib_memset (slt, 0, sizeof (*slt));
   return slt;
 }
 
@@ -39,9 +45,9 @@ session_table_index (session_table_t * slt)
 session_table_t *
 session_table_get (u32 table_index)
 {
-  if (vec_len (lookup_tables) <= table_index)
+  if (pool_is_free_index (lookup_tables, table_index))
     return 0;
-  return vec_elt_at_index (lookup_tables, table_index);
+  return pool_elt_at_index (lookup_tables, table_index);
 }
 
 #define foreach_hash_table_parameter            \
@@ -61,34 +67,44 @@ session_table_get (u32 table_index)
  * otherwise it uses defaults above.
  */
 void
-session_table_init (session_table_t * slt)
+session_table_init (session_table_t * slt, u8 fib_proto)
 {
+  u8 all = fib_proto > FIB_PROTOCOL_IP6 ? 1 : 0;
+  int i;
+
 #define _(af,table,parm,value)                                                 \
   u32 configured_##af##_##table##_table_##parm = value;
   foreach_hash_table_parameter;
 #undef _
 
 #define _(af,table,parm,value)                                          \
-  if (session_manager_main.configured_##af##_##table##_table_##parm)    \
+  if (session_main.configured_##af##_##table##_table_##parm)    \
     configured_##af##_##table##_table_##parm =                          \
-      session_manager_main.configured_##af##_##table##_table_##parm;
+      session_main.configured_##af##_##table##_table_##parm;
   foreach_hash_table_parameter;
 #undef _
 
-  clib_bihash_init_16_8 (&slt->v4_session_hash, "v4 session table",
-                        configured_v4_session_table_buckets,
-                        configured_v4_session_table_memory);
-  clib_bihash_init_48_8 (&slt->v6_session_hash, "v6 session table",
-                        configured_v6_session_table_buckets,
-                        configured_v6_session_table_memory);
-  clib_bihash_init_16_8 (&slt->v4_half_open_hash, "v4 half-open table",
-                        configured_v4_halfopen_table_buckets,
-                        configured_v4_halfopen_table_memory);
-  clib_bihash_init_48_8 (&slt->v6_half_open_hash, "v6 half-open table",
-                        configured_v6_halfopen_table_buckets,
-                        configured_v6_halfopen_table_memory);
-
-  session_rules_table_init (&slt->session_rules);
+  if (fib_proto == FIB_PROTOCOL_IP4 || all)
+    {
+      clib_bihash_init_16_8 (&slt->v4_session_hash, "v4 session table",
+                            configured_v4_session_table_buckets,
+                            configured_v4_session_table_memory);
+      clib_bihash_init_16_8 (&slt->v4_half_open_hash, "v4 half-open table",
+                            configured_v4_halfopen_table_buckets,
+                            configured_v4_halfopen_table_memory);
+    }
+  if (fib_proto == FIB_PROTOCOL_IP6 || all)
+    {
+      clib_bihash_init_48_8 (&slt->v6_session_hash, "v6 session table",
+                            configured_v6_session_table_buckets,
+                            configured_v6_session_table_memory);
+      clib_bihash_init_48_8 (&slt->v6_half_open_hash, "v6 half-open table",
+                            configured_v6_halfopen_table_buckets,
+                            configured_v6_halfopen_table_memory);
+    }
+
+  for (i = 0; i < TRANSPORT_N_PROTO; i++)
+    session_rules_table_init (&slt->session_rules[i]);
 }
 
 typedef struct _ip4_session_table_walk_ctx_t