ifcfg-rh: write all [ethernet] settings for write_wired_for_virtual()

It's not the task of the writer to mangle/normalize profiles. If a profile
for a virtual device can have an [ethernet] setting, then unsuitable values
like s390 options must be either rejected by nm_connection_verify() or normalized
by nm_connection_normalize(). In no way it's right that the writer simple
pretends they are not set.
This commit is contained in:
Thomas Haller
2021-05-10 22:48:15 +02:00
parent 166c458411
commit 6f3f25cead

View File

@@ -1096,78 +1096,70 @@ write_wired_setting_impl(NMSettingWired *s_wired, shvarFile *ifcfg, gboolean is_
"GENERATE_MAC_ADDRESS_MASK", "GENERATE_MAC_ADDRESS_MASK",
nm_setting_wired_get_generate_mac_address_mask(s_wired)); nm_setting_wired_get_generate_mac_address_mask(s_wired));
if (!is_virtual) { macaddr_blacklist = nm_setting_wired_get_mac_address_blacklist(s_wired);
macaddr_blacklist = nm_setting_wired_get_mac_address_blacklist(s_wired); if (macaddr_blacklist[0]) {
if (macaddr_blacklist[0]) { gs_free char *blacklist_str = NULL;
gs_free char *blacklist_str = NULL;
blacklist_str = g_strjoinv(" ", (char **) macaddr_blacklist); blacklist_str = g_strjoinv(" ", (char **) macaddr_blacklist);
svSetValueStr(ifcfg, "HWADDR_BLACKLIST", blacklist_str); svSetValueStr(ifcfg, "HWADDR_BLACKLIST", blacklist_str);
}
} }
mtu = nm_setting_wired_get_mtu(s_wired); mtu = nm_setting_wired_get_mtu(s_wired);
svSetValueInt64_cond(ifcfg, "MTU", mtu != 0, mtu); svSetValueInt64_cond(ifcfg, "MTU", mtu != 0, mtu);
if (!is_virtual) { s390_subchannels = nm_setting_wired_get_s390_subchannels(s_wired);
s390_subchannels = nm_setting_wired_get_s390_subchannels(s_wired);
{ {
gs_free char *tmp = NULL; gs_free char *tmp = NULL;
gsize len = NM_PTRARRAY_LEN(s390_subchannels); gsize len = NM_PTRARRAY_LEN(s390_subchannels);
if (len == 2) { if (len == 2) {
tmp = g_strdup_printf("%s,%s", s390_subchannels[0], s390_subchannels[1]); tmp = g_strdup_printf("%s,%s", s390_subchannels[0], s390_subchannels[1]);
} else if (len == 3) { } else if (len == 3) {
tmp = g_strdup_printf("%s,%s,%s", tmp = g_strdup_printf("%s,%s,%s",
s390_subchannels[0], s390_subchannels[0],
s390_subchannels[1], s390_subchannels[1],
s390_subchannels[2]); s390_subchannels[2]);
}
svSetValueStr(ifcfg, "SUBCHANNELS", tmp);
} }
svSetValueStr(ifcfg, "NETTYPE", nm_setting_wired_get_s390_nettype(s_wired)); svSetValueStr(ifcfg, "SUBCHANNELS", tmp);
}
svSetValueStr(ifcfg, svSetValueStr(ifcfg, "NETTYPE", nm_setting_wired_get_s390_nettype(s_wired));
"PORTNAME",
nm_setting_wired_get_s390_option_by_key(s_wired, "portname"));
svSetValueStr(ifcfg, svSetValueStr(ifcfg, "PORTNAME", nm_setting_wired_get_s390_option_by_key(s_wired, "portname"));
"CTCPROT",
nm_setting_wired_get_s390_option_by_key(s_wired, "ctcprot"));
num_opts = nm_setting_wired_get_num_s390_options(s_wired); svSetValueStr(ifcfg, "CTCPROT", nm_setting_wired_get_s390_option_by_key(s_wired, "ctcprot"));
if (s390_subchannels && num_opts) {
nm_auto_free_gstring GString *tmp = NULL;
for (i = 0; i < num_opts; i++) { num_opts = nm_setting_wired_get_num_s390_options(s_wired);
const char *s390_key, *s390_val; if (s390_subchannels && num_opts) {
nm_auto_free_gstring GString *tmp = NULL;
nm_setting_wired_get_s390_option(s_wired, i, &s390_key, &s390_val); for (i = 0; i < num_opts; i++) {
const char *s390_key, *s390_val;
/* portname is handled separately */ nm_setting_wired_get_s390_option(s_wired, i, &s390_key, &s390_val);
if (NM_IN_STRSET(s390_key, "portname", "ctcprot"))
continue;
if (strchr(s390_key, '=')) { /* portname is handled separately */
/* this key cannot be expressed. But after all, it's not valid anyway if (NM_IN_STRSET(s390_key, "portname", "ctcprot"))
continue;
if (strchr(s390_key, '=')) {
/* this key cannot be expressed. But after all, it's not valid anyway
* and the connection shouldn't even verify. */ * and the connection shouldn't even verify. */
continue; continue;
}
if (!tmp)
tmp = g_string_sized_new(30);
else
g_string_append_c(tmp, ' ');
nm_utils_escaped_tokens_escape_gstr(s390_key, NM_ASCII_SPACES, tmp);
g_string_append_c(tmp, '=');
nm_utils_escaped_tokens_escape_gstr(s390_val, NM_ASCII_SPACES, tmp);
} }
if (tmp)
svSetValueStr(ifcfg, "OPTIONS", tmp->str); if (!tmp)
tmp = g_string_sized_new(30);
else
g_string_append_c(tmp, ' ');
nm_utils_escaped_tokens_escape_gstr(s390_key, NM_ASCII_SPACES, tmp);
g_string_append_c(tmp, '=');
nm_utils_escaped_tokens_escape_gstr(s390_val, NM_ASCII_SPACES, tmp);
} }
if (tmp)
svSetValueStr(ifcfg, "OPTIONS", tmp->str);
} }
if (!is_virtual) if (!is_virtual)