From c9abf5584a4691818b4c76e59d569e67fb34314e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 11 Sep 2017 11:12:03 -0400 Subject: [PATCH 1/3] zebra: Small performance improvement for garbage collection There is no need to retrieve the zvrf *unless* we are doing debugs. So move the retrieval under the debug statement. Signed-off-by: Donald Sharp --- zebra/zebra_rib.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index c4c80b156b..9dc0630c8c 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1118,7 +1118,6 @@ static int rib_can_delete_dest(rib_dest_t *dest) int rib_gc_dest(struct route_node *rn) { rib_dest_t *dest; - struct zebra_vrf *zvrf; dest = rib_dest_from_rnode(rn); if (!dest) @@ -1127,9 +1126,12 @@ int rib_gc_dest(struct route_node *rn) if (!rib_can_delete_dest(dest)) return 0; - zvrf = rib_dest_vrf(dest); - if (IS_ZEBRA_DEBUG_RIB) + if (IS_ZEBRA_DEBUG_RIB) { + struct zebra_vrf *zvrf; + + zvrf = rib_dest_vrf(dest); rnode_debug(rn, zvrf_id(zvrf), "removing dest from table"); + } dest->rnode = NULL; XFREE(MTYPE_RIB_DEST, dest); From 407c87a6c3b3282331b708a71a4392ac7d2aace4 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 11 Sep 2017 13:13:17 -0400 Subject: [PATCH 2/3] zebra: Fixup indentation RNODE_FOREACH_RE... function calls were not properly being indented when we switched over to the new format. Let's fix this issue. Signed-off-by: Donald Sharp --- zebra/redistribute.c | 12 +++++++----- zebra/zebra_mpls.c | 11 ++++++++--- zebra/zebra_snmp.c | 15 +++++++++------ zebra/zebra_vrf.c | 5 +++-- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/zebra/redistribute.c b/zebra/redistribute.c index ce86b6c1e3..93bfc0c031 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -84,11 +84,13 @@ static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id) if (!rn) continue; - RNODE_FOREACH_RE(rn, newre) - if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED) - && newre->distance != DISTANCE_INFINITY) - zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD, - client, &rn->p, NULL, newre); + RNODE_FOREACH_RE(rn, newre) { + if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED) + && newre->distance != DISTANCE_INFINITY) + zsend_redistribute_route( + ZEBRA_REDISTRIBUTE_ROUTE_ADD, + client, &rn->p, NULL, newre); + } route_unlock_node(rn); } diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 273945778a..e3ce414127 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -2392,15 +2392,20 @@ void mpls_ldp_ftn_uninstall_all(struct zebra_vrf *zvrf, int afi) for (rn = route_top(table); rn; rn = route_next(rn)) { update = 0; - RNODE_FOREACH_RE(rn, re) - for (nexthop = re->nexthop; nexthop; nexthop = nexthop->next) - if (nexthop->nh_label_type == ZEBRA_LSP_LDP) { + RNODE_FOREACH_RE(rn, re) { + for (nexthop = re->nexthop; + nexthop; + nexthop = nexthop->next) { + if (nexthop->nh_label_type != ZEBRA_LSP_LDP) + continue; + nexthop_del_labels(nexthop); SET_FLAG(re->status, ROUTE_ENTRY_CHANGED); SET_FLAG(re->status, ROUTE_ENTRY_LABELS_CHANGED); update = 1; } + } if (update) rib_queue_add(rn); diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c index 4d6ba566ca..9ac24c53ed 100644 --- a/zebra/zebra_snmp.c +++ b/zebra/zebra_snmp.c @@ -155,8 +155,9 @@ static u_char *ipFwNumber(struct variable *v, oid objid[], size_t *objid_len, /* Return number of routing entries. */ result = 0; for (rn = route_top(table); rn; rn = route_next(rn)) - RNODE_FOREACH_RE(rn, re) - result++; + RNODE_FOREACH_RE(rn, re) { + result++; + } return (u_char *)&result; } @@ -182,8 +183,9 @@ static u_char *ipCidrNumber(struct variable *v, oid objid[], size_t *objid_len, /* Return number of routing entries. */ result = 0; for (rn = route_top(table); rn; rn = route_next(rn)) - RNODE_FOREACH_RE(rn, re) - result++; + RNODE_FOREACH_RE(rn, re) { + result++; + } return (u_char *)&result; } @@ -388,8 +390,9 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], /* Check destination first */ if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest) > 0) - RNODE_FOREACH_RE(np2, re2) - check_replace(np2, re2, np, re); + RNODE_FOREACH_RE(np2, re2) { + check_replace(np2, re2, np, re); + } if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest) == 0) { /* have to look at each re individually */ diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 0a26ac6ad7..62c7d020bc 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -290,8 +290,9 @@ static void zebra_rtable_node_cleanup(struct route_table *table, { struct route_entry *re, *next; - RNODE_FOREACH_RE_SAFE(node, re, next) - rib_unlink(node, re); + RNODE_FOREACH_RE_SAFE(node, re, next) { + rib_unlink(node, re); + } if (node->info) XFREE(MTYPE_RIB_DEST, node->info); From 0a16efff9bb19e617e861fbcae6b772e67e6b500 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 11 Sep 2017 13:29:24 -0400 Subject: [PATCH 3/3] zebra: Fix rib_update_table We should only be operating RIB_UPDATE_IF_CHANGE on types that zebra has control of. We assume that the calling routing protocol is going to take care of their own route changes based upon the interface state change. Also try to re-organize the code a tiny bit to allow it to fit better within a tabed world. Signed-off-by: Donald Sharp --- zebra/zebra_rib.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 9dc0630c8c..376425329b 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2553,27 +2553,29 @@ static void rib_update_table(struct route_table *table, */ RNODE_FOREACH_RE_SAFE(rn, re, next) { - if (re->type == ZEBRA_ROUTE_OSPF - || re->type == ZEBRA_ROUTE_OSPF6 - || re->type == ZEBRA_ROUTE_BGP) - continue; /* protocol will handle. */ - else if (re->type == ZEBRA_ROUTE_STATIC) { - struct nexthop *nh; - for (nh = re->nexthop; nh; - nh = nh->next) - if (!(nh->type - == NEXTHOP_TYPE_IPV4 - || nh->type - == NEXTHOP_TYPE_IPV6)) - break; + struct nexthop *nh; - /* If we only have nexthops to a - * gateway, NHT will - * take care. - */ - if (nh) - rib_queue_add(rn); - } else + if (re->type != ZEBRA_ROUTE_SYSTEM && + re->type != ZEBRA_ROUTE_KERNEL && + re->type != ZEBRA_ROUTE_CONNECT && + re->type != ZEBRA_ROUTE_STATIC) + continue; + + if (re->type != ZEBRA_ROUTE_STATIC) { + rib_queue_add(rn); + continue; + } + + for (nh = re->nexthop; nh; nh = nh->next) + if (!(nh->type == NEXTHOP_TYPE_IPV4 + || nh->type == NEXTHOP_TYPE_IPV6)) + break; + + /* If we only have nexthops to a + * gateway, NHT will + * take care. + */ + if (nh) rib_queue_add(rn); } break;