From 593e4eb1e8d2151e1067d30765c3517fb55a1670 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Sun, 17 Mar 2019 14:41:11 -0400 Subject: [PATCH] zebra: add dplane context accessors Add several accessors for data items needed to produce a notification context. Signed-off-by: Mark Stapp --- zebra/zebra_dplane.c | 86 +++++++++++++++++++++++++++++++++++++++++++- zebra/zebra_dplane.h | 19 ++++++++-- 2 files changed, 102 insertions(+), 3 deletions(-) diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 3ded32ea19..a13fc28d7d 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -353,7 +353,7 @@ struct thread_master *dplane_get_thread_master(void) /* * Allocate a dataplane update context */ -static struct zebra_dplane_ctx *dplane_ctx_alloc(void) +struct zebra_dplane_ctx *dplane_ctx_alloc(void) { struct zebra_dplane_ctx *p; @@ -546,6 +546,12 @@ bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx) return CHECK_FLAG(ctx->zd_flags, DPLANE_CTX_FLAG_NO_KERNEL); } +void dplane_ctx_set_op(struct zebra_dplane_ctx *ctx, enum dplane_op_e op) +{ + DPLANE_CTX_VALID(ctx); + ctx->zd_op = op; +} + enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -631,6 +637,14 @@ const char *dplane_res2str(enum zebra_dplane_result res) return ret; } +void dplane_ctx_set_dest(struct zebra_dplane_ctx *ctx, + const struct prefix *dest) +{ + DPLANE_CTX_VALID(ctx); + + prefix_copy(&(ctx->u.rinfo.zd_dest), dest); +} + const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -638,6 +652,16 @@ const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx) return &(ctx->u.rinfo.zd_dest); } +void dplane_ctx_set_src(struct zebra_dplane_ctx *ctx, const struct prefix *src) +{ + DPLANE_CTX_VALID(ctx); + + if (src) + prefix_copy(&(ctx->u.rinfo.zd_src), src); + else + memset(&(ctx->u.rinfo.zd_src), 0, sizeof(struct prefix)); +} + /* Source prefix is a little special - return NULL for "no src prefix" */ const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx) { @@ -672,6 +696,13 @@ uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx) return ctx->zd_old_seq; } +void dplane_ctx_set_vrf(struct zebra_dplane_ctx *ctx, vrf_id_t vrf) +{ + DPLANE_CTX_VALID(ctx); + + ctx->zd_vrf_id = vrf; +} + vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -679,6 +710,13 @@ vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx) return ctx->zd_vrf_id; } +void dplane_ctx_set_type(struct zebra_dplane_ctx *ctx, int type) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.rinfo.zd_type = type; +} + int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -693,6 +731,13 @@ int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx) return ctx->u.rinfo.zd_old_type; } +void dplane_ctx_set_afi(struct zebra_dplane_ctx *ctx, afi_t afi) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.rinfo.zd_afi = afi; +} + afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -700,6 +745,13 @@ afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx) return ctx->u.rinfo.zd_afi; } +void dplane_ctx_set_safi(struct zebra_dplane_ctx *ctx, safi_t safi) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.rinfo.zd_safi = safi; +} + safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -707,6 +759,13 @@ safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx) return ctx->u.rinfo.zd_safi; } +void dplane_ctx_set_table(struct zebra_dplane_ctx *ctx, uint32_t table) +{ + DPLANE_CTX_VALID(ctx); + + ctx->zd_table_id = table; +} + uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -784,6 +843,17 @@ uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx) return ctx->u.rinfo.zd_old_distance; } +void dplane_ctx_set_nexthops(struct zebra_dplane_ctx *ctx, struct nexthop *nh) +{ + DPLANE_CTX_VALID(ctx); + + if (ctx->u.rinfo.zd_ng.nexthop) { + nexthops_free(ctx->u.rinfo.zd_ng.nexthop); + ctx->u.rinfo.zd_ng.nexthop = NULL; + } + copy_nexthops(&(ctx->u.rinfo.zd_ng.nexthop), nh, NULL); +} + const struct nexthop_group *dplane_ctx_get_ng( const struct zebra_dplane_ctx *ctx) { @@ -2053,6 +2123,20 @@ int dplane_provider_work_ready(void) return AOK; } +/* + * Enqueue a context directly to zebra main. + */ +void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx *ctx) +{ + struct dplane_ctx_q temp_list; + + /* Zebra's api takes a list, so we need to use a temporary list */ + TAILQ_INIT(&temp_list); + + TAILQ_INSERT_TAIL(&temp_list, ctx, zd_q_entries); + (zdplane_info.dg_results_cb)(&temp_list); +} + /* * Kernel dataplane provider */ diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h index cffcb94d45..0a487e0712 100644 --- a/zebra/zebra_dplane.h +++ b/zebra/zebra_dplane.h @@ -140,6 +140,9 @@ void dplane_enable_sys_route_notifs(void); */ TAILQ_HEAD(dplane_ctx_q, zebra_dplane_ctx); +/* Allocate a context object */ +struct zebra_dplane_ctx *dplane_ctx_alloc(void); + /* Return a dataplane results context block after use; the caller's pointer will * be cleared. */ @@ -170,9 +173,12 @@ void dplane_ctx_set_status(struct zebra_dplane_ctx *ctx, const char *dplane_res2str(enum zebra_dplane_result res); enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_op(struct zebra_dplane_ctx *ctx, enum dplane_op_e op); const char *dplane_op2str(enum dplane_op_e op); const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_dest(struct zebra_dplane_ctx *ctx, + const struct prefix *dest); /* Retrieve last/current provider id */ uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx); @@ -187,17 +193,23 @@ bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx); * to mean "no src prefix" */ const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_src(struct zebra_dplane_ctx *ctx, const struct prefix *src); bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx); uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx); uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_vrf(struct zebra_dplane_ctx *ctx, vrf_id_t vrf); vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx); /* Accessors for route update information */ +void dplane_ctx_set_type(struct zebra_dplane_ctx *ctx, int type); int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx); int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_afi(struct zebra_dplane_ctx *ctx, afi_t afi); afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_safi(struct zebra_dplane_ctx *ctx, safi_t safi); safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_table(struct zebra_dplane_ctx *ctx, uint32_t table); uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx); route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx); route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx); @@ -210,6 +222,7 @@ uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx); uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx); uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_nexthops(struct zebra_dplane_ctx *ctx, struct nexthop *nh); const struct nexthop_group *dplane_ctx_get_ng( const struct zebra_dplane_ctx *ctx); const struct nexthop_group *dplane_ctx_get_old_ng( @@ -322,7 +335,6 @@ uint32_t dplane_get_in_queue_len(void); int dplane_show_helper(struct vty *vty, bool detailed); int dplane_show_provs_helper(struct vty *vty, bool detailed); - /* * Dataplane providers: modules that process or consume dataplane events. */ @@ -417,10 +429,13 @@ struct zebra_dplane_ctx *dplane_provider_dequeue_in_ctx( int dplane_provider_dequeue_in_list(struct zebra_dplane_provider *prov, struct dplane_ctx_q *listp); -/* Enqueue, maintain associated counter and locking */ +/* Enqueue completed work, maintain associated counter and locking */ void dplane_provider_enqueue_out_ctx(struct zebra_dplane_provider *prov, struct zebra_dplane_ctx *ctx); +/* Enqueue a context directly to zebra main. */ +void dplane_provider_enqueue_to_zebra(struct zebra_dplane_ctx *ctx); + /* * Initialize the dataplane modules at zebra startup. This is currently called * by the rib module. Zebra registers a results callback with the dataplane. -- 2.39.5