Remove configure probe for sockaddr_in6 and require AF_INET6.
authorThomas Munro <[email protected]>
Thu, 25 Aug 2022 22:13:22 +0000 (10:13 +1200)
committerThomas Munro <[email protected]>
Thu, 25 Aug 2022 22:18:30 +0000 (10:18 +1200)
SUSv3 <netinet/in.h> defines struct sockaddr_in6, and all targeted Unix
systems have it.  Windows has it in <ws2ipdef.h>.  Remove the configure
probe, the macro and a small amount of dead code.

Also remove a mention of IPv6-less builds from the documentation, since
there aren't any.

This is similar to commits f5580882 and 077bf2f2 for Unix sockets.  Even
though AF_INET6 is an "optional" component of SUSv3, there are no known
modern operating system without it, and it seems even less likely to be
omitted from future systems than AF_UNIX.

Reviewed-by: Andres Freund <[email protected]>
Discussion: https://postgr.es/m/CA+hUKGKErNfhmvb_H0UprEmp4LPzGN06yR2_0tYikjzB-2ECMw@mail.gmail.com

16 files changed:
configure
configure.ac
doc/src/sgml/client-auth.sgml
src/backend/libpq/auth.c
src/backend/libpq/hba.c
src/backend/libpq/ifaddr.c
src/backend/libpq/pqcomm.c
src/backend/utils/adt/network.c
src/backend/utils/adt/pgstatfuncs.c
src/bin/initdb/initdb.c
src/include/pg_config.h.in
src/include/utils/inet.h
src/interfaces/libpq/fe-connect.c
src/port/inet_net_ntop.c
src/tools/ifaddrs/test_ifaddrs.c
src/tools/msvc/Solution.pm

index 814014a96b1c158326576eba1fce08a9fba94092..a268780c5dbd314e3a252deda80e9c8121bb9662 100755 (executable)
--- a/configure
+++ b/configure
@@ -16218,16 +16218,6 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
-ac_fn_c_check_type "$LINENO" "struct sockaddr_in6" "ac_cv_type_struct_sockaddr_in6" "$ac_includes_default
-#include <netinet/in.h>
-"
-if test "x$ac_cv_type_struct_sockaddr_in6" = xyes; then :
-
-$as_echo "#define HAVE_IPV6 1" >>confdefs.h
-
-fi
-
-
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for PS_STRINGS" >&5
 $as_echo_n "checking for PS_STRINGS... " >&6; }
 if ${pgac_cv_var_PS_STRINGS+:} false; then :
index 6ff294d4052033d637460baf8c9da0f226c4a26e..993b5d5cb0a5c15aee40a46709f6b45cecb3f7f6 100644 (file)
@@ -1801,12 +1801,6 @@ AC_CHECK_DECLS([pwritev], [], [AC_LIBOBJ(pwritev)], [#include <sys/uio.h>])
 # This is probably only present on macOS, but may as well check always
 AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])
 
-AC_CHECK_TYPE([struct sockaddr_in6],
-        [AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if you have support for IPv6.])],
-        [],
-[$ac_includes_default
-#include <netinet/in.h>])
-
 AC_CACHE_CHECK([for PS_STRINGS], [pgac_cv_var_PS_STRINGS],
 [AC_LINK_IFELSE([AC_LANG_PROGRAM(
 [#include <machine/vmparam.h>
index 433759928bc187f6c275ebc92313668461acd4c2..c6f1b70fd36cf2404fb9b974c9f232fc6330d3a3 100644 (file)
@@ -305,8 +305,6 @@ hostnogssenc  <replaceable>database</replaceable>  <replaceable>user</replaceabl
        An entry given in IPv4 format will match only IPv4 connections,
        and an entry given in IPv6 format will match only IPv6 connections,
        even if the represented address is in the IPv4-in-IPv6 range.
-       Note that entries in IPv6 format will be rejected if the system's
-       C library does not have support for IPv6 addresses.
       </para>
 
       <para>
index 10cd19e6cd9991d10fb0941f481e9bc286773cf3..b2b0b83a97b0dc118c450d5f15cac16b3ed70f89 100644 (file)
@@ -3015,13 +3015,8 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
        int                     packetlength;
        pgsocket        sock;
 
-#ifdef HAVE_IPV6
        struct sockaddr_in6 localaddr;
        struct sockaddr_in6 remoteaddr;
-#else
-       struct sockaddr_in localaddr;
-       struct sockaddr_in remoteaddr;
-#endif
        struct addrinfo hint;
        struct addrinfo *serveraddrs;
        int                     port;
@@ -3131,18 +3126,12 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
        }
 
        memset(&localaddr, 0, sizeof(localaddr));
-#ifdef HAVE_IPV6
        localaddr.sin6_family = serveraddrs[0].ai_family;
        localaddr.sin6_addr = in6addr_any;
        if (localaddr.sin6_family == AF_INET6)
                addrsize = sizeof(struct sockaddr_in6);
        else
                addrsize = sizeof(struct sockaddr_in);
-#else
-       localaddr.sin_family = serveraddrs[0].ai_family;
-       localaddr.sin_addr.s_addr = INADDR_ANY;
-       addrsize = sizeof(struct sockaddr_in);
-#endif
 
        if (bind(sock, (struct sockaddr *) &localaddr, addrsize))
        {
@@ -3245,21 +3234,11 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
                        return STATUS_ERROR;
                }
 
-#ifdef HAVE_IPV6
                if (remoteaddr.sin6_port != pg_hton16(port))
-#else
-               if (remoteaddr.sin_port != pg_hton16(port))
-#endif
                {
-#ifdef HAVE_IPV6
                        ereport(LOG,
                                        (errmsg("RADIUS response from %s was sent from incorrect port: %d",
                                                        server, pg_ntoh16(remoteaddr.sin6_port))));
-#else
-                       ereport(LOG,
-                                       (errmsg("RADIUS response from %s was sent from incorrect port: %d",
-                                                       server, pg_ntoh16(remoteaddr.sin_port))));
-#endif
                        continue;
                }
 
index 1447588c4aeb6f57b9b7d2fe3d4af8047e73a4f1..8f2b8c6b03a8fcad97674774294b47b27014a740 100644 (file)
@@ -645,8 +645,6 @@ ipv4eq(struct sockaddr_in *a, struct sockaddr_in *b)
        return (a->sin_addr.s_addr == b->sin_addr.s_addr);
 }
 
-#ifdef HAVE_IPV6
-
 static bool
 ipv6eq(struct sockaddr_in6 *a, struct sockaddr_in6 *b)
 {
@@ -658,7 +656,6 @@ ipv6eq(struct sockaddr_in6 *a, struct sockaddr_in6 *b)
 
        return true;
 }
-#endif                                                 /* HAVE_IPV6 */
 
 /*
  * Check whether host name matches pattern.
@@ -747,7 +744,6 @@ check_hostname(hbaPort *port, const char *hostname)
                                        break;
                                }
                        }
-#ifdef HAVE_IPV6
                        else if (gai->ai_addr->sa_family == AF_INET6)
                        {
                                if (ipv6eq((struct sockaddr_in6 *) gai->ai_addr,
@@ -757,7 +753,6 @@ check_hostname(hbaPort *port, const char *hostname)
                                        break;
                                }
                        }
-#endif
                }
        }
 
index de35fbba4555cd9a77fdde45e6f9ed1944c107e3..ff9dadfb37982f480d25f36da20ca3f53854e621 100644 (file)
@@ -34,11 +34,9 @@ static int   range_sockaddr_AF_INET(const struct sockaddr_in *addr,
                                                                   const struct sockaddr_in *netaddr,
                                                                   const struct sockaddr_in *netmask);
 
-#ifdef HAVE_IPV6
 static int     range_sockaddr_AF_INET6(const struct sockaddr_in6 *addr,
                                                                        const struct sockaddr_in6 *netaddr,
                                                                        const struct sockaddr_in6 *netmask);
-#endif
 
 
 /*
@@ -56,12 +54,10 @@ pg_range_sockaddr(const struct sockaddr_storage *addr,
                return range_sockaddr_AF_INET((const struct sockaddr_in *) addr,
                                                                          (const struct sockaddr_in *) netaddr,
                                                                          (const struct sockaddr_in *) netmask);
-#ifdef HAVE_IPV6
        else if (addr->ss_family == AF_INET6)
                return range_sockaddr_AF_INET6((const struct sockaddr_in6 *) addr,
                                                                           (const struct sockaddr_in6 *) netaddr,
                                                                           (const struct sockaddr_in6 *) netmask);
-#endif
        else
                return 0;
 }
@@ -78,9 +74,6 @@ range_sockaddr_AF_INET(const struct sockaddr_in *addr,
                return 0;
 }
 
-
-#ifdef HAVE_IPV6
-
 static int
 range_sockaddr_AF_INET6(const struct sockaddr_in6 *addr,
                                                const struct sockaddr_in6 *netaddr,
@@ -97,7 +90,6 @@ range_sockaddr_AF_INET6(const struct sockaddr_in6 *addr,
 
        return 1;
 }
-#endif                                                 /* HAVE_IPV6 */
 
 /*
  *     pg_sockaddr_cidr_mask - make a network mask of the appropriate family
@@ -147,7 +139,6 @@ pg_sockaddr_cidr_mask(struct sockaddr_storage *mask, char *numbits, int family)
                                break;
                        }
 
-#ifdef HAVE_IPV6
                case AF_INET6:
                        {
                                struct sockaddr_in6 mask6;
@@ -172,7 +163,7 @@ pg_sockaddr_cidr_mask(struct sockaddr_storage *mask, char *numbits, int family)
                                memcpy(mask, &mask6, sizeof(mask6));
                                break;
                        }
-#endif
+
                default:
                        return -1;
        }
@@ -207,13 +198,11 @@ run_ifaddr_callback(PgIfAddrCallback callback, void *cb_data,
                        if (((struct sockaddr_in *) mask)->sin_addr.s_addr == INADDR_ANY)
                                mask = NULL;
                }
-#ifdef HAVE_IPV6
                else if (mask->sa_family == AF_INET6)
                {
                        if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *) mask)->sin6_addr))
                                mask = NULL;
                }
-#endif
        }
 
        /* If mask is invalid, generate our own fully-set mask */
@@ -437,10 +426,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
 {
        struct sockaddr_in addr;
        struct sockaddr_storage mask;
-
-#ifdef HAVE_IPV6
        struct sockaddr_in6 addr6;
-#endif
 
        /* addr 127.0.0.1/8 */
        memset(&addr, 0, sizeof(addr));
@@ -452,7 +438,6 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
                                                (struct sockaddr *) &addr,
                                                (struct sockaddr *) &mask);
 
-#ifdef HAVE_IPV6
        /* addr ::1/128 */
        memset(&addr6, 0, sizeof(addr6));
        addr6.sin6_family = AF_INET6;
@@ -462,7 +447,6 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
        run_ifaddr_callback(callback, cb_data,
                                                (struct sockaddr *) &addr6,
                                                (struct sockaddr *) &mask);
-#endif
 
        return 0;
 }
index 7112e9751b17b5c23ccf9ea598de4ce6911c72b8..cba0caced73f0fac421c15de9b533ba8fc3de7fd 100644 (file)
@@ -413,11 +413,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
                        case AF_INET:
                                familyDesc = _("IPv4");
                                break;
-#ifdef HAVE_IPV6
                        case AF_INET6:
                                familyDesc = _("IPv6");
                                break;
-#endif
                        case AF_UNIX:
                                familyDesc = _("Unix");
                                break;
index ea1c7390d0d9017045bbe5f5f0ec29fe5d8287fe..6d580ea78f62eb9502b29f2da7828a6ecd75daf1 100644 (file)
@@ -1725,9 +1725,7 @@ inet_client_addr(PG_FUNCTION_ARGS)
        switch (port->raddr.addr.ss_family)
        {
                case AF_INET:
-#ifdef HAVE_IPV6
                case AF_INET6:
-#endif
                        break;
                default:
                        PG_RETURN_NULL();
@@ -1764,9 +1762,7 @@ inet_client_port(PG_FUNCTION_ARGS)
        switch (port->raddr.addr.ss_family)
        {
                case AF_INET:
-#ifdef HAVE_IPV6
                case AF_INET6:
-#endif
                        break;
                default:
                        PG_RETURN_NULL();
@@ -1801,9 +1797,7 @@ inet_server_addr(PG_FUNCTION_ARGS)
        switch (port->laddr.addr.ss_family)
        {
                case AF_INET:
-#ifdef HAVE_IPV6
                case AF_INET6:
-#endif
                        break;
                default:
                        PG_RETURN_NULL();
@@ -1840,9 +1834,7 @@ inet_server_port(PG_FUNCTION_ARGS)
        switch (port->laddr.addr.ss_family)
        {
                case AF_INET:
-#ifdef HAVE_IPV6
                case AF_INET6:
-#endif
                        break;
                default:
                        PG_RETURN_NULL();
@@ -2102,7 +2094,6 @@ inetmi(PG_FUNCTION_ARGS)
 void
 clean_ipv6_addr(int addr_family, char *addr)
 {
-#ifdef HAVE_IPV6
        if (addr_family == AF_INET6)
        {
                char       *pct = strchr(addr, '%');
@@ -2110,5 +2101,4 @@ clean_ipv6_addr(int addr_family, char *addr)
                if (pct)
                        *pct = '\0';
        }
-#endif
 }
index d9e2a79382964c210ecb0f6dae46b70971e2e52e..4cca30aae7ce3e383641ef730d2fc5b9d9bccfca 100644 (file)
@@ -735,11 +735,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
                        }
                        else
                        {
-                               if (beentry->st_clientaddr.addr.ss_family == AF_INET
-#ifdef HAVE_IPV6
-                                       || beentry->st_clientaddr.addr.ss_family == AF_INET6
-#endif
-                                       )
+                               if (beentry->st_clientaddr.addr.ss_family == AF_INET ||
+                                       beentry->st_clientaddr.addr.ss_family == AF_INET6)
                                {
                                        char            remote_host[NI_MAXHOST];
                                        char            remote_port[NI_MAXSERV];
@@ -1105,9 +1102,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
        switch (beentry->st_clientaddr.addr.ss_family)
        {
                case AF_INET:
-#ifdef HAVE_IPV6
                case AF_INET6:
-#endif
                        break;
                default:
                        PG_RETURN_NULL();
@@ -1152,9 +1147,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
        switch (beentry->st_clientaddr.addr.ss_family)
        {
                case AF_INET:
-#ifdef HAVE_IPV6
                case AF_INET6:
-#endif
                        break;
                case AF_UNIX:
                        PG_RETURN_INT32(-1);
index a779153c74e72fc0618a3751638df09be3844b77..29c28b73153ca591e9dc2a1e755e75ebd94b57eb 100644 (file)
@@ -1176,7 +1176,6 @@ setup_config(void)
 
        conflines = replace_token(conflines, "@remove-line-for-nolocal@", "");
 
-#ifdef HAVE_IPV6
 
        /*
         * Probe to see if there is really any platform support for IPv6, and
@@ -1218,15 +1217,6 @@ setup_config(void)
                                                                          "#host    replication     all             ::1");
                }
        }
-#else                                                  /* !HAVE_IPV6 */
-       /* If we didn't compile IPV6 support at all, always comment it out */
-       conflines = replace_token(conflines,
-                                                         "host    all             all             ::1",
-                                                         "#host    all             all             ::1");
-       conflines = replace_token(conflines,
-                                                         "host    replication     all             ::1",
-                                                         "#host    replication     all             ::1");
-#endif                                                 /* HAVE_IPV6 */
 
        /* Replace default authentication methods */
        conflines = replace_token(conflines,
index 109776e465be422a073a67b8112bec18e69d0e37..c5a80b829e70395951b633752c479bea9dad49f9 100644 (file)
 /* Define to 1 if you have the global variable 'int timezone'. */
 #undef HAVE_INT_TIMEZONE
 
-/* Define to 1 if you have support for IPv6. */
-#undef HAVE_IPV6
-
 /* Define to 1 if __builtin_constant_p(x) implies "i"(x) acceptance. */
 #undef HAVE_I_CONSTRAINT__BUILTIN_CONSTANT_P
 
index 3073c0307ebfa3774ffe50c9ae7d7c908e664cb8..b1ec9723dfbab5a1f2a072404dff6f8c175784cb 100644 (file)
@@ -31,8 +31,8 @@ typedef struct
  * We use these values for the "family" field.
  *
  * Referencing all of the non-AF_INET types to AF_INET lets us work on
- * machines which may not have the appropriate address family (like
- * inet6 addresses when AF_INET6 isn't present) but doesn't cause a
+ * machines which did not have the appropriate address family (like
+ * inet6 addresses when AF_INET6 wasn't present) but didn't cause a
  * dump/reload requirement.  Pre-7.4 databases used AF_INET for the family
  * type on disk.
  */
index 8cefef20d1e5059a33db3a5b15e15f8f333d08e1..917b19e0e9d8f5c0644ebb1f042d548c6e8b139c 100644 (file)
@@ -1652,7 +1652,6 @@ getHostaddr(PGconn *conn, char *host_addr, int host_addr_len)
                                                         host_addr, host_addr_len) == NULL)
                        host_addr[0] = '\0';
        }
-#ifdef HAVE_IPV6
        else if (addr->ss_family == AF_INET6)
        {
                if (pg_inet_net_ntop(AF_INET6,
@@ -1661,7 +1660,6 @@ getHostaddr(PGconn *conn, char *host_addr, int host_addr_len)
                                                         host_addr, host_addr_len) == NULL)
                        host_addr[0] = '\0';
        }
-#endif
        else
                host_addr[0] = '\0';
 }
index b8ad69c3909473fc1d5c56a985a42ab1a5e821a4..500c66dbf18e2be5d96580306fccda148c2f06cb 100644 (file)
@@ -80,15 +80,14 @@ pg_inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
         * We need to cover both the address family constants used by the PG inet
         * type (PGSQL_AF_INET and PGSQL_AF_INET6) and those used by the system
         * libraries (AF_INET and AF_INET6).  We can safely assume PGSQL_AF_INET
-        * == AF_INET, but the INET6 constants are very likely to be different. If
-        * AF_INET6 isn't defined, silently ignore it.
+        * == AF_INET, but the INET6 constants are very likely to be different.
         */
        switch (af)
        {
                case PGSQL_AF_INET:
                        return (inet_net_ntop_ipv4(src, bits, dst, size));
                case PGSQL_AF_INET6:
-#if defined(AF_INET6) && AF_INET6 != PGSQL_AF_INET6
+#if AF_INET6 != PGSQL_AF_INET6
                case AF_INET6:
 #endif
                        return (inet_net_ntop_ipv6(src, bits, dst, size));
index b8dbb8494557b38c0ea5a0f3d5d664f14517d02a..b9a1b7b5e84ec5362b01b803dd5065fdf095ce0b 100644 (file)
@@ -26,11 +26,9 @@ print_addr(struct sockaddr *addr)
                case AF_INET:
                        len = sizeof(struct sockaddr_in);
                        break;
-#ifdef HAVE_IPV6
                case AF_INET6:
                        len = sizeof(struct sockaddr_in6);
                        break;
-#endif
                default:
                        len = sizeof(struct sockaddr_storage);
                        break;
index a3da3f748a1522f37c5c2190bfb6405ec9d42c22..c2acb58df0e920948898ff77407e6f1a4d755225 100644 (file)
@@ -277,7 +277,6 @@ sub GenerateFiles
                HAVE_INTTYPES_H                             => undef,
                HAVE_INT_OPTERR                             => undef,
                HAVE_INT_OPTRESET                           => undef,
-               HAVE_IPV6                                   => 1,
                HAVE_I_CONSTRAINT__BUILTIN_CONSTANT_P       => undef,
                HAVE_KQUEUE                                 => undef,
                HAVE_LANGINFO_H                             => undef,