| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /******************************************************************************* |
|---|
| 2 | 3 | * Filename: target_core_fabric_lib.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 7 | 8 | * (c) Copyright 2010-2013 Datera, Inc. |
|---|
| 8 | 9 | * |
|---|
| 9 | 10 | * Nicholas A. Bellinger <nab@linux-iscsi.org> |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 12 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 13 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 14 | | - * (at your option) any later version. |
|---|
| 15 | | - * |
|---|
| 16 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 17 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | | - * GNU General Public License for more details. |
|---|
| 20 | | - * |
|---|
| 21 | | - * You should have received a copy of the GNU General Public License |
|---|
| 22 | | - * along with this program; if not, write to the Free Software |
|---|
| 23 | | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 24 | 11 | * |
|---|
| 25 | 12 | ******************************************************************************/ |
|---|
| 26 | 13 | |
|---|
| .. | .. |
|---|
| 145 | 132 | unsigned char *buf) |
|---|
| 146 | 133 | { |
|---|
| 147 | 134 | u32 off = 4, padding = 0; |
|---|
| 135 | + int isid_len; |
|---|
| 148 | 136 | u16 len = 0; |
|---|
| 149 | 137 | |
|---|
| 150 | 138 | spin_lock_irq(&se_nacl->nacl_sess_lock); |
|---|
| 151 | 139 | /* |
|---|
| 152 | | - * From spc4r17 Section 7.5.4.6: TransportID for initiator |
|---|
| 153 | | - * ports using SCSI over iSCSI. |
|---|
| 140 | + * Only null terminate the last field. |
|---|
| 154 | 141 | * |
|---|
| 155 | | - * The null-terminated, null-padded (see 4.4.2) ISCSI NAME field |
|---|
| 156 | | - * shall contain the iSCSI name of an iSCSI initiator node (see |
|---|
| 157 | | - * RFC 3720). The first ISCSI NAME field byte containing an ASCII |
|---|
| 158 | | - * null character terminates the ISCSI NAME field without regard for |
|---|
| 159 | | - * the specified length of the iSCSI TransportID or the contents of |
|---|
| 160 | | - * the ADDITIONAL LENGTH field. |
|---|
| 142 | + * From spc4r37 section 7.6.4.6: TransportID for initiator ports using |
|---|
| 143 | + * SCSI over iSCSI. |
|---|
| 144 | + * |
|---|
| 145 | + * Table 507 TPID=0 Initiator device TransportID |
|---|
| 146 | + * |
|---|
| 147 | + * The null-terminated, null-padded (see 4.3.2) ISCSI NAME field shall |
|---|
| 148 | + * contain the iSCSI name of an iSCSI initiator node (see RFC 7143). |
|---|
| 149 | + * The first ISCSI NAME field byte containing an ASCII null character |
|---|
| 150 | + * terminates the ISCSI NAME field without regard for the specified |
|---|
| 151 | + * length of the iSCSI TransportID or the contents of the ADDITIONAL |
|---|
| 152 | + * LENGTH field. |
|---|
| 161 | 153 | */ |
|---|
| 162 | 154 | len = sprintf(&buf[off], "%s", se_nacl->initiatorname); |
|---|
| 163 | | - /* |
|---|
| 164 | | - * Add Extra byte for NULL terminator |
|---|
| 165 | | - */ |
|---|
| 166 | | - len++; |
|---|
| 167 | | - /* |
|---|
| 168 | | - * If there is ISID present with the registration and *format code == 1 |
|---|
| 169 | | - * 1, use iSCSI Initiator port TransportID format. |
|---|
| 170 | | - * |
|---|
| 171 | | - * Otherwise use iSCSI Initiator device TransportID format that |
|---|
| 172 | | - * does not contain the ASCII encoded iSCSI Initiator iSID value |
|---|
| 173 | | - * provied by the iSCSi Initiator during the iSCSI login process. |
|---|
| 174 | | - */ |
|---|
| 155 | + off += len; |
|---|
| 175 | 156 | if ((*format_code == 1) && (pr_reg->isid_present_at_reg)) { |
|---|
| 176 | 157 | /* |
|---|
| 177 | 158 | * Set FORMAT CODE 01b for iSCSI Initiator port TransportID |
|---|
| .. | .. |
|---|
| 179 | 160 | */ |
|---|
| 180 | 161 | buf[0] |= 0x40; |
|---|
| 181 | 162 | /* |
|---|
| 182 | | - * From spc4r17 Section 7.5.4.6: TransportID for initiator |
|---|
| 183 | | - * ports using SCSI over iSCSI. Table 390 |
|---|
| 163 | + * From spc4r37 Section 7.6.4.6 |
|---|
| 164 | + * |
|---|
| 165 | + * Table 508 TPID=1 Initiator port TransportID. |
|---|
| 166 | + * |
|---|
| 167 | + * The ISCSI NAME field shall not be null-terminated |
|---|
| 168 | + * (see 4.3.2) and shall not be padded. |
|---|
| 184 | 169 | * |
|---|
| 185 | 170 | * The SEPARATOR field shall contain the five ASCII |
|---|
| 186 | 171 | * characters ",i,0x". |
|---|
| .. | .. |
|---|
| 190 | 175 | * (see RFC 3720) in the form of ASCII characters that are the |
|---|
| 191 | 176 | * hexadecimal digits converted from the binary iSCSI initiator |
|---|
| 192 | 177 | * session identifier value. The first ISCSI INITIATOR SESSION |
|---|
| 193 | | - * ID field byte containing an ASCII null character |
|---|
| 178 | + * ID field byte containing an ASCII null character terminates |
|---|
| 179 | + * the ISCSI INITIATOR SESSION ID field without regard for the |
|---|
| 180 | + * specified length of the iSCSI TransportID or the contents |
|---|
| 181 | + * of the ADDITIONAL LENGTH field. |
|---|
| 194 | 182 | */ |
|---|
| 195 | | - buf[off+len] = 0x2c; off++; /* ASCII Character: "," */ |
|---|
| 196 | | - buf[off+len] = 0x69; off++; /* ASCII Character: "i" */ |
|---|
| 197 | | - buf[off+len] = 0x2c; off++; /* ASCII Character: "," */ |
|---|
| 198 | | - buf[off+len] = 0x30; off++; /* ASCII Character: "0" */ |
|---|
| 199 | | - buf[off+len] = 0x78; off++; /* ASCII Character: "x" */ |
|---|
| 183 | + buf[off++] = 0x2c; /* ASCII Character: "," */ |
|---|
| 184 | + buf[off++] = 0x69; /* ASCII Character: "i" */ |
|---|
| 185 | + buf[off++] = 0x2c; /* ASCII Character: "," */ |
|---|
| 186 | + buf[off++] = 0x30; /* ASCII Character: "0" */ |
|---|
| 187 | + buf[off++] = 0x78; /* ASCII Character: "x" */ |
|---|
| 200 | 188 | len += 5; |
|---|
| 201 | | - buf[off+len] = pr_reg->pr_reg_isid[0]; off++; |
|---|
| 202 | | - buf[off+len] = pr_reg->pr_reg_isid[1]; off++; |
|---|
| 203 | | - buf[off+len] = pr_reg->pr_reg_isid[2]; off++; |
|---|
| 204 | | - buf[off+len] = pr_reg->pr_reg_isid[3]; off++; |
|---|
| 205 | | - buf[off+len] = pr_reg->pr_reg_isid[4]; off++; |
|---|
| 206 | | - buf[off+len] = pr_reg->pr_reg_isid[5]; off++; |
|---|
| 207 | | - buf[off+len] = '\0'; off++; |
|---|
| 208 | | - len += 7; |
|---|
| 189 | + |
|---|
| 190 | + isid_len = sprintf(buf + off, "%s", pr_reg->pr_reg_isid); |
|---|
| 191 | + off += isid_len; |
|---|
| 192 | + len += isid_len; |
|---|
| 209 | 193 | } |
|---|
| 194 | + buf[off] = '\0'; |
|---|
| 195 | + len += 1; |
|---|
| 210 | 196 | spin_unlock_irq(&se_nacl->nacl_sess_lock); |
|---|
| 211 | 197 | /* |
|---|
| 212 | 198 | * The ADDITIONAL LENGTH field specifies the number of bytes that follow |
|---|
| .. | .. |
|---|
| 249 | 235 | */ |
|---|
| 250 | 236 | if (pr_reg->isid_present_at_reg) { |
|---|
| 251 | 237 | len += 5; /* For ",i,0x" ASCII separator */ |
|---|
| 252 | | - len += 7; /* For iSCSI Initiator Session ID + Null terminator */ |
|---|
| 238 | + len += strlen(pr_reg->pr_reg_isid); |
|---|
| 253 | 239 | *format_code = 1; |
|---|
| 254 | 240 | } else |
|---|
| 255 | 241 | *format_code = 0; |
|---|
| .. | .. |
|---|
| 278 | 264 | char **port_nexus_ptr) |
|---|
| 279 | 265 | { |
|---|
| 280 | 266 | char *p; |
|---|
| 281 | | - u32 tid_len, padding; |
|---|
| 282 | 267 | int i; |
|---|
| 283 | | - u16 add_len; |
|---|
| 284 | 268 | u8 format_code = (buf[0] & 0xc0); |
|---|
| 285 | 269 | /* |
|---|
| 286 | 270 | * Check for FORMAT CODE 00b or 01b from spc4r17, section 7.5.4.6: |
|---|
| .. | .. |
|---|
| 306 | 290 | */ |
|---|
| 307 | 291 | if (out_tid_len) { |
|---|
| 308 | 292 | /* The shift works thanks to integer promotion rules */ |
|---|
| 309 | | - add_len = get_unaligned_be16(&buf[2]); |
|---|
| 310 | | - |
|---|
| 311 | | - tid_len = strlen(&buf[4]); |
|---|
| 312 | | - tid_len += 4; /* Add four bytes for iSCSI Transport ID header */ |
|---|
| 313 | | - tid_len += 1; /* Add one byte for NULL terminator */ |
|---|
| 314 | | - padding = ((-tid_len) & 3); |
|---|
| 315 | | - if (padding != 0) |
|---|
| 316 | | - tid_len += padding; |
|---|
| 317 | | - |
|---|
| 318 | | - if ((add_len + 4) != tid_len) { |
|---|
| 319 | | - pr_debug("LIO-Target Extracted add_len: %hu " |
|---|
| 320 | | - "does not match calculated tid_len: %u," |
|---|
| 321 | | - " using tid_len instead\n", add_len+4, tid_len); |
|---|
| 322 | | - *out_tid_len = tid_len; |
|---|
| 323 | | - } else |
|---|
| 324 | | - *out_tid_len = (add_len + 4); |
|---|
| 293 | + *out_tid_len = get_unaligned_be16(&buf[2]); |
|---|
| 294 | + /* Add four bytes for iSCSI Transport ID header */ |
|---|
| 295 | + *out_tid_len += 4; |
|---|
| 325 | 296 | } |
|---|
| 297 | + |
|---|
| 326 | 298 | /* |
|---|
| 327 | 299 | * Check for ',i,0x' separator between iSCSI Name and iSCSI Initiator |
|---|
| 328 | 300 | * Session ID as defined in Table 390 - iSCSI initiator port TransportID |
|---|
| .. | .. |
|---|
| 347 | 319 | * iscsi_target.c:lio_sess_get_initiator_sid() |
|---|
| 348 | 320 | */ |
|---|
| 349 | 321 | for (i = 0; i < 12; i++) { |
|---|
| 322 | + /* |
|---|
| 323 | + * The first ISCSI INITIATOR SESSION ID field byte |
|---|
| 324 | + * containing an ASCII null character terminates the |
|---|
| 325 | + * ISCSI INITIATOR SESSION ID field without regard for |
|---|
| 326 | + * the specified length of the iSCSI TransportID or the |
|---|
| 327 | + * contents of the ADDITIONAL LENGTH field. |
|---|
| 328 | + */ |
|---|
| 329 | + if (*p == '\0') |
|---|
| 330 | + break; |
|---|
| 331 | + |
|---|
| 350 | 332 | if (isdigit(*p)) { |
|---|
| 351 | 333 | p++; |
|---|
| 352 | 334 | continue; |
|---|
| .. | .. |
|---|
| 354 | 336 | *p = tolower(*p); |
|---|
| 355 | 337 | p++; |
|---|
| 356 | 338 | } |
|---|
| 357 | | - } |
|---|
| 339 | + } else |
|---|
| 340 | + *port_nexus_ptr = NULL; |
|---|
| 358 | 341 | |
|---|
| 359 | 342 | return &buf[4]; |
|---|
| 360 | 343 | } |
|---|