Skip to content

Commit cb45172

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: remove smb2_buf_length in smb2_hdr
To move smb2_hdr to smbfs_common, This patch remove smb2_buf_length variable in smb2_hdr. Also, declare smb2_get_msg function to get smb2 request/response from ->request/response_buf. Cc: Ronnie Sahlberg <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 561a1cf commit cb45172

File tree

10 files changed

+260
-262
lines changed

10 files changed

+260
-262
lines changed

fs/ksmbd/auth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,9 +873,9 @@ int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf,
873873
__u8 *pi_hash)
874874
{
875875
int rc;
876-
struct smb2_hdr *rcv_hdr = (struct smb2_hdr *)buf;
876+
struct smb2_hdr *rcv_hdr = smb2_get_msg(buf);
877877
char *all_bytes_msg = (char *)&rcv_hdr->ProtocolId;
878-
int msg_size = be32_to_cpu(rcv_hdr->smb2_buf_length);
878+
int msg_size = get_rfc1002_len(buf);
879879
struct ksmbd_crypto_ctx *ctx = NULL;
880880

881881
if (conn->preauth_info->Preauth_HashId !=

fs/ksmbd/connection.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,13 @@ void ksmbd_conn_wait_idle(struct ksmbd_conn *conn)
158158
int ksmbd_conn_write(struct ksmbd_work *work)
159159
{
160160
struct ksmbd_conn *conn = work->conn;
161-
struct smb_hdr *rsp_hdr = work->response_buf;
162161
size_t len = 0;
163162
int sent;
164163
struct kvec iov[3];
165164
int iov_idx = 0;
166165

167166
ksmbd_conn_try_dequeue_request(work);
168-
if (!rsp_hdr) {
167+
if (!work->response_buf) {
169168
pr_err("NULL response header\n");
170169
return -EINVAL;
171170
}
@@ -177,16 +176,16 @@ int ksmbd_conn_write(struct ksmbd_work *work)
177176
}
178177

179178
if (work->aux_payload_sz) {
180-
iov[iov_idx] = (struct kvec) { rsp_hdr, work->resp_hdr_sz };
179+
iov[iov_idx] = (struct kvec) { work->response_buf, work->resp_hdr_sz };
181180
len += iov[iov_idx++].iov_len;
182181
iov[iov_idx] = (struct kvec) { work->aux_payload_buf, work->aux_payload_sz };
183182
len += iov[iov_idx++].iov_len;
184183
} else {
185184
if (work->tr_buf)
186185
iov[iov_idx].iov_len = work->resp_hdr_sz;
187186
else
188-
iov[iov_idx].iov_len = get_rfc1002_len(rsp_hdr) + 4;
189-
iov[iov_idx].iov_base = rsp_hdr;
187+
iov[iov_idx].iov_len = get_rfc1002_len(work->response_buf) + 4;
188+
iov[iov_idx].iov_base = work->response_buf;
190189
len += iov[iov_idx++].iov_len;
191190
}
192191

fs/ksmbd/ksmbd_work.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct ksmbd_work {
9292
*/
9393
static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work)
9494
{
95-
return work->response_buf + work->next_smb2_rsp_hdr_off;
95+
return work->response_buf + work->next_smb2_rsp_hdr_off + 4;
9696
}
9797

9898
/**
@@ -101,7 +101,7 @@ static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work)
101101
*/
102102
static inline void *ksmbd_req_buf_next(struct ksmbd_work *work)
103103
{
104-
return work->request_buf + work->next_smb2_rcv_hdr_off;
104+
return work->request_buf + work->next_smb2_rcv_hdr_off + 4;
105105
}
106106

107107
struct ksmbd_work *ksmbd_alloc_work_struct(void);

fs/ksmbd/oplock.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,10 @@ static void __smb2_oplock_break_noti(struct work_struct *wk)
629629
return;
630630
}
631631

632-
rsp_hdr = work->response_buf;
632+
rsp_hdr = smb2_get_msg(work->response_buf);
633633
memset(rsp_hdr, 0, sizeof(struct smb2_hdr) + 2);
634-
rsp_hdr->smb2_buf_length =
635-
cpu_to_be32(smb2_hdr_size_no_buflen(conn->vals));
634+
*(__be32 *)work->response_buf =
635+
cpu_to_be32(conn->vals->header_size);
636636
rsp_hdr->ProtocolId = SMB2_PROTO_NUMBER;
637637
rsp_hdr->StructureSize = SMB2_HEADER_STRUCTURE_SIZE;
638638
rsp_hdr->CreditRequest = cpu_to_le16(0);
@@ -645,7 +645,7 @@ static void __smb2_oplock_break_noti(struct work_struct *wk)
645645
rsp_hdr->SessionId = 0;
646646
memset(rsp_hdr->Signature, 0, 16);
647647

648-
rsp = work->response_buf;
648+
rsp = smb2_get_msg(work->response_buf);
649649

650650
rsp->StructureSize = cpu_to_le16(24);
651651
if (!br_info->open_trunc &&
@@ -659,7 +659,7 @@ static void __smb2_oplock_break_noti(struct work_struct *wk)
659659
rsp->PersistentFid = cpu_to_le64(fp->persistent_id);
660660
rsp->VolatileFid = cpu_to_le64(fp->volatile_id);
661661

662-
inc_rfc1001_len(rsp, 24);
662+
inc_rfc1001_len(work->response_buf, 24);
663663

664664
ksmbd_debug(OPLOCK,
665665
"sending oplock break v_id %llu p_id = %llu lock level = %d\n",
@@ -736,10 +736,10 @@ static void __smb2_lease_break_noti(struct work_struct *wk)
736736
return;
737737
}
738738

739-
rsp_hdr = work->response_buf;
739+
rsp_hdr = smb2_get_msg(work->response_buf);
740740
memset(rsp_hdr, 0, sizeof(struct smb2_hdr) + 2);
741-
rsp_hdr->smb2_buf_length =
742-
cpu_to_be32(smb2_hdr_size_no_buflen(conn->vals));
741+
*(__be32 *)work->response_buf =
742+
cpu_to_be32(conn->vals->header_size);
743743
rsp_hdr->ProtocolId = SMB2_PROTO_NUMBER;
744744
rsp_hdr->StructureSize = SMB2_HEADER_STRUCTURE_SIZE;
745745
rsp_hdr->CreditRequest = cpu_to_le16(0);
@@ -752,7 +752,7 @@ static void __smb2_lease_break_noti(struct work_struct *wk)
752752
rsp_hdr->SessionId = 0;
753753
memset(rsp_hdr->Signature, 0, 16);
754754

755-
rsp = work->response_buf;
755+
rsp = smb2_get_msg(work->response_buf);
756756
rsp->StructureSize = cpu_to_le16(44);
757757
rsp->Epoch = br_info->epoch;
758758
rsp->Flags = 0;
@@ -768,7 +768,7 @@ static void __smb2_lease_break_noti(struct work_struct *wk)
768768
rsp->AccessMaskHint = 0;
769769
rsp->ShareMaskHint = 0;
770770

771-
inc_rfc1001_len(rsp, 44);
771+
inc_rfc1001_len(work->response_buf, 44);
772772

773773
ksmbd_conn_write(work);
774774
ksmbd_free_work_struct(work);
@@ -1398,7 +1398,7 @@ struct lease_ctx_info *parse_lease_state(void *open_req)
13981398
if (!lreq)
13991399
return NULL;
14001400

1401-
data_offset = (char *)req + 4 + le32_to_cpu(req->CreateContextsOffset);
1401+
data_offset = (char *)req + le32_to_cpu(req->CreateContextsOffset);
14021402
cc = (struct create_context *)data_offset;
14031403
do {
14041404
cc = (struct create_context *)((char *)cc + next);
@@ -1462,7 +1462,7 @@ struct create_context *smb2_find_context_vals(void *open_req, const char *tag)
14621462
* CreateContextsOffset and CreateContextsLength are guaranteed to
14631463
* be valid because of ksmbd_smb2_check_message().
14641464
*/
1465-
cc = (struct create_context *)((char *)req + 4 +
1465+
cc = (struct create_context *)((char *)req +
14661466
le32_to_cpu(req->CreateContextsOffset));
14671467
remain_len = le32_to_cpu(req->CreateContextsLength);
14681468
do {

fs/ksmbd/smb2misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
351351
struct smb2_hdr *hdr = &pdu->hdr;
352352
int command;
353353
__u32 clc_len; /* calculated length */
354-
__u32 len = get_rfc1002_len(pdu);
354+
__u32 len = get_rfc1002_len(work->request_buf);
355355

356356
if (le32_to_cpu(hdr->NextCommand) > 0)
357357
len = le32_to_cpu(hdr->NextCommand);

0 commit comments

Comments
 (0)