session: fix session_table_get_or_alloc
[vpp.git] / src / vnet / session / session_lookup.c
index 9868323..3b33098 100644 (file)
@@ -156,25 +156,28 @@ make_v6_ss_kv_from_tc (session_kv6_t * kv, transport_connection_t * tc)
 }
 
 static session_table_t *
-session_table_get_or_alloc (u8 fib_proto, u8 fib_index)
+session_table_get_or_alloc (u8 fib_proto, u32 fib_index)
 {
   session_table_t *st;
   u32 table_index;
-  if (vec_len (fib_index_to_table_index[fib_proto]) <= fib_index)
+  ASSERT (fib_index != ~0);
+  if (vec_len (fib_index_to_table_index[fib_proto]) > fib_index &&
+      fib_index_to_table_index[fib_proto][fib_index] != ~0)
+    {
+      table_index = fib_index_to_table_index[fib_proto][fib_index];
+      return session_table_get (table_index);
+    }
+  else
     {
       st = session_table_alloc ();
       table_index = session_table_index (st);
-      vec_validate (fib_index_to_table_index[fib_proto], fib_index);
+      vec_validate_init_empty (fib_index_to_table_index[fib_proto], fib_index,
+                              ~0);
       fib_index_to_table_index[fib_proto][fib_index] = table_index;
       st->active_fib_proto = fib_proto;
       session_table_init (st, fib_proto);
       return st;
     }
-  else
-    {
-      table_index = fib_index_to_table_index[fib_proto][fib_index];
-      return session_table_get (table_index);
-    }
 }
 
 static session_table_t *
@@ -1289,6 +1292,19 @@ session_lookup_safe6 (u32 fib_index, ip6_address_t * lcl, ip6_address_t * rmt,
   return 0;
 }
 
+transport_connection_t *
+session_lookup_connection (u32 fib_index, ip46_address_t * lcl,
+                          ip46_address_t * rmt, u16 lcl_port, u16 rmt_port,
+                          u8 proto, u8 is_ip4)
+{
+  if (is_ip4)
+    return session_lookup_connection4 (fib_index, &lcl->ip4, &rmt->ip4,
+                                      lcl_port, rmt_port, proto);
+  else
+    return session_lookup_connection6 (fib_index, &lcl->ip6, &rmt->ip6,
+                                      lcl_port, rmt_port, proto);
+}
+
 int
 vnet_session_rule_add_del (session_rule_add_del_args_t * args)
 {