session: api to add new transport types
[vpp.git] / src / vnet / session / mma_template.c
index 81333a7..ae730e5 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:
@@ -53,15 +53,15 @@ RTT (mma_rule) * RT (mma_rules_table_rule_alloc) (RTT (mma_rules_table) * srt)
 {
   RTT (mma_rule) * rule;
   pool_get (srt->rules, rule);
-  memset (rule, 0, sizeof (*rule));
+  clib_memset (rule, 0, sizeof (*rule));
   return rule;
 }
 
 RTT (mma_rule) *
 RT (mma_rule_free) (RTT (mma_rules_table) * srt, RTT (mma_rule) * rule)
 {
+  clib_memset (rule, 0xfa, sizeof (*rule));
   pool_put (srt->rules, rule);
-  memset (rule, 0xfa, sizeof (*rule));
   return rule;
 }
 
@@ -94,16 +94,16 @@ RT (mma_rules_table_lookup) (RTT (mma_rules_table) * srt,
   u32 rv;
   int i;
 
-  ASSERT (rule_index != SESSION_RULES_TABLE_INVALID_INDEX);
+  ASSERT (rule_index != MMA_TABLE_INVALID_INDEX);
   rp = RT (mma_rules_table_get_rule) (srt, rule_index);
   ASSERT (rp);
 
   if (!RT (rule_is_match_for_key) (key, rp))
-    return ~0;
+    return MMA_TABLE_INVALID_INDEX;
   for (i = 0; i < vec_len (rp->next_indices); i++)
     {
       rv = RT (mma_rules_table_lookup) (srt, key, rp->next_indices[i]);
-      if (rv != ~0)
+      if (rv != MMA_TABLE_INVALID_INDEX)
        return (rv);
     }
   return (rp->action_index);
@@ -118,16 +118,16 @@ RT (mma_rules_table_lookup_rule) (RTT (mma_rules_table) * srt,
   u32 rv;
   int i;
 
-  ASSERT (rule_index != SESSION_RULES_TABLE_INVALID_INDEX);
+  ASSERT (rule_index != MMA_TABLE_INVALID_INDEX);
   rp = RT (mma_rules_table_get_rule) (srt, rule_index);
   ASSERT (rp);
 
   if (!RT (rule_is_match_for_key) (key, rp))
-    return ~0;
+    return MMA_TABLE_INVALID_INDEX;
   for (i = 0; i < vec_len (rp->next_indices); i++)
     {
       rv = RT (mma_rules_table_lookup_rule) (srt, key, rp->next_indices[i]);
-      if (rv != ~0)
+      if (rv != MMA_TABLE_INVALID_INDEX)
        return (rv);
     }
   return rule_index;
@@ -214,13 +214,17 @@ RT (mma_rules_table_del_rule) (RTT (mma_rules_table) * srt,
   u32 rv;
   int i;
 
-  ASSERT (rule_index != SESSION_RULES_TABLE_INVALID_INDEX);
+  ASSERT (rule_index != MMA_TABLE_INVALID_INDEX);
   rp = RT (mma_rules_table_get_rule) (srt, rule_index);
 
   if (!RT (rule_is_match_for_key) (&rule->match, rp))
-    return ~0;
+    return MMA_TABLE_INVALID_INDEX;
   if (RT (rule_is_exact_match) (rule, rp))
-    return 1;
+    {
+      if (rule_index == srt->root_index)
+       rp->action_index = MMA_TABLE_INVALID_INDEX;
+      return 1;
+    }
   for (i = 0; i < vec_len (rp->next_indices); i++)
     {
       rv = RT (mma_rules_table_del_rule) (srt, rule, rp->next_indices[i]);
@@ -234,7 +238,7 @@ RT (mma_rules_table_del_rule) (RTT (mma_rules_table) * srt,
          if (i != 0)
            {
              vec_add2 (next_indices, new_elts, i);
-             clib_memcpy (new_elts, rp->next_indices, i * sizeof (u32));
+             clib_memcpy_fast (new_elts, rp->next_indices, i * sizeof (u32));
            }
          if (vec_len (child->next_indices))
            vec_append (next_indices, child->next_indices);
@@ -242,8 +246,8 @@ RT (mma_rules_table_del_rule) (RTT (mma_rules_table) * srt,
          if (left_to_add)
            {
              vec_add2 (next_indices, new_elts, left_to_add);
-             clib_memcpy (new_elts, &rp->next_indices[i + 1],
-                          left_to_add * sizeof (u32));
+             clib_memcpy_fast (new_elts, &rp->next_indices[i + 1],
+                               left_to_add * sizeof (u32));
            }
          RT (mma_rule_free) (srt, child);
          vec_free (rp->next_indices);
@@ -253,7 +257,7 @@ RT (mma_rules_table_del_rule) (RTT (mma_rules_table) * srt,
       else if (rv == 0)
        return rv;
     }
-  return ~0;
+  return MMA_TABLE_INVALID_INDEX;
 }
 
 /*