Skip to content

Commit

Permalink
Merge pull request #14964 from pguibert6WIND/nhg_del_in_queue
Browse files Browse the repository at this point in the history
zebra: enqueue NHG_DEL in rib_nhg meta queue
  • Loading branch information
donaldsharp authored Dec 8, 2023
2 parents c659e1c + 4d60d9e commit 4a2ece9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 23 deletions.
1 change: 1 addition & 0 deletions zebra/rib.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ extern int rib_queue_nhg_ctx_add(struct nhg_ctx *ctx);

/* Enqueue incoming nhg from proto daemon for processing */
extern int rib_queue_nhe_add(struct nhg_hash_entry *nhe);
extern int rib_queue_nhe_del(struct nhg_hash_entry *nhe);

/* Enqueue evpn route for processing */
int zebra_rib_queue_evpn_route_add(vrf_id_t vrf_id, const struct ethaddr *rmac,
Expand Down
25 changes: 12 additions & 13 deletions zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1959,20 +1959,19 @@ static void zread_nhg_del(ZAPI_HANDLER_ARGS)
return;
}

/*
* Delete the received nhg id
*/
nhe = zebra_nhg_proto_del(api_nhg.id, api_nhg.proto);
/* Create a temporary nhe */
nhe = zebra_nhg_alloc();
nhe->id = api_nhg.id;
nhe->type = api_nhg.proto;
nhe->zapi_instance = client->instance;
nhe->zapi_session = client->session_id;

/* Sanity check - Empty nexthop and group */
nhe->nhg.nexthop = NULL;

/* Enqueue to workqueue for processing */
rib_queue_nhe_del(nhe);

if (nhe) {
zebra_nhg_decrement_ref(nhe);
zsend_nhg_notify(api_nhg.proto, client->instance,
client->session_id, api_nhg.id,
ZAPI_NHG_REMOVED);
} else
zsend_nhg_notify(api_nhg.proto, client->instance,
client->session_id, api_nhg.id,
ZAPI_NHG_REMOVE_FAIL);
/* Stats */
client->nhg_del_cnt++;
}
Expand Down
62 changes: 52 additions & 10 deletions zebra/zebra_rib.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ struct wq_nhg_wrapper {
struct nhg_ctx *ctx;
struct nhg_hash_entry *nhe;
} u;
bool deletion;
};

#define WQ_NHG_WRAPPER_TYPE_CTX 0x01
Expand Down Expand Up @@ -2531,7 +2532,7 @@ static void process_subq_evpn(struct listnode *lnode)
static void process_subq_nhg(struct listnode *lnode)
{
struct nhg_ctx *ctx;
struct nhg_hash_entry *nhe, *newnhe;
struct nhg_hash_entry *nhe, *newnhe, *oldnhe;
struct wq_nhg_wrapper *w;
uint8_t qindex = META_QUEUE_NHG;

Expand Down Expand Up @@ -2563,15 +2564,33 @@ static void process_subq_nhg(struct listnode *lnode)
subqueue2str(qindex));

/* Process incoming nhg update, probably from a proto daemon */
newnhe = zebra_nhg_proto_add(nhe->id, nhe->type,
nhe->zapi_instance,
nhe->zapi_session, &nhe->nhg, 0);
if (w->deletion) {
/*
* Delete the received nhg id
*/
oldnhe = zebra_nhg_proto_del(nhe->id, nhe->type);
if (oldnhe) {
zsend_nhg_notify(nhe->type, nhe->zapi_instance,
nhe->zapi_session, nhe->id,
ZAPI_NHG_REMOVED);
zebra_nhg_decrement_ref(oldnhe);
} else
zsend_nhg_notify(nhe->type, nhe->zapi_instance,
nhe->zapi_session, nhe->id,
ZAPI_NHG_REMOVE_FAIL);

/* Report error to daemon via ZAPI */
if (newnhe == NULL)
zsend_nhg_notify(nhe->type, nhe->zapi_instance,
nhe->zapi_session, nhe->id,
ZAPI_NHG_FAIL_INSTALL);
} else {
newnhe = zebra_nhg_proto_add(nhe->id, nhe->type,
nhe->zapi_instance,
nhe->zapi_session,
&nhe->nhg, 0);

/* Report error to daemon via ZAPI */
if (newnhe == NULL)
zsend_nhg_notify(nhe->type, nhe->zapi_instance,
nhe->zapi_session, nhe->id,
ZAPI_NHG_FAIL_INSTALL);
}

/* Free temp nhe - we own that memory. */
zebra_nhg_free(nhe);
Expand Down Expand Up @@ -3339,7 +3358,8 @@ static int rib_meta_queue_nhg_ctx_add(struct meta_queue *mq, void *data)
return 0;
}

static int rib_meta_queue_nhg_add(struct meta_queue *mq, void *data)
static int rib_meta_queue_nhg_process(struct meta_queue *mq, void *data,
bool deletion)
{
struct nhg_hash_entry *nhe = NULL;
uint8_t qindex = META_QUEUE_NHG;
Expand All @@ -3354,6 +3374,7 @@ static int rib_meta_queue_nhg_add(struct meta_queue *mq, void *data)

w->type = WQ_NHG_WRAPPER_TYPE_NHG;
w->u.nhe = nhe;
w->deletion = deletion;

listnode_add(mq->subq[qindex], w);
mq->size++;
Expand All @@ -3365,6 +3386,16 @@ static int rib_meta_queue_nhg_add(struct meta_queue *mq, void *data)
return 0;
}

static int rib_meta_queue_nhg_add(struct meta_queue *mq, void *data)
{
return rib_meta_queue_nhg_process(mq, data, false);
}

static int rib_meta_queue_nhg_del(struct meta_queue *mq, void *data)
{
return rib_meta_queue_nhg_process(mq, data, true);
}

static int rib_meta_queue_evpn_add(struct meta_queue *mq, void *data)
{
listnode_add(mq->subq[META_QUEUE_EVPN], data);
Expand Down Expand Up @@ -3472,6 +3503,17 @@ int rib_queue_nhe_add(struct nhg_hash_entry *nhe)
return mq_add_handler(nhe, rib_meta_queue_nhg_add);
}

/*
* Enqueue incoming nhg from proto daemon for processing
*/
int rib_queue_nhe_del(struct nhg_hash_entry *nhe)
{
if (nhe == NULL)
return -1;

return mq_add_handler(nhe, rib_meta_queue_nhg_del);
}

/*
* Enqueue evpn route for processing
*/
Expand Down

0 comments on commit 4a2ece9

Please sign in to comment.