Ejemplo n.º 1
0
        private void ProcessConnectionBuffer(ConnectionState state)
        {
            ISCSIConnectionReceiveBuffer buffer = state.ReceiveBuffer;

            while (buffer.HasCompletePDU())
            {
                ISCSIPDU pdu = null;
                try
                {
                    pdu = buffer.DequeuePDU();
                }
                catch (Exception)
                {
                    throw;
                }

                if (pdu.GetType() == typeof(ISCSIPDU))
                {
                    throw new Exception("Unsupported");
                }
                else
                {
                    ProcessPDU(pdu, state);
                }
            }
        }
Ejemplo n.º 2
0
        private void ProcessConnectionBuffer(ConnectionState state)
        {
            Socket clientSocket = state.ClientSocket;

            ISCSIConnectionReceiveBuffer buffer = state.ReceiveBuffer;

            while (buffer.HasCompletePDU())
            {
                ISCSIPDU pdu = null;
                try
                {
                    pdu = buffer.DequeuePDU();
                }
                catch (Exception ex)
                {
                    byte[] pduBytes = buffer.DequeuePDUBytes();
                    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(pdu.GetBytes(), 0, 48);
                        state.SendQueue.Enqueue(reject);
                    }
                    else
                    {
                        bool valid = ValidateCommandNumbering(pdu, state);
                        if (valid)
                        {
                            ProcessPDU(pdu, state);
                        }
                        else
                        {
                            // We ignore this PDU
                            Log(Severity.Warning, "[{0}] Ignoring PDU with CmdSN outside of expected range", state.ConnectionIdentifier);
                        }
                    }
                }

                if (!clientSocket.Connected)
                {
                    // Do not continue to process the buffer if the other side closed the connection
                    if (buffer.BytesInBuffer > 0)
                    {
                        Log(Severity.Debug, "[{0}] Buffer processing aborted, bytes left in receive buffer: {1}", state.ConnectionIdentifier, buffer.BytesInBuffer);
                    }
                    return;
                }
            }
        }