~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/lockd/svcxdr.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * Encode/decode NLM basic data types
  4  *
  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:
  8  * XNFS, Version 3W".
  9  *
 10  * Basic NLMv4 XDR data types are defined in Appendix II.1.4 of
 11  * RFC 1813: "NFS Version 3 Protocol Specification".
 12  *
 13  * Author: Chuck Lever <chuck.lever@oracle.com>
 14  *
 15  * Copyright (c) 2020, Oracle and/or its affiliates.
 16  */
 17 
 18 #ifndef _LOCKD_SVCXDR_H_
 19 #define _LOCKD_SVCXDR_H_
 20 
 21 static inline bool
 22 svcxdr_decode_stats(struct xdr_stream *xdr, __be32 *status)
 23 {
 24         __be32 *p;
 25 
 26         p = xdr_inline_decode(xdr, XDR_UNIT);
 27         if (!p)
 28                 return false;
 29         *status = *p;
 30 
 31         return true;
 32 }
 33 
 34 static inline bool
 35 svcxdr_encode_stats(struct xdr_stream *xdr, __be32 status)
 36 {
 37         __be32 *p;
 38 
 39         p = xdr_reserve_space(xdr, XDR_UNIT);
 40         if (!p)
 41                 return false;
 42         *p = status;
 43 
 44         return true;
 45 }
 46 
 47 static inline bool
 48 svcxdr_decode_string(struct xdr_stream *xdr, char **data, unsigned int *data_len)
 49 {
 50         __be32 *p;
 51         u32 len;
 52 
 53         if (xdr_stream_decode_u32(xdr, &len) < 0)
 54                 return false;
 55         if (len > NLM_MAXSTRLEN)
 56                 return false;
 57         p = xdr_inline_decode(xdr, len);
 58         if (!p)
 59                 return false;
 60         *data_len = len;
 61         *data = (char *)p;
 62 
 63         return true;
 64 }
 65 
 66 /*
 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
 70  * specially.
 71  */
 72 static inline bool
 73 svcxdr_decode_cookie(struct xdr_stream *xdr, struct nlm_cookie *cookie)
 74 {
 75         __be32 *p;
 76         u32 len;
 77 
 78         if (xdr_stream_decode_u32(xdr, &len) < 0)
 79                 return false;
 80         if (len > NLM_MAXCOOKIELEN)
 81                 return false;
 82         if (!len)
 83                 goto out_hpux;
 84 
 85         p = xdr_inline_decode(xdr, len);
 86         if (!p)
 87                 return false;
 88         cookie->len = len;
 89         memcpy(cookie->data, p, len);
 90 
 91         return true;
 92 
 93         /* apparently HPUX can return empty cookies */
 94 out_hpux:
 95         cookie->len = 4;
 96         memset(cookie->data, 0, 4);
 97         return true;
 98 }
 99 
100 static inline bool
101 svcxdr_encode_cookie(struct xdr_stream *xdr, const struct nlm_cookie *cookie)
102 {
103         __be32 *p;
104 
105         if (xdr_stream_encode_u32(xdr, cookie->len) < 0)
106                 return false;
107         p = xdr_reserve_space(xdr, cookie->len);
108         if (!p)
109                 return false;
110         memcpy(p, cookie->data, cookie->len);
111 
112         return true;
113 }
114 
115 static inline bool
116 svcxdr_decode_owner(struct xdr_stream *xdr, struct xdr_netobj *obj)
117 {
118         __be32 *p;
119         u32 len;
120 
121         if (xdr_stream_decode_u32(xdr, &len) < 0)
122                 return false;
123         if (len > XDR_MAX_NETOBJ)
124                 return false;
125         p = xdr_inline_decode(xdr, len);
126         if (!p)
127                 return false;
128         obj->len = len;
129         obj->data = (u8 *)p;
130 
131         return true;
132 }
133 
134 static inline bool
135 svcxdr_encode_owner(struct xdr_stream *xdr, const struct xdr_netobj *obj)
136 {
137         if (obj->len > XDR_MAX_NETOBJ)
138                 return false;
139         return xdr_stream_encode_opaque(xdr, obj->data, obj->len) > 0;
140 }
141 
142 #endif /* _LOCKD_SVCXDR_H_ */
143 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php