From fad4d69cd4f529c25b99e8b4f746502d1128c500 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Wed, 20 Mar 2019 11:27:20 -0400 Subject: [PATCH] zebra: add api to locate route-node from dplane ctx Create a helper api that locates a zebra route-node from info in a dplane context struct. Moved code from the results handler to make a more-general api that could be used in other paths. Signed-off-by: Mark Stapp --- zebra/zebra_rib.c | 49 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 835bdc4d31..13799ac890 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1892,20 +1892,16 @@ static int rib_update_re_from_ctx(struct route_entry *re, } /* - * Route-update results processing after async dataplane update. + * Helper to locate a zebra route-node from a dplane context. This is used + * when processing dplane results, e.g. Note well: the route-node is returned + * with a ref held - route_unlock_node() must be called eventually. */ -static void rib_process_result(struct zebra_dplane_ctx *ctx) +static struct route_node * +rib_find_rn_from_ctx(const struct zebra_dplane_ctx *ctx) { struct route_table *table = NULL; - struct zebra_vrf *zvrf = NULL; struct route_node *rn = NULL; - struct route_entry *re = NULL, *old_re = NULL, *rib; - bool is_update = false; - char dest_str[PREFIX_STRLEN] = ""; - enum dplane_op_e op; - enum zebra_dplane_result status; const struct prefix *dest_pfx, *src_pfx; - uint32_t seq; /* Locate rn and re(s) from ctx */ @@ -1915,7 +1911,7 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) dplane_ctx_get_table(ctx)); if (table == NULL) { if (IS_ZEBRA_DEBUG_DPLANE) { - zlog_debug("Failed to process dplane results: no table for afi %d, safi %d, vrf %u", + zlog_debug("Failed to find route for ctx: no table for afi %d, safi %d, vrf %u", dplane_ctx_get_afi(ctx), dplane_ctx_get_safi(ctx), dplane_ctx_get_vrf(ctx)); @@ -1923,8 +1919,34 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) goto done; } - zvrf = vrf_info_lookup(dplane_ctx_get_vrf(ctx)); + dest_pfx = dplane_ctx_get_dest(ctx); + src_pfx = dplane_ctx_get_src(ctx); + + rn = srcdest_rnode_get(table, dest_pfx, + src_pfx ? (struct prefix_ipv6 *)src_pfx : NULL); + +done: + return rn; +} + + +/* + * Route-update results processing after async dataplane update. + */ +static void rib_process_result(struct zebra_dplane_ctx *ctx) +{ + struct zebra_vrf *zvrf = NULL; + struct route_node *rn = NULL; + struct route_entry *re = NULL, *old_re = NULL, *rib; + bool is_update = false; + char dest_str[PREFIX_STRLEN] = ""; + enum dplane_op_e op; + enum zebra_dplane_result status; + const struct prefix *dest_pfx, *src_pfx; + uint32_t seq; + + zvrf = vrf_info_lookup(dplane_ctx_get_vrf(ctx)); dest_pfx = dplane_ctx_get_dest(ctx); /* Note well: only capturing the prefix string if debug is enabled here; @@ -1933,9 +1955,8 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) if (IS_ZEBRA_DEBUG_DPLANE) prefix2str(dest_pfx, dest_str, sizeof(dest_str)); - src_pfx = dplane_ctx_get_src(ctx); - rn = srcdest_rnode_get(table, dplane_ctx_get_dest(ctx), - src_pfx ? (struct prefix_ipv6 *)src_pfx : NULL); + /* Locate rn and re(s) from ctx */ + rn = rib_find_rn_from_ctx(ctx); if (rn == NULL) { if (IS_ZEBRA_DEBUG_DPLANE) { zlog_debug("Failed to process dplane results: no route for %u:%s", -- 2.39.5