Merge tag 'ipsec-2023-03-15' of git://git.kernel.org/pub/scm/linux/kernel/git/klasser...
[linux-block.git] / fs / cifs / smb2pdu.h
CommitLineData
929be906 1/* SPDX-License-Identifier: LGPL-2.1 */
ddfbefbd 2/*
ddfbefbd 3 *
be7457d3 4 * Copyright (c) International Business Machines Corp., 2009, 2013
ddfbefbd
SF
5 * Etersoft, 2012
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
8 *
ddfbefbd
SF
9 */
10
11#ifndef _SMB2PDU_H
12#define _SMB2PDU_H
13
14#include <net/sock.h>
90810c25 15#include "cifsacl.h"
ddfbefbd 16
58d15ed1 17/* 52 transform hdr + 64 hdr + 88 create rsp */
c4627e66 18#define SMB2_TRANSFORM_HEADER_SIZE 52
58d15ed1 19#define MAX_SMB2_HDR_SIZE 204
2dc7e1c0 20
f7950cb0 21/* The total header size for SMB2 read and write */
0d35e382 22#define SMB2_READWRITE_PDU_HEADER_SIZE (48 + sizeof(struct smb2_hdr))
8f233431 23
3984bdc0
SF
24/* See MS-SMB2 2.2.43 */
25struct 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
bb9cad1b
SF
34/* TransformType */
35#define SMB2_RDMA_TRANSFORM_TYPE_ENCRYPTION 0x0001
36#define SMB2_RDMA_TRANSFORM_TYPE_SIGNING 0x0002
37
38struct smb2_rdma_crypto_transform {
3984bdc0
SF
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
093b2bda
PS
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 */
74112860 56
730928c8
RS
57#define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
58
76894f3e 59#define SMB2_SYMLINK_STRUCT_SIZE \
eb3e28c1 60 (sizeof(struct smb2_err_rsp) + sizeof(struct smb2_symlink_err_rsp))
76894f3e 61
df070afd
RS
62#define SYMLINK_ERROR_TAG 0x4c4d5953
63
b42bf888
PS
64struct 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;
cff2def5 75 __u8 PathBuffer[];
b42bf888
PS
76} __packed;
77
5f60a564
SF
78/* SMB 3.1.1 and later dialects. See MS-SMB2 section 2.2.2.1 */
79struct smb2_error_context_rsp {
80 __le32 ErrorDataLength;
81 __le32 ErrorId;
82 __u8 ErrorContextData; /* ErrorDataLength long array */
83} __packed;
84
8895c66f
SF
85/* ErrorId values */
86#define SMB2_ERROR_ID_DEFAULT 0x00000000
87#define SMB2_ERROR_ID_SHARE_REDIRECT cpu_to_le32(0x72645253) /* "rdRS" */
88
5f60a564
SF
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
93struct 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
99struct share_redirect_error_context_rsp {
100 __le32 StructureSize;
101 __le32 NotificationType;
102 __le32 ResourceNameOffset;
103 __le32 ResourceNameLength;
2438c0bd 104 __le16 Reserved;
5f60a564
SF
105 __le16 TargetType;
106 __le32 IPAddrCount;
cff2def5 107 struct move_dst_ipaddr IpAddrMoveList[];
5f60a564
SF
108 /* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
109} __packed;
110
4d8dfafc
RS
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
ff2a09e9
SF
119 * [6] : query id context
120 * [7] : compound padding
4d8dfafc 121 */
ff2a09e9 122#define SMB2_CREATE_IOV_SIZE 8
4d8dfafc 123
c4627e66
RS
124/*
125 * Maximum size of a SMB2_CREATE response is 64 (smb2 header) +
ff2a09e9 126 * 88 (fixed part of create response) + 520 (path) + 208 (contexts) +
c4627e66
RS
127 * 2 bytes of padding.
128 */
ff2a09e9 129#define MAX_SMB2_CREATE_RESPONSE_SIZE 880
c4627e66 130
53ef1016
PS
131#define SMB2_LEASE_READ_CACHING_HE 0x01
132#define SMB2_LEASE_HANDLE_CACHING_HE 0x02
133#define SMB2_LEASE_WRITE_CACHING_HE 0x04
134
63eb3def
PS
135struct create_durable {
136 struct create_context ccontext;
137 __u8 Name[8];
9cbc0b73
PS
138 union {
139 __u8 Reserved[16];
140 struct {
141 __u64 PersistentFileId;
142 __u64 VolatileFileId;
143 } Fid;
144 } Data;
63eb3def
PS
145} __packed;
146
b56eae4d
SF
147/* See MS-SMB2 2.2.13.2.11 */
148/* Flags */
149#define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
150struct durable_context_v2 {
151 __le32 Timeout;
152 __le32 Flags;
153 __u64 Reserved;
154 __u8 CreateGuid[16];
155} __packed;
156
157struct create_durable_v2 {
158 struct create_context ccontext;
159 __u8 Name[8];
160 struct durable_context_v2 dcontext;
161} __packed;
162
163/* See MS-SMB2 2.2.13.2.12 */
164struct durable_reconnect_context_v2 {
165 struct {
166 __u64 PersistentFileId;
167 __u64 VolatileFileId;
168 } Fid;
169 __u8 CreateGuid[16];
170 __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
171} __packed;
172
e7348e35 173/* See MS-SMB2 2.2.14.2.9 */
89a5bfa3
SF
174struct create_on_disk_id {
175 struct create_context ccontext;
176 __u8 Name[8];
e7348e35
SF
177 __le64 DiskFileId;
178 __le64 VolumeId;
ff2a09e9 179 __u32 Reserved[4];
e7348e35
SF
180} __packed;
181
b56eae4d
SF
182/* See MS-SMB2 2.2.14.2.12 */
183struct durable_reconnect_context_v2_rsp {
184 __le32 Timeout;
185 __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
186} __packed;
187
188struct create_durable_handle_reconnect_v2 {
189 struct create_context ccontext;
190 __u8 Name[8];
191 struct durable_reconnect_context_v2 dcontext;
d243af7a 192 __u8 Pad[4];
b56eae4d
SF
193} __packed;
194
cdeaf9d0
SF
195/* See MS-SMB2 2.2.13.2.5 */
196struct crt_twarp_ctxt {
197 struct create_context ccontext;
198 __u8 Name[8];
199 __le64 Timestamp;
200
201} __packed;
202
ff2a09e9
SF
203/* See MS-SMB2 2.2.13.2.9 */
204struct crt_query_id_ctxt {
205 struct create_context ccontext;
206 __u8 Name[8];
207} __packed;
208
fdef665b
SF
209struct crt_sd_ctxt {
210 struct create_context ccontext;
211 __u8 Name[8];
212 struct smb3_sd sd;
fdef665b
SF
213} __packed;
214
215
41c1358e
SF
216#define COPY_CHUNK_RES_KEY_SIZE 24
217struct resume_key_req {
218 char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
219 __le32 ContextLength; /* MBZ */
cff2def5 220 char Context[]; /* ignored, Windows sets to 4 bytes of zero */
41c1358e
SF
221} __packed;
222
be7457d3
SF
223/* this goes in the ioctl buffer when doing a copychunk request */
224struct copychunk_ioctl {
41c1358e 225 char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
be7457d3
SF
226 __le32 ChunkCount; /* we are only sending 1 */
227 __le32 Reserved;
228 /* array will only be one chunk long for us */
229 __le64 SourceOffset;
230 __le64 TargetOffset;
c8664730 231 __le32 Length; /* how many bytes to copy */
be7457d3
SF
232 __u32 Reserved2;
233} __packed;
234
41c1358e
SF
235struct copychunk_ioctl_rsp {
236 __le32 ChunksWritten;
237 __le32 ChunkBytesWritten;
238 __le32 TotalBytesWritten;
239} __packed;
240
7d03ae4d
SF
241/* See MS-FSCC 2.3.29 and 2.3.30 */
242struct get_retrieval_pointer_count_req {
243 __le64 StartingVcn; /* virtual cluster number (signed) */
244} __packed;
245
246struct get_retrieval_pointer_count_rsp {
247 __le32 ExtentCount;
248} __packed;
249
250/*
251 * See MS-FSCC 2.3.33 and 2.3.34
252 * request is the same as get_retrieval_point_count_req struct above
253 */
254struct smb3_extents {
255 __le64 NextVcn;
256 __le64 Lcn; /* logical cluster number */
257} __packed;
258
259struct get_retrieval_pointers_refcount_rsp {
260 __le32 ExtentCount;
261 __u32 Reserved;
262 __le64 StartingVcn;
263 struct smb3_extents extents[];
264} __packed;
265
9d49640a
AA
266/* See MS-DFSC 2.2.2 */
267struct fsctl_get_dfs_referral_req {
268 __le16 MaxReferralLevel;
269 __u8 RequestFileName[];
270} __packed;
271
272/* DFS response is struct get_dfs_refer_rsp */
273
b56eae4d
SF
274/* See MS-SMB2 2.2.31.3 */
275struct network_resiliency_req {
276 __le32 Timeout;
277 __le32 Reserved;
278} __packed;
279/* There is no buffer for the response ie no struct network_resiliency_rsp */
280
bead042c
AA
281#define RSS_CAPABLE cpu_to_le32(0x00000001)
282#define RDMA_CAPABLE cpu_to_le32(0x00000002)
283
284#define INTERNETWORK cpu_to_le16(0x0002)
285#define INTERNETWORKV6 cpu_to_le16(0x0017)
4a72dafa
SF
286
287struct network_interface_info_ioctl_rsp {
288 __le32 Next; /* next interface. zero if this is last one */
289 __le32 IfIndex;
290 __le32 Capability; /* RSS or RDMA Capable */
291 __le32 Reserved;
292 __le64 LinkSpeed;
bead042c
AA
293 __le16 Family;
294 __u8 Buffer[126];
295} __packed;
296
297struct iface_info_ipv4 {
298 __be16 Port;
299 __be32 IPv4Address;
300 __be64 Reserved;
301} __packed;
302
303struct iface_info_ipv6 {
304 __be16 Port;
305 __be32 FlowInfo;
306 __u8 IPv6Address[16];
307 __be32 ScopeId;
4a72dafa
SF
308} __packed;
309
310#define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
311
64a5cfa6 312struct compress_ioctl {
c7f508a9 313 __le16 CompressionState; /* See cifspdu.h for possible flag values */
64a5cfa6
SF
314} __packed;
315
72c419d9
RS
316/*
317 * Maximum number of iovs we need for an ioctl request.
318 * [0] : struct smb2_ioctl_req
319 * [1] : in_data
320 */
321#define SMB2_IOCTL_IOV_SIZE 2
322
be4cb9e3 323/*
be135000 324 * PDU query infolevel structure definitions
be4cb9e3
PS
325 * BB consider moving to a different header
326 */
327
95907fea
RS
328struct smb2_file_full_ea_info { /* encoding of response for level 15 */
329 __le32 next_entry_offset;
330 __u8 flags;
331 __u8 ea_name_length;
332 __le16 ea_value_length;
cff2def5 333 char ea_data[]; /* \0 terminated name plus value */
95907fea
RS
334} __packed; /* level 15 Set */
335
2e4564b3
SF
336struct smb2_file_reparse_point_info {
337 __le64 IndexNumber;
338 __le32 Tag;
339} __packed;
340
43f8a6a7
SF
341struct smb2_file_network_open_info {
342 __le64 CreationTime;
343 __le64 LastAccessTime;
344 __le64 LastWriteTime;
345 __le64 ChangeTime;
346 __le64 AllocationSize;
347 __le64 EndOfFile;
348 __le32 Attributes;
349 __le32 Reserved;
350} __packed; /* level 34 Query also similar returned in close rsp and open rsp */
351
2438c0bd 352/* See MS-FSCC 2.4.21 */
51d92d69
SF
353struct smb2_file_id_information {
354 __le64 VolumeSerialNumber;
355 __u64 PersistentFileId; /* opaque endianness */
356 __u64 VolatileFileId; /* opaque endianness */
357} __packed; /* level 59 */
358
2438c0bd
SF
359/* See MS-FSCC 2.4.18 */
360struct smb2_file_id_extd_directory_info {
361 __le32 NextEntryOffset;
362 __u32 FileIndex;
363 __le64 CreationTime;
364 __le64 LastAccessTime;
365 __le64 LastWriteTime;
366 __le64 ChangeTime;
367 __le64 EndOfFile;
368 __le64 AllocationSize;
369 __le32 FileAttributes;
370 __le32 FileNameLength;
371 __le32 EaSize; /* EA size */
372 __le32 ReparsePointTag; /* valid if FILE_ATTR_REPARSE_POINT set in FileAttributes */
373 __le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit */
35235e19 374 char FileName[];
2438c0bd
SF
375} __packed; /* level 60 */
376
730928c8
RS
377extern char smb2_padding[7];
378
ab3459d8 379/* equivalent of the contents of SMB3.1.1 POSIX open context response */
2e8af978 380struct create_posix_rsp {
69dda305
AA
381 u32 nlink;
382 u32 reparse_tag;
383 u32 mode;
384 struct cifs_sid owner; /* var-sized on the wire */
385 struct cifs_sid group; /* var-sized on the wire */
2e8af978 386} __packed;
349e13ad 387
be135000
SF
388#define SMB2_QUERY_DIRECTORY_IOV_SIZE 2
389
349e13ad 390/*
6a5f6592 391 * SMB2-only POSIX info level for query dir
349e13ad
AA
392 *
393 * See posix_info_sid_size(), posix_info_extra_size() and
394 * posix_info_parse() to help with the handling of this struct.
395 */
396struct smb2_posix_info {
397 __le32 NextEntryOffset;
398 __u32 Ignored;
399 __le64 CreationTime;
400 __le64 LastAccessTime;
401 __le64 LastWriteTime;
402 __le64 ChangeTime;
403 __le64 EndOfFile;
404 __le64 AllocationSize;
405 __le32 DosAttributes;
406 __le64 Inode;
407 __le32 DeviceId;
408 __le32 Zero;
409 /* beginning of POSIX Create Context Response */
410 __le32 HardLinks;
411 __le32 ReparseTag;
412 __le32 Mode;
413 /*
414 * var sized owner SID
415 * var sized group SID
416 * le32 filenamelength
417 * u8 filename[]
418 */
419} __packed;
420
421/*
422 * Parsed version of the above struct. Allows direct access to the
423 * variable length fields
424 */
425struct smb2_posix_info_parsed {
426 const struct smb2_posix_info *base;
427 size_t size;
428 struct cifs_sid owner;
429 struct cifs_sid group;
430 int name_len;
431 const u8 *name;
ab3459d8 432};
349e13ad 433
ddfbefbd 434#endif /* _SMB2PDU_H */