xref: /openbmc/linux/fs/smb/client/smb2pdu.h (revision 5cd17f0e)
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3  *
4  *   Copyright (c) International Business Machines  Corp., 2009, 2013
5  *                 Etersoft, 2012
6  *   Author(s): Steve French (sfrench@us.ibm.com)
7  *              Pavel Shilovsky (pshilovsky@samba.org) 2012
8  *
9  */
10 
11 #ifndef _SMB2PDU_H
12 #define _SMB2PDU_H
13 
14 #include <net/sock.h>
15 #include "cifsacl.h"
16 
17 /* 52 transform hdr + 64 hdr + 88 create rsp */
18 #define SMB2_TRANSFORM_HEADER_SIZE 52
19 #define MAX_SMB2_HDR_SIZE 204
20 
21 /* The total header size for SMB2 read and write */
22 #define SMB2_READWRITE_PDU_HEADER_SIZE (48 + sizeof(struct smb2_hdr))
23 
24 /* See MS-SMB2 2.2.43 */
25 struct smb2_rdma_transform {
26 	__le16 RdmaDescriptorOffset;
27 	__le16 RdmaDescriptorLength;
28 	__le32 Channel; /* for values see channel description in smb2 read above */
29 	__le16 TransformCount;
30 	__le16 Reserved1;
31 	__le32 Reserved2;
32 } __packed;
33 
34 /* TransformType */
35 #define SMB2_RDMA_TRANSFORM_TYPE_ENCRYPTION	0x0001
36 #define SMB2_RDMA_TRANSFORM_TYPE_SIGNING	0x0002
37 
38 struct smb2_rdma_crypto_transform {
39 	__le16	TransformType;
40 	__le16	SignatureLength;
41 	__le16	NonceLength;
42 	__u16	Reserved;
43 	__u8	Signature[]; /* variable length */
44 	/* u8 Nonce[] */
45 	/* followed by padding */
46 } __packed;
47 
48 /*
49  *	Definitions for SMB2 Protocol Data Units (network frames)
50  *
51  *  See MS-SMB2.PDF specification for protocol details.
52  *  The Naming convention is the lower case version of the SMB2
53  *  command code name for the struct. Note that structures must be packed.
54  *
55  */
56 
57 #define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
58 
59 #define SMB2_SYMLINK_STRUCT_SIZE \
60 	(sizeof(struct smb2_err_rsp) + sizeof(struct smb2_symlink_err_rsp))
61 
62 #define SYMLINK_ERROR_TAG 0x4c4d5953
63 
64 struct smb2_symlink_err_rsp {
65 	__le32 SymLinkLength;
66 	__le32 SymLinkErrorTag;
67 	__le32 ReparseTag;
68 	__le16 ReparseDataLength;
69 	__le16 UnparsedPathLength;
70 	__le16 SubstituteNameOffset;
71 	__le16 SubstituteNameLength;
72 	__le16 PrintNameOffset;
73 	__le16 PrintNameLength;
74 	__le32 Flags;
75 	__u8  PathBuffer[];
76 } __packed;
77 
78 /* SMB 3.1.1 and later dialects. See MS-SMB2 section 2.2.2.1 */
79 struct smb2_error_context_rsp {
80 	__le32 ErrorDataLength;
81 	__le32 ErrorId;
82 	__u8  ErrorContextData; /* ErrorDataLength long array */
83 } __packed;
84 
85 /* ErrorId values */
86 #define SMB2_ERROR_ID_DEFAULT		0x00000000
87 #define SMB2_ERROR_ID_SHARE_REDIRECT	cpu_to_le32(0x72645253)	/* "rdRS" */
88 
89 /* Defines for Type field below (see MS-SMB2 2.2.2.2.2.1) */
90 #define MOVE_DST_IPADDR_V4	cpu_to_le32(0x00000001)
91 #define MOVE_DST_IPADDR_V6	cpu_to_le32(0x00000002)
92 
93 struct move_dst_ipaddr {
94 	__le32 Type;
95 	__u32  Reserved;
96 	__u8   address[16]; /* IPv4 followed by 12 bytes rsvd or IPv6 address */
97 } __packed;
98 
99 struct share_redirect_error_context_rsp {
100 	__le32 StructureSize;
101 	__le32 NotificationType;
102 	__le32 ResourceNameOffset;
103 	__le32 ResourceNameLength;
104 	__le16 Reserved;
105 	__le16 TargetType;
106 	__le32 IPAddrCount;
107 	struct move_dst_ipaddr IpAddrMoveList[];
108 	/* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
109 } __packed;
110 
111 /*
112  * Maximum number of iovs we need for an open/create request.
113  * [0] : struct smb2_create_req
114  * [1] : path
115  * [2] : lease context
116  * [3] : durable context
117  * [4] : posix context
118  * [5] : time warp context
119  * [6] : query id context
120  * [7] : create ea context
121  * [8] : compound padding
122  */
123 #define SMB2_CREATE_IOV_SIZE 9
124 
125 /*
126  * Maximum size of a SMB2_CREATE response is 64 (smb2 header) +
127  * 88 (fixed part of create response) + 520 (path) + 208 (contexts) +
128  * 2 bytes of padding.
129  */
130 #define MAX_SMB2_CREATE_RESPONSE_SIZE 880
131 
132 #define SMB2_LEASE_READ_CACHING_HE	0x01
133 #define SMB2_LEASE_HANDLE_CACHING_HE	0x02
134 #define SMB2_LEASE_WRITE_CACHING_HE	0x04
135 
136 
137 /* See MS-SMB2 2.2.13.2.11 */
138 /* Flags */
139 #define SMB2_DHANDLE_FLAG_PERSISTENT	0x00000002
140 struct durable_context_v2 {
141 	__le32 Timeout;
142 	__le32 Flags;
143 	__u64 Reserved;
144 	__u8 CreateGuid[16];
145 } __packed;
146 
147 struct create_durable_v2 {
148 	struct create_context_hdr ccontext;
149 	__u8   Name[8];
150 	struct durable_context_v2 dcontext;
151 } __packed;
152 
153 /* See MS-SMB2 2.2.13.2.12 */
154 struct durable_reconnect_context_v2 {
155 	struct {
156 		__u64 PersistentFileId;
157 		__u64 VolatileFileId;
158 	} Fid;
159 	__u8 CreateGuid[16];
160 	__le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
161 } __packed;
162 
163 /* See MS-SMB2 2.2.14.2.12 */
164 struct durable_reconnect_context_v2_rsp {
165 	__le32 Timeout;
166 	__le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
167 } __packed;
168 
169 struct create_durable_handle_reconnect_v2 {
170 	struct create_context_hdr ccontext;
171 	__u8   Name[8];
172 	struct durable_reconnect_context_v2 dcontext;
173 	__u8   Pad[4];
174 } __packed;
175 
176 /* See MS-SMB2 2.2.13.2.5 */
177 struct crt_twarp_ctxt {
178 	struct create_context_hdr ccontext;
179 	__u8	Name[8];
180 	__le64	Timestamp;
181 
182 } __packed;
183 
184 /* See MS-SMB2 2.2.13.2.9 */
185 struct crt_query_id_ctxt {
186 	struct create_context_hdr ccontext;
187 	__u8	Name[8];
188 } __packed;
189 
190 struct crt_sd_ctxt {
191 	struct create_context_hdr ccontext;
192 	__u8	Name[8];
193 	struct smb3_sd sd;
194 } __packed;
195 
196 
197 #define COPY_CHUNK_RES_KEY_SIZE	24
198 struct resume_key_req {
199 	char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
200 	__le32	ContextLength;	/* MBZ */
201 	char	Context[];	/* ignored, Windows sets to 4 bytes of zero */
202 } __packed;
203 
204 /* this goes in the ioctl buffer when doing a copychunk request */
205 struct copychunk_ioctl {
206 	char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
207 	__le32 ChunkCount; /* we are only sending 1 */
208 	__le32 Reserved;
209 	/* array will only be one chunk long for us */
210 	__le64 SourceOffset;
211 	__le64 TargetOffset;
212 	__le32 Length; /* how many bytes to copy */
213 	__u32 Reserved2;
214 } __packed;
215 
216 struct copychunk_ioctl_rsp {
217 	__le32 ChunksWritten;
218 	__le32 ChunkBytesWritten;
219 	__le32 TotalBytesWritten;
220 } __packed;
221 
222 /* See MS-FSCC 2.3.29 and 2.3.30 */
223 struct get_retrieval_pointer_count_req {
224 	__le64 StartingVcn; /* virtual cluster number (signed) */
225 } __packed;
226 
227 struct get_retrieval_pointer_count_rsp {
228 	__le32 ExtentCount;
229 } __packed;
230 
231 /*
232  * See MS-FSCC 2.3.33 and 2.3.34
233  * request is the same as get_retrieval_point_count_req struct above
234  */
235 struct smb3_extents {
236 	__le64 NextVcn;
237 	__le64 Lcn; /* logical cluster number */
238 } __packed;
239 
240 struct get_retrieval_pointers_refcount_rsp {
241 	__le32 ExtentCount;
242 	__u32  Reserved;
243 	__le64 StartingVcn;
244 	struct smb3_extents extents[];
245 } __packed;
246 
247 /* See MS-DFSC 2.2.2 */
248 struct fsctl_get_dfs_referral_req {
249 	__le16 MaxReferralLevel;
250 	__u8 RequestFileName[];
251 } __packed;
252 
253 /* DFS response is struct get_dfs_refer_rsp */
254 
255 /* See MS-SMB2 2.2.31.3 */
256 struct network_resiliency_req {
257 	__le32 Timeout;
258 	__le32 Reserved;
259 } __packed;
260 /* There is no buffer for the response ie no struct network_resiliency_rsp */
261 
262 #define RSS_CAPABLE	cpu_to_le32(0x00000001)
263 #define RDMA_CAPABLE	cpu_to_le32(0x00000002)
264 
265 #define INTERNETWORK	cpu_to_le16(0x0002)
266 #define INTERNETWORKV6	cpu_to_le16(0x0017)
267 
268 struct network_interface_info_ioctl_rsp {
269 	__le32 Next; /* next interface. zero if this is last one */
270 	__le32 IfIndex;
271 	__le32 Capability; /* RSS or RDMA Capable */
272 	__le32 Reserved;
273 	__le64 LinkSpeed;
274 	__le16 Family;
275 	__u8 Buffer[126];
276 } __packed;
277 
278 struct iface_info_ipv4 {
279 	__be16 Port;
280 	__be32 IPv4Address;
281 	__be64 Reserved;
282 } __packed;
283 
284 struct iface_info_ipv6 {
285 	__be16 Port;
286 	__be32 FlowInfo;
287 	__u8   IPv6Address[16];
288 	__be32 ScopeId;
289 } __packed;
290 
291 #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
292 
293 struct compress_ioctl {
294 	__le16 CompressionState; /* See cifspdu.h for possible flag values */
295 } __packed;
296 
297 /*
298  * Maximum number of iovs we need for an ioctl request.
299  * [0] : struct smb2_ioctl_req
300  * [1] : in_data
301  */
302 #define SMB2_IOCTL_IOV_SIZE 2
303 
304 /*
305  *	PDU query infolevel structure definitions
306  *	BB consider moving to a different header
307  */
308 
309 struct smb2_file_full_ea_info { /* encoding of response for level 15 */
310 	__le32 next_entry_offset;
311 	__u8   flags;
312 	__u8   ea_name_length;
313 	__le16 ea_value_length;
314 	char   ea_data[]; /* \0 terminated name plus value */
315 } __packed; /* level 15 Set */
316 
317 struct smb2_file_reparse_point_info {
318 	__le64 IndexNumber;
319 	__le32 Tag;
320 } __packed;
321 
322 struct smb2_file_network_open_info {
323 	struct_group_attr(network_open_info, __packed,
324 		__le64 CreationTime;
325 		__le64 LastAccessTime;
326 		__le64 LastWriteTime;
327 		__le64 ChangeTime;
328 		__le64 AllocationSize;
329 		__le64 EndOfFile;
330 		__le32 Attributes;
331 	);
332 	__le32 Reserved;
333 } __packed; /* level 34 Query also similar returned in close rsp and open rsp */
334 
335 /* See MS-FSCC 2.4.21 */
336 struct smb2_file_id_information {
337 	__le64	VolumeSerialNumber;
338 	__u64  PersistentFileId; /* opaque endianness */
339 	__u64  VolatileFileId; /* opaque endianness */
340 } __packed; /* level 59 */
341 
342 /* See MS-FSCC 2.4.18 */
343 struct smb2_file_id_extd_directory_info {
344 	__le32 NextEntryOffset;
345 	__u32 FileIndex;
346 	__le64 CreationTime;
347 	__le64 LastAccessTime;
348 	__le64 LastWriteTime;
349 	__le64 ChangeTime;
350 	__le64 EndOfFile;
351 	__le64 AllocationSize;
352 	__le32 FileAttributes;
353 	__le32 FileNameLength;
354 	__le32 EaSize; /* EA size */
355 	__le32 ReparsePointTag; /* valid if FILE_ATTR_REPARSE_POINT set in FileAttributes */
356 	__le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit */
357 	char FileName[];
358 } __packed; /* level 60 */
359 
360 extern char smb2_padding[7];
361 
362 /* equivalent of the contents of SMB3.1.1 POSIX open context response */
363 struct create_posix_rsp {
364 	u32 nlink;
365 	u32 reparse_tag;
366 	u32 mode;
367 	struct cifs_sid owner; /* var-sized on the wire */
368 	struct cifs_sid group; /* var-sized on the wire */
369 } __packed;
370 
371 #define SMB2_QUERY_DIRECTORY_IOV_SIZE 2
372 
373 /*
374  * SMB2-only POSIX info level for query dir
375  *
376  * See posix_info_sid_size(), posix_info_extra_size() and
377  * posix_info_parse() to help with the handling of this struct.
378  */
379 struct smb2_posix_info {
380 	__le32 NextEntryOffset;
381 	__u32 Ignored;
382 	__le64 CreationTime;
383 	__le64 LastAccessTime;
384 	__le64 LastWriteTime;
385 	__le64 ChangeTime;
386 	__le64 EndOfFile;
387 	__le64 AllocationSize;
388 	__le32 DosAttributes;
389 	__le64 Inode;
390 	__le32 DeviceId;
391 	__le32 Zero;
392 	/* beginning of POSIX Create Context Response */
393 	__le32 HardLinks;
394 	__le32 ReparseTag;
395 	__le32 Mode;
396 	/*
397 	 * var sized owner SID
398 	 * var sized group SID
399 	 * le32 filenamelength
400 	 * u8  filename[]
401 	 */
402 } __packed;
403 
404 /*
405  * Parsed version of the above struct. Allows direct access to the
406  * variable length fields
407  */
408 struct smb2_posix_info_parsed {
409 	const struct smb2_posix_info *base;
410 	size_t size;
411 	struct cifs_sid owner;
412 	struct cifs_sid group;
413 	int name_len;
414 	const u8 *name;
415 };
416 
417 struct smb2_create_ea_ctx {
418 	struct create_context_hdr ctx;
419 	__u8 name[8];
420 	struct smb2_file_full_ea_info ea;
421 } __packed;
422 
423 #define SMB2_WSL_XATTR_UID		"$LXUID"
424 #define SMB2_WSL_XATTR_GID		"$LXGID"
425 #define SMB2_WSL_XATTR_MODE		"$LXMOD"
426 #define SMB2_WSL_XATTR_DEV		"$LXDEV"
427 #define SMB2_WSL_XATTR_NAME_LEN	6
428 #define SMB2_WSL_NUM_XATTRS		4
429 
430 #define SMB2_WSL_XATTR_UID_SIZE	4
431 #define SMB2_WSL_XATTR_GID_SIZE	4
432 #define SMB2_WSL_XATTR_MODE_SIZE	4
433 #define SMB2_WSL_XATTR_DEV_SIZE	8
434 
435 #define SMB2_WSL_MIN_QUERY_EA_RESP_SIZE \
436 	(ALIGN((SMB2_WSL_NUM_XATTRS - 1) * \
437 	       (SMB2_WSL_XATTR_NAME_LEN + 1 + \
438 		sizeof(struct smb2_file_full_ea_info)), 4) + \
439 	 SMB2_WSL_XATTR_NAME_LEN + 1 + sizeof(struct smb2_file_full_ea_info))
440 
441 #define SMB2_WSL_MAX_QUERY_EA_RESP_SIZE \
442 	(ALIGN(SMB2_WSL_MIN_QUERY_EA_RESP_SIZE + \
443 	       SMB2_WSL_XATTR_UID_SIZE + \
444 	       SMB2_WSL_XATTR_GID_SIZE + \
445 	       SMB2_WSL_XATTR_MODE_SIZE + \
446 	       SMB2_WSL_XATTR_DEV_SIZE, 4))
447 
448 #endif				/* _SMB2PDU_H */
449