vlib: address vlib_error_t scaling issue
[vpp.git] / src / plugins / map / map.c
index a535442..2f036da 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <vnet/fib/fib_table.h>
+#include <vnet/fib/fib_entry_track.h>
 #include <vnet/fib/ip6_fib.h>
 #include <vnet/adj/adj.h>
 #include <vppinfra/crc32.h>
@@ -60,15 +61,14 @@ map_main_t map_main;
 
 
 /*
- * Save usre-assigned MAP domain names ("tags") in a vector of
+ * Save user-assigned MAP domain names ("tags") in a vector of
  * extra domain information.
  */
 static void
-map_save_extras (u32 map_domain_index, char *tag)
+map_save_extras (u32 map_domain_index, u8 * tag)
 {
   map_main_t *mm = &map_main;
   map_domain_extra_t *de;
-  u32 len;
 
   if (map_domain_index == ~0)
     return;
@@ -80,9 +80,7 @@ map_save_extras (u32 map_domain_index, char *tag)
   if (!tag)
     return;
 
-  len = strlen (tag) + 1;
-  de->tag = clib_mem_alloc (len);
-  clib_memcpy (de->tag, tag, len);
+  de->tag = vec_dup (tag);
 }
 
 
@@ -91,7 +89,7 @@ map_free_extras (u32 map_domain_index)
 {
   map_main_t *mm = &map_main;
   map_domain_extra_t *de;
-  char *tag;
+  u8 *tag;
 
   if (map_domain_index == ~0)
     return;
@@ -101,7 +99,7 @@ map_free_extras (u32 map_domain_index)
   if (!tag)
     return;
 
-  clib_mem_free (tag);
+  vec_free (tag);
   de->tag = 0;
 }
 
@@ -116,7 +114,7 @@ map_create_domain (ip4_address_t * ip4_prefix,
                   u8 ea_bits_len,
                   u8 psid_offset,
                   u8 psid_length,
-                  u32 * map_domain_index, u16 mtu, u8 flags, char *tag)
+                  u32 * map_domain_index, u16 mtu, u8 flags, u8 * tag)
 {
   u8 suffix_len, suffix_shift;
   map_main_t *mm = &map_main;
@@ -388,10 +386,8 @@ map_fib_resolve (map_main_pre_resolved_t * pr,
     .fp_addr = *addr,
   };
 
-  pr->fei = fib_table_entry_special_add (0,    // default fib
-                                        &pfx,
-                                        FIB_SOURCE_RR, FIB_ENTRY_FLAG_NONE);
-  pr->sibling = fib_entry_child_add (pr->fei, FIB_NODE_TYPE_MAP_E, proto);
+  pr->fei = fib_entry_track (0,        // default fib
+                            &pfx, FIB_NODE_TYPE_MAP_E, proto, &pr->sibling);
   map_stack (pr);
 }
 
@@ -399,18 +395,10 @@ static void
 map_fib_unresolve (map_main_pre_resolved_t * pr,
                   fib_protocol_t proto, u8 len, const ip46_address_t * addr)
 {
-  fib_prefix_t pfx = {
-    .fp_proto = proto,
-    .fp_len = len,
-    .fp_addr = *addr,
-  };
-
   if (pr->fei != FIB_NODE_INDEX_INVALID)
     {
-      fib_entry_child_remove (pr->fei, pr->sibling);
+      fib_entry_untrack (pr->fei, pr->sibling);
 
-      fib_table_entry_special_remove (0,       // default fib
-                                     &pfx, FIB_SOURCE_RR);
       dpo_reset (&pr->dpo);
 
       pr->fei = FIB_NODE_INDEX_INVALID;
@@ -566,7 +554,7 @@ map_add_domain_command_fn (vlib_main_t * vm,
        num_m_args++;
       else if (unformat (line_input, "mtu %d", &mtu))
        num_m_args++;
-      else if (unformat (line_input, "tag %s", &tag))
+      else if (unformat (line_input, "tag %v", &tag))
        ;
       else
        {
@@ -585,7 +573,7 @@ map_add_domain_command_fn (vlib_main_t * vm,
   map_create_domain (&ip4_prefix, ip4_prefix_len,
                     &ip6_prefix, ip6_prefix_len, &ip6_src, ip6_src_len,
                     ea_bits_len, psid_offset, psid_length, &map_domain_index,
-                    mtu, flags, (char *) tag);
+                    mtu, flags, tag);
 
 done:
   unformat_free (line_input);
@@ -938,7 +926,7 @@ format_map_domain (u8 * s, va_list * args)
   de = vec_elt_at_index (mm->domain_extras, map_domain_index);
 
   s = format (s,
-             "[%d] tag {%s} ip4-pfx %U/%d ip6-pfx %U/%d ip6-src %U/%d "
+             "[%d] tag {%v} ip4-pfx %U/%d ip6-pfx %U/%d ip6-src %U/%d "
              "ea-bits-len %d psid-offset %d psid-len %d mtu %d %s",
              map_domain_index, de->tag,
              format_ip4_address, &d->ip4_prefix, d->ip4_prefix_len,
@@ -1098,7 +1086,7 @@ map_error_counter_get (u32 node_index, map_error_t map_error)
   vlib_node_t *n = vlib_get_node (vm, node_index);
   u32 ci;
 
-  ci = vlib_error_get_code (e);
+  ci = vlib_error_get_code (&vm->node_main, e);
   ASSERT (ci < n->n_errors);
   ci += n->error_heap_index;
 
@@ -2223,7 +2211,7 @@ VLIB_CLI_COMMAND(map_if_command, static) = {
 
 VLIB_PLUGIN_REGISTER() = {
   .version = VPP_BUILD_VER,
-  .description = "Mapping of address and port (MAP)",
+  .description = "Mapping of Address and Port (MAP)",
 };
 
 /* *INDENT-ON* */