]> git.proxmox.com Git - pve-common.git/commitdiff
daemon: explicitly bind to wildcard address.
authorStoiko Ivanov <s.ivanov@proxmox.com>
Wed, 5 May 2021 14:36:23 +0000 (16:36 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 7 May 2021 14:19:09 +0000 (16:19 +0200)
with the recent change in pve-manager pveproxy (and spiceproxy)
try binding to '::' per default. This fails for hosts having disabled
ipv6 via kernel commandline.

Our desired behavior of binding on '::' and only falling back to
'0.0.0.0' in case this is not supported is not directly possible with
IO::Socket::IP->new (or rather by Socket::GetAddrInfo, which at least
on my system always returns the v4 wildcard-address first).

the code now binds to:
* the provided $host if not undef
* '::' if $host is not set
* '0.0.0.0' if $host is not set and binding on '::' yields undef,
  which means that it failed to create a socket which normally means
  that IPv6 is disabled

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/Daemon.pm

index 79b90adb65dcf0a5d64293811d1705c3d4bd9a8b..2ab4f35bc94a8a291d12884048d51fbb79161711 100644 (file)
@@ -819,14 +819,23 @@ sub create_reusable_socket {
        $socket->fcntl(Fcntl::F_SETFD(), Fcntl::FD_CLOEXEC);
     } else {
 
-       $socket = IO::Socket::IP->new(
-           LocalHost => $host,
+       my %sockargs = (
            LocalPort => $port,
            Listen => SOMAXCONN,
            Proto  => 'tcp',
            GetAddrInfoFlags => 0,
-           ReuseAddr => 1) ||
-           die "unable to create socket - $@\n";
+           ReuseAddr => 1,
+       );
+       if (defined($host)) {
+           $socket = IO::Socket::IP->new( LocalHost => $host, %sockargs) ||
+               die "unable to create socket - $@\n";
+       } else {
+           # disabling AF_INET6 (by adding ipv6.disable=1 to the kernel cmdline)
+           # causes bind on :: to fail, try 0.0.0.0 in that case
+           $socket = IO::Socket::IP->new( LocalHost => '::', %sockargs) //
+               IO::Socket::IP->new( LocalHost => '0.0.0.0', %sockargs);
+           die "unable to create socket - $@\n" if !$socket;
+       }
 
        # we often observe delays when using Nagle algorithm,
        # so we disable that to maximize performance