1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Encode/decode NLM basic data types
5 * Basic NLMv3 XDR data types are not defined in an IETF standards
6 * document. X/Open has a description of these data types that
7 * is useful. See Chapter 10 of "Protocols for Interworking:
10 * Basic NLMv4 XDR data types are defined in Appendix II.1.4 of
11 * RFC 1813: "NFS Version 3 Protocol Specification".
13 * Author: Chuck Lever <chuck.lever@oracle.com>
15 * Copyright (c) 2020, Oracle and/or its affiliates.
18 #ifndef _LOCKD_SVCXDR_H_
19 #define _LOCKD_SVCXDR_H_
22 svcxdr_decode_stats(struct xdr_stream
*xdr
, __be32
*status
)
26 p
= xdr_inline_decode(xdr
, XDR_UNIT
);
35 svcxdr_encode_stats(struct xdr_stream
*xdr
, __be32 status
)
39 p
= xdr_reserve_space(xdr
, XDR_UNIT
);
48 svcxdr_decode_string(struct xdr_stream
*xdr
, char **data
, unsigned int *data_len
)
53 if (xdr_stream_decode_u32(xdr
, &len
) < 0)
55 if (len
> NLM_MAXSTRLEN
)
57 p
= xdr_inline_decode(xdr
, len
);
67 * NLM cookies are defined by specification to be a variable-length
68 * XDR opaque no longer than 1024 bytes. However, this implementation
69 * limits their length to 32 bytes, and treats zero-length cookies
73 svcxdr_decode_cookie(struct xdr_stream
*xdr
, struct nlm_cookie
*cookie
)
78 if (xdr_stream_decode_u32(xdr
, &len
) < 0)
80 if (len
> NLM_MAXCOOKIELEN
)
85 p
= xdr_inline_decode(xdr
, len
);
89 memcpy(cookie
->data
, p
, len
);
93 /* apparently HPUX can return empty cookies */
96 memset(cookie
->data
, 0, 4);
101 svcxdr_encode_cookie(struct xdr_stream
*xdr
, const struct nlm_cookie
*cookie
)
105 if (xdr_stream_encode_u32(xdr
, cookie
->len
) < 0)
107 p
= xdr_reserve_space(xdr
, cookie
->len
);
110 memcpy(p
, cookie
->data
, cookie
->len
);
116 svcxdr_decode_owner(struct xdr_stream
*xdr
, struct xdr_netobj
*obj
)
121 if (xdr_stream_decode_u32(xdr
, &len
) < 0)
123 if (len
> XDR_MAX_NETOBJ
)
125 p
= xdr_inline_decode(xdr
, len
);
135 svcxdr_encode_owner(struct xdr_stream
*xdr
, const struct xdr_netobj
*obj
)
137 if (obj
->len
> XDR_MAX_NETOBJ
)
139 return xdr_stream_encode_opaque(xdr
, obj
->data
, obj
->len
) > 0;
142 #endif /* _LOCKD_SVCXDR_H_ */