diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-01-20 10:11:21 +1100 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-01-20 10:11:21 +1100 |
commit | 05f12fecffab242122c2702c049b48500ae8081a (patch) | |
tree | d10b223c178ba9e32cbaea7e671f4b60f6837a76 /lib/Vyatta/Misc.pm | |
parent | c28287fcf5ba523a46f86ec84c6dd648d2fcbe73 (diff) | |
download | vyatta-cfg-05f12fecffab242122c2702c049b48500ae8081a.tar.gz vyatta-cfg-05f12fecffab242122c2702c049b48500ae8081a.zip |
Fix isIPinInterfaces
fix bug in conversion to Vyatta::Interface by rewriting/refactoring.
Diffstat (limited to 'lib/Vyatta/Misc.pm')
-rwxr-xr-x | lib/Vyatta/Misc.pm | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index 3d0f7b2..3c89871 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -99,6 +99,29 @@ sub getInterfaces { return @interfaces; } +sub getIP { + my ($name, $type) = @_; + my @addresses; + + open my $ipcmd, "ip addr show dev $name |" + or die "ip addr command failed: $!"; + + <$ipcmd>; + while (<$ipcmd>) { + my ($proto, $addr) = split; + next unless ($proto =~ /inet/); + if ($type) { + next if ($proto eq 'inet6' && $type != 6); + next if ($proto eq 'inet' && $type != 4); + } + + push @addresses, $addr; + } + close $ipcmd; + + return @addresses; +} + my %type_hash = ( 'broadcast' => IFF_BROADCAST, 'multicast' => IFF_MULTICAST, @@ -212,22 +235,16 @@ sub is_ip_in_list { return $list_hash{$ip}; } + sub isIPinInterfaces { my ($vc, $ip_addr, @interfaces) = @_; return unless $ip_addr; # undef == false foreach my $name (@interfaces) { - my $name = shift; - my $intf = new Vyatta::Interface($name); - next unless $intf; # unknown interface type - - my @addresses = $intf->address(); - - return 1 if (is_ip_in_list($ip_addr, @addresses)); + return 1 if (is_ip_in_list($ip_addr, getIP($name))); } - - return; # undef == false + # false (undef) } sub isClusteringEnabled { |