public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 12/12] libexport.a: Enable IPv6 support in hostname.c
Date: Mon, 13 Sep 2010 13:23:02 -0400	[thread overview]
Message-ID: <20100913172302.19017.47401.stgit@seurat.1015granger.net> (raw)
In-Reply-To: <20100913171844.19017.13446.stgit@seurat.1015granger.net>

If --enable-ipv6 is specified when building nfs-utils, libexport's
host_foo() helpers can now return both IPv4 and IPv6 addresses.

This means IPv6 presentation addresses and IPv6 DNS resolution
results are handled properly in the mountd cache and /etc/exports,
but does not yet enable IPv6 mountd listeners.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 support/export/hostname.c |   31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/support/export/hostname.c b/support/export/hostname.c
index 232e040..3c55ce7 100644
--- a/support/export/hostname.c
+++ b/support/export/hostname.c
@@ -34,16 +34,6 @@
 #define AI_ADDRCONFIG	0
 #endif
 
-#ifdef HAVE_GETNAMEINFO
-static socklen_t
-sockaddr_size(const struct sockaddr *sap)
-{
-	if (sap->sa_family != AF_INET)
-		return 0;
-	return (socklen_t)sizeof(struct sockaddr_in);
-}
-#endif	/* HAVE_GETNAMEINFO */
-
 /**
  * host_ntop - generate presentation address given a sockaddr
  * @sap: pointer to socket address
@@ -56,7 +46,7 @@ sockaddr_size(const struct sockaddr *sap)
 char *
 host_ntop(const struct sockaddr *sap, char *buf, const size_t buflen)
 {
-	socklen_t salen = sockaddr_size(sap);
+	socklen_t salen = nfs_sockaddr_length(sap);
 	int error;
 
 	memset(buf, 0, buflen);
@@ -117,7 +107,7 @@ host_pton(const char *paddr)
 		.ai_family	= AF_UNSPEC,
 	};
 	struct sockaddr_in sin;
-	int error;
+	int error, inet4;
 
 	/*
 	 * Although getaddrinfo(3) is easier to use and supports
@@ -129,12 +119,17 @@ host_pton(const char *paddr)
 	 * have a real AF_INET presentation address, before invoking
 	 * getaddrinfo(3) to generate the full addrinfo list.
 	 */
+	inet4 = 1;
 	if (inet_pton(AF_INET, paddr, &sin.sin_addr) == 0)
-		return NULL;
+		inet4 = 0;
 
 	error = getaddrinfo(paddr, NULL, &hint, &ai);
 	switch (error) {
 	case 0:
+		if (!inet4 && ai->ai_addr->sa_family == AF_INET) {
+			freeaddrinfo(ai);
+			break;
+		}
 		return ai;
 	case EAI_NONAME:
 		if (paddr == NULL)
@@ -168,7 +163,11 @@ host_addrinfo(const char *hostname)
 {
 	struct addrinfo *ai = NULL;
 	struct addrinfo hint = {
+#ifdef IPV6_SUPPORTED
+		.ai_family	= AF_UNSPEC,
+#else
 		.ai_family	= AF_INET,
+#endif
 		/* don't return duplicates */
 		.ai_protocol	= (int)IPPROTO_UDP,
 		.ai_flags	= AI_ADDRCONFIG | AI_CANONNAME,
@@ -208,7 +207,7 @@ __attribute_malloc__
 char *
 host_canonname(const struct sockaddr *sap)
 {
-	socklen_t salen = sockaddr_size(sap);
+	socklen_t salen = nfs_sockaddr_length(sap);
 	char buf[NI_MAXHOST];
 	int error;
 
@@ -298,8 +297,8 @@ __attribute_malloc__
 struct addrinfo *
 host_numeric_addrinfo(const struct sockaddr *sap)
 {
-	socklen_t salen = sockaddr_size(sap);
-	char buf[INET_ADDRSTRLEN];
+	socklen_t salen = nfs_sockaddr_length(sap);
+	char buf[INET6_ADDRSTRLEN];
 	struct addrinfo *ai;
 	int error;
 


  parent reply	other threads:[~2010-09-13 17:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-13 17:20 [PATCH 00/12] Next series of mountd IPv6 support patches Chuck Lever
2010-09-13 17:20 ` [PATCH 01/12] libnfs.a: Fix API for getfh() & friends Chuck Lever
2010-09-13 17:21 ` [PATCH 02/12] mountd: add IPv6 support in auth_authenticate() Chuck Lever
2010-09-13 17:21 ` [PATCH 03/12] mountd: Support IPv6 in mountd's svc routines Chuck Lever
2010-09-13 17:21 ` [PATCH 04/12] mountd: support IPv6 in mountlist_del_all() Chuck Lever
2010-09-13 17:21 ` [PATCH 05/12] mountd: Add mountlist_freeall() Chuck Lever
2010-09-13 17:22 ` [PATCH 06/12] mountd: Handle memory exhaustion in mountlist_list() Chuck Lever
2010-09-13 17:22 ` [PATCH 07/12] mountd: Support IPv6 " Chuck Lever
2010-09-13 17:22 ` [PATCH 08/12] exportfs: Enable IPv6 support in matchhostname() Chuck Lever
2010-09-13 17:22 ` [PATCH 09/12] mountd: clean up cache API Chuck Lever
2010-09-13 17:22 ` [PATCH 10/12] mountd: Handle IPv6 addresses in kernel auth_unix_ip upcalls Chuck Lever
2010-09-13 17:22 ` [PATCH 11/12] mountd: Ensure cache downcall can handle IPv6 addresses Chuck Lever
2010-09-13 17:23 ` Chuck Lever [this message]
     [not found] ` <20100913171844.19017.13446.stgit-x+BlCsqV7M/wdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2010-09-16 21:29   ` [PATCH 00/12] Next series of mountd IPv6 support patches 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=20100913172302.19017.47401.stgit@seurat.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