From: Maciej W. Rozycki Date: Thu, 5 Jun 2025 18:04:46 +0000 (+0100) Subject: Linux: Drop obsolete kernel support with `if_nameindex' and `if_nametoindex' X-Git-Tag: glibc-2.42~156 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7a751ce39c266143807ef830a949cb8b831783ba;p=thirdparty%2Fglibc.git 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. --- diff --git a/sysdeps/unix/sysv/linux/if_index.c b/sysdeps/unix/sysv/linux/if_index.c index 0b01fd1f14..5d137598f0 100644 --- a/sysdeps/unix/sysv/linux/if_index.c +++ b/sysdeps/unix/sysv/linux/if_index.c @@ -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)