lib, zebra: Add ability to send down a nhgid over route install

Modify the send down of a route to use the nexthop group id
if we have one associated with the route.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2020-05-01 17:56:23 -04:00 committed by Stephen Worley
parent 2f35a820bf
commit 27141ea94e
3 changed files with 26 additions and 5 deletions

View File

@ -1103,6 +1103,9 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
stream_write(s, (uint8_t *)&api->src_prefix.prefix, psize);
}
if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NHG))
stream_putl(s, api->nhgid);
/* Nexthops. */
if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) {
/* limit the number of nexthops if necessary */
@ -1373,6 +1376,9 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
}
}
if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NHG))
STREAM_GETL(s, api->nhgid);
/* Nexthops. */
if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) {
STREAM_GETW(s, api->nexthop_num);

View File

@ -374,6 +374,7 @@ struct zclient {
#define ZAPI_MESSAGE_SRCPFX 0x20
/* Backup nexthops are present */
#define ZAPI_MESSAGE_BACKUP_NEXTHOPS 0x40
#define ZAPI_MESSAGE_NHG 0x80
/*
* This should only be used by a DAEMON that needs to communicate
@ -518,6 +519,8 @@ struct zapi_route {
uint16_t backup_nexthop_num;
struct zapi_nexthop backup_nexthops[MULTIPATH_NUM];
uint32_t nhgid;
uint8_t distance;
uint32_t metric;

View File

@ -1806,6 +1806,16 @@ stream_failure:
return;
}
static bool zapi_msg_get_nhg(struct zapi_route *api, struct nexthop_group **ng)
{
if (!CHECK_FLAG(api->message, ZAPI_MESSAGE_NHG))
return false;
/* TODO lookup the ng from api->nhgid */
*ng = NULL;
return true;
}
static void zread_route_add(ZAPI_HANDLER_ARGS)
{
struct stream *s;
@ -1851,8 +1861,9 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
else
re->table = zvrf->table_id;
if (!CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)
|| api.nexthop_num == 0) {
if (!CHECK_FLAG(api.message, ZAPI_MESSAGE_NHG)
&& (!CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)
|| api.nexthop_num == 0)) {
flog_warn(EC_ZEBRA_RX_ROUTE_NO_NEXTHOPS,
"%s: received a route without nexthops for prefix %pFX from client %s",
__func__, &api.prefix,
@ -1871,9 +1882,10 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
zebra_route_string(client->proto), &api.prefix);
}
if (!zapi_read_nexthops(client, &api.prefix, api.nexthops, api.flags,
api.message, api.nexthop_num,
api.backup_nexthop_num, &ng, NULL)
if (zapi_msg_get_nhg(&api, &ng)
|| !zapi_read_nexthops(client, &api.prefix, api.nexthops, api.flags,
api.message, api.nexthop_num,
api.backup_nexthop_num, &ng, NULL)
|| !zapi_read_nexthops(client, &api.prefix, api.backup_nexthops,
api.flags, api.message,
api.backup_nexthop_num,