Skip to content

Commit 96d3cca

Browse files
committed
smb3: Send netname context during negotiate protocol
See MS-SMB2 2.2.3.1.4 Allows hostname to be used by load balancers Signed-off-by: Steve French <[email protected]>
1 parent 9fe5ff1 commit 96d3cca

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

fs/cifs/smb2pdu.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,21 @@ build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt)
495495
pneg_ctxt->Ciphers[1] = SMB2_ENCRYPTION_AES128_CCM;
496496
}
497497

498+
static unsigned int
499+
build_netname_ctxt(struct smb2_netname_neg_context *pneg_ctxt, char *hostname)
500+
{
501+
struct nls_table *cp = load_nls_default();
502+
503+
pneg_ctxt->ContextType = SMB2_NETNAME_NEGOTIATE_CONTEXT_ID;
504+
505+
/* copy up to max of first 100 bytes of server name to NetName field */
506+
pneg_ctxt->DataLength = cpu_to_le16(2 +
507+
(2 * cifs_strtoUTF16(pneg_ctxt->NetName, hostname, 100, cp)));
508+
/* context size is DataLength + minimal smb2_neg_context */
509+
return DIV_ROUND_UP(le16_to_cpu(pneg_ctxt->DataLength) +
510+
sizeof(struct smb2_neg_context), 8) * 8;
511+
}
512+
498513
static void
499514
build_posix_ctxt(struct smb2_posix_neg_context *pneg_ctxt)
500515
{
@@ -559,9 +574,15 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
559574
8) * 8;
560575
*total_len += ctxt_len;
561576
pneg_ctxt += ctxt_len;
562-
req->NegotiateContextCount = cpu_to_le16(4);
577+
req->NegotiateContextCount = cpu_to_le16(5);
563578
} else
564-
req->NegotiateContextCount = cpu_to_le16(3);
579+
req->NegotiateContextCount = cpu_to_le16(4);
580+
581+
ctxt_len = build_netname_ctxt((struct smb2_netname_neg_context *)pneg_ctxt,
582+
server->hostname);
583+
*total_len += ctxt_len;
584+
pneg_ctxt += ctxt_len;
585+
565586
build_posix_ctxt((struct smb2_posix_neg_context *)pneg_ctxt);
566587
*total_len += sizeof(struct smb2_posix_neg_context);
567588
}

fs/cifs/smb2pdu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ struct smb2_compression_capabilities_context {
317317
* For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
318318
* Its struct simply contains NetName, an array of Unicode characters
319319
*/
320+
struct smb2_netname_neg_context {
321+
__le16 ContextType; /* 0x100 */
322+
__le16 DataLength;
323+
__le32 Reserved;
324+
__le16 NetName[0]; /* hostname of target converted to UCS-2 */
325+
} __packed;
320326

321327
#define POSIX_CTXT_DATA_LEN 16
322328
struct smb2_posix_neg_context {

0 commit comments

Comments
 (0)