From 2c3f967d1a6362fe5aba296eaf01aa3a9e278ab5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 16 Sep 2021 16:50:15 +0200 Subject: [PATCH] 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). --- src/nm-initrd-generator/nmi-cmdline-reader.c | 25 ++++++++++--------- .../tests/test-cmdline-reader.c | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/nm-initrd-generator/nmi-cmdline-reader.c b/src/nm-initrd-generator/nmi-cmdline-reader.c index 9606b45427..3f4e304345 100644 --- a/src/nm-initrd-generator/nmi-cmdline-reader.c +++ b/src/nm-initrd-generator/nmi-cmdline-reader.c @@ -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, diff --git a/src/nm-initrd-generator/tests/test-cmdline-reader.c b/src/nm-initrd-generator/tests/test-cmdline-reader.c index c20f8c29bd..f13f625b1f 100644 --- a/src/nm-initrd-generator/tests/test-cmdline-reader.c +++ b/src/nm-initrd-generator/tests/test-cmdline-reader.c @@ -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); } /*****************************************************************************/