From 1d3e071fd8311aaea2f6c096ae117f39aff795ed Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 15 Apr 2020 15:16:11 +0200 Subject: [PATCH] zebra: fix speed set to UINT32_MAX get_iflink_speed() returns UINT32_MAX when the speeds is unknown. Routing daemons (at least ospfd) interprets it as the high value. Return errors in get_iflink_speed() to avoid the confusion. Signed-off-by: Philippe Guibert Signed-off-by: Louis Scalbert --- zebra/if_netlink.c | 13 ++++++++++--- zebra/interface.c | 6 +++--- zebra/interface.h | 3 +++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 551ef6533ed5..5f096e3039b1 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -261,6 +261,7 @@ static uint32_t get_iflink_speed(struct interface *interface, int *error) int sd; int rc; const char *ifname = interface->name; + uint32_t ret; if (error) *error = 0; @@ -285,7 +286,7 @@ static uint32_t get_iflink_speed(struct interface *interface, int *error) ifname, errno, safe_strerror(errno)); /* no vrf socket creation may probably mean vrf issue */ if (error) - *error = -1; + *error = INTERFACE_SPEED_ERROR_READ; return 0; } /* Get the current link state for the interface */ @@ -299,14 +300,20 @@ static uint32_t get_iflink_speed(struct interface *interface, int *error) ifname, errno, safe_strerror(errno)); /* no device means interface unreachable */ if (errno == ENODEV && error) - *error = -1; + *error = INTERFACE_SPEED_ERROR_READ; ecmd.speed_hi = 0; ecmd.speed = 0; } close(sd); - return ((uint32_t)ecmd.speed_hi << 16) | ecmd.speed; + ret = ((uint32_t)ecmd.speed_hi << 16) | ecmd.speed; + if (ret == UINT32_MAX) { + if (error) + *error = INTERFACE_SPEED_ERROR_UNKNOWN; + ret = 0; + } + return ret; } uint32_t kernel_get_speed(struct interface *ifp, int *error) diff --git a/zebra/interface.c b/zebra/interface.c index f864b9182253..4cb85152beb6 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -65,7 +65,7 @@ static void if_zebra_speed_update(struct event *thread) * interfaces not available. * note that loopback & virtual interfaces can return 0 as speed */ - if (error < 0) + if (error == INTERFACE_SPEED_ERROR_READ) return; if (new_speed != ifp->speed) { @@ -76,7 +76,7 @@ static void if_zebra_speed_update(struct event *thread) changed = true; } - if (changed || new_speed == UINT32_MAX) { + if (changed || error == INTERFACE_SPEED_ERROR_UNKNOWN) { #define SPEED_UPDATE_SLEEP_TIME 5 #define SPEED_UPDATE_COUNT_MAX (4 * 60 / SPEED_UPDATE_SLEEP_TIME) /* @@ -91,7 +91,7 @@ static void if_zebra_speed_update(struct event *thread) * to not update the system to keep track of that. This * is far simpler to just stop trying after 4 minutes */ - if (new_speed == UINT32_MAX && + if (error == INTERFACE_SPEED_ERROR_UNKNOWN && zif->speed_update_count == SPEED_UPDATE_COUNT_MAX) return; diff --git a/zebra/interface.h b/zebra/interface.h index a96f2ec7188d..15622652ccd3 100644 --- a/zebra/interface.h +++ b/zebra/interface.h @@ -201,6 +201,9 @@ struct zebra_if { ifindex_t link_ifindex; struct interface *link; +#define INTERFACE_SPEED_ERROR_READ -1 +#define INTERFACE_SPEED_ERROR_UNKNOWN -2 + uint8_t speed_update_count; struct event *speed_update;