From e28492ae84632d4f6be44e3219a3615df7821f17 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Mon, 16 Dec 2019 15:42:37 -0500 Subject: [PATCH] lib: default nexthop weights to one Default all nexthop weights to one. The linux kernel does some weird stuff where it adds one to all nexthop weight values it gets. So, we added df7fb5800b3798057747873c8be245eb13f3ec36 with some special subtracing/adding to account for this. Though, that patch did not account for the default case of the weight being zero for elements in the group. Hence, this patch defaults the nexthop weight to one during creation. This should be a valid value on all platforms anyway so shouldn't affect anything. Signed-off-by: Stephen Worley --- lib/nexthop.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/nexthop.c b/lib/nexthop.c index 718cda7355..d2ab70e209 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -230,7 +230,23 @@ bool nexthop_labels_match(const struct nexthop *nh1, const struct nexthop *nh2) struct nexthop *nexthop_new(void) { - return XCALLOC(MTYPE_NEXTHOP, sizeof(struct nexthop)); + struct nexthop *nh; + + nh = XCALLOC(MTYPE_NEXTHOP, sizeof(struct nexthop)); + + /* + * Default the weight to 1 here for all nexthops. + * The linux kernel does some weird stuff with adding +1 to + * all nexthop weights it gets over netlink. + * To handle this, just default everything to 1 right from + * from the beggining so we don't have to special case + * default weights in the linux netlink code. + * + * 1 should be a valid on all platforms anyway. + */ + nh->weight = 1; + + return nh; } /* Free nexthop. */ -- 2.39.5