mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
device: add nm_match_spec_device_data_init_from_device() helper
Will be used later.
This commit is contained in:
parent
dbb45f14d3
commit
798ea93c45
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
NMMatchSpecDeviceData data;
|
||||
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()),
|
||||
}));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue