]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Linux: Drop obsolete kernel support with `if_nameindex' and `if_nametoindex'
authorMaciej W. Rozycki <macro@redhat.com>
Thu, 5 Jun 2025 18:04:46 +0000 (19:04 +0100)
committerMaciej W. Rozycki <macro@redhat.com>
Thu, 5 Jun 2025 18:04:46 +0000 (19:04 +0100)
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.

sysdeps/unix/sysv/linux/if_index.c

index 0b01fd1f147d97efc78b277ba7a87513b6f20d5f..5d137598f0eb46a80834ee1ad687fc209a831b95 100644 (file)
 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)