summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2008-06-04 00:46:36 +0200
committerMichael Brown2008-06-04 00:47:20 +0200
commit75965c9c6e9eca6d790710351f054689f4578a85 (patch)
tree33131a0d6481b36fa1547014ea37d62da9e5010b
parent[Makefile] Remove obsolete SRCDIRS (diff)
downloadipxe-75965c9c6e9eca6d790710351f054689f4578a85.tar.gz
ipxe-75965c9c6e9eca6d790710351f054689f4578a85.tar.xz
ipxe-75965c9c6e9eca6d790710351f054689f4578a85.zip
[iSCSI] Produce meaningful errors on login failure
Return the most appropriate of EACCES, EPERM, ENODEV, ENOTSUP, EIO or EINVAL depending on the exact error returned by the target, rather than just always returning EPERM. Also, ensure that error strings exist for these errors.
-rw-r--r--src/hci/strerror.c17
-rw-r--r--src/include/gpxe/iscsi.h12
-rw-r--r--src/net/tcp/iscsi.c37
3 files changed, 52 insertions, 14 deletions
diff --git a/src/hci/strerror.c b/src/hci/strerror.c
index 69675905e..74995e8b4 100644
--- a/src/hci/strerror.c
+++ b/src/hci/strerror.c
@@ -108,15 +108,18 @@ const char * strerror ( int errno ) {
/** The most common errors */
struct errortab common_errors[] __errortab = {
{ 0, "No error" },
- { ENOMEM, "Out of memory" },
+ { EACCES, "Permission denied" },
+ { ECANCELED, "Operation cancelled" },
+ { ECONNRESET, "Connection reset" },
{ EINVAL, "Invalid argument" },
- { ENOSPC, "No space left on device" },
{ EIO, "Input/output error" },
- { EACCES, "Permission denied" },
- { ENOENT, "File not found" },
{ ENETUNREACH, "Network unreachable" },
- { ETIMEDOUT, "Connection timed out" },
- { EPIPE, "Broken pipe" },
- { ECANCELED, "Operation cancelled" },
+ { ENODEV, "No such device" },
+ { ENOENT, "File not found" },
{ ENOEXEC, "Not an executable image" },
+ { ENOMEM, "Out of memory" },
+ { ENOSPC, "No space left on device" },
+ { ENOTSUP, "Not supported" },
+ { EPERM, "Operation not permitted" },
+ { ETIMEDOUT, "Connection timed out" },
};
diff --git a/src/include/gpxe/iscsi.h b/src/include/gpxe/iscsi.h
index e4df68494..5c446757b 100644
--- a/src/include/gpxe/iscsi.h
+++ b/src/include/gpxe/iscsi.h
@@ -224,10 +224,14 @@ struct iscsi_bhs_login_response {
#define ISCSI_OPCODE_LOGIN_RESPONSE 0x23
/* Login response status codes */
-#define ISCSI_STATUS_SUCCESS 0x00
-#define ISCSI_STATUS_REDIRECT 0x01
-#define ISCSI_STATUS_INITIATOR_ERROR 0x02
-#define ISCSI_STATUS_TARGET_ERROR 0x03
+#define ISCSI_STATUS_SUCCESS 0x00
+#define ISCSI_STATUS_REDIRECT 0x01
+#define ISCSI_STATUS_INITIATOR_ERROR 0x02
+#define ISCSI_STATUS_INITIATOR_ERROR_AUTHENTICATION 0x01
+#define ISCSI_STATUS_INITIATOR_ERROR_AUTHORISATION 0x02
+#define ISCSI_STATUS_INITIATOR_ERROR_NOT_FOUND 0x03
+#define ISCSI_STATUS_INITIATOR_ERROR_REMOVED 0x04
+#define ISCSI_STATUS_TARGET_ERROR 0x03
/**
* iSCSI SCSI command basic header segment
diff --git a/src/net/tcp/iscsi.c b/src/net/tcp/iscsi.c
index 3cd547037..a12fca857 100644
--- a/src/net/tcp/iscsi.c
+++ b/src/net/tcp/iscsi.c
@@ -831,6 +831,35 @@ static int iscsi_rx_buffered_data ( struct iscsi_session *iscsi,
}
/**
+ * 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;
+ }
+}
+
+/**
* Receive data segment of an iSCSI login response PDU
*
* @v iscsi iSCSI session
@@ -877,8 +906,10 @@ static int iscsi_rx_login_response ( struct iscsi_session *iscsi,
if ( response->status_class != 0 ) {
DBGC ( iscsi, "iSCSI login failure: class %02x detail %02x\n",
response->status_class, response->status_detail );
- iscsi->instant_rc = -EPERM;
- return -EPERM;
+ rc = iscsi_status_to_rc ( response->status_class,
+ response->status_detail );
+ iscsi->instant_rc = rc;
+ return rc;
}
/* Handle login transitions */
@@ -1177,7 +1208,7 @@ static int iscsi_rx_data ( struct iscsi_session *iscsi, const void *data,
return 0;
DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
response->opcode );
- return -EOPNOTSUPP;
+ return -ENOTSUP;
}
}