networkctl: use uint64_t for link speed throughout

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
This commit is contained in:
наб 2020-05-07 21:34:39 +02:00 committed by Zbigniew Jędrzejewski-Szmek
parent a114ab6373
commit 2f665f2437
2 changed files with 2 additions and 2 deletions

View File

@ -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)

View File

@ -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);