Merge pull request #5241 from sworleys/SA-NHG

One More Zebra NHG SA Fix and nhg_ctx API Adjustment
This commit is contained in:
Russ White 2019-11-19 11:44:15 -05:00 committed by GitHub
commit 943de56af6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -589,20 +589,6 @@ zebra_nhg_find_nexthop(uint32_t id, struct nexthop *nh, afi_t afi, int type)
return nhe;
}
static struct nhg_ctx *nhg_ctx_new()
{
struct nhg_ctx *new = NULL;
new = XCALLOC(MTYPE_NHG_CTX, sizeof(struct nhg_ctx));
return new;
}
static void nhg_ctx_free(struct nhg_ctx *ctx)
{
XFREE(MTYPE_NHG_CTX, ctx);
}
static uint32_t nhg_ctx_get_id(const struct nhg_ctx *ctx)
{
return ctx->id;
@ -658,6 +644,36 @@ static struct nh_grp *nhg_ctx_get_grp(struct nhg_ctx *ctx)
return ctx->u.grp;
}
static struct nhg_ctx *nhg_ctx_new()
{
struct nhg_ctx *new = NULL;
new = XCALLOC(MTYPE_NHG_CTX, sizeof(struct nhg_ctx));
return new;
}
static void nhg_ctx_free(struct nhg_ctx **ctx)
{
struct nexthop *nh;
if (ctx == NULL)
return;
assert((*ctx) != NULL);
if (nhg_ctx_get_count(*ctx))
goto done;
nh = nhg_ctx_get_nh(*ctx);
nexthop_del_labels(nh);
done:
XFREE(MTYPE_NHG_CTX, *ctx);
*ctx = NULL;
}
static struct nhg_ctx *nhg_ctx_init(uint32_t id, struct nexthop *nh,
struct nh_grp *grp, vrf_id_t vrf_id,
afi_t afi, int type, uint8_t count)
@ -906,23 +922,13 @@ static int nhg_ctx_process_del(struct nhg_ctx *ctx)
return 0;
}
static void nhg_ctx_process_finish(struct nhg_ctx *ctx)
static void nhg_ctx_fini(struct nhg_ctx **ctx)
{
struct nexthop *nh;
/*
* Just freeing for now, maybe do something more in the future
* based on flag.
*/
if (nhg_ctx_get_count(ctx))
goto done;
nh = nhg_ctx_get_nh(ctx);
nexthop_del_labels(nh);
done:
nhg_ctx_free(ctx);
}
@ -978,7 +984,7 @@ int nhg_ctx_process(struct nhg_ctx *ctx)
nhg_ctx_set_status(ctx, (ret ? NHG_CTX_FAILURE : NHG_CTX_SUCCESS));
nhg_ctx_process_finish(ctx);
nhg_ctx_fini(&ctx);
return ret;
}
@ -1007,7 +1013,7 @@ int zebra_nhg_kernel_find(uint32_t id, struct nexthop *nh, struct nh_grp *grp,
return nhg_ctx_process(ctx);
if (queue_add(ctx)) {
nhg_ctx_process_finish(ctx);
nhg_ctx_fini(&ctx);
return -1;
}
@ -1024,7 +1030,7 @@ int zebra_nhg_kernel_del(uint32_t id)
nhg_ctx_set_op(ctx, NHG_CTX_OP_DEL);
if (queue_add(ctx)) {
nhg_ctx_process_finish(ctx);
nhg_ctx_fini(&ctx);
return -1;
}
@ -1037,6 +1043,9 @@ static struct nhg_hash_entry *depends_find(struct nexthop *nh, afi_t afi)
struct nexthop *lookup = NULL;
struct nhg_hash_entry *nhe = NULL;
if (!nh)
goto done;
copy_nexthops(&lookup, nh, NULL);
/* Clear it, in case its a group */
@ -1049,6 +1058,7 @@ static struct nhg_hash_entry *depends_find(struct nexthop *nh, afi_t afi)
nexthops_free(lookup);
done:
return nhe;
}