Enable IPv6 server support. From: Neil Brown define IPV6_SUPPORTED and enhance a few places to allow IPv6 addresses. Signed-off-by: NeilBrown --- support/export/client.c | 14 ++++++++++++++ support/export/hostname.c | 18 +++++++++++------- utils/mountd/cache.c | 6 +++--- utils/mountd/rmtab.c | 2 +- utils/nfsd/nfsd.c | 2 +- utils/nfsd/nfssvc.c | 2 +- 6 files changed, 31 insertions(+), 13 deletions(-) --- nfs-utils-1.2.1.orig/support/export/client.c +++ nfs-utils-1.2.1/support/export/client.c @@ -392,12 +392,26 @@ addrs_match4(const struct sockaddr *sa1, } static _Bool +addrs_match6(const struct sockaddr *sa1, const struct sockaddr *sa2) +{ + const struct sockaddr_in6 *si1 = (const struct sockaddr_in6 *)sa1; + const struct sockaddr_in6 *si2 = (const struct sockaddr_in6 *)sa2; + int i; + for (i=0; i<16; i++) + if (si1->sin6_addr.s6_addr[i] != si2->sin6_addr.s6_addr[i]) + return 0; + return 1; +} + +static _Bool addrs_match(const struct sockaddr *sa1, const struct sockaddr *sa2) { if (sa1->sa_family == sa2->sa_family) switch (sa1->sa_family) { case AF_INET: return addrs_match4(sa1, sa2); + case AF_INET6: + return addrs_match6(sa1, sa2); } return false; --- nfs-utils-1.2.1.orig/support/export/hostname.c +++ nfs-utils-1.2.1/support/export/hostname.c @@ -171,9 +171,11 @@ hostent_dup (struct hostent *hp) static socklen_t sockaddr_size(const struct sockaddr *sap) { - if (sap->sa_family != AF_INET) - return 0; - return (socklen_t)sizeof(struct sockaddr_in); + if (sap->sa_family == AF_INET) + return (socklen_t)sizeof(struct sockaddr_in); + if (sap->sa_family == AF_INET6) + return (socklen_t)sizeof(struct sockaddr_in6); + return 0; } #endif /* HAVE_GETNAMEINFO */ @@ -250,6 +252,7 @@ host_pton(const char *paddr) .ai_family = AF_UNSPEC, }; struct sockaddr_in sin; + struct sockaddr_in6 sin6; int error; /* @@ -262,7 +265,8 @@ host_pton(const char *paddr) * have a real AF_INET presentation address, before invoking * getaddrinfo(3) to generate the full addrinfo list. */ - if (inet_pton(AF_INET, paddr, &sin.sin_addr) == 0) + if (inet_pton(AF_INET, paddr, &sin.sin_addr) == 0 && + inet_pton(AF_INET6, paddr, &sin6.sin6_addr) == 0) return NULL; error = getaddrinfo(paddr, NULL, &hint, &ai); @@ -301,7 +305,7 @@ host_addrinfo(const char *hostname) { struct addrinfo *ai = NULL; struct addrinfo hint = { - .ai_family = AF_INET, + .ai_family = AF_UNSPEC, /* don't return duplicates */ .ai_protocol = (int)IPPROTO_UDP, .ai_flags = AI_ADDRCONFIG | AI_CANONNAME, @@ -432,7 +436,7 @@ struct addrinfo * host_numeric_addrinfo(const struct sockaddr *sap) { socklen_t salen = sockaddr_size(sap); - char buf[INET_ADDRSTRLEN]; + char buf[INET6_ADDRSTRLEN]; struct addrinfo *ai; int error; @@ -481,7 +485,7 @@ host_numeric_addrinfo(const struct socka { const struct sockaddr_in *sin = (const struct sockaddr_in *)sap; const struct in_addr *addr = &sin->sin_addr; - char buf[INET_ADDRSTRLEN]; + char buf[INET6_ADDRSTRLEN]; struct addrinfo *ai; if (sap->sa_family != AF_INET) --- nfs-utils-1.2.1.orig/utils/mountd/cache.c +++ nfs-utils-1.2.1/utils/mountd/cache.c @@ -75,7 +75,7 @@ void auth_unix_ip(FILE *f) */ char *cp; char class[20]; - char ipaddr[20]; + char ipaddr[60]; char *client = NULL; struct addrinfo *tmp = NULL; struct addrinfo *ai = NULL; @@ -90,7 +90,7 @@ void auth_unix_ip(FILE *f) strcmp(class, "nfsd") != 0) return; - if (qword_get(&cp, ipaddr, 20) <= 0) + if (qword_get(&cp, ipaddr, 60) <= 0) return; tmp = host_pton(ipaddr); @@ -867,7 +867,7 @@ int cache_export_ent(char *domain, struc int cache_export(nfs_export *exp, char *path) { - char buf[INET_ADDRSTRLEN]; + char buf[INET6_ADDRSTRLEN]; int err; FILE *f; --- nfs-utils-1.2.1.orig/utils/mountd/rmtab.c +++ nfs-utils-1.2.1/utils/mountd/rmtab.c @@ -142,7 +142,7 @@ mountlist_del_all(struct sockaddr_in *si return; hostname = host_canonname((struct sockaddr *)sin); if (hostname == NULL) { - char buf[INET_ADDRSTRLEN]; + char buf[INET6_ADDRSTRLEN]; xlog(L_ERROR, "can't get hostname of %s", host_ntop((struct sockaddr *)sin, buf, sizeof(buf))); goto out_unlock; --- nfs-utils-1.2.1.orig/utils/nfsd/nfsd.c +++ nfs-utils-1.2.1/utils/nfsd/nfsd.c @@ -34,7 +34,7 @@ * now, hardcode the IPv6 switch into the off position until the other daemons * are functional. */ -#undef IPV6_SUPPORTED +#define IPV6_SUPPORTED static void usage(const char *); --- nfs-utils-1.2.1.orig/utils/nfsd/nfssvc.c +++ nfs-utils-1.2.1/utils/nfsd/nfssvc.c @@ -29,7 +29,7 @@ * now, hardcode the IPv6 switch into the off position until the other daemons * are functional. */ -#undef IPV6_SUPPORTED +#define IPV6_SUPPORTED #define NFSD_PORTS_FILE "/proc/fs/nfsd/portlist" #define NFSD_VERS_FILE "/proc/fs/nfsd/versions"