Merge branch 'parisc-5.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git/deller...
[linux-2.6-microblaze.git] / drivers / target / target_core_fabric_lib.c
index 1e031d8..6600ae4 100644 (file)
@@ -132,33 +132,27 @@ static int iscsi_get_pr_transport_id(
        unsigned char *buf)
 {
        u32 off = 4, padding = 0;
+       int isid_len;
        u16 len = 0;
 
        spin_lock_irq(&se_nacl->nacl_sess_lock);
        /*
-        * From spc4r17 Section 7.5.4.6: TransportID for initiator
-        * ports using SCSI over iSCSI.
+        * Only null terminate the last field.
         *
-        * The null-terminated, null-padded (see 4.4.2) ISCSI NAME field
-        * shall contain the iSCSI name of an iSCSI initiator node (see
-        * RFC 3720). The first ISCSI NAME field byte containing an ASCII
-        * null character terminates the ISCSI NAME field without regard for
-        * the specified length of the iSCSI TransportID or the contents of
-        * the ADDITIONAL LENGTH field.
-        */
-       len = sprintf(&buf[off], "%s", se_nacl->initiatorname);
-       /*
-        * Add Extra byte for NULL terminator
-        */
-       len++;
-       /*
-        * If there is ISID present with the registration and *format code == 1
-        * 1, use iSCSI Initiator port TransportID format.
+        * From spc4r37 section 7.6.4.6: TransportID for initiator ports using
+        * SCSI over iSCSI.
+        *
+        * Table 507 TPID=0 Initiator device TransportID
         *
-        * Otherwise use iSCSI Initiator device TransportID format that
-        * does not contain the ASCII encoded iSCSI Initiator iSID value
-        * provied by the iSCSi Initiator during the iSCSI login process.
+        * The null-terminated, null-padded (see 4.3.2) ISCSI NAME field shall
+        * contain the iSCSI name of an iSCSI initiator node (see RFC 7143).
+        * The first ISCSI NAME field byte containing an ASCII null character
+        * terminates the ISCSI NAME field without regard for the specified
+        * length of the iSCSI TransportID or the contents of the ADDITIONAL
+        * LENGTH field.
         */
+       len = sprintf(&buf[off], "%s", se_nacl->initiatorname);
+       off += len;
        if ((*format_code == 1) && (pr_reg->isid_present_at_reg)) {
                /*
                 * Set FORMAT CODE 01b for iSCSI Initiator port TransportID
@@ -166,8 +160,12 @@ static int iscsi_get_pr_transport_id(
                 */
                buf[0] |= 0x40;
                /*
-                * From spc4r17 Section 7.5.4.6: TransportID for initiator
-                * ports using SCSI over iSCSI.  Table 390
+                * From spc4r37 Section 7.6.4.6
+                *
+                * Table 508 TPID=1 Initiator port TransportID.
+                *
+                * The ISCSI NAME field shall not be null-terminated
+                * (see 4.3.2) and shall not be padded.
                 *
                 * The SEPARATOR field shall contain the five ASCII
                 * characters ",i,0x".
@@ -177,23 +175,24 @@ static int iscsi_get_pr_transport_id(
                 * (see RFC 3720) in the form of ASCII characters that are the
                 * hexadecimal digits converted from the binary iSCSI initiator
                 * session identifier value. The first ISCSI INITIATOR SESSION
-                * ID field byte containing an ASCII null character
+                * ID field byte containing an ASCII null character terminates
+                * the ISCSI INITIATOR SESSION ID field without regard for the
+                * specified length of the iSCSI TransportID or the contents
+                * of the ADDITIONAL LENGTH field.
                 */
-               buf[off+len] = 0x2c; off++; /* ASCII Character: "," */
-               buf[off+len] = 0x69; off++; /* ASCII Character: "i" */
-               buf[off+len] = 0x2c; off++; /* ASCII Character: "," */
-               buf[off+len] = 0x30; off++; /* ASCII Character: "0" */
-               buf[off+len] = 0x78; off++; /* ASCII Character: "x" */
+               buf[off++] = 0x2c; /* ASCII Character: "," */
+               buf[off++] = 0x69; /* ASCII Character: "i" */
+               buf[off++] = 0x2c; /* ASCII Character: "," */
+               buf[off++] = 0x30; /* ASCII Character: "0" */
+               buf[off++] = 0x78; /* ASCII Character: "x" */
                len += 5;
-               buf[off+len] = pr_reg->pr_reg_isid[0]; off++;
-               buf[off+len] = pr_reg->pr_reg_isid[1]; off++;
-               buf[off+len] = pr_reg->pr_reg_isid[2]; off++;
-               buf[off+len] = pr_reg->pr_reg_isid[3]; off++;
-               buf[off+len] = pr_reg->pr_reg_isid[4]; off++;
-               buf[off+len] = pr_reg->pr_reg_isid[5]; off++;
-               buf[off+len] = '\0'; off++;
-               len += 7;
+
+               isid_len = sprintf(buf + off, "%s", pr_reg->pr_reg_isid);
+               off += isid_len;
+               len += isid_len;
        }
+       buf[off] = '\0';
+       len += 1;
        spin_unlock_irq(&se_nacl->nacl_sess_lock);
        /*
         * The ADDITIONAL LENGTH field specifies the number of bytes that follow
@@ -236,7 +235,7 @@ static int iscsi_get_pr_transport_id_len(
         */
        if (pr_reg->isid_present_at_reg) {
                len += 5; /* For ",i,0x" ASCII separator */
-               len += 7; /* For iSCSI Initiator Session ID + Null terminator */
+               len += strlen(pr_reg->pr_reg_isid);
                *format_code = 1;
        } else
                *format_code = 0;
@@ -265,9 +264,7 @@ static char *iscsi_parse_pr_out_transport_id(
        char **port_nexus_ptr)
 {
        char *p;
-       u32 tid_len, padding;
        int i;
-       u16 add_len;
        u8 format_code = (buf[0] & 0xc0);
        /*
         * Check for FORMAT CODE 00b or 01b from spc4r17, section 7.5.4.6:
@@ -293,23 +290,11 @@ static char *iscsi_parse_pr_out_transport_id(
         */
        if (out_tid_len) {
                /* The shift works thanks to integer promotion rules */
-               add_len = get_unaligned_be16(&buf[2]);
-
-               tid_len = strlen(&buf[4]);
-               tid_len += 4; /* Add four bytes for iSCSI Transport ID header */
-               tid_len += 1; /* Add one byte for NULL terminator */
-               padding = ((-tid_len) & 3);
-               if (padding != 0)
-                       tid_len += padding;
-
-               if ((add_len + 4) != tid_len) {
-                       pr_debug("LIO-Target Extracted add_len: %hu "
-                               "does not match calculated tid_len: %u,"
-                               " using tid_len instead\n", add_len+4, tid_len);
-                       *out_tid_len = tid_len;
-               } else
-                       *out_tid_len = (add_len + 4);
+               *out_tid_len = get_unaligned_be16(&buf[2]);
+               /* Add four bytes for iSCSI Transport ID header */
+               *out_tid_len += 4;
        }
+
        /*
         * Check for ',i,0x' separator between iSCSI Name and iSCSI Initiator
         * Session ID as defined in Table 390 - iSCSI initiator port TransportID
@@ -334,6 +319,16 @@ static char *iscsi_parse_pr_out_transport_id(
                 * iscsi_target.c:lio_sess_get_initiator_sid()
                 */
                for (i = 0; i < 12; i++) {
+                       /*
+                        * The first ISCSI INITIATOR SESSION ID field byte
+                        * containing an ASCII null character terminates the
+                        * ISCSI INITIATOR SESSION ID field without regard for
+                        * the specified length of the iSCSI TransportID or the
+                        * contents of the ADDITIONAL LENGTH field.
+                        */
+                       if (*p == '\0')
+                               break;
+
                        if (isdigit(*p)) {
                                p++;
                                continue;