From 2f665f24376c6fb0cceef69e50610e45132808bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 7 May 2020 21:34:39 +0200 Subject: [PATCH] networkctl: use uint64_t for link speed throughout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit format-table used size_t/uint64_t interchangeably for TABLE_BPS, and ethtool-util used SIZE_MAX to indicate SPEED_UNKNOWN, which worked only on ABIs with 64-bit pointers. For example, the tg3 driver returns SPEED_UNKNOWN with no link (cf. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/broadcom/tg3.c?id=3eb2efbea193789397c36f52b17d8692ac79bf68#n12190) which on x32 (and other 32-bit ABIs, presumably) caused "networkctl status" to mark it with "Speed: 4Gbps": nabijaczleweli@szarotka:~$ networkctl --version systemd 245 (245.5-2) nabijaczleweli@szarotka:~$ file $(which networkctl) /bin/networkctl: ELF 32-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /libx32/ld-linux-x32.so.2, BuildID[sha1]=36d684cb1fc8fb5060050d32b969e5aa172fa607, for GNU/Linux 3.4.0, stripped nabijaczleweli@szarotka:~$ networkctl status onboard1 ● 4: onboard1 Driver: tg3 Model: NetXtreme BCM5755 Gigabit Ethernet PCI Express Speed: 4Gbps Whereas on 64-bit-pointer ABIs (here: amd64): nabijaczleweli@szarotka:~$ networkctl --version systemd 245 (245.5-2) nabijaczleweli@szarotka:~$ file $(which networkctl) /bin/networkctl: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=7a3e406e54968d7774ad467fc3f6a9d35ff7aea2, for GNU/Linux 3.2.0, stripped nabijaczleweli@szarotka:~$ networkctl status onboard1 ● 4: onboard1 Driver: tg3 Model: NetXtreme BCM5755 Gigabit Ethernet PCI Express Speed: n/a With this patch, networkctl returns, for x32: nabijaczleweli@szarotka:~$ networkctl --version systemd 245 (245.5-2.1~networkctl-4g-v2) nabijaczleweli@szarotka:~$ file $(which networkctl) /bin/networkctl: ELF 32-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /libx32/ld-linux-x32.so.2, BuildID[sha1]=36d684cb1fc8fb5060050d32b969e5aa172fa607, for GNU/Linux 3.4.0, stripped nabijaczleweli@szarotka:~$ networkctl status onboard1 ● 4: onboard1 Driver: tg3 Model: NetXtreme BCM5755 Gigabit Ethernet PCI Express Speed: n/a And for amd64: nabijaczleweli@szarotka:~$ file $(which networkctl) /bin/networkctl: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=7a3e406e54968d7774ad467fc3f6a9d35ff7aea2, for GNU/Linux 3.2.0, stripped nabijaczleweli@szarotka:~$ networkctl status onboard1 ● 4: onboard1 Driver: tg3 Model: NetXtreme BCM5755 Gigabit Ethernet PCI Express Speed: n/a --- src/shared/ethtool-util.c | 2 +- src/shared/format-table.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index 0cde87f5ac..57bffe00be 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -209,7 +209,7 @@ int ethtool_get_link_info(int *ethtool_fd, const char *ifname, speed = ethtool_cmd_speed(&ecmd); *ret_speed = speed == (uint32_t) SPEED_UNKNOWN ? - SIZE_MAX : (size_t) speed * 1000 * 1000; + UINT64_MAX : (uint64_t) speed * 1000 * 1000; } if (ret_duplex) diff --git a/src/shared/format-table.c b/src/shared/format-table.c index f12ad2d038..87ef5c3f00 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -2269,7 +2269,7 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) { case TABLE_SIZE: case TABLE_BPS: - if (d->size == (size_t) -1) + if (d->size == (uint64_t) -1) return json_variant_new_null(ret); return json_variant_new_unsigned(ret, d->size);