Преглед на файлове

[iscsi] Disambiguate some common authentication errors

Signed-off-by: Michael Brown <mcb30@etherboot.org>
tags/v1.20.1
Michael Brown преди 15 години
родител
ревизия
73c71f6492
променени са 1 файла, в които са добавени 27 реда и са изтрити 14 реда
  1. 27
    14
      src/net/tcp/iscsi.c

+ 27
- 14
src/net/tcp/iscsi.c Целия файл

@@ -45,6 +45,19 @@ FILE_LICENCE ( GPL2_OR_LATER );
45 45
 
46 46
 FEATURE ( FEATURE_PROTOCOL, "iSCSI", DHCP_EB_FEATURE_ISCSI, 1 );
47 47
 
48
+/* Disambiguate the various error causes */
49
+#define EACCES_INCORRECT_TARGET_USERNAME ( EACCES | EUNIQ_01 )
50
+#define EACCES_INCORRECT_TARGET_PASSWORD ( EACCES | EUNIQ_02 )
51
+#define ENOTSUP_INITIATOR_STATUS ( ENOTSUP | EUNIQ_01 )
52
+#define ENOTSUP_OPCODE ( ENOTSUP | EUNIQ_02 )
53
+#define ENOTSUP_DISCOVERY ( ENOTSUP | EUNIQ_03 )
54
+#define EPERM_INITIATOR_AUTHENTICATION ( EPERM | EUNIQ_01 )
55
+#define EPERM_INITIATOR_AUTHORISATION ( EPERM | EUNIQ_02 )
56
+#define EPROTO_INVALID_CHAP_ALGORITHM ( EPROTO | EUNIQ_01 )
57
+#define EPROTO_INVALID_CHAP_IDENTIFIER ( EPROTO | EUNIQ_02 )
58
+#define EPROTO_INVALID_CHAP_CHALLENGE ( EPROTO | EUNIQ_03 )
59
+#define EPROTO_INVALID_CHAP_RESPONSE ( EPROTO | EUNIQ_04 )
60
+
48 61
 /** iSCSI initiator name (explicitly specified) */
49 62
 static char *iscsi_explicit_initiator_iqn;
50 63
 
@@ -671,7 +684,7 @@ static int iscsi_handle_chap_a_value ( struct iscsi_session *iscsi,
671 684
 	if ( strcmp ( value, "5" ) != 0 ) {
672 685
 		DBGC ( iscsi, "iSCSI %p got invalid CHAP algorithm \"%s\"\n",
673 686
 		       iscsi, value );
674
-		return -EPROTO;
687
+		return -EPROTO_INVALID_CHAP_ALGORITHM;
675 688
 	}
676 689
 
677 690
 	return 0;
@@ -695,7 +708,7 @@ static int iscsi_handle_chap_i_value ( struct iscsi_session *iscsi,
695 708
 	if ( *endp != '\0' ) {
696 709
 		DBGC ( iscsi, "iSCSI %p saw invalid CHAP identifier \"%s\"\n",
697 710
 		       iscsi, value );
698
-		return -EPROTO;
711
+		return -EPROTO_INVALID_CHAP_IDENTIFIER;
699 712
 	}
700 713
 
701 714
 	/* Prepare for CHAP with MD5 */
@@ -736,7 +749,7 @@ static int iscsi_handle_chap_c_value ( struct iscsi_session *iscsi,
736 749
 	if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
737 750
 		DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge \"%s\"\n",
738 751
 		       iscsi, value );
739
-		return -EPROTO;
752
+		return -EPROTO_INVALID_CHAP_CHALLENGE;
740 753
 	}
741 754
 	value += 2;
742 755
 
@@ -748,7 +761,7 @@ static int iscsi_handle_chap_c_value ( struct iscsi_session *iscsi,
748 761
 		if ( *endp != '\0' ) {
749 762
 			DBGC ( iscsi, "iSCSI %p saw invalid CHAP challenge "
750 763
 			       "byte \"%s\"\n", iscsi, buf );
751
-			return -EPROTO;
764
+			return -EPROTO_INVALID_CHAP_CHALLENGE;
752 765
 		}
753 766
 		chap_update ( &iscsi->chap, &byte, sizeof ( byte ) );
754 767
 	}
@@ -793,7 +806,7 @@ static int iscsi_handle_chap_n_value ( struct iscsi_session *iscsi,
793 806
 		DBGC ( iscsi, "iSCSI %p target username \"%s\" incorrect "
794 807
 		       "(wanted \"%s\")\n",
795 808
 		       iscsi, value, iscsi->target_username );
796
-		return -EACCES;
809
+		return -EACCES_INCORRECT_TARGET_USERNAME;
797 810
 	}
798 811
 
799 812
 	return 0;
@@ -834,7 +847,7 @@ static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
834 847
 	if ( ( value[0] != '0' ) || ( value[1] != 'x' ) ) {
835 848
 		DBGC ( iscsi, "iSCSI %p saw invalid CHAP response \"%s\"\n",
836 849
 		       iscsi, value );
837
-		return -EPROTO;
850
+		return -EPROTO_INVALID_CHAP_RESPONSE;
838 851
 	}
839 852
 	value += 2;
840 853
 
@@ -842,7 +855,7 @@ static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
842 855
 	if ( strlen ( value ) != ( 2 * iscsi->chap.response_len ) ) {
843 856
 		DBGC ( iscsi, "iSCSI %p invalid CHAP response length\n",
844 857
 		       iscsi );
845
-		return -EPROTO;
858
+		return -EPROTO_INVALID_CHAP_RESPONSE;
846 859
 	}
847 860
 
848 861
 	/* Process response an octet at a time */
@@ -853,12 +866,12 @@ static int iscsi_handle_chap_r_value ( struct iscsi_session *iscsi,
853 866
 		if ( *endp != '\0' ) {
854 867
 			DBGC ( iscsi, "iSCSI %p saw invalid CHAP response "
855 868
 			       "byte \"%s\"\n", iscsi, buf );
856
-			return -EPROTO;
869
+			return -EPROTO_INVALID_CHAP_RESPONSE;
857 870
 		}
858 871
 		if ( byte != iscsi->chap.response[i] ) {
859 872
 			DBGC ( iscsi, "iSCSI %p saw incorrect CHAP "
860 873
 			       "response\n", iscsi );
861
-			return -EACCES;
874
+			return -EACCES_INCORRECT_TARGET_PASSWORD;
862 875
 		}
863 876
 	}
864 877
 	assert ( i == iscsi->chap.response_len );
@@ -999,14 +1012,14 @@ static int iscsi_status_to_rc ( unsigned int status_class,
999 1012
 	case ISCSI_STATUS_INITIATOR_ERROR :
1000 1013
 		switch ( status_detail ) {
1001 1014
 		case ISCSI_STATUS_INITIATOR_ERROR_AUTHENTICATION :
1002
-			return -EACCES;
1015
+			return -EPERM_INITIATOR_AUTHENTICATION;
1003 1016
 		case ISCSI_STATUS_INITIATOR_ERROR_AUTHORISATION :
1004
-			return -EPERM;
1017
+			return -EPERM_INITIATOR_AUTHORISATION;
1005 1018
 		case ISCSI_STATUS_INITIATOR_ERROR_NOT_FOUND :
1006 1019
 		case ISCSI_STATUS_INITIATOR_ERROR_REMOVED :
1007 1020
 			return -ENODEV;
1008 1021
 		default :
1009
-			return -ENOTSUP;
1022
+			return -ENOTSUP_INITIATOR_STATUS;
1010 1023
 		}
1011 1024
 	case ISCSI_STATUS_TARGET_ERROR :
1012 1025
 		return -EIO;
@@ -1374,7 +1387,7 @@ static int iscsi_rx_data ( struct iscsi_session *iscsi, const void *data,
1374 1387
 			return 0;
1375 1388
 		DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
1376 1389
 		       response->opcode );
1377
-		return -ENOTSUP;
1390
+		return -ENOTSUP_OPCODE;
1378 1391
 	}
1379 1392
 }
1380 1393
 
@@ -1757,7 +1770,7 @@ int iscsi_attach ( struct scsi_device *scsi, const char *root_path ) {
1757 1770
 	if ( ! iscsi->target_address ) {
1758 1771
 		DBGC ( iscsi, "iSCSI %p does not yet support discovery\n",
1759 1772
 		       iscsi );
1760
-		rc = -ENOTSUP;
1773
+		rc = -ENOTSUP_DISCOVERY;
1761 1774
 		goto err;
1762 1775
 	}
1763 1776
 	if ( ! iscsi->target_iqn ) {

Loading…
Отказ
Запис