1 /*******************************************************************************
2 * This file contains main functions related to iSCSI Parameter negotiation.
4 * (c) Copyright 2007-2013 Datera, Inc.
6 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 ******************************************************************************/
19 #include <linux/slab.h>
21 #include <target/iscsi/iscsi_target_core.h>
22 #include "iscsi_target_util.h"
23 #include "iscsi_target_parameters.h"
25 int iscsi_login_rx_data(
26 struct iscsi_conn
*conn
,
33 memset(&iov
, 0, sizeof(struct kvec
));
37 rx_got
= rx_data(conn
, &iov
, 1, length
);
38 if (rx_got
!= length
) {
39 pr_err("rx_data returned %d, expecting %d.\n",
47 int iscsi_login_tx_data(
48 struct iscsi_conn
*conn
,
53 int length
, tx_sent
, iov_cnt
= 1;
56 length
= (ISCSI_HDR_LEN
+ text_length
);
58 memset(&iov
[0], 0, 2 * sizeof(struct kvec
));
59 iov
[0].iov_len
= ISCSI_HDR_LEN
;
60 iov
[0].iov_base
= pdu_buf
;
62 if (text_buf
&& text_length
) {
63 iov
[1].iov_len
= text_length
;
64 iov
[1].iov_base
= text_buf
;
68 tx_sent
= tx_data(conn
, &iov
[0], iov_cnt
, length
);
69 if (tx_sent
!= length
) {
70 pr_err("tx_data returned %d, expecting %d.\n",
78 void iscsi_dump_conn_ops(struct iscsi_conn_ops
*conn_ops
)
80 pr_debug("HeaderDigest: %s\n", (conn_ops
->HeaderDigest
) ?
82 pr_debug("DataDigest: %s\n", (conn_ops
->DataDigest
) ?
84 pr_debug("MaxRecvDataSegmentLength: %u\n",
85 conn_ops
->MaxRecvDataSegmentLength
);
88 void iscsi_dump_sess_ops(struct iscsi_sess_ops
*sess_ops
)
90 pr_debug("InitiatorName: %s\n", sess_ops
->InitiatorName
);
91 pr_debug("InitiatorAlias: %s\n", sess_ops
->InitiatorAlias
);
92 pr_debug("TargetName: %s\n", sess_ops
->TargetName
);
93 pr_debug("TargetAlias: %s\n", sess_ops
->TargetAlias
);
94 pr_debug("TargetPortalGroupTag: %hu\n",
95 sess_ops
->TargetPortalGroupTag
);
96 pr_debug("MaxConnections: %hu\n", sess_ops
->MaxConnections
);
97 pr_debug("InitialR2T: %s\n",
98 (sess_ops
->InitialR2T
) ? "Yes" : "No");
99 pr_debug("ImmediateData: %s\n", (sess_ops
->ImmediateData
) ?
101 pr_debug("MaxBurstLength: %u\n", sess_ops
->MaxBurstLength
);
102 pr_debug("FirstBurstLength: %u\n", sess_ops
->FirstBurstLength
);
103 pr_debug("DefaultTime2Wait: %hu\n", sess_ops
->DefaultTime2Wait
);
104 pr_debug("DefaultTime2Retain: %hu\n",
105 sess_ops
->DefaultTime2Retain
);
106 pr_debug("MaxOutstandingR2T: %hu\n",
107 sess_ops
->MaxOutstandingR2T
);
108 pr_debug("DataPDUInOrder: %s\n",
109 (sess_ops
->DataPDUInOrder
) ? "Yes" : "No");
110 pr_debug("DataSequenceInOrder: %s\n",
111 (sess_ops
->DataSequenceInOrder
) ? "Yes" : "No");
112 pr_debug("ErrorRecoveryLevel: %hu\n",
113 sess_ops
->ErrorRecoveryLevel
);
114 pr_debug("SessionType: %s\n", (sess_ops
->SessionType
) ?
115 "Discovery" : "Normal");
118 void iscsi_print_params(struct iscsi_param_list
*param_list
)
120 struct iscsi_param
*param
;
122 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
)
123 pr_debug("%s: %s\n", param
->name
, param
->value
);
126 static struct iscsi_param
*iscsi_set_default_param(struct iscsi_param_list
*param_list
,
127 char *name
, char *value
, u8 phase
, u8 scope
, u8 sender
,
128 u16 type_range
, u8 use
)
130 struct iscsi_param
*param
= NULL
;
132 param
= kzalloc(sizeof(struct iscsi_param
), GFP_KERNEL
);
134 pr_err("Unable to allocate memory for parameter.\n");
137 INIT_LIST_HEAD(¶m
->p_list
);
139 param
->name
= kstrdup(name
, GFP_KERNEL
);
141 pr_err("Unable to allocate memory for parameter name.\n");
145 param
->value
= kstrdup(value
, GFP_KERNEL
);
147 pr_err("Unable to allocate memory for parameter value.\n");
151 param
->phase
= phase
;
152 param
->scope
= scope
;
153 param
->sender
= sender
;
155 param
->type_range
= type_range
;
157 switch (param
->type_range
) {
158 case TYPERANGE_BOOL_AND
:
159 param
->type
= TYPE_BOOL_AND
;
161 case TYPERANGE_BOOL_OR
:
162 param
->type
= TYPE_BOOL_OR
;
164 case TYPERANGE_0_TO_2
:
165 case TYPERANGE_0_TO_3600
:
166 case TYPERANGE_0_TO_32767
:
167 case TYPERANGE_0_TO_65535
:
168 case TYPERANGE_1_TO_65535
:
169 case TYPERANGE_2_TO_3600
:
170 case TYPERANGE_512_TO_16777215
:
171 param
->type
= TYPE_NUMBER
;
174 case TYPERANGE_DIGEST
:
175 param
->type
= TYPE_VALUE_LIST
| TYPE_STRING
;
177 case TYPERANGE_ISCSINAME
:
178 case TYPERANGE_SESSIONTYPE
:
179 case TYPERANGE_TARGETADDRESS
:
181 param
->type
= TYPE_STRING
;
184 pr_err("Unknown type_range 0x%02x\n",
188 list_add_tail(¶m
->p_list
, ¶m_list
->param_list
);
201 /* #warning Add extension keys */
202 int iscsi_create_default_params(struct iscsi_param_list
**param_list_ptr
)
204 struct iscsi_param
*param
= NULL
;
205 struct iscsi_param_list
*pl
;
207 pl
= kzalloc(sizeof(struct iscsi_param_list
), GFP_KERNEL
);
209 pr_err("Unable to allocate memory for"
210 " struct iscsi_param_list.\n");
213 INIT_LIST_HEAD(&pl
->param_list
);
214 INIT_LIST_HEAD(&pl
->extra_response_list
);
217 * The format for setting the initial parameter definitions are:
227 param
= iscsi_set_default_param(pl
, AUTHMETHOD
, INITIAL_AUTHMETHOD
,
228 PHASE_SECURITY
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
229 TYPERANGE_AUTH
, USE_INITIAL_ONLY
);
233 param
= iscsi_set_default_param(pl
, HEADERDIGEST
, INITIAL_HEADERDIGEST
,
234 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
235 TYPERANGE_DIGEST
, USE_INITIAL_ONLY
);
239 param
= iscsi_set_default_param(pl
, DATADIGEST
, INITIAL_DATADIGEST
,
240 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
241 TYPERANGE_DIGEST
, USE_INITIAL_ONLY
);
245 param
= iscsi_set_default_param(pl
, MAXCONNECTIONS
,
246 INITIAL_MAXCONNECTIONS
, PHASE_OPERATIONAL
,
247 SCOPE_SESSION_WIDE
, SENDER_BOTH
,
248 TYPERANGE_1_TO_65535
, USE_LEADING_ONLY
);
252 param
= iscsi_set_default_param(pl
, SENDTARGETS
, INITIAL_SENDTARGETS
,
253 PHASE_FFP0
, SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
258 param
= iscsi_set_default_param(pl
, TARGETNAME
, INITIAL_TARGETNAME
,
259 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
260 TYPERANGE_ISCSINAME
, USE_ALL
);
264 param
= iscsi_set_default_param(pl
, INITIATORNAME
,
265 INITIAL_INITIATORNAME
, PHASE_DECLARATIVE
,
266 SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
267 TYPERANGE_ISCSINAME
, USE_INITIAL_ONLY
);
271 param
= iscsi_set_default_param(pl
, TARGETALIAS
, INITIAL_TARGETALIAS
,
272 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_TARGET
,
273 TYPERANGE_UTF8
, USE_ALL
);
277 param
= iscsi_set_default_param(pl
, INITIATORALIAS
,
278 INITIAL_INITIATORALIAS
, PHASE_DECLARATIVE
,
279 SCOPE_SESSION_WIDE
, SENDER_INITIATOR
, TYPERANGE_UTF8
,
284 param
= iscsi_set_default_param(pl
, TARGETADDRESS
,
285 INITIAL_TARGETADDRESS
, PHASE_DECLARATIVE
,
286 SCOPE_SESSION_WIDE
, SENDER_TARGET
,
287 TYPERANGE_TARGETADDRESS
, USE_ALL
);
291 param
= iscsi_set_default_param(pl
, TARGETPORTALGROUPTAG
,
292 INITIAL_TARGETPORTALGROUPTAG
,
293 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_TARGET
,
294 TYPERANGE_0_TO_65535
, USE_INITIAL_ONLY
);
298 param
= iscsi_set_default_param(pl
, INITIALR2T
, INITIAL_INITIALR2T
,
299 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
300 TYPERANGE_BOOL_OR
, USE_LEADING_ONLY
);
304 param
= iscsi_set_default_param(pl
, IMMEDIATEDATA
,
305 INITIAL_IMMEDIATEDATA
, PHASE_OPERATIONAL
,
306 SCOPE_SESSION_WIDE
, SENDER_BOTH
, TYPERANGE_BOOL_AND
,
311 param
= iscsi_set_default_param(pl
, MAXXMITDATASEGMENTLENGTH
,
312 INITIAL_MAXXMITDATASEGMENTLENGTH
,
313 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
314 TYPERANGE_512_TO_16777215
, USE_ALL
);
318 param
= iscsi_set_default_param(pl
, MAXRECVDATASEGMENTLENGTH
,
319 INITIAL_MAXRECVDATASEGMENTLENGTH
,
320 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
321 TYPERANGE_512_TO_16777215
, USE_ALL
);
325 param
= iscsi_set_default_param(pl
, MAXBURSTLENGTH
,
326 INITIAL_MAXBURSTLENGTH
, PHASE_OPERATIONAL
,
327 SCOPE_SESSION_WIDE
, SENDER_BOTH
,
328 TYPERANGE_512_TO_16777215
, USE_LEADING_ONLY
);
332 param
= iscsi_set_default_param(pl
, FIRSTBURSTLENGTH
,
333 INITIAL_FIRSTBURSTLENGTH
,
334 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
335 TYPERANGE_512_TO_16777215
, USE_LEADING_ONLY
);
339 param
= iscsi_set_default_param(pl
, DEFAULTTIME2WAIT
,
340 INITIAL_DEFAULTTIME2WAIT
,
341 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
342 TYPERANGE_0_TO_3600
, USE_LEADING_ONLY
);
346 param
= iscsi_set_default_param(pl
, DEFAULTTIME2RETAIN
,
347 INITIAL_DEFAULTTIME2RETAIN
,
348 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
349 TYPERANGE_0_TO_3600
, USE_LEADING_ONLY
);
353 param
= iscsi_set_default_param(pl
, MAXOUTSTANDINGR2T
,
354 INITIAL_MAXOUTSTANDINGR2T
,
355 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
356 TYPERANGE_1_TO_65535
, USE_LEADING_ONLY
);
360 param
= iscsi_set_default_param(pl
, DATAPDUINORDER
,
361 INITIAL_DATAPDUINORDER
, PHASE_OPERATIONAL
,
362 SCOPE_SESSION_WIDE
, SENDER_BOTH
, TYPERANGE_BOOL_OR
,
367 param
= iscsi_set_default_param(pl
, DATASEQUENCEINORDER
,
368 INITIAL_DATASEQUENCEINORDER
,
369 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
370 TYPERANGE_BOOL_OR
, USE_LEADING_ONLY
);
374 param
= iscsi_set_default_param(pl
, ERRORRECOVERYLEVEL
,
375 INITIAL_ERRORRECOVERYLEVEL
,
376 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
377 TYPERANGE_0_TO_2
, USE_LEADING_ONLY
);
381 param
= iscsi_set_default_param(pl
, SESSIONTYPE
, INITIAL_SESSIONTYPE
,
382 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
383 TYPERANGE_SESSIONTYPE
, USE_LEADING_ONLY
);
387 param
= iscsi_set_default_param(pl
, IFMARKER
, INITIAL_IFMARKER
,
388 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
389 TYPERANGE_BOOL_AND
, USE_INITIAL_ONLY
);
393 param
= iscsi_set_default_param(pl
, OFMARKER
, INITIAL_OFMARKER
,
394 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
395 TYPERANGE_BOOL_AND
, USE_INITIAL_ONLY
);
399 param
= iscsi_set_default_param(pl
, IFMARKINT
, INITIAL_IFMARKINT
,
400 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
401 TYPERANGE_UTF8
, USE_INITIAL_ONLY
);
405 param
= iscsi_set_default_param(pl
, OFMARKINT
, INITIAL_OFMARKINT
,
406 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
407 TYPERANGE_UTF8
, USE_INITIAL_ONLY
);
411 * Extra parameters for ISER from RFC-5046
413 param
= iscsi_set_default_param(pl
, RDMAEXTENSIONS
, INITIAL_RDMAEXTENSIONS
,
414 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
415 TYPERANGE_BOOL_AND
, USE_LEADING_ONLY
);
419 param
= iscsi_set_default_param(pl
, INITIATORRECVDATASEGMENTLENGTH
,
420 INITIAL_INITIATORRECVDATASEGMENTLENGTH
,
421 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
422 TYPERANGE_512_TO_16777215
, USE_ALL
);
426 param
= iscsi_set_default_param(pl
, TARGETRECVDATASEGMENTLENGTH
,
427 INITIAL_TARGETRECVDATASEGMENTLENGTH
,
428 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
429 TYPERANGE_512_TO_16777215
, USE_ALL
);
433 *param_list_ptr
= pl
;
436 iscsi_release_param_list(pl
);
440 int iscsi_set_keys_to_negotiate(
441 struct iscsi_param_list
*param_list
,
444 struct iscsi_param
*param
;
446 param_list
->iser
= iser
;
448 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
450 if (!strcmp(param
->name
, AUTHMETHOD
)) {
451 SET_PSTATE_NEGOTIATE(param
);
452 } else if (!strcmp(param
->name
, HEADERDIGEST
)) {
454 SET_PSTATE_NEGOTIATE(param
);
455 } else if (!strcmp(param
->name
, DATADIGEST
)) {
457 SET_PSTATE_NEGOTIATE(param
);
458 } else if (!strcmp(param
->name
, MAXCONNECTIONS
)) {
459 SET_PSTATE_NEGOTIATE(param
);
460 } else if (!strcmp(param
->name
, TARGETNAME
)) {
462 } else if (!strcmp(param
->name
, INITIATORNAME
)) {
464 } else if (!strcmp(param
->name
, TARGETALIAS
)) {
466 SET_PSTATE_NEGOTIATE(param
);
467 } else if (!strcmp(param
->name
, INITIATORALIAS
)) {
469 } else if (!strcmp(param
->name
, TARGETPORTALGROUPTAG
)) {
470 SET_PSTATE_NEGOTIATE(param
);
471 } else if (!strcmp(param
->name
, INITIALR2T
)) {
472 SET_PSTATE_NEGOTIATE(param
);
473 } else if (!strcmp(param
->name
, IMMEDIATEDATA
)) {
474 SET_PSTATE_NEGOTIATE(param
);
475 } else if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
477 SET_PSTATE_NEGOTIATE(param
);
478 } else if (!strcmp(param
->name
, MAXXMITDATASEGMENTLENGTH
)) {
480 } else if (!strcmp(param
->name
, MAXBURSTLENGTH
)) {
481 SET_PSTATE_NEGOTIATE(param
);
482 } else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
483 SET_PSTATE_NEGOTIATE(param
);
484 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
485 SET_PSTATE_NEGOTIATE(param
);
486 } else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
)) {
487 SET_PSTATE_NEGOTIATE(param
);
488 } else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
)) {
489 SET_PSTATE_NEGOTIATE(param
);
490 } else if (!strcmp(param
->name
, DATAPDUINORDER
)) {
491 SET_PSTATE_NEGOTIATE(param
);
492 } else if (!strcmp(param
->name
, DATASEQUENCEINORDER
)) {
493 SET_PSTATE_NEGOTIATE(param
);
494 } else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
495 SET_PSTATE_NEGOTIATE(param
);
496 } else if (!strcmp(param
->name
, SESSIONTYPE
)) {
497 SET_PSTATE_NEGOTIATE(param
);
498 } else if (!strcmp(param
->name
, IFMARKER
)) {
499 SET_PSTATE_NEGOTIATE(param
);
500 } else if (!strcmp(param
->name
, OFMARKER
)) {
501 SET_PSTATE_NEGOTIATE(param
);
502 } else if (!strcmp(param
->name
, IFMARKINT
)) {
503 SET_PSTATE_REJECT(param
);
504 } else if (!strcmp(param
->name
, OFMARKINT
)) {
505 SET_PSTATE_REJECT(param
);
506 } else if (!strcmp(param
->name
, RDMAEXTENSIONS
)) {
508 SET_PSTATE_NEGOTIATE(param
);
509 } else if (!strcmp(param
->name
, INITIATORRECVDATASEGMENTLENGTH
)) {
511 SET_PSTATE_NEGOTIATE(param
);
512 } else if (!strcmp(param
->name
, TARGETRECVDATASEGMENTLENGTH
)) {
514 SET_PSTATE_NEGOTIATE(param
);
521 int iscsi_set_keys_irrelevant_for_discovery(
522 struct iscsi_param_list
*param_list
)
524 struct iscsi_param
*param
;
526 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
527 if (!strcmp(param
->name
, MAXCONNECTIONS
))
528 param
->state
&= ~PSTATE_NEGOTIATE
;
529 else if (!strcmp(param
->name
, INITIALR2T
))
530 param
->state
&= ~PSTATE_NEGOTIATE
;
531 else if (!strcmp(param
->name
, IMMEDIATEDATA
))
532 param
->state
&= ~PSTATE_NEGOTIATE
;
533 else if (!strcmp(param
->name
, MAXBURSTLENGTH
))
534 param
->state
&= ~PSTATE_NEGOTIATE
;
535 else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
))
536 param
->state
&= ~PSTATE_NEGOTIATE
;
537 else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
))
538 param
->state
&= ~PSTATE_NEGOTIATE
;
539 else if (!strcmp(param
->name
, DATAPDUINORDER
))
540 param
->state
&= ~PSTATE_NEGOTIATE
;
541 else if (!strcmp(param
->name
, DATASEQUENCEINORDER
))
542 param
->state
&= ~PSTATE_NEGOTIATE
;
543 else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
))
544 param
->state
&= ~PSTATE_NEGOTIATE
;
545 else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
))
546 param
->state
&= ~PSTATE_NEGOTIATE
;
547 else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
))
548 param
->state
&= ~PSTATE_NEGOTIATE
;
549 else if (!strcmp(param
->name
, IFMARKER
))
550 param
->state
&= ~PSTATE_NEGOTIATE
;
551 else if (!strcmp(param
->name
, OFMARKER
))
552 param
->state
&= ~PSTATE_NEGOTIATE
;
553 else if (!strcmp(param
->name
, IFMARKINT
))
554 param
->state
&= ~PSTATE_NEGOTIATE
;
555 else if (!strcmp(param
->name
, OFMARKINT
))
556 param
->state
&= ~PSTATE_NEGOTIATE
;
557 else if (!strcmp(param
->name
, RDMAEXTENSIONS
))
558 param
->state
&= ~PSTATE_NEGOTIATE
;
559 else if (!strcmp(param
->name
, INITIATORRECVDATASEGMENTLENGTH
))
560 param
->state
&= ~PSTATE_NEGOTIATE
;
561 else if (!strcmp(param
->name
, TARGETRECVDATASEGMENTLENGTH
))
562 param
->state
&= ~PSTATE_NEGOTIATE
;
568 int iscsi_copy_param_list(
569 struct iscsi_param_list
**dst_param_list
,
570 struct iscsi_param_list
*src_param_list
,
573 struct iscsi_param
*param
= NULL
;
574 struct iscsi_param
*new_param
= NULL
;
575 struct iscsi_param_list
*param_list
= NULL
;
577 param_list
= kzalloc(sizeof(struct iscsi_param_list
), GFP_KERNEL
);
579 pr_err("Unable to allocate memory for struct iscsi_param_list.\n");
582 INIT_LIST_HEAD(¶m_list
->param_list
);
583 INIT_LIST_HEAD(¶m_list
->extra_response_list
);
585 list_for_each_entry(param
, &src_param_list
->param_list
, p_list
) {
586 if (!leading
&& (param
->scope
& SCOPE_SESSION_WIDE
)) {
587 if ((strcmp(param
->name
, "TargetName") != 0) &&
588 (strcmp(param
->name
, "InitiatorName") != 0) &&
589 (strcmp(param
->name
, "TargetPortalGroupTag") != 0))
593 new_param
= kzalloc(sizeof(struct iscsi_param
), GFP_KERNEL
);
595 pr_err("Unable to allocate memory for struct iscsi_param.\n");
599 new_param
->name
= kstrdup(param
->name
, GFP_KERNEL
);
600 new_param
->value
= kstrdup(param
->value
, GFP_KERNEL
);
601 if (!new_param
->value
|| !new_param
->name
) {
602 kfree(new_param
->value
);
603 kfree(new_param
->name
);
605 pr_err("Unable to allocate memory for parameter name/value.\n");
609 new_param
->set_param
= param
->set_param
;
610 new_param
->phase
= param
->phase
;
611 new_param
->scope
= param
->scope
;
612 new_param
->sender
= param
->sender
;
613 new_param
->type
= param
->type
;
614 new_param
->use
= param
->use
;
615 new_param
->type_range
= param
->type_range
;
617 list_add_tail(&new_param
->p_list
, ¶m_list
->param_list
);
620 if (!list_empty(¶m_list
->param_list
)) {
621 *dst_param_list
= param_list
;
623 pr_err("No parameters allocated.\n");
630 iscsi_release_param_list(param_list
);
634 static void iscsi_release_extra_responses(struct iscsi_param_list
*param_list
)
636 struct iscsi_extra_response
*er
, *er_tmp
;
638 list_for_each_entry_safe(er
, er_tmp
, ¶m_list
->extra_response_list
,
640 list_del(&er
->er_list
);
645 void iscsi_release_param_list(struct iscsi_param_list
*param_list
)
647 struct iscsi_param
*param
, *param_tmp
;
649 list_for_each_entry_safe(param
, param_tmp
, ¶m_list
->param_list
,
651 list_del(¶m
->p_list
);
658 iscsi_release_extra_responses(param_list
);
663 struct iscsi_param
*iscsi_find_param_from_key(
665 struct iscsi_param_list
*param_list
)
667 struct iscsi_param
*param
;
669 if (!key
|| !param_list
) {
670 pr_err("Key or parameter list pointer is NULL.\n");
674 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
675 if (!strcmp(key
, param
->name
))
679 pr_err("Unable to locate key \"%s\".\n", key
);
683 int iscsi_extract_key_value(char *textbuf
, char **key
, char **value
)
685 *value
= strchr(textbuf
, '=');
687 pr_err("Unable to locate \"=\" separator for key,"
688 " ignoring request.\n");
699 int iscsi_update_param_value(struct iscsi_param
*param
, char *value
)
703 param
->value
= kstrdup(value
, GFP_KERNEL
);
705 pr_err("Unable to allocate memory for value.\n");
709 pr_debug("iSCSI Parameter updated to %s=%s\n",
710 param
->name
, param
->value
);
714 static int iscsi_add_notunderstood_response(
717 struct iscsi_param_list
*param_list
)
719 struct iscsi_extra_response
*extra_response
;
721 if (strlen(value
) > VALUE_MAXLEN
) {
722 pr_err("Value for notunderstood key \"%s\" exceeds %d,"
723 " protocol error.\n", key
, VALUE_MAXLEN
);
727 extra_response
= kzalloc(sizeof(struct iscsi_extra_response
), GFP_KERNEL
);
728 if (!extra_response
) {
729 pr_err("Unable to allocate memory for"
730 " struct iscsi_extra_response.\n");
733 INIT_LIST_HEAD(&extra_response
->er_list
);
735 strlcpy(extra_response
->key
, key
, sizeof(extra_response
->key
));
736 strlcpy(extra_response
->value
, NOTUNDERSTOOD
,
737 sizeof(extra_response
->value
));
739 list_add_tail(&extra_response
->er_list
,
740 ¶m_list
->extra_response_list
);
744 static int iscsi_check_for_auth_key(char *key
)
749 if (!strcmp(key
, "CHAP_A") || !strcmp(key
, "CHAP_I") ||
750 !strcmp(key
, "CHAP_C") || !strcmp(key
, "CHAP_N") ||
751 !strcmp(key
, "CHAP_R"))
757 if (!strcmp(key
, "SRP_U") || !strcmp(key
, "SRP_N") ||
758 !strcmp(key
, "SRP_g") || !strcmp(key
, "SRP_s") ||
759 !strcmp(key
, "SRP_A") || !strcmp(key
, "SRP_B") ||
760 !strcmp(key
, "SRP_M") || !strcmp(key
, "SRP_HM"))
766 static void iscsi_check_proposer_for_optional_reply(struct iscsi_param
*param
)
768 if (IS_TYPE_BOOL_AND(param
)) {
769 if (!strcmp(param
->value
, NO
))
770 SET_PSTATE_REPLY_OPTIONAL(param
);
771 } else if (IS_TYPE_BOOL_OR(param
)) {
772 if (!strcmp(param
->value
, YES
))
773 SET_PSTATE_REPLY_OPTIONAL(param
);
775 * Required for gPXE iSCSI boot client
777 if (!strcmp(param
->name
, IMMEDIATEDATA
))
778 SET_PSTATE_REPLY_OPTIONAL(param
);
779 } else if (IS_TYPE_NUMBER(param
)) {
780 if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
))
781 SET_PSTATE_REPLY_OPTIONAL(param
);
783 * The GlobalSAN iSCSI Initiator for MacOSX does
784 * not respond to MaxBurstLength, FirstBurstLength,
785 * DefaultTime2Wait or DefaultTime2Retain parameter keys.
786 * So, we set them to 'reply optional' here, and assume the
787 * the defaults from iscsi_parameters.h if the initiator
788 * is not RFC compliant and the keys are not negotiated.
790 if (!strcmp(param
->name
, MAXBURSTLENGTH
))
791 SET_PSTATE_REPLY_OPTIONAL(param
);
792 if (!strcmp(param
->name
, FIRSTBURSTLENGTH
))
793 SET_PSTATE_REPLY_OPTIONAL(param
);
794 if (!strcmp(param
->name
, DEFAULTTIME2WAIT
))
795 SET_PSTATE_REPLY_OPTIONAL(param
);
796 if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
))
797 SET_PSTATE_REPLY_OPTIONAL(param
);
799 * Required for gPXE iSCSI boot client
801 if (!strcmp(param
->name
, MAXCONNECTIONS
))
802 SET_PSTATE_REPLY_OPTIONAL(param
);
803 } else if (IS_PHASE_DECLARATIVE(param
))
804 SET_PSTATE_REPLY_OPTIONAL(param
);
807 static int iscsi_check_boolean_value(struct iscsi_param
*param
, char *value
)
809 if (strcmp(value
, YES
) && strcmp(value
, NO
)) {
810 pr_err("Illegal value for \"%s\", must be either"
811 " \"%s\" or \"%s\".\n", param
->name
, YES
, NO
);
818 static int iscsi_check_numerical_value(struct iscsi_param
*param
, char *value_ptr
)
823 value
= simple_strtoul(value_ptr
, &tmpptr
, 0);
825 if (IS_TYPERANGE_0_TO_2(param
)) {
826 if ((value
< 0) || (value
> 2)) {
827 pr_err("Illegal value for \"%s\", must be"
828 " between 0 and 2.\n", param
->name
);
833 if (IS_TYPERANGE_0_TO_3600(param
)) {
834 if ((value
< 0) || (value
> 3600)) {
835 pr_err("Illegal value for \"%s\", must be"
836 " between 0 and 3600.\n", param
->name
);
841 if (IS_TYPERANGE_0_TO_32767(param
)) {
842 if ((value
< 0) || (value
> 32767)) {
843 pr_err("Illegal value for \"%s\", must be"
844 " between 0 and 32767.\n", param
->name
);
849 if (IS_TYPERANGE_0_TO_65535(param
)) {
850 if ((value
< 0) || (value
> 65535)) {
851 pr_err("Illegal value for \"%s\", must be"
852 " between 0 and 65535.\n", param
->name
);
857 if (IS_TYPERANGE_1_TO_65535(param
)) {
858 if ((value
< 1) || (value
> 65535)) {
859 pr_err("Illegal value for \"%s\", must be"
860 " between 1 and 65535.\n", param
->name
);
865 if (IS_TYPERANGE_2_TO_3600(param
)) {
866 if ((value
< 2) || (value
> 3600)) {
867 pr_err("Illegal value for \"%s\", must be"
868 " between 2 and 3600.\n", param
->name
);
873 if (IS_TYPERANGE_512_TO_16777215(param
)) {
874 if ((value
< 512) || (value
> 16777215)) {
875 pr_err("Illegal value for \"%s\", must be"
876 " between 512 and 16777215.\n", param
->name
);
885 static int iscsi_check_string_or_list_value(struct iscsi_param
*param
, char *value
)
887 if (IS_PSTATE_PROPOSER(param
))
890 if (IS_TYPERANGE_AUTH_PARAM(param
)) {
891 if (strcmp(value
, KRB5
) && strcmp(value
, SPKM1
) &&
892 strcmp(value
, SPKM2
) && strcmp(value
, SRP
) &&
893 strcmp(value
, CHAP
) && strcmp(value
, NONE
)) {
894 pr_err("Illegal value for \"%s\", must be"
895 " \"%s\", \"%s\", \"%s\", \"%s\", \"%s\""
896 " or \"%s\".\n", param
->name
, KRB5
,
897 SPKM1
, SPKM2
, SRP
, CHAP
, NONE
);
901 if (IS_TYPERANGE_DIGEST_PARAM(param
)) {
902 if (strcmp(value
, CRC32C
) && strcmp(value
, NONE
)) {
903 pr_err("Illegal value for \"%s\", must be"
904 " \"%s\" or \"%s\".\n", param
->name
,
909 if (IS_TYPERANGE_SESSIONTYPE(param
)) {
910 if (strcmp(value
, DISCOVERY
) && strcmp(value
, NORMAL
)) {
911 pr_err("Illegal value for \"%s\", must be"
912 " \"%s\" or \"%s\".\n", param
->name
,
921 static char *iscsi_check_valuelist_for_support(
922 struct iscsi_param
*param
,
925 char *tmp1
= NULL
, *tmp2
= NULL
;
926 char *acceptor_values
= NULL
, *proposer_values
= NULL
;
928 acceptor_values
= param
->value
;
929 proposer_values
= value
;
932 if (!proposer_values
)
934 tmp1
= strchr(proposer_values
, ',');
937 acceptor_values
= param
->value
;
939 if (!acceptor_values
) {
944 tmp2
= strchr(acceptor_values
, ',');
947 if (!strcmp(acceptor_values
, proposer_values
)) {
955 acceptor_values
= tmp2
;
956 } while (acceptor_values
);
959 proposer_values
= tmp1
;
960 } while (proposer_values
);
963 return proposer_values
;
966 static int iscsi_check_acceptor_state(struct iscsi_param
*param
, char *value
,
967 struct iscsi_conn
*conn
)
969 u8 acceptor_boolean_value
= 0, proposer_boolean_value
= 0;
970 char *negotiated_value
= NULL
;
972 if (IS_PSTATE_ACCEPTOR(param
)) {
973 pr_err("Received key \"%s\" twice, protocol error.\n",
978 if (IS_PSTATE_REJECT(param
))
981 if (IS_TYPE_BOOL_AND(param
)) {
982 if (!strcmp(value
, YES
))
983 proposer_boolean_value
= 1;
984 if (!strcmp(param
->value
, YES
))
985 acceptor_boolean_value
= 1;
986 if (acceptor_boolean_value
&& proposer_boolean_value
)
989 if (iscsi_update_param_value(param
, NO
) < 0)
991 if (!proposer_boolean_value
)
992 SET_PSTATE_REPLY_OPTIONAL(param
);
994 } else if (IS_TYPE_BOOL_OR(param
)) {
995 if (!strcmp(value
, YES
))
996 proposer_boolean_value
= 1;
997 if (!strcmp(param
->value
, YES
))
998 acceptor_boolean_value
= 1;
999 if (acceptor_boolean_value
|| proposer_boolean_value
) {
1000 if (iscsi_update_param_value(param
, YES
) < 0)
1002 if (proposer_boolean_value
)
1003 SET_PSTATE_REPLY_OPTIONAL(param
);
1005 } else if (IS_TYPE_NUMBER(param
)) {
1006 char *tmpptr
, buf
[11];
1007 u32 acceptor_value
= simple_strtoul(param
->value
, &tmpptr
, 0);
1008 u32 proposer_value
= simple_strtoul(value
, &tmpptr
, 0);
1010 memset(buf
, 0, sizeof(buf
));
1012 if (!strcmp(param
->name
, MAXCONNECTIONS
) ||
1013 !strcmp(param
->name
, MAXBURSTLENGTH
) ||
1014 !strcmp(param
->name
, FIRSTBURSTLENGTH
) ||
1015 !strcmp(param
->name
, MAXOUTSTANDINGR2T
) ||
1016 !strcmp(param
->name
, DEFAULTTIME2RETAIN
) ||
1017 !strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
1018 if (proposer_value
> acceptor_value
) {
1019 sprintf(buf
, "%u", acceptor_value
);
1020 if (iscsi_update_param_value(param
,
1024 if (iscsi_update_param_value(param
, value
) < 0)
1027 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
1028 if (acceptor_value
> proposer_value
) {
1029 sprintf(buf
, "%u", acceptor_value
);
1030 if (iscsi_update_param_value(param
,
1034 if (iscsi_update_param_value(param
, value
) < 0)
1038 if (iscsi_update_param_value(param
, value
) < 0)
1042 if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
1043 struct iscsi_param
*param_mxdsl
;
1044 unsigned long long tmp
;
1047 rc
= kstrtoull(param
->value
, 0, &tmp
);
1051 conn
->conn_ops
->MaxRecvDataSegmentLength
= tmp
;
1052 pr_debug("Saving op->MaxRecvDataSegmentLength from"
1053 " original initiator received value: %u\n",
1054 conn
->conn_ops
->MaxRecvDataSegmentLength
);
1056 param_mxdsl
= iscsi_find_param_from_key(
1057 MAXXMITDATASEGMENTLENGTH
,
1062 rc
= iscsi_update_param_value(param
,
1063 param_mxdsl
->value
);
1067 pr_debug("Updated %s to target MXDSL value: %s\n",
1068 param
->name
, param
->value
);
1070 } else if (IS_TYPE_VALUE_LIST(param
)) {
1071 negotiated_value
= iscsi_check_valuelist_for_support(
1073 if (!negotiated_value
) {
1074 pr_err("Proposer's value list \"%s\" contains"
1075 " no valid values from Acceptor's value list"
1076 " \"%s\".\n", value
, param
->value
);
1079 if (iscsi_update_param_value(param
, negotiated_value
) < 0)
1081 } else if (IS_PHASE_DECLARATIVE(param
)) {
1082 if (iscsi_update_param_value(param
, value
) < 0)
1084 SET_PSTATE_REPLY_OPTIONAL(param
);
1090 static int iscsi_check_proposer_state(struct iscsi_param
*param
, char *value
)
1092 if (IS_PSTATE_RESPONSE_GOT(param
)) {
1093 pr_err("Received key \"%s\" twice, protocol error.\n",
1098 if (IS_TYPE_VALUE_LIST(param
)) {
1099 char *comma_ptr
= NULL
, *tmp_ptr
= NULL
;
1101 comma_ptr
= strchr(value
, ',');
1103 pr_err("Illegal \",\" in response for \"%s\".\n",
1108 tmp_ptr
= iscsi_check_valuelist_for_support(param
, value
);
1113 if (iscsi_update_param_value(param
, value
) < 0)
1119 static int iscsi_check_value(struct iscsi_param
*param
, char *value
)
1121 char *comma_ptr
= NULL
;
1123 if (!strcmp(value
, REJECT
)) {
1124 if (!strcmp(param
->name
, IFMARKINT
) ||
1125 !strcmp(param
->name
, OFMARKINT
)) {
1127 * Reject is not fatal for [I,O]FMarkInt, and causes
1128 * [I,O]FMarker to be reset to No. (See iSCSI v20 A.3.2)
1130 SET_PSTATE_REJECT(param
);
1133 pr_err("Received %s=%s\n", param
->name
, value
);
1136 if (!strcmp(value
, IRRELEVANT
)) {
1137 pr_debug("Received %s=%s\n", param
->name
, value
);
1138 SET_PSTATE_IRRELEVANT(param
);
1141 if (!strcmp(value
, NOTUNDERSTOOD
)) {
1142 if (!IS_PSTATE_PROPOSER(param
)) {
1143 pr_err("Received illegal offer %s=%s\n",
1144 param
->name
, value
);
1148 /* #warning FIXME: Add check for X-ExtensionKey here */
1149 pr_err("Standard iSCSI key \"%s\" cannot be answered"
1150 " with \"%s\", protocol error.\n", param
->name
, value
);
1156 comma_ptr
= strchr(value
, ',');
1158 if (comma_ptr
&& !IS_TYPE_VALUE_LIST(param
)) {
1159 pr_err("Detected value separator \",\", but"
1160 " key \"%s\" does not allow a value list,"
1161 " protocol error.\n", param
->name
);
1167 if (strlen(value
) > VALUE_MAXLEN
) {
1168 pr_err("Value for key \"%s\" exceeds %d,"
1169 " protocol error.\n", param
->name
,
1174 if (IS_TYPE_BOOL_AND(param
) || IS_TYPE_BOOL_OR(param
)) {
1175 if (iscsi_check_boolean_value(param
, value
) < 0)
1177 } else if (IS_TYPE_NUMBER(param
)) {
1178 if (iscsi_check_numerical_value(param
, value
) < 0)
1180 } else if (IS_TYPE_STRING(param
) || IS_TYPE_VALUE_LIST(param
)) {
1181 if (iscsi_check_string_or_list_value(param
, value
) < 0)
1184 pr_err("Huh? 0x%02x\n", param
->type
);
1197 static struct iscsi_param
*__iscsi_check_key(
1200 struct iscsi_param_list
*param_list
)
1202 struct iscsi_param
*param
;
1204 if (strlen(key
) > KEY_MAXLEN
) {
1205 pr_err("Length of key name \"%s\" exceeds %d.\n",
1210 param
= iscsi_find_param_from_key(key
, param_list
);
1214 if ((sender
& SENDER_INITIATOR
) && !IS_SENDER_INITIATOR(param
)) {
1215 pr_err("Key \"%s\" may not be sent to %s,"
1216 " protocol error.\n", param
->name
,
1217 (sender
& SENDER_RECEIVER
) ? "target" : "initiator");
1221 if ((sender
& SENDER_TARGET
) && !IS_SENDER_TARGET(param
)) {
1222 pr_err("Key \"%s\" may not be sent to %s,"
1223 " protocol error.\n", param
->name
,
1224 (sender
& SENDER_RECEIVER
) ? "initiator" : "target");
1231 static struct iscsi_param
*iscsi_check_key(
1235 struct iscsi_param_list
*param_list
)
1237 struct iscsi_param
*param
;
1239 * Key name length must not exceed 63 bytes. (See iSCSI v20 5.1)
1241 if (strlen(key
) > KEY_MAXLEN
) {
1242 pr_err("Length of key name \"%s\" exceeds %d.\n",
1247 param
= iscsi_find_param_from_key(key
, param_list
);
1251 if ((sender
& SENDER_INITIATOR
) && !IS_SENDER_INITIATOR(param
)) {
1252 pr_err("Key \"%s\" may not be sent to %s,"
1253 " protocol error.\n", param
->name
,
1254 (sender
& SENDER_RECEIVER
) ? "target" : "initiator");
1257 if ((sender
& SENDER_TARGET
) && !IS_SENDER_TARGET(param
)) {
1258 pr_err("Key \"%s\" may not be sent to %s,"
1259 " protocol error.\n", param
->name
,
1260 (sender
& SENDER_RECEIVER
) ? "initiator" : "target");
1264 if (IS_PSTATE_ACCEPTOR(param
)) {
1265 pr_err("Key \"%s\" received twice, protocol error.\n",
1273 if (!(param
->phase
& phase
)) {
1274 pr_err("Key \"%s\" may not be negotiated during ",
1277 case PHASE_SECURITY
:
1278 pr_debug("Security phase.\n");
1280 case PHASE_OPERATIONAL
:
1281 pr_debug("Operational phase.\n");
1284 pr_debug("Unknown phase.\n");
1292 static int iscsi_enforce_integrity_rules(
1294 struct iscsi_param_list
*param_list
)
1297 u8 DataSequenceInOrder
= 0;
1298 u8 ErrorRecoveryLevel
= 0, SessionType
= 0;
1299 u32 FirstBurstLength
= 0, MaxBurstLength
= 0;
1300 struct iscsi_param
*param
= NULL
;
1302 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1303 if (!(param
->phase
& phase
))
1305 if (!strcmp(param
->name
, SESSIONTYPE
))
1306 if (!strcmp(param
->value
, NORMAL
))
1308 if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
))
1309 ErrorRecoveryLevel
= simple_strtoul(param
->value
,
1311 if (!strcmp(param
->name
, DATASEQUENCEINORDER
))
1312 if (!strcmp(param
->value
, YES
))
1313 DataSequenceInOrder
= 1;
1314 if (!strcmp(param
->name
, MAXBURSTLENGTH
))
1315 MaxBurstLength
= simple_strtoul(param
->value
,
1319 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1320 if (!(param
->phase
& phase
))
1322 if (!SessionType
&& !IS_PSTATE_ACCEPTOR(param
))
1324 if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
) &&
1325 DataSequenceInOrder
&& (ErrorRecoveryLevel
> 0)) {
1326 if (strcmp(param
->value
, "1")) {
1327 if (iscsi_update_param_value(param
, "1") < 0)
1329 pr_debug("Reset \"%s\" to \"%s\".\n",
1330 param
->name
, param
->value
);
1333 if (!strcmp(param
->name
, MAXCONNECTIONS
) && !SessionType
) {
1334 if (strcmp(param
->value
, "1")) {
1335 if (iscsi_update_param_value(param
, "1") < 0)
1337 pr_debug("Reset \"%s\" to \"%s\".\n",
1338 param
->name
, param
->value
);
1341 if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
1342 FirstBurstLength
= simple_strtoul(param
->value
,
1344 if (FirstBurstLength
> MaxBurstLength
) {
1346 memset(tmpbuf
, 0, sizeof(tmpbuf
));
1347 sprintf(tmpbuf
, "%u", MaxBurstLength
);
1348 if (iscsi_update_param_value(param
, tmpbuf
))
1350 pr_debug("Reset \"%s\" to \"%s\".\n",
1351 param
->name
, param
->value
);
1359 int iscsi_decode_text_input(
1364 struct iscsi_conn
*conn
)
1366 struct iscsi_param_list
*param_list
= conn
->param_list
;
1367 char *tmpbuf
, *start
= NULL
, *end
= NULL
;
1369 tmpbuf
= kzalloc(length
+ 1, GFP_KERNEL
);
1371 pr_err("Unable to allocate %u + 1 bytes for tmpbuf.\n", length
);
1375 memcpy(tmpbuf
, textbuf
, length
);
1376 tmpbuf
[length
] = '\0';
1378 end
= (start
+ length
);
1380 while (start
< end
) {
1382 struct iscsi_param
*param
;
1384 if (iscsi_extract_key_value(start
, &key
, &value
) < 0) {
1389 pr_debug("Got key: %s=%s\n", key
, value
);
1391 if (phase
& PHASE_SECURITY
) {
1392 if (iscsi_check_for_auth_key(key
) > 0) {
1398 param
= iscsi_check_key(key
, phase
, sender
, param_list
);
1400 if (iscsi_add_notunderstood_response(key
,
1401 value
, param_list
) < 0) {
1405 start
+= strlen(key
) + strlen(value
) + 2;
1408 if (iscsi_check_value(param
, value
) < 0) {
1413 start
+= strlen(key
) + strlen(value
) + 2;
1415 if (IS_PSTATE_PROPOSER(param
)) {
1416 if (iscsi_check_proposer_state(param
, value
) < 0) {
1420 SET_PSTATE_RESPONSE_GOT(param
);
1422 if (iscsi_check_acceptor_state(param
, value
, conn
) < 0) {
1426 SET_PSTATE_ACCEPTOR(param
);
1434 int iscsi_encode_text_output(
1439 struct iscsi_param_list
*param_list
)
1441 char *output_buf
= NULL
;
1442 struct iscsi_extra_response
*er
;
1443 struct iscsi_param
*param
;
1445 output_buf
= textbuf
+ *length
;
1447 if (iscsi_enforce_integrity_rules(phase
, param_list
) < 0)
1450 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1451 if (!(param
->sender
& sender
))
1453 if (IS_PSTATE_ACCEPTOR(param
) &&
1454 !IS_PSTATE_RESPONSE_SENT(param
) &&
1455 !IS_PSTATE_REPLY_OPTIONAL(param
) &&
1456 (param
->phase
& phase
)) {
1457 *length
+= sprintf(output_buf
, "%s=%s",
1458 param
->name
, param
->value
);
1460 output_buf
= textbuf
+ *length
;
1461 SET_PSTATE_RESPONSE_SENT(param
);
1462 pr_debug("Sending key: %s=%s\n",
1463 param
->name
, param
->value
);
1466 if (IS_PSTATE_NEGOTIATE(param
) &&
1467 !IS_PSTATE_ACCEPTOR(param
) &&
1468 !IS_PSTATE_PROPOSER(param
) &&
1469 (param
->phase
& phase
)) {
1470 *length
+= sprintf(output_buf
, "%s=%s",
1471 param
->name
, param
->value
);
1473 output_buf
= textbuf
+ *length
;
1474 SET_PSTATE_PROPOSER(param
);
1475 iscsi_check_proposer_for_optional_reply(param
);
1476 pr_debug("Sending key: %s=%s\n",
1477 param
->name
, param
->value
);
1481 list_for_each_entry(er
, ¶m_list
->extra_response_list
, er_list
) {
1482 *length
+= sprintf(output_buf
, "%s=%s", er
->key
, er
->value
);
1484 output_buf
= textbuf
+ *length
;
1485 pr_debug("Sending key: %s=%s\n", er
->key
, er
->value
);
1487 iscsi_release_extra_responses(param_list
);
1492 int iscsi_check_negotiated_keys(struct iscsi_param_list
*param_list
)
1495 struct iscsi_param
*param
;
1497 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1498 if (IS_PSTATE_NEGOTIATE(param
) &&
1499 IS_PSTATE_PROPOSER(param
) &&
1500 !IS_PSTATE_RESPONSE_GOT(param
) &&
1501 !IS_PSTATE_REPLY_OPTIONAL(param
) &&
1502 !IS_PHASE_DECLARATIVE(param
)) {
1503 pr_err("No response for proposed key \"%s\".\n",
1512 int iscsi_change_param_value(
1514 struct iscsi_param_list
*param_list
,
1517 char *key
= NULL
, *value
= NULL
;
1518 struct iscsi_param
*param
;
1521 if (iscsi_extract_key_value(keyvalue
, &key
, &value
) < 0)
1525 param
= __iscsi_check_key(keyvalue
, sender
, param_list
);
1529 param
= iscsi_check_key(keyvalue
, 0, sender
, param_list
);
1533 param
->set_param
= 1;
1534 if (iscsi_check_value(param
, value
) < 0) {
1535 param
->set_param
= 0;
1538 param
->set_param
= 0;
1541 if (iscsi_update_param_value(param
, value
) < 0)
1547 void iscsi_set_connection_parameters(
1548 struct iscsi_conn_ops
*ops
,
1549 struct iscsi_param_list
*param_list
)
1552 struct iscsi_param
*param
;
1554 pr_debug("---------------------------------------------------"
1555 "---------------\n");
1556 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1558 * Special case to set MAXXMITDATASEGMENTLENGTH from the
1559 * target requested MaxRecvDataSegmentLength, even though
1560 * this key is not sent over the wire.
1562 if (!strcmp(param
->name
, MAXXMITDATASEGMENTLENGTH
)) {
1563 ops
->MaxXmitDataSegmentLength
=
1564 simple_strtoul(param
->value
, &tmpptr
, 0);
1565 pr_debug("MaxXmitDataSegmentLength: %s\n",
1569 if (!IS_PSTATE_ACCEPTOR(param
) && !IS_PSTATE_PROPOSER(param
))
1571 if (!strcmp(param
->name
, AUTHMETHOD
)) {
1572 pr_debug("AuthMethod: %s\n",
1574 } else if (!strcmp(param
->name
, HEADERDIGEST
)) {
1575 ops
->HeaderDigest
= !strcmp(param
->value
, CRC32C
);
1576 pr_debug("HeaderDigest: %s\n",
1578 } else if (!strcmp(param
->name
, DATADIGEST
)) {
1579 ops
->DataDigest
= !strcmp(param
->value
, CRC32C
);
1580 pr_debug("DataDigest: %s\n",
1582 } else if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
1584 * At this point iscsi_check_acceptor_state() will have
1585 * set ops->MaxRecvDataSegmentLength from the original
1586 * initiator provided value.
1588 pr_debug("MaxRecvDataSegmentLength: %u\n",
1589 ops
->MaxRecvDataSegmentLength
);
1590 } else if (!strcmp(param
->name
, INITIATORRECVDATASEGMENTLENGTH
)) {
1591 ops
->InitiatorRecvDataSegmentLength
=
1592 simple_strtoul(param
->value
, &tmpptr
, 0);
1593 pr_debug("InitiatorRecvDataSegmentLength: %s\n",
1595 ops
->MaxRecvDataSegmentLength
=
1596 ops
->InitiatorRecvDataSegmentLength
;
1597 pr_debug("Set MRDSL from InitiatorRecvDataSegmentLength\n");
1598 } else if (!strcmp(param
->name
, TARGETRECVDATASEGMENTLENGTH
)) {
1599 ops
->TargetRecvDataSegmentLength
=
1600 simple_strtoul(param
->value
, &tmpptr
, 0);
1601 pr_debug("TargetRecvDataSegmentLength: %s\n",
1603 ops
->MaxXmitDataSegmentLength
=
1604 ops
->TargetRecvDataSegmentLength
;
1605 pr_debug("Set MXDSL from TargetRecvDataSegmentLength\n");
1608 pr_debug("----------------------------------------------------"
1609 "--------------\n");
1612 void iscsi_set_session_parameters(
1613 struct iscsi_sess_ops
*ops
,
1614 struct iscsi_param_list
*param_list
,
1618 struct iscsi_param
*param
;
1620 pr_debug("----------------------------------------------------"
1621 "--------------\n");
1622 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1623 if (!IS_PSTATE_ACCEPTOR(param
) && !IS_PSTATE_PROPOSER(param
))
1625 if (!strcmp(param
->name
, INITIATORNAME
)) {
1629 snprintf(ops
->InitiatorName
,
1630 sizeof(ops
->InitiatorName
),
1631 "%s", param
->value
);
1632 pr_debug("InitiatorName: %s\n",
1634 } else if (!strcmp(param
->name
, INITIATORALIAS
)) {
1637 snprintf(ops
->InitiatorAlias
,
1638 sizeof(ops
->InitiatorAlias
),
1639 "%s", param
->value
);
1640 pr_debug("InitiatorAlias: %s\n",
1642 } else if (!strcmp(param
->name
, TARGETNAME
)) {
1646 snprintf(ops
->TargetName
,
1647 sizeof(ops
->TargetName
),
1648 "%s", param
->value
);
1649 pr_debug("TargetName: %s\n",
1651 } else if (!strcmp(param
->name
, TARGETALIAS
)) {
1654 snprintf(ops
->TargetAlias
, sizeof(ops
->TargetAlias
),
1655 "%s", param
->value
);
1656 pr_debug("TargetAlias: %s\n",
1658 } else if (!strcmp(param
->name
, TARGETPORTALGROUPTAG
)) {
1659 ops
->TargetPortalGroupTag
=
1660 simple_strtoul(param
->value
, &tmpptr
, 0);
1661 pr_debug("TargetPortalGroupTag: %s\n",
1663 } else if (!strcmp(param
->name
, MAXCONNECTIONS
)) {
1664 ops
->MaxConnections
=
1665 simple_strtoul(param
->value
, &tmpptr
, 0);
1666 pr_debug("MaxConnections: %s\n",
1668 } else if (!strcmp(param
->name
, INITIALR2T
)) {
1669 ops
->InitialR2T
= !strcmp(param
->value
, YES
);
1670 pr_debug("InitialR2T: %s\n",
1672 } else if (!strcmp(param
->name
, IMMEDIATEDATA
)) {
1673 ops
->ImmediateData
= !strcmp(param
->value
, YES
);
1674 pr_debug("ImmediateData: %s\n",
1676 } else if (!strcmp(param
->name
, MAXBURSTLENGTH
)) {
1677 ops
->MaxBurstLength
=
1678 simple_strtoul(param
->value
, &tmpptr
, 0);
1679 pr_debug("MaxBurstLength: %s\n",
1681 } else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
1682 ops
->FirstBurstLength
=
1683 simple_strtoul(param
->value
, &tmpptr
, 0);
1684 pr_debug("FirstBurstLength: %s\n",
1686 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
1687 ops
->DefaultTime2Wait
=
1688 simple_strtoul(param
->value
, &tmpptr
, 0);
1689 pr_debug("DefaultTime2Wait: %s\n",
1691 } else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
)) {
1692 ops
->DefaultTime2Retain
=
1693 simple_strtoul(param
->value
, &tmpptr
, 0);
1694 pr_debug("DefaultTime2Retain: %s\n",
1696 } else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
)) {
1697 ops
->MaxOutstandingR2T
=
1698 simple_strtoul(param
->value
, &tmpptr
, 0);
1699 pr_debug("MaxOutstandingR2T: %s\n",
1701 } else if (!strcmp(param
->name
, DATAPDUINORDER
)) {
1702 ops
->DataPDUInOrder
= !strcmp(param
->value
, YES
);
1703 pr_debug("DataPDUInOrder: %s\n",
1705 } else if (!strcmp(param
->name
, DATASEQUENCEINORDER
)) {
1706 ops
->DataSequenceInOrder
= !strcmp(param
->value
, YES
);
1707 pr_debug("DataSequenceInOrder: %s\n",
1709 } else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
1710 ops
->ErrorRecoveryLevel
=
1711 simple_strtoul(param
->value
, &tmpptr
, 0);
1712 pr_debug("ErrorRecoveryLevel: %s\n",
1714 } else if (!strcmp(param
->name
, SESSIONTYPE
)) {
1715 ops
->SessionType
= !strcmp(param
->value
, DISCOVERY
);
1716 pr_debug("SessionType: %s\n",
1718 } else if (!strcmp(param
->name
, RDMAEXTENSIONS
)) {
1719 ops
->RDMAExtensions
= !strcmp(param
->value
, YES
);
1720 pr_debug("RDMAExtensions: %s\n",
1724 pr_debug("----------------------------------------------------"
1725 "--------------\n");