From 5a9c0931aa9571b875db8658ced6f1dc6f10a2b1 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Wed, 20 Jan 2021 16:00:45 -0500 Subject: [PATCH] sharpd: don't send invalid nexthop-groups to zebra Ensure that there are valid (resolved) nexthops, and no invalid backup nexthops, in nhgs sent to zebra for installation. Signed-off-by: Mark Stapp --- sharpd/sharp_zebra.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 4445bc0132..fed732b843 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -539,6 +539,7 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg, struct zapi_nhg api_nhg = {}; struct zapi_nexthop *api_nh; struct nexthop *nh; + bool is_valid = true; api_nhg.id = id; for (ALL_NEXTHOPS_PTR(nhg, nh)) { @@ -549,12 +550,25 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg, break; } + /* Unresolved nexthops will lead to failure - only send + * nexthops that zebra will consider valid. + */ + if (nh->ifindex == 0) + continue; + api_nh = &api_nhg.nexthops[api_nhg.nexthop_num]; zapi_nexthop_from_nexthop(api_nh, nh); api_nhg.nexthop_num++; } + if (api_nhg.nexthop_num == 0) { + zlog_debug("%s: nhg %u not sent: no valid nexthops", + __func__, id); + is_valid = false; + goto done; + } + if (backup_nhg) { for (ALL_NEXTHOPS_PTR(backup_nhg, nh)) { if (api_nhg.backup_nexthop_num >= MULTIPATH_NUM) { @@ -563,6 +577,20 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg, __func__); break; } + + /* Unresolved nexthop: will be rejected by zebra. + * That causes a problem, since the primary nexthops + * rely on array indexing into the backup nexthops. If + * that array isn't valid, the backup indexes won't be + * valid. + */ + if (nh->ifindex == 0) { + zlog_debug("%s: nhg %u: invalid backup nexthop", + __func__, id); + is_valid = false; + break; + } + api_nh = &api_nhg.backup_nexthops [api_nhg.backup_nexthop_num]; @@ -571,7 +599,9 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg, } } - zclient_nhg_send(zclient, ZEBRA_NHG_ADD, &api_nhg); +done: + if (is_valid) + zclient_nhg_send(zclient, ZEBRA_NHG_ADD, &api_nhg); } void nhg_del(uint32_t id)