summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-12-13 13:18:13 +0100
committerThomas Haller <thaller@redhat.com>2018-12-13 19:50:06 +0100
commit37171a4b0430f6ed58b54d4876f5569c991f1b04 (patch)
tree4f39c6cd145e2ebfc426de0fe4a812d718f2737e
parentd4b0d72859744a87df6ba42540531d8862a65f99 (diff)
downloadNetworkManager-37171a4b0430f6ed58b54d4876f5569c991f1b04.tar.gz
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 ID for a link, meaning it can change any time. Also, we already have the (ip) ifindex as proper identifier for the platform link. We shouldn't use two redundant links. 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/. 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.
-rw-r--r--src/devices/nm-device.c12
-rw-r--r--src/devices/nm-device.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 8eed3abb04..11123fa19a 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 83215256c9..4cf4e31b59 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);