Commit 91c7a905 authored by Chuck Lever's avatar Chuck Lever

NFSD: Clean up nfsd4_do_encode_secinfo()

Refactor nfsd4_encode_secinfo() so it is more clear what XDR data
item is being encoded by which piece of code.
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent d38e570f
...@@ -4555,14 +4555,35 @@ nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, ...@@ -4555,14 +4555,35 @@ nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr,
return nfsd4_encode_change_info4(xdr, &rename->rn_tinfo); return nfsd4_encode_change_info4(xdr, &rename->rn_tinfo);
} }
static __be32
nfsd4_encode_rpcsec_gss_info(struct xdr_stream *xdr,
struct rpcsec_gss_info *info)
{
__be32 status;
/* oid */
if (xdr_stream_encode_opaque(xdr, info->oid.data, info->oid.len) < 0)
return nfserr_resource;
/* qop */
status = nfsd4_encode_qop4(xdr, info->qop);
if (status != nfs_ok)
return status;
/* service */
if (xdr_stream_encode_u32(xdr, info->service) != XDR_UNIT)
return nfserr_resource;
return nfs_ok;
}
static __be32 static __be32
nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
{ {
u32 i, nflavs, supported; u32 i, nflavs, supported;
struct exp_flavor_info *flavs; struct exp_flavor_info *flavs;
struct exp_flavor_info def_flavs[2]; struct exp_flavor_info def_flavs[2];
__be32 *p, *flavorsp;
static bool report = true; static bool report = true;
__be32 *flavorsp;
__be32 status;
if (exp->ex_nflavors) { if (exp->ex_nflavors) {
flavs = exp->ex_flavors; flavs = exp->ex_flavors;
...@@ -4585,10 +4606,9 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) ...@@ -4585,10 +4606,9 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
} }
supported = 0; supported = 0;
p = xdr_reserve_space(xdr, 4); flavorsp = xdr_reserve_space(xdr, XDR_UNIT);
if (!p) if (!flavorsp)
return nfserr_resource; return nfserr_resource;
flavorsp = p++; /* to be backfilled later */
for (i = 0; i < nflavs; i++) { for (i = 0; i < nflavs; i++) {
rpc_authflavor_t pf = flavs[i].pseudoflavor; rpc_authflavor_t pf = flavs[i].pseudoflavor;
...@@ -4596,20 +4616,22 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) ...@@ -4596,20 +4616,22 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
if (rpcauth_get_gssinfo(pf, &info) == 0) { if (rpcauth_get_gssinfo(pf, &info) == 0) {
supported++; supported++;
p = xdr_reserve_space(xdr, 4 + 4 +
XDR_LEN(info.oid.len) + 4 + 4); /* flavor */
if (!p) status = nfsd4_encode_uint32_t(xdr, RPC_AUTH_GSS);
return nfserr_resource; if (status != nfs_ok)
*p++ = cpu_to_be32(RPC_AUTH_GSS); return status;
p = xdr_encode_opaque(p, info.oid.data, info.oid.len); /* flavor_info */
*p++ = cpu_to_be32(info.qop); status = nfsd4_encode_rpcsec_gss_info(xdr, &info);
*p++ = cpu_to_be32(info.service); if (status != nfs_ok)
return status;
} else if (pf < RPC_AUTH_MAXFLAVOR) { } else if (pf < RPC_AUTH_MAXFLAVOR) {
supported++; supported++;
p = xdr_reserve_space(xdr, 4);
if (!p) /* flavor */
return nfserr_resource; status = nfsd4_encode_uint32_t(xdr, pf);
*p++ = cpu_to_be32(pf); if (status != nfs_ok)
return status;
} else { } else {
if (report) if (report)
pr_warn("NFS: SECINFO: security flavor %u " pr_warn("NFS: SECINFO: security flavor %u "
...@@ -4619,7 +4641,7 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) ...@@ -4619,7 +4641,7 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
if (nflavs != supported) if (nflavs != supported)
report = false; report = false;
*flavorsp = htonl(supported); *flavorsp = cpu_to_be32(supported);
return 0; return 0;
} }
......
...@@ -96,6 +96,7 @@ nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val) ...@@ -96,6 +96,7 @@ nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val)
#define nfsd4_encode_count4(x, v) nfsd4_encode_uint32_t(x, v) #define nfsd4_encode_count4(x, v) nfsd4_encode_uint32_t(x, v)
#define nfsd4_encode_mode4(x, v) nfsd4_encode_uint32_t(x, v) #define nfsd4_encode_mode4(x, v) nfsd4_encode_uint32_t(x, v)
#define nfsd4_encode_nfs_lease4(x, v) nfsd4_encode_uint32_t(x, v) #define nfsd4_encode_nfs_lease4(x, v) nfsd4_encode_uint32_t(x, v)
#define nfsd4_encode_qop4(x, v) nfsd4_encode_uint32_t(x, v)
#define nfsd4_encode_sequenceid4(x, v) nfsd4_encode_uint32_t(x, v) #define nfsd4_encode_sequenceid4(x, v) nfsd4_encode_uint32_t(x, v)
#define nfsd4_encode_slotid4(x, v) nfsd4_encode_uint32_t(x, v) #define nfsd4_encode_slotid4(x, v) nfsd4_encode_uint32_t(x, v)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment