Debian Codegraph @

fs/smb/client/compress.h

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2024, SUSE LLC
4 *
5 * Authors: Enzo Matsumiya <[email protected]>
6 *
7 * This file implements I/O compression support for SMB2 messages (SMB 3.1.1 only).
8 * See compress/ for implementation details of each algorithm.
9 *
10 * References:
11 * MS-SMB2 "3.1.4.4 Compressing the Message" - for compression details
12 * MS-SMB2 "3.1.5.3 Decompressing the Chained Message" - for decompression details
13 * MS-XCA - for details of the supported algorithms
14 */
15 #ifndef _SMB_COMPRESS_H
16 #define _SMB_COMPRESS_H
17
18 #include <linux/uio.h>
19 #include <linux/kernel.h>
20 #include "../common/smb2pdu.h"
21 #include "cifsglob.h"
22
23 /* sizeof(smb2_compression_hdr) - sizeof(OriginalPayloadSize) */
24 #define SMB_COMPRESS_HDR_LEN 16
25 /* sizeof(smb2_compression_payload_hdr) - sizeof(OriginalPayloadSize) */
26 #define SMB_COMPRESS_PAYLOAD_HDR_LEN 8
27 #define SMB_COMPRESS_MIN_LEN PAGE_SIZE
28
29 #ifdef CONFIG_CIFS_COMPRESSION
30 typedef int (*compress_send_fn)(struct TCP_Server_Info *, int, struct smb_rqst *);
31
32
33 int smb_compress(struct TCP_Server_Info *server, struct smb_rqst *rq,
34 compress_send_fn send_fn);
35 bool should_compress(const struct cifs_tcon *tcon, const struct smb_rqst *rq);
36
37 /*
38 * smb_compress_alg_valid() - Validate a compression algorithm.
39 * @alg: Compression algorithm to check.
40 * @valid_none: Conditional check whether NONE algorithm should be
41 * considered valid or not.
42 *
43 * If @alg is SMB3_COMPRESS_NONE, this function returns @valid_none.
44 *
45 * Note that 'NONE' (0) compressor type is considered invalid in protocol
46 * negotiation, as it's never requested to/returned from the server.
47 *
48 * Return: true if @alg is valid/supported, false otherwise.
49 */
50 static __always_inline int smb_compress_alg_valid(__le16 alg, bool valid_none)
51 {
52 if (alg == SMB3_COMPRESS_NONE)
53 return valid_none;
54
55 if (alg == SMB3_COMPRESS_LZ77 || alg == SMB3_COMPRESS_PATTERN)
56 return true;
57
58 return false;
59 }
60 #else /* !CONFIG_CIFS_COMPRESSION */
61 static inline int smb_compress(void *unused1, void *unused2, void *unused3)
62 {
63 return -EOPNOTSUPP;
64 }
65
66 static inline bool should_compress(void *unused1, void *unused2)
67 {
68 return false;
69 }
70
71 static inline int smb_compress_alg_valid(__le16 unused1, bool unused2)
72 {
73 return -EOPNOTSUPP;
74 }
75 #endif /* !CONFIG_CIFS_COMPRESSION */
76 #endif /* _SMB_COMPRESS_H */