diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 86e4f2570cbe..c365d44e59a0 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1857,6 +1857,8 @@ static int zapi_nhg_decode(struct stream *s, int cmd, struct zapi_nhg *api_nhg) { uint16_t i; struct zapi_nexthop *znh; + bool same_weight = true; + uint64_t max_weight = 0; STREAM_GETW(s, api_nhg->proto); STREAM_GETL(s, api_nhg->id); @@ -1888,8 +1890,29 @@ static int zapi_nhg_decode(struct stream *s, int cmd, struct zapi_nhg *api_nhg) "%s: Nexthop creation failed", __func__); return -1; } + + if (max_weight < znh->weight) { + if (i != 0) + same_weight = false; + + max_weight = znh->weight; + } + } + + if (!same_weight) { + for (i = 0; i < api_nhg->nexthop_num; i++) { + uint64_t tmp; + + znh = &((api_nhg->nexthops)[i]); + + tmp = (uint64_t)znh->weight * 255; + znh->weight = MAX(1, ((uint32_t)(tmp/max_weight))); + } } + same_weight = true; + max_weight = 0; + /* Backup Nexthops */ STREAM_GETW(s, api_nhg->backup_nexthop_num); @@ -1905,8 +1928,27 @@ static int zapi_nhg_decode(struct stream *s, int cmd, struct zapi_nhg *api_nhg) __func__); return -1; } + + if (max_weight < znh->weight) { + if (i != 0) + same_weight = false; + + max_weight = znh->weight; + } + } + if (!same_weight) { + for (i = 0; i < api_nhg->nexthop_num; i++) { + uint64_t tmp; + + znh = &((api_nhg->backup_nexthops)[i]); + + tmp = (uint64_t)znh->weight * 255; + znh->weight = MAX(1, ((uint32_t)(tmp/max_weight))); + } + } + done: return 0;