add a socket family argument to next_*_port functions
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 12 May 2015 07:51:11 +0000 (09:51 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 12 May 2015 08:35:31 +0000 (10:35 +0200)
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.

src/PVE/Tools.pm

index 0e1af09..0c6e532 100644 (file)
@@ -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