]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/if_rmap.c
mpls: add support for LDP LSPs
[mirror_frr.git] / lib / if_rmap.c
index 6730e94cb8fc7c580fd70e63a368c9609cd040f1..736f2e237d4803b6f3cea7bff35aad4705099229 100644 (file)
 #include "if.h"
 #include "if_rmap.h"
 
+DEFINE_MTYPE_STATIC(LIB, IF_RMAP,      "Interface route map")
+DEFINE_MTYPE_STATIC(LIB, IF_RMAP_NAME, "I.f. route map name")
+
 struct hash *ifrmaphash;
 
 /* Hook functions. */
 static void (*if_rmap_add_hook) (struct if_rmap *) = NULL;
 static void (*if_rmap_delete_hook) (struct if_rmap *) = NULL;
-\f
+
 static struct if_rmap *
 if_rmap_new (void)
 {
@@ -47,12 +50,12 @@ static void
 if_rmap_free (struct if_rmap *if_rmap)
 {
   if (if_rmap->ifname)
-    free (if_rmap->ifname);
+    XFREE (MTYPE_IF_RMAP_NAME, if_rmap->ifname);
 
   if (if_rmap->routemap[IF_RMAP_IN])
-    free (if_rmap->routemap[IF_RMAP_IN]);
+    XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]);
   if (if_rmap->routemap[IF_RMAP_OUT])
-    free (if_rmap->routemap[IF_RMAP_OUT]);
+    XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]);
 
   XFREE (MTYPE_IF_RMAP, if_rmap);
 }
@@ -64,10 +67,13 @@ if_rmap_lookup (const char *ifname)
   struct if_rmap *if_rmap;
 
   /* temporary copy */
-  key.ifname = (char *)ifname;
+  key.ifname = (ifname) ? XSTRDUP (MTYPE_IF_RMAP_NAME, ifname) : NULL;
 
   if_rmap = hash_lookup (ifrmaphash, &key);
   
+  if (key.ifname)
+    XFREE(MTYPE_IF_RMAP_NAME, key.ifname);
+
   return if_rmap;
 }
 
@@ -86,11 +92,11 @@ if_rmap_hook_delete (void (*func) (struct if_rmap *))
 static void *
 if_rmap_hash_alloc (void *arg)
 {
-  struct if_rmap *ifarg = arg;
+  struct if_rmap *ifarg = (struct if_rmap *)arg;
   struct if_rmap *if_rmap;
 
   if_rmap = if_rmap_new ();
-  if_rmap->ifname = strdup (ifarg->ifname);
+  if_rmap->ifname = XSTRDUP (MTYPE_IF_RMAP_NAME, ifarg->ifname);
 
   return if_rmap;
 }
@@ -99,36 +105,36 @@ static struct if_rmap *
 if_rmap_get (const char *ifname)
 {
   struct if_rmap key;
+  struct if_rmap *ret;
 
   /* temporary copy */
-  key.ifname = (char *)ifname;
+  key.ifname = (ifname) ? XSTRDUP (MTYPE_IF_RMAP_NAME, ifname) : NULL;
+
+  ret = hash_get (ifrmaphash, &key, if_rmap_hash_alloc);
+
+  if (key.ifname)
+    XFREE(MTYPE_IF_RMAP_NAME, key.ifname);
 
-  return (struct if_rmap *) hash_get (ifrmaphash, &key, if_rmap_hash_alloc);
+  return ret;
 }
 
 static unsigned int
 if_rmap_hash_make (void *data)
 {
-  struct if_rmap *if_rmap = data;
-  unsigned int i, key;
+  const struct if_rmap *if_rmap = data;
 
-  key = 0;
-  for (i = 0; i < strlen (if_rmap->ifname); i++)
-    key += if_rmap->ifname[i];
-
-  return key;
+  return string_hash_make (if_rmap->ifname);
 }
 
 static int
-if_rmap_hash_cmp (void *arg1, void* arg2)
+if_rmap_hash_cmp (const void *arg1, const void* arg2)
 {
-  struct if_rmap *if_rmap1 = arg1;
-  struct if_rmap *if_rmap2 = arg2;
-  if (strcmp (if_rmap1->ifname, if_rmap2->ifname) == 0)
-    return 1;
-  return 0;
+  const struct if_rmap *if_rmap1 = arg1;
+  const struct if_rmap *if_rmap2 = arg2;
+
+  return strcmp (if_rmap1->ifname, if_rmap2->ifname) == 0;
 }
-\f
+
 static struct if_rmap *
 if_rmap_set (const char *ifname, enum if_rmap_type type, 
              const char *routemap_name)
@@ -140,14 +146,16 @@ if_rmap_set (const char *ifname, enum if_rmap_type type,
   if (type == IF_RMAP_IN)
     {
       if (if_rmap->routemap[IF_RMAP_IN])
-       free (if_rmap->routemap[IF_RMAP_IN]);
-      if_rmap->routemap[IF_RMAP_IN] = strdup (routemap_name);
+       XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]);
+      if_rmap->routemap[IF_RMAP_IN] 
+        = XSTRDUP (MTYPE_IF_RMAP_NAME, routemap_name);
     }
   if (type == IF_RMAP_OUT)
     {
       if (if_rmap->routemap[IF_RMAP_OUT])
-       free (if_rmap->routemap[IF_RMAP_OUT]);
-      if_rmap->routemap[IF_RMAP_OUT] = strdup (routemap_name);
+       XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]);
+      if_rmap->routemap[IF_RMAP_OUT] 
+        = XSTRDUP (MTYPE_IF_RMAP_NAME, routemap_name);
     }
 
   if (if_rmap_add_hook)
@@ -173,7 +181,7 @@ if_rmap_unset (const char *ifname, enum if_rmap_type type,
       if (strcmp (if_rmap->routemap[IF_RMAP_IN], routemap_name) != 0)
        return 0;
 
-      free (if_rmap->routemap[IF_RMAP_IN]);
+      XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]);
       if_rmap->routemap[IF_RMAP_IN] = NULL;      
     }
 
@@ -184,7 +192,7 @@ if_rmap_unset (const char *ifname, enum if_rmap_type type,
       if (strcmp (if_rmap->routemap[IF_RMAP_OUT], routemap_name) != 0)
        return 0;
 
-      free (if_rmap->routemap[IF_RMAP_OUT]);
+      XFREE (MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]);
       if_rmap->routemap[IF_RMAP_OUT] = NULL;      
     }
 
@@ -211,7 +219,6 @@ DEFUN (if_rmap,
        "Route map interface name\n")
 {
   enum if_rmap_type type;
-  struct if_rmap *if_rmap;
 
   if (strncmp (argv[1], "i", 1) == 0)
     type = IF_RMAP_IN;
@@ -223,7 +230,7 @@ DEFUN (if_rmap,
       return CMD_WARNING;
     }
 
-  if_rmap = if_rmap_set (argv[2], type, argv[0]);
+  if_rmap_set (argv[2], type, argv[0]);
 
   return CMD_SUCCESS;
 }      
@@ -278,7 +285,7 @@ ALIAS (no_if_rmap,
        "Route map for input filtering\n"
        "Route map for output filtering\n"
        "Route map interface name\n")
-\f
+
 /* Configuration write function. */
 int
 config_write_if_rmap (struct vty *vty)