2 * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <gpxe/vsprintf.h>
27 #include <gpxe/socket.h>
28 #include <gpxe/xfer.h>
29 #include <gpxe/open.h>
30 #include <gpxe/scsi.h>
31 #include <gpxe/process.h>
32 #include <gpxe/uaccess.h>
33 #include <gpxe/tcpip.h>
34 #include <gpxe/dhcp.h>
35 #include <gpxe/features.h>
36 #include <gpxe/iscsi.h>
44 FEATURE ( FEATURE_PROTOCOL, "iSCSI", DHCP_EB_FEATURE_ISCSI, 1 );
46 /** iSCSI initiator name (explicitly specified) */
47 static char *iscsi_explicit_initiator_iqn;
49 /** Default iSCSI initiator name (constructed from hostname) */
50 static char *iscsi_default_initiator_iqn;
53 static char *iscsi_username;
56 static char *iscsi_password;
58 static void iscsi_start_tx ( struct iscsi_session *iscsi );
59 static void iscsi_start_login ( struct iscsi_session *iscsi );
60 static void iscsi_start_data_out ( struct iscsi_session *iscsi,
61 unsigned int datasn );
64 * Finish receiving PDU data into buffer
66 * @v iscsi iSCSI session
68 static void iscsi_rx_buffered_data_done ( struct iscsi_session *iscsi ) {
69 free ( iscsi->rx_buffer );
70 iscsi->rx_buffer = NULL;
76 * @v refcnt Reference counter
78 static void iscsi_free ( struct refcnt *refcnt ) {
79 struct iscsi_session *iscsi =
80 container_of ( refcnt, struct iscsi_session, refcnt );
82 free ( iscsi->target_address );
83 free ( iscsi->target_iqn );
84 free ( iscsi->username );
85 free ( iscsi->password );
86 chap_finish ( &iscsi->chap );
87 iscsi_rx_buffered_data_done ( iscsi );
92 * Open iSCSI transport-layer connection
94 * @v iscsi iSCSI session
95 * @ret rc Return status code
97 static int iscsi_open_connection ( struct iscsi_session *iscsi ) {
98 struct sockaddr_tcpip target;
101 assert ( iscsi->tx_state == ISCSI_TX_IDLE );
102 assert ( iscsi->rx_state == ISCSI_RX_BHS );
103 assert ( iscsi->rx_offset == 0 );
106 memset ( &target, 0, sizeof ( target ) );
107 target.st_port = htons ( iscsi->target_port );
108 if ( ( rc = xfer_open_named_socket ( &iscsi->socket, SOCK_STREAM,
109 ( struct sockaddr * ) &target,
110 iscsi->target_address,
112 DBGC ( iscsi, "iSCSI %p could not open socket: %s\n",
113 iscsi, strerror ( rc ) );
117 /* Enter security negotiation phase */
118 iscsi->status = ( ISCSI_STATUS_SECURITY_NEGOTIATION_PHASE |
119 ISCSI_STATUS_STRINGS_SECURITY );
121 /* Assign fresh initiator task tag */
125 iscsi_start_login ( iscsi );
131 * Close iSCSI transport-layer connection
133 * @v iscsi iSCSI session
134 * @v rc Reason for close
136 * Closes the transport-layer connection and resets the session state
137 * ready to attempt a fresh login.
139 static void iscsi_close_connection ( struct iscsi_session *iscsi, int rc ) {
141 /* Close all data transfer interfaces */
142 xfer_close ( &iscsi->socket, rc );
144 /* Clear connection status */
147 /* Reset TX and RX state machines */
148 iscsi->tx_state = ISCSI_TX_IDLE;
149 iscsi->rx_state = ISCSI_RX_BHS;
150 iscsi->rx_offset = 0;
152 /* Free any temporary dynamically allocated memory */
153 chap_finish ( &iscsi->chap );
154 iscsi_rx_buffered_data_done ( iscsi );
158 * Mark iSCSI SCSI operation as complete
160 * @v iscsi iSCSI session
161 * @v rc Return status code
163 * Note that iscsi_scsi_done() will not close the connection, and must
164 * therefore be called only when the internal state machines are in an
165 * appropriate state, otherwise bad things may happen on the next call
166 * to iscsi_issue(). The general rule is to call iscsi_scsi_done()
167 * only at the end of receiving a PDU; at this point the TX and RX
168 * engines should both be idle.
170 static void iscsi_scsi_done ( struct iscsi_session *iscsi, int rc ) {
172 assert ( iscsi->tx_state == ISCSI_TX_IDLE );
174 iscsi->command = NULL;
178 /****************************************************************************
180 * iSCSI SCSI command issuing
185 * Build iSCSI SCSI command BHS
187 * @v iscsi iSCSI session
189 * We don't currently support bidirectional commands (i.e. with both
190 * Data-In and Data-Out segments); these would require providing code
191 * to generate an AHS, and there doesn't seem to be any need for it at
194 static void iscsi_start_command ( struct iscsi_session *iscsi ) {
195 struct iscsi_bhs_scsi_command *command = &iscsi->tx_bhs.scsi_command;
197 assert ( ! ( iscsi->command->data_in && iscsi->command->data_out ) );
199 /* Construct BHS and initiate transmission */
200 iscsi_start_tx ( iscsi );
201 command->opcode = ISCSI_OPCODE_SCSI_COMMAND;
202 command->flags = ( ISCSI_FLAG_FINAL |
203 ISCSI_COMMAND_ATTR_SIMPLE );
204 if ( iscsi->command->data_in )
205 command->flags |= ISCSI_COMMAND_FLAG_READ;
206 if ( iscsi->command->data_out )
207 command->flags |= ISCSI_COMMAND_FLAG_WRITE;
208 /* lengths left as zero */
209 command->lun = iscsi->lun;
210 command->itt = htonl ( ++iscsi->itt );
211 command->exp_len = htonl ( iscsi->command->data_in_len |
212 iscsi->command->data_out_len );
213 command->cmdsn = htonl ( iscsi->cmdsn );
214 command->expstatsn = htonl ( iscsi->statsn + 1 );
215 memcpy ( &command->cdb, &iscsi->command->cdb, sizeof ( command->cdb ));
216 DBGC ( iscsi, "iSCSI %p start " SCSI_CDB_FORMAT " %s %#zx\n",
217 iscsi, SCSI_CDB_DATA ( command->cdb ),
218 ( iscsi->command->data_in ? "in" : "out" ),
219 ( iscsi->command->data_in ?
220 iscsi->command->data_in_len : iscsi->command->data_out_len ));
224 * Receive data segment of an iSCSI SCSI response PDU
226 * @v iscsi iSCSI session
227 * @v data Received data
228 * @v len Length of received data
229 * @v remaining Data remaining after this data
230 * @ret rc Return status code
232 static int iscsi_rx_scsi_response ( struct iscsi_session *iscsi,
233 const void *data, size_t len,
235 struct iscsi_bhs_scsi_response *response
236 = &iscsi->rx_bhs.scsi_response;
239 /* Capture the sense response code as it floats past, if present */
240 sense_offset = ISCSI_SENSE_RESPONSE_CODE_OFFSET - iscsi->rx_offset;
241 if ( ( sense_offset >= 0 ) && len ) {
242 iscsi->command->sense_response =
243 * ( ( char * ) data + sense_offset );
246 /* Wait for whole SCSI response to arrive */
250 /* Record SCSI status code */
251 iscsi->command->status = response->status;
253 /* Check for errors */
254 if ( response->response != ISCSI_RESPONSE_COMMAND_COMPLETE )
257 /* Mark as completed */
258 iscsi_scsi_done ( iscsi, 0 );
263 * Receive data segment of an iSCSI data-in PDU
265 * @v iscsi iSCSI session
266 * @v data Received data
267 * @v len Length of received data
268 * @v remaining Data remaining after this data
269 * @ret rc Return status code
271 static int iscsi_rx_data_in ( struct iscsi_session *iscsi,
272 const void *data, size_t len,
273 size_t remaining __unused ) {
274 struct iscsi_bhs_data_in *data_in = &iscsi->rx_bhs.data_in;
275 unsigned long offset;
277 /* Copy data to data-in buffer */
278 offset = ntohl ( data_in->offset ) + iscsi->rx_offset;
279 assert ( iscsi->command != NULL );
280 assert ( iscsi->command->data_in );
281 assert ( ( offset + len ) <= iscsi->command->data_in_len );
282 copy_to_user ( iscsi->command->data_in, offset, data, len );
284 /* Record SCSI status, if present */
285 if ( data_in->flags & ISCSI_DATA_FLAG_STATUS )
286 iscsi->command->status = data_in->status;
288 /* If this is the end, flag as complete */
289 if ( ( offset + len ) == iscsi->command->data_in_len ) {
290 assert ( data_in->flags & ISCSI_FLAG_FINAL );
291 assert ( remaining == 0 );
292 iscsi_scsi_done ( iscsi, 0 );
299 * Receive data segment of an iSCSI R2T PDU
301 * @v iscsi iSCSI session
302 * @v data Received data
303 * @v len Length of received data
304 * @v remaining Data remaining after this data
305 * @ret rc Return status code
307 static int iscsi_rx_r2t ( struct iscsi_session *iscsi,
308 const void *data __unused, size_t len __unused,
309 size_t remaining __unused ) {
310 struct iscsi_bhs_r2t *r2t = &iscsi->rx_bhs.r2t;
312 /* Record transfer parameters and trigger first data-out */
313 iscsi->ttt = ntohl ( r2t->ttt );
314 iscsi->transfer_offset = ntohl ( r2t->offset );
315 iscsi->transfer_len = ntohl ( r2t->len );
316 iscsi_start_data_out ( iscsi, 0 );
322 * Build iSCSI data-out BHS
324 * @v iscsi iSCSI session
325 * @v datasn Data sequence number within the transfer
328 static void iscsi_start_data_out ( struct iscsi_session *iscsi,
329 unsigned int datasn ) {
330 struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
331 unsigned long offset;
332 unsigned long remaining;
335 /* We always send 512-byte Data-Out PDUs; this removes the
336 * need to worry about the target's MaxRecvDataSegmentLength.
338 offset = datasn * 512;
339 remaining = iscsi->transfer_len - offset;
344 /* Construct BHS and initiate transmission */
345 iscsi_start_tx ( iscsi );
346 data_out->opcode = ISCSI_OPCODE_DATA_OUT;
347 if ( len == remaining )
348 data_out->flags = ( ISCSI_FLAG_FINAL );
349 ISCSI_SET_LENGTHS ( data_out->lengths, 0, len );
350 data_out->lun = iscsi->lun;
351 data_out->itt = htonl ( iscsi->itt );
352 data_out->ttt = htonl ( iscsi->ttt );
353 data_out->expstatsn = htonl ( iscsi->statsn + 1 );
354 data_out->datasn = htonl ( datasn );
355 data_out->offset = htonl ( iscsi->transfer_offset + offset );
356 DBGC ( iscsi, "iSCSI %p start data out DataSN %#x len %#lx\n",
357 iscsi, datasn, len );
361 * Complete iSCSI data-out PDU transmission
363 * @v iscsi iSCSI session
366 static void iscsi_data_out_done ( struct iscsi_session *iscsi ) {
367 struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
369 /* If we haven't reached the end of the sequence, start
370 * sending the next data-out PDU.
372 if ( ! ( data_out->flags & ISCSI_FLAG_FINAL ) )
373 iscsi_start_data_out ( iscsi, ntohl ( data_out->datasn ) + 1 );
377 * Send iSCSI data-out data segment
379 * @v iscsi iSCSI session
380 * @ret rc Return status code
382 static int iscsi_tx_data_out ( struct iscsi_session *iscsi ) {
383 struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
384 struct io_buffer *iobuf;
385 unsigned long offset;
388 offset = ntohl ( data_out->offset );
389 len = ISCSI_DATA_LEN ( data_out->lengths );
391 assert ( iscsi->command != NULL );
392 assert ( iscsi->command->data_out );
393 assert ( ( offset + len ) <= iscsi->command->data_out_len );
395 iobuf = xfer_alloc_iob ( &iscsi->socket, len );
399 copy_from_user ( iob_put ( iobuf, len ),
400 iscsi->command->data_out, offset, len );
402 return xfer_deliver_iob ( &iscsi->socket, iobuf );
405 /****************************************************************************
412 * Build iSCSI login request strings
414 * @v iscsi iSCSI session
416 * These are the initial set of strings sent in the first login
417 * request PDU. We want the following settings:
421 * MaxConnections is irrelevant; we make only one connection anyway
423 * ImmediateData is irrelevant; we never send immediate data
424 * MaxRecvDataSegmentLength=8192 (default; we don't care) [3]
425 * MaxBurstLength=262144 (default; we don't care) [3]
426 * FirstBurstLength=262144 (default; we don't care)
427 * DefaultTime2Wait=0 [2]
428 * DefaultTime2Retain=0 [2]
429 * MaxOutstandingR2T=1
431 * DataSequenceInOrder=Yes
432 * ErrorRecoveryLevel=0
434 * [1] InitialR2T has an OR resolution function, so the target may
435 * force us to use it. We therefore simplify our logic by always
438 * [2] These ensure that we can safely start a new task once we have
439 * reconnected after a failure, without having to manually tidy up
442 * [3] We are quite happy to use the RFC-defined default values for
443 * these parameters, but some targets (notably OpenSolaris)
444 * incorrectly assume a default value of zero, so we explicitly
445 * specify the default values.
447 static int iscsi_build_login_request_strings ( struct iscsi_session *iscsi,
448 void *data, size_t len ) {
449 unsigned int used = 0;
452 if ( iscsi->status & ISCSI_STATUS_STRINGS_SECURITY ) {
453 used += ssnprintf ( data + used, len - used,
456 "SessionType=Normal%c"
457 "AuthMethod=CHAP,None%c",
458 iscsi_initiator_iqn(), 0,
459 iscsi->target_iqn, 0, 0, 0 );
462 if ( iscsi->status & ISCSI_STATUS_STRINGS_CHAP_ALGORITHM ) {
463 used += ssnprintf ( data + used, len - used, "CHAP_A=5%c", 0 );
466 if ( ( iscsi->status & ISCSI_STATUS_STRINGS_CHAP_RESPONSE ) &&
468 used += ssnprintf ( data + used, len - used,
469 "CHAP_N=%s%cCHAP_R=0x",
470 iscsi->username, 0 );
471 for ( i = 0 ; i < iscsi->chap.response_len ; i++ ) {
472 used += ssnprintf ( data + used, len - used, "%02x",
473 iscsi->chap.response[i] );
475 used += ssnprintf ( data + used, len - used, "%c", 0 );
478 if ( iscsi->status & ISCSI_STATUS_STRINGS_OPERATIONAL ) {
479 used += ssnprintf ( data + used, len - used,
480 "HeaderDigest=None%c"
483 "MaxRecvDataSegmentLength=8192%c"
484 "MaxBurstLength=262144%c"
485 "DefaultTime2Wait=0%c"
486 "DefaultTime2Retain=0%c"
487 "MaxOutstandingR2T=1%c"
488 "DataPDUInOrder=Yes%c"
489 "DataSequenceInOrder=Yes%c"
490 "ErrorRecoveryLevel=0%c",
491 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
498 * Build iSCSI login request BHS
500 * @v iscsi iSCSI session
502 static void iscsi_start_login ( struct iscsi_session *iscsi ) {
503 struct iscsi_bhs_login_request *request = &iscsi->tx_bhs.login_request;
506 /* Construct BHS and initiate transmission */
507 iscsi_start_tx ( iscsi );
508 request->opcode = ( ISCSI_OPCODE_LOGIN_REQUEST |
509 ISCSI_FLAG_IMMEDIATE );
510 request->flags = ( ( iscsi->status & ISCSI_STATUS_PHASE_MASK ) |
511 ISCSI_LOGIN_FLAG_TRANSITION );
512 /* version_max and version_min left as zero */
513 len = iscsi_build_login_request_strings ( iscsi, NULL, 0 );
514 ISCSI_SET_LENGTHS ( request->lengths, 0, len );
515 request->isid_iana_en = htonl ( ISCSI_ISID_IANA |
516 IANA_EN_FEN_SYSTEMS );
517 /* isid_iana_qual left as zero */
518 request->tsih = htons ( iscsi->tsih );
519 request->itt = htonl ( iscsi->itt );
520 /* cid left as zero */
521 request->cmdsn = htonl ( iscsi->cmdsn );
522 request->expstatsn = htonl ( iscsi->statsn + 1 );
526 * Complete iSCSI login request PDU transmission
528 * @v iscsi iSCSI session
531 static void iscsi_login_request_done ( struct iscsi_session *iscsi ) {
533 /* Clear any "strings to send" flags */
534 iscsi->status &= ~ISCSI_STATUS_STRINGS_MASK;
536 /* Free any dynamically allocated storage used for login */
537 chap_finish ( &iscsi->chap );
541 * Transmit data segment of an iSCSI login request PDU
543 * @v iscsi iSCSI session
544 * @ret rc Return status code
546 * For login requests, the data segment consists of the login strings.
548 static int iscsi_tx_login_request ( struct iscsi_session *iscsi ) {
549 struct iscsi_bhs_login_request *request = &iscsi->tx_bhs.login_request;
550 struct io_buffer *iobuf;
553 len = ISCSI_DATA_LEN ( request->lengths );
554 iobuf = xfer_alloc_iob ( &iscsi->socket, len );
557 iob_put ( iobuf, len );
558 iscsi_build_login_request_strings ( iscsi, iobuf->data, len );
559 return xfer_deliver_iob ( &iscsi->socket, iobuf );
563 * Handle iSCSI TargetAddress text value
565 * @v iscsi iSCSI session
566 * @v value TargetAddress value
567 * @ret rc Return status code
569 static int iscsi_handle_targetaddress_value ( struct iscsi_session *iscsi,
570 const char *value ) {
572 DBGC ( iscsi, "iSCSI %p will redirect to %s\n", iscsi, value );
574 /* Replace target address */
575 free ( iscsi->target_address );
576 iscsi->target_address = strdup ( value );
577 if ( ! iscsi->target_address )
583 * Handle iSCSI AuthMethod text value
585 * @v iscsi iSCSI session
586 * @v value AuthMethod value
587 * @ret rc Return status code
589 static int iscsi_handle_authmethod_value ( struct iscsi_session *iscsi,
590 const char *value ) {
592 /* If server requests CHAP, send the CHAP_A string */
593 if ( strcmp ( value, "CHAP" ) == 0 ) {
594 DBGC ( iscsi, "iSCSI %p initiating CHAP authentication\n",
596 iscsi->status |= ISCSI_STATUS_STRINGS_CHAP_ALGORITHM;
602 * Handle iSCSI CHAP_A text value
604 * @v iscsi iSCSI session
605 * @v value CHAP_A value
606 * @ret rc Return status code
608 static int iscsi_handle_chap_a_value ( struct iscsi_session *iscsi,
609 const char *value ) {
612 /* We only ever offer "5" (i.e. MD5) as an algorithm, so if
613 * the server responds with anything else it is a protocol
616 if ( strcmp ( value, "5" ) != 0 ) {
617 DBGC ( iscsi, "iSCSI %p got invalid CHAP algorithm \"%s\"\n",
622 /* Prepare for CHAP with MD5 */
623 if ( ( rc = chap_init ( &iscsi->chap, &md5_algorithm ) ) != 0 ) {
624 DBGC ( iscsi, "iSCSI %p could not initialise CHAP: %s\n",
625 iscsi, strerror ( rc ) );
633 * Handle iSCSI CHAP_I text value
635 * @v iscsi iSCSI session
636 * @v value CHAP_I value
637 * @ret rc Return status code
639 static int iscsi_handle_chap_i_value ( struct iscsi_session *iscsi,
640 const char *value ) {
641 unsigned int identifier;
644 /* The CHAP identifier is an integer value */
645 identifier = strtoul ( value, &endp, 0 );
646 if ( *endp != '\0' ) {
647 DBGC ( iscsi, "iSCSI %p saw invalid CHAP identifier \"%s\"\n",
652 /* Identifier and secret are the first two components of the
655 chap_set_identifier ( &iscsi->chap, identifier );
656 if ( iscsi->password ) {
657 chap_update ( &iscsi->chap, iscsi->password,
658 strlen ( iscsi->password ) );
665 * Handle iSCSI CHAP_C text value
667 * @v iscsi iSCSI session
668 * @v value CHAP_C value
669 * @ret rc Return status code
671 static int iscsi_handle_chap_c_value ( struct iscsi_session *iscsi,
672 const char *value ) {
677 /* Check and strip leading "0x" */
678 if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
679 DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge \"%s\"\n",
684 /* Process challenge an octet at a time */
685 for ( ; ( value[0] && value[1] ) ; value += 2 ) {
686 memcpy ( buf, value, 2 );
688 byte = strtoul ( buf, &endp, 16 );
689 if ( *endp != '\0' ) {
690 DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge "
691 "byte \"%s\"\n", iscsi, buf );
694 chap_update ( &iscsi->chap, &byte, sizeof ( byte ) );
697 /* Build CHAP response */
698 DBGC ( iscsi, "iSCSI %p sending CHAP response\n", iscsi );
699 chap_respond ( &iscsi->chap );
700 iscsi->status |= ISCSI_STATUS_STRINGS_CHAP_RESPONSE;
705 /** An iSCSI text string that we want to handle */
706 struct iscsi_string_type {
709 * This is the portion up to and including the "=" sign,
710 * e.g. "InitiatorName=", "CHAP_A=", etc.
713 /** Handle iSCSI string value
715 * @v iscsi iSCSI session
716 * @v value iSCSI string value
717 * @ret rc Return status code
719 int ( * handle ) ( struct iscsi_session *iscsi, const char *value );
722 /** iSCSI text strings that we want to handle */
723 static struct iscsi_string_type iscsi_string_types[] = {
724 { "TargetAddress=", iscsi_handle_targetaddress_value },
725 { "AuthMethod=", iscsi_handle_authmethod_value },
726 { "CHAP_A=", iscsi_handle_chap_a_value },
727 { "CHAP_I=", iscsi_handle_chap_i_value },
728 { "CHAP_C=", iscsi_handle_chap_c_value },
733 * Handle iSCSI string
735 * @v iscsi iSCSI session
736 * @v string iSCSI string (in "key=value" format)
737 * @ret rc Return status code
739 static int iscsi_handle_string ( struct iscsi_session *iscsi,
740 const char *string ) {
741 struct iscsi_string_type *type;
745 for ( type = iscsi_string_types ; type->key ; type++ ) {
746 key_len = strlen ( type->key );
747 if ( strncmp ( string, type->key, key_len ) != 0 )
749 DBGC ( iscsi, "iSCSI %p handling %s\n", iscsi, string );
750 if ( ( rc = type->handle ( iscsi,
751 ( string + key_len ) ) ) != 0 ) {
752 DBGC ( iscsi, "iSCSI %p could not handle %s: %s\n",
753 iscsi, string, strerror ( rc ) );
758 DBGC ( iscsi, "iSCSI %p ignoring %s\n", iscsi, string );
763 * Handle iSCSI strings
765 * @v iscsi iSCSI session
766 * @v string iSCSI string buffer
767 * @v len Length of string buffer
768 * @ret rc Return status code
770 static int iscsi_handle_strings ( struct iscsi_session *iscsi,
771 const char *strings, size_t len ) {
775 /* Handle each string in turn, taking care not to overrun the
776 * data buffer in case of badly-terminated data.
779 string_len = ( strnlen ( strings, len ) + 1 );
780 if ( string_len > len )
782 if ( ( rc = iscsi_handle_string ( iscsi, strings ) ) != 0 )
784 strings += string_len;
791 * Receive PDU data into buffer
793 * @v iscsi iSCSI session
794 * @v data Data to receive
795 * @v len Length of data
796 * @ret rc Return status code
798 * This can be used when the RX PDU type handler wishes to buffer up
799 * all received data and process the PDU as a single unit. The caller
800 * is repsonsible for calling iscsi_rx_buffered_data_done() after
801 * processing the data.
803 static int iscsi_rx_buffered_data ( struct iscsi_session *iscsi,
804 const void *data, size_t len ) {
806 /* Allocate buffer on first call */
807 if ( ! iscsi->rx_buffer ) {
808 iscsi->rx_buffer = malloc ( iscsi->rx_len );
809 if ( ! iscsi->rx_buffer )
813 /* Copy data to buffer */
814 assert ( ( iscsi->rx_offset + len ) <= iscsi->rx_len );
815 memcpy ( ( iscsi->rx_buffer + iscsi->rx_offset ), data, len );
821 * Receive data segment of an iSCSI login response PDU
823 * @v iscsi iSCSI session
824 * @v data Received data
825 * @v len Length of received data
826 * @v remaining Data remaining after this data
827 * @ret rc Return status code
829 static int iscsi_rx_login_response ( struct iscsi_session *iscsi,
830 const void *data, size_t len,
832 struct iscsi_bhs_login_response *response
833 = &iscsi->rx_bhs.login_response;
836 /* Buffer up the PDU data */
837 if ( ( rc = iscsi_rx_buffered_data ( iscsi, data, len ) ) != 0 ) {
838 DBGC ( iscsi, "iSCSI %p could not buffer login response: %s\n",
839 iscsi, strerror ( rc ) );
845 /* Process string data and discard string buffer */
846 if ( ( rc = iscsi_handle_strings ( iscsi, iscsi->rx_buffer,
847 iscsi->rx_len ) ) != 0 )
849 iscsi_rx_buffered_data_done ( iscsi );
851 /* Check for login redirection */
852 if ( response->status_class == ISCSI_STATUS_REDIRECT ) {
853 DBGC ( iscsi, "iSCSI %p redirecting to new server\n", iscsi );
854 iscsi_close_connection ( iscsi, 0 );
855 if ( ( rc = iscsi_open_connection ( iscsi ) ) != 0 ) {
856 DBGC ( iscsi, "iSCSI %p could not redirect: %s\n ",
857 iscsi, strerror ( rc ) );
863 /* Check for fatal errors */
864 if ( response->status_class != 0 ) {
865 DBGC ( iscsi, "iSCSI login failure: class %02x detail %02x\n",
866 response->status_class, response->status_detail );
867 iscsi->instant_rc = -EPERM;
871 /* Handle login transitions */
872 if ( response->flags & ISCSI_LOGIN_FLAG_TRANSITION ) {
873 switch ( response->flags & ISCSI_LOGIN_NSG_MASK ) {
874 case ISCSI_LOGIN_NSG_OPERATIONAL_NEGOTIATION:
876 ( ISCSI_STATUS_OPERATIONAL_NEGOTIATION_PHASE |
877 ISCSI_STATUS_STRINGS_OPERATIONAL );
879 case ISCSI_LOGIN_NSG_FULL_FEATURE_PHASE:
880 iscsi->status = ISCSI_STATUS_FULL_FEATURE_PHASE;
883 DBGC ( iscsi, "iSCSI %p got invalid response flags "
884 "%02x\n", iscsi, response->flags );
889 /* Send next login request PDU if we haven't reached the full
892 if ( ( iscsi->status & ISCSI_STATUS_PHASE_MASK ) !=
893 ISCSI_STATUS_FULL_FEATURE_PHASE ) {
894 iscsi_start_login ( iscsi );
898 /* Reset retry count */
899 iscsi->retry_count = 0;
901 /* Record TSIH for future reference */
902 iscsi->tsih = ntohl ( response->tsih );
904 /* Send the actual SCSI command */
905 iscsi_start_command ( iscsi );
910 /****************************************************************************
912 * iSCSI to socket interface
917 * Start up a new TX PDU
919 * @v iscsi iSCSI session
921 * This initiates the process of sending a new PDU. Only one PDU may
922 * be in transit at any one time.
924 static void iscsi_start_tx ( struct iscsi_session *iscsi ) {
925 assert ( iscsi->tx_state == ISCSI_TX_IDLE );
927 /* Initialise TX BHS */
928 memset ( &iscsi->tx_bhs, 0, sizeof ( iscsi->tx_bhs ) );
930 /* Flag TX engine to start transmitting */
931 iscsi->tx_state = ISCSI_TX_BHS;
937 * @v iscsi iSCSI session
938 * @ret rc Return status code
940 static int iscsi_tx_nothing ( struct iscsi_session *iscsi __unused ) {
945 * Transmit basic header segment of an iSCSI PDU
947 * @v iscsi iSCSI session
948 * @ret rc Return status code
950 static int iscsi_tx_bhs ( struct iscsi_session *iscsi ) {
951 return xfer_deliver_raw ( &iscsi->socket, &iscsi->tx_bhs,
952 sizeof ( iscsi->tx_bhs ) );
956 * Transmit data segment of an iSCSI PDU
958 * @v iscsi iSCSI session
959 * @ret rc Return status code
961 * Handle transmission of part of a PDU data segment. iscsi::tx_bhs
962 * will be valid when this is called.
964 static int iscsi_tx_data ( struct iscsi_session *iscsi ) {
965 struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
967 switch ( common->opcode & ISCSI_OPCODE_MASK ) {
968 case ISCSI_OPCODE_DATA_OUT:
969 return iscsi_tx_data_out ( iscsi );
970 case ISCSI_OPCODE_LOGIN_REQUEST:
971 return iscsi_tx_login_request ( iscsi );
973 /* Nothing to send in other states */
979 * Transmit data padding of an iSCSI PDU
981 * @v iscsi iSCSI session
982 * @ret rc Return status code
984 * Handle transmission of any data padding in a PDU data segment.
985 * iscsi::tx_bhs will be valid when this is called.
987 static int iscsi_tx_data_padding ( struct iscsi_session *iscsi ) {
988 static const char pad[] = { '\0', '\0', '\0' };
989 struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
992 pad_len = ISCSI_DATA_PAD_LEN ( common->lengths );
996 return xfer_deliver_raw ( &iscsi->socket, pad, pad_len );
1000 * Complete iSCSI PDU transmission
1002 * @v iscsi iSCSI session
1004 * Called when a PDU has been completely transmitted and the TX state
1005 * machine is about to enter the idle state. iscsi::tx_bhs will be
1006 * valid for the just-completed PDU when this is called.
1008 static void iscsi_tx_done ( struct iscsi_session *iscsi ) {
1009 struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
1011 switch ( common->opcode & ISCSI_OPCODE_MASK ) {
1012 case ISCSI_OPCODE_DATA_OUT:
1013 iscsi_data_out_done ( iscsi );
1014 case ISCSI_OPCODE_LOGIN_REQUEST:
1015 iscsi_login_request_done ( iscsi );
1023 * Transmit iSCSI PDU
1025 * @v iscsi iSCSI session
1026 * @v buf Temporary data buffer
1027 * @v len Length of temporary data buffer
1029 * Constructs data to be sent for the current TX state
1031 static void iscsi_tx_step ( struct process *process ) {
1032 struct iscsi_session *iscsi =
1033 container_of ( process, struct iscsi_session, process );
1034 struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
1035 int ( * tx ) ( struct iscsi_session *iscsi );
1036 enum iscsi_tx_state next_state;
1040 /* Select fragment to transmit */
1042 switch ( iscsi->tx_state ) {
1044 /* Stop processing */
1048 tx_len = sizeof ( iscsi->tx_bhs );
1049 next_state = ISCSI_TX_AHS;
1052 tx = iscsi_tx_nothing;
1054 next_state = ISCSI_TX_DATA;
1058 tx_len = ISCSI_DATA_LEN ( common->lengths );
1059 next_state = ISCSI_TX_DATA_PADDING;
1061 case ISCSI_TX_DATA_PADDING:
1062 tx = iscsi_tx_data_padding;
1063 tx_len = ISCSI_DATA_PAD_LEN ( common->lengths );
1064 next_state = ISCSI_TX_IDLE;
1071 /* Check for window availability, if needed */
1072 if ( tx_len && ( xfer_window ( &iscsi->socket ) == 0 ) ) {
1073 /* Cannot transmit at this point; stop processing */
1078 if ( ( rc = tx ( iscsi ) ) != 0 ) {
1079 DBGC ( iscsi, "iSCSI %p could not transmit: %s\n",
1080 iscsi, strerror ( rc ) );
1084 /* Move to next state */
1085 iscsi->tx_state = next_state;
1086 if ( next_state == ISCSI_TX_IDLE )
1087 iscsi_tx_done ( iscsi );
1092 * Receive basic header segment of an iSCSI PDU
1094 * @v iscsi iSCSI session
1095 * @v data Received data
1096 * @v len Length of received data
1097 * @v remaining Data remaining after this data
1098 * @ret rc Return status code
1100 * This fills in iscsi::rx_bhs with the data from the BHS portion of
1103 static int iscsi_rx_bhs ( struct iscsi_session *iscsi, const void *data,
1104 size_t len, size_t remaining __unused ) {
1105 memcpy ( &iscsi->rx_bhs.bytes[iscsi->rx_offset], data, len );
1106 if ( ( iscsi->rx_offset + len ) >= sizeof ( iscsi->rx_bhs ) ) {
1107 DBGC ( iscsi, "iSCSI %p received PDU opcode %#x len %#lx\n",
1108 iscsi, iscsi->rx_bhs.common.opcode,
1109 ISCSI_DATA_LEN ( iscsi->rx_bhs.common.lengths ) );
1115 * Discard portion of an iSCSI PDU.
1117 * @v iscsi iSCSI session
1118 * @v data Received data
1119 * @v len Length of received data
1120 * @v remaining Data remaining after this data
1121 * @ret rc Return status code
1123 * This discards data from a portion of a received PDU.
1125 static int iscsi_rx_discard ( struct iscsi_session *iscsi __unused,
1126 const void *data __unused, size_t len __unused,
1127 size_t remaining __unused ) {
1133 * Receive data segment of an iSCSI PDU
1135 * @v iscsi iSCSI session
1136 * @v data Received data
1137 * @v len Length of received data
1138 * @v remaining Data remaining after this data
1139 * @ret rc Return status code
1141 * Handle processing of part of a PDU data segment. iscsi::rx_bhs
1142 * will be valid when this is called.
1144 static int iscsi_rx_data ( struct iscsi_session *iscsi, const void *data,
1145 size_t len, size_t remaining ) {
1146 struct iscsi_bhs_common_response *response
1147 = &iscsi->rx_bhs.common_response;
1149 /* Update cmdsn and statsn */
1150 iscsi->cmdsn = ntohl ( response->expcmdsn );
1151 iscsi->statsn = ntohl ( response->statsn );
1153 switch ( response->opcode & ISCSI_OPCODE_MASK ) {
1154 case ISCSI_OPCODE_LOGIN_RESPONSE:
1155 return iscsi_rx_login_response ( iscsi, data, len, remaining );
1156 case ISCSI_OPCODE_SCSI_RESPONSE:
1157 return iscsi_rx_scsi_response ( iscsi, data, len, remaining );
1158 case ISCSI_OPCODE_DATA_IN:
1159 return iscsi_rx_data_in ( iscsi, data, len, remaining );
1160 case ISCSI_OPCODE_R2T:
1161 return iscsi_rx_r2t ( iscsi, data, len, remaining );
1165 DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
1174 * @v socket Transport layer interface
1175 * @v data Received data
1176 * @v len Length of received data
1177 * @ret rc Return status code
1179 * This handles received PDUs. The receive strategy is to fill in
1180 * iscsi::rx_bhs with the contents of the BHS portion of the PDU,
1181 * throw away any AHS portion, and then process each part of the data
1182 * portion as it arrives. The data processing routine therefore
1183 * always has a full copy of the BHS available, even for portions of
1184 * the data in different packets to the BHS.
1186 static int iscsi_socket_deliver_raw ( struct xfer_interface *socket,
1187 const void *data, size_t len ) {
1188 struct iscsi_session *iscsi =
1189 container_of ( socket, struct iscsi_session, socket );
1190 struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
1191 int ( * rx ) ( struct iscsi_session *iscsi, const void *data,
1192 size_t len, size_t remaining );
1193 enum iscsi_rx_state next_state;
1199 switch ( iscsi->rx_state ) {
1202 iscsi->rx_len = sizeof ( iscsi->rx_bhs );
1203 next_state = ISCSI_RX_AHS;
1206 rx = iscsi_rx_discard;
1207 iscsi->rx_len = 4 * ISCSI_AHS_LEN ( common->lengths );
1208 next_state = ISCSI_RX_DATA;
1212 iscsi->rx_len = ISCSI_DATA_LEN ( common->lengths );
1213 next_state = ISCSI_RX_DATA_PADDING;
1215 case ISCSI_RX_DATA_PADDING:
1216 rx = iscsi_rx_discard;
1217 iscsi->rx_len = ISCSI_DATA_PAD_LEN ( common->lengths );
1218 next_state = ISCSI_RX_BHS;
1225 frag_len = iscsi->rx_len - iscsi->rx_offset;
1226 if ( frag_len > len )
1228 remaining = iscsi->rx_len - iscsi->rx_offset - frag_len;
1229 if ( ( rc = rx ( iscsi, data, frag_len, remaining ) ) != 0 ) {
1230 DBGC ( iscsi, "iSCSI %p could not process received "
1231 "data: %s\n", iscsi, strerror ( rc ) );
1232 iscsi_close_connection ( iscsi, rc );
1233 iscsi_scsi_done ( iscsi, rc );
1237 iscsi->rx_offset += frag_len;
1241 /* If all the data for this state has not yet been
1242 * received, stay in this state for now.
1244 if ( iscsi->rx_offset != iscsi->rx_len )
1247 iscsi->rx_state = next_state;
1248 iscsi->rx_offset = 0;
1255 * Handle stream connection closure
1257 * @v socket Transport layer interface
1258 * @v rc Reason for close
1261 static void iscsi_socket_close ( struct xfer_interface *socket, int rc ) {
1262 struct iscsi_session *iscsi =
1263 container_of ( socket, struct iscsi_session, socket );
1265 /* Even a graceful close counts as an error for iSCSI */
1269 /* Close session cleanly */
1270 iscsi_close_connection ( iscsi, rc );
1272 /* Retry connection if within the retry limit, otherwise fail */
1273 if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) {
1274 DBGC ( iscsi, "iSCSI %p retrying connection (retry #%d)\n",
1275 iscsi, iscsi->retry_count );
1276 if ( ( rc = iscsi_open_connection ( iscsi ) ) != 0 ) {
1277 DBGC ( iscsi, "iSCSI %p could not reconnect: %s\n",
1278 iscsi, strerror ( rc ) );
1279 iscsi_scsi_done ( iscsi, rc );
1282 DBGC ( iscsi, "iSCSI %p retry count exceeded\n", iscsi );
1283 iscsi->instant_rc = rc;
1284 iscsi_scsi_done ( iscsi, rc );
1289 * Handle redirection event
1291 * @v socket Transport layer interface
1292 * @v type Location type
1293 * @v args Remaining arguments depend upon location type
1294 * @ret rc Return status code
1296 static int iscsi_vredirect ( struct xfer_interface *socket, int type,
1298 struct iscsi_session *iscsi =
1299 container_of ( socket, struct iscsi_session, socket );
1301 struct sockaddr *peer;
1303 /* Intercept redirects to a LOCATION_SOCKET and record the IP
1304 * address for the iBFT. This is a bit of a hack, but avoids
1305 * inventing an ioctl()-style call to retrieve the socket
1306 * address from a data-xfer interface.
1308 if ( type == LOCATION_SOCKET ) {
1309 va_copy ( tmp, args );
1310 ( void ) va_arg ( tmp, int ); /* Discard "semantics" */
1311 peer = va_arg ( tmp, struct sockaddr * );
1312 memcpy ( &iscsi->target_sockaddr, peer,
1313 sizeof ( iscsi->target_sockaddr ) );
1317 return xfer_vopen ( socket, type, args );
1321 /** iSCSI socket operations */
1322 static struct xfer_interface_operations iscsi_socket_operations = {
1323 .close = iscsi_socket_close,
1324 .vredirect = iscsi_vredirect,
1325 .window = unlimited_xfer_window,
1326 .alloc_iob = default_xfer_alloc_iob,
1327 .deliver_iob = xfer_deliver_as_raw,
1328 .deliver_raw = iscsi_socket_deliver_raw,
1332 /****************************************************************************
1334 * iSCSI command issuing
1339 * Issue SCSI command
1341 * @v scsi SCSI device
1342 * @v command SCSI command
1343 * @ret rc Return status code
1345 static int iscsi_command ( struct scsi_device *scsi,
1346 struct scsi_command *command ) {
1347 struct iscsi_session *iscsi =
1348 container_of ( scsi->backend, struct iscsi_session, refcnt );
1351 /* Record SCSI command */
1352 iscsi->command = command;
1354 /* Abort immediately if we have a recorded permanent failure */
1355 if ( iscsi->instant_rc ) {
1356 rc = iscsi->instant_rc;
1360 /* Issue command or open connection as appropriate */
1361 if ( iscsi->status ) {
1362 iscsi_start_command ( iscsi );
1364 if ( ( rc = iscsi_open_connection ( iscsi ) ) != 0 )
1368 /* Wait for command to complete */
1369 iscsi->rc = -EINPROGRESS;
1370 while ( iscsi->rc == -EINPROGRESS )
1375 iscsi->command = NULL;
1379 static int iscsi_detached_command ( struct scsi_device *scsi __unused,
1380 struct scsi_command *command __unused ) {
1385 * Shut down iSCSI interface
1387 * @v scsi SCSI device
1389 void iscsi_detach ( struct scsi_device *scsi ) {
1390 struct iscsi_session *iscsi =
1391 container_of ( scsi->backend, struct iscsi_session, refcnt );
1393 xfer_nullify ( &iscsi->socket );
1394 iscsi_close_connection ( iscsi, 0 );
1395 process_del ( &iscsi->process );
1396 scsi->command = iscsi_detached_command;
1397 ref_put ( scsi->backend );
1398 scsi->backend = NULL;
1401 /****************************************************************************
1407 /** iSCSI root path components (as per RFC4173) */
1408 enum iscsi_root_path_component {
1421 * @v iscsi iSCSI session
1422 * @v lun_string LUN string representation (as per RFC4173)
1423 * @ret rc Return status code
1425 static int iscsi_parse_lun ( struct iscsi_session *iscsi,
1426 const char *lun_string ) {
1427 char *p = ( char * ) lun_string;
1434 /* Empty LUN; assume LUN 0 */
1435 if ( ! *lun_string )
1438 for ( i = 0 ; i < 4 ; i++ ) {
1439 lun.u16[i] = strtoul ( p, &p, 16 );
1447 iscsi->lun = lun.u64;
1452 * Parse iSCSI root path
1454 * @v iscsi iSCSI session
1455 * @v root_path iSCSI root path (as per RFC4173)
1456 * @ret rc Return status code
1458 static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
1459 const char *root_path ) {
1460 char rp_copy[ strlen ( root_path ) + 1 ];
1461 char *rp_comp[NUM_RP_COMPONENTS];
1466 /* Split root path into component parts */
1467 strcpy ( rp_copy, root_path );
1470 if ( i == NUM_RP_COMPONENTS )
1472 for ( ; *rp != ':' ; rp++ ) {
1474 DBGC ( iscsi, "iSCSI %p root path \"%s\" "
1475 "too short\n", iscsi, root_path );
1482 /* Use root path components to configure iSCSI session */
1483 iscsi->target_address = strdup ( rp_comp[RP_SERVERNAME] );
1484 if ( ! iscsi->target_address )
1486 iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
1487 if ( ! iscsi->target_port )
1488 iscsi->target_port = ISCSI_PORT;
1489 if ( ( rc = iscsi_parse_lun ( iscsi, rp_comp[RP_LUN] ) ) != 0 ) {
1490 DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
1491 iscsi, rp_comp[RP_LUN] );
1494 iscsi->target_iqn = strdup ( rp_comp[RP_TARGETNAME] );
1495 if ( ! iscsi->target_iqn )
1502 * Set iSCSI authentication details
1504 * @v iscsi iSCSI session
1505 * @v username Username, if any
1506 * @v password Password, if any
1507 * @ret rc Return status code
1509 static int iscsi_set_auth ( struct iscsi_session *iscsi,
1510 const char *username, const char *password ) {
1513 iscsi->username = strdup ( username );
1514 if ( ! iscsi->username )
1519 iscsi->password = strdup ( password );
1520 if ( ! iscsi->password )
1528 * Attach iSCSI interface
1530 * @v scsi SCSI device
1531 * @v root_path iSCSI root path (as per RFC4173)
1532 * @ret rc Return status code
1534 int iscsi_attach ( struct scsi_device *scsi, const char *root_path ) {
1535 struct iscsi_session *iscsi;
1538 /* Allocate and initialise structure */
1539 iscsi = zalloc ( sizeof ( *iscsi ) );
1542 iscsi->refcnt.free = iscsi_free;
1543 xfer_init ( &iscsi->socket, &iscsi_socket_operations, &iscsi->refcnt );
1544 process_init ( &iscsi->process, iscsi_tx_step, &iscsi->refcnt );
1546 /* Parse root path */
1547 if ( ( rc = iscsi_parse_root_path ( iscsi, root_path ) ) != 0 )
1549 /* Set fields not specified by root path */
1550 if ( ( rc = iscsi_set_auth ( iscsi, iscsi_username,
1551 iscsi_password ) ) != 0 )
1555 if ( ! iscsi->target_address ) {
1556 DBGC ( iscsi, "iSCSI %p does not yet support discovery\n",
1561 if ( ! iscsi->target_iqn ) {
1562 DBGC ( iscsi, "iSCSI %p no target address supplied in %s\n",
1568 /* Attach parent interface, mortalise self, and return */
1569 scsi->backend = ref_get ( &iscsi->refcnt );
1570 scsi->command = iscsi_command;
1571 scsi->lun = iscsi->lun;
1572 ref_put ( &iscsi->refcnt );
1576 ref_put ( &iscsi->refcnt );
1580 /****************************************************************************
1582 * DHCP option applicators
1587 * Apply DHCP iSCSI option
1589 * @v tag DHCP option tag
1590 * @v option DHCP option
1591 * @ret rc Return status code
1593 static int apply_dhcp_iscsi_string ( unsigned int tag,
1594 struct dhcp_option *option ) {
1601 /* Identify string and prefix */
1603 case DHCP_ISCSI_INITIATOR_IQN:
1604 string = &iscsi_explicit_initiator_iqn;
1606 case DHCP_EB_USERNAME:
1607 string = &iscsi_username;
1609 case DHCP_EB_PASSWORD:
1610 string = &iscsi_password;
1612 case DHCP_HOST_NAME:
1613 string = &iscsi_default_initiator_iqn;
1614 prefix = "iqn.2000-09.org.etherboot:";
1621 /* Free old string */
1625 /* Allocate and fill new string */
1626 prefix_len = strlen ( prefix );
1627 len = ( prefix_len + option->len + 1 );
1628 p = *string = malloc ( len );
1631 strcpy ( p, prefix );
1632 dhcp_snprintf ( ( p + prefix_len ), ( len - prefix_len ), option );
1636 /** DHCP iSCSI option applicators */
1637 struct dhcp_option_applicator dhcp_iscsi_applicators[] __dhcp_applicator = {
1639 .tag = DHCP_ISCSI_INITIATOR_IQN,
1640 .apply = apply_dhcp_iscsi_string,
1643 .tag = DHCP_EB_USERNAME,
1644 .apply = apply_dhcp_iscsi_string,
1647 .tag = DHCP_EB_PASSWORD,
1648 .apply = apply_dhcp_iscsi_string,
1651 .tag = DHCP_HOST_NAME,
1652 .apply = apply_dhcp_iscsi_string,
1656 /****************************************************************************
1663 * Get iSCSI initiator IQN
1665 * @v iscsi iSCSI session
1666 * @ret rc Return status code
1668 const char * iscsi_initiator_iqn ( void ) {
1670 if ( iscsi_explicit_initiator_iqn )
1671 return iscsi_explicit_initiator_iqn;
1672 if ( iscsi_default_initiator_iqn )
1673 return iscsi_default_initiator_iqn;
1674 return "iqn.2000-09.org.etherboot:UNKNOWN";