From dfc5667603ec4bb5c781cfcfe4b4283035bab099 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 14 May 2021 12:52:41 +0200 Subject: [PATCH] libnm: reject setting ethtool.pause-autoneg while setting pause-rx/pause-tx Setting pause-rx/pause-tx to an explicit value, implies that the user does not want to enable autoneg. Reject that as invalid value in the connection profile. --- src/libnm-core-impl/nm-setting-ethtool.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libnm-core-impl/nm-setting-ethtool.c b/src/libnm-core-impl/nm-setting-ethtool.c index 2329f228a6..abedcae3eb 100644 --- a/src/libnm-core-impl/nm-setting-ethtool.c +++ b/src/libnm-core-impl/nm-setting-ethtool.c @@ -9,6 +9,7 @@ #include "nm-setting-private.h" #include "libnm-base/nm-ethtool-base.h" +#include "libnm-base/nm-ethtool-utils-base.h" /*****************************************************************************/ @@ -288,6 +289,9 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) GVariant *const * variants; guint len; guint i; + NMTernary pause_autoneg = NM_TERNARY_DEFAULT; + NMTernary pause_tx = NM_TERNARY_DEFAULT; + NMTernary pause_rx = NM_TERNARY_DEFAULT; len = _nm_setting_option_get_all(setting, &optnames, &variants); @@ -329,6 +333,25 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) g_prefix_error(error, "%s.%s: ", NM_SETTING_ETHTOOL_SETTING_NAME, optname); return FALSE; } + } else if (NM_IN_SET(ethtool_id, NM_ETHTOOL_ID_PAUSE_AUTONEG)) + pause_autoneg = g_variant_get_boolean(variant); + else if (NM_IN_SET(ethtool_id, NM_ETHTOOL_ID_PAUSE_RX)) + pause_rx = g_variant_get_boolean(variant); + else if (NM_IN_SET(ethtool_id, NM_ETHTOOL_ID_PAUSE_TX)) + pause_tx = g_variant_get_boolean(variant); + } + + if (pause_rx != NM_TERNARY_DEFAULT || pause_tx != NM_TERNARY_DEFAULT) { + if (pause_autoneg == NM_TERNARY_TRUE) { + g_set_error_literal(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("pause-autoneg cannot be enabled when setting rx/tx options")); + g_prefix_error(error, + "%s.%s: ", + NM_SETTING_ETHTOOL_SETTING_NAME, + NM_ETHTOOL_OPTNAME_PAUSE_AUTONEG); + return FALSE; } }