]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Refactor v4 and v6 static_delete
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 24 Aug 2016 04:07:49 +0000 (00:07 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 1 Sep 2016 11:20:18 +0000 (07:20 -0400)
Refactor v4 and v6 static delete into 1 function.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
zebra/zebra_static.c
zebra/zebra_static.h
zebra/zebra_vty.c

index 9d16f12679a3d16753b1ffc36ea06047f8a8b0cd..74a37c45c16c9d765fcf9b3c30f663bb85d507b2 100644 (file)
@@ -355,7 +355,8 @@ static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t
 
   /* Distance or tag changed. */
   if (update)
-    static_delete_ipv4 (safi, p, gate, ifindex, update->tag, update->distance, zvrf);
+    static_delete_route (AFI_IP, safi, type, p, (union g_addr *)gate,
+                        ifindex, update->tag, update->distance, zvrf);
 
   /* Make new static route structure. */
   si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route));
@@ -406,16 +407,16 @@ static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t
 }
 
 int
-static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex,
-                   u_short tag, u_char distance, struct zebra_vrf *zvrf)
+static_delete_route (afi_t afi, safi_t safi, u_char type, struct prefix *p,
+                    union g_addr *gate, ifindex_t ifindex,
+                    u_short tag, u_char distance, struct zebra_vrf *zvrf)
 {
-  u_char type = 0;
   struct route_node *rn;
   struct static_route *si;
   struct route_table *stable;
 
   /* Lookup table.  */
-  stable = zebra_vrf_static_table (AFI_IP, safi, zvrf);
+  stable = zebra_vrf_static_table (afi, safi, zvrf);
   if (! stable)
     return -1;
 
@@ -424,18 +425,12 @@ static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex
   if (! rn)
     return 0;
 
-  /* Make flags. */
-  if (gate)
-    type = STATIC_IPV4_GATEWAY;
-  else if (ifindex)
-    type = STATIC_IFINDEX;
-  else
-    type = STATIC_IPV4_BLACKHOLE;
-
   /* Find same static route is the tree */
   for (si = rn->info; si; si = si->next)
     if (type == si->type
-       && (! gate || IPV4_ADDR_SAME (gate, &si->addr.ipv4))
+       && (! gate || (
+                      (afi == AFI_IP && IPV4_ADDR_SAME (gate, &si->addr.ipv4)) ||
+                      (afi == AFI_IP6 && IPV6_ADDR_SAME (gate, &si->addr.ipv6))))
        && (! ifindex || ifindex == si->ifindex)
        && (! tag || (tag == si->tag)))
       break;
@@ -513,7 +508,9 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
 
   /* Distance or tag changed. */
   if (update)
-    static_delete_ipv6 (p, type, gate, ifindex, update->tag, update->distance, zvrf);
+    static_delete_route (AFI_IP6, SAFI_UNICAST, type, p,
+                        (union g_addr *)gate, ifindex,
+                        update->tag, update->distance, zvrf);
 
   /* Make new static route structure. */
   si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route));
@@ -562,56 +559,3 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
 
   return 1;
 }
-
-/* Delete static route from static route configuration. */
-int
-static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
-                   ifindex_t ifindex, u_short tag, u_char distance,
-                    struct zebra_vrf *zvrf)
-{
-  struct route_node *rn;
-  struct static_route *si;
-  struct route_table *stable;
-
-  /* Lookup table.  */
-  stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, zvrf);
-  if (! stable)
-    return -1;
-
-  /* Lookup static route prefix. */
-  rn = route_node_lookup (stable, p);
-  if (! rn)
-    return 0;
-
-  /* Find same static route is the tree */
-  for (si = rn->info; si; si = si->next)
-    if (distance == si->distance
-       && type == si->type
-       && (! gate || IPV6_ADDR_SAME (gate, &si->addr.ipv6))
-       && (! ifindex || ifindex == si->ifindex)
-       && (! tag || (tag == si->tag)))
-      break;
-
-  /* Can't find static route. */
-  if (! si)
-    {
-      route_unlock_node (rn);
-      return 0;
-    }
-
-  /* Install into rib. */
-  static_uninstall_route (AFI_IP6, SAFI_UNICAST, p, si);
-
-  /* Unlink static route from linked list. */
-  if (si->prev)
-    si->prev->next = si->next;
-  else
-    rn->info = si->next;
-  if (si->next)
-    si->next->prev = si->prev;
-
-  /* Free static route configuration. */
-  XFREE (MTYPE_STATIC_ROUTE, si);
-
-  return 1;
-}
index a3096725f74205aa81145845e899d0c6be95b199..b2f5ea0bb1eb0393beb37f00752b4359925b4b06 100644 (file)
@@ -79,17 +79,14 @@ static_add_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t
                 u_char distance, struct zebra_vrf *zvrf);
 
 extern int
-static_delete_ipv4 (safi_t safi, struct prefix *p, struct in_addr *gate, ifindex_t ifindex,
-                   u_short tag, u_char distance, struct zebra_vrf *zvrf);
+static_delete_route (afi_t, safi_t safi, u_char type, struct prefix *p,
+                    union g_addr *gate, ifindex_t ifindex,
+                    u_short tag, u_char distance,
+                    struct zebra_vrf *zvrf);
 
 extern int
 static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
                 ifindex_t ifindex, const char *ifname, u_char flags,
                 u_short tag, u_char distance, struct zebra_vrf *zvrf);
 
-extern int
-static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
-                   ifindex_t ifindex, u_short tag, u_char distance,
-                    struct zebra_vrf *zvrf);
-
 #endif
index 716e74c0b066fff6cfc51ba753955345de264871..f8774f00265ed2deb80707b3e129d4dfe401ce06 100644 (file)
@@ -66,6 +66,7 @@ zebra_static_ipv4 (struct vty *vty, safi_t safi, int add_cmd,
   struct zebra_vrf *zvrf = NULL;
   unsigned int ifindex = 0;
   const char *ifname = NULL;
+  u_char type = STATIC_IPV4_BLACKHOLE;
 
   ret = str2prefix (dest_str, &p);
   if (ret <= 0)
@@ -119,7 +120,7 @@ zebra_static_ipv4 (struct vty *vty, safi_t safi, int add_cmd,
       if (add_cmd)
         static_add_ipv4 (safi, &p, NULL, ifindex, ifname, ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf);
       else
-        static_delete_ipv4 (safi, &p, NULL, ifindex, tag, distance, zvrf);
+        static_delete_route (AFI_IP, safi, type, &p, NULL, ifindex, tag, distance, zvrf);
       return CMD_SUCCESS;
     }
 
@@ -142,10 +143,11 @@ zebra_static_ipv4 (struct vty *vty, safi_t safi, int add_cmd,
 
   if (gate_str == NULL)
   {
+    type = STATIC_IFINDEX;
     if (add_cmd)
       static_add_ipv4 (safi, &p, NULL, ifindex, ifname, flag, tag, distance, zvrf);
     else
-      static_delete_ipv4 (safi, &p, NULL, ifindex, tag, distance, zvrf);
+      static_delete_route (AFI_IP, safi, type, &p, NULL, ifindex, tag, distance, zvrf);
 
     return CMD_SUCCESS;
   }
@@ -164,12 +166,15 @@ zebra_static_ipv4 (struct vty *vty, safi_t safi, int add_cmd,
       else
         ifindex = ifp->ifindex;
       ifname = gate_str;
+      type = STATIC_IFINDEX;
     }
+  else
+    type = STATIC_IPV4_GATEWAY;
 
   if (add_cmd)
     static_add_ipv4 (safi, &p, ifindex ? NULL : &gate, ifindex, ifname, flag, tag, distance, zvrf);
   else
-    static_delete_ipv4 (safi, &p, ifindex ? NULL : &gate, ifindex, tag, distance, zvrf);
+    static_delete_route (AFI_IP, safi, type, &p, ifindex ? NULL : (union g_addr *)&gate, ifindex, tag, distance, zvrf);
 
   return CMD_SUCCESS;
 }
@@ -3735,7 +3740,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
   if (add_cmd)
     static_add_ipv6 (&p, type, gate, ifindex, ifname, flag, tag, distance, zvrf);
   else
-    static_delete_ipv6 (&p, type, gate, ifindex, tag, distance, zvrf);
+    static_delete_route (AFI_IP6, SAFI_UNICAST, type, &p, (union g_addr *)gate, ifindex, tag, distance, zvrf);
 
   return CMD_SUCCESS;
 }