]> git.puffer.fish Git - mirror/frr.git/commitdiff
Zebra: Eliminate unnecessary del-add upon static route addition
authorvivek <vivek@cumulusnetworks.com>
Tue, 8 Dec 2015 23:04:48 +0000 (15:04 -0800)
committervivek <vivek@cumulusnetworks.com>
Tue, 8 Dec 2015 23:04:48 +0000 (15:04 -0800)
When static routes are added, they get processed and potentially installed
in the RIB once. Subsequently, NHT is invoked and ends up scheduling the
route for processing again because this is the first time the nexthop is
resolved for NHT. This used to result in a del-add earlier (as noted in
the defect), but is a replace now. This change eliminates the unnecessary
replace by ensuring NHT is invoked first if the static route has a nexthop
that will be tracked by NHT.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Dinesh Dutt <ddutt@cumulusnetworks.com>
Ticket: CM-4573
Reviewed By: CCR-3903
Testing Done: Manual and bgpsmoke

Note: Updates/improves static route NHT patch(es).

zebra/zebra_rib.c

index 25166dea211cc90ab4551ece591a8081f905f851..87425cb4b93943dabbe5e8f70cf6d518cadc58a6 100644 (file)
@@ -1914,7 +1914,7 @@ rib_queue_init (struct zebra_t *zebra)
  
 /* Add RIB to head of the route node. */
 static void
-rib_link (struct route_node *rn, struct rib *rib)
+rib_link (struct route_node *rn, struct rib *rib, int process)
 {
   struct rib *head;
   rib_dest_t *dest;
@@ -1949,7 +1949,10 @@ rib_link (struct route_node *rn, struct rib *rib)
 
   /* Further processing only if entry is in main table */
   if ((rib->table == RT_TABLE_MAIN) || (rib->table == zebrad.rtm_table_default))
-    rib_queue_add (&zebrad, rn);
+    {
+      if (process)
+        rib_queue_add (&zebrad, rn);
+    }
   else
     {
       afi = (rn->p.family == AF_INET) ? AFI_IP :
@@ -1960,7 +1963,7 @@ rib_link (struct route_node *rn, struct rib *rib)
 }
 
 static void
-rib_addnode (struct route_node *rn, struct rib *rib)
+rib_addnode (struct route_node *rn, struct rib *rib, int process)
 {
   /* RIB node has been un-removed before route-node is processed. 
    * route_node must hence already be on the queue for processing.. 
@@ -1970,7 +1973,7 @@ rib_addnode (struct route_node *rn, struct rib *rib)
       UNSET_FLAG (rib->status, RIB_ENTRY_REMOVED);
       return;
     }
-  rib_link (rn, rib);
+  rib_link (rn, rib, process);
 }
 
 /*
@@ -2153,7 +2156,7 @@ rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
       if (IS_ZEBRA_DEBUG_RIB_DETAILED)
         rib_dump ((struct prefix *)p, rib);
     }
-  rib_addnode (rn, rib);
+  rib_addnode (rn, rib, 1);
   
   /* Free implicit route.*/
   if (same)
@@ -2396,7 +2399,7 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi)
       if (IS_ZEBRA_DEBUG_RIB_DETAILED)
         rib_dump ((struct prefix *)p, rib);
     }
-  rib_addnode (rn, rib);
+  rib_addnode (rn, rib, 1);
   ret = 1;
 
   /* Free implicit route.*/
@@ -2630,7 +2633,12 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
                           si->vrf_id, buf, p->prefixlen, rn, rib, rib->type);
             }
         }
-      rib_queue_add (&zebrad, rn);
+      /* Schedule route for processing or invoke NHT, as appropriate. */
+      if (si->type == STATIC_IPV4_GATEWAY ||
+          si->type == STATIC_IPV6_GATEWAY)
+        zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, RNH_NEXTHOP_TYPE, &nh_p);
+      else
+        rib_queue_add (&zebrad, rn);
     }
   else
     {
@@ -2679,7 +2687,6 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
       /* Save the flags of this static routes (reject, blackhole) */
       rib->flags = si->flags;
 
-      /* Link this rib to the tree. */
       if (IS_ZEBRA_DEBUG_RIB)
         {
           char buf[INET6_ADDRSTRLEN];
@@ -2690,7 +2697,17 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
                           si->vrf_id, buf, p->prefixlen, rn, rib, rib->type);
             }
         }
-      rib_addnode (rn, rib);
+      /* Link this rib to the tree. Schedule for processing or invoke NHT,
+       * as appropriate.
+       */
+      if (si->type == STATIC_IPV4_GATEWAY ||
+          si->type == STATIC_IPV6_GATEWAY)
+        {
+          rib_addnode (rn, rib, 0);
+          zebra_evaluate_rnh(si->vrf_id, nh_p.family, 1, RNH_NEXTHOP_TYPE, &nh_p);
+        }
+      else
+        rib_addnode (rn, rib, 1);
     }
 }
 
@@ -3095,7 +3112,7 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
       if (IS_ZEBRA_DEBUG_RIB_DETAILED)
         rib_dump ((struct prefix *)p, rib);
     }
-  rib_addnode (rn, rib);
+  rib_addnode (rn, rib, 1);
 
   /* Free implicit route.*/
   if (same)
@@ -3216,7 +3233,7 @@ rib_add_ipv6_multipath (struct prefix *p, struct rib *rib, safi_t safi,
       if (IS_ZEBRA_DEBUG_RIB_DETAILED)
         rib_dump ((struct prefix *)p, rib);
     }
-  rib_addnode (rn, rib);
+  rib_addnode (rn, rib, 1);
   ret = 1;
 
   /* Free implicit route.*/