summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Southworth <john.southworth@vyatta.com>2011-07-01 17:31:40 -0700
committerJohn Southworth <john.southworth@vyatta.com>2011-07-01 17:31:40 -0700
commit824d961ba24251866e28a53aa71adff377c56192 (patch)
treee67853eab1626de01c4ada0d0becd6161bdfdb8c
parent443b54cda22d525986dde93647939fc45d056a49 (diff)
downloadvyatta-cfg-system-824d961ba24251866e28a53aa71adff377c56192.tar.gz
vyatta-cfg-system-824d961ba24251866e28a53aa71adff377c56192.zip
bugfix 6801: check to see if the same address is configured on another interface in the working config before allowing an address to be set on an interface, allows for swapping addresses in the same commit
-rwxr-xr-xscripts/vyatta-interfaces.pl33
1 files changed, 29 insertions, 4 deletions
diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl
index 26f2791a..f139dcf6 100755
--- a/scripts/vyatta-interfaces.pl
+++ b/scripts/vyatta-interfaces.pl
@@ -103,6 +103,31 @@ sub is_ip_configured {
return ($found > 0);
}
+sub is_uniq_address {
+ my $ip = pop(@_);
+ my @cfgifs = Vyatta::Interface::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);
+}
+
sub is_ipv4 {
return index($_[0],':') < 0;
}
@@ -290,12 +315,12 @@ sub is_valid_addr_commit {
my ($dhcp, $static_v4);
foreach my $addr (@addrs) {
next if ($addr eq 'dhcpv6');
-
if ($addr eq 'dhcp') {
$dhcp = 1;
- } elsif ($ipaddr_hash{$addr} && !is_ip_configured($ifname, $addr)) {
- my $h = Vyatta::Misc::get_ipnet_intf_hash();
- print "Warning: possible duplicate address $addr on $h->{$addr}\n";
+ } elsif (!is_uniq_address($addr)) {
+ my $h = Vyatta::Misc::get_ipnet_intf_hash();
+ print "Error: duplicate address $addr on $h->{$addr}\n";
+ exit 1;
} elsif ( is_ipv4($addr) ) {
$static_v4 = 1;
}