1 /*******************************************************************************
2 * This file contains main functions related to iSCSI Parameter negotiation.
4 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
6 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
8 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 ******************************************************************************/
21 #include <linux/slab.h>
23 #include "iscsi_target_core.h"
24 #include "iscsi_target_util.h"
25 #include "iscsi_target_parameters.h"
27 int iscsi_login_rx_data(
28 struct iscsi_conn *conn,
35 memset(&iov, 0, sizeof(struct kvec));
40 * Initial Marker-less Interval.
41 * Add the values regardless of IFMarker/OFMarker, considering
42 * it may not be negoitated yet.
44 conn->of_marker += length;
46 rx_got = rx_data(conn, &iov, 1, length);
47 if (rx_got != length) {
48 pr_err("rx_data returned %d, expecting %d.\n",
56 int iscsi_login_tx_data(
57 struct iscsi_conn *conn,
62 int length, tx_sent, iov_cnt = 1;
65 length = (ISCSI_HDR_LEN + text_length);
67 memset(&iov[0], 0, 2 * sizeof(struct kvec));
68 iov[0].iov_len = ISCSI_HDR_LEN;
69 iov[0].iov_base = pdu_buf;
71 if (text_buf && text_length) {
72 iov[1].iov_len = text_length;
73 iov[1].iov_base = text_buf;
78 * Initial Marker-less Interval.
79 * Add the values regardless of IFMarker/OFMarker, considering
80 * it may not be negoitated yet.
82 conn->if_marker += length;
84 tx_sent = tx_data(conn, &iov[0], iov_cnt, length);
85 if (tx_sent != length) {
86 pr_err("tx_data returned %d, expecting %d.\n",
94 void iscsi_dump_conn_ops(struct iscsi_conn_ops *conn_ops)
96 pr_debug("HeaderDigest: %s\n", (conn_ops->HeaderDigest) ?
98 pr_debug("DataDigest: %s\n", (conn_ops->DataDigest) ?
100 pr_debug("MaxRecvDataSegmentLength: %u\n",
101 conn_ops->MaxRecvDataSegmentLength);
102 pr_debug("OFMarker: %s\n", (conn_ops->OFMarker) ? "Yes" : "No");
103 pr_debug("IFMarker: %s\n", (conn_ops->IFMarker) ? "Yes" : "No");
104 if (conn_ops->OFMarker)
105 pr_debug("OFMarkInt: %u\n", conn_ops->OFMarkInt);
106 if (conn_ops->IFMarker)
107 pr_debug("IFMarkInt: %u\n", conn_ops->IFMarkInt);
110 void iscsi_dump_sess_ops(struct iscsi_sess_ops *sess_ops)
112 pr_debug("InitiatorName: %s\n", sess_ops->InitiatorName);
113 pr_debug("InitiatorAlias: %s\n", sess_ops->InitiatorAlias);
114 pr_debug("TargetName: %s\n", sess_ops->TargetName);
115 pr_debug("TargetAlias: %s\n", sess_ops->TargetAlias);
116 pr_debug("TargetPortalGroupTag: %hu\n",
117 sess_ops->TargetPortalGroupTag);
118 pr_debug("MaxConnections: %hu\n", sess_ops->MaxConnections);
119 pr_debug("InitialR2T: %s\n",
120 (sess_ops->InitialR2T) ? "Yes" : "No");
121 pr_debug("ImmediateData: %s\n", (sess_ops->ImmediateData) ?
123 pr_debug("MaxBurstLength: %u\n", sess_ops->MaxBurstLength);
124 pr_debug("FirstBurstLength: %u\n", sess_ops->FirstBurstLength);
125 pr_debug("DefaultTime2Wait: %hu\n", sess_ops->DefaultTime2Wait);
126 pr_debug("DefaultTime2Retain: %hu\n",
127 sess_ops->DefaultTime2Retain);
128 pr_debug("MaxOutstandingR2T: %hu\n",
129 sess_ops->MaxOutstandingR2T);
130 pr_debug("DataPDUInOrder: %s\n",
131 (sess_ops->DataPDUInOrder) ? "Yes" : "No");
132 pr_debug("DataSequenceInOrder: %s\n",
133 (sess_ops->DataSequenceInOrder) ? "Yes" : "No");
134 pr_debug("ErrorRecoveryLevel: %hu\n",
135 sess_ops->ErrorRecoveryLevel);
136 pr_debug("SessionType: %s\n", (sess_ops->SessionType) ?
137 "Discovery" : "Normal");
140 void iscsi_print_params(struct iscsi_param_list *param_list)
142 struct iscsi_param *param;
144 list_for_each_entry(param, ¶m_list->param_list, p_list)
145 pr_debug("%s: %s\n", param->name, param->value);
148 static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *param_list,
149 char *name, char *value, u8 phase, u8 scope, u8 sender,
150 u16 type_range, u8 use)
152 struct iscsi_param *param = NULL;
154 param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
156 pr_err("Unable to allocate memory for parameter.\n");
159 INIT_LIST_HEAD(¶m->p_list);
161 param->name = kstrdup(name, GFP_KERNEL);
163 pr_err("Unable to allocate memory for parameter name.\n");
167 param->value = kstrdup(value, GFP_KERNEL);
169 pr_err("Unable to allocate memory for parameter value.\n");
173 param->phase = phase;
174 param->scope = scope;
175 param->sender = sender;
177 param->type_range = type_range;
179 switch (param->type_range) {
180 case TYPERANGE_BOOL_AND:
181 param->type = TYPE_BOOL_AND;
183 case TYPERANGE_BOOL_OR:
184 param->type = TYPE_BOOL_OR;
186 case TYPERANGE_0_TO_2:
187 case TYPERANGE_0_TO_3600:
188 case TYPERANGE_0_TO_32767:
189 case TYPERANGE_0_TO_65535:
190 case TYPERANGE_1_TO_65535:
191 case TYPERANGE_2_TO_3600:
192 case TYPERANGE_512_TO_16777215:
193 param->type = TYPE_NUMBER;
196 case TYPERANGE_DIGEST:
197 param->type = TYPE_VALUE_LIST | TYPE_STRING;
199 case TYPERANGE_MARKINT:
200 param->type = TYPE_NUMBER_RANGE;
201 param->type_range |= TYPERANGE_1_TO_65535;
203 case TYPERANGE_ISCSINAME:
204 case TYPERANGE_SESSIONTYPE:
205 case TYPERANGE_TARGETADDRESS:
207 param->type = TYPE_STRING;
210 pr_err("Unknown type_range 0x%02x\n",
214 list_add_tail(¶m->p_list, ¶m_list->param_list);
227 /* #warning Add extension keys */
228 int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)
230 struct iscsi_param *param = NULL;
231 struct iscsi_param_list *pl;
233 pl = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL);
235 pr_err("Unable to allocate memory for"
236 " struct iscsi_param_list.\n");
239 INIT_LIST_HEAD(&pl->param_list);
240 INIT_LIST_HEAD(&pl->extra_response_list);
243 * The format for setting the initial parameter definitions are:
253 param = iscsi_set_default_param(pl, AUTHMETHOD, INITIAL_AUTHMETHOD,
254 PHASE_SECURITY, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
255 TYPERANGE_AUTH, USE_INITIAL_ONLY);
259 param = iscsi_set_default_param(pl, HEADERDIGEST, INITIAL_HEADERDIGEST,
260 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
261 TYPERANGE_DIGEST, USE_INITIAL_ONLY);
265 param = iscsi_set_default_param(pl, DATADIGEST, INITIAL_DATADIGEST,
266 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
267 TYPERANGE_DIGEST, USE_INITIAL_ONLY);
271 param = iscsi_set_default_param(pl, MAXCONNECTIONS,
272 INITIAL_MAXCONNECTIONS, PHASE_OPERATIONAL,
273 SCOPE_SESSION_WIDE, SENDER_BOTH,
274 TYPERANGE_1_TO_65535, USE_LEADING_ONLY);
278 param = iscsi_set_default_param(pl, SENDTARGETS, INITIAL_SENDTARGETS,
279 PHASE_FFP0, SCOPE_SESSION_WIDE, SENDER_INITIATOR,
284 param = iscsi_set_default_param(pl, TARGETNAME, INITIAL_TARGETNAME,
285 PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_BOTH,
286 TYPERANGE_ISCSINAME, USE_ALL);
290 param = iscsi_set_default_param(pl, INITIATORNAME,
291 INITIAL_INITIATORNAME, PHASE_DECLARATIVE,
292 SCOPE_SESSION_WIDE, SENDER_INITIATOR,
293 TYPERANGE_ISCSINAME, USE_INITIAL_ONLY);
297 param = iscsi_set_default_param(pl, TARGETALIAS, INITIAL_TARGETALIAS,
298 PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_TARGET,
299 TYPERANGE_UTF8, USE_ALL);
303 param = iscsi_set_default_param(pl, INITIATORALIAS,
304 INITIAL_INITIATORALIAS, PHASE_DECLARATIVE,
305 SCOPE_SESSION_WIDE, SENDER_INITIATOR, TYPERANGE_UTF8,
310 param = iscsi_set_default_param(pl, TARGETADDRESS,
311 INITIAL_TARGETADDRESS, PHASE_DECLARATIVE,
312 SCOPE_SESSION_WIDE, SENDER_TARGET,
313 TYPERANGE_TARGETADDRESS, USE_ALL);
317 param = iscsi_set_default_param(pl, TARGETPORTALGROUPTAG,
318 INITIAL_TARGETPORTALGROUPTAG,
319 PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_TARGET,
320 TYPERANGE_0_TO_65535, USE_INITIAL_ONLY);
324 param = iscsi_set_default_param(pl, INITIALR2T, INITIAL_INITIALR2T,
325 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
326 TYPERANGE_BOOL_OR, USE_LEADING_ONLY);
330 param = iscsi_set_default_param(pl, IMMEDIATEDATA,
331 INITIAL_IMMEDIATEDATA, PHASE_OPERATIONAL,
332 SCOPE_SESSION_WIDE, SENDER_BOTH, TYPERANGE_BOOL_AND,
337 param = iscsi_set_default_param(pl, MAXXMITDATASEGMENTLENGTH,
338 INITIAL_MAXXMITDATASEGMENTLENGTH,
339 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
340 TYPERANGE_512_TO_16777215, USE_ALL);
344 param = iscsi_set_default_param(pl, MAXRECVDATASEGMENTLENGTH,
345 INITIAL_MAXRECVDATASEGMENTLENGTH,
346 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
347 TYPERANGE_512_TO_16777215, USE_ALL);
351 param = iscsi_set_default_param(pl, MAXBURSTLENGTH,
352 INITIAL_MAXBURSTLENGTH, PHASE_OPERATIONAL,
353 SCOPE_SESSION_WIDE, SENDER_BOTH,
354 TYPERANGE_512_TO_16777215, USE_LEADING_ONLY);
358 param = iscsi_set_default_param(pl, FIRSTBURSTLENGTH,
359 INITIAL_FIRSTBURSTLENGTH,
360 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
361 TYPERANGE_512_TO_16777215, USE_LEADING_ONLY);
365 param = iscsi_set_default_param(pl, DEFAULTTIME2WAIT,
366 INITIAL_DEFAULTTIME2WAIT,
367 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
368 TYPERANGE_0_TO_3600, USE_LEADING_ONLY);
372 param = iscsi_set_default_param(pl, DEFAULTTIME2RETAIN,
373 INITIAL_DEFAULTTIME2RETAIN,
374 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
375 TYPERANGE_0_TO_3600, USE_LEADING_ONLY);
379 param = iscsi_set_default_param(pl, MAXOUTSTANDINGR2T,
380 INITIAL_MAXOUTSTANDINGR2T,
381 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
382 TYPERANGE_1_TO_65535, USE_LEADING_ONLY);
386 param = iscsi_set_default_param(pl, DATAPDUINORDER,
387 INITIAL_DATAPDUINORDER, PHASE_OPERATIONAL,
388 SCOPE_SESSION_WIDE, SENDER_BOTH, TYPERANGE_BOOL_OR,
393 param = iscsi_set_default_param(pl, DATASEQUENCEINORDER,
394 INITIAL_DATASEQUENCEINORDER,
395 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
396 TYPERANGE_BOOL_OR, USE_LEADING_ONLY);
400 param = iscsi_set_default_param(pl, ERRORRECOVERYLEVEL,
401 INITIAL_ERRORRECOVERYLEVEL,
402 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
403 TYPERANGE_0_TO_2, USE_LEADING_ONLY);
407 param = iscsi_set_default_param(pl, SESSIONTYPE, INITIAL_SESSIONTYPE,
408 PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_INITIATOR,
409 TYPERANGE_SESSIONTYPE, USE_LEADING_ONLY);
413 param = iscsi_set_default_param(pl, IFMARKER, INITIAL_IFMARKER,
414 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
415 TYPERANGE_BOOL_AND, USE_INITIAL_ONLY);
419 param = iscsi_set_default_param(pl, OFMARKER, INITIAL_OFMARKER,
420 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
421 TYPERANGE_BOOL_AND, USE_INITIAL_ONLY);
425 param = iscsi_set_default_param(pl, IFMARKINT, INITIAL_IFMARKINT,
426 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
427 TYPERANGE_MARKINT, USE_INITIAL_ONLY);
431 param = iscsi_set_default_param(pl, OFMARKINT, INITIAL_OFMARKINT,
432 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
433 TYPERANGE_MARKINT, USE_INITIAL_ONLY);
437 * Extra parameters for ISER from RFC-5046
439 param = iscsi_set_default_param(pl, RDMAEXTENTIONS, INITIAL_RDMAEXTENTIONS,
440 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
441 TYPERANGE_BOOL_AND, USE_LEADING_ONLY);
445 param = iscsi_set_default_param(pl, INITIATORRECVDATASEGMENTLENGTH,
446 INITIAL_INITIATORRECVDATASEGMENTLENGTH,
447 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
448 TYPERANGE_512_TO_16777215, USE_ALL);
452 param = iscsi_set_default_param(pl, TARGETRECVDATASEGMENTLENGTH,
453 INITIAL_TARGETRECVDATASEGMENTLENGTH,
454 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
455 TYPERANGE_512_TO_16777215, USE_ALL);
459 *param_list_ptr = pl;
462 iscsi_release_param_list(pl);
466 int iscsi_set_keys_to_negotiate(
467 struct iscsi_param_list *param_list,
470 struct iscsi_param *param;
472 param_list->iser = iser;
474 list_for_each_entry(param, ¶m_list->param_list, p_list) {
476 if (!strcmp(param->name, AUTHMETHOD)) {
477 SET_PSTATE_NEGOTIATE(param);
478 } else if (!strcmp(param->name, HEADERDIGEST)) {
480 SET_PSTATE_NEGOTIATE(param);
481 } else if (!strcmp(param->name, DATADIGEST)) {
483 SET_PSTATE_NEGOTIATE(param);
484 } else if (!strcmp(param->name, MAXCONNECTIONS)) {
485 SET_PSTATE_NEGOTIATE(param);
486 } else if (!strcmp(param->name, TARGETNAME)) {
488 } else if (!strcmp(param->name, INITIATORNAME)) {
490 } else if (!strcmp(param->name, TARGETALIAS)) {
492 SET_PSTATE_NEGOTIATE(param);
493 } else if (!strcmp(param->name, INITIATORALIAS)) {
495 } else if (!strcmp(param->name, TARGETPORTALGROUPTAG)) {
496 SET_PSTATE_NEGOTIATE(param);
497 } else if (!strcmp(param->name, INITIALR2T)) {
498 SET_PSTATE_NEGOTIATE(param);
499 } else if (!strcmp(param->name, IMMEDIATEDATA)) {
500 SET_PSTATE_NEGOTIATE(param);
501 } else if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH)) {
503 SET_PSTATE_NEGOTIATE(param);
504 } else if (!strcmp(param->name, MAXXMITDATASEGMENTLENGTH)) {
506 } else if (!strcmp(param->name, MAXBURSTLENGTH)) {
507 SET_PSTATE_NEGOTIATE(param);
508 } else if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
509 SET_PSTATE_NEGOTIATE(param);
510 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
511 SET_PSTATE_NEGOTIATE(param);
512 } else if (!strcmp(param->name, DEFAULTTIME2RETAIN)) {
513 SET_PSTATE_NEGOTIATE(param);
514 } else if (!strcmp(param->name, MAXOUTSTANDINGR2T)) {
515 SET_PSTATE_NEGOTIATE(param);
516 } else if (!strcmp(param->name, DATAPDUINORDER)) {
517 SET_PSTATE_NEGOTIATE(param);
518 } else if (!strcmp(param->name, DATASEQUENCEINORDER)) {
519 SET_PSTATE_NEGOTIATE(param);
520 } else if (!strcmp(param->name, ERRORRECOVERYLEVEL)) {
521 SET_PSTATE_NEGOTIATE(param);
522 } else if (!strcmp(param->name, SESSIONTYPE)) {
523 SET_PSTATE_NEGOTIATE(param);
524 } else if (!strcmp(param->name, IFMARKER)) {
525 SET_PSTATE_NEGOTIATE(param);
526 } else if (!strcmp(param->name, OFMARKER)) {
527 SET_PSTATE_NEGOTIATE(param);
528 } else if (!strcmp(param->name, IFMARKINT)) {
529 SET_PSTATE_NEGOTIATE(param);
530 } else if (!strcmp(param->name, OFMARKINT)) {
531 SET_PSTATE_NEGOTIATE(param);
532 } else if (!strcmp(param->name, RDMAEXTENTIONS)) {
534 SET_PSTATE_NEGOTIATE(param);
535 } else if (!strcmp(param->name, INITIATORRECVDATASEGMENTLENGTH)) {
537 SET_PSTATE_NEGOTIATE(param);
538 } else if (!strcmp(param->name, TARGETRECVDATASEGMENTLENGTH)) {
540 SET_PSTATE_NEGOTIATE(param);
547 int iscsi_set_keys_irrelevant_for_discovery(
548 struct iscsi_param_list *param_list)
550 struct iscsi_param *param;
552 list_for_each_entry(param, ¶m_list->param_list, p_list) {
553 if (!strcmp(param->name, MAXCONNECTIONS))
554 param->state &= ~PSTATE_NEGOTIATE;
555 else if (!strcmp(param->name, INITIALR2T))
556 param->state &= ~PSTATE_NEGOTIATE;
557 else if (!strcmp(param->name, IMMEDIATEDATA))
558 param->state &= ~PSTATE_NEGOTIATE;
559 else if (!strcmp(param->name, MAXBURSTLENGTH))
560 param->state &= ~PSTATE_NEGOTIATE;
561 else if (!strcmp(param->name, FIRSTBURSTLENGTH))
562 param->state &= ~PSTATE_NEGOTIATE;
563 else if (!strcmp(param->name, MAXOUTSTANDINGR2T))
564 param->state &= ~PSTATE_NEGOTIATE;
565 else if (!strcmp(param->name, DATAPDUINORDER))
566 param->state &= ~PSTATE_NEGOTIATE;
567 else if (!strcmp(param->name, DATASEQUENCEINORDER))
568 param->state &= ~PSTATE_NEGOTIATE;
569 else if (!strcmp(param->name, ERRORRECOVERYLEVEL))
570 param->state &= ~PSTATE_NEGOTIATE;
571 else if (!strcmp(param->name, DEFAULTTIME2WAIT))
572 param->state &= ~PSTATE_NEGOTIATE;
573 else if (!strcmp(param->name, DEFAULTTIME2RETAIN))
574 param->state &= ~PSTATE_NEGOTIATE;
575 else if (!strcmp(param->name, IFMARKER))
576 param->state &= ~PSTATE_NEGOTIATE;
577 else if (!strcmp(param->name, OFMARKER))
578 param->state &= ~PSTATE_NEGOTIATE;
579 else if (!strcmp(param->name, IFMARKINT))
580 param->state &= ~PSTATE_NEGOTIATE;
581 else if (!strcmp(param->name, OFMARKINT))
582 param->state &= ~PSTATE_NEGOTIATE;
583 else if (!strcmp(param->name, RDMAEXTENTIONS))
584 param->state &= ~PSTATE_NEGOTIATE;
585 else if (!strcmp(param->name, INITIATORRECVDATASEGMENTLENGTH))
586 param->state &= ~PSTATE_NEGOTIATE;
587 else if (!strcmp(param->name, TARGETRECVDATASEGMENTLENGTH))
588 param->state &= ~PSTATE_NEGOTIATE;
594 int iscsi_copy_param_list(
595 struct iscsi_param_list **dst_param_list,
596 struct iscsi_param_list *src_param_list,
599 struct iscsi_param *param = NULL;
600 struct iscsi_param *new_param = NULL;
601 struct iscsi_param_list *param_list = NULL;
603 param_list = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL);
605 pr_err("Unable to allocate memory for struct iscsi_param_list.\n");
608 INIT_LIST_HEAD(¶m_list->param_list);
609 INIT_LIST_HEAD(¶m_list->extra_response_list);
611 list_for_each_entry(param, &src_param_list->param_list, p_list) {
612 if (!leading && (param->scope & SCOPE_SESSION_WIDE)) {
613 if ((strcmp(param->name, "TargetName") != 0) &&
614 (strcmp(param->name, "InitiatorName") != 0) &&
615 (strcmp(param->name, "TargetPortalGroupTag") != 0))
619 new_param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
621 pr_err("Unable to allocate memory for struct iscsi_param.\n");
625 new_param->name = kstrdup(param->name, GFP_KERNEL);
626 new_param->value = kstrdup(param->value, GFP_KERNEL);
627 if (!new_param->value || !new_param->name) {
628 kfree(new_param->value);
629 kfree(new_param->name);
631 pr_err("Unable to allocate memory for parameter name/value.\n");
635 new_param->set_param = param->set_param;
636 new_param->phase = param->phase;
637 new_param->scope = param->scope;
638 new_param->sender = param->sender;
639 new_param->type = param->type;
640 new_param->use = param->use;
641 new_param->type_range = param->type_range;
643 list_add_tail(&new_param->p_list, ¶m_list->param_list);
646 if (!list_empty(¶m_list->param_list)) {
647 *dst_param_list = param_list;
649 pr_err("No parameters allocated.\n");
656 iscsi_release_param_list(param_list);
660 static void iscsi_release_extra_responses(struct iscsi_param_list *param_list)
662 struct iscsi_extra_response *er, *er_tmp;
664 list_for_each_entry_safe(er, er_tmp, ¶m_list->extra_response_list,
666 list_del(&er->er_list);
671 void iscsi_release_param_list(struct iscsi_param_list *param_list)
673 struct iscsi_param *param, *param_tmp;
675 list_for_each_entry_safe(param, param_tmp, ¶m_list->param_list,
677 list_del(¶m->p_list);
684 iscsi_release_extra_responses(param_list);
689 struct iscsi_param *iscsi_find_param_from_key(
691 struct iscsi_param_list *param_list)
693 struct iscsi_param *param;
695 if (!key || !param_list) {
696 pr_err("Key or parameter list pointer is NULL.\n");
700 list_for_each_entry(param, ¶m_list->param_list, p_list) {
701 if (!strcmp(key, param->name))
705 pr_err("Unable to locate key \"%s\".\n", key);
709 int iscsi_extract_key_value(char *textbuf, char **key, char **value)
711 *value = strchr(textbuf, '=');
713 pr_err("Unable to locate \"=\" separator for key,"
714 " ignoring request.\n");
725 int iscsi_update_param_value(struct iscsi_param *param, char *value)
729 param->value = kstrdup(value, GFP_KERNEL);
731 pr_err("Unable to allocate memory for value.\n");
735 pr_debug("iSCSI Parameter updated to %s=%s\n",
736 param->name, param->value);
740 static int iscsi_add_notunderstood_response(
743 struct iscsi_param_list *param_list)
745 struct iscsi_extra_response *extra_response;
747 if (strlen(value) > VALUE_MAXLEN) {
748 pr_err("Value for notunderstood key \"%s\" exceeds %d,"
749 " protocol error.\n", key, VALUE_MAXLEN);
753 extra_response = kzalloc(sizeof(struct iscsi_extra_response), GFP_KERNEL);
754 if (!extra_response) {
755 pr_err("Unable to allocate memory for"
756 " struct iscsi_extra_response.\n");
759 INIT_LIST_HEAD(&extra_response->er_list);
761 strncpy(extra_response->key, key, strlen(key) + 1);
762 strncpy(extra_response->value, NOTUNDERSTOOD,
763 strlen(NOTUNDERSTOOD) + 1);
765 list_add_tail(&extra_response->er_list,
766 ¶m_list->extra_response_list);
770 static int iscsi_check_for_auth_key(char *key)
775 if (!strcmp(key, "CHAP_A") || !strcmp(key, "CHAP_I") ||
776 !strcmp(key, "CHAP_C") || !strcmp(key, "CHAP_N") ||
777 !strcmp(key, "CHAP_R"))
783 if (!strcmp(key, "SRP_U") || !strcmp(key, "SRP_N") ||
784 !strcmp(key, "SRP_g") || !strcmp(key, "SRP_s") ||
785 !strcmp(key, "SRP_A") || !strcmp(key, "SRP_B") ||
786 !strcmp(key, "SRP_M") || !strcmp(key, "SRP_HM"))
792 static void iscsi_check_proposer_for_optional_reply(struct iscsi_param *param)
794 if (IS_TYPE_BOOL_AND(param)) {
795 if (!strcmp(param->value, NO))
796 SET_PSTATE_REPLY_OPTIONAL(param);
797 } else if (IS_TYPE_BOOL_OR(param)) {
798 if (!strcmp(param->value, YES))
799 SET_PSTATE_REPLY_OPTIONAL(param);
801 * Required for gPXE iSCSI boot client
803 if (!strcmp(param->name, IMMEDIATEDATA))
804 SET_PSTATE_REPLY_OPTIONAL(param);
805 } else if (IS_TYPE_NUMBER(param)) {
806 if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH))
807 SET_PSTATE_REPLY_OPTIONAL(param);
809 * The GlobalSAN iSCSI Initiator for MacOSX does
810 * not respond to MaxBurstLength, FirstBurstLength,
811 * DefaultTime2Wait or DefaultTime2Retain parameter keys.
812 * So, we set them to 'reply optional' here, and assume the
813 * the defaults from iscsi_parameters.h if the initiator
814 * is not RFC compliant and the keys are not negotiated.
816 if (!strcmp(param->name, MAXBURSTLENGTH))
817 SET_PSTATE_REPLY_OPTIONAL(param);
818 if (!strcmp(param->name, FIRSTBURSTLENGTH))
819 SET_PSTATE_REPLY_OPTIONAL(param);
820 if (!strcmp(param->name, DEFAULTTIME2WAIT))
821 SET_PSTATE_REPLY_OPTIONAL(param);
822 if (!strcmp(param->name, DEFAULTTIME2RETAIN))
823 SET_PSTATE_REPLY_OPTIONAL(param);
825 * Required for gPXE iSCSI boot client
827 if (!strcmp(param->name, MAXCONNECTIONS))
828 SET_PSTATE_REPLY_OPTIONAL(param);
829 } else if (IS_PHASE_DECLARATIVE(param))
830 SET_PSTATE_REPLY_OPTIONAL(param);
833 static int iscsi_check_boolean_value(struct iscsi_param *param, char *value)
835 if (strcmp(value, YES) && strcmp(value, NO)) {
836 pr_err("Illegal value for \"%s\", must be either"
837 " \"%s\" or \"%s\".\n", param->name, YES, NO);
844 static int iscsi_check_numerical_value(struct iscsi_param *param, char *value_ptr)
849 value = simple_strtoul(value_ptr, &tmpptr, 0);
851 if (IS_TYPERANGE_0_TO_2(param)) {
852 if ((value < 0) || (value > 2)) {
853 pr_err("Illegal value for \"%s\", must be"
854 " between 0 and 2.\n", param->name);
859 if (IS_TYPERANGE_0_TO_3600(param)) {
860 if ((value < 0) || (value > 3600)) {
861 pr_err("Illegal value for \"%s\", must be"
862 " between 0 and 3600.\n", param->name);
867 if (IS_TYPERANGE_0_TO_32767(param)) {
868 if ((value < 0) || (value > 32767)) {
869 pr_err("Illegal value for \"%s\", must be"
870 " between 0 and 32767.\n", param->name);
875 if (IS_TYPERANGE_0_TO_65535(param)) {
876 if ((value < 0) || (value > 65535)) {
877 pr_err("Illegal value for \"%s\", must be"
878 " between 0 and 65535.\n", param->name);
883 if (IS_TYPERANGE_1_TO_65535(param)) {
884 if ((value < 1) || (value > 65535)) {
885 pr_err("Illegal value for \"%s\", must be"
886 " between 1 and 65535.\n", param->name);
891 if (IS_TYPERANGE_2_TO_3600(param)) {
892 if ((value < 2) || (value > 3600)) {
893 pr_err("Illegal value for \"%s\", must be"
894 " between 2 and 3600.\n", param->name);
899 if (IS_TYPERANGE_512_TO_16777215(param)) {
900 if ((value < 512) || (value > 16777215)) {
901 pr_err("Illegal value for \"%s\", must be"
902 " between 512 and 16777215.\n", param->name);
911 static int iscsi_check_numerical_range_value(struct iscsi_param *param, char *value)
913 char *left_val_ptr = NULL, *right_val_ptr = NULL;
914 char *tilde_ptr = NULL;
915 u32 left_val, right_val, local_left_val;
917 if (strcmp(param->name, IFMARKINT) &&
918 strcmp(param->name, OFMARKINT)) {
919 pr_err("Only parameters \"%s\" or \"%s\" may contain a"
920 " numerical range value.\n", IFMARKINT, OFMARKINT);
924 if (IS_PSTATE_PROPOSER(param))
927 tilde_ptr = strchr(value, '~');
929 pr_err("Unable to locate numerical range indicator"
930 " \"~\" for \"%s\".\n", param->name);
935 left_val_ptr = value;
936 right_val_ptr = value + strlen(left_val_ptr) + 1;
938 if (iscsi_check_numerical_value(param, left_val_ptr) < 0)
940 if (iscsi_check_numerical_value(param, right_val_ptr) < 0)
943 left_val = simple_strtoul(left_val_ptr, NULL, 0);
944 right_val = simple_strtoul(right_val_ptr, NULL, 0);
947 if (right_val < left_val) {
948 pr_err("Numerical range for parameter \"%s\" contains"
949 " a right value which is less than the left.\n",
955 * For now, enforce reasonable defaults for [I,O]FMarkInt.
957 tilde_ptr = strchr(param->value, '~');
959 pr_err("Unable to locate numerical range indicator"
960 " \"~\" for \"%s\".\n", param->name);
965 left_val_ptr = param->value;
966 right_val_ptr = param->value + strlen(left_val_ptr) + 1;
968 local_left_val = simple_strtoul(left_val_ptr, NULL, 0);
971 if (param->set_param) {
972 if ((left_val < local_left_val) ||
973 (right_val < local_left_val)) {
974 pr_err("Passed value range \"%u~%u\" is below"
975 " minimum left value \"%u\" for key \"%s\","
976 " rejecting.\n", left_val, right_val,
977 local_left_val, param->name);
981 if ((left_val < local_left_val) &&
982 (right_val < local_left_val)) {
983 pr_err("Received value range \"%u~%u\" is"
984 " below minimum left value \"%u\" for key"
985 " \"%s\", rejecting.\n", left_val, right_val,
986 local_left_val, param->name);
987 SET_PSTATE_REJECT(param);
988 if (iscsi_update_param_value(param, REJECT) < 0)
996 static int iscsi_check_string_or_list_value(struct iscsi_param *param, char *value)
998 if (IS_PSTATE_PROPOSER(param))
1001 if (IS_TYPERANGE_AUTH_PARAM(param)) {
1002 if (strcmp(value, KRB5) && strcmp(value, SPKM1) &&
1003 strcmp(value, SPKM2) && strcmp(value, SRP) &&
1004 strcmp(value, CHAP) && strcmp(value, NONE)) {
1005 pr_err("Illegal value for \"%s\", must be"
1006 " \"%s\", \"%s\", \"%s\", \"%s\", \"%s\""
1007 " or \"%s\".\n", param->name, KRB5,
1008 SPKM1, SPKM2, SRP, CHAP, NONE);
1012 if (IS_TYPERANGE_DIGEST_PARAM(param)) {
1013 if (strcmp(value, CRC32C) && strcmp(value, NONE)) {
1014 pr_err("Illegal value for \"%s\", must be"
1015 " \"%s\" or \"%s\".\n", param->name,
1020 if (IS_TYPERANGE_SESSIONTYPE(param)) {
1021 if (strcmp(value, DISCOVERY) && strcmp(value, NORMAL)) {
1022 pr_err("Illegal value for \"%s\", must be"
1023 " \"%s\" or \"%s\".\n", param->name,
1033 * This function is used to pick a value range number, currently just
1034 * returns the lesser of both right values.
1036 static char *iscsi_get_value_from_number_range(
1037 struct iscsi_param *param,
1040 char *end_ptr, *tilde_ptr1 = NULL, *tilde_ptr2 = NULL;
1041 u32 acceptor_right_value, proposer_right_value;
1043 tilde_ptr1 = strchr(value, '~');
1046 *tilde_ptr1++ = '\0';
1047 proposer_right_value = simple_strtoul(tilde_ptr1, &end_ptr, 0);
1049 tilde_ptr2 = strchr(param->value, '~');
1052 *tilde_ptr2++ = '\0';
1053 acceptor_right_value = simple_strtoul(tilde_ptr2, &end_ptr, 0);
1055 return (acceptor_right_value >= proposer_right_value) ?
1056 tilde_ptr1 : tilde_ptr2;
1059 static char *iscsi_check_valuelist_for_support(
1060 struct iscsi_param *param,
1063 char *tmp1 = NULL, *tmp2 = NULL;
1064 char *acceptor_values = NULL, *proposer_values = NULL;
1066 acceptor_values = param->value;
1067 proposer_values = value;
1070 if (!proposer_values)
1072 tmp1 = strchr(proposer_values, ',');
1075 acceptor_values = param->value;
1077 if (!acceptor_values) {
1082 tmp2 = strchr(acceptor_values, ',');
1085 if (!strcmp(acceptor_values, proposer_values)) {
1093 acceptor_values = tmp2;
1094 } while (acceptor_values);
1097 proposer_values = tmp1;
1098 } while (proposer_values);
1101 return proposer_values;
1104 static int iscsi_check_acceptor_state(struct iscsi_param *param, char *value,
1105 struct iscsi_conn *conn)
1107 u8 acceptor_boolean_value = 0, proposer_boolean_value = 0;
1108 char *negoitated_value = NULL;
1110 if (IS_PSTATE_ACCEPTOR(param)) {
1111 pr_err("Received key \"%s\" twice, protocol error.\n",
1116 if (IS_PSTATE_REJECT(param))
1119 if (IS_TYPE_BOOL_AND(param)) {
1120 if (!strcmp(value, YES))
1121 proposer_boolean_value = 1;
1122 if (!strcmp(param->value, YES))
1123 acceptor_boolean_value = 1;
1124 if (acceptor_boolean_value && proposer_boolean_value)
1127 if (iscsi_update_param_value(param, NO) < 0)
1129 if (!proposer_boolean_value)
1130 SET_PSTATE_REPLY_OPTIONAL(param);
1132 } else if (IS_TYPE_BOOL_OR(param)) {
1133 if (!strcmp(value, YES))
1134 proposer_boolean_value = 1;
1135 if (!strcmp(param->value, YES))
1136 acceptor_boolean_value = 1;
1137 if (acceptor_boolean_value || proposer_boolean_value) {
1138 if (iscsi_update_param_value(param, YES) < 0)
1140 if (proposer_boolean_value)
1141 SET_PSTATE_REPLY_OPTIONAL(param);
1143 } else if (IS_TYPE_NUMBER(param)) {
1144 char *tmpptr, buf[11];
1145 u32 acceptor_value = simple_strtoul(param->value, &tmpptr, 0);
1146 u32 proposer_value = simple_strtoul(value, &tmpptr, 0);
1148 memset(buf, 0, sizeof(buf));
1150 if (!strcmp(param->name, MAXCONNECTIONS) ||
1151 !strcmp(param->name, MAXBURSTLENGTH) ||
1152 !strcmp(param->name, FIRSTBURSTLENGTH) ||
1153 !strcmp(param->name, MAXOUTSTANDINGR2T) ||
1154 !strcmp(param->name, DEFAULTTIME2RETAIN) ||
1155 !strcmp(param->name, ERRORRECOVERYLEVEL)) {
1156 if (proposer_value > acceptor_value) {
1157 sprintf(buf, "%u", acceptor_value);
1158 if (iscsi_update_param_value(param,
1162 if (iscsi_update_param_value(param, value) < 0)
1165 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
1166 if (acceptor_value > proposer_value) {
1167 sprintf(buf, "%u", acceptor_value);
1168 if (iscsi_update_param_value(param,
1172 if (iscsi_update_param_value(param, value) < 0)
1176 if (iscsi_update_param_value(param, value) < 0)
1180 if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH)) {
1181 struct iscsi_param *param_mxdsl;
1182 unsigned long long tmp;
1185 rc = strict_strtoull(param->value, 0, &tmp);
1189 conn->conn_ops->MaxRecvDataSegmentLength = tmp;
1190 pr_debug("Saving op->MaxRecvDataSegmentLength from"
1191 " original initiator received value: %u\n",
1192 conn->conn_ops->MaxRecvDataSegmentLength);
1194 param_mxdsl = iscsi_find_param_from_key(
1195 MAXXMITDATASEGMENTLENGTH,
1200 rc = iscsi_update_param_value(param,
1201 param_mxdsl->value);
1205 pr_debug("Updated %s to target MXDSL value: %s\n",
1206 param->name, param->value);
1209 } else if (IS_TYPE_NUMBER_RANGE(param)) {
1210 negoitated_value = iscsi_get_value_from_number_range(
1212 if (!negoitated_value)
1214 if (iscsi_update_param_value(param, negoitated_value) < 0)
1216 } else if (IS_TYPE_VALUE_LIST(param)) {
1217 negoitated_value = iscsi_check_valuelist_for_support(
1219 if (!negoitated_value) {
1220 pr_err("Proposer's value list \"%s\" contains"
1221 " no valid values from Acceptor's value list"
1222 " \"%s\".\n", value, param->value);
1225 if (iscsi_update_param_value(param, negoitated_value) < 0)
1227 } else if (IS_PHASE_DECLARATIVE(param)) {
1228 if (iscsi_update_param_value(param, value) < 0)
1230 SET_PSTATE_REPLY_OPTIONAL(param);
1236 static int iscsi_check_proposer_state(struct iscsi_param *param, char *value)
1238 if (IS_PSTATE_RESPONSE_GOT(param)) {
1239 pr_err("Received key \"%s\" twice, protocol error.\n",
1244 if (IS_TYPE_NUMBER_RANGE(param)) {
1245 u32 left_val = 0, right_val = 0, recieved_value = 0;
1246 char *left_val_ptr = NULL, *right_val_ptr = NULL;
1247 char *tilde_ptr = NULL;
1249 if (!strcmp(value, IRRELEVANT) || !strcmp(value, REJECT)) {
1250 if (iscsi_update_param_value(param, value) < 0)
1255 tilde_ptr = strchr(value, '~');
1257 pr_err("Illegal \"~\" in response for \"%s\".\n",
1261 tilde_ptr = strchr(param->value, '~');
1263 pr_err("Unable to locate numerical range"
1264 " indicator \"~\" for \"%s\".\n", param->name);
1269 left_val_ptr = param->value;
1270 right_val_ptr = param->value + strlen(left_val_ptr) + 1;
1271 left_val = simple_strtoul(left_val_ptr, NULL, 0);
1272 right_val = simple_strtoul(right_val_ptr, NULL, 0);
1273 recieved_value = simple_strtoul(value, NULL, 0);
1277 if ((recieved_value < left_val) ||
1278 (recieved_value > right_val)) {
1279 pr_err("Illegal response \"%s=%u\", value must"
1280 " be between %u and %u.\n", param->name,
1281 recieved_value, left_val, right_val);
1284 } else if (IS_TYPE_VALUE_LIST(param)) {
1285 char *comma_ptr = NULL, *tmp_ptr = NULL;
1287 comma_ptr = strchr(value, ',');
1289 pr_err("Illegal \",\" in response for \"%s\".\n",
1294 tmp_ptr = iscsi_check_valuelist_for_support(param, value);
1299 if (iscsi_update_param_value(param, value) < 0)
1305 static int iscsi_check_value(struct iscsi_param *param, char *value)
1307 char *comma_ptr = NULL;
1309 if (!strcmp(value, REJECT)) {
1310 if (!strcmp(param->name, IFMARKINT) ||
1311 !strcmp(param->name, OFMARKINT)) {
1313 * Reject is not fatal for [I,O]FMarkInt, and causes
1314 * [I,O]FMarker to be reset to No. (See iSCSI v20 A.3.2)
1316 SET_PSTATE_REJECT(param);
1319 pr_err("Received %s=%s\n", param->name, value);
1322 if (!strcmp(value, IRRELEVANT)) {
1323 pr_debug("Received %s=%s\n", param->name, value);
1324 SET_PSTATE_IRRELEVANT(param);
1327 if (!strcmp(value, NOTUNDERSTOOD)) {
1328 if (!IS_PSTATE_PROPOSER(param)) {
1329 pr_err("Received illegal offer %s=%s\n",
1330 param->name, value);
1334 /* #warning FIXME: Add check for X-ExtensionKey here */
1335 pr_err("Standard iSCSI key \"%s\" cannot be answered"
1336 " with \"%s\", protocol error.\n", param->name, value);
1342 comma_ptr = strchr(value, ',');
1344 if (comma_ptr && !IS_TYPE_VALUE_LIST(param)) {
1345 pr_err("Detected value separator \",\", but"
1346 " key \"%s\" does not allow a value list,"
1347 " protocol error.\n", param->name);
1353 if (strlen(value) > VALUE_MAXLEN) {
1354 pr_err("Value for key \"%s\" exceeds %d,"
1355 " protocol error.\n", param->name,
1360 if (IS_TYPE_BOOL_AND(param) || IS_TYPE_BOOL_OR(param)) {
1361 if (iscsi_check_boolean_value(param, value) < 0)
1363 } else if (IS_TYPE_NUMBER(param)) {
1364 if (iscsi_check_numerical_value(param, value) < 0)
1366 } else if (IS_TYPE_NUMBER_RANGE(param)) {
1367 if (iscsi_check_numerical_range_value(param, value) < 0)
1369 } else if (IS_TYPE_STRING(param) || IS_TYPE_VALUE_LIST(param)) {
1370 if (iscsi_check_string_or_list_value(param, value) < 0)
1373 pr_err("Huh? 0x%02x\n", param->type);
1386 static struct iscsi_param *__iscsi_check_key(
1389 struct iscsi_param_list *param_list)
1391 struct iscsi_param *param;
1393 if (strlen(key) > KEY_MAXLEN) {
1394 pr_err("Length of key name \"%s\" exceeds %d.\n",
1399 param = iscsi_find_param_from_key(key, param_list);
1403 if ((sender & SENDER_INITIATOR) && !IS_SENDER_INITIATOR(param)) {
1404 pr_err("Key \"%s\" may not be sent to %s,"
1405 " protocol error.\n", param->name,
1406 (sender & SENDER_RECEIVER) ? "target" : "initiator");
1410 if ((sender & SENDER_TARGET) && !IS_SENDER_TARGET(param)) {
1411 pr_err("Key \"%s\" may not be sent to %s,"
1412 " protocol error.\n", param->name,
1413 (sender & SENDER_RECEIVER) ? "initiator" : "target");
1420 static struct iscsi_param *iscsi_check_key(
1424 struct iscsi_param_list *param_list)
1426 struct iscsi_param *param;
1428 * Key name length must not exceed 63 bytes. (See iSCSI v20 5.1)
1430 if (strlen(key) > KEY_MAXLEN) {
1431 pr_err("Length of key name \"%s\" exceeds %d.\n",
1436 param = iscsi_find_param_from_key(key, param_list);
1440 if ((sender & SENDER_INITIATOR) && !IS_SENDER_INITIATOR(param)) {
1441 pr_err("Key \"%s\" may not be sent to %s,"
1442 " protocol error.\n", param->name,
1443 (sender & SENDER_RECEIVER) ? "target" : "initiator");
1446 if ((sender & SENDER_TARGET) && !IS_SENDER_TARGET(param)) {
1447 pr_err("Key \"%s\" may not be sent to %s,"
1448 " protocol error.\n", param->name,
1449 (sender & SENDER_RECEIVER) ? "initiator" : "target");
1453 if (IS_PSTATE_ACCEPTOR(param)) {
1454 pr_err("Key \"%s\" received twice, protocol error.\n",
1462 if (!(param->phase & phase)) {
1463 pr_err("Key \"%s\" may not be negotiated during ",
1466 case PHASE_SECURITY:
1467 pr_debug("Security phase.\n");
1469 case PHASE_OPERATIONAL:
1470 pr_debug("Operational phase.\n");
1473 pr_debug("Unknown phase.\n");
1481 static int iscsi_enforce_integrity_rules(
1483 struct iscsi_param_list *param_list)
1486 u8 DataSequenceInOrder = 0;
1487 u8 ErrorRecoveryLevel = 0, SessionType = 0;
1488 u8 IFMarker = 0, OFMarker = 0;
1489 u8 IFMarkInt_Reject = 1, OFMarkInt_Reject = 1;
1490 u32 FirstBurstLength = 0, MaxBurstLength = 0;
1491 struct iscsi_param *param = NULL;
1493 list_for_each_entry(param, ¶m_list->param_list, p_list) {
1494 if (!(param->phase & phase))
1496 if (!strcmp(param->name, SESSIONTYPE))
1497 if (!strcmp(param->value, NORMAL))
1499 if (!strcmp(param->name, ERRORRECOVERYLEVEL))
1500 ErrorRecoveryLevel = simple_strtoul(param->value,
1502 if (!strcmp(param->name, DATASEQUENCEINORDER))
1503 if (!strcmp(param->value, YES))
1504 DataSequenceInOrder = 1;
1505 if (!strcmp(param->name, MAXBURSTLENGTH))
1506 MaxBurstLength = simple_strtoul(param->value,
1508 if (!strcmp(param->name, IFMARKER))
1509 if (!strcmp(param->value, YES))
1511 if (!strcmp(param->name, OFMARKER))
1512 if (!strcmp(param->value, YES))
1514 if (!strcmp(param->name, IFMARKINT))
1515 if (!strcmp(param->value, REJECT))
1516 IFMarkInt_Reject = 1;
1517 if (!strcmp(param->name, OFMARKINT))
1518 if (!strcmp(param->value, REJECT))
1519 OFMarkInt_Reject = 1;
1522 list_for_each_entry(param, ¶m_list->param_list, p_list) {
1523 if (!(param->phase & phase))
1525 if (!SessionType && (!IS_PSTATE_ACCEPTOR(param) &&
1526 (strcmp(param->name, IFMARKER) &&
1527 strcmp(param->name, OFMARKER) &&
1528 strcmp(param->name, IFMARKINT) &&
1529 strcmp(param->name, OFMARKINT))))
1531 if (!strcmp(param->name, MAXOUTSTANDINGR2T) &&
1532 DataSequenceInOrder && (ErrorRecoveryLevel > 0)) {
1533 if (strcmp(param->value, "1")) {
1534 if (iscsi_update_param_value(param, "1") < 0)
1536 pr_debug("Reset \"%s\" to \"%s\".\n",
1537 param->name, param->value);
1540 if (!strcmp(param->name, MAXCONNECTIONS) && !SessionType) {
1541 if (strcmp(param->value, "1")) {
1542 if (iscsi_update_param_value(param, "1") < 0)
1544 pr_debug("Reset \"%s\" to \"%s\".\n",
1545 param->name, param->value);
1548 if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
1549 FirstBurstLength = simple_strtoul(param->value,
1551 if (FirstBurstLength > MaxBurstLength) {
1553 memset(tmpbuf, 0, sizeof(tmpbuf));
1554 sprintf(tmpbuf, "%u", MaxBurstLength);
1555 if (iscsi_update_param_value(param, tmpbuf))
1557 pr_debug("Reset \"%s\" to \"%s\".\n",
1558 param->name, param->value);
1561 if (!strcmp(param->name, IFMARKER) && IFMarkInt_Reject) {
1562 if (iscsi_update_param_value(param, NO) < 0)
1565 pr_debug("Reset \"%s\" to \"%s\".\n",
1566 param->name, param->value);
1568 if (!strcmp(param->name, OFMARKER) && OFMarkInt_Reject) {
1569 if (iscsi_update_param_value(param, NO) < 0)
1572 pr_debug("Reset \"%s\" to \"%s\".\n",
1573 param->name, param->value);
1575 if (!strcmp(param->name, IFMARKINT) && !IFMarker) {
1576 if (!strcmp(param->value, REJECT))
1578 param->state &= ~PSTATE_NEGOTIATE;
1579 if (iscsi_update_param_value(param, IRRELEVANT) < 0)
1581 pr_debug("Reset \"%s\" to \"%s\".\n",
1582 param->name, param->value);
1584 if (!strcmp(param->name, OFMARKINT) && !OFMarker) {
1585 if (!strcmp(param->value, REJECT))
1587 param->state &= ~PSTATE_NEGOTIATE;
1588 if (iscsi_update_param_value(param, IRRELEVANT) < 0)
1590 pr_debug("Reset \"%s\" to \"%s\".\n",
1591 param->name, param->value);
1598 int iscsi_decode_text_input(
1603 struct iscsi_conn *conn)
1605 struct iscsi_param_list *param_list = conn->param_list;
1606 char *tmpbuf, *start = NULL, *end = NULL;
1608 tmpbuf = kzalloc(length + 1, GFP_KERNEL);
1610 pr_err("Unable to allocate memory for tmpbuf.\n");
1614 memcpy(tmpbuf, textbuf, length);
1615 tmpbuf[length] = '\0';
1617 end = (start + length);
1619 while (start < end) {
1621 struct iscsi_param *param;
1623 if (iscsi_extract_key_value(start, &key, &value) < 0) {
1628 pr_debug("Got key: %s=%s\n", key, value);
1630 if (phase & PHASE_SECURITY) {
1631 if (iscsi_check_for_auth_key(key) > 0) {
1632 char *tmpptr = key + strlen(key);
1639 param = iscsi_check_key(key, phase, sender, param_list);
1641 if (iscsi_add_notunderstood_response(key,
1642 value, param_list) < 0) {
1646 start += strlen(key) + strlen(value) + 2;
1649 if (iscsi_check_value(param, value) < 0) {
1654 start += strlen(key) + strlen(value) + 2;
1656 if (IS_PSTATE_PROPOSER(param)) {
1657 if (iscsi_check_proposer_state(param, value) < 0) {
1661 SET_PSTATE_RESPONSE_GOT(param);
1663 if (iscsi_check_acceptor_state(param, value, conn) < 0) {
1667 SET_PSTATE_ACCEPTOR(param);
1675 int iscsi_encode_text_output(
1680 struct iscsi_param_list *param_list)
1682 char *output_buf = NULL;
1683 struct iscsi_extra_response *er;
1684 struct iscsi_param *param;
1686 output_buf = textbuf + *length;
1688 if (iscsi_enforce_integrity_rules(phase, param_list) < 0)
1691 list_for_each_entry(param, ¶m_list->param_list, p_list) {
1692 if (!(param->sender & sender))
1694 if (IS_PSTATE_ACCEPTOR(param) &&
1695 !IS_PSTATE_RESPONSE_SENT(param) &&
1696 !IS_PSTATE_REPLY_OPTIONAL(param) &&
1697 (param->phase & phase)) {
1698 *length += sprintf(output_buf, "%s=%s",
1699 param->name, param->value);
1701 output_buf = textbuf + *length;
1702 SET_PSTATE_RESPONSE_SENT(param);
1703 pr_debug("Sending key: %s=%s\n",
1704 param->name, param->value);
1707 if (IS_PSTATE_NEGOTIATE(param) &&
1708 !IS_PSTATE_ACCEPTOR(param) &&
1709 !IS_PSTATE_PROPOSER(param) &&
1710 (param->phase & phase)) {
1711 *length += sprintf(output_buf, "%s=%s",
1712 param->name, param->value);
1714 output_buf = textbuf + *length;
1715 SET_PSTATE_PROPOSER(param);
1716 iscsi_check_proposer_for_optional_reply(param);
1717 pr_debug("Sending key: %s=%s\n",
1718 param->name, param->value);
1722 list_for_each_entry(er, ¶m_list->extra_response_list, er_list) {
1723 *length += sprintf(output_buf, "%s=%s", er->key, er->value);
1725 output_buf = textbuf + *length;
1726 pr_debug("Sending key: %s=%s\n", er->key, er->value);
1728 iscsi_release_extra_responses(param_list);
1733 int iscsi_check_negotiated_keys(struct iscsi_param_list *param_list)
1736 struct iscsi_param *param;
1738 list_for_each_entry(param, ¶m_list->param_list, p_list) {
1739 if (IS_PSTATE_NEGOTIATE(param) &&
1740 IS_PSTATE_PROPOSER(param) &&
1741 !IS_PSTATE_RESPONSE_GOT(param) &&
1742 !IS_PSTATE_REPLY_OPTIONAL(param) &&
1743 !IS_PHASE_DECLARATIVE(param)) {
1744 pr_err("No response for proposed key \"%s\".\n",
1753 int iscsi_change_param_value(
1755 struct iscsi_param_list *param_list,
1758 char *key = NULL, *value = NULL;
1759 struct iscsi_param *param;
1762 if (iscsi_extract_key_value(keyvalue, &key, &value) < 0)
1766 param = __iscsi_check_key(keyvalue, sender, param_list);
1770 param = iscsi_check_key(keyvalue, 0, sender, param_list);
1774 param->set_param = 1;
1775 if (iscsi_check_value(param, value) < 0) {
1776 param->set_param = 0;
1779 param->set_param = 0;
1782 if (iscsi_update_param_value(param, value) < 0)
1788 void iscsi_set_connection_parameters(
1789 struct iscsi_conn_ops *ops,
1790 struct iscsi_param_list *param_list)
1793 struct iscsi_param *param;
1795 pr_debug("---------------------------------------------------"
1796 "---------------\n");
1797 list_for_each_entry(param, ¶m_list->param_list, p_list) {
1799 * Special case to set MAXXMITDATASEGMENTLENGTH from the
1800 * target requested MaxRecvDataSegmentLength, even though
1801 * this key is not sent over the wire.
1803 if (!strcmp(param->name, MAXXMITDATASEGMENTLENGTH)) {
1804 if (param_list->iser == true)
1807 ops->MaxXmitDataSegmentLength =
1808 simple_strtoul(param->value, &tmpptr, 0);
1809 pr_debug("MaxXmitDataSegmentLength: %s\n",
1813 if (!IS_PSTATE_ACCEPTOR(param) && !IS_PSTATE_PROPOSER(param))
1815 if (!strcmp(param->name, AUTHMETHOD)) {
1816 pr_debug("AuthMethod: %s\n",
1818 } else if (!strcmp(param->name, HEADERDIGEST)) {
1819 ops->HeaderDigest = !strcmp(param->value, CRC32C);
1820 pr_debug("HeaderDigest: %s\n",
1822 } else if (!strcmp(param->name, DATADIGEST)) {
1823 ops->DataDigest = !strcmp(param->value, CRC32C);
1824 pr_debug("DataDigest: %s\n",
1826 } else if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH)) {
1828 * At this point iscsi_check_acceptor_state() will have
1829 * set ops->MaxRecvDataSegmentLength from the original
1830 * initiator provided value.
1832 pr_debug("MaxRecvDataSegmentLength: %u\n",
1833 ops->MaxRecvDataSegmentLength);
1834 } else if (!strcmp(param->name, OFMARKER)) {
1835 ops->OFMarker = !strcmp(param->value, YES);
1836 pr_debug("OFMarker: %s\n",
1838 } else if (!strcmp(param->name, IFMARKER)) {
1839 ops->IFMarker = !strcmp(param->value, YES);
1840 pr_debug("IFMarker: %s\n",
1842 } else if (!strcmp(param->name, OFMARKINT)) {
1844 simple_strtoul(param->value, &tmpptr, 0);
1845 pr_debug("OFMarkInt: %s\n",
1847 } else if (!strcmp(param->name, IFMARKINT)) {
1849 simple_strtoul(param->value, &tmpptr, 0);
1850 pr_debug("IFMarkInt: %s\n",
1852 } else if (!strcmp(param->name, INITIATORRECVDATASEGMENTLENGTH)) {
1853 ops->InitiatorRecvDataSegmentLength =
1854 simple_strtoul(param->value, &tmpptr, 0);
1855 pr_debug("InitiatorRecvDataSegmentLength: %s\n",
1857 ops->MaxRecvDataSegmentLength =
1858 ops->InitiatorRecvDataSegmentLength;
1859 pr_debug("Set MRDSL from InitiatorRecvDataSegmentLength\n");
1860 } else if (!strcmp(param->name, TARGETRECVDATASEGMENTLENGTH)) {
1861 ops->TargetRecvDataSegmentLength =
1862 simple_strtoul(param->value, &tmpptr, 0);
1863 pr_debug("TargetRecvDataSegmentLength: %s\n",
1865 ops->MaxXmitDataSegmentLength =
1866 ops->TargetRecvDataSegmentLength;
1867 pr_debug("Set MXDSL from TargetRecvDataSegmentLength\n");
1870 pr_debug("----------------------------------------------------"
1871 "--------------\n");
1874 void iscsi_set_session_parameters(
1875 struct iscsi_sess_ops *ops,
1876 struct iscsi_param_list *param_list,
1880 struct iscsi_param *param;
1882 pr_debug("----------------------------------------------------"
1883 "--------------\n");
1884 list_for_each_entry(param, ¶m_list->param_list, p_list) {
1885 if (!IS_PSTATE_ACCEPTOR(param) && !IS_PSTATE_PROPOSER(param))
1887 if (!strcmp(param->name, INITIATORNAME)) {
1891 snprintf(ops->InitiatorName,
1892 sizeof(ops->InitiatorName),
1893 "%s", param->value);
1894 pr_debug("InitiatorName: %s\n",
1896 } else if (!strcmp(param->name, INITIATORALIAS)) {
1899 snprintf(ops->InitiatorAlias,
1900 sizeof(ops->InitiatorAlias),
1901 "%s", param->value);
1902 pr_debug("InitiatorAlias: %s\n",
1904 } else if (!strcmp(param->name, TARGETNAME)) {
1908 snprintf(ops->TargetName,
1909 sizeof(ops->TargetName),
1910 "%s", param->value);
1911 pr_debug("TargetName: %s\n",
1913 } else if (!strcmp(param->name, TARGETALIAS)) {
1916 snprintf(ops->TargetAlias, sizeof(ops->TargetAlias),
1917 "%s", param->value);
1918 pr_debug("TargetAlias: %s\n",
1920 } else if (!strcmp(param->name, TARGETPORTALGROUPTAG)) {
1921 ops->TargetPortalGroupTag =
1922 simple_strtoul(param->value, &tmpptr, 0);
1923 pr_debug("TargetPortalGroupTag: %s\n",
1925 } else if (!strcmp(param->name, MAXCONNECTIONS)) {
1926 ops->MaxConnections =
1927 simple_strtoul(param->value, &tmpptr, 0);
1928 pr_debug("MaxConnections: %s\n",
1930 } else if (!strcmp(param->name, INITIALR2T)) {
1931 ops->InitialR2T = !strcmp(param->value, YES);
1932 pr_debug("InitialR2T: %s\n",
1934 } else if (!strcmp(param->name, IMMEDIATEDATA)) {
1935 ops->ImmediateData = !strcmp(param->value, YES);
1936 pr_debug("ImmediateData: %s\n",
1938 } else if (!strcmp(param->name, MAXBURSTLENGTH)) {
1939 ops->MaxBurstLength =
1940 simple_strtoul(param->value, &tmpptr, 0);
1941 pr_debug("MaxBurstLength: %s\n",
1943 } else if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
1944 ops->FirstBurstLength =
1945 simple_strtoul(param->value, &tmpptr, 0);
1946 pr_debug("FirstBurstLength: %s\n",
1948 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
1949 ops->DefaultTime2Wait =
1950 simple_strtoul(param->value, &tmpptr, 0);
1951 pr_debug("DefaultTime2Wait: %s\n",
1953 } else if (!strcmp(param->name, DEFAULTTIME2RETAIN)) {
1954 ops->DefaultTime2Retain =
1955 simple_strtoul(param->value, &tmpptr, 0);
1956 pr_debug("DefaultTime2Retain: %s\n",
1958 } else if (!strcmp(param->name, MAXOUTSTANDINGR2T)) {
1959 ops->MaxOutstandingR2T =
1960 simple_strtoul(param->value, &tmpptr, 0);
1961 pr_debug("MaxOutstandingR2T: %s\n",
1963 } else if (!strcmp(param->name, DATAPDUINORDER)) {
1964 ops->DataPDUInOrder = !strcmp(param->value, YES);
1965 pr_debug("DataPDUInOrder: %s\n",
1967 } else if (!strcmp(param->name, DATASEQUENCEINORDER)) {
1968 ops->DataSequenceInOrder = !strcmp(param->value, YES);
1969 pr_debug("DataSequenceInOrder: %s\n",
1971 } else if (!strcmp(param->name, ERRORRECOVERYLEVEL)) {
1972 ops->ErrorRecoveryLevel =
1973 simple_strtoul(param->value, &tmpptr, 0);
1974 pr_debug("ErrorRecoveryLevel: %s\n",
1976 } else if (!strcmp(param->name, SESSIONTYPE)) {
1977 ops->SessionType = !strcmp(param->value, DISCOVERY);
1978 pr_debug("SessionType: %s\n",
1980 } else if (!strcmp(param->name, RDMAEXTENTIONS)) {
1981 ops->RDMAExtensions = !strcmp(param->value, YES);
1982 pr_debug("RDMAExtensions: %s\n",
1986 pr_debug("----------------------------------------------------"
1987 "--------------\n");