1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*******************************************************************************
3 * This file contains main functions related to iSCSI Parameter negotiation.
5 * (c) Copyright 2007-2013 Datera, Inc.
7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
9 ******************************************************************************/
11 #include <linux/slab.h>
12 #include <linux/uio.h> /* struct kvec */
13 #include <target/iscsi/iscsi_target_core.h>
14 #include "iscsi_target_util.h"
15 #include "iscsi_target_parameters.h"
17 int iscsi_login_rx_data(
18 struct iscsi_conn
*conn
,
25 memset(&iov
, 0, sizeof(struct kvec
));
29 rx_got
= rx_data(conn
, &iov
, 1, length
);
30 if (rx_got
!= length
) {
31 pr_err("rx_data returned %d, expecting %d.\n",
39 int iscsi_login_tx_data(
40 struct iscsi_conn
*conn
,
45 int length
, tx_sent
, iov_cnt
= 1;
48 length
= (ISCSI_HDR_LEN
+ text_length
);
50 memset(&iov
[0], 0, 2 * sizeof(struct kvec
));
51 iov
[0].iov_len
= ISCSI_HDR_LEN
;
52 iov
[0].iov_base
= pdu_buf
;
54 if (text_buf
&& text_length
) {
55 iov
[1].iov_len
= text_length
;
56 iov
[1].iov_base
= text_buf
;
60 tx_sent
= tx_data(conn
, &iov
[0], iov_cnt
, length
);
61 if (tx_sent
!= length
) {
62 pr_err("tx_data returned %d, expecting %d.\n",
70 void iscsi_dump_conn_ops(struct iscsi_conn_ops
*conn_ops
)
72 pr_debug("HeaderDigest: %s\n", (conn_ops
->HeaderDigest
) ?
74 pr_debug("DataDigest: %s\n", (conn_ops
->DataDigest
) ?
76 pr_debug("MaxRecvDataSegmentLength: %u\n",
77 conn_ops
->MaxRecvDataSegmentLength
);
80 void iscsi_dump_sess_ops(struct iscsi_sess_ops
*sess_ops
)
82 pr_debug("InitiatorName: %s\n", sess_ops
->InitiatorName
);
83 pr_debug("InitiatorAlias: %s\n", sess_ops
->InitiatorAlias
);
84 pr_debug("TargetName: %s\n", sess_ops
->TargetName
);
85 pr_debug("TargetAlias: %s\n", sess_ops
->TargetAlias
);
86 pr_debug("TargetPortalGroupTag: %hu\n",
87 sess_ops
->TargetPortalGroupTag
);
88 pr_debug("MaxConnections: %hu\n", sess_ops
->MaxConnections
);
89 pr_debug("InitialR2T: %s\n",
90 (sess_ops
->InitialR2T
) ? "Yes" : "No");
91 pr_debug("ImmediateData: %s\n", (sess_ops
->ImmediateData
) ?
93 pr_debug("MaxBurstLength: %u\n", sess_ops
->MaxBurstLength
);
94 pr_debug("FirstBurstLength: %u\n", sess_ops
->FirstBurstLength
);
95 pr_debug("DefaultTime2Wait: %hu\n", sess_ops
->DefaultTime2Wait
);
96 pr_debug("DefaultTime2Retain: %hu\n",
97 sess_ops
->DefaultTime2Retain
);
98 pr_debug("MaxOutstandingR2T: %hu\n",
99 sess_ops
->MaxOutstandingR2T
);
100 pr_debug("DataPDUInOrder: %s\n",
101 (sess_ops
->DataPDUInOrder
) ? "Yes" : "No");
102 pr_debug("DataSequenceInOrder: %s\n",
103 (sess_ops
->DataSequenceInOrder
) ? "Yes" : "No");
104 pr_debug("ErrorRecoveryLevel: %hu\n",
105 sess_ops
->ErrorRecoveryLevel
);
106 pr_debug("SessionType: %s\n", (sess_ops
->SessionType
) ?
107 "Discovery" : "Normal");
110 void iscsi_print_params(struct iscsi_param_list
*param_list
)
112 struct iscsi_param
*param
;
114 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
)
115 pr_debug("%s: %s\n", param
->name
, param
->value
);
118 static struct iscsi_param
*iscsi_set_default_param(struct iscsi_param_list
*param_list
,
119 char *name
, char *value
, u8 phase
, u8 scope
, u8 sender
,
120 u16 type_range
, u8 use
)
122 struct iscsi_param
*param
= NULL
;
124 param
= kzalloc(sizeof(struct iscsi_param
), GFP_KERNEL
);
126 pr_err("Unable to allocate memory for parameter.\n");
129 INIT_LIST_HEAD(¶m
->p_list
);
131 param
->name
= kstrdup(name
, GFP_KERNEL
);
133 pr_err("Unable to allocate memory for parameter name.\n");
137 param
->value
= kstrdup(value
, GFP_KERNEL
);
139 pr_err("Unable to allocate memory for parameter value.\n");
143 param
->phase
= phase
;
144 param
->scope
= scope
;
145 param
->sender
= sender
;
147 param
->type_range
= type_range
;
149 switch (param
->type_range
) {
150 case TYPERANGE_BOOL_AND
:
151 param
->type
= TYPE_BOOL_AND
;
153 case TYPERANGE_BOOL_OR
:
154 param
->type
= TYPE_BOOL_OR
;
156 case TYPERANGE_0_TO_2
:
157 case TYPERANGE_0_TO_3600
:
158 case TYPERANGE_0_TO_32767
:
159 case TYPERANGE_0_TO_65535
:
160 case TYPERANGE_1_TO_65535
:
161 case TYPERANGE_2_TO_3600
:
162 case TYPERANGE_512_TO_16777215
:
163 param
->type
= TYPE_NUMBER
;
166 case TYPERANGE_DIGEST
:
167 param
->type
= TYPE_VALUE_LIST
| TYPE_STRING
;
169 case TYPERANGE_ISCSINAME
:
170 case TYPERANGE_SESSIONTYPE
:
171 case TYPERANGE_TARGETADDRESS
:
173 param
->type
= TYPE_STRING
;
176 pr_err("Unknown type_range 0x%02x\n",
180 list_add_tail(¶m
->p_list
, ¶m_list
->param_list
);
193 /* #warning Add extension keys */
194 int iscsi_create_default_params(struct iscsi_param_list
**param_list_ptr
)
196 struct iscsi_param
*param
= NULL
;
197 struct iscsi_param_list
*pl
;
199 pl
= kzalloc(sizeof(struct iscsi_param_list
), GFP_KERNEL
);
201 pr_err("Unable to allocate memory for"
202 " struct iscsi_param_list.\n");
205 INIT_LIST_HEAD(&pl
->param_list
);
206 INIT_LIST_HEAD(&pl
->extra_response_list
);
209 * The format for setting the initial parameter definitions are:
219 param
= iscsi_set_default_param(pl
, AUTHMETHOD
, INITIAL_AUTHMETHOD
,
220 PHASE_SECURITY
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
221 TYPERANGE_AUTH
, USE_INITIAL_ONLY
);
225 param
= iscsi_set_default_param(pl
, HEADERDIGEST
, INITIAL_HEADERDIGEST
,
226 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
227 TYPERANGE_DIGEST
, USE_INITIAL_ONLY
);
231 param
= iscsi_set_default_param(pl
, DATADIGEST
, INITIAL_DATADIGEST
,
232 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
233 TYPERANGE_DIGEST
, USE_INITIAL_ONLY
);
237 param
= iscsi_set_default_param(pl
, MAXCONNECTIONS
,
238 INITIAL_MAXCONNECTIONS
, PHASE_OPERATIONAL
,
239 SCOPE_SESSION_WIDE
, SENDER_BOTH
,
240 TYPERANGE_1_TO_65535
, USE_LEADING_ONLY
);
244 param
= iscsi_set_default_param(pl
, SENDTARGETS
, INITIAL_SENDTARGETS
,
245 PHASE_FFP0
, SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
250 param
= iscsi_set_default_param(pl
, TARGETNAME
, INITIAL_TARGETNAME
,
251 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
252 TYPERANGE_ISCSINAME
, USE_ALL
);
256 param
= iscsi_set_default_param(pl
, INITIATORNAME
,
257 INITIAL_INITIATORNAME
, PHASE_DECLARATIVE
,
258 SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
259 TYPERANGE_ISCSINAME
, USE_INITIAL_ONLY
);
263 param
= iscsi_set_default_param(pl
, TARGETALIAS
, INITIAL_TARGETALIAS
,
264 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_TARGET
,
265 TYPERANGE_UTF8
, USE_ALL
);
269 param
= iscsi_set_default_param(pl
, INITIATORALIAS
,
270 INITIAL_INITIATORALIAS
, PHASE_DECLARATIVE
,
271 SCOPE_SESSION_WIDE
, SENDER_INITIATOR
, TYPERANGE_UTF8
,
276 param
= iscsi_set_default_param(pl
, TARGETADDRESS
,
277 INITIAL_TARGETADDRESS
, PHASE_DECLARATIVE
,
278 SCOPE_SESSION_WIDE
, SENDER_TARGET
,
279 TYPERANGE_TARGETADDRESS
, USE_ALL
);
283 param
= iscsi_set_default_param(pl
, TARGETPORTALGROUPTAG
,
284 INITIAL_TARGETPORTALGROUPTAG
,
285 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_TARGET
,
286 TYPERANGE_0_TO_65535
, USE_INITIAL_ONLY
);
290 param
= iscsi_set_default_param(pl
, INITIALR2T
, INITIAL_INITIALR2T
,
291 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
292 TYPERANGE_BOOL_OR
, USE_LEADING_ONLY
);
296 param
= iscsi_set_default_param(pl
, IMMEDIATEDATA
,
297 INITIAL_IMMEDIATEDATA
, PHASE_OPERATIONAL
,
298 SCOPE_SESSION_WIDE
, SENDER_BOTH
, TYPERANGE_BOOL_AND
,
303 param
= iscsi_set_default_param(pl
, MAXXMITDATASEGMENTLENGTH
,
304 INITIAL_MAXXMITDATASEGMENTLENGTH
,
305 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
306 TYPERANGE_512_TO_16777215
, USE_ALL
);
310 param
= iscsi_set_default_param(pl
, MAXRECVDATASEGMENTLENGTH
,
311 INITIAL_MAXRECVDATASEGMENTLENGTH
,
312 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
313 TYPERANGE_512_TO_16777215
, USE_ALL
);
317 param
= iscsi_set_default_param(pl
, MAXBURSTLENGTH
,
318 INITIAL_MAXBURSTLENGTH
, PHASE_OPERATIONAL
,
319 SCOPE_SESSION_WIDE
, SENDER_BOTH
,
320 TYPERANGE_512_TO_16777215
, USE_LEADING_ONLY
);
324 param
= iscsi_set_default_param(pl
, FIRSTBURSTLENGTH
,
325 INITIAL_FIRSTBURSTLENGTH
,
326 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
327 TYPERANGE_512_TO_16777215
, USE_LEADING_ONLY
);
331 param
= iscsi_set_default_param(pl
, DEFAULTTIME2WAIT
,
332 INITIAL_DEFAULTTIME2WAIT
,
333 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
334 TYPERANGE_0_TO_3600
, USE_LEADING_ONLY
);
338 param
= iscsi_set_default_param(pl
, DEFAULTTIME2RETAIN
,
339 INITIAL_DEFAULTTIME2RETAIN
,
340 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
341 TYPERANGE_0_TO_3600
, USE_LEADING_ONLY
);
345 param
= iscsi_set_default_param(pl
, MAXOUTSTANDINGR2T
,
346 INITIAL_MAXOUTSTANDINGR2T
,
347 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
348 TYPERANGE_1_TO_65535
, USE_LEADING_ONLY
);
352 param
= iscsi_set_default_param(pl
, DATAPDUINORDER
,
353 INITIAL_DATAPDUINORDER
, PHASE_OPERATIONAL
,
354 SCOPE_SESSION_WIDE
, SENDER_BOTH
, TYPERANGE_BOOL_OR
,
359 param
= iscsi_set_default_param(pl
, DATASEQUENCEINORDER
,
360 INITIAL_DATASEQUENCEINORDER
,
361 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
362 TYPERANGE_BOOL_OR
, USE_LEADING_ONLY
);
366 param
= iscsi_set_default_param(pl
, ERRORRECOVERYLEVEL
,
367 INITIAL_ERRORRECOVERYLEVEL
,
368 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
369 TYPERANGE_0_TO_2
, USE_LEADING_ONLY
);
373 param
= iscsi_set_default_param(pl
, SESSIONTYPE
, INITIAL_SESSIONTYPE
,
374 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
375 TYPERANGE_SESSIONTYPE
, USE_LEADING_ONLY
);
379 param
= iscsi_set_default_param(pl
, IFMARKER
, INITIAL_IFMARKER
,
380 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
381 TYPERANGE_BOOL_AND
, USE_INITIAL_ONLY
);
385 param
= iscsi_set_default_param(pl
, OFMARKER
, INITIAL_OFMARKER
,
386 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
387 TYPERANGE_BOOL_AND
, USE_INITIAL_ONLY
);
391 param
= iscsi_set_default_param(pl
, IFMARKINT
, INITIAL_IFMARKINT
,
392 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
393 TYPERANGE_UTF8
, USE_INITIAL_ONLY
);
397 param
= iscsi_set_default_param(pl
, OFMARKINT
, INITIAL_OFMARKINT
,
398 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
399 TYPERANGE_UTF8
, USE_INITIAL_ONLY
);
404 * Extra parameters for ISER from RFC-5046
406 param
= iscsi_set_default_param(pl
, RDMAEXTENSIONS
, INITIAL_RDMAEXTENSIONS
,
407 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
408 TYPERANGE_BOOL_AND
, USE_LEADING_ONLY
);
412 param
= iscsi_set_default_param(pl
, INITIATORRECVDATASEGMENTLENGTH
,
413 INITIAL_INITIATORRECVDATASEGMENTLENGTH
,
414 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
415 TYPERANGE_512_TO_16777215
, USE_ALL
);
419 param
= iscsi_set_default_param(pl
, TARGETRECVDATASEGMENTLENGTH
,
420 INITIAL_TARGETRECVDATASEGMENTLENGTH
,
421 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
422 TYPERANGE_512_TO_16777215
, USE_ALL
);
426 *param_list_ptr
= pl
;
429 iscsi_release_param_list(pl
);
433 int iscsi_set_keys_to_negotiate(
434 struct iscsi_param_list
*param_list
,
437 struct iscsi_param
*param
;
439 param_list
->iser
= iser
;
441 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
443 if (!strcmp(param
->name
, AUTHMETHOD
)) {
444 SET_PSTATE_NEGOTIATE(param
);
445 } else if (!strcmp(param
->name
, HEADERDIGEST
)) {
447 SET_PSTATE_NEGOTIATE(param
);
448 } 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
)) {
470 SET_PSTATE_NEGOTIATE(param
);
471 } else if (!strcmp(param
->name
, MAXXMITDATASEGMENTLENGTH
)) {
473 } else if (!strcmp(param
->name
, MAXBURSTLENGTH
)) {
474 SET_PSTATE_NEGOTIATE(param
);
475 } else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
476 SET_PSTATE_NEGOTIATE(param
);
477 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
478 SET_PSTATE_NEGOTIATE(param
);
479 } else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
)) {
480 SET_PSTATE_NEGOTIATE(param
);
481 } else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
)) {
482 SET_PSTATE_NEGOTIATE(param
);
483 } else if (!strcmp(param
->name
, DATAPDUINORDER
)) {
484 SET_PSTATE_NEGOTIATE(param
);
485 } else if (!strcmp(param
->name
, DATASEQUENCEINORDER
)) {
486 SET_PSTATE_NEGOTIATE(param
);
487 } else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
488 SET_PSTATE_NEGOTIATE(param
);
489 } else if (!strcmp(param
->name
, SESSIONTYPE
)) {
490 SET_PSTATE_NEGOTIATE(param
);
491 } else if (!strcmp(param
->name
, IFMARKER
)) {
492 SET_PSTATE_REJECT(param
);
493 } else if (!strcmp(param
->name
, OFMARKER
)) {
494 SET_PSTATE_REJECT(param
);
495 } else if (!strcmp(param
->name
, IFMARKINT
)) {
496 SET_PSTATE_REJECT(param
);
497 } else if (!strcmp(param
->name
, OFMARKINT
)) {
498 SET_PSTATE_REJECT(param
);
499 } else if (!strcmp(param
->name
, RDMAEXTENSIONS
)) {
501 SET_PSTATE_NEGOTIATE(param
);
502 } else if (!strcmp(param
->name
, INITIATORRECVDATASEGMENTLENGTH
)) {
504 SET_PSTATE_NEGOTIATE(param
);
505 } else if (!strcmp(param
->name
, TARGETRECVDATASEGMENTLENGTH
)) {
507 SET_PSTATE_NEGOTIATE(param
);
514 int iscsi_set_keys_irrelevant_for_discovery(
515 struct iscsi_param_list
*param_list
)
517 struct iscsi_param
*param
;
519 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
520 if (!strcmp(param
->name
, MAXCONNECTIONS
))
521 param
->state
&= ~PSTATE_NEGOTIATE
;
522 else if (!strcmp(param
->name
, INITIALR2T
))
523 param
->state
&= ~PSTATE_NEGOTIATE
;
524 else if (!strcmp(param
->name
, IMMEDIATEDATA
))
525 param
->state
&= ~PSTATE_NEGOTIATE
;
526 else if (!strcmp(param
->name
, MAXBURSTLENGTH
))
527 param
->state
&= ~PSTATE_NEGOTIATE
;
528 else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
))
529 param
->state
&= ~PSTATE_NEGOTIATE
;
530 else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
))
531 param
->state
&= ~PSTATE_NEGOTIATE
;
532 else if (!strcmp(param
->name
, DATAPDUINORDER
))
533 param
->state
&= ~PSTATE_NEGOTIATE
;
534 else if (!strcmp(param
->name
, DATASEQUENCEINORDER
))
535 param
->state
&= ~PSTATE_NEGOTIATE
;
536 else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
))
537 param
->state
&= ~PSTATE_NEGOTIATE
;
538 else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
))
539 param
->state
&= ~PSTATE_NEGOTIATE
;
540 else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
))
541 param
->state
&= ~PSTATE_NEGOTIATE
;
542 else if (!strcmp(param
->name
, IFMARKER
))
543 param
->state
&= ~PSTATE_NEGOTIATE
;
544 else if (!strcmp(param
->name
, OFMARKER
))
545 param
->state
&= ~PSTATE_NEGOTIATE
;
546 else if (!strcmp(param
->name
, IFMARKINT
))
547 param
->state
&= ~PSTATE_NEGOTIATE
;
548 else if (!strcmp(param
->name
, OFMARKINT
))
549 param
->state
&= ~PSTATE_NEGOTIATE
;
550 else if (!strcmp(param
->name
, RDMAEXTENSIONS
))
551 param
->state
&= ~PSTATE_NEGOTIATE
;
552 else if (!strcmp(param
->name
, INITIATORRECVDATASEGMENTLENGTH
))
553 param
->state
&= ~PSTATE_NEGOTIATE
;
554 else if (!strcmp(param
->name
, TARGETRECVDATASEGMENTLENGTH
))
555 param
->state
&= ~PSTATE_NEGOTIATE
;
561 int iscsi_copy_param_list(
562 struct iscsi_param_list
**dst_param_list
,
563 struct iscsi_param_list
*src_param_list
,
566 struct iscsi_param
*param
= NULL
;
567 struct iscsi_param
*new_param
= NULL
;
568 struct iscsi_param_list
*param_list
= NULL
;
570 param_list
= kzalloc(sizeof(struct iscsi_param_list
), GFP_KERNEL
);
572 pr_err("Unable to allocate memory for struct iscsi_param_list.\n");
575 INIT_LIST_HEAD(¶m_list
->param_list
);
576 INIT_LIST_HEAD(¶m_list
->extra_response_list
);
578 list_for_each_entry(param
, &src_param_list
->param_list
, p_list
) {
579 if (!leading
&& (param
->scope
& SCOPE_SESSION_WIDE
)) {
580 if ((strcmp(param
->name
, "TargetName") != 0) &&
581 (strcmp(param
->name
, "InitiatorName") != 0) &&
582 (strcmp(param
->name
, "TargetPortalGroupTag") != 0))
586 new_param
= kzalloc(sizeof(struct iscsi_param
), GFP_KERNEL
);
588 pr_err("Unable to allocate memory for struct iscsi_param.\n");
592 new_param
->name
= kstrdup(param
->name
, GFP_KERNEL
);
593 new_param
->value
= kstrdup(param
->value
, GFP_KERNEL
);
594 if (!new_param
->value
|| !new_param
->name
) {
595 kfree(new_param
->value
);
596 kfree(new_param
->name
);
598 pr_err("Unable to allocate memory for parameter name/value.\n");
602 new_param
->set_param
= param
->set_param
;
603 new_param
->phase
= param
->phase
;
604 new_param
->scope
= param
->scope
;
605 new_param
->sender
= param
->sender
;
606 new_param
->type
= param
->type
;
607 new_param
->use
= param
->use
;
608 new_param
->type_range
= param
->type_range
;
610 list_add_tail(&new_param
->p_list
, ¶m_list
->param_list
);
613 if (!list_empty(¶m_list
->param_list
)) {
614 *dst_param_list
= param_list
;
616 pr_err("No parameters allocated.\n");
623 iscsi_release_param_list(param_list
);
627 static void iscsi_release_extra_responses(struct iscsi_param_list
*param_list
)
629 struct iscsi_extra_response
*er
, *er_tmp
;
631 list_for_each_entry_safe(er
, er_tmp
, ¶m_list
->extra_response_list
,
633 list_del(&er
->er_list
);
638 void iscsi_release_param_list(struct iscsi_param_list
*param_list
)
640 struct iscsi_param
*param
, *param_tmp
;
642 list_for_each_entry_safe(param
, param_tmp
, ¶m_list
->param_list
,
644 list_del(¶m
->p_list
);
651 iscsi_release_extra_responses(param_list
);
656 struct iscsi_param
*iscsi_find_param_from_key(
658 struct iscsi_param_list
*param_list
)
660 struct iscsi_param
*param
;
662 if (!key
|| !param_list
) {
663 pr_err("Key or parameter list pointer is NULL.\n");
667 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
668 if (!strcmp(key
, param
->name
))
672 pr_err("Unable to locate key \"%s\".\n", key
);
675 EXPORT_SYMBOL(iscsi_find_param_from_key
);
677 int iscsi_extract_key_value(char *textbuf
, char **key
, char **value
)
679 *value
= strchr(textbuf
, '=');
681 pr_err("Unable to locate \"=\" separator for key,"
682 " ignoring request.\n");
693 int iscsi_update_param_value(struct iscsi_param
*param
, char *value
)
697 param
->value
= kstrdup(value
, GFP_KERNEL
);
699 pr_err("Unable to allocate memory for value.\n");
703 pr_debug("iSCSI Parameter updated to %s=%s\n",
704 param
->name
, param
->value
);
708 static int iscsi_add_notunderstood_response(
711 struct iscsi_param_list
*param_list
)
713 struct iscsi_extra_response
*extra_response
;
715 if (strlen(value
) > VALUE_MAXLEN
) {
716 pr_err("Value for notunderstood key \"%s\" exceeds %d,"
717 " protocol error.\n", key
, VALUE_MAXLEN
);
721 extra_response
= kzalloc(sizeof(struct iscsi_extra_response
), GFP_KERNEL
);
722 if (!extra_response
) {
723 pr_err("Unable to allocate memory for"
724 " struct iscsi_extra_response.\n");
727 INIT_LIST_HEAD(&extra_response
->er_list
);
729 strlcpy(extra_response
->key
, key
, sizeof(extra_response
->key
));
730 strlcpy(extra_response
->value
, NOTUNDERSTOOD
,
731 sizeof(extra_response
->value
));
733 list_add_tail(&extra_response
->er_list
,
734 ¶m_list
->extra_response_list
);
738 static int iscsi_check_for_auth_key(char *key
)
743 if (!strcmp(key
, "CHAP_A") || !strcmp(key
, "CHAP_I") ||
744 !strcmp(key
, "CHAP_C") || !strcmp(key
, "CHAP_N") ||
745 !strcmp(key
, "CHAP_R"))
751 if (!strcmp(key
, "SRP_U") || !strcmp(key
, "SRP_N") ||
752 !strcmp(key
, "SRP_g") || !strcmp(key
, "SRP_s") ||
753 !strcmp(key
, "SRP_A") || !strcmp(key
, "SRP_B") ||
754 !strcmp(key
, "SRP_M") || !strcmp(key
, "SRP_HM"))
760 static void iscsi_check_proposer_for_optional_reply(struct iscsi_param
*param
,
761 bool keys_workaround
)
763 if (IS_TYPE_BOOL_AND(param
)) {
764 if (!strcmp(param
->value
, NO
))
765 SET_PSTATE_REPLY_OPTIONAL(param
);
766 } else if (IS_TYPE_BOOL_OR(param
)) {
767 if (!strcmp(param
->value
, YES
))
768 SET_PSTATE_REPLY_OPTIONAL(param
);
770 if (keys_workaround
) {
772 * Required for gPXE iSCSI boot client
774 if (!strcmp(param
->name
, IMMEDIATEDATA
))
775 SET_PSTATE_REPLY_OPTIONAL(param
);
777 } else if (IS_TYPE_NUMBER(param
)) {
778 if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
))
779 SET_PSTATE_REPLY_OPTIONAL(param
);
781 if (keys_workaround
) {
783 * Required for Mellanox Flexboot PXE boot ROM
785 if (!strcmp(param
->name
, FIRSTBURSTLENGTH
))
786 SET_PSTATE_REPLY_OPTIONAL(param
);
789 * Required for gPXE iSCSI boot client
791 if (!strcmp(param
->name
, MAXCONNECTIONS
))
792 SET_PSTATE_REPLY_OPTIONAL(param
);
794 } else if (IS_PHASE_DECLARATIVE(param
))
795 SET_PSTATE_REPLY_OPTIONAL(param
);
798 static int iscsi_check_boolean_value(struct iscsi_param
*param
, char *value
)
800 if (strcmp(value
, YES
) && strcmp(value
, NO
)) {
801 pr_err("Illegal value for \"%s\", must be either"
802 " \"%s\" or \"%s\".\n", param
->name
, YES
, NO
);
809 static int iscsi_check_numerical_value(struct iscsi_param
*param
, char *value_ptr
)
814 value
= simple_strtoul(value_ptr
, &tmpptr
, 0);
816 if (IS_TYPERANGE_0_TO_2(param
)) {
817 if ((value
< 0) || (value
> 2)) {
818 pr_err("Illegal value for \"%s\", must be"
819 " between 0 and 2.\n", param
->name
);
824 if (IS_TYPERANGE_0_TO_3600(param
)) {
825 if ((value
< 0) || (value
> 3600)) {
826 pr_err("Illegal value for \"%s\", must be"
827 " between 0 and 3600.\n", param
->name
);
832 if (IS_TYPERANGE_0_TO_32767(param
)) {
833 if ((value
< 0) || (value
> 32767)) {
834 pr_err("Illegal value for \"%s\", must be"
835 " between 0 and 32767.\n", param
->name
);
840 if (IS_TYPERANGE_0_TO_65535(param
)) {
841 if ((value
< 0) || (value
> 65535)) {
842 pr_err("Illegal value for \"%s\", must be"
843 " between 0 and 65535.\n", param
->name
);
848 if (IS_TYPERANGE_1_TO_65535(param
)) {
849 if ((value
< 1) || (value
> 65535)) {
850 pr_err("Illegal value for \"%s\", must be"
851 " between 1 and 65535.\n", param
->name
);
856 if (IS_TYPERANGE_2_TO_3600(param
)) {
857 if ((value
< 2) || (value
> 3600)) {
858 pr_err("Illegal value for \"%s\", must be"
859 " between 2 and 3600.\n", param
->name
);
864 if (IS_TYPERANGE_512_TO_16777215(param
)) {
865 if ((value
< 512) || (value
> 16777215)) {
866 pr_err("Illegal value for \"%s\", must be"
867 " between 512 and 16777215.\n", param
->name
);
876 static int iscsi_check_string_or_list_value(struct iscsi_param
*param
, char *value
)
878 if (IS_PSTATE_PROPOSER(param
))
881 if (IS_TYPERANGE_AUTH_PARAM(param
)) {
882 if (strcmp(value
, KRB5
) && strcmp(value
, SPKM1
) &&
883 strcmp(value
, SPKM2
) && strcmp(value
, SRP
) &&
884 strcmp(value
, CHAP
) && strcmp(value
, NONE
)) {
885 pr_err("Illegal value for \"%s\", must be"
886 " \"%s\", \"%s\", \"%s\", \"%s\", \"%s\""
887 " or \"%s\".\n", param
->name
, KRB5
,
888 SPKM1
, SPKM2
, SRP
, CHAP
, NONE
);
892 if (IS_TYPERANGE_DIGEST_PARAM(param
)) {
893 if (strcmp(value
, CRC32C
) && strcmp(value
, NONE
)) {
894 pr_err("Illegal value for \"%s\", must be"
895 " \"%s\" or \"%s\".\n", param
->name
,
900 if (IS_TYPERANGE_SESSIONTYPE(param
)) {
901 if (strcmp(value
, DISCOVERY
) && strcmp(value
, NORMAL
)) {
902 pr_err("Illegal value for \"%s\", must be"
903 " \"%s\" or \"%s\".\n", param
->name
,
912 static char *iscsi_check_valuelist_for_support(
913 struct iscsi_param
*param
,
916 char *tmp1
= NULL
, *tmp2
= NULL
;
917 char *acceptor_values
= NULL
, *proposer_values
= NULL
;
919 acceptor_values
= param
->value
;
920 proposer_values
= value
;
923 if (!proposer_values
)
925 tmp1
= strchr(proposer_values
, ',');
928 acceptor_values
= param
->value
;
930 if (!acceptor_values
) {
935 tmp2
= strchr(acceptor_values
, ',');
938 if (!strcmp(acceptor_values
, proposer_values
)) {
946 acceptor_values
= tmp2
;
947 } while (acceptor_values
);
950 proposer_values
= tmp1
;
951 } while (proposer_values
);
954 return proposer_values
;
957 static int iscsi_check_acceptor_state(struct iscsi_param
*param
, char *value
,
958 struct iscsi_conn
*conn
)
960 u8 acceptor_boolean_value
= 0, proposer_boolean_value
= 0;
961 char *negotiated_value
= NULL
;
963 if (IS_PSTATE_ACCEPTOR(param
)) {
964 pr_err("Received key \"%s\" twice, protocol error.\n",
969 if (IS_PSTATE_REJECT(param
))
972 if (IS_TYPE_BOOL_AND(param
)) {
973 if (!strcmp(value
, YES
))
974 proposer_boolean_value
= 1;
975 if (!strcmp(param
->value
, YES
))
976 acceptor_boolean_value
= 1;
977 if (acceptor_boolean_value
&& proposer_boolean_value
)
980 if (iscsi_update_param_value(param
, NO
) < 0)
982 if (!proposer_boolean_value
)
983 SET_PSTATE_REPLY_OPTIONAL(param
);
985 } else if (IS_TYPE_BOOL_OR(param
)) {
986 if (!strcmp(value
, YES
))
987 proposer_boolean_value
= 1;
988 if (!strcmp(param
->value
, YES
))
989 acceptor_boolean_value
= 1;
990 if (acceptor_boolean_value
|| proposer_boolean_value
) {
991 if (iscsi_update_param_value(param
, YES
) < 0)
993 if (proposer_boolean_value
)
994 SET_PSTATE_REPLY_OPTIONAL(param
);
996 } else if (IS_TYPE_NUMBER(param
)) {
997 char *tmpptr
, buf
[11];
998 u32 acceptor_value
= simple_strtoul(param
->value
, &tmpptr
, 0);
999 u32 proposer_value
= simple_strtoul(value
, &tmpptr
, 0);
1001 memset(buf
, 0, sizeof(buf
));
1003 if (!strcmp(param
->name
, MAXCONNECTIONS
) ||
1004 !strcmp(param
->name
, MAXBURSTLENGTH
) ||
1005 !strcmp(param
->name
, FIRSTBURSTLENGTH
) ||
1006 !strcmp(param
->name
, MAXOUTSTANDINGR2T
) ||
1007 !strcmp(param
->name
, DEFAULTTIME2RETAIN
) ||
1008 !strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
1009 if (proposer_value
> acceptor_value
) {
1010 sprintf(buf
, "%u", acceptor_value
);
1011 if (iscsi_update_param_value(param
,
1015 if (iscsi_update_param_value(param
, value
) < 0)
1018 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
1019 if (acceptor_value
> proposer_value
) {
1020 sprintf(buf
, "%u", acceptor_value
);
1021 if (iscsi_update_param_value(param
,
1025 if (iscsi_update_param_value(param
, value
) < 0)
1029 if (iscsi_update_param_value(param
, value
) < 0)
1033 if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
1034 struct iscsi_param
*param_mxdsl
;
1035 unsigned long long tmp
;
1038 rc
= kstrtoull(param
->value
, 0, &tmp
);
1042 conn
->conn_ops
->MaxRecvDataSegmentLength
= tmp
;
1043 pr_debug("Saving op->MaxRecvDataSegmentLength from"
1044 " original initiator received value: %u\n",
1045 conn
->conn_ops
->MaxRecvDataSegmentLength
);
1047 param_mxdsl
= iscsi_find_param_from_key(
1048 MAXXMITDATASEGMENTLENGTH
,
1053 rc
= iscsi_update_param_value(param
,
1054 param_mxdsl
->value
);
1058 pr_debug("Updated %s to target MXDSL value: %s\n",
1059 param
->name
, param
->value
);
1061 } else if (IS_TYPE_VALUE_LIST(param
)) {
1062 negotiated_value
= iscsi_check_valuelist_for_support(
1064 if (!negotiated_value
) {
1065 pr_err("Proposer's value list \"%s\" contains"
1066 " no valid values from Acceptor's value list"
1067 " \"%s\".\n", value
, param
->value
);
1070 if (iscsi_update_param_value(param
, negotiated_value
) < 0)
1072 } else if (IS_PHASE_DECLARATIVE(param
)) {
1073 if (iscsi_update_param_value(param
, value
) < 0)
1075 SET_PSTATE_REPLY_OPTIONAL(param
);
1081 static int iscsi_check_proposer_state(struct iscsi_param
*param
, char *value
)
1083 if (IS_PSTATE_RESPONSE_GOT(param
)) {
1084 pr_err("Received key \"%s\" twice, protocol error.\n",
1089 if (IS_TYPE_VALUE_LIST(param
)) {
1090 char *comma_ptr
= NULL
, *tmp_ptr
= NULL
;
1092 comma_ptr
= strchr(value
, ',');
1094 pr_err("Illegal \",\" in response for \"%s\".\n",
1099 tmp_ptr
= iscsi_check_valuelist_for_support(param
, value
);
1104 if (iscsi_update_param_value(param
, value
) < 0)
1110 static int iscsi_check_value(struct iscsi_param
*param
, char *value
)
1112 char *comma_ptr
= NULL
;
1114 if (!strcmp(value
, REJECT
)) {
1115 if (!strcmp(param
->name
, IFMARKINT
) ||
1116 !strcmp(param
->name
, OFMARKINT
)) {
1118 * Reject is not fatal for [I,O]FMarkInt, and causes
1119 * [I,O]FMarker to be reset to No. (See iSCSI v20 A.3.2)
1121 SET_PSTATE_REJECT(param
);
1124 pr_err("Received %s=%s\n", param
->name
, value
);
1127 if (!strcmp(value
, IRRELEVANT
)) {
1128 pr_debug("Received %s=%s\n", param
->name
, value
);
1129 SET_PSTATE_IRRELEVANT(param
);
1132 if (!strcmp(value
, NOTUNDERSTOOD
)) {
1133 if (!IS_PSTATE_PROPOSER(param
)) {
1134 pr_err("Received illegal offer %s=%s\n",
1135 param
->name
, value
);
1139 /* #warning FIXME: Add check for X-ExtensionKey here */
1140 pr_err("Standard iSCSI key \"%s\" cannot be answered"
1141 " with \"%s\", protocol error.\n", param
->name
, value
);
1147 comma_ptr
= strchr(value
, ',');
1149 if (comma_ptr
&& !IS_TYPE_VALUE_LIST(param
)) {
1150 pr_err("Detected value separator \",\", but"
1151 " key \"%s\" does not allow a value list,"
1152 " protocol error.\n", param
->name
);
1158 if (strlen(value
) > VALUE_MAXLEN
) {
1159 pr_err("Value for key \"%s\" exceeds %d,"
1160 " protocol error.\n", param
->name
,
1165 if (IS_TYPE_BOOL_AND(param
) || IS_TYPE_BOOL_OR(param
)) {
1166 if (iscsi_check_boolean_value(param
, value
) < 0)
1168 } else if (IS_TYPE_NUMBER(param
)) {
1169 if (iscsi_check_numerical_value(param
, value
) < 0)
1171 } else if (IS_TYPE_STRING(param
) || IS_TYPE_VALUE_LIST(param
)) {
1172 if (iscsi_check_string_or_list_value(param
, value
) < 0)
1175 pr_err("Huh? 0x%02x\n", param
->type
);
1188 static struct iscsi_param
*__iscsi_check_key(
1191 struct iscsi_param_list
*param_list
)
1193 struct iscsi_param
*param
;
1195 if (strlen(key
) > KEY_MAXLEN
) {
1196 pr_err("Length of key name \"%s\" exceeds %d.\n",
1201 param
= iscsi_find_param_from_key(key
, param_list
);
1205 if ((sender
& SENDER_INITIATOR
) && !IS_SENDER_INITIATOR(param
)) {
1206 pr_err("Key \"%s\" may not be sent to %s,"
1207 " protocol error.\n", param
->name
,
1208 (sender
& SENDER_RECEIVER
) ? "target" : "initiator");
1212 if ((sender
& SENDER_TARGET
) && !IS_SENDER_TARGET(param
)) {
1213 pr_err("Key \"%s\" may not be sent to %s,"
1214 " protocol error.\n", param
->name
,
1215 (sender
& SENDER_RECEIVER
) ? "initiator" : "target");
1222 static struct iscsi_param
*iscsi_check_key(
1226 struct iscsi_param_list
*param_list
)
1228 struct iscsi_param
*param
;
1230 * Key name length must not exceed 63 bytes. (See iSCSI v20 5.1)
1232 if (strlen(key
) > KEY_MAXLEN
) {
1233 pr_err("Length of key name \"%s\" exceeds %d.\n",
1238 param
= iscsi_find_param_from_key(key
, param_list
);
1242 if ((sender
& SENDER_INITIATOR
) && !IS_SENDER_INITIATOR(param
)) {
1243 pr_err("Key \"%s\" may not be sent to %s,"
1244 " protocol error.\n", param
->name
,
1245 (sender
& SENDER_RECEIVER
) ? "target" : "initiator");
1248 if ((sender
& SENDER_TARGET
) && !IS_SENDER_TARGET(param
)) {
1249 pr_err("Key \"%s\" may not be sent to %s,"
1250 " protocol error.\n", param
->name
,
1251 (sender
& SENDER_RECEIVER
) ? "initiator" : "target");
1255 if (IS_PSTATE_ACCEPTOR(param
)) {
1256 pr_err("Key \"%s\" received twice, protocol error.\n",
1264 if (!(param
->phase
& phase
)) {
1265 pr_err("Key \"%s\" may not be negotiated during ",
1268 case PHASE_SECURITY
:
1269 pr_debug("Security phase.\n");
1271 case PHASE_OPERATIONAL
:
1272 pr_debug("Operational phase.\n");
1275 pr_debug("Unknown phase.\n");
1283 static int iscsi_enforce_integrity_rules(
1285 struct iscsi_param_list
*param_list
)
1288 u8 DataSequenceInOrder
= 0;
1289 u8 ErrorRecoveryLevel
= 0, SessionType
= 0;
1290 u32 FirstBurstLength
= 0, MaxBurstLength
= 0;
1291 struct iscsi_param
*param
= NULL
;
1293 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1294 if (!(param
->phase
& phase
))
1296 if (!strcmp(param
->name
, SESSIONTYPE
))
1297 if (!strcmp(param
->value
, NORMAL
))
1299 if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
))
1300 ErrorRecoveryLevel
= simple_strtoul(param
->value
,
1302 if (!strcmp(param
->name
, DATASEQUENCEINORDER
))
1303 if (!strcmp(param
->value
, YES
))
1304 DataSequenceInOrder
= 1;
1305 if (!strcmp(param
->name
, MAXBURSTLENGTH
))
1306 MaxBurstLength
= simple_strtoul(param
->value
,
1310 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1311 if (!(param
->phase
& phase
))
1313 if (!SessionType
&& !IS_PSTATE_ACCEPTOR(param
))
1315 if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
) &&
1316 DataSequenceInOrder
&& (ErrorRecoveryLevel
> 0)) {
1317 if (strcmp(param
->value
, "1")) {
1318 if (iscsi_update_param_value(param
, "1") < 0)
1320 pr_debug("Reset \"%s\" to \"%s\".\n",
1321 param
->name
, param
->value
);
1324 if (!strcmp(param
->name
, MAXCONNECTIONS
) && !SessionType
) {
1325 if (strcmp(param
->value
, "1")) {
1326 if (iscsi_update_param_value(param
, "1") < 0)
1328 pr_debug("Reset \"%s\" to \"%s\".\n",
1329 param
->name
, param
->value
);
1332 if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
1333 FirstBurstLength
= simple_strtoul(param
->value
,
1335 if (FirstBurstLength
> MaxBurstLength
) {
1337 memset(tmpbuf
, 0, sizeof(tmpbuf
));
1338 sprintf(tmpbuf
, "%u", MaxBurstLength
);
1339 if (iscsi_update_param_value(param
, tmpbuf
))
1341 pr_debug("Reset \"%s\" to \"%s\".\n",
1342 param
->name
, param
->value
);
1350 int iscsi_decode_text_input(
1355 struct iscsi_conn
*conn
)
1357 struct iscsi_param_list
*param_list
= conn
->param_list
;
1358 char *tmpbuf
, *start
= NULL
, *end
= NULL
;
1360 tmpbuf
= kzalloc(length
+ 1, GFP_KERNEL
);
1362 pr_err("Unable to allocate %u + 1 bytes for tmpbuf.\n", length
);
1366 memcpy(tmpbuf
, textbuf
, length
);
1367 tmpbuf
[length
] = '\0';
1369 end
= (start
+ length
);
1371 while (start
< end
) {
1373 struct iscsi_param
*param
;
1375 if (iscsi_extract_key_value(start
, &key
, &value
) < 0)
1378 pr_debug("Got key: %s=%s\n", key
, value
);
1380 if (phase
& PHASE_SECURITY
) {
1381 if (iscsi_check_for_auth_key(key
) > 0) {
1387 param
= iscsi_check_key(key
, phase
, sender
, param_list
);
1389 if (iscsi_add_notunderstood_response(key
, value
,
1393 start
+= strlen(key
) + strlen(value
) + 2;
1396 if (iscsi_check_value(param
, value
) < 0)
1399 start
+= strlen(key
) + strlen(value
) + 2;
1401 if (IS_PSTATE_PROPOSER(param
)) {
1402 if (iscsi_check_proposer_state(param
, value
) < 0)
1405 SET_PSTATE_RESPONSE_GOT(param
);
1407 if (iscsi_check_acceptor_state(param
, value
, conn
) < 0)
1410 SET_PSTATE_ACCEPTOR(param
);
1422 int iscsi_encode_text_output(
1427 struct iscsi_param_list
*param_list
,
1428 bool keys_workaround
)
1430 char *output_buf
= NULL
;
1431 struct iscsi_extra_response
*er
;
1432 struct iscsi_param
*param
;
1434 output_buf
= textbuf
+ *length
;
1436 if (iscsi_enforce_integrity_rules(phase
, param_list
) < 0)
1439 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1440 if (!(param
->sender
& sender
))
1442 if (IS_PSTATE_ACCEPTOR(param
) &&
1443 !IS_PSTATE_RESPONSE_SENT(param
) &&
1444 !IS_PSTATE_REPLY_OPTIONAL(param
) &&
1445 (param
->phase
& phase
)) {
1446 *length
+= sprintf(output_buf
, "%s=%s",
1447 param
->name
, param
->value
);
1449 output_buf
= textbuf
+ *length
;
1450 SET_PSTATE_RESPONSE_SENT(param
);
1451 pr_debug("Sending key: %s=%s\n",
1452 param
->name
, param
->value
);
1455 if (IS_PSTATE_NEGOTIATE(param
) &&
1456 !IS_PSTATE_ACCEPTOR(param
) &&
1457 !IS_PSTATE_PROPOSER(param
) &&
1458 (param
->phase
& phase
)) {
1459 *length
+= sprintf(output_buf
, "%s=%s",
1460 param
->name
, param
->value
);
1462 output_buf
= textbuf
+ *length
;
1463 SET_PSTATE_PROPOSER(param
);
1464 iscsi_check_proposer_for_optional_reply(param
,
1466 pr_debug("Sending key: %s=%s\n",
1467 param
->name
, param
->value
);
1471 list_for_each_entry(er
, ¶m_list
->extra_response_list
, er_list
) {
1472 *length
+= sprintf(output_buf
, "%s=%s", er
->key
, er
->value
);
1474 output_buf
= textbuf
+ *length
;
1475 pr_debug("Sending key: %s=%s\n", er
->key
, er
->value
);
1477 iscsi_release_extra_responses(param_list
);
1482 int iscsi_check_negotiated_keys(struct iscsi_param_list
*param_list
)
1485 struct iscsi_param
*param
;
1487 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1488 if (IS_PSTATE_NEGOTIATE(param
) &&
1489 IS_PSTATE_PROPOSER(param
) &&
1490 !IS_PSTATE_RESPONSE_GOT(param
) &&
1491 !IS_PSTATE_REPLY_OPTIONAL(param
) &&
1492 !IS_PHASE_DECLARATIVE(param
)) {
1493 pr_err("No response for proposed key \"%s\".\n",
1502 int iscsi_change_param_value(
1504 struct iscsi_param_list
*param_list
,
1507 char *key
= NULL
, *value
= NULL
;
1508 struct iscsi_param
*param
;
1511 if (iscsi_extract_key_value(keyvalue
, &key
, &value
) < 0)
1515 param
= __iscsi_check_key(keyvalue
, sender
, param_list
);
1519 param
= iscsi_check_key(keyvalue
, 0, sender
, param_list
);
1523 param
->set_param
= 1;
1524 if (iscsi_check_value(param
, value
) < 0) {
1525 param
->set_param
= 0;
1528 param
->set_param
= 0;
1531 if (iscsi_update_param_value(param
, value
) < 0)
1537 void iscsi_set_connection_parameters(
1538 struct iscsi_conn_ops
*ops
,
1539 struct iscsi_param_list
*param_list
)
1542 struct iscsi_param
*param
;
1544 pr_debug("---------------------------------------------------"
1545 "---------------\n");
1546 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1548 * Special case to set MAXXMITDATASEGMENTLENGTH from the
1549 * target requested MaxRecvDataSegmentLength, even though
1550 * this key is not sent over the wire.
1552 if (!strcmp(param
->name
, MAXXMITDATASEGMENTLENGTH
)) {
1553 ops
->MaxXmitDataSegmentLength
=
1554 simple_strtoul(param
->value
, &tmpptr
, 0);
1555 pr_debug("MaxXmitDataSegmentLength: %s\n",
1559 if (!IS_PSTATE_ACCEPTOR(param
) && !IS_PSTATE_PROPOSER(param
))
1561 if (!strcmp(param
->name
, AUTHMETHOD
)) {
1562 pr_debug("AuthMethod: %s\n",
1564 } else if (!strcmp(param
->name
, HEADERDIGEST
)) {
1565 ops
->HeaderDigest
= !strcmp(param
->value
, CRC32C
);
1566 pr_debug("HeaderDigest: %s\n",
1568 } else if (!strcmp(param
->name
, DATADIGEST
)) {
1569 ops
->DataDigest
= !strcmp(param
->value
, CRC32C
);
1570 pr_debug("DataDigest: %s\n",
1572 } else if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
1574 * At this point iscsi_check_acceptor_state() will have
1575 * set ops->MaxRecvDataSegmentLength from the original
1576 * initiator provided value.
1578 pr_debug("MaxRecvDataSegmentLength: %u\n",
1579 ops
->MaxRecvDataSegmentLength
);
1580 } else if (!strcmp(param
->name
, INITIATORRECVDATASEGMENTLENGTH
)) {
1581 ops
->InitiatorRecvDataSegmentLength
=
1582 simple_strtoul(param
->value
, &tmpptr
, 0);
1583 pr_debug("InitiatorRecvDataSegmentLength: %s\n",
1585 ops
->MaxRecvDataSegmentLength
=
1586 ops
->InitiatorRecvDataSegmentLength
;
1587 pr_debug("Set MRDSL from InitiatorRecvDataSegmentLength\n");
1588 } else if (!strcmp(param
->name
, TARGETRECVDATASEGMENTLENGTH
)) {
1589 ops
->TargetRecvDataSegmentLength
=
1590 simple_strtoul(param
->value
, &tmpptr
, 0);
1591 pr_debug("TargetRecvDataSegmentLength: %s\n",
1593 ops
->MaxXmitDataSegmentLength
=
1594 ops
->TargetRecvDataSegmentLength
;
1595 pr_debug("Set MXDSL from TargetRecvDataSegmentLength\n");
1598 pr_debug("----------------------------------------------------"
1599 "--------------\n");
1602 void iscsi_set_session_parameters(
1603 struct iscsi_sess_ops
*ops
,
1604 struct iscsi_param_list
*param_list
,
1608 struct iscsi_param
*param
;
1610 pr_debug("----------------------------------------------------"
1611 "--------------\n");
1612 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1613 if (!IS_PSTATE_ACCEPTOR(param
) && !IS_PSTATE_PROPOSER(param
))
1615 if (!strcmp(param
->name
, INITIATORNAME
)) {
1619 snprintf(ops
->InitiatorName
,
1620 sizeof(ops
->InitiatorName
),
1621 "%s", param
->value
);
1622 pr_debug("InitiatorName: %s\n",
1624 } else if (!strcmp(param
->name
, INITIATORALIAS
)) {
1627 snprintf(ops
->InitiatorAlias
,
1628 sizeof(ops
->InitiatorAlias
),
1629 "%s", param
->value
);
1630 pr_debug("InitiatorAlias: %s\n",
1632 } else if (!strcmp(param
->name
, TARGETNAME
)) {
1636 snprintf(ops
->TargetName
,
1637 sizeof(ops
->TargetName
),
1638 "%s", param
->value
);
1639 pr_debug("TargetName: %s\n",
1641 } else if (!strcmp(param
->name
, TARGETALIAS
)) {
1644 snprintf(ops
->TargetAlias
, sizeof(ops
->TargetAlias
),
1645 "%s", param
->value
);
1646 pr_debug("TargetAlias: %s\n",
1648 } else if (!strcmp(param
->name
, TARGETPORTALGROUPTAG
)) {
1649 ops
->TargetPortalGroupTag
=
1650 simple_strtoul(param
->value
, &tmpptr
, 0);
1651 pr_debug("TargetPortalGroupTag: %s\n",
1653 } else if (!strcmp(param
->name
, MAXCONNECTIONS
)) {
1654 ops
->MaxConnections
=
1655 simple_strtoul(param
->value
, &tmpptr
, 0);
1656 pr_debug("MaxConnections: %s\n",
1658 } else if (!strcmp(param
->name
, INITIALR2T
)) {
1659 ops
->InitialR2T
= !strcmp(param
->value
, YES
);
1660 pr_debug("InitialR2T: %s\n",
1662 } else if (!strcmp(param
->name
, IMMEDIATEDATA
)) {
1663 ops
->ImmediateData
= !strcmp(param
->value
, YES
);
1664 pr_debug("ImmediateData: %s\n",
1666 } else if (!strcmp(param
->name
, MAXBURSTLENGTH
)) {
1667 ops
->MaxBurstLength
=
1668 simple_strtoul(param
->value
, &tmpptr
, 0);
1669 pr_debug("MaxBurstLength: %s\n",
1671 } else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
1672 ops
->FirstBurstLength
=
1673 simple_strtoul(param
->value
, &tmpptr
, 0);
1674 pr_debug("FirstBurstLength: %s\n",
1676 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
1677 ops
->DefaultTime2Wait
=
1678 simple_strtoul(param
->value
, &tmpptr
, 0);
1679 pr_debug("DefaultTime2Wait: %s\n",
1681 } else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
)) {
1682 ops
->DefaultTime2Retain
=
1683 simple_strtoul(param
->value
, &tmpptr
, 0);
1684 pr_debug("DefaultTime2Retain: %s\n",
1686 } else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
)) {
1687 ops
->MaxOutstandingR2T
=
1688 simple_strtoul(param
->value
, &tmpptr
, 0);
1689 pr_debug("MaxOutstandingR2T: %s\n",
1691 } else if (!strcmp(param
->name
, DATAPDUINORDER
)) {
1692 ops
->DataPDUInOrder
= !strcmp(param
->value
, YES
);
1693 pr_debug("DataPDUInOrder: %s\n",
1695 } else if (!strcmp(param
->name
, DATASEQUENCEINORDER
)) {
1696 ops
->DataSequenceInOrder
= !strcmp(param
->value
, YES
);
1697 pr_debug("DataSequenceInOrder: %s\n",
1699 } else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
1700 ops
->ErrorRecoveryLevel
=
1701 simple_strtoul(param
->value
, &tmpptr
, 0);
1702 pr_debug("ErrorRecoveryLevel: %s\n",
1704 } else if (!strcmp(param
->name
, SESSIONTYPE
)) {
1705 ops
->SessionType
= !strcmp(param
->value
, DISCOVERY
);
1706 pr_debug("SessionType: %s\n",
1708 } else if (!strcmp(param
->name
, RDMAEXTENSIONS
)) {
1709 ops
->RDMAExtensions
= !strcmp(param
->value
, YES
);
1710 pr_debug("RDMAExtensions: %s\n",
1714 pr_debug("----------------------------------------------------"
1715 "--------------\n");