diff options
author | Thomas Haller <thaller@redhat.com> | 2023-06-12 12:11:54 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-06-14 11:07:34 +0200 |
commit | 798ea93c459b329f654d535eceecceab42e4709e (patch) | |
tree | 56fd48cad90c8b69e8f76c1d49aa8307b5c8e9b3 | |
parent | dbb45f14d325369cffc9c05fa4b57ca47c0eed09 (diff) |
device: add nm_match_spec_device_data_init_from_device() helper
Will be used later.
-rw-r--r-- | src/core/NetworkManagerUtils.c | 42 | ||||
-rw-r--r-- | src/core/NetworkManagerUtils.h | 6 | ||||
-rw-r--r-- | src/core/devices/nm-device.c | 28 |
3 files changed, 51 insertions, 25 deletions
diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c index 94e14852af..33a0c0a466 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" /*****************************************************************************/ @@ -900,6 +901,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 514d1cc8da..c6d6e274ba 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 e84317c2f5..67babb055f 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -17293,32 +17293,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); } |