blob: 0c4760fabfc0f63f753d921ebb60ba2fe1ad3e18 [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{
62 int length, tx_sent;
63 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;
70 iov[1].iov_len = text_length;
71 iov[1].iov_base = text_buf;
72
73 /*
74 * Initial Marker-less Interval.
75 * Add the values regardless of IFMarker/OFMarker, considering
76 * it may not be negoitated yet.
77 */
78 conn->if_marker += length;
79
80 tx_sent = tx_data(conn, &iov[0], 2, length);
81 if (tx_sent != length) {
82 pr_err("tx_data returned %d, expecting %d.\n",
83 tx_sent, length);
84 return -1;
85 }
86
87 return 0;
88}
89
90void iscsi_dump_conn_ops(struct iscsi_conn_ops *conn_ops)
91{
92 pr_debug("HeaderDigest: %s\n", (conn_ops->HeaderDigest) ?
93 "CRC32C" : "None");
94 pr_debug("DataDigest: %s\n", (conn_ops->DataDigest) ?
95 "CRC32C" : "None");
96 pr_debug("MaxRecvDataSegmentLength: %u\n",
97 conn_ops->MaxRecvDataSegmentLength);
98 pr_debug("OFMarker: %s\n", (conn_ops->OFMarker) ? "Yes" : "No");
99 pr_debug("IFMarker: %s\n", (conn_ops->IFMarker) ? "Yes" : "No");
100 if (conn_ops->OFMarker)
101 pr_debug("OFMarkInt: %u\n", conn_ops->OFMarkInt);
102 if (conn_ops->IFMarker)
103 pr_debug("IFMarkInt: %u\n", conn_ops->IFMarkInt);
104}
105
106void iscsi_dump_sess_ops(struct iscsi_sess_ops *sess_ops)
107{
108 pr_debug("InitiatorName: %s\n", sess_ops->InitiatorName);
109 pr_debug("InitiatorAlias: %s\n", sess_ops->InitiatorAlias);
110 pr_debug("TargetName: %s\n", sess_ops->TargetName);
111 pr_debug("TargetAlias: %s\n", sess_ops->TargetAlias);
112 pr_debug("TargetPortalGroupTag: %hu\n",
113 sess_ops->TargetPortalGroupTag);
114 pr_debug("MaxConnections: %hu\n", sess_ops->MaxConnections);
115 pr_debug("InitialR2T: %s\n",
116 (sess_ops->InitialR2T) ? "Yes" : "No");
117 pr_debug("ImmediateData: %s\n", (sess_ops->ImmediateData) ?
118 "Yes" : "No");
119 pr_debug("MaxBurstLength: %u\n", sess_ops->MaxBurstLength);
120 pr_debug("FirstBurstLength: %u\n", sess_ops->FirstBurstLength);
121 pr_debug("DefaultTime2Wait: %hu\n", sess_ops->DefaultTime2Wait);
122 pr_debug("DefaultTime2Retain: %hu\n",
123 sess_ops->DefaultTime2Retain);
124 pr_debug("MaxOutstandingR2T: %hu\n",
125 sess_ops->MaxOutstandingR2T);
126 pr_debug("DataPDUInOrder: %s\n",
127 (sess_ops->DataPDUInOrder) ? "Yes" : "No");
128 pr_debug("DataSequenceInOrder: %s\n",
129 (sess_ops->DataSequenceInOrder) ? "Yes" : "No");
130 pr_debug("ErrorRecoveryLevel: %hu\n",
131 sess_ops->ErrorRecoveryLevel);
132 pr_debug("SessionType: %s\n", (sess_ops->SessionType) ?
133 "Discovery" : "Normal");
134}
135
136void iscsi_print_params(struct iscsi_param_list *param_list)
137{
138 struct iscsi_param *param;
139
140 list_for_each_entry(param, &param_list->param_list, p_list)
141 pr_debug("%s: %s\n", param->name, param->value);
142}
143
144static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *param_list,
145 char *name, char *value, u8 phase, u8 scope, u8 sender,
146 u16 type_range, u8 use)
147{
148 struct iscsi_param *param = NULL;
149
150 param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
151 if (!param) {
152 pr_err("Unable to allocate memory for parameter.\n");
153 goto out;
154 }
155 INIT_LIST_HEAD(&param->p_list);
156
157 param->name = kzalloc(strlen(name) + 1, GFP_KERNEL);
158 if (!param->name) {
159 pr_err("Unable to allocate memory for parameter name.\n");
160 goto out;
161 }
162
163 param->value = kzalloc(strlen(value) + 1, GFP_KERNEL);
164 if (!param->value) {
165 pr_err("Unable to allocate memory for parameter value.\n");
166 goto out;
167 }
168
169 memcpy(param->name, name, strlen(name));
170 param->name[strlen(name)] = '\0';
171 memcpy(param->value, value, strlen(value));
172 param->value[strlen(value)] = '\0';
173 param->phase = phase;
174 param->scope = scope;
175 param->sender = sender;
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
337 param = iscsi_set_default_param(pl, MAXRECVDATASEGMENTLENGTH,
338 INITIAL_MAXRECVDATASEGMENTLENGTH,
339 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
340 TYPERANGE_512_TO_16777215, USE_ALL);
341 if (!param)
342 goto out;
343
344 param = iscsi_set_default_param(pl, MAXBURSTLENGTH,
345 INITIAL_MAXBURSTLENGTH, PHASE_OPERATIONAL,
346 SCOPE_SESSION_WIDE, SENDER_BOTH,
347 TYPERANGE_512_TO_16777215, USE_LEADING_ONLY);
348 if (!param)
349 goto out;
350
351 param = iscsi_set_default_param(pl, FIRSTBURSTLENGTH,
352 INITIAL_FIRSTBURSTLENGTH,
353 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
354 TYPERANGE_512_TO_16777215, USE_LEADING_ONLY);
355 if (!param)
356 goto out;
357
358 param = iscsi_set_default_param(pl, DEFAULTTIME2WAIT,
359 INITIAL_DEFAULTTIME2WAIT,
360 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
361 TYPERANGE_0_TO_3600, USE_LEADING_ONLY);
362 if (!param)
363 goto out;
364
365 param = iscsi_set_default_param(pl, DEFAULTTIME2RETAIN,
366 INITIAL_DEFAULTTIME2RETAIN,
367 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
368 TYPERANGE_0_TO_3600, USE_LEADING_ONLY);
369 if (!param)
370 goto out;
371
372 param = iscsi_set_default_param(pl, MAXOUTSTANDINGR2T,
373 INITIAL_MAXOUTSTANDINGR2T,
374 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
375 TYPERANGE_1_TO_65535, USE_LEADING_ONLY);
376 if (!param)
377 goto out;
378
379 param = iscsi_set_default_param(pl, DATAPDUINORDER,
380 INITIAL_DATAPDUINORDER, PHASE_OPERATIONAL,
381 SCOPE_SESSION_WIDE, SENDER_BOTH, TYPERANGE_BOOL_OR,
382 USE_LEADING_ONLY);
383 if (!param)
384 goto out;
385
386 param = iscsi_set_default_param(pl, DATASEQUENCEINORDER,
387 INITIAL_DATASEQUENCEINORDER,
388 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
389 TYPERANGE_BOOL_OR, USE_LEADING_ONLY);
390 if (!param)
391 goto out;
392
393 param = iscsi_set_default_param(pl, ERRORRECOVERYLEVEL,
394 INITIAL_ERRORRECOVERYLEVEL,
395 PHASE_OPERATIONAL, SCOPE_SESSION_WIDE, SENDER_BOTH,
396 TYPERANGE_0_TO_2, USE_LEADING_ONLY);
397 if (!param)
398 goto out;
399
400 param = iscsi_set_default_param(pl, SESSIONTYPE, INITIAL_SESSIONTYPE,
401 PHASE_DECLARATIVE, SCOPE_SESSION_WIDE, SENDER_INITIATOR,
402 TYPERANGE_SESSIONTYPE, USE_LEADING_ONLY);
403 if (!param)
404 goto out;
405
406 param = iscsi_set_default_param(pl, IFMARKER, INITIAL_IFMARKER,
407 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
408 TYPERANGE_BOOL_AND, USE_INITIAL_ONLY);
409 if (!param)
410 goto out;
411
412 param = iscsi_set_default_param(pl, OFMARKER, INITIAL_OFMARKER,
413 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
414 TYPERANGE_BOOL_AND, USE_INITIAL_ONLY);
415 if (!param)
416 goto out;
417
418 param = iscsi_set_default_param(pl, IFMARKINT, INITIAL_IFMARKINT,
419 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
420 TYPERANGE_MARKINT, USE_INITIAL_ONLY);
421 if (!param)
422 goto out;
423
424 param = iscsi_set_default_param(pl, OFMARKINT, INITIAL_OFMARKINT,
425 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH,
426 TYPERANGE_MARKINT, USE_INITIAL_ONLY);
427 if (!param)
428 goto out;
429
430 *param_list_ptr = pl;
431 return 0;
432out:
433 iscsi_release_param_list(pl);
434 return -1;
435}
436
437int iscsi_set_keys_to_negotiate(
438 int sessiontype,
439 struct iscsi_param_list *param_list)
440{
441 struct iscsi_param *param;
442
443 list_for_each_entry(param, &param_list->param_list, p_list) {
444 param->state = 0;
445 if (!strcmp(param->name, AUTHMETHOD)) {
446 SET_PSTATE_NEGOTIATE(param);
447 } else if (!strcmp(param->name, HEADERDIGEST)) {
448 SET_PSTATE_NEGOTIATE(param);
449 } else if (!strcmp(param->name, DATADIGEST)) {
450 SET_PSTATE_NEGOTIATE(param);
451 } else if (!strcmp(param->name, MAXCONNECTIONS)) {
452 SET_PSTATE_NEGOTIATE(param);
453 } else if (!strcmp(param->name, TARGETNAME)) {
454 continue;
455 } else if (!strcmp(param->name, INITIATORNAME)) {
456 continue;
457 } else if (!strcmp(param->name, TARGETALIAS)) {
458 if (param->value)
459 SET_PSTATE_NEGOTIATE(param);
460 } else if (!strcmp(param->name, INITIATORALIAS)) {
461 continue;
462 } else if (!strcmp(param->name, TARGETPORTALGROUPTAG)) {
463 SET_PSTATE_NEGOTIATE(param);
464 } else if (!strcmp(param->name, INITIALR2T)) {
465 SET_PSTATE_NEGOTIATE(param);
466 } else if (!strcmp(param->name, IMMEDIATEDATA)) {
467 SET_PSTATE_NEGOTIATE(param);
468 } else if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH)) {
469 SET_PSTATE_NEGOTIATE(param);
470 } else if (!strcmp(param->name, MAXBURSTLENGTH)) {
471 SET_PSTATE_NEGOTIATE(param);
472 } else if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
473 SET_PSTATE_NEGOTIATE(param);
474 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
475 SET_PSTATE_NEGOTIATE(param);
476 } else if (!strcmp(param->name, DEFAULTTIME2RETAIN)) {
477 SET_PSTATE_NEGOTIATE(param);
478 } else if (!strcmp(param->name, MAXOUTSTANDINGR2T)) {
479 SET_PSTATE_NEGOTIATE(param);
480 } else if (!strcmp(param->name, DATAPDUINORDER)) {
481 SET_PSTATE_NEGOTIATE(param);
482 } else if (!strcmp(param->name, DATASEQUENCEINORDER)) {
483 SET_PSTATE_NEGOTIATE(param);
484 } else if (!strcmp(param->name, ERRORRECOVERYLEVEL)) {
485 SET_PSTATE_NEGOTIATE(param);
486 } else if (!strcmp(param->name, SESSIONTYPE)) {
487 SET_PSTATE_NEGOTIATE(param);
488 } else if (!strcmp(param->name, IFMARKER)) {
489 SET_PSTATE_NEGOTIATE(param);
490 } else if (!strcmp(param->name, OFMARKER)) {
491 SET_PSTATE_NEGOTIATE(param);
492 } else if (!strcmp(param->name, IFMARKINT)) {
493 SET_PSTATE_NEGOTIATE(param);
494 } else if (!strcmp(param->name, OFMARKINT)) {
495 SET_PSTATE_NEGOTIATE(param);
496 }
497 }
498
499 return 0;
500}
501
502int iscsi_set_keys_irrelevant_for_discovery(
503 struct iscsi_param_list *param_list)
504{
505 struct iscsi_param *param;
506
507 list_for_each_entry(param, &param_list->param_list, p_list) {
508 if (!strcmp(param->name, MAXCONNECTIONS))
509 param->state &= ~PSTATE_NEGOTIATE;
510 else if (!strcmp(param->name, INITIALR2T))
511 param->state &= ~PSTATE_NEGOTIATE;
512 else if (!strcmp(param->name, IMMEDIATEDATA))
513 param->state &= ~PSTATE_NEGOTIATE;
514 else if (!strcmp(param->name, MAXBURSTLENGTH))
515 param->state &= ~PSTATE_NEGOTIATE;
516 else if (!strcmp(param->name, FIRSTBURSTLENGTH))
517 param->state &= ~PSTATE_NEGOTIATE;
518 else if (!strcmp(param->name, MAXOUTSTANDINGR2T))
519 param->state &= ~PSTATE_NEGOTIATE;
520 else if (!strcmp(param->name, DATAPDUINORDER))
521 param->state &= ~PSTATE_NEGOTIATE;
522 else if (!strcmp(param->name, DATASEQUENCEINORDER))
523 param->state &= ~PSTATE_NEGOTIATE;
524 else if (!strcmp(param->name, ERRORRECOVERYLEVEL))
525 param->state &= ~PSTATE_NEGOTIATE;
526 else if (!strcmp(param->name, DEFAULTTIME2WAIT))
527 param->state &= ~PSTATE_NEGOTIATE;
528 else if (!strcmp(param->name, DEFAULTTIME2RETAIN))
529 param->state &= ~PSTATE_NEGOTIATE;
530 else if (!strcmp(param->name, IFMARKER))
531 param->state &= ~PSTATE_NEGOTIATE;
532 else if (!strcmp(param->name, OFMARKER))
533 param->state &= ~PSTATE_NEGOTIATE;
534 else if (!strcmp(param->name, IFMARKINT))
535 param->state &= ~PSTATE_NEGOTIATE;
536 else if (!strcmp(param->name, OFMARKINT))
537 param->state &= ~PSTATE_NEGOTIATE;
538 }
539
540 return 0;
541}
542
543int iscsi_copy_param_list(
544 struct iscsi_param_list **dst_param_list,
545 struct iscsi_param_list *src_param_list,
546 int leading)
547{
Jesper Juhl9be08c52011-08-02 10:26:36 +0200548 struct iscsi_param *param = NULL;
549 struct iscsi_param *new_param = NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000550 struct iscsi_param_list *param_list = NULL;
551
552 param_list = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL);
553 if (!param_list) {
Jesper Juhl9be08c52011-08-02 10:26:36 +0200554 pr_err("Unable to allocate memory for struct iscsi_param_list.\n");
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000555 goto err_out;
556 }
557 INIT_LIST_HEAD(&param_list->param_list);
558 INIT_LIST_HEAD(&param_list->extra_response_list);
559
560 list_for_each_entry(param, &src_param_list->param_list, p_list) {
561 if (!leading && (param->scope & SCOPE_SESSION_WIDE)) {
562 if ((strcmp(param->name, "TargetName") != 0) &&
563 (strcmp(param->name, "InitiatorName") != 0) &&
564 (strcmp(param->name, "TargetPortalGroupTag") != 0))
565 continue;
566 }
567
568 new_param = kzalloc(sizeof(struct iscsi_param), GFP_KERNEL);
569 if (!new_param) {
Jesper Juhl9be08c52011-08-02 10:26:36 +0200570 pr_err("Unable to allocate memory for struct iscsi_param.\n");
571 goto err_out;
572 }
573
574 new_param->name = kstrdup(param->name, GFP_KERNEL);
575 new_param->value = kstrdup(param->value, GFP_KERNEL);
576 if (!new_param->value || !new_param->name) {
577 kfree(new_param->value);
578 kfree(new_param->name);
579 kfree(new_param);
580 pr_err("Unable to allocate memory for parameter name/value.\n");
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000581 goto err_out;
582 }
583
584 new_param->set_param = param->set_param;
585 new_param->phase = param->phase;
586 new_param->scope = param->scope;
587 new_param->sender = param->sender;
588 new_param->type = param->type;
589 new_param->use = param->use;
590 new_param->type_range = param->type_range;
591
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000592 list_add_tail(&new_param->p_list, &param_list->param_list);
593 }
594
Jesper Juhl9be08c52011-08-02 10:26:36 +0200595 if (!list_empty(&param_list->param_list)) {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000596 *dst_param_list = param_list;
Jesper Juhl9be08c52011-08-02 10:26:36 +0200597 } else {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000598 pr_err("No parameters allocated.\n");
599 goto err_out;
600 }
601
602 return 0;
603
604err_out:
605 iscsi_release_param_list(param_list);
606 return -1;
607}
608
609static void iscsi_release_extra_responses(struct iscsi_param_list *param_list)
610{
611 struct iscsi_extra_response *er, *er_tmp;
612
613 list_for_each_entry_safe(er, er_tmp, &param_list->extra_response_list,
614 er_list) {
615 list_del(&er->er_list);
616 kfree(er);
617 }
618}
619
620void iscsi_release_param_list(struct iscsi_param_list *param_list)
621{
622 struct iscsi_param *param, *param_tmp;
623
624 list_for_each_entry_safe(param, param_tmp, &param_list->param_list,
625 p_list) {
626 list_del(&param->p_list);
627
628 kfree(param->name);
629 param->name = NULL;
630 kfree(param->value);
631 param->value = NULL;
632 kfree(param);
633 param = NULL;
634 }
635
636 iscsi_release_extra_responses(param_list);
637
638 kfree(param_list);
639}
640
641struct iscsi_param *iscsi_find_param_from_key(
642 char *key,
643 struct iscsi_param_list *param_list)
644{
645 struct iscsi_param *param;
646
647 if (!key || !param_list) {
648 pr_err("Key or parameter list pointer is NULL.\n");
649 return NULL;
650 }
651
652 list_for_each_entry(param, &param_list->param_list, p_list) {
653 if (!strcmp(key, param->name))
654 return param;
655 }
656
657 pr_err("Unable to locate key \"%s\".\n", key);
658 return NULL;
659}
660
661int iscsi_extract_key_value(char *textbuf, char **key, char **value)
662{
663 *value = strchr(textbuf, '=');
664 if (!*value) {
665 pr_err("Unable to locate \"=\" seperator for key,"
666 " ignoring request.\n");
667 return -1;
668 }
669
670 *key = textbuf;
671 **value = '\0';
672 *value = *value + 1;
673
674 return 0;
675}
676
677int iscsi_update_param_value(struct iscsi_param *param, char *value)
678{
679 kfree(param->value);
680
681 param->value = kzalloc(strlen(value) + 1, GFP_KERNEL);
682 if (!param->value) {
683 pr_err("Unable to allocate memory for value.\n");
Andy Grover617a0c22012-07-12 17:34:56 -0700684 return -ENOMEM;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000685 }
686
687 memcpy(param->value, value, strlen(value));
688 param->value[strlen(value)] = '\0';
689
690 pr_debug("iSCSI Parameter updated to %s=%s\n",
691 param->name, param->value);
692 return 0;
693}
694
695static int iscsi_add_notunderstood_response(
696 char *key,
697 char *value,
698 struct iscsi_param_list *param_list)
699{
700 struct iscsi_extra_response *extra_response;
701
702 if (strlen(value) > VALUE_MAXLEN) {
703 pr_err("Value for notunderstood key \"%s\" exceeds %d,"
704 " protocol error.\n", key, VALUE_MAXLEN);
705 return -1;
706 }
707
708 extra_response = kzalloc(sizeof(struct iscsi_extra_response), GFP_KERNEL);
709 if (!extra_response) {
710 pr_err("Unable to allocate memory for"
711 " struct iscsi_extra_response.\n");
712 return -1;
713 }
714 INIT_LIST_HEAD(&extra_response->er_list);
715
716 strncpy(extra_response->key, key, strlen(key) + 1);
717 strncpy(extra_response->value, NOTUNDERSTOOD,
718 strlen(NOTUNDERSTOOD) + 1);
719
720 list_add_tail(&extra_response->er_list,
721 &param_list->extra_response_list);
722 return 0;
723}
724
725static int iscsi_check_for_auth_key(char *key)
726{
727 /*
728 * RFC 1994
729 */
730 if (!strcmp(key, "CHAP_A") || !strcmp(key, "CHAP_I") ||
731 !strcmp(key, "CHAP_C") || !strcmp(key, "CHAP_N") ||
732 !strcmp(key, "CHAP_R"))
733 return 1;
734
735 /*
736 * RFC 2945
737 */
738 if (!strcmp(key, "SRP_U") || !strcmp(key, "SRP_N") ||
739 !strcmp(key, "SRP_g") || !strcmp(key, "SRP_s") ||
740 !strcmp(key, "SRP_A") || !strcmp(key, "SRP_B") ||
741 !strcmp(key, "SRP_M") || !strcmp(key, "SRP_HM"))
742 return 1;
743
744 return 0;
745}
746
747static void iscsi_check_proposer_for_optional_reply(struct iscsi_param *param)
748{
749 if (IS_TYPE_BOOL_AND(param)) {
750 if (!strcmp(param->value, NO))
751 SET_PSTATE_REPLY_OPTIONAL(param);
752 } else if (IS_TYPE_BOOL_OR(param)) {
753 if (!strcmp(param->value, YES))
754 SET_PSTATE_REPLY_OPTIONAL(param);
755 /*
756 * Required for gPXE iSCSI boot client
757 */
758 if (!strcmp(param->name, IMMEDIATEDATA))
759 SET_PSTATE_REPLY_OPTIONAL(param);
760 } else if (IS_TYPE_NUMBER(param)) {
761 if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH))
762 SET_PSTATE_REPLY_OPTIONAL(param);
763 /*
764 * The GlobalSAN iSCSI Initiator for MacOSX does
765 * not respond to MaxBurstLength, FirstBurstLength,
766 * DefaultTime2Wait or DefaultTime2Retain parameter keys.
767 * So, we set them to 'reply optional' here, and assume the
768 * the defaults from iscsi_parameters.h if the initiator
769 * is not RFC compliant and the keys are not negotiated.
770 */
771 if (!strcmp(param->name, MAXBURSTLENGTH))
772 SET_PSTATE_REPLY_OPTIONAL(param);
773 if (!strcmp(param->name, FIRSTBURSTLENGTH))
774 SET_PSTATE_REPLY_OPTIONAL(param);
775 if (!strcmp(param->name, DEFAULTTIME2WAIT))
776 SET_PSTATE_REPLY_OPTIONAL(param);
777 if (!strcmp(param->name, DEFAULTTIME2RETAIN))
778 SET_PSTATE_REPLY_OPTIONAL(param);
779 /*
780 * Required for gPXE iSCSI boot client
781 */
782 if (!strcmp(param->name, MAXCONNECTIONS))
783 SET_PSTATE_REPLY_OPTIONAL(param);
784 } else if (IS_PHASE_DECLARATIVE(param))
785 SET_PSTATE_REPLY_OPTIONAL(param);
786}
787
788static int iscsi_check_boolean_value(struct iscsi_param *param, char *value)
789{
790 if (strcmp(value, YES) && strcmp(value, NO)) {
791 pr_err("Illegal value for \"%s\", must be either"
792 " \"%s\" or \"%s\".\n", param->name, YES, NO);
793 return -1;
794 }
795
796 return 0;
797}
798
799static int iscsi_check_numerical_value(struct iscsi_param *param, char *value_ptr)
800{
801 char *tmpptr;
802 int value = 0;
803
804 value = simple_strtoul(value_ptr, &tmpptr, 0);
805
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000806 if (IS_TYPERANGE_0_TO_2(param)) {
807 if ((value < 0) || (value > 2)) {
808 pr_err("Illegal value for \"%s\", must be"
809 " between 0 and 2.\n", param->name);
810 return -1;
811 }
812 return 0;
813 }
814 if (IS_TYPERANGE_0_TO_3600(param)) {
815 if ((value < 0) || (value > 3600)) {
816 pr_err("Illegal value for \"%s\", must be"
817 " between 0 and 3600.\n", param->name);
818 return -1;
819 }
820 return 0;
821 }
822 if (IS_TYPERANGE_0_TO_32767(param)) {
823 if ((value < 0) || (value > 32767)) {
824 pr_err("Illegal value for \"%s\", must be"
825 " between 0 and 32767.\n", param->name);
826 return -1;
827 }
828 return 0;
829 }
830 if (IS_TYPERANGE_0_TO_65535(param)) {
831 if ((value < 0) || (value > 65535)) {
832 pr_err("Illegal value for \"%s\", must be"
833 " between 0 and 65535.\n", param->name);
834 return -1;
835 }
836 return 0;
837 }
838 if (IS_TYPERANGE_1_TO_65535(param)) {
839 if ((value < 1) || (value > 65535)) {
840 pr_err("Illegal value for \"%s\", must be"
841 " between 1 and 65535.\n", param->name);
842 return -1;
843 }
844 return 0;
845 }
846 if (IS_TYPERANGE_2_TO_3600(param)) {
847 if ((value < 2) || (value > 3600)) {
848 pr_err("Illegal value for \"%s\", must be"
849 " between 2 and 3600.\n", param->name);
850 return -1;
851 }
852 return 0;
853 }
854 if (IS_TYPERANGE_512_TO_16777215(param)) {
855 if ((value < 512) || (value > 16777215)) {
856 pr_err("Illegal value for \"%s\", must be"
857 " between 512 and 16777215.\n", param->name);
858 return -1;
859 }
860 return 0;
861 }
862
863 return 0;
864}
865
866static int iscsi_check_numerical_range_value(struct iscsi_param *param, char *value)
867{
868 char *left_val_ptr = NULL, *right_val_ptr = NULL;
Jörn Engela227fb32012-03-15 15:08:03 -0400869 char *tilde_ptr = NULL;
870 u32 left_val, right_val, local_left_val;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000871
872 if (strcmp(param->name, IFMARKINT) &&
873 strcmp(param->name, OFMARKINT)) {
874 pr_err("Only parameters \"%s\" or \"%s\" may contain a"
875 " numerical range value.\n", IFMARKINT, OFMARKINT);
876 return -1;
877 }
878
879 if (IS_PSTATE_PROPOSER(param))
880 return 0;
881
882 tilde_ptr = strchr(value, '~');
883 if (!tilde_ptr) {
884 pr_err("Unable to locate numerical range indicator"
885 " \"~\" for \"%s\".\n", param->name);
886 return -1;
887 }
888 *tilde_ptr = '\0';
889
890 left_val_ptr = value;
891 right_val_ptr = value + strlen(left_val_ptr) + 1;
892
893 if (iscsi_check_numerical_value(param, left_val_ptr) < 0)
894 return -1;
895 if (iscsi_check_numerical_value(param, right_val_ptr) < 0)
896 return -1;
897
Jörn Engela227fb32012-03-15 15:08:03 -0400898 left_val = simple_strtoul(left_val_ptr, NULL, 0);
899 right_val = simple_strtoul(right_val_ptr, NULL, 0);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000900 *tilde_ptr = '~';
901
902 if (right_val < left_val) {
903 pr_err("Numerical range for parameter \"%s\" contains"
904 " a right value which is less than the left.\n",
905 param->name);
906 return -1;
907 }
908
909 /*
910 * For now, enforce reasonable defaults for [I,O]FMarkInt.
911 */
912 tilde_ptr = strchr(param->value, '~');
913 if (!tilde_ptr) {
914 pr_err("Unable to locate numerical range indicator"
915 " \"~\" for \"%s\".\n", param->name);
916 return -1;
917 }
918 *tilde_ptr = '\0';
919
920 left_val_ptr = param->value;
921 right_val_ptr = param->value + strlen(left_val_ptr) + 1;
922
Jörn Engela227fb32012-03-15 15:08:03 -0400923 local_left_val = simple_strtoul(left_val_ptr, NULL, 0);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000924 *tilde_ptr = '~';
925
926 if (param->set_param) {
927 if ((left_val < local_left_val) ||
928 (right_val < local_left_val)) {
929 pr_err("Passed value range \"%u~%u\" is below"
930 " minimum left value \"%u\" for key \"%s\","
931 " rejecting.\n", left_val, right_val,
932 local_left_val, param->name);
933 return -1;
934 }
935 } else {
936 if ((left_val < local_left_val) &&
937 (right_val < local_left_val)) {
938 pr_err("Received value range \"%u~%u\" is"
939 " below minimum left value \"%u\" for key"
940 " \"%s\", rejecting.\n", left_val, right_val,
941 local_left_val, param->name);
942 SET_PSTATE_REJECT(param);
943 if (iscsi_update_param_value(param, REJECT) < 0)
944 return -1;
945 }
946 }
947
948 return 0;
949}
950
951static int iscsi_check_string_or_list_value(struct iscsi_param *param, char *value)
952{
953 if (IS_PSTATE_PROPOSER(param))
954 return 0;
955
956 if (IS_TYPERANGE_AUTH_PARAM(param)) {
957 if (strcmp(value, KRB5) && strcmp(value, SPKM1) &&
958 strcmp(value, SPKM2) && strcmp(value, SRP) &&
959 strcmp(value, CHAP) && strcmp(value, NONE)) {
960 pr_err("Illegal value for \"%s\", must be"
961 " \"%s\", \"%s\", \"%s\", \"%s\", \"%s\""
962 " or \"%s\".\n", param->name, KRB5,
963 SPKM1, SPKM2, SRP, CHAP, NONE);
964 return -1;
965 }
966 }
967 if (IS_TYPERANGE_DIGEST_PARAM(param)) {
968 if (strcmp(value, CRC32C) && strcmp(value, NONE)) {
969 pr_err("Illegal value for \"%s\", must be"
970 " \"%s\" or \"%s\".\n", param->name,
971 CRC32C, NONE);
972 return -1;
973 }
974 }
975 if (IS_TYPERANGE_SESSIONTYPE(param)) {
976 if (strcmp(value, DISCOVERY) && strcmp(value, NORMAL)) {
977 pr_err("Illegal value for \"%s\", must be"
978 " \"%s\" or \"%s\".\n", param->name,
979 DISCOVERY, NORMAL);
980 return -1;
981 }
982 }
983
984 return 0;
985}
986
987/*
988 * This function is used to pick a value range number, currently just
989 * returns the lesser of both right values.
990 */
991static char *iscsi_get_value_from_number_range(
992 struct iscsi_param *param,
993 char *value)
994{
995 char *end_ptr, *tilde_ptr1 = NULL, *tilde_ptr2 = NULL;
996 u32 acceptor_right_value, proposer_right_value;
997
998 tilde_ptr1 = strchr(value, '~');
999 if (!tilde_ptr1)
1000 return NULL;
1001 *tilde_ptr1++ = '\0';
1002 proposer_right_value = simple_strtoul(tilde_ptr1, &end_ptr, 0);
1003
1004 tilde_ptr2 = strchr(param->value, '~');
1005 if (!tilde_ptr2)
1006 return NULL;
1007 *tilde_ptr2++ = '\0';
1008 acceptor_right_value = simple_strtoul(tilde_ptr2, &end_ptr, 0);
1009
1010 return (acceptor_right_value >= proposer_right_value) ?
1011 tilde_ptr1 : tilde_ptr2;
1012}
1013
1014static char *iscsi_check_valuelist_for_support(
1015 struct iscsi_param *param,
1016 char *value)
1017{
1018 char *tmp1 = NULL, *tmp2 = NULL;
1019 char *acceptor_values = NULL, *proposer_values = NULL;
1020
1021 acceptor_values = param->value;
1022 proposer_values = value;
1023
1024 do {
1025 if (!proposer_values)
1026 return NULL;
1027 tmp1 = strchr(proposer_values, ',');
1028 if (tmp1)
1029 *tmp1 = '\0';
1030 acceptor_values = param->value;
1031 do {
1032 if (!acceptor_values) {
1033 if (tmp1)
1034 *tmp1 = ',';
1035 return NULL;
1036 }
1037 tmp2 = strchr(acceptor_values, ',');
1038 if (tmp2)
1039 *tmp2 = '\0';
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001040 if (!strcmp(acceptor_values, proposer_values)) {
1041 if (tmp2)
1042 *tmp2 = ',';
1043 goto out;
1044 }
1045 if (tmp2)
1046 *tmp2++ = ',';
1047
1048 acceptor_values = tmp2;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001049 } while (acceptor_values);
1050 if (tmp1)
1051 *tmp1++ = ',';
1052 proposer_values = tmp1;
1053 } while (proposer_values);
1054
1055out:
1056 return proposer_values;
1057}
1058
1059static int iscsi_check_acceptor_state(struct iscsi_param *param, char *value)
1060{
1061 u8 acceptor_boolean_value = 0, proposer_boolean_value = 0;
1062 char *negoitated_value = NULL;
1063
1064 if (IS_PSTATE_ACCEPTOR(param)) {
1065 pr_err("Received key \"%s\" twice, protocol error.\n",
1066 param->name);
1067 return -1;
1068 }
1069
1070 if (IS_PSTATE_REJECT(param))
1071 return 0;
1072
1073 if (IS_TYPE_BOOL_AND(param)) {
1074 if (!strcmp(value, YES))
1075 proposer_boolean_value = 1;
1076 if (!strcmp(param->value, YES))
1077 acceptor_boolean_value = 1;
1078 if (acceptor_boolean_value && proposer_boolean_value)
1079 do {} while (0);
1080 else {
1081 if (iscsi_update_param_value(param, NO) < 0)
1082 return -1;
1083 if (!proposer_boolean_value)
1084 SET_PSTATE_REPLY_OPTIONAL(param);
1085 }
1086 } else if (IS_TYPE_BOOL_OR(param)) {
1087 if (!strcmp(value, YES))
1088 proposer_boolean_value = 1;
1089 if (!strcmp(param->value, YES))
1090 acceptor_boolean_value = 1;
1091 if (acceptor_boolean_value || proposer_boolean_value) {
1092 if (iscsi_update_param_value(param, YES) < 0)
1093 return -1;
1094 if (proposer_boolean_value)
1095 SET_PSTATE_REPLY_OPTIONAL(param);
1096 }
1097 } else if (IS_TYPE_NUMBER(param)) {
1098 char *tmpptr, buf[10];
1099 u32 acceptor_value = simple_strtoul(param->value, &tmpptr, 0);
1100 u32 proposer_value = simple_strtoul(value, &tmpptr, 0);
1101
1102 memset(buf, 0, 10);
1103
1104 if (!strcmp(param->name, MAXCONNECTIONS) ||
1105 !strcmp(param->name, MAXBURSTLENGTH) ||
1106 !strcmp(param->name, FIRSTBURSTLENGTH) ||
1107 !strcmp(param->name, MAXOUTSTANDINGR2T) ||
1108 !strcmp(param->name, DEFAULTTIME2RETAIN) ||
1109 !strcmp(param->name, ERRORRECOVERYLEVEL)) {
1110 if (proposer_value > acceptor_value) {
1111 sprintf(buf, "%u", acceptor_value);
1112 if (iscsi_update_param_value(param,
1113 &buf[0]) < 0)
1114 return -1;
1115 } else {
1116 if (iscsi_update_param_value(param, value) < 0)
1117 return -1;
1118 }
1119 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
1120 if (acceptor_value > proposer_value) {
1121 sprintf(buf, "%u", acceptor_value);
1122 if (iscsi_update_param_value(param,
1123 &buf[0]) < 0)
1124 return -1;
1125 } else {
1126 if (iscsi_update_param_value(param, value) < 0)
1127 return -1;
1128 }
1129 } else {
1130 if (iscsi_update_param_value(param, value) < 0)
1131 return -1;
1132 }
1133
1134 if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH))
1135 SET_PSTATE_REPLY_OPTIONAL(param);
1136 } else if (IS_TYPE_NUMBER_RANGE(param)) {
1137 negoitated_value = iscsi_get_value_from_number_range(
1138 param, value);
1139 if (!negoitated_value)
1140 return -1;
1141 if (iscsi_update_param_value(param, negoitated_value) < 0)
1142 return -1;
1143 } else if (IS_TYPE_VALUE_LIST(param)) {
1144 negoitated_value = iscsi_check_valuelist_for_support(
1145 param, value);
1146 if (!negoitated_value) {
1147 pr_err("Proposer's value list \"%s\" contains"
1148 " no valid values from Acceptor's value list"
1149 " \"%s\".\n", value, param->value);
1150 return -1;
1151 }
1152 if (iscsi_update_param_value(param, negoitated_value) < 0)
1153 return -1;
1154 } else if (IS_PHASE_DECLARATIVE(param)) {
1155 if (iscsi_update_param_value(param, value) < 0)
1156 return -1;
1157 SET_PSTATE_REPLY_OPTIONAL(param);
1158 }
1159
1160 return 0;
1161}
1162
1163static int iscsi_check_proposer_state(struct iscsi_param *param, char *value)
1164{
1165 if (IS_PSTATE_RESPONSE_GOT(param)) {
1166 pr_err("Received key \"%s\" twice, protocol error.\n",
1167 param->name);
1168 return -1;
1169 }
1170
1171 if (IS_TYPE_NUMBER_RANGE(param)) {
1172 u32 left_val = 0, right_val = 0, recieved_value = 0;
1173 char *left_val_ptr = NULL, *right_val_ptr = NULL;
Jörn Engela227fb32012-03-15 15:08:03 -04001174 char *tilde_ptr = NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001175
1176 if (!strcmp(value, IRRELEVANT) || !strcmp(value, REJECT)) {
1177 if (iscsi_update_param_value(param, value) < 0)
1178 return -1;
1179 return 0;
1180 }
1181
1182 tilde_ptr = strchr(value, '~');
1183 if (tilde_ptr) {
1184 pr_err("Illegal \"~\" in response for \"%s\".\n",
1185 param->name);
1186 return -1;
1187 }
1188 tilde_ptr = strchr(param->value, '~');
1189 if (!tilde_ptr) {
1190 pr_err("Unable to locate numerical range"
1191 " indicator \"~\" for \"%s\".\n", param->name);
1192 return -1;
1193 }
1194 *tilde_ptr = '\0';
1195
1196 left_val_ptr = param->value;
1197 right_val_ptr = param->value + strlen(left_val_ptr) + 1;
Jörn Engela227fb32012-03-15 15:08:03 -04001198 left_val = simple_strtoul(left_val_ptr, NULL, 0);
1199 right_val = simple_strtoul(right_val_ptr, NULL, 0);
1200 recieved_value = simple_strtoul(value, NULL, 0);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001201
1202 *tilde_ptr = '~';
1203
1204 if ((recieved_value < left_val) ||
1205 (recieved_value > right_val)) {
1206 pr_err("Illegal response \"%s=%u\", value must"
1207 " be between %u and %u.\n", param->name,
1208 recieved_value, left_val, right_val);
1209 return -1;
1210 }
1211 } else if (IS_TYPE_VALUE_LIST(param)) {
1212 char *comma_ptr = NULL, *tmp_ptr = NULL;
1213
1214 comma_ptr = strchr(value, ',');
1215 if (comma_ptr) {
1216 pr_err("Illegal \",\" in response for \"%s\".\n",
1217 param->name);
1218 return -1;
1219 }
1220
1221 tmp_ptr = iscsi_check_valuelist_for_support(param, value);
1222 if (!tmp_ptr)
1223 return -1;
1224 }
1225
1226 if (iscsi_update_param_value(param, value) < 0)
1227 return -1;
1228
1229 return 0;
1230}
1231
1232static int iscsi_check_value(struct iscsi_param *param, char *value)
1233{
1234 char *comma_ptr = NULL;
1235
1236 if (!strcmp(value, REJECT)) {
1237 if (!strcmp(param->name, IFMARKINT) ||
1238 !strcmp(param->name, OFMARKINT)) {
1239 /*
1240 * Reject is not fatal for [I,O]FMarkInt, and causes
1241 * [I,O]FMarker to be reset to No. (See iSCSI v20 A.3.2)
1242 */
1243 SET_PSTATE_REJECT(param);
1244 return 0;
1245 }
1246 pr_err("Received %s=%s\n", param->name, value);
1247 return -1;
1248 }
1249 if (!strcmp(value, IRRELEVANT)) {
1250 pr_debug("Received %s=%s\n", param->name, value);
1251 SET_PSTATE_IRRELEVANT(param);
1252 return 0;
1253 }
1254 if (!strcmp(value, NOTUNDERSTOOD)) {
1255 if (!IS_PSTATE_PROPOSER(param)) {
1256 pr_err("Received illegal offer %s=%s\n",
1257 param->name, value);
1258 return -1;
1259 }
1260
1261/* #warning FIXME: Add check for X-ExtensionKey here */
1262 pr_err("Standard iSCSI key \"%s\" cannot be answered"
1263 " with \"%s\", protocol error.\n", param->name, value);
1264 return -1;
1265 }
1266
1267 do {
1268 comma_ptr = NULL;
1269 comma_ptr = strchr(value, ',');
1270
1271 if (comma_ptr && !IS_TYPE_VALUE_LIST(param)) {
1272 pr_err("Detected value seperator \",\", but"
1273 " key \"%s\" does not allow a value list,"
1274 " protocol error.\n", param->name);
1275 return -1;
1276 }
1277 if (comma_ptr)
1278 *comma_ptr = '\0';
1279
1280 if (strlen(value) > VALUE_MAXLEN) {
1281 pr_err("Value for key \"%s\" exceeds %d,"
1282 " protocol error.\n", param->name,
1283 VALUE_MAXLEN);
1284 return -1;
1285 }
1286
1287 if (IS_TYPE_BOOL_AND(param) || IS_TYPE_BOOL_OR(param)) {
1288 if (iscsi_check_boolean_value(param, value) < 0)
1289 return -1;
1290 } else if (IS_TYPE_NUMBER(param)) {
1291 if (iscsi_check_numerical_value(param, value) < 0)
1292 return -1;
1293 } else if (IS_TYPE_NUMBER_RANGE(param)) {
1294 if (iscsi_check_numerical_range_value(param, value) < 0)
1295 return -1;
1296 } else if (IS_TYPE_STRING(param) || IS_TYPE_VALUE_LIST(param)) {
1297 if (iscsi_check_string_or_list_value(param, value) < 0)
1298 return -1;
1299 } else {
1300 pr_err("Huh? 0x%02x\n", param->type);
1301 return -1;
1302 }
1303
1304 if (comma_ptr)
1305 *comma_ptr++ = ',';
1306
1307 value = comma_ptr;
1308 } while (value);
1309
1310 return 0;
1311}
1312
1313static struct iscsi_param *__iscsi_check_key(
1314 char *key,
1315 int sender,
1316 struct iscsi_param_list *param_list)
1317{
1318 struct iscsi_param *param;
1319
1320 if (strlen(key) > KEY_MAXLEN) {
1321 pr_err("Length of key name \"%s\" exceeds %d.\n",
1322 key, KEY_MAXLEN);
1323 return NULL;
1324 }
1325
1326 param = iscsi_find_param_from_key(key, param_list);
1327 if (!param)
1328 return NULL;
1329
1330 if ((sender & SENDER_INITIATOR) && !IS_SENDER_INITIATOR(param)) {
1331 pr_err("Key \"%s\" may not be sent to %s,"
1332 " protocol error.\n", param->name,
1333 (sender & SENDER_RECEIVER) ? "target" : "initiator");
1334 return NULL;
1335 }
1336
1337 if ((sender & SENDER_TARGET) && !IS_SENDER_TARGET(param)) {
1338 pr_err("Key \"%s\" may not be sent to %s,"
1339 " protocol error.\n", param->name,
1340 (sender & SENDER_RECEIVER) ? "initiator" : "target");
1341 return NULL;
1342 }
1343
1344 return param;
1345}
1346
1347static struct iscsi_param *iscsi_check_key(
1348 char *key,
1349 int phase,
1350 int sender,
1351 struct iscsi_param_list *param_list)
1352{
1353 struct iscsi_param *param;
1354 /*
1355 * Key name length must not exceed 63 bytes. (See iSCSI v20 5.1)
1356 */
1357 if (strlen(key) > KEY_MAXLEN) {
1358 pr_err("Length of key name \"%s\" exceeds %d.\n",
1359 key, KEY_MAXLEN);
1360 return NULL;
1361 }
1362
1363 param = iscsi_find_param_from_key(key, param_list);
1364 if (!param)
1365 return NULL;
1366
1367 if ((sender & SENDER_INITIATOR) && !IS_SENDER_INITIATOR(param)) {
1368 pr_err("Key \"%s\" may not be sent to %s,"
1369 " protocol error.\n", param->name,
1370 (sender & SENDER_RECEIVER) ? "target" : "initiator");
1371 return NULL;
1372 }
1373 if ((sender & SENDER_TARGET) && !IS_SENDER_TARGET(param)) {
1374 pr_err("Key \"%s\" may not be sent to %s,"
1375 " protocol error.\n", param->name,
1376 (sender & SENDER_RECEIVER) ? "initiator" : "target");
1377 return NULL;
1378 }
1379
1380 if (IS_PSTATE_ACCEPTOR(param)) {
1381 pr_err("Key \"%s\" received twice, protocol error.\n",
1382 key);
1383 return NULL;
1384 }
1385
1386 if (!phase)
1387 return param;
1388
1389 if (!(param->phase & phase)) {
1390 pr_err("Key \"%s\" may not be negotiated during ",
1391 param->name);
1392 switch (phase) {
1393 case PHASE_SECURITY:
1394 pr_debug("Security phase.\n");
1395 break;
1396 case PHASE_OPERATIONAL:
1397 pr_debug("Operational phase.\n");
1398 default:
1399 pr_debug("Unknown phase.\n");
1400 }
1401 return NULL;
1402 }
1403
1404 return param;
1405}
1406
1407static int iscsi_enforce_integrity_rules(
1408 u8 phase,
1409 struct iscsi_param_list *param_list)
1410{
1411 char *tmpptr;
1412 u8 DataSequenceInOrder = 0;
1413 u8 ErrorRecoveryLevel = 0, SessionType = 0;
1414 u8 IFMarker = 0, OFMarker = 0;
Nicholas Bellinger2ff017f2011-09-16 01:44:54 -07001415 u8 IFMarkInt_Reject = 1, OFMarkInt_Reject = 1;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001416 u32 FirstBurstLength = 0, MaxBurstLength = 0;
1417 struct iscsi_param *param = NULL;
1418
1419 list_for_each_entry(param, &param_list->param_list, p_list) {
1420 if (!(param->phase & phase))
1421 continue;
1422 if (!strcmp(param->name, SESSIONTYPE))
1423 if (!strcmp(param->value, NORMAL))
1424 SessionType = 1;
1425 if (!strcmp(param->name, ERRORRECOVERYLEVEL))
1426 ErrorRecoveryLevel = simple_strtoul(param->value,
1427 &tmpptr, 0);
1428 if (!strcmp(param->name, DATASEQUENCEINORDER))
1429 if (!strcmp(param->value, YES))
1430 DataSequenceInOrder = 1;
1431 if (!strcmp(param->name, MAXBURSTLENGTH))
1432 MaxBurstLength = simple_strtoul(param->value,
1433 &tmpptr, 0);
1434 if (!strcmp(param->name, IFMARKER))
1435 if (!strcmp(param->value, YES))
1436 IFMarker = 1;
1437 if (!strcmp(param->name, OFMARKER))
1438 if (!strcmp(param->value, YES))
1439 OFMarker = 1;
1440 if (!strcmp(param->name, IFMARKINT))
1441 if (!strcmp(param->value, REJECT))
1442 IFMarkInt_Reject = 1;
1443 if (!strcmp(param->name, OFMARKINT))
1444 if (!strcmp(param->value, REJECT))
1445 OFMarkInt_Reject = 1;
1446 }
1447
1448 list_for_each_entry(param, &param_list->param_list, p_list) {
1449 if (!(param->phase & phase))
1450 continue;
1451 if (!SessionType && (!IS_PSTATE_ACCEPTOR(param) &&
1452 (strcmp(param->name, IFMARKER) &&
1453 strcmp(param->name, OFMARKER) &&
1454 strcmp(param->name, IFMARKINT) &&
1455 strcmp(param->name, OFMARKINT))))
1456 continue;
1457 if (!strcmp(param->name, MAXOUTSTANDINGR2T) &&
1458 DataSequenceInOrder && (ErrorRecoveryLevel > 0)) {
1459 if (strcmp(param->value, "1")) {
1460 if (iscsi_update_param_value(param, "1") < 0)
1461 return -1;
1462 pr_debug("Reset \"%s\" to \"%s\".\n",
1463 param->name, param->value);
1464 }
1465 }
1466 if (!strcmp(param->name, MAXCONNECTIONS) && !SessionType) {
1467 if (strcmp(param->value, "1")) {
1468 if (iscsi_update_param_value(param, "1") < 0)
1469 return -1;
1470 pr_debug("Reset \"%s\" to \"%s\".\n",
1471 param->name, param->value);
1472 }
1473 }
1474 if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
1475 FirstBurstLength = simple_strtoul(param->value,
1476 &tmpptr, 0);
1477 if (FirstBurstLength > MaxBurstLength) {
1478 char tmpbuf[10];
1479 memset(tmpbuf, 0, 10);
1480 sprintf(tmpbuf, "%u", MaxBurstLength);
1481 if (iscsi_update_param_value(param, tmpbuf))
1482 return -1;
1483 pr_debug("Reset \"%s\" to \"%s\".\n",
1484 param->name, param->value);
1485 }
1486 }
1487 if (!strcmp(param->name, IFMARKER) && IFMarkInt_Reject) {
1488 if (iscsi_update_param_value(param, NO) < 0)
1489 return -1;
1490 IFMarker = 0;
1491 pr_debug("Reset \"%s\" to \"%s\".\n",
1492 param->name, param->value);
1493 }
1494 if (!strcmp(param->name, OFMARKER) && OFMarkInt_Reject) {
1495 if (iscsi_update_param_value(param, NO) < 0)
1496 return -1;
1497 OFMarker = 0;
1498 pr_debug("Reset \"%s\" to \"%s\".\n",
1499 param->name, param->value);
1500 }
1501 if (!strcmp(param->name, IFMARKINT) && !IFMarker) {
1502 if (!strcmp(param->value, REJECT))
1503 continue;
1504 param->state &= ~PSTATE_NEGOTIATE;
1505 if (iscsi_update_param_value(param, IRRELEVANT) < 0)
1506 return -1;
1507 pr_debug("Reset \"%s\" to \"%s\".\n",
1508 param->name, param->value);
1509 }
1510 if (!strcmp(param->name, OFMARKINT) && !OFMarker) {
1511 if (!strcmp(param->value, REJECT))
1512 continue;
1513 param->state &= ~PSTATE_NEGOTIATE;
1514 if (iscsi_update_param_value(param, IRRELEVANT) < 0)
1515 return -1;
1516 pr_debug("Reset \"%s\" to \"%s\".\n",
1517 param->name, param->value);
1518 }
1519 }
1520
1521 return 0;
1522}
1523
1524int iscsi_decode_text_input(
1525 u8 phase,
1526 u8 sender,
1527 char *textbuf,
1528 u32 length,
1529 struct iscsi_param_list *param_list)
1530{
1531 char *tmpbuf, *start = NULL, *end = NULL;
1532
1533 tmpbuf = kzalloc(length + 1, GFP_KERNEL);
1534 if (!tmpbuf) {
1535 pr_err("Unable to allocate memory for tmpbuf.\n");
1536 return -1;
1537 }
1538
1539 memcpy(tmpbuf, textbuf, length);
1540 tmpbuf[length] = '\0';
1541 start = tmpbuf;
1542 end = (start + length);
1543
1544 while (start < end) {
1545 char *key, *value;
1546 struct iscsi_param *param;
1547
1548 if (iscsi_extract_key_value(start, &key, &value) < 0) {
1549 kfree(tmpbuf);
1550 return -1;
1551 }
1552
1553 pr_debug("Got key: %s=%s\n", key, value);
1554
1555 if (phase & PHASE_SECURITY) {
1556 if (iscsi_check_for_auth_key(key) > 0) {
1557 char *tmpptr = key + strlen(key);
1558 *tmpptr = '=';
1559 kfree(tmpbuf);
1560 return 1;
1561 }
1562 }
1563
1564 param = iscsi_check_key(key, phase, sender, param_list);
1565 if (!param) {
1566 if (iscsi_add_notunderstood_response(key,
1567 value, param_list) < 0) {
1568 kfree(tmpbuf);
1569 return -1;
1570 }
1571 start += strlen(key) + strlen(value) + 2;
1572 continue;
1573 }
1574 if (iscsi_check_value(param, value) < 0) {
1575 kfree(tmpbuf);
1576 return -1;
1577 }
1578
1579 start += strlen(key) + strlen(value) + 2;
1580
1581 if (IS_PSTATE_PROPOSER(param)) {
1582 if (iscsi_check_proposer_state(param, value) < 0) {
1583 kfree(tmpbuf);
1584 return -1;
1585 }
1586 SET_PSTATE_RESPONSE_GOT(param);
1587 } else {
1588 if (iscsi_check_acceptor_state(param, value) < 0) {
1589 kfree(tmpbuf);
1590 return -1;
1591 }
1592 SET_PSTATE_ACCEPTOR(param);
1593 }
1594 }
1595
1596 kfree(tmpbuf);
1597 return 0;
1598}
1599
1600int iscsi_encode_text_output(
1601 u8 phase,
1602 u8 sender,
1603 char *textbuf,
1604 u32 *length,
1605 struct iscsi_param_list *param_list)
1606{
1607 char *output_buf = NULL;
1608 struct iscsi_extra_response *er;
1609 struct iscsi_param *param;
1610
1611 output_buf = textbuf + *length;
1612
1613 if (iscsi_enforce_integrity_rules(phase, param_list) < 0)
1614 return -1;
1615
1616 list_for_each_entry(param, &param_list->param_list, p_list) {
1617 if (!(param->sender & sender))
1618 continue;
1619 if (IS_PSTATE_ACCEPTOR(param) &&
1620 !IS_PSTATE_RESPONSE_SENT(param) &&
1621 !IS_PSTATE_REPLY_OPTIONAL(param) &&
1622 (param->phase & phase)) {
1623 *length += sprintf(output_buf, "%s=%s",
1624 param->name, param->value);
1625 *length += 1;
1626 output_buf = textbuf + *length;
1627 SET_PSTATE_RESPONSE_SENT(param);
1628 pr_debug("Sending key: %s=%s\n",
1629 param->name, param->value);
1630 continue;
1631 }
1632 if (IS_PSTATE_NEGOTIATE(param) &&
1633 !IS_PSTATE_ACCEPTOR(param) &&
1634 !IS_PSTATE_PROPOSER(param) &&
1635 (param->phase & phase)) {
1636 *length += sprintf(output_buf, "%s=%s",
1637 param->name, param->value);
1638 *length += 1;
1639 output_buf = textbuf + *length;
1640 SET_PSTATE_PROPOSER(param);
1641 iscsi_check_proposer_for_optional_reply(param);
1642 pr_debug("Sending key: %s=%s\n",
1643 param->name, param->value);
1644 }
1645 }
1646
1647 list_for_each_entry(er, &param_list->extra_response_list, er_list) {
1648 *length += sprintf(output_buf, "%s=%s", er->key, er->value);
1649 *length += 1;
1650 output_buf = textbuf + *length;
1651 pr_debug("Sending key: %s=%s\n", er->key, er->value);
1652 }
1653 iscsi_release_extra_responses(param_list);
1654
1655 return 0;
1656}
1657
1658int iscsi_check_negotiated_keys(struct iscsi_param_list *param_list)
1659{
1660 int ret = 0;
1661 struct iscsi_param *param;
1662
1663 list_for_each_entry(param, &param_list->param_list, p_list) {
1664 if (IS_PSTATE_NEGOTIATE(param) &&
1665 IS_PSTATE_PROPOSER(param) &&
1666 !IS_PSTATE_RESPONSE_GOT(param) &&
1667 !IS_PSTATE_REPLY_OPTIONAL(param) &&
1668 !IS_PHASE_DECLARATIVE(param)) {
1669 pr_err("No response for proposed key \"%s\".\n",
1670 param->name);
1671 ret = -1;
1672 }
1673 }
1674
1675 return ret;
1676}
1677
1678int iscsi_change_param_value(
1679 char *keyvalue,
1680 struct iscsi_param_list *param_list,
1681 int check_key)
1682{
1683 char *key = NULL, *value = NULL;
1684 struct iscsi_param *param;
1685 int sender = 0;
1686
1687 if (iscsi_extract_key_value(keyvalue, &key, &value) < 0)
1688 return -1;
1689
1690 if (!check_key) {
1691 param = __iscsi_check_key(keyvalue, sender, param_list);
1692 if (!param)
1693 return -1;
1694 } else {
1695 param = iscsi_check_key(keyvalue, 0, sender, param_list);
1696 if (!param)
1697 return -1;
1698
1699 param->set_param = 1;
1700 if (iscsi_check_value(param, value) < 0) {
1701 param->set_param = 0;
1702 return -1;
1703 }
1704 param->set_param = 0;
1705 }
1706
1707 if (iscsi_update_param_value(param, value) < 0)
1708 return -1;
1709
1710 return 0;
1711}
1712
1713void iscsi_set_connection_parameters(
1714 struct iscsi_conn_ops *ops,
1715 struct iscsi_param_list *param_list)
1716{
1717 char *tmpptr;
1718 struct iscsi_param *param;
1719
1720 pr_debug("---------------------------------------------------"
1721 "---------------\n");
1722 list_for_each_entry(param, &param_list->param_list, p_list) {
1723 if (!IS_PSTATE_ACCEPTOR(param) && !IS_PSTATE_PROPOSER(param))
1724 continue;
1725 if (!strcmp(param->name, AUTHMETHOD)) {
1726 pr_debug("AuthMethod: %s\n",
1727 param->value);
1728 } else if (!strcmp(param->name, HEADERDIGEST)) {
1729 ops->HeaderDigest = !strcmp(param->value, CRC32C);
1730 pr_debug("HeaderDigest: %s\n",
1731 param->value);
1732 } else if (!strcmp(param->name, DATADIGEST)) {
1733 ops->DataDigest = !strcmp(param->value, CRC32C);
1734 pr_debug("DataDigest: %s\n",
1735 param->value);
1736 } else if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH)) {
1737 ops->MaxRecvDataSegmentLength =
1738 simple_strtoul(param->value, &tmpptr, 0);
1739 pr_debug("MaxRecvDataSegmentLength: %s\n",
1740 param->value);
1741 } else if (!strcmp(param->name, OFMARKER)) {
1742 ops->OFMarker = !strcmp(param->value, YES);
1743 pr_debug("OFMarker: %s\n",
1744 param->value);
1745 } else if (!strcmp(param->name, IFMARKER)) {
1746 ops->IFMarker = !strcmp(param->value, YES);
1747 pr_debug("IFMarker: %s\n",
1748 param->value);
1749 } else if (!strcmp(param->name, OFMARKINT)) {
1750 ops->OFMarkInt =
1751 simple_strtoul(param->value, &tmpptr, 0);
1752 pr_debug("OFMarkInt: %s\n",
1753 param->value);
1754 } else if (!strcmp(param->name, IFMARKINT)) {
1755 ops->IFMarkInt =
1756 simple_strtoul(param->value, &tmpptr, 0);
1757 pr_debug("IFMarkInt: %s\n",
1758 param->value);
1759 }
1760 }
1761 pr_debug("----------------------------------------------------"
1762 "--------------\n");
1763}
1764
1765void iscsi_set_session_parameters(
1766 struct iscsi_sess_ops *ops,
1767 struct iscsi_param_list *param_list,
1768 int leading)
1769{
1770 char *tmpptr;
1771 struct iscsi_param *param;
1772
1773 pr_debug("----------------------------------------------------"
1774 "--------------\n");
1775 list_for_each_entry(param, &param_list->param_list, p_list) {
1776 if (!IS_PSTATE_ACCEPTOR(param) && !IS_PSTATE_PROPOSER(param))
1777 continue;
1778 if (!strcmp(param->name, INITIATORNAME)) {
1779 if (!param->value)
1780 continue;
1781 if (leading)
1782 snprintf(ops->InitiatorName,
1783 sizeof(ops->InitiatorName),
1784 "%s", param->value);
1785 pr_debug("InitiatorName: %s\n",
1786 param->value);
1787 } else if (!strcmp(param->name, INITIATORALIAS)) {
1788 if (!param->value)
1789 continue;
1790 snprintf(ops->InitiatorAlias,
1791 sizeof(ops->InitiatorAlias),
1792 "%s", param->value);
1793 pr_debug("InitiatorAlias: %s\n",
1794 param->value);
1795 } else if (!strcmp(param->name, TARGETNAME)) {
1796 if (!param->value)
1797 continue;
1798 if (leading)
1799 snprintf(ops->TargetName,
1800 sizeof(ops->TargetName),
1801 "%s", param->value);
1802 pr_debug("TargetName: %s\n",
1803 param->value);
1804 } else if (!strcmp(param->name, TARGETALIAS)) {
1805 if (!param->value)
1806 continue;
1807 snprintf(ops->TargetAlias, sizeof(ops->TargetAlias),
1808 "%s", param->value);
1809 pr_debug("TargetAlias: %s\n",
1810 param->value);
1811 } else if (!strcmp(param->name, TARGETPORTALGROUPTAG)) {
1812 ops->TargetPortalGroupTag =
1813 simple_strtoul(param->value, &tmpptr, 0);
1814 pr_debug("TargetPortalGroupTag: %s\n",
1815 param->value);
1816 } else if (!strcmp(param->name, MAXCONNECTIONS)) {
1817 ops->MaxConnections =
1818 simple_strtoul(param->value, &tmpptr, 0);
1819 pr_debug("MaxConnections: %s\n",
1820 param->value);
1821 } else if (!strcmp(param->name, INITIALR2T)) {
1822 ops->InitialR2T = !strcmp(param->value, YES);
1823 pr_debug("InitialR2T: %s\n",
1824 param->value);
1825 } else if (!strcmp(param->name, IMMEDIATEDATA)) {
1826 ops->ImmediateData = !strcmp(param->value, YES);
1827 pr_debug("ImmediateData: %s\n",
1828 param->value);
1829 } else if (!strcmp(param->name, MAXBURSTLENGTH)) {
1830 ops->MaxBurstLength =
1831 simple_strtoul(param->value, &tmpptr, 0);
1832 pr_debug("MaxBurstLength: %s\n",
1833 param->value);
1834 } else if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
1835 ops->FirstBurstLength =
1836 simple_strtoul(param->value, &tmpptr, 0);
1837 pr_debug("FirstBurstLength: %s\n",
1838 param->value);
1839 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
1840 ops->DefaultTime2Wait =
1841 simple_strtoul(param->value, &tmpptr, 0);
1842 pr_debug("DefaultTime2Wait: %s\n",
1843 param->value);
1844 } else if (!strcmp(param->name, DEFAULTTIME2RETAIN)) {
1845 ops->DefaultTime2Retain =
1846 simple_strtoul(param->value, &tmpptr, 0);
1847 pr_debug("DefaultTime2Retain: %s\n",
1848 param->value);
1849 } else if (!strcmp(param->name, MAXOUTSTANDINGR2T)) {
1850 ops->MaxOutstandingR2T =
1851 simple_strtoul(param->value, &tmpptr, 0);
1852 pr_debug("MaxOutstandingR2T: %s\n",
1853 param->value);
1854 } else if (!strcmp(param->name, DATAPDUINORDER)) {
1855 ops->DataPDUInOrder = !strcmp(param->value, YES);
1856 pr_debug("DataPDUInOrder: %s\n",
1857 param->value);
1858 } else if (!strcmp(param->name, DATASEQUENCEINORDER)) {
1859 ops->DataSequenceInOrder = !strcmp(param->value, YES);
1860 pr_debug("DataSequenceInOrder: %s\n",
1861 param->value);
1862 } else if (!strcmp(param->name, ERRORRECOVERYLEVEL)) {
1863 ops->ErrorRecoveryLevel =
1864 simple_strtoul(param->value, &tmpptr, 0);
1865 pr_debug("ErrorRecoveryLevel: %s\n",
1866 param->value);
1867 } else if (!strcmp(param->name, SESSIONTYPE)) {
1868 ops->SessionType = !strcmp(param->value, DISCOVERY);
1869 pr_debug("SessionType: %s\n",
1870 param->value);
1871 }
1872 }
1873 pr_debug("----------------------------------------------------"
1874 "--------------\n");
1875
1876}