Combine the static_install_ipv[4|6] function calls into
static_install_route.

Signed-off-by: Donald Sharp <[email protected]>
---
 zebra/zebra_rib.c |  141 ++++++++++++++++-------------------------------------
 1 file changed, 41 insertions(+), 100 deletions(-)

diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index be4ac5b..de71c9c 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -1615,7 +1615,7 @@ rib_queue_init (struct zebra_t *zebra)
  * as a route_node will not be requeued, if already queued.
  *
  * RIBs are submitted via rib_addnode or rib_delnode which set minimal
- * state, or static_install_ipv{4,6} (when an existing RIB is updated)
+ * state, or static_install_route (when an existing RIB is updated)
  * and then submit route_node to queue for best-path selection later.
  * Order of add/delete state changes are preserved for any given RIB.
  *
@@ -2225,14 +2225,14 @@ rib_delete_ipv4 (int type, int flags, struct 
prefix_ipv4 *p,
 
 /* Install static route into rib. */
 static void
-static_install_ipv4 (safi_t safi, struct prefix *p, struct static_route *si)
+static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct 
static_route *si)
 {
   struct rib *rib;
   struct route_node *rn;
   struct route_table *table;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP, safi, si->vrf_id);
+  table = zebra_vrf_table (afi, safi, si->vrf_id);
   if (! table)
     return;
 
@@ -2254,15 +2254,24 @@ static_install_ipv4 (safi_t safi, struct prefix *p, 
struct static_route *si)
       route_unlock_node (rn);
       switch (si->type)
         {
-          case STATIC_IPV4_GATEWAY:
-            nexthop_ipv4_add (rib, &si->addr.ipv4, NULL);
-            break;
-          case STATIC_IPV4_IFNAME:
-            nexthop_ifname_add (rib, si->ifname);
-            break;
-          case STATIC_IPV4_BLACKHOLE:
-            nexthop_blackhole_add (rib);
-            break;
+       case STATIC_IPV4_GATEWAY:
+         nexthop_ipv4_add (rib, &si->addr.ipv4, NULL);
+         break;
+       case STATIC_IPV4_IFNAME:
+         nexthop_ifname_add (rib, si->ifname);
+         break;
+       case STATIC_IPV4_BLACKHOLE:
+         nexthop_blackhole_add (rib);
+         break;
+       case STATIC_IPV6_GATEWAY:
+         nexthop_ipv6_add (rib, &si->addr.ipv6);
+         break;
+       case STATIC_IPV6_IFNAME:
+         nexthop_ifname_add (rib, si->ifname);
+         break;
+       case STATIC_IPV6_GATEWAY_IFNAME:
+         nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname);
+         break;
         }
       rib_queue_add (&zebrad, rn);
     }
@@ -2280,15 +2289,24 @@ static_install_ipv4 (safi_t safi, struct prefix *p, 
struct static_route *si)
 
       switch (si->type)
         {
-          case STATIC_IPV4_GATEWAY:
-            nexthop_ipv4_add (rib, &si->addr.ipv4, NULL);
-            break;
-          case STATIC_IPV4_IFNAME:
-            nexthop_ifname_add (rib, si->ifname);
-            break;
-          case STATIC_IPV4_BLACKHOLE:
-            nexthop_blackhole_add (rib);
-            break;
+       case STATIC_IPV4_GATEWAY:
+         nexthop_ipv4_add (rib, &si->addr.ipv4, NULL);
+         break;
+       case STATIC_IPV4_IFNAME:
+         nexthop_ifname_add (rib, si->ifname);
+         break;
+       case STATIC_IPV4_BLACKHOLE:
+         nexthop_blackhole_add (rib);
+         break;
+       case STATIC_IPV6_GATEWAY:
+         nexthop_ipv6_add (rib, &si->addr.ipv6);
+         break;
+       case STATIC_IPV6_IFNAME:
+         nexthop_ifname_add (rib, si->ifname);
+         break;
+       case STATIC_IPV6_GATEWAY_IFNAME:
+         nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname);
+         break;
         }
 
       /* Save the flags of this static routes (reject, blackhole) */
@@ -2467,7 +2485,7 @@ static_add_ipv4_safi (safi_t safi, struct prefix *p, 
struct in_addr *gate,
   si->next = cp;
 
   /* Install into rib. */
-  static_install_ipv4 (safi, p, si);
+  static_install_route (AFI_IP, safi, p, si);
 
   return 1;
 }
@@ -2770,83 +2788,6 @@ rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 
*p,
   return 0;
 }
 
-/* Install static route into rib. */
-static void
-static_install_ipv6 (struct prefix *p, struct static_route *si)
-{
-  struct rib *rib;
-  struct route_table *table;
-  struct route_node *rn;
-
-  /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, si->vrf_id);
-  if (! table)
-    return;
-
-  /* Lookup existing route */
-  rn = route_node_get (table, p);
-  RNODE_FOREACH_RIB (rn, rib)
-    {
-      if (CHECK_FLAG(rib->status, RIB_ENTRY_REMOVED))
-        continue;
-
-      if (rib->type == ZEBRA_ROUTE_STATIC && rib->distance == si->distance)
-        break;
-    }
-
-  if (rib)
-    {
-      /* Same distance static route is there.  Update it with new
-         nexthop. */
-      route_unlock_node (rn);
-
-      switch (si->type)
-       {
-       case STATIC_IPV6_GATEWAY:
-         nexthop_ipv6_add (rib, &si->addr.ipv6);
-         break;
-       case STATIC_IPV6_IFNAME:
-         nexthop_ifname_add (rib, si->ifname);
-         break;
-       case STATIC_IPV6_GATEWAY_IFNAME:
-         nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname);
-         break;
-       }
-      rib_queue_add (&zebrad, rn);
-    }
-  else
-    {
-      /* This is new static route. */
-      rib = XCALLOC (MTYPE_RIB, sizeof (struct rib));
-      
-      rib->type = ZEBRA_ROUTE_STATIC;
-      rib->distance = si->distance;
-      rib->metric = 0;
-      rib->vrf_id = si->vrf_id;
-      rib->table = zebrad.rtm_table_default;
-      rib->nexthop_num = 0;
-
-      switch (si->type)
-       {
-       case STATIC_IPV6_GATEWAY:
-         nexthop_ipv6_add (rib, &si->addr.ipv6);
-         break;
-       case STATIC_IPV6_IFNAME:
-         nexthop_ifname_add (rib, si->ifname);
-         break;
-       case STATIC_IPV6_GATEWAY_IFNAME:
-         nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname);
-         break;
-       }
-
-      /* Save the flags of this static routes (reject, blackhole) */
-      rib->flags = si->flags;
-
-      /* Link this rib to the tree. */
-      rib_addnode (rn, rib);
-    }
-}
-
 static int
 static_ipv6_nexthop_same (struct nexthop *nexthop, struct static_route *si)
 {
@@ -3011,7 +2952,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct 
in6_addr *gate,
   si->next = cp;
 
   /* Install into rib. */
-  static_install_ipv6 (p, si);
+  static_install_route (AFI_IP6, SAFI_UNICAST, p, si);
 
   return 1;
 }
-- 
1.7.10.4


_______________________________________________
Quagga-dev mailing list
[email protected]
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to