From 2f8be3bfda203065b22e60862e5f98d831a46921 Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Wed, 5 May 2021 16:36:23 +0200 Subject: [PATCH] daemon: explicitly bind to wildcard address. 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 Signed-off-by: Thomas Lamprecht --- src/PVE/Daemon.pm | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/PVE/Daemon.pm b/src/PVE/Daemon.pm index 79b90ad..2ab4f35 100644 --- a/src/PVE/Daemon.pm +++ b/src/PVE/Daemon.pm @@ -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 -- 2.39.5