From f9077fa74da0dc2657d81bc8f696e7f49d0a91a7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Dec 2018 13:18:13 +0100 Subject: [PATCH] device: add nm_device_get_ip_iface_from_platform() We have a cached nm_device_get_ip_iface() property. However, the interface name is not an identifier for a link because it can change at any time. Also, we already have the (ip) ifindex as proper identifier for the platform link. We shouldn't use two redundant identifiers to refer to a link. Clearly, sometimes we need an ifname. For example for ethtool ioctl or sysctl path names. For ethtool API, we resolve the actual name as late as possible, and for sysctl API we prefer NMP_SYSCTL_PATHID_NETDIR*(). However, that is not always possible, for example for /proc/sys/net/ipv6/conf/ sysctls. Add a function that resolves the ifname by looking into the cache. This of course is still racy, but it minimizes the time. Also, we should less and less rely on the ifname, and resolve it as late as possible. This patch adds a small wrapper going into that direction. --- src/devices/nm-device.c | 12 ++++++++++++ src/devices/nm-device.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 2acbc554f3..bee031fd1b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1480,6 +1480,18 @@ nm_device_get_ip_iface (NMDevice *self) return priv->ip_iface ?: priv->iface; } +const char * +nm_device_get_ip_iface_from_platform (NMDevice *self) +{ + int ifindex; + + ifindex = nm_device_get_ip_ifindex (self); + if (ifindex <= 0) + return NULL; + + return nm_platform_link_get_name (nm_device_get_platform (self), ifindex); +} + int nm_device_get_ip_ifindex (const NMDevice *self) { diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 1778faef92..c2e3c474fb 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -485,6 +485,7 @@ int nm_device_get_ifindex (NMDevice *dev); gboolean nm_device_is_software (NMDevice *dev); gboolean nm_device_is_real (NMDevice *dev); const char * nm_device_get_ip_iface (NMDevice *dev); +const char * nm_device_get_ip_iface_from_platform (NMDevice *dev); int nm_device_get_ip_ifindex (const NMDevice *dev); const char * nm_device_get_driver (NMDevice *dev); const char * nm_device_get_driver_version (NMDevice *dev);