From patchwork Tue Dec 6 22:02:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovskiy X-Patchwork-Id: 9463319 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 199BB60231 for ; Tue, 6 Dec 2016 22:17:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B41E284F3 for ; Tue, 6 Dec 2016 22:17:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00392284F5; Tue, 6 Dec 2016 22:17:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 799FB284F3 for ; Tue, 6 Dec 2016 22:17:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751476AbcLFWRv (ORCPT ); Tue, 6 Dec 2016 17:17:51 -0500 Received: from mail-bn3nam01on0100.outbound.protection.outlook.com ([104.47.33.100]:51568 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751817AbcLFWRt (ORCPT ); Tue, 6 Dec 2016 17:17:49 -0500 X-Greylist: delayed 892 seconds by postgrey-1.27 at vger.kernel.org; Tue, 06 Dec 2016 17:17:41 EST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=bXBwqe0SsplEVPcA4iHsdYe+mgRh+6sx41JGRBD/rhM=; b=bugshJLOF8eqfYyqZyo6UyQS1ssBaItf3XCjfIwRPGxMHvNkKCBRhZF27wlojDKKVg44hawvTZ2r51hOG/TeTocDuXYxwmO6PfEGBCWxS3GzkSJJbrExMGqOCt9LILpb4GcfwI/PgbH4x7Damlq/ACKki0ECOF9W59TOB1xcWtQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pshilov@microsoft.com; Received: from ubuntu-vm.corp.microsoft.com (2001:4898:80e8:2::63b) by CY4PR03MB2549.namprd03.prod.outlook.com (10.173.41.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.761.9; Tue, 6 Dec 2016 22:02:47 +0000 From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 05/15] CIFS: Separate SMB2 sync header processing Date: Tue, 6 Dec 2016 14:02:28 -0800 Message-Id: <1481061758-52020-6-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481061758-52020-1-git-send-email-pshilov@microsoft.com> References: <1481061758-52020-1-git-send-email-pshilov@microsoft.com> MIME-Version: 1.0 X-Originating-IP: [2001:4898:80e8:2::63b] X-ClientProxiedBy: CY1PR17CA0004.namprd17.prod.outlook.com (10.163.68.14) To CY4PR03MB2549.namprd03.prod.outlook.com (10.173.41.148) X-MS-Office365-Filtering-Correlation-Id: 15d8e587-bf83-4d54-04d9-08d41e239d29 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:CY4PR03MB2549; X-Microsoft-Exchange-Diagnostics: 1; CY4PR03MB2549; 3:4UApr/XwxOOEC+TfJIlGKyEF3sfvedLXw+oYIh6ZwJWzVfwvQNMquCVdm4QQANlF1y4KAR8nXCDB8+Pfx+7rEjj1lGcr/3CtmQpCzPgPgfnFRlOR+/MWBF2oACUTrn0q1PKjWd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J0WEr8+3xsSO3/YACQsGtfUTqjf3QPl87EQeAwVm73WSrNfrKM0xoKzSriSbeHSp9UZllqJerT9sP+qc8xW+7Y7XgwKS44rEFJtHsdmokDktanyyPefEO3bh2BfuCpzbcmq8kzn4AZj40vpRXByUZ2u4gIrhyBaiLEg/9OnQlzj2WuyAGErm2EAcrBErr4zHPD4/luxPT0uzOvQwehe+vPkqpsxUU87i1M73ktmMJvhdXuNcJnpj6Nxq5G+C1tQh2ge1RKsipvNT3JircDoOK0t3FU; 20:LFcJnGWSu6zJjWaXXkj/JOl/ifo5vr/TaGp+S448SiXFxDNjbtj2zjlcppi6d1KTpxKCtb79E35jLycTxuFCvLXQiIvCkUxAyzkFjmtKam6sHe0vAQkmrcFvr6YBsmODKJfnE5/rglayZhb0kT44UX8VbBgfNkhWfGqj6FNtJgYS9xWHMUFjTvb/QEa6A98l012tZdey4tLNiClwK3aX+7VDaKDe3K+z1Sutk65yDBzysFTPaQfL8Vru/+aQZ+iEZgrzjPh7/mE/Vh9y4uccxnKVpU2Z5QSfp4Wi8fprOJudacJrPMtGb6VsZSfo1OsZERN114IyCDJmBIQFPRLswrVMJNCmatpBM+66SmZ73zkFbt1emVOhTwz4bpL6Vz5neNRomJexOuHewQP0vM8sIY3iMLvLILr1J3FlSoDQtbt87SkkPXfSLz4zFtjiapJdEiItkTkMJYwVqGmDdpX7OQ+TWjy5iBTnpLXJAnfpMBzm//UhRZkj9tSHtY7UmdRP X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(158342451672863); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123560025)(20161123562025)(20161123564025)(20161123555025)(6047074)(6072148); SRVR:CY4PR03MB2549; BCL:0; PCL:0; RULEID:; SRVR:CY4PR03MB2549; X-Microsoft-Exchange-Diagnostics: 1; CY4PR03MB2549; 4:Y4qVhLYj+8w5Sm4Djzl3YzBM7WrAHmfa6chgp5V3esITv440o6kdAoeFK9M29/fShT1zm8Kz+SJa9uuN+/bxqvvZTc4WeAocDVdtwIn4sQ2YEUb21yWlvcZ5frzEFbP1K9r4yqU99ECD6TnR1egujM9D044iIAR3X32WAPL4QdcGBNshenqmnnZueiVFPfYLJMBv7mSiXybw0wJdRg8vUA1e1cI7C2Y/yfirRhP6oIO1v5mxWujc8smGE5sZZq5qyl8kiHpeqdEQ5XqyJ9fGMwemaS67xmLk4zfs0sG2CmSvfyoUMFz6NtXW2z0F6KgHLsli2eStUVp3D1shyadECZ4VkO4SqNtaBHCD8C60kHIH0rkSPbj5a8i9gAdvLRzKfy9CwivHvGKzA9IXH7eVsMXBgGhXDsIKdjfX3I8Nm6dw575yMKsQE+ZqgWL1WOjS7oUjAxluo28twOsuaLYxUc9HhVwjWcH1dppxOnaQVC4ISJR3v58LPDJmsVEy2jdKz45cDiHeJ7N8gXsAxrui4woCQBLPb8dq6vv4BVxt4hv3edNCIIxcRqgACfLg9zE1fFzf7l3uhmzxs2vh8d+avGmGB21bsyFNzTtBGT7Na9mUVZflsD/YswYR3784FuwKtCR3tOQKuZvG0jiCHgVVtZqiEAdivEpxAEcY0fTC0Ug= X-Forefront-PRVS: 01480965DA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(50466002)(92566002)(101416001)(86362001)(33646002)(47776003)(48376002)(2950100002)(6916009)(106356001)(105586002)(6666003)(50986999)(42186005)(39860400001)(39850400001)(39840400001)(86612001)(76176999)(2361001)(110136003)(2351001)(450100001)(189998001)(5660300001)(10090500001)(5003940100001)(10290500002)(38730400001)(5005710100001)(8676002)(6116002)(36756003)(107886002)(39410400001)(733004)(7846002)(2906002)(39450400002)(6486002)(7736002)(50226002)(68736007)(305945005)(81156014)(97736004)(81166006); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR03MB2549; H:ubuntu-vm.corp.microsoft.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR03MB2549; 23:BnNNMPM5KN+27KAcaCXtPXIcSa5mZv0vYQzHXMmp4?= =?us-ascii?Q?noRV5O6B+OXfu9j3do+AOqmxRHkkYeGIkqihqWfy7QgNs9fyEbTPee6zH4uF?= =?us-ascii?Q?7w4SJzAAF/1x8ntK3zRjpgbdSZWn+/UCXhrOjrgnWcw6J43JeKK3gLiUGYvL?= =?us-ascii?Q?aJRfSV0Z5wTx7KLcIC142B2j8uV/xBW6Jg2wQ3Z0YXE3ScO2Z47Na+qxCAze?= =?us-ascii?Q?LqvwZTiMPzuYBDGJqKxCtnNm8VQHb/1ODVW6ZO1jWIP5ycTi2giqOYauGWiP?= =?us-ascii?Q?tMZBN3EnU52uQ/7sPIbG/RGUEL/0hBhefwpg048sYs2L/0VAQOdLHzwsz8BO?= =?us-ascii?Q?Z5MdyBZw5NnZxXT9wNGnrWaj5lMxiGraSSrzTYPr49qVOAdRsq25oIqAwl8H?= =?us-ascii?Q?Pewzd6dKml1BToKqZtNZhrG+YzKC6cAwqK/rVnnHPmbKV/kT3kxRUTB2EuVc?= =?us-ascii?Q?GQ6xF1H4JHydwmuTrutkdIcPxToZ31hmjNTRSxQastqbO39zExmInB33sKto?= =?us-ascii?Q?joHlhzeyVv4pCX5Ek2bVNoPY9+XIjwGi8wE+CI+FVG/KKKudp1NiDmW5GqcK?= =?us-ascii?Q?Gxqswt5lnNhGPuuRBzN8yGm3Jybu1nm4XG7vPSNR+CwhiSO84w/AEC2LSVKF?= =?us-ascii?Q?RhV1+ynjEBOb5BbQ9fGJzvp7nvMrNfm8ZoRzFPzzYDbNTu8iV+oP51YqAlTi?= =?us-ascii?Q?RtRIG4q7/wYXINVri6cshsVaJtEcY6XqYIukcBkl+z3AxZyoOwKtQjzLkERI?= =?us-ascii?Q?IQXcTZTKL7iK95E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nfYcTNG3fucguasQbLeXwBVlaLkjBrsFSBziX6GhNRBSF9Nf6GC456tBzWqlfCrrw29M0HDGtd7/jYuuhy3NLQ==; 5:6zbOQDOfYFsMTcGLBDap1YnSWgF2p4oYpY7ujdHb+l5nPDU+zoCKq7PMbAzIsbPq0lvRZMoiocRmyaZqRgZla3hZkaiURLmIUMYe+6kH0UKbNX2vXrLrg577XvHOVeJtVCG1cTzEcmXMZiXxGVEYvxDO8Dmq313fJ+V/9JJQtck=; 24:mEjcSWwLQ91GnOokDiXE7KRbqDTKeNiC3CqFDrfhUqg/x0zyTx6etsEPc8MVUzSzq3nMW0eXlWQMjyGhTuXf8+YH5p3lJzBDvYobe3eeEpg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR03MB2549; 7:A6pIYxFknZmXeeVlzwUxtGU2kD24vESkGZjVmh9mczWQkn44hd6GIBSPXJl5On97aHN2wx1NLioCvggJRkEdYUREI6rKeW3hGAoFz6VgrBA1dsiHA2Ejmlb5ZTmqimHfpVVCfpcXXPciAcr9YHE4DBMPaOSfXHAB4zJZOjAQl8Ai3Ch7L1pDyzDuR8FZTy/mKg8OceSb2wP7vvl+JtGR2h/pu7Ry/6hk7GnHeNJXFXSOnxSeqCHMRrcL/xviYjtsG0ULbro9nhG2Z0d9p73yriC5NvYib3MkqDIb3Zuqs6orGJmAVTjuRIZDS/dRVScFSuQ0rYZ2eIxRTVJhg8J9umD6E5tCtlhhxpfzb5H8Iu7Fhz+h9WAgSOPMtPErOXBHmdnEVoEF04kmqdEupcO8A1yBNEnOAMg6R+gmAz+Yo2o4cVs1XiTt6vjP3T3iw+nX6UUgEqcKLnQLKKnWTaZZxw== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2016 22:02:47.4591 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR03MB2549 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Do not process RFC1001 length in smb2_hdr_assemble() because it is not a part of SMB2 header. This allows to cleanup the code and adds a possibility combine several SMB2 packets into one for compounding. Signed-off-by: Pavel Shilovsky --- fs/cifs/smb2pdu.c | 50 ++++++++++++++++++++++++++++++-------------------- fs/cifs/smb2pdu.h | 5 +++++ 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 438c4b1..f6ba2c0 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -79,25 +79,9 @@ static const int smb2_req_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = { static void -smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ , +smb2_hdr_assemble(struct smb2_sync_hdr *shdr, __le16 smb2_cmd, const struct cifs_tcon *tcon) { - struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; - struct smb2_sync_hdr *shdr = get_sync_hdr(hdr); - char *temp = (char *)hdr; - /* lookup word count ie StructureSize from table */ - __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_cmd)]; - - /* - * smaller than SMALL_BUFFER_SIZE but bigger than fixed area of - * largest operations (Create) - */ - memset(temp, 0, 256); - - /* Note this is only network field converted to big endian */ - hdr->smb2_buf_length = - cpu_to_be32(parmsize + sizeof(struct smb2_sync_hdr)); - shdr->ProtocolId = SMB2_PROTO_NUMBER; shdr->StructureSize = cpu_to_le16(64); shdr->Command = smb2_cmd; @@ -149,7 +133,6 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ , if (tcon->ses && tcon->ses->server && tcon->ses->server->sign) shdr->Flags |= SMB2_FLAGS_SIGNED; out: - pdu->StructureSize2 = cpu_to_le16(parmsize); return; } @@ -290,6 +273,26 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon) return rc; } +static void +fill_small_buf(__le16 smb2_command, struct cifs_tcon *tcon, void *buf, + unsigned int *total_len) +{ + struct smb2_sync_pdu *spdu = (struct smb2_sync_pdu *)buf; + /* lookup word count ie StructureSize from table */ + __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_command)]; + + /* + * smaller than SMALL_BUFFER_SIZE but bigger than fixed area of + * largest operations (Create) + */ + memset(buf, 0, 256); + + smb2_hdr_assemble(&spdu->sync_hdr, smb2_command, tcon); + spdu->StructureSize2 = cpu_to_le16(parmsize); + + *total_len = parmsize + sizeof(struct smb2_sync_hdr); +} + /* * Allocate and return pointer to an SMB request hdr, and set basic * SMB information in the SMB header. If the return code is zero, this @@ -299,7 +302,9 @@ static int small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon, void **request_buf) { - int rc = 0; + int rc; + unsigned int total_len; + struct smb2_pdu *pdu; rc = smb2_reconnect(smb2_command, tcon); if (rc) @@ -312,7 +317,12 @@ small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon, return -ENOMEM; } - smb2_hdr_assemble((struct smb2_hdr *) *request_buf, smb2_command, tcon); + pdu = (struct smb2_pdu *)(*request_buf); + + fill_small_buf(smb2_command, tcon, get_sync_hdr(pdu), &total_len); + + /* Note this is only network field converted to big endian */ + pdu->hdr.smb2_buf_length = cpu_to_be32(total_len); if (tcon != NULL) { #ifdef CONFIG_CIFS_STATS2 diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h index 8dd24b7..052342d 100644 --- a/fs/cifs/smb2pdu.h +++ b/fs/cifs/smb2pdu.h @@ -117,6 +117,11 @@ struct smb2_sync_hdr { __u8 Signature[16]; } __packed; +struct smb2_sync_pdu { + struct smb2_sync_hdr sync_hdr; + __le16 StructureSize2; /* size of wct area (varies, request specific) */ +} __packed; + struct smb2_hdr { __be32 smb2_buf_length; /* big endian on wire */ /* length is only two or three bytes - with */