efficiency gains in set_canonical_ip

This commit is contained in:
Oliver Gorwits
2017-05-14 20:50:03 +01:00
parent 3816aad829
commit 824ec751e2

View File

@@ -58,18 +58,20 @@ sub set_canonical_ip {
$new_ip = $revofname; $new_ip = $revofname;
} }
if (ref {} eq ref setting('device_identity')) { if (ref {} eq ref setting('device_identity')
my $idmap = setting('device_identity') || {}; and scalar keys %{ setting('device_identity') }) {
my $idmap = setting('device_identity');
my $devips = $device->device_ips->order_by('alias'); my $devips = $device->device_ips->order_by('alias');
ALIAS: while (my $alias = $devips->next) { ALIAS: while (my $alias = $devips->next) {
next if $alias->alias eq $old_ip;
foreach my $this (keys %$idmap) { foreach my $this (keys %$idmap) {
$anded_this = [(ref $this ? @$this : $this), 'op:and']; $anded_this = [(ref $this ? @$this : $this), 'op:and'];
# lhs of device_identity matches device, rhs matches device_ip
if (check_acl($device, $anded_this) if (check_acl($device, $anded_this)
and check_acl($alias, $idmap->{$this}) and check_acl($alias, $idmap->{$this})) {
and $alias->alias ne $old_ip) {
$new_ip = $alias->alias; $new_ip = $alias->alias;
last ALIAS; last ALIAS;
} }