From 04f0491a588af1a2f20e900cdeb8cf7b7a635388 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 3 Dec 2024 10:28:16 +0100 Subject: [PATCH] cloud-setup: make _device_get_hwaddr() work with all kinds of devices We'll have Vlans and MacVlans soon, and those don't have permanent addresses. --- src/nm-cloud-setup/main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/nm-cloud-setup/main.c b/src/nm-cloud-setup/main.c index de03535ebd..e636aaf6bc 100644 --- a/src/nm-cloud-setup/main.c +++ b/src/nm-cloud-setup/main.c @@ -198,13 +198,14 @@ _map_interfaces_parse(void) } static const char * -_device_get_hwaddr(NMDeviceEthernet *device) +_device_get_hwaddr(NMDevice *device) { static const NMUtilsNamedValue *gl_map_interfaces_map = NULL; static gsize gl_initialized = 0; const NMUtilsNamedValue *map = NULL; - nm_assert(NM_IS_DEVICE_ETHERNET(device)); + nm_assert(NM_IS_DEVICE_ETHERNET(device) || NM_IS_DEVICE_MACVLAN(device) + || NM_IS_DEVICE_VLAN(device)); /* Network interfaces in cloud environments are identified by their permanent * MAC address. @@ -238,7 +239,11 @@ _device_get_hwaddr(NMDeviceEthernet *device) return NULL; } - return nm_device_ethernet_get_permanent_hw_address(device); + if (NM_IS_DEVICE_ETHERNET(device)) { + return nm_device_ethernet_get_permanent_hw_address(NM_DEVICE_ETHERNET(device)); + } else { + return nm_device_get_hw_address(device); + } } static char ** @@ -263,7 +268,7 @@ _nmc_get_ethernet_hwaddrs(NMClient *nmc) if (nm_device_get_state(device) < NM_DEVICE_STATE_UNAVAILABLE) continue; - hwaddr = _device_get_hwaddr(NM_DEVICE_ETHERNET(device)); + hwaddr = _device_get_hwaddr(device); if (!hwaddr) continue; @@ -305,7 +310,7 @@ _nmc_get_device_by_hwaddr(NMClient *nmc, const char *hwaddr) if (!NM_IS_DEVICE_ETHERNET(device)) continue; - hwaddr_dev = _device_get_hwaddr(NM_DEVICE_ETHERNET(device)); + hwaddr_dev = _device_get_hwaddr(device); if (!hwaddr_dev) continue;