2006-05-15 01:29:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2006-05-13 13:39:46 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
2006-11-28 01:29:02 +01:00
|
|
|
#include <stdlib.h>
|
2007-01-19 02:13:12 +01:00
|
|
|
#include <stdio.h>
|
2006-05-13 13:39:46 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <byteswap.h>
|
2007-05-31 15:26:50 +02:00
|
|
|
#include <gpxe/vsprintf.h>
|
2007-07-08 17:04:13 +02:00
|
|
|
#include <gpxe/socket.h>
|
|
|
|
#include <gpxe/xfer.h>
|
|
|
|
#include <gpxe/open.h>
|
2006-05-13 13:39:46 +02:00
|
|
|
#include <gpxe/scsi.h>
|
|
|
|
#include <gpxe/process.h>
|
2006-05-19 17:06:51 +02:00
|
|
|
#include <gpxe/uaccess.h>
|
2007-07-08 17:04:13 +02:00
|
|
|
#include <gpxe/tcpip.h>
|
2008-03-21 00:15:48 +01:00
|
|
|
#include <gpxe/settings.h>
|
2007-08-02 05:24:39 +02:00
|
|
|
#include <gpxe/features.h>
|
2006-05-13 13:39:46 +02:00
|
|
|
#include <gpxe/iscsi.h>
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* iSCSI protocol
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-08-02 15:51:03 +02:00
|
|
|
FEATURE ( FEATURE_PROTOCOL, "iSCSI", DHCP_EB_FEATURE_ISCSI, 1 );
|
2007-08-02 05:24:39 +02:00
|
|
|
|
2007-07-08 19:51:56 +02:00
|
|
|
/** iSCSI initiator name (explicitly specified) */
|
2007-07-26 03:13:38 +02:00
|
|
|
static char *iscsi_explicit_initiator_iqn;
|
2007-07-08 19:51:56 +02:00
|
|
|
|
|
|
|
/** Default iSCSI initiator name (constructed from hostname) */
|
2007-07-26 03:13:38 +02:00
|
|
|
static char *iscsi_default_initiator_iqn;
|
2007-07-08 19:51:56 +02:00
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
/** iSCSI initiator username */
|
|
|
|
static char *iscsi_initiator_username;
|
2007-07-08 19:51:56 +02:00
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
/** iSCSI initiator password */
|
|
|
|
static char *iscsi_initiator_password;
|
|
|
|
|
|
|
|
/** iSCSI target username */
|
|
|
|
static char *iscsi_target_username;
|
|
|
|
|
|
|
|
/** iSCSI target password */
|
|
|
|
static char *iscsi_target_password;
|
2007-07-08 19:51:56 +02:00
|
|
|
|
2006-05-13 13:39:46 +02:00
|
|
|
static void iscsi_start_tx ( struct iscsi_session *iscsi );
|
2007-07-08 17:04:13 +02:00
|
|
|
static void iscsi_start_login ( struct iscsi_session *iscsi );
|
2006-05-19 02:20:08 +02:00
|
|
|
static void iscsi_start_data_out ( struct iscsi_session *iscsi,
|
|
|
|
unsigned int datasn );
|
2006-05-13 13:39:46 +02:00
|
|
|
|
2006-12-05 01:39:05 +01:00
|
|
|
/**
|
2007-07-08 17:04:13 +02:00
|
|
|
* Finish receiving PDU data into buffer
|
2006-12-05 01:39:05 +01:00
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static void iscsi_rx_buffered_data_done ( struct iscsi_session *iscsi ) {
|
|
|
|
free ( iscsi->rx_buffer );
|
|
|
|
iscsi->rx_buffer = NULL;
|
|
|
|
}
|
2006-12-05 01:39:05 +01:00
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
/**
|
|
|
|
* Free iSCSI session
|
|
|
|
*
|
|
|
|
* @v refcnt Reference counter
|
|
|
|
*/
|
|
|
|
static void iscsi_free ( struct refcnt *refcnt ) {
|
|
|
|
struct iscsi_session *iscsi =
|
|
|
|
container_of ( refcnt, struct iscsi_session, refcnt );
|
|
|
|
|
|
|
|
free ( iscsi->target_address );
|
|
|
|
free ( iscsi->target_iqn );
|
2008-08-11 04:12:38 +02:00
|
|
|
free ( iscsi->initiator_username );
|
|
|
|
free ( iscsi->initiator_password );
|
|
|
|
free ( iscsi->target_username );
|
|
|
|
free ( iscsi->target_password );
|
2007-07-08 17:04:13 +02:00
|
|
|
chap_finish ( &iscsi->chap );
|
|
|
|
iscsi_rx_buffered_data_done ( iscsi );
|
|
|
|
free ( iscsi );
|
2006-12-05 01:39:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-08 17:04:13 +02:00
|
|
|
* Open iSCSI transport-layer connection
|
2006-12-05 01:39:05 +01:00
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-12-05 01:39:05 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_open_connection ( struct iscsi_session *iscsi ) {
|
|
|
|
struct sockaddr_tcpip target;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
assert ( iscsi->tx_state == ISCSI_TX_IDLE );
|
|
|
|
assert ( iscsi->rx_state == ISCSI_RX_BHS );
|
|
|
|
assert ( iscsi->rx_offset == 0 );
|
|
|
|
|
|
|
|
/* Open socket */
|
|
|
|
memset ( &target, 0, sizeof ( target ) );
|
2007-07-08 19:51:56 +02:00
|
|
|
target.st_port = htons ( iscsi->target_port );
|
2007-07-08 17:04:13 +02:00
|
|
|
if ( ( rc = xfer_open_named_socket ( &iscsi->socket, SOCK_STREAM,
|
|
|
|
( struct sockaddr * ) &target,
|
|
|
|
iscsi->target_address,
|
|
|
|
NULL ) ) != 0 ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p could not open socket: %s\n",
|
|
|
|
iscsi, strerror ( rc ) );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enter security negotiation phase */
|
|
|
|
iscsi->status = ( ISCSI_STATUS_SECURITY_NEGOTIATION_PHASE |
|
|
|
|
ISCSI_STATUS_STRINGS_SECURITY );
|
|
|
|
|
|
|
|
/* Assign fresh initiator task tag */
|
|
|
|
iscsi->itt++;
|
|
|
|
|
|
|
|
/* Initiate login */
|
|
|
|
iscsi_start_login ( iscsi );
|
|
|
|
|
|
|
|
return 0;
|
2006-12-05 01:39:05 +01:00
|
|
|
}
|
|
|
|
|
2007-01-09 05:31:33 +01:00
|
|
|
/**
|
2007-07-08 17:04:13 +02:00
|
|
|
* Close iSCSI transport-layer connection
|
2007-01-09 05:31:33 +01:00
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2007-07-08 17:04:13 +02:00
|
|
|
* @v rc Reason for close
|
|
|
|
*
|
|
|
|
* Closes the transport-layer connection and resets the session state
|
|
|
|
* ready to attempt a fresh login.
|
2007-01-09 05:31:33 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static void iscsi_close_connection ( struct iscsi_session *iscsi, int rc ) {
|
2007-01-09 05:31:33 +01:00
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
/* Close all data transfer interfaces */
|
|
|
|
xfer_close ( &iscsi->socket, rc );
|
2007-01-09 05:31:33 +01:00
|
|
|
|
|
|
|
/* Clear connection status */
|
|
|
|
iscsi->status = 0;
|
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
/* Deauthenticate target */
|
|
|
|
iscsi->target_auth_ok = 0;
|
|
|
|
|
2007-01-09 05:31:33 +01:00
|
|
|
/* Reset TX and RX state machines */
|
|
|
|
iscsi->tx_state = ISCSI_TX_IDLE;
|
|
|
|
iscsi->rx_state = ISCSI_RX_BHS;
|
2007-07-10 07:31:11 +02:00
|
|
|
iscsi->rx_offset = 0;
|
2007-01-09 05:31:33 +01:00
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
/* Free any temporary dynamically allocated memory */
|
2007-01-09 05:31:33 +01:00
|
|
|
chap_finish ( &iscsi->chap );
|
|
|
|
iscsi_rx_buffered_data_done ( iscsi );
|
|
|
|
}
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
/**
|
2007-07-08 17:04:13 +02:00
|
|
|
* Mark iSCSI SCSI operation as complete
|
2006-11-28 01:29:02 +01:00
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v rc Return status code
|
|
|
|
*
|
2007-07-08 17:04:13 +02:00
|
|
|
* Note that iscsi_scsi_done() will not close the connection, and must
|
2006-11-28 01:29:02 +01:00
|
|
|
* therefore be called only when the internal state machines are in an
|
|
|
|
* appropriate state, otherwise bad things may happen on the next call
|
2007-07-08 17:04:13 +02:00
|
|
|
* to iscsi_issue(). The general rule is to call iscsi_scsi_done()
|
|
|
|
* only at the end of receiving a PDU; at this point the TX and RX
|
|
|
|
* engines should both be idle.
|
2006-11-28 01:29:02 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static void iscsi_scsi_done ( struct iscsi_session *iscsi, int rc ) {
|
2006-12-05 01:39:05 +01:00
|
|
|
|
2007-01-09 05:31:33 +01:00
|
|
|
assert ( iscsi->tx_state == ISCSI_TX_IDLE );
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
iscsi->command = NULL;
|
2007-07-08 20:33:26 +02:00
|
|
|
iscsi->rc = rc;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
2006-05-13 13:39:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* iSCSI SCSI command issuing
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build iSCSI SCSI command BHS
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-05-19 02:20:08 +02:00
|
|
|
*
|
|
|
|
* We don't currently support bidirectional commands (i.e. with both
|
|
|
|
* Data-In and Data-Out segments); these would require providing code
|
|
|
|
* to generate an AHS, and there doesn't seem to be any need for it at
|
|
|
|
* the moment.
|
2006-05-13 13:39:46 +02:00
|
|
|
*/
|
|
|
|
static void iscsi_start_command ( struct iscsi_session *iscsi ) {
|
|
|
|
struct iscsi_bhs_scsi_command *command = &iscsi->tx_bhs.scsi_command;
|
|
|
|
|
|
|
|
assert ( ! ( iscsi->command->data_in && iscsi->command->data_out ) );
|
|
|
|
|
|
|
|
/* Construct BHS and initiate transmission */
|
|
|
|
iscsi_start_tx ( iscsi );
|
|
|
|
command->opcode = ISCSI_OPCODE_SCSI_COMMAND;
|
|
|
|
command->flags = ( ISCSI_FLAG_FINAL |
|
|
|
|
ISCSI_COMMAND_ATTR_SIMPLE );
|
|
|
|
if ( iscsi->command->data_in )
|
|
|
|
command->flags |= ISCSI_COMMAND_FLAG_READ;
|
|
|
|
if ( iscsi->command->data_out )
|
|
|
|
command->flags |= ISCSI_COMMAND_FLAG_WRITE;
|
2006-05-19 02:20:08 +02:00
|
|
|
/* lengths left as zero */
|
2006-05-13 13:39:46 +02:00
|
|
|
command->lun = iscsi->lun;
|
2006-05-19 02:20:08 +02:00
|
|
|
command->itt = htonl ( ++iscsi->itt );
|
|
|
|
command->exp_len = htonl ( iscsi->command->data_in_len |
|
|
|
|
iscsi->command->data_out_len );
|
|
|
|
command->cmdsn = htonl ( iscsi->cmdsn );
|
|
|
|
command->expstatsn = htonl ( iscsi->statsn + 1 );
|
2006-05-13 13:39:46 +02:00
|
|
|
memcpy ( &command->cdb, &iscsi->command->cdb, sizeof ( command->cdb ));
|
2008-08-11 04:12:38 +02:00
|
|
|
DBGC2 ( iscsi, "iSCSI %p start " SCSI_CDB_FORMAT " %s %#zx\n",
|
|
|
|
iscsi, SCSI_CDB_DATA ( command->cdb ),
|
|
|
|
( iscsi->command->data_in ? "in" : "out" ),
|
|
|
|
( iscsi->command->data_in ?
|
|
|
|
iscsi->command->data_in_len :
|
|
|
|
iscsi->command->data_out_len ) );
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-05-19 02:20:08 +02:00
|
|
|
* Receive data segment of an iSCSI SCSI response PDU
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-05-19 02:20:08 +02:00
|
|
|
* @v data Received data
|
|
|
|
* @v len Length of received data
|
|
|
|
* @v remaining Data remaining after this data
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_rx_scsi_response ( struct iscsi_session *iscsi,
|
|
|
|
const void *data, size_t len,
|
|
|
|
size_t remaining ) {
|
2006-05-19 02:20:08 +02:00
|
|
|
struct iscsi_bhs_scsi_response *response
|
|
|
|
= &iscsi->rx_bhs.scsi_response;
|
|
|
|
int sense_offset;
|
|
|
|
|
|
|
|
/* Capture the sense response code as it floats past, if present */
|
|
|
|
sense_offset = ISCSI_SENSE_RESPONSE_CODE_OFFSET - iscsi->rx_offset;
|
|
|
|
if ( ( sense_offset >= 0 ) && len ) {
|
|
|
|
iscsi->command->sense_response =
|
|
|
|
* ( ( char * ) data + sense_offset );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for whole SCSI response to arrive */
|
|
|
|
if ( remaining )
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-05-19 02:20:08 +02:00
|
|
|
|
|
|
|
/* Record SCSI status code */
|
|
|
|
iscsi->command->status = response->status;
|
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
/* Check for errors */
|
|
|
|
if ( response->response != ISCSI_RESPONSE_COMMAND_COMPLETE )
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* Mark as completed */
|
|
|
|
iscsi_scsi_done ( iscsi, 0 );
|
|
|
|
return 0;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive data segment of an iSCSI data-in PDU
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v data Received data
|
|
|
|
* @v len Length of received data
|
|
|
|
* @v remaining Data remaining after this data
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_rx_data_in ( struct iscsi_session *iscsi,
|
|
|
|
const void *data, size_t len,
|
2008-02-07 23:46:26 +01:00
|
|
|
size_t remaining ) {
|
2006-05-13 13:39:46 +02:00
|
|
|
struct iscsi_bhs_data_in *data_in = &iscsi->rx_bhs.data_in;
|
|
|
|
unsigned long offset;
|
|
|
|
|
|
|
|
/* Copy data to data-in buffer */
|
|
|
|
offset = ntohl ( data_in->offset ) + iscsi->rx_offset;
|
|
|
|
assert ( iscsi->command != NULL );
|
2006-08-10 19:35:14 +02:00
|
|
|
assert ( iscsi->command->data_in );
|
2006-05-13 13:39:46 +02:00
|
|
|
assert ( ( offset + len ) <= iscsi->command->data_in_len );
|
2006-05-19 17:06:51 +02:00
|
|
|
copy_to_user ( iscsi->command->data_in, offset, data, len );
|
2006-05-13 13:39:46 +02:00
|
|
|
|
2008-02-07 23:46:26 +01:00
|
|
|
/* Wait for whole SCSI response to arrive */
|
|
|
|
if ( remaining )
|
|
|
|
return 0;
|
2006-05-19 02:20:08 +02:00
|
|
|
|
2008-02-07 23:46:26 +01:00
|
|
|
/* Mark as completed if status is present */
|
|
|
|
if ( data_in->flags & ISCSI_DATA_FLAG_STATUS ) {
|
|
|
|
assert ( ( offset + len ) == iscsi->command->data_in_len );
|
2006-05-19 02:20:08 +02:00
|
|
|
assert ( data_in->flags & ISCSI_FLAG_FINAL );
|
2008-02-07 23:46:26 +01:00
|
|
|
iscsi->command->status = data_in->status;
|
|
|
|
/* iSCSI cannot return an error status via a data-in */
|
2007-07-08 17:04:13 +02:00
|
|
|
iscsi_scsi_done ( iscsi, 0 );
|
2006-05-19 02:20:08 +02:00
|
|
|
}
|
2007-07-08 17:04:13 +02:00
|
|
|
|
|
|
|
return 0;
|
2006-05-19 02:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive data segment of an iSCSI R2T PDU
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v data Received data
|
|
|
|
* @v len Length of received data
|
|
|
|
* @v remaining Data remaining after this data
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-19 02:20:08 +02:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_rx_r2t ( struct iscsi_session *iscsi,
|
|
|
|
const void *data __unused, size_t len __unused,
|
|
|
|
size_t remaining __unused ) {
|
2006-05-19 02:20:08 +02:00
|
|
|
struct iscsi_bhs_r2t *r2t = &iscsi->rx_bhs.r2t;
|
|
|
|
|
|
|
|
/* Record transfer parameters and trigger first data-out */
|
|
|
|
iscsi->ttt = ntohl ( r2t->ttt );
|
|
|
|
iscsi->transfer_offset = ntohl ( r2t->offset );
|
|
|
|
iscsi->transfer_len = ntohl ( r2t->len );
|
|
|
|
iscsi_start_data_out ( iscsi, 0 );
|
2007-07-08 17:04:13 +02:00
|
|
|
|
|
|
|
return 0;
|
2006-05-19 02:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build iSCSI data-out BHS
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v datasn Data sequence number within the transfer
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void iscsi_start_data_out ( struct iscsi_session *iscsi,
|
|
|
|
unsigned int datasn ) {
|
|
|
|
struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
|
|
|
|
unsigned long offset;
|
|
|
|
unsigned long remaining;
|
|
|
|
unsigned long len;
|
|
|
|
|
|
|
|
/* We always send 512-byte Data-Out PDUs; this removes the
|
|
|
|
* need to worry about the target's MaxRecvDataSegmentLength.
|
|
|
|
*/
|
|
|
|
offset = datasn * 512;
|
|
|
|
remaining = iscsi->transfer_len - offset;
|
|
|
|
len = remaining;
|
|
|
|
if ( len > 512 )
|
|
|
|
len = 512;
|
|
|
|
|
|
|
|
/* Construct BHS and initiate transmission */
|
|
|
|
iscsi_start_tx ( iscsi );
|
|
|
|
data_out->opcode = ISCSI_OPCODE_DATA_OUT;
|
|
|
|
if ( len == remaining )
|
|
|
|
data_out->flags = ( ISCSI_FLAG_FINAL );
|
|
|
|
ISCSI_SET_LENGTHS ( data_out->lengths, 0, len );
|
|
|
|
data_out->lun = iscsi->lun;
|
|
|
|
data_out->itt = htonl ( iscsi->itt );
|
|
|
|
data_out->ttt = htonl ( iscsi->ttt );
|
|
|
|
data_out->expstatsn = htonl ( iscsi->statsn + 1 );
|
|
|
|
data_out->datasn = htonl ( datasn );
|
|
|
|
data_out->offset = htonl ( iscsi->transfer_offset + offset );
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p start data out DataSN %#x len %#lx\n",
|
|
|
|
iscsi, datasn, len );
|
2006-05-19 02:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Complete iSCSI data-out PDU transmission
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void iscsi_data_out_done ( struct iscsi_session *iscsi ) {
|
|
|
|
struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
|
|
|
|
|
|
|
|
/* If we haven't reached the end of the sequence, start
|
|
|
|
* sending the next data-out PDU.
|
|
|
|
*/
|
|
|
|
if ( ! ( data_out->flags & ISCSI_FLAG_FINAL ) )
|
|
|
|
iscsi_start_data_out ( iscsi, ntohl ( data_out->datasn ) + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send iSCSI data-out data segment
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-19 02:20:08 +02:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_tx_data_out ( struct iscsi_session *iscsi ) {
|
2006-05-19 02:20:08 +02:00
|
|
|
struct iscsi_bhs_data_out *data_out = &iscsi->tx_bhs.data_out;
|
2007-07-08 17:04:13 +02:00
|
|
|
struct io_buffer *iobuf;
|
2006-05-19 02:20:08 +02:00
|
|
|
unsigned long offset;
|
2007-07-08 17:04:13 +02:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
offset = ntohl ( data_out->offset );
|
|
|
|
len = ISCSI_DATA_LEN ( data_out->lengths );
|
2006-05-19 02:20:08 +02:00
|
|
|
|
|
|
|
assert ( iscsi->command != NULL );
|
2006-08-10 19:35:14 +02:00
|
|
|
assert ( iscsi->command->data_out );
|
2007-07-08 17:04:13 +02:00
|
|
|
assert ( ( offset + len ) <= iscsi->command->data_out_len );
|
|
|
|
|
|
|
|
iobuf = xfer_alloc_iob ( &iscsi->socket, len );
|
|
|
|
if ( ! iobuf )
|
|
|
|
return -ENOMEM;
|
2006-05-19 02:20:08 +02:00
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
copy_from_user ( iob_put ( iobuf, len ),
|
|
|
|
iscsi->command->data_out, offset, len );
|
2006-05-19 17:06:51 +02:00
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
return xfer_deliver_iob ( &iscsi->socket, iobuf );
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* iSCSI login
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build iSCSI login request strings
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
*
|
|
|
|
* These are the initial set of strings sent in the first login
|
2006-05-19 02:31:42 +02:00
|
|
|
* request PDU. We want the following settings:
|
|
|
|
*
|
|
|
|
* HeaderDigest=None
|
|
|
|
* DataDigest=None
|
|
|
|
* MaxConnections is irrelevant; we make only one connection anyway
|
2006-05-19 19:50:49 +02:00
|
|
|
* InitialR2T=Yes [1]
|
2006-05-19 02:31:42 +02:00
|
|
|
* ImmediateData is irrelevant; we never send immediate data
|
2007-11-05 14:29:05 +01:00
|
|
|
* MaxRecvDataSegmentLength=8192 (default; we don't care) [3]
|
|
|
|
* MaxBurstLength=262144 (default; we don't care) [3]
|
2006-05-19 19:50:49 +02:00
|
|
|
* FirstBurstLength=262144 (default; we don't care)
|
2006-05-19 02:31:42 +02:00
|
|
|
* DefaultTime2Wait=0 [2]
|
|
|
|
* DefaultTime2Retain=0 [2]
|
2006-05-19 19:50:49 +02:00
|
|
|
* MaxOutstandingR2T=1
|
|
|
|
* DataPDUInOrder=Yes
|
|
|
|
* DataSequenceInOrder=Yes
|
|
|
|
* ErrorRecoveryLevel=0
|
2006-05-19 02:31:42 +02:00
|
|
|
*
|
|
|
|
* [1] InitialR2T has an OR resolution function, so the target may
|
|
|
|
* force us to use it. We therefore simplify our logic by always
|
|
|
|
* using it.
|
|
|
|
*
|
|
|
|
* [2] These ensure that we can safely start a new task once we have
|
|
|
|
* reconnected after a failure, without having to manually tidy up
|
|
|
|
* after the old one.
|
2007-11-05 14:29:05 +01:00
|
|
|
*
|
|
|
|
* [3] We are quite happy to use the RFC-defined default values for
|
|
|
|
* these parameters, but some targets (notably OpenSolaris)
|
|
|
|
* incorrectly assume a default value of zero, so we explicitly
|
|
|
|
* specify the default values.
|
2006-05-13 13:39:46 +02:00
|
|
|
*/
|
|
|
|
static int iscsi_build_login_request_strings ( struct iscsi_session *iscsi,
|
|
|
|
void *data, size_t len ) {
|
2006-11-28 01:29:02 +01:00
|
|
|
unsigned int used = 0;
|
|
|
|
unsigned int i;
|
2008-08-11 04:12:38 +02:00
|
|
|
const char *auth_method;
|
2006-11-28 01:29:02 +01:00
|
|
|
|
|
|
|
if ( iscsi->status & ISCSI_STATUS_STRINGS_SECURITY ) {
|
2008-08-11 04:12:38 +02:00
|
|
|
/* Default to allowing no authentication */
|
|
|
|
auth_method = "None";
|
|
|
|
/* If we have a credential to supply, permit CHAP */
|
|
|
|
if ( iscsi->initiator_username )
|
|
|
|
auth_method = "CHAP,None";
|
|
|
|
/* If we have a credential to check, force CHAP */
|
|
|
|
if ( iscsi->target_username )
|
|
|
|
auth_method = "CHAP";
|
2006-11-28 01:29:02 +01:00
|
|
|
used += ssnprintf ( data + used, len - used,
|
|
|
|
"InitiatorName=%s%c"
|
|
|
|
"TargetName=%s%c"
|
|
|
|
"SessionType=Normal%c"
|
2008-08-11 04:12:38 +02:00
|
|
|
"AuthMethod=%s%c",
|
2007-07-26 03:13:38 +02:00
|
|
|
iscsi_initiator_iqn(), 0,
|
2008-04-24 14:48:29 +02:00
|
|
|
iscsi->target_iqn, 0, 0,
|
2008-08-11 04:12:38 +02:00
|
|
|
auth_method, 0 );
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
2006-10-03 11:17:38 +02:00
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
if ( iscsi->status & ISCSI_STATUS_STRINGS_CHAP_ALGORITHM ) {
|
|
|
|
used += ssnprintf ( data + used, len - used, "CHAP_A=5%c", 0 );
|
|
|
|
}
|
|
|
|
|
2008-04-24 14:48:29 +02:00
|
|
|
if ( ( iscsi->status & ISCSI_STATUS_STRINGS_CHAP_RESPONSE ) ) {
|
2008-08-11 04:12:38 +02:00
|
|
|
assert ( iscsi->initiator_username != NULL );
|
2006-11-28 01:29:02 +01:00
|
|
|
used += ssnprintf ( data + used, len - used,
|
|
|
|
"CHAP_N=%s%cCHAP_R=0x",
|
2008-08-11 04:12:38 +02:00
|
|
|
iscsi->initiator_username, 0 );
|
2006-11-28 01:29:02 +01:00
|
|
|
for ( i = 0 ; i < iscsi->chap.response_len ; i++ ) {
|
|
|
|
used += ssnprintf ( data + used, len - used, "%02x",
|
|
|
|
iscsi->chap.response[i] );
|
|
|
|
}
|
|
|
|
used += ssnprintf ( data + used, len - used, "%c", 0 );
|
|
|
|
}
|
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
if ( ( iscsi->status & ISCSI_STATUS_STRINGS_CHAP_CHALLENGE ) ) {
|
|
|
|
used += ssnprintf ( data + used, len - used,
|
|
|
|
"CHAP_I=%d%cCHAP_C=0x",
|
|
|
|
iscsi->chap_challenge[0], 0 );
|
|
|
|
for ( i = 1 ; i < sizeof ( iscsi->chap_challenge ) ; i++ ) {
|
|
|
|
used += ssnprintf ( data + used, len - used, "%02x",
|
|
|
|
iscsi->chap_challenge[i] );
|
|
|
|
}
|
|
|
|
used += ssnprintf ( data + used, len - used, "%c", 0 );
|
|
|
|
}
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
if ( iscsi->status & ISCSI_STATUS_STRINGS_OPERATIONAL ) {
|
|
|
|
used += ssnprintf ( data + used, len - used,
|
|
|
|
"HeaderDigest=None%c"
|
|
|
|
"DataDigest=None%c"
|
|
|
|
"InitialR2T=Yes%c"
|
2007-11-05 14:29:05 +01:00
|
|
|
"MaxRecvDataSegmentLength=8192%c"
|
|
|
|
"MaxBurstLength=262144%c"
|
2006-11-28 01:29:02 +01:00
|
|
|
"DefaultTime2Wait=0%c"
|
|
|
|
"DefaultTime2Retain=0%c"
|
|
|
|
"MaxOutstandingR2T=1%c"
|
|
|
|
"DataPDUInOrder=Yes%c"
|
|
|
|
"DataSequenceInOrder=Yes%c"
|
|
|
|
"ErrorRecoveryLevel=0%c",
|
2007-11-05 14:29:05 +01:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
|
2006-10-03 11:17:38 +02:00
|
|
|
}
|
2006-11-28 01:29:02 +01:00
|
|
|
|
|
|
|
return used;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build iSCSI login request BHS
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
*/
|
2006-11-28 01:29:02 +01:00
|
|
|
static void iscsi_start_login ( struct iscsi_session *iscsi ) {
|
2006-05-13 13:39:46 +02:00
|
|
|
struct iscsi_bhs_login_request *request = &iscsi->tx_bhs.login_request;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* Construct BHS and initiate transmission */
|
|
|
|
iscsi_start_tx ( iscsi );
|
|
|
|
request->opcode = ( ISCSI_OPCODE_LOGIN_REQUEST |
|
|
|
|
ISCSI_FLAG_IMMEDIATE );
|
2006-11-28 01:29:02 +01:00
|
|
|
request->flags = ( ( iscsi->status & ISCSI_STATUS_PHASE_MASK ) |
|
|
|
|
ISCSI_LOGIN_FLAG_TRANSITION );
|
2006-05-13 13:39:46 +02:00
|
|
|
/* version_max and version_min left as zero */
|
2006-11-28 01:29:02 +01:00
|
|
|
len = iscsi_build_login_request_strings ( iscsi, NULL, 0 );
|
|
|
|
ISCSI_SET_LENGTHS ( request->lengths, 0, len );
|
2006-05-13 13:39:46 +02:00
|
|
|
request->isid_iana_en = htonl ( ISCSI_ISID_IANA |
|
|
|
|
IANA_EN_FEN_SYSTEMS );
|
|
|
|
/* isid_iana_qual left as zero */
|
|
|
|
request->tsih = htons ( iscsi->tsih );
|
2006-05-19 02:20:08 +02:00
|
|
|
request->itt = htonl ( iscsi->itt );
|
2006-05-13 13:39:46 +02:00
|
|
|
/* cid left as zero */
|
2006-05-19 02:20:08 +02:00
|
|
|
request->cmdsn = htonl ( iscsi->cmdsn );
|
|
|
|
request->expstatsn = htonl ( iscsi->statsn + 1 );
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
/**
|
|
|
|
* Complete iSCSI login request PDU transmission
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void iscsi_login_request_done ( struct iscsi_session *iscsi ) {
|
|
|
|
|
|
|
|
/* Clear any "strings to send" flags */
|
|
|
|
iscsi->status &= ~ISCSI_STATUS_STRINGS_MASK;
|
2007-01-09 05:31:33 +01:00
|
|
|
|
|
|
|
/* Free any dynamically allocated storage used for login */
|
|
|
|
chap_finish ( &iscsi->chap );
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
2006-05-13 13:39:46 +02:00
|
|
|
/**
|
|
|
|
* Transmit data segment of an iSCSI login request PDU
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
* For login requests, the data segment consists of the login strings.
|
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_tx_login_request ( struct iscsi_session *iscsi ) {
|
|
|
|
struct iscsi_bhs_login_request *request = &iscsi->tx_bhs.login_request;
|
|
|
|
struct io_buffer *iobuf;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = ISCSI_DATA_LEN ( request->lengths );
|
|
|
|
iobuf = xfer_alloc_iob ( &iscsi->socket, len );
|
|
|
|
if ( ! iobuf )
|
|
|
|
return -ENOMEM;
|
|
|
|
iob_put ( iobuf, len );
|
|
|
|
iscsi_build_login_request_strings ( iscsi, iobuf->data, len );
|
|
|
|
return xfer_deliver_iob ( &iscsi->socket, iobuf );
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
2006-12-05 02:41:32 +01:00
|
|
|
/**
|
|
|
|
* Handle iSCSI TargetAddress text value
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v value TargetAddress value
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-12-05 02:41:32 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_handle_targetaddress_value ( struct iscsi_session *iscsi,
|
|
|
|
const char *value ) {
|
2008-02-07 23:46:26 +01:00
|
|
|
char *separator;
|
2006-12-05 02:41:32 +01:00
|
|
|
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p will redirect to %s\n", iscsi, value );
|
2007-07-08 17:04:13 +02:00
|
|
|
|
|
|
|
/* Replace target address */
|
|
|
|
free ( iscsi->target_address );
|
|
|
|
iscsi->target_address = strdup ( value );
|
|
|
|
if ( ! iscsi->target_address )
|
|
|
|
return -ENOMEM;
|
2008-02-07 23:46:26 +01:00
|
|
|
|
|
|
|
/* Replace target port */
|
|
|
|
iscsi->target_port = htons ( ISCSI_PORT );
|
|
|
|
separator = strchr ( iscsi->target_address, ':' );
|
|
|
|
if ( separator ) {
|
|
|
|
*separator = '\0';
|
|
|
|
iscsi->target_port = strtoul ( ( separator + 1 ), NULL, 0 );
|
|
|
|
}
|
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-12-05 02:41:32 +01:00
|
|
|
}
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
/**
|
|
|
|
* Handle iSCSI AuthMethod text value
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-12-05 02:08:56 +01:00
|
|
|
* @v value AuthMethod value
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-11-28 01:29:02 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_handle_authmethod_value ( struct iscsi_session *iscsi,
|
|
|
|
const char *value ) {
|
2006-11-28 01:29:02 +01:00
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
/* Mark target as authenticated if no authentication required */
|
|
|
|
if ( ! iscsi->target_username )
|
|
|
|
iscsi->target_auth_ok = 1;
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
/* If server requests CHAP, send the CHAP_A string */
|
2006-12-05 02:08:56 +01:00
|
|
|
if ( strcmp ( value, "CHAP" ) == 0 ) {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p initiating CHAP authentication\n",
|
|
|
|
iscsi );
|
2006-11-28 01:29:02 +01:00
|
|
|
iscsi->status |= ISCSI_STATUS_STRINGS_CHAP_ALGORITHM;
|
|
|
|
}
|
2008-08-11 04:12:38 +02:00
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle iSCSI CHAP_A text value
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-12-05 02:08:56 +01:00
|
|
|
* @v value CHAP_A value
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-11-28 01:29:02 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_handle_chap_a_value ( struct iscsi_session *iscsi,
|
|
|
|
const char *value ) {
|
2006-11-28 01:29:02 +01:00
|
|
|
|
|
|
|
/* We only ever offer "5" (i.e. MD5) as an algorithm, so if
|
|
|
|
* the server responds with anything else it is a protocol
|
|
|
|
* violation.
|
|
|
|
*/
|
2006-12-05 02:08:56 +01:00
|
|
|
if ( strcmp ( value, "5" ) != 0 ) {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p got invalid CHAP algorithm \"%s\"\n",
|
|
|
|
iscsi, value );
|
2007-07-08 17:04:13 +02:00
|
|
|
return -EPROTO;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle iSCSI CHAP_I text value
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-12-05 02:08:56 +01:00
|
|
|
* @v value CHAP_I value
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-11-28 01:29:02 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_handle_chap_i_value ( struct iscsi_session *iscsi,
|
|
|
|
const char *value ) {
|
2006-11-28 01:29:02 +01:00
|
|
|
unsigned int identifier;
|
|
|
|
char *endp;
|
2008-08-11 04:12:38 +02:00
|
|
|
int rc;
|
2006-11-28 01:29:02 +01:00
|
|
|
|
|
|
|
/* The CHAP identifier is an integer value */
|
2006-12-05 02:08:56 +01:00
|
|
|
identifier = strtoul ( value, &endp, 0 );
|
2006-11-28 01:29:02 +01:00
|
|
|
if ( *endp != '\0' ) {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p saw invalid CHAP identifier \"%s\"\n",
|
|
|
|
iscsi, value );
|
2007-07-08 17:04:13 +02:00
|
|
|
return -EPROTO;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
/* Prepare for CHAP with MD5 */
|
|
|
|
chap_finish ( &iscsi->chap );
|
|
|
|
if ( ( rc = chap_init ( &iscsi->chap, &md5_algorithm ) ) != 0 ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p could not initialise CHAP: %s\n",
|
|
|
|
iscsi, strerror ( rc ) );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
/* Identifier and secret are the first two components of the
|
|
|
|
* challenge.
|
|
|
|
*/
|
|
|
|
chap_set_identifier ( &iscsi->chap, identifier );
|
2008-08-11 04:12:38 +02:00
|
|
|
if ( iscsi->initiator_password ) {
|
|
|
|
chap_update ( &iscsi->chap, iscsi->initiator_password,
|
|
|
|
strlen ( iscsi->initiator_password ) );
|
2006-12-21 19:38:24 +01:00
|
|
|
}
|
2007-07-08 17:04:13 +02:00
|
|
|
|
|
|
|
return 0;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle iSCSI CHAP_C text value
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-12-05 02:08:56 +01:00
|
|
|
* @v value CHAP_C value
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-11-28 01:29:02 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_handle_chap_c_value ( struct iscsi_session *iscsi,
|
|
|
|
const char *value ) {
|
2006-12-05 02:08:56 +01:00
|
|
|
char buf[3];
|
2006-11-28 01:29:02 +01:00
|
|
|
char *endp;
|
2006-12-05 02:08:56 +01:00
|
|
|
uint8_t byte;
|
2008-08-11 04:12:38 +02:00
|
|
|
unsigned int i;
|
2006-11-28 01:29:02 +01:00
|
|
|
|
2006-12-05 02:08:56 +01:00
|
|
|
/* Check and strip leading "0x" */
|
|
|
|
if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge \"%s\"\n",
|
|
|
|
iscsi, value );
|
2008-08-11 04:12:38 +02:00
|
|
|
return -EPROTO;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
2006-12-05 02:08:56 +01:00
|
|
|
value += 2;
|
|
|
|
|
|
|
|
/* Process challenge an octet at a time */
|
|
|
|
for ( ; ( value[0] && value[1] ) ; value += 2 ) {
|
|
|
|
memcpy ( buf, value, 2 );
|
2008-01-07 14:12:43 +01:00
|
|
|
buf[2] = 0;
|
2006-12-05 02:08:56 +01:00
|
|
|
byte = strtoul ( buf, &endp, 16 );
|
|
|
|
if ( *endp != '\0' ) {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge "
|
|
|
|
"byte \"%s\"\n", iscsi, buf );
|
2007-07-08 17:04:13 +02:00
|
|
|
return -EPROTO;
|
2006-12-05 02:08:56 +01:00
|
|
|
}
|
|
|
|
chap_update ( &iscsi->chap, &byte, sizeof ( byte ) );
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
2006-12-05 02:08:56 +01:00
|
|
|
/* Build CHAP response */
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p sending CHAP response\n", iscsi );
|
2006-12-05 02:08:56 +01:00
|
|
|
chap_respond ( &iscsi->chap );
|
|
|
|
iscsi->status |= ISCSI_STATUS_STRINGS_CHAP_RESPONSE;
|
2007-07-08 17:04:13 +02:00
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
/* Send CHAP challenge, if applicable */
|
|
|
|
if ( iscsi->target_username ) {
|
|
|
|
iscsi->status |= ISCSI_STATUS_STRINGS_CHAP_CHALLENGE;
|
|
|
|
/* Generate CHAP challenge data */
|
|
|
|
for ( i = 0 ; i < sizeof ( iscsi->chap_challenge ) ; i++ ) {
|
|
|
|
iscsi->chap_challenge[i] = random();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle iSCSI CHAP_N text value
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v value CHAP_N value
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int iscsi_handle_chap_n_value ( struct iscsi_session *iscsi,
|
|
|
|
const char *value ) {
|
|
|
|
|
|
|
|
/* The target username isn't actually involved at any point in
|
|
|
|
* the authentication process; it merely serves to identify
|
|
|
|
* which password the target is using to generate the CHAP
|
|
|
|
* response. We unnecessarily verify that the username is as
|
|
|
|
* expected, in order to provide mildly helpful diagnostics if
|
|
|
|
* the target is supplying the wrong username/password
|
|
|
|
* combination.
|
|
|
|
*/
|
|
|
|
if ( iscsi->target_username &&
|
|
|
|
( strcmp ( iscsi->target_username, value ) != 0 ) ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p target username \"%s\" incorrect "
|
|
|
|
"(wanted \"%s\")\n",
|
|
|
|
iscsi, value, iscsi->target_username );
|
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle iSCSI CHAP_R text value
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v value CHAP_R value
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
|
|
|
|
const char *value ) {
|
|
|
|
char buf[3];
|
|
|
|
char *endp;
|
|
|
|
uint8_t byte;
|
|
|
|
unsigned int i;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Generate CHAP response for verification */
|
|
|
|
chap_finish ( &iscsi->chap );
|
|
|
|
if ( ( rc = chap_init ( &iscsi->chap, &md5_algorithm ) ) != 0 ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p could not initialise CHAP: %s\n",
|
|
|
|
iscsi, strerror ( rc ) );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
chap_set_identifier ( &iscsi->chap, iscsi->chap_challenge[0] );
|
|
|
|
if ( iscsi->target_password ) {
|
|
|
|
chap_update ( &iscsi->chap, iscsi->target_password,
|
|
|
|
strlen ( iscsi->target_password ) );
|
|
|
|
}
|
|
|
|
chap_update ( &iscsi->chap, &iscsi->chap_challenge[1],
|
|
|
|
( sizeof ( iscsi->chap_challenge ) - 1 ) );
|
|
|
|
chap_respond ( &iscsi->chap );
|
|
|
|
|
|
|
|
/* Check and strip leading "0x" */
|
|
|
|
if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p saw invalid CHAP response \"%s\"\n",
|
|
|
|
iscsi, value );
|
|
|
|
return -EPROTO;
|
|
|
|
}
|
|
|
|
value += 2;
|
|
|
|
|
|
|
|
/* Check CHAP response length */
|
|
|
|
if ( strlen ( value ) != ( 2 * iscsi->chap.response_len ) ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p invalid CHAP response length\n",
|
|
|
|
iscsi );
|
|
|
|
return -EPROTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process response an octet at a time */
|
|
|
|
for ( i = 0 ; ( value[0] && value[1] ) ; value += 2, i++ ) {
|
|
|
|
memcpy ( buf, value, 2 );
|
|
|
|
buf[2] = 0;
|
|
|
|
byte = strtoul ( buf, &endp, 16 );
|
|
|
|
if ( *endp != '\0' ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p saw invalid CHAP response "
|
|
|
|
"byte \"%s\"\n", iscsi, buf );
|
|
|
|
return -EPROTO;
|
|
|
|
}
|
|
|
|
if ( byte != iscsi->chap.response[i] ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p saw incorrect CHAP "
|
|
|
|
"response\n", iscsi );
|
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert ( i == iscsi->chap.response_len );
|
|
|
|
|
|
|
|
/* Mark session as authenticated */
|
|
|
|
iscsi->target_auth_ok = 1;
|
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** An iSCSI text string that we want to handle */
|
|
|
|
struct iscsi_string_type {
|
2006-12-05 02:08:56 +01:00
|
|
|
/** String key
|
2006-11-28 01:29:02 +01:00
|
|
|
*
|
2006-12-05 02:08:56 +01:00
|
|
|
* This is the portion up to and including the "=" sign,
|
|
|
|
* e.g. "InitiatorName=", "CHAP_A=", etc.
|
2006-11-28 01:29:02 +01:00
|
|
|
*/
|
2006-12-05 02:08:56 +01:00
|
|
|
const char *key;
|
2006-11-28 01:29:02 +01:00
|
|
|
/** Handle iSCSI string value
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-12-05 02:08:56 +01:00
|
|
|
* @v value iSCSI string value
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-11-28 01:29:02 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
int ( * handle ) ( struct iscsi_session *iscsi, const char *value );
|
2006-11-28 01:29:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** iSCSI text strings that we want to handle */
|
2007-07-09 02:04:54 +02:00
|
|
|
static struct iscsi_string_type iscsi_string_types[] = {
|
2006-12-05 02:41:32 +01:00
|
|
|
{ "TargetAddress=", iscsi_handle_targetaddress_value },
|
2006-12-05 02:08:56 +01:00
|
|
|
{ "AuthMethod=", iscsi_handle_authmethod_value },
|
|
|
|
{ "CHAP_A=", iscsi_handle_chap_a_value },
|
|
|
|
{ "CHAP_I=", iscsi_handle_chap_i_value },
|
|
|
|
{ "CHAP_C=", iscsi_handle_chap_c_value },
|
2008-08-11 04:12:38 +02:00
|
|
|
{ "CHAP_N=", iscsi_handle_chap_n_value },
|
|
|
|
{ "CHAP_R=", iscsi_handle_chap_r_value },
|
2006-11-28 01:29:02 +01:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2006-12-05 02:08:56 +01:00
|
|
|
* Handle iSCSI string
|
2006-11-28 01:29:02 +01:00
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-12-05 02:08:56 +01:00
|
|
|
* @v string iSCSI string (in "key=value" format)
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-11-28 01:29:02 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_handle_string ( struct iscsi_session *iscsi,
|
|
|
|
const char *string ) {
|
2006-12-05 02:08:56 +01:00
|
|
|
struct iscsi_string_type *type;
|
|
|
|
size_t key_len;
|
2007-07-08 17:04:13 +02:00
|
|
|
int rc;
|
2006-12-05 02:08:56 +01:00
|
|
|
|
|
|
|
for ( type = iscsi_string_types ; type->key ; type++ ) {
|
|
|
|
key_len = strlen ( type->key );
|
2007-07-08 17:04:13 +02:00
|
|
|
if ( strncmp ( string, type->key, key_len ) != 0 )
|
|
|
|
continue;
|
|
|
|
DBGC ( iscsi, "iSCSI %p handling %s\n", iscsi, string );
|
|
|
|
if ( ( rc = type->handle ( iscsi,
|
|
|
|
( string + key_len ) ) ) != 0 ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p could not handle %s: %s\n",
|
|
|
|
iscsi, string, strerror ( rc ) );
|
|
|
|
return rc;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p ignoring %s\n", iscsi, string );
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-12-05 02:08:56 +01:00
|
|
|
* Handle iSCSI strings
|
2006-11-28 01:29:02 +01:00
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-12-05 02:08:56 +01:00
|
|
|
* @v string iSCSI string buffer
|
|
|
|
* @v len Length of string buffer
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-11-28 01:29:02 +01:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_handle_strings ( struct iscsi_session *iscsi,
|
|
|
|
const char *strings, size_t len ) {
|
2006-12-05 02:08:56 +01:00
|
|
|
size_t string_len;
|
2007-07-08 17:04:13 +02:00
|
|
|
int rc;
|
2006-12-05 02:08:56 +01:00
|
|
|
|
|
|
|
/* Handle each string in turn, taking care not to overrun the
|
|
|
|
* data buffer in case of badly-terminated data.
|
|
|
|
*/
|
|
|
|
while ( 1 ) {
|
|
|
|
string_len = ( strnlen ( strings, len ) + 1 );
|
|
|
|
if ( string_len > len )
|
|
|
|
break;
|
2007-07-08 17:04:13 +02:00
|
|
|
if ( ( rc = iscsi_handle_string ( iscsi, strings ) ) != 0 )
|
|
|
|
return rc;
|
2006-12-05 02:08:56 +01:00
|
|
|
strings += string_len;
|
|
|
|
len -= string_len;
|
2006-12-05 01:39:05 +01:00
|
|
|
}
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive PDU data into buffer
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v data Data to receive
|
|
|
|
* @v len Length of data
|
|
|
|
* @ret rc Return status code
|
|
|
|
*
|
|
|
|
* This can be used when the RX PDU type handler wishes to buffer up
|
|
|
|
* all received data and process the PDU as a single unit. The caller
|
|
|
|
* is repsonsible for calling iscsi_rx_buffered_data_done() after
|
|
|
|
* processing the data.
|
|
|
|
*/
|
|
|
|
static int iscsi_rx_buffered_data ( struct iscsi_session *iscsi,
|
|
|
|
const void *data, size_t len ) {
|
|
|
|
|
|
|
|
/* Allocate buffer on first call */
|
|
|
|
if ( ! iscsi->rx_buffer ) {
|
|
|
|
iscsi->rx_buffer = malloc ( iscsi->rx_len );
|
|
|
|
if ( ! iscsi->rx_buffer )
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy data to buffer */
|
|
|
|
assert ( ( iscsi->rx_offset + len ) <= iscsi->rx_len );
|
|
|
|
memcpy ( ( iscsi->rx_buffer + iscsi->rx_offset ), data, len );
|
|
|
|
|
|
|
|
return 0;
|
2006-12-05 01:39:05 +01:00
|
|
|
}
|
|
|
|
|
2008-06-04 00:46:36 +02:00
|
|
|
/**
|
|
|
|
* Convert iSCSI response status to return status code
|
|
|
|
*
|
|
|
|
* @v status_class iSCSI status class
|
|
|
|
* @v status_detail iSCSI status detail
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int iscsi_status_to_rc ( unsigned int status_class,
|
|
|
|
unsigned int status_detail ) {
|
|
|
|
switch ( status_class ) {
|
|
|
|
case ISCSI_STATUS_INITIATOR_ERROR :
|
|
|
|
switch ( status_detail ) {
|
|
|
|
case ISCSI_STATUS_INITIATOR_ERROR_AUTHENTICATION :
|
|
|
|
return -EACCES;
|
|
|
|
case ISCSI_STATUS_INITIATOR_ERROR_AUTHORISATION :
|
|
|
|
return -EPERM;
|
|
|
|
case ISCSI_STATUS_INITIATOR_ERROR_NOT_FOUND :
|
|
|
|
case ISCSI_STATUS_INITIATOR_ERROR_REMOVED :
|
|
|
|
return -ENODEV;
|
|
|
|
default :
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
case ISCSI_STATUS_TARGET_ERROR :
|
|
|
|
return -EIO;
|
|
|
|
default :
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-13 13:39:46 +02:00
|
|
|
/**
|
|
|
|
* Receive data segment of an iSCSI login response PDU
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v data Received data
|
|
|
|
* @v len Length of received data
|
|
|
|
* @v remaining Data remaining after this data
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_rx_login_response ( struct iscsi_session *iscsi,
|
|
|
|
const void *data, size_t len,
|
|
|
|
size_t remaining ) {
|
2006-05-13 13:39:46 +02:00
|
|
|
struct iscsi_bhs_login_response *response
|
|
|
|
= &iscsi->rx_bhs.login_response;
|
2006-12-05 01:39:05 +01:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Buffer up the PDU data */
|
|
|
|
if ( ( rc = iscsi_rx_buffered_data ( iscsi, data, len ) ) != 0 ) {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p could not buffer login response: %s\n",
|
|
|
|
iscsi, strerror ( rc ) );
|
2007-07-08 17:04:13 +02:00
|
|
|
return rc;
|
2006-12-05 01:39:05 +01:00
|
|
|
}
|
|
|
|
if ( remaining )
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-12-05 01:39:05 +01:00
|
|
|
|
|
|
|
/* Process string data and discard string buffer */
|
2007-07-08 17:04:13 +02:00
|
|
|
if ( ( rc = iscsi_handle_strings ( iscsi, iscsi->rx_buffer,
|
|
|
|
iscsi->rx_len ) ) != 0 )
|
|
|
|
return rc;
|
2006-12-05 01:39:05 +01:00
|
|
|
iscsi_rx_buffered_data_done ( iscsi );
|
2006-05-13 13:39:46 +02:00
|
|
|
|
2006-12-05 02:41:32 +01:00
|
|
|
/* Check for login redirection */
|
|
|
|
if ( response->status_class == ISCSI_STATUS_REDIRECT ) {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p redirecting to new server\n", iscsi );
|
2007-07-08 17:04:13 +02:00
|
|
|
iscsi_close_connection ( iscsi, 0 );
|
|
|
|
if ( ( rc = iscsi_open_connection ( iscsi ) ) != 0 ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p could not redirect: %s\n ",
|
2007-01-31 03:09:13 +01:00
|
|
|
iscsi, strerror ( rc ) );
|
2007-07-08 17:04:13 +02:00
|
|
|
return rc;
|
2006-12-28 00:09:46 +01:00
|
|
|
}
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-12-05 02:41:32 +01:00
|
|
|
}
|
|
|
|
|
2006-05-13 13:39:46 +02:00
|
|
|
/* Check for fatal errors */
|
|
|
|
if ( response->status_class != 0 ) {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI login failure: class %02x detail %02x\n",
|
|
|
|
response->status_class, response->status_detail );
|
2008-06-04 00:46:36 +02:00
|
|
|
rc = iscsi_status_to_rc ( response->status_class,
|
|
|
|
response->status_detail );
|
|
|
|
iscsi->instant_rc = rc;
|
|
|
|
return rc;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
/* Handle login transitions */
|
|
|
|
if ( response->flags & ISCSI_LOGIN_FLAG_TRANSITION ) {
|
|
|
|
switch ( response->flags & ISCSI_LOGIN_NSG_MASK ) {
|
|
|
|
case ISCSI_LOGIN_NSG_OPERATIONAL_NEGOTIATION:
|
|
|
|
iscsi->status =
|
|
|
|
( ISCSI_STATUS_OPERATIONAL_NEGOTIATION_PHASE |
|
|
|
|
ISCSI_STATUS_STRINGS_OPERATIONAL );
|
|
|
|
break;
|
|
|
|
case ISCSI_LOGIN_NSG_FULL_FEATURE_PHASE:
|
|
|
|
iscsi->status = ISCSI_STATUS_FULL_FEATURE_PHASE;
|
|
|
|
break;
|
|
|
|
default:
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p got invalid response flags "
|
|
|
|
"%02x\n", iscsi, response->flags );
|
2007-07-08 17:04:13 +02:00
|
|
|
return -EIO;
|
2006-11-28 01:29:02 +01:00
|
|
|
}
|
2006-10-03 11:17:38 +02:00
|
|
|
}
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
/* Send next login request PDU if we haven't reached the full
|
|
|
|
* feature phase yet.
|
2006-10-03 11:17:38 +02:00
|
|
|
*/
|
2006-11-28 01:29:02 +01:00
|
|
|
if ( ( iscsi->status & ISCSI_STATUS_PHASE_MASK ) !=
|
|
|
|
ISCSI_STATUS_FULL_FEATURE_PHASE ) {
|
|
|
|
iscsi_start_login ( iscsi );
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
/* Check that target authentication was successful (if required) */
|
|
|
|
if ( ! iscsi->target_auth_ok ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p nefarious target tried to bypass "
|
|
|
|
"authentication\n", iscsi );
|
|
|
|
return -EPROTO;
|
|
|
|
}
|
|
|
|
|
2007-01-09 05:31:33 +01:00
|
|
|
/* Reset retry count */
|
|
|
|
iscsi->retry_count = 0;
|
|
|
|
|
2006-05-13 13:39:46 +02:00
|
|
|
/* Record TSIH for future reference */
|
|
|
|
iscsi->tsih = ntohl ( response->tsih );
|
|
|
|
|
2006-11-28 01:29:02 +01:00
|
|
|
/* Send the actual SCSI command */
|
2006-05-13 13:39:46 +02:00
|
|
|
iscsi_start_command ( iscsi );
|
2007-07-08 17:04:13 +02:00
|
|
|
|
|
|
|
return 0;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
2007-07-08 17:04:13 +02:00
|
|
|
* iSCSI to socket interface
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start up a new TX PDU
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
*
|
|
|
|
* This initiates the process of sending a new PDU. Only one PDU may
|
|
|
|
* be in transit at any one time.
|
|
|
|
*/
|
|
|
|
static void iscsi_start_tx ( struct iscsi_session *iscsi ) {
|
|
|
|
assert ( iscsi->tx_state == ISCSI_TX_IDLE );
|
|
|
|
|
|
|
|
/* Initialise TX BHS */
|
|
|
|
memset ( &iscsi->tx_bhs, 0, sizeof ( iscsi->tx_bhs ) );
|
|
|
|
|
|
|
|
/* Flag TX engine to start transmitting */
|
|
|
|
iscsi->tx_state = ISCSI_TX_BHS;
|
2007-07-08 17:04:13 +02:00
|
|
|
}
|
|
|
|
|
2007-07-09 01:52:45 +02:00
|
|
|
/**
|
|
|
|
* Transmit nothing
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int iscsi_tx_nothing ( struct iscsi_session *iscsi __unused ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
/**
|
|
|
|
* Transmit basic header segment of an iSCSI PDU
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int iscsi_tx_bhs ( struct iscsi_session *iscsi ) {
|
|
|
|
return xfer_deliver_raw ( &iscsi->socket, &iscsi->tx_bhs,
|
|
|
|
sizeof ( iscsi->tx_bhs ) );
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transmit data segment of an iSCSI PDU
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
* Handle transmission of part of a PDU data segment. iscsi::tx_bhs
|
|
|
|
* will be valid when this is called.
|
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_tx_data ( struct iscsi_session *iscsi ) {
|
2006-05-13 13:39:46 +02:00
|
|
|
struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
|
|
|
|
|
|
|
|
switch ( common->opcode & ISCSI_OPCODE_MASK ) {
|
2006-05-19 02:20:08 +02:00
|
|
|
case ISCSI_OPCODE_DATA_OUT:
|
2007-07-08 17:04:13 +02:00
|
|
|
return iscsi_tx_data_out ( iscsi );
|
2006-05-13 13:39:46 +02:00
|
|
|
case ISCSI_OPCODE_LOGIN_REQUEST:
|
2007-07-08 17:04:13 +02:00
|
|
|
return iscsi_tx_login_request ( iscsi );
|
2006-05-13 13:39:46 +02:00
|
|
|
default:
|
2007-07-09 01:52:45 +02:00
|
|
|
/* Nothing to send in other states */
|
|
|
|
return 0;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
/**
|
|
|
|
* Transmit data padding of an iSCSI PDU
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @ret rc Return status code
|
|
|
|
*
|
|
|
|
* Handle transmission of any data padding in a PDU data segment.
|
|
|
|
* iscsi::tx_bhs will be valid when this is called.
|
|
|
|
*/
|
|
|
|
static int iscsi_tx_data_padding ( struct iscsi_session *iscsi ) {
|
|
|
|
static const char pad[] = { '\0', '\0', '\0' };
|
|
|
|
struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
|
|
|
|
size_t pad_len;
|
|
|
|
|
|
|
|
pad_len = ISCSI_DATA_PAD_LEN ( common->lengths );
|
|
|
|
if ( ! pad_len )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return xfer_deliver_raw ( &iscsi->socket, pad, pad_len );
|
|
|
|
}
|
|
|
|
|
2006-05-19 02:20:08 +02:00
|
|
|
/**
|
|
|
|
* Complete iSCSI PDU transmission
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
*
|
|
|
|
* Called when a PDU has been completely transmitted and the TX state
|
|
|
|
* machine is about to enter the idle state. iscsi::tx_bhs will be
|
|
|
|
* valid for the just-completed PDU when this is called.
|
|
|
|
*/
|
|
|
|
static void iscsi_tx_done ( struct iscsi_session *iscsi ) {
|
|
|
|
struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
|
|
|
|
|
|
|
|
switch ( common->opcode & ISCSI_OPCODE_MASK ) {
|
|
|
|
case ISCSI_OPCODE_DATA_OUT:
|
|
|
|
iscsi_data_out_done ( iscsi );
|
2006-11-28 01:29:02 +01:00
|
|
|
case ISCSI_OPCODE_LOGIN_REQUEST:
|
|
|
|
iscsi_login_request_done ( iscsi );
|
2006-05-19 02:20:08 +02:00
|
|
|
default:
|
|
|
|
/* No action */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-13 13:39:46 +02:00
|
|
|
/**
|
|
|
|
* Transmit iSCSI PDU
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2006-06-18 01:20:54 +02:00
|
|
|
* @v buf Temporary data buffer
|
|
|
|
* @v len Length of temporary data buffer
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
* Constructs data to be sent for the current TX state
|
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static void iscsi_tx_step ( struct process *process ) {
|
|
|
|
struct iscsi_session *iscsi =
|
|
|
|
container_of ( process, struct iscsi_session, process );
|
2007-07-09 01:52:45 +02:00
|
|
|
struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
|
|
|
|
int ( * tx ) ( struct iscsi_session *iscsi );
|
|
|
|
enum iscsi_tx_state next_state;
|
|
|
|
size_t tx_len;
|
|
|
|
int rc;
|
2006-05-13 13:39:46 +02:00
|
|
|
|
2007-07-09 01:52:45 +02:00
|
|
|
/* Select fragment to transmit */
|
|
|
|
while ( 1 ) {
|
|
|
|
switch ( iscsi->tx_state ) {
|
|
|
|
case ISCSI_TX_IDLE:
|
|
|
|
/* Stop processing */
|
|
|
|
return;
|
|
|
|
case ISCSI_TX_BHS:
|
|
|
|
tx = iscsi_tx_bhs;
|
|
|
|
tx_len = sizeof ( iscsi->tx_bhs );
|
|
|
|
next_state = ISCSI_TX_AHS;
|
2007-07-08 17:04:13 +02:00
|
|
|
break;
|
2007-07-09 01:52:45 +02:00
|
|
|
case ISCSI_TX_AHS:
|
|
|
|
tx = iscsi_tx_nothing;
|
|
|
|
tx_len = 0;
|
|
|
|
next_state = ISCSI_TX_DATA;
|
2007-07-08 17:04:13 +02:00
|
|
|
break;
|
2007-07-09 01:52:45 +02:00
|
|
|
case ISCSI_TX_DATA:
|
|
|
|
tx = iscsi_tx_data;
|
|
|
|
tx_len = ISCSI_DATA_LEN ( common->lengths );
|
|
|
|
next_state = ISCSI_TX_DATA_PADDING;
|
2007-07-08 17:04:13 +02:00
|
|
|
break;
|
2007-07-09 01:52:45 +02:00
|
|
|
case ISCSI_TX_DATA_PADDING:
|
|
|
|
tx = iscsi_tx_data_padding;
|
|
|
|
tx_len = ISCSI_DATA_PAD_LEN ( common->lengths );
|
|
|
|
next_state = ISCSI_TX_IDLE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert ( 0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for window availability, if needed */
|
|
|
|
if ( tx_len && ( xfer_window ( &iscsi->socket ) == 0 ) ) {
|
|
|
|
/* Cannot transmit at this point; stop processing */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transmit data */
|
|
|
|
if ( ( rc = tx ( iscsi ) ) != 0 ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p could not transmit: %s\n",
|
|
|
|
iscsi, strerror ( rc ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to next state */
|
|
|
|
iscsi->tx_state = next_state;
|
|
|
|
if ( next_state == ISCSI_TX_IDLE )
|
|
|
|
iscsi_tx_done ( iscsi );
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-08 17:04:13 +02:00
|
|
|
* Receive basic header segment of an iSCSI PDU
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v data Received data
|
|
|
|
* @v len Length of received data
|
|
|
|
* @v remaining Data remaining after this data
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
2007-07-08 17:04:13 +02:00
|
|
|
* This fills in iscsi::rx_bhs with the data from the BHS portion of
|
|
|
|
* the received PDU.
|
2006-05-13 13:39:46 +02:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_rx_bhs ( struct iscsi_session *iscsi, const void *data,
|
|
|
|
size_t len, size_t remaining __unused ) {
|
|
|
|
memcpy ( &iscsi->rx_bhs.bytes[iscsi->rx_offset], data, len );
|
|
|
|
if ( ( iscsi->rx_offset + len ) >= sizeof ( iscsi->rx_bhs ) ) {
|
2008-08-11 04:12:38 +02:00
|
|
|
DBGC2 ( iscsi, "iSCSI %p received PDU opcode %#x len %#lx\n",
|
|
|
|
iscsi, iscsi->rx_bhs.common.opcode,
|
|
|
|
ISCSI_DATA_LEN ( iscsi->rx_bhs.common.lengths ) );
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Discard portion of an iSCSI PDU.
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v data Received data
|
|
|
|
* @v len Length of received data
|
|
|
|
* @v remaining Data remaining after this data
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
* This discards data from a portion of a received PDU.
|
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_rx_discard ( struct iscsi_session *iscsi __unused,
|
|
|
|
const void *data __unused, size_t len __unused,
|
|
|
|
size_t remaining __unused ) {
|
2006-05-13 13:39:46 +02:00
|
|
|
/* Do nothing */
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-08 17:04:13 +02:00
|
|
|
* Receive data segment of an iSCSI PDU
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v data Received data
|
|
|
|
* @v len Length of received data
|
|
|
|
* @v remaining Data remaining after this data
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
2007-07-08 17:04:13 +02:00
|
|
|
* Handle processing of part of a PDU data segment. iscsi::rx_bhs
|
|
|
|
* will be valid when this is called.
|
2006-05-13 13:39:46 +02:00
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_rx_data ( struct iscsi_session *iscsi, const void *data,
|
|
|
|
size_t len, size_t remaining ) {
|
|
|
|
struct iscsi_bhs_common_response *response
|
|
|
|
= &iscsi->rx_bhs.common_response;
|
|
|
|
|
|
|
|
/* Update cmdsn and statsn */
|
|
|
|
iscsi->cmdsn = ntohl ( response->expcmdsn );
|
|
|
|
iscsi->statsn = ntohl ( response->statsn );
|
|
|
|
|
|
|
|
switch ( response->opcode & ISCSI_OPCODE_MASK ) {
|
|
|
|
case ISCSI_OPCODE_LOGIN_RESPONSE:
|
|
|
|
return iscsi_rx_login_response ( iscsi, data, len, remaining );
|
|
|
|
case ISCSI_OPCODE_SCSI_RESPONSE:
|
|
|
|
return iscsi_rx_scsi_response ( iscsi, data, len, remaining );
|
|
|
|
case ISCSI_OPCODE_DATA_IN:
|
|
|
|
return iscsi_rx_data_in ( iscsi, data, len, remaining );
|
|
|
|
case ISCSI_OPCODE_R2T:
|
|
|
|
return iscsi_rx_r2t ( iscsi, data, len, remaining );
|
|
|
|
default:
|
|
|
|
if ( remaining )
|
|
|
|
return 0;
|
|
|
|
DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
|
|
|
|
response->opcode );
|
2008-06-04 00:46:36 +02:00
|
|
|
return -ENOTSUP;
|
2006-08-16 02:15:40 +02:00
|
|
|
}
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive new data
|
|
|
|
*
|
2007-07-08 17:04:13 +02:00
|
|
|
* @v socket Transport layer interface
|
2006-05-13 13:39:46 +02:00
|
|
|
* @v data Received data
|
|
|
|
* @v len Length of received data
|
2007-07-08 17:04:13 +02:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
* This handles received PDUs. The receive strategy is to fill in
|
|
|
|
* iscsi::rx_bhs with the contents of the BHS portion of the PDU,
|
|
|
|
* throw away any AHS portion, and then process each part of the data
|
|
|
|
* portion as it arrives. The data processing routine therefore
|
|
|
|
* always has a full copy of the BHS available, even for portions of
|
|
|
|
* the data in different packets to the BHS.
|
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static int iscsi_socket_deliver_raw ( struct xfer_interface *socket,
|
|
|
|
const void *data, size_t len ) {
|
|
|
|
struct iscsi_session *iscsi =
|
|
|
|
container_of ( socket, struct iscsi_session, socket );
|
2006-05-13 13:39:46 +02:00
|
|
|
struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
|
2007-07-09 01:52:45 +02:00
|
|
|
int ( * rx ) ( struct iscsi_session *iscsi, const void *data,
|
|
|
|
size_t len, size_t remaining );
|
2006-05-13 13:39:46 +02:00
|
|
|
enum iscsi_rx_state next_state;
|
|
|
|
size_t frag_len;
|
|
|
|
size_t remaining;
|
2007-07-08 17:04:13 +02:00
|
|
|
int rc;
|
2006-05-13 13:39:46 +02:00
|
|
|
|
|
|
|
while ( 1 ) {
|
|
|
|
switch ( iscsi->rx_state ) {
|
|
|
|
case ISCSI_RX_BHS:
|
2007-07-09 01:52:45 +02:00
|
|
|
rx = iscsi_rx_bhs;
|
2006-12-05 01:39:05 +01:00
|
|
|
iscsi->rx_len = sizeof ( iscsi->rx_bhs );
|
2006-05-13 13:39:46 +02:00
|
|
|
next_state = ISCSI_RX_AHS;
|
|
|
|
break;
|
|
|
|
case ISCSI_RX_AHS:
|
2007-07-09 01:52:45 +02:00
|
|
|
rx = iscsi_rx_discard;
|
2006-12-05 01:39:05 +01:00
|
|
|
iscsi->rx_len = 4 * ISCSI_AHS_LEN ( common->lengths );
|
2006-05-13 13:39:46 +02:00
|
|
|
next_state = ISCSI_RX_DATA;
|
|
|
|
break;
|
|
|
|
case ISCSI_RX_DATA:
|
2007-07-09 01:52:45 +02:00
|
|
|
rx = iscsi_rx_data;
|
2006-12-05 01:39:05 +01:00
|
|
|
iscsi->rx_len = ISCSI_DATA_LEN ( common->lengths );
|
2006-05-13 13:39:46 +02:00
|
|
|
next_state = ISCSI_RX_DATA_PADDING;
|
|
|
|
break;
|
|
|
|
case ISCSI_RX_DATA_PADDING:
|
2007-07-09 01:52:45 +02:00
|
|
|
rx = iscsi_rx_discard;
|
2006-12-05 01:39:05 +01:00
|
|
|
iscsi->rx_len = ISCSI_DATA_PAD_LEN ( common->lengths );
|
2006-05-13 13:39:46 +02:00
|
|
|
next_state = ISCSI_RX_BHS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert ( 0 );
|
2007-07-08 17:04:13 +02:00
|
|
|
return -EINVAL;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
2006-12-05 01:39:05 +01:00
|
|
|
frag_len = iscsi->rx_len - iscsi->rx_offset;
|
2006-05-13 13:39:46 +02:00
|
|
|
if ( frag_len > len )
|
|
|
|
frag_len = len;
|
2006-12-05 01:39:05 +01:00
|
|
|
remaining = iscsi->rx_len - iscsi->rx_offset - frag_len;
|
2007-07-09 01:52:45 +02:00
|
|
|
if ( ( rc = rx ( iscsi, data, frag_len, remaining ) ) != 0 ) {
|
2007-07-08 17:04:13 +02:00
|
|
|
DBGC ( iscsi, "iSCSI %p could not process received "
|
|
|
|
"data: %s\n", iscsi, strerror ( rc ) );
|
|
|
|
iscsi_close_connection ( iscsi, rc );
|
|
|
|
iscsi_scsi_done ( iscsi, rc );
|
|
|
|
return rc;
|
|
|
|
}
|
2006-05-13 13:39:46 +02:00
|
|
|
|
|
|
|
iscsi->rx_offset += frag_len;
|
|
|
|
data += frag_len;
|
|
|
|
len -= frag_len;
|
|
|
|
|
|
|
|
/* If all the data for this state has not yet been
|
|
|
|
* received, stay in this state for now.
|
|
|
|
*/
|
2006-12-05 01:39:05 +01:00
|
|
|
if ( iscsi->rx_offset != iscsi->rx_len )
|
2007-07-08 17:04:13 +02:00
|
|
|
return 0;
|
2006-05-13 13:39:46 +02:00
|
|
|
|
|
|
|
iscsi->rx_state = next_state;
|
|
|
|
iscsi->rx_offset = 0;
|
|
|
|
}
|
2007-07-08 17:04:13 +02:00
|
|
|
|
|
|
|
return 0;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-01-31 03:09:13 +01:00
|
|
|
* Handle stream connection closure
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
2007-07-08 17:04:13 +02:00
|
|
|
* @v socket Transport layer interface
|
|
|
|
* @v rc Reason for close
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
|
|
|
*/
|
2007-07-08 17:04:13 +02:00
|
|
|
static void iscsi_socket_close ( struct xfer_interface *socket, int rc ) {
|
|
|
|
struct iscsi_session *iscsi =
|
|
|
|
container_of ( socket, struct iscsi_session, socket );
|
2006-05-13 13:39:46 +02:00
|
|
|
|
2007-01-09 05:31:33 +01:00
|
|
|
/* Even a graceful close counts as an error for iSCSI */
|
2007-07-08 17:04:13 +02:00
|
|
|
if ( ! rc )
|
|
|
|
rc = -ECONNRESET;
|
2007-01-09 05:31:33 +01:00
|
|
|
|
|
|
|
/* Close session cleanly */
|
2007-07-08 17:04:13 +02:00
|
|
|
iscsi_close_connection ( iscsi, rc );
|
2006-05-13 13:39:46 +02:00
|
|
|
|
|
|
|
/* Retry connection if within the retry limit, otherwise fail */
|
|
|
|
if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p retrying connection (retry #%d)\n",
|
|
|
|
iscsi, iscsi->retry_count );
|
2007-07-08 17:04:13 +02:00
|
|
|
if ( ( rc = iscsi_open_connection ( iscsi ) ) != 0 ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p could not reconnect: %s\n",
|
2007-01-31 03:09:13 +01:00
|
|
|
iscsi, strerror ( rc ) );
|
2007-07-08 17:04:13 +02:00
|
|
|
iscsi_scsi_done ( iscsi, rc );
|
2006-12-28 00:09:46 +01:00
|
|
|
}
|
2006-05-13 13:39:46 +02:00
|
|
|
} else {
|
2007-01-09 05:38:39 +01:00
|
|
|
DBGC ( iscsi, "iSCSI %p retry count exceeded\n", iscsi );
|
2007-07-08 17:04:13 +02:00
|
|
|
iscsi->instant_rc = rc;
|
|
|
|
iscsi_scsi_done ( iscsi, rc );
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-26 03:13:38 +02:00
|
|
|
/**
|
|
|
|
* Handle redirection event
|
|
|
|
*
|
|
|
|
* @v socket Transport layer interface
|
|
|
|
* @v type Location type
|
|
|
|
* @v args Remaining arguments depend upon location type
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int iscsi_vredirect ( struct xfer_interface *socket, int type,
|
|
|
|
va_list args ) {
|
|
|
|
struct iscsi_session *iscsi =
|
|
|
|
container_of ( socket, struct iscsi_session, socket );
|
|
|
|
va_list tmp;
|
|
|
|
struct sockaddr *peer;
|
|
|
|
|
|
|
|
/* Intercept redirects to a LOCATION_SOCKET and record the IP
|
|
|
|
* address for the iBFT. This is a bit of a hack, but avoids
|
|
|
|
* inventing an ioctl()-style call to retrieve the socket
|
|
|
|
* address from a data-xfer interface.
|
|
|
|
*/
|
|
|
|
if ( type == LOCATION_SOCKET ) {
|
|
|
|
va_copy ( tmp, args );
|
|
|
|
( void ) va_arg ( tmp, int ); /* Discard "semantics" */
|
|
|
|
peer = va_arg ( tmp, struct sockaddr * );
|
|
|
|
memcpy ( &iscsi->target_sockaddr, peer,
|
|
|
|
sizeof ( iscsi->target_sockaddr ) );
|
|
|
|
va_end ( tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
return xfer_vopen ( socket, type, args );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-08 17:04:13 +02:00
|
|
|
/** iSCSI socket operations */
|
|
|
|
static struct xfer_interface_operations iscsi_socket_operations = {
|
|
|
|
.close = iscsi_socket_close,
|
2007-07-26 03:13:38 +02:00
|
|
|
.vredirect = iscsi_vredirect,
|
2007-07-08 17:04:13 +02:00
|
|
|
.window = unlimited_xfer_window,
|
|
|
|
.alloc_iob = default_xfer_alloc_iob,
|
|
|
|
.deliver_iob = xfer_deliver_as_raw,
|
|
|
|
.deliver_raw = iscsi_socket_deliver_raw,
|
2006-05-13 13:39:46 +02:00
|
|
|
};
|
|
|
|
|
2007-07-08 19:51:56 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
2007-07-08 23:01:49 +02:00
|
|
|
* iSCSI command issuing
|
2007-07-08 19:51:56 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-05-13 13:39:46 +02:00
|
|
|
/**
|
2007-07-08 19:51:56 +02:00
|
|
|
* Issue SCSI command
|
2006-05-13 13:39:46 +02:00
|
|
|
*
|
2007-07-08 23:01:49 +02:00
|
|
|
* @v scsi SCSI device
|
2006-05-13 13:39:46 +02:00
|
|
|
* @v command SCSI command
|
2007-01-15 09:49:10 +01:00
|
|
|
* @ret rc Return status code
|
2006-05-13 13:39:46 +02:00
|
|
|
*/
|
2007-07-08 23:01:49 +02:00
|
|
|
static int iscsi_command ( struct scsi_device *scsi,
|
|
|
|
struct scsi_command *command ) {
|
2007-07-08 19:51:56 +02:00
|
|
|
struct iscsi_session *iscsi =
|
2007-07-08 23:01:49 +02:00
|
|
|
container_of ( scsi->backend, struct iscsi_session, refcnt );
|
2006-12-28 00:09:46 +01:00
|
|
|
int rc;
|
|
|
|
|
2007-07-08 20:33:26 +02:00
|
|
|
/* Record SCSI command */
|
|
|
|
iscsi->command = command;
|
2006-05-13 13:39:46 +02:00
|
|
|
|
2007-07-08 19:51:56 +02:00
|
|
|
/* Abort immediately if we have a recorded permanent failure */
|
2007-07-08 20:33:26 +02:00
|
|
|
if ( iscsi->instant_rc ) {
|
|
|
|
rc = iscsi->instant_rc;
|
|
|
|
goto done;
|
|
|
|
}
|
2007-07-08 19:51:56 +02:00
|
|
|
|
|
|
|
/* Issue command or open connection as appropriate */
|
|
|
|
if ( iscsi->status ) {
|
2007-01-09 05:31:33 +01:00
|
|
|
iscsi_start_command ( iscsi );
|
2006-05-13 13:39:46 +02:00
|
|
|
} else {
|
2007-07-08 19:51:56 +02:00
|
|
|
if ( ( rc = iscsi_open_connection ( iscsi ) ) != 0 )
|
2007-07-08 20:33:26 +02:00
|
|
|
goto done;
|
2007-07-08 19:51:56 +02:00
|
|
|
}
|
|
|
|
|
2007-07-08 20:33:26 +02:00
|
|
|
/* Wait for command to complete */
|
|
|
|
iscsi->rc = -EINPROGRESS;
|
|
|
|
while ( iscsi->rc == -EINPROGRESS )
|
|
|
|
step();
|
|
|
|
rc = iscsi->rc;
|
|
|
|
|
|
|
|
done:
|
|
|
|
iscsi->command = NULL;
|
|
|
|
return rc;
|
2007-07-08 19:51:56 +02:00
|
|
|
}
|
|
|
|
|
2007-07-08 23:01:49 +02:00
|
|
|
static int iscsi_detached_command ( struct scsi_device *scsi __unused,
|
|
|
|
struct scsi_command *command __unused ) {
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2007-07-08 19:51:56 +02:00
|
|
|
/**
|
2007-07-08 23:01:49 +02:00
|
|
|
* Shut down iSCSI interface
|
2007-07-08 19:51:56 +02:00
|
|
|
*
|
2007-07-08 23:01:49 +02:00
|
|
|
* @v scsi SCSI device
|
2007-07-08 19:51:56 +02:00
|
|
|
*/
|
2007-07-08 23:01:49 +02:00
|
|
|
void iscsi_detach ( struct scsi_device *scsi ) {
|
2007-07-08 19:51:56 +02:00
|
|
|
struct iscsi_session *iscsi =
|
2007-07-08 23:01:49 +02:00
|
|
|
container_of ( scsi->backend, struct iscsi_session, refcnt );
|
2007-07-08 19:51:56 +02:00
|
|
|
|
2007-07-09 01:52:45 +02:00
|
|
|
xfer_nullify ( &iscsi->socket );
|
2007-07-08 23:01:49 +02:00
|
|
|
iscsi_close_connection ( iscsi, 0 );
|
2007-07-08 19:51:56 +02:00
|
|
|
process_del ( &iscsi->process );
|
2007-07-08 23:01:49 +02:00
|
|
|
scsi->command = iscsi_detached_command;
|
|
|
|
ref_put ( scsi->backend );
|
|
|
|
scsi->backend = NULL;
|
2007-07-08 19:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Instantiator
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** iSCSI root path components (as per RFC4173) */
|
|
|
|
enum iscsi_root_path_component {
|
|
|
|
RP_LITERAL = 0,
|
|
|
|
RP_SERVERNAME,
|
|
|
|
RP_PROTOCOL,
|
|
|
|
RP_PORT,
|
|
|
|
RP_LUN,
|
|
|
|
RP_TARGETNAME,
|
|
|
|
NUM_RP_COMPONENTS
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse iSCSI LUN
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v lun_string LUN string representation (as per RFC4173)
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int iscsi_parse_lun ( struct iscsi_session *iscsi,
|
|
|
|
const char *lun_string ) {
|
|
|
|
char *p = ( char * ) lun_string;
|
|
|
|
union {
|
|
|
|
uint64_t u64;
|
|
|
|
uint16_t u16[4];
|
|
|
|
} lun;
|
|
|
|
int i;
|
|
|
|
|
2007-07-09 01:00:34 +02:00
|
|
|
/* Empty LUN; assume LUN 0 */
|
|
|
|
if ( ! *lun_string )
|
|
|
|
return 0;
|
|
|
|
|
2007-07-08 19:51:56 +02:00
|
|
|
for ( i = 0 ; i < 4 ; i++ ) {
|
|
|
|
lun.u16[i] = strtoul ( p, &p, 16 );
|
|
|
|
if ( *p != '-' )
|
|
|
|
return -EINVAL;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if ( *p )
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
iscsi->lun = lun.u64;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse iSCSI root path
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @v root_path iSCSI root path (as per RFC4173)
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
|
|
|
|
const char *root_path ) {
|
2007-07-09 01:00:34 +02:00
|
|
|
char rp_copy[ strlen ( root_path ) + 1 ];
|
|
|
|
char *rp_comp[NUM_RP_COMPONENTS];
|
|
|
|
char *rp = rp_copy;
|
|
|
|
int i = 0;
|
2007-07-08 19:51:56 +02:00
|
|
|
int rc;
|
|
|
|
|
2007-07-09 01:00:34 +02:00
|
|
|
/* Split root path into component parts */
|
|
|
|
strcpy ( rp_copy, root_path );
|
|
|
|
while ( 1 ) {
|
|
|
|
rp_comp[i++] = rp;
|
|
|
|
if ( i == NUM_RP_COMPONENTS )
|
2007-07-08 19:51:56 +02:00
|
|
|
break;
|
2007-07-09 01:00:34 +02:00
|
|
|
for ( ; *rp != ':' ; rp++ ) {
|
|
|
|
if ( ! *rp ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p root path \"%s\" "
|
|
|
|
"too short\n", iscsi, root_path );
|
|
|
|
return -EINVAL;
|
2007-07-08 19:51:56 +02:00
|
|
|
}
|
2006-12-28 00:09:46 +01:00
|
|
|
}
|
2007-07-09 01:00:34 +02:00
|
|
|
*(rp++) = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use root path components to configure iSCSI session */
|
|
|
|
iscsi->target_address = strdup ( rp_comp[RP_SERVERNAME] );
|
|
|
|
if ( ! iscsi->target_address )
|
|
|
|
return -ENOMEM;
|
|
|
|
iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
|
|
|
|
if ( ! iscsi->target_port )
|
|
|
|
iscsi->target_port = ISCSI_PORT;
|
|
|
|
if ( ( rc = iscsi_parse_lun ( iscsi, rp_comp[RP_LUN] ) ) != 0 ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
|
|
|
|
iscsi, rp_comp[RP_LUN] );
|
|
|
|
return rc;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
2007-07-09 01:00:34 +02:00
|
|
|
iscsi->target_iqn = strdup ( rp_comp[RP_TARGETNAME] );
|
|
|
|
if ( ! iscsi->target_iqn )
|
|
|
|
return -ENOMEM;
|
2006-05-13 13:39:46 +02:00
|
|
|
|
2007-01-15 09:49:10 +01:00
|
|
|
return 0;
|
2006-05-13 13:39:46 +02:00
|
|
|
}
|
2006-12-21 18:17:47 +01:00
|
|
|
|
2007-07-26 03:13:38 +02:00
|
|
|
/**
|
|
|
|
* Set iSCSI authentication details
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
2008-08-11 04:12:38 +02:00
|
|
|
* @v initiator_username Initiator username, if any
|
|
|
|
* @v initiator_password Initiator password, if any
|
|
|
|
* @v target_username Target username, if any
|
|
|
|
* @v target_password Target password, if any
|
2007-07-26 03:13:38 +02:00
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int iscsi_set_auth ( struct iscsi_session *iscsi,
|
2008-08-11 04:12:38 +02:00
|
|
|
const char *initiator_username,
|
|
|
|
const char *initiator_password,
|
|
|
|
const char *target_username,
|
|
|
|
const char *target_password ) {
|
|
|
|
|
|
|
|
/* Check for initiator or target credentials */
|
|
|
|
if ( initiator_username || initiator_password ||
|
|
|
|
target_username || target_password ) {
|
|
|
|
|
|
|
|
/* We must have at least an initiator username+password */
|
|
|
|
if ( ! ( initiator_username && initiator_password ) )
|
|
|
|
goto invalid_auth;
|
|
|
|
|
|
|
|
/* Store initiator credentials */
|
|
|
|
iscsi->initiator_username = strdup ( initiator_username );
|
|
|
|
if ( ! iscsi->initiator_username )
|
2007-07-26 03:13:38 +02:00
|
|
|
return -ENOMEM;
|
2008-08-11 04:12:38 +02:00
|
|
|
iscsi->initiator_password = strdup ( initiator_password );
|
|
|
|
if ( ! iscsi->initiator_password )
|
2007-07-26 03:13:38 +02:00
|
|
|
return -ENOMEM;
|
2008-08-11 04:12:38 +02:00
|
|
|
|
|
|
|
/* Check for target credentials */
|
|
|
|
if ( target_username || target_password ) {
|
|
|
|
|
|
|
|
/* We must have target username+password */
|
|
|
|
if ( ! ( target_username && target_password ) )
|
|
|
|
goto invalid_auth;
|
|
|
|
|
|
|
|
/* Store target credentials */
|
|
|
|
iscsi->target_username = strdup ( target_username );
|
|
|
|
if ( ! iscsi->target_username )
|
|
|
|
return -ENOMEM;
|
|
|
|
iscsi->target_password = strdup ( target_password );
|
|
|
|
if ( ! iscsi->target_password )
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2007-07-26 03:13:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-08-11 04:12:38 +02:00
|
|
|
|
|
|
|
invalid_auth:
|
|
|
|
DBGC ( iscsi, "iSCSI %p invalid credentials: initiator "
|
|
|
|
"%sname,%spw, target %sname,%spw\n", iscsi,
|
|
|
|
( initiator_username ? "" : "no " ),
|
|
|
|
( initiator_password ? "" : "no " ),
|
|
|
|
( target_username ? "" : "no " ),
|
|
|
|
( target_password ? "" : "no " ) );
|
|
|
|
return -EINVAL;
|
2007-07-26 03:13:38 +02:00
|
|
|
}
|
|
|
|
|
2006-12-21 18:17:47 +01:00
|
|
|
/**
|
2007-07-08 19:51:56 +02:00
|
|
|
* Attach iSCSI interface
|
2006-12-21 18:17:47 +01:00
|
|
|
*
|
2007-07-08 23:01:49 +02:00
|
|
|
* @v scsi SCSI device
|
2007-07-08 19:51:56 +02:00
|
|
|
* @v root_path iSCSI root path (as per RFC4173)
|
|
|
|
* @ret rc Return status code
|
2006-12-21 18:17:47 +01:00
|
|
|
*/
|
2007-07-08 23:01:49 +02:00
|
|
|
int iscsi_attach ( struct scsi_device *scsi, const char *root_path ) {
|
2007-07-08 19:51:56 +02:00
|
|
|
struct iscsi_session *iscsi;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Allocate and initialise structure */
|
|
|
|
iscsi = zalloc ( sizeof ( *iscsi ) );
|
|
|
|
if ( ! iscsi )
|
|
|
|
return -ENOMEM;
|
2007-07-08 23:01:49 +02:00
|
|
|
iscsi->refcnt.free = iscsi_free;
|
2007-07-08 19:51:56 +02:00
|
|
|
xfer_init ( &iscsi->socket, &iscsi_socket_operations, &iscsi->refcnt );
|
|
|
|
process_init ( &iscsi->process, iscsi_tx_step, &iscsi->refcnt );
|
|
|
|
|
|
|
|
/* Parse root path */
|
|
|
|
if ( ( rc = iscsi_parse_root_path ( iscsi, root_path ) ) != 0 )
|
|
|
|
goto err;
|
2007-07-26 03:13:38 +02:00
|
|
|
/* Set fields not specified by root path */
|
2008-08-11 04:12:38 +02:00
|
|
|
if ( ( rc = iscsi_set_auth ( iscsi,
|
|
|
|
iscsi_initiator_username,
|
|
|
|
iscsi_initiator_password,
|
|
|
|
iscsi_target_username,
|
|
|
|
iscsi_target_password ) ) != 0 )
|
2007-07-26 03:13:38 +02:00
|
|
|
goto err;
|
2007-07-08 19:51:56 +02:00
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
if ( ! iscsi->target_address ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p does not yet support discovery\n",
|
|
|
|
iscsi );
|
|
|
|
rc = -ENOTSUP;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if ( ! iscsi->target_iqn ) {
|
|
|
|
DBGC ( iscsi, "iSCSI %p no target address supplied in %s\n",
|
|
|
|
iscsi, root_path );
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach parent interface, mortalise self, and return */
|
2007-07-08 23:01:49 +02:00
|
|
|
scsi->backend = ref_get ( &iscsi->refcnt );
|
|
|
|
scsi->command = iscsi_command;
|
|
|
|
scsi->lun = iscsi->lun;
|
2007-07-08 19:51:56 +02:00
|
|
|
ref_put ( &iscsi->refcnt );
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2007-07-08 17:04:13 +02:00
|
|
|
ref_put ( &iscsi->refcnt );
|
2007-07-08 19:51:56 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
2008-03-25 21:46:16 +01:00
|
|
|
* Settings
|
2007-07-08 19:51:56 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-03-25 21:46:16 +01:00
|
|
|
/** iSCSI initiator IQN setting */
|
|
|
|
struct setting initiator_iqn_setting __setting = {
|
|
|
|
.name = "initiator-iqn",
|
|
|
|
.description = "iSCSI initiator name",
|
|
|
|
.tag = DHCP_ISCSI_INITIATOR_IQN,
|
|
|
|
.type = &setting_type_string,
|
|
|
|
};
|
|
|
|
|
2008-08-11 04:12:38 +02:00
|
|
|
/** iSCSI reverse username setting */
|
|
|
|
struct setting reverse_username_setting __setting = {
|
|
|
|
.name = "reverse-username",
|
|
|
|
.description = "Reverse user name",
|
|
|
|
.tag = DHCP_EB_REVERSE_USERNAME,
|
|
|
|
.type = &setting_type_string,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** iSCSI reverse password setting */
|
|
|
|
struct setting reverse_password_setting __setting = {
|
|
|
|
.name = "reverse-password",
|
|
|
|
.description = "Reverse password",
|
|
|
|
.tag = DHCP_EB_REVERSE_PASSWORD,
|
|
|
|
.type = &setting_type_string,
|
|
|
|
};
|
|
|
|
|
2008-03-21 00:15:48 +01:00
|
|
|
/** An iSCSI string setting */
|
|
|
|
struct iscsi_string_setting {
|
2008-03-25 21:46:16 +01:00
|
|
|
/** Setting */
|
|
|
|
struct setting *setting;
|
2008-03-21 00:15:48 +01:00
|
|
|
/** String to update */
|
2007-07-08 19:51:56 +02:00
|
|
|
char **string;
|
2008-03-21 00:15:48 +01:00
|
|
|
/** String prefix */
|
|
|
|
const char *prefix;
|
|
|
|
};
|
2007-07-08 19:51:56 +02:00
|
|
|
|
2008-03-21 00:15:48 +01:00
|
|
|
/** iSCSI string settings */
|
|
|
|
static struct iscsi_string_setting iscsi_string_settings[] = {
|
2007-07-08 19:51:56 +02:00
|
|
|
{
|
2008-03-25 21:46:16 +01:00
|
|
|
.setting = &initiator_iqn_setting,
|
2008-03-21 00:15:48 +01:00
|
|
|
.string = &iscsi_explicit_initiator_iqn,
|
|
|
|
.prefix = "",
|
2007-07-08 19:51:56 +02:00
|
|
|
},
|
|
|
|
{
|
2008-03-25 21:46:16 +01:00
|
|
|
.setting = &username_setting,
|
2008-08-11 04:12:38 +02:00
|
|
|
.string = &iscsi_initiator_username,
|
2008-03-21 00:15:48 +01:00
|
|
|
.prefix = "",
|
2007-07-08 19:51:56 +02:00
|
|
|
},
|
|
|
|
{
|
2008-03-25 21:46:16 +01:00
|
|
|
.setting = &password_setting,
|
2008-08-11 04:12:38 +02:00
|
|
|
.string = &iscsi_initiator_password,
|
|
|
|
.prefix = "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.setting = &reverse_username_setting,
|
|
|
|
.string = &iscsi_target_username,
|
|
|
|
.prefix = "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.setting = &reverse_password_setting,
|
|
|
|
.string = &iscsi_target_password,
|
2008-03-21 00:15:48 +01:00
|
|
|
.prefix = "",
|
2007-07-08 19:51:56 +02:00
|
|
|
},
|
|
|
|
{
|
2008-03-25 21:46:16 +01:00
|
|
|
.setting = &hostname_setting,
|
2008-03-21 00:15:48 +01:00
|
|
|
.string = &iscsi_default_initiator_iqn,
|
2008-09-19 18:46:07 +02:00
|
|
|
.prefix = "iqn.2000-01.org.etherboot:",
|
2007-07-08 19:51:56 +02:00
|
|
|
},
|
|
|
|
};
|
2007-07-26 03:13:38 +02:00
|
|
|
|
2008-03-21 00:15:48 +01:00
|
|
|
/**
|
|
|
|
* Apply iSCSI setting
|
|
|
|
*
|
|
|
|
* @v setting iSCSI string setting
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int apply_iscsi_string_setting ( struct iscsi_string_setting *setting ){
|
|
|
|
size_t prefix_len;
|
|
|
|
int setting_len;
|
|
|
|
size_t len;
|
|
|
|
int check_len;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
/* Free old string */
|
|
|
|
free ( *setting->string );
|
|
|
|
*setting->string = NULL;
|
|
|
|
|
|
|
|
/* Allocate new string */
|
|
|
|
prefix_len = strlen ( setting->prefix );
|
2008-03-25 21:46:16 +01:00
|
|
|
setting_len = fetch_setting_len ( NULL, setting->setting );
|
2008-03-21 23:55:59 +01:00
|
|
|
if ( setting_len < 0 ) {
|
|
|
|
/* Missing settings are not errors; leave strings as NULL */
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-21 00:15:48 +01:00
|
|
|
len = ( prefix_len + setting_len + 1 );
|
|
|
|
p = *setting->string = malloc ( len );
|
|
|
|
if ( ! p )
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Fill new string */
|
|
|
|
strcpy ( p, setting->prefix );
|
2008-03-25 21:46:16 +01:00
|
|
|
check_len = fetch_string_setting ( NULL, setting->setting,
|
2008-03-21 00:15:48 +01:00
|
|
|
( p + prefix_len ),
|
|
|
|
( len - prefix_len ) );
|
|
|
|
assert ( check_len == setting_len );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply iSCSI settings
|
|
|
|
*
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static int apply_iscsi_settings ( void ) {
|
|
|
|
struct iscsi_string_setting *setting;
|
|
|
|
unsigned int i;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
for ( i = 0 ; i < ( sizeof ( iscsi_string_settings ) /
|
|
|
|
sizeof ( iscsi_string_settings[0] ) ) ; i++ ) {
|
|
|
|
setting = &iscsi_string_settings[i];
|
|
|
|
if ( ( rc = apply_iscsi_string_setting ( setting ) ) != 0 ) {
|
2008-03-25 21:46:16 +01:00
|
|
|
DBG ( "iSCSI could not apply setting %s\n",
|
|
|
|
setting->setting->name );
|
2008-03-21 00:15:48 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** iSCSI settings applicator */
|
|
|
|
struct settings_applicator iscsi_settings_applicator __settings_applicator = {
|
|
|
|
.apply = apply_iscsi_settings,
|
|
|
|
};
|
|
|
|
|
2007-07-26 03:13:38 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* Initiator name
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get iSCSI initiator IQN
|
|
|
|
*
|
|
|
|
* @v iscsi iSCSI session
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
const char * iscsi_initiator_iqn ( void ) {
|
|
|
|
|
|
|
|
if ( iscsi_explicit_initiator_iqn )
|
|
|
|
return iscsi_explicit_initiator_iqn;
|
|
|
|
if ( iscsi_default_initiator_iqn )
|
|
|
|
return iscsi_default_initiator_iqn;
|
|
|
|
return "iqn.2000-09.org.etherboot:UNKNOWN";
|
|
|
|
}
|