Skip to content

Commit

Permalink
zebra: Abstract dplane_ctx_route_init to init route without copying
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cscarpitta committed Jul 7, 2023
1 parent 30f511e commit 745a0fc
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions zebra/zebra_dplane.c
Original file line number Diff line number Diff line change
Expand Up @@ -3257,14 +3257,21 @@ 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);

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;

Expand Down Expand Up @@ -3296,6 +3303,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)
Expand All @@ -3312,9 +3321,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
Expand Down

0 comments on commit 745a0fc

Please sign in to comment.