Changeset 22258 in vbox for trunk/src/VBox
- Timestamp:
- Aug 14, 2009 1:14:46 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/ISCSIHDDCore.cpp
r22256 r22258 456 456 static int iscsiTextGetKeyValue(const uint8_t *pbBuf, size_t cbBuf, const char *pcszKey, const char **ppcszValue); 457 457 static int iscsiStrToBinary(const char *pcszValue, uint8_t *pbValue, size_t *pcbValue); 458 static int iscsiUpdateParameters(PISCSIIMAGE pImage, const uint8_t *pbBuf, size_t cbBuf); 458 459 459 460 /* Serial number arithmetic comparison. */ … … 838 839 pImage->cbRecvDataLength = ISCSI_DATA_LENGTH_MAX; 839 840 pImage->cbSendDataLength = ISCSI_DATA_LENGTH_MAX; 840 char szMaxRecvDataSegmentLength[16]; 841 RTStrPrintf(szMaxRecvDataSegmentLength, sizeof(szMaxRecvDataSegmentLength), "%u", ISCSI_DATA_LENGTH_MAX); 842 char szMaxBurstLength[16]; 843 RTStrPrintf(szMaxBurstLength, sizeof(szMaxBurstLength), "%u", ISCSI_DATA_LENGTH_MAX); 844 char szFirstBurstLength[16]; 845 RTStrPrintf(szFirstBurstLength, sizeof(szFirstBurstLength), "%u", ISCSI_DATA_LENGTH_MAX); 841 char szMaxDataLength[16]; 842 RTStrPrintf(szMaxDataLength, sizeof(szMaxDataLength), "%u", ISCSI_DATA_LENGTH_MAX); 846 843 ISCSIPARAMETER aParameterNeg[] = 847 844 { … … 851 848 { "InitialR2T", "No", 0 }, 852 849 { "ImmediateData", "Yes", 0 }, 853 { "MaxRecvDataSegmentLength", szMax RecvDataSegmentLength, 0 },854 { "MaxBurstLength", szMax BurstLength, 0 },855 { "FirstBurstLength", sz FirstBurstLength, 0 },850 { "MaxRecvDataSegmentLength", szMaxDataLength, 0 }, 851 { "MaxBurstLength", szMaxDataLength, 0 }, 852 { "FirstBurstLength", szMaxDataLength, 0 }, 856 853 { "DefaultTime2Wait", "0", 0 }, 857 854 { "DefaultTime2Retain", "60", 0 }, … … 1044 1041 { 1045 1042 case 0x0000: /* security negotiation, step 0: receive final authentication. */ 1043 rc = iscsiUpdateParameters(pImage, bBuf, aISCSIRes[1].cbSeg); 1044 if (RT_FAILURE(rc)) 1045 break; 1046 1046 1047 const char *pcszAuthMethod; 1047 1048 … … 1072 1073 break; 1073 1074 case 0x0001: /* security negotiation, step 1: receive final CHAP variant and challenge. */ 1075 rc = iscsiUpdateParameters(pImage, bBuf, aISCSIRes[1].cbSeg); 1076 if (RT_FAILURE(rc)) 1077 break; 1078 1074 1079 const char *pcszChapAuthMethod; 1075 1080 const char *pcszChapIdxTarget; … … 1113 1118 break; 1114 1119 case 0x0002: /* security negotiation, step 2: check authentication success. */ 1120 rc = iscsiUpdateParameters(pImage, bBuf, aISCSIRes[1].cbSeg); 1121 if (RT_FAILURE(rc)) 1122 break; 1123 1115 1124 if (targetCSG == 0 && targetNSG == 1 && targetTransit) 1116 1125 { … … 1124 1133 break; 1125 1134 case 0x0100: /* login operational negotiation, step 0: check results. */ 1126 { 1127 const char *pcszMaxRecvDataSegmentLength = NULL; 1128 const char *pcszMaxBurstLength = NULL; 1129 const char *pcszFirstBurstLength = NULL; 1130 rc = iscsiTextGetKeyValue(bBuf, aISCSIRes[1].cbSeg, "MaxRecvDataSegmentLength", &pcszMaxRecvDataSegmentLength); 1131 if (rc == VERR_INVALID_NAME) 1132 rc = VINF_SUCCESS; 1135 rc = iscsiUpdateParameters(pImage, bBuf, aISCSIRes[1].cbSeg); 1133 1136 if (RT_FAILURE(rc)) 1134 {1135 rc = VERR_PARSE_ERROR;1136 1137 break; 1137 }1138 if (pcszMaxRecvDataSegmentLength && strlen(pcszMaxRecvDataSegmentLength) >= sizeof(szMaxRecvDataSegmentLength))1139 {1140 rc = VERR_BUFFER_OVERFLOW;1141 break;1142 }1143 rc = iscsiTextGetKeyValue(bBuf, aISCSIRes[1].cbSeg, "MaxBurstLength", &pcszMaxBurstLength);1144 if (rc == VERR_INVALID_NAME)1145 rc = VINF_SUCCESS;1146 if (RT_FAILURE(rc))1147 {1148 rc = VERR_PARSE_ERROR;1149 break;1150 }1151 if (pcszMaxBurstLength && strlen(pcszMaxBurstLength) >= sizeof(szMaxBurstLength))1152 {1153 rc = VERR_BUFFER_OVERFLOW;1154 break;1155 }1156 rc = iscsiTextGetKeyValue(bBuf, aISCSIRes[1].cbSeg, "FirstBurstLength", &pcszFirstBurstLength);1157 if (rc == VERR_INVALID_NAME)1158 rc = VINF_SUCCESS;1159 if (RT_FAILURE(rc))1160 {1161 rc = VERR_PARSE_ERROR;1162 break;1163 }1164 if (pcszFirstBurstLength && strlen(pcszFirstBurstLength) >= sizeof(szFirstBurstLength))1165 {1166 rc = VERR_BUFFER_OVERFLOW;1167 break;1168 }1169 if (pcszMaxRecvDataSegmentLength)1170 {1171 uint32_t cb = pImage->cbSendDataLength;1172 rc = RTStrToUInt32Full(pcszMaxRecvDataSegmentLength, 0, &cb);1173 AssertRC(rc);1174 pImage->cbSendDataLength = RT_MIN(pImage->cbSendDataLength, cb);1175 }1176 if (pcszMaxBurstLength)1177 {1178 uint32_t cb = pImage->cbSendDataLength;1179 rc = RTStrToUInt32Full(pcszMaxBurstLength, 0, &cb);1180 AssertRC(rc);1181 pImage->cbSendDataLength = RT_MIN(pImage->cbSendDataLength, cb);1182 }1183 if (pcszFirstBurstLength)1184 {1185 uint32_t cb = pImage->cbSendDataLength;1186 rc = RTStrToUInt32Full(pcszFirstBurstLength, 0, &cb);1187 AssertRC(rc);1188 pImage->cbSendDataLength = RT_MIN(pImage->cbSendDataLength, cb);1189 }1190 1138 1191 1139 if (targetCSG == 1 && targetNSG == 3 && targetTransit) … … 1207 1155 rc = VERR_PARSE_ERROR; 1208 1156 break; 1209 }1210 1157 case 0x0300: /* full feature phase. */ 1211 1158 default: … … 2116 2063 default: 2117 2064 return VERR_PARSE_ERROR; 2065 } 2066 return VINF_SUCCESS; 2067 } 2068 2069 2070 /** 2071 * Retrieve the relevant parameter values and update the initiator state. 2072 * 2073 * @returns VBOX status. 2074 * @param pImage Current iSCSI initiator state. 2075 * @param pbBuf Buffer containing key=value pairs. 2076 * @param cbBuf Length of buffer with key=value pairs. 2077 */ 2078 static int iscsiUpdateParameters(PISCSIIMAGE pImage, const uint8_t *pbBuf, size_t cbBuf) 2079 { 2080 int rc; 2081 const char *pcszMaxRecvDataSegmentLength = NULL; 2082 const char *pcszMaxBurstLength = NULL; 2083 const char *pcszFirstBurstLength = NULL; 2084 rc = iscsiTextGetKeyValue(pbBuf, cbBuf, "MaxRecvDataSegmentLength", &pcszMaxRecvDataSegmentLength); 2085 if (rc == VERR_INVALID_NAME) 2086 rc = VINF_SUCCESS; 2087 if (RT_FAILURE(rc)) 2088 return VERR_PARSE_ERROR; 2089 rc = iscsiTextGetKeyValue(pbBuf, cbBuf, "MaxBurstLength", &pcszMaxBurstLength); 2090 if (rc == VERR_INVALID_NAME) 2091 rc = VINF_SUCCESS; 2092 if (RT_FAILURE(rc)) 2093 return VERR_PARSE_ERROR; 2094 rc = iscsiTextGetKeyValue(pbBuf, cbBuf, "FirstBurstLength", &pcszFirstBurstLength); 2095 if (rc == VERR_INVALID_NAME) 2096 rc = VINF_SUCCESS; 2097 if (RT_FAILURE(rc)) 2098 return VERR_PARSE_ERROR; 2099 if (pcszMaxRecvDataSegmentLength) 2100 { 2101 uint32_t cb = pImage->cbSendDataLength; 2102 rc = RTStrToUInt32Full(pcszMaxRecvDataSegmentLength, 0, &cb); 2103 AssertRC(rc); 2104 pImage->cbSendDataLength = RT_MIN(pImage->cbSendDataLength, cb); 2105 } 2106 if (pcszMaxBurstLength) 2107 { 2108 uint32_t cb = pImage->cbSendDataLength; 2109 rc = RTStrToUInt32Full(pcszMaxBurstLength, 0, &cb); 2110 AssertRC(rc); 2111 pImage->cbSendDataLength = RT_MIN(pImage->cbSendDataLength, cb); 2112 } 2113 if (pcszFirstBurstLength) 2114 { 2115 uint32_t cb = pImage->cbSendDataLength; 2116 rc = RTStrToUInt32Full(pcszFirstBurstLength, 0, &cb); 2117 AssertRC(rc); 2118 pImage->cbSendDataLength = RT_MIN(pImage->cbSendDataLength, cb); 2118 2119 } 2119 2120 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.