summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-06-12 12:11:54 +0200
committerThomas Haller <thaller@redhat.com>2023-06-30 18:05:43 +0200
commit75f240704b4ddd940d2d951cb4429684b0e21d12 (patch)
treef668f3969f83b90ac814769fd01c3e7c42e87234
parentcb701c6a5ddc026e5f2db799c60ae9f6031ae384 (diff)
device: add nm_match_spec_device_data_init_from_device() helper
Will be used later. (cherry picked from commit 798ea93c459b329f654d535eceecceab42e4709e)
-rw-r--r--src/core/NetworkManagerUtils.c42
-rw-r--r--src/core/NetworkManagerUtils.h6
-rw-r--r--src/core/devices/nm-device.c28
3 files changed, 51 insertions, 25 deletions
diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c
index 42ed16d5f5..ad67671104 100644
--- a/src/core/NetworkManagerUtils.c
+++ b/src/core/NetworkManagerUtils.c
@@ -30,6 +30,7 @@
#include "libnm-platform/nm-linux-platform.h"
#include "libnm-platform/nm-platform-utils.h"
#include "nm-auth-utils.h"
+#include "devices/nm-device.h"
/*****************************************************************************/
@@ -896,6 +897,47 @@ nm_utils_match_connection(NMConnection *const *connections,
/*****************************************************************************/
+const struct _NMMatchSpecDeviceData *
+nm_match_spec_device_data_init_from_device(struct _NMMatchSpecDeviceData *out_data,
+ NMDevice *device)
+{
+ const char *hw_address;
+ gboolean is_fake;
+
+ nm_assert(out_data);
+
+ if (!device) {
+ *out_data = (NMMatchSpecDeviceData){};
+ return out_data;
+ }
+
+ nm_assert(NM_IS_DEVICE(device));
+
+ hw_address = nm_device_get_permanent_hw_address_full(
+ device,
+ !nm_device_get_unmanaged_flags(device, NM_UNMANAGED_PLATFORM_INIT),
+ &is_fake);
+
+ /* Note that here we access various getters on @device, without cloning
+ * or taking ownership and return it to the caller.
+ *
+ * The returned data is only valid, until NMDevice gets modified again. */
+
+ *out_data = (NMMatchSpecDeviceData){
+ .interface_name = nm_device_get_iface(device),
+ .device_type = nm_device_get_type_description(device),
+ .driver = nm_device_get_driver(device),
+ .driver_version = nm_device_get_driver_version(device),
+ .hwaddr = is_fake ? NULL : hw_address,
+ .s390_subchannels = nm_device_get_s390_subchannels(device),
+ .dhcp_plugin = nm_dhcp_manager_get_config(nm_dhcp_manager_get()),
+ };
+
+ return out_data;
+}
+
+/*****************************************************************************/
+
int
nm_match_spec_device_by_pllink(const NMPlatformLink *pllink,
const char *match_device_type,
diff --git a/src/core/NetworkManagerUtils.h b/src/core/NetworkManagerUtils.h
index 676215f38c..d7144aeb52 100644
--- a/src/core/NetworkManagerUtils.h
+++ b/src/core/NetworkManagerUtils.h
@@ -91,6 +91,12 @@ NMConnection *nm_utils_match_connection(NMConnection *const *connections,
/*****************************************************************************/
+struct _NMMatchSpecDeviceData;
+
+const struct _NMMatchSpecDeviceData *
+nm_match_spec_device_data_init_from_device(struct _NMMatchSpecDeviceData *out_data,
+ NMDevice *device);
+
int nm_match_spec_device_by_pllink(const NMPlatformLink *pllink,
const char *match_device_type,
const char *match_dhcp_plugin,
diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c
index 170b9676b8..0db60d2fac 100644
--- a/src/core/devices/nm-device.c
+++ b/src/core/devices/nm-device.c
@@ -17049,32 +17049,10 @@ nm_device_spec_match_list(NMDevice *self, const GSList *specs)
int
nm_device_spec_match_list_full(NMDevice *self, const GSList *specs, int no_match_value)
{
- NMDeviceClass *klass;
- NMMatchSpecMatchType m;
- const char *hw_address = NULL;
- gboolean is_fake;
-
- g_return_val_if_fail(NM_IS_DEVICE(self), FALSE);
-
- klass = NM_DEVICE_GET_CLASS(self);
- hw_address = nm_device_get_permanent_hw_address_full(
- self,
- !nm_device_get_unmanaged_flags(self, NM_UNMANAGED_PLATFORM_INIT),
- &is_fake);
-
- m = nm_match_spec_device(
- specs,
- &((const NMMatchSpecDeviceData){
- .interface_name = nm_device_get_iface(self),
- .device_type = nm_device_get_type_description(self),
- .driver = nm_device_get_driver(self),
- .driver_version = nm_device_get_driver_version(self),
- .hwaddr = is_fake ? NULL : hw_address,
- .s390_subchannels =
- klass->get_s390_subchannels ? klass->get_s390_subchannels(self) : NULL,
- .dhcp_plugin = nm_dhcp_manager_get_config(nm_dhcp_manager_get()),
- }));
+ NMMatchSpecDeviceData data;
+ NMMatchSpecMatchType m;
+ m = nm_match_spec_device(specs, nm_match_spec_device_data_init_from_device(&data, self));
return nm_match_spec_match_type_to_bool(m, no_match_value);
}