Since introduction of chardev hotplug the code was wrong for the UDP
case and basically created a TCP socket instead. Use proper objects and
type for UDP.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1377602
---
 src/qemu/qemu_monitor_json.c | 12 ++++++++++--
 tests/qemumonitorjsontest.c  | 20 ++++++++++++++++----
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 126927e..c720376 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6212,12 +6212,20 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
         break;

     case VIR_DOMAIN_CHR_TYPE_UDP:
-        backend_type = "socket";
+        backend_type = "udp";
         addr = qemuMonitorJSONBuildInetSocketAddress(chr->data.udp.connectHost,
                                                      
chr->data.udp.connectService);
         if (!addr ||
-            virJSONValueObjectAppend(data, "addr", addr) < 0)
+            virJSONValueObjectAppend(data, "remote", addr) < 0)
             goto error;
+
+        if (chr->data.udp.bindHost) {
+            addr = 
qemuMonitorJSONBuildInetSocketAddress(chr->data.udp.bindHost,
+                                                         
chr->data.udp.bindService);
+            if (!addr ||
+                virJSONValueObjectAppend(data, "local", addr) < 0)
+                goto error;
+        }
         addr = NULL;
         break;

diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 61344b7..0574f8c 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -853,10 +853,22 @@ qemuMonitorJSONTestAttachChardev(virDomainXMLOptionPtr 
xmlopt)
     chr.data.udp.connectService = (char *) "1234";
     CHECK("udp", false,
           "{'id':'alias',"
-           "'backend':{'type':'socket',"
-                      "'data':{'addr':{'type':'inet',"
-                                      "'data':{'host':'example.com',"
-                                              "'port':'1234'}}}}}");
+           "'backend':{'type':'udp',"
+                      "'data':{'remote':{'type':'inet',"
+                                        "'data':{'host':'example.com',"
+                                                "'port':'1234'}}}}}");
+
+    chr.data.udp.bindHost = (char *) "localhost";
+    chr.data.udp.bindService = (char *) "4321";
+    CHECK("udp", false,
+          "{'id':'alias',"
+           "'backend':{'type':'udp',"
+                      "'data':{'remote':{'type':'inet',"
+                                        "'data':{'host':'example.com',"
+                                                "'port':'1234'}},"
+                              "'local':{'type':'inet',"
+                                       "'data':{'host':'localhost',"
+                                               "'port':'4321'}}}}}");

     memset(&chr, 0, sizeof(chr));
     chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
-- 
2.10.0

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

Reply via email to