summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2022-05-05 10:29:19 +0200
committerLubomir Rintel <lkundrak@v3.sk>2022-05-10 21:41:19 +0200
commit41291ef773f7628a179f19a271239fd2676ffa37 (patch)
treeb2ac0ffb8466912c9b5e94ff28dcabfcbebd980f
parent62f461ebeb4d0577a401d591a82479b4df8e185b (diff)
downloadNetworkManager-41291ef773f7628a179f19a271239fd2676ffa37.tar.gz
core/connection: ensure wired settings are around for bridges
Bridges are wired ethernet bridges, it makes sense for them to have wired ethernet settings. Ensuring they always exist makes reapplying the MTU changes more convenient. The MTU for bridges is taken from wired settings, making it impossible to change and reapply it for connections that lack them (as reapply doesn't really cope well with addition and removal of settings). https://bugzilla.redhat.com/show_bug.cgi?id=2076131 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1208
-rw-r--r--src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c6
-rw-r--r--src/libnm-core-impl/nm-connection.c2
-rw-r--r--src/libnm-core-impl/nm-setting-bridge.c9
3 files changed, 16 insertions, 1 deletions
diff --git a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c
index 11a8e4169c..b24acc45af 100644
--- a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c
+++ b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c
@@ -1924,6 +1924,7 @@ test_write_bridge_main(void)
gs_unref_object NMConnection *connection = NULL;
NMSettingConnection *s_con;
NMSettingBridge *s_bridge;
+ NMSettingWired *s_wired;
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
@@ -1953,6 +1954,11 @@ test_write_bridge_main(void)
g_assert(s_bridge);
nm_connection_add_setting(connection, NM_SETTING(s_bridge));
+ /* Ethernet setting */
+ s_wired = (NMSettingWired *) nm_setting_wired_new();
+ g_assert(s_wired);
+ nm_connection_add_setting(connection, NM_SETTING(s_wired));
+
/* IP4 setting */
s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new();
g_assert(s_ip4);
diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c
index 5f1a157a65..aed4be2113 100644
--- a/src/libnm-core-impl/nm-connection.c
+++ b/src/libnm-core-impl/nm-connection.c
@@ -1708,7 +1708,7 @@ _normalize_required_settings(NMConnection *self)
NMSetting *s_bridge;
gboolean changed = FALSE;
- if (nm_connection_get_setting_vlan(self)) {
+ if (nm_connection_get_setting_vlan(self) || nm_connection_get_setting_bridge(self)) {
if (!nm_connection_get_setting_wired(self)) {
nm_connection_add_setting(self, nm_setting_wired_new());
changed = TRUE;
diff --git a/src/libnm-core-impl/nm-setting-bridge.c b/src/libnm-core-impl/nm-setting-bridge.c
index fab6e4762e..39a3fb6017 100644
--- a/src/libnm-core-impl/nm-setting-bridge.c
+++ b/src/libnm-core-impl/nm-setting-bridge.c
@@ -1311,6 +1311,15 @@ verify(NMSetting *setting, NMConnection *connection, GError **error)
NM_SETTING_BRIDGE_VLANS))
return NM_SETTING_VERIFY_NORMALIZABLE;
+ if (connection && !nm_connection_get_setting_wired(connection)) {
+ g_set_error_literal(error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_SETTING_NOT_FOUND,
+ _("bridge connection should have a ethernet setting as well"));
+ g_prefix_error(error, "%s: ", NM_SETTING_BRIDGE_SETTING_NAME);
+ return NM_SETTING_VERIFY_NORMALIZABLE;
+ }
+
return TRUE;
}