nvme: optimise io_uring passthrough completion
[linux-block.git] / fs / ksmbd / smb2pdu.h
CommitLineData
e2f34481
NJ
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
5 */
6
7#ifndef _SMB2PDU_H
8#define _SMB2PDU_H
9
10#include "ntlmssp.h"
11#include "smbacl.h"
12
e2f34481
NJ
13/*Create Action Flags*/
14#define FILE_SUPERSEDED 0x00000000
15#define FILE_OPENED 0x00000001
16#define FILE_CREATED 0x00000002
17#define FILE_OVERWRITTEN 0x00000003
18
e2f34481
NJ
19/* SMB2 Max Credits */
20#define SMB2_MAX_CREDITS 8192
21
e2f34481
NJ
22/* BB FIXME - analyze following length BB */
23#define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
24
e2f34481 25#define SMB21_DEFAULT_IOSIZE (1024 * 1024)
e2f34481 26#define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
62c487b5
NJ
27#define SMB3_MIN_IOSIZE (64 * 1024)
28#define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
29#define SMB3_MAX_MSGSIZE (4 * 4096)
e2f34481 30
e2f34481
NJ
31/*
32 * Definitions for SMB2 Protocol Data Units (network frames)
33 *
34 * See MS-SMB2.PDF specification for protocol details.
35 * The Naming convention is the lower case version of the SMB2
36 * command code name for the struct. Note that structures must be packed.
37 *
38 */
39
e2f34481
NJ
40struct preauth_integrity_info {
41 /* PreAuth integrity Hash ID */
42 __le16 Preauth_HashId;
43 /* PreAuth integrity Hash Value */
d6c9ad23 44 __u8 Preauth_HashValue[SMB2_PREAUTH_HASH_SIZE];
e2f34481
NJ
45};
46
cb451720 47/* offset is sizeof smb2_negotiate_rsp but rounded up to 8 bytes. */
e2f34481 48#ifdef CONFIG_SMB_SERVER_KERBEROS5
cb451720 49/* sizeof(struct smb2_negotiate_rsp) =
e2f34481
NJ
50 * header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0)
51 */
52#define OFFSET_OF_NEG_CONTEXT 0xe0
53#else
cb451720 54/* sizeof(struct smb2_negotiate_rsp) =
e2f34481
NJ
55 * header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6)
56 */
57#define OFFSET_OF_NEG_CONTEXT 0xd0
58#endif
59
e2f34481 60#define SMB2_SESSION_EXPIRED (0)
64b39f4a
NJ
61#define SMB2_SESSION_IN_PROGRESS BIT(0)
62#define SMB2_SESSION_VALID BIT(1)
e2f34481 63
ea174a91
NJ
64#define SMB2_SESSION_TIMEOUT (10 * HZ)
65
e2f34481
NJ
66struct create_durable_req_v2 {
67 struct create_context ccontext;
68 __u8 Name[8];
69 __le32 Timeout;
70 __le32 Flags;
71 __u8 Reserved[8];
72 __u8 CreateGuid[16];
73} __packed;
74
e2f34481
NJ
75struct create_durable_reconn_v2_req {
76 struct create_context ccontext;
77 __u8 Name[8];
78 struct {
2d004c6c
PA
79 __u64 PersistentFileId;
80 __u64 VolatileFileId;
e2f34481
NJ
81 } Fid;
82 __u8 CreateGuid[16];
83 __le32 Flags;
84} __packed;
85
e2f34481
NJ
86struct create_alloc_size_req {
87 struct create_context ccontext;
88 __u8 Name[8];
89 __le64 AllocationSize;
90} __packed;
91
e2f34481
NJ
92struct create_durable_rsp {
93 struct create_context ccontext;
94 __u8 Name[8];
95 union {
96 __u8 Reserved[8];
97 __u64 data;
98 } Data;
99} __packed;
100
101struct create_durable_v2_rsp {
102 struct create_context ccontext;
103 __u8 Name[8];
104 __le32 Timeout;
105 __le32 Flags;
106} __packed;
107
e2f34481
NJ
108/* equivalent of the contents of SMB3.1.1 POSIX open context response */
109struct create_posix_rsp {
110 struct create_context ccontext;
111 __u8 Name[16];
112 __le32 nlink;
113 __le32 reparse_tag;
114 __le32 mode;
5609bdd9
NJ
115 /* SidBuffer contain two sids(Domain sid(28), UNIX group sid(16)) */
116 u8 SidBuffer[44];
e2f34481
NJ
117} __packed;
118
e2f34481
NJ
119struct smb2_buffer_desc_v1 {
120 __le64 offset;
121 __le32 token;
122 __le32 length;
123} __packed;
124
e2f34481
NJ
125#define SMB2_0_IOCTL_IS_FSCTL 0x00000001
126
e2f34481
NJ
127struct smb_sockaddr_in {
128 __be16 Port;
129 __be32 IPv4address;
130 __u8 Reserved[8];
131} __packed;
132
133struct smb_sockaddr_in6 {
134 __be16 Port;
135 __be32 FlowInfo;
136 __u8 IPv6address[16];
137 __be32 ScopeId;
138} __packed;
139
140#define INTERNETWORK 0x0002
141#define INTERNETWORKV6 0x0017
142
143struct sockaddr_storage_rsp {
144 __le16 Family;
145 union {
146 struct smb_sockaddr_in addr4;
147 struct smb_sockaddr_in6 addr6;
148 };
149} __packed;
150
151#define RSS_CAPABLE 0x00000001
152#define RDMA_CAPABLE 0x00000002
153
154struct network_interface_info_ioctl_rsp {
155 __le32 Next; /* next interface. zero if this is last one */
156 __le32 IfIndex;
157 __le32 Capability; /* RSS or RDMA Capable */
158 __le32 Reserved;
159 __le64 LinkSpeed;
160 char SockAddr_Storage[128];
161} __packed;
162
163struct file_object_buf_type1_ioctl_rsp {
164 __u8 ObjectId[16];
165 __u8 BirthVolumeId[16];
166 __u8 BirthObjectId[16];
167 __u8 DomainId[16];
168} __packed;
169
170struct resume_key_ioctl_rsp {
2d004c6c 171 __u64 ResumeKey[3];
e2f34481
NJ
172 __le32 ContextLength;
173 __u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
174} __packed;
175
176struct copychunk_ioctl_req {
177 __le64 ResumeKey[3];
178 __le32 ChunkCount;
179 __le32 Reserved;
180 __u8 Chunks[1]; /* array of srv_copychunk */
181} __packed;
182
183struct srv_copychunk {
184 __le64 SourceOffset;
185 __le64 TargetOffset;
186 __le32 Length;
187 __le32 Reserved;
188} __packed;
189
190struct copychunk_ioctl_rsp {
191 __le32 ChunksWritten;
192 __le32 ChunkBytesWritten;
193 __le32 TotalBytesWritten;
194} __packed;
195
196struct file_sparse {
197 __u8 SetSparse;
198} __packed;
199
e2f34481
NJ
200/* FILE Info response size */
201#define FILE_DIRECTORY_INFORMATION_SIZE 1
202#define FILE_FULL_DIRECTORY_INFORMATION_SIZE 2
203#define FILE_BOTH_DIRECTORY_INFORMATION_SIZE 3
204#define FILE_BASIC_INFORMATION_SIZE 40
205#define FILE_STANDARD_INFORMATION_SIZE 24
206#define FILE_INTERNAL_INFORMATION_SIZE 8
207#define FILE_EA_INFORMATION_SIZE 4
208#define FILE_ACCESS_INFORMATION_SIZE 4
209#define FILE_NAME_INFORMATION_SIZE 9
210#define FILE_RENAME_INFORMATION_SIZE 10
211#define FILE_LINK_INFORMATION_SIZE 11
212#define FILE_NAMES_INFORMATION_SIZE 12
213#define FILE_DISPOSITION_INFORMATION_SIZE 13
214#define FILE_POSITION_INFORMATION_SIZE 14
215#define FILE_FULL_EA_INFORMATION_SIZE 15
216#define FILE_MODE_INFORMATION_SIZE 4
217#define FILE_ALIGNMENT_INFORMATION_SIZE 4
218#define FILE_ALL_INFORMATION_SIZE 104
219#define FILE_ALLOCATION_INFORMATION_SIZE 19
220#define FILE_END_OF_FILE_INFORMATION_SIZE 20
221#define FILE_ALTERNATE_NAME_INFORMATION_SIZE 8
222#define FILE_STREAM_INFORMATION_SIZE 32
223#define FILE_PIPE_INFORMATION_SIZE 23
224#define FILE_PIPE_LOCAL_INFORMATION_SIZE 24
225#define FILE_PIPE_REMOTE_INFORMATION_SIZE 25
226#define FILE_MAILSLOT_QUERY_INFORMATION_SIZE 26
227#define FILE_MAILSLOT_SET_INFORMATION_SIZE 27
228#define FILE_COMPRESSION_INFORMATION_SIZE 16
229#define FILE_OBJECT_ID_INFORMATION_SIZE 29
230/* Number 30 not defined in documents */
231#define FILE_MOVE_CLUSTER_INFORMATION_SIZE 31
232#define FILE_QUOTA_INFORMATION_SIZE 32
233#define FILE_REPARSE_POINT_INFORMATION_SIZE 33
234#define FILE_NETWORK_OPEN_INFORMATION_SIZE 56
235#define FILE_ATTRIBUTE_TAG_INFORMATION_SIZE 8
236
e2f34481
NJ
237/* FS Info response size */
238#define FS_DEVICE_INFORMATION_SIZE 8
239#define FS_ATTRIBUTE_INFORMATION_SIZE 16
240#define FS_VOLUME_INFORMATION_SIZE 24
241#define FS_SIZE_INFORMATION_SIZE 24
242#define FS_FULL_SIZE_INFORMATION_SIZE 32
243#define FS_SECTOR_SIZE_INFORMATION_SIZE 28
244#define FS_OBJECT_ID_INFORMATION_SIZE 64
245#define FS_CONTROL_INFORMATION_SIZE 48
246#define FS_POSIX_INFORMATION_SIZE 56
247
248/* FS_ATTRIBUTE_File_System_Name */
249#define FS_TYPE_SUPPORT_SIZE 44
250struct fs_type_info {
251 char *fs_name;
252 long magic_number;
253} __packed;
254
e2f34481 255/*
be135000 256 * PDU query infolevel structure definitions
e2f34481
NJ
257 * BB consider moving to a different header
258 */
259
e2f34481
NJ
260struct smb2_file_access_info {
261 __le32 AccessFlags;
262} __packed;
263
264struct smb2_file_alignment_info {
265 __le32 AlignmentRequirement;
266} __packed;
267
88d30052
NJ
268struct smb2_file_basic_info { /* data block encoding of response to level 18 */
269 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
270 __le64 LastAccessTime;
271 __le64 LastWriteTime;
272 __le64 ChangeTime;
273 __le32 Attributes;
274 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
275} __packed;
276
e2f34481
NJ
277struct smb2_file_alt_name_info {
278 __le32 FileNameLength;
5224f790 279 char FileName[];
e2f34481
NJ
280} __packed;
281
282struct smb2_file_stream_info {
283 __le32 NextEntryOffset;
284 __le32 StreamNameLength;
285 __le64 StreamSize;
286 __le64 StreamAllocationSize;
5224f790 287 char StreamName[];
e2f34481
NJ
288} __packed;
289
e2f34481
NJ
290struct smb2_file_ntwrk_info {
291 __le64 CreationTime;
292 __le64 LastAccessTime;
293 __le64 LastWriteTime;
294 __le64 ChangeTime;
295 __le64 AllocationSize;
296 __le64 EndOfFile;
297 __le32 Attributes;
298 __le32 Reserved;
299} __packed;
300
301struct smb2_file_standard_info {
302 __le64 AllocationSize;
303 __le64 EndOfFile;
304 __le32 NumberOfLinks; /* hard links */
305 __u8 DeletePending;
306 __u8 Directory;
307 __le16 Reserved;
308} __packed; /* level 18 Query */
309
310struct smb2_file_ea_info {
311 __le32 EASize;
312} __packed;
313
314struct smb2_file_alloc_info {
315 __le64 AllocationSize;
316} __packed;
317
318struct smb2_file_disposition_info {
319 __u8 DeletePending;
320} __packed;
321
322struct smb2_file_pos_info {
323 __le64 CurrentByteOffset;
324} __packed;
325
26a2787d 326#define FILE_MODE_INFO_MASK cpu_to_le32(0x0000100e)
e2f34481
NJ
327
328struct smb2_file_mode_info {
329 __le32 Mode;
330} __packed;
331
332#define COMPRESSION_FORMAT_NONE 0x0000
333#define COMPRESSION_FORMAT_LZNT1 0x0002
334
335struct smb2_file_comp_info {
336 __le64 CompressedFileSize;
337 __le16 CompressionFormat;
338 __u8 CompressionUnitShift;
339 __u8 ChunkShift;
340 __u8 ClusterShift;
341 __u8 Reserved[3];
342} __packed;
343
344struct smb2_file_attr_tag_info {
345 __le32 FileAttributes;
346 __le32 ReparseTag;
347} __packed;
348
349#define SL_RESTART_SCAN 0x00000001
350#define SL_RETURN_SINGLE_ENTRY 0x00000002
351#define SL_INDEX_SPECIFIED 0x00000004
352
353struct smb2_ea_info_req {
354 __le32 NextEntryOffset;
355 __u8 EaNameLength;
356 char name[1];
357} __packed; /* level 15 Query */
358
359struct smb2_ea_info {
360 __le32 NextEntryOffset;
361 __u8 Flags;
362 __u8 EaNameLength;
363 __le16 EaValueLength;
364 char name[1];
365 /* optionally followed by value */
366} __packed; /* level 15 Query */
367
368struct create_ea_buf_req {
369 struct create_context ccontext;
370 __u8 Name[8];
371 struct smb2_ea_info ea;
372} __packed;
373
374struct create_sd_buf_req {
375 struct create_context ccontext;
376 __u8 Name[8];
377 struct smb_ntsd ntsd;
378} __packed;
379
e2f34481
NJ
380struct smb2_posix_info {
381 __le32 NextEntryOffset;
382 __u32 Ignored;
383 __le64 CreationTime;
384 __le64 LastAccessTime;
385 __le64 LastWriteTime;
386 __le64 ChangeTime;
387 __le64 EndOfFile;
388 __le64 AllocationSize;
389 __le32 DosAttributes;
390 __le64 Inode;
391 __le32 DeviceId;
392 __le32 Zero;
393 /* beginning of POSIX Create Context Response */
394 __le32 HardLinks;
395 __le32 ReparseTag;
396 __le32 Mode;
5609bdd9
NJ
397 /* SidBuffer contain two sids (UNIX user sid(16), UNIX group sid(16)) */
398 u8 SidBuffer[32];
e2f34481 399 __le32 name_len;
d272e01f 400 u8 name[];
e2f34481
NJ
401 /*
402 * var sized owner SID
403 * var sized group SID
404 * le32 filenamelength
405 * u8 filename[]
406 */
407} __packed;
408
409/* functions */
64b39f4a
NJ
410void init_smb2_1_server(struct ksmbd_conn *conn);
411void init_smb3_0_server(struct ksmbd_conn *conn);
412void init_smb3_02_server(struct ksmbd_conn *conn);
413int init_smb3_11_server(struct ksmbd_conn *conn);
414
415void init_smb2_max_read_size(unsigned int sz);
416void init_smb2_max_write_size(unsigned int sz);
417void init_smb2_max_trans_size(unsigned int sz);
004443b3 418void init_smb2_max_credits(unsigned int sz);
64b39f4a 419
f4228b67
NJ
420bool is_smb2_neg_cmd(struct ksmbd_work *work);
421bool is_smb2_rsp(struct ksmbd_work *work);
64b39f4a
NJ
422
423u16 get_smb2_cmd_val(struct ksmbd_work *work);
424void set_smb2_rsp_status(struct ksmbd_work *work, __le32 err);
425int init_smb2_rsp_hdr(struct ksmbd_work *work);
426int smb2_allocate_rsp_buf(struct ksmbd_work *work);
427bool is_chained_smb2_message(struct ksmbd_work *work);
428int init_smb2_neg_rsp(struct ksmbd_work *work);
429void smb2_set_err_rsp(struct ksmbd_work *work);
430int smb2_check_user_session(struct ksmbd_work *work);
431int smb2_get_ksmbd_tcon(struct ksmbd_work *work);
432bool smb2_is_sign_req(struct ksmbd_work *work, unsigned int command);
433int smb2_check_sign_req(struct ksmbd_work *work);
434void smb2_set_sign_rsp(struct ksmbd_work *work);
435int smb3_check_sign_req(struct ksmbd_work *work);
436void smb3_set_sign_rsp(struct ksmbd_work *work);
437int find_matching_smb2_dialect(int start_index, __le16 *cli_dialects,
d7e5852b 438 __le16 dialects_count);
64b39f4a
NJ
439struct file_lock *smb_flock_init(struct file *f);
440int setup_async_work(struct ksmbd_work *work, void (*fn)(void **),
d7e5852b 441 void **arg);
3a9b557f 442void release_async_work(struct ksmbd_work *work);
64b39f4a 443void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status);
f5a544e3
NJ
444struct channel *lookup_chann_list(struct ksmbd_session *sess,
445 struct ksmbd_conn *conn);
64b39f4a 446void smb3_preauth_hash_rsp(struct ksmbd_work *work);
f4228b67 447bool smb3_is_transform_hdr(void *buf);
64b39f4a
NJ
448int smb3_decrypt_req(struct ksmbd_work *work);
449int smb3_encrypt_resp(struct ksmbd_work *work);
450bool smb3_11_final_sess_setup_resp(struct ksmbd_work *work);
451int smb2_set_rsp_credits(struct ksmbd_work *work);
5bedae90 452bool smb3_encryption_negotiated(struct ksmbd_conn *conn);
e2f34481
NJ
453
454/* smb2 misc functions */
64b39f4a 455int ksmbd_smb2_check_message(struct ksmbd_work *work);
e2f34481
NJ
456
457/* smb2 command handlers */
64b39f4a
NJ
458int smb2_handle_negotiate(struct ksmbd_work *work);
459int smb2_negotiate_request(struct ksmbd_work *work);
460int smb2_sess_setup(struct ksmbd_work *work);
461int smb2_tree_connect(struct ksmbd_work *work);
462int smb2_tree_disconnect(struct ksmbd_work *work);
463int smb2_session_logoff(struct ksmbd_work *work);
464int smb2_open(struct ksmbd_work *work);
465int smb2_query_info(struct ksmbd_work *work);
466int smb2_query_dir(struct ksmbd_work *work);
467int smb2_close(struct ksmbd_work *work);
468int smb2_echo(struct ksmbd_work *work);
469int smb2_set_info(struct ksmbd_work *work);
470int smb2_read(struct ksmbd_work *work);
471int smb2_write(struct ksmbd_work *work);
472int smb2_flush(struct ksmbd_work *work);
473int smb2_cancel(struct ksmbd_work *work);
474int smb2_lock(struct ksmbd_work *work);
475int smb2_ioctl(struct ksmbd_work *work);
476int smb2_oplock_break(struct ksmbd_work *work);
477int smb2_notify(struct ksmbd_work *ksmbd_work);
e2f34481 478
cb451720
NJ
479/*
480 * Get the body of the smb2 message excluding the 4 byte rfc1002 headers
481 * from request/response buffer.
482 */
483static inline void *smb2_get_msg(void *buf)
484{
485 return buf + 4;
486}
487
e2f34481 488#endif /* _SMB2PDU_H */