Skip to content

Commit

Permalink
zebra: optimize the RIB get_next() callback
Browse files Browse the repository at this point in the history
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 <renato@opensourcerouting.org>
  • Loading branch information
rwestphal committed May 16, 2020
1 parent 9b4d578 commit 78769ea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions ripd/rip_nb_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions ripngd/ripng_nb_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion zebra/zebra_nb_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 78769ea

Please sign in to comment.