From f373e1f860e6a5d61c6b2ccf310f7f92a5b6cec3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 28 Apr 2023 13:08:10 +0200 Subject: [PATCH 1/3] core: factor out unblocking autoconnect for port profiles from activate_slave_connections() --- src/core/nm-policy.c | 99 ++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 41 deletions(-) diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index bad8d32f6..1262f0970 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -1774,20 +1774,65 @@ _connection_autoconnect_retries_set(NMPolicy *self, } static void -activate_slave_connections(NMPolicy *self, NMDevice *device) +unblock_autoconnect_for_ports(NMPolicy *self, + const char *master_device, + const char *master_uuid_settings, + const char *master_uuid_applied, + gboolean reset_devcon_autoconnect) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self); - const char *master_device; - const char *master_uuid_settings = NULL; - const char *master_uuid_applied = NULL; - guint i; - NMActRequest *req; - gboolean internal_activation = FALSE; NMSettingsConnection *const *connections; gboolean changed; + guint i; + + changed = FALSE; + connections = nm_settings_get_connections(priv->settings, NULL); + for (i = 0; connections[i]; i++) { + NMSettingsConnection *sett_conn = connections[i]; + NMSettingConnection *s_slave_con; + const char *slave_master; + + s_slave_con = + nm_connection_get_setting_connection(nm_settings_connection_get_connection(sett_conn)); + slave_master = nm_setting_connection_get_master(s_slave_con); + if (!slave_master) + continue; + + if (!NM_IN_STRSET(slave_master, master_device, master_uuid_applied, master_uuid_settings)) + continue; + + if (reset_devcon_autoconnect) { + if (nm_manager_devcon_autoconnect_retries_reset(priv->manager, NULL, sett_conn)) + changed = TRUE; + } + + /* unblock the devices associated with that connection */ + if (nm_manager_devcon_autoconnect_blocked_reason_set( + priv->manager, + NULL, + sett_conn, + NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED, + FALSE)) { + if (!nm_settings_connection_autoconnect_is_blocked(sett_conn)) + changed = TRUE; + } + } + + if (changed) + nm_policy_device_recheck_auto_activate_all_schedule(self); +} + +static void +activate_slave_connections(NMPolicy *self, NMDevice *device) +{ + const char *master_device; + const char *master_uuid_settings = NULL; + const char *master_uuid_applied = NULL; + NMActRequest *req; + gboolean internal_activation = FALSE; master_device = nm_device_get_iface(device); - g_assert(master_device); + nm_assert(master_device); req = nm_device_get_act_request(device); if (req) { @@ -1811,39 +1856,11 @@ activate_slave_connections(NMPolicy *self, NMDevice *device) subject && (nm_auth_subject_get_subject_type(subject) == NM_AUTH_SUBJECT_TYPE_INTERNAL); } - changed = FALSE; - connections = nm_settings_get_connections(priv->settings, NULL); - for (i = 0; connections[i]; i++) { - NMSettingsConnection *sett_conn = connections[i]; - NMSettingConnection *s_slave_con; - const char *slave_master; - - s_slave_con = - nm_connection_get_setting_connection(nm_settings_connection_get_connection(sett_conn)); - slave_master = nm_setting_connection_get_master(s_slave_con); - if (!slave_master) - continue; - if (!NM_IN_STRSET(slave_master, master_device, master_uuid_applied, master_uuid_settings)) - continue; - - if (!internal_activation) { - if (nm_manager_devcon_autoconnect_retries_reset(priv->manager, NULL, sett_conn)) - changed = TRUE; - } - /* unblock the devices associated with that connection */ - if (nm_manager_devcon_autoconnect_blocked_reason_set( - priv->manager, - NULL, - sett_conn, - NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED, - FALSE)) { - if (!nm_settings_connection_autoconnect_is_blocked(sett_conn)) - changed = TRUE; - } - } - - if (changed) - nm_policy_device_recheck_auto_activate_all_schedule(self); + unblock_autoconnect_for_ports(self, + master_device, + master_uuid_settings, + master_uuid_applied, + !internal_activation); } static gboolean From 481cf3594bb69ea1127aff15d0087991dfdb4e58 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 5 May 2023 10:11:18 +0200 Subject: [PATCH 2/3] core: log when we unblock port profiles for controller change --- src/core/nm-policy.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index 1262f0970..87f8e792a 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -1785,6 +1785,17 @@ unblock_autoconnect_for_ports(NMPolicy *self, gboolean changed; guint i; + _LOGT(LOGD_CORE, + "block-autoconnect: unblocking port profiles for controller ifname=%s%s%s, uuid=%s%s%s" + "%s%s%s", + NM_PRINT_FMT_QUOTE_STRING(master_device), + NM_PRINT_FMT_QUOTE_STRING(master_uuid_settings), + NM_PRINT_FMT_QUOTED(master_uuid_applied, + ", applied-uuid=\"", + master_uuid_applied, + "\"", + "")); + changed = FALSE; connections = nm_settings_get_connections(priv->settings, NULL); for (i = 0; connections[i]; i++) { @@ -1793,7 +1804,7 @@ unblock_autoconnect_for_ports(NMPolicy *self, const char *slave_master; s_slave_con = - nm_connection_get_setting_connection(nm_settings_connection_get_connection(sett_conn)); + nm_settings_connection_get_setting(sett_conn, NM_META_SETTING_TYPE_CONNECTION); slave_master = nm_setting_connection_get_master(s_slave_con); if (!slave_master) continue; @@ -1840,16 +1851,16 @@ activate_slave_connections(NMPolicy *self, NMDevice *device) NMSettingsConnection *sett_conn; NMAuthSubject *subject; + sett_conn = nm_active_connection_get_settings_connection(NM_ACTIVE_CONNECTION(req)); + if (sett_conn) + master_uuid_settings = nm_settings_connection_get_uuid(sett_conn); + connection = nm_active_connection_get_applied_connection(NM_ACTIVE_CONNECTION(req)); if (connection) master_uuid_applied = nm_connection_get_uuid(connection); - sett_conn = nm_active_connection_get_settings_connection(NM_ACTIVE_CONNECTION(req)); - if (sett_conn) { - master_uuid_settings = nm_settings_connection_get_uuid(sett_conn); - if (nm_streq0(master_uuid_settings, master_uuid_applied)) - master_uuid_settings = NULL; - } + if (nm_streq0(master_uuid_settings, master_uuid_applied)) + master_uuid_applied = NULL; subject = nm_active_connection_get_subject(NM_ACTIVE_CONNECTION(req)); internal_activation = From 645a1bb0ef1befcfb526ab2b8932cf52dfab2f3b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 3 May 2023 11:34:06 +0200 Subject: [PATCH 3/3] core: unblock autoconnect when master profile changes When a port cannot activate because the controller is not ready, it gets blocked from autoconnect (see commit 725fed01cf7c ('policy: block connection from autoconnect in case of failed dependency')). Later, when the master activates we call activate_slave_connections() (see commit 32efb87d4dab ('core: unblock failed connections when the master is available')), which unblocks those port profiles so they can autoconnect. However, imagine you add a port profile with autoconnect enabled. The profile tries to autoconnect, finds no master and gets blocked. Then, add the controller profile with autoconnect disabled. The controller is not autoactivating, not calling activate_slave_connections() and the profiles stay down. Fix that by unblocking autoconnect of the ports when the controller profile changes. --- src/core/nm-policy.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index 87f8e792a..efdb06360 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -1833,6 +1833,26 @@ unblock_autoconnect_for_ports(NMPolicy *self, nm_policy_device_recheck_auto_activate_all_schedule(self); } +static void +unblock_autoconnect_for_ports_for_sett_conn(NMPolicy *self, NMSettingsConnection *sett_conn) +{ + const char *master_device; + const char *master_uuid_settings; + NMSettingConnection *s_con; + + nm_assert(NM_IS_POLICY(self)); + nm_assert(NM_IS_SETTINGS_CONNECTION(sett_conn)); + + s_con = nm_settings_connection_get_setting(sett_conn, NM_META_SETTING_TYPE_CONNECTION); + + nm_assert(NM_IS_SETTING_CONNECTION(s_con)); + + master_uuid_settings = nm_setting_connection_get_uuid(s_con); + master_device = nm_setting_connection_get_interface_name(s_con); + + unblock_autoconnect_for_ports(self, master_device, master_uuid_settings, NULL, TRUE); +} + static void activate_slave_connections(NMPolicy *self, NMDevice *device) { @@ -2573,6 +2593,8 @@ connection_added(NMSettings *settings, NMSettingsConnection *connection, gpointe NMPolicyPrivate *priv = user_data; NMPolicy *self = _PRIV_TO_SELF(priv); + unblock_autoconnect_for_ports_for_sett_conn(self, connection); + nm_policy_device_recheck_auto_activate_all_schedule(self); } @@ -2630,6 +2652,8 @@ connection_updated(NMSettings *settings, NMPolicy *self = _PRIV_TO_SELF(priv); NMSettingsConnectionUpdateReason update_reason = update_reason_u; + unblock_autoconnect_for_ports_for_sett_conn(self, connection); + if (NM_FLAGS_HAS(update_reason, NM_SETTINGS_CONNECTION_UPDATE_REASON_REAPPLY_PARTIAL)) { const CList *tmp_lst; NMDevice *device;