[PATCH] target/iscsi: Fix sendtargets_response() for ipv6, again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Revert commit 1997e6259, which just papers over the issue and causes
double brackets on ipv6 inaddr_any address.

Now, both addresses via conn->local_ip and np->np_ip for ipv6 are kept
in bracketed format.

Change lio_target_call_addnptotpg() to pass bracketed ipv6 address to
iscsit_tpg_add_network_portal. Alas, we need to rebuild the bracketed
string at the end because we need unbracketed for in6_pton().

Fix and extend some comments earlier in the function.

Tested to work for :: and ::1 via iscsiadm, previously :: failed, see
https://bugzilla.redhat.com/show_bug.cgi?id=1249107 .

Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Andy Grover <agrover@xxxxxxxxxx>
---
 drivers/target/iscsi/iscsi_target.c          |  9 ++-------
 drivers/target/iscsi/iscsi_target_configfs.c | 13 +++++++++++--
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index cd77a06..8051a8b 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -3464,7 +3464,6 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,
 						tpg_np_list) {
 				struct iscsi_np *np = tpg_np->tpg_np;
 				bool inaddr_any = iscsit_check_inaddr_any(np);
-				char *fmt_str;
 
 				if (np->np_network_transport != network_transport)
 					continue;
@@ -3492,12 +3491,8 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,
 					}
 				}
 
-				if (np->np_sockaddr.ss_family == AF_INET6)
-					fmt_str = "TargetAddress=[%s]:%hu,%hu";
-				else
-					fmt_str = "TargetAddress=%s:%hu,%hu";
-
-				len = sprintf(buf, fmt_str,
+				len = sprintf(buf, "TargetAddress="
+					"%s:%hu,%hu",
 					inaddr_any ? conn->local_ip : np->np_ip,
 					np->np_port,
 					tpg->tpgt);
diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c
index c1898c8..cca9ff4 100644
--- a/drivers/target/iscsi/iscsi_target_configfs.c
+++ b/drivers/target/iscsi/iscsi_target_configfs.c
@@ -248,8 +248,8 @@ static struct se_tpg_np *lio_target_call_addnptotpg(
 			return ERR_PTR(-EINVAL);
 		}
 		str++; /* Skip over leading "[" */
-		*str2 = '\0'; /* Terminate the IPv6 address */
-		str2++; /* Skip over the "]" */
+		*str2 = '\0'; /* Terminate the unbracketed IPv6 address */
+		str2++; /* Skip over the \0 */
 		port_str = strstr(str2, ":");
 		if (!port_str) {
 			pr_err("Unable to locate \":port\""
@@ -273,6 +273,15 @@ static struct se_tpg_np *lio_target_call_addnptotpg(
 			pr_err("in6_pton returned: %d\n", ret);
 			return ERR_PTR(-EINVAL);
 		}
+		/*
+		 * Restore str to with-brackets format, which is what
+		 * iscsi uses in sendtargets and what we should pass to
+		 * iscsit_tpg_add_network_portal().
+		 */
+		str--;
+		*str2 = '\0';
+		str2--;
+		*str2 = ']';
 	} else {
 		str = ip_str = &buf[0];
 		port_str = strstr(ip_str, ":");
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux