private bool CheckSMBDNegotiate() { try { using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout)) { var config = DetectionInfo.SMBDClientCapability; client.ConnectOverRDMA(DetectionInfo.DriverRdmaNICIPAddress, DetectionInfo.SUTRdmaNICIPAddress, DetectionInfo.SMBDPort, config.MaxReceiveSize); client.SMBDNegotiate( config.CreditsRequested, config.ReceiveCreditMax, config.PreferredSendSize, config.MaxReceiveSize, config.MaxFragmentedSize ); return(true); } } catch (Exception ex) { DetectorUtil.WriteLog(String.Format("CheckSMBDNegotiate threw exception: {0}", ex)); return(false); } }
private bool CheckSMBDReadWrite(DialectRevision[] dialects, Channel_Values channel) { try { using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout)) { var config = DetectionInfo.SMBDClientCapability; RdmaAdapterInfo rdmaAdapterInfo; client.ConnectOverRDMA(DetectionInfo.DriverRdmaNICIPAddress, DetectionInfo.SUTRdmaNICIPAddress, DetectionInfo.SMBDPort, config.MaxReceiveSize, out rdmaAdapterInfo); client.SMBDNegotiate( config.CreditsRequested, config.ReceiveCreditMax, config.PreferredSendSize, config.MaxReceiveSize, config.MaxFragmentedSize ); client.Smb2Negotiate(dialects); client.Smb2SessionSetup(DetectionInfo.Authentication, DetectionInfo.DomainName, DetectionInfo.SUTName, DetectionInfo.UserName, DetectionInfo.Password); string path = Smb2Utility.GetUncPath(DetectionInfo.SUTName, DetectionInfo.ShareFolder); uint treeId; client.Smb2TreeConnect(path, out treeId); FILEID fileId; client.CreateRandomFile(treeId, out fileId); uint length = client.CalculateSMBDMaxReadWriteSize(); var buffer = Smb2Utility.CreateRandomByteArray((int)length); client.SMBDWrite(treeId, fileId, channel, buffer, 0, DetectionInfo.Endian); var readBuffer = new byte[length]; client.SMBDRead(treeId, fileId, channel, out readBuffer, 0, length, DetectionInfo.Endian); if (!Enumerable.SequenceEqual(buffer, readBuffer)) { throw new InvalidOperationException("The data is inconsistent for write and read!"); } return(true); } } catch (Exception ex) { DetectorUtil.WriteLog(String.Format("CheckSMBDReadWrite threw exception: {0}", ex)); return(false); } }
public bool ConnectToShare(string serverIp, string clientIp) { try { using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout)) { client.Connect(IPAddress.Parse(serverIp), IPAddress.Parse(clientIp)); client.Smb2Negotiate(DetectionInfo.SupportedSmbDialects); client.Smb2SessionSetup(DetectionInfo.Authentication, DetectionInfo.DomainName, DetectionInfo.SUTName, DetectionInfo.UserName, DetectionInfo.Password); string path = Smb2Utility.GetUncPath(DetectionInfo.SUTName, DetectionInfo.ShareFolder); uint treeId; client.Smb2TreeConnect(path, out treeId); FILEID fileId; client.CreateRandomFile(treeId, out fileId); uint fileLength = client.CalculateSmb2MaxReadWriteSize(); var buffer = Smb2Utility.CreateRandomByteArray((int)fileLength); client.Smb2Write(treeId, fileId, 0, buffer); byte[] output; client.Smb2Read(treeId, fileId, 0, fileLength, out output); bool result = Enumerable.SequenceEqual(buffer, output); if (!result) { DetectorUtil.WriteLog("The content of read and write is inconsistent."); } return(result); } } catch (Exception ex) { DetectorUtil.WriteLog(String.Format("ConnectToShare threw exception: {0}", ex)); return(false); } }
private bool TryNegotiateDialect(IPAddress ip, DialectRevision dialect) { try { using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout)) { client.Connect(ip, IPAddress.Parse(DetectionInfo.DriverNonRdmaNICIPAddress)); client.Smb2Negotiate(new DialectRevision[] { dialect }); return(true); } } catch (Exception ex) { DetectorUtil.WriteLog(String.Format("TryNegotiateDialect threw exception: {0}", ex)); return(false); } }
private bool GetRemoteNetworkInterfaceInformation(IPAddress ip) { try { using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout)) { client.Connect(ip, IPAddress.Parse(DetectionInfo.DriverNonRdmaNICIPAddress)); client.Smb2Negotiate(new DialectRevision[] { DialectRevision.Smb30, DialectRevision.Smb302, DialectRevision.Smb311 }); client.Smb2SessionSetup(DetectionInfo.Authentication, DetectionInfo.DomainName, DetectionInfo.SUTName, DetectionInfo.UserName, DetectionInfo.Password); uint treeId; string ipcPath = Smb2Utility.GetIPCPath(DetectionInfo.SUTName); client.Smb2TreeConnect(ipcPath, out treeId); byte[] input; byte[] output; client.IoCtl(treeId, CtlCode_Values.FSCTL_QUERY_NETWORK_INTERFACE_INFO, FILEID.Invalid, IOCTL_Request_Flags_Values.SMB2_0_IOCTL_IS_FSCTL, out input, out output); var networkInterfaces = Smb2Utility.UnmarshalNetworkInterfaceInfoResponse(output); var remoteInterfaces = ParseRemoteNetworkInterfaceInformation(networkInterfaces); FilterNetworkInterfaces(remoteInterfaces); return(true); } } catch (Exception ex) { DetectorUtil.WriteLog(String.Format("GetRemoteNetworkInterfaceInformation failed for {0}: {1}.", ip.ToString(), ex.ToString())); return(false); } }