Skip to content

Commit d291e70

Browse files
z00467499Steve French
authored andcommitted
cifs: Add helper function to check smb1+ server
SMB1 server's header_preamble_size is not 0, add use is_smb1 function to simplify the code, no actual functional changes. Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent b6b3624 commit d291e70

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

fs/cifs/cifsencrypt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ int __cifs_calc_signature(struct smb_rqst *rqst,
3232
int rc;
3333
struct kvec *iov = rqst->rq_iov;
3434
int n_vec = rqst->rq_nvec;
35-
bool is_smb2 = HEADER_PREAMBLE_SIZE(server) == 0;
3635

3736
/* iov[0] is actual data and not the rfc1002 length for SMB2+ */
38-
if (is_smb2) {
37+
if (!is_smb1(server)) {
3938
if (iov[0].iov_len <= 4)
4039
return -EIO;
4140
i = 0;

fs/cifs/cifsglob.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,11 @@ struct TCP_Server_Info {
752752
#endif
753753
};
754754

755+
static inline bool is_smb1(struct TCP_Server_Info *server)
756+
{
757+
return HEADER_PREAMBLE_SIZE(server) != 0;
758+
}
759+
755760
static inline void cifs_server_lock(struct TCP_Server_Info *server)
756761
{
757762
unsigned int nofs_flag = memalloc_nofs_save();

fs/cifs/connect.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ smb2_get_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
871871
/*
872872
* SMB1 does not use credits.
873873
*/
874-
if (HEADER_PREAMBLE_SIZE(server))
874+
if (is_smb1(server))
875875
return 0;
876876

877877
return le16_to_cpu(shdr->CreditRequest);
@@ -1121,7 +1121,7 @@ smb2_add_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
11211121
/*
11221122
* SMB1 does not use credits.
11231123
*/
1124-
if (HEADER_PREAMBLE_SIZE(server))
1124+
if (is_smb1(server))
11251125
return;
11261126

11271127
if (shdr->CreditRequest) {
@@ -1179,10 +1179,10 @@ cifs_demultiplex_thread(void *p)
11791179
if (length < 0)
11801180
continue;
11811181

1182-
if (HEADER_PREAMBLE_SIZE(server) == 0)
1183-
server->total_read = 0;
1184-
else
1182+
if (is_smb1(server))
11851183
server->total_read = length;
1184+
else
1185+
server->total_read = 0;
11861186

11871187
/*
11881188
* The right amount was read from socket - 4 bytes,

fs/cifs/transport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ smb_rqst_len(struct TCP_Server_Info *server, struct smb_rqst *rqst)
261261
int nvec;
262262
unsigned long buflen = 0;
263263

264-
if (HEADER_PREAMBLE_SIZE(server) == 0 && rqst->rq_nvec >= 2 &&
264+
if (!is_smb1(server) && rqst->rq_nvec >= 2 &&
265265
rqst->rq_iov[0].iov_len == 4) {
266266
iov = &rqst->rq_iov[1];
267267
nvec = rqst->rq_nvec - 1;
@@ -346,7 +346,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
346346
sigprocmask(SIG_BLOCK, &mask, &oldmask);
347347

348348
/* Generate a rfc1002 marker for SMB2+ */
349-
if (HEADER_PREAMBLE_SIZE(server) == 0) {
349+
if (!is_smb1(server)) {
350350
struct kvec hiov = {
351351
.iov_base = &rfc1002_marker,
352352
.iov_len = 4

0 commit comments

Comments
 (0)