From 2bf26d4184cd6b6fdea42629725cd2005f8bef47 Mon Sep 17 00:00:00 2001 From: vivek Date: Tue, 8 Dec 2015 15:04:48 -0800 Subject: [PATCH] Zebra: Eliminate unnecessary del-add upon static route addition 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 Reviewed-by: Donald Sharp Reviewed-by: Dinesh Dutt Ticket: CM-4573 Reviewed By: CCR-3903 Testing Done: Manual and bgpsmoke Note: Updates/improves static route NHT patch(es). --- zebra/zebra_rib.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 25166dea21..87425cb4b9 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -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.*/ -- 2.39.5