]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Fix interface based static routes
authorDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 10 May 2016 12:49:28 +0000 (08:49 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 10 May 2016 19:07:04 +0000 (15:07 -0400)
This commit fixes interface based static routes.

static routes are now stored and if an interface
comes up it finds the route and installs it.

Ticket: CM-10869
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Don Slice <dslice@cumulusnetworks.com>
zebra/interface.c
zebra/rib.h
zebra/zebra_rib.c
zebra/zebra_vrf.c
zebra/zebra_vty.c

index 7d3d0851a7e875c6fbe2065b8e1cad3028dea251..2efcbac5711182867005c730cdefae32c9c0a3b1 100644 (file)
@@ -102,6 +102,8 @@ if_zebra_new_hook (struct interface *ifp)
   zebra_if->ipv4_subnets = route_table_init ();
 
   ifp->info = zebra_if;
+
+  zebra_vrf_static_route_interface_fixup (ifp);
   return 0;
 }
 
@@ -816,6 +818,8 @@ if_up (struct interface *ifp)
     zlog_debug ("%u: IF %s up, scheduling RIB processing",
                 ifp->vrf_id, ifp->name);
   rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
+
+  zebra_vrf_static_route_interface_fixup (ifp);
 }
 
 /* Interface goes down.  We have to manage different behavior of based
index d41519042e36aa501039836fa6a813d1d5a1a792..95c6a506c8aba8d02d76f8829457f5c091ab7f30 100644 (file)
@@ -389,7 +389,8 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_
 
 extern int
 static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
-                 u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf);
+                 const char *ifname, u_char flags, u_short tag,
+                u_char distance, struct zebra_vrf *zvrf);
 
 extern int
 static_delete_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
@@ -413,8 +414,8 @@ extern struct route_table *rib_table_ipv6;
 
 extern int
 static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
-                unsigned int ifindex, u_char flags, u_short tag,
-                 u_char distance, struct zebra_vrf *zvrf);
+                unsigned int ifindex, const char *ifname, u_char flags,
+                u_short tag, u_char distance, struct zebra_vrf *zvrf);
 
 extern int
 rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t,
index 312a90bc5ff913519d0fc20d5d554e61396e2c84..f4dbb3877d09589a11fa70244893d90f1a7b1174 100644 (file)
@@ -3020,7 +3020,8 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_
 /* Add static route into static route configuration. */
 int
 static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
-                u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf)
+                const char *ifname, u_char flags, u_short tag,
+                u_char distance, struct zebra_vrf *zvrf)
 {
   u_char type = 0;
   struct route_node *rn;
@@ -3075,7 +3076,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
   si->vrf_id = zvrf->vrf_id;
   si->ifindex = ifindex;
   if (si->ifindex)
-    strcpy(si->ifname, ifindex2ifname_vrf (si->ifindex, si->vrf_id));
+    strcpy(si->ifname, ifname);
 
   if (gate)
     si->addr.ipv4 = *gate;
@@ -3540,8 +3541,8 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
 /* Add static route into static route configuration. */
 int
 static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
-                unsigned int ifindex, u_char flags, u_short tag,
-                 u_char distance, struct zebra_vrf *zvrf)
+                unsigned int ifindex, const char *ifname, u_char flags,
+                u_short tag, u_char distance, struct zebra_vrf *zvrf)
 {
   struct route_node *rn;
   struct static_route *si;
@@ -3594,6 +3595,8 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
   si->tag = tag;
   si->vrf_id = zvrf->vrf_id;
   si->ifindex = ifindex;
+  if (si->ifindex)
+    strcpy (si->ifname, ifname);
 
   switch (type)
     {
index 04aa16f71b8c780f78db81186174667488774852..382d5e4a52ad574d265f000ab00844ce346c211c 100644 (file)
@@ -345,12 +345,14 @@ zebra_vrf_list_lookup_by_name (const char *name)
   struct listnode *node;
   struct zebra_vrf *zvrf;
 
-  if (name)
-    for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf))
-      {
-        if (strcmp(name, zvrf->name) == 0)
-          return zvrf;
-      }
+  if (!name)
+    name = VRF_DEFAULT_NAME;
+
+  for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf))
+    {
+      if (strcmp(name, zvrf->name) == 0)
+        return zvrf;
+    }
   return NULL;
 }
 
index 6da085b28fb66c156af2dff0d44de7d25a030c48..1b5de1dc5d42ad3c51c5b9a641f13ffcb862f701 100644 (file)
 
 extern int allow_delete;
 
-static struct zebra_vrf *
-zebra_vty_vrf_lookup (const char *vrf_id_str)
-{
-  struct vrf *vrf = NULL;
-
-  if (vrf_id_str)
-    {
-      vrf = vrf_list_lookup_by_name (vrf_id_str); //Pending: create VRF if the given vrf doesnt exist?
-    }
-  else
-    {
-      vrf = vrf_list_lookup_by_name (VRF_DEFAULT_NAME);
-    }
-
-  if (vrf)
-    return (struct zebra_vrf *)vrf->info;
-
-  return NULL;
-}
-
 /* General fucntion for static route. */
 static int
 zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
@@ -74,6 +54,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
   u_short tag = 0;
   struct zebra_vrf *zvrf = NULL;
   unsigned int ifindex = 0;
+  const char *ifname = NULL;
 
   ret = str2prefix (dest_str, &p);
   if (ret <= 0)
@@ -108,7 +89,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
     tag = atoi(tag_str);
 
   /* VRF id */
-  zvrf = zebra_vty_vrf_lookup (vrf_id_str);
+  zvrf = zebra_vrf_list_lookup_by_name (vrf_id_str);
 
   if (!zvrf)
     {
@@ -125,7 +106,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
           return CMD_WARNING;
         }
       if (add_cmd)
-        static_add_ipv4 (&p, NULL, ifindex, ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf);
+        static_add_ipv4 (&p, NULL, ifindex, ifname, ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf);
       else
         static_delete_ipv4 (&p, NULL, ifindex, tag, distance, zvrf);
       return CMD_SUCCESS;
@@ -151,7 +132,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
   if (gate_str == NULL)
   {
     if (add_cmd)
-      static_add_ipv4 (&p, NULL, ifindex, flag, tag, distance, zvrf);
+      static_add_ipv4 (&p, NULL, ifindex, ifname, flag, tag, distance, zvrf);
     else
       static_delete_ipv4 (&p, NULL, ifindex, tag, distance, zvrf);
 
@@ -165,15 +146,17 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
     {
       struct interface *ifp = if_lookup_by_name_vrf (gate_str, zvrf->vrf_id);
       if (!ifp)
-       {
+        {
          vty_out (vty, "%% Unknown interface: %s%s", gate_str, VTY_NEWLINE);
-         return CMD_WARNING;
-       }
-      ifindex = ifp->ifindex;
+          ifindex = IFINDEX_DELETED;
+        }
+      else
+        ifindex = ifp->ifindex;
+      ifname = gate_str;
     }
 
   if (add_cmd)
-    static_add_ipv4 (&p, ifindex ? NULL : &gate, ifindex, flag, tag, distance, zvrf);
+    static_add_ipv4 (&p, ifindex ? NULL : &gate, ifindex, ifname, flag, tag, distance, zvrf);
   else
     static_delete_ipv4 (&p, ifindex ? NULL : &gate, ifindex, tag, distance, zvrf);
 
@@ -3435,7 +3418,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
   ret = inet_pton (AF_INET6, gate_str, &gate_addr);
 
   /* VRF id */
-  zvrf = zebra_vty_vrf_lookup (vrf_id_str);
+  zvrf = zebra_vrf_list_lookup_by_name (vrf_id_str);
 
   if (!zvrf)
     {
@@ -3476,14 +3459,16 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
          if (!ifp)
            {
              vty_out (vty, "%% Malformed Interface name %s%s", gate_str, VTY_NEWLINE);
-             return CMD_WARNING;
+              ifindex = IFINDEX_DELETED;
            }
-         ifindex = ifp->ifindex;
+          else
+           ifindex = ifp->ifindex;
+         ifname = gate_str;
        }
     }
 
   if (add_cmd)
-    static_add_ipv6 (&p, type, gate, ifindex, flag, tag, distance, zvrf);
+    static_add_ipv6 (&p, type, gate, ifindex, ifname, flag, tag, distance, zvrf);
   else
     static_delete_ipv6 (&p, type, gate, ifindex, tag, distance, zvrf);