ifcfg-rh: avoid setting empty "-C/-K/-G" options for ethtool settings

If no options are set, we should not generate -C/-K/-G options
without parameter.
This commit is contained in:
Thomas Haller
2020-05-20 16:46:25 +02:00
parent c48bfdf584
commit adcb935089
2 changed files with 43 additions and 35 deletions

View File

@@ -1079,6 +1079,27 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
return TRUE; return TRUE;
} }
static void
_ethtool_gstring_prepare (GString **str,
gboolean *is_first,
char cmdline_flag,
const char *iface)
{
if (!*is_first) {
nm_assert (*str && (*str)->len > 0);
return;
}
if (!*str)
*str = g_string_sized_new (30);
else {
nm_assert ((*str)->len > 0);
g_string_append (*str, " ; ");
}
g_string_append_printf (*str, "-%c %s", cmdline_flag, iface);
*is_first = FALSE;
}
static gboolean static gboolean
write_ethtool_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) write_ethtool_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
{ {
@@ -1160,7 +1181,10 @@ write_ethtool_setting (NMConnection *connection, shvarFile *ifcfg, GError **erro
if (s_ethtool) { if (s_ethtool) {
NMEthtoolID ethtool_id; NMEthtoolID ethtool_id;
NMSettingConnection *s_con; NMSettingConnection *s_con;
const char *iface = NULL; const char *iface;
gboolean is_first;
guint32 u32;
NMTernary t;
s_con = nm_connection_get_setting_connection (connection); s_con = nm_connection_get_setting_connection (connection);
if (s_con) { if (s_con) {
@@ -1172,62 +1196,46 @@ write_ethtool_setting (NMConnection *connection, shvarFile *ifcfg, GError **erro
|| (ch >= '0' && ch <= '9') || (ch >= '0' && ch <= '9')
|| NM_IN_SET (ch, '_')))) || NM_IN_SET (ch, '_'))))
iface = NULL; iface = NULL;
} } else
iface = NULL;
if (!str) if (!iface)
str = g_string_sized_new (30); iface = "net0";
else
g_string_append (str, " ; ");
g_string_append (str, "-K ");
g_string_append (str, iface ?: "net0");
is_first = TRUE;
for (ethtool_id = _NM_ETHTOOL_ID_FEATURE_FIRST; ethtool_id <= _NM_ETHTOOL_ID_FEATURE_LAST; ethtool_id++) { for (ethtool_id = _NM_ETHTOOL_ID_FEATURE_FIRST; ethtool_id <= _NM_ETHTOOL_ID_FEATURE_LAST; ethtool_id++) {
const NMEthtoolData *ed = nm_ethtool_data[ethtool_id];
NMTernary val;
nm_assert (nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id)); nm_assert (nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id));
t = nm_setting_ethtool_get_feature (s_ethtool, nm_ethtool_data[ethtool_id]->optname);
val = nm_setting_ethtool_get_feature (s_ethtool, ed->optname); if (t == NM_TERNARY_DEFAULT)
if (val == NM_TERNARY_DEFAULT)
continue; continue;
_ethtool_gstring_prepare (&str, &is_first, 'K', iface);
g_string_append_c (str, ' '); g_string_append_c (str, ' ');
g_string_append (str, nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id)); g_string_append (str, nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id));
g_string_append (str, val == NM_TERNARY_TRUE ? " on" : " off"); g_string_append (str, t != NM_TERNARY_FALSE ? " on" : " off");
} }
g_string_append (str, " ; -C "); is_first = TRUE;
g_string_append (str, iface ?: "net0");
for (ethtool_id = _NM_ETHTOOL_ID_COALESCE_FIRST; ethtool_id <= _NM_ETHTOOL_ID_COALESCE_LAST; ethtool_id++) { for (ethtool_id = _NM_ETHTOOL_ID_COALESCE_FIRST; ethtool_id <= _NM_ETHTOOL_ID_COALESCE_LAST; ethtool_id++) {
const NMEthtoolData *ed = nm_ethtool_data[ethtool_id];
guint32 val;
nm_assert (nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id)); nm_assert (nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id));
if (!nm_setting_ethtool_get_coalesce (s_ethtool, nm_ethtool_data[ethtool_id]->optname, &u32))
if (!nm_setting_ethtool_get_coalesce (s_ethtool, ed->optname, &val))
continue; continue;
_ethtool_gstring_prepare (&str, &is_first, 'C', iface);
g_string_append_c (str, ' '); g_string_append_c (str, ' ');
g_string_append (str, nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id)); g_string_append (str, nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id));
g_string_append_printf (str, " %"G_GUINT32_FORMAT, val); g_string_append_printf (str, " %"G_GUINT32_FORMAT, u32);
} }
g_string_append (str, " ; -G "); is_first = TRUE;
g_string_append (str, iface ?: "net0");
for (ethtool_id = _NM_ETHTOOL_ID_RING_FIRST; ethtool_id <= _NM_ETHTOOL_ID_RING_LAST; ethtool_id++) { for (ethtool_id = _NM_ETHTOOL_ID_RING_FIRST; ethtool_id <= _NM_ETHTOOL_ID_RING_LAST; ethtool_id++) {
const NMEthtoolData *ed = nm_ethtool_data[ethtool_id];
guint32 val;
nm_assert (nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id)); nm_assert (nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id));
if (!nm_setting_ethtool_get_ring (s_ethtool, nm_ethtool_data[ethtool_id]->optname, &u32))
if (!nm_setting_ethtool_get_ring (s_ethtool, ed->optname, &val))
continue; continue;
_ethtool_gstring_prepare (&str, &is_first, 'G', iface);
g_string_append_c (str, ' '); g_string_append_c (str, ' ');
g_string_append (str, nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id)); g_string_append (str, nms_ifcfg_rh_utils_get_ethtool_name (ethtool_id));
g_string_append_printf (str, " %"G_GUINT32_FORMAT, val); g_string_append_printf (str, " %"G_GUINT32_FORMAT, u32);
} }
} }

View File

@@ -1,7 +1,7 @@
TYPE=Ethernet TYPE=Ethernet
PROXY_METHOD=none PROXY_METHOD=none
BROWSER_ONLY=no BROWSER_ONLY=no
ETHTOOL_OPTS="autoneg on ; -K net0 rxvlan off tx on ; -C net0 ; -G net0" ETHTOOL_OPTS="autoneg on ; -K net0 rxvlan off tx on"
BOOTPROTO=dhcp BOOTPROTO=dhcp
DEFROUTE=yes DEFROUTE=yes
IPV4_FAILURE_FATAL=no IPV4_FAILURE_FATAL=no