mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-01 05:40:27 +01:00
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.
This commit is contained in:
parent
91b5babff2
commit
f9077fa74d
2 changed files with 13 additions and 0 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue