]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Abstract `dplane_ctx_route_init` to init route without copying
authorCarmine Scarpitta <carmine.scarpitta@uniroma2.it>
Fri, 7 Jul 2023 00:55:18 +0000 (02:55 +0200)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Fri, 7 Jul 2023 16:16:36 +0000 (16:16 +0000)
The function `dplane_ctx_route_init` initializes a dplane route context
from the route object passed as an argument. Let's abstract this
function to allow initializing the dplane route context without actually
copying a route object.

This allows us to use this function for initializing a dplane route
context when we don't have any route to copy in it.

Signed-off-by: Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
(cherry picked from commit 745a0fcbb21a6bd7330454437abe34aff0bf82c0)

zebra/zebra_dplane.c

index eb408232ab90a1f34cf5b1c9bd552f0a93a354e5..639f3cd918cc310b581c6f39d8d700c4604df485 100644 (file)
@@ -2798,7 +2798,7 @@ int dplane_ctx_route_init_basic(struct zebra_dplane_ctx *ctx,
 {
        int ret = EINVAL;
 
-       if (!ctx || !re)
+       if (!ctx)
                return ret;
 
        dplane_intf_extra_list_init(&ctx->u.rinfo.intf_extra_list);
@@ -2806,6 +2806,13 @@ int dplane_ctx_route_init_basic(struct zebra_dplane_ctx *ctx,
        ctx->zd_op = op;
        ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS;
 
+       /* This function may be called to create/init a dplane context, not
+        * necessarily to copy a route object. Let's return if there is no route
+        * object to copy.
+        */
+       if (!re)
+               return AOK;
+
        ctx->u.rinfo.zd_type = re->type;
        ctx->u.rinfo.zd_old_type = re->type;
 
@@ -2837,6 +2844,8 @@ int dplane_ctx_route_init_basic(struct zebra_dplane_ctx *ctx,
 
 /*
  * Initialize a context block for a route update from zebra data structs.
+ * If the `rn` or `re` parameters are NULL, this function only initializes the
+ * dplane context without copying a route object into it.
  */
 int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
                          struct route_node *rn, struct route_entry *re)
@@ -2853,9 +2862,17 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
        const struct interface *ifp;
        struct dplane_intf_extra *if_extra;
 
-       if (!ctx || !rn || !re)
+       if (!ctx)
                return ret;
 
+       /*
+        * Initialize the dplane context and return, if there is no route
+        * object to copy
+        */
+       if (!re || !rn)
+               return dplane_ctx_route_init_basic(ctx, op, NULL, NULL, NULL,
+                                                  AFI_UNSPEC, SAFI_UNSPEC);
+
        /*
         * Let's grab the data from the route_node
         * so that we can call a helper function