initrd: only reset autoneg/speed if specified

The idea of positional arguments is that they might be extended in the
future. That means, there might be an option "rd.ethtool:eth0:::foo".

Also, if multiple "rd.ethtool:eth0" options are specified on the command
line, then the autoneg/speed settings should only be set if present.
That means

  "rd.ethtool:eth0:on:100 rd.ethtool:eth0:::foo"

should work as expected and first set autoneg/speed options, but the
second argument only sets "foo" (without resetting autoneg/speed).
This commit is contained in:
Thomas Haller 2021-09-16 16:50:15 +02:00
parent b7b275dead
commit 2c3f967d1a
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 14 additions and 13 deletions

View file

@ -1210,20 +1210,21 @@ reader_parse_ethtool(Reader *reader, char *argument)
"rd.ethtool: autoneg ignored. Cannot disable autoneg without setting speed");
}
if (autoneg == -1)
autoneg = FALSE;
connection = reader_get_connection(reader, interface, NM_SETTING_WIRED_SETTING_NAME, TRUE);
s_wired = nm_connection_get_setting_wired(connection);
g_object_set(s_wired,
NM_SETTING_WIRED_AUTO_NEGOTIATE,
(gboolean) autoneg,
NM_SETTING_WIRED_SPEED,
speed,
NM_SETTING_WIRED_DUPLEX,
speed == 0 ? NULL : "full",
NULL);
if (autoneg != -1 || speed != 0) {
if (autoneg == -1)
autoneg = FALSE;
s_wired = nm_connection_get_setting_wired(connection);
g_object_set(s_wired,
NM_SETTING_WIRED_AUTO_NEGOTIATE,
(gboolean) autoneg,
NM_SETTING_WIRED_SPEED,
speed,
NM_SETTING_WIRED_DUPLEX,
speed == 0 ? NULL : "full",
NULL);
}
if (*argument)
_LOGW(LOGD_CORE,

View file

@ -2423,7 +2423,7 @@ test_rd_ethtool(void)
NMTST_EXPECT_NM_WARN("cmdline-reader: rd.ethtool: autoneg ignored. Cannot disable autoneg "
"without setting speed");
_ethtool_check_v(NM_MAKE_STRV("rd.ethtool=eth0:on:100", "rd.ethtool=eth0:off"), FALSE, 0);
_ethtool_check_v(NM_MAKE_STRV("rd.ethtool=eth0:off:100", "rd.ethtool=eth0:"), FALSE, 0);
_ethtool_check_v(NM_MAKE_STRV("rd.ethtool=eth0:off:100", "rd.ethtool=eth0:"), FALSE, 100);
}
/*****************************************************************************/