Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 */
0002 /*
0003  *
0004  *   Copyright (c) International Business Machines  Corp., 2009, 2013
0005  *                 Etersoft, 2012
0006  *   Author(s): Steve French (sfrench@us.ibm.com)
0007  *              Pavel Shilovsky (pshilovsky@samba.org) 2012
0008  *
0009  */
0010 
0011 #ifndef _SMB2PDU_H
0012 #define _SMB2PDU_H
0013 
0014 #include <net/sock.h>
0015 #include "cifsacl.h"
0016 
0017 /* 52 transform hdr + 64 hdr + 88 create rsp */
0018 #define SMB2_TRANSFORM_HEADER_SIZE 52
0019 #define MAX_SMB2_HDR_SIZE 204
0020 
0021 /* The total header size for SMB2 read and write */
0022 #define SMB2_READWRITE_PDU_HEADER_SIZE (48 + sizeof(struct smb2_hdr))
0023 
0024 /* See MS-SMB2 2.2.43 */
0025 struct smb2_rdma_transform {
0026     __le16 RdmaDescriptorOffset;
0027     __le16 RdmaDescriptorLength;
0028     __le32 Channel; /* for values see channel description in smb2 read above */
0029     __le16 TransformCount;
0030     __le16 Reserved1;
0031     __le32 Reserved2;
0032 } __packed;
0033 
0034 /* TransformType */
0035 #define SMB2_RDMA_TRANSFORM_TYPE_ENCRYPTION 0x0001
0036 #define SMB2_RDMA_TRANSFORM_TYPE_SIGNING    0x0002
0037 
0038 struct smb2_rdma_crypto_transform {
0039     __le16  TransformType;
0040     __le16  SignatureLength;
0041     __le16  NonceLength;
0042     __u16   Reserved;
0043     __u8    Signature[]; /* variable length */
0044     /* u8 Nonce[] */
0045     /* followed by padding */
0046 } __packed;
0047 
0048 /*
0049  *  Definitions for SMB2 Protocol Data Units (network frames)
0050  *
0051  *  See MS-SMB2.PDF specification for protocol details.
0052  *  The Naming convention is the lower case version of the SMB2
0053  *  command code name for the struct. Note that structures must be packed.
0054  *
0055  */
0056 
0057 #define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
0058 
0059 #define SYMLINK_ERROR_TAG 0x4c4d5953
0060 
0061 struct smb2_symlink_err_rsp {
0062     __le32 SymLinkLength;
0063     __le32 SymLinkErrorTag;
0064     __le32 ReparseTag;
0065     __le16 ReparseDataLength;
0066     __le16 UnparsedPathLength;
0067     __le16 SubstituteNameOffset;
0068     __le16 SubstituteNameLength;
0069     __le16 PrintNameOffset;
0070     __le16 PrintNameLength;
0071     __le32 Flags;
0072     __u8  PathBuffer[];
0073 } __packed;
0074 
0075 /* SMB 3.1.1 and later dialects. See MS-SMB2 section 2.2.2.1 */
0076 struct smb2_error_context_rsp {
0077     __le32 ErrorDataLength;
0078     __le32 ErrorId;
0079     __u8  ErrorContextData; /* ErrorDataLength long array */
0080 } __packed;
0081 
0082 /* ErrorId values */
0083 #define SMB2_ERROR_ID_DEFAULT       0x00000000
0084 #define SMB2_ERROR_ID_SHARE_REDIRECT    cpu_to_le32(0x72645253) /* "rdRS" */
0085 
0086 /* Defines for Type field below (see MS-SMB2 2.2.2.2.2.1) */
0087 #define MOVE_DST_IPADDR_V4  cpu_to_le32(0x00000001)
0088 #define MOVE_DST_IPADDR_V6  cpu_to_le32(0x00000002)
0089 
0090 struct move_dst_ipaddr {
0091     __le32 Type;
0092     __u32  Reserved;
0093     __u8   address[16]; /* IPv4 followed by 12 bytes rsvd or IPv6 address */
0094 } __packed;
0095 
0096 struct share_redirect_error_context_rsp {
0097     __le32 StructureSize;
0098     __le32 NotificationType;
0099     __le32 ResourceNameOffset;
0100     __le32 ResourceNameLength;
0101     __le16 Reserved;
0102     __le16 TargetType;
0103     __le32 IPAddrCount;
0104     struct move_dst_ipaddr IpAddrMoveList[];
0105     /* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
0106 } __packed;
0107 
0108 /*
0109  * Maximum number of iovs we need for an open/create request.
0110  * [0] : struct smb2_create_req
0111  * [1] : path
0112  * [2] : lease context
0113  * [3] : durable context
0114  * [4] : posix context
0115  * [5] : time warp context
0116  * [6] : query id context
0117  * [7] : compound padding
0118  */
0119 #define SMB2_CREATE_IOV_SIZE 8
0120 
0121 /*
0122  * Maximum size of a SMB2_CREATE response is 64 (smb2 header) +
0123  * 88 (fixed part of create response) + 520 (path) + 208 (contexts) +
0124  * 2 bytes of padding.
0125  */
0126 #define MAX_SMB2_CREATE_RESPONSE_SIZE 880
0127 
0128 #define SMB2_LEASE_READ_CACHING_HE  0x01
0129 #define SMB2_LEASE_HANDLE_CACHING_HE    0x02
0130 #define SMB2_LEASE_WRITE_CACHING_HE 0x04
0131 
0132 struct create_durable {
0133     struct create_context ccontext;
0134     __u8   Name[8];
0135     union {
0136         __u8  Reserved[16];
0137         struct {
0138             __u64 PersistentFileId;
0139             __u64 VolatileFileId;
0140         } Fid;
0141     } Data;
0142 } __packed;
0143 
0144 /* See MS-SMB2 2.2.13.2.11 */
0145 /* Flags */
0146 #define SMB2_DHANDLE_FLAG_PERSISTENT    0x00000002
0147 struct durable_context_v2 {
0148     __le32 Timeout;
0149     __le32 Flags;
0150     __u64 Reserved;
0151     __u8 CreateGuid[16];
0152 } __packed;
0153 
0154 struct create_durable_v2 {
0155     struct create_context ccontext;
0156     __u8   Name[8];
0157     struct durable_context_v2 dcontext;
0158 } __packed;
0159 
0160 /* See MS-SMB2 2.2.13.2.12 */
0161 struct durable_reconnect_context_v2 {
0162     struct {
0163         __u64 PersistentFileId;
0164         __u64 VolatileFileId;
0165     } Fid;
0166     __u8 CreateGuid[16];
0167     __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
0168 } __packed;
0169 
0170 /* See MS-SMB2 2.2.14.2.9 */
0171 struct create_on_disk_id {
0172     struct create_context ccontext;
0173     __u8   Name[8];
0174     __le64 DiskFileId;
0175     __le64 VolumeId;
0176     __u32  Reserved[4];
0177 } __packed;
0178 
0179 /* See MS-SMB2 2.2.14.2.12 */
0180 struct durable_reconnect_context_v2_rsp {
0181     __le32 Timeout;
0182     __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
0183 } __packed;
0184 
0185 struct create_durable_handle_reconnect_v2 {
0186     struct create_context ccontext;
0187     __u8   Name[8];
0188     struct durable_reconnect_context_v2 dcontext;
0189     __u8   Pad[4];
0190 } __packed;
0191 
0192 /* See MS-SMB2 2.2.13.2.5 */
0193 struct crt_twarp_ctxt {
0194     struct create_context ccontext;
0195     __u8    Name[8];
0196     __le64  Timestamp;
0197 
0198 } __packed;
0199 
0200 /* See MS-SMB2 2.2.13.2.9 */
0201 struct crt_query_id_ctxt {
0202     struct create_context ccontext;
0203     __u8    Name[8];
0204 } __packed;
0205 
0206 struct crt_sd_ctxt {
0207     struct create_context ccontext;
0208     __u8    Name[8];
0209     struct smb3_sd sd;
0210 } __packed;
0211 
0212 
0213 #define COPY_CHUNK_RES_KEY_SIZE 24
0214 struct resume_key_req {
0215     char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
0216     __le32  ContextLength;  /* MBZ */
0217     char    Context[];  /* ignored, Windows sets to 4 bytes of zero */
0218 } __packed;
0219 
0220 /* this goes in the ioctl buffer when doing a copychunk request */
0221 struct copychunk_ioctl {
0222     char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
0223     __le32 ChunkCount; /* we are only sending 1 */
0224     __le32 Reserved;
0225     /* array will only be one chunk long for us */
0226     __le64 SourceOffset;
0227     __le64 TargetOffset;
0228     __le32 Length; /* how many bytes to copy */
0229     __u32 Reserved2;
0230 } __packed;
0231 
0232 struct copychunk_ioctl_rsp {
0233     __le32 ChunksWritten;
0234     __le32 ChunkBytesWritten;
0235     __le32 TotalBytesWritten;
0236 } __packed;
0237 
0238 /* See MS-FSCC 2.3.29 and 2.3.30 */
0239 struct get_retrieval_pointer_count_req {
0240     __le64 StartingVcn; /* virtual cluster number (signed) */
0241 } __packed;
0242 
0243 struct get_retrieval_pointer_count_rsp {
0244     __le32 ExtentCount;
0245 } __packed;
0246 
0247 /*
0248  * See MS-FSCC 2.3.33 and 2.3.34
0249  * request is the same as get_retrieval_point_count_req struct above
0250  */
0251 struct smb3_extents {
0252     __le64 NextVcn;
0253     __le64 Lcn; /* logical cluster number */
0254 } __packed;
0255 
0256 struct get_retrieval_pointers_refcount_rsp {
0257     __le32 ExtentCount;
0258     __u32  Reserved;
0259     __le64 StartingVcn;
0260     struct smb3_extents extents[];
0261 } __packed;
0262 
0263 /* See MS-DFSC 2.2.2 */
0264 struct fsctl_get_dfs_referral_req {
0265     __le16 MaxReferralLevel;
0266     __u8 RequestFileName[];
0267 } __packed;
0268 
0269 /* DFS response is struct get_dfs_refer_rsp */
0270 
0271 /* See MS-SMB2 2.2.31.3 */
0272 struct network_resiliency_req {
0273     __le32 Timeout;
0274     __le32 Reserved;
0275 } __packed;
0276 /* There is no buffer for the response ie no struct network_resiliency_rsp */
0277 
0278 #define RSS_CAPABLE cpu_to_le32(0x00000001)
0279 #define RDMA_CAPABLE    cpu_to_le32(0x00000002)
0280 
0281 #define INTERNETWORK    cpu_to_le16(0x0002)
0282 #define INTERNETWORKV6  cpu_to_le16(0x0017)
0283 
0284 struct network_interface_info_ioctl_rsp {
0285     __le32 Next; /* next interface. zero if this is last one */
0286     __le32 IfIndex;
0287     __le32 Capability; /* RSS or RDMA Capable */
0288     __le32 Reserved;
0289     __le64 LinkSpeed;
0290     __le16 Family;
0291     __u8 Buffer[126];
0292 } __packed;
0293 
0294 struct iface_info_ipv4 {
0295     __be16 Port;
0296     __be32 IPv4Address;
0297     __be64 Reserved;
0298 } __packed;
0299 
0300 struct iface_info_ipv6 {
0301     __be16 Port;
0302     __be32 FlowInfo;
0303     __u8   IPv6Address[16];
0304     __be32 ScopeId;
0305 } __packed;
0306 
0307 #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
0308 
0309 struct compress_ioctl {
0310     __le16 CompressionState; /* See cifspdu.h for possible flag values */
0311 } __packed;
0312 
0313 /*
0314  * Maximum number of iovs we need for an ioctl request.
0315  * [0] : struct smb2_ioctl_req
0316  * [1] : in_data
0317  */
0318 #define SMB2_IOCTL_IOV_SIZE 2
0319 
0320 /*
0321  *  PDU query infolevel structure definitions
0322  *  BB consider moving to a different header
0323  */
0324 
0325 struct smb2_file_full_ea_info { /* encoding of response for level 15 */
0326     __le32 next_entry_offset;
0327     __u8   flags;
0328     __u8   ea_name_length;
0329     __le16 ea_value_length;
0330     char   ea_data[]; /* \0 terminated name plus value */
0331 } __packed; /* level 15 Set */
0332 
0333 struct smb2_file_reparse_point_info {
0334     __le64 IndexNumber;
0335     __le32 Tag;
0336 } __packed;
0337 
0338 struct smb2_file_network_open_info {
0339     __le64 CreationTime;
0340     __le64 LastAccessTime;
0341     __le64 LastWriteTime;
0342     __le64 ChangeTime;
0343     __le64 AllocationSize;
0344     __le64 EndOfFile;
0345     __le32 Attributes;
0346     __le32 Reserved;
0347 } __packed; /* level 34 Query also similar returned in close rsp and open rsp */
0348 
0349 /* See MS-FSCC 2.4.21 */
0350 struct smb2_file_id_information {
0351     __le64  VolumeSerialNumber;
0352     __u64  PersistentFileId; /* opaque endianness */
0353     __u64  VolatileFileId; /* opaque endianness */
0354 } __packed; /* level 59 */
0355 
0356 /* See MS-FSCC 2.4.18 */
0357 struct smb2_file_id_extd_directory_info {
0358     __le32 NextEntryOffset;
0359     __u32 FileIndex;
0360     __le64 CreationTime;
0361     __le64 LastAccessTime;
0362     __le64 LastWriteTime;
0363     __le64 ChangeTime;
0364     __le64 EndOfFile;
0365     __le64 AllocationSize;
0366     __le32 FileAttributes;
0367     __le32 FileNameLength;
0368     __le32 EaSize; /* EA size */
0369     __le32 ReparsePointTag; /* valid if FILE_ATTR_REPARSE_POINT set in FileAttributes */
0370     __le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit */
0371     char FileName[1];
0372 } __packed; /* level 60 */
0373 
0374 extern char smb2_padding[7];
0375 
0376 /* equivalent of the contents of SMB3.1.1 POSIX open context response */
0377 struct create_posix_rsp {
0378     u32 nlink;
0379     u32 reparse_tag;
0380     u32 mode;
0381     struct cifs_sid owner; /* var-sized on the wire */
0382     struct cifs_sid group; /* var-sized on the wire */
0383 } __packed;
0384 
0385 #define SMB2_QUERY_DIRECTORY_IOV_SIZE 2
0386 
0387 /*
0388  * SMB2-only POSIX info level for query dir
0389  *
0390  * See posix_info_sid_size(), posix_info_extra_size() and
0391  * posix_info_parse() to help with the handling of this struct.
0392  */
0393 struct smb2_posix_info {
0394     __le32 NextEntryOffset;
0395     __u32 Ignored;
0396     __le64 CreationTime;
0397     __le64 LastAccessTime;
0398     __le64 LastWriteTime;
0399     __le64 ChangeTime;
0400     __le64 EndOfFile;
0401     __le64 AllocationSize;
0402     __le32 DosAttributes;
0403     __le64 Inode;
0404     __le32 DeviceId;
0405     __le32 Zero;
0406     /* beginning of POSIX Create Context Response */
0407     __le32 HardLinks;
0408     __le32 ReparseTag;
0409     __le32 Mode;
0410     /*
0411      * var sized owner SID
0412      * var sized group SID
0413      * le32 filenamelength
0414      * u8  filename[]
0415      */
0416 } __packed;
0417 
0418 /*
0419  * Parsed version of the above struct. Allows direct access to the
0420  * variable length fields
0421  */
0422 struct smb2_posix_info_parsed {
0423     const struct smb2_posix_info *base;
0424     size_t size;
0425     struct cifs_sid owner;
0426     struct cifs_sid group;
0427     int name_len;
0428     const u8 *name;
0429 };
0430 
0431 #endif              /* _SMB2PDU_H */