summaryrefslogtreecommitdiff
path: root/lib/Vyatta/Interface.pm
diff options
context:
space:
mode:
authorJohn Southworth <john.southworth@vyatta.com>2011-07-05 16:21:19 -0500
committerJohn Southworth <john.southworth@vyatta.com>2011-07-05 16:21:19 -0500
commit921f033e717c688004e70920c78bd4d1b70a59bd (patch)
tree2af83b30be39d973b53eb4dc7d85b27b1cc70b6c /lib/Vyatta/Interface.pm
parented5f6659c107a0a17fd36f0317dc6ce6c117140d (diff)
downloadvyatta-cfg-921f033e717c688004e70920c78bd4d1b70a59bd.tar.gz
vyatta-cfg-921f033e717c688004e70920c78bd4d1b70a59bd.zip
Move the is_uniq_address function to Interface.pm
Diffstat (limited to 'lib/Vyatta/Interface.pm')
-rwxr-xr-xlib/Vyatta/Interface.pm26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm
index ff9e067..6d8de08 100755
--- a/lib/Vyatta/Interface.pm
+++ b/lib/Vyatta/Interface.pm
@@ -85,6 +85,32 @@ sub interface_types {
return @types;
}
+# check to see if an address is unique in the working configuration
+sub is_uniq_address {
+ my $ip = pop(@_);
+ my @cfgifs = get_all_cfg_interfaces();
+ my $config = new Vyatta::Config;
+ my %addr_hash = ();
+ foreach my $intf ( @cfgifs ) {
+ my $addrs = [ ];
+ my $path = "$intf->{'path'}";
+ if ($path =~ /openvpn/) {
+ $addrs = [$config->listNodes("$path local-address")];
+ } else {
+ $addrs = [$config->returnValues("$path address")];
+ }
+ foreach my $addr ( @{$addrs} ){
+ if (not exists $addr_hash{$addr}){
+ $addr_hash{$addr} = { _intf => [ $intf->{name} ] };
+ } else {
+ $addr_hash{$addr}->{_intf} =
+ [ @{$addr_hash{$addr}->{_intf}}, $intf->{name} ];
+ }
+ }
+ }
+ return ((scalar @{$addr_hash{$ip}->{_intf}}) <= 1);
+}
+
# get all configured interfaces (in active or working configuration)
sub get_all_cfg_interfaces {
my ($in_active) = @_;