diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 76df0aa..2a48826 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2274,17 +2274,27 @@ qemuBuildChrChardevStr(virDomainChrSourceDefPtr dev, const char *alias, virBufferAsprintf(&buf, "stdio,id=char%s", alias); break; - case VIR_DOMAIN_CHR_TYPE_UDP: + case VIR_DOMAIN_CHR_TYPE_UDP: { + const char *connectHost = dev->data.udp.connectHost; + const char *bindHost = dev->data.udp.bindHost; + const char *bindService = dev->data.udp.bindService; + + if (connectHost == NULL) + connectHost = ""; + if (bindHost == NULL) + bindHost = ""; + if (bindService == NULL) + bindService = "0"; + virBufferAsprintf(&buf, "udp,id=char%s,host=%s,port=%s,localaddr=%s," "localport=%s", alias, - dev->data.udp.connectHost, + connectHost, dev->data.udp.connectService, - dev->data.udp.bindHost, - dev->data.udp.bindService); + bindHost, bindService); break; - + } case VIR_DOMAIN_CHR_TYPE_TCP: telnet = dev->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET; virBufferAsprintf(&buf, @@ -2371,14 +2381,25 @@ qemuBuildChrArgStr(virDomainChrSourceDefPtr dev, const char *prefix) virBufferAddLit(&buf, "stdio"); break; - case VIR_DOMAIN_CHR_TYPE_UDP: + case VIR_DOMAIN_CHR_TYPE_UDP: { + const char *connectHost = dev->data.udp.connectHost; + const char *bindHost = dev->data.udp.bindHost; + const char *bindService = dev->data.udp.bindService; + + if (connectHost == NULL) + connectHost = ""; + if (bindHost == NULL) + bindHost = ""; + if (bindService == NULL) + bindService = "0"; + virBufferAsprintf(&buf, "udp:%s:%s@%s:%s", - dev->data.udp.connectHost, + connectHost, dev->data.udp.connectService, - dev->data.udp.bindHost, - dev->data.udp.bindService); + bindHost, + bindService); break; - + } case VIR_DOMAIN_CHR_TYPE_TCP: if (dev->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET) { virBufferAsprintf(&buf, "telnet:%s:%s%s", @@ -5649,13 +5670,12 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, host2 = svc1 ? strchr(svc1, '@') : NULL; svc2 = host2 ? strchr(host2, ':') : NULL; - if (svc1) + if (svc1 && (svc1 != val)) { source->data.udp.connectHost = strndup(val, svc1-val); - else - source->data.udp.connectHost = strdup(val); - if (!source->data.udp.connectHost) - goto no_memory; + if (!source->data.udp.connectHost) + goto no_memory; + } if (svc1) { svc1++; @@ -5670,19 +5690,21 @@ qemuParseCommandLineChr(virDomainChrSourceDefPtr source, if (host2) { host2++; - if (svc2) + if (svc2 && (svc2 != host2)) { source->data.udp.bindHost = strndup(host2, svc2-host2); - else - source->data.udp.bindHost = strdup(host2); - if (!source->data.udp.bindHost) - goto no_memory; + if (!source->data.udp.bindHost) + goto no_memory; + } } + if (svc2) { svc2++; - source->data.udp.bindService = strdup(svc2); - if (!source->data.udp.bindService) - goto no_memory; + if (STRNEQ(svc2, "0")) { + source->data.udp.bindService = strdup(svc2); + if (!source->data.udp.bindService) + goto no_memory; + } } } else if (STRPREFIX(val, "tcp:") || STRPREFIX(val, "telnet:")) { diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-udp-chardev.args b/tests/qemuxml2argvdata/qemuxml2argv-serial-udp-chardev.args index 362d860..7d1cb67 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-serial-udp-chardev.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-serial-udp-chardev.args @@ -3,5 +3,7 @@ pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev socket,\ id=charmonitor,path=/tmp/test-monitor,server,nowait -mon chardev=charmonitor,\ id=monitor,mode=readline -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -chardev \ udp,id=charserial0,host=127.0.0.1,port=9998,localaddr=127.0.0.1,localport=9999 \ --device isa-serial,chardev=charserial0,id=serial0 -usb -device \ +-device isa-serial,chardev=charserial0,id=serial0 \ +-chardev udp,id=charserial1,host=,port=9999,localaddr=,localport=0 \ +-device isa-serial,chardev=charserial1,id=serial1 -usb -device \ virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-udp-chardev.xml b/tests/qemuxml2argvdata/qemuxml2argv-serial-udp-chardev.xml index 12622d4..9627c67 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-serial-udp-chardev.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-serial-udp-chardev.xml @@ -25,6 +25,10 @@ + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-udp.args b/tests/qemuxml2argvdata/qemuxml2argv-serial-udp.args index 53c69bc..b612e4b 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-serial-udp.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-serial-udp.args @@ -1,4 +1,4 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial \ -udp:127.0.0.1:9998@127.0.0.1:9999 -parallel none -usb +udp:127.0.0.1:9998@127.0.0.1:9999 -serial udp::9999@:0 -parallel none -usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-udp.xml b/tests/qemuxml2argvdata/qemuxml2argv-serial-udp.xml index 8697f5a..f606ea4 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-serial-udp.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-serial-udp.xml @@ -25,6 +25,10 @@ + + + +