Skip to content

Commit

Permalink
zebra: Rearrange dplane_ctx_route_init
Browse files Browse the repository at this point in the history
In order for a future commit to abstract the dplane_ctx_route_init
so that the kernel can use it, let's move some stuff around
and add a dplane_ctx_route_init_basic that can be used by multiple
different paths

Signed-off-by: Donald Sharp <[email protected]>

create a dplane_ctx_route_init_basic so it can be used

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Dec 12, 2022
1 parent 10388e9 commit f935122
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
62 changes: 42 additions & 20 deletions zebra/zebra_dplane.c
Original file line number Diff line number Diff line change
Expand Up @@ -2782,24 +2782,15 @@ static int dplane_ctx_ns_init(struct zebra_dplane_ctx *ctx,
return AOK;
}

/*
* Initialize a context block for a route update from zebra data structs.
*/
int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
struct route_node *rn, struct route_entry *re)
int dplane_ctx_route_init_basic(struct zebra_dplane_ctx *ctx,
enum dplane_op_e op, struct route_entry *re,
const struct prefix *p,
const struct prefix *src_p, afi_t afi,
safi_t safi)
{
int ret = EINVAL;
const struct route_table *table = NULL;
const struct rib_table_info *info;
const struct prefix *p, *src_p;
struct zebra_ns *zns;
struct zebra_vrf *zvrf;
struct nexthop *nexthop;
struct zebra_l3vni *zl3vni;
const struct interface *ifp;
struct dplane_intf_extra *if_extra;

if (!ctx || !rn || !re)
if (!ctx || !re)
return ret;

TAILQ_INIT(&ctx->u.rinfo.intf_extra_q);
Expand All @@ -2810,9 +2801,6 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
ctx->u.rinfo.zd_type = re->type;
ctx->u.rinfo.zd_old_type = re->type;

/* Prefixes: dest, and optional source */
srcdest_rnode_prefixes(rn, &p, &src_p);

prefix_copy(&(ctx->u.rinfo.zd_dest), p);

if (src_p)
Expand All @@ -2833,11 +2821,45 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
ctx->u.rinfo.zd_old_tag = re->tag;
ctx->u.rinfo.zd_distance = re->distance;

ctx->u.rinfo.zd_afi = afi;
ctx->u.rinfo.zd_safi = safi;

return AOK;
}

/*
* Initialize a context block for a route update from zebra data structs.
*/
int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
struct route_node *rn, struct route_entry *re)
{
int ret = EINVAL;
const struct route_table *table = NULL;
const struct rib_table_info *info;
const struct prefix *p, *src_p;
struct zebra_ns *zns;
struct zebra_vrf *zvrf;
struct nexthop *nexthop;
struct zebra_l3vni *zl3vni;
const struct interface *ifp;
struct dplane_intf_extra *if_extra;

if (!ctx || !rn || !re)
return ret;

/*
* Let's grab the data from the route_node
* so that we can call a helper function
*/

/* Prefixes: dest, and optional source */
srcdest_rnode_prefixes(rn, &p, &src_p);
table = srcdest_rnode_table(rn);
info = table->info;

ctx->u.rinfo.zd_afi = info->afi;
ctx->u.rinfo.zd_safi = info->safi;
if (dplane_ctx_route_init_basic(ctx, op, re, p, src_p, info->afi,
info->safi) != AOK)
return ret;

/* Copy nexthops; recursive info is included too */
copy_nexthops(&(ctx->u.rinfo.zd_ng.nexthop),
Expand Down
6 changes: 6 additions & 0 deletions zebra/zebra_dplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@ dplane_pbr_ipset_entry_delete(struct zebra_pbr_ipset_entry *ipset);
int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
struct route_node *rn, struct route_entry *re);

int dplane_ctx_route_init_basic(struct zebra_dplane_ctx *ctx,
enum dplane_op_e op, struct route_entry *re,
const struct prefix *p,
const struct prefix *src_p, afi_t afi,
safi_t safi);

/* Encode next hop information into data plane context. */
int dplane_ctx_nexthop_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
struct nhg_hash_entry *nhe);
Expand Down

0 comments on commit f935122

Please sign in to comment.