1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-12-24 17:51:17 +03:00

Linux: Drop obsolete kernel support with if_nameindex' and if_nametoindex'

Support for the SIOCGIFINDEX ioctl(2) Linux ABI (0x8933 command, called
SIOGIFINDEX in the API originally) was added with kernel version 2.1.14
for AF_INET6 sockets, followed by general support with version 2.1.22.
The Linux API was then updated by adding the current SIOCGIFINDEX name
with kernel version 2.1.68, back in Nov 1997.

All these kernel versions are well below our current default required
minimum of 3.2.0, let alone some platform higher version requirements.

Drop support for the absence of the SIOCGIFINDEX ioctl(2) in the API or
ABI, by removing arrangements for the ENOSYS error condition.  Discard
the indirection from '__if_nameindex' to 'if_nameindex_netlink' and
adjust the implementation of '__if_nametoindex' accordingly for a better
code flow.
This commit is contained in:
Maciej W. Rozycki
2025-06-05 19:04:46 +01:00
parent fcd6a8b5c5
commit 7a751ce39c

View File

@@ -32,35 +32,23 @@
unsigned int
__if_nametoindex (const char *ifname)
{
#ifndef SIOCGIFINDEX
__set_errno (ENOSYS);
return 0;
#else
struct ifreq ifr;
if (strlen (ifname) >= IFNAMSIZ)
{
__set_errno (ENODEV);
return 0;
}
strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
int fd = __opensock ();
if (fd < 0)
return 0;
if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0)
{
int saved_errno = errno;
__close_nocancel_nostatus (fd);
if (saved_errno == EINVAL)
__set_errno (ENOSYS);
return 0;
}
struct ifreq ifr;
strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
int status = __ioctl (fd, SIOCGIFINDEX, &ifr);
__close_nocancel_nostatus (fd);
return ifr.ifr_ifindex;
#endif
return status < 0 ? 0 : ifr.ifr_ifindex;
}
libc_hidden_def (__if_nametoindex)
weak_alias (__if_nametoindex, if_nametoindex)
@@ -83,8 +71,8 @@ weak_alias (__if_freenameindex, if_freenameindex)
libc_hidden_weak (if_freenameindex)
static struct if_nameindex *
if_nameindex_netlink (void)
struct if_nameindex *
__if_nameindex (void)
{
struct netlink_handle nh = { 0, 0, 0, NULL, NULL };
struct if_nameindex *idx = NULL;
@@ -196,19 +184,6 @@ if_nameindex_netlink (void)
return idx;
}
struct if_nameindex *
__if_nameindex (void)
{
#ifndef SIOCGIFINDEX
__set_errno (ENOSYS);
return NULL;
#else
struct if_nameindex *result = if_nameindex_netlink ();
return result;
#endif
}
weak_alias (__if_nameindex, if_nameindex)
libc_hidden_weak (if_nameindex)