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
,
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
;
70 iov
[1].iov_len
= text_length
;
71 iov
[1].iov_base
= text_buf
;
74 * Initial Marker-less Interval.
75 * Add the values regardless of IFMarker/OFMarker, considering
76 * it may not be negoitated yet.
78 conn
->if_marker
+= length
;
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",
90 void iscsi_dump_conn_ops(struct iscsi_conn_ops
*conn_ops
)
92 pr_debug("HeaderDigest: %s\n", (conn_ops
->HeaderDigest
) ?
94 pr_debug("DataDigest: %s\n", (conn_ops
->DataDigest
) ?
96 pr_debug("MaxRecvDataSegmentLength: %u\n",
97 conn_ops
->MaxRecvDataSegmentLength
);
98 pr_debug("OFMarker: %s\n", (conn_ops
->OFMarker
) ? "Yes" : "No");
99 pr_debug("IFMarker: %s\n", (conn_ops
->IFMarker
) ? "Yes" : "No");
100 if (conn_ops
->OFMarker
)
101 pr_debug("OFMarkInt: %u\n", conn_ops
->OFMarkInt
);
102 if (conn_ops
->IFMarker
)
103 pr_debug("IFMarkInt: %u\n", conn_ops
->IFMarkInt
);
106 void iscsi_dump_sess_ops(struct iscsi_sess_ops
*sess_ops
)
108 pr_debug("InitiatorName: %s\n", sess_ops
->InitiatorName
);
109 pr_debug("InitiatorAlias: %s\n", sess_ops
->InitiatorAlias
);
110 pr_debug("TargetName: %s\n", sess_ops
->TargetName
);
111 pr_debug("TargetAlias: %s\n", sess_ops
->TargetAlias
);
112 pr_debug("TargetPortalGroupTag: %hu\n",
113 sess_ops
->TargetPortalGroupTag
);
114 pr_debug("MaxConnections: %hu\n", sess_ops
->MaxConnections
);
115 pr_debug("InitialR2T: %s\n",
116 (sess_ops
->InitialR2T
) ? "Yes" : "No");
117 pr_debug("ImmediateData: %s\n", (sess_ops
->ImmediateData
) ?
119 pr_debug("MaxBurstLength: %u\n", sess_ops
->MaxBurstLength
);
120 pr_debug("FirstBurstLength: %u\n", sess_ops
->FirstBurstLength
);
121 pr_debug("DefaultTime2Wait: %hu\n", sess_ops
->DefaultTime2Wait
);
122 pr_debug("DefaultTime2Retain: %hu\n",
123 sess_ops
->DefaultTime2Retain
);
124 pr_debug("MaxOutstandingR2T: %hu\n",
125 sess_ops
->MaxOutstandingR2T
);
126 pr_debug("DataPDUInOrder: %s\n",
127 (sess_ops
->DataPDUInOrder
) ? "Yes" : "No");
128 pr_debug("DataSequenceInOrder: %s\n",
129 (sess_ops
->DataSequenceInOrder
) ? "Yes" : "No");
130 pr_debug("ErrorRecoveryLevel: %hu\n",
131 sess_ops
->ErrorRecoveryLevel
);
132 pr_debug("SessionType: %s\n", (sess_ops
->SessionType
) ?
133 "Discovery" : "Normal");
136 void iscsi_print_params(struct iscsi_param_list
*param_list
)
138 struct iscsi_param
*param
;
140 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
)
141 pr_debug("%s: %s\n", param
->name
, param
->value
);
144 static struct iscsi_param
*iscsi_set_default_param(struct iscsi_param_list
*param_list
,
145 char *name
, char *value
, u8 phase
, u8 scope
, u8 sender
,
146 u16 type_range
, u8 use
)
148 struct iscsi_param
*param
= NULL
;
150 param
= kzalloc(sizeof(struct iscsi_param
), GFP_KERNEL
);
152 pr_err("Unable to allocate memory for parameter.\n");
155 INIT_LIST_HEAD(¶m
->p_list
);
157 param
->name
= kzalloc(strlen(name
) + 1, GFP_KERNEL
);
159 pr_err("Unable to allocate memory for parameter name.\n");
163 param
->value
= kzalloc(strlen(value
) + 1, GFP_KERNEL
);
165 pr_err("Unable to allocate memory for parameter value.\n");
169 memcpy(param
->name
, name
, strlen(name
));
170 param
->name
[strlen(name
)] = '\0';
171 memcpy(param
->value
, value
, strlen(value
));
172 param
->value
[strlen(value
)] = '\0';
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
, MAXRECVDATASEGMENTLENGTH
,
338 INITIAL_MAXRECVDATASEGMENTLENGTH
,
339 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
340 TYPERANGE_512_TO_16777215
, USE_ALL
);
344 param
= iscsi_set_default_param(pl
, MAXBURSTLENGTH
,
345 INITIAL_MAXBURSTLENGTH
, PHASE_OPERATIONAL
,
346 SCOPE_SESSION_WIDE
, SENDER_BOTH
,
347 TYPERANGE_512_TO_16777215
, USE_LEADING_ONLY
);
351 param
= iscsi_set_default_param(pl
, FIRSTBURSTLENGTH
,
352 INITIAL_FIRSTBURSTLENGTH
,
353 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
354 TYPERANGE_512_TO_16777215
, USE_LEADING_ONLY
);
358 param
= iscsi_set_default_param(pl
, DEFAULTTIME2WAIT
,
359 INITIAL_DEFAULTTIME2WAIT
,
360 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
361 TYPERANGE_0_TO_3600
, USE_LEADING_ONLY
);
365 param
= iscsi_set_default_param(pl
, DEFAULTTIME2RETAIN
,
366 INITIAL_DEFAULTTIME2RETAIN
,
367 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
368 TYPERANGE_0_TO_3600
, USE_LEADING_ONLY
);
372 param
= iscsi_set_default_param(pl
, MAXOUTSTANDINGR2T
,
373 INITIAL_MAXOUTSTANDINGR2T
,
374 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
375 TYPERANGE_1_TO_65535
, USE_LEADING_ONLY
);
379 param
= iscsi_set_default_param(pl
, DATAPDUINORDER
,
380 INITIAL_DATAPDUINORDER
, PHASE_OPERATIONAL
,
381 SCOPE_SESSION_WIDE
, SENDER_BOTH
, TYPERANGE_BOOL_OR
,
386 param
= iscsi_set_default_param(pl
, DATASEQUENCEINORDER
,
387 INITIAL_DATASEQUENCEINORDER
,
388 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
389 TYPERANGE_BOOL_OR
, USE_LEADING_ONLY
);
393 param
= iscsi_set_default_param(pl
, ERRORRECOVERYLEVEL
,
394 INITIAL_ERRORRECOVERYLEVEL
,
395 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
396 TYPERANGE_0_TO_2
, USE_LEADING_ONLY
);
400 param
= iscsi_set_default_param(pl
, SESSIONTYPE
, INITIAL_SESSIONTYPE
,
401 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
402 TYPERANGE_SESSIONTYPE
, USE_LEADING_ONLY
);
406 param
= iscsi_set_default_param(pl
, IFMARKER
, INITIAL_IFMARKER
,
407 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
408 TYPERANGE_BOOL_AND
, USE_INITIAL_ONLY
);
412 param
= iscsi_set_default_param(pl
, OFMARKER
, INITIAL_OFMARKER
,
413 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
414 TYPERANGE_BOOL_AND
, USE_INITIAL_ONLY
);
418 param
= iscsi_set_default_param(pl
, IFMARKINT
, INITIAL_IFMARKINT
,
419 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
420 TYPERANGE_MARKINT
, USE_INITIAL_ONLY
);
424 param
= iscsi_set_default_param(pl
, OFMARKINT
, INITIAL_OFMARKINT
,
425 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
426 TYPERANGE_MARKINT
, USE_INITIAL_ONLY
);
430 *param_list_ptr
= pl
;
433 iscsi_release_param_list(pl
);
437 int iscsi_set_keys_to_negotiate(
439 struct iscsi_param_list
*param_list
)
441 struct iscsi_param
*param
;
443 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
445 if (!strcmp(param
->name
, AUTHMETHOD
)) {
446 SET_PSTATE_NEGOTIATE(param
);
447 } else if (!strcmp(param
->name
, HEADERDIGEST
)) {
448 SET_PSTATE_NEGOTIATE(param
);
449 } else if (!strcmp(param
->name
, DATADIGEST
)) {
450 SET_PSTATE_NEGOTIATE(param
);
451 } else if (!strcmp(param
->name
, MAXCONNECTIONS
)) {
452 SET_PSTATE_NEGOTIATE(param
);
453 } else if (!strcmp(param
->name
, TARGETNAME
)) {
455 } else if (!strcmp(param
->name
, INITIATORNAME
)) {
457 } else if (!strcmp(param
->name
, TARGETALIAS
)) {
459 SET_PSTATE_NEGOTIATE(param
);
460 } else if (!strcmp(param
->name
, INITIATORALIAS
)) {
462 } else if (!strcmp(param
->name
, TARGETPORTALGROUPTAG
)) {
463 SET_PSTATE_NEGOTIATE(param
);
464 } else if (!strcmp(param
->name
, INITIALR2T
)) {
465 SET_PSTATE_NEGOTIATE(param
);
466 } else if (!strcmp(param
->name
, IMMEDIATEDATA
)) {
467 SET_PSTATE_NEGOTIATE(param
);
468 } else if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
469 SET_PSTATE_NEGOTIATE(param
);
470 } else if (!strcmp(param
->name
, MAXBURSTLENGTH
)) {
471 SET_PSTATE_NEGOTIATE(param
);
472 } else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
473 SET_PSTATE_NEGOTIATE(param
);
474 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
475 SET_PSTATE_NEGOTIATE(param
);
476 } else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
)) {
477 SET_PSTATE_NEGOTIATE(param
);
478 } else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
)) {
479 SET_PSTATE_NEGOTIATE(param
);
480 } else if (!strcmp(param
->name
, DATAPDUINORDER
)) {
481 SET_PSTATE_NEGOTIATE(param
);
482 } else if (!strcmp(param
->name
, DATASEQUENCEINORDER
)) {
483 SET_PSTATE_NEGOTIATE(param
);
484 } else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
485 SET_PSTATE_NEGOTIATE(param
);
486 } else if (!strcmp(param
->name
, SESSIONTYPE
)) {
487 SET_PSTATE_NEGOTIATE(param
);
488 } else if (!strcmp(param
->name
, IFMARKER
)) {
489 SET_PSTATE_NEGOTIATE(param
);
490 } else if (!strcmp(param
->name
, OFMARKER
)) {
491 SET_PSTATE_NEGOTIATE(param
);
492 } else if (!strcmp(param
->name
, IFMARKINT
)) {
493 SET_PSTATE_NEGOTIATE(param
);
494 } else if (!strcmp(param
->name
, OFMARKINT
)) {
495 SET_PSTATE_NEGOTIATE(param
);
502 int iscsi_set_keys_irrelevant_for_discovery(
503 struct iscsi_param_list
*param_list
)
505 struct iscsi_param
*param
;
507 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
508 if (!strcmp(param
->name
, MAXCONNECTIONS
))
509 param
->state
&= ~PSTATE_NEGOTIATE
;
510 else if (!strcmp(param
->name
, INITIALR2T
))
511 param
->state
&= ~PSTATE_NEGOTIATE
;
512 else if (!strcmp(param
->name
, IMMEDIATEDATA
))
513 param
->state
&= ~PSTATE_NEGOTIATE
;
514 else if (!strcmp(param
->name
, MAXBURSTLENGTH
))
515 param
->state
&= ~PSTATE_NEGOTIATE
;
516 else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
))
517 param
->state
&= ~PSTATE_NEGOTIATE
;
518 else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
))
519 param
->state
&= ~PSTATE_NEGOTIATE
;
520 else if (!strcmp(param
->name
, DATAPDUINORDER
))
521 param
->state
&= ~PSTATE_NEGOTIATE
;
522 else if (!strcmp(param
->name
, DATASEQUENCEINORDER
))
523 param
->state
&= ~PSTATE_NEGOTIATE
;
524 else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
))
525 param
->state
&= ~PSTATE_NEGOTIATE
;
526 else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
))
527 param
->state
&= ~PSTATE_NEGOTIATE
;
528 else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
))
529 param
->state
&= ~PSTATE_NEGOTIATE
;
530 else if (!strcmp(param
->name
, IFMARKER
))
531 param
->state
&= ~PSTATE_NEGOTIATE
;
532 else if (!strcmp(param
->name
, OFMARKER
))
533 param
->state
&= ~PSTATE_NEGOTIATE
;
534 else if (!strcmp(param
->name
, IFMARKINT
))
535 param
->state
&= ~PSTATE_NEGOTIATE
;
536 else if (!strcmp(param
->name
, OFMARKINT
))
537 param
->state
&= ~PSTATE_NEGOTIATE
;
543 int iscsi_copy_param_list(
544 struct iscsi_param_list
**dst_param_list
,
545 struct iscsi_param_list
*src_param_list
,
548 struct iscsi_param
*param
= NULL
;
549 struct iscsi_param
*new_param
= NULL
;
550 struct iscsi_param_list
*param_list
= NULL
;
552 param_list
= kzalloc(sizeof(struct iscsi_param_list
), GFP_KERNEL
);
554 pr_err("Unable to allocate memory for struct iscsi_param_list.\n");
557 INIT_LIST_HEAD(¶m_list
->param_list
);
558 INIT_LIST_HEAD(¶m_list
->extra_response_list
);
560 list_for_each_entry(param
, &src_param_list
->param_list
, p_list
) {
561 if (!leading
&& (param
->scope
& SCOPE_SESSION_WIDE
)) {
562 if ((strcmp(param
->name
, "TargetName") != 0) &&
563 (strcmp(param
->name
, "InitiatorName") != 0) &&
564 (strcmp(param
->name
, "TargetPortalGroupTag") != 0))
568 new_param
= kzalloc(sizeof(struct iscsi_param
), GFP_KERNEL
);
570 pr_err("Unable to allocate memory for struct iscsi_param.\n");
574 new_param
->name
= kstrdup(param
->name
, GFP_KERNEL
);
575 new_param
->value
= kstrdup(param
->value
, GFP_KERNEL
);
576 if (!new_param
->value
|| !new_param
->name
) {
577 kfree(new_param
->value
);
578 kfree(new_param
->name
);
580 pr_err("Unable to allocate memory for parameter name/value.\n");
584 new_param
->set_param
= param
->set_param
;
585 new_param
->phase
= param
->phase
;
586 new_param
->scope
= param
->scope
;
587 new_param
->sender
= param
->sender
;
588 new_param
->type
= param
->type
;
589 new_param
->use
= param
->use
;
590 new_param
->type_range
= param
->type_range
;
592 list_add_tail(&new_param
->p_list
, ¶m_list
->param_list
);
595 if (!list_empty(¶m_list
->param_list
)) {
596 *dst_param_list
= param_list
;
598 pr_err("No parameters allocated.\n");
605 iscsi_release_param_list(param_list
);
609 static void iscsi_release_extra_responses(struct iscsi_param_list
*param_list
)
611 struct iscsi_extra_response
*er
, *er_tmp
;
613 list_for_each_entry_safe(er
, er_tmp
, ¶m_list
->extra_response_list
,
615 list_del(&er
->er_list
);
620 void iscsi_release_param_list(struct iscsi_param_list
*param_list
)
622 struct iscsi_param
*param
, *param_tmp
;
624 list_for_each_entry_safe(param
, param_tmp
, ¶m_list
->param_list
,
626 list_del(¶m
->p_list
);
636 iscsi_release_extra_responses(param_list
);
641 struct iscsi_param
*iscsi_find_param_from_key(
643 struct iscsi_param_list
*param_list
)
645 struct iscsi_param
*param
;
647 if (!key
|| !param_list
) {
648 pr_err("Key or parameter list pointer is NULL.\n");
652 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
653 if (!strcmp(key
, param
->name
))
657 pr_err("Unable to locate key \"%s\".\n", key
);
661 int iscsi_extract_key_value(char *textbuf
, char **key
, char **value
)
663 *value
= strchr(textbuf
, '=');
665 pr_err("Unable to locate \"=\" seperator for key,"
666 " ignoring request.\n");
677 int iscsi_update_param_value(struct iscsi_param
*param
, char *value
)
681 param
->value
= kzalloc(strlen(value
) + 1, GFP_KERNEL
);
683 pr_err("Unable to allocate memory for value.\n");
687 memcpy(param
->value
, value
, strlen(value
));
688 param
->value
[strlen(value
)] = '\0';
690 pr_debug("iSCSI Parameter updated to %s=%s\n",
691 param
->name
, param
->value
);
695 static int iscsi_add_notunderstood_response(
698 struct iscsi_param_list
*param_list
)
700 struct iscsi_extra_response
*extra_response
;
702 if (strlen(value
) > VALUE_MAXLEN
) {
703 pr_err("Value for notunderstood key \"%s\" exceeds %d,"
704 " protocol error.\n", key
, VALUE_MAXLEN
);
708 extra_response
= kzalloc(sizeof(struct iscsi_extra_response
), GFP_KERNEL
);
709 if (!extra_response
) {
710 pr_err("Unable to allocate memory for"
711 " struct iscsi_extra_response.\n");
714 INIT_LIST_HEAD(&extra_response
->er_list
);
716 strncpy(extra_response
->key
, key
, strlen(key
) + 1);
717 strncpy(extra_response
->value
, NOTUNDERSTOOD
,
718 strlen(NOTUNDERSTOOD
) + 1);
720 list_add_tail(&extra_response
->er_list
,
721 ¶m_list
->extra_response_list
);
725 static int iscsi_check_for_auth_key(char *key
)
730 if (!strcmp(key
, "CHAP_A") || !strcmp(key
, "CHAP_I") ||
731 !strcmp(key
, "CHAP_C") || !strcmp(key
, "CHAP_N") ||
732 !strcmp(key
, "CHAP_R"))
738 if (!strcmp(key
, "SRP_U") || !strcmp(key
, "SRP_N") ||
739 !strcmp(key
, "SRP_g") || !strcmp(key
, "SRP_s") ||
740 !strcmp(key
, "SRP_A") || !strcmp(key
, "SRP_B") ||
741 !strcmp(key
, "SRP_M") || !strcmp(key
, "SRP_HM"))
747 static void iscsi_check_proposer_for_optional_reply(struct iscsi_param
*param
)
749 if (IS_TYPE_BOOL_AND(param
)) {
750 if (!strcmp(param
->value
, NO
))
751 SET_PSTATE_REPLY_OPTIONAL(param
);
752 } else if (IS_TYPE_BOOL_OR(param
)) {
753 if (!strcmp(param
->value
, YES
))
754 SET_PSTATE_REPLY_OPTIONAL(param
);
756 * Required for gPXE iSCSI boot client
758 if (!strcmp(param
->name
, IMMEDIATEDATA
))
759 SET_PSTATE_REPLY_OPTIONAL(param
);
760 } else if (IS_TYPE_NUMBER(param
)) {
761 if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
))
762 SET_PSTATE_REPLY_OPTIONAL(param
);
764 * The GlobalSAN iSCSI Initiator for MacOSX does
765 * not respond to MaxBurstLength, FirstBurstLength,
766 * DefaultTime2Wait or DefaultTime2Retain parameter keys.
767 * So, we set them to 'reply optional' here, and assume the
768 * the defaults from iscsi_parameters.h if the initiator
769 * is not RFC compliant and the keys are not negotiated.
771 if (!strcmp(param
->name
, MAXBURSTLENGTH
))
772 SET_PSTATE_REPLY_OPTIONAL(param
);
773 if (!strcmp(param
->name
, FIRSTBURSTLENGTH
))
774 SET_PSTATE_REPLY_OPTIONAL(param
);
775 if (!strcmp(param
->name
, DEFAULTTIME2WAIT
))
776 SET_PSTATE_REPLY_OPTIONAL(param
);
777 if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
))
778 SET_PSTATE_REPLY_OPTIONAL(param
);
780 * Required for gPXE iSCSI boot client
782 if (!strcmp(param
->name
, MAXCONNECTIONS
))
783 SET_PSTATE_REPLY_OPTIONAL(param
);
784 } else if (IS_PHASE_DECLARATIVE(param
))
785 SET_PSTATE_REPLY_OPTIONAL(param
);
788 static int iscsi_check_boolean_value(struct iscsi_param
*param
, char *value
)
790 if (strcmp(value
, YES
) && strcmp(value
, NO
)) {
791 pr_err("Illegal value for \"%s\", must be either"
792 " \"%s\" or \"%s\".\n", param
->name
, YES
, NO
);
799 static int iscsi_check_numerical_value(struct iscsi_param
*param
, char *value_ptr
)
804 value
= simple_strtoul(value_ptr
, &tmpptr
, 0);
806 if (IS_TYPERANGE_0_TO_2(param
)) {
807 if ((value
< 0) || (value
> 2)) {
808 pr_err("Illegal value for \"%s\", must be"
809 " between 0 and 2.\n", param
->name
);
814 if (IS_TYPERANGE_0_TO_3600(param
)) {
815 if ((value
< 0) || (value
> 3600)) {
816 pr_err("Illegal value for \"%s\", must be"
817 " between 0 and 3600.\n", param
->name
);
822 if (IS_TYPERANGE_0_TO_32767(param
)) {
823 if ((value
< 0) || (value
> 32767)) {
824 pr_err("Illegal value for \"%s\", must be"
825 " between 0 and 32767.\n", param
->name
);
830 if (IS_TYPERANGE_0_TO_65535(param
)) {
831 if ((value
< 0) || (value
> 65535)) {
832 pr_err("Illegal value for \"%s\", must be"
833 " between 0 and 65535.\n", param
->name
);
838 if (IS_TYPERANGE_1_TO_65535(param
)) {
839 if ((value
< 1) || (value
> 65535)) {
840 pr_err("Illegal value for \"%s\", must be"
841 " between 1 and 65535.\n", param
->name
);
846 if (IS_TYPERANGE_2_TO_3600(param
)) {
847 if ((value
< 2) || (value
> 3600)) {
848 pr_err("Illegal value for \"%s\", must be"
849 " between 2 and 3600.\n", param
->name
);
854 if (IS_TYPERANGE_512_TO_16777215(param
)) {
855 if ((value
< 512) || (value
> 16777215)) {
856 pr_err("Illegal value for \"%s\", must be"
857 " between 512 and 16777215.\n", param
->name
);
866 static int iscsi_check_numerical_range_value(struct iscsi_param
*param
, char *value
)
868 char *left_val_ptr
= NULL
, *right_val_ptr
= NULL
;
869 char *tilde_ptr
= NULL
;
870 u32 left_val
, right_val
, local_left_val
;
872 if (strcmp(param
->name
, IFMARKINT
) &&
873 strcmp(param
->name
, OFMARKINT
)) {
874 pr_err("Only parameters \"%s\" or \"%s\" may contain a"
875 " numerical range value.\n", IFMARKINT
, OFMARKINT
);
879 if (IS_PSTATE_PROPOSER(param
))
882 tilde_ptr
= strchr(value
, '~');
884 pr_err("Unable to locate numerical range indicator"
885 " \"~\" for \"%s\".\n", param
->name
);
890 left_val_ptr
= value
;
891 right_val_ptr
= value
+ strlen(left_val_ptr
) + 1;
893 if (iscsi_check_numerical_value(param
, left_val_ptr
) < 0)
895 if (iscsi_check_numerical_value(param
, right_val_ptr
) < 0)
898 left_val
= simple_strtoul(left_val_ptr
, NULL
, 0);
899 right_val
= simple_strtoul(right_val_ptr
, NULL
, 0);
902 if (right_val
< left_val
) {
903 pr_err("Numerical range for parameter \"%s\" contains"
904 " a right value which is less than the left.\n",
910 * For now, enforce reasonable defaults for [I,O]FMarkInt.
912 tilde_ptr
= strchr(param
->value
, '~');
914 pr_err("Unable to locate numerical range indicator"
915 " \"~\" for \"%s\".\n", param
->name
);
920 left_val_ptr
= param
->value
;
921 right_val_ptr
= param
->value
+ strlen(left_val_ptr
) + 1;
923 local_left_val
= simple_strtoul(left_val_ptr
, NULL
, 0);
926 if (param
->set_param
) {
927 if ((left_val
< local_left_val
) ||
928 (right_val
< local_left_val
)) {
929 pr_err("Passed value range \"%u~%u\" is below"
930 " minimum left value \"%u\" for key \"%s\","
931 " rejecting.\n", left_val
, right_val
,
932 local_left_val
, param
->name
);
936 if ((left_val
< local_left_val
) &&
937 (right_val
< local_left_val
)) {
938 pr_err("Received value range \"%u~%u\" is"
939 " below minimum left value \"%u\" for key"
940 " \"%s\", rejecting.\n", left_val
, right_val
,
941 local_left_val
, param
->name
);
942 SET_PSTATE_REJECT(param
);
943 if (iscsi_update_param_value(param
, REJECT
) < 0)
951 static int iscsi_check_string_or_list_value(struct iscsi_param
*param
, char *value
)
953 if (IS_PSTATE_PROPOSER(param
))
956 if (IS_TYPERANGE_AUTH_PARAM(param
)) {
957 if (strcmp(value
, KRB5
) && strcmp(value
, SPKM1
) &&
958 strcmp(value
, SPKM2
) && strcmp(value
, SRP
) &&
959 strcmp(value
, CHAP
) && strcmp(value
, NONE
)) {
960 pr_err("Illegal value for \"%s\", must be"
961 " \"%s\", \"%s\", \"%s\", \"%s\", \"%s\""
962 " or \"%s\".\n", param
->name
, KRB5
,
963 SPKM1
, SPKM2
, SRP
, CHAP
, NONE
);
967 if (IS_TYPERANGE_DIGEST_PARAM(param
)) {
968 if (strcmp(value
, CRC32C
) && strcmp(value
, NONE
)) {
969 pr_err("Illegal value for \"%s\", must be"
970 " \"%s\" or \"%s\".\n", param
->name
,
975 if (IS_TYPERANGE_SESSIONTYPE(param
)) {
976 if (strcmp(value
, DISCOVERY
) && strcmp(value
, NORMAL
)) {
977 pr_err("Illegal value for \"%s\", must be"
978 " \"%s\" or \"%s\".\n", param
->name
,
988 * This function is used to pick a value range number, currently just
989 * returns the lesser of both right values.
991 static char *iscsi_get_value_from_number_range(
992 struct iscsi_param
*param
,
995 char *end_ptr
, *tilde_ptr1
= NULL
, *tilde_ptr2
= NULL
;
996 u32 acceptor_right_value
, proposer_right_value
;
998 tilde_ptr1
= strchr(value
, '~');
1001 *tilde_ptr1
++ = '\0';
1002 proposer_right_value
= simple_strtoul(tilde_ptr1
, &end_ptr
, 0);
1004 tilde_ptr2
= strchr(param
->value
, '~');
1007 *tilde_ptr2
++ = '\0';
1008 acceptor_right_value
= simple_strtoul(tilde_ptr2
, &end_ptr
, 0);
1010 return (acceptor_right_value
>= proposer_right_value
) ?
1011 tilde_ptr1
: tilde_ptr2
;
1014 static char *iscsi_check_valuelist_for_support(
1015 struct iscsi_param
*param
,
1018 char *tmp1
= NULL
, *tmp2
= NULL
;
1019 char *acceptor_values
= NULL
, *proposer_values
= NULL
;
1021 acceptor_values
= param
->value
;
1022 proposer_values
= value
;
1025 if (!proposer_values
)
1027 tmp1
= strchr(proposer_values
, ',');
1030 acceptor_values
= param
->value
;
1032 if (!acceptor_values
) {
1037 tmp2
= strchr(acceptor_values
, ',');
1040 if (!strcmp(acceptor_values
, proposer_values
)) {
1048 acceptor_values
= tmp2
;
1049 } while (acceptor_values
);
1052 proposer_values
= tmp1
;
1053 } while (proposer_values
);
1056 return proposer_values
;
1059 static int iscsi_check_acceptor_state(struct iscsi_param
*param
, char *value
)
1061 u8 acceptor_boolean_value
= 0, proposer_boolean_value
= 0;
1062 char *negoitated_value
= NULL
;
1064 if (IS_PSTATE_ACCEPTOR(param
)) {
1065 pr_err("Received key \"%s\" twice, protocol error.\n",
1070 if (IS_PSTATE_REJECT(param
))
1073 if (IS_TYPE_BOOL_AND(param
)) {
1074 if (!strcmp(value
, YES
))
1075 proposer_boolean_value
= 1;
1076 if (!strcmp(param
->value
, YES
))
1077 acceptor_boolean_value
= 1;
1078 if (acceptor_boolean_value
&& proposer_boolean_value
)
1081 if (iscsi_update_param_value(param
, NO
) < 0)
1083 if (!proposer_boolean_value
)
1084 SET_PSTATE_REPLY_OPTIONAL(param
);
1086 } else if (IS_TYPE_BOOL_OR(param
)) {
1087 if (!strcmp(value
, YES
))
1088 proposer_boolean_value
= 1;
1089 if (!strcmp(param
->value
, YES
))
1090 acceptor_boolean_value
= 1;
1091 if (acceptor_boolean_value
|| proposer_boolean_value
) {
1092 if (iscsi_update_param_value(param
, YES
) < 0)
1094 if (proposer_boolean_value
)
1095 SET_PSTATE_REPLY_OPTIONAL(param
);
1097 } else if (IS_TYPE_NUMBER(param
)) {
1098 char *tmpptr
, buf
[10];
1099 u32 acceptor_value
= simple_strtoul(param
->value
, &tmpptr
, 0);
1100 u32 proposer_value
= simple_strtoul(value
, &tmpptr
, 0);
1104 if (!strcmp(param
->name
, MAXCONNECTIONS
) ||
1105 !strcmp(param
->name
, MAXBURSTLENGTH
) ||
1106 !strcmp(param
->name
, FIRSTBURSTLENGTH
) ||
1107 !strcmp(param
->name
, MAXOUTSTANDINGR2T
) ||
1108 !strcmp(param
->name
, DEFAULTTIME2RETAIN
) ||
1109 !strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
1110 if (proposer_value
> acceptor_value
) {
1111 sprintf(buf
, "%u", acceptor_value
);
1112 if (iscsi_update_param_value(param
,
1116 if (iscsi_update_param_value(param
, value
) < 0)
1119 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
1120 if (acceptor_value
> proposer_value
) {
1121 sprintf(buf
, "%u", acceptor_value
);
1122 if (iscsi_update_param_value(param
,
1126 if (iscsi_update_param_value(param
, value
) < 0)
1130 if (iscsi_update_param_value(param
, value
) < 0)
1134 if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
))
1135 SET_PSTATE_REPLY_OPTIONAL(param
);
1136 } else if (IS_TYPE_NUMBER_RANGE(param
)) {
1137 negoitated_value
= iscsi_get_value_from_number_range(
1139 if (!negoitated_value
)
1141 if (iscsi_update_param_value(param
, negoitated_value
) < 0)
1143 } else if (IS_TYPE_VALUE_LIST(param
)) {
1144 negoitated_value
= iscsi_check_valuelist_for_support(
1146 if (!negoitated_value
) {
1147 pr_err("Proposer's value list \"%s\" contains"
1148 " no valid values from Acceptor's value list"
1149 " \"%s\".\n", value
, param
->value
);
1152 if (iscsi_update_param_value(param
, negoitated_value
) < 0)
1154 } else if (IS_PHASE_DECLARATIVE(param
)) {
1155 if (iscsi_update_param_value(param
, value
) < 0)
1157 SET_PSTATE_REPLY_OPTIONAL(param
);
1163 static int iscsi_check_proposer_state(struct iscsi_param
*param
, char *value
)
1165 if (IS_PSTATE_RESPONSE_GOT(param
)) {
1166 pr_err("Received key \"%s\" twice, protocol error.\n",
1171 if (IS_TYPE_NUMBER_RANGE(param
)) {
1172 u32 left_val
= 0, right_val
= 0, recieved_value
= 0;
1173 char *left_val_ptr
= NULL
, *right_val_ptr
= NULL
;
1174 char *tilde_ptr
= NULL
;
1176 if (!strcmp(value
, IRRELEVANT
) || !strcmp(value
, REJECT
)) {
1177 if (iscsi_update_param_value(param
, value
) < 0)
1182 tilde_ptr
= strchr(value
, '~');
1184 pr_err("Illegal \"~\" in response for \"%s\".\n",
1188 tilde_ptr
= strchr(param
->value
, '~');
1190 pr_err("Unable to locate numerical range"
1191 " indicator \"~\" for \"%s\".\n", param
->name
);
1196 left_val_ptr
= param
->value
;
1197 right_val_ptr
= param
->value
+ strlen(left_val_ptr
) + 1;
1198 left_val
= simple_strtoul(left_val_ptr
, NULL
, 0);
1199 right_val
= simple_strtoul(right_val_ptr
, NULL
, 0);
1200 recieved_value
= simple_strtoul(value
, NULL
, 0);
1204 if ((recieved_value
< left_val
) ||
1205 (recieved_value
> right_val
)) {
1206 pr_err("Illegal response \"%s=%u\", value must"
1207 " be between %u and %u.\n", param
->name
,
1208 recieved_value
, left_val
, right_val
);
1211 } else if (IS_TYPE_VALUE_LIST(param
)) {
1212 char *comma_ptr
= NULL
, *tmp_ptr
= NULL
;
1214 comma_ptr
= strchr(value
, ',');
1216 pr_err("Illegal \",\" in response for \"%s\".\n",
1221 tmp_ptr
= iscsi_check_valuelist_for_support(param
, value
);
1226 if (iscsi_update_param_value(param
, value
) < 0)
1232 static int iscsi_check_value(struct iscsi_param
*param
, char *value
)
1234 char *comma_ptr
= NULL
;
1236 if (!strcmp(value
, REJECT
)) {
1237 if (!strcmp(param
->name
, IFMARKINT
) ||
1238 !strcmp(param
->name
, OFMARKINT
)) {
1240 * Reject is not fatal for [I,O]FMarkInt, and causes
1241 * [I,O]FMarker to be reset to No. (See iSCSI v20 A.3.2)
1243 SET_PSTATE_REJECT(param
);
1246 pr_err("Received %s=%s\n", param
->name
, value
);
1249 if (!strcmp(value
, IRRELEVANT
)) {
1250 pr_debug("Received %s=%s\n", param
->name
, value
);
1251 SET_PSTATE_IRRELEVANT(param
);
1254 if (!strcmp(value
, NOTUNDERSTOOD
)) {
1255 if (!IS_PSTATE_PROPOSER(param
)) {
1256 pr_err("Received illegal offer %s=%s\n",
1257 param
->name
, value
);
1261 /* #warning FIXME: Add check for X-ExtensionKey here */
1262 pr_err("Standard iSCSI key \"%s\" cannot be answered"
1263 " with \"%s\", protocol error.\n", param
->name
, value
);
1269 comma_ptr
= strchr(value
, ',');
1271 if (comma_ptr
&& !IS_TYPE_VALUE_LIST(param
)) {
1272 pr_err("Detected value seperator \",\", but"
1273 " key \"%s\" does not allow a value list,"
1274 " protocol error.\n", param
->name
);
1280 if (strlen(value
) > VALUE_MAXLEN
) {
1281 pr_err("Value for key \"%s\" exceeds %d,"
1282 " protocol error.\n", param
->name
,
1287 if (IS_TYPE_BOOL_AND(param
) || IS_TYPE_BOOL_OR(param
)) {
1288 if (iscsi_check_boolean_value(param
, value
) < 0)
1290 } else if (IS_TYPE_NUMBER(param
)) {
1291 if (iscsi_check_numerical_value(param
, value
) < 0)
1293 } else if (IS_TYPE_NUMBER_RANGE(param
)) {
1294 if (iscsi_check_numerical_range_value(param
, value
) < 0)
1296 } else if (IS_TYPE_STRING(param
) || IS_TYPE_VALUE_LIST(param
)) {
1297 if (iscsi_check_string_or_list_value(param
, value
) < 0)
1300 pr_err("Huh? 0x%02x\n", param
->type
);
1313 static struct iscsi_param
*__iscsi_check_key(
1316 struct iscsi_param_list
*param_list
)
1318 struct iscsi_param
*param
;
1320 if (strlen(key
) > KEY_MAXLEN
) {
1321 pr_err("Length of key name \"%s\" exceeds %d.\n",
1326 param
= iscsi_find_param_from_key(key
, param_list
);
1330 if ((sender
& SENDER_INITIATOR
) && !IS_SENDER_INITIATOR(param
)) {
1331 pr_err("Key \"%s\" may not be sent to %s,"
1332 " protocol error.\n", param
->name
,
1333 (sender
& SENDER_RECEIVER
) ? "target" : "initiator");
1337 if ((sender
& SENDER_TARGET
) && !IS_SENDER_TARGET(param
)) {
1338 pr_err("Key \"%s\" may not be sent to %s,"
1339 " protocol error.\n", param
->name
,
1340 (sender
& SENDER_RECEIVER
) ? "initiator" : "target");
1347 static struct iscsi_param
*iscsi_check_key(
1351 struct iscsi_param_list
*param_list
)
1353 struct iscsi_param
*param
;
1355 * Key name length must not exceed 63 bytes. (See iSCSI v20 5.1)
1357 if (strlen(key
) > KEY_MAXLEN
) {
1358 pr_err("Length of key name \"%s\" exceeds %d.\n",
1363 param
= iscsi_find_param_from_key(key
, param_list
);
1367 if ((sender
& SENDER_INITIATOR
) && !IS_SENDER_INITIATOR(param
)) {
1368 pr_err("Key \"%s\" may not be sent to %s,"
1369 " protocol error.\n", param
->name
,
1370 (sender
& SENDER_RECEIVER
) ? "target" : "initiator");
1373 if ((sender
& SENDER_TARGET
) && !IS_SENDER_TARGET(param
)) {
1374 pr_err("Key \"%s\" may not be sent to %s,"
1375 " protocol error.\n", param
->name
,
1376 (sender
& SENDER_RECEIVER
) ? "initiator" : "target");
1380 if (IS_PSTATE_ACCEPTOR(param
)) {
1381 pr_err("Key \"%s\" received twice, protocol error.\n",
1389 if (!(param
->phase
& phase
)) {
1390 pr_err("Key \"%s\" may not be negotiated during ",
1393 case PHASE_SECURITY
:
1394 pr_debug("Security phase.\n");
1396 case PHASE_OPERATIONAL
:
1397 pr_debug("Operational phase.\n");
1399 pr_debug("Unknown phase.\n");
1407 static int iscsi_enforce_integrity_rules(
1409 struct iscsi_param_list
*param_list
)
1412 u8 DataSequenceInOrder
= 0;
1413 u8 ErrorRecoveryLevel
= 0, SessionType
= 0;
1414 u8 IFMarker
= 0, OFMarker
= 0;
1415 u8 IFMarkInt_Reject
= 1, OFMarkInt_Reject
= 1;
1416 u32 FirstBurstLength
= 0, MaxBurstLength
= 0;
1417 struct iscsi_param
*param
= NULL
;
1419 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1420 if (!(param
->phase
& phase
))
1422 if (!strcmp(param
->name
, SESSIONTYPE
))
1423 if (!strcmp(param
->value
, NORMAL
))
1425 if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
))
1426 ErrorRecoveryLevel
= simple_strtoul(param
->value
,
1428 if (!strcmp(param
->name
, DATASEQUENCEINORDER
))
1429 if (!strcmp(param
->value
, YES
))
1430 DataSequenceInOrder
= 1;
1431 if (!strcmp(param
->name
, MAXBURSTLENGTH
))
1432 MaxBurstLength
= simple_strtoul(param
->value
,
1434 if (!strcmp(param
->name
, IFMARKER
))
1435 if (!strcmp(param
->value
, YES
))
1437 if (!strcmp(param
->name
, OFMARKER
))
1438 if (!strcmp(param
->value
, YES
))
1440 if (!strcmp(param
->name
, IFMARKINT
))
1441 if (!strcmp(param
->value
, REJECT
))
1442 IFMarkInt_Reject
= 1;
1443 if (!strcmp(param
->name
, OFMARKINT
))
1444 if (!strcmp(param
->value
, REJECT
))
1445 OFMarkInt_Reject
= 1;
1448 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1449 if (!(param
->phase
& phase
))
1451 if (!SessionType
&& (!IS_PSTATE_ACCEPTOR(param
) &&
1452 (strcmp(param
->name
, IFMARKER
) &&
1453 strcmp(param
->name
, OFMARKER
) &&
1454 strcmp(param
->name
, IFMARKINT
) &&
1455 strcmp(param
->name
, OFMARKINT
))))
1457 if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
) &&
1458 DataSequenceInOrder
&& (ErrorRecoveryLevel
> 0)) {
1459 if (strcmp(param
->value
, "1")) {
1460 if (iscsi_update_param_value(param
, "1") < 0)
1462 pr_debug("Reset \"%s\" to \"%s\".\n",
1463 param
->name
, param
->value
);
1466 if (!strcmp(param
->name
, MAXCONNECTIONS
) && !SessionType
) {
1467 if (strcmp(param
->value
, "1")) {
1468 if (iscsi_update_param_value(param
, "1") < 0)
1470 pr_debug("Reset \"%s\" to \"%s\".\n",
1471 param
->name
, param
->value
);
1474 if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
1475 FirstBurstLength
= simple_strtoul(param
->value
,
1477 if (FirstBurstLength
> MaxBurstLength
) {
1479 memset(tmpbuf
, 0, 10);
1480 sprintf(tmpbuf
, "%u", MaxBurstLength
);
1481 if (iscsi_update_param_value(param
, tmpbuf
))
1483 pr_debug("Reset \"%s\" to \"%s\".\n",
1484 param
->name
, param
->value
);
1487 if (!strcmp(param
->name
, IFMARKER
) && IFMarkInt_Reject
) {
1488 if (iscsi_update_param_value(param
, NO
) < 0)
1491 pr_debug("Reset \"%s\" to \"%s\".\n",
1492 param
->name
, param
->value
);
1494 if (!strcmp(param
->name
, OFMARKER
) && OFMarkInt_Reject
) {
1495 if (iscsi_update_param_value(param
, NO
) < 0)
1498 pr_debug("Reset \"%s\" to \"%s\".\n",
1499 param
->name
, param
->value
);
1501 if (!strcmp(param
->name
, IFMARKINT
) && !IFMarker
) {
1502 if (!strcmp(param
->value
, REJECT
))
1504 param
->state
&= ~PSTATE_NEGOTIATE
;
1505 if (iscsi_update_param_value(param
, IRRELEVANT
) < 0)
1507 pr_debug("Reset \"%s\" to \"%s\".\n",
1508 param
->name
, param
->value
);
1510 if (!strcmp(param
->name
, OFMARKINT
) && !OFMarker
) {
1511 if (!strcmp(param
->value
, REJECT
))
1513 param
->state
&= ~PSTATE_NEGOTIATE
;
1514 if (iscsi_update_param_value(param
, IRRELEVANT
) < 0)
1516 pr_debug("Reset \"%s\" to \"%s\".\n",
1517 param
->name
, param
->value
);
1524 int iscsi_decode_text_input(
1529 struct iscsi_param_list
*param_list
)
1531 char *tmpbuf
, *start
= NULL
, *end
= NULL
;
1533 tmpbuf
= kzalloc(length
+ 1, GFP_KERNEL
);
1535 pr_err("Unable to allocate memory for tmpbuf.\n");
1539 memcpy(tmpbuf
, textbuf
, length
);
1540 tmpbuf
[length
] = '\0';
1542 end
= (start
+ length
);
1544 while (start
< end
) {
1546 struct iscsi_param
*param
;
1548 if (iscsi_extract_key_value(start
, &key
, &value
) < 0) {
1553 pr_debug("Got key: %s=%s\n", key
, value
);
1555 if (phase
& PHASE_SECURITY
) {
1556 if (iscsi_check_for_auth_key(key
) > 0) {
1557 char *tmpptr
= key
+ strlen(key
);
1564 param
= iscsi_check_key(key
, phase
, sender
, param_list
);
1566 if (iscsi_add_notunderstood_response(key
,
1567 value
, param_list
) < 0) {
1571 start
+= strlen(key
) + strlen(value
) + 2;
1574 if (iscsi_check_value(param
, value
) < 0) {
1579 start
+= strlen(key
) + strlen(value
) + 2;
1581 if (IS_PSTATE_PROPOSER(param
)) {
1582 if (iscsi_check_proposer_state(param
, value
) < 0) {
1586 SET_PSTATE_RESPONSE_GOT(param
);
1588 if (iscsi_check_acceptor_state(param
, value
) < 0) {
1592 SET_PSTATE_ACCEPTOR(param
);
1600 int iscsi_encode_text_output(
1605 struct iscsi_param_list
*param_list
)
1607 char *output_buf
= NULL
;
1608 struct iscsi_extra_response
*er
;
1609 struct iscsi_param
*param
;
1611 output_buf
= textbuf
+ *length
;
1613 if (iscsi_enforce_integrity_rules(phase
, param_list
) < 0)
1616 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1617 if (!(param
->sender
& sender
))
1619 if (IS_PSTATE_ACCEPTOR(param
) &&
1620 !IS_PSTATE_RESPONSE_SENT(param
) &&
1621 !IS_PSTATE_REPLY_OPTIONAL(param
) &&
1622 (param
->phase
& phase
)) {
1623 *length
+= sprintf(output_buf
, "%s=%s",
1624 param
->name
, param
->value
);
1626 output_buf
= textbuf
+ *length
;
1627 SET_PSTATE_RESPONSE_SENT(param
);
1628 pr_debug("Sending key: %s=%s\n",
1629 param
->name
, param
->value
);
1632 if (IS_PSTATE_NEGOTIATE(param
) &&
1633 !IS_PSTATE_ACCEPTOR(param
) &&
1634 !IS_PSTATE_PROPOSER(param
) &&
1635 (param
->phase
& phase
)) {
1636 *length
+= sprintf(output_buf
, "%s=%s",
1637 param
->name
, param
->value
);
1639 output_buf
= textbuf
+ *length
;
1640 SET_PSTATE_PROPOSER(param
);
1641 iscsi_check_proposer_for_optional_reply(param
);
1642 pr_debug("Sending key: %s=%s\n",
1643 param
->name
, param
->value
);
1647 list_for_each_entry(er
, ¶m_list
->extra_response_list
, er_list
) {
1648 *length
+= sprintf(output_buf
, "%s=%s", er
->key
, er
->value
);
1650 output_buf
= textbuf
+ *length
;
1651 pr_debug("Sending key: %s=%s\n", er
->key
, er
->value
);
1653 iscsi_release_extra_responses(param_list
);
1658 int iscsi_check_negotiated_keys(struct iscsi_param_list
*param_list
)
1661 struct iscsi_param
*param
;
1663 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1664 if (IS_PSTATE_NEGOTIATE(param
) &&
1665 IS_PSTATE_PROPOSER(param
) &&
1666 !IS_PSTATE_RESPONSE_GOT(param
) &&
1667 !IS_PSTATE_REPLY_OPTIONAL(param
) &&
1668 !IS_PHASE_DECLARATIVE(param
)) {
1669 pr_err("No response for proposed key \"%s\".\n",
1678 int iscsi_change_param_value(
1680 struct iscsi_param_list
*param_list
,
1683 char *key
= NULL
, *value
= NULL
;
1684 struct iscsi_param
*param
;
1687 if (iscsi_extract_key_value(keyvalue
, &key
, &value
) < 0)
1691 param
= __iscsi_check_key(keyvalue
, sender
, param_list
);
1695 param
= iscsi_check_key(keyvalue
, 0, sender
, param_list
);
1699 param
->set_param
= 1;
1700 if (iscsi_check_value(param
, value
) < 0) {
1701 param
->set_param
= 0;
1704 param
->set_param
= 0;
1707 if (iscsi_update_param_value(param
, value
) < 0)
1713 void iscsi_set_connection_parameters(
1714 struct iscsi_conn_ops
*ops
,
1715 struct iscsi_param_list
*param_list
)
1718 struct iscsi_param
*param
;
1720 pr_debug("---------------------------------------------------"
1721 "---------------\n");
1722 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1723 if (!IS_PSTATE_ACCEPTOR(param
) && !IS_PSTATE_PROPOSER(param
))
1725 if (!strcmp(param
->name
, AUTHMETHOD
)) {
1726 pr_debug("AuthMethod: %s\n",
1728 } else if (!strcmp(param
->name
, HEADERDIGEST
)) {
1729 ops
->HeaderDigest
= !strcmp(param
->value
, CRC32C
);
1730 pr_debug("HeaderDigest: %s\n",
1732 } else if (!strcmp(param
->name
, DATADIGEST
)) {
1733 ops
->DataDigest
= !strcmp(param
->value
, CRC32C
);
1734 pr_debug("DataDigest: %s\n",
1736 } else if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
1737 ops
->MaxRecvDataSegmentLength
=
1738 simple_strtoul(param
->value
, &tmpptr
, 0);
1739 pr_debug("MaxRecvDataSegmentLength: %s\n",
1741 } else if (!strcmp(param
->name
, OFMARKER
)) {
1742 ops
->OFMarker
= !strcmp(param
->value
, YES
);
1743 pr_debug("OFMarker: %s\n",
1745 } else if (!strcmp(param
->name
, IFMARKER
)) {
1746 ops
->IFMarker
= !strcmp(param
->value
, YES
);
1747 pr_debug("IFMarker: %s\n",
1749 } else if (!strcmp(param
->name
, OFMARKINT
)) {
1751 simple_strtoul(param
->value
, &tmpptr
, 0);
1752 pr_debug("OFMarkInt: %s\n",
1754 } else if (!strcmp(param
->name
, IFMARKINT
)) {
1756 simple_strtoul(param
->value
, &tmpptr
, 0);
1757 pr_debug("IFMarkInt: %s\n",
1761 pr_debug("----------------------------------------------------"
1762 "--------------\n");
1765 void iscsi_set_session_parameters(
1766 struct iscsi_sess_ops
*ops
,
1767 struct iscsi_param_list
*param_list
,
1771 struct iscsi_param
*param
;
1773 pr_debug("----------------------------------------------------"
1774 "--------------\n");
1775 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1776 if (!IS_PSTATE_ACCEPTOR(param
) && !IS_PSTATE_PROPOSER(param
))
1778 if (!strcmp(param
->name
, INITIATORNAME
)) {
1782 snprintf(ops
->InitiatorName
,
1783 sizeof(ops
->InitiatorName
),
1784 "%s", param
->value
);
1785 pr_debug("InitiatorName: %s\n",
1787 } else if (!strcmp(param
->name
, INITIATORALIAS
)) {
1790 snprintf(ops
->InitiatorAlias
,
1791 sizeof(ops
->InitiatorAlias
),
1792 "%s", param
->value
);
1793 pr_debug("InitiatorAlias: %s\n",
1795 } else if (!strcmp(param
->name
, TARGETNAME
)) {
1799 snprintf(ops
->TargetName
,
1800 sizeof(ops
->TargetName
),
1801 "%s", param
->value
);
1802 pr_debug("TargetName: %s\n",
1804 } else if (!strcmp(param
->name
, TARGETALIAS
)) {
1807 snprintf(ops
->TargetAlias
, sizeof(ops
->TargetAlias
),
1808 "%s", param
->value
);
1809 pr_debug("TargetAlias: %s\n",
1811 } else if (!strcmp(param
->name
, TARGETPORTALGROUPTAG
)) {
1812 ops
->TargetPortalGroupTag
=
1813 simple_strtoul(param
->value
, &tmpptr
, 0);
1814 pr_debug("TargetPortalGroupTag: %s\n",
1816 } else if (!strcmp(param
->name
, MAXCONNECTIONS
)) {
1817 ops
->MaxConnections
=
1818 simple_strtoul(param
->value
, &tmpptr
, 0);
1819 pr_debug("MaxConnections: %s\n",
1821 } else if (!strcmp(param
->name
, INITIALR2T
)) {
1822 ops
->InitialR2T
= !strcmp(param
->value
, YES
);
1823 pr_debug("InitialR2T: %s\n",
1825 } else if (!strcmp(param
->name
, IMMEDIATEDATA
)) {
1826 ops
->ImmediateData
= !strcmp(param
->value
, YES
);
1827 pr_debug("ImmediateData: %s\n",
1829 } else if (!strcmp(param
->name
, MAXBURSTLENGTH
)) {
1830 ops
->MaxBurstLength
=
1831 simple_strtoul(param
->value
, &tmpptr
, 0);
1832 pr_debug("MaxBurstLength: %s\n",
1834 } else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
1835 ops
->FirstBurstLength
=
1836 simple_strtoul(param
->value
, &tmpptr
, 0);
1837 pr_debug("FirstBurstLength: %s\n",
1839 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
1840 ops
->DefaultTime2Wait
=
1841 simple_strtoul(param
->value
, &tmpptr
, 0);
1842 pr_debug("DefaultTime2Wait: %s\n",
1844 } else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
)) {
1845 ops
->DefaultTime2Retain
=
1846 simple_strtoul(param
->value
, &tmpptr
, 0);
1847 pr_debug("DefaultTime2Retain: %s\n",
1849 } else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
)) {
1850 ops
->MaxOutstandingR2T
=
1851 simple_strtoul(param
->value
, &tmpptr
, 0);
1852 pr_debug("MaxOutstandingR2T: %s\n",
1854 } else if (!strcmp(param
->name
, DATAPDUINORDER
)) {
1855 ops
->DataPDUInOrder
= !strcmp(param
->value
, YES
);
1856 pr_debug("DataPDUInOrder: %s\n",
1858 } else if (!strcmp(param
->name
, DATASEQUENCEINORDER
)) {
1859 ops
->DataSequenceInOrder
= !strcmp(param
->value
, YES
);
1860 pr_debug("DataSequenceInOrder: %s\n",
1862 } else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
1863 ops
->ErrorRecoveryLevel
=
1864 simple_strtoul(param
->value
, &tmpptr
, 0);
1865 pr_debug("ErrorRecoveryLevel: %s\n",
1867 } else if (!strcmp(param
->name
, SESSIONTYPE
)) {
1868 ops
->SessionType
= !strcmp(param
->value
, DISCOVERY
);
1869 pr_debug("SessionType: %s\n",
1873 pr_debug("----------------------------------------------------"
1874 "--------------\n");