From: Chuck Lever <chuck.lever@oracle.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 03/31] getport: Remove AI_ADDRCONFIG from nfs_gp_loopback_address()
Date: Mon, 29 Jun 2009 13:35:17 -0400 [thread overview]
Message-ID: <20090629173516.2076.8213.stgit@matisse.1015granger.net> (raw)
In-Reply-To: <20090629172704.2076.45402.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
AI_ADDRCONFIG was used ostensibly to figure out if the local system
had IPv6 available when generating a loopback address.
A legacy version of nfs_gp_loopback_address() was created to handle
ANYADDR address generation for old versions of glibc where
AI_ADDRCONFIG doesn't exist. This means we have to be careful to
test both the normal and legacy versions when committing changes in
this area.
But it turns out that even contemporary versions of glibc ignore
AI_ADDRCONFIG when the hostname string is NULL. getaddrinfo(3)
always returns an AF_INET and an AF_INET6 loopback address in this
case, no matter how the system is configured.
Change nfs_gp_loopback_address() to have one version that simply looks
up "localhost" instead of doing anything fancy. If "localhost" is an
IPv6 address, we'll use that. Otherwise, it should nearly always be
an AF_INET loopback address.
This eliminates the need for AI_ADDRCONFIG, and removes the duplicate
version of nfs_gp_loopback_address(). Note that callers never used
the port number in the returned socket address, so get rid of the
"sunrpc" service string too.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
support/nfs/getport.c | 54 +++++++++----------------------------------------
1 files changed, 10 insertions(+), 44 deletions(-)
diff --git a/support/nfs/getport.c b/support/nfs/getport.c
index 2b80dce..9d85e89 100644
--- a/support/nfs/getport.c
+++ b/support/nfs/getport.c
@@ -65,59 +65,32 @@ static const rpcvers_t default_rpcb_version = RPCBVERS_4;
static const rpcvers_t default_rpcb_version = PMAPVERS;
#endif /* !HAVE_LIBTIRPC */
-#ifdef HAVE_DECL_AI_ADDRCONFIG
/*
- * getaddrinfo(3) generates a usable loopback address based on how the
- * local network interfaces are configured. RFC 3484 requires that the
- * results are sorted so that the first result has the best likelihood
- * of working, so we try just that first result.
+ * There's no easy way to tell how the local system's networking
+ * and rpcbind is configured (ie. whether we want to use IPv6 or
+ * IPv4 loopback to contact RPC services on the local host). We
+ * punt and simply try to look up "localhost".
*
* Returns TRUE on success.
*/
static int nfs_gp_loopback_address(struct sockaddr *sap, socklen_t *salen)
{
struct addrinfo *gai_results;
- struct addrinfo gai_hint = {
- .ai_flags = AI_ADDRCONFIG,
- };
- socklen_t len = *salen;
int ret = 0;
- if (getaddrinfo(NULL, "sunrpc", &gai_hint, &gai_results))
+ if (getaddrinfo("localhost", NULL, NULL, &gai_results))
return 0;
- switch (gai_results->ai_addr->sa_family) {
- case AF_INET:
- case AF_INET6:
- if (len >= gai_results->ai_addrlen) {
- memcpy(sap, gai_results->ai_addr,
- gai_results->ai_addrlen);
- *salen = gai_results->ai_addrlen;
- ret = 1;
- }
+ if (*salen >= gai_results->ai_addrlen) {
+ memcpy(sap, gai_results->ai_addr,
+ gai_results->ai_addrlen);
+ *salen = gai_results->ai_addrlen;
+ ret = 1;
}
freeaddrinfo(gai_results);
return ret;
}
-#else
-/*
- * Old versions of getaddrinfo(3) don't support AI_ADDRCONFIG, so we
- * have a fallback for building on legacy systems.
- */
-static int nfs_gp_loopback_address(struct sockaddr *sap, socklen_t *salen)
-{
- struct sockaddr_in *sin = (struct sockaddr_in *)sap;
-
- memset(sin, 0, sizeof(*sin));
-
- sin->sin_family = AF_INET;
- sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- *salen = sizeof(*sin);
-
- return 1;
-}
-#endif
/*
* Plant port number in @sap. @port is already in network byte order.
@@ -839,13 +812,6 @@ int nfs_getport_ping(struct sockaddr *sap, const socklen_t salen,
* isn't listening on /var/run/rpcbind.sock), send a query via UDP to localhost
* (UDP doesn't leave a socket in TIME_WAIT, and the timeout is a relatively
* short 3 seconds).
- *
- * getaddrinfo(3) generates a usable loopback address. RFC 3484 requires that
- * the results are sorted so that the first result has the best likelihood of
- * working, so we try just that first result. If IPv6 is all that is
- * available, we are sure to generate an AF_INET6 loopback address and use
- * rpcbindv4/v3 GETADDR. AF_INET6 requests go via rpcbind v4/3 in order to
- * detect if the requested RPC service supports AF_INET6 or not.
*/
unsigned short nfs_getlocalport(const rpcprot_t program,
const rpcvers_t version,
next prev parent reply other threads:[~2009-06-29 17:35 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-29 17:34 [PATCH 00/31] mount.nfs patches for next nfs-utils release Chuck Lever
[not found] ` <20090629172704.2076.45402.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
2009-06-29 17:34 ` [PATCH 01/31] getport: RPCB_GETADDR r_owner should be an empty string Chuck Lever
2009-06-29 17:35 ` [PATCH 02/31] getport: RPCB_GETADDR's r_addr should contain rpcbind port, not zero Chuck Lever
2009-06-29 17:35 ` Chuck Lever [this message]
2009-06-29 17:35 ` [PATCH 04/31] getport: replace getnameinfo(NI_NUMERICHOST) with inet_ntop(3) Chuck Lever
2009-06-29 17:35 ` [PATCH 05/31] getport: Remove unneeded @salen arguments Chuck Lever
2009-06-29 17:35 ` [PATCH 06/31] New versions of libtool add extra aclocal scripts Chuck Lever
2009-06-29 17:35 ` [PATCH 07/31] support: Use HAVE_LIBTIRPC to switch in bindresvport_sa(3t) Chuck Lever
2009-06-29 17:36 ` [PATCH 08/31] support: Don't return RPC_UNKNOWNHOST from rpc_socket.c Chuck Lever
2009-06-29 17:36 ` [PATCH 09/31] support: Set proper retransmit timeout for datagram transports Chuck Lever
2009-06-29 17:36 ` [PATCH 10/31] getport: RPC_PROGNOTREGISTERED is a permanent error Chuck Lever
2009-06-29 17:36 ` [PATCH 11/31] getport: Clear shared error fields before trying rpcbind queries Chuck Lever
2009-06-29 17:36 ` [PATCH 12/31] mount.nfs: Add more debugging output around nfs_getport() Chuck Lever
2009-06-29 17:36 ` [PATCH 13/31] getport: Restore historical TCP connect timeout error code Chuck Lever
2009-06-29 17:37 ` [PATCH 14/31] getport: Convert TCP connection refused to RPC_CANTRECV Chuck Lever
2009-06-29 17:37 ` [PATCH 15/31] mount.nfs: If port= specifies an unregistered port, retry, then fail Chuck Lever
2009-06-29 17:37 ` [PATCH 16/31] mount.nfs: force rpcbind queries if options aren't specified Chuck Lever
2009-06-29 17:37 ` [PATCH 17/31] mount.nfs: make nfs_options2pmap return errors Chuck Lever
2009-06-29 17:37 ` [PATCH 18/31] mount.nfs: rearchitect mount version/protocol negotiation logic Chuck Lever
2009-06-29 17:37 ` [PATCH 19/31] mount.nfs: Clean up nfs_is_permanent_error() Chuck Lever
2009-06-29 17:37 ` [PATCH 20/31] mount.nfs: Clean up after restructuring version/protocol negotiation Chuck Lever
2009-06-29 17:38 ` [PATCH 21/31] mount.nfs: Don't update extra_opts after text-based negotiation Chuck Lever
2009-06-29 17:38 ` [PATCH 22/31] support: Introduce sockaddr helpers to get and set IP port numbers Chuck Lever
2009-06-29 17:38 ` [PATCH 23/31] mount.nfs: Use correct data type in discover_nfs_mount_data_version() Chuck Lever
2009-06-29 17:38 ` [PATCH 24/31] mount.nfs: Remove unused parameter in try_mount() Chuck Lever
2009-06-29 17:38 ` [PATCH 25/31] mount.nfs: Fix some nfs_error() nits in network.c Chuck Lever
2009-06-29 17:39 ` [PATCH 26/31] mount.nfs: Remove unused @salen parameter from nfs_ca_gai() Chuck Lever
2009-06-29 17:39 ` [PATCH 27/31] mount.nfs: remove unused @addrlen argument from nfs_string_to_sockaddr() Chuck Lever
2009-06-29 17:39 ` [PATCH 28/31] umount.nfs: Use correct data type in nfsumount() Chuck Lever
2009-06-29 17:39 ` [PATCH 29/31] mount.nfs: Fix compiler warning in stropts.c Chuck Lever
2009-06-29 17:39 ` [PATCH 30/31] mount.nfs: Squelch unused parameter warnings on empty functions Chuck Lever
2009-06-29 17:39 ` [PATCH 31/31] mount.nfs: Squelch compiler warnings in nfs_strerror() Chuck Lever
2009-07-15 13:50 ` [PATCH 00/31] mount.nfs patches for next nfs-utils release Steve Dickson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090629173516.2076.8213.stgit@matisse.1015granger.net \
--to=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox