Remove configure probe for sockaddr_in6 and require AF_INET6.

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 <andres@anarazel.de>
Discussion: https://postgr.es/m/CA+hUKGKErNfhmvb_H0UprEmp4LPzGN06yR2_0tYikjzB-2ECMw@mail.gmail.com
This commit is contained in:
Thomas Munro 2022-08-26 10:13:22 +12:00
parent 28ec316787
commit bcc8b14ef6
16 changed files with 7 additions and 105 deletions

10
configure vendored
View File

@ -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 :

View 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>

View 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>

View 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;
}

View 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
}
}

View 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;
}

View 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;

View 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
}

View 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);

View 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,

View File

@ -241,9 +241,6 @@
/* 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

View 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.
*/

View 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';
}

View 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));

View 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;

View 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,