From 78769ea20595351136cff1fcf3ce0448b0cd4e21 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 18 May 2020 23:26:53 -0300 Subject: [PATCH] zebra: optimize the RIB get_next() callback When fetching the next route node in the RIB, skip the empty ones to avoid calling other northbound callbacks later unnecessarily. Signed-off-by: Renato Westphal --- ripd/rip_nb_state.c | 1 + ripngd/ripng_nb_state.c | 1 + zebra/zebra_nb_state.c | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ripd/rip_nb_state.c b/ripd/rip_nb_state.c index e88f33ec68..184c760998 100644 --- a/ripd/rip_nb_state.c +++ b/ripd/rip_nb_state.c @@ -175,6 +175,7 @@ ripd_instance_state_routes_route_get_next(struct nb_cb_get_next_args *args) rn = route_top(rip->table); else rn = route_next((struct route_node *)args->list_entry); + /* Optimization: skip empty route nodes. */ while (rn && rn->info == NULL) rn = route_next(rn); diff --git a/ripngd/ripng_nb_state.c b/ripngd/ripng_nb_state.c index 926573b407..02a00ac429 100644 --- a/ripngd/ripng_nb_state.c +++ b/ripngd/ripng_nb_state.c @@ -144,6 +144,7 @@ ripngd_instance_state_routes_route_get_next(struct nb_cb_get_next_args *args) rn = agg_route_top(ripng->table); else rn = agg_route_next((struct agg_node *)args->list_entry); + /* Optimization: skip empty route nodes. */ while (rn && rn->info == NULL) rn = agg_route_next(rn); diff --git a/zebra/zebra_nb_state.c b/zebra/zebra_nb_state.c index e1c06819fa..afbabe342c 100644 --- a/zebra/zebra_nb_state.c +++ b/zebra/zebra_nb_state.c @@ -221,12 +221,15 @@ const void * lib_vrf_zebra_ribs_rib_route_get_next(struct nb_cb_get_next_args *args) { const struct zebra_router_table *zrt = args->parent_list_entry; - const struct route_node *rn = args->list_entry; + struct route_node *rn = (struct route_node *)args->list_entry; if (args->list_entry == NULL) rn = route_top(zrt->table); else rn = srcdest_route_next((struct route_node *)rn); + /* Optimization: skip empty route nodes. */ + while (rn && rn->info == NULL) + rn = route_next(rn); /* Skip link-local routes. */ if (rn && rn->p.family == AF_INET6 -- 2.39.5