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.
This commit is contained in:
Lubomir Rintel 2024-12-03 10:28:16 +01:00
parent 871a53cbef
commit 3c720fa108

View file

@ -198,14 +198,12 @@ _map_interfaces_parse(void)
} }
static const char * static const char *
_device_get_hwaddr(NMDeviceEthernet *device) _device_get_hwaddr(NMDevice *device)
{ {
static const NMUtilsNamedValue *gl_map_interfaces_map = NULL; static const NMUtilsNamedValue *gl_map_interfaces_map = NULL;
static gsize gl_initialized = 0; static gsize gl_initialized = 0;
const NMUtilsNamedValue *map = NULL; const NMUtilsNamedValue *map = NULL;
nm_assert(NM_IS_DEVICE_ETHERNET(device));
/* Network interfaces in cloud environments are identified by their permanent /* Network interfaces in cloud environments are identified by their permanent
* MAC address. * MAC address.
* *
@ -238,7 +236,11 @@ _device_get_hwaddr(NMDeviceEthernet *device)
return NULL; 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 ** static char **
@ -263,7 +265,7 @@ _nmc_get_ethernet_hwaddrs(NMClient *nmc)
if (nm_device_get_state(device) < NM_DEVICE_STATE_UNAVAILABLE) if (nm_device_get_state(device) < NM_DEVICE_STATE_UNAVAILABLE)
continue; continue;
hwaddr = _device_get_hwaddr(NM_DEVICE_ETHERNET(device)); hwaddr = _device_get_hwaddr(device);
if (!hwaddr) if (!hwaddr)
continue; continue;
@ -305,7 +307,7 @@ _nmc_get_device_by_hwaddr(NMClient *nmc, const char *hwaddr)
if (!NM_IS_DEVICE_ETHERNET(device)) if (!NM_IS_DEVICE_ETHERNET(device))
continue; continue;
hwaddr_dev = _device_get_hwaddr(NM_DEVICE_ETHERNET(device)); hwaddr_dev = _device_get_hwaddr(device);
if (!hwaddr_dev) if (!hwaddr_dev)
continue; continue;