Skip to content

Commit 91c7a90

Browse files
committed
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: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent d38e570 commit 91c7a90

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4555,14 +4555,35 @@ nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr,
45554555
return nfsd4_encode_change_info4(xdr, &rename->rn_tinfo);
45564556
}
45574557

4558+
static __be32
4559+
nfsd4_encode_rpcsec_gss_info(struct xdr_stream *xdr,
4560+
struct rpcsec_gss_info *info)
4561+
{
4562+
__be32 status;
4563+
4564+
/* oid */
4565+
if (xdr_stream_encode_opaque(xdr, info->oid.data, info->oid.len) < 0)
4566+
return nfserr_resource;
4567+
/* qop */
4568+
status = nfsd4_encode_qop4(xdr, info->qop);
4569+
if (status != nfs_ok)
4570+
return status;
4571+
/* service */
4572+
if (xdr_stream_encode_u32(xdr, info->service) != XDR_UNIT)
4573+
return nfserr_resource;
4574+
4575+
return nfs_ok;
4576+
}
4577+
45584578
static __be32
45594579
nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
45604580
{
45614581
u32 i, nflavs, supported;
45624582
struct exp_flavor_info *flavs;
45634583
struct exp_flavor_info def_flavs[2];
4564-
__be32 *p, *flavorsp;
45654584
static bool report = true;
4585+
__be32 *flavorsp;
4586+
__be32 status;
45664587

45674588
if (exp->ex_nflavors) {
45684589
flavs = exp->ex_flavors;
@@ -4585,31 +4606,32 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
45854606
}
45864607

45874608
supported = 0;
4588-
p = xdr_reserve_space(xdr, 4);
4589-
if (!p)
4609+
flavorsp = xdr_reserve_space(xdr, XDR_UNIT);
4610+
if (!flavorsp)
45904611
return nfserr_resource;
4591-
flavorsp = p++; /* to be backfilled later */
45924612

45934613
for (i = 0; i < nflavs; i++) {
45944614
rpc_authflavor_t pf = flavs[i].pseudoflavor;
45954615
struct rpcsec_gss_info info;
45964616

45974617
if (rpcauth_get_gssinfo(pf, &info) == 0) {
45984618
supported++;
4599-
p = xdr_reserve_space(xdr, 4 + 4 +
4600-
XDR_LEN(info.oid.len) + 4 + 4);
4601-
if (!p)
4602-
return nfserr_resource;
4603-
*p++ = cpu_to_be32(RPC_AUTH_GSS);
4604-
p = xdr_encode_opaque(p, info.oid.data, info.oid.len);
4605-
*p++ = cpu_to_be32(info.qop);
4606-
*p++ = cpu_to_be32(info.service);
4619+
4620+
/* flavor */
4621+
status = nfsd4_encode_uint32_t(xdr, RPC_AUTH_GSS);
4622+
if (status != nfs_ok)
4623+
return status;
4624+
/* flavor_info */
4625+
status = nfsd4_encode_rpcsec_gss_info(xdr, &info);
4626+
if (status != nfs_ok)
4627+
return status;
46074628
} else if (pf < RPC_AUTH_MAXFLAVOR) {
46084629
supported++;
4609-
p = xdr_reserve_space(xdr, 4);
4610-
if (!p)
4611-
return nfserr_resource;
4612-
*p++ = cpu_to_be32(pf);
4630+
4631+
/* flavor */
4632+
status = nfsd4_encode_uint32_t(xdr, pf);
4633+
if (status != nfs_ok)
4634+
return status;
46134635
} else {
46144636
if (report)
46154637
pr_warn("NFS: SECINFO: security flavor %u "
@@ -4619,7 +4641,7 @@ nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
46194641

46204642
if (nflavs != supported)
46214643
report = false;
4622-
*flavorsp = htonl(supported);
4644+
*flavorsp = cpu_to_be32(supported);
46234645
return 0;
46244646
}
46254647

fs/nfsd/xdr4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val)
9696
#define nfsd4_encode_count4(x, v) nfsd4_encode_uint32_t(x, v)
9797
#define nfsd4_encode_mode4(x, v) nfsd4_encode_uint32_t(x, v)
9898
#define nfsd4_encode_nfs_lease4(x, v) nfsd4_encode_uint32_t(x, v)
99+
#define nfsd4_encode_qop4(x, v) nfsd4_encode_uint32_t(x, v)
99100
#define nfsd4_encode_sequenceid4(x, v) nfsd4_encode_uint32_t(x, v)
100101
#define nfsd4_encode_slotid4(x, v) nfsd4_encode_uint32_t(x, v)
101102

0 commit comments

Comments
 (0)