Return-Path: Received: from mx141.netapp.com ([216.240.21.12]:19225 "EHLO mx141.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751663AbdI1RaE (ORCPT ); Thu, 28 Sep 2017 13:30:04 -0400 From: Olga Kornievskaia To: CC: Subject: [PATCH v4 1/8] NFSD fill-in netloc4 structure Date: Thu, 28 Sep 2017 13:29:55 -0400 Message-ID: <20170928173002.50818-2-kolga@netapp.com> In-Reply-To: <20170928173002.50818-1-kolga@netapp.com> References: <20170928173002.50818-1-kolga@netapp.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-nfs-owner@vger.kernel.org List-ID: nfs.4 defines nfs42_netaddr structure that represents netloc4. Populate needed fields from the sockaddr structure. This will be used by flexfiles and 4.2 inter copy Signed-off-by: Olga Kornievskaia --- fs/nfsd/nfsd.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index b9c538a..2fc3030 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -17,7 +17,7 @@ #include #include #include - +#include #include #include "stats.h" @@ -364,6 +364,35 @@ static inline bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) extern const u32 nfsd_suppattrs[3][3]; +static inline u32 nfsd4_set_netaddr(struct sockaddr *addr, struct nfs42_netaddr *netaddr) +{ + struct sockaddr_in *sin = (struct sockaddr_in *)addr; + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr; + unsigned int port; + size_t ret; + + switch (addr->sa_family) { + case AF_INET: + port = ntohs(sin->sin_port); + sprintf(netaddr->netid, "tcp"); + netaddr->netid_len = 3; + break; + case AF_INET6: + port = ntohs(sin6->sin6_port); + sprintf(netaddr->netid, "tcp6"); + netaddr->netid_len = 4; + break; + default: + return nfserrno(-EINVAL); + } + ret = rpc_ntop(addr, netaddr->addr, sizeof(netaddr->addr)); + netaddr->addr_len = ret + snprintf(netaddr->addr + ret, + RPCBIND_MAXUADDRLEN + 1, + ".%u.%u", port >> 8, port & 0xff); + + return 0; +} + static inline bool bmval_is_subset(const u32 *bm1, const u32 *bm2) { return !((bm1[0] & ~bm2[0]) || -- 1.8.3.1