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,
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 /* Wait for whole SCSI response to arrive */
288 /* Mark as completed if status is present */
289 if ( data_in->flags & ISCSI_DATA_FLAG_STATUS ) {
290 assert ( ( offset + len ) == iscsi->command->data_in_len );
291 assert ( data_in->flags & ISCSI_FLAG_FINAL );
292 iscsi->command->status = data_in->status;
293 /* iSCSI cannot return an error status via a data-in */
294 iscsi_scsi_done ( iscsi, 0 );
301 * Receive data segment of an iSCSI R2T PDU
303 * @v iscsi iSCSI session
304 * @v data Received data
305 * @v len Length of received data
306 * @v remaining Data remaining after this data
307 * @ret rc Return status code
309 static int iscsi_rx_r2t ( struct iscsi_session *iscsi,
310 const void *data __unused, size_t len __unused,
311 size_t remaining __unused ) {
312 struct iscsi_bhs_r2t *r2t = &iscsi->rx_bhs.r2t;
314 /* Record transfer parameters and trigger first data-out */
315 iscsi->ttt = ntohl ( r2t->ttt );
316 iscsi->transfer_offset = ntohl ( r2t->offset );
317 iscsi->transfer_len = ntohl ( r2t->len );
318 iscsi_start_data_out ( iscsi, 0 );
324 * Build iSCSI data-out BHS
326 * @v iscsi iSCSI session
327 * @v datasn Data sequence number within the transfer
330 static void iscsi_start_data_out ( struct iscsi_session *iscsi,
331 unsigned int datasn ) {
332 struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
333 unsigned long offset;
334 unsigned long remaining;
337 /* We always send 512-byte Data-Out PDUs; this removes the
338 * need to worry about the target's MaxRecvDataSegmentLength.
340 offset = datasn * 512;
341 remaining = iscsi->transfer_len - offset;
346 /* Construct BHS and initiate transmission */
347 iscsi_start_tx ( iscsi );
348 data_out->opcode = ISCSI_OPCODE_DATA_OUT;
349 if ( len == remaining )
350 data_out->flags = ( ISCSI_FLAG_FINAL );
351 ISCSI_SET_LENGTHS ( data_out->lengths, 0, len );
352 data_out->lun = iscsi->lun;
353 data_out->itt = htonl ( iscsi->itt );
354 data_out->ttt = htonl ( iscsi->ttt );
355 data_out->expstatsn = htonl ( iscsi->statsn + 1 );
356 data_out->datasn = htonl ( datasn );
357 data_out->offset = htonl ( iscsi->transfer_offset + offset );
358 DBGC ( iscsi, "iSCSI %p start data out DataSN %#x len %#lx\n",
359 iscsi, datasn, len );
363 * Complete iSCSI data-out PDU transmission
365 * @v iscsi iSCSI session
368 static void iscsi_data_out_done ( struct iscsi_session *iscsi ) {
369 struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
371 /* If we haven't reached the end of the sequence, start
372 * sending the next data-out PDU.
374 if ( ! ( data_out->flags & ISCSI_FLAG_FINAL ) )
375 iscsi_start_data_out ( iscsi, ntohl ( data_out->datasn ) + 1 );
379 * Send iSCSI data-out data segment
381 * @v iscsi iSCSI session
382 * @ret rc Return status code
384 static int iscsi_tx_data_out ( struct iscsi_session *iscsi ) {
385 struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
386 struct io_buffer *iobuf;
387 unsigned long offset;
390 offset = ntohl ( data_out->offset );
391 len = ISCSI_DATA_LEN ( data_out->lengths );
393 assert ( iscsi->command != NULL );
394 assert ( iscsi->command->data_out );
395 assert ( ( offset + len ) <= iscsi->command->data_out_len );
397 iobuf = xfer_alloc_iob ( &iscsi->socket, len );
401 copy_from_user ( iob_put ( iobuf, len ),
402 iscsi->command->data_out, offset, len );
404 return xfer_deliver_iob ( &iscsi->socket, iobuf );
407 /****************************************************************************
414 * Build iSCSI login request strings
416 * @v iscsi iSCSI session
418 * These are the initial set of strings sent in the first login
419 * request PDU. We want the following settings:
423 * MaxConnections is irrelevant; we make only one connection anyway
425 * ImmediateData is irrelevant; we never send immediate data
426 * MaxRecvDataSegmentLength=8192 (default; we don't care) [3]
427 * MaxBurstLength=262144 (default; we don't care) [3]
428 * FirstBurstLength=262144 (default; we don't care)
429 * DefaultTime2Wait=0 [2]
430 * DefaultTime2Retain=0 [2]
431 * MaxOutstandingR2T=1
433 * DataSequenceInOrder=Yes
434 * ErrorRecoveryLevel=0
436 * [1] InitialR2T has an OR resolution function, so the target may
437 * force us to use it. We therefore simplify our logic by always
440 * [2] These ensure that we can safely start a new task once we have
441 * reconnected after a failure, without having to manually tidy up
444 * [3] We are quite happy to use the RFC-defined default values for
445 * these parameters, but some targets (notably OpenSolaris)
446 * incorrectly assume a default value of zero, so we explicitly
447 * specify the default values.
449 static int iscsi_build_login_request_strings ( struct iscsi_session *iscsi,
450 void *data, size_t len ) {
451 unsigned int used = 0;
454 if ( iscsi->status & ISCSI_STATUS_STRINGS_SECURITY ) {
455 used += ssnprintf ( data + used, len - used,
458 "SessionType=Normal%c"
459 "AuthMethod=CHAP,None%c",
460 iscsi_initiator_iqn(), 0,
461 iscsi->target_iqn, 0, 0, 0 );
464 if ( iscsi->status & ISCSI_STATUS_STRINGS_CHAP_ALGORITHM ) {
465 used += ssnprintf ( data + used, len - used, "CHAP_A=5%c", 0 );
468 if ( ( iscsi->status & ISCSI_STATUS_STRINGS_CHAP_RESPONSE ) &&
470 used += ssnprintf ( data + used, len - used,
471 "CHAP_N=%s%cCHAP_R=0x",
472 iscsi->username, 0 );
473 for ( i = 0 ; i < iscsi->chap.response_len ; i++ ) {
474 used += ssnprintf ( data + used, len - used, "%02x",
475 iscsi->chap.response[i] );
477 used += ssnprintf ( data + used, len - used, "%c", 0 );
480 if ( iscsi->status & ISCSI_STATUS_STRINGS_OPERATIONAL ) {
481 used += ssnprintf ( data + used, len - used,
482 "HeaderDigest=None%c"
485 "MaxRecvDataSegmentLength=8192%c"
486 "MaxBurstLength=262144%c"
487 "DefaultTime2Wait=0%c"
488 "DefaultTime2Retain=0%c"
489 "MaxOutstandingR2T=1%c"
490 "DataPDUInOrder=Yes%c"
491 "DataSequenceInOrder=Yes%c"
492 "ErrorRecoveryLevel=0%c",
493 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
500 * Build iSCSI login request BHS
502 * @v iscsi iSCSI session
504 static void iscsi_start_login ( struct iscsi_session *iscsi ) {
505 struct iscsi_bhs_login_request *request = &iscsi->tx_bhs.login_request;
508 /* Construct BHS and initiate transmission */
509 iscsi_start_tx ( iscsi );
510 request->opcode = ( ISCSI_OPCODE_LOGIN_REQUEST |
511 ISCSI_FLAG_IMMEDIATE );
512 request->flags = ( ( iscsi->status & ISCSI_STATUS_PHASE_MASK ) |
513 ISCSI_LOGIN_FLAG_TRANSITION );
514 /* version_max and version_min left as zero */
515 len = iscsi_build_login_request_strings ( iscsi, NULL, 0 );
516 ISCSI_SET_LENGTHS ( request->lengths, 0, len );
517 request->isid_iana_en = htonl ( ISCSI_ISID_IANA |
518 IANA_EN_FEN_SYSTEMS );
519 /* isid_iana_qual left as zero */
520 request->tsih = htons ( iscsi->tsih );
521 request->itt = htonl ( iscsi->itt );
522 /* cid left as zero */
523 request->cmdsn = htonl ( iscsi->cmdsn );
524 request->expstatsn = htonl ( iscsi->statsn + 1 );
528 * Complete iSCSI login request PDU transmission
530 * @v iscsi iSCSI session
533 static void iscsi_login_request_done ( struct iscsi_session *iscsi ) {
535 /* Clear any "strings to send" flags */
536 iscsi->status &= ~ISCSI_STATUS_STRINGS_MASK;
538 /* Free any dynamically allocated storage used for login */
539 chap_finish ( &iscsi->chap );
543 * Transmit data segment of an iSCSI login request PDU
545 * @v iscsi iSCSI session
546 * @ret rc Return status code
548 * For login requests, the data segment consists of the login strings.
550 static int iscsi_tx_login_request ( struct iscsi_session *iscsi ) {
551 struct iscsi_bhs_login_request *request = &iscsi->tx_bhs.login_request;
552 struct io_buffer *iobuf;
555 len = ISCSI_DATA_LEN ( request->lengths );
556 iobuf = xfer_alloc_iob ( &iscsi->socket, len );
559 iob_put ( iobuf, len );
560 iscsi_build_login_request_strings ( iscsi, iobuf->data, len );
561 return xfer_deliver_iob ( &iscsi->socket, iobuf );
565 * Handle iSCSI TargetAddress text value
567 * @v iscsi iSCSI session
568 * @v value TargetAddress value
569 * @ret rc Return status code
571 static int iscsi_handle_targetaddress_value ( struct iscsi_session *iscsi,
572 const char *value ) {
575 DBGC ( iscsi, "iSCSI %p will redirect to %s\n", iscsi, value );
577 /* Replace target address */
578 free ( iscsi->target_address );
579 iscsi->target_address = strdup ( value );
580 if ( ! iscsi->target_address )
583 /* Replace target port */
584 iscsi->target_port = htons ( ISCSI_PORT );
585 separator = strchr ( iscsi->target_address, ':' );
588 iscsi->target_port = strtoul ( ( separator + 1 ), NULL, 0 );
595 * Handle iSCSI AuthMethod text value
597 * @v iscsi iSCSI session
598 * @v value AuthMethod value
599 * @ret rc Return status code
601 static int iscsi_handle_authmethod_value ( struct iscsi_session *iscsi,
602 const char *value ) {
604 /* If server requests CHAP, send the CHAP_A string */
605 if ( strcmp ( value, "CHAP" ) == 0 ) {
606 DBGC ( iscsi, "iSCSI %p initiating CHAP authentication\n",
608 iscsi->status |= ISCSI_STATUS_STRINGS_CHAP_ALGORITHM;
614 * Handle iSCSI CHAP_A text value
616 * @v iscsi iSCSI session
617 * @v value CHAP_A value
618 * @ret rc Return status code
620 static int iscsi_handle_chap_a_value ( struct iscsi_session *iscsi,
621 const char *value ) {
624 /* We only ever offer "5" (i.e. MD5) as an algorithm, so if
625 * the server responds with anything else it is a protocol
628 if ( strcmp ( value, "5" ) != 0 ) {
629 DBGC ( iscsi, "iSCSI %p got invalid CHAP algorithm \"%s\"\n",
634 /* Prepare for CHAP with MD5 */
635 if ( ( rc = chap_init ( &iscsi->chap, &md5_algorithm ) ) != 0 ) {
636 DBGC ( iscsi, "iSCSI %p could not initialise CHAP: %s\n",
637 iscsi, strerror ( rc ) );
645 * Handle iSCSI CHAP_I text value
647 * @v iscsi iSCSI session
648 * @v value CHAP_I value
649 * @ret rc Return status code
651 static int iscsi_handle_chap_i_value ( struct iscsi_session *iscsi,
652 const char *value ) {
653 unsigned int identifier;
656 /* The CHAP identifier is an integer value */
657 identifier = strtoul ( value, &endp, 0 );
658 if ( *endp != '\0' ) {
659 DBGC ( iscsi, "iSCSI %p saw invalid CHAP identifier \"%s\"\n",
664 /* Identifier and secret are the first two components of the
667 chap_set_identifier ( &iscsi->chap, identifier );
668 if ( iscsi->password ) {
669 chap_update ( &iscsi->chap, iscsi->password,
670 strlen ( iscsi->password ) );
677 * Handle iSCSI CHAP_C text value
679 * @v iscsi iSCSI session
680 * @v value CHAP_C value
681 * @ret rc Return status code
683 static int iscsi_handle_chap_c_value ( struct iscsi_session *iscsi,
684 const char *value ) {
689 /* Check and strip leading "0x" */
690 if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
691 DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge \"%s\"\n",
696 /* Process challenge an octet at a time */
697 for ( ; ( value[0] && value[1] ) ; value += 2 ) {
698 memcpy ( buf, value, 2 );
700 byte = strtoul ( buf, &endp, 16 );
701 if ( *endp != '\0' ) {
702 DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge "
703 "byte \"%s\"\n", iscsi, buf );
706 chap_update ( &iscsi->chap, &byte, sizeof ( byte ) );
709 /* Build CHAP response */
710 DBGC ( iscsi, "iSCSI %p sending CHAP response\n", iscsi );
711 chap_respond ( &iscsi->chap );
712 iscsi->status |= ISCSI_STATUS_STRINGS_CHAP_RESPONSE;
717 /** An iSCSI text string that we want to handle */
718 struct iscsi_string_type {
721 * This is the portion up to and including the "=" sign,
722 * e.g. "InitiatorName=", "CHAP_A=", etc.
725 /** Handle iSCSI string value
727 * @v iscsi iSCSI session
728 * @v value iSCSI string value
729 * @ret rc Return status code
731 int ( * handle ) ( struct iscsi_session *iscsi, const char *value );
734 /** iSCSI text strings that we want to handle */
735 static struct iscsi_string_type iscsi_string_types[] = {
736 { "TargetAddress=", iscsi_handle_targetaddress_value },
737 { "AuthMethod=", iscsi_handle_authmethod_value },
738 { "CHAP_A=", iscsi_handle_chap_a_value },
739 { "CHAP_I=", iscsi_handle_chap_i_value },
740 { "CHAP_C=", iscsi_handle_chap_c_value },
745 * Handle iSCSI string
747 * @v iscsi iSCSI session
748 * @v string iSCSI string (in "key=value" format)
749 * @ret rc Return status code
751 static int iscsi_handle_string ( struct iscsi_session *iscsi,
752 const char *string ) {
753 struct iscsi_string_type *type;
757 for ( type = iscsi_string_types ; type->key ; type++ ) {
758 key_len = strlen ( type->key );
759 if ( strncmp ( string, type->key, key_len ) != 0 )
761 DBGC ( iscsi, "iSCSI %p handling %s\n", iscsi, string );
762 if ( ( rc = type->handle ( iscsi,
763 ( string + key_len ) ) ) != 0 ) {
764 DBGC ( iscsi, "iSCSI %p could not handle %s: %s\n",
765 iscsi, string, strerror ( rc ) );
770 DBGC ( iscsi, "iSCSI %p ignoring %s\n", iscsi, string );
775 * Handle iSCSI strings
777 * @v iscsi iSCSI session
778 * @v string iSCSI string buffer
779 * @v len Length of string buffer
780 * @ret rc Return status code
782 static int iscsi_handle_strings ( struct iscsi_session *iscsi,
783 const char *strings, size_t len ) {
787 /* Handle each string in turn, taking care not to overrun the
788 * data buffer in case of badly-terminated data.
791 string_len = ( strnlen ( strings, len ) + 1 );
792 if ( string_len > len )
794 if ( ( rc = iscsi_handle_string ( iscsi, strings ) ) != 0 )
796 strings += string_len;
803 * Receive PDU data into buffer
805 * @v iscsi iSCSI session
806 * @v data Data to receive
807 * @v len Length of data
808 * @ret rc Return status code
810 * This can be used when the RX PDU type handler wishes to buffer up
811 * all received data and process the PDU as a single unit. The caller
812 * is repsonsible for calling iscsi_rx_buffered_data_done() after
813 * processing the data.
815 static int iscsi_rx_buffered_data ( struct iscsi_session *iscsi,
816 const void *data, size_t len ) {
818 /* Allocate buffer on first call */
819 if ( ! iscsi->rx_buffer ) {
820 iscsi->rx_buffer = malloc ( iscsi->rx_len );
821 if ( ! iscsi->rx_buffer )
825 /* Copy data to buffer */
826 assert ( ( iscsi->rx_offset + len ) <= iscsi->rx_len );
827 memcpy ( ( iscsi->rx_buffer + iscsi->rx_offset ), data, len );
833 * Receive data segment of an iSCSI login response PDU
835 * @v iscsi iSCSI session
836 * @v data Received data
837 * @v len Length of received data
838 * @v remaining Data remaining after this data
839 * @ret rc Return status code
841 static int iscsi_rx_login_response ( struct iscsi_session *iscsi,
842 const void *data, size_t len,
844 struct iscsi_bhs_login_response *response
845 = &iscsi->rx_bhs.login_response;
848 /* Buffer up the PDU data */
849 if ( ( rc = iscsi_rx_buffered_data ( iscsi, data, len ) ) != 0 ) {
850 DBGC ( iscsi, "iSCSI %p could not buffer login response: %s\n",
851 iscsi, strerror ( rc ) );
857 /* Process string data and discard string buffer */
858 if ( ( rc = iscsi_handle_strings ( iscsi, iscsi->rx_buffer,
859 iscsi->rx_len ) ) != 0 )
861 iscsi_rx_buffered_data_done ( iscsi );
863 /* Check for login redirection */
864 if ( response->status_class == ISCSI_STATUS_REDIRECT ) {
865 DBGC ( iscsi, "iSCSI %p redirecting to new server\n", iscsi );
866 iscsi_close_connection ( iscsi, 0 );
867 if ( ( rc = iscsi_open_connection ( iscsi ) ) != 0 ) {
868 DBGC ( iscsi, "iSCSI %p could not redirect: %s\n ",
869 iscsi, strerror ( rc ) );
875 /* Check for fatal errors */
876 if ( response->status_class != 0 ) {
877 DBGC ( iscsi, "iSCSI login failure: class %02x detail %02x\n",
878 response->status_class, response->status_detail );
879 iscsi->instant_rc = -EPERM;
883 /* Handle login transitions */
884 if ( response->flags & ISCSI_LOGIN_FLAG_TRANSITION ) {
885 switch ( response->flags & ISCSI_LOGIN_NSG_MASK ) {
886 case ISCSI_LOGIN_NSG_OPERATIONAL_NEGOTIATION:
888 ( ISCSI_STATUS_OPERATIONAL_NEGOTIATION_PHASE |
889 ISCSI_STATUS_STRINGS_OPERATIONAL );
891 case ISCSI_LOGIN_NSG_FULL_FEATURE_PHASE:
892 iscsi->status = ISCSI_STATUS_FULL_FEATURE_PHASE;
895 DBGC ( iscsi, "iSCSI %p got invalid response flags "
896 "%02x\n", iscsi, response->flags );
901 /* Send next login request PDU if we haven't reached the full
904 if ( ( iscsi->status & ISCSI_STATUS_PHASE_MASK ) !=
905 ISCSI_STATUS_FULL_FEATURE_PHASE ) {
906 iscsi_start_login ( iscsi );
910 /* Reset retry count */
911 iscsi->retry_count = 0;
913 /* Record TSIH for future reference */
914 iscsi->tsih = ntohl ( response->tsih );
916 /* Send the actual SCSI command */
917 iscsi_start_command ( iscsi );
922 /****************************************************************************
924 * iSCSI to socket interface
929 * Start up a new TX PDU
931 * @v iscsi iSCSI session
933 * This initiates the process of sending a new PDU. Only one PDU may
934 * be in transit at any one time.
936 static void iscsi_start_tx ( struct iscsi_session *iscsi ) {
937 assert ( iscsi->tx_state == ISCSI_TX_IDLE );
939 /* Initialise TX BHS */
940 memset ( &iscsi->tx_bhs, 0, sizeof ( iscsi->tx_bhs ) );
942 /* Flag TX engine to start transmitting */
943 iscsi->tx_state = ISCSI_TX_BHS;
949 * @v iscsi iSCSI session
950 * @ret rc Return status code
952 static int iscsi_tx_nothing ( struct iscsi_session *iscsi __unused ) {
957 * Transmit basic header segment of an iSCSI PDU
959 * @v iscsi iSCSI session
960 * @ret rc Return status code
962 static int iscsi_tx_bhs ( struct iscsi_session *iscsi ) {
963 return xfer_deliver_raw ( &iscsi->socket, &iscsi->tx_bhs,
964 sizeof ( iscsi->tx_bhs ) );
968 * Transmit data segment of an iSCSI PDU
970 * @v iscsi iSCSI session
971 * @ret rc Return status code
973 * Handle transmission of part of a PDU data segment. iscsi::tx_bhs
974 * will be valid when this is called.
976 static int iscsi_tx_data ( struct iscsi_session *iscsi ) {
977 struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
979 switch ( common->opcode & ISCSI_OPCODE_MASK ) {
980 case ISCSI_OPCODE_DATA_OUT:
981 return iscsi_tx_data_out ( iscsi );
982 case ISCSI_OPCODE_LOGIN_REQUEST:
983 return iscsi_tx_login_request ( iscsi );
985 /* Nothing to send in other states */
991 * Transmit data padding of an iSCSI PDU
993 * @v iscsi iSCSI session
994 * @ret rc Return status code
996 * Handle transmission of any data padding in a PDU data segment.
997 * iscsi::tx_bhs will be valid when this is called.
999 static int iscsi_tx_data_padding ( struct iscsi_session *iscsi ) {
1000 static const char pad[] = { '\0', '\0', '\0' };
1001 struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
1004 pad_len = ISCSI_DATA_PAD_LEN ( common->lengths );
1008 return xfer_deliver_raw ( &iscsi->socket, pad, pad_len );
1012 * Complete iSCSI PDU transmission
1014 * @v iscsi iSCSI session
1016 * Called when a PDU has been completely transmitted and the TX state
1017 * machine is about to enter the idle state. iscsi::tx_bhs will be
1018 * valid for the just-completed PDU when this is called.
1020 static void iscsi_tx_done ( struct iscsi_session *iscsi ) {
1021 struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
1023 switch ( common->opcode & ISCSI_OPCODE_MASK ) {
1024 case ISCSI_OPCODE_DATA_OUT:
1025 iscsi_data_out_done ( iscsi );
1026 case ISCSI_OPCODE_LOGIN_REQUEST:
1027 iscsi_login_request_done ( iscsi );
1035 * Transmit iSCSI PDU
1037 * @v iscsi iSCSI session
1038 * @v buf Temporary data buffer
1039 * @v len Length of temporary data buffer
1041 * Constructs data to be sent for the current TX state
1043 static void iscsi_tx_step ( struct process *process ) {
1044 struct iscsi_session *iscsi =
1045 container_of ( process, struct iscsi_session, process );
1046 struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
1047 int ( * tx ) ( struct iscsi_session *iscsi );
1048 enum iscsi_tx_state next_state;
1052 /* Select fragment to transmit */
1054 switch ( iscsi->tx_state ) {
1056 /* Stop processing */
1060 tx_len = sizeof ( iscsi->tx_bhs );
1061 next_state = ISCSI_TX_AHS;
1064 tx = iscsi_tx_nothing;
1066 next_state = ISCSI_TX_DATA;
1070 tx_len = ISCSI_DATA_LEN ( common->lengths );
1071 next_state = ISCSI_TX_DATA_PADDING;
1073 case ISCSI_TX_DATA_PADDING:
1074 tx = iscsi_tx_data_padding;
1075 tx_len = ISCSI_DATA_PAD_LEN ( common->lengths );
1076 next_state = ISCSI_TX_IDLE;
1083 /* Check for window availability, if needed */
1084 if ( tx_len && ( xfer_window ( &iscsi->socket ) == 0 ) ) {
1085 /* Cannot transmit at this point; stop processing */
1090 if ( ( rc = tx ( iscsi ) ) != 0 ) {
1091 DBGC ( iscsi, "iSCSI %p could not transmit: %s\n",
1092 iscsi, strerror ( rc ) );
1096 /* Move to next state */
1097 iscsi->tx_state = next_state;
1098 if ( next_state == ISCSI_TX_IDLE )
1099 iscsi_tx_done ( iscsi );
1104 * Receive basic header segment of an iSCSI PDU
1106 * @v iscsi iSCSI session
1107 * @v data Received data
1108 * @v len Length of received data
1109 * @v remaining Data remaining after this data
1110 * @ret rc Return status code
1112 * This fills in iscsi::rx_bhs with the data from the BHS portion of
1115 static int iscsi_rx_bhs ( struct iscsi_session *iscsi, const void *data,
1116 size_t len, size_t remaining __unused ) {
1117 memcpy ( &iscsi->rx_bhs.bytes[iscsi->rx_offset], data, len );
1118 if ( ( iscsi->rx_offset + len ) >= sizeof ( iscsi->rx_bhs ) ) {
1119 DBGC ( iscsi, "iSCSI %p received PDU opcode %#x len %#lx\n",
1120 iscsi, iscsi->rx_bhs.common.opcode,
1121 ISCSI_DATA_LEN ( iscsi->rx_bhs.common.lengths ) );
1127 * Discard portion of an iSCSI PDU.
1129 * @v iscsi iSCSI session
1130 * @v data Received data
1131 * @v len Length of received data
1132 * @v remaining Data remaining after this data
1133 * @ret rc Return status code
1135 * This discards data from a portion of a received PDU.
1137 static int iscsi_rx_discard ( struct iscsi_session *iscsi __unused,
1138 const void *data __unused, size_t len __unused,
1139 size_t remaining __unused ) {
1145 * Receive data segment of an iSCSI PDU
1147 * @v iscsi iSCSI session
1148 * @v data Received data
1149 * @v len Length of received data
1150 * @v remaining Data remaining after this data
1151 * @ret rc Return status code
1153 * Handle processing of part of a PDU data segment. iscsi::rx_bhs
1154 * will be valid when this is called.
1156 static int iscsi_rx_data ( struct iscsi_session *iscsi, const void *data,
1157 size_t len, size_t remaining ) {
1158 struct iscsi_bhs_common_response *response
1159 = &iscsi->rx_bhs.common_response;
1161 /* Update cmdsn and statsn */
1162 iscsi->cmdsn = ntohl ( response->expcmdsn );
1163 iscsi->statsn = ntohl ( response->statsn );
1165 switch ( response->opcode & ISCSI_OPCODE_MASK ) {
1166 case ISCSI_OPCODE_LOGIN_RESPONSE:
1167 return iscsi_rx_login_response ( iscsi, data, len, remaining );
1168 case ISCSI_OPCODE_SCSI_RESPONSE:
1169 return iscsi_rx_scsi_response ( iscsi, data, len, remaining );
1170 case ISCSI_OPCODE_DATA_IN:
1171 return iscsi_rx_data_in ( iscsi, data, len, remaining );
1172 case ISCSI_OPCODE_R2T:
1173 return iscsi_rx_r2t ( iscsi, data, len, remaining );
1177 DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
1186 * @v socket Transport layer interface
1187 * @v data Received data
1188 * @v len Length of received data
1189 * @ret rc Return status code
1191 * This handles received PDUs. The receive strategy is to fill in
1192 * iscsi::rx_bhs with the contents of the BHS portion of the PDU,
1193 * throw away any AHS portion, and then process each part of the data
1194 * portion as it arrives. The data processing routine therefore
1195 * always has a full copy of the BHS available, even for portions of
1196 * the data in different packets to the BHS.
1198 static int iscsi_socket_deliver_raw ( struct xfer_interface *socket,
1199 const void *data, size_t len ) {
1200 struct iscsi_session *iscsi =
1201 container_of ( socket, struct iscsi_session, socket );
1202 struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
1203 int ( * rx ) ( struct iscsi_session *iscsi, const void *data,
1204 size_t len, size_t remaining );
1205 enum iscsi_rx_state next_state;
1211 switch ( iscsi->rx_state ) {
1214 iscsi->rx_len = sizeof ( iscsi->rx_bhs );
1215 next_state = ISCSI_RX_AHS;
1218 rx = iscsi_rx_discard;
1219 iscsi->rx_len = 4 * ISCSI_AHS_LEN ( common->lengths );
1220 next_state = ISCSI_RX_DATA;
1224 iscsi->rx_len = ISCSI_DATA_LEN ( common->lengths );
1225 next_state = ISCSI_RX_DATA_PADDING;
1227 case ISCSI_RX_DATA_PADDING:
1228 rx = iscsi_rx_discard;
1229 iscsi->rx_len = ISCSI_DATA_PAD_LEN ( common->lengths );
1230 next_state = ISCSI_RX_BHS;
1237 frag_len = iscsi->rx_len - iscsi->rx_offset;
1238 if ( frag_len > len )
1240 remaining = iscsi->rx_len - iscsi->rx_offset - frag_len;
1241 if ( ( rc = rx ( iscsi, data, frag_len, remaining ) ) != 0 ) {
1242 DBGC ( iscsi, "iSCSI %p could not process received "
1243 "data: %s\n", iscsi, strerror ( rc ) );
1244 iscsi_close_connection ( iscsi, rc );
1245 iscsi_scsi_done ( iscsi, rc );
1249 iscsi->rx_offset += frag_len;
1253 /* If all the data for this state has not yet been
1254 * received, stay in this state for now.
1256 if ( iscsi->rx_offset != iscsi->rx_len )
1259 iscsi->rx_state = next_state;
1260 iscsi->rx_offset = 0;
1267 * Handle stream connection closure
1269 * @v socket Transport layer interface
1270 * @v rc Reason for close
1273 static void iscsi_socket_close ( struct xfer_interface *socket, int rc ) {
1274 struct iscsi_session *iscsi =
1275 container_of ( socket, struct iscsi_session, socket );
1277 /* Even a graceful close counts as an error for iSCSI */
1281 /* Close session cleanly */
1282 iscsi_close_connection ( iscsi, rc );
1284 /* Retry connection if within the retry limit, otherwise fail */
1285 if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) {
1286 DBGC ( iscsi, "iSCSI %p retrying connection (retry #%d)\n",
1287 iscsi, iscsi->retry_count );
1288 if ( ( rc = iscsi_open_connection ( iscsi ) ) != 0 ) {
1289 DBGC ( iscsi, "iSCSI %p could not reconnect: %s\n",
1290 iscsi, strerror ( rc ) );
1291 iscsi_scsi_done ( iscsi, rc );
1294 DBGC ( iscsi, "iSCSI %p retry count exceeded\n", iscsi );
1295 iscsi->instant_rc = rc;
1296 iscsi_scsi_done ( iscsi, rc );
1301 * Handle redirection event
1303 * @v socket Transport layer interface
1304 * @v type Location type
1305 * @v args Remaining arguments depend upon location type
1306 * @ret rc Return status code
1308 static int iscsi_vredirect ( struct xfer_interface *socket, int type,
1310 struct iscsi_session *iscsi =
1311 container_of ( socket, struct iscsi_session, socket );
1313 struct sockaddr *peer;
1315 /* Intercept redirects to a LOCATION_SOCKET and record the IP
1316 * address for the iBFT. This is a bit of a hack, but avoids
1317 * inventing an ioctl()-style call to retrieve the socket
1318 * address from a data-xfer interface.
1320 if ( type == LOCATION_SOCKET ) {
1321 va_copy ( tmp, args );
1322 ( void ) va_arg ( tmp, int ); /* Discard "semantics" */
1323 peer = va_arg ( tmp, struct sockaddr * );
1324 memcpy ( &iscsi->target_sockaddr, peer,
1325 sizeof ( iscsi->target_sockaddr ) );
1329 return xfer_vopen ( socket, type, args );
1333 /** iSCSI socket operations */
1334 static struct xfer_interface_operations iscsi_socket_operations = {
1335 .close = iscsi_socket_close,
1336 .vredirect = iscsi_vredirect,
1337 .window = unlimited_xfer_window,
1338 .alloc_iob = default_xfer_alloc_iob,
1339 .deliver_iob = xfer_deliver_as_raw,
1340 .deliver_raw = iscsi_socket_deliver_raw,
1344 /****************************************************************************
1346 * iSCSI command issuing
1351 * Issue SCSI command
1353 * @v scsi SCSI device
1354 * @v command SCSI command
1355 * @ret rc Return status code
1357 static int iscsi_command ( struct scsi_device *scsi,
1358 struct scsi_command *command ) {
1359 struct iscsi_session *iscsi =
1360 container_of ( scsi->backend, struct iscsi_session, refcnt );
1363 /* Record SCSI command */
1364 iscsi->command = command;
1366 /* Abort immediately if we have a recorded permanent failure */
1367 if ( iscsi->instant_rc ) {
1368 rc = iscsi->instant_rc;
1372 /* Issue command or open connection as appropriate */
1373 if ( iscsi->status ) {
1374 iscsi_start_command ( iscsi );
1376 if ( ( rc = iscsi_open_connection ( iscsi ) ) != 0 )
1380 /* Wait for command to complete */
1381 iscsi->rc = -EINPROGRESS;
1382 while ( iscsi->rc == -EINPROGRESS )
1387 iscsi->command = NULL;
1391 static int iscsi_detached_command ( struct scsi_device *scsi __unused,
1392 struct scsi_command *command __unused ) {
1397 * Shut down iSCSI interface
1399 * @v scsi SCSI device
1401 void iscsi_detach ( struct scsi_device *scsi ) {
1402 struct iscsi_session *iscsi =
1403 container_of ( scsi->backend, struct iscsi_session, refcnt );
1405 xfer_nullify ( &iscsi->socket );
1406 iscsi_close_connection ( iscsi, 0 );
1407 process_del ( &iscsi->process );
1408 scsi->command = iscsi_detached_command;
1409 ref_put ( scsi->backend );
1410 scsi->backend = NULL;
1413 /****************************************************************************
1419 /** iSCSI root path components (as per RFC4173) */
1420 enum iscsi_root_path_component {
1433 * @v iscsi iSCSI session
1434 * @v lun_string LUN string representation (as per RFC4173)
1435 * @ret rc Return status code
1437 static int iscsi_parse_lun ( struct iscsi_session *iscsi,
1438 const char *lun_string ) {
1439 char *p = ( char * ) lun_string;
1446 /* Empty LUN; assume LUN 0 */
1447 if ( ! *lun_string )
1450 for ( i = 0 ; i < 4 ; i++ ) {
1451 lun.u16[i] = strtoul ( p, &p, 16 );
1459 iscsi->lun = lun.u64;
1464 * Parse iSCSI root path
1466 * @v iscsi iSCSI session
1467 * @v root_path iSCSI root path (as per RFC4173)
1468 * @ret rc Return status code
1470 static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
1471 const char *root_path ) {
1472 char rp_copy[ strlen ( root_path ) + 1 ];
1473 char *rp_comp[NUM_RP_COMPONENTS];
1478 /* Split root path into component parts */
1479 strcpy ( rp_copy, root_path );
1482 if ( i == NUM_RP_COMPONENTS )
1484 for ( ; *rp != ':' ; rp++ ) {
1486 DBGC ( iscsi, "iSCSI %p root path \"%s\" "
1487 "too short\n", iscsi, root_path );
1494 /* Use root path components to configure iSCSI session */
1495 iscsi->target_address = strdup ( rp_comp[RP_SERVERNAME] );
1496 if ( ! iscsi->target_address )
1498 iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
1499 if ( ! iscsi->target_port )
1500 iscsi->target_port = ISCSI_PORT;
1501 if ( ( rc = iscsi_parse_lun ( iscsi, rp_comp[RP_LUN] ) ) != 0 ) {
1502 DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
1503 iscsi, rp_comp[RP_LUN] );
1506 iscsi->target_iqn = strdup ( rp_comp[RP_TARGETNAME] );
1507 if ( ! iscsi->target_iqn )
1514 * Set iSCSI authentication details
1516 * @v iscsi iSCSI session
1517 * @v username Username, if any
1518 * @v password Password, if any
1519 * @ret rc Return status code
1521 static int iscsi_set_auth ( struct iscsi_session *iscsi,
1522 const char *username, const char *password ) {
1525 iscsi->username = strdup ( username );
1526 if ( ! iscsi->username )
1531 iscsi->password = strdup ( password );
1532 if ( ! iscsi->password )
1540 * Attach iSCSI interface
1542 * @v scsi SCSI device
1543 * @v root_path iSCSI root path (as per RFC4173)
1544 * @ret rc Return status code
1546 int iscsi_attach ( struct scsi_device *scsi, const char *root_path ) {
1547 struct iscsi_session *iscsi;
1550 /* Allocate and initialise structure */
1551 iscsi = zalloc ( sizeof ( *iscsi ) );
1554 iscsi->refcnt.free = iscsi_free;
1555 xfer_init ( &iscsi->socket, &iscsi_socket_operations, &iscsi->refcnt );
1556 process_init ( &iscsi->process, iscsi_tx_step, &iscsi->refcnt );
1558 /* Parse root path */
1559 if ( ( rc = iscsi_parse_root_path ( iscsi, root_path ) ) != 0 )
1561 /* Set fields not specified by root path */
1562 if ( ( rc = iscsi_set_auth ( iscsi, iscsi_username,
1563 iscsi_password ) ) != 0 )
1567 if ( ! iscsi->target_address ) {
1568 DBGC ( iscsi, "iSCSI %p does not yet support discovery\n",
1573 if ( ! iscsi->target_iqn ) {
1574 DBGC ( iscsi, "iSCSI %p no target address supplied in %s\n",
1580 /* Attach parent interface, mortalise self, and return */
1581 scsi->backend = ref_get ( &iscsi->refcnt );
1582 scsi->command = iscsi_command;
1583 scsi->lun = iscsi->lun;
1584 ref_put ( &iscsi->refcnt );
1588 ref_put ( &iscsi->refcnt );
1592 /****************************************************************************
1594 * DHCP option applicators
1599 * Apply DHCP iSCSI option
1601 * @v tag DHCP option tag
1602 * @v option DHCP option
1603 * @ret rc Return status code
1605 static int apply_dhcp_iscsi_string ( unsigned int tag,
1606 struct dhcp_option *option ) {
1613 /* Identify string and prefix */
1615 case DHCP_ISCSI_INITIATOR_IQN:
1616 string = &iscsi_explicit_initiator_iqn;
1618 case DHCP_EB_USERNAME:
1619 string = &iscsi_username;
1621 case DHCP_EB_PASSWORD:
1622 string = &iscsi_password;
1624 case DHCP_HOST_NAME:
1625 string = &iscsi_default_initiator_iqn;
1626 prefix = "iqn.2000-09.org.etherboot:";
1633 /* Free old string */
1637 /* Allocate and fill new string */
1638 prefix_len = strlen ( prefix );
1639 len = ( prefix_len + option->len + 1 );
1640 p = *string = malloc ( len );
1643 strcpy ( p, prefix );
1644 dhcp_snprintf ( ( p + prefix_len ), ( len - prefix_len ), option );
1648 /** DHCP iSCSI option applicators */
1649 struct dhcp_option_applicator dhcp_iscsi_applicators[] __dhcp_applicator = {
1651 .tag = DHCP_ISCSI_INITIATOR_IQN,
1652 .apply = apply_dhcp_iscsi_string,
1655 .tag = DHCP_EB_USERNAME,
1656 .apply = apply_dhcp_iscsi_string,
1659 .tag = DHCP_EB_PASSWORD,
1660 .apply = apply_dhcp_iscsi_string,
1663 .tag = DHCP_HOST_NAME,
1664 .apply = apply_dhcp_iscsi_string,
1668 /****************************************************************************
1675 * Get iSCSI initiator IQN
1677 * @v iscsi iSCSI session
1678 * @ret rc Return status code
1680 const char * iscsi_initiator_iqn ( void ) {
1682 if ( iscsi_explicit_initiator_iqn )
1683 return iscsi_explicit_initiator_iqn;
1684 if ( iscsi_default_initiator_iqn )
1685 return iscsi_default_initiator_iqn;
1686 return "iqn.2000-09.org.etherboot:UNKNOWN";