import NetworkManager-1.40.16-13.el8_9

i8c changed/i8c/NetworkManager-1.40.16-13.el8_9
MSVSphere Packaging Team 12 months ago
parent d73f490419
commit 3ed2605a57

@ -0,0 +1,50 @@
From a5826caf0607ca3c490bdc76d1d453226ca2e191 Mon Sep 17 00:00:00 2001
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
Date: Tue, 18 Jul 2023 13:46:30 +0200
Subject: [PATCH] manager: allow controller activation if device is
deactivating
When activating a port connection it will require the controller
connection is active or a valid controller device candidate is available
for activation.
One of the conditions we consider for a controller device to be a valid
candidate for the connection is that it is not active, therefore we
should also consider as valid a device that is currently deactivating.
Otherwise, we could fail during the port activation just because the
deactivation of the controller device candidate didn't finish yet.
https://bugzilla.redhat.com/show_bug.cgi?id=2125615
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1693
(cherry picked from commit fb362e0583fe9b75269220c7c8b966e2247084ea)
(cherry picked from commit 43f244ef2e4c4052fe708b77244444ee7eff238c)
(cherry picked from commit 401f153dfb52d12495bb39899f2b4dde7dfb72ce)
---
src/core/nm-manager.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c
index 822df7ad3b..4ef87a5d83 100644
--- a/src/core/nm-manager.c
+++ b/src/core/nm-manager.c
@@ -4608,11 +4608,11 @@ ensure_master_active_connection(NMManager *self,
NULL))
continue;
- if (!nm_device_is_software(candidate)) {
- master_state = nm_device_get_state(candidate);
- if (nm_device_is_real(candidate) && master_state != NM_DEVICE_STATE_DISCONNECTED)
- continue;
- }
+ if (nm_device_is_real(candidate)
+ && !NM_IN_SET(nm_device_get_state(candidate),
+ NM_DEVICE_STATE_DISCONNECTED,
+ NM_DEVICE_STATE_DEACTIVATING))
+ continue;
master_ac = nm_manager_activate_connection(
self,
--
2.41.0

@ -0,0 +1,299 @@
From 5b8d8494f9c00de2fd1c7f30aafef4e19566bf6b Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Tue, 26 Sep 2023 15:00:32 +0800
Subject: [PATCH 1/2] emit DNS CONFIG_CHANGED signal even dns=none
Instruct the `NMDnsManager` to emit `CONFIG_CHANGED` signal even
`dns=none` or failed to modify `/etc/resolv.conf`.
The `NMPolicy` will only update hostname when DNS is managed.
Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit a847ba807572c3ef3682e833432f2f93e9d519a0)
(cherry picked from commit d10f20fd01a7bb3225c7e38ed80449e19156344b)
(cherry picked from commit e0f3a91a95d45f729bd42956617aafb84e26a47b)
(cherry picked from commit cd9ebfd2bb76b99b861af1272f5ef9bb0d279008)
---
src/core/dns/nm-dns-manager.c | 12 +++++++++++-
src/core/dns/nm-dns-manager.h | 2 ++
src/core/nm-policy.c | 10 ++++++----
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c
index 416a9bf915..2d5f1245b3 100644
--- a/src/core/dns/nm-dns-manager.c
+++ b/src/core/dns/nm-dns-manager.c
@@ -1907,7 +1907,7 @@ plugin_skip:;
}
/* signal that DNS resolution configs were changed */
- if ((do_update || caching || force_emit) && result == SR_SUCCESS)
+ if ((caching || force_emit) && result == SR_SUCCESS)
g_signal_emit(self, signals[CONFIG_CHANGED], 0);
nm_clear_pointer(&priv->config_variant, g_variant_unref);
@@ -1923,6 +1923,16 @@ plugin_skip:;
return TRUE;
}
+gboolean
+nm_dns_manager_is_unmanaged(NMDnsManager *self)
+{
+ NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self);
+
+ return NM_IN_SET(priv->rc_manager,
+ NM_DNS_MANAGER_RESOLV_CONF_MAN_UNMANAGED,
+ NM_DNS_MANAGER_RESOLV_CONF_MAN_IMMUTABLE);
+}
+
/*****************************************************************************/
gboolean
diff --git a/src/core/dns/nm-dns-manager.h b/src/core/dns/nm-dns-manager.h
index b41bf1ccf2..b697b3e380 100644
--- a/src/core/dns/nm-dns-manager.h
+++ b/src/core/dns/nm-dns-manager.h
@@ -148,4 +148,6 @@ char *nmtst_dns_create_resolv_conf(const char *const *searches,
const char *const *nameservers,
const char *const *options);
+gboolean nm_dns_manager_is_unmanaged(NMDnsManager *self);
+
#endif /* __NETWORKMANAGER_DNS_MANAGER_H__ */
diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c
index 0b7c9eddca..d9e7643fa2 100644
--- a/src/core/nm-policy.c
+++ b/src/core/nm-policy.c
@@ -2563,11 +2563,13 @@ dns_config_changed(NMDnsManager *dns_manager, gpointer user_data)
if (priv->updating_dns)
return;
- nm_manager_for_each_device (priv->manager, device, tmp_lst) {
- nm_device_clear_dns_lookup_data(device, "DNS configuration changed");
- }
+ if (!nm_dns_manager_is_unmanaged(dns_manager)) {
+ nm_manager_for_each_device (priv->manager, device, tmp_lst) {
+ nm_device_clear_dns_lookup_data(device, "DNS configuration changed");
+ }
- update_system_hostname(self, "DNS configuration changed");
+ update_system_hostname(self, "DNS configuration changed");
+ }
}
static void
--
2.41.0
From a2c92e569d7bf99365dc809529f863f03d426241 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Wed, 18 Oct 2023 15:03:13 +0800
Subject: [PATCH 2/2] dispatch `dns-change` dispatcher event
Introducing new dispatcher event -- `dns-change` which will be emitted when
DNS configuration changed(even in `dns=none` mode). This is to solve two
use cases:
* Invoke dispatch script for DNS changes triggered by the global DNS
API.
* Do not invoke [OpenShift resolv-prepender][1] for non-DNS changes.
Bug reference: https://issues.redhat.com/browse/RHEL-1671
[1]: https://github.com/openshift/machine-config-operator/blob/master/templates/common/on-prem/files/resolv-prepender.yaml
Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit a1db61ebc9712d1faf2ef8f1b2cb14cd819346d3)
(cherry picked from commit 3cdce71b95cea11bf409d9353c35a4dea6f33984)
(cherry picked from commit 9ae535c61a5116179ba2f775458427b93518ac49)
(cherry picked from commit e74a349e1e88e06436a6809b92faa249910daabd)
---
man/NetworkManager-dispatcher.xml | 5 +-
src/core/nm-dispatcher.c | 51 ++++++++++++++++---
src/core/nm-dispatcher.h | 5 +-
src/core/nm-policy.c | 2 +
src/libnm-core-aux-extern/nm-dispatcher-api.h | 1 +
src/nm-dispatcher/nm-dispatcher-utils.c | 8 ++-
6 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/man/NetworkManager-dispatcher.xml b/man/NetworkManager-dispatcher.xml
index 4a603b1566..8a3c0b46ed 100644
--- a/man/NetworkManager-dispatcher.xml
+++ b/man/NetworkManager-dispatcher.xml
@@ -68,8 +68,9 @@
device an operation just happened on, and second the action. For device actions,
the interface is the name of the kernel interface suitable for IP configuration.
Thus it is either VPN_IP_IFACE, DEVICE_IP_IFACE, or DEVICE_IFACE, as applicable.
- For the <varname>hostname</varname> action the device name is always <literal>"none"</literal>
- and for <varname>connectivity-change</varname> it is empty.
+ For the <varname>hostname</varname> action the device name is always <literal>"none"</literal>.
+ For <varname>connectivity-change</varname> it is empty.
+ For <varname>dns-change</varname> it is empty.
</para>
<para>The actions are:</para>
<variablelist class="dispatcher-options">
diff --git a/src/core/nm-dispatcher.c b/src/core/nm-dispatcher.c
index d3529ee4de..a0ce4de80d 100644
--- a/src/core/nm-dispatcher.c
+++ b/src/core/nm-dispatcher.c
@@ -49,6 +49,8 @@
} \
G_STMT_END
+static gboolean nm_dispatcher_need_device(NMDispatcherAction action);
+
/*****************************************************************************/
struct NMDispatcherCallId {
@@ -465,7 +467,8 @@ static const char *action_table[] = {[NM_DISPATCHER_ACTION_HOSTNAME] = NMD_
[NM_DISPATCHER_ACTION_DHCP_CHANGE_4] = NMD_ACTION_DHCP4_CHANGE,
[NM_DISPATCHER_ACTION_DHCP_CHANGE_6] = NMD_ACTION_DHCP6_CHANGE,
[NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE] =
- NMD_ACTION_CONNECTIVITY_CHANGE};
+ NMD_ACTION_CONNECTIVITY_CHANGE,
+ [NM_DISPATCHER_ACTION_DNS_CHANGE] = NMD_ACTION_DNS_CHANGE};
static const char *
action_to_string(NMDispatcherAction action)
@@ -526,9 +529,7 @@ _dispatcher_call(NMDispatcherAction action,
if (G_UNLIKELY(!request_id))
request_id = ++gl.request_id_counter;
- /* All actions except 'hostname' and 'connectivity-change' require a device */
- if (action == NM_DISPATCHER_ACTION_HOSTNAME
- || action == NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE) {
+ if (!nm_dispatcher_need_device(action)) {
_LOG2D(request_id,
log_ifname,
log_con_uuid,
@@ -588,9 +589,8 @@ _dispatcher_call(NMDispatcherAction action,
g_variant_builder_init(&vpn_ip4_props, G_VARIANT_TYPE_VARDICT);
g_variant_builder_init(&vpn_ip6_props, G_VARIANT_TYPE_VARDICT);
- /* hostname and connectivity-change actions don't send device data */
- if (action != NM_DISPATCHER_ACTION_HOSTNAME
- && action != NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE) {
+ /* hostname, DNS and connectivity-change actions don't send device data */
+ if (nm_dispatcher_need_device(action)) {
fill_device_props(device,
&device_props,
&device_proxy_props,
@@ -921,6 +921,30 @@ nm_dispatcher_call_connectivity(NMConnectivityState connectivity_state,
out_call_id);
}
+/**
+ * nm_dispatcher_call_dns_change():
+ *
+ * This method does not block the caller.
+ *
+ * Returns: %TRUE if the action was dispatched, %FALSE on failure
+ */
+gboolean
+nm_dispatcher_call_dns_change(void)
+{
+ return _dispatcher_call(NM_DISPATCHER_ACTION_DNS_CHANGE,
+ FALSE,
+ NULL,
+ NULL,
+ NULL,
+ FALSE,
+ NM_CONNECTIVITY_UNKNOWN,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+}
+
void
nm_dispatcher_call_cancel(NMDispatcherCallId *call_id)
{
@@ -933,3 +957,16 @@ nm_dispatcher_call_cancel(NMDispatcherCallId *call_id)
_LOG3D(call_id, "cancelling dispatcher callback action");
call_id->callback = NULL;
}
+
+/* All actions except 'hostname', 'connectivity-change' and 'dns-change' require
+ * a device */
+static gboolean
+nm_dispatcher_need_device(NMDispatcherAction action)
+{
+ if (action == NM_DISPATCHER_ACTION_HOSTNAME
+ || action == NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE
+ || action == NM_DISPATCHER_ACTION_DNS_CHANGE) {
+ return FALSE;
+ }
+ return TRUE;
+}
diff --git a/src/core/nm-dispatcher.h b/src/core/nm-dispatcher.h
index 73e0599a75..50d50e9a6a 100644
--- a/src/core/nm-dispatcher.h
+++ b/src/core/nm-dispatcher.h
@@ -21,7 +21,8 @@ typedef enum {
NM_DISPATCHER_ACTION_VPN_DOWN,
NM_DISPATCHER_ACTION_DHCP_CHANGE_4,
NM_DISPATCHER_ACTION_DHCP_CHANGE_6,
- NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE
+ NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE,
+ NM_DISPATCHER_ACTION_DNS_CHANGE,
} NMDispatcherAction;
#define NM_DISPATCHER_ACTION_DHCP_CHANGE_X(IS_IPv4) \
@@ -68,6 +69,8 @@ gboolean nm_dispatcher_call_connectivity(NMConnectivityState state,
gpointer user_data,
NMDispatcherCallId **out_call_id);
+gboolean nm_dispatcher_call_dns_change(void);
+
void nm_dispatcher_call_cancel(NMDispatcherCallId *call_id);
#endif /* __NM_DISPATCHER_H__ */
diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c
index d9e7643fa2..9316325c68 100644
--- a/src/core/nm-policy.c
+++ b/src/core/nm-policy.c
@@ -2570,6 +2570,8 @@ dns_config_changed(NMDnsManager *dns_manager, gpointer user_data)
update_system_hostname(self, "DNS configuration changed");
}
+
+ nm_dispatcher_call_dns_change();
}
static void
diff --git a/src/libnm-core-aux-extern/nm-dispatcher-api.h b/src/libnm-core-aux-extern/nm-dispatcher-api.h
index 7776c84f9a..d19caa0bb5 100644
--- a/src/libnm-core-aux-extern/nm-dispatcher-api.h
+++ b/src/libnm-core-aux-extern/nm-dispatcher-api.h
@@ -33,6 +33,7 @@
#define NMD_ACTION_DHCP4_CHANGE "dhcp4-change"
#define NMD_ACTION_DHCP6_CHANGE "dhcp6-change"
#define NMD_ACTION_CONNECTIVITY_CHANGE "connectivity-change"
+#define NMD_ACTION_DNS_CHANGE "dns-change"
typedef enum {
DISPATCH_RESULT_UNKNOWN = 0,
diff --git a/src/nm-dispatcher/nm-dispatcher-utils.c b/src/nm-dispatcher/nm-dispatcher-utils.c
index 74ea4e4001..f8a4c28000 100644
--- a/src/nm-dispatcher/nm-dispatcher-utils.c
+++ b/src/nm-dispatcher/nm-dispatcher-utils.c
@@ -453,8 +453,12 @@ nm_dispatcher_utils_construct_envp(const char *action,
items = g_ptr_array_new_with_free_func(g_free);
- /* Hostname and connectivity changes don't require a device nor contain a connection */
- if (NM_IN_STRSET(action, NMD_ACTION_HOSTNAME, NMD_ACTION_CONNECTIVITY_CHANGE))
+ /* Hostname, dns and connectivity changes don't require a device nor contain
+ * a connection */
+ if (NM_IN_STRSET(action,
+ NMD_ACTION_HOSTNAME,
+ NMD_ACTION_CONNECTIVITY_CHANGE,
+ NMD_ACTION_DNS_CHANGE))
goto done;
/* Connection properties */
--
2.41.0

@ -0,0 +1,51 @@
From 51901a2266d7d1ffd3465906c55064c512cb075d Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Wed, 12 Jul 2023 16:22:03 +0800
Subject: [PATCH] device: do not set MAC address on iface with index <=0
The `nm_device_hw_addr_reset()` should only set MAC address on NIC
with valid(>0) interface index.
The failure was found by `ovs_mtu` test of NMCI, failed to reproduce
the original problem (`ovs_mtu` test of NMCI) with 100 times retry.
And no trace log found for original test failure, hence cannot tell why
`nm_device_hw_addr_reset()` been invoked with iface index 0.
Signed-off-by: Gris Ge <fge@redhat.com>
(cherry picked from commit 215bc1525501b22325c2a17090a5f911e01f06a9)
(cherry picked from commit 21f1e5cdc7d72376cdaa63112d8a134b714b2002)
(cherry picked from commit 37bd70034f7f43becf2cc64468143c5ea2666762)
---
src/core/devices/nm-device.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c
index 2ac55fa83c..5748d80393 100644
--- a/src/core/devices/nm-device.c
+++ b/src/core/devices/nm-device.c
@@ -16859,6 +16859,7 @@ nm_device_hw_addr_reset(NMDevice *self, const char *detail)
{
NMDevicePrivate *priv;
const char *addr;
+ int ifindex;
g_return_val_if_fail(NM_IS_DEVICE(self), FALSE);
@@ -16868,7 +16869,13 @@ nm_device_hw_addr_reset(NMDevice *self, const char *detail)
return TRUE;
priv->hw_addr_type = HW_ADDR_TYPE_UNSET;
- addr = nm_device_get_initial_hw_address(self);
+
+ ifindex = nm_device_get_ip_ifindex(self);
+ if (ifindex <= 0) {
+ return TRUE;
+ }
+
+ addr = nm_device_get_initial_hw_address(self);
if (!addr) {
/* as hw_addr_type is not UNSET, we expect that we can get an
* initial address to which to reset. */
--
2.41.0

@ -0,0 +1,822 @@
From a55f8f9151878f8a0c634316713abd2c77dfaea9 Mon Sep 17 00:00:00 2001
From: Thomas Haller <thaller@redhat.com>
Date: Wed, 3 May 2023 11:43:33 +0200
Subject: [PATCH 1/5] libnm/trivial: rename internal connection-get-setting
methods
This function will be exposed on the internal header. Rename to
_nm_connection_get_setting_by_metatype().
(cherry picked from commit 27cbf584bdb7451e196b03b706c4c4dfa266ba3e)
(cherry picked from commit c194db5755f18b3fd55a9a7b4b4d25882f05ce05)
(cherry picked from commit 39227612384c08da845a7d97a87de3b10277320a)
---
src/libnm-core-impl/nm-connection.c | 81 ++++++++++++++---------------
1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c
index 67a9034dcc..fc4bc51c17 100644
--- a/src/libnm-core-impl/nm-connection.c
+++ b/src/libnm-core-impl/nm-connection.c
@@ -339,7 +339,7 @@ _connection_get_setting_check(NMConnection *connection, GType setting_type)
}
static gpointer
-_connection_get_setting_by_meta_type_check(NMConnection *connection, NMMetaSettingType meta_type)
+_nm_connection_get_setting_by_metatype(NMConnection *connection, NMMetaSettingType meta_type)
{
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
@@ -3231,7 +3231,7 @@ nm_connection_get_virtual_device_description(NMConnection *connection)
NMSetting8021x *
nm_connection_get_setting_802_1x(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_802_1X);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_802_1X);
}
/**
@@ -3245,7 +3245,7 @@ nm_connection_get_setting_802_1x(NMConnection *connection)
NMSettingBluetooth *
nm_connection_get_setting_bluetooth(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_BLUETOOTH);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_BLUETOOTH);
}
/**
@@ -3259,7 +3259,7 @@ nm_connection_get_setting_bluetooth(NMConnection *connection)
NMSettingBond *
nm_connection_get_setting_bond(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_BOND);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_BOND);
}
/**
@@ -3273,7 +3273,7 @@ nm_connection_get_setting_bond(NMConnection *connection)
NMSettingTeam *
nm_connection_get_setting_team(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_TEAM);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_TEAM);
}
/**
@@ -3287,7 +3287,7 @@ nm_connection_get_setting_team(NMConnection *connection)
NMSettingTeamPort *
nm_connection_get_setting_team_port(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_TEAM_PORT);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_TEAM_PORT);
}
/**
@@ -3301,7 +3301,7 @@ nm_connection_get_setting_team_port(NMConnection *connection)
NMSettingBridge *
nm_connection_get_setting_bridge(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_BRIDGE);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_BRIDGE);
}
/**
@@ -3315,7 +3315,7 @@ nm_connection_get_setting_bridge(NMConnection *connection)
NMSettingCdma *
nm_connection_get_setting_cdma(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_CDMA);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_CDMA);
}
/**
@@ -3329,7 +3329,7 @@ nm_connection_get_setting_cdma(NMConnection *connection)
NMSettingConnection *
nm_connection_get_setting_connection(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_CONNECTION);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_CONNECTION);
}
/**
@@ -3343,7 +3343,7 @@ nm_connection_get_setting_connection(NMConnection *connection)
NMSettingDcb *
nm_connection_get_setting_dcb(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_DCB);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_DCB);
}
/**
@@ -3359,7 +3359,7 @@ nm_connection_get_setting_dcb(NMConnection *connection)
NMSettingDummy *
nm_connection_get_setting_dummy(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_DUMMY);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_DUMMY);
}
/**
@@ -3373,7 +3373,7 @@ nm_connection_get_setting_dummy(NMConnection *connection)
NMSettingGeneric *
nm_connection_get_setting_generic(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_GENERIC);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_GENERIC);
}
/**
@@ -3387,7 +3387,7 @@ nm_connection_get_setting_generic(NMConnection *connection)
NMSettingGsm *
nm_connection_get_setting_gsm(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_GSM);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_GSM);
}
/**
@@ -3401,7 +3401,7 @@ nm_connection_get_setting_gsm(NMConnection *connection)
NMSettingInfiniband *
nm_connection_get_setting_infiniband(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_INFINIBAND);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_INFINIBAND);
}
/**
@@ -3420,7 +3420,7 @@ nm_connection_get_setting_infiniband(NMConnection *connection)
NMSettingIPConfig *
nm_connection_get_setting_ip4_config(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_IP4_CONFIG);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_IP4_CONFIG);
}
/**
@@ -3436,7 +3436,7 @@ nm_connection_get_setting_ip4_config(NMConnection *connection)
NMSettingIPTunnel *
nm_connection_get_setting_ip_tunnel(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_IP_TUNNEL);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_IP_TUNNEL);
}
/**
@@ -3455,7 +3455,7 @@ nm_connection_get_setting_ip_tunnel(NMConnection *connection)
NMSettingIPConfig *
nm_connection_get_setting_ip6_config(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_IP6_CONFIG);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_IP6_CONFIG);
}
/**
@@ -3471,7 +3471,7 @@ nm_connection_get_setting_ip6_config(NMConnection *connection)
NMSettingMacsec *
nm_connection_get_setting_macsec(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_MACSEC);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_MACSEC);
}
/**
@@ -3487,7 +3487,7 @@ nm_connection_get_setting_macsec(NMConnection *connection)
NMSettingMacvlan *
nm_connection_get_setting_macvlan(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_MACVLAN);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_MACVLAN);
}
/**
@@ -3501,7 +3501,7 @@ nm_connection_get_setting_macvlan(NMConnection *connection)
NMSettingOlpcMesh *
nm_connection_get_setting_olpc_mesh(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_OLPC_MESH);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OLPC_MESH);
}
/**
@@ -3517,7 +3517,7 @@ nm_connection_get_setting_olpc_mesh(NMConnection *connection)
NMSettingOvsBridge *
nm_connection_get_setting_ovs_bridge(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_OVS_BRIDGE);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OVS_BRIDGE);
}
/**
@@ -3533,8 +3533,7 @@ nm_connection_get_setting_ovs_bridge(NMConnection *connection)
NMSettingOvsInterface *
nm_connection_get_setting_ovs_interface(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection,
- NM_META_SETTING_TYPE_OVS_INTERFACE);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OVS_INTERFACE);
}
/**
@@ -3550,7 +3549,7 @@ nm_connection_get_setting_ovs_interface(NMConnection *connection)
NMSettingOvsPatch *
nm_connection_get_setting_ovs_patch(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_OVS_PATCH);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OVS_PATCH);
}
/**
@@ -3566,7 +3565,7 @@ nm_connection_get_setting_ovs_patch(NMConnection *connection)
NMSettingOvsPort *
nm_connection_get_setting_ovs_port(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_OVS_PORT);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_OVS_PORT);
}
/**
@@ -3580,7 +3579,7 @@ nm_connection_get_setting_ovs_port(NMConnection *connection)
NMSettingPpp *
nm_connection_get_setting_ppp(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_PPP);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_PPP);
}
/**
@@ -3594,7 +3593,7 @@ nm_connection_get_setting_ppp(NMConnection *connection)
NMSettingPppoe *
nm_connection_get_setting_pppoe(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_PPPOE);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_PPPOE);
}
/**
@@ -3610,7 +3609,7 @@ nm_connection_get_setting_pppoe(NMConnection *connection)
NMSettingProxy *
nm_connection_get_setting_proxy(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_PROXY);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_PROXY);
}
/**
@@ -3624,7 +3623,7 @@ nm_connection_get_setting_proxy(NMConnection *connection)
NMSettingSerial *
nm_connection_get_setting_serial(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_SERIAL);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_SERIAL);
}
/**
@@ -3640,7 +3639,7 @@ nm_connection_get_setting_serial(NMConnection *connection)
NMSettingTCConfig *
nm_connection_get_setting_tc_config(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_TC_CONFIG);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_TC_CONFIG);
}
/**
@@ -3656,7 +3655,7 @@ nm_connection_get_setting_tc_config(NMConnection *connection)
NMSettingTun *
nm_connection_get_setting_tun(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_TUN);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_TUN);
}
/**
@@ -3670,7 +3669,7 @@ nm_connection_get_setting_tun(NMConnection *connection)
NMSettingVpn *
nm_connection_get_setting_vpn(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_VPN);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_VPN);
}
/**
@@ -3686,7 +3685,7 @@ nm_connection_get_setting_vpn(NMConnection *connection)
NMSettingVxlan *
nm_connection_get_setting_vxlan(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_VXLAN);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_VXLAN);
}
/**
@@ -3700,7 +3699,7 @@ nm_connection_get_setting_vxlan(NMConnection *connection)
NMSettingWimax *
nm_connection_get_setting_wimax(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_WIMAX);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_WIMAX);
}
/**
@@ -3714,7 +3713,7 @@ nm_connection_get_setting_wimax(NMConnection *connection)
NMSettingWired *
nm_connection_get_setting_wired(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_WIRED);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_WIRED);
}
/**
@@ -3728,7 +3727,7 @@ nm_connection_get_setting_wired(NMConnection *connection)
NMSettingAdsl *
nm_connection_get_setting_adsl(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_ADSL);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_ADSL);
}
/**
@@ -3742,7 +3741,7 @@ nm_connection_get_setting_adsl(NMConnection *connection)
NMSettingWireless *
nm_connection_get_setting_wireless(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_WIRELESS);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_WIRELESS);
}
/**
@@ -3756,8 +3755,8 @@ nm_connection_get_setting_wireless(NMConnection *connection)
NMSettingWirelessSecurity *
nm_connection_get_setting_wireless_security(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection,
- NM_META_SETTING_TYPE_WIRELESS_SECURITY);
+ return _nm_connection_get_setting_by_metatype(connection,
+ NM_META_SETTING_TYPE_WIRELESS_SECURITY);
}
/**
@@ -3771,7 +3770,7 @@ nm_connection_get_setting_wireless_security(NMConnection *connection)
NMSettingBridgePort *
nm_connection_get_setting_bridge_port(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_BRIDGE_PORT);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_BRIDGE_PORT);
}
/**
@@ -3785,7 +3784,7 @@ nm_connection_get_setting_bridge_port(NMConnection *connection)
NMSettingVlan *
nm_connection_get_setting_vlan(NMConnection *connection)
{
- return _connection_get_setting_by_meta_type_check(connection, NM_META_SETTING_TYPE_VLAN);
+ return _nm_connection_get_setting_by_metatype(connection, NM_META_SETTING_TYPE_VLAN);
}
NMSettingBluetooth *
--
2.41.0
From 91bae3c3bd5a80cab7950f8d85a9669ca1f721fe Mon Sep 17 00:00:00 2001
From: Thomas Haller <thaller@redhat.com>
Date: Thu, 4 May 2023 11:34:58 +0200
Subject: [PATCH 2/5] libnm: cleanup redundant nm_connection_get_setting
functions
Refactor and cleanup the functions to get a setting from a connection.
As the NMConnection tracks the settings in an array indexed by
NMMetaSettingType, the most direct and efficient way is to look up via
that enum.
Previously, nm_connection_get_setting_by_name() would first look up the GType
(which already involved looking up the NMMetaSettingInfo), then based on the
GType it would look up the NMMetaSettingInfo again to get the meta_type. That
is unnecessary. Directly look up the NMMetaSettingInfo, which directly
gives the meta_type.
(cherry picked from commit c60a4649b80e03f5b50e5d94f3d8c7c71c079af9)
(cherry picked from commit eebbd362701abb52d29a84f02ab57d81742e97ea)
(cherry picked from commit 58fd65c37e4eb2516faec22ea345457a59cfa9d7)
---
src/libnm-core-impl/nm-connection.c | 76 +++++++++++++----------------
src/libnm-core-impl/nm-setting.c | 4 ++
2 files changed, 37 insertions(+), 43 deletions(-)
diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c
index fc4bc51c17..08eab900d8 100644
--- a/src/libnm-core-impl/nm-connection.c
+++ b/src/libnm-core-impl/nm-connection.c
@@ -302,26 +302,7 @@ nm_connection_remove_setting(NMConnection *connection, GType setting_type)
}
static gpointer
-_connection_get_setting(NMConnection *connection, GType setting_type)
-{
- NMSetting *setting;
- const NMMetaSettingInfo *setting_info;
-
- nm_assert(NM_IS_CONNECTION(connection));
- nm_assert(g_type_is_a(setting_type, NM_TYPE_SETTING));
-
- setting_info = _nm_meta_setting_info_from_gtype(setting_type);
- if (!setting_info)
- g_return_val_if_reached(NULL);
-
- setting = NM_CONNECTION_GET_PRIVATE(connection)->settings[setting_info->meta_type];
-
- nm_assert(!setting || G_TYPE_CHECK_INSTANCE_TYPE(setting, setting_type));
- return setting;
-}
-
-static gpointer
-_connection_get_setting_by_meta_type(NMConnectionPrivate *priv, NMMetaSettingType meta_type)
+_get_setting_by_metatype(NMConnectionPrivate *priv, NMMetaSettingType meta_type)
{
nm_assert(priv);
nm_assert(_NM_INT_NOT_NEGATIVE(meta_type));
@@ -330,20 +311,12 @@ _connection_get_setting_by_meta_type(NMConnectionPrivate *priv, NMMetaSettingTyp
return priv->settings[meta_type];
}
-static gpointer
-_connection_get_setting_check(NMConnection *connection, GType setting_type)
-{
- g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
-
- return _connection_get_setting(connection, setting_type);
-}
-
static gpointer
_nm_connection_get_setting_by_metatype(NMConnection *connection, NMMetaSettingType meta_type)
{
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
- return _connection_get_setting_by_meta_type(NM_CONNECTION_GET_PRIVATE(connection), meta_type);
+ return _get_setting_by_metatype(NM_CONNECTION_GET_PRIVATE(connection), meta_type);
}
/**
@@ -360,19 +333,34 @@ _nm_connection_get_setting_by_metatype(NMConnection *connection, NMMetaSettingTy
NMSetting *
nm_connection_get_setting(NMConnection *connection, GType setting_type)
{
- g_return_val_if_fail(g_type_is_a(setting_type, NM_TYPE_SETTING), NULL);
+ NMSetting *setting;
+ const NMMetaSettingInfo *setting_info;
+
+ g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
+
+ setting_info = _nm_meta_setting_info_from_gtype(setting_type);
+
+ if (!setting_info)
+ g_return_val_if_reached(NULL);
+
+ setting = NM_CONNECTION_GET_PRIVATE(connection)->settings[setting_info->meta_type];
+
+ nm_assert(!setting || G_TYPE_CHECK_INSTANCE_TYPE(setting, setting_type));
- return _connection_get_setting_check(connection, setting_type);
+ return setting;
}
NMSettingIPConfig *
nm_connection_get_setting_ip_config(NMConnection *connection, int addr_family)
{
+ g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
+
nm_assert_addr_family(addr_family);
- return NM_SETTING_IP_CONFIG(_connection_get_setting(
- connection,
- (addr_family == AF_INET) ? NM_TYPE_SETTING_IP4_CONFIG : NM_TYPE_SETTING_IP6_CONFIG));
+ return NM_SETTING_IP_CONFIG(_get_setting_by_metatype(NM_CONNECTION_GET_PRIVATE(connection),
+ (addr_family == AF_INET)
+ ? NM_META_SETTING_TYPE_IP4_CONFIG
+ : NM_META_SETTING_TYPE_IP6_CONFIG));
}
/**
@@ -389,12 +377,14 @@ nm_connection_get_setting_ip_config(NMConnection *connection, int addr_family)
NMSetting *
nm_connection_get_setting_by_name(NMConnection *connection, const char *name)
{
- GType type;
+ const NMMetaSettingInfo *setting_info;
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
- type = nm_setting_lookup_type(name);
- return type ? _connection_get_setting(connection, type) : NULL;
+ setting_info = nm_meta_setting_infos_by_name(name);
+ return setting_info ? _get_setting_by_metatype(NM_CONNECTION_GET_PRIVATE(connection),
+ setting_info->meta_type)
+ : NULL;
}
/*****************************************************************************/
@@ -1672,8 +1662,8 @@ _normalize_802_1x_empty_strings(NMConnection *self)
NMSetting8021x *s_8021x;
gboolean changed = FALSE;
- s_8021x = _connection_get_setting_by_meta_type(NM_CONNECTION_GET_PRIVATE(self),
- NM_META_SETTING_TYPE_802_1X);
+ s_8021x =
+ _get_setting_by_metatype(NM_CONNECTION_GET_PRIVATE(self), NM_META_SETTING_TYPE_802_1X);
if (!s_8021x)
return FALSE;
@@ -1823,7 +1813,7 @@ _nm_connection_verify(NMConnection *connection, GError **error)
priv = NM_CONNECTION_GET_PRIVATE(connection);
- if (!_connection_get_setting_by_meta_type(priv, NM_META_SETTING_TYPE_CONNECTION)) {
+ if (!_get_setting_by_metatype(priv, NM_META_SETTING_TYPE_CONNECTION)) {
g_set_error_literal(error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_MISSING_SETTING,
@@ -1868,9 +1858,9 @@ _nm_connection_verify(NMConnection *connection, GError **error)
g_clear_error(&verify_error);
}
- s_ip4 = _connection_get_setting_by_meta_type(priv, NM_META_SETTING_TYPE_IP4_CONFIG);
- s_ip6 = _connection_get_setting_by_meta_type(priv, NM_META_SETTING_TYPE_IP6_CONFIG);
- s_proxy = _connection_get_setting_by_meta_type(priv, NM_META_SETTING_TYPE_PROXY);
+ s_ip4 = _get_setting_by_metatype(priv, NM_META_SETTING_TYPE_IP4_CONFIG);
+ s_ip6 = _get_setting_by_metatype(priv, NM_META_SETTING_TYPE_IP6_CONFIG);
+ s_proxy = _get_setting_by_metatype(priv, NM_META_SETTING_TYPE_PROXY);
nm_assert(normalizable_error_type != NM_SETTING_VERIFY_ERROR);
if (NM_IN_SET(normalizable_error_type,
diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c
index b6f721371f..a4404ba87b 100644
--- a/src/libnm-core-impl/nm-setting.c
+++ b/src/libnm-core-impl/nm-setting.c
@@ -110,6 +110,10 @@ nm_setting_lookup_type(const char *name)
{
const NMMetaSettingInfo *setting_info;
+ /* various callers check whether the result is valid with plain `if (gtype)`.
+ * Assert that G_TYPE_INVALID is zero. */
+ G_STATIC_ASSERT(G_TYPE_INVALID == 0);
+
g_return_val_if_fail(name, G_TYPE_INVALID);
setting_info = nm_meta_setting_infos_by_name(name);
--
2.41.0
From d78c89ef0a031fde52107d88ce4a0600be16323f Mon Sep 17 00:00:00 2001
From: Thomas Haller <thaller@redhat.com>
Date: Wed, 3 May 2023 12:01:14 +0200
Subject: [PATCH 3/5] libnm: expose _nm_connection_get_setting_by_metatype() in
internal header
We have several variants to get the NMSetting from an NMConnection. Some
of them are public API (nm_connection_get_setting(), nm_connection_get_setting_by_name()).
The most efficient way is lookup by NMMetaSettingType. Expose that as
internal API, so it can be used. The NMMetaSettingType is internal, but
it exists because it's a very useful enum. Allow others to make use of
it.
Also, add a static assert which prevents various wrong uses at compile
time, for example
_nm_connection_get_setting_by_metatype(connection, NM_TYPE_SETTING_CONNECTION)
(cherry picked from commit db5946ac2fc349269835b18c37f1df35ac326cda)
(cherry picked from commit 50b6c2d622f66d2fef187c6da1498b091f34df20)
(cherry picked from commit 1cd4f675c888a7d01f4920a07b4eab838fed8a2f)
---
src/libnm-core-impl/nm-connection.c | 7 +++++--
src/libnm-core-intern/nm-core-internal.h | 14 ++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c
index 08eab900d8..9d94cf56cc 100644
--- a/src/libnm-core-impl/nm-connection.c
+++ b/src/libnm-core-impl/nm-connection.c
@@ -311,8 +311,11 @@ _get_setting_by_metatype(NMConnectionPrivate *priv, NMMetaSettingType meta_type)
return priv->settings[meta_type];
}
-static gpointer
-_nm_connection_get_setting_by_metatype(NMConnection *connection, NMMetaSettingType meta_type)
+/* The "unsafe" part here is that _nm_connection_get_setting_by_metatype() has a compile
+ * time check that meta_type is valid. With the unsafe variant, the caller must ensure that,
+ * and we only get an nm_assert() check -- which is basically nothing. */
+gpointer
+_nm_connection_get_setting_by_metatype_unsafe(NMConnection *connection, NMMetaSettingType meta_type)
{
g_return_val_if_fail(NM_IS_CONNECTION(connection), NULL);
diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h
index 1857e03bbd..695cd75c04 100644
--- a/src/libnm-core-intern/nm-core-internal.h
+++ b/src/libnm-core-intern/nm-core-internal.h
@@ -479,6 +479,20 @@ _nm_connection_get_setting(NMConnection *connection, GType type)
return (gpointer) nm_connection_get_setting(connection, type);
}
+gpointer _nm_connection_get_setting_by_metatype_unsafe(NMConnection *connection,
+ NMMetaSettingType meta_type);
+
+/* This variant is the most efficient one, because it does not require resolving a
+ * name/GType first. The NMMetaSettingType enum allows for a direct lookup. */
+#define _nm_connection_get_setting_by_metatype(connection, meta_type) \
+ ({ \
+ /* Static assert that meta_type is in the valid range. If you don't want that,
+ * because the argument is no a compile time constant, use _nm_connection_get_setting_by_metatype_unsafe(). */ \
+ G_STATIC_ASSERT((meta_type) < _NM_META_SETTING_TYPE_NUM && ((int) meta_type) >= 0); \
+ \
+ _nm_connection_get_setting_by_metatype_unsafe((connection), (meta_type)); \
+ })
+
NMSettingIPConfig *nm_connection_get_setting_ip_config(NMConnection *connection, int addr_family);
/*****************************************************************************/
--
2.41.0
From 5c2b3730d8ab5ece5aba1ca23adf2e4f624233da Mon Sep 17 00:00:00 2001
From: Thomas Haller <thaller@redhat.com>
Date: Wed, 3 May 2023 12:15:47 +0200
Subject: [PATCH 4/5] core: add nm_settings_connection_get_setting() helper
For efficiently and conveniently lookup an NMSetting from the
NMConnection inside the NMSettingsConnection.
Note that this uses the NMMetaSettingType as lookup key. That is a novel
approach, compared to lookup by name (nm_connection_get_setting_by_name())
or GType (nm_connection_get_setting()).
Using the NMMetaSettingType enum is however faster, because it does not
require resolving the name/GType first. This is perfecly fine internal API,
we should use it.
(cherry picked from commit 429cf416fd12f14d3a5639d7890f0d334c5e9328)
(cherry picked from commit 10e493bbe82ce06bd217a148fb0a6e531c8ee0a6)
(cherry picked from commit c2cf898c19627f7ec6ea645206d76a19b5821a07)
---
src/core/settings/nm-settings-connection.c | 14 ++++++++++++++
src/core/settings/nm-settings-connection.h | 4 ++++
2 files changed, 18 insertions(+)
diff --git a/src/core/settings/nm-settings-connection.c b/src/core/settings/nm-settings-connection.c
index 1638efcd7e..c0137637ab 100644
--- a/src/core/settings/nm-settings-connection.c
+++ b/src/core/settings/nm-settings-connection.c
@@ -361,6 +361,20 @@ nm_settings_connection_get_connection(NMSettingsConnection *self)
return NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->connection;
}
+gpointer
+nm_settings_connection_get_setting(NMSettingsConnection *self, NMMetaSettingType meta_type)
+{
+ NMConnection *connection;
+
+ nm_assert(NM_IS_SETTINGS_CONNECTION(self));
+
+ connection = NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->connection;
+
+ nm_assert(NM_IS_SIMPLE_CONNECTION(connection));
+
+ return _nm_connection_get_setting_by_metatype_unsafe(connection, meta_type);
+}
+
void
_nm_settings_connection_set_connection(NMSettingsConnection *self,
NMConnection *new_connection,
diff --git a/src/core/settings/nm-settings-connection.h b/src/core/settings/nm-settings-connection.h
index 893b0d7b74..68d75ab6f4 100644
--- a/src/core/settings/nm-settings-connection.h
+++ b/src/core/settings/nm-settings-connection.h
@@ -7,6 +7,8 @@
#ifndef __NETWORKMANAGER_SETTINGS_CONNECTION_H__
#define __NETWORKMANAGER_SETTINGS_CONNECTION_H__
+#include "libnm-core-intern/nm-meta-setting-base.h"
+
#include "nm-dbus-object.h"
#include "nm-connection.h"
@@ -218,6 +220,8 @@ GType nm_settings_connection_get_type(void);
NMSettingsConnection *nm_settings_connection_new(void);
NMConnection *nm_settings_connection_get_connection(NMSettingsConnection *self);
+gpointer nm_settings_connection_get_setting(NMSettingsConnection *self,
+ NMMetaSettingType meta_type);
void _nm_settings_connection_set_connection(NMSettingsConnection *self,
NMConnection *new_connection,
--
2.41.0
From 3e68288800dd1e9499edcc3b32b8d8f61f588b15 Mon Sep 17 00:00:00 2001
From: Fernando Fernandez Mancera <ffmancera@riseup.net>
Date: Tue, 4 Jul 2023 12:50:29 +0200
Subject: [PATCH 5/5] utils: extend connection matching function for UUID in
controller
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
(cherry picked from commit 5b8fdd25ab431dd1318eff00e725448f7c699a30)
(cherry picked from commit 5ca93db6928d7bbeb5ae378512843877359f06ba)
(cherry picked from commit 8c0f262549d5ab34fd06ec0594d0e8fab58fef70)
---
src/core/NetworkManagerUtils.c | 51 ++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c
index f5b7666b0e..c58433e76d 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"
@@ -683,6 +684,53 @@ check_connection_cloned_mac_address(NMConnection *orig,
return FALSE;
}
+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)
{
@@ -764,6 +812,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;
--
2.41.0

@ -6,7 +6,7 @@
%global epoch_version 1 %global epoch_version 1
%global real_version 1.40.16 %global real_version 1.40.16
%global rpm_version %{real_version} %global rpm_version %{real_version}
%global release_version 9 %global release_version 13
%global snapshot %{nil} %global snapshot %{nil}
%global git_sha %{nil} %global git_sha %{nil}
%global bcond_default_debug 0 %global bcond_default_debug 0
@ -204,6 +204,10 @@ Patch1005: 1005-ipv6ll-don-t-regenerate-the-address-when-removed-rh2209353.patch
Patch1006: 1006-fix-read-infiniband-from-ifcfg-rh2209164.patch Patch1006: 1006-fix-read-infiniband-from-ifcfg-rh2209164.patch
Patch1007: 1007-unblock-autoconnect-on-reapply-rh2207690.patch Patch1007: 1007-unblock-autoconnect-on-reapply-rh2207690.patch
Patch1008: 1008-cloud-setup-fix-terminating-in-reconfig-rh2221903.patch Patch1008: 1008-cloud-setup-fix-terminating-in-reconfig-rh2221903.patch
Patch1009: 1009-manager-allow-controller-activation-if-device-is-dea-rhel-5119.patch
Patch1010: 1010-better-dispatch-way-for-dns-changes-RHEL-14886.patch
Patch1011: 1011-device-do-not-set-MAC-address-on-iface-with-index-0-RHEL-17839.patch
Patch1012: 1012-fix-matching-existing-connection-by-UUID-on-restart-rhel-5122.patch
Requires(post): systemd Requires(post): systemd
%if 0%{?fedora} || 0%{?rhel} >= 8 %if 0%{?fedora} || 0%{?rhel} >= 8
@ -1239,6 +1243,18 @@ fi
%changelog %changelog
* Fri Dec 08 2023 Wen Liang <wenliang@redhat.com> - 1:1.40.16-13
- Fix matching existing connection by UUID on restart (RHEL-5122)
* Mon Dec 04 2023 Fernando Fernandez Mancera <ferferna@redhat.com> - 1:1.40.16-12
- device: do not set MAC address on iface with index <=0 (RHEL-17839)
* Thu Nov 16 2023 Íñigo Huguet <ihuguet@redhat.com> - 1:1.40.16-11
- New dispatcher event 'dns-change' (RHEL-14886)
* Wed Oct 04 2023 Fernando Fernandez Mancera <ferferna@redhat.com> - 1:1.40.16-10
- manager: allow controller activation if device is deactivating (RHEL-5119)
* Tue Jul 25 2023 MSVSphere Packaging Team <packager@msvsphere.ru> - 1:1.40.16-9 * Tue Jul 25 2023 MSVSphere Packaging Team <packager@msvsphere.ru> - 1:1.40.16-9
- Rebuilt for MSVSphere 8.8 - Rebuilt for MSVSphere 8.8

Loading…
Cancel
Save