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