]> git.proxmox.com Git - qemu-server.git/commitdiff
fix #1229: more explicit spice port allocation
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 30 May 2017 13:30:14 +0000 (15:30 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 31 May 2017 06:07:34 +0000 (08:07 +0200)
We cannot look for ports on "any" wildcard address while
letting qemu bind to "localhost", this may lead to a qemu
process occupying ::1 while the next search successfully
finds the same port available for IPv4's '*' address.

Instead, we now lookup the IP of the desired family for
'localhost'. Note that while we could simply be hardcoding
::1 or 127.0.0.1, with this code we are protocol agnostic.

PVE/QemuServer.pm

index 6ce5910f2a4e6b556c214149a6b1e5ba7ef20681..a01c0ba82a7df97a86f9ffebc6738f49d1f6eaf7 100644 (file)
@@ -3157,9 +3157,12 @@ sub config_to_command {
 
        my $nodename = PVE::INotify::nodename();
        my $pfamily = PVE::Tools::get_host_address_family($nodename);
 
        my $nodename = PVE::INotify::nodename();
        my $pfamily = PVE::Tools::get_host_address_family($nodename);
-       $spice_port = PVE::Tools::next_spice_port($pfamily);
+       my @nodeaddrs = PVE::Tools::getaddrinfo_all('localhost', family => $pfamily);
+       die "failed to get an ip address of type $pfamily for 'localhost'\n" if !@nodeaddrs;
+       my $localhost = PVE::Network::addr_to_ip($nodeaddrs[0]->{addr});
+       $spice_port = PVE::Tools::next_spice_port($pfamily, $localhost);
 
 
-       push @$devices, '-spice', "tls-port=${spice_port},addr=localhost,tls-ciphers=HIGH,seamless-migration=on";
+       push @$devices, '-spice', "tls-port=${spice_port},addr=$localhost,tls-ciphers=HIGH,seamless-migration=on";
 
        push @$devices, '-device', "virtio-serial,id=spice$pciaddr";
        push @$devices, '-chardev', "spicevmc,id=vdagent,name=vdagent";
 
        push @$devices, '-device', "virtio-serial,id=spice$pciaddr";
        push @$devices, '-chardev', "spicevmc,id=vdagent,name=vdagent";