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 "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
));
38 * Initial Marker-less Interval.
39 * Add the values regardless of IFMarker/OFMarker, considering
40 * it may not be negoitated yet.
42 conn
->of_marker
+= length
;
44 rx_got
= rx_data(conn
, &iov
, 1, length
);
45 if (rx_got
!= length
) {
46 pr_err("rx_data returned %d, expecting %d.\n",
54 int iscsi_login_tx_data(
55 struct iscsi_conn
*conn
,
60 int length
, tx_sent
, iov_cnt
= 1;
63 length
= (ISCSI_HDR_LEN
+ text_length
);
65 memset(&iov
[0], 0, 2 * sizeof(struct kvec
));
66 iov
[0].iov_len
= ISCSI_HDR_LEN
;
67 iov
[0].iov_base
= pdu_buf
;
69 if (text_buf
&& text_length
) {
70 iov
[1].iov_len
= text_length
;
71 iov
[1].iov_base
= text_buf
;
76 * Initial Marker-less Interval.
77 * Add the values regardless of IFMarker/OFMarker, considering
78 * it may not be negoitated yet.
80 conn
->if_marker
+= length
;
82 tx_sent
= tx_data(conn
, &iov
[0], iov_cnt
, length
);
83 if (tx_sent
!= length
) {
84 pr_err("tx_data returned %d, expecting %d.\n",
92 void iscsi_dump_conn_ops(struct iscsi_conn_ops
*conn_ops
)
94 pr_debug("HeaderDigest: %s\n", (conn_ops
->HeaderDigest
) ?
96 pr_debug("DataDigest: %s\n", (conn_ops
->DataDigest
) ?
98 pr_debug("MaxRecvDataSegmentLength: %u\n",
99 conn_ops
->MaxRecvDataSegmentLength
);
100 pr_debug("OFMarker: %s\n", (conn_ops
->OFMarker
) ? "Yes" : "No");
101 pr_debug("IFMarker: %s\n", (conn_ops
->IFMarker
) ? "Yes" : "No");
102 if (conn_ops
->OFMarker
)
103 pr_debug("OFMarkInt: %u\n", conn_ops
->OFMarkInt
);
104 if (conn_ops
->IFMarker
)
105 pr_debug("IFMarkInt: %u\n", conn_ops
->IFMarkInt
);
108 void iscsi_dump_sess_ops(struct iscsi_sess_ops
*sess_ops
)
110 pr_debug("InitiatorName: %s\n", sess_ops
->InitiatorName
);
111 pr_debug("InitiatorAlias: %s\n", sess_ops
->InitiatorAlias
);
112 pr_debug("TargetName: %s\n", sess_ops
->TargetName
);
113 pr_debug("TargetAlias: %s\n", sess_ops
->TargetAlias
);
114 pr_debug("TargetPortalGroupTag: %hu\n",
115 sess_ops
->TargetPortalGroupTag
);
116 pr_debug("MaxConnections: %hu\n", sess_ops
->MaxConnections
);
117 pr_debug("InitialR2T: %s\n",
118 (sess_ops
->InitialR2T
) ? "Yes" : "No");
119 pr_debug("ImmediateData: %s\n", (sess_ops
->ImmediateData
) ?
121 pr_debug("MaxBurstLength: %u\n", sess_ops
->MaxBurstLength
);
122 pr_debug("FirstBurstLength: %u\n", sess_ops
->FirstBurstLength
);
123 pr_debug("DefaultTime2Wait: %hu\n", sess_ops
->DefaultTime2Wait
);
124 pr_debug("DefaultTime2Retain: %hu\n",
125 sess_ops
->DefaultTime2Retain
);
126 pr_debug("MaxOutstandingR2T: %hu\n",
127 sess_ops
->MaxOutstandingR2T
);
128 pr_debug("DataPDUInOrder: %s\n",
129 (sess_ops
->DataPDUInOrder
) ? "Yes" : "No");
130 pr_debug("DataSequenceInOrder: %s\n",
131 (sess_ops
->DataSequenceInOrder
) ? "Yes" : "No");
132 pr_debug("ErrorRecoveryLevel: %hu\n",
133 sess_ops
->ErrorRecoveryLevel
);
134 pr_debug("SessionType: %s\n", (sess_ops
->SessionType
) ?
135 "Discovery" : "Normal");
138 void iscsi_print_params(struct iscsi_param_list
*param_list
)
140 struct iscsi_param
*param
;
142 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
)
143 pr_debug("%s: %s\n", param
->name
, param
->value
);
146 static struct iscsi_param
*iscsi_set_default_param(struct iscsi_param_list
*param_list
,
147 char *name
, char *value
, u8 phase
, u8 scope
, u8 sender
,
148 u16 type_range
, u8 use
)
150 struct iscsi_param
*param
= NULL
;
152 param
= kzalloc(sizeof(struct iscsi_param
), GFP_KERNEL
);
154 pr_err("Unable to allocate memory for parameter.\n");
157 INIT_LIST_HEAD(¶m
->p_list
);
159 param
->name
= kstrdup(name
, GFP_KERNEL
);
161 pr_err("Unable to allocate memory for parameter name.\n");
165 param
->value
= kstrdup(value
, GFP_KERNEL
);
167 pr_err("Unable to allocate memory for parameter value.\n");
171 param
->phase
= phase
;
172 param
->scope
= scope
;
173 param
->sender
= sender
;
175 param
->type_range
= type_range
;
177 switch (param
->type_range
) {
178 case TYPERANGE_BOOL_AND
:
179 param
->type
= TYPE_BOOL_AND
;
181 case TYPERANGE_BOOL_OR
:
182 param
->type
= TYPE_BOOL_OR
;
184 case TYPERANGE_0_TO_2
:
185 case TYPERANGE_0_TO_3600
:
186 case TYPERANGE_0_TO_32767
:
187 case TYPERANGE_0_TO_65535
:
188 case TYPERANGE_1_TO_65535
:
189 case TYPERANGE_2_TO_3600
:
190 case TYPERANGE_512_TO_16777215
:
191 param
->type
= TYPE_NUMBER
;
194 case TYPERANGE_DIGEST
:
195 param
->type
= TYPE_VALUE_LIST
| TYPE_STRING
;
197 case TYPERANGE_MARKINT
:
198 param
->type
= TYPE_NUMBER_RANGE
;
199 param
->type_range
|= TYPERANGE_1_TO_65535
;
201 case TYPERANGE_ISCSINAME
:
202 case TYPERANGE_SESSIONTYPE
:
203 case TYPERANGE_TARGETADDRESS
:
205 param
->type
= TYPE_STRING
;
208 pr_err("Unknown type_range 0x%02x\n",
212 list_add_tail(¶m
->p_list
, ¶m_list
->param_list
);
225 /* #warning Add extension keys */
226 int iscsi_create_default_params(struct iscsi_param_list
**param_list_ptr
)
228 struct iscsi_param
*param
= NULL
;
229 struct iscsi_param_list
*pl
;
231 pl
= kzalloc(sizeof(struct iscsi_param_list
), GFP_KERNEL
);
233 pr_err("Unable to allocate memory for"
234 " struct iscsi_param_list.\n");
237 INIT_LIST_HEAD(&pl
->param_list
);
238 INIT_LIST_HEAD(&pl
->extra_response_list
);
241 * The format for setting the initial parameter definitions are:
251 param
= iscsi_set_default_param(pl
, AUTHMETHOD
, INITIAL_AUTHMETHOD
,
252 PHASE_SECURITY
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
253 TYPERANGE_AUTH
, USE_INITIAL_ONLY
);
257 param
= iscsi_set_default_param(pl
, HEADERDIGEST
, INITIAL_HEADERDIGEST
,
258 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
259 TYPERANGE_DIGEST
, USE_INITIAL_ONLY
);
263 param
= iscsi_set_default_param(pl
, DATADIGEST
, INITIAL_DATADIGEST
,
264 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
265 TYPERANGE_DIGEST
, USE_INITIAL_ONLY
);
269 param
= iscsi_set_default_param(pl
, MAXCONNECTIONS
,
270 INITIAL_MAXCONNECTIONS
, PHASE_OPERATIONAL
,
271 SCOPE_SESSION_WIDE
, SENDER_BOTH
,
272 TYPERANGE_1_TO_65535
, USE_LEADING_ONLY
);
276 param
= iscsi_set_default_param(pl
, SENDTARGETS
, INITIAL_SENDTARGETS
,
277 PHASE_FFP0
, SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
282 param
= iscsi_set_default_param(pl
, TARGETNAME
, INITIAL_TARGETNAME
,
283 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
284 TYPERANGE_ISCSINAME
, USE_ALL
);
288 param
= iscsi_set_default_param(pl
, INITIATORNAME
,
289 INITIAL_INITIATORNAME
, PHASE_DECLARATIVE
,
290 SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
291 TYPERANGE_ISCSINAME
, USE_INITIAL_ONLY
);
295 param
= iscsi_set_default_param(pl
, TARGETALIAS
, INITIAL_TARGETALIAS
,
296 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_TARGET
,
297 TYPERANGE_UTF8
, USE_ALL
);
301 param
= iscsi_set_default_param(pl
, INITIATORALIAS
,
302 INITIAL_INITIATORALIAS
, PHASE_DECLARATIVE
,
303 SCOPE_SESSION_WIDE
, SENDER_INITIATOR
, TYPERANGE_UTF8
,
308 param
= iscsi_set_default_param(pl
, TARGETADDRESS
,
309 INITIAL_TARGETADDRESS
, PHASE_DECLARATIVE
,
310 SCOPE_SESSION_WIDE
, SENDER_TARGET
,
311 TYPERANGE_TARGETADDRESS
, USE_ALL
);
315 param
= iscsi_set_default_param(pl
, TARGETPORTALGROUPTAG
,
316 INITIAL_TARGETPORTALGROUPTAG
,
317 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_TARGET
,
318 TYPERANGE_0_TO_65535
, USE_INITIAL_ONLY
);
322 param
= iscsi_set_default_param(pl
, INITIALR2T
, INITIAL_INITIALR2T
,
323 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
324 TYPERANGE_BOOL_OR
, USE_LEADING_ONLY
);
328 param
= iscsi_set_default_param(pl
, IMMEDIATEDATA
,
329 INITIAL_IMMEDIATEDATA
, PHASE_OPERATIONAL
,
330 SCOPE_SESSION_WIDE
, SENDER_BOTH
, TYPERANGE_BOOL_AND
,
335 param
= iscsi_set_default_param(pl
, MAXXMITDATASEGMENTLENGTH
,
336 INITIAL_MAXXMITDATASEGMENTLENGTH
,
337 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
338 TYPERANGE_512_TO_16777215
, USE_ALL
);
342 param
= iscsi_set_default_param(pl
, MAXRECVDATASEGMENTLENGTH
,
343 INITIAL_MAXRECVDATASEGMENTLENGTH
,
344 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
345 TYPERANGE_512_TO_16777215
, USE_ALL
);
349 param
= iscsi_set_default_param(pl
, MAXBURSTLENGTH
,
350 INITIAL_MAXBURSTLENGTH
, PHASE_OPERATIONAL
,
351 SCOPE_SESSION_WIDE
, SENDER_BOTH
,
352 TYPERANGE_512_TO_16777215
, USE_LEADING_ONLY
);
356 param
= iscsi_set_default_param(pl
, FIRSTBURSTLENGTH
,
357 INITIAL_FIRSTBURSTLENGTH
,
358 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
359 TYPERANGE_512_TO_16777215
, USE_LEADING_ONLY
);
363 param
= iscsi_set_default_param(pl
, DEFAULTTIME2WAIT
,
364 INITIAL_DEFAULTTIME2WAIT
,
365 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
366 TYPERANGE_0_TO_3600
, USE_LEADING_ONLY
);
370 param
= iscsi_set_default_param(pl
, DEFAULTTIME2RETAIN
,
371 INITIAL_DEFAULTTIME2RETAIN
,
372 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
373 TYPERANGE_0_TO_3600
, USE_LEADING_ONLY
);
377 param
= iscsi_set_default_param(pl
, MAXOUTSTANDINGR2T
,
378 INITIAL_MAXOUTSTANDINGR2T
,
379 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
380 TYPERANGE_1_TO_65535
, USE_LEADING_ONLY
);
384 param
= iscsi_set_default_param(pl
, DATAPDUINORDER
,
385 INITIAL_DATAPDUINORDER
, PHASE_OPERATIONAL
,
386 SCOPE_SESSION_WIDE
, SENDER_BOTH
, TYPERANGE_BOOL_OR
,
391 param
= iscsi_set_default_param(pl
, DATASEQUENCEINORDER
,
392 INITIAL_DATASEQUENCEINORDER
,
393 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
394 TYPERANGE_BOOL_OR
, USE_LEADING_ONLY
);
398 param
= iscsi_set_default_param(pl
, ERRORRECOVERYLEVEL
,
399 INITIAL_ERRORRECOVERYLEVEL
,
400 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
401 TYPERANGE_0_TO_2
, USE_LEADING_ONLY
);
405 param
= iscsi_set_default_param(pl
, SESSIONTYPE
, INITIAL_SESSIONTYPE
,
406 PHASE_DECLARATIVE
, SCOPE_SESSION_WIDE
, SENDER_INITIATOR
,
407 TYPERANGE_SESSIONTYPE
, USE_LEADING_ONLY
);
411 param
= iscsi_set_default_param(pl
, IFMARKER
, INITIAL_IFMARKER
,
412 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
413 TYPERANGE_BOOL_AND
, USE_INITIAL_ONLY
);
417 param
= iscsi_set_default_param(pl
, OFMARKER
, INITIAL_OFMARKER
,
418 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
419 TYPERANGE_BOOL_AND
, USE_INITIAL_ONLY
);
423 param
= iscsi_set_default_param(pl
, IFMARKINT
, INITIAL_IFMARKINT
,
424 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
425 TYPERANGE_MARKINT
, USE_INITIAL_ONLY
);
429 param
= iscsi_set_default_param(pl
, OFMARKINT
, INITIAL_OFMARKINT
,
430 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
431 TYPERANGE_MARKINT
, USE_INITIAL_ONLY
);
435 * Extra parameters for ISER from RFC-5046
437 param
= iscsi_set_default_param(pl
, RDMAEXTENSIONS
, INITIAL_RDMAEXTENSIONS
,
438 PHASE_OPERATIONAL
, SCOPE_SESSION_WIDE
, SENDER_BOTH
,
439 TYPERANGE_BOOL_AND
, USE_LEADING_ONLY
);
443 param
= iscsi_set_default_param(pl
, INITIATORRECVDATASEGMENTLENGTH
,
444 INITIAL_INITIATORRECVDATASEGMENTLENGTH
,
445 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
446 TYPERANGE_512_TO_16777215
, USE_ALL
);
450 param
= iscsi_set_default_param(pl
, TARGETRECVDATASEGMENTLENGTH
,
451 INITIAL_TARGETRECVDATASEGMENTLENGTH
,
452 PHASE_OPERATIONAL
, SCOPE_CONNECTION_ONLY
, SENDER_BOTH
,
453 TYPERANGE_512_TO_16777215
, USE_ALL
);
457 *param_list_ptr
= pl
;
460 iscsi_release_param_list(pl
);
464 int iscsi_set_keys_to_negotiate(
465 struct iscsi_param_list
*param_list
,
468 struct iscsi_param
*param
;
470 param_list
->iser
= iser
;
472 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
474 if (!strcmp(param
->name
, AUTHMETHOD
)) {
475 SET_PSTATE_NEGOTIATE(param
);
476 } else if (!strcmp(param
->name
, HEADERDIGEST
)) {
478 SET_PSTATE_NEGOTIATE(param
);
479 } else if (!strcmp(param
->name
, DATADIGEST
)) {
481 SET_PSTATE_NEGOTIATE(param
);
482 } else if (!strcmp(param
->name
, MAXCONNECTIONS
)) {
483 SET_PSTATE_NEGOTIATE(param
);
484 } else if (!strcmp(param
->name
, TARGETNAME
)) {
486 } else if (!strcmp(param
->name
, INITIATORNAME
)) {
488 } else if (!strcmp(param
->name
, TARGETALIAS
)) {
490 SET_PSTATE_NEGOTIATE(param
);
491 } else if (!strcmp(param
->name
, INITIATORALIAS
)) {
493 } else if (!strcmp(param
->name
, TARGETPORTALGROUPTAG
)) {
494 SET_PSTATE_NEGOTIATE(param
);
495 } else if (!strcmp(param
->name
, INITIALR2T
)) {
496 SET_PSTATE_NEGOTIATE(param
);
497 } else if (!strcmp(param
->name
, IMMEDIATEDATA
)) {
498 SET_PSTATE_NEGOTIATE(param
);
499 } else if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
501 SET_PSTATE_NEGOTIATE(param
);
502 } else if (!strcmp(param
->name
, MAXXMITDATASEGMENTLENGTH
)) {
504 } else if (!strcmp(param
->name
, MAXBURSTLENGTH
)) {
505 SET_PSTATE_NEGOTIATE(param
);
506 } else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
507 SET_PSTATE_NEGOTIATE(param
);
508 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
509 SET_PSTATE_NEGOTIATE(param
);
510 } else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
)) {
511 SET_PSTATE_NEGOTIATE(param
);
512 } else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
)) {
513 SET_PSTATE_NEGOTIATE(param
);
514 } else if (!strcmp(param
->name
, DATAPDUINORDER
)) {
515 SET_PSTATE_NEGOTIATE(param
);
516 } else if (!strcmp(param
->name
, DATASEQUENCEINORDER
)) {
517 SET_PSTATE_NEGOTIATE(param
);
518 } else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
519 SET_PSTATE_NEGOTIATE(param
);
520 } else if (!strcmp(param
->name
, SESSIONTYPE
)) {
521 SET_PSTATE_NEGOTIATE(param
);
522 } else if (!strcmp(param
->name
, IFMARKER
)) {
523 SET_PSTATE_NEGOTIATE(param
);
524 } else if (!strcmp(param
->name
, OFMARKER
)) {
525 SET_PSTATE_NEGOTIATE(param
);
526 } else if (!strcmp(param
->name
, IFMARKINT
)) {
527 SET_PSTATE_NEGOTIATE(param
);
528 } else if (!strcmp(param
->name
, OFMARKINT
)) {
529 SET_PSTATE_NEGOTIATE(param
);
530 } else if (!strcmp(param
->name
, RDMAEXTENSIONS
)) {
532 SET_PSTATE_NEGOTIATE(param
);
533 } else if (!strcmp(param
->name
, INITIATORRECVDATASEGMENTLENGTH
)) {
535 SET_PSTATE_NEGOTIATE(param
);
536 } else if (!strcmp(param
->name
, TARGETRECVDATASEGMENTLENGTH
)) {
538 SET_PSTATE_NEGOTIATE(param
);
545 int iscsi_set_keys_irrelevant_for_discovery(
546 struct iscsi_param_list
*param_list
)
548 struct iscsi_param
*param
;
550 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
551 if (!strcmp(param
->name
, MAXCONNECTIONS
))
552 param
->state
&= ~PSTATE_NEGOTIATE
;
553 else if (!strcmp(param
->name
, INITIALR2T
))
554 param
->state
&= ~PSTATE_NEGOTIATE
;
555 else if (!strcmp(param
->name
, IMMEDIATEDATA
))
556 param
->state
&= ~PSTATE_NEGOTIATE
;
557 else if (!strcmp(param
->name
, MAXBURSTLENGTH
))
558 param
->state
&= ~PSTATE_NEGOTIATE
;
559 else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
))
560 param
->state
&= ~PSTATE_NEGOTIATE
;
561 else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
))
562 param
->state
&= ~PSTATE_NEGOTIATE
;
563 else if (!strcmp(param
->name
, DATAPDUINORDER
))
564 param
->state
&= ~PSTATE_NEGOTIATE
;
565 else if (!strcmp(param
->name
, DATASEQUENCEINORDER
))
566 param
->state
&= ~PSTATE_NEGOTIATE
;
567 else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
))
568 param
->state
&= ~PSTATE_NEGOTIATE
;
569 else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
))
570 param
->state
&= ~PSTATE_NEGOTIATE
;
571 else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
))
572 param
->state
&= ~PSTATE_NEGOTIATE
;
573 else if (!strcmp(param
->name
, IFMARKER
))
574 param
->state
&= ~PSTATE_NEGOTIATE
;
575 else if (!strcmp(param
->name
, OFMARKER
))
576 param
->state
&= ~PSTATE_NEGOTIATE
;
577 else if (!strcmp(param
->name
, IFMARKINT
))
578 param
->state
&= ~PSTATE_NEGOTIATE
;
579 else if (!strcmp(param
->name
, OFMARKINT
))
580 param
->state
&= ~PSTATE_NEGOTIATE
;
581 else if (!strcmp(param
->name
, RDMAEXTENSIONS
))
582 param
->state
&= ~PSTATE_NEGOTIATE
;
583 else if (!strcmp(param
->name
, INITIATORRECVDATASEGMENTLENGTH
))
584 param
->state
&= ~PSTATE_NEGOTIATE
;
585 else if (!strcmp(param
->name
, TARGETRECVDATASEGMENTLENGTH
))
586 param
->state
&= ~PSTATE_NEGOTIATE
;
592 int iscsi_copy_param_list(
593 struct iscsi_param_list
**dst_param_list
,
594 struct iscsi_param_list
*src_param_list
,
597 struct iscsi_param
*param
= NULL
;
598 struct iscsi_param
*new_param
= NULL
;
599 struct iscsi_param_list
*param_list
= NULL
;
601 param_list
= kzalloc(sizeof(struct iscsi_param_list
), GFP_KERNEL
);
603 pr_err("Unable to allocate memory for struct iscsi_param_list.\n");
606 INIT_LIST_HEAD(¶m_list
->param_list
);
607 INIT_LIST_HEAD(¶m_list
->extra_response_list
);
609 list_for_each_entry(param
, &src_param_list
->param_list
, p_list
) {
610 if (!leading
&& (param
->scope
& SCOPE_SESSION_WIDE
)) {
611 if ((strcmp(param
->name
, "TargetName") != 0) &&
612 (strcmp(param
->name
, "InitiatorName") != 0) &&
613 (strcmp(param
->name
, "TargetPortalGroupTag") != 0))
617 new_param
= kzalloc(sizeof(struct iscsi_param
), GFP_KERNEL
);
619 pr_err("Unable to allocate memory for struct iscsi_param.\n");
623 new_param
->name
= kstrdup(param
->name
, GFP_KERNEL
);
624 new_param
->value
= kstrdup(param
->value
, GFP_KERNEL
);
625 if (!new_param
->value
|| !new_param
->name
) {
626 kfree(new_param
->value
);
627 kfree(new_param
->name
);
629 pr_err("Unable to allocate memory for parameter name/value.\n");
633 new_param
->set_param
= param
->set_param
;
634 new_param
->phase
= param
->phase
;
635 new_param
->scope
= param
->scope
;
636 new_param
->sender
= param
->sender
;
637 new_param
->type
= param
->type
;
638 new_param
->use
= param
->use
;
639 new_param
->type_range
= param
->type_range
;
641 list_add_tail(&new_param
->p_list
, ¶m_list
->param_list
);
644 if (!list_empty(¶m_list
->param_list
)) {
645 *dst_param_list
= param_list
;
647 pr_err("No parameters allocated.\n");
654 iscsi_release_param_list(param_list
);
658 static void iscsi_release_extra_responses(struct iscsi_param_list
*param_list
)
660 struct iscsi_extra_response
*er
, *er_tmp
;
662 list_for_each_entry_safe(er
, er_tmp
, ¶m_list
->extra_response_list
,
664 list_del(&er
->er_list
);
669 void iscsi_release_param_list(struct iscsi_param_list
*param_list
)
671 struct iscsi_param
*param
, *param_tmp
;
673 list_for_each_entry_safe(param
, param_tmp
, ¶m_list
->param_list
,
675 list_del(¶m
->p_list
);
682 iscsi_release_extra_responses(param_list
);
687 struct iscsi_param
*iscsi_find_param_from_key(
689 struct iscsi_param_list
*param_list
)
691 struct iscsi_param
*param
;
693 if (!key
|| !param_list
) {
694 pr_err("Key or parameter list pointer is NULL.\n");
698 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
699 if (!strcmp(key
, param
->name
))
703 pr_err("Unable to locate key \"%s\".\n", key
);
707 int iscsi_extract_key_value(char *textbuf
, char **key
, char **value
)
709 *value
= strchr(textbuf
, '=');
711 pr_err("Unable to locate \"=\" separator for key,"
712 " ignoring request.\n");
723 int iscsi_update_param_value(struct iscsi_param
*param
, char *value
)
727 param
->value
= kstrdup(value
, GFP_KERNEL
);
729 pr_err("Unable to allocate memory for value.\n");
733 pr_debug("iSCSI Parameter updated to %s=%s\n",
734 param
->name
, param
->value
);
738 static int iscsi_add_notunderstood_response(
741 struct iscsi_param_list
*param_list
)
743 struct iscsi_extra_response
*extra_response
;
745 if (strlen(value
) > VALUE_MAXLEN
) {
746 pr_err("Value for notunderstood key \"%s\" exceeds %d,"
747 " protocol error.\n", key
, VALUE_MAXLEN
);
751 extra_response
= kzalloc(sizeof(struct iscsi_extra_response
), GFP_KERNEL
);
752 if (!extra_response
) {
753 pr_err("Unable to allocate memory for"
754 " struct iscsi_extra_response.\n");
757 INIT_LIST_HEAD(&extra_response
->er_list
);
759 strlcpy(extra_response
->key
, key
, sizeof(extra_response
->key
));
760 strlcpy(extra_response
->value
, NOTUNDERSTOOD
,
761 sizeof(extra_response
->value
));
763 list_add_tail(&extra_response
->er_list
,
764 ¶m_list
->extra_response_list
);
768 static int iscsi_check_for_auth_key(char *key
)
773 if (!strcmp(key
, "CHAP_A") || !strcmp(key
, "CHAP_I") ||
774 !strcmp(key
, "CHAP_C") || !strcmp(key
, "CHAP_N") ||
775 !strcmp(key
, "CHAP_R"))
781 if (!strcmp(key
, "SRP_U") || !strcmp(key
, "SRP_N") ||
782 !strcmp(key
, "SRP_g") || !strcmp(key
, "SRP_s") ||
783 !strcmp(key
, "SRP_A") || !strcmp(key
, "SRP_B") ||
784 !strcmp(key
, "SRP_M") || !strcmp(key
, "SRP_HM"))
790 static void iscsi_check_proposer_for_optional_reply(struct iscsi_param
*param
)
792 if (IS_TYPE_BOOL_AND(param
)) {
793 if (!strcmp(param
->value
, NO
))
794 SET_PSTATE_REPLY_OPTIONAL(param
);
795 } else if (IS_TYPE_BOOL_OR(param
)) {
796 if (!strcmp(param
->value
, YES
))
797 SET_PSTATE_REPLY_OPTIONAL(param
);
799 * Required for gPXE iSCSI boot client
801 if (!strcmp(param
->name
, IMMEDIATEDATA
))
802 SET_PSTATE_REPLY_OPTIONAL(param
);
803 } else if (IS_TYPE_NUMBER(param
)) {
804 if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
))
805 SET_PSTATE_REPLY_OPTIONAL(param
);
807 * The GlobalSAN iSCSI Initiator for MacOSX does
808 * not respond to MaxBurstLength, FirstBurstLength,
809 * DefaultTime2Wait or DefaultTime2Retain parameter keys.
810 * So, we set them to 'reply optional' here, and assume the
811 * the defaults from iscsi_parameters.h if the initiator
812 * is not RFC compliant and the keys are not negotiated.
814 if (!strcmp(param
->name
, MAXBURSTLENGTH
))
815 SET_PSTATE_REPLY_OPTIONAL(param
);
816 if (!strcmp(param
->name
, FIRSTBURSTLENGTH
))
817 SET_PSTATE_REPLY_OPTIONAL(param
);
818 if (!strcmp(param
->name
, DEFAULTTIME2WAIT
))
819 SET_PSTATE_REPLY_OPTIONAL(param
);
820 if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
))
821 SET_PSTATE_REPLY_OPTIONAL(param
);
823 * Required for gPXE iSCSI boot client
825 if (!strcmp(param
->name
, MAXCONNECTIONS
))
826 SET_PSTATE_REPLY_OPTIONAL(param
);
827 } else if (IS_PHASE_DECLARATIVE(param
))
828 SET_PSTATE_REPLY_OPTIONAL(param
);
831 static int iscsi_check_boolean_value(struct iscsi_param
*param
, char *value
)
833 if (strcmp(value
, YES
) && strcmp(value
, NO
)) {
834 pr_err("Illegal value for \"%s\", must be either"
835 " \"%s\" or \"%s\".\n", param
->name
, YES
, NO
);
842 static int iscsi_check_numerical_value(struct iscsi_param
*param
, char *value_ptr
)
847 value
= simple_strtoul(value_ptr
, &tmpptr
, 0);
849 if (IS_TYPERANGE_0_TO_2(param
)) {
850 if ((value
< 0) || (value
> 2)) {
851 pr_err("Illegal value for \"%s\", must be"
852 " between 0 and 2.\n", param
->name
);
857 if (IS_TYPERANGE_0_TO_3600(param
)) {
858 if ((value
< 0) || (value
> 3600)) {
859 pr_err("Illegal value for \"%s\", must be"
860 " between 0 and 3600.\n", param
->name
);
865 if (IS_TYPERANGE_0_TO_32767(param
)) {
866 if ((value
< 0) || (value
> 32767)) {
867 pr_err("Illegal value for \"%s\", must be"
868 " between 0 and 32767.\n", param
->name
);
873 if (IS_TYPERANGE_0_TO_65535(param
)) {
874 if ((value
< 0) || (value
> 65535)) {
875 pr_err("Illegal value for \"%s\", must be"
876 " between 0 and 65535.\n", param
->name
);
881 if (IS_TYPERANGE_1_TO_65535(param
)) {
882 if ((value
< 1) || (value
> 65535)) {
883 pr_err("Illegal value for \"%s\", must be"
884 " between 1 and 65535.\n", param
->name
);
889 if (IS_TYPERANGE_2_TO_3600(param
)) {
890 if ((value
< 2) || (value
> 3600)) {
891 pr_err("Illegal value for \"%s\", must be"
892 " between 2 and 3600.\n", param
->name
);
897 if (IS_TYPERANGE_512_TO_16777215(param
)) {
898 if ((value
< 512) || (value
> 16777215)) {
899 pr_err("Illegal value for \"%s\", must be"
900 " between 512 and 16777215.\n", param
->name
);
909 static int iscsi_check_numerical_range_value(struct iscsi_param
*param
, char *value
)
911 char *left_val_ptr
= NULL
, *right_val_ptr
= NULL
;
912 char *tilde_ptr
= NULL
;
913 u32 left_val
, right_val
, local_left_val
;
915 if (strcmp(param
->name
, IFMARKINT
) &&
916 strcmp(param
->name
, OFMARKINT
)) {
917 pr_err("Only parameters \"%s\" or \"%s\" may contain a"
918 " numerical range value.\n", IFMARKINT
, OFMARKINT
);
922 if (IS_PSTATE_PROPOSER(param
))
925 tilde_ptr
= strchr(value
, '~');
927 pr_err("Unable to locate numerical range indicator"
928 " \"~\" for \"%s\".\n", param
->name
);
933 left_val_ptr
= value
;
934 right_val_ptr
= value
+ strlen(left_val_ptr
) + 1;
936 if (iscsi_check_numerical_value(param
, left_val_ptr
) < 0)
938 if (iscsi_check_numerical_value(param
, right_val_ptr
) < 0)
941 left_val
= simple_strtoul(left_val_ptr
, NULL
, 0);
942 right_val
= simple_strtoul(right_val_ptr
, NULL
, 0);
945 if (right_val
< left_val
) {
946 pr_err("Numerical range for parameter \"%s\" contains"
947 " a right value which is less than the left.\n",
953 * For now, enforce reasonable defaults for [I,O]FMarkInt.
955 tilde_ptr
= strchr(param
->value
, '~');
957 pr_err("Unable to locate numerical range indicator"
958 " \"~\" for \"%s\".\n", param
->name
);
963 left_val_ptr
= param
->value
;
964 right_val_ptr
= param
->value
+ strlen(left_val_ptr
) + 1;
966 local_left_val
= simple_strtoul(left_val_ptr
, NULL
, 0);
969 if (param
->set_param
) {
970 if ((left_val
< local_left_val
) ||
971 (right_val
< local_left_val
)) {
972 pr_err("Passed value range \"%u~%u\" is below"
973 " minimum left value \"%u\" for key \"%s\","
974 " rejecting.\n", left_val
, right_val
,
975 local_left_val
, param
->name
);
979 if ((left_val
< local_left_val
) &&
980 (right_val
< local_left_val
)) {
981 pr_err("Received value range \"%u~%u\" is"
982 " below minimum left value \"%u\" for key"
983 " \"%s\", rejecting.\n", left_val
, right_val
,
984 local_left_val
, param
->name
);
985 SET_PSTATE_REJECT(param
);
986 if (iscsi_update_param_value(param
, REJECT
) < 0)
994 static int iscsi_check_string_or_list_value(struct iscsi_param
*param
, char *value
)
996 if (IS_PSTATE_PROPOSER(param
))
999 if (IS_TYPERANGE_AUTH_PARAM(param
)) {
1000 if (strcmp(value
, KRB5
) && strcmp(value
, SPKM1
) &&
1001 strcmp(value
, SPKM2
) && strcmp(value
, SRP
) &&
1002 strcmp(value
, CHAP
) && strcmp(value
, NONE
)) {
1003 pr_err("Illegal value for \"%s\", must be"
1004 " \"%s\", \"%s\", \"%s\", \"%s\", \"%s\""
1005 " or \"%s\".\n", param
->name
, KRB5
,
1006 SPKM1
, SPKM2
, SRP
, CHAP
, NONE
);
1010 if (IS_TYPERANGE_DIGEST_PARAM(param
)) {
1011 if (strcmp(value
, CRC32C
) && strcmp(value
, NONE
)) {
1012 pr_err("Illegal value for \"%s\", must be"
1013 " \"%s\" or \"%s\".\n", param
->name
,
1018 if (IS_TYPERANGE_SESSIONTYPE(param
)) {
1019 if (strcmp(value
, DISCOVERY
) && strcmp(value
, NORMAL
)) {
1020 pr_err("Illegal value for \"%s\", must be"
1021 " \"%s\" or \"%s\".\n", param
->name
,
1031 * This function is used to pick a value range number, currently just
1032 * returns the lesser of both right values.
1034 static char *iscsi_get_value_from_number_range(
1035 struct iscsi_param
*param
,
1038 char *end_ptr
, *tilde_ptr1
= NULL
, *tilde_ptr2
= NULL
;
1039 u32 acceptor_right_value
, proposer_right_value
;
1041 tilde_ptr1
= strchr(value
, '~');
1044 *tilde_ptr1
++ = '\0';
1045 proposer_right_value
= simple_strtoul(tilde_ptr1
, &end_ptr
, 0);
1047 tilde_ptr2
= strchr(param
->value
, '~');
1050 *tilde_ptr2
++ = '\0';
1051 acceptor_right_value
= simple_strtoul(tilde_ptr2
, &end_ptr
, 0);
1053 return (acceptor_right_value
>= proposer_right_value
) ?
1054 tilde_ptr1
: tilde_ptr2
;
1057 static char *iscsi_check_valuelist_for_support(
1058 struct iscsi_param
*param
,
1061 char *tmp1
= NULL
, *tmp2
= NULL
;
1062 char *acceptor_values
= NULL
, *proposer_values
= NULL
;
1064 acceptor_values
= param
->value
;
1065 proposer_values
= value
;
1068 if (!proposer_values
)
1070 tmp1
= strchr(proposer_values
, ',');
1073 acceptor_values
= param
->value
;
1075 if (!acceptor_values
) {
1080 tmp2
= strchr(acceptor_values
, ',');
1083 if (!strcmp(acceptor_values
, proposer_values
)) {
1091 acceptor_values
= tmp2
;
1092 } while (acceptor_values
);
1095 proposer_values
= tmp1
;
1096 } while (proposer_values
);
1099 return proposer_values
;
1102 static int iscsi_check_acceptor_state(struct iscsi_param
*param
, char *value
,
1103 struct iscsi_conn
*conn
)
1105 u8 acceptor_boolean_value
= 0, proposer_boolean_value
= 0;
1106 char *negoitated_value
= NULL
;
1108 if (IS_PSTATE_ACCEPTOR(param
)) {
1109 pr_err("Received key \"%s\" twice, protocol error.\n",
1114 if (IS_PSTATE_REJECT(param
))
1117 if (IS_TYPE_BOOL_AND(param
)) {
1118 if (!strcmp(value
, YES
))
1119 proposer_boolean_value
= 1;
1120 if (!strcmp(param
->value
, YES
))
1121 acceptor_boolean_value
= 1;
1122 if (acceptor_boolean_value
&& proposer_boolean_value
)
1125 if (iscsi_update_param_value(param
, NO
) < 0)
1127 if (!proposer_boolean_value
)
1128 SET_PSTATE_REPLY_OPTIONAL(param
);
1130 } else if (IS_TYPE_BOOL_OR(param
)) {
1131 if (!strcmp(value
, YES
))
1132 proposer_boolean_value
= 1;
1133 if (!strcmp(param
->value
, YES
))
1134 acceptor_boolean_value
= 1;
1135 if (acceptor_boolean_value
|| proposer_boolean_value
) {
1136 if (iscsi_update_param_value(param
, YES
) < 0)
1138 if (proposer_boolean_value
)
1139 SET_PSTATE_REPLY_OPTIONAL(param
);
1141 } else if (IS_TYPE_NUMBER(param
)) {
1142 char *tmpptr
, buf
[11];
1143 u32 acceptor_value
= simple_strtoul(param
->value
, &tmpptr
, 0);
1144 u32 proposer_value
= simple_strtoul(value
, &tmpptr
, 0);
1146 memset(buf
, 0, sizeof(buf
));
1148 if (!strcmp(param
->name
, MAXCONNECTIONS
) ||
1149 !strcmp(param
->name
, MAXBURSTLENGTH
) ||
1150 !strcmp(param
->name
, FIRSTBURSTLENGTH
) ||
1151 !strcmp(param
->name
, MAXOUTSTANDINGR2T
) ||
1152 !strcmp(param
->name
, DEFAULTTIME2RETAIN
) ||
1153 !strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
1154 if (proposer_value
> acceptor_value
) {
1155 sprintf(buf
, "%u", acceptor_value
);
1156 if (iscsi_update_param_value(param
,
1160 if (iscsi_update_param_value(param
, value
) < 0)
1163 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
1164 if (acceptor_value
> proposer_value
) {
1165 sprintf(buf
, "%u", acceptor_value
);
1166 if (iscsi_update_param_value(param
,
1170 if (iscsi_update_param_value(param
, value
) < 0)
1174 if (iscsi_update_param_value(param
, value
) < 0)
1178 if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
1179 struct iscsi_param
*param_mxdsl
;
1180 unsigned long long tmp
;
1183 rc
= kstrtoull(param
->value
, 0, &tmp
);
1187 conn
->conn_ops
->MaxRecvDataSegmentLength
= tmp
;
1188 pr_debug("Saving op->MaxRecvDataSegmentLength from"
1189 " original initiator received value: %u\n",
1190 conn
->conn_ops
->MaxRecvDataSegmentLength
);
1192 param_mxdsl
= iscsi_find_param_from_key(
1193 MAXXMITDATASEGMENTLENGTH
,
1198 rc
= iscsi_update_param_value(param
,
1199 param_mxdsl
->value
);
1203 pr_debug("Updated %s to target MXDSL value: %s\n",
1204 param
->name
, param
->value
);
1207 } else if (IS_TYPE_NUMBER_RANGE(param
)) {
1208 negoitated_value
= iscsi_get_value_from_number_range(
1210 if (!negoitated_value
)
1212 if (iscsi_update_param_value(param
, negoitated_value
) < 0)
1214 } else if (IS_TYPE_VALUE_LIST(param
)) {
1215 negoitated_value
= iscsi_check_valuelist_for_support(
1217 if (!negoitated_value
) {
1218 pr_err("Proposer's value list \"%s\" contains"
1219 " no valid values from Acceptor's value list"
1220 " \"%s\".\n", value
, param
->value
);
1223 if (iscsi_update_param_value(param
, negoitated_value
) < 0)
1225 } else if (IS_PHASE_DECLARATIVE(param
)) {
1226 if (iscsi_update_param_value(param
, value
) < 0)
1228 SET_PSTATE_REPLY_OPTIONAL(param
);
1234 static int iscsi_check_proposer_state(struct iscsi_param
*param
, char *value
)
1236 if (IS_PSTATE_RESPONSE_GOT(param
)) {
1237 pr_err("Received key \"%s\" twice, protocol error.\n",
1242 if (IS_TYPE_NUMBER_RANGE(param
)) {
1243 u32 left_val
= 0, right_val
= 0, recieved_value
= 0;
1244 char *left_val_ptr
= NULL
, *right_val_ptr
= NULL
;
1245 char *tilde_ptr
= NULL
;
1247 if (!strcmp(value
, IRRELEVANT
) || !strcmp(value
, REJECT
)) {
1248 if (iscsi_update_param_value(param
, value
) < 0)
1253 tilde_ptr
= strchr(value
, '~');
1255 pr_err("Illegal \"~\" in response for \"%s\".\n",
1259 tilde_ptr
= strchr(param
->value
, '~');
1261 pr_err("Unable to locate numerical range"
1262 " indicator \"~\" for \"%s\".\n", param
->name
);
1267 left_val_ptr
= param
->value
;
1268 right_val_ptr
= param
->value
+ strlen(left_val_ptr
) + 1;
1269 left_val
= simple_strtoul(left_val_ptr
, NULL
, 0);
1270 right_val
= simple_strtoul(right_val_ptr
, NULL
, 0);
1271 recieved_value
= simple_strtoul(value
, NULL
, 0);
1275 if ((recieved_value
< left_val
) ||
1276 (recieved_value
> right_val
)) {
1277 pr_err("Illegal response \"%s=%u\", value must"
1278 " be between %u and %u.\n", param
->name
,
1279 recieved_value
, left_val
, right_val
);
1282 } else if (IS_TYPE_VALUE_LIST(param
)) {
1283 char *comma_ptr
= NULL
, *tmp_ptr
= NULL
;
1285 comma_ptr
= strchr(value
, ',');
1287 pr_err("Illegal \",\" in response for \"%s\".\n",
1292 tmp_ptr
= iscsi_check_valuelist_for_support(param
, value
);
1297 if (iscsi_update_param_value(param
, value
) < 0)
1303 static int iscsi_check_value(struct iscsi_param
*param
, char *value
)
1305 char *comma_ptr
= NULL
;
1307 if (!strcmp(value
, REJECT
)) {
1308 if (!strcmp(param
->name
, IFMARKINT
) ||
1309 !strcmp(param
->name
, OFMARKINT
)) {
1311 * Reject is not fatal for [I,O]FMarkInt, and causes
1312 * [I,O]FMarker to be reset to No. (See iSCSI v20 A.3.2)
1314 SET_PSTATE_REJECT(param
);
1317 pr_err("Received %s=%s\n", param
->name
, value
);
1320 if (!strcmp(value
, IRRELEVANT
)) {
1321 pr_debug("Received %s=%s\n", param
->name
, value
);
1322 SET_PSTATE_IRRELEVANT(param
);
1325 if (!strcmp(value
, NOTUNDERSTOOD
)) {
1326 if (!IS_PSTATE_PROPOSER(param
)) {
1327 pr_err("Received illegal offer %s=%s\n",
1328 param
->name
, value
);
1332 /* #warning FIXME: Add check for X-ExtensionKey here */
1333 pr_err("Standard iSCSI key \"%s\" cannot be answered"
1334 " with \"%s\", protocol error.\n", param
->name
, value
);
1340 comma_ptr
= strchr(value
, ',');
1342 if (comma_ptr
&& !IS_TYPE_VALUE_LIST(param
)) {
1343 pr_err("Detected value separator \",\", but"
1344 " key \"%s\" does not allow a value list,"
1345 " protocol error.\n", param
->name
);
1351 if (strlen(value
) > VALUE_MAXLEN
) {
1352 pr_err("Value for key \"%s\" exceeds %d,"
1353 " protocol error.\n", param
->name
,
1358 if (IS_TYPE_BOOL_AND(param
) || IS_TYPE_BOOL_OR(param
)) {
1359 if (iscsi_check_boolean_value(param
, value
) < 0)
1361 } else if (IS_TYPE_NUMBER(param
)) {
1362 if (iscsi_check_numerical_value(param
, value
) < 0)
1364 } else if (IS_TYPE_NUMBER_RANGE(param
)) {
1365 if (iscsi_check_numerical_range_value(param
, value
) < 0)
1367 } else if (IS_TYPE_STRING(param
) || IS_TYPE_VALUE_LIST(param
)) {
1368 if (iscsi_check_string_or_list_value(param
, value
) < 0)
1371 pr_err("Huh? 0x%02x\n", param
->type
);
1384 static struct iscsi_param
*__iscsi_check_key(
1387 struct iscsi_param_list
*param_list
)
1389 struct iscsi_param
*param
;
1391 if (strlen(key
) > KEY_MAXLEN
) {
1392 pr_err("Length of key name \"%s\" exceeds %d.\n",
1397 param
= iscsi_find_param_from_key(key
, param_list
);
1401 if ((sender
& SENDER_INITIATOR
) && !IS_SENDER_INITIATOR(param
)) {
1402 pr_err("Key \"%s\" may not be sent to %s,"
1403 " protocol error.\n", param
->name
,
1404 (sender
& SENDER_RECEIVER
) ? "target" : "initiator");
1408 if ((sender
& SENDER_TARGET
) && !IS_SENDER_TARGET(param
)) {
1409 pr_err("Key \"%s\" may not be sent to %s,"
1410 " protocol error.\n", param
->name
,
1411 (sender
& SENDER_RECEIVER
) ? "initiator" : "target");
1418 static struct iscsi_param
*iscsi_check_key(
1422 struct iscsi_param_list
*param_list
)
1424 struct iscsi_param
*param
;
1426 * Key name length must not exceed 63 bytes. (See iSCSI v20 5.1)
1428 if (strlen(key
) > KEY_MAXLEN
) {
1429 pr_err("Length of key name \"%s\" exceeds %d.\n",
1434 param
= iscsi_find_param_from_key(key
, param_list
);
1438 if ((sender
& SENDER_INITIATOR
) && !IS_SENDER_INITIATOR(param
)) {
1439 pr_err("Key \"%s\" may not be sent to %s,"
1440 " protocol error.\n", param
->name
,
1441 (sender
& SENDER_RECEIVER
) ? "target" : "initiator");
1444 if ((sender
& SENDER_TARGET
) && !IS_SENDER_TARGET(param
)) {
1445 pr_err("Key \"%s\" may not be sent to %s,"
1446 " protocol error.\n", param
->name
,
1447 (sender
& SENDER_RECEIVER
) ? "initiator" : "target");
1451 if (IS_PSTATE_ACCEPTOR(param
)) {
1452 pr_err("Key \"%s\" received twice, protocol error.\n",
1460 if (!(param
->phase
& phase
)) {
1461 pr_err("Key \"%s\" may not be negotiated during ",
1464 case PHASE_SECURITY
:
1465 pr_debug("Security phase.\n");
1467 case PHASE_OPERATIONAL
:
1468 pr_debug("Operational phase.\n");
1471 pr_debug("Unknown phase.\n");
1479 static int iscsi_enforce_integrity_rules(
1481 struct iscsi_param_list
*param_list
)
1484 u8 DataSequenceInOrder
= 0;
1485 u8 ErrorRecoveryLevel
= 0, SessionType
= 0;
1486 u8 IFMarker
= 0, OFMarker
= 0;
1487 u8 IFMarkInt_Reject
= 1, OFMarkInt_Reject
= 1;
1488 u32 FirstBurstLength
= 0, MaxBurstLength
= 0;
1489 struct iscsi_param
*param
= NULL
;
1491 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1492 if (!(param
->phase
& phase
))
1494 if (!strcmp(param
->name
, SESSIONTYPE
))
1495 if (!strcmp(param
->value
, NORMAL
))
1497 if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
))
1498 ErrorRecoveryLevel
= simple_strtoul(param
->value
,
1500 if (!strcmp(param
->name
, DATASEQUENCEINORDER
))
1501 if (!strcmp(param
->value
, YES
))
1502 DataSequenceInOrder
= 1;
1503 if (!strcmp(param
->name
, MAXBURSTLENGTH
))
1504 MaxBurstLength
= simple_strtoul(param
->value
,
1506 if (!strcmp(param
->name
, IFMARKER
))
1507 if (!strcmp(param
->value
, YES
))
1509 if (!strcmp(param
->name
, OFMARKER
))
1510 if (!strcmp(param
->value
, YES
))
1512 if (!strcmp(param
->name
, IFMARKINT
))
1513 if (!strcmp(param
->value
, REJECT
))
1514 IFMarkInt_Reject
= 1;
1515 if (!strcmp(param
->name
, OFMARKINT
))
1516 if (!strcmp(param
->value
, REJECT
))
1517 OFMarkInt_Reject
= 1;
1520 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1521 if (!(param
->phase
& phase
))
1523 if (!SessionType
&& (!IS_PSTATE_ACCEPTOR(param
) &&
1524 (strcmp(param
->name
, IFMARKER
) &&
1525 strcmp(param
->name
, OFMARKER
) &&
1526 strcmp(param
->name
, IFMARKINT
) &&
1527 strcmp(param
->name
, OFMARKINT
))))
1529 if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
) &&
1530 DataSequenceInOrder
&& (ErrorRecoveryLevel
> 0)) {
1531 if (strcmp(param
->value
, "1")) {
1532 if (iscsi_update_param_value(param
, "1") < 0)
1534 pr_debug("Reset \"%s\" to \"%s\".\n",
1535 param
->name
, param
->value
);
1538 if (!strcmp(param
->name
, MAXCONNECTIONS
) && !SessionType
) {
1539 if (strcmp(param
->value
, "1")) {
1540 if (iscsi_update_param_value(param
, "1") < 0)
1542 pr_debug("Reset \"%s\" to \"%s\".\n",
1543 param
->name
, param
->value
);
1546 if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
1547 FirstBurstLength
= simple_strtoul(param
->value
,
1549 if (FirstBurstLength
> MaxBurstLength
) {
1551 memset(tmpbuf
, 0, sizeof(tmpbuf
));
1552 sprintf(tmpbuf
, "%u", MaxBurstLength
);
1553 if (iscsi_update_param_value(param
, tmpbuf
))
1555 pr_debug("Reset \"%s\" to \"%s\".\n",
1556 param
->name
, param
->value
);
1559 if (!strcmp(param
->name
, IFMARKER
) && IFMarkInt_Reject
) {
1560 if (iscsi_update_param_value(param
, NO
) < 0)
1563 pr_debug("Reset \"%s\" to \"%s\".\n",
1564 param
->name
, param
->value
);
1566 if (!strcmp(param
->name
, OFMARKER
) && OFMarkInt_Reject
) {
1567 if (iscsi_update_param_value(param
, NO
) < 0)
1570 pr_debug("Reset \"%s\" to \"%s\".\n",
1571 param
->name
, param
->value
);
1573 if (!strcmp(param
->name
, IFMARKINT
) && !IFMarker
) {
1574 if (!strcmp(param
->value
, REJECT
))
1576 param
->state
&= ~PSTATE_NEGOTIATE
;
1577 if (iscsi_update_param_value(param
, IRRELEVANT
) < 0)
1579 pr_debug("Reset \"%s\" to \"%s\".\n",
1580 param
->name
, param
->value
);
1582 if (!strcmp(param
->name
, OFMARKINT
) && !OFMarker
) {
1583 if (!strcmp(param
->value
, REJECT
))
1585 param
->state
&= ~PSTATE_NEGOTIATE
;
1586 if (iscsi_update_param_value(param
, IRRELEVANT
) < 0)
1588 pr_debug("Reset \"%s\" to \"%s\".\n",
1589 param
->name
, param
->value
);
1596 int iscsi_decode_text_input(
1601 struct iscsi_conn
*conn
)
1603 struct iscsi_param_list
*param_list
= conn
->param_list
;
1604 char *tmpbuf
, *start
= NULL
, *end
= NULL
;
1606 tmpbuf
= kzalloc(length
+ 1, GFP_KERNEL
);
1608 pr_err("Unable to allocate memory for tmpbuf.\n");
1612 memcpy(tmpbuf
, textbuf
, length
);
1613 tmpbuf
[length
] = '\0';
1615 end
= (start
+ length
);
1617 while (start
< end
) {
1619 struct iscsi_param
*param
;
1621 if (iscsi_extract_key_value(start
, &key
, &value
) < 0) {
1626 pr_debug("Got key: %s=%s\n", key
, value
);
1628 if (phase
& PHASE_SECURITY
) {
1629 if (iscsi_check_for_auth_key(key
) > 0) {
1635 param
= iscsi_check_key(key
, phase
, sender
, param_list
);
1637 if (iscsi_add_notunderstood_response(key
,
1638 value
, param_list
) < 0) {
1642 start
+= strlen(key
) + strlen(value
) + 2;
1645 if (iscsi_check_value(param
, value
) < 0) {
1650 start
+= strlen(key
) + strlen(value
) + 2;
1652 if (IS_PSTATE_PROPOSER(param
)) {
1653 if (iscsi_check_proposer_state(param
, value
) < 0) {
1657 SET_PSTATE_RESPONSE_GOT(param
);
1659 if (iscsi_check_acceptor_state(param
, value
, conn
) < 0) {
1663 SET_PSTATE_ACCEPTOR(param
);
1671 int iscsi_encode_text_output(
1676 struct iscsi_param_list
*param_list
)
1678 char *output_buf
= NULL
;
1679 struct iscsi_extra_response
*er
;
1680 struct iscsi_param
*param
;
1682 output_buf
= textbuf
+ *length
;
1684 if (iscsi_enforce_integrity_rules(phase
, param_list
) < 0)
1687 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1688 if (!(param
->sender
& sender
))
1690 if (IS_PSTATE_ACCEPTOR(param
) &&
1691 !IS_PSTATE_RESPONSE_SENT(param
) &&
1692 !IS_PSTATE_REPLY_OPTIONAL(param
) &&
1693 (param
->phase
& phase
)) {
1694 *length
+= sprintf(output_buf
, "%s=%s",
1695 param
->name
, param
->value
);
1697 output_buf
= textbuf
+ *length
;
1698 SET_PSTATE_RESPONSE_SENT(param
);
1699 pr_debug("Sending key: %s=%s\n",
1700 param
->name
, param
->value
);
1703 if (IS_PSTATE_NEGOTIATE(param
) &&
1704 !IS_PSTATE_ACCEPTOR(param
) &&
1705 !IS_PSTATE_PROPOSER(param
) &&
1706 (param
->phase
& phase
)) {
1707 *length
+= sprintf(output_buf
, "%s=%s",
1708 param
->name
, param
->value
);
1710 output_buf
= textbuf
+ *length
;
1711 SET_PSTATE_PROPOSER(param
);
1712 iscsi_check_proposer_for_optional_reply(param
);
1713 pr_debug("Sending key: %s=%s\n",
1714 param
->name
, param
->value
);
1718 list_for_each_entry(er
, ¶m_list
->extra_response_list
, er_list
) {
1719 *length
+= sprintf(output_buf
, "%s=%s", er
->key
, er
->value
);
1721 output_buf
= textbuf
+ *length
;
1722 pr_debug("Sending key: %s=%s\n", er
->key
, er
->value
);
1724 iscsi_release_extra_responses(param_list
);
1729 int iscsi_check_negotiated_keys(struct iscsi_param_list
*param_list
)
1732 struct iscsi_param
*param
;
1734 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1735 if (IS_PSTATE_NEGOTIATE(param
) &&
1736 IS_PSTATE_PROPOSER(param
) &&
1737 !IS_PSTATE_RESPONSE_GOT(param
) &&
1738 !IS_PSTATE_REPLY_OPTIONAL(param
) &&
1739 !IS_PHASE_DECLARATIVE(param
)) {
1740 pr_err("No response for proposed key \"%s\".\n",
1749 int iscsi_change_param_value(
1751 struct iscsi_param_list
*param_list
,
1754 char *key
= NULL
, *value
= NULL
;
1755 struct iscsi_param
*param
;
1758 if (iscsi_extract_key_value(keyvalue
, &key
, &value
) < 0)
1762 param
= __iscsi_check_key(keyvalue
, sender
, param_list
);
1766 param
= iscsi_check_key(keyvalue
, 0, sender
, param_list
);
1770 param
->set_param
= 1;
1771 if (iscsi_check_value(param
, value
) < 0) {
1772 param
->set_param
= 0;
1775 param
->set_param
= 0;
1778 if (iscsi_update_param_value(param
, value
) < 0)
1784 void iscsi_set_connection_parameters(
1785 struct iscsi_conn_ops
*ops
,
1786 struct iscsi_param_list
*param_list
)
1789 struct iscsi_param
*param
;
1791 pr_debug("---------------------------------------------------"
1792 "---------------\n");
1793 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1795 * Special case to set MAXXMITDATASEGMENTLENGTH from the
1796 * target requested MaxRecvDataSegmentLength, even though
1797 * this key is not sent over the wire.
1799 if (!strcmp(param
->name
, MAXXMITDATASEGMENTLENGTH
)) {
1800 ops
->MaxXmitDataSegmentLength
=
1801 simple_strtoul(param
->value
, &tmpptr
, 0);
1802 pr_debug("MaxXmitDataSegmentLength: %s\n",
1806 if (!IS_PSTATE_ACCEPTOR(param
) && !IS_PSTATE_PROPOSER(param
))
1808 if (!strcmp(param
->name
, AUTHMETHOD
)) {
1809 pr_debug("AuthMethod: %s\n",
1811 } else if (!strcmp(param
->name
, HEADERDIGEST
)) {
1812 ops
->HeaderDigest
= !strcmp(param
->value
, CRC32C
);
1813 pr_debug("HeaderDigest: %s\n",
1815 } else if (!strcmp(param
->name
, DATADIGEST
)) {
1816 ops
->DataDigest
= !strcmp(param
->value
, CRC32C
);
1817 pr_debug("DataDigest: %s\n",
1819 } else if (!strcmp(param
->name
, MAXRECVDATASEGMENTLENGTH
)) {
1821 * At this point iscsi_check_acceptor_state() will have
1822 * set ops->MaxRecvDataSegmentLength from the original
1823 * initiator provided value.
1825 pr_debug("MaxRecvDataSegmentLength: %u\n",
1826 ops
->MaxRecvDataSegmentLength
);
1827 } else if (!strcmp(param
->name
, OFMARKER
)) {
1828 ops
->OFMarker
= !strcmp(param
->value
, YES
);
1829 pr_debug("OFMarker: %s\n",
1831 } else if (!strcmp(param
->name
, IFMARKER
)) {
1832 ops
->IFMarker
= !strcmp(param
->value
, YES
);
1833 pr_debug("IFMarker: %s\n",
1835 } else if (!strcmp(param
->name
, OFMARKINT
)) {
1837 simple_strtoul(param
->value
, &tmpptr
, 0);
1838 pr_debug("OFMarkInt: %s\n",
1840 } else if (!strcmp(param
->name
, IFMARKINT
)) {
1842 simple_strtoul(param
->value
, &tmpptr
, 0);
1843 pr_debug("IFMarkInt: %s\n",
1845 } else if (!strcmp(param
->name
, INITIATORRECVDATASEGMENTLENGTH
)) {
1846 ops
->InitiatorRecvDataSegmentLength
=
1847 simple_strtoul(param
->value
, &tmpptr
, 0);
1848 pr_debug("InitiatorRecvDataSegmentLength: %s\n",
1850 ops
->MaxRecvDataSegmentLength
=
1851 ops
->InitiatorRecvDataSegmentLength
;
1852 pr_debug("Set MRDSL from InitiatorRecvDataSegmentLength\n");
1853 } else if (!strcmp(param
->name
, TARGETRECVDATASEGMENTLENGTH
)) {
1854 ops
->TargetRecvDataSegmentLength
=
1855 simple_strtoul(param
->value
, &tmpptr
, 0);
1856 pr_debug("TargetRecvDataSegmentLength: %s\n",
1858 ops
->MaxXmitDataSegmentLength
=
1859 ops
->TargetRecvDataSegmentLength
;
1860 pr_debug("Set MXDSL from TargetRecvDataSegmentLength\n");
1863 pr_debug("----------------------------------------------------"
1864 "--------------\n");
1867 void iscsi_set_session_parameters(
1868 struct iscsi_sess_ops
*ops
,
1869 struct iscsi_param_list
*param_list
,
1873 struct iscsi_param
*param
;
1875 pr_debug("----------------------------------------------------"
1876 "--------------\n");
1877 list_for_each_entry(param
, ¶m_list
->param_list
, p_list
) {
1878 if (!IS_PSTATE_ACCEPTOR(param
) && !IS_PSTATE_PROPOSER(param
))
1880 if (!strcmp(param
->name
, INITIATORNAME
)) {
1884 snprintf(ops
->InitiatorName
,
1885 sizeof(ops
->InitiatorName
),
1886 "%s", param
->value
);
1887 pr_debug("InitiatorName: %s\n",
1889 } else if (!strcmp(param
->name
, INITIATORALIAS
)) {
1892 snprintf(ops
->InitiatorAlias
,
1893 sizeof(ops
->InitiatorAlias
),
1894 "%s", param
->value
);
1895 pr_debug("InitiatorAlias: %s\n",
1897 } else if (!strcmp(param
->name
, TARGETNAME
)) {
1901 snprintf(ops
->TargetName
,
1902 sizeof(ops
->TargetName
),
1903 "%s", param
->value
);
1904 pr_debug("TargetName: %s\n",
1906 } else if (!strcmp(param
->name
, TARGETALIAS
)) {
1909 snprintf(ops
->TargetAlias
, sizeof(ops
->TargetAlias
),
1910 "%s", param
->value
);
1911 pr_debug("TargetAlias: %s\n",
1913 } else if (!strcmp(param
->name
, TARGETPORTALGROUPTAG
)) {
1914 ops
->TargetPortalGroupTag
=
1915 simple_strtoul(param
->value
, &tmpptr
, 0);
1916 pr_debug("TargetPortalGroupTag: %s\n",
1918 } else if (!strcmp(param
->name
, MAXCONNECTIONS
)) {
1919 ops
->MaxConnections
=
1920 simple_strtoul(param
->value
, &tmpptr
, 0);
1921 pr_debug("MaxConnections: %s\n",
1923 } else if (!strcmp(param
->name
, INITIALR2T
)) {
1924 ops
->InitialR2T
= !strcmp(param
->value
, YES
);
1925 pr_debug("InitialR2T: %s\n",
1927 } else if (!strcmp(param
->name
, IMMEDIATEDATA
)) {
1928 ops
->ImmediateData
= !strcmp(param
->value
, YES
);
1929 pr_debug("ImmediateData: %s\n",
1931 } else if (!strcmp(param
->name
, MAXBURSTLENGTH
)) {
1932 ops
->MaxBurstLength
=
1933 simple_strtoul(param
->value
, &tmpptr
, 0);
1934 pr_debug("MaxBurstLength: %s\n",
1936 } else if (!strcmp(param
->name
, FIRSTBURSTLENGTH
)) {
1937 ops
->FirstBurstLength
=
1938 simple_strtoul(param
->value
, &tmpptr
, 0);
1939 pr_debug("FirstBurstLength: %s\n",
1941 } else if (!strcmp(param
->name
, DEFAULTTIME2WAIT
)) {
1942 ops
->DefaultTime2Wait
=
1943 simple_strtoul(param
->value
, &tmpptr
, 0);
1944 pr_debug("DefaultTime2Wait: %s\n",
1946 } else if (!strcmp(param
->name
, DEFAULTTIME2RETAIN
)) {
1947 ops
->DefaultTime2Retain
=
1948 simple_strtoul(param
->value
, &tmpptr
, 0);
1949 pr_debug("DefaultTime2Retain: %s\n",
1951 } else if (!strcmp(param
->name
, MAXOUTSTANDINGR2T
)) {
1952 ops
->MaxOutstandingR2T
=
1953 simple_strtoul(param
->value
, &tmpptr
, 0);
1954 pr_debug("MaxOutstandingR2T: %s\n",
1956 } else if (!strcmp(param
->name
, DATAPDUINORDER
)) {
1957 ops
->DataPDUInOrder
= !strcmp(param
->value
, YES
);
1958 pr_debug("DataPDUInOrder: %s\n",
1960 } else if (!strcmp(param
->name
, DATASEQUENCEINORDER
)) {
1961 ops
->DataSequenceInOrder
= !strcmp(param
->value
, YES
);
1962 pr_debug("DataSequenceInOrder: %s\n",
1964 } else if (!strcmp(param
->name
, ERRORRECOVERYLEVEL
)) {
1965 ops
->ErrorRecoveryLevel
=
1966 simple_strtoul(param
->value
, &tmpptr
, 0);
1967 pr_debug("ErrorRecoveryLevel: %s\n",
1969 } else if (!strcmp(param
->name
, SESSIONTYPE
)) {
1970 ops
->SessionType
= !strcmp(param
->value
, DISCOVERY
);
1971 pr_debug("SessionType: %s\n",
1973 } else if (!strcmp(param
->name
, RDMAEXTENSIONS
)) {
1974 ops
->RDMAExtensions
= !strcmp(param
->value
, YES
);
1975 pr_debug("RDMAExtensions: %s\n",
1979 pr_debug("----------------------------------------------------"
1980 "--------------\n");