|
@@ -328,56 +328,70 @@ namespace ISCSI.Server
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (pdu is LoginRequestPDU)
|
|
|
+ if (!state.SessionParameters.IsFullFeaturePhase)
|
|
|
{
|
|
|
- LoginRequestPDU request = (LoginRequestPDU)pdu;
|
|
|
- Log("[{0}][ReceiveCallback] Login Request, current stage: {1}, next stage: {2}, parameters: {3}", state.ConnectionIdentifier, request.CurrentStage, request.NextStage, KeyValuePairUtils.ToString(request.LoginParameters));
|
|
|
- if (request.TSIH != 0)
|
|
|
+ if (pdu is LoginRequestPDU)
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
- lock (m_activeConnections)
|
|
|
+ LoginRequestPDU request = (LoginRequestPDU)pdu;
|
|
|
+ Log("[{0}][ReceiveCallback] Login Request, current stage: {1}, next stage: {2}, parameters: {3}", state.ConnectionIdentifier, request.CurrentStage, request.NextStage, KeyValuePairUtils.ToString(request.LoginParameters));
|
|
|
+ if (request.TSIH != 0)
|
|
|
{
|
|
|
- int existingConnectionIndex = GetStateObjectIndex(m_activeConnections, request.ISID, request.TSIH, request.CID);
|
|
|
- if (existingConnectionIndex >= 0)
|
|
|
+
|
|
|
+
|
|
|
+ lock (m_activeConnections)
|
|
|
{
|
|
|
-
|
|
|
- Log("[{0}][ProcessPDU] Initiating implicit logout", state.ConnectionIdentifier);
|
|
|
- SocketUtils.ReleaseSocket(m_activeConnections[existingConnectionIndex].ClientSocket);
|
|
|
- if (m_activeConnections[existingConnectionIndex].Target != null)
|
|
|
+ int existingConnectionIndex = GetStateObjectIndex(m_activeConnections, request.ISID, request.TSIH, request.CID);
|
|
|
+ if (existingConnectionIndex >= 0)
|
|
|
{
|
|
|
- lock (m_activeConnections[existingConnectionIndex].Target.IOLock)
|
|
|
+
|
|
|
+ Log("[{0}][ProcessPDU] Initiating implicit logout", state.ConnectionIdentifier);
|
|
|
+ SocketUtils.ReleaseSocket(m_activeConnections[existingConnectionIndex].ClientSocket);
|
|
|
+ if (m_activeConnections[existingConnectionIndex].Target != null)
|
|
|
{
|
|
|
-
|
|
|
+ lock (m_activeConnections[existingConnectionIndex].Target.IOLock)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
+ m_activeConnections.RemoveAt(existingConnectionIndex);
|
|
|
+ Log("[{0}][ProcessPDU] Implicit logout completed", state.ConnectionIdentifier);
|
|
|
}
|
|
|
- m_activeConnections.RemoveAt(existingConnectionIndex);
|
|
|
- Log("[{0}][ProcessPDU] 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;
|
|
|
+ lock (m_activeConnections)
|
|
|
+ {
|
|
|
+ m_activeConnections.Add(state);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Log("[{0}][ReceiveCallback] Login Response parameters: {1}", state.ConnectionIdentifier, KeyValuePairUtils.ToString(response.LoginParameters));
|
|
|
+ TrySendPDU(state, response);
|
|
|
}
|
|
|
- LoginResponsePDU response = ServerResponseHelper.GetLoginResponsePDU(request, m_targets, state.SessionParameters, state.ConnectionParameters, ref state.Target, GetNextTSIH);
|
|
|
- if (state.SessionParameters.IsFullFeaturePhase)
|
|
|
+ else
|
|
|
{
|
|
|
- state.SessionParameters.ISID = request.ISID;
|
|
|
- state.ConnectionParameters.CID = request.CID;
|
|
|
- lock (m_activeConnections)
|
|
|
+
|
|
|
+ Log("[{0}][ProcessPDU] Improper command during login phase, OpCode: 0x{1}", state.ConnectionIdentifier, pdu.OpCode.ToString("x"));
|
|
|
+ if (state.SessionParameters.TSIH == 0)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ clientSocket.Close();
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- m_activeConnections.Add(state);
|
|
|
+
|
|
|
+
|
|
|
+ LoginResponsePDU loginResponse = new LoginResponsePDU();
|
|
|
+ loginResponse.TSIH = state.SessionParameters.TSIH;
|
|
|
+ loginResponse.Status = LoginResponseStatusName.InvalidDuringLogon;
|
|
|
+ TrySendPDU(state, loginResponse);
|
|
|
+ clientSocket.Close();
|
|
|
}
|
|
|
}
|
|
|
- Log("[{0}][ReceiveCallback] Login Response parameters: {1}", state.ConnectionIdentifier, KeyValuePairUtils.ToString(response.LoginParameters));
|
|
|
- TrySendPDU(state, response);
|
|
|
- }
|
|
|
- else if (!state.SessionParameters.IsFullFeaturePhase)
|
|
|
- {
|
|
|
-
|
|
|
- Log("[{0}][ProcessPDU] Improper command during login phase, OpCode: 0x{1}", state.ConnectionIdentifier, pdu.OpCode.ToString("x"));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- clientSocket.Close();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -452,9 +466,26 @@ namespace ISCSI.Server
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ else if (pdu is LoginRequestPDU)
|
|
|
+ {
|
|
|
+ Log("[{0}][ProcessPDU] Protocol Error (Login request during full feature phase)", state.ConnectionIdentifier);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ RejectPDU reject = new RejectPDU();
|
|
|
+ reject.Reason = RejectReason.ProtocolError;
|
|
|
+ reject.Data = ByteReader.ReadBytes(pdu.GetBytes(), 0, 48);
|
|
|
+
|
|
|
+ TrySendPDU(state, reject);
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
Log("[{0}][ProcessPDU] 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);
|
|
|
+
|
|
|
+ TrySendPDU(state, reject);
|
|
|
}
|
|
|
}
|
|
|
}
|