From: Yu Watanabe Date: Thu, 20 May 2021 21:03:14 +0000 (+0900) Subject: ethtool-util: disable autonegotiation when speed, duplex, or port is specified X-Git-Tag: v249-rc1~169^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c8e644b116ef1fe10aec8827d12643a6effaca6a;p=thirdparty%2Fsystemd.git ethtool-util: disable autonegotiation when speed, duplex, or port is specified And if autonegotiation is enabled, speed, duplex, and port are ignored. Fixes #19625. --- diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index 11e69929813..81d8e56544d 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -828,9 +828,16 @@ int ethtool_set_glinksettings( * the speed is 0, %SPEED_UNKNOWN or the highest enabled speed and @duplex is %DUPLEX_UNKNOWN * or the best enabled duplex mode. */ - if (autonegotiation != AUTONEG_DISABLE && memeqzero(advertise, sizeof(uint32_t) * N_ADVERTISE)) { - log_debug("ethtool: autonegotiation is unset or enabled, the speed and duplex are not writable."); - return 0; + if (speed > 0 || duplex >= 0 || port >= 0) { + if (autonegotiation == AUTONEG_ENABLE || !memeqzero(advertise, sizeof(uint32_t) * N_ADVERTISE)) { + log_debug("ethtool: autonegotiation is enabled, ignoring speed, duplex, or port settings."); + speed = 0; + duplex = _DUP_INVALID; + port = _NET_DEV_PORT_INVALID; + } else { + log_debug("ethtool: setting speed, duplex, or port, disabling autonegotiation."); + autonegotiation = AUTONEG_DISABLE; + } } r = ethtool_connect(fd);