]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: add api to locate route-node from dplane ctx
authorMark Stapp <mjs@voltanet.io>
Wed, 20 Mar 2019 15:27:20 +0000 (11:27 -0400)
committerMark Stapp <mjs@voltanet.io>
Tue, 28 May 2019 12:21:20 +0000 (08:21 -0400)
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 <mjs@voltanet.io>
zebra/zebra_rib.c

index 835bdc4d31d4e92cea6470891c82c88ab3b8c625..13799ac8900088e40cdb8fa8065f7c037d20f4bc 100644 (file)
@@ -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",