123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- /* Copyright (C) 2012-2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
- *
- * 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,
- * either version 3 of the License, or (at your option) any later version.
- */
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using Utilities;
- namespace ISCSI.Server
- {
- public delegate ushort GetNextTSIH();
- public class ISCSIServer // Server may serve more than one target
- {
- public const int DefaultPort = 3260;
- // Offered Session Parameters:
- public static bool OfferedInitialR2T = true;
- public static bool OfferedImmediateData = true;
- public static int OfferedMaxBurstLength = SessionParameters.DefaultMaxBurstLength;
- public static int OfferedFirstBurstLength = SessionParameters.DefaultFirstBurstLength;
- public static int OfferedDefaultTime2Wait = 0;
- public static int OfferedDefaultTime2Retain = 20;
- public static int OfferedMaxOutstandingR2T = 1;
- public static bool OfferedDataPDUInOrder = true;
- public static bool OfferedDataSequenceInOrder = true;
- public static int OfferedErrorRecoveryLevel = 0;
- public static int OfferedMaxConnections = 1;
- private List<ISCSITarget> m_targets;
- private int m_port;
- private ushort m_nextTSIH = 1; // Next Target Session Identifying Handle
- private Socket m_listenerSocket;
- private bool m_listening;
- public ConnectionManager m_connectionManager = new ConnectionManager();
- public event EventHandler<LogEntry> OnLogEntry;
-
- public ISCSIServer(List<ISCSITarget> targets) : this(targets, DefaultPort)
- { }
- public ISCSIServer(List<ISCSITarget> targets, int port) : this(targets, port, String.Empty)
- { }
- /// <summary>
- /// Server needs to be started with Start()
- /// </summary>
- public ISCSIServer(List<ISCSITarget> targets, int port, string logFilePath)
- {
- m_port = port;
- m_targets = targets;
- }
- public void Start()
- {
- if (!m_listening)
- {
- Log(Severity.Information, "Starting Server");
- m_listening = true;
- m_listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- m_listenerSocket.Bind(new IPEndPoint(IPAddress.Any, m_port));
- m_listenerSocket.Listen(1000);
- m_listenerSocket.BeginAccept(ConnectRequestCallback, m_listenerSocket);
- }
- }
- // This method accepts new connections
- private void ConnectRequestCallback(IAsyncResult ar)
- {
- Socket listenerSocket = (Socket)ar.AsyncState;
- Socket clientSocket;
- try
- {
- clientSocket = listenerSocket.EndAccept(ar);
- }
- catch (ObjectDisposedException)
- {
- return;
- }
- catch (SocketException)
- {
- return;
- }
- Log(Severity.Information, "New connection has been accepted");
- ConnectionState state = new ConnectionState();
- state.ConnectionParameters.InitiatorEndPoint = clientSocket.RemoteEndPoint as IPEndPoint;
- state.ReceiveBuffer = new byte[ConnectionState.ReceiveBufferSize];
- // Disable the Nagle Algorithm for this tcp socket:
- clientSocket.NoDelay = true;
- state.ClientSocket = clientSocket;
- Thread senderThread = new Thread(delegate()
- {
- ProcessSendQueue(state);
- });
- senderThread.IsBackground = true;
- senderThread.Start();
- try
- {
- clientSocket.BeginReceive(state.ReceiveBuffer, 0, ConnectionState.ReceiveBufferSize, 0, ReceiveCallback, state);
- }
- catch (ObjectDisposedException)
- {
- Log(Severity.Debug, "[OnConnectRequest] BeginReceive ObjectDisposedException");
- }
- catch (SocketException ex)
- {
- Log(Severity.Debug, "[OnConnectRequest] BeginReceive SocketException: {0}", ex.Message);
- }
- m_listenerSocket.BeginAccept(ConnectRequestCallback, m_listenerSocket);
- }
- public void Stop()
- {
- Log(Severity.Information, "Stopping Server");
- m_listening = false;
- SocketUtils.ReleaseSocket(m_listenerSocket);
- }
- private void ReceiveCallback(IAsyncResult result)
- {
- if (!m_listening)
- {
- return;
- }
- ConnectionState state = (ConnectionState)result.AsyncState;
- Socket clientSocket = state.ClientSocket;
- if (!clientSocket.Connected)
- {
- return;
- }
- int numberOfBytesReceived;
- try
- {
- numberOfBytesReceived = clientSocket.EndReceive(result);
- }
- catch (ObjectDisposedException)
- {
- Log(Severity.Debug, "[ReceiveCallback] EndReceive ObjectDisposedException");
- return;
- }
- catch (SocketException ex)
- {
- Log(Severity.Debug, "[ReceiveCallback] EndReceive SocketException: {0}", ex.Message);
- return;
- }
- if (numberOfBytesReceived == 0)
- {
- // The other side has closed the connection
- clientSocket.Close();
- Log(Severity.Verbose, "The initiator has closed the connection");
- // Wait for pending I/O to complete.
- state.RunningSCSICommands.WaitUntilZero();
- state.SendQueue.Stop();
- m_connectionManager.RemoveConnection(state);
- return;
- }
- byte[] currentBuffer = ByteReader.ReadBytes(state.ReceiveBuffer, 0, numberOfBytesReceived);
- ProcessCurrentBuffer(currentBuffer, state);
- try
- {
- clientSocket.BeginReceive(state.ReceiveBuffer, 0, ConnectionState.ReceiveBufferSize, 0, ReceiveCallback, state);
- }
- catch (ObjectDisposedException)
- {
- Log(Severity.Debug, "[ReceiveCallback] BeginReceive ObjectDisposedException");
- }
- catch (SocketException ex)
- {
- Log(Severity.Debug, "[ReceiveCallback] BeginReceive SocketException: {0}", ex.Message);
- }
- }
- private void ProcessCurrentBuffer(byte[] currentBuffer, ConnectionState state)
- {
- Socket clientSocket = state.ClientSocket;
- if (state.ConnectionBuffer.Length == 0)
- {
- state.ConnectionBuffer = currentBuffer;
- }
- else
- {
- state.ConnectionBuffer = ByteUtils.Concatenate(state.ConnectionBuffer, currentBuffer);
- }
- // we now have all PDU bytes received so far in state.ConnectionBuffer
- int bytesLeftInBuffer = state.ConnectionBuffer.Length;
- while (bytesLeftInBuffer >= 8)
- {
- int bufferOffset = state.ConnectionBuffer.Length - bytesLeftInBuffer;
- int pduLength = ISCSIPDU.GetPDULength(state.ConnectionBuffer, bufferOffset);
- if (pduLength > bytesLeftInBuffer)
- {
- Log(Severity.Debug, "[{0}][ProcessCurrentBuffer] Bytes left in receive buffer: {1}", state.ConnectionIdentifier, bytesLeftInBuffer);
- break;
- }
- else
- {
- byte[] pduBytes = ByteReader.ReadBytes(state.ConnectionBuffer, bufferOffset, pduLength);
- bytesLeftInBuffer -= pduLength;
- ISCSIPDU pdu = null;
- try
- {
- pdu = ISCSIPDU.GetPDU(pduBytes);
- }
- catch (Exception ex)
- {
- Log(Severity.Error, "[{0}] Failed to read PDU (Exception: {1})", state.ConnectionIdentifier, ex.Message);
- RejectPDU reject = new RejectPDU();
- reject.Reason = RejectReason.InvalidPDUField;
- reject.Data = ByteReader.ReadBytes(pduBytes, 0, 48);
- state.SendQueue.Enqueue(reject);
- }
- if (pdu != null)
- {
- if (pdu.GetType() == typeof(ISCSIPDU))
- {
- Log(Severity.Error, "[{0}][ProcessCurrentBuffer] Unsupported PDU (0x{1})", state.ConnectionIdentifier, pdu.OpCode.ToString("X"));
- // Unsupported PDU
- RejectPDU reject = new RejectPDU();
- reject.InitiatorTaskTag = pdu.InitiatorTaskTag;
- reject.Reason = RejectReason.CommandNotSupported;
- reject.Data = ByteReader.ReadBytes(pduBytes, 0, 48);
- state.SendQueue.Enqueue(reject);
- }
- else
- {
- ProcessPDU(pdu, state);
- }
- }
-
- if (!clientSocket.Connected)
- {
- // Do not continue to process the buffer if the other side closed the connection
- if (bytesLeftInBuffer > 0)
- {
- Log(Severity.Debug, "[{0}] Buffer processing aborted, bytes left in receive buffer: {1}", state.ConnectionIdentifier, bytesLeftInBuffer);
- }
- return;
- }
- }
- }
- if (bytesLeftInBuffer > 0)
- {
- state.ConnectionBuffer = ByteReader.ReadBytes(state.ConnectionBuffer, state.ConnectionBuffer.Length - bytesLeftInBuffer, bytesLeftInBuffer);
- }
- else
- {
- state.ConnectionBuffer = new byte[0];
- }
- }
- private void ProcessPDU(ISCSIPDU pdu, ConnectionState state)
- {
- Socket clientSocket = state.ClientSocket;
-
- uint? cmdSN = PDUHelper.GetCmdSN(pdu);
- Log(Severity.Trace, "Entering ProcessPDU");
- Log(Severity.Verbose, "[{0}] Received PDU from initiator, Operation: {1}, Size: {2}, CmdSN: {3}", state.ConnectionIdentifier, (ISCSIOpCodeName)pdu.OpCode, pdu.Length, cmdSN);
- // RFC 3720: On any connection, the iSCSI initiator MUST send the commands in increasing order of CmdSN,
- // except for commands that are retransmitted due to digest error recovery and connection recovery.
- if (cmdSN.HasValue)
- {
- if (state.SessionParameters.CommandNumberingStarted)
- {
- if (cmdSN != state.SessionParameters.ExpCmdSN)
- {
- Log(Severity.Error, "[{0}] CmdSN outside of expected range", state.ConnectionIdentifier);
- // We ignore this PDU
- Log(Severity.Trace, "Leaving ProcessPDU");
- return;
- }
- }
- else
- {
- state.SessionParameters.ExpCmdSN = cmdSN.Value;
- state.SessionParameters.CommandNumberingStarted = true;
- }
- if (pdu is LogoutRequestPDU || pdu is TextRequestPDU || pdu is SCSICommandPDU || pdu is RejectPDU)
- {
- if (!pdu.ImmediateDelivery)
- {
- state.SessionParameters.ExpCmdSN++;
- }
- }
- }
- if (!state.SessionParameters.IsFullFeaturePhase)
- {
- if (pdu is LoginRequestPDU)
- {
- LoginRequestPDU request = (LoginRequestPDU)pdu;
- Log(Severity.Verbose, "[{0}] Login Request, current stage: {1}, next stage: {2}, parameters: {3}", state.ConnectionIdentifier, request.CurrentStage, request.NextStage, KeyValuePairUtils.ToString(request.LoginParameters));
- if (request.TSIH != 0)
- {
- // RFC 3720: A Login Request with a non-zero TSIH and a CID equal to that of an existing
- // connection implies a logout of the connection followed by a Login
- ConnectionState existingConnection = m_connectionManager.FindConnection(request.ISID, request.TSIH, request.CID);
- if (existingConnection != null)
- {
- // Perform implicit logout
- Log(Severity.Verbose, "[{0}] Initiating implicit logout", state.ConnectionIdentifier);
- // Wait for pending I/O to complete.
- existingConnection.RunningSCSICommands.WaitUntilZero();
- SocketUtils.ReleaseSocket(existingConnection.ClientSocket);
- existingConnection.SendQueue.Stop();
- m_connectionManager.RemoveConnection(existingConnection);
- Log(Severity.Verbose, "[{0}] Implicit logout completed", state.ConnectionIdentifier);
- }
- }
- LoginResponsePDU response = ServerResponseHelper.GetLoginResponsePDU(request, m_targets, state.SessionParameters, state.ConnectionParameters, ref state.Target, GetNextTSIH);
- if (state.SessionParameters.IsFullFeaturePhase)
- {
- state.SessionParameters.ISID = request.ISID;
- state.ConnectionParameters.CID = request.CID;
- m_connectionManager.AddConnection(state);
- }
- Log(Severity.Verbose, "[{0}] Login Response parameters: {1}", state.ConnectionIdentifier, KeyValuePairUtils.ToString(response.LoginParameters));
- state.SendQueue.Enqueue(response);
- }
- else
- {
- // Before the Full Feature Phase is established, only Login Request and Login Response PDUs are allowed.
- Log(Severity.Error, "[{0}] Improper command during login phase, OpCode: 0x{1}", state.ConnectionIdentifier, pdu.OpCode.ToString("x"));
- if (state.SessionParameters.TSIH == 0)
- {
- // A target receiving any PDU except a Login request before the Login phase is started MUST
- // immediately terminate the connection on which the PDU was received.
- clientSocket.Close();
- }
- else
- {
- // Once the Login phase has started, if the target receives any PDU except a Login request,
- // it MUST send a Login reject (with Status "invalid during login") and then disconnect.
- LoginResponsePDU loginResponse = new LoginResponsePDU();
- loginResponse.TSIH = state.SessionParameters.TSIH;
- loginResponse.Status = LoginResponseStatusName.InvalidDuringLogon;
- state.SendQueue.Enqueue(loginResponse);
- }
- }
- }
- else // Logged in
- {
- if (pdu is TextRequestPDU)
- {
- TextRequestPDU request = (TextRequestPDU)pdu;
- TextResponsePDU response = ServerResponseHelper.GetTextResponsePDU(request, m_targets);
- state.SendQueue.Enqueue(response);
- }
- else if (pdu is LogoutRequestPDU)
- {
- Log(Severity.Verbose, "[{0}] Logour Request", state.ConnectionIdentifier);
- LogoutRequestPDU request = (LogoutRequestPDU)pdu;
- if (state.SessionParameters.IsDiscovery && request.ReasonCode != LogoutReasonCode.CloseTheSession)
- {
- // RFC 3720: Discovery-session: The target MUST ONLY accept [..] logout request with the reason "close the session"
- RejectPDU reject = new RejectPDU();
- reject.Reason = RejectReason.ProtocolError;
- reject.Data = ByteReader.ReadBytes(pdu.GetBytes(), 0, 48);
- state.SendQueue.Enqueue(reject);
- }
- else
- {
- List<ConnectionState> connectionsToClose = new List<ConnectionState>();
- if (request.ReasonCode == LogoutReasonCode.CloseTheSession)
- {
- connectionsToClose = m_connectionManager.GetSessionConnections(state.SessionParameters.ISID, state.SessionParameters.TSIH);
- }
- else
- {
- // RFC 3720: A Logout for a CID may be performed on a different transport connection when the TCP connection for the CID has already been terminated.
- ConnectionState existingConnection = m_connectionManager.FindConnection(state.SessionParameters.ISID, state.SessionParameters.TSIH, request.CID);
- if (existingConnection != null && existingConnection != state)
- {
- connectionsToClose.Add(existingConnection);
- }
- connectionsToClose.Add(state);
- }
- foreach (ConnectionState connection in connectionsToClose)
- {
- // Wait for pending I/O to complete.
- connection.RunningSCSICommands.WaitUntilZero();
- if (connection != state)
- {
- SocketUtils.ReleaseSocket(connection.ClientSocket);
- }
- m_connectionManager.RemoveConnection(connection);
- }
- LogoutResponsePDU response = ServerResponseHelper.GetLogoutResponsePDU(request);
- state.SendQueue.Enqueue(response);
- // connection will be closed after a LogoutResponsePDU has been sent.
- }
- }
- else if (state.SessionParameters.IsDiscovery)
- {
- // The target MUST ONLY accept text requests with the SendTargets key and a logout
- // request with the reason "close the session". All other requests MUST be rejected.
- Log(Severity.Error, "[{0}] Improper command during discovery session, OpCode: 0x{1}", state.ConnectionIdentifier, pdu.OpCode.ToString("x"));
- RejectPDU reject = new RejectPDU();
- reject.Reason = RejectReason.ProtocolError;
- reject.Data = ByteReader.ReadBytes(pdu.GetBytes(), 0, 48);
- state.SendQueue.Enqueue(reject);
- }
- else if (pdu is NOPOutPDU)
- {
- NOPOutPDU request = (NOPOutPDU)pdu;
- if (request.InitiatorTaskTag != 0xFFFFFFFF)
- {
- NOPInPDU response = ServerResponseHelper.GetNOPResponsePDU(request);
- state.SendQueue.Enqueue(response);
- }
- }
- else if (pdu is SCSIDataOutPDU || pdu is SCSICommandPDU)
- {
- // RFC 3720: the iSCSI target layer MUST deliver the commands for execution (to the SCSI execution engine) in the order specified by CmdSN.
- // e.g. read requests should not be executed while previous write request data is being received (via R2T)
- List<SCSICommandPDU> commandsToExecute = null;
- List<ReadyToTransferPDU> readyToTransferPDUs = new List<ReadyToTransferPDU>();
- if (pdu is SCSIDataOutPDU)
- {
- SCSIDataOutPDU request = (SCSIDataOutPDU)pdu;
- Log(Severity.Debug, "[{0}] SCSIDataOutPDU: Target transfer tag: {1}, LUN: {2}, Buffer offset: {3}, Data segment length: {4}, DataSN: {5}, Final: {6}", state.ConnectionIdentifier, request.TargetTransferTag, (ushort)request.LUN, request.BufferOffset, request.DataSegmentLength, request.DataSN, request.Final);
- try
- {
- readyToTransferPDUs = TargetResponseHelper.GetReadyToTransferPDUs(request, state.Target, state.SessionParameters, state.ConnectionParameters, out commandsToExecute);
- }
- catch (InvalidTargetTransferTagException ex)
- {
- Log(Severity.Error, "[{0}] Invalid TargetTransferTag: {1}", state.ConnectionIdentifier, ex.TargetTransferTag);
- RejectPDU reject = new RejectPDU();
- reject.InitiatorTaskTag = request.InitiatorTaskTag;
- reject.Reason = RejectReason.InvalidPDUField;
- reject.Data = ByteReader.ReadBytes(request.GetBytes(), 0, 48);
- state.SendQueue.Enqueue(reject);
- }
- }
- else
- {
- SCSICommandPDU command = (SCSICommandPDU)pdu;
- Log(Severity.Debug, "[{0}] SCSICommandPDU: CmdSN: {1}, LUN: {2}, Data segment length: {3}, Expected Data Transfer Length: {4}, Final: {5}", state.ConnectionIdentifier, command.CmdSN, (ushort)command.LUN, command.DataSegmentLength, command.ExpectedDataTransferLength, command.Final);
- readyToTransferPDUs = TargetResponseHelper.GetReadyToTransferPDUs(command, state.Target, state.SessionParameters, state.ConnectionParameters, out commandsToExecute);
- }
- foreach (ReadyToTransferPDU readyToTransferPDU in readyToTransferPDUs)
- {
- state.SendQueue.Enqueue(readyToTransferPDU);
- }
- if (commandsToExecute != null)
- {
- state.RunningSCSICommands.Add(commandsToExecute.Count);
- }
- List<ISCSIPDU> responseList = new List<ISCSIPDU>();
- foreach(SCSICommandPDU command in commandsToExecute)
- {
- Log(Severity.Debug, "[{0}] Executing command: CmdSN: {1}", state.ConnectionIdentifier, command.CmdSN);
- List<ISCSIPDU> commandResponseList = TargetResponseHelper.GetSCSICommandResponse(command, state.Target, state.SessionParameters, state.ConnectionParameters);
- state.RunningSCSICommands.Decrement();
- responseList.AddRange(commandResponseList);
- }
- state.SendQueue.Enqueue(responseList);
- }
- else if (pdu is LoginRequestPDU)
- {
- Log(Severity.Error, "[{0}] Protocol Error (Login request during full feature phase)", state.ConnectionIdentifier);
- // RFC 3720: Login requests and responses MUST be used exclusively during Login.
- // On any connection, the login phase MUST immediately follow TCP connection establishment and
- // a subsequent Login Phase MUST NOT occur before tearing down a connection
- RejectPDU reject = new RejectPDU();
- reject.Reason = RejectReason.ProtocolError;
- reject.Data = ByteReader.ReadBytes(pdu.GetBytes(), 0, 48);
- state.SendQueue.Enqueue(reject);
- }
- else
- {
- Log(Severity.Error, "[{0}] Unsupported command, OpCode: 0x{1}", state.ConnectionIdentifier, pdu.OpCode.ToString("x"));
- RejectPDU reject = new RejectPDU();
- reject.Reason = RejectReason.CommandNotSupported;
- reject.Data = ByteReader.ReadBytes(pdu.GetBytes(), 0, 48);
- state.SendQueue.Enqueue(reject);
- }
- }
- Log(Severity.Trace, "Leaving ProcessPDU");
- }
- private void ProcessSendQueue(ConnectionState state)
- {
- while (true)
- {
- Log(Severity.Trace, "Entering ProcessSendQueue");
- ISCSIPDU response;
- bool stopped = !state.SendQueue.TryDequeue(out response);
- if (stopped)
- {
- return;
- }
- Socket clientSocket = state.ClientSocket;
- PDUHelper.SetStatSN(response, state.ConnectionParameters.StatSN);
- PDUHelper.SetExpCmdSN(response, state.SessionParameters.ExpCmdSN, state.SessionParameters.ExpCmdSN + state.SessionParameters.CommandQueueSize);
- if (response is SCSIResponsePDU ||
- response is LoginResponsePDU ||
- response is TextResponsePDU ||
- (response is SCSIDataInPDU && ((SCSIDataInPDU)response).StatusPresent) ||
- response is RejectPDU)
- {
- state.ConnectionParameters.StatSN++;
- }
- try
- {
- clientSocket.Send(response.GetBytes());
- Log(Severity.Verbose, "[{0}] Sent response to initator, Operation: {1}, Size: {2}", state.ConnectionIdentifier, response.OpCode, response.Length);
- if (response is LogoutResponsePDU)
- {
- clientSocket.Close(); // We can close the connection now
- Log(Severity.Trace, "Leaving ProcessSendQueue");
- return;
- }
- else if (response is LoginResponsePDU)
- {
- if (((LoginResponsePDU)response).Status == LoginResponseStatusName.InvalidDuringLogon)
- {
- clientSocket.Close(); // We can close the connection now
- Log(Severity.Trace, "Leaving ProcessSendQueue");
- return;
- }
- }
- }
- catch (SocketException ex)
- {
- Log(Severity.Verbose, "[{0}] Failed to send response to initator. Operation: {1}, Size: {2}, SocketException: {3}", state.ConnectionIdentifier, response.OpCode, response.Length, ex.Message);
- Log(Severity.Trace, "Leaving ProcessSendQueue");
- return;
- }
- catch (ObjectDisposedException)
- {
- Log(Severity.Verbose, "[{0}] Failed to send response to initator. Operation: {1}, Size: {2}. ObjectDisposedException", state.ConnectionIdentifier, response.OpCode, response.Length);
- Log(Severity.Trace, "Leaving ProcessSendQueue");
- return;
- }
- }
- }
- public void Log(Severity severity, string message)
- {
- // To be thread-safe we must capture the delegate reference first
- EventHandler<LogEntry> handler = OnLogEntry;
- if (handler != null)
- {
- handler(this, new LogEntry(DateTime.Now, severity, "iSCSI Server", message));
- }
- }
- public void Log(Severity severity, string message, params object[] args)
- {
- Log(severity, String.Format(message, args));
- }
- public ushort GetNextTSIH()
- {
- // The iSCSI Target selects a non-zero value for the TSIH at
- // session creation (when an initiator presents a 0 value at Login).
- // After being selected, the same TSIH value MUST be used whenever the
- // initiator or target refers to the session and a TSIH is required
- ushort nextTSIH = m_nextTSIH;
- m_nextTSIH++;
- if (m_nextTSIH == 0)
- {
- m_nextTSIH++;
- }
- return nextTSIH;
- }
- }
- }
|