Commit Graph

2212 Commits

Author SHA1 Message Date
Ronnie Sahlberg
914eb5d578 Fix compiler warning/error from the previous commit
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-06-18 10:06:54 +10:00
Ronnie Sahlberg
3a6cfc1273 Merge pull request #449 from lishiao144/master
fix ExpStatSN handling for Data-Out PDUs
2025-06-18 09:55:59 +10:00
lishiao
8ebfb20c55 Optimize the judgment conditions 2025-06-17 12:24:40 +08:00
lishiao
a81eacc0b1 iscsi: compute Data Digest for out_data segments 2025-06-17 11:57:38 +08:00
lishiao144
cbba36e150 fix ExpStatSN handling for Data-Out PDUs 2025-06-12 18:26:19 +08:00
Ronnie Sahlberg
54ef3353a2 Merge pull request #448 from lishiao144/master
Fix length check to exclude padding when comparing against initiator
2025-06-12 18:55:23 +10:00
lishiao144
484adf5017 Fix length check to exclude padding when comparing against initiator_max_recv_data_segment_length 2025-06-12 16:41:53 +08:00
Ronnie Sahlberg
2803276f60 Merge remote-tracking branch 'refs/remotes/origin/master' 2025-05-30 10:53:25 +10:00
Ronnie Sahlberg
37e324c370 Merge pull request #447 from lishiao144/master
Fix CHAP_C Encoding and CHAP_R Comparison in CHAP Authentication
2025-05-30 10:47:06 +10:00
lishiao144
de86745f14 Update login.c 2025-05-29 14:00:53 +08:00
lishiao144
a57f51708c Incorrect handling of CHAP_C encoding during CHAP_R computation 2025-05-29 11:51:50 +08:00
lishiao144
676afd07a0 Signed vs. unsigned byte mismatch in CHAP_R comparison 2025-05-29 11:50:20 +08:00
Ronnie Sahlberg
35cb001a39 Merge pull request #446 from lishiao144/master
Fix CHAP response buffer zero-init and increase MAX_CHAP_R_SIZE to support SHA-256
2025-05-28 19:16:18 +10:00
lishiao144
7254f954ff zero-initialize target_chap_c to avoid relying on stack memory 2025-05-28 15:59:27 +08:00
lishiao144
b4d1cd7907 MAX_CHAP_R_SIZE updata 2025-05-28 15:57:40 +08:00
Ronnie Sahlberg
bd439878c0 New version 1.20.2
- Fix for Apple as their pthreads do not provide spinlock support.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-05-05 16:20:09 +10:00
Ronnie Sahlberg
fa37a2136c Apple: use mutexes instead of spinlocks on apple
Apple do not support spinlocks so we must remap to the much slower
mutexes instead if we think we are compiling for apple.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-05-03 20:49:46 +10:00
Ronnie Sahlberg
8cd2381476 New version 1.20.1
Add sha1/sha256/sha3 authentication
Add multithreading support

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-05-03 10:02:42 +10:00
Ronnie Sahlberg
eb19863f77 Fix race between queueing the pdu and update the task data
After we have called iscsi_queue_pdu from iscsi_scsi_command_async
the pdu might have already completed if we are using multithreading
so we should not dereference pdu at that point.

Move the assignment of task->cmdsn and task->itt we need for
task management into iscsi_pdu_set_cmdsn instead.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 11:55:47 +10:00
Ronnie Sahlberg
d5e3bf6175 Merge branch 'tst' 2025-04-26 11:30:58 +10:00
Ronnie Sahlberg
7e86ed7962 Add multithreaded example using the async API
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 11:28:57 +10:00
Ronnie Sahlberg
31fd95dc8f README: add blurb about multithreading
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:59:28 +10:00
Ronnie Sahlberg
edd7d9b843 Remove the small allocations
This is not compatible with multithreading and would require a complete
re-design.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
8047421868 Protect some variables in iscsi_context by the spinlock
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
91cc1e4197 Protect outqueue and waitpdu with a spinlock
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
4593746363 Add spinlock primitives
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
3fc5d2996b iscsi_queue_pdu() can never fail, make it void
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
37bc6fcd81 TCP: immediately trigger the service thread to write PDU
IF qe queue a new PDU to an empty outqueue then the mt service thread
will still be stuck in poll() until it timesout or the socket becomes
readable.

Fix this by sending SIGUSR1 to the service thread when we queue a PDU
to an empty queue. This will break out of poll() and we can immediately
go and write to the socket.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
f63ed0b76e Remove two global variables used to set the initial seed
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
ca0df22ede Add iscsi-pthreads-readloop
This is a tool to create multiple contexts and threads and run read operations on all
of them in a loop.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
5b391ad188 Pass iscsi to iscsi_init_sync_state
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
09ec037e34 Make the mutex symbols always available
so we do not need to wrap them inside an ifdef.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
1f91358c8a Flag variables in iscsi_context for multithreading audit
These variables may need to be protected by a mutex.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
3c48aea225 Add initial multithreading support and example
This is the basic support for doing i/o in a separate worker thread.
It is still not threads safe but a start.
Now we need to protect all variables such as outqueue, waitpdu
and friends.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-04-26 08:56:16 +10:00
Ronnie Sahlberg
ecc8a10212 Merge pull request #440 from plieven/small_fixes
Small fixes
2025-03-27 09:38:01 +10:00
Peter Lieven
eb0853e36e fix: use correct maximum length for TargetName and InitiatorName
Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-26 13:28:23 +00:00
Peter Lieven
90036a167d refactor(TODO): cleanup todos that have been implemented for ages
Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-26 13:19:47 +00:00
Ronnie Sahlberg
e968a37c4d Merge pull request #439 from plieven/feat/improve_logging
Add some logging improvements
2025-03-26 08:23:30 +10:00
Peter Lieven
696c946a9b feat(socket): log resolved ip addresses if portal is a hostname
Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-25 22:06:21 +00:00
Peter Lieven
98f0f2f7f1 fix(socket): restore logging of local ip and port
commit a92b413 removed the logging of local ip and port.
For debugging puposes these information can be important.
Restore functionality by using the new thread safe replacement
for inet_ntoa called inet_ntop.

Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-25 22:06:19 +00:00
Peter Lieven
7f0a8597d6 feat(logging): include LUN into log messages
a process might have a connection to different LUNs on the same target.
To be able to distinguish the different connections add the LUN id to the target
to log messages.

Signed-off-by: Peter Lieven <pl@dlhnet.de>
2025-03-25 22:06:15 +00:00
Ronnie Sahlberg
cb44ad4e26 Add multithreading helpers
Add an abstraction for mutexts and threads
that handles both pthread api and native win32 api

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-03-07 08:46:47 +10:00
Ronnie Sahlberg
f8542ab5cc Add checks if pthreads are available and enable HAVE_MULTITHREADING
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-03-07 07:04:17 +10:00
Ronnie Sahlberg
b8d9fbf5e3 Add CHAP SHA3-256 support
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-01-04 14:20:28 +10:00
Ronnie Sahlberg
34e83f7dbd Add support for CHAP with SHA-256
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-01-04 09:09:02 +10:00
Ronnie Sahlberg
95a0d98cfd Add support for CHAP using SHA1
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-01-04 00:59:02 +10:00
Ronnie Sahlberg
a92b41318c Don't use inet_ntoa, it is deprecated
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2025-01-03 15:48:51 +10:00
Ronnie Sahlberg
9637e1371e Merge pull request #434 from raywang-dev/fix-stack-corruption
fix: scan PDUs before exiting event_loop due to connect timedout
2024-12-07 01:30:47 -05:00
Ronnie Sahlberg
6f2f7855c2 Merge pull request #433 from tianrenz2/invalid-fd
lib: finish event_loop on invalid fd
2024-12-07 01:29:43 -05:00
hongleiwang
5cb77051ce fix: scan PDUs before exiting event_loop due to connect timedout
In iSCSI synchronous operations, a struct iscsi_sync_state variable
(state) is allocated on the stack, and its address is assigned to
pdu->scsi_cbdata.private_data. This address is eventually used in
the PDU callback function.

However, if a reconnection occurs during a synchronous operation
(e.g., read or write), but the connect function fails (iscsi->fd
will be set to -1), the event_loop times out and exits. At this point,
unprocessed PDUs remain. If the PDU callback function is triggered
after the timeout (e.g., during iscsi_destroy_context), it may
access the pdu->scsi_cbdata.private_data address, which no longer
points to the original stack allocation. Writing to this invalid
address in the callback corrupts the current stack structure,
leading to process crash.

This patch addresses the issue by scanning PDUs before exiting the
event_loop due connect timedout, ensuring the unprocessed PDUs are
properly handled to prevent stack corruption and crash.

Signed-off-by: raywang <honglei.wang@smartx.com>
2024-12-04 17:55:49 +08:00