840 Commits

Author SHA1 Message Date
David Disseldorp
1bdec140a7 test-tool: add iSCSICHAP.Base64Oversize test
This is very similar to the previous Base64 CHAP test, except we
intentionally inject extra base64 characters into the CHAP_R field.
This should cause login to fail. On LIO this can trigger a buffer
overwrite reported at:
https://lore.kernel.org/target-devel/6a0a00f2.e1ea9722.1dc845.b85e@mx.google.com/

Signed-off-by: David Disseldorp <ddiss@suse.de>
2026-05-22 00:17:18 +10:00
David Disseldorp
311548e860 test-tool: add iSCSICHAP.Base64 test
Some targets such as LIO support base64 encoded CHAP_R values. Test this
by intercepting hex-encoded CHAP_R responses and converting the value to
base64.
This will fail on targets which don't support base64; we should probably
skip the test instead.
base64 encoding is performed using the gnutls_base64_encode2() function,
so the test is only present for gnutls-enabled builds.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2026-05-21 21:53:43 +10:00
Anatoliy Glagolev
19d05ab7a7 RTPG support
Implementing support of the Report Target Port Groups command.

Tested on Ubuntu against Pure Storage Flash Array
using designated unit tests and new iscsi-rtpg utility

./iscsi-rtpg  -i iqn.2005-03.org.open-iscsi:6feb2db21ea iscsi://192.168.1.12/iqn.2010-06.com.purestorage:flasharray.4e8d52d82e4b2c0f/1
RTPG retrieved 2 groups
Group 0x0000: preferred 0, format 0x00, ALUA state ACTIVE-OPTIMIZED,flags 0x8f, status code 0x02, port count 65
Ports: [ 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4a 0x4b 0x4c
0x4d 0x4e 0x4f 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b 0x5c 0x5d 0x5e 0x5f 0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67
0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f 0x70 0x71]
Group 0x0001: preferred 0, format 0x00, ALUA state ACTIVE-OPTIMIZED,flags 0x8f, status code 0x02, port count 65
Ports: [ 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f 0x20 0x72 0x73 0x74 0x75 0x76 0x77 0x78 0x79 0x7a
0x7b 0x7c 0x7d 0x7e 0x7f 0x80 0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f 0x90 0x91 0x92 0x93 0x94 0x95
0x96 0x97 0x98 0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f 0xa0 0xa1 0xa2]
2025-07-03 17:20:52 -06: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
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
Folkert van Heusden
aed7faf4db For failing writes, show what is in the sector instead 2024-10-18 08:05:53 +02:00
folkert van heusden
5fc2dcb88f A possible 'fix' for https://github.com/sahlberg/libiscsi/issues/415
This patch adds a timestamp before each logged line. That could help
correlating a logging to a network-trace. Because of offsets in time
between the tracer and the test and the DUT, this does not always help.
2024-02-14 00:44:26 +01:00
Michael Tokarev
6e0206c135 spelling fixes: eventhough, shoudl, asyncronous, maxium, implicity
These changes are carried in debian for a long time, some since 2016.
The last one (implicity) is new in 1.20.0.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2024-02-05 10:22:23 -08:00
folkert van heusden
a51eafa90d Previously, 'task->status' was printed as decimal. In iscsi.h, the
values that are put into it are defined as hexadecimal. This is a bit
confusing (grepping through the code for 251658241 did not result in
anything while the hex variant f000001 resulted in SCSI_STATUS_ERROR).
2024-01-30 19:47:28 +01:00
folkert van heusden
abedc1848c Fix for https://github.com/sahlberg/libiscsi/issues/409
'ms->pages' was not checked for being NULL. This can happen when a
target does not return any pages.
2024-01-30 06:39:08 -08:00
Li kunyu
6b520bee52 test-tool: remove a redundant semicolon
Signed-off-by: Li kunyu <kunyu@nfschina.com>
2022-10-08 20:34:36 -07:00
Li Feng
97d2f681d7 iscsi-support: fix memory leak
If doesn't support the report_supported_opcodes, the task will not be
freed in REPORT_SUPPORTED_OPCODES.

Change-Id: I1e251eec518721fb35e51013621aa61865d4b46b
Signed-off-by: Li Feng <fengli@smartx.com>
2021-09-30 19:54:08 -07:00
Bart Van Assche
b781b21d50 test-tool, xcopy: Fix target descriptor handling
Fail the XCOPY tests if no appropriate target descriptor is available
instead of causing memory corruption or truncating the descriptor.
2021-09-05 20:00:02 -07:00
David Disseldorp
73d541b00b test: fix ExtendedCopy.Large SKIPPED cases
CU_PASS() needs to be coupled with a return to actually skip the test.
Similarly, the CU_PASS message isn't printed, so a logging() call is
also needed here.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2021-07-29 17:39:39 +02:00
Bart Van Assche
696ac1e948 Merge pull request #353 from Ser01x/master
Before running the SCSI.ReceiveCopyResults.CopyStatus test we should check that it is supported
2021-07-26 20:34:19 -07:00
Ser01x
e8c15866fa Fixed several code style problems 2021-07-26 09:24:54 +00:00
Ser01x
053c6db9e1 test-tool: check that ReceiveCopyResults is implemented
We check that the RECEIVE COPY STATUS(LID1) command is supported
by SCSI device before sending it.
2021-07-21 16:37:57 +00:00
Bart Van Assche
c49461e4b7 test-tool: Do not use empty initializers
Empty initializers are a GNU extension that is not supported by older
versions of gcc.

Fixes: https://github.com/sahlberg/libiscsi/issues/356
2021-06-24 20:07:54 -07:00
Bart Van Assche
2a5a0b3291 Enable -Wno-unused-parameter
Instead of adding __attribute__((unused)) to unused arguments, add the
-Wno-unused-parameter compiler flag.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2021-05-23 13:23:41 -07:00
Bart Van Assche
ea6b2282d4 Use __attribute__((format(printf, ...))) directly
Instead of defining the macro _R_(), define __attribute__() as a macro for
compilers that do not support __attribute__(), namely Microsoft Visual
Studio.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2021-05-23 11:52:40 -07:00
orbea
c437afa825 build: Add -no-undefined where missing
Signed-off-by: orbea <orbea@riseup.net>
2021-05-22 19:32:12 -07:00
orbea
9649fe1ddc build: Correct usage of LIBADD and LDADD
Signed-off-by: orbea <orbea@riseup.net>
2021-05-22 19:31:52 -07:00
orbea
c547d2dc7f build: Remove bogus LDADD variables
Signed-off-by: orbea <orbea@riseup.net>
2021-05-22 19:31:50 -07:00
Bart Van Assche
f87a5adaa0 test-tool: Change command_is_implemented from a global variable into an argument
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2021-02-08 19:01:31 -08:00
Bart Van Assche
c7a9f51d23 test-tool: Move a logging statement into write_residuals_test()
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2021-02-08 17:55:19 -08:00
Bart Van Assche
a21065cf71 test-tool: Add default clauses in recently modified switch statements
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2021-02-08 17:50:46 -08:00
Bart Van Assche
0c304f0c3c test-tool, residuals: Rename struct residuals_test_data members
Bring the names of these struture members closer to the names used in the
SCSI and iSCSI standards.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2021-02-08 17:50:38 -08:00
Anastasia Kovaleva
1b7d1743ae test-tool: Add overwrite check for all test cases
Check if the residual data does not owerwrite existing data blocks has now
been added for all testing data to improve the uniformity of test runs,
increase test readability and remove the duplicate testing data records.
2021-02-08 15:28:26 +03:00
Anastasia Kovaleva
e9bf7c2d05 test-tool: Change write residuals tests overwrite check according to FCP-4
According to FCP-4 there are several possibilities for target to react on
incorrect data length field value in CDB:

a) process the command normally except that data beyond the FCP_DL count
shall not be requested or transferred;

b) transfer no data and return CHECK CONDITION status with the sense key
set to ILLEGAL REQUEST and the additional sense code set to
INVALID FIELD IN COMMAND INFORMATION UNIT;

Add check to support the second one and accept no data write.
2021-02-08 15:23:55 +03:00
Anastasia Kovaleva
2e8c571955 test-tool: Refactoring residuals write tests
Looking at test_write10_residuals.c, test_write12_residuals.c and
test_write16_residuals.c tests the similarity of the testing scenario
can be found. There are several EDTL and SPDTL combinations which are
the same for different length write command tests. They form the core
of testing scenario of these commands. There aren't so much differences
in the way of testing these combinations itself either. It is possible
to move the main parameters describing the testing scenario into a
separate structure and move the scenario itself into a separate function.
It will increase the readability and reduce the duplicate code of these tests.
2021-02-08 15:23:49 +03:00
Anastasia Kovaleva
34fd477ede test-tool: Allow CHECK CONDITION in response to overflow/underflow
According to the RFC 7143 11.4.5.1:
"Targets may set the residual count,and initiators may use
 it when the response code is Command Completed at Target (even if the
 status returned is not GOOD)."

Therefore valid retuned status may be not only GOOD. Also this check:
task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT
would make Underflow/Overflow response universal for FC/ISCSI.
2021-02-02 11:46:27 +03:00
David Disseldorp
88a6060c7a test-tool: add simple REPORT LUNS test
Check for duplicate LUN entries in the REPORT LUNS response.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2021-01-22 21:27:18 +01:00
Bart Van Assche
a8fcd18850 Revert "specify number of blocks in write_same command"
As reported by Sitsofe Wheeler, the WRITE SAME commands with zero blocks are
only issued if WSNZ == 0. WSNZ == 0 means that zero in the NUMBER OF LOGICAL
BLOCKS field means that all logical blocks until the end are affected. In
other words, the original code was fine. Hence revert commit dfff7e9d16.

Reported-by: Sitsofe Wheeler <sitsofe@yahoo.com>
2020-12-17 13:58:13 -08:00
David Disseldorp
957cc96232 test-tool: add COMPARE AND WRITE MiscompareSense test
This test checks regular sense/ascq values on miscompare as well as
the Information sense field, which should be set as follows:
  sense key set to MISCOMPARE and the additional sense code set to
  MISCOMPARE DURING VERIFY OPERATION. In the sense data (see 4.18 and
  SPC-5) the offset from the start of the Data-Out Buffer to the first
  byte of data that was not equal shall be reported in the INFORMATION
  field.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-10-19 14:54:58 +02:00
Aleksandr Miloserdov
f342056a52 test-tool: add version descriptor checks for more SBC-3 versions
If device claims SBC-3 version in its version descriptors it won't be marked as SBC-3 compliant.

This commit adds checks for:
* SBC-3 T10/BSR INCITS 514 revision 35
* SBC-3 T10/BSR INCITS 514 revision 36
* SBC-3 ANSI INCITS 514-2014
2020-09-11 13:26:26 +03:00
Consus
859070854d test-tool: Fix CmdSN tests
After commit 10868c491d CmdSN tests no
longer work because iscsi->cmdsn is incremented during the second test
phase (sending "good" TUR after "bad" TUR), so the resulting CmdSN is
not ExpCmdSN, but ExpCmdSN + 1 that is not acknowledged by the target.
This commit fixes the issue by setting iscsi->cmdsn to iscsi->expcmdsn - 1.

Affected tests:

 * iSCSI.iSCSIcmdsn.iSCSICmdSnTooLow
 * iSCSI.iSCSIcmdsn.iSCSICmdSnTooHigh
2020-09-03 09:56:52 +03:00
Dharmesh Shah
5553d6bddf test-tool/test_async_lu_reset_simple: Move an assert statement
In the test iSCSI.iSCSITMF.LUNResetSimpleAsync
CU_ASSERT_EQUAL(reconnect_succeeded, 1) must be called after the async
TMF command completes. Hence move that assert into the TMF completion
callback.

This patch fixes a race condition.

[bvanassche: edited commit message]
2020-09-01 13:37:20 -07:00
David Disseldorp
54b3dcaa30 test-tool: add LogoutDuringIOAsync test case
This attempts to reproduce upstream LIO reports of a use after free bug
when logout occurs alongside concurrent I/O.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-08-18 17:12:28 +02:00
David Disseldorp
4080c09839 test-tool: rename async write dispatch/complete counters
Add an io_ prefix, to differentiate between I/O and future iSCSI Logout
request tracking.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-08-18 16:43:54 +02:00
Consus
9e160e02b6 test-tool: Use block_size instead of hardcoded 512 bytes
Fix another couple of tests that fail on 4Kn drives:

* iSCSI.iSCSITMF.AbortTaskSimpleAsync
* iSCSI.iSCSITMF.LUNResetSimpleAsync
2020-08-10 15:59:49 +03:00
Consus
7258fbfd83 test-tool: Use block_size instead of hardcoded 512 bytes
This commit fixes some tests (like ProutReserve) on pure 4k devices.
2020-06-17 15:50:44 +03:00
Bart Van Assche
33c66f2c39 test-tool, compare and write: Reduce maximum number of blocks from 256 to 255
Since the NUMBER OF LOGICAL BLOCKS field in the COMPARE AND WRITE command
is an 8 bit field, the maximum value that can be encoded is 255.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-05-21 18:39:49 -07:00
Bart Van Assche
b4d59cd29c test_compareandwrite_invalid_dataout_size: Simplify this test
Assign the NUMBER OF LOGICAL BLOCKS field in the COMPARE AND WRITE PDU
directly. Use the terminology from SBC-4, namely NUMBER OF LOGICAL BLOCKS
instead of TL.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-05-21 18:39:49 -07:00
Bart Van Assche
9fcdce3101 test-tool: Use asprintf() in sg_send_scsi_cmd()
Use asprintf() instead of snprintf() + strdup().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-05-15 10:40:00 -07:00
Bart Van Assche
b9effb556f test-tool: Fix a comment in sg_send_scsi_cmd()
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-05-14 11:50:57 -07:00
Bart Van Assche
6aa5acb659 test-tool: Split send_scsi_command()
This patch does not change any functionality.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-05-14 11:47:56 -07:00
David Disseldorp
a89583aec3 test/xcopy_simple: add XCOPY test with 0x0A segment descriptor
Check for 0x0A descriptor support via SCSI_COPY_RESULTS_OP_PARAMS. If
supported, perform a 0x0A type XCOPY using target's
maximum_segment_length (or 256M if larger).

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-18 18:59:43 +01:00
David Disseldorp
c8992f45b1 test: add support for 0x0A type XCOPY segment descriptors
Type 0x0A segment descriptors provide a 32-bit wide number-of-bytes
field, allowing for much larger copy offloads with a single segment
descriptor.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-18 18:59:34 +01:00
David Disseldorp
385c6e8ae9 test/xcopy_simple: zero destination range before copy
Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-18 18:59:34 +01:00
David Disseldorp
da7c1c4b0a test: use spec defined XCOPY segment descriptor lengths
The SPC4r37 specification defines XCOPY Segment Descriptor lengths for
each SD type. The spec defined SD lengths don't account for the four SD
header bytes. To make it easier to match the spec to the implementation,
use the spec defined lengths in get_desc_len() with a four byte SD
header addition.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-18 00:49:36 +01:00