21 #include <linux/slab.h>
46 rx_got =
rx_data(conn, &iov, 1, length);
47 if (rx_got != length) {
48 pr_err(
"rx_data returned %d, expecting %d.\n",
80 tx_sent =
tx_data(conn, &iov[0], 2, length);
81 if (tx_sent != length) {
82 pr_err(
"tx_data returned %d, expecting %d.\n",
96 pr_debug(
"MaxRecvDataSegmentLength: %u\n",
112 pr_debug(
"TargetPortalGroupTag: %hu\n",
122 pr_debug(
"DefaultTime2Retain: %hu\n",
124 pr_debug(
"MaxOutstandingR2T: %hu\n",
128 pr_debug(
"DataSequenceInOrder: %s\n",
130 pr_debug(
"ErrorRecoveryLevel: %hu\n",
133 "Discovery" :
"Normal");
152 pr_err(
"Unable to allocate memory for parameter.\n");
155 INIT_LIST_HEAD(¶m->
p_list);
159 pr_err(
"Unable to allocate memory for parameter name.\n");
165 pr_err(
"Unable to allocate memory for parameter value.\n");
210 pr_err(
"Unknown type_range 0x%02x\n",
235 pr_err(
"Unable to allocate memory for"
236 " struct iscsi_param_list.\n");
437 *param_list_ptr =
pl;
563 pr_err(
"Unable to allocate memory for struct iscsi_param_list.\n");
571 if ((
strcmp(param->
name,
"TargetName") != 0) &&
572 (
strcmp(param->
name,
"InitiatorName") != 0) &&
573 (
strcmp(param->
name,
"TargetPortalGroupTag") != 0))
579 pr_err(
"Unable to allocate memory for struct iscsi_param.\n");
585 if (!new_param->
value || !new_param->
name) {
589 pr_err(
"Unable to allocate memory for parameter name/value.\n");
598 new_param->
use = param->
use;
607 pr_err(
"No parameters allocated.\n");
618 static void iscsi_release_extra_responses(
struct iscsi_param_list *param_list)
645 iscsi_release_extra_responses(param_list);
656 if (!key || !param_list) {
657 pr_err(
"Key or parameter list pointer is NULL.\n");
666 pr_err(
"Unable to locate key \"%s\".\n", key);
672 *value =
strchr(textbuf,
'=');
674 pr_err(
"Unable to locate \"=\" separator for key,"
675 " ignoring request.\n");
692 pr_err(
"Unable to allocate memory for value.\n");
699 pr_debug(
"iSCSI Parameter updated to %s=%s\n",
704 static int iscsi_add_notunderstood_response(
712 pr_err(
"Value for notunderstood key \"%s\" exceeds %d,"
718 if (!extra_response) {
719 pr_err(
"Unable to allocate memory for"
720 " struct iscsi_extra_response.\n");
723 INIT_LIST_HEAD(&extra_response->
er_list);
734 static int iscsi_check_for_auth_key(
char *key)
756 static void iscsi_check_proposer_for_optional_reply(
struct iscsi_param *param)
797 static int iscsi_check_boolean_value(
struct iscsi_param *param,
char *value)
800 pr_err(
"Illegal value for \"%s\", must be either"
801 " \"%s\" or \"%s\".\n", param->
name,
YES,
NO);
808 static int iscsi_check_numerical_value(
struct iscsi_param *param,
char *value_ptr)
816 if ((value < 0) || (value > 2)) {
817 pr_err(
"Illegal value for \"%s\", must be"
818 " between 0 and 2.\n", param->
name);
824 if ((value < 0) || (value > 3600)) {
825 pr_err(
"Illegal value for \"%s\", must be"
826 " between 0 and 3600.\n", param->
name);
832 if ((value < 0) || (value > 32767)) {
833 pr_err(
"Illegal value for \"%s\", must be"
834 " between 0 and 32767.\n", param->
name);
840 if ((value < 0) || (value > 65535)) {
841 pr_err(
"Illegal value for \"%s\", must be"
842 " between 0 and 65535.\n", param->
name);
848 if ((value < 1) || (value > 65535)) {
849 pr_err(
"Illegal value for \"%s\", must be"
850 " between 1 and 65535.\n", param->
name);
856 if ((value < 2) || (value > 3600)) {
857 pr_err(
"Illegal value for \"%s\", must be"
858 " between 2 and 3600.\n", param->
name);
864 if ((value < 512) || (value > 16777215)) {
865 pr_err(
"Illegal value for \"%s\", must be"
866 " between 512 and 16777215.\n", param->
name);
875 static int iscsi_check_numerical_range_value(
struct iscsi_param *param,
char *value)
877 char *left_val_ptr =
NULL, *right_val_ptr =
NULL;
878 char *tilde_ptr =
NULL;
879 u32 left_val, right_val, local_left_val;
883 pr_err(
"Only parameters \"%s\" or \"%s\" may contain a"
891 tilde_ptr =
strchr(value,
'~');
893 pr_err(
"Unable to locate numerical range indicator"
894 " \"~\" for \"%s\".\n", param->
name);
899 left_val_ptr =
value;
900 right_val_ptr = value +
strlen(left_val_ptr) + 1;
902 if (iscsi_check_numerical_value(param, left_val_ptr) < 0)
904 if (iscsi_check_numerical_value(param, right_val_ptr) < 0)
911 if (right_val < left_val) {
912 pr_err(
"Numerical range for parameter \"%s\" contains"
913 " a right value which is less than the left.\n",
923 pr_err(
"Unable to locate numerical range indicator"
924 " \"~\" for \"%s\".\n", param->
name);
929 left_val_ptr = param->
value;
930 right_val_ptr = param->
value +
strlen(left_val_ptr) + 1;
936 if ((left_val < local_left_val) ||
937 (right_val < local_left_val)) {
938 pr_err(
"Passed value range \"%u~%u\" is below"
939 " minimum left value \"%u\" for key \"%s\","
940 " rejecting.\n", left_val, right_val,
941 local_left_val, param->
name);
945 if ((left_val < local_left_val) &&
946 (right_val < local_left_val)) {
947 pr_err(
"Received value range \"%u~%u\" is"
948 " below minimum left value \"%u\" for key"
949 " \"%s\", rejecting.\n", left_val, right_val,
950 local_left_val, param->
name);
960 static int iscsi_check_string_or_list_value(
struct iscsi_param *param,
char *value)
969 pr_err(
"Illegal value for \"%s\", must be"
970 " \"%s\", \"%s\", \"%s\", \"%s\", \"%s\""
978 pr_err(
"Illegal value for \"%s\", must be"
979 " \"%s\" or \"%s\".\n", param->
name,
986 pr_err(
"Illegal value for \"%s\", must be"
987 " \"%s\" or \"%s\".\n", param->
name,
1000 static char *iscsi_get_value_from_number_range(
1004 char *end_ptr, *tilde_ptr1 =
NULL, *tilde_ptr2 =
NULL;
1005 u32 acceptor_right_value, proposer_right_value;
1007 tilde_ptr1 =
strchr(value,
'~');
1010 *tilde_ptr1++ =
'\0';
1016 *tilde_ptr2++ =
'\0';
1019 return (acceptor_right_value >= proposer_right_value) ?
1020 tilde_ptr1 : tilde_ptr2;
1023 static char *iscsi_check_valuelist_for_support(
1028 char *acceptor_values =
NULL, *proposer_values =
NULL;
1030 acceptor_values = param->
value;
1031 proposer_values =
value;
1034 if (!proposer_values)
1036 tmp1 =
strchr(proposer_values,
',');
1039 acceptor_values = param->
value;
1041 if (!acceptor_values) {
1046 tmp2 =
strchr(acceptor_values,
',');
1049 if (!
strcmp(acceptor_values, proposer_values)) {
1057 acceptor_values = tmp2;
1058 }
while (acceptor_values);
1061 proposer_values =
tmp1;
1062 }
while (proposer_values);
1065 return proposer_values;
1068 static int iscsi_check_acceptor_state(
struct iscsi_param *param,
char *value,
1071 u8 acceptor_boolean_value = 0, proposer_boolean_value = 0;
1072 char *negoitated_value =
NULL;
1075 pr_err(
"Received key \"%s\" twice, protocol error.\n",
1085 proposer_boolean_value = 1;
1087 acceptor_boolean_value = 1;
1088 if (acceptor_boolean_value && proposer_boolean_value)
1093 if (!proposer_boolean_value)
1098 proposer_boolean_value = 1;
1100 acceptor_boolean_value = 1;
1101 if (acceptor_boolean_value || proposer_boolean_value) {
1104 if (proposer_boolean_value)
1108 char *tmpptr,
buf[10];
1120 if (proposer_value > acceptor_value) {
1121 sprintf(buf,
"%u", acceptor_value);
1130 if (acceptor_value > proposer_value) {
1131 sprintf(buf,
"%u", acceptor_value);
1146 unsigned long long tmp;
1154 pr_debug(
"Saving op->MaxRecvDataSegmentLength from"
1155 " original initiator received value: %u\n",
1156 conn->
conn_ops->MaxRecvDataSegmentLength);
1165 param_mxdsl->
value);
1169 pr_debug(
"Updated %s to target MXDSL value: %s\n",
1174 negoitated_value = iscsi_get_value_from_number_range(
1176 if (!negoitated_value)
1181 negoitated_value = iscsi_check_valuelist_for_support(
1183 if (!negoitated_value) {
1184 pr_err(
"Proposer's value list \"%s\" contains"
1185 " no valid values from Acceptor's value list"
1186 " \"%s\".\n", value, param->
value);
1200 static int iscsi_check_proposer_state(
struct iscsi_param *param,
char *value)
1203 pr_err(
"Received key \"%s\" twice, protocol error.\n",
1209 u32 left_val = 0, right_val = 0, recieved_value = 0;
1210 char *left_val_ptr =
NULL, *right_val_ptr =
NULL;
1211 char *tilde_ptr =
NULL;
1219 tilde_ptr =
strchr(value,
'~');
1221 pr_err(
"Illegal \"~\" in response for \"%s\".\n",
1227 pr_err(
"Unable to locate numerical range"
1228 " indicator \"~\" for \"%s\".\n", param->
name);
1233 left_val_ptr = param->
value;
1234 right_val_ptr = param->
value +
strlen(left_val_ptr) + 1;
1241 if ((recieved_value < left_val) ||
1242 (recieved_value > right_val)) {
1243 pr_err(
"Illegal response \"%s=%u\", value must"
1244 " be between %u and %u.\n", param->
name,
1245 recieved_value, left_val, right_val);
1249 char *comma_ptr =
NULL, *tmp_ptr =
NULL;
1251 comma_ptr =
strchr(value,
',');
1253 pr_err(
"Illegal \",\" in response for \"%s\".\n",
1258 tmp_ptr = iscsi_check_valuelist_for_support(param, value);
1269 static int iscsi_check_value(
struct iscsi_param *param,
char *value)
1271 char *comma_ptr =
NULL;
1283 pr_err(
"Received %s=%s\n", param->
name, value);
1293 pr_err(
"Received illegal offer %s=%s\n",
1294 param->
name, value);
1299 pr_err(
"Standard iSCSI key \"%s\" cannot be answered"
1300 " with \"%s\", protocol error.\n", param->
name, value);
1306 comma_ptr =
strchr(value,
',');
1309 pr_err(
"Detected value separator \",\", but"
1310 " key \"%s\" does not allow a value list,"
1311 " protocol error.\n", param->
name);
1318 pr_err(
"Value for key \"%s\" exceeds %d,"
1319 " protocol error.\n", param->
name,
1325 if (iscsi_check_boolean_value(param, value) < 0)
1328 if (iscsi_check_numerical_value(param, value) < 0)
1331 if (iscsi_check_numerical_range_value(param, value) < 0)
1334 if (iscsi_check_string_or_list_value(param, value) < 0)
1358 pr_err(
"Length of key name \"%s\" exceeds %d.\n",
1368 pr_err(
"Key \"%s\" may not be sent to %s,"
1369 " protocol error.\n", param->
name,
1375 pr_err(
"Key \"%s\" may not be sent to %s,"
1376 " protocol error.\n", param->
name,
1395 pr_err(
"Length of key name \"%s\" exceeds %d.\n",
1405 pr_err(
"Key \"%s\" may not be sent to %s,"
1406 " protocol error.\n", param->
name,
1411 pr_err(
"Key \"%s\" may not be sent to %s,"
1412 " protocol error.\n", param->
name,
1418 pr_err(
"Key \"%s\" received twice, protocol error.\n",
1426 if (!(param->
phase & phase)) {
1427 pr_err(
"Key \"%s\" may not be negotiated during ",
1444 static int iscsi_enforce_integrity_rules(
1449 u8 DataSequenceInOrder = 0;
1450 u8 ErrorRecoveryLevel = 0, SessionType = 0;
1451 u8 IFMarker = 0, OFMarker = 0;
1452 u8 IFMarkInt_Reject = 1, OFMarkInt_Reject = 1;
1453 u32 FirstBurstLength = 0, MaxBurstLength = 0;
1457 if (!(param->
phase & phase))
1467 DataSequenceInOrder = 1;
1479 IFMarkInt_Reject = 1;
1482 OFMarkInt_Reject = 1;
1486 if (!(param->
phase & phase))
1495 DataSequenceInOrder && (ErrorRecoveryLevel > 0)) {
1499 pr_debug(
"Reset \"%s\" to \"%s\".\n",
1507 pr_debug(
"Reset \"%s\" to \"%s\".\n",
1514 if (FirstBurstLength > MaxBurstLength) {
1517 sprintf(tmpbuf,
"%u", MaxBurstLength);
1520 pr_debug(
"Reset \"%s\" to \"%s\".\n",
1528 pr_debug(
"Reset \"%s\" to \"%s\".\n",
1535 pr_debug(
"Reset \"%s\" to \"%s\".\n",
1544 pr_debug(
"Reset \"%s\" to \"%s\".\n",
1553 pr_debug(
"Reset \"%s\" to \"%s\".\n",
1573 pr_err(
"Unable to allocate memory for tmpbuf.\n");
1577 memcpy(tmpbuf, textbuf, length);
1582 while (start < end) {
1591 pr_debug(
"Got key: %s=%s\n", key, value);
1594 if (iscsi_check_for_auth_key(key) > 0) {
1595 char *tmpptr = key +
strlen(key);
1602 param = iscsi_check_key(key, phase, sender, param_list);
1604 if (iscsi_add_notunderstood_response(key,
1605 value, param_list) < 0) {
1612 if (iscsi_check_value(param, value) < 0) {
1620 if (iscsi_check_proposer_state(param, value) < 0) {
1626 if (iscsi_check_acceptor_state(param, value, conn) < 0) {
1645 char *output_buf =
NULL;
1649 output_buf = textbuf + *
length;
1651 if (iscsi_enforce_integrity_rules(phase, param_list) < 0)
1655 if (!(param->
sender & sender))
1660 (param->
phase & phase)) {
1661 *length +=
sprintf(output_buf,
"%s=%s",
1664 output_buf = textbuf + *
length;
1673 (param->
phase & phase)) {
1674 *length +=
sprintf(output_buf,
"%s=%s",
1677 output_buf = textbuf + *
length;
1679 iscsi_check_proposer_for_optional_reply(param);
1688 output_buf = textbuf + *
length;
1691 iscsi_release_extra_responses(param_list);
1707 pr_err(
"No response for proposed key \"%s\".\n",
1729 param = __iscsi_check_key(keyvalue, sender, param_list);
1733 param = iscsi_check_key(keyvalue, 0, sender, param_list);
1738 if (iscsi_check_value(param, value) < 0) {
1758 pr_debug(
"---------------------------------------------------"
1759 "---------------\n");
1769 pr_debug(
"MaxXmitDataSegmentLength: %s\n",
1792 pr_debug(
"MaxRecvDataSegmentLength: %u\n",
1814 pr_debug(
"----------------------------------------------------"
1815 "--------------\n");
1826 pr_debug(
"----------------------------------------------------"
1827 "--------------\n");
1837 "%s", param->
value);
1845 "%s", param->
value);
1854 "%s", param->
value);
1861 "%s", param->
value);
1867 pr_debug(
"TargetPortalGroupTag: %s\n",
1900 pr_debug(
"DefaultTime2Retain: %s\n",
1905 pr_debug(
"MaxOutstandingR2T: %s\n",
1913 pr_debug(
"DataSequenceInOrder: %s\n",
1918 pr_debug(
"ErrorRecoveryLevel: %s\n",
1926 pr_debug(
"----------------------------------------------------"
1927 "--------------\n");