summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2025-11-12 14:41:52 +0100
committerSimon Rettberg2025-12-09 15:33:21 +0100
commit518c2855d51c4c2e79ff32a25d7efd78abf57cf8 (patch)
treef3febf86880f9f80a3193d6eeac5b984a3055480 /src
parent[SERVER] iscsi: fix typo (diff)
downloaddnbd3-518c2855d51c4c2e79ff32a25d7efd78abf57cf8.tar.gz
dnbd3-518c2855d51c4c2e79ff32a25d7efd78abf57cf8.tar.xz
dnbd3-518c2855d51c4c2e79ff32a25d7efd78abf57cf8.zip
[SERVER] iscsi: Fix handling of reason_code in logout request
Only the lower 7 bits carry the reason code, mask away highest bit.
Diffstat (limited to 'src')
-rw-r--r--src/server/iscsi.c5
-rw-r--r--src/server/iscsi.h4
2 files changed, 7 insertions, 2 deletions
diff --git a/src/server/iscsi.c b/src/server/iscsi.c
index 1b29dbe..b7aacec 100644
--- a/src/server/iscsi.c
+++ b/src/server/iscsi.c
@@ -2764,8 +2764,11 @@ static int iscsi_connection_handle_logout_req(iscsi_connection *conn, const iscs
{
iscsi_logout_req_packet *logout_req_pkt = (iscsi_logout_req_packet *) request_pdu->bhs_pkt;
- if ( (conn->state == ISCSI_CONNECT_STATE_NEW) || (logout_req_pkt->reason_code != ISCSI_LOGOUT_REQ_REASON_CODE_CLOSE_SESSION) )
+ if ( (conn->state == ISCSI_CONNECT_STATE_NEW)
+ || ((logout_req_pkt->reason_code & ISCSI_LOGOUT_REQ_REASON_CODE_MASK) != ISCSI_LOGOUT_REQ_REASON_CODE_CLOSE_SESSION) ) {
+ logadd( LOG_DEBUG1, "Invalid logout request in state %d, reason_code %d", conn->state, logout_req_pkt->reason_code );
return ISCSI_CONNECT_PDU_READ_ERR_FATAL;
+ }
iscsi_pdu CLEANUP_PDU response_pdu;
if ( !iscsi_connection_pdu_init( &response_pdu, 0, false ) )
diff --git a/src/server/iscsi.h b/src/server/iscsi.h
index 53c4b0e..8c5831c 100644
--- a/src/server/iscsi.h
+++ b/src/server/iscsi.h
@@ -4105,6 +4105,8 @@ typedef struct __attribute__((packed)) iscsi_login_response_packet {
/// Logout request reason code: Remove the connection for recovery. The connection is closed, and all commands associated with it, if any, are to be prepared for a new allegiance.
#define ISCSI_LOGOUT_REQ_REASON_CODE_REMOVE_CONNECTION_RECOVERY 0x02
+/// Mask to get the logout reason from the reason_code field (lower 7 bits)
+#define ISCSI_LOGOUT_REQ_REASON_CODE_MASK 0x7f
/**
* @brief Logout request implicit reason code: Session reinstatement.
@@ -4236,7 +4238,7 @@ typedef struct __attribute__((packed)) iscsi_logout_req_packet {
* I_T_L nexus with the status of CHECK CONDITION, the ASC/ASCQ value
* of 0x47 / 0x7F ("SOME COMMANDS CLEARED BY ISCSI PROTOCOL EVENT"), etc.
*/
- int8_t reason_code;
+ uint8_t reason_code;
/// Reserved for future usage, always MUST be 0.
uint16_t reserved;