From owner-svn-src-projects@freebsd.org Fri Jun 29 22:07:26 2018 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A818CF7EBC1 for ; Fri, 29 Jun 2018 22:07:26 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 59C867E3CE; Fri, 29 Jun 2018 22:07:26 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3632526B55; Fri, 29 Jun 2018 22:07:26 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5TM7Q8a052771; Fri, 29 Jun 2018 22:07:26 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5TM7QX9052770; Fri, 29 Jun 2018 22:07:26 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201806292207.w5TM7QX9052770@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Fri, 29 Jun 2018 22:07:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r335806 - projects/pnfs-planb-server/usr.sbin/nfsd X-SVN-Group: projects X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: projects/pnfs-planb-server/usr.sbin/nfsd X-SVN-Commit-Revision: 335806 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jun 2018 22:07:26 -0000 Author: rmacklem Date: Fri Jun 29 22:07:25 2018 New Revision: 335806 URL: https://svnweb.freebsd.org/changeset/base/335806 Log: Add support for IPv6 addresses to the "-p" option for the pNFS server DS specifications. Modified: projects/pnfs-planb-server/usr.sbin/nfsd/nfsd.c Modified: projects/pnfs-planb-server/usr.sbin/nfsd/nfsd.c ============================================================================== --- projects/pnfs-planb-server/usr.sbin/nfsd/nfsd.c Fri Jun 29 21:15:26 2018 (r335805) +++ projects/pnfs-planb-server/usr.sbin/nfsd/nfsd.c Fri Jun 29 22:07:25 2018 (r335806) @@ -1177,14 +1177,16 @@ backup_stable(__unused int signo) static void parse_dsserver(const char *optionarg, struct nfsd_nfsd_args *nfsdargp) { - char *ad, *cp, *cp2, *dsaddr, *dshost, *dspath, *dsvol, nfsprt[9]; - char *mdspath, *mdsp; + char *cp, *cp2, *dsaddr, *dshost, *dspath, *dsvol, nfsprt[9]; + char *mdspath, *mdsp, ip6[INET6_ADDRSTRLEN]; + const char *ad; int ecode; u_int adsiz, dsaddrcnt, dshostcnt, dspathcnt, hostsiz, pathsiz; u_int mdspathcnt; size_t dsaddrsiz, dshostsiz, dspathsiz, nfsprtsiz, mdspathsiz; - struct addrinfo hints, *ai_tcp; + struct addrinfo hints, *ai_tcp, *res; struct sockaddr_in sin; + struct sockaddr_in6 sin6; cp = strdup(optionarg); if (cp == NULL) @@ -1273,22 +1275,45 @@ parse_dsserver(const char *optionarg, struct nfsd_nfsd /* Get the fully qualified domain name and IP address. */ memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_CANONNAME; - hints.ai_family = AF_INET; + hints.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; + hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; ecode = getaddrinfo(cp, NULL, &hints, &ai_tcp); if (ecode != 0) err(1, "getaddrinfo pnfs: %s %s", cp, gai_strerror(ecode)); - if (ai_tcp->ai_addr->sa_family != AF_INET || - ai_tcp->ai_addrlen < sizeof(sin)) - err(1, "getaddrinfo() returned non-INET address"); - /* Mips cares about sockaddr_in alignment, so copy the addr. */ - memcpy(&sin, ai_tcp->ai_addr, sizeof(sin)); + ad = NULL; + for (res = ai_tcp; res != NULL; res = res->ai_next) { + if (res->ai_addr->sa_family == AF_INET) { + if (res->ai_addrlen < sizeof(sin)) + err(1, "getaddrinfo() returned " + "undersized IPv4 address"); + /* + * Mips cares about sockaddr_in alignment, + * so copy the address. + */ + memcpy(&sin, res->ai_addr, sizeof(sin)); + ad = inet_ntoa(sin.sin_addr); + break; + } else if (res->ai_family == AF_INET6) { + if (res->ai_addrlen < sizeof(sin6)) + err(1, "getaddrinfo() returned " + "undersized IPv6 address"); + /* + * Mips cares about sockaddr_in6 alignment, + * so copy the address. + */ + memcpy(&sin6, res->ai_addr, sizeof(sin6)); + ad = inet_ntop(AF_INET6, &sin6.sin6_addr, ip6, + sizeof(ip6)); + break; + } + } + if (ad == NULL) + err(1, "No IP address for %s", cp); /* Append this address to dsaddr. */ - ad = inet_ntoa(sin.sin_addr); adsiz = strlen(ad); if (dsaddrcnt + adsiz + nfsprtsiz + 1 > dsaddrsiz) { dsaddrsiz *= 2;