]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ethtool-util: disable autonegotiation when speed, duplex, or port is specified
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 20 May 2021 21:03:14 +0000 (06:03 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 23 May 2021 02:40:15 +0000 (11:40 +0900)
And if autonegotiation is enabled, speed, duplex, and port are ignored.

Fixes #19625.

src/shared/ethtool-util.c

index 11e6992981301ddcb5ad341d189d7f724810b03c..81d8e56544d16843a95a9ee69c12075de079d3de 100644 (file)
@@ -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);