0002-Remove-dead-ifaddr.c-fallback-code.patch
text/x-patch
Filename: 0002-Remove-dead-ifaddr.c-fallback-code.patch
Type: text/x-patch
Part: 1
Patch
Format: format-patch
Series: patch 0002
Subject: Remove dead ifaddr.c fallback code.
| File | + | − |
|---|---|---|
| src/backend/libpq/ifaddr.c | 2 | 99 |
From 4fc436b20807a25576d4652e6d4069e88a5b566a Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Mon, 15 Aug 2022 15:19:13 +1200
Subject: [PATCH 2/6] Remove dead ifaddr.c fallback code.
We carried a special implementation using Solaris-specific ioctl
SIOCGLIFCONF, but Solaris 11 and illumos adopted BSD-style getifaddrs()
a bit over a decade ago, and Solaris 10 is EOL'd. Remove the dead code.
Our comment about which OSes have getifaddrs() incorrectly listed AIX,
so fix that. It is in fact the only Unix in the build farm that
*doesn't* have it today, so the implementation based on SIOCGIFCONF
(note, no 'L') is still live. There may be a better way to do this on
AIX, though (not investigated).
The last-stop fallback is dead code in practice, but it's hard to
justify removing it because our better options are all non-standard.
---
src/backend/libpq/ifaddr.c | 101 +------------------------------------
1 file changed, 2 insertions(+), 99 deletions(-)
diff --git a/src/backend/libpq/ifaddr.c b/src/backend/libpq/ifaddr.c
index cb1645bc57..876a1dac08 100644
--- a/src/backend/libpq/ifaddr.c
+++ b/src/backend/libpq/ifaddr.c
@@ -291,7 +291,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
* for each one. Returns 0 if successful, -1 if trouble.
*
* This version uses the getifaddrs() interface, which is available on
- * BSDs, AIX, and modern Linux.
+ * BSDs, macOS, Solaris, illumos and Linux.
*/
int
pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
@@ -321,104 +321,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
#include <sys/sockio.h>
#endif
-/*
- * SIOCGIFCONF does not return IPv6 addresses on Solaris.
- * So we prefer SIOCGLIFCONF if it's available.
- */
-
-#if defined(SIOCGLIFCONF)
-
-/*
- * Enumerate the system's network interface addresses and call the callback
- * for each one. Returns 0 if successful, -1 if trouble.
- *
- * This version uses ioctl(SIOCGLIFCONF).
- */
-int
-pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
-{
- struct lifconf lifc;
- struct lifreq *lifr,
- lmask;
- struct sockaddr *addr,
- *mask;
- char *ptr,
- *buffer = NULL;
- size_t n_buffer = 1024;
- pgsocket sock,
- fd;
- pgsocket sock6;
- int i,
- total;
-
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock == PGINVALID_SOCKET)
- return -1;
-
- while (n_buffer < 1024 * 100)
- {
- n_buffer += 1024;
- ptr = realloc(buffer, n_buffer);
- if (!ptr)
- {
- free(buffer);
- close(sock);
- errno = ENOMEM;
- return -1;
- }
-
- memset(&lifc, 0, sizeof(lifc));
- lifc.lifc_family = AF_UNSPEC;
- lifc.lifc_buf = buffer = ptr;
- lifc.lifc_len = n_buffer;
-
- if (ioctl(sock, SIOCGLIFCONF, &lifc) < 0)
- {
- if (errno == EINVAL)
- continue;
- free(buffer);
- close(sock);
- return -1;
- }
-
- /*
- * Some Unixes try to return as much data as possible, with no
- * indication of whether enough space allocated. Don't believe we have
- * it all unless there's lots of slop.
- */
- if (lifc.lifc_len < n_buffer - 1024)
- break;
- }
-
- /* We'll need an IPv6 socket too for the SIOCGLIFNETMASK ioctls */
- sock6 = socket(AF_INET6, SOCK_DGRAM, 0);
- if (sock6 == PGINVALID_SOCKET)
- {
- free(buffer);
- close(sock);
- return -1;
- }
-
- total = lifc.lifc_len / sizeof(struct lifreq);
- lifr = lifc.lifc_req;
- for (i = 0; i < total; ++i)
- {
- addr = (struct sockaddr *) &lifr[i].lifr_addr;
- memcpy(&lmask, &lifr[i], sizeof(struct lifreq));
- fd = (addr->sa_family == AF_INET6) ? sock6 : sock;
- if (ioctl(fd, SIOCGLIFNETMASK, &lmask) < 0)
- mask = NULL;
- else
- mask = (struct sockaddr *) &lmask.lifr_addr;
- run_ifaddr_callback(callback, cb_data, addr, mask);
- }
-
- free(buffer);
- close(sock);
- close(sock6);
- return 0;
-}
-#elif defined(SIOCGIFCONF)
+#if defined(SIOCGIFCONF)
/*
* Remaining Unixes use SIOCGIFCONF. Some only return IPv4 information
--
2.35.1