Commit Graph

48 Commits

Author SHA1 Message Date
Ronnie Sahlberg
6f36a6ca2b Change HeaderDigest to default to None,CRC32C instead of None
This allows our default setting to work with any target configuration.
2011-01-03 15:54:38 +11:00
Ronnie Sahlberg
9ddce8dc24 Replace bzero() with memset() 2011-01-03 15:35:36 +11:00
Ronnie Sahlberg
7253a667ae Add a helper function to parse a Portal URL.
A Portal URL is of the form
   iscsi://[<username>[%<password>]@]<host>[:<port>]
and is used by command such as iscsi-ls during the discovery login phase.

During discovery we do not yet know the target iqn name, nor the lun of
any devices.
2011-01-03 15:22:01 +11:00
Ronnie Sahlberg
178f9c8751 Only set CHAP username/password if BOTH have been provided.
There is no point in setting the username if there is no password
and vice versa.

Also, if we only set username but not passwd this would lead to a segv.
2011-01-03 15:01:38 +11:00
Ronnie Sahlberg
5928575bac Allow setting the CHAP username/password via environment variables
so that the password will not be showing up in log where the application
logs the "filename/iscsi url" or in ps aux output.

LIBISCSI_CHAP_USERNAME and LIBISCSI_CHAP_PASSWORD environment variables are
available to set these outside of the url.
If hte username/password is ALSO set in the URL, the settings in the URL
will override the environment variables.
2011-01-03 14:58:52 +11:00
Ronnie Sahlberg
87072d5622 Dont use gethostbyname2() at all since it is non-portable,
use gethostbyname() instead.
2011-01-03 14:48:43 +11:00
Ronnie Sahlberg
adfb7326e3 Solaris needs -lsocket and -lnsl and does not support gethostbyname2()
With these changes we build and work on solaris
2011-01-03 10:57:35 +11:00
Ronnie Sahlberg
e7c24af75e Handle ImmediateData=Yes correctly when sending data to the target.
We should not handle any combination of
ImmediateData=Yes/No
InitialR2T=Yes/No
correctly
2011-01-02 19:51:08 +11:00
Ronnie Sahlberg
20eaf85dd4 Handle InitialR2T=Yes correctly when sendign data to a target and wait for a R2T before sending the first block of data.
We should now honour, and handle the case of
ImmediateData=No
InitialR2T=Yes
correctly for targets that are limited on receiveing data too fast.
2011-01-02 19:33:43 +11:00
Ronnie Sahlberg
74fadc9337 Add support for R2T PDUs.
Update the "send scsi command" fucntion to honour
"FirstBurstLength" so that we only send this many bytes as unsolicited data.

The wait for a train of R2T from the target to clock out additional
busrts of data until the full task data has been sent to the Target.

We should now honour, and handle the case of
ImmediateData=No
InitialR2T=No
correctly for targets that are limited on receiveing data too fast.
2011-01-02 19:27:32 +11:00
Ronnie Sahlberg
502843d64a Honour MaxRecvDataSegmentLength from the target and split DATAOUT into
chunks of this size.
2011-01-02 19:27:23 +11:00
Ronnie Sahlberg
d240e8b5aa Use an initiator specific and one target specific value for MaxRecvDataSegmentLength 2011-01-02 19:27:16 +11:00
Ronnie Sahlberg
5e5d6c05c0 Add a function to send DATAOUT PDUs.
Update the send pdu command to trap when we need to send data to the target
but we are not allowed to send using immediate data.
For this case, send the data as a separate DATAOUT pdu instead.

Twiddle the flags and other fields to now manage that we send the data
as two separate PDUs.
2011-01-02 18:01:21 +11:00
Ronnie Sahlberg
9a8fca8bea Add two new helpers iscsi_pdu_set_[datasn|bufferoffset]()
These two helpers can be used to set the corresponding fields in a
DATAOUT PDU
2011-01-02 18:01:08 +11:00
Ronnie Sahlberg
9cd03ca559 Add a new helper function iscsi_allocate_pdu_with_itt_flags()
This function can allocate a new pdu using a specific itt value
and specific flags instead of using the defaults of, next iff, no flags set.

This can be used when we need to allocate additional PDUs in a chain,
for commands that span across multiple PDUs and where all need to keep
the same itt value.

For example
   ->WRITE10 cdb
   ->DATAOUT
   -<RESPONSE

Here the DATAOUT PDU belongs to the same task that was started by write10
so it need to use the same itt value.
2011-01-02 18:01:00 +11:00
Ronnie Sahlberg
1569624fd2 Add a new helper function _set_itt() that can be used to set the itt of
a pdu, instead of having to twiddle the bits and bytes manually.
2011-01-02 18:00:46 +11:00
Ronnie Sahlberg
72f9d8fa82 Add a new pdu flag : NO_CALLBACK
This flag is used when we dont want the CANCEL callback to be invoked if the
context is destroyed.

Thsi will be used for the sequence where we send multiple PDUs
to the target for one single scsi task, such as
    -> WRITE10 cdb
    -> DATAOUT
    -< RESPONSE

Since if the context is destroyed when the command is in flight, we
already get the CANCEL callback for the WRITE10 PDU, so we dont need to invoke
it again for when we destroy the DATAOUT pdu, since they both refer to the same
task.
2011-01-02 18:00:37 +11:00
Ronnie Sahlberg
490a01053a Add a flags field to the pdu structure
Add a new pdu flag : DELETE_WHEN_SENT. When this pdu has been
sent to the wire, the pdu will be deleted and not put on the waitpdu list.

This will be useful for sequences such as
    -> WRITE10 cdb
    -> DATAOUT the data to write
    -< RESPONSE

Where we want to match WRITE10 and RESPONSE but where the plain DATAOUT pdu
will not be soliciting its own response.
We dont need to wait for the response to DATAOUT pdus, we are already waitin
for the response form the initial PDU in the sequence.
2011-01-02 18:00:19 +11:00
Ronnie Sahlberg
1f1e5111d4 Negotiate ImmediateData during login and store the result in iscsi->
We will use this later to decide when we should send unsolicited imemdiate
data to the target. Currently we always send unsolicited immediate data
but targets configured to not allow immediate data may refuce this and
turn an error.
2011-01-02 12:59:41 +11:00
Ronnie Sahlberg
32228a4509 Negotiate InitialR2T during login. Default to offer No, but update
and accept what Target responds.

Store the result of the negotiated setting in the iscsi context
so we can use it later to determine how to send solicited/unsolicited
data.
2011-01-02 12:50:00 +11:00
Ronnie Sahlberg
190ea92810 Rework error messages generated when login fails to not repeat the same
thing "Failed to login to target" several times as the error cascades
up through the layers of callbacks.
2011-01-02 12:12:30 +11:00
Ronnie Sahlberg
796b3a6acc login.c: Dont end error strings with \n, Leave that for the caller. 2011-01-02 08:22:38 +11:00
Ronnie Sahlberg
8eb62fec87 Improve error messages when parsing of iscsi url fails
Always print the correct url syntax when parsing has failed.
Test if the user forgot to specify a <target-iqn> at all and log
this as a missing target-iqn error. Not as a missing <lun> error.

Remove \n from the error strings in init.c
2011-01-02 08:04:41 +11:00
Ronnie Sahlberg
6947502759 Add negotiation of IFMarker, OFMarker and MaxConnections during login 2011-01-01 12:42:48 +11:00
Ronnie Sahlberg
ec252d78f8 Changte time2retain default from 20 to 0 2011-01-01 12:38:41 +11:00
Ronnie Sahlberg
820fffe04e Add negotiation of MaxOutstandingR2T and ErrorRecoveryLevel during login phase 2011-01-01 11:51:09 +11:00
Ronnie Sahlberg
27038e5c8b Negotiate DefaultTime2Wait and DefaultTime2Retain during login phase 2011-01-01 11:45:07 +11:00
Ronnie Sahlberg
172dbb6846 Update what we try to negotiate as header digest when we receive
a reply back from the target.
2011-01-01 11:38:06 +11:00
Ronnie Sahlberg
e004161c1f Update login functions to use asprint to build the key=value pairs
instead of calling iscsi_pdu_add_data twice, once for key= and once for value
2011-01-01 10:07:24 +11:00
Ronnie Sahlberg
a3328a85ef Negotiation of MaxBurstLength, FirstBurstLength, MaxRecvDataSegmentLength
Add these settings to the iscsi context structure and initialize them to
sane valued.
When sending login commands to the target, use these values instead
of hardcoded values.
Parse when the target sends a login reply back to us and update these variables
if the target asks us to.

This allows us to detect when our defaults are too big for the target
and adjust the settings we use so we match the target.

Some targets have a very small accepted default for some settings.
During login, we will initially send these keys with our dafult values.
These targets will then respond back by refusing to transition to the next
login phase, and by telling us back what the maximum of these values should be.
In this case we have to try the login again but use the smaller values we got
from the target.
Othervise, if we try again, ignoring the value from the target, and just repeat
using our defaults the target will abort the login with a "initiator error".
2011-01-01 09:51:16 +11:00
Ronnie Sahlberg
46199d2f59 Improve the parsing of iscsi URLs and validate the input.
Generate better error messages when a badly formed URL is given
and an error string that points to the field there is a problem with.
2010-12-31 09:44:14 +11:00
Ronnie Sahlberg
2b30e3a7fe When getting a socket POLLERR event, use getsockopt(SO_ERROR)
to create a better error message about the reason for the socket failing.
2010-12-31 06:01:41 +11:00
Stefan Hajnoczi
6981b79516 Check SO_ERROR when async connect completes
When non-blocking connect completes the error code can be read using
getsockopt(SO_ERROR).  Doing this is important for identifying failure
to connect, especially if POLLERR and POLLHUP were not employed by the
user.

The QEMU iscsi block driver does not use POLLERR/POLLHUP and depends on
SO_ERROR to detect connection failure.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
2010-12-29 08:57:48 +00:00
Stefan Hajnoczi
faec3c0dfd Only await POLLOUT events until connected
Non-blocking socket connect(2) involves waiting for the socket to become
writeable to detect that a connection has been made.  POLLIN events
should not be requested until the socket is connected because they are
processed even if the iSCSI context is not yet connected.

For example, the QEMU iscsi block driver does something like this:

iscsi_full_connect_async(...)

/* Now wait until the socket becomes ready */
poll(POLLIN|POLLOUT) = POLLIN|POLLOUT

/* QEMU calls POLLIN and POLLOUT handlers individually and it happens to
 * call the POLLIN handler *before* the POLLOUT handler.
 */
iscsi_service(POLLIN)
iscsi_service(POLLOUT)

POLLIN processing will read from the socket and consume the error code
if connect failed.  As a result, the POLLOUT handler will write to a
disconnected socket and raise a SIGPIPE which kills the process.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
2010-12-29 08:57:48 +00:00
Ronnie Sahlberg
647ebd222e Try to resolve hostnames into ip addresses
Dont assume everyone just uses dotted-decimal always on their networks.
Try resolve hostnames specified in the iscsi URLs into addresses
2010-12-28 13:51:54 +11:00
Ronnie Sahlberg
7a7a227fee Suppress a compiler warning 2010-12-27 10:12:45 +11:00
Ronnie Sahlberg
240e250b11 USERNAME / PASSWORD
When failing iscsi-ls due to a missing url, print the url syntax
in the error message before aborting
2010-12-25 12:04:29 +11:00
Ronnie Sahlberg
60718652a4 USERNAME PASSWORD
When generating an error after failing to parse a iscsi url
add username/password to the url syntax that is printed in the error message
2010-12-25 12:00:09 +11:00
Ronnie Sahlberg
40abe849b0 CHAP
Add unidirectional chap support so we can authenticate to the target.

Make the login phase more "intelligent" so we can iterate over login
pdus until we have reached full feature phase

Add a new helper functions to parse a iscsi url and break it down
into elements in a structure

Update iscsi-inq to allow CHAP authentication
2010-12-22 22:23:55 +11:00
Ronnie Sahlberg
633a08bc22 MD5
Add a public domain implementation of MD5 so we can compute CHAP
The md5 implementation is copied from TGTD
2010-12-22 21:57:58 +11:00
Ronnie Sahlberg
cf0ddbd0d9 URL PARSER
Add a function to parse a common iscsi://... URL so we dont have to re
implement the same code in every application
2010-12-22 18:40:46 +11:00
Ronnie Sahlberg
79b821db44 LOGIN
We pass header and data separately now so no need to check id size
is less than header size.

Add error reporting of login type and error string describing
the error when login status has failed.
2010-12-22 16:55:48 +11:00
Ronnie Sahlberg
1c024d6bc4 Input processing:
Input processing used to keep all data in one single input buffer, which
makes it hard to handle nested events as well as reading directly from the
socket into the application buffer without an extra copy.

Create a new iscsi_in_pdu structure where we store the header, and any data
for the recevied pdu and store them in a proper input queue.

Change the signature for all processing functions to tahe a iscsi_in_pdu
structure for the received pdu instead of just a pointer to a buffer.
2010-12-11 15:15:51 +11:00
Ronnie Sahlberg
8a6665a092 Licence
Change to LGPL 2.1+ to be compatible with kvm/qemu
2010-12-11 11:47:28 +11:00
Ronnie Sahlberg
3d3da6c6e3 include config.h from lib/socket.c and use this to conditionaly
compile code to set sin_len on platforms that require this field
in the sockaddr structures.
2010-12-05 13:53:41 +11:00
Ronnie Sahlberg
709d85c4da Add a COPYING file and updat ehte LGPL boilerplate 2010-12-05 11:11:37 +11:00
Ronnie Sahlberg
4f49ca5d54 Add missing LGPL boilerplate to crc32c.c 2010-12-05 11:11:09 +11:00
Ronnie Sahlberg
098bc5a9a7 Initial import of libiscsi 2010-12-05 08:24:57 +11:00