Server: Enabled Large MTU support

This commit is contained in:
Tal Aloni 2020-01-31 12:12:24 +02:00
parent 85bc276cb0
commit 2ee081ab51
3 changed files with 35 additions and 12 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. /* Copyright (C) 2017-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
* *
* You can redistribute this program and/or modify it under the terms of * You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation, * the GNU Lesser Public License as published by the Free Software Foundation,
@ -22,9 +22,12 @@ namespace SMBLibrary.Server.SMB2
public const uint ServerMaxTransactSize = 65536; public const uint ServerMaxTransactSize = 65536;
public const uint ServerMaxReadSize = 65536; public const uint ServerMaxReadSize = 65536;
public const uint ServerMaxWriteSize = 65536; public const uint ServerMaxWriteSize = 65536;
public const uint ServerMaxTransactSizeLargeMTU = 8388608;
public const uint ServerMaxReadSizeLargeMTU = 8388608;
public const uint ServerMaxWriteSizeLargeMTU = 8388608;
// Special case - SMB2 client initially connecting using SMB1 // Special case - SMB2 client initially connecting using SMB1
internal static SMB2Command GetNegotiateResponse(List<string> smb2Dialects, GSSProvider securityProvider, ConnectionState state, Guid serverGuid, DateTime serverStartTime) internal static SMB2Command GetNegotiateResponse(List<string> smb2Dialects, GSSProvider securityProvider, ConnectionState state, SMBTransportType transportType, Guid serverGuid, DateTime serverStartTime)
{ {
NegotiateResponse response = new NegotiateResponse(); NegotiateResponse response = new NegotiateResponse();
response.Header.Credits = 1; response.Header.Credits = 1;
@ -44,16 +47,26 @@ namespace SMBLibrary.Server.SMB2
} }
response.SecurityMode = SecurityMode.SigningEnabled; response.SecurityMode = SecurityMode.SigningEnabled;
response.ServerGuid = serverGuid; response.ServerGuid = serverGuid;
response.MaxTransactSize = ServerMaxTransactSize; if (state.Dialect != SMBDialect.SMB202 && transportType == SMBTransportType.DirectTCPTransport)
response.MaxReadSize = ServerMaxReadSize; {
response.MaxWriteSize = ServerMaxWriteSize; response.Capabilities = Capabilities.LargeMTU;
response.MaxTransactSize = ServerMaxTransactSizeLargeMTU;
response.MaxReadSize = ServerMaxReadSizeLargeMTU;
response.MaxWriteSize = ServerMaxWriteSizeLargeMTU;
}
else
{
response.MaxTransactSize = ServerMaxTransactSize;
response.MaxReadSize = ServerMaxReadSize;
response.MaxWriteSize = ServerMaxWriteSize;
}
response.SystemTime = DateTime.Now; response.SystemTime = DateTime.Now;
response.ServerStartTime = serverStartTime; response.ServerStartTime = serverStartTime;
response.SecurityBuffer = securityProvider.GetSPNEGOTokenInitBytes(); response.SecurityBuffer = securityProvider.GetSPNEGOTokenInitBytes();
return response; return response;
} }
internal static SMB2Command GetNegotiateResponse(NegotiateRequest request, GSSProvider securityProvider, ConnectionState state, Guid serverGuid, DateTime serverStartTime) internal static SMB2Command GetNegotiateResponse(NegotiateRequest request, GSSProvider securityProvider, ConnectionState state, SMBTransportType transportType, Guid serverGuid, DateTime serverStartTime)
{ {
NegotiateResponse response = new NegotiateResponse(); NegotiateResponse response = new NegotiateResponse();
if (request.Dialects.Contains(SMB2Dialect.SMB210)) if (request.Dialects.Contains(SMB2Dialect.SMB210))
@ -73,9 +86,19 @@ namespace SMBLibrary.Server.SMB2
} }
response.SecurityMode = SecurityMode.SigningEnabled; response.SecurityMode = SecurityMode.SigningEnabled;
response.ServerGuid = serverGuid; response.ServerGuid = serverGuid;
response.MaxTransactSize = ServerMaxTransactSize; if (state.Dialect != SMBDialect.SMB202 && transportType == SMBTransportType.DirectTCPTransport)
response.MaxReadSize = ServerMaxReadSize; {
response.MaxWriteSize = ServerMaxWriteSize; response.Capabilities = Capabilities.LargeMTU;
response.MaxTransactSize = ServerMaxTransactSizeLargeMTU;
response.MaxReadSize = ServerMaxReadSizeLargeMTU;
response.MaxWriteSize = ServerMaxWriteSizeLargeMTU;
}
else
{
response.MaxTransactSize = ServerMaxTransactSize;
response.MaxReadSize = ServerMaxReadSize;
response.MaxWriteSize = ServerMaxWriteSize;
}
response.SystemTime = DateTime.Now; response.SystemTime = DateTime.Now;
response.ServerStartTime = serverStartTime; response.ServerStartTime = serverStartTime;
response.SecurityBuffer = securityProvider.GetSPNEGOTokenInitBytes(); response.SecurityBuffer = securityProvider.GetSPNEGOTokenInitBytes();

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. /* Copyright (C) 2017-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
* *
* You can redistribute this program and/or modify it under the terms of * You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation, * the GNU Lesser Public License as published by the Free Software Foundation,
@ -83,7 +83,7 @@ namespace SMBLibrary.Server
if (command is NegotiateRequest) if (command is NegotiateRequest)
{ {
NegotiateRequest request = (NegotiateRequest)command; NegotiateRequest request = (NegotiateRequest)command;
SMB2Command response = NegotiateHelper.GetNegotiateResponse(request, m_securityProvider, state, m_serverGuid, m_serverStartTime); SMB2Command response = NegotiateHelper.GetNegotiateResponse(request, m_securityProvider, state, m_transport, m_serverGuid, m_serverStartTime);
if (state.Dialect != SMBDialect.NotSet) if (state.Dialect != SMBDialect.NotSet)
{ {
state = new SMB2ConnectionState(state); state = new SMB2ConnectionState(state);

View file

@ -319,7 +319,7 @@ namespace SMBLibrary.Server
List<string> smb2Dialects = SMB2.NegotiateHelper.FindSMB2Dialects(message); List<string> smb2Dialects = SMB2.NegotiateHelper.FindSMB2Dialects(message);
if (smb2Dialects.Count > 0) if (smb2Dialects.Count > 0)
{ {
SMB2Command response = SMB2.NegotiateHelper.GetNegotiateResponse(smb2Dialects, m_securityProvider, state, m_serverGuid, m_serverStartTime); SMB2Command response = SMB2.NegotiateHelper.GetNegotiateResponse(smb2Dialects, m_securityProvider, state, m_transport, m_serverGuid, m_serverStartTime);
if (state.Dialect != SMBDialect.NotSet) if (state.Dialect != SMBDialect.NotSet)
{ {
state = new SMB2ConnectionState(state); state = new SMB2ConnectionState(state);