]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storage: Fix parsing of IPv6 portal address for iSCSI
authorPeter Krempa <pkrempa@redhat.com>
Tue, 7 Nov 2017 15:20:23 +0000 (16:20 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 8 Nov 2017 12:10:40 +0000 (13:10 +0100)
Split on the last colon and avoid parsing port if the split remainder
contains the closing square bracket, so that IPv6 addresses are
interpreted correctly.

src/util/virstoragefile.c
tests/virstoragetest.c

index 9cee6431210c9c650f482ff8219159759689b735..45a6dea8a0268c277a2514adde0d8c2b7ba54dc9 100644 (file)
@@ -3016,7 +3016,8 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
     if (VIR_STRDUP(src->hosts->name, portal) < 0)
         goto cleanup;
 
-    if ((port = strchr(src->hosts->name, ':'))) {
+    if ((port = strrchr(src->hosts->name, ':')) &&
+        !strchr(port, ']')) {
         if (virStringParsePort(port + 1, &src->hosts->port) < 0)
             goto cleanup;
 
index 8a5ff078cf41ee10d645ec7baa0d2bdc5f04d551..806c5465ce43c245e54d00bf9bfeaeac105b064c 100644 (file)
@@ -1578,6 +1578,26 @@ mymain(void)
                        "<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n"
                        "  <host name='test.org' port='1234'/>\n"
                        "</source>\n");
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"iscsi\","
+                                       "\"transport\":\"tcp\","
+                                       "\"portal\":\"[2001::0]:1234\","
+                                       "\"target\":\"iqn.2016-12.com.virttest:emulated-iscsi-noauth.target\","
+                                       "\"lun\":6"
+                                      "}"
+                            "}",
+                       "<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n"
+                       "  <host name='[2001::0]' port='1234'/>\n"
+                       "</source>\n");
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"iscsi\","
+                                       "\"transport\":\"tcp\","
+                                       "\"portal\":\"[2001::0]\","
+                                       "\"target\":\"iqn.2016-12.com.virttest:emulated-iscsi-noauth.target\","
+                                       "\"lun\":6"
+                                      "}"
+                            "}",
+                       "<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n"
+                       "  <host name='[2001::0]' port='3260'/>\n"
+                       "</source>\n");
     TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"sheepdog\","
                                        "\"vdi\":\"test\","
                                        "\"server\":{ \"type\":\"inet\","