From: Wolfgang Bumiller Date: Tue, 12 May 2015 07:51:11 +0000 (+0200) Subject: add a socket family argument to next_*_port functions X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=467752183d14a62e6412156eff8ec2f3554fb38e;hp=4808fea7c0d04336d7440526ec769904b381ead1 add a socket family argument to next_*_port functions Instead of assuming a local address of 0.0.0.0, the next_*_port family of functions now takes an optional packet family argument (AF_INET/AF_INET6), used for ipv6 support. --- diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 0e1af09..0c6e532 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -660,7 +660,7 @@ sub wait_for_vnc_port { } sub next_unused_port { - my ($range_start, $range_end) = @_; + my ($range_start, $range_end, $family) = @_; # We use a file to register allocated ports. # Those registrations expires after $expiretime. @@ -693,9 +693,9 @@ sub next_unused_port { next if $ports->{$p}; # reserved my $sock = IO::Socket::IP->new(Listen => 5, - LocalAddr => '0.0.0.0', LocalPort => $p, ReuseAddr => 1, + Family => $family, Proto => 0); if ($sock) { @@ -725,15 +725,18 @@ sub next_unused_port { } sub next_migrate_port { - return next_unused_port(60000, 60050); + my ($family) = @_; + return next_unused_port(60000, 60050, $family); } sub next_vnc_port { - return next_unused_port(5900, 6000); + my ($family) = @_; + return next_unused_port(5900, 6000, $family); } sub next_spice_port { - return next_unused_port(61000, 61099); + my ($family) = @_; + return next_unused_port(61000, 61099, $family); } # NOTE: NFS syscall can't be interrupted, so alarm does