diff options
author | Fernando Fernandez Mancera <ffmancera@riseup.net> | 2023-07-04 12:50:29 +0200 |
---|---|---|
committer | Fernando Fernandez Mancera <ffmancera@riseup.net> | 2023-07-11 17:00:40 +0200 |
commit | 8cc1fd9f3c7222485be69c423cfab67d65bb58ea (patch) | |
tree | 798aeb0da4c76a73b3eaf29945e17a98ce9f4152 | |
parent | 5565aebf306cc81495455c28e7ab53832924f4ec (diff) |
utils: extend connection matching function for UUID in controllerff/revert_uuid_con_master
When matching two connections one might be using UUID and the other one
could be using interface-name for the controller property. When
recovering from a fresh start NM does not have any context and when
generating a connection we are using UUID as the controller.
It is always hard to guess what is the right candidate to pick but at
least something NM can do is checking if the UUID matches a connection
with the same controller interface-name. If there are no other
conflicts, then we can assume that is a good canditate to activate.
This is a follow up to `dc254f90e2b306700a0b81f7194e9b0438c62f4c`.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1684
-rw-r--r-- | src/core/NetworkManagerUtils.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c index 94b2351310..35730d2b5f 100644 --- a/src/core/NetworkManagerUtils.c +++ b/src/core/NetworkManagerUtils.c @@ -23,6 +23,7 @@ #include "nm-setting-connection.h" #include "nm-setting-ip4-config.h" #include "nm-setting-ip6-config.h" +#include "settings/nm-settings.h" #include "libnm-core-intern/nm-core-internal.h" #include "libnm-platform/nmp-object.h" @@ -685,6 +686,53 @@ check_connection_cloned_mac_address(NMConnection *orig, } static gboolean +check_connection_controller(NMConnection *orig, NMConnection *candidate, GHashTable *settings) +{ + GHashTable *props; + const char *orig_controller = NULL, *cand_controller = NULL; + NMSettingConnection *s_con_orig, *s_con_cand, *s_con_controller; + NMSettingsConnection *con_controller; + + props = check_property_in_hash(settings, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_MASTER); + if (!props) + return TRUE; + + s_con_orig = nm_connection_get_setting_connection(orig); + s_con_cand = nm_connection_get_setting_connection(candidate); + orig_controller = nm_setting_connection_get_master(s_con_orig); + cand_controller = nm_setting_connection_get_master(s_con_cand); + + /* A generated connection uses the UUID to specify the controller. Accept + * candidates that specify as controller an interface name matching that + * UUID */ + if (orig_controller && cand_controller) { + if (nm_utils_is_uuid(orig_controller)) { + con_controller = nm_settings_get_connection_by_uuid(NM_SETTINGS_GET, orig_controller); + /* no connection found for that uuid */ + if (!con_controller) + return FALSE; + + s_con_controller = + nm_settings_connection_get_setting(con_controller, NM_META_SETTING_TYPE_CONNECTION); + if (nm_streq0(nm_setting_connection_get_interface_name(s_con_controller), + cand_controller)) { + remove_from_hash(settings, + props, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_MASTER); + return TRUE; + } else { + return FALSE; + } + } + } + + return FALSE; +} + +static gboolean check_connection_s390_props(NMConnection *orig, NMConnection *candidate, GHashTable *settings) { GHashTable *props1, *props2, *props3; @@ -765,6 +813,9 @@ check_possible_match(NMConnection *orig, if (!check_connection_cloned_mac_address(orig, candidate, settings)) return NULL; + if (!check_connection_controller(orig, candidate, settings)) + return NULL; + if (!check_connection_s390_props(orig, candidate, settings)) return NULL; |