blob: 40864ee70302e5f8b4486361763f2a61012794d3 [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
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);
638 param->name = NULL;
639 kfree(param->value);
640 param->value = NULL;
641 kfree(param);
642 param = NULL;
643 }
644
645 iscsi_release_extra_responses(param_list);
646
647 kfree(param_list);
648}
649
650struct iscsi_param *iscsi_find_param_from_key(
651 char *key,
652 struct iscsi_param_list *param_list)
653{
654 struct iscsi_param *param;
655
656 if (!key || !param_list) {
657 pr_err("Key or parameter list pointer is NULL.\n");
658 return NULL;
659 }
660
661 list_for_each_entry(param, &param_list->param_list, p_list) {
662 if (!strcmp(key, param->name))
663 return param;
664 }
665
666 pr_err("Unable to locate key \"%s\".\n", key);
667 return NULL;
668}
669
670int iscsi_extract_key_value(char *textbuf, char **key, char **value)
671{
672 *value = strchr(textbuf, '=');
673 if (!*value) {
674 pr_err("Unable to locate \"=\" seperator for key,"
675 " ignoring request.\n");
676 return -1;
677 }
678
679 *key = textbuf;
680 **value = '\0';
681 *value = *value + 1;
682
683 return 0;
684}
685
686int iscsi_update_param_value(struct iscsi_param *param, char *value)
687{
688 kfree(param->value);
689
690 param->value = kzalloc(strlen(value) + 1, GFP_KERNEL);
691 if (!param->value) {
692 pr_err("Unable to allocate memory for value.\n");
Andy Grover617a0c22012-07-12 17:34:56 -0700693 return -ENOMEM;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000694 }
695
696 memcpy(param->value, value, strlen(value));
697 param->value[strlen(value)] = '\0';
698
699 pr_debug("iSCSI Parameter updated to %s=%s\n",
700 param->name, param->value);
701 return 0;
702}
703
704static int iscsi_add_notunderstood_response(
705 char *key,
706 char *value,
707 struct iscsi_param_list *param_list)
708{
709 struct iscsi_extra_response *extra_response;
710
711 if (strlen(value) > VALUE_MAXLEN) {
712 pr_err("Value for notunderstood key \"%s\" exceeds %d,"
713 " protocol error.\n", key, VALUE_MAXLEN);
714 return -1;
715 }
716
717 extra_response = kzalloc(sizeof(struct iscsi_extra_response), GFP_KERNEL);
718 if (!extra_response) {
719 pr_err("Unable to allocate memory for"
720 " struct iscsi_extra_response.\n");
721 return -1;
722 }
723 INIT_LIST_HEAD(&extra_response->er_list);
724
725 strncpy(extra_response->key, key, strlen(key) + 1);
726 strncpy(extra_response->value, NOTUNDERSTOOD,
727 strlen(NOTUNDERSTOOD) + 1);
728
729 list_add_tail(&extra_response->er_list,
730 &param_list->extra_response_list);
731 return 0;
732}
733
734static int iscsi_check_for_auth_key(char *key)
735{
736 /*
737 * RFC 1994
738 */
739 if (!strcmp(key, "CHAP_A") || !strcmp(key, "CHAP_I") ||
740 !strcmp(key, "CHAP_C") || !strcmp(key, "CHAP_N") ||
741 !strcmp(key, "CHAP_R"))
742 return 1;
743
744 /*
745 * RFC 2945
746 */
747 if (!strcmp(key, "SRP_U") || !strcmp(key, "SRP_N") ||
748 !strcmp(key, "SRP_g") || !strcmp(key, "SRP_s") ||
749 !strcmp(key, "SRP_A") || !strcmp(key, "SRP_B") ||
750 !strcmp(key, "SRP_M") || !strcmp(key, "SRP_HM"))
751 return 1;
752
753 return 0;
754}
755
756static void iscsi_check_proposer_for_optional_reply(struct iscsi_param *param)
757{
758 if (IS_TYPE_BOOL_AND(param)) {
759 if (!strcmp(param->value, NO))
760 SET_PSTATE_REPLY_OPTIONAL(param);
761 } else if (IS_TYPE_BOOL_OR(param)) {
762 if (!strcmp(param->value, YES))
763 SET_PSTATE_REPLY_OPTIONAL(param);
764 /*
765 * Required for gPXE iSCSI boot client
766 */
767 if (!strcmp(param->name, IMMEDIATEDATA))
768 SET_PSTATE_REPLY_OPTIONAL(param);
769 } else if (IS_TYPE_NUMBER(param)) {
770 if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH))
771 SET_PSTATE_REPLY_OPTIONAL(param);
772 /*
773 * The GlobalSAN iSCSI Initiator for MacOSX does
774 * not respond to MaxBurstLength, FirstBurstLength,
775 * DefaultTime2Wait or DefaultTime2Retain parameter keys.
776 * So, we set them to 'reply optional' here, and assume the
777 * the defaults from iscsi_parameters.h if the initiator
778 * is not RFC compliant and the keys are not negotiated.
779 */
780 if (!strcmp(param->name, MAXBURSTLENGTH))
781 SET_PSTATE_REPLY_OPTIONAL(param);
782 if (!strcmp(param->name, FIRSTBURSTLENGTH))
783 SET_PSTATE_REPLY_OPTIONAL(param);
784 if (!strcmp(param->name, DEFAULTTIME2WAIT))
785 SET_PSTATE_REPLY_OPTIONAL(param);
786 if (!strcmp(param->name, DEFAULTTIME2RETAIN))
787 SET_PSTATE_REPLY_OPTIONAL(param);
788 /*
789 * Required for gPXE iSCSI boot client
790 */
791 if (!strcmp(param->name, MAXCONNECTIONS))
792 SET_PSTATE_REPLY_OPTIONAL(param);
793 } else if (IS_PHASE_DECLARATIVE(param))
794 SET_PSTATE_REPLY_OPTIONAL(param);
795}
796
797static int iscsi_check_boolean_value(struct iscsi_param *param, char *value)
798{
799 if (strcmp(value, YES) && strcmp(value, NO)) {
800 pr_err("Illegal value for \"%s\", must be either"
801 " \"%s\" or \"%s\".\n", param->name, YES, NO);
802 return -1;
803 }
804
805 return 0;
806}
807
808static int iscsi_check_numerical_value(struct iscsi_param *param, char *value_ptr)
809{
810 char *tmpptr;
811 int value = 0;
812
813 value = simple_strtoul(value_ptr, &tmpptr, 0);
814
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000815 if (IS_TYPERANGE_0_TO_2(param)) {
816 if ((value < 0) || (value > 2)) {
817 pr_err("Illegal value for \"%s\", must be"
818 " between 0 and 2.\n", param->name);
819 return -1;
820 }
821 return 0;
822 }
823 if (IS_TYPERANGE_0_TO_3600(param)) {
824 if ((value < 0) || (value > 3600)) {
825 pr_err("Illegal value for \"%s\", must be"
826 " between 0 and 3600.\n", param->name);
827 return -1;
828 }
829 return 0;
830 }
831 if (IS_TYPERANGE_0_TO_32767(param)) {
832 if ((value < 0) || (value > 32767)) {
833 pr_err("Illegal value for \"%s\", must be"
834 " between 0 and 32767.\n", param->name);
835 return -1;
836 }
837 return 0;
838 }
839 if (IS_TYPERANGE_0_TO_65535(param)) {
840 if ((value < 0) || (value > 65535)) {
841 pr_err("Illegal value for \"%s\", must be"
842 " between 0 and 65535.\n", param->name);
843 return -1;
844 }
845 return 0;
846 }
847 if (IS_TYPERANGE_1_TO_65535(param)) {
848 if ((value < 1) || (value > 65535)) {
849 pr_err("Illegal value for \"%s\", must be"
850 " between 1 and 65535.\n", param->name);
851 return -1;
852 }
853 return 0;
854 }
855 if (IS_TYPERANGE_2_TO_3600(param)) {
856 if ((value < 2) || (value > 3600)) {
857 pr_err("Illegal value for \"%s\", must be"
858 " between 2 and 3600.\n", param->name);
859 return -1;
860 }
861 return 0;
862 }
863 if (IS_TYPERANGE_512_TO_16777215(param)) {
864 if ((value < 512) || (value > 16777215)) {
865 pr_err("Illegal value for \"%s\", must be"
866 " between 512 and 16777215.\n", param->name);
867 return -1;
868 }
869 return 0;
870 }
871
872 return 0;
873}
874
875static int iscsi_check_numerical_range_value(struct iscsi_param *param, char *value)
876{
877 char *left_val_ptr = NULL, *right_val_ptr = NULL;
Jörn Engela227fb32012-03-15 15:08:03 -0400878 char *tilde_ptr = NULL;
879 u32 left_val, right_val, local_left_val;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000880
881 if (strcmp(param->name, IFMARKINT) &&
882 strcmp(param->name, OFMARKINT)) {
883 pr_err("Only parameters \"%s\" or \"%s\" may contain a"
884 " numerical range value.\n", IFMARKINT, OFMARKINT);
885 return -1;
886 }
887
888 if (IS_PSTATE_PROPOSER(param))
889 return 0;
890
891 tilde_ptr = strchr(value, '~');
892 if (!tilde_ptr) {
893 pr_err("Unable to locate numerical range indicator"
894 " \"~\" for \"%s\".\n", param->name);
895 return -1;
896 }
897 *tilde_ptr = '\0';
898
899 left_val_ptr = value;
900 right_val_ptr = value + strlen(left_val_ptr) + 1;
901
902 if (iscsi_check_numerical_value(param, left_val_ptr) < 0)
903 return -1;
904 if (iscsi_check_numerical_value(param, right_val_ptr) < 0)
905 return -1;
906
Jörn Engela227fb32012-03-15 15:08:03 -0400907 left_val = simple_strtoul(left_val_ptr, NULL, 0);
908 right_val = simple_strtoul(right_val_ptr, NULL, 0);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000909 *tilde_ptr = '~';
910
911 if (right_val < left_val) {
912 pr_err("Numerical range for parameter \"%s\" contains"
913 " a right value which is less than the left.\n",
914 param->name);
915 return -1;
916 }
917
918 /*
919 * For now, enforce reasonable defaults for [I,O]FMarkInt.
920 */
921 tilde_ptr = strchr(param->value, '~');
922 if (!tilde_ptr) {
923 pr_err("Unable to locate numerical range indicator"
924 " \"~\" for \"%s\".\n", param->name);
925 return -1;
926 }
927 *tilde_ptr = '\0';
928
929 left_val_ptr = param->value;
930 right_val_ptr = param->value + strlen(left_val_ptr) + 1;
931
Jörn Engela227fb32012-03-15 15:08:03 -0400932 local_left_val = simple_strtoul(left_val_ptr, NULL, 0);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000933 *tilde_ptr = '~';
934
935 if (param->set_param) {
936 if ((left_val < local_left_val) ||
937 (right_val < local_left_val)) {
938 pr_err("Passed value range \"%u~%u\" is below"
939 " minimum left value \"%u\" for key \"%s\","
940 " rejecting.\n", left_val, right_val,
941 local_left_val, param->name);
942 return -1;
943 }
944 } else {
945 if ((left_val < local_left_val) &&
946 (right_val < local_left_val)) {
947 pr_err("Received value range \"%u~%u\" is"
948 " below minimum left value \"%u\" for key"
949 " \"%s\", rejecting.\n", left_val, right_val,
950 local_left_val, param->name);
951 SET_PSTATE_REJECT(param);
952 if (iscsi_update_param_value(param, REJECT) < 0)
953 return -1;
954 }
955 }
956
957 return 0;
958}
959
960static int iscsi_check_string_or_list_value(struct iscsi_param *param, char *value)
961{
962 if (IS_PSTATE_PROPOSER(param))
963 return 0;
964
965 if (IS_TYPERANGE_AUTH_PARAM(param)) {
966 if (strcmp(value, KRB5) && strcmp(value, SPKM1) &&
967 strcmp(value, SPKM2) && strcmp(value, SRP) &&
968 strcmp(value, CHAP) && strcmp(value, NONE)) {
969 pr_err("Illegal value for \"%s\", must be"
970 " \"%s\", \"%s\", \"%s\", \"%s\", \"%s\""
971 " or \"%s\".\n", param->name, KRB5,
972 SPKM1, SPKM2, SRP, CHAP, NONE);
973 return -1;
974 }
975 }
976 if (IS_TYPERANGE_DIGEST_PARAM(param)) {
977 if (strcmp(value, CRC32C) && strcmp(value, NONE)) {
978 pr_err("Illegal value for \"%s\", must be"
979 " \"%s\" or \"%s\".\n", param->name,
980 CRC32C, NONE);
981 return -1;
982 }
983 }
984 if (IS_TYPERANGE_SESSIONTYPE(param)) {
985 if (strcmp(value, DISCOVERY) && strcmp(value, NORMAL)) {
986 pr_err("Illegal value for \"%s\", must be"
987 " \"%s\" or \"%s\".\n", param->name,
988 DISCOVERY, NORMAL);
989 return -1;
990 }
991 }
992
993 return 0;
994}
995
996/*
997 * This function is used to pick a value range number, currently just
998 * returns the lesser of both right values.
999 */
1000static char *iscsi_get_value_from_number_range(
1001 struct iscsi_param *param,
1002 char *value)
1003{
1004 char *end_ptr, *tilde_ptr1 = NULL, *tilde_ptr2 = NULL;
1005 u32 acceptor_right_value, proposer_right_value;
1006
1007 tilde_ptr1 = strchr(value, '~');
1008 if (!tilde_ptr1)
1009 return NULL;
1010 *tilde_ptr1++ = '\0';
1011 proposer_right_value = simple_strtoul(tilde_ptr1, &end_ptr, 0);
1012
1013 tilde_ptr2 = strchr(param->value, '~');
1014 if (!tilde_ptr2)
1015 return NULL;
1016 *tilde_ptr2++ = '\0';
1017 acceptor_right_value = simple_strtoul(tilde_ptr2, &end_ptr, 0);
1018
1019 return (acceptor_right_value >= proposer_right_value) ?
1020 tilde_ptr1 : tilde_ptr2;
1021}
1022
1023static char *iscsi_check_valuelist_for_support(
1024 struct iscsi_param *param,
1025 char *value)
1026{
1027 char *tmp1 = NULL, *tmp2 = NULL;
1028 char *acceptor_values = NULL, *proposer_values = NULL;
1029
1030 acceptor_values = param->value;
1031 proposer_values = value;
1032
1033 do {
1034 if (!proposer_values)
1035 return NULL;
1036 tmp1 = strchr(proposer_values, ',');
1037 if (tmp1)
1038 *tmp1 = '\0';
1039 acceptor_values = param->value;
1040 do {
1041 if (!acceptor_values) {
1042 if (tmp1)
1043 *tmp1 = ',';
1044 return NULL;
1045 }
1046 tmp2 = strchr(acceptor_values, ',');
1047 if (tmp2)
1048 *tmp2 = '\0';
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001049 if (!strcmp(acceptor_values, proposer_values)) {
1050 if (tmp2)
1051 *tmp2 = ',';
1052 goto out;
1053 }
1054 if (tmp2)
1055 *tmp2++ = ',';
1056
1057 acceptor_values = tmp2;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001058 } while (acceptor_values);
1059 if (tmp1)
1060 *tmp1++ = ',';
1061 proposer_values = tmp1;
1062 } while (proposer_values);
1063
1064out:
1065 return proposer_values;
1066}
1067
1068static int iscsi_check_acceptor_state(struct iscsi_param *param, char *value)
1069{
1070 u8 acceptor_boolean_value = 0, proposer_boolean_value = 0;
1071 char *negoitated_value = NULL;
1072
1073 if (IS_PSTATE_ACCEPTOR(param)) {
1074 pr_err("Received key \"%s\" twice, protocol error.\n",
1075 param->name);
1076 return -1;
1077 }
1078
1079 if (IS_PSTATE_REJECT(param))
1080 return 0;
1081
1082 if (IS_TYPE_BOOL_AND(param)) {
1083 if (!strcmp(value, YES))
1084 proposer_boolean_value = 1;
1085 if (!strcmp(param->value, YES))
1086 acceptor_boolean_value = 1;
1087 if (acceptor_boolean_value && proposer_boolean_value)
1088 do {} while (0);
1089 else {
1090 if (iscsi_update_param_value(param, NO) < 0)
1091 return -1;
1092 if (!proposer_boolean_value)
1093 SET_PSTATE_REPLY_OPTIONAL(param);
1094 }
1095 } else if (IS_TYPE_BOOL_OR(param)) {
1096 if (!strcmp(value, YES))
1097 proposer_boolean_value = 1;
1098 if (!strcmp(param->value, YES))
1099 acceptor_boolean_value = 1;
1100 if (acceptor_boolean_value || proposer_boolean_value) {
1101 if (iscsi_update_param_value(param, YES) < 0)
1102 return -1;
1103 if (proposer_boolean_value)
1104 SET_PSTATE_REPLY_OPTIONAL(param);
1105 }
1106 } else if (IS_TYPE_NUMBER(param)) {
1107 char *tmpptr, buf[10];
1108 u32 acceptor_value = simple_strtoul(param->value, &tmpptr, 0);
1109 u32 proposer_value = simple_strtoul(value, &tmpptr, 0);
1110
1111 memset(buf, 0, 10);
1112
1113 if (!strcmp(param->name, MAXCONNECTIONS) ||
1114 !strcmp(param->name, MAXBURSTLENGTH) ||
1115 !strcmp(param->name, FIRSTBURSTLENGTH) ||
1116 !strcmp(param->name, MAXOUTSTANDINGR2T) ||
1117 !strcmp(param->name, DEFAULTTIME2RETAIN) ||
1118 !strcmp(param->name, ERRORRECOVERYLEVEL)) {
1119 if (proposer_value > acceptor_value) {
1120 sprintf(buf, "%u", acceptor_value);
1121 if (iscsi_update_param_value(param,
1122 &buf[0]) < 0)
1123 return -1;
1124 } else {
1125 if (iscsi_update_param_value(param, value) < 0)
1126 return -1;
1127 }
1128 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
1129 if (acceptor_value > proposer_value) {
1130 sprintf(buf, "%u", acceptor_value);
1131 if (iscsi_update_param_value(param,
1132 &buf[0]) < 0)
1133 return -1;
1134 } else {
1135 if (iscsi_update_param_value(param, value) < 0)
1136 return -1;
1137 }
1138 } else {
1139 if (iscsi_update_param_value(param, value) < 0)
1140 return -1;
1141 }
1142
1143 if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH))
1144 SET_PSTATE_REPLY_OPTIONAL(param);
1145 } else if (IS_TYPE_NUMBER_RANGE(param)) {
1146 negoitated_value = iscsi_get_value_from_number_range(
1147 param, value);
1148 if (!negoitated_value)
1149 return -1;
1150 if (iscsi_update_param_value(param, negoitated_value) < 0)
1151 return -1;
1152 } else if (IS_TYPE_VALUE_LIST(param)) {
1153 negoitated_value = iscsi_check_valuelist_for_support(
1154 param, value);
1155 if (!negoitated_value) {
1156 pr_err("Proposer's value list \"%s\" contains"
1157 " no valid values from Acceptor's value list"
1158 " \"%s\".\n", value, param->value);
1159 return -1;
1160 }
1161 if (iscsi_update_param_value(param, negoitated_value) < 0)
1162 return -1;
1163 } else if (IS_PHASE_DECLARATIVE(param)) {
1164 if (iscsi_update_param_value(param, value) < 0)
1165 return -1;
1166 SET_PSTATE_REPLY_OPTIONAL(param);
1167 }
1168
1169 return 0;
1170}
1171
1172static int iscsi_check_proposer_state(struct iscsi_param *param, char *value)
1173{
1174 if (IS_PSTATE_RESPONSE_GOT(param)) {
1175 pr_err("Received key \"%s\" twice, protocol error.\n",
1176 param->name);
1177 return -1;
1178 }
1179
1180 if (IS_TYPE_NUMBER_RANGE(param)) {
1181 u32 left_val = 0, right_val = 0, recieved_value = 0;
1182 char *left_val_ptr = NULL, *right_val_ptr = NULL;
Jörn Engela227fb32012-03-15 15:08:03 -04001183 char *tilde_ptr = NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001184
1185 if (!strcmp(value, IRRELEVANT) || !strcmp(value, REJECT)) {
1186 if (iscsi_update_param_value(param, value) < 0)
1187 return -1;
1188 return 0;
1189 }
1190
1191 tilde_ptr = strchr(value, '~');
1192 if (tilde_ptr) {
1193 pr_err("Illegal \"~\" in response for \"%s\".\n",
1194 param->name);
1195 return -1;
1196 }
1197 tilde_ptr = strchr(param->value, '~');
1198 if (!tilde_ptr) {
1199 pr_err("Unable to locate numerical range"
1200 " indicator \"~\" for \"%s\".\n", param->name);
1201 return -1;
1202 }
1203 *tilde_ptr = '\0';
1204
1205 left_val_ptr = param->value;
1206 right_val_ptr = param->value + strlen(left_val_ptr) + 1;
Jörn Engela227fb32012-03-15 15:08:03 -04001207 left_val = simple_strtoul(left_val_ptr, NULL, 0);
1208 right_val = simple_strtoul(right_val_ptr, NULL, 0);
1209 recieved_value = simple_strtoul(value, NULL, 0);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001210
1211 *tilde_ptr = '~';
1212
1213 if ((recieved_value < left_val) ||
1214 (recieved_value > right_val)) {
1215 pr_err("Illegal response \"%s=%u\", value must"
1216 " be between %u and %u.\n", param->name,
1217 recieved_value, left_val, right_val);
1218 return -1;
1219 }
1220 } else if (IS_TYPE_VALUE_LIST(param)) {
1221 char *comma_ptr = NULL, *tmp_ptr = NULL;
1222
1223 comma_ptr = strchr(value, ',');
1224 if (comma_ptr) {
1225 pr_err("Illegal \",\" in response for \"%s\".\n",
1226 param->name);
1227 return -1;
1228 }
1229
1230 tmp_ptr = iscsi_check_valuelist_for_support(param, value);
1231 if (!tmp_ptr)
1232 return -1;
1233 }
1234
1235 if (iscsi_update_param_value(param, value) < 0)
1236 return -1;
1237
1238 return 0;
1239}
1240
1241static int iscsi_check_value(struct iscsi_param *param, char *value)
1242{
1243 char *comma_ptr = NULL;
1244
1245 if (!strcmp(value, REJECT)) {
1246 if (!strcmp(param->name, IFMARKINT) ||
1247 !strcmp(param->name, OFMARKINT)) {
1248 /*
1249 * Reject is not fatal for [I,O]FMarkInt, and causes
1250 * [I,O]FMarker to be reset to No. (See iSCSI v20 A.3.2)
1251 */
1252 SET_PSTATE_REJECT(param);
1253 return 0;
1254 }
1255 pr_err("Received %s=%s\n", param->name, value);
1256 return -1;
1257 }
1258 if (!strcmp(value, IRRELEVANT)) {
1259 pr_debug("Received %s=%s\n", param->name, value);
1260 SET_PSTATE_IRRELEVANT(param);
1261 return 0;
1262 }
1263 if (!strcmp(value, NOTUNDERSTOOD)) {
1264 if (!IS_PSTATE_PROPOSER(param)) {
1265 pr_err("Received illegal offer %s=%s\n",
1266 param->name, value);
1267 return -1;
1268 }
1269
1270/* #warning FIXME: Add check for X-ExtensionKey here */
1271 pr_err("Standard iSCSI key \"%s\" cannot be answered"
1272 " with \"%s\", protocol error.\n", param->name, value);
1273 return -1;
1274 }
1275
1276 do {
1277 comma_ptr = NULL;
1278 comma_ptr = strchr(value, ',');
1279
1280 if (comma_ptr && !IS_TYPE_VALUE_LIST(param)) {
1281 pr_err("Detected value seperator \",\", but"
1282 " key \"%s\" does not allow a value list,"
1283 " protocol error.\n", param->name);
1284 return -1;
1285 }
1286 if (comma_ptr)
1287 *comma_ptr = '\0';
1288
1289 if (strlen(value) > VALUE_MAXLEN) {
1290 pr_err("Value for key \"%s\" exceeds %d,"
1291 " protocol error.\n", param->name,
1292 VALUE_MAXLEN);
1293 return -1;
1294 }
1295
1296 if (IS_TYPE_BOOL_AND(param) || IS_TYPE_BOOL_OR(param)) {
1297 if (iscsi_check_boolean_value(param, value) < 0)
1298 return -1;
1299 } else if (IS_TYPE_NUMBER(param)) {
1300 if (iscsi_check_numerical_value(param, value) < 0)
1301 return -1;
1302 } else if (IS_TYPE_NUMBER_RANGE(param)) {
1303 if (iscsi_check_numerical_range_value(param, value) < 0)
1304 return -1;
1305 } else if (IS_TYPE_STRING(param) || IS_TYPE_VALUE_LIST(param)) {
1306 if (iscsi_check_string_or_list_value(param, value) < 0)
1307 return -1;
1308 } else {
1309 pr_err("Huh? 0x%02x\n", param->type);
1310 return -1;
1311 }
1312
1313 if (comma_ptr)
1314 *comma_ptr++ = ',';
1315
1316 value = comma_ptr;
1317 } while (value);
1318
1319 return 0;
1320}
1321
1322static struct iscsi_param *__iscsi_check_key(
1323 char *key,
1324 int sender,
1325 struct iscsi_param_list *param_list)
1326{
1327 struct iscsi_param *param;
1328
1329 if (strlen(key) > KEY_MAXLEN) {
1330 pr_err("Length of key name \"%s\" exceeds %d.\n",
1331 key, KEY_MAXLEN);
1332 return NULL;
1333 }
1334
1335 param = iscsi_find_param_from_key(key, param_list);
1336 if (!param)
1337 return NULL;
1338
1339 if ((sender & SENDER_INITIATOR) && !IS_SENDER_INITIATOR(param)) {
1340 pr_err("Key \"%s\" may not be sent to %s,"
1341 " protocol error.\n", param->name,
1342 (sender & SENDER_RECEIVER) ? "target" : "initiator");
1343 return NULL;
1344 }
1345
1346 if ((sender & SENDER_TARGET) && !IS_SENDER_TARGET(param)) {
1347 pr_err("Key \"%s\" may not be sent to %s,"
1348 " protocol error.\n", param->name,
1349 (sender & SENDER_RECEIVER) ? "initiator" : "target");
1350 return NULL;
1351 }
1352
1353 return param;
1354}
1355
1356static struct iscsi_param *iscsi_check_key(
1357 char *key,
1358 int phase,
1359 int sender,
1360 struct iscsi_param_list *param_list)
1361{
1362 struct iscsi_param *param;
1363 /*
1364 * Key name length must not exceed 63 bytes. (See iSCSI v20 5.1)
1365 */
1366 if (strlen(key) > KEY_MAXLEN) {
1367 pr_err("Length of key name \"%s\" exceeds %d.\n",
1368 key, KEY_MAXLEN);
1369 return NULL;
1370 }
1371
1372 param = iscsi_find_param_from_key(key, param_list);
1373 if (!param)
1374 return NULL;
1375
1376 if ((sender & SENDER_INITIATOR) && !IS_SENDER_INITIATOR(param)) {
1377 pr_err("Key \"%s\" may not be sent to %s,"
1378 " protocol error.\n", param->name,
1379 (sender & SENDER_RECEIVER) ? "target" : "initiator");
1380 return NULL;
1381 }
1382 if ((sender & SENDER_TARGET) && !IS_SENDER_TARGET(param)) {
1383 pr_err("Key \"%s\" may not be sent to %s,"
1384 " protocol error.\n", param->name,
1385 (sender & SENDER_RECEIVER) ? "initiator" : "target");
1386 return NULL;
1387 }
1388
1389 if (IS_PSTATE_ACCEPTOR(param)) {
1390 pr_err("Key \"%s\" received twice, protocol error.\n",
1391 key);
1392 return NULL;
1393 }
1394
1395 if (!phase)
1396 return param;
1397
1398 if (!(param->phase & phase)) {
1399 pr_err("Key \"%s\" may not be negotiated during ",
1400 param->name);
1401 switch (phase) {
1402 case PHASE_SECURITY:
1403 pr_debug("Security phase.\n");
1404 break;
1405 case PHASE_OPERATIONAL:
1406 pr_debug("Operational phase.\n");
1407 default:
1408 pr_debug("Unknown phase.\n");
1409 }
1410 return NULL;
1411 }
1412
1413 return param;
1414}
1415
1416static int iscsi_enforce_integrity_rules(
1417 u8 phase,
1418 struct iscsi_param_list *param_list)
1419{
1420 char *tmpptr;
1421 u8 DataSequenceInOrder = 0;
1422 u8 ErrorRecoveryLevel = 0, SessionType = 0;
1423 u8 IFMarker = 0, OFMarker = 0;
Nicholas Bellinger2ff017f2011-09-16 01:44:54 -07001424 u8 IFMarkInt_Reject = 1, OFMarkInt_Reject = 1;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001425 u32 FirstBurstLength = 0, MaxBurstLength = 0;
1426 struct iscsi_param *param = NULL;
1427
1428 list_for_each_entry(param, &param_list->param_list, p_list) {
1429 if (!(param->phase & phase))
1430 continue;
1431 if (!strcmp(param->name, SESSIONTYPE))
1432 if (!strcmp(param->value, NORMAL))
1433 SessionType = 1;
1434 if (!strcmp(param->name, ERRORRECOVERYLEVEL))
1435 ErrorRecoveryLevel = simple_strtoul(param->value,
1436 &tmpptr, 0);
1437 if (!strcmp(param->name, DATASEQUENCEINORDER))
1438 if (!strcmp(param->value, YES))
1439 DataSequenceInOrder = 1;
1440 if (!strcmp(param->name, MAXBURSTLENGTH))
1441 MaxBurstLength = simple_strtoul(param->value,
1442 &tmpptr, 0);
1443 if (!strcmp(param->name, IFMARKER))
1444 if (!strcmp(param->value, YES))
1445 IFMarker = 1;
1446 if (!strcmp(param->name, OFMARKER))
1447 if (!strcmp(param->value, YES))
1448 OFMarker = 1;
1449 if (!strcmp(param->name, IFMARKINT))
1450 if (!strcmp(param->value, REJECT))
1451 IFMarkInt_Reject = 1;
1452 if (!strcmp(param->name, OFMARKINT))
1453 if (!strcmp(param->value, REJECT))
1454 OFMarkInt_Reject = 1;
1455 }
1456
1457 list_for_each_entry(param, &param_list->param_list, p_list) {
1458 if (!(param->phase & phase))
1459 continue;
1460 if (!SessionType && (!IS_PSTATE_ACCEPTOR(param) &&
1461 (strcmp(param->name, IFMARKER) &&
1462 strcmp(param->name, OFMARKER) &&
1463 strcmp(param->name, IFMARKINT) &&
1464 strcmp(param->name, OFMARKINT))))
1465 continue;
1466 if (!strcmp(param->name, MAXOUTSTANDINGR2T) &&
1467 DataSequenceInOrder && (ErrorRecoveryLevel > 0)) {
1468 if (strcmp(param->value, "1")) {
1469 if (iscsi_update_param_value(param, "1") < 0)
1470 return -1;
1471 pr_debug("Reset \"%s\" to \"%s\".\n",
1472 param->name, param->value);
1473 }
1474 }
1475 if (!strcmp(param->name, MAXCONNECTIONS) && !SessionType) {
1476 if (strcmp(param->value, "1")) {
1477 if (iscsi_update_param_value(param, "1") < 0)
1478 return -1;
1479 pr_debug("Reset \"%s\" to \"%s\".\n",
1480 param->name, param->value);
1481 }
1482 }
1483 if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
1484 FirstBurstLength = simple_strtoul(param->value,
1485 &tmpptr, 0);
1486 if (FirstBurstLength > MaxBurstLength) {
1487 char tmpbuf[10];
1488 memset(tmpbuf, 0, 10);
1489 sprintf(tmpbuf, "%u", MaxBurstLength);
1490 if (iscsi_update_param_value(param, tmpbuf))
1491 return -1;
1492 pr_debug("Reset \"%s\" to \"%s\".\n",
1493 param->name, param->value);
1494 }
1495 }
1496 if (!strcmp(param->name, IFMARKER) && IFMarkInt_Reject) {
1497 if (iscsi_update_param_value(param, NO) < 0)
1498 return -1;
1499 IFMarker = 0;
1500 pr_debug("Reset \"%s\" to \"%s\".\n",
1501 param->name, param->value);
1502 }
1503 if (!strcmp(param->name, OFMARKER) && OFMarkInt_Reject) {
1504 if (iscsi_update_param_value(param, NO) < 0)
1505 return -1;
1506 OFMarker = 0;
1507 pr_debug("Reset \"%s\" to \"%s\".\n",
1508 param->name, param->value);
1509 }
1510 if (!strcmp(param->name, IFMARKINT) && !IFMarker) {
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 if (!strcmp(param->name, OFMARKINT) && !OFMarker) {
1520 if (!strcmp(param->value, REJECT))
1521 continue;
1522 param->state &= ~PSTATE_NEGOTIATE;
1523 if (iscsi_update_param_value(param, IRRELEVANT) < 0)
1524 return -1;
1525 pr_debug("Reset \"%s\" to \"%s\".\n",
1526 param->name, param->value);
1527 }
1528 }
1529
1530 return 0;
1531}
1532
1533int iscsi_decode_text_input(
1534 u8 phase,
1535 u8 sender,
1536 char *textbuf,
1537 u32 length,
1538 struct iscsi_param_list *param_list)
1539{
1540 char *tmpbuf, *start = NULL, *end = NULL;
1541
1542 tmpbuf = kzalloc(length + 1, GFP_KERNEL);
1543 if (!tmpbuf) {
1544 pr_err("Unable to allocate memory for tmpbuf.\n");
1545 return -1;
1546 }
1547
1548 memcpy(tmpbuf, textbuf, length);
1549 tmpbuf[length] = '\0';
1550 start = tmpbuf;
1551 end = (start + length);
1552
1553 while (start < end) {
1554 char *key, *value;
1555 struct iscsi_param *param;
1556
1557 if (iscsi_extract_key_value(start, &key, &value) < 0) {
1558 kfree(tmpbuf);
1559 return -1;
1560 }
1561
1562 pr_debug("Got key: %s=%s\n", key, value);
1563
1564 if (phase & PHASE_SECURITY) {
1565 if (iscsi_check_for_auth_key(key) > 0) {
1566 char *tmpptr = key + strlen(key);
1567 *tmpptr = '=';
1568 kfree(tmpbuf);
1569 return 1;
1570 }
1571 }
1572
1573 param = iscsi_check_key(key, phase, sender, param_list);
1574 if (!param) {
1575 if (iscsi_add_notunderstood_response(key,
1576 value, param_list) < 0) {
1577 kfree(tmpbuf);
1578 return -1;
1579 }
1580 start += strlen(key) + strlen(value) + 2;
1581 continue;
1582 }
1583 if (iscsi_check_value(param, value) < 0) {
1584 kfree(tmpbuf);
1585 return -1;
1586 }
1587
1588 start += strlen(key) + strlen(value) + 2;
1589
1590 if (IS_PSTATE_PROPOSER(param)) {
1591 if (iscsi_check_proposer_state(param, value) < 0) {
1592 kfree(tmpbuf);
1593 return -1;
1594 }
1595 SET_PSTATE_RESPONSE_GOT(param);
1596 } else {
1597 if (iscsi_check_acceptor_state(param, value) < 0) {
1598 kfree(tmpbuf);
1599 return -1;
1600 }
1601 SET_PSTATE_ACCEPTOR(param);
1602 }
1603 }
1604
1605 kfree(tmpbuf);
1606 return 0;
1607}
1608
1609int iscsi_encode_text_output(
1610 u8 phase,
1611 u8 sender,
1612 char *textbuf,
1613 u32 *length,
1614 struct iscsi_param_list *param_list)
1615{
1616 char *output_buf = NULL;
1617 struct iscsi_extra_response *er;
1618 struct iscsi_param *param;
1619
1620 output_buf = textbuf + *length;
1621
1622 if (iscsi_enforce_integrity_rules(phase, param_list) < 0)
1623 return -1;
1624
1625 list_for_each_entry(param, &param_list->param_list, p_list) {
1626 if (!(param->sender & sender))
1627 continue;
1628 if (IS_PSTATE_ACCEPTOR(param) &&
1629 !IS_PSTATE_RESPONSE_SENT(param) &&
1630 !IS_PSTATE_REPLY_OPTIONAL(param) &&
1631 (param->phase & phase)) {
1632 *length += sprintf(output_buf, "%s=%s",
1633 param->name, param->value);
1634 *length += 1;
1635 output_buf = textbuf + *length;
1636 SET_PSTATE_RESPONSE_SENT(param);
1637 pr_debug("Sending key: %s=%s\n",
1638 param->name, param->value);
1639 continue;
1640 }
1641 if (IS_PSTATE_NEGOTIATE(param) &&
1642 !IS_PSTATE_ACCEPTOR(param) &&
1643 !IS_PSTATE_PROPOSER(param) &&
1644 (param->phase & phase)) {
1645 *length += sprintf(output_buf, "%s=%s",
1646 param->name, param->value);
1647 *length += 1;
1648 output_buf = textbuf + *length;
1649 SET_PSTATE_PROPOSER(param);
1650 iscsi_check_proposer_for_optional_reply(param);
1651 pr_debug("Sending key: %s=%s\n",
1652 param->name, param->value);
1653 }
1654 }
1655
1656 list_for_each_entry(er, &param_list->extra_response_list, er_list) {
1657 *length += sprintf(output_buf, "%s=%s", er->key, er->value);
1658 *length += 1;
1659 output_buf = textbuf + *length;
1660 pr_debug("Sending key: %s=%s\n", er->key, er->value);
1661 }
1662 iscsi_release_extra_responses(param_list);
1663
1664 return 0;
1665}
1666
1667int iscsi_check_negotiated_keys(struct iscsi_param_list *param_list)
1668{
1669 int ret = 0;
1670 struct iscsi_param *param;
1671
1672 list_for_each_entry(param, &param_list->param_list, p_list) {
1673 if (IS_PSTATE_NEGOTIATE(param) &&
1674 IS_PSTATE_PROPOSER(param) &&
1675 !IS_PSTATE_RESPONSE_GOT(param) &&
1676 !IS_PSTATE_REPLY_OPTIONAL(param) &&
1677 !IS_PHASE_DECLARATIVE(param)) {
1678 pr_err("No response for proposed key \"%s\".\n",
1679 param->name);
1680 ret = -1;
1681 }
1682 }
1683
1684 return ret;
1685}
1686
1687int iscsi_change_param_value(
1688 char *keyvalue,
1689 struct iscsi_param_list *param_list,
1690 int check_key)
1691{
1692 char *key = NULL, *value = NULL;
1693 struct iscsi_param *param;
1694 int sender = 0;
1695
1696 if (iscsi_extract_key_value(keyvalue, &key, &value) < 0)
1697 return -1;
1698
1699 if (!check_key) {
1700 param = __iscsi_check_key(keyvalue, sender, param_list);
1701 if (!param)
1702 return -1;
1703 } else {
1704 param = iscsi_check_key(keyvalue, 0, sender, param_list);
1705 if (!param)
1706 return -1;
1707
1708 param->set_param = 1;
1709 if (iscsi_check_value(param, value) < 0) {
1710 param->set_param = 0;
1711 return -1;
1712 }
1713 param->set_param = 0;
1714 }
1715
1716 if (iscsi_update_param_value(param, value) < 0)
1717 return -1;
1718
1719 return 0;
1720}
1721
1722void iscsi_set_connection_parameters(
1723 struct iscsi_conn_ops *ops,
1724 struct iscsi_param_list *param_list)
1725{
1726 char *tmpptr;
1727 struct iscsi_param *param;
1728
1729 pr_debug("---------------------------------------------------"
1730 "---------------\n");
1731 list_for_each_entry(param, &param_list->param_list, p_list) {
Nicholas Bellingere004cb22012-09-29 21:47:16 -07001732 /*
1733 * Special case to set MAXXMITDATASEGMENTLENGTH from the
1734 * target requested MaxRecvDataSegmentLength, even though
1735 * this key is not sent over the wire.
1736 */
1737 if (!strcmp(param->name, MAXXMITDATASEGMENTLENGTH)) {
1738 ops->MaxXmitDataSegmentLength =
1739 simple_strtoul(param->value, &tmpptr, 0);
1740 pr_debug("MaxXmitDataSegmentLength: %s\n",
1741 param->value);
1742 }
1743
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001744 if (!IS_PSTATE_ACCEPTOR(param) && !IS_PSTATE_PROPOSER(param))
1745 continue;
1746 if (!strcmp(param->name, AUTHMETHOD)) {
1747 pr_debug("AuthMethod: %s\n",
1748 param->value);
1749 } else if (!strcmp(param->name, HEADERDIGEST)) {
1750 ops->HeaderDigest = !strcmp(param->value, CRC32C);
1751 pr_debug("HeaderDigest: %s\n",
1752 param->value);
1753 } else if (!strcmp(param->name, DATADIGEST)) {
1754 ops->DataDigest = !strcmp(param->value, CRC32C);
1755 pr_debug("DataDigest: %s\n",
1756 param->value);
1757 } else if (!strcmp(param->name, MAXRECVDATASEGMENTLENGTH)) {
1758 ops->MaxRecvDataSegmentLength =
1759 simple_strtoul(param->value, &tmpptr, 0);
1760 pr_debug("MaxRecvDataSegmentLength: %s\n",
1761 param->value);
1762 } else if (!strcmp(param->name, OFMARKER)) {
1763 ops->OFMarker = !strcmp(param->value, YES);
1764 pr_debug("OFMarker: %s\n",
1765 param->value);
1766 } else if (!strcmp(param->name, IFMARKER)) {
1767 ops->IFMarker = !strcmp(param->value, YES);
1768 pr_debug("IFMarker: %s\n",
1769 param->value);
1770 } else if (!strcmp(param->name, OFMARKINT)) {
1771 ops->OFMarkInt =
1772 simple_strtoul(param->value, &tmpptr, 0);
1773 pr_debug("OFMarkInt: %s\n",
1774 param->value);
1775 } else if (!strcmp(param->name, IFMARKINT)) {
1776 ops->IFMarkInt =
1777 simple_strtoul(param->value, &tmpptr, 0);
1778 pr_debug("IFMarkInt: %s\n",
1779 param->value);
1780 }
1781 }
1782 pr_debug("----------------------------------------------------"
1783 "--------------\n");
1784}
1785
1786void iscsi_set_session_parameters(
1787 struct iscsi_sess_ops *ops,
1788 struct iscsi_param_list *param_list,
1789 int leading)
1790{
1791 char *tmpptr;
1792 struct iscsi_param *param;
1793
1794 pr_debug("----------------------------------------------------"
1795 "--------------\n");
1796 list_for_each_entry(param, &param_list->param_list, p_list) {
1797 if (!IS_PSTATE_ACCEPTOR(param) && !IS_PSTATE_PROPOSER(param))
1798 continue;
1799 if (!strcmp(param->name, INITIATORNAME)) {
1800 if (!param->value)
1801 continue;
1802 if (leading)
1803 snprintf(ops->InitiatorName,
1804 sizeof(ops->InitiatorName),
1805 "%s", param->value);
1806 pr_debug("InitiatorName: %s\n",
1807 param->value);
1808 } else if (!strcmp(param->name, INITIATORALIAS)) {
1809 if (!param->value)
1810 continue;
1811 snprintf(ops->InitiatorAlias,
1812 sizeof(ops->InitiatorAlias),
1813 "%s", param->value);
1814 pr_debug("InitiatorAlias: %s\n",
1815 param->value);
1816 } else if (!strcmp(param->name, TARGETNAME)) {
1817 if (!param->value)
1818 continue;
1819 if (leading)
1820 snprintf(ops->TargetName,
1821 sizeof(ops->TargetName),
1822 "%s", param->value);
1823 pr_debug("TargetName: %s\n",
1824 param->value);
1825 } else if (!strcmp(param->name, TARGETALIAS)) {
1826 if (!param->value)
1827 continue;
1828 snprintf(ops->TargetAlias, sizeof(ops->TargetAlias),
1829 "%s", param->value);
1830 pr_debug("TargetAlias: %s\n",
1831 param->value);
1832 } else if (!strcmp(param->name, TARGETPORTALGROUPTAG)) {
1833 ops->TargetPortalGroupTag =
1834 simple_strtoul(param->value, &tmpptr, 0);
1835 pr_debug("TargetPortalGroupTag: %s\n",
1836 param->value);
1837 } else if (!strcmp(param->name, MAXCONNECTIONS)) {
1838 ops->MaxConnections =
1839 simple_strtoul(param->value, &tmpptr, 0);
1840 pr_debug("MaxConnections: %s\n",
1841 param->value);
1842 } else if (!strcmp(param->name, INITIALR2T)) {
1843 ops->InitialR2T = !strcmp(param->value, YES);
1844 pr_debug("InitialR2T: %s\n",
1845 param->value);
1846 } else if (!strcmp(param->name, IMMEDIATEDATA)) {
1847 ops->ImmediateData = !strcmp(param->value, YES);
1848 pr_debug("ImmediateData: %s\n",
1849 param->value);
1850 } else if (!strcmp(param->name, MAXBURSTLENGTH)) {
1851 ops->MaxBurstLength =
1852 simple_strtoul(param->value, &tmpptr, 0);
1853 pr_debug("MaxBurstLength: %s\n",
1854 param->value);
1855 } else if (!strcmp(param->name, FIRSTBURSTLENGTH)) {
1856 ops->FirstBurstLength =
1857 simple_strtoul(param->value, &tmpptr, 0);
1858 pr_debug("FirstBurstLength: %s\n",
1859 param->value);
1860 } else if (!strcmp(param->name, DEFAULTTIME2WAIT)) {
1861 ops->DefaultTime2Wait =
1862 simple_strtoul(param->value, &tmpptr, 0);
1863 pr_debug("DefaultTime2Wait: %s\n",
1864 param->value);
1865 } else if (!strcmp(param->name, DEFAULTTIME2RETAIN)) {
1866 ops->DefaultTime2Retain =
1867 simple_strtoul(param->value, &tmpptr, 0);
1868 pr_debug("DefaultTime2Retain: %s\n",
1869 param->value);
1870 } else if (!strcmp(param->name, MAXOUTSTANDINGR2T)) {
1871 ops->MaxOutstandingR2T =
1872 simple_strtoul(param->value, &tmpptr, 0);
1873 pr_debug("MaxOutstandingR2T: %s\n",
1874 param->value);
1875 } else if (!strcmp(param->name, DATAPDUINORDER)) {
1876 ops->DataPDUInOrder = !strcmp(param->value, YES);
1877 pr_debug("DataPDUInOrder: %s\n",
1878 param->value);
1879 } else if (!strcmp(param->name, DATASEQUENCEINORDER)) {
1880 ops->DataSequenceInOrder = !strcmp(param->value, YES);
1881 pr_debug("DataSequenceInOrder: %s\n",
1882 param->value);
1883 } else if (!strcmp(param->name, ERRORRECOVERYLEVEL)) {
1884 ops->ErrorRecoveryLevel =
1885 simple_strtoul(param->value, &tmpptr, 0);
1886 pr_debug("ErrorRecoveryLevel: %s\n",
1887 param->value);
1888 } else if (!strcmp(param->name, SESSIONTYPE)) {
1889 ops->SessionType = !strcmp(param->value, DISCOVERY);
1890 pr_debug("SessionType: %s\n",
1891 param->value);
1892 }
1893 }
1894 pr_debug("----------------------------------------------------"
1895 "--------------\n");
1896
1897}