From da094d42b10d9e4add7830ec8554ae62f26edb05 Mon Sep 17 00:00:00 2001 From: Folkert van Heusden Date: Mon, 14 Oct 2024 08:52:20 +0200 Subject: [PATCH] IFR_IO_ERROR returns a iscsi_pdu_scsi_response with read-error sense code --- server.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/server.cpp b/server.cpp index d31ce13..bae7d1a 100644 --- a/server.cpp +++ b/server.cpp @@ -566,12 +566,23 @@ void server::handler() if (ifr != IFR_OK && ifr != IFR_CONNECTION) { // something wrong with the received PDU? DOLOG(logging::ll_debug, "server::handler", endpoint, "invalid PDU"); + std::optional reject; std::optional reason; - if (ifr == IFR_INVALID_FIELD || ifr == IFR_IO_ERROR || ifr == IFR_MISC) { + if (ifr == IFR_INVALID_FIELD || ifr == IFR_MISC) { is->iscsiInstSsnFormatErrors++; reason = 0x09; } + else if (ifr == IFR_IO_ERROR) { + auto *temp = new iscsi_pdu_scsi_response(ses) /* 0x21 */; + + if (temp->set(*reinterpret_cast(pdu), s->error_read_error(), { }, 0x09) == false) { + reason = IFR_CONNECTION; + DOLOG(logging::ll_info, "server::handler", ses->get_endpoint_name(), "iscsi_pdu_scsi_response::set returned error"); + } + + reject = temp->get()[0]; + } else if (ifr == IFR_DIGEST) { is->iscsiInstSsnDigestErrors++; reason = 0x02; @@ -582,10 +593,12 @@ void server::handler() DOLOG(logging::ll_error, "server::handler", endpoint, "internal error, IFR %d not known", ifr); } - std::optional reject = generate_reject_pdu(*pdu, reason); if (reject.has_value() == false) { - DOLOG(logging::ll_error, "server::handler", endpoint, "cannot generate reject PDU"); - continue; + reject = generate_reject_pdu(*pdu, reason); + if (reject.has_value() == false) { + DOLOG(logging::ll_error, "server::handler", endpoint, "cannot generate reject PDU"); + continue; + } } bool rc = cc->send(reject.value().data, reject.value().n);