]> git.proxmox.com Git - pve-common.git/commitdiff
net: ip from CIDR: sort result
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 25 Feb 2021 12:07:56 +0000 (13:07 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 25 Feb 2021 12:47:56 +0000 (13:47 +0100)
this should not be a real problem yet, but the perl keys hash pseudo
random order was an issue way to often to bet on that..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/Network.pm

index 3b1afdd1dfa8c4912e82265e36409b3c032944be..38019f7e3aedff5db8a52821947ad639f74db291 100644 (file)
@@ -600,13 +600,14 @@ sub get_local_ip_from_cidr {
     my ($cidr) = @_;
 
     my $IPs = {};
+    my $i = 1;
     run_command(['/sbin/ip', 'address', 'show', 'to', $cidr, 'up'], outfunc => sub {
        if ($_[0] =~ m!^\s*inet(?:6)?\s+($PVE::Tools::IPRE)(?:/\d+|\s+peer\s+)!) {
-           $IPs->{$1} = 1;
+           $IPs->{$1} = $i++ if !exists($IPs->{$1});
        }
     });
 
-    return [ keys %{$IPs} ];
+    return [ sort { $IPs->{$a} <=> $IPs->{$b} } keys %{$IPs} ];
 }
 
 sub addr_to_ip {