diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2012-06-22 12:11:37 -0700 |
---|---|---|
committer | Stephen Hemminger <shemminger@vyatta.com> | 2012-06-22 15:49:55 -0700 |
commit | 12a5b876d2502c2add58e0d50b6ac23ef3a7dc51 (patch) | |
tree | d89da4edaf13be20461a624720a741a32440c2bc /lib/Vyatta/Interface.pm | |
parent | 60be8c5723af5e8e314b4796fe57371a2e880f75 (diff) | |
download | vyatta-cfg-12a5b876d2502c2add58e0d50b6ac23ef3a7dc51.tar.gz vyatta-cfg-12a5b876d2502c2add58e0d50b6ac23ef3a7dc51.zip |
Add new function to find hash of configured addresses
Useful to optimize lookup and resolve issue in Bz 8171
Diffstat (limited to 'lib/Vyatta/Interface.pm')
-rwxr-xr-x | lib/Vyatta/Interface.pm | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index a02bd1e..a25fddd 100755 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -97,33 +97,46 @@ 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(); +# get map of current addresses on the system +# returns reference to hash of form: +# ( "192.168.1.1" => { 'eth0', 'eth2' } ) +sub get_cfg_addresses { my $config = new Vyatta::Config; - my %addr_hash = (); + my @cfgifs = get_all_cfg_interfaces(); + my %ahash; + foreach my $intf ( @cfgifs ) { - my $addrs = [ ]; - my $path = "$intf->{'path'}"; - if ($path =~ /openvpn/) { - $addrs = [$config->listNodes("$path local-address")]; + my $name = $intf->{'name'}; + + # workaround openvpn wart + my @addrs; + $config->setLevel($intf->{'path'}); + if ($name =~ /^vtun/) { + @addrs = $config->listNodes('local-address'); } else { - $addrs = [$config->returnValues("$path address")]; + @addrs = $config->returnValues('address'); } - foreach my $addr ( @{$addrs} ){ - if (not exists $addr_hash{$addr}){ - $addr_hash{$addr} = { _intf => [ $intf->{name} ] }; + + foreach my $addr ( @addrs ){ + next if ($addr =~ /^dhcp/); + + # put interface into + my $aif = $ahash{$addr}; + if ($aif) { + push @{$aif}, $name; } else { - $addr_hash{$addr}->{_intf} = - [ @{$addr_hash{$addr}->{_intf}}, $intf->{name} ]; + $ahash{$addr} = [ $name ]; } } } - return ((scalar @{$addr_hash{$ip}->{_intf}}) <= 1); + + return \%ahash; } # get all configured interfaces (in active or working configuration) +# return a hash of: +# 'name' => ethX +# 'path' => "interfaces ethernet ethX" sub get_all_cfg_interfaces { my ($in_active) = @_; my $vfunc = ($in_active ? 'listOrigNodes' : 'listNodes'); |