zebra: revise struct names to resolve review comments

Use standard type naming and remove use of typedef to resolve
some review comments.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
This commit is contained in:
Mark Stapp 2018-09-19 13:25:12 -04:00
parent 14c8b173d2
commit 2577906481
8 changed files with 154 additions and 151 deletions

View File

@ -35,7 +35,8 @@
* Update or delete a prefix from the kernel, * Update or delete a prefix from the kernel,
* using info from a dataplane context. * using info from a dataplane context.
*/ */
extern enum zebra_dplane_result kernel_route_update(dplane_ctx_h ctx); extern enum zebra_dplane_result kernel_route_update(
struct zebra_dplane_ctx *ctx);
extern int kernel_address_add_ipv4(struct interface *, struct connected *); extern int kernel_address_add_ipv4(struct interface *, struct connected *);
extern int kernel_address_delete_ipv4(struct interface *, struct connected *); extern int kernel_address_delete_ipv4(struct interface *, struct connected *);

View File

@ -1446,7 +1446,7 @@ static int netlink_neigh_update(int cmd, int ifindex, uint32_t addr, char *lla,
/* /*
* Routing table change via netlink interface, using a dataplane context object * Routing table change via netlink interface, using a dataplane context object
*/ */
static int netlink_route_multipath(int cmd, dplane_ctx_h ctx) static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
{ {
int bytelen; int bytelen;
struct sockaddr_nl snl; struct sockaddr_nl snl;
@ -1827,7 +1827,7 @@ int kernel_get_ipmr_sg_stats(struct zebra_vrf *zvrf, void *in)
* Update or delete a prefix from the kernel, * Update or delete a prefix from the kernel,
* using info from a dataplane context. * using info from a dataplane context.
*/ */
enum zebra_dplane_result kernel_route_update(dplane_ctx_h ctx) enum zebra_dplane_result kernel_route_update(struct zebra_dplane_ctx *ctx)
{ {
int cmd, ret; int cmd, ret;
const struct prefix *p = dplane_ctx_get_dest(ctx); const struct prefix *p = dplane_ctx_get_dest(ctx);

View File

@ -400,7 +400,7 @@ static int kernel_rtm(int cmd, const struct prefix *p,
* Update or delete a prefix from the kernel, * Update or delete a prefix from the kernel,
* using info from a dataplane context struct. * using info from a dataplane context struct.
*/ */
enum zebra_dplane_result kernel_route_update(dplane_ctx_h ctx) enum zebra_dplane_result kernel_route_update(struct zebra_dplane_ctx *ctx)
{ {
enum zebra_dplane_result res = ZEBRA_DPLANE_REQUEST_SUCCESS; enum zebra_dplane_result res = ZEBRA_DPLANE_REQUEST_SUCCESS;

View File

@ -743,7 +743,7 @@ int zsend_route_notify_owner(struct route_entry *re, const struct prefix *p,
/* /*
* Route-owner notification using info from dataplane update context. * Route-owner notification using info from dataplane update context.
*/ */
int zsend_route_notify_owner_ctx(dplane_ctx_h ctx, int zsend_route_notify_owner_ctx(const struct zebra_dplane_ctx *ctx,
enum zapi_route_notify_owner note) enum zapi_route_notify_owner note)
{ {
return (route_notify_internal(dplane_ctx_get_dest(ctx), return (route_notify_internal(dplane_ctx_get_dest(ctx),

View File

@ -70,7 +70,7 @@ extern int zsend_pw_update(struct zserv *client, struct zebra_pw *pw);
extern int zsend_route_notify_owner(struct route_entry *re, extern int zsend_route_notify_owner(struct route_entry *re,
const struct prefix *p, const struct prefix *p,
enum zapi_route_notify_owner note); enum zapi_route_notify_owner note);
extern int zsend_route_notify_owner_ctx(dplane_ctx_h ctx, extern int zsend_route_notify_owner_ctx(const struct zebra_dplane_ctx *ctx,
enum zapi_route_notify_owner note); enum zapi_route_notify_owner note);
extern void zsend_rule_notify_owner(struct zebra_pbr_rule *rule, extern void zsend_rule_notify_owner(struct zebra_pbr_rule *rule,

View File

@ -38,16 +38,13 @@ DEFINE_MTYPE(ZEBRA, DP_PROV, "Zebra DPlane Provider")
# define AOK 0 # define AOK 0
#endif #endif
/* Validation value for context blocks */
const uint32_t DPLANE_CTX_MAGIC = 0xb97a557f;
/* Validation check macro for context blocks */ /* Validation check macro for context blocks */
/* #define DPLANE_DEBUG 1 */ /* #define DPLANE_DEBUG 1 */
#ifdef DPLANE_DEBUG #ifdef DPLANE_DEBUG
# define DPLANE_CTX_VALID(p) \ # define DPLANE_CTX_VALID(p) \
assert((p) && ((p)->zd_magic == DPLANE_CTX_MAGIC)) assert((p) != NULL)
#else #else
@ -60,7 +57,7 @@ const uint32_t DPLANE_CTX_MAGIC = 0xb97a557f;
* the boundary between the zebra main context (and pthread) and the * the boundary between the zebra main context (and pthread) and the
* dataplane layer (and pthread). * dataplane layer (and pthread).
*/ */
struct zebra_dplane_ctx_s { struct zebra_dplane_ctx {
/* Operation code */ /* Operation code */
enum dplane_op_e zd_op; enum dplane_op_e zd_op;
@ -114,16 +111,13 @@ struct zebra_dplane_ctx_s {
/* TODO -- use fixed array of nexthops, to avoid mallocs? */ /* TODO -- use fixed array of nexthops, to avoid mallocs? */
/* Embedded list linkage */ /* Embedded list linkage */
TAILQ_ENTRY(zebra_dplane_ctx_s) zd_q_entries; TAILQ_ENTRY(zebra_dplane_ctx) zd_q_entries;
/* Magic validation value */
uint32_t zd_magic;
}; };
/* /*
* Registration block for one dataplane provider. * Registration block for one dataplane provider.
*/ */
struct zebra_dplane_provider_s { struct zebra_dplane_provider {
/* Name */ /* Name */
char dp_name[DPLANE_PROVIDER_NAMELEN + 1]; char dp_name[DPLANE_PROVIDER_NAMELEN + 1];
@ -141,14 +135,14 @@ struct zebra_dplane_provider_s {
_Atomic uint64_t dp_error_counter; _Atomic uint64_t dp_error_counter;
/* Embedded list linkage */ /* Embedded list linkage */
TAILQ_ENTRY(zebra_dplane_provider_s) dp_q_providers; TAILQ_ENTRY(zebra_dplane_provider) dp_q_providers;
}; };
/* /*
* Globals * Globals
*/ */
static struct zebra_dplane_globals_s { static struct zebra_dplane_globals {
/* Mutex to control access to dataplane components */ /* Mutex to control access to dataplane components */
pthread_mutex_t dg_mutex; pthread_mutex_t dg_mutex;
@ -162,10 +156,10 @@ static struct zebra_dplane_globals_s {
volatile bool dg_run; volatile bool dg_run;
/* Route-update context queue inbound to the dataplane */ /* Route-update context queue inbound to the dataplane */
TAILQ_HEAD(zdg_ctx_q, zebra_dplane_ctx_s) dg_route_ctx_q; TAILQ_HEAD(zdg_ctx_q, zebra_dplane_ctx) dg_route_ctx_q;
/* Ordered list of providers */ /* Ordered list of providers */
TAILQ_HEAD(zdg_prov_q, zebra_dplane_provider_s) dg_providers_q; TAILQ_HEAD(zdg_prov_q, zebra_dplane_provider) dg_providers_q;
/* Counter used to assign internal ids to providers */ /* Counter used to assign internal ids to providers */
uint32_t dg_provider_id; uint32_t dg_provider_id;
@ -184,14 +178,14 @@ static struct zebra_dplane_globals_s {
/* Event pointer for pending shutdown check loop */ /* Event pointer for pending shutdown check loop */
struct thread *dg_t_shutdown_check; struct thread *dg_t_shutdown_check;
} zdplane_g; } zdplane_info;
/* /*
* Lock and unlock for interactions with the zebra 'core' * Lock and unlock for interactions with the zebra 'core'
*/ */
#define DPLANE_LOCK() pthread_mutex_lock(&zdplane_g.dg_mutex) #define DPLANE_LOCK() pthread_mutex_lock(&zdplane_info.dg_mutex)
#define DPLANE_UNLOCK() pthread_mutex_unlock(&zdplane_g.dg_mutex) #define DPLANE_UNLOCK() pthread_mutex_unlock(&zdplane_info.dg_mutex)
/* Prototypes */ /* Prototypes */
static int dplane_route_process(struct thread *event); static int dplane_route_process(struct thread *event);
@ -203,16 +197,14 @@ static int dplane_route_process(struct thread *event);
/* /*
* Allocate a dataplane update context * Allocate a dataplane update context
*/ */
static dplane_ctx_h dplane_ctx_alloc(void) static struct zebra_dplane_ctx *dplane_ctx_alloc(void)
{ {
struct zebra_dplane_ctx_s *p; struct zebra_dplane_ctx *p;
/* TODO -- just alloc'ing memory, but would like to maintain /* TODO -- just alloc'ing memory, but would like to maintain
* a pool * a pool
*/ */
p = XCALLOC(MTYPE_DP_CTX, sizeof(struct zebra_dplane_ctx_s)); p = XCALLOC(MTYPE_DP_CTX, sizeof(struct zebra_dplane_ctx));
if (p)
p->zd_magic = DPLANE_CTX_MAGIC;
return p; return p;
} }
@ -220,7 +212,7 @@ static dplane_ctx_h dplane_ctx_alloc(void)
/* /*
* Free a dataplane results context. * Free a dataplane results context.
*/ */
static void dplane_ctx_free(dplane_ctx_h *pctx) static void dplane_ctx_free(struct zebra_dplane_ctx **pctx)
{ {
if (pctx) { if (pctx) {
DPLANE_CTX_VALID(*pctx); DPLANE_CTX_VALID(*pctx);
@ -240,9 +232,6 @@ static void dplane_ctx_free(dplane_ctx_h *pctx)
nexthops_free((*pctx)->zd_old_ng.nexthop); nexthops_free((*pctx)->zd_old_ng.nexthop);
} }
/* Clear validation value */
(*pctx)->zd_magic = 0;
XFREE(MTYPE_DP_CTX, *pctx); XFREE(MTYPE_DP_CTX, *pctx);
*pctx = NULL; *pctx = NULL;
} }
@ -251,22 +240,23 @@ static void dplane_ctx_free(dplane_ctx_h *pctx)
/* /*
* Return a context block to the dplane module after processing * Return a context block to the dplane module after processing
*/ */
void dplane_ctx_fini(dplane_ctx_h *pctx) void dplane_ctx_fini(struct zebra_dplane_ctx **pctx)
{ {
/* TODO -- enqueue for next provider; for now, just free */ /* TODO -- enqueue for next provider; for now, just free */
dplane_ctx_free(pctx); dplane_ctx_free(pctx);
} }
/* Enqueue a context block */ /* Enqueue a context block */
void dplane_ctx_enqueue_tail(struct dplane_ctx_q_s *q, dplane_ctx_h ctx) void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q,
const struct zebra_dplane_ctx *ctx)
{ {
TAILQ_INSERT_TAIL(q, ctx, zd_q_entries); TAILQ_INSERT_TAIL(q, (struct zebra_dplane_ctx *)ctx, zd_q_entries);
} }
/* Dequeue a context block from the head of a list */ /* Dequeue a context block from the head of a list */
void dplane_ctx_dequeue(struct dplane_ctx_q_s *q, dplane_ctx_h *ctxp) void dplane_ctx_dequeue(struct dplane_ctx_q *q, struct zebra_dplane_ctx **ctxp)
{ {
dplane_ctx_h ctx = TAILQ_FIRST(q); struct zebra_dplane_ctx *ctx = TAILQ_FIRST(q);
if (ctx) if (ctx)
TAILQ_REMOVE(q, ctx, zd_q_entries); TAILQ_REMOVE(q, ctx, zd_q_entries);
@ -277,14 +267,15 @@ void dplane_ctx_dequeue(struct dplane_ctx_q_s *q, dplane_ctx_h *ctxp)
/* /*
* Accessors for information from the context object * Accessors for information from the context object
*/ */
enum zebra_dplane_result dplane_ctx_get_status(const dplane_ctx_h ctx) enum zebra_dplane_result dplane_ctx_get_status(
const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_status; return ctx->zd_status;
} }
enum dplane_op_e dplane_ctx_get_op(const dplane_ctx_h ctx) enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
@ -335,7 +326,7 @@ const char *dplane_res2str(enum zebra_dplane_result res)
return ret; return ret;
} }
const struct prefix *dplane_ctx_get_dest(const dplane_ctx_h ctx) const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
@ -343,7 +334,7 @@ const struct prefix *dplane_ctx_get_dest(const dplane_ctx_h ctx)
} }
/* Source prefix is a little special - return NULL for "no src prefix" */ /* Source prefix is a little special - return NULL for "no src prefix" */
const struct prefix *dplane_ctx_get_src(const dplane_ctx_h ctx) const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
@ -355,154 +346,157 @@ const struct prefix *dplane_ctx_get_src(const dplane_ctx_h ctx)
} }
} }
bool dplane_ctx_is_update(const dplane_ctx_h ctx) bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_is_update; return ctx->zd_is_update;
} }
uint32_t dplane_ctx_get_seq(const dplane_ctx_h ctx) uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_seq; return ctx->zd_seq;
} }
uint32_t dplane_ctx_get_old_seq(const dplane_ctx_h ctx) uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_old_seq; return ctx->zd_old_seq;
} }
vrf_id_t dplane_ctx_get_vrf(const dplane_ctx_h ctx) vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_vrf_id; return ctx->zd_vrf_id;
} }
int dplane_ctx_get_type(const dplane_ctx_h ctx) int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_type; return ctx->zd_type;
} }
int dplane_ctx_get_old_type(const dplane_ctx_h ctx) int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_old_type; return ctx->zd_old_type;
} }
afi_t dplane_ctx_get_afi(const dplane_ctx_h ctx) afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_afi; return ctx->zd_afi;
} }
safi_t dplane_ctx_get_safi(const dplane_ctx_h ctx) safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_safi; return ctx->zd_safi;
} }
uint32_t dplane_ctx_get_table(const dplane_ctx_h ctx) uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_table_id; return ctx->zd_table_id;
} }
route_tag_t dplane_ctx_get_tag(const dplane_ctx_h ctx) route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_tag; return ctx->zd_tag;
} }
route_tag_t dplane_ctx_get_old_tag(const dplane_ctx_h ctx) route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_old_tag; return ctx->zd_old_tag;
} }
uint16_t dplane_ctx_get_instance(const dplane_ctx_h ctx) uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_instance; return ctx->zd_instance;
} }
uint16_t dplane_ctx_get_old_instance(const dplane_ctx_h ctx) uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_instance; return ctx->zd_instance;
} }
uint32_t dplane_ctx_get_metric(const dplane_ctx_h ctx) uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_metric; return ctx->zd_metric;
} }
uint32_t dplane_ctx_get_old_metric(const dplane_ctx_h ctx) uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_old_metric; return ctx->zd_old_metric;
} }
uint32_t dplane_ctx_get_mtu(const dplane_ctx_h ctx) uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_mtu; return ctx->zd_mtu;
} }
uint32_t dplane_ctx_get_nh_mtu(const dplane_ctx_h ctx) uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_nexthop_mtu; return ctx->zd_nexthop_mtu;
} }
uint8_t dplane_ctx_get_distance(const dplane_ctx_h ctx) uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_distance; return ctx->zd_distance;
} }
uint8_t dplane_ctx_get_old_distance(const dplane_ctx_h ctx) uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return ctx->zd_old_distance; return ctx->zd_old_distance;
} }
const struct nexthop_group *dplane_ctx_get_ng(const dplane_ctx_h ctx) const struct nexthop_group *dplane_ctx_get_ng(
const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return &(ctx->zd_ng); return &(ctx->zd_ng);
} }
const struct nexthop_group *dplane_ctx_get_old_ng(const dplane_ctx_h ctx) const struct nexthop_group *dplane_ctx_get_old_ng(
const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
return &(ctx->zd_old_ng); return &(ctx->zd_old_ng);
} }
const struct zebra_dplane_info *dplane_ctx_get_ns(const dplane_ctx_h ctx) const struct zebra_dplane_info *dplane_ctx_get_ns(
const struct zebra_dplane_ctx *ctx)
{ {
DPLANE_CTX_VALID(ctx); DPLANE_CTX_VALID(ctx);
@ -516,7 +510,7 @@ const struct zebra_dplane_info *dplane_ctx_get_ns(const dplane_ctx_h ctx)
/* /*
* Initialize a context block for a route update from zebra data structs. * Initialize a context block for a route update from zebra data structs.
*/ */
static int dplane_ctx_route_init(dplane_ctx_h ctx, static int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx,
enum dplane_op_e op, enum dplane_op_e op,
struct route_node *rn, struct route_node *rn,
struct route_entry *re) struct route_entry *re)
@ -606,20 +600,21 @@ done:
* Enqueue a new route update, * Enqueue a new route update,
* and ensure an event is active for the dataplane thread. * and ensure an event is active for the dataplane thread.
*/ */
static int dplane_route_enqueue(dplane_ctx_h ctx) static int dplane_route_enqueue(struct zebra_dplane_ctx *ctx)
{ {
int ret = EINVAL; int ret = EINVAL;
/* Enqueue for processing by the dataplane thread */ /* Enqueue for processing by the dataplane thread */
DPLANE_LOCK(); DPLANE_LOCK();
{ {
TAILQ_INSERT_TAIL(&zdplane_g.dg_route_ctx_q, ctx, zd_q_entries); TAILQ_INSERT_TAIL(&zdplane_info.dg_route_ctx_q, ctx,
zd_q_entries);
} }
DPLANE_UNLOCK(); DPLANE_UNLOCK();
/* Ensure that an event for the dataplane thread is active */ /* Ensure that an event for the dataplane thread is active */
thread_add_event(zdplane_g.dg_master, dplane_route_process, NULL, 0, thread_add_event(zdplane_info.dg_master, dplane_route_process, NULL, 0,
&zdplane_g.dg_t_update); &zdplane_info.dg_t_update);
ret = AOK; ret = AOK;
@ -629,15 +624,15 @@ static int dplane_route_enqueue(dplane_ctx_h ctx)
/* /*
* Attempt to dequeue a route-update block * Attempt to dequeue a route-update block
*/ */
static dplane_ctx_h dplane_route_dequeue(void) static struct zebra_dplane_ctx *dplane_route_dequeue(void)
{ {
dplane_ctx_h ctx = NULL; struct zebra_dplane_ctx *ctx = NULL;
DPLANE_LOCK(); DPLANE_LOCK();
{ {
ctx = TAILQ_FIRST(&zdplane_g.dg_route_ctx_q); ctx = TAILQ_FIRST(&zdplane_info.dg_route_ctx_q);
if (ctx) { if (ctx) {
TAILQ_REMOVE(&zdplane_g.dg_route_ctx_q, TAILQ_REMOVE(&zdplane_info.dg_route_ctx_q,
ctx, zd_q_entries); ctx, zd_q_entries);
} }
} }
@ -657,7 +652,7 @@ dplane_route_update_internal(struct route_node *rn,
{ {
enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE;
int ret = EINVAL; int ret = EINVAL;
dplane_ctx_h ctx = NULL; struct zebra_dplane_ctx *ctx = NULL;
/* Obtain context block */ /* Obtain context block */
ctx = dplane_ctx_alloc(); ctx = dplane_ctx_alloc();
@ -700,24 +695,24 @@ dplane_route_update_internal(struct route_node *rn,
done: done:
/* Update counters */ /* Update counters */
atomic_fetch_add_explicit(&zdplane_g.dg_routes_in, 1, atomic_fetch_add_explicit(&zdplane_info.dg_routes_in, 1,
memory_order_relaxed); memory_order_relaxed);
if (ret == AOK) { if (ret == AOK) {
uint32_t high, curr; uint32_t high, curr;
curr = atomic_fetch_add_explicit(&zdplane_g.dg_routes_queued, 1, curr = atomic_fetch_add_explicit(&zdplane_info.dg_routes_queued,
memory_order_seq_cst); 1, memory_order_seq_cst);
/* We don't have add_and_fetch - sigh */ /* We don't have add_and_fetch - sigh */
curr++; curr++;
/* Maybe update high-water counter also */ /* Maybe update high-water counter also */
high = atomic_load_explicit(&zdplane_g.dg_routes_queued_max, high = atomic_load_explicit(&zdplane_info.dg_routes_queued_max,
memory_order_seq_cst); memory_order_seq_cst);
while (high < curr) { while (high < curr) {
if (atomic_compare_exchange_weak_explicit( if (atomic_compare_exchange_weak_explicit(
&zdplane_g.dg_routes_queued_max, &zdplane_info.dg_routes_queued_max,
&high, curr, &high, curr,
memory_order_seq_cst, memory_order_seq_cst,
memory_order_seq_cst)) memory_order_seq_cst))
@ -726,7 +721,7 @@ done:
result = ZEBRA_DPLANE_REQUEST_QUEUED; result = ZEBRA_DPLANE_REQUEST_QUEUED;
} else if (ctx) { } else if (ctx) {
atomic_fetch_add_explicit(&zdplane_g.dg_route_errors, 1, atomic_fetch_add_explicit(&zdplane_info.dg_route_errors, 1,
memory_order_relaxed); memory_order_relaxed);
dplane_ctx_free(&ctx); dplane_ctx_free(&ctx);
} }
@ -794,11 +789,11 @@ done:
static int dplane_route_process(struct thread *event) static int dplane_route_process(struct thread *event)
{ {
enum zebra_dplane_result res; enum zebra_dplane_result res;
dplane_ctx_h ctx; struct zebra_dplane_ctx *ctx;
while (1) { while (1) {
/* Check for shutdown */ /* Check for shutdown */
if (!zdplane_g.dg_run) if (!zdplane_info.dg_run)
break; break;
/* TODO -- limit number of updates per cycle? */ /* TODO -- limit number of updates per cycle? */
@ -807,7 +802,7 @@ static int dplane_route_process(struct thread *event)
break; break;
/* Update counter */ /* Update counter */
atomic_fetch_sub_explicit(&zdplane_g.dg_routes_queued, 1, atomic_fetch_sub_explicit(&zdplane_info.dg_routes_queued, 1,
memory_order_relaxed); memory_order_relaxed);
if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) {
@ -827,13 +822,13 @@ static int dplane_route_process(struct thread *event)
res = kernel_route_update(ctx); res = kernel_route_update(ctx);
if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) if (res != ZEBRA_DPLANE_REQUEST_SUCCESS)
atomic_fetch_add_explicit(&zdplane_g.dg_route_errors, 1, atomic_fetch_add_explicit(&zdplane_info.dg_route_errors,
memory_order_relaxed); 1, memory_order_relaxed);
ctx->zd_status = res; ctx->zd_status = res;
/* Enqueue result to zebra main context */ /* Enqueue result to zebra main context */
(*zdplane_g.dg_results_cb)(ctx); (*zdplane_info.dg_results_cb)(ctx);
ctx = NULL; ctx = NULL;
} }
@ -851,13 +846,13 @@ int dplane_show_helper(struct vty *vty, bool detailed)
/* Using atomics because counters are being changed in different /* Using atomics because counters are being changed in different
* contexts. * contexts.
*/ */
incoming = atomic_load_explicit(&zdplane_g.dg_routes_in, incoming = atomic_load_explicit(&zdplane_info.dg_routes_in,
memory_order_relaxed); memory_order_relaxed);
queued = atomic_load_explicit(&zdplane_g.dg_routes_queued, queued = atomic_load_explicit(&zdplane_info.dg_routes_queued,
memory_order_relaxed); memory_order_relaxed);
queue_max = atomic_load_explicit(&zdplane_g.dg_routes_queued_max, queue_max = atomic_load_explicit(&zdplane_info.dg_routes_queued_max,
memory_order_relaxed); memory_order_relaxed);
errs = atomic_load_explicit(&zdplane_g.dg_route_errors, errs = atomic_load_explicit(&zdplane_info.dg_route_errors,
memory_order_relaxed); memory_order_relaxed);
vty_out(vty, "Route updates: %"PRIu64"\n", incoming); vty_out(vty, "Route updates: %"PRIu64"\n", incoming);
@ -888,7 +883,7 @@ int dplane_provider_register(const char *name,
dplane_provider_fini_fp fini_fp) dplane_provider_fini_fp fini_fp)
{ {
int ret = 0; int ret = 0;
struct zebra_dplane_provider_s *p, *last; struct zebra_dplane_provider *p, *last;
/* Validate */ /* Validate */
if (fp == NULL) { if (fp == NULL) {
@ -903,7 +898,7 @@ int dplane_provider_register(const char *name,
} }
/* Allocate and init new provider struct */ /* Allocate and init new provider struct */
p = XCALLOC(MTYPE_DP_PROV, sizeof(struct zebra_dplane_provider_s)); p = XCALLOC(MTYPE_DP_PROV, sizeof(struct zebra_dplane_provider));
if (p == NULL) { if (p == NULL) {
ret = ENOMEM; ret = ENOMEM;
goto done; goto done;
@ -919,10 +914,10 @@ int dplane_provider_register(const char *name,
/* Lock the lock - the dplane pthread may be running */ /* Lock the lock - the dplane pthread may be running */
DPLANE_LOCK(); DPLANE_LOCK();
p->dp_id = ++zdplane_g.dg_provider_id; p->dp_id = ++zdplane_info.dg_provider_id;
/* Insert into list ordered by priority */ /* Insert into list ordered by priority */
TAILQ_FOREACH(last, &zdplane_g.dg_providers_q, dp_q_providers) { TAILQ_FOREACH(last, &zdplane_info.dg_providers_q, dp_q_providers) {
if (last->dp_priority > p->dp_priority) if (last->dp_priority > p->dp_priority)
break; break;
} }
@ -930,7 +925,8 @@ int dplane_provider_register(const char *name,
if (last) if (last)
TAILQ_INSERT_BEFORE(last, p, dp_q_providers); TAILQ_INSERT_BEFORE(last, p, dp_q_providers);
else else
TAILQ_INSERT_TAIL(&zdplane_g.dg_providers_q, p, dp_q_providers); TAILQ_INSERT_TAIL(&zdplane_info.dg_providers_q, p,
dp_q_providers);
/* And unlock */ /* And unlock */
DPLANE_UNLOCK(); DPLANE_UNLOCK();
@ -944,7 +940,7 @@ done:
*/ */
int dplane_results_register(dplane_results_fp fp) int dplane_results_register(dplane_results_fp fp)
{ {
zdplane_g.dg_results_cb = fp; zdplane_info.dg_results_cb = fp;
return AOK; return AOK;
} }
@ -953,21 +949,21 @@ int dplane_results_register(dplane_results_fp fp)
*/ */
static void zebra_dplane_init_internal(struct zebra_t *zebra) static void zebra_dplane_init_internal(struct zebra_t *zebra)
{ {
memset(&zdplane_g, 0, sizeof(zdplane_g)); memset(&zdplane_info, 0, sizeof(zdplane_info));
pthread_mutex_init(&zdplane_g.dg_mutex, NULL); pthread_mutex_init(&zdplane_info.dg_mutex, NULL);
TAILQ_INIT(&zdplane_g.dg_route_ctx_q); TAILQ_INIT(&zdplane_info.dg_route_ctx_q);
TAILQ_INIT(&zdplane_g.dg_providers_q); TAILQ_INIT(&zdplane_info.dg_providers_q);
/* TODO -- register default kernel 'provider' during init */ /* TODO -- register default kernel 'provider' during init */
zdplane_g.dg_run = true; zdplane_info.dg_run = true;
/* TODO -- start dataplane pthread. We're using the zebra /* TODO -- start dataplane pthread. We're using the zebra
* core/main thread temporarily * core/main thread temporarily
*/ */
zdplane_g.dg_master = zebra->master; zdplane_info.dg_master = zebra->master;
} }
/* Indicates zebra shutdown/exit is in progress. Some operations may be /* Indicates zebra shutdown/exit is in progress. Some operations may be
@ -975,7 +971,7 @@ static void zebra_dplane_init_internal(struct zebra_t *zebra)
*/ */
bool dplane_is_in_shutdown(void) bool dplane_is_in_shutdown(void)
{ {
return zdplane_g.dg_is_shutdown; return zdplane_info.dg_is_shutdown;
} }
/* /*
@ -990,7 +986,7 @@ void zebra_dplane_pre_finish(void)
if (IS_ZEBRA_DEBUG_DPLANE) if (IS_ZEBRA_DEBUG_DPLANE)
zlog_debug("Zebra dataplane pre-fini called"); zlog_debug("Zebra dataplane pre-fini called");
zdplane_g.dg_is_shutdown = true; zdplane_info.dg_is_shutdown = true;
/* Notify provider(s) of pending shutdown */ /* Notify provider(s) of pending shutdown */
} }
@ -1001,12 +997,12 @@ void zebra_dplane_pre_finish(void)
*/ */
static bool dplane_work_pending(void) static bool dplane_work_pending(void)
{ {
dplane_ctx_h ctx; struct zebra_dplane_ctx *ctx;
/* TODO -- just checking incoming/pending work for now */ /* TODO -- just checking incoming/pending work for now */
DPLANE_LOCK(); DPLANE_LOCK();
{ {
ctx = TAILQ_FIRST(&zdplane_g.dg_route_ctx_q); ctx = TAILQ_FIRST(&zdplane_info.dg_route_ctx_q);
} }
DPLANE_UNLOCK(); DPLANE_UNLOCK();
@ -1027,10 +1023,10 @@ static int dplane_check_shutdown_status(struct thread *event)
if (dplane_work_pending()) { if (dplane_work_pending()) {
/* Reschedule dplane check on a short timer */ /* Reschedule dplane check on a short timer */
thread_add_timer_msec(zdplane_g.dg_master, thread_add_timer_msec(zdplane_info.dg_master,
dplane_check_shutdown_status, dplane_check_shutdown_status,
NULL, 100, NULL, 100,
&zdplane_g.dg_t_shutdown_check); &zdplane_info.dg_t_shutdown_check);
/* TODO - give up and stop waiting after a short time? */ /* TODO - give up and stop waiting after a short time? */
@ -1059,9 +1055,9 @@ void zebra_dplane_finish(void)
if (IS_ZEBRA_DEBUG_DPLANE) if (IS_ZEBRA_DEBUG_DPLANE)
zlog_debug("Zebra dataplane fini called"); zlog_debug("Zebra dataplane fini called");
thread_add_event(zdplane_g.dg_master, thread_add_event(zdplane_info.dg_master,
dplane_check_shutdown_status, NULL, 0, dplane_check_shutdown_status, NULL, 0,
&zdplane_g.dg_t_shutdown_check); &zdplane_info.dg_t_shutdown_check);
} }
/* /*
@ -1075,9 +1071,9 @@ void zebra_dplane_shutdown(void)
/* Stop dplane thread, if it's running */ /* Stop dplane thread, if it's running */
zdplane_g.dg_run = false; zdplane_info.dg_run = false;
THREAD_OFF(zdplane_g.dg_t_update); THREAD_OFF(zdplane_info.dg_t_update);
/* TODO */ /* TODO */
/* frr_pthread_stop(...) */ /* frr_pthread_stop(...) */

View File

@ -105,70 +105,75 @@ enum dplane_op_e {
}; };
/* /*
* Opaque context block used to exchange info between the main zebra * The dataplane context struct is used to exchange info between the main zebra
* context and the dataplane module(s). If these are two independent pthreads, * context and the dataplane module(s). If these are two independent pthreads,
* they cannot share existing global data structures safely. * they cannot share existing global data structures safely.
*/ */
typedef struct zebra_dplane_ctx_s *dplane_ctx_h;
/* Define a tailq list type for context blocks. The list is exposed/public, /* Define a tailq list type for context blocks. The list is exposed/public,
* but the internal linkage in the context struct is private, so there * but the internal linkage in the context struct is private, so there
* are accessor apis that support enqueue and dequeue. * are accessor apis that support enqueue and dequeue.
*/ */
TAILQ_HEAD(dplane_ctx_q_s, zebra_dplane_ctx_s); TAILQ_HEAD(dplane_ctx_q, zebra_dplane_ctx);
/* Return a dataplane results context block after use; the caller's pointer will /* Return a dataplane results context block after use; the caller's pointer will
* be cleared. * be cleared.
*/ */
void dplane_ctx_fini(dplane_ctx_h *pctx); void dplane_ctx_fini(struct zebra_dplane_ctx **pctx);
/* Enqueue a context block to caller's tailq. This just exists so that the /* Enqueue a context block to caller's tailq. This just exists so that the
* context struct can remain opaque. * context struct can remain opaque.
*/ */
void dplane_ctx_enqueue_tail(struct dplane_ctx_q_s *q, dplane_ctx_h ctx); void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q,
const struct zebra_dplane_ctx *ctx);
/* Dequeue a context block from the head of caller's tailq */ /* Dequeue a context block from the head of caller's tailq */
void dplane_ctx_dequeue(struct dplane_ctx_q_s *q, dplane_ctx_h *ctxp); void dplane_ctx_dequeue(struct dplane_ctx_q *q, struct zebra_dplane_ctx **ctxp);
/* /*
* Accessors for information from the context object * Accessors for information from the context object
*/ */
enum zebra_dplane_result dplane_ctx_get_status(const dplane_ctx_h ctx); enum zebra_dplane_result dplane_ctx_get_status(
const struct zebra_dplane_ctx *ctx);
const char *dplane_res2str(enum zebra_dplane_result res); const char *dplane_res2str(enum zebra_dplane_result res);
enum dplane_op_e dplane_ctx_get_op(const dplane_ctx_h ctx); enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx);
const char *dplane_op2str(enum dplane_op_e op); const char *dplane_op2str(enum dplane_op_e op);
const struct prefix *dplane_ctx_get_dest(const dplane_ctx_h ctx); const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx);
/* Source prefix is a little special - use convention to return NULL /* Source prefix is a little special - use convention to return NULL
* to mean "no src prefix" * to mean "no src prefix"
*/ */
const struct prefix *dplane_ctx_get_src(const dplane_ctx_h ctx); const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx);
bool dplane_ctx_is_update(const dplane_ctx_h ctx); bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_get_seq(const dplane_ctx_h ctx); uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_get_old_seq(const dplane_ctx_h ctx); uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx);
vrf_id_t dplane_ctx_get_vrf(const dplane_ctx_h ctx); vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx);
int dplane_ctx_get_type(const dplane_ctx_h ctx); int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx);
int dplane_ctx_get_old_type(const dplane_ctx_h ctx); int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx);
afi_t dplane_ctx_get_afi(const dplane_ctx_h ctx); afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx);
safi_t dplane_ctx_get_safi(const dplane_ctx_h ctx); safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_get_table(const dplane_ctx_h ctx); uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx);
route_tag_t dplane_ctx_get_tag(const dplane_ctx_h ctx); route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx);
route_tag_t dplane_ctx_get_old_tag(const dplane_ctx_h ctx); route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx);
uint16_t dplane_ctx_get_instance(const dplane_ctx_h ctx); uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx);
uint16_t dplane_ctx_get_old_instance(const dplane_ctx_h ctx); uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_get_metric(const dplane_ctx_h ctx); uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_get_old_metric(const dplane_ctx_h ctx); uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_get_mtu(const dplane_ctx_h ctx); uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_get_nh_mtu(const dplane_ctx_h ctx); uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx);
uint8_t dplane_ctx_get_distance(const dplane_ctx_h ctx); uint8_t dplane_ctx_get_distance(const struct zebra_dplane_ctx *ctx);
uint8_t dplane_ctx_get_old_distance(const dplane_ctx_h ctx); uint8_t dplane_ctx_get_old_distance(const struct zebra_dplane_ctx *ctx);
const struct nexthop_group *dplane_ctx_get_ng(const dplane_ctx_h ctx); const struct nexthop_group *dplane_ctx_get_ng(
const struct zebra_dplane_info *dplane_ctx_get_ns(const dplane_ctx_h ctx); const struct zebra_dplane_ctx *ctx);
const struct nexthop_group *dplane_ctx_get_old_ng(const dplane_ctx_h ctx); const struct nexthop_group *dplane_ctx_get_old_ng(
const struct zebra_dplane_ctx *ctx);
const struct zebra_dplane_info *dplane_ctx_get_ns(
const struct zebra_dplane_ctx *ctx);
/* Indicates zebra shutdown/exit is in progress. Some operations may be /* Indicates zebra shutdown/exit is in progress. Some operations may be
* simplified or skipped during shutdown processing. * simplified or skipped during shutdown processing.
@ -217,7 +222,7 @@ enum dplane_provider_prio_e {
}; };
/* Provider's entry-point to process a context block */ /* Provider's entry-point to process a context block */
typedef int (*dplane_provider_process_fp)(dplane_ctx_h ctx); typedef int (*dplane_provider_process_fp)(struct zebra_dplane_ctx *ctx);
/* Provider's entry-point for shutdown and cleanup */ /* Provider's entry-point for shutdown and cleanup */
typedef int (*dplane_provider_fini_fp)(void); typedef int (*dplane_provider_fini_fp)(void);
@ -231,7 +236,7 @@ int dplane_provider_register(const char *name,
/* /*
* Results are returned to zebra core via a callback * Results are returned to zebra core via a callback
*/ */
typedef int (*dplane_results_fp)(const dplane_ctx_h ctx); typedef int (*dplane_results_fp)(const struct zebra_dplane_ctx *ctx);
/* /*
* Zebra registers a results callback with the dataplane. The callback is * Zebra registers a results callback with the dataplane. The callback is

View File

@ -60,7 +60,7 @@
*/ */
static pthread_mutex_t dplane_mutex; static pthread_mutex_t dplane_mutex;
static struct thread *t_dplane; static struct thread *t_dplane;
static struct dplane_ctx_q_s rib_dplane_q; static struct dplane_ctx_q rib_dplane_q;
DEFINE_HOOK(rib_update, (struct route_node * rn, const char *reason), DEFINE_HOOK(rib_update, (struct route_node * rn, const char *reason),
(rn, reason)) (rn, reason))
@ -1818,7 +1818,8 @@ static void rib_process(struct route_node *rn)
* Utility to match route with dplane context data * Utility to match route with dplane context data
*/ */
static bool rib_route_match_ctx(const struct route_entry *re, static bool rib_route_match_ctx(const struct route_entry *re,
const dplane_ctx_h ctx, bool is_update) const struct zebra_dplane_ctx *ctx,
bool is_update)
{ {
bool result = false; bool result = false;
@ -1875,7 +1876,7 @@ done:
* TODO - WIP version of route-update processing after async dataplane * TODO - WIP version of route-update processing after async dataplane
* update. * update.
*/ */
static void rib_process_after(dplane_ctx_h ctx) static void rib_process_after(struct zebra_dplane_ctx *ctx)
{ {
struct route_table *table = NULL; struct route_table *table = NULL;
struct zebra_vrf *zvrf = NULL; struct zebra_vrf *zvrf = NULL;
@ -3240,7 +3241,7 @@ void rib_close_table(struct route_table *table)
*/ */
static int rib_process_dplane_results(struct thread *thread) static int rib_process_dplane_results(struct thread *thread)
{ {
dplane_ctx_h ctx; struct zebra_dplane_ctx *ctx;
do { do {
/* Take lock controlling queue of results */ /* Take lock controlling queue of results */
@ -3269,7 +3270,7 @@ static int rib_process_dplane_results(struct thread *thread)
* the dataplane pthread. We enqueue the results here for processing by * the dataplane pthread. We enqueue the results here for processing by
* the main thread later. * the main thread later.
*/ */
static int rib_dplane_results(dplane_ctx_h ctx) static int rib_dplane_results(const struct zebra_dplane_ctx *ctx)
{ {
/* Take lock controlling queue of results */ /* Take lock controlling queue of results */
pthread_mutex_lock(&dplane_mutex); pthread_mutex_lock(&dplane_mutex);