blob: 84ce94a14948a6c1cc992b0ff7830df329efc689 [file] [log] [blame]
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001/*******************************************************************************
2 * This file contains main functions related to iSCSI Parameter negotiation.
3 *
4 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
5 *
6 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
7 *
8 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 ******************************************************************************/
20
21#include <linux/slab.h>
22
23#include "iscsi_target_core.h"
24#include "iscsi_target_util.h"
25#include "iscsi_target_parameters.h"
26
27int iscsi_login_rx_data(
28 struct iscsi_conn *conn,
29 char *buf,
30 int length)
31{
32 int rx_got;
33 struct kvec iov;
34
35 memset(&iov, 0, sizeof(struct kvec));
36 iov.iov_len = length;
37 iov.iov_base = buf;
38
39 /*
40 * Initial Marker-less Interval.
41 * Add the values regardless of IFMarker/OFMarker, considering
42 * it may not be negoitated yet.
43 */
44 conn->of_marker += length;
45
46 rx_got = rx_data(conn, &iov, 1, length);
47 if (rx_got != length) {
48 pr_err("rx_data returned %d, expecting %d.\n",
49 rx_got, length);
50 return -1;
51 }
52
53 return 0 ;
54}
55
56int iscsi_login_tx_data(
57 struct iscsi_conn *conn,
58 char *pdu_buf,
59 char *text_buf,
60 int text_length)
61{
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -080062 int length, tx_sent, iov_cnt = 1;
Nicholas Bellingere48354c2011-07-23 06:43:04 +000063 struct kvec iov[2];
64
65 length = (ISCSI_HDR_LEN + text_length);
66
67 memset(&iov[0], 0, 2 * sizeof(struct kvec));
68 iov[0].iov_len = ISCSI_HDR_LEN;
69 iov[0].iov_base = pdu_buf;
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -080070
71 if (text_buf && text_length) {
72 iov[1].iov_len = text_length;
73 iov[1].iov_base = text_buf;
74 iov_cnt++;
75 }
Nicholas Bellingere48354c2011-07-23 06:43:04 +000076
77 /*
78 * Initial Marker-less Interval.
79 * Add the values regardless of IFMarker/OFMarker, considering
80 * it may not be negoitated yet.
81 */
82 conn->if_marker += length;
83
Nicholas Bellingerbaa4d642013-03-06 21:54:13 -080084 tx_sent = tx_data(conn, &iov[0], iov_cnt, length);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000085 if (tx_sent != length) {
86 pr_err("tx_data returned %d, expecting %d.\n",
87 tx_sent, length);
88 return -1;
89 }
90
91 return 0;
92}
93
94void iscsi_dump_conn_ops(struct iscsi_conn_ops *conn_ops)
95{
96 pr_debug("HeaderDigest: %s\n", (conn_ops->HeaderDigest) ?
97 "CRC32C" : "None");
98 pr_debug("DataDigest: %s\n", (conn_ops->DataDigest) ?
99 "CRC32C" : "None");
100 pr_debug("MaxRecvDataSegmentLength: %u\n",
101 conn_ops->MaxRecvDataSegmentLength);
102 pr_debug("OFMarker: %s\n", (conn_ops->OFMarker) ? "Yes" : "No");
103 pr_debug("IFMarker: %s\n", (conn_ops->IFMarker) ? "Yes" : "No");
104 if (conn_ops->OFMarker)
105 pr_debug("OFMarkInt: %u\n", conn_ops->OFMarkInt);
106 if (conn_ops->IFMarker)
107 pr_debug("IFMarkInt: %u\n", conn_ops->IFMarkInt);
108}
109
110void iscsi_dump_sess_ops(struct iscsi_sess_ops *sess_ops)
111{
112 pr_debug("InitiatorName: %s\n", sess_ops->InitiatorName);
113 pr_debug("InitiatorAlias: %s\n", sess_ops->InitiatorAlias);
114 pr_debug("TargetName: %s\n", sess_ops->TargetName);
115 pr_debug("TargetAlias: %s\n", sess_ops->TargetAlias);
116 pr_debug("TargetPortalGroupTag: %hu\n",
117 sess_ops->TargetPortalGroupTag);
118 pr_debug("MaxConnections: %hu\n", sess_ops->MaxConnections);
119 pr_debug("InitialR2T: %s\n",
120 (sess_ops->InitialR2T) ? "Yes" : "No");
121 pr_debug("ImmediateData: %s\n", (sess_ops->ImmediateData) ?
122 "Yes" : "No");
123 pr_debug("MaxBurstLength: %u\n", sess_ops->MaxBurstLength);
124 pr_debug("FirstBurstLength: %u\n", sess_ops->FirstBurstLength);
125 pr_debug("DefaultTime2Wait: %hu\n", sess_ops->DefaultTime2Wait);
126 pr_debug("DefaultTime2Retain: %hu\n",
127 sess_ops->DefaultTime2Retain);
128 pr_debug("MaxOutstandingR2T: %hu\n",
129 sess_ops->MaxOutstandingR2T);
130 pr_debug("DataPDUInOrder: %s\n",
131 (sess_ops->DataPDUInOrder) ? "Yes" : "No");
132 pr_debug("DataSequenceInOrder: %s\n",
133 (sess_ops->DataSequenceInOrder) ? "Yes" : "No");
134 pr_debug("ErrorRecoveryLevel: %hu\n",
135 sess_ops->ErrorRecoveryLevel);
136 pr_debug("SessionType: %s\n", (sess_ops->SessionType) ?
137 "Discovery" : "Normal");
138}
139
140void iscsi_print_params(struct iscsi_param_list *param_list)
141{
142 struct iscsi_param *param;
143
144 list_for_each_entry(param, &param_list->param_list, p_list)
145 pr_debug("%s: %s\n", param->name, param->value);
146}
147
148static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *param_list,
149 char *name, char *value, u8 phase, u8 scope, u8 sender,
150 u16 type_range, u8 use)
151{
152 struct iscsi_param *param = NULL;
153
154 param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
155 if (!param) {
156 pr_err("Unable to allocate memory for parameter.\n");
157 goto out;
158 }
159 INIT_LIST_HEAD(&param->p_list);
160
Sebastian Andrzej Siewiored72a4d2012-11-29 20:29:01 +0100161 param->name = kstrdup(name, GFP_KERNEL);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000162 if (!param->name) {
163 pr_err("Unable to allocate memory for parameter name.\n");
164 goto out;
165 }
166
Sebastian Andrzej Siewiored72a4d2012-11-29 20:29:01 +0100167 param->value = kstrdup(value, GFP_KERNEL);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000168 if (!param->value) {
169 pr_err("Unable to allocate memory for parameter value.\n");
170 goto out;
171 }
172
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000173 param->phase = phase;
174 param->scope = scope;
175 param->sender = sender;
176 param->use = use;
177 param->type_range = type_range;
178
179 switch (param->type_range) {
180 case TYPERANGE_BOOL_AND:
181 param->type = TYPE_BOOL_AND;
182 break;
183 case TYPERANGE_BOOL_OR:
184 param->type = TYPE_BOOL_OR;
185 break;
186 case TYPERANGE_0_TO_2:
187 case TYPERANGE_0_TO_3600:
188 case TYPERANGE_0_TO_32767:
189 case TYPERANGE_0_TO_65535:
190 case TYPERANGE_1_TO_65535:
191 case TYPERANGE_2_TO_3600:
192 case TYPERANGE_512_TO_16777215:
193 param->type = TYPE_NUMBER;
194 break;
195 case TYPERANGE_AUTH:
196 case TYPERANGE_DIGEST:
197 param->type = TYPE_VALUE_LIST | TYPE_STRING;
198 break;
199 case TYPERANGE_MARKINT:
200 param->type = TYPE_NUMBER_RANGE;
201 param->type_range |= TYPERANGE_1_TO_65535;
202 break;
203 case TYPERANGE_ISCSINAME:
204 case TYPERANGE_SESSIONTYPE:
205 case TYPERANGE_TARGETADDRESS:
206 case TYPERANGE_UTF8:
207 param->type = TYPE_STRING;
208 break;
209 default:
210 pr_err("Unknown type_range 0x%02x\n",
211 param->type_range);
212 goto out;
213 }
214 list_add_tail(&param->p_list, &param_list->param_list);
215
216 return param;
217out:
218 if (param) {
219 kfree(param->value);
220 kfree(param->name);
221 kfree(param);
222 }
223
224 return NULL;
225}
226
227/* #warning Add extension keys */
228int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr)
229{
230 struct iscsi_param *param = NULL;
231 struct iscsi_param_list *pl;
232
233 pl = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL);
234 if (!pl) {
235 pr_err("Unable to allocate memory for"
236 " struct iscsi_param_list.\n");
237 return -1 ;
238 }
239 INIT_LIST_HEAD(&pl->param_list);
240 INIT_LIST_HEAD(&pl->extra_response_list);
241
242 /*
243 * The format for setting the initial parameter definitions are:
244 *
245 * Parameter name:
246 * Initial value:
247 * Allowable phase:
248 * Scope:
249 * Allowable senders:
250 * Typerange:
251 * Use:
252 */
253 param = iscsi_set_default_param(pl, AUTHMETHOD, INITIAL_AUTHMETHOD,
254 PHASE_SECURITY, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
255 TYPERANGE_AUTH, USE_INITIAL_ONLY);
256 if (!param)
257 goto out;
258
259 param = iscsi_set_default_param(pl, HEADERDIGEST, INITIAL_HEADERDIGEST,
260 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
261 TYPERANGE_DIGEST, USE_INITIAL_ONLY);
262 if (!param)
263 goto out;
264
265 param = iscsi_set_default_param(pl, DATADIGEST, INITIAL_DATADIGEST,
266 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
267 TYPERANGE_DIGEST, USE_INITIAL_ONLY);
268 if (!param)
269 goto out;
270
271 param = iscsi_set_default_param(pl, MAXCONNECTIONS,
272 INITIAL_MAXCONNECTIONS, PHASE_OPERATIONAL,
273 SCOPE_SESSION_WIDE, SENDER_BOTH,
274 TYPERANGE_1_TO_65535, USE_LEADING_ONLY);
275 if (!param)
276 goto out;
277
278 param = iscsi_set_default_param(pl, SENDTARGETS, INITIAL_SENDTARGETS,
279 PHASE_FFP0, SCOPE_SESSION_WIDE, SENDER_INITIATOR,
280 TYPERANGE_UTF8, 0);
281 if (!param)
282 goto out;
283
284 param = iscsi_set_default_param(pl, TARGETNAME, INITIAL_TARGETNAME,
285 PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_BOTH,
286 TYPERANGE_ISCSINAME, USE_ALL);
287 if (!param)
288 goto out;
289
290 param = iscsi_set_default_param(pl, INITIATORNAME,
291 INITIAL_INITIATORNAME, PHASE_DECLARATIVE,
292 SCOPE_SESSION_WIDE, SENDER_INITIATOR,
293 TYPERANGE_ISCSINAME, USE_INITIAL_ONLY);
294 if (!param)
295 goto out;
296
297 param = iscsi_set_default_param(pl, TARGETALIAS, INITIAL_TARGETALIAS,
298 PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_TARGET,
299 TYPERANGE_UTF8, USE_ALL);
300 if (!param)
301 goto out;
302
303 param = iscsi_set_default_param(pl, INITIATORALIAS,
304 INITIAL_INITIATORALIAS, PHASE_DECLARATIVE,
305 SCOPE_SESSION_WIDE, SENDER_INITIATOR, TYPERANGE_UTF8,
306 USE_ALL);
307 if (!param)
308 goto out;
309
310 param = iscsi_set_default_param(pl, TARGETADDRESS,
311 INITIAL_TARGETADDRESS, PHASE_DECLARATIVE,
312 SCOPE_SESSION_WIDE, SENDER_TARGET,
313 TYPERANGE_TARGETADDRESS, USE_ALL);
314 if (!param)
315 goto out;
316
317 param = iscsi_set_default_param(pl, TARGETPORTALGROUPTAG,
318 INITIAL_TARGETPORTALGROUPTAG,
319 PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_TARGET,
320 TYPERANGE_0_TO_65535, USE_INITIAL_ONLY);
321 if (!param)
322 goto out;
323
324 param = iscsi_set_default_param(pl, INITIALR2T, INITIAL_INITIALR2T,
325 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
326 TYPERANGE_BOOL_OR, USE_LEADING_ONLY);
327 if (!param)
328 goto out;
329
330 param = iscsi_set_default_param(pl, IMMEDIATEDATA,
331 INITIAL_IMMEDIATEDATA, PHASE_OPERATIONAL,
332 SCOPE_SESSION_WIDE, SENDER_BOTH, TYPERANGE_BOOL_AND,
333 USE_LEADING_ONLY);
334 if (!param)
335 goto out;
336
Nicholas Bellingere004cb22012-09-29 21:47:16 -0700337 param = iscsi_set_default_param(pl, MAXXMITDATASEGMENTLENGTH,
338 INITIAL_MAXXMITDATASEGMENTLENGTH,
339 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
340 TYPERANGE_512_TO_16777215, USE_ALL);
341 if (!param)
342 goto out;
343
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000344 param = iscsi_set_default_param(pl, MAXRECVDATASEGMENTLENGTH,
345 INITIAL_MAXRECVDATASEGMENTLENGTH,
346 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
347 TYPERANGE_512_TO_16777215, USE_ALL);
348 if (!param)
349 goto out;
350
351 param = iscsi_set_default_param(pl, MAXBURSTLENGTH,
352 INITIAL_MAXBURSTLENGTH, PHASE_OPERATIONAL,
353 SCOPE_SESSION_WIDE, SENDER_BOTH,
354 TYPERANGE_512_TO_16777215, USE_LEADING_ONLY);
355 if (!param)
356 goto out;
357
358 param = iscsi_set_default_param(pl, FIRSTBURSTLENGTH,
359 INITIAL_FIRSTBURSTLENGTH,
360 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
361 TYPERANGE_512_TO_16777215, USE_LEADING_ONLY);
362 if (!param)
363 goto out;
364
365 param = iscsi_set_default_param(pl, DEFAULTTIME2WAIT,
366 INITIAL_DEFAULTTIME2WAIT,
367 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
368 TYPERANGE_0_TO_3600, USE_LEADING_ONLY);
369 if (!param)
370 goto out;
371
372 param = iscsi_set_default_param(pl, DEFAULTTIME2RETAIN,
373 INITIAL_DEFAULTTIME2RETAIN,
374 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
375 TYPERANGE_0_TO_3600, USE_LEADING_ONLY);
376 if (!param)
377 goto out;
378
379 param = iscsi_set_default_param(pl, MAXOUTSTANDINGR2T,
380 INITIAL_MAXOUTSTANDINGR2T,
381 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
382 TYPERANGE_1_TO_65535, USE_LEADING_ONLY);
383 if (!param)
384 goto out;
385
386 param = iscsi_set_default_param(pl, DATAPDUINORDER,
387 INITIAL_DATAPDUINORDER, PHASE_OPERATIONAL,
388 SCOPE_SESSION_WIDE, SENDER_BOTH, TYPERANGE_BOOL_OR,
389 USE_LEADING_ONLY);
390 if (!param)
391 goto out;
392
393 param = iscsi_set_default_param(pl, DATASEQUENCEINORDER,
394 INITIAL_DATASEQUENCEINORDER,
395 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
396 TYPERANGE_BOOL_OR, USE_LEADING_ONLY);
397 if (!param)
398 goto out;
399
400 param = iscsi_set_default_param(pl, ERRORRECOVERYLEVEL,
401 INITIAL_ERRORRECOVERYLEVEL,
402 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
403 TYPERANGE_0_TO_2, USE_LEADING_ONLY);
404 if (!param)
405 goto out;
406
407 param = iscsi_set_default_param(pl, SESSIONTYPE, INITIAL_SESSIONTYPE,
408 PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_INITIATOR,
409 TYPERANGE_SESSIONTYPE, USE_LEADING_ONLY);
410 if (!param)
411 goto out;
412
413 param = iscsi_set_default_param(pl, IFMARKER, INITIAL_IFMARKER,
414 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
415 TYPERANGE_BOOL_AND, USE_INITIAL_ONLY);
416 if (!param)
417 goto out;
418
419 param = iscsi_set_default_param(pl, OFMARKER, INITIAL_OFMARKER,
420 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
421 TYPERANGE_BOOL_AND, USE_INITIAL_ONLY);
422 if (!param)
423 goto out;
424
425 param = iscsi_set_default_param(pl, IFMARKINT, INITIAL_IFMARKINT,
426 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
427 TYPERANGE_MARKINT, USE_INITIAL_ONLY);
428 if (!param)
429 goto out;
430
431 param = iscsi_set_default_param(pl, OFMARKINT, INITIAL_OFMARKINT,
432 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
433 TYPERANGE_MARKINT, USE_INITIAL_ONLY);
434 if (!param)
435 goto out;
436
437 *param_list_ptr = pl;
438 return 0;
439out:
440 iscsi_release_param_list(pl);
441 return -1;
442}
443
444int iscsi_set_keys_to_negotiate(
445 int sessiontype,
446 struct iscsi_param_list *param_list)
447{
448 struct iscsi_param *param;
449
450 list_for_each_entry(param, &param_list->param_list, p_list) {
451 param->state = 0;
452 if (!strcmp(param->name, AUTHMETHOD)) {
453 SET_PSTATE_NEGOTIATE(param);
454 } else if (!strcmp(param->name, HEADERDIGEST)) {
455 SET_PSTATE_NEGOTIATE(param);
456 } else if (!strcmp(param->name, DATADIGEST)) {
457 SET_PSTATE_NEGOTIATE(param);
458 } else if (!strcmp(param->name, MAXCONNECTIONS)) {
459 SET_PSTATE_NEGOTIATE(param);
460 } else if (!strcmp(param->name, TARGETNAME)) {
461 continue;
462 } else if (!strcmp(param->name, INITIATORNAME)) {
463 continue;
464 } else if (!strcmp(param->name, TARGETALIAS)) {
465 if (param->value)
466 SET_PSTATE_NEGOTIATE(param);
467 } else if (!strcmp(param->name, INITIATORALIAS)) {
468 continue;
469 } else if (!strcmp(param->name, TARGETPORTALGROUPTAG)) {
470 SET_PSTATE_NEGOTIATE(param);
471 } else if (!strcmp(param->name, INITIALR2T)) {
472 SET_PSTATE_NEGOTIATE(param);
473 } else if (!strcmp(param->name, IMMEDIATEDATA)) {
474 SET_PSTATE_NEGOTIATE(param);
475 } else if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH)) {
476 SET_PSTATE_NEGOTIATE(param);
Nicholas Bellingere004cb22012-09-29 21:47:16 -0700477 } else if (!strcmp(param->name, MAXXMITDATASEGMENTLENGTH)) {
478 continue;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000479 } else if (!strcmp(param->name, MAXBURSTLENGTH)) {
480 SET_PSTATE_NEGOTIATE(param);
481 } else if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
482 SET_PSTATE_NEGOTIATE(param);
483 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
484 SET_PSTATE_NEGOTIATE(param);
485 } else if (!strcmp(param->name, DEFAULTTIME2RETAIN)) {
486 SET_PSTATE_NEGOTIATE(param);
487 } else if (!strcmp(param->name, MAXOUTSTANDINGR2T)) {
488 SET_PSTATE_NEGOTIATE(param);
489 } else if (!strcmp(param->name, DATAPDUINORDER)) {
490 SET_PSTATE_NEGOTIATE(param);
491 } else if (!strcmp(param->name, DATASEQUENCEINORDER)) {
492 SET_PSTATE_NEGOTIATE(param);
493 } else if (!strcmp(param->name, ERRORRECOVERYLEVEL)) {
494 SET_PSTATE_NEGOTIATE(param);
495 } else if (!strcmp(param->name, SESSIONTYPE)) {
496 SET_PSTATE_NEGOTIATE(param);
497 } else if (!strcmp(param->name, IFMARKER)) {
498 SET_PSTATE_NEGOTIATE(param);
499 } else if (!strcmp(param->name, OFMARKER)) {
500 SET_PSTATE_NEGOTIATE(param);
501 } else if (!strcmp(param->name, IFMARKINT)) {
502 SET_PSTATE_NEGOTIATE(param);
503 } else if (!strcmp(param->name, OFMARKINT)) {
504 SET_PSTATE_NEGOTIATE(param);
505 }
506 }
507
508 return 0;
509}
510
511int iscsi_set_keys_irrelevant_for_discovery(
512 struct iscsi_param_list *param_list)
513{
514 struct iscsi_param *param;
515
516 list_for_each_entry(param, &param_list->param_list, p_list) {
517 if (!strcmp(param->name, MAXCONNECTIONS))
518 param->state &= ~PSTATE_NEGOTIATE;
519 else if (!strcmp(param->name, INITIALR2T))
520 param->state &= ~PSTATE_NEGOTIATE;
521 else if (!strcmp(param->name, IMMEDIATEDATA))
522 param->state &= ~PSTATE_NEGOTIATE;
523 else if (!strcmp(param->name, MAXBURSTLENGTH))
524 param->state &= ~PSTATE_NEGOTIATE;
525 else if (!strcmp(param->name, FIRSTBURSTLENGTH))
526 param->state &= ~PSTATE_NEGOTIATE;
527 else if (!strcmp(param->name, MAXOUTSTANDINGR2T))
528 param->state &= ~PSTATE_NEGOTIATE;
529 else if (!strcmp(param->name, DATAPDUINORDER))
530 param->state &= ~PSTATE_NEGOTIATE;
531 else if (!strcmp(param->name, DATASEQUENCEINORDER))
532 param->state &= ~PSTATE_NEGOTIATE;
533 else if (!strcmp(param->name, ERRORRECOVERYLEVEL))
534 param->state &= ~PSTATE_NEGOTIATE;
535 else if (!strcmp(param->name, DEFAULTTIME2WAIT))
536 param->state &= ~PSTATE_NEGOTIATE;
537 else if (!strcmp(param->name, DEFAULTTIME2RETAIN))
538 param->state &= ~PSTATE_NEGOTIATE;
539 else if (!strcmp(param->name, IFMARKER))
540 param->state &= ~PSTATE_NEGOTIATE;
541 else if (!strcmp(param->name, OFMARKER))
542 param->state &= ~PSTATE_NEGOTIATE;
543 else if (!strcmp(param->name, IFMARKINT))
544 param->state &= ~PSTATE_NEGOTIATE;
545 else if (!strcmp(param->name, OFMARKINT))
546 param->state &= ~PSTATE_NEGOTIATE;
547 }
548
549 return 0;
550}
551
552int iscsi_copy_param_list(
553 struct iscsi_param_list **dst_param_list,
554 struct iscsi_param_list *src_param_list,
555 int leading)
556{
Jesper Juhl9be08c52011-08-02 10:26:36 +0200557 struct iscsi_param *param = NULL;
558 struct iscsi_param *new_param = NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000559 struct iscsi_param_list *param_list = NULL;
560
561 param_list = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL);
562 if (!param_list) {
Jesper Juhl9be08c52011-08-02 10:26:36 +0200563 pr_err("Unable to allocate memory for struct iscsi_param_list.\n");
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000564 goto err_out;
565 }
566 INIT_LIST_HEAD(&param_list->param_list);
567 INIT_LIST_HEAD(&param_list->extra_response_list);
568
569 list_for_each_entry(param, &src_param_list->param_list, p_list) {
570 if (!leading && (param->scope & SCOPE_SESSION_WIDE)) {
571 if ((strcmp(param->name, "TargetName") != 0) &&
572 (strcmp(param->name, "InitiatorName") != 0) &&
573 (strcmp(param->name, "TargetPortalGroupTag") != 0))
574 continue;
575 }
576
577 new_param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
578 if (!new_param) {
Jesper Juhl9be08c52011-08-02 10:26:36 +0200579 pr_err("Unable to allocate memory for struct iscsi_param.\n");
580 goto err_out;
581 }
582
583 new_param->name = kstrdup(param->name, GFP_KERNEL);
584 new_param->value = kstrdup(param->value, GFP_KERNEL);
585 if (!new_param->value || !new_param->name) {
586 kfree(new_param->value);
587 kfree(new_param->name);
588 kfree(new_param);
589 pr_err("Unable to allocate memory for parameter name/value.\n");
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000590 goto err_out;
591 }
592
593 new_param->set_param = param->set_param;
594 new_param->phase = param->phase;
595 new_param->scope = param->scope;
596 new_param->sender = param->sender;
597 new_param->type = param->type;
598 new_param->use = param->use;
599 new_param->type_range = param->type_range;
600
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000601 list_add_tail(&new_param->p_list, &param_list->param_list);
602 }
603
Jesper Juhl9be08c52011-08-02 10:26:36 +0200604 if (!list_empty(&param_list->param_list)) {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000605 *dst_param_list = param_list;
Jesper Juhl9be08c52011-08-02 10:26:36 +0200606 } else {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000607 pr_err("No parameters allocated.\n");
608 goto err_out;
609 }
610
611 return 0;
612
613err_out:
614 iscsi_release_param_list(param_list);
615 return -1;
616}
617
618static void iscsi_release_extra_responses(struct iscsi_param_list *param_list)
619{
620 struct iscsi_extra_response *er, *er_tmp;
621
622 list_for_each_entry_safe(er, er_tmp, &param_list->extra_response_list,
623 er_list) {
624 list_del(&er->er_list);
625 kfree(er);
626 }
627}
628
629void iscsi_release_param_list(struct iscsi_param_list *param_list)
630{
631 struct iscsi_param *param, *param_tmp;
632
633 list_for_each_entry_safe(param, param_tmp, &param_list->param_list,
634 p_list) {
635 list_del(&param->p_list);
636
637 kfree(param->name);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000638 kfree(param->value);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000639 kfree(param);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000640 }
641
642 iscsi_release_extra_responses(param_list);
643
644 kfree(param_list);
645}
646
647struct iscsi_param *iscsi_find_param_from_key(
648 char *key,
649 struct iscsi_param_list *param_list)
650{
651 struct iscsi_param *param;
652
653 if (!key || !param_list) {
654 pr_err("Key or parameter list pointer is NULL.\n");
655 return NULL;
656 }
657
658 list_for_each_entry(param, &param_list->param_list, p_list) {
659 if (!strcmp(key, param->name))
660 return param;
661 }
662
663 pr_err("Unable to locate key \"%s\".\n", key);
664 return NULL;
665}
666
667int iscsi_extract_key_value(char *textbuf, char **key, char **value)
668{
669 *value = strchr(textbuf, '=');
670 if (!*value) {
Masanari Iida59e13d42012-04-25 00:24:16 +0900671 pr_err("Unable to locate \"=\" separator for key,"
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000672 " ignoring request.\n");
673 return -1;
674 }
675
676 *key = textbuf;
677 **value = '\0';
678 *value = *value + 1;
679
680 return 0;
681}
682
683int iscsi_update_param_value(struct iscsi_param *param, char *value)
684{
685 kfree(param->value);
686
Sebastian Andrzej Siewiored72a4d2012-11-29 20:29:01 +0100687 param->value = kstrdup(value, GFP_KERNEL);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000688 if (!param->value) {
689 pr_err("Unable to allocate memory for value.\n");
Andy Grover617a0c22012-07-12 17:34:56 -0700690 return -ENOMEM;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000691 }
692
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000693 pr_debug("iSCSI Parameter updated to %s=%s\n",
694 param->name, param->value);
695 return 0;
696}
697
698static int iscsi_add_notunderstood_response(
699 char *key,
700 char *value,
701 struct iscsi_param_list *param_list)
702{
703 struct iscsi_extra_response *extra_response;
704
705 if (strlen(value) > VALUE_MAXLEN) {
706 pr_err("Value for notunderstood key \"%s\" exceeds %d,"
707 " protocol error.\n", key, VALUE_MAXLEN);
708 return -1;
709 }
710
711 extra_response = kzalloc(sizeof(struct iscsi_extra_response), GFP_KERNEL);
712 if (!extra_response) {
713 pr_err("Unable to allocate memory for"
714 " struct iscsi_extra_response.\n");
715 return -1;
716 }
717 INIT_LIST_HEAD(&extra_response->er_list);
718
719 strncpy(extra_response->key, key, strlen(key) + 1);
720 strncpy(extra_response->value, NOTUNDERSTOOD,
721 strlen(NOTUNDERSTOOD) + 1);
722
723 list_add_tail(&extra_response->er_list,
724 &param_list->extra_response_list);
725 return 0;
726}
727
728static int iscsi_check_for_auth_key(char *key)
729{
730 /*
731 * RFC 1994
732 */
733 if (!strcmp(key, "CHAP_A") || !strcmp(key, "CHAP_I") ||
734 !strcmp(key, "CHAP_C") || !strcmp(key, "CHAP_N") ||
735 !strcmp(key, "CHAP_R"))
736 return 1;
737
738 /*
739 * RFC 2945
740 */
741 if (!strcmp(key, "SRP_U") || !strcmp(key, "SRP_N") ||
742 !strcmp(key, "SRP_g") || !strcmp(key, "SRP_s") ||
743 !strcmp(key, "SRP_A") || !strcmp(key, "SRP_B") ||
744 !strcmp(key, "SRP_M") || !strcmp(key, "SRP_HM"))
745 return 1;
746
747 return 0;
748}
749
750static void iscsi_check_proposer_for_optional_reply(struct iscsi_param *param)
751{
752 if (IS_TYPE_BOOL_AND(param)) {
753 if (!strcmp(param->value, NO))
754 SET_PSTATE_REPLY_OPTIONAL(param);
755 } else if (IS_TYPE_BOOL_OR(param)) {
756 if (!strcmp(param->value, YES))
757 SET_PSTATE_REPLY_OPTIONAL(param);
758 /*
759 * Required for gPXE iSCSI boot client
760 */
761 if (!strcmp(param->name, IMMEDIATEDATA))
762 SET_PSTATE_REPLY_OPTIONAL(param);
763 } else if (IS_TYPE_NUMBER(param)) {
764 if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH))
765 SET_PSTATE_REPLY_OPTIONAL(param);
766 /*
767 * The GlobalSAN iSCSI Initiator for MacOSX does
768 * not respond to MaxBurstLength, FirstBurstLength,
769 * DefaultTime2Wait or DefaultTime2Retain parameter keys.
770 * So, we set them to 'reply optional' here, and assume the
771 * the defaults from iscsi_parameters.h if the initiator
772 * is not RFC compliant and the keys are not negotiated.
773 */
774 if (!strcmp(param->name, MAXBURSTLENGTH))
775 SET_PSTATE_REPLY_OPTIONAL(param);
776 if (!strcmp(param->name, FIRSTBURSTLENGTH))
777 SET_PSTATE_REPLY_OPTIONAL(param);
778 if (!strcmp(param->name, DEFAULTTIME2WAIT))
779 SET_PSTATE_REPLY_OPTIONAL(param);
780 if (!strcmp(param->name, DEFAULTTIME2RETAIN))
781 SET_PSTATE_REPLY_OPTIONAL(param);
782 /*
783 * Required for gPXE iSCSI boot client
784 */
785 if (!strcmp(param->name, MAXCONNECTIONS))
786 SET_PSTATE_REPLY_OPTIONAL(param);
787 } else if (IS_PHASE_DECLARATIVE(param))
788 SET_PSTATE_REPLY_OPTIONAL(param);
789}
790
791static int iscsi_check_boolean_value(struct iscsi_param *param, char *value)
792{
793 if (strcmp(value, YES) && strcmp(value, NO)) {
794 pr_err("Illegal value for \"%s\", must be either"
795 " \"%s\" or \"%s\".\n", param->name, YES, NO);
796 return -1;
797 }
798
799 return 0;
800}
801
802static int iscsi_check_numerical_value(struct iscsi_param *param, char *value_ptr)
803{
804 char *tmpptr;
805 int value = 0;
806
807 value = simple_strtoul(value_ptr, &tmpptr, 0);
808
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000809 if (IS_TYPERANGE_0_TO_2(param)) {
810 if ((value < 0) || (value > 2)) {
811 pr_err("Illegal value for \"%s\", must be"
812 " between 0 and 2.\n", param->name);
813 return -1;
814 }
815 return 0;
816 }
817 if (IS_TYPERANGE_0_TO_3600(param)) {
818 if ((value < 0) || (value > 3600)) {
819 pr_err("Illegal value for \"%s\", must be"
820 " between 0 and 3600.\n", param->name);
821 return -1;
822 }
823 return 0;
824 }
825 if (IS_TYPERANGE_0_TO_32767(param)) {
826 if ((value < 0) || (value > 32767)) {
827 pr_err("Illegal value for \"%s\", must be"
828 " between 0 and 32767.\n", param->name);
829 return -1;
830 }
831 return 0;
832 }
833 if (IS_TYPERANGE_0_TO_65535(param)) {
834 if ((value < 0) || (value > 65535)) {
835 pr_err("Illegal value for \"%s\", must be"
836 " between 0 and 65535.\n", param->name);
837 return -1;
838 }
839 return 0;
840 }
841 if (IS_TYPERANGE_1_TO_65535(param)) {
842 if ((value < 1) || (value > 65535)) {
843 pr_err("Illegal value for \"%s\", must be"
844 " between 1 and 65535.\n", param->name);
845 return -1;
846 }
847 return 0;
848 }
849 if (IS_TYPERANGE_2_TO_3600(param)) {
850 if ((value < 2) || (value > 3600)) {
851 pr_err("Illegal value for \"%s\", must be"
852 " between 2 and 3600.\n", param->name);
853 return -1;
854 }
855 return 0;
856 }
857 if (IS_TYPERANGE_512_TO_16777215(param)) {
858 if ((value < 512) || (value > 16777215)) {
859 pr_err("Illegal value for \"%s\", must be"
860 " between 512 and 16777215.\n", param->name);
861 return -1;
862 }
863 return 0;
864 }
865
866 return 0;
867}
868
869static int iscsi_check_numerical_range_value(struct iscsi_param *param, char *value)
870{
871 char *left_val_ptr = NULL, *right_val_ptr = NULL;
Jörn Engela227fb32012-03-15 15:08:03 -0400872 char *tilde_ptr = NULL;
873 u32 left_val, right_val, local_left_val;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000874
875 if (strcmp(param->name, IFMARKINT) &&
876 strcmp(param->name, OFMARKINT)) {
877 pr_err("Only parameters \"%s\" or \"%s\" may contain a"
878 " numerical range value.\n", IFMARKINT, OFMARKINT);
879 return -1;
880 }
881
882 if (IS_PSTATE_PROPOSER(param))
883 return 0;
884
885 tilde_ptr = strchr(value, '~');
886 if (!tilde_ptr) {
887 pr_err("Unable to locate numerical range indicator"
888 " \"~\" for \"%s\".\n", param->name);
889 return -1;
890 }
891 *tilde_ptr = '\0';
892
893 left_val_ptr = value;
894 right_val_ptr = value + strlen(left_val_ptr) + 1;
895
896 if (iscsi_check_numerical_value(param, left_val_ptr) < 0)
897 return -1;
898 if (iscsi_check_numerical_value(param, right_val_ptr) < 0)
899 return -1;
900
Jörn Engela227fb32012-03-15 15:08:03 -0400901 left_val = simple_strtoul(left_val_ptr, NULL, 0);
902 right_val = simple_strtoul(right_val_ptr, NULL, 0);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000903 *tilde_ptr = '~';
904
905 if (right_val < left_val) {
906 pr_err("Numerical range for parameter \"%s\" contains"
907 " a right value which is less than the left.\n",
908 param->name);
909 return -1;
910 }
911
912 /*
913 * For now, enforce reasonable defaults for [I,O]FMarkInt.
914 */
915 tilde_ptr = strchr(param->value, '~');
916 if (!tilde_ptr) {
917 pr_err("Unable to locate numerical range indicator"
918 " \"~\" for \"%s\".\n", param->name);
919 return -1;
920 }
921 *tilde_ptr = '\0';
922
923 left_val_ptr = param->value;
924 right_val_ptr = param->value + strlen(left_val_ptr) + 1;
925
Jörn Engela227fb32012-03-15 15:08:03 -0400926 local_left_val = simple_strtoul(left_val_ptr, NULL, 0);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000927 *tilde_ptr = '~';
928
929 if (param->set_param) {
930 if ((left_val < local_left_val) ||
931 (right_val < local_left_val)) {
932 pr_err("Passed value range \"%u~%u\" is below"
933 " minimum left value \"%u\" for key \"%s\","
934 " rejecting.\n", left_val, right_val,
935 local_left_val, param->name);
936 return -1;
937 }
938 } else {
939 if ((left_val < local_left_val) &&
940 (right_val < local_left_val)) {
941 pr_err("Received value range \"%u~%u\" is"
942 " below minimum left value \"%u\" for key"
943 " \"%s\", rejecting.\n", left_val, right_val,
944 local_left_val, param->name);
945 SET_PSTATE_REJECT(param);
946 if (iscsi_update_param_value(param, REJECT) < 0)
947 return -1;
948 }
949 }
950
951 return 0;
952}
953
954static int iscsi_check_string_or_list_value(struct iscsi_param *param, char *value)
955{
956 if (IS_PSTATE_PROPOSER(param))
957 return 0;
958
959 if (IS_TYPERANGE_AUTH_PARAM(param)) {
960 if (strcmp(value, KRB5) && strcmp(value, SPKM1) &&
961 strcmp(value, SPKM2) && strcmp(value, SRP) &&
962 strcmp(value, CHAP) && strcmp(value, NONE)) {
963 pr_err("Illegal value for \"%s\", must be"
964 " \"%s\", \"%s\", \"%s\", \"%s\", \"%s\""
965 " or \"%s\".\n", param->name, KRB5,
966 SPKM1, SPKM2, SRP, CHAP, NONE);
967 return -1;
968 }
969 }
970 if (IS_TYPERANGE_DIGEST_PARAM(param)) {
971 if (strcmp(value, CRC32C) && strcmp(value, NONE)) {
972 pr_err("Illegal value for \"%s\", must be"
973 " \"%s\" or \"%s\".\n", param->name,
974 CRC32C, NONE);
975 return -1;
976 }
977 }
978 if (IS_TYPERANGE_SESSIONTYPE(param)) {
979 if (strcmp(value, DISCOVERY) && strcmp(value, NORMAL)) {
980 pr_err("Illegal value for \"%s\", must be"
981 " \"%s\" or \"%s\".\n", param->name,
982 DISCOVERY, NORMAL);
983 return -1;
984 }
985 }
986
987 return 0;
988}
989
990/*
991 * This function is used to pick a value range number, currently just
992 * returns the lesser of both right values.
993 */
994static char *iscsi_get_value_from_number_range(
995 struct iscsi_param *param,
996 char *value)
997{
998 char *end_ptr, *tilde_ptr1 = NULL, *tilde_ptr2 = NULL;
999 u32 acceptor_right_value, proposer_right_value;
1000
1001 tilde_ptr1 = strchr(value, '~');
1002 if (!tilde_ptr1)
1003 return NULL;
1004 *tilde_ptr1++ = '\0';
1005 proposer_right_value = simple_strtoul(tilde_ptr1, &end_ptr, 0);
1006
1007 tilde_ptr2 = strchr(param->value, '~');
1008 if (!tilde_ptr2)
1009 return NULL;
1010 *tilde_ptr2++ = '\0';
1011 acceptor_right_value = simple_strtoul(tilde_ptr2, &end_ptr, 0);
1012
1013 return (acceptor_right_value >= proposer_right_value) ?
1014 tilde_ptr1 : tilde_ptr2;
1015}
1016
1017static char *iscsi_check_valuelist_for_support(
1018 struct iscsi_param *param,
1019 char *value)
1020{
1021 char *tmp1 = NULL, *tmp2 = NULL;
1022 char *acceptor_values = NULL, *proposer_values = NULL;
1023
1024 acceptor_values = param->value;
1025 proposer_values = value;
1026
1027 do {
1028 if (!proposer_values)
1029 return NULL;
1030 tmp1 = strchr(proposer_values, ',');
1031 if (tmp1)
1032 *tmp1 = '\0';
1033 acceptor_values = param->value;
1034 do {
1035 if (!acceptor_values) {
1036 if (tmp1)
1037 *tmp1 = ',';
1038 return NULL;
1039 }
1040 tmp2 = strchr(acceptor_values, ',');
1041 if (tmp2)
1042 *tmp2 = '\0';
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001043 if (!strcmp(acceptor_values, proposer_values)) {
1044 if (tmp2)
1045 *tmp2 = ',';
1046 goto out;
1047 }
1048 if (tmp2)
1049 *tmp2++ = ',';
1050
1051 acceptor_values = tmp2;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001052 } while (acceptor_values);
1053 if (tmp1)
1054 *tmp1++ = ',';
1055 proposer_values = tmp1;
1056 } while (proposer_values);
1057
1058out:
1059 return proposer_values;
1060}
1061
Nicholas Bellinger9977bb12012-09-29 21:49:59 -07001062static int iscsi_check_acceptor_state(struct iscsi_param *param, char *value,
1063 struct iscsi_conn *conn)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001064{
1065 u8 acceptor_boolean_value = 0, proposer_boolean_value = 0;
1066 char *negoitated_value = NULL;
1067
1068 if (IS_PSTATE_ACCEPTOR(param)) {
1069 pr_err("Received key \"%s\" twice, protocol error.\n",
1070 param->name);
1071 return -1;
1072 }
1073
1074 if (IS_PSTATE_REJECT(param))
1075 return 0;
1076
1077 if (IS_TYPE_BOOL_AND(param)) {
1078 if (!strcmp(value, YES))
1079 proposer_boolean_value = 1;
1080 if (!strcmp(param->value, YES))
1081 acceptor_boolean_value = 1;
1082 if (acceptor_boolean_value && proposer_boolean_value)
1083 do {} while (0);
1084 else {
1085 if (iscsi_update_param_value(param, NO) < 0)
1086 return -1;
1087 if (!proposer_boolean_value)
1088 SET_PSTATE_REPLY_OPTIONAL(param);
1089 }
1090 } else if (IS_TYPE_BOOL_OR(param)) {
1091 if (!strcmp(value, YES))
1092 proposer_boolean_value = 1;
1093 if (!strcmp(param->value, YES))
1094 acceptor_boolean_value = 1;
1095 if (acceptor_boolean_value || proposer_boolean_value) {
1096 if (iscsi_update_param_value(param, YES) < 0)
1097 return -1;
1098 if (proposer_boolean_value)
1099 SET_PSTATE_REPLY_OPTIONAL(param);
1100 }
1101 } else if (IS_TYPE_NUMBER(param)) {
Dan Carpenter1be29562013-01-24 10:06:37 +03001102 char *tmpptr, buf[11];
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001103 u32 acceptor_value = simple_strtoul(param->value, &tmpptr, 0);
1104 u32 proposer_value = simple_strtoul(value, &tmpptr, 0);
1105
Dan Carpenter1be29562013-01-24 10:06:37 +03001106 memset(buf, 0, sizeof(buf));
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001107
1108 if (!strcmp(param->name, MAXCONNECTIONS) ||
1109 !strcmp(param->name, MAXBURSTLENGTH) ||
1110 !strcmp(param->name, FIRSTBURSTLENGTH) ||
1111 !strcmp(param->name, MAXOUTSTANDINGR2T) ||
1112 !strcmp(param->name, DEFAULTTIME2RETAIN) ||
1113 !strcmp(param->name, ERRORRECOVERYLEVEL)) {
1114 if (proposer_value > acceptor_value) {
1115 sprintf(buf, "%u", acceptor_value);
1116 if (iscsi_update_param_value(param,
1117 &buf[0]) < 0)
1118 return -1;
1119 } else {
1120 if (iscsi_update_param_value(param, value) < 0)
1121 return -1;
1122 }
1123 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
1124 if (acceptor_value > proposer_value) {
1125 sprintf(buf, "%u", acceptor_value);
1126 if (iscsi_update_param_value(param,
1127 &buf[0]) < 0)
1128 return -1;
1129 } else {
1130 if (iscsi_update_param_value(param, value) < 0)
1131 return -1;
1132 }
1133 } else {
1134 if (iscsi_update_param_value(param, value) < 0)
1135 return -1;
1136 }
1137
Nicholas Bellinger9977bb12012-09-29 21:49:59 -07001138 if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH)) {
1139 struct iscsi_param *param_mxdsl;
1140 unsigned long long tmp;
1141 int rc;
1142
1143 rc = strict_strtoull(param->value, 0, &tmp);
1144 if (rc < 0)
1145 return -1;
1146
1147 conn->conn_ops->MaxRecvDataSegmentLength = tmp;
1148 pr_debug("Saving op->MaxRecvDataSegmentLength from"
1149 " original initiator received value: %u\n",
1150 conn->conn_ops->MaxRecvDataSegmentLength);
1151
1152 param_mxdsl = iscsi_find_param_from_key(
1153 MAXXMITDATASEGMENTLENGTH,
1154 conn->param_list);
1155 if (!param_mxdsl)
1156 return -1;
1157
1158 rc = iscsi_update_param_value(param,
1159 param_mxdsl->value);
1160 if (rc < 0)
1161 return -1;
1162
1163 pr_debug("Updated %s to target MXDSL value: %s\n",
1164 param->name, param->value);
1165 }
1166
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001167 } else if (IS_TYPE_NUMBER_RANGE(param)) {
1168 negoitated_value = iscsi_get_value_from_number_range(
1169 param, value);
1170 if (!negoitated_value)
1171 return -1;
1172 if (iscsi_update_param_value(param, negoitated_value) < 0)
1173 return -1;
1174 } else if (IS_TYPE_VALUE_LIST(param)) {
1175 negoitated_value = iscsi_check_valuelist_for_support(
1176 param, value);
1177 if (!negoitated_value) {
1178 pr_err("Proposer's value list \"%s\" contains"
1179 " no valid values from Acceptor's value list"
1180 " \"%s\".\n", value, param->value);
1181 return -1;
1182 }
1183 if (iscsi_update_param_value(param, negoitated_value) < 0)
1184 return -1;
1185 } else if (IS_PHASE_DECLARATIVE(param)) {
1186 if (iscsi_update_param_value(param, value) < 0)
1187 return -1;
1188 SET_PSTATE_REPLY_OPTIONAL(param);
1189 }
1190
1191 return 0;
1192}
1193
1194static int iscsi_check_proposer_state(struct iscsi_param *param, char *value)
1195{
1196 if (IS_PSTATE_RESPONSE_GOT(param)) {
1197 pr_err("Received key \"%s\" twice, protocol error.\n",
1198 param->name);
1199 return -1;
1200 }
1201
1202 if (IS_TYPE_NUMBER_RANGE(param)) {
1203 u32 left_val = 0, right_val = 0, recieved_value = 0;
1204 char *left_val_ptr = NULL, *right_val_ptr = NULL;
Jörn Engela227fb32012-03-15 15:08:03 -04001205 char *tilde_ptr = NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001206
1207 if (!strcmp(value, IRRELEVANT) || !strcmp(value, REJECT)) {
1208 if (iscsi_update_param_value(param, value) < 0)
1209 return -1;
1210 return 0;
1211 }
1212
1213 tilde_ptr = strchr(value, '~');
1214 if (tilde_ptr) {
1215 pr_err("Illegal \"~\" in response for \"%s\".\n",
1216 param->name);
1217 return -1;
1218 }
1219 tilde_ptr = strchr(param->value, '~');
1220 if (!tilde_ptr) {
1221 pr_err("Unable to locate numerical range"
1222 " indicator \"~\" for \"%s\".\n", param->name);
1223 return -1;
1224 }
1225 *tilde_ptr = '\0';
1226
1227 left_val_ptr = param->value;
1228 right_val_ptr = param->value + strlen(left_val_ptr) + 1;
Jörn Engela227fb32012-03-15 15:08:03 -04001229 left_val = simple_strtoul(left_val_ptr, NULL, 0);
1230 right_val = simple_strtoul(right_val_ptr, NULL, 0);
1231 recieved_value = simple_strtoul(value, NULL, 0);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001232
1233 *tilde_ptr = '~';
1234
1235 if ((recieved_value < left_val) ||
1236 (recieved_value > right_val)) {
1237 pr_err("Illegal response \"%s=%u\", value must"
1238 " be between %u and %u.\n", param->name,
1239 recieved_value, left_val, right_val);
1240 return -1;
1241 }
1242 } else if (IS_TYPE_VALUE_LIST(param)) {
1243 char *comma_ptr = NULL, *tmp_ptr = NULL;
1244
1245 comma_ptr = strchr(value, ',');
1246 if (comma_ptr) {
1247 pr_err("Illegal \",\" in response for \"%s\".\n",
1248 param->name);
1249 return -1;
1250 }
1251
1252 tmp_ptr = iscsi_check_valuelist_for_support(param, value);
1253 if (!tmp_ptr)
1254 return -1;
1255 }
1256
1257 if (iscsi_update_param_value(param, value) < 0)
1258 return -1;
1259
1260 return 0;
1261}
1262
1263static int iscsi_check_value(struct iscsi_param *param, char *value)
1264{
1265 char *comma_ptr = NULL;
1266
1267 if (!strcmp(value, REJECT)) {
1268 if (!strcmp(param->name, IFMARKINT) ||
1269 !strcmp(param->name, OFMARKINT)) {
1270 /*
1271 * Reject is not fatal for [I,O]FMarkInt, and causes
1272 * [I,O]FMarker to be reset to No. (See iSCSI v20 A.3.2)
1273 */
1274 SET_PSTATE_REJECT(param);
1275 return 0;
1276 }
1277 pr_err("Received %s=%s\n", param->name, value);
1278 return -1;
1279 }
1280 if (!strcmp(value, IRRELEVANT)) {
1281 pr_debug("Received %s=%s\n", param->name, value);
1282 SET_PSTATE_IRRELEVANT(param);
1283 return 0;
1284 }
1285 if (!strcmp(value, NOTUNDERSTOOD)) {
1286 if (!IS_PSTATE_PROPOSER(param)) {
1287 pr_err("Received illegal offer %s=%s\n",
1288 param->name, value);
1289 return -1;
1290 }
1291
1292/* #warning FIXME: Add check for X-ExtensionKey here */
1293 pr_err("Standard iSCSI key \"%s\" cannot be answered"
1294 " with \"%s\", protocol error.\n", param->name, value);
1295 return -1;
1296 }
1297
1298 do {
1299 comma_ptr = NULL;
1300 comma_ptr = strchr(value, ',');
1301
1302 if (comma_ptr && !IS_TYPE_VALUE_LIST(param)) {
Masanari Iida59e13d42012-04-25 00:24:16 +09001303 pr_err("Detected value separator \",\", but"
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001304 " key \"%s\" does not allow a value list,"
1305 " protocol error.\n", param->name);
1306 return -1;
1307 }
1308 if (comma_ptr)
1309 *comma_ptr = '\0';
1310
1311 if (strlen(value) > VALUE_MAXLEN) {
1312 pr_err("Value for key \"%s\" exceeds %d,"
1313 " protocol error.\n", param->name,
1314 VALUE_MAXLEN);
1315 return -1;
1316 }
1317
1318 if (IS_TYPE_BOOL_AND(param) || IS_TYPE_BOOL_OR(param)) {
1319 if (iscsi_check_boolean_value(param, value) < 0)
1320 return -1;
1321 } else if (IS_TYPE_NUMBER(param)) {
1322 if (iscsi_check_numerical_value(param, value) < 0)
1323 return -1;
1324 } else if (IS_TYPE_NUMBER_RANGE(param)) {
1325 if (iscsi_check_numerical_range_value(param, value) < 0)
1326 return -1;
1327 } else if (IS_TYPE_STRING(param) || IS_TYPE_VALUE_LIST(param)) {
1328 if (iscsi_check_string_or_list_value(param, value) < 0)
1329 return -1;
1330 } else {
1331 pr_err("Huh? 0x%02x\n", param->type);
1332 return -1;
1333 }
1334
1335 if (comma_ptr)
1336 *comma_ptr++ = ',';
1337
1338 value = comma_ptr;
1339 } while (value);
1340
1341 return 0;
1342}
1343
1344static struct iscsi_param *__iscsi_check_key(
1345 char *key,
1346 int sender,
1347 struct iscsi_param_list *param_list)
1348{
1349 struct iscsi_param *param;
1350
1351 if (strlen(key) > KEY_MAXLEN) {
1352 pr_err("Length of key name \"%s\" exceeds %d.\n",
1353 key, KEY_MAXLEN);
1354 return NULL;
1355 }
1356
1357 param = iscsi_find_param_from_key(key, param_list);
1358 if (!param)
1359 return NULL;
1360
1361 if ((sender & SENDER_INITIATOR) && !IS_SENDER_INITIATOR(param)) {
1362 pr_err("Key \"%s\" may not be sent to %s,"
1363 " protocol error.\n", param->name,
1364 (sender & SENDER_RECEIVER) ? "target" : "initiator");
1365 return NULL;
1366 }
1367
1368 if ((sender & SENDER_TARGET) && !IS_SENDER_TARGET(param)) {
1369 pr_err("Key \"%s\" may not be sent to %s,"
1370 " protocol error.\n", param->name,
1371 (sender & SENDER_RECEIVER) ? "initiator" : "target");
1372 return NULL;
1373 }
1374
1375 return param;
1376}
1377
1378static struct iscsi_param *iscsi_check_key(
1379 char *key,
1380 int phase,
1381 int sender,
1382 struct iscsi_param_list *param_list)
1383{
1384 struct iscsi_param *param;
1385 /*
1386 * Key name length must not exceed 63 bytes. (See iSCSI v20 5.1)
1387 */
1388 if (strlen(key) > KEY_MAXLEN) {
1389 pr_err("Length of key name \"%s\" exceeds %d.\n",
1390 key, KEY_MAXLEN);
1391 return NULL;
1392 }
1393
1394 param = iscsi_find_param_from_key(key, param_list);
1395 if (!param)
1396 return NULL;
1397
1398 if ((sender & SENDER_INITIATOR) && !IS_SENDER_INITIATOR(param)) {
1399 pr_err("Key \"%s\" may not be sent to %s,"
1400 " protocol error.\n", param->name,
1401 (sender & SENDER_RECEIVER) ? "target" : "initiator");
1402 return NULL;
1403 }
1404 if ((sender & SENDER_TARGET) && !IS_SENDER_TARGET(param)) {
1405 pr_err("Key \"%s\" may not be sent to %s,"
1406 " protocol error.\n", param->name,
1407 (sender & SENDER_RECEIVER) ? "initiator" : "target");
1408 return NULL;
1409 }
1410
1411 if (IS_PSTATE_ACCEPTOR(param)) {
1412 pr_err("Key \"%s\" received twice, protocol error.\n",
1413 key);
1414 return NULL;
1415 }
1416
1417 if (!phase)
1418 return param;
1419
1420 if (!(param->phase & phase)) {
1421 pr_err("Key \"%s\" may not be negotiated during ",
1422 param->name);
1423 switch (phase) {
1424 case PHASE_SECURITY:
1425 pr_debug("Security phase.\n");
1426 break;
1427 case PHASE_OPERATIONAL:
1428 pr_debug("Operational phase.\n");
Alan Coxdb831012012-10-16 11:52:32 +01001429 break;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001430 default:
1431 pr_debug("Unknown phase.\n");
1432 }
1433 return NULL;
1434 }
1435
1436 return param;
1437}
1438
1439static int iscsi_enforce_integrity_rules(
1440 u8 phase,
1441 struct iscsi_param_list *param_list)
1442{
1443 char *tmpptr;
1444 u8 DataSequenceInOrder = 0;
1445 u8 ErrorRecoveryLevel = 0, SessionType = 0;
1446 u8 IFMarker = 0, OFMarker = 0;
Nicholas Bellinger2ff017f2011-09-16 01:44:54 -07001447 u8 IFMarkInt_Reject = 1, OFMarkInt_Reject = 1;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001448 u32 FirstBurstLength = 0, MaxBurstLength = 0;
1449 struct iscsi_param *param = NULL;
1450
1451 list_for_each_entry(param, &param_list->param_list, p_list) {
1452 if (!(param->phase & phase))
1453 continue;
1454 if (!strcmp(param->name, SESSIONTYPE))
1455 if (!strcmp(param->value, NORMAL))
1456 SessionType = 1;
1457 if (!strcmp(param->name, ERRORRECOVERYLEVEL))
1458 ErrorRecoveryLevel = simple_strtoul(param->value,
1459 &tmpptr, 0);
1460 if (!strcmp(param->name, DATASEQUENCEINORDER))
1461 if (!strcmp(param->value, YES))
1462 DataSequenceInOrder = 1;
1463 if (!strcmp(param->name, MAXBURSTLENGTH))
1464 MaxBurstLength = simple_strtoul(param->value,
1465 &tmpptr, 0);
1466 if (!strcmp(param->name, IFMARKER))
1467 if (!strcmp(param->value, YES))
1468 IFMarker = 1;
1469 if (!strcmp(param->name, OFMARKER))
1470 if (!strcmp(param->value, YES))
1471 OFMarker = 1;
1472 if (!strcmp(param->name, IFMARKINT))
1473 if (!strcmp(param->value, REJECT))
1474 IFMarkInt_Reject = 1;
1475 if (!strcmp(param->name, OFMARKINT))
1476 if (!strcmp(param->value, REJECT))
1477 OFMarkInt_Reject = 1;
1478 }
1479
1480 list_for_each_entry(param, &param_list->param_list, p_list) {
1481 if (!(param->phase & phase))
1482 continue;
1483 if (!SessionType && (!IS_PSTATE_ACCEPTOR(param) &&
1484 (strcmp(param->name, IFMARKER) &&
1485 strcmp(param->name, OFMARKER) &&
1486 strcmp(param->name, IFMARKINT) &&
1487 strcmp(param->name, OFMARKINT))))
1488 continue;
1489 if (!strcmp(param->name, MAXOUTSTANDINGR2T) &&
1490 DataSequenceInOrder && (ErrorRecoveryLevel > 0)) {
1491 if (strcmp(param->value, "1")) {
1492 if (iscsi_update_param_value(param, "1") < 0)
1493 return -1;
1494 pr_debug("Reset \"%s\" to \"%s\".\n",
1495 param->name, param->value);
1496 }
1497 }
1498 if (!strcmp(param->name, MAXCONNECTIONS) && !SessionType) {
1499 if (strcmp(param->value, "1")) {
1500 if (iscsi_update_param_value(param, "1") < 0)
1501 return -1;
1502 pr_debug("Reset \"%s\" to \"%s\".\n",
1503 param->name, param->value);
1504 }
1505 }
1506 if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
1507 FirstBurstLength = simple_strtoul(param->value,
1508 &tmpptr, 0);
1509 if (FirstBurstLength > MaxBurstLength) {
Dan Carpenter1be29562013-01-24 10:06:37 +03001510 char tmpbuf[11];
1511 memset(tmpbuf, 0, sizeof(tmpbuf));
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001512 sprintf(tmpbuf, "%u", MaxBurstLength);
1513 if (iscsi_update_param_value(param, tmpbuf))
1514 return -1;
1515 pr_debug("Reset \"%s\" to \"%s\".\n",
1516 param->name, param->value);
1517 }
1518 }
1519 if (!strcmp(param->name, IFMARKER) && IFMarkInt_Reject) {
1520 if (iscsi_update_param_value(param, NO) < 0)
1521 return -1;
1522 IFMarker = 0;
1523 pr_debug("Reset \"%s\" to \"%s\".\n",
1524 param->name, param->value);
1525 }
1526 if (!strcmp(param->name, OFMARKER) && OFMarkInt_Reject) {
1527 if (iscsi_update_param_value(param, NO) < 0)
1528 return -1;
1529 OFMarker = 0;
1530 pr_debug("Reset \"%s\" to \"%s\".\n",
1531 param->name, param->value);
1532 }
1533 if (!strcmp(param->name, IFMARKINT) && !IFMarker) {
1534 if (!strcmp(param->value, REJECT))
1535 continue;
1536 param->state &= ~PSTATE_NEGOTIATE;
1537 if (iscsi_update_param_value(param, IRRELEVANT) < 0)
1538 return -1;
1539 pr_debug("Reset \"%s\" to \"%s\".\n",
1540 param->name, param->value);
1541 }
1542 if (!strcmp(param->name, OFMARKINT) && !OFMarker) {
1543 if (!strcmp(param->value, REJECT))
1544 continue;
1545 param->state &= ~PSTATE_NEGOTIATE;
1546 if (iscsi_update_param_value(param, IRRELEVANT) < 0)
1547 return -1;
1548 pr_debug("Reset \"%s\" to \"%s\".\n",
1549 param->name, param->value);
1550 }
1551 }
1552
1553 return 0;
1554}
1555
1556int iscsi_decode_text_input(
1557 u8 phase,
1558 u8 sender,
1559 char *textbuf,
1560 u32 length,
Nicholas Bellinger9977bb12012-09-29 21:49:59 -07001561 struct iscsi_conn *conn)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001562{
Nicholas Bellinger9977bb12012-09-29 21:49:59 -07001563 struct iscsi_param_list *param_list = conn->param_list;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001564 char *tmpbuf, *start = NULL, *end = NULL;
1565
1566 tmpbuf = kzalloc(length + 1, GFP_KERNEL);
1567 if (!tmpbuf) {
1568 pr_err("Unable to allocate memory for tmpbuf.\n");
1569 return -1;
1570 }
1571
1572 memcpy(tmpbuf, textbuf, length);
1573 tmpbuf[length] = '\0';
1574 start = tmpbuf;
1575 end = (start + length);
1576
1577 while (start < end) {
1578 char *key, *value;
1579 struct iscsi_param *param;
1580
1581 if (iscsi_extract_key_value(start, &key, &value) < 0) {
1582 kfree(tmpbuf);
1583 return -1;
1584 }
1585
1586 pr_debug("Got key: %s=%s\n", key, value);
1587
1588 if (phase & PHASE_SECURITY) {
1589 if (iscsi_check_for_auth_key(key) > 0) {
1590 char *tmpptr = key + strlen(key);
1591 *tmpptr = '=';
1592 kfree(tmpbuf);
1593 return 1;
1594 }
1595 }
1596
1597 param = iscsi_check_key(key, phase, sender, param_list);
1598 if (!param) {
1599 if (iscsi_add_notunderstood_response(key,
1600 value, param_list) < 0) {
1601 kfree(tmpbuf);
1602 return -1;
1603 }
1604 start += strlen(key) + strlen(value) + 2;
1605 continue;
1606 }
1607 if (iscsi_check_value(param, value) < 0) {
1608 kfree(tmpbuf);
1609 return -1;
1610 }
1611
1612 start += strlen(key) + strlen(value) + 2;
1613
1614 if (IS_PSTATE_PROPOSER(param)) {
1615 if (iscsi_check_proposer_state(param, value) < 0) {
1616 kfree(tmpbuf);
1617 return -1;
1618 }
1619 SET_PSTATE_RESPONSE_GOT(param);
1620 } else {
Nicholas Bellinger9977bb12012-09-29 21:49:59 -07001621 if (iscsi_check_acceptor_state(param, value, conn) < 0) {
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001622 kfree(tmpbuf);
1623 return -1;
1624 }
1625 SET_PSTATE_ACCEPTOR(param);
1626 }
1627 }
1628
1629 kfree(tmpbuf);
1630 return 0;
1631}
1632
1633int iscsi_encode_text_output(
1634 u8 phase,
1635 u8 sender,
1636 char *textbuf,
1637 u32 *length,
1638 struct iscsi_param_list *param_list)
1639{
1640 char *output_buf = NULL;
1641 struct iscsi_extra_response *er;
1642 struct iscsi_param *param;
1643
1644 output_buf = textbuf + *length;
1645
1646 if (iscsi_enforce_integrity_rules(phase, param_list) < 0)
1647 return -1;
1648
1649 list_for_each_entry(param, &param_list->param_list, p_list) {
1650 if (!(param->sender & sender))
1651 continue;
1652 if (IS_PSTATE_ACCEPTOR(param) &&
1653 !IS_PSTATE_RESPONSE_SENT(param) &&
1654 !IS_PSTATE_REPLY_OPTIONAL(param) &&
1655 (param->phase & phase)) {
1656 *length += sprintf(output_buf, "%s=%s",
1657 param->name, param->value);
1658 *length += 1;
1659 output_buf = textbuf + *length;
1660 SET_PSTATE_RESPONSE_SENT(param);
1661 pr_debug("Sending key: %s=%s\n",
1662 param->name, param->value);
1663 continue;
1664 }
1665 if (IS_PSTATE_NEGOTIATE(param) &&
1666 !IS_PSTATE_ACCEPTOR(param) &&
1667 !IS_PSTATE_PROPOSER(param) &&
1668 (param->phase & phase)) {
1669 *length += sprintf(output_buf, "%s=%s",
1670 param->name, param->value);
1671 *length += 1;
1672 output_buf = textbuf + *length;
1673 SET_PSTATE_PROPOSER(param);
1674 iscsi_check_proposer_for_optional_reply(param);
1675 pr_debug("Sending key: %s=%s\n",
1676 param->name, param->value);
1677 }
1678 }
1679
1680 list_for_each_entry(er, &param_list->extra_response_list, er_list) {
1681 *length += sprintf(output_buf, "%s=%s", er->key, er->value);
1682 *length += 1;
1683 output_buf = textbuf + *length;
1684 pr_debug("Sending key: %s=%s\n", er->key, er->value);
1685 }
1686 iscsi_release_extra_responses(param_list);
1687
1688 return 0;
1689}
1690
1691int iscsi_check_negotiated_keys(struct iscsi_param_list *param_list)
1692{
1693 int ret = 0;
1694 struct iscsi_param *param;
1695
1696 list_for_each_entry(param, &param_list->param_list, p_list) {
1697 if (IS_PSTATE_NEGOTIATE(param) &&
1698 IS_PSTATE_PROPOSER(param) &&
1699 !IS_PSTATE_RESPONSE_GOT(param) &&
1700 !IS_PSTATE_REPLY_OPTIONAL(param) &&
1701 !IS_PHASE_DECLARATIVE(param)) {
1702 pr_err("No response for proposed key \"%s\".\n",
1703 param->name);
1704 ret = -1;
1705 }
1706 }
1707
1708 return ret;
1709}
1710
1711int iscsi_change_param_value(
1712 char *keyvalue,
1713 struct iscsi_param_list *param_list,
1714 int check_key)
1715{
1716 char *key = NULL, *value = NULL;
1717 struct iscsi_param *param;
1718 int sender = 0;
1719
1720 if (iscsi_extract_key_value(keyvalue, &key, &value) < 0)
1721 return -1;
1722
1723 if (!check_key) {
1724 param = __iscsi_check_key(keyvalue, sender, param_list);
1725 if (!param)
1726 return -1;
1727 } else {
1728 param = iscsi_check_key(keyvalue, 0, sender, param_list);
1729 if (!param)
1730 return -1;
1731
1732 param->set_param = 1;
1733 if (iscsi_check_value(param, value) < 0) {
1734 param->set_param = 0;
1735 return -1;
1736 }
1737 param->set_param = 0;
1738 }
1739
1740 if (iscsi_update_param_value(param, value) < 0)
1741 return -1;
1742
1743 return 0;
1744}
1745
1746void iscsi_set_connection_parameters(
1747 struct iscsi_conn_ops *ops,
1748 struct iscsi_param_list *param_list)
1749{
1750 char *tmpptr;
1751 struct iscsi_param *param;
1752
1753 pr_debug("---------------------------------------------------"
1754 "---------------\n");
1755 list_for_each_entry(param, &param_list->param_list, p_list) {
Nicholas Bellingere004cb22012-09-29 21:47:16 -07001756 /*
1757 * Special case to set MAXXMITDATASEGMENTLENGTH from the
1758 * target requested MaxRecvDataSegmentLength, even though
1759 * this key is not sent over the wire.
1760 */
1761 if (!strcmp(param->name, MAXXMITDATASEGMENTLENGTH)) {
1762 ops->MaxXmitDataSegmentLength =
1763 simple_strtoul(param->value, &tmpptr, 0);
1764 pr_debug("MaxXmitDataSegmentLength: %s\n",
1765 param->value);
1766 }
1767
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001768 if (!IS_PSTATE_ACCEPTOR(param) && !IS_PSTATE_PROPOSER(param))
1769 continue;
1770 if (!strcmp(param->name, AUTHMETHOD)) {
1771 pr_debug("AuthMethod: %s\n",
1772 param->value);
1773 } else if (!strcmp(param->name, HEADERDIGEST)) {
1774 ops->HeaderDigest = !strcmp(param->value, CRC32C);
1775 pr_debug("HeaderDigest: %s\n",
1776 param->value);
1777 } else if (!strcmp(param->name, DATADIGEST)) {
1778 ops->DataDigest = !strcmp(param->value, CRC32C);
1779 pr_debug("DataDigest: %s\n",
1780 param->value);
1781 } else if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH)) {
Nicholas Bellinger9977bb12012-09-29 21:49:59 -07001782 /*
1783 * At this point iscsi_check_acceptor_state() will have
1784 * set ops->MaxRecvDataSegmentLength from the original
1785 * initiator provided value.
1786 */
1787 pr_debug("MaxRecvDataSegmentLength: %u\n",
1788 ops->MaxRecvDataSegmentLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001789 } else if (!strcmp(param->name, OFMARKER)) {
1790 ops->OFMarker = !strcmp(param->value, YES);
1791 pr_debug("OFMarker: %s\n",
1792 param->value);
1793 } else if (!strcmp(param->name, IFMARKER)) {
1794 ops->IFMarker = !strcmp(param->value, YES);
1795 pr_debug("IFMarker: %s\n",
1796 param->value);
1797 } else if (!strcmp(param->name, OFMARKINT)) {
1798 ops->OFMarkInt =
1799 simple_strtoul(param->value, &tmpptr, 0);
1800 pr_debug("OFMarkInt: %s\n",
1801 param->value);
1802 } else if (!strcmp(param->name, IFMARKINT)) {
1803 ops->IFMarkInt =
1804 simple_strtoul(param->value, &tmpptr, 0);
1805 pr_debug("IFMarkInt: %s\n",
1806 param->value);
1807 }
1808 }
1809 pr_debug("----------------------------------------------------"
1810 "--------------\n");
1811}
1812
1813void iscsi_set_session_parameters(
1814 struct iscsi_sess_ops *ops,
1815 struct iscsi_param_list *param_list,
1816 int leading)
1817{
1818 char *tmpptr;
1819 struct iscsi_param *param;
1820
1821 pr_debug("----------------------------------------------------"
1822 "--------------\n");
1823 list_for_each_entry(param, &param_list->param_list, p_list) {
1824 if (!IS_PSTATE_ACCEPTOR(param) && !IS_PSTATE_PROPOSER(param))
1825 continue;
1826 if (!strcmp(param->name, INITIATORNAME)) {
1827 if (!param->value)
1828 continue;
1829 if (leading)
1830 snprintf(ops->InitiatorName,
1831 sizeof(ops->InitiatorName),
1832 "%s", param->value);
1833 pr_debug("InitiatorName: %s\n",
1834 param->value);
1835 } else if (!strcmp(param->name, INITIATORALIAS)) {
1836 if (!param->value)
1837 continue;
1838 snprintf(ops->InitiatorAlias,
1839 sizeof(ops->InitiatorAlias),
1840 "%s", param->value);
1841 pr_debug("InitiatorAlias: %s\n",
1842 param->value);
1843 } else if (!strcmp(param->name, TARGETNAME)) {
1844 if (!param->value)
1845 continue;
1846 if (leading)
1847 snprintf(ops->TargetName,
1848 sizeof(ops->TargetName),
1849 "%s", param->value);
1850 pr_debug("TargetName: %s\n",
1851 param->value);
1852 } else if (!strcmp(param->name, TARGETALIAS)) {
1853 if (!param->value)
1854 continue;
1855 snprintf(ops->TargetAlias, sizeof(ops->TargetAlias),
1856 "%s", param->value);
1857 pr_debug("TargetAlias: %s\n",
1858 param->value);
1859 } else if (!strcmp(param->name, TARGETPORTALGROUPTAG)) {
1860 ops->TargetPortalGroupTag =
1861 simple_strtoul(param->value, &tmpptr, 0);
1862 pr_debug("TargetPortalGroupTag: %s\n",
1863 param->value);
1864 } else if (!strcmp(param->name, MAXCONNECTIONS)) {
1865 ops->MaxConnections =
1866 simple_strtoul(param->value, &tmpptr, 0);
1867 pr_debug("MaxConnections: %s\n",
1868 param->value);
1869 } else if (!strcmp(param->name, INITIALR2T)) {
1870 ops->InitialR2T = !strcmp(param->value, YES);
1871 pr_debug("InitialR2T: %s\n",
1872 param->value);
1873 } else if (!strcmp(param->name, IMMEDIATEDATA)) {
1874 ops->ImmediateData = !strcmp(param->value, YES);
1875 pr_debug("ImmediateData: %s\n",
1876 param->value);
1877 } else if (!strcmp(param->name, MAXBURSTLENGTH)) {
1878 ops->MaxBurstLength =
1879 simple_strtoul(param->value, &tmpptr, 0);
1880 pr_debug("MaxBurstLength: %s\n",
1881 param->value);
1882 } else if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
1883 ops->FirstBurstLength =
1884 simple_strtoul(param->value, &tmpptr, 0);
1885 pr_debug("FirstBurstLength: %s\n",
1886 param->value);
1887 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
1888 ops->DefaultTime2Wait =
1889 simple_strtoul(param->value, &tmpptr, 0);
1890 pr_debug("DefaultTime2Wait: %s\n",
1891 param->value);
1892 } else if (!strcmp(param->name, DEFAULTTIME2RETAIN)) {
1893 ops->DefaultTime2Retain =
1894 simple_strtoul(param->value, &tmpptr, 0);
1895 pr_debug("DefaultTime2Retain: %s\n",
1896 param->value);
1897 } else if (!strcmp(param->name, MAXOUTSTANDINGR2T)) {
1898 ops->MaxOutstandingR2T =
1899 simple_strtoul(param->value, &tmpptr, 0);
1900 pr_debug("MaxOutstandingR2T: %s\n",
1901 param->value);
1902 } else if (!strcmp(param->name, DATAPDUINORDER)) {
1903 ops->DataPDUInOrder = !strcmp(param->value, YES);
1904 pr_debug("DataPDUInOrder: %s\n",
1905 param->value);
1906 } else if (!strcmp(param->name, DATASEQUENCEINORDER)) {
1907 ops->DataSequenceInOrder = !strcmp(param->value, YES);
1908 pr_debug("DataSequenceInOrder: %s\n",
1909 param->value);
1910 } else if (!strcmp(param->name, ERRORRECOVERYLEVEL)) {
1911 ops->ErrorRecoveryLevel =
1912 simple_strtoul(param->value, &tmpptr, 0);
1913 pr_debug("ErrorRecoveryLevel: %s\n",
1914 param->value);
1915 } else if (!strcmp(param->name, SESSIONTYPE)) {
1916 ops->SessionType = !strcmp(param->value, DISCOVERY);
1917 pr_debug("SessionType: %s\n",
1918 param->value);
1919 }
1920 }
1921 pr_debug("----------------------------------------------------"
1922 "--------------\n");
1923
1924}