net: ip from CIDR: sort result

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>
This commit is contained in:
Thomas Lamprecht 2021-02-25 13:07:56 +01:00
parent 1e55a6cd22
commit ef737f0b3c

View 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 {