[libvirt] [PATCH] util: storage: Fix parsing of IPv6 portal address for iSCSI

Peter Krempa posted 1 patch 6 years, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/8b833ac17a6437f962e2ec288ab6f587fd10b115.1510068411.git.pkrempa@redhat.com
src/util/virstoragefile.c |  3 ++-
tests/virstoragetest.c    | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
[libvirt] [PATCH] util: storage: Fix parsing of IPv6 portal address for iSCSI
Posted by Peter Krempa 6 years, 5 months ago
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 |  3 ++-
 tests/virstoragetest.c    | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 3a2d2aa05..e7fcb1238 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -3008,7 +3008,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;

diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index cfcd8a79c..52a685d91 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -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\","
-- 
2.14.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: storage: Fix parsing of IPv6 portal address for iSCSI
Posted by Jiri Denemark 6 years, 5 months ago
On Tue, Nov 07, 2017 at 16:26:51 +0100, Peter Krempa wrote:
> 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 |  3 ++-
>  tests/virstoragetest.c    | 20 ++++++++++++++++++++
>  2 files changed, 22 insertions(+), 1 deletion(-)

ACK

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list