Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Oct 2017 22:22:28 +0000 (UTC)
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r324639 - head/sys/fs/nfsserver
Message-ID:  <201710152222.v9FMMSNp051485@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rmacklem
Date: Sun Oct 15 22:22:27 2017
New Revision: 324639
URL: https://svnweb.freebsd.org/changeset/base/324639

Log:
  Fix the client IP address reported by nfsdumpstate for 64bit arch and NFSv4.1.
  
  The client IP address was not being reported for some NFSv4 mounts by
  nfsdumpstate. Upon investigation, two problems were found for mounts
  using IPv4. One was that the code (originally written and tested on i386)
  assumed that a "u_long" was a "uint32_t" and would exactly store an
  IPv4 host address. Not correct for 64bit arches.
  Also, for NFSv4.1 mounts, the field was not being filled in. This was
  basically correct, because NFSv4.1 does not use a callback address.
  However, it meant that nfsdumpstate could not report the client IP addr.
  This patch should fix both of these issues.
  For IPv6, the address will still not be reported. The original NFSv4 RFC
  only specified IPv4 callback addresses. I think this has changed and, if so,
  a future commit to fix reporting of IPv6 addresses will be needed.
  
  Reported by:	manu
  PR:		223036
  MFC after:	2 weeks

Modified:
  head/sys/fs/nfsserver/nfs_nfsdserv.c
  head/sys/fs/nfsserver/nfs_nfsdstate.c

Modified: head/sys/fs/nfsserver/nfs_nfsdserv.c
==============================================================================
--- head/sys/fs/nfsserver/nfs_nfsdserv.c	Sun Oct 15 19:33:30 2017	(r324638)
+++ head/sys/fs/nfsserver/nfs_nfsdserv.c	Sun Oct 15 22:22:27 2017	(r324639)
@@ -3729,6 +3729,7 @@ nfsrvd_exchangeid(struct nfsrv_descript *nd, __unused 
 	uint32_t sp4type, v41flags;
 	uint64_t owner_minor;
 	struct timespec verstime;
+	struct sockaddr_in *sad, *rad;
 
 	if (nfs_rootfhset == 0 || nfsd_checkrootexp(nd) != 0) {
 		nd->nd_repstat = NFSERR_WRONGSEC;
@@ -3752,6 +3753,13 @@ nfsrvd_exchangeid(struct nfsrv_descript *nd, __unused 
 	NFSINITSOCKMUTEX(&clp->lc_req.nr_mtx);
 	NFSSOCKADDRALLOC(clp->lc_req.nr_nam);
 	NFSSOCKADDRSIZE(clp->lc_req.nr_nam, sizeof (struct sockaddr_in));
+	sad = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in *);
+	rad = NFSSOCKADDR(clp->lc_req.nr_nam, struct sockaddr_in *);
+	rad->sin_family = AF_INET;
+	rad->sin_addr.s_addr = 0;
+	rad->sin_port = 0;
+	if (sad->sin_family == AF_INET)
+		rad->sin_addr.s_addr = sad->sin_addr.s_addr;
 	clp->lc_req.nr_cred = NULL;
 	NFSBCOPY(verf, clp->lc_verf, NFSX_VERF);
 	clp->lc_idlen = idlen;

Modified: head/sys/fs/nfsserver/nfs_nfsdstate.c
==============================================================================
--- head/sys/fs/nfsserver/nfs_nfsdstate.c	Sun Oct 15 19:33:30 2017	(r324638)
+++ head/sys/fs/nfsserver/nfs_nfsdstate.c	Sun Oct 15 22:22:27 2017	(r324639)
@@ -3891,11 +3891,11 @@ nfsrv_getclientipaddr(struct nfsrv_descript *nd, struc
 	u_char protocol[5], addr[24];
 	int error = 0, cantparse = 0;
 	union {
-		u_long ival;
+		in_addr_t ival;
 		u_char cval[4];
 	} ip;
 	union {
-		u_short sval;
+		in_port_t sval;
 		u_char cval[2];
 	} port;
 
@@ -3989,8 +3989,10 @@ nfsrv_getclientipaddr(struct nfsrv_descript *nd, struc
 	}
 	if (cantparse) {
 		sad = NFSSOCKADDR(nd->nd_nam, struct sockaddr_in *);
-		rad->sin_addr.s_addr = sad->sin_addr.s_addr;
-		rad->sin_port = 0x0;
+		if (sad->sin_family == AF_INET) {
+			rad->sin_addr.s_addr = sad->sin_addr.s_addr;
+			rad->sin_port = 0x0;
+		}
 		clp->lc_program = 0;
 	}
 nfsmout:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201710152222.v9FMMSNp051485>