NetworkManager/SOURCES/1012-fix-matching-existing-connection-by-UUID-on-restart-rhel-5119.patch
eabdullin afcae0195a - Apply 1009-manager-allow-controller-activation-if-device-is-dea-rhel-5119
- Apply 1010-dispatch-dns-change-event-rhel-10195
- Apply 1011-device-do-not-set-MAC-address-on-iface-with-index-0-rhel-16008
- Apply 1012-fix-matching-existing-connection-by-UUID-on-restart-rhel-5119
2024-01-15 11:56:29 +03:00

823 lines
33 KiB
Diff

From e49026b4856fd492eb6e30a18133414841eeb609 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 15f0394acf2b0866190a3f603150a7e1ee96833c 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 fdf8ad3fdd8ddf03f8acd85a3e8eb4af67722699 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 0a8007057e5075df95a5dfc7ebb35269a2e99266 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 3608f7e2bbdd0e49450c55a7fbf882d360edfd74 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