summaryrefslogtreecommitdiff
path: root/scripts/vyatta-interfaces.pl
diff options
context:
space:
mode:
authorStig Thormodsrud <stig@vyatta.com>2008-01-28 13:34:15 -0800
committerStig Thormodsrud <stig@vyatta.com>2008-01-28 13:34:15 -0800
commit8457dbb2b898b31e04c49f0482b7002f5ad1933f (patch)
tree509edf8bf2dea4633645e14b0ad79c67c862f33f /scripts/vyatta-interfaces.pl
parent35977317f7dafb2ce7ce372e1c406f1aa042fff6 (diff)
downloadvyatta-cfg-8457dbb2b898b31e04c49f0482b7002f5ad1933f.tar.gz
vyatta-cfg-8457dbb2b898b31e04c49f0482b7002f5ad1933f.zip
fix 2718: Set failed after a duplicated address was set for an interface
Diffstat (limited to 'scripts/vyatta-interfaces.pl')
-rw-r--r--scripts/vyatta-interfaces.pl26
1 files changed, 24 insertions, 2 deletions
diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl
index 1f13e20..20203c7 100644
--- a/scripts/vyatta-interfaces.pl
+++ b/scripts/vyatta-interfaces.pl
@@ -53,9 +53,18 @@ if (defined $eth_update) { update_eth_addrs($eth_update, $dev); }
if (defined $eth_delete) { delete_eth_addrs($eth_delete, $dev); }
if (defined $addr) { is_valid_addr($addr, $dev); }
+sub is_ip_configured {
+ my ($intf, $ip) = @_;
+ my $wc = `ip addr show $intf | grep $ip | wc -l`;
+ if (defined $wc and $wc > 0) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
sub is_ip_duplicate {
- my $ip = shift;
+ my ($intf, $ip) = @_;
#
# get a list of all ipv4 and ipv6 addresses
@@ -65,6 +74,12 @@ sub is_ip_duplicate {
my %ipaddrs_hash = map { $_ => 1 } @ipaddrs;
if (defined $ipaddrs_hash{$ip}) {
+ #
+ # allow dup if it's the same interface
+ #
+ if (is_ip_configured($intf, $ip)) {
+ return 0;
+ }
return 1;
} else {
return 0;
@@ -260,6 +275,13 @@ sub update_eth_addrs {
if (!defined $version) {
exit 1;
}
+ if (is_ip_configured($intf, $addr)) {
+ #
+ # treat this as informational, don't fail
+ #
+ print "Address $addr already configured on $intf\n";
+ exit 0;
+ }
if ($version == 4) {
return system("ip addr add $addr broadcast + dev $intf");
@@ -328,7 +350,7 @@ sub is_valid_addr {
print "Error: remove dhcp before adding static addresses for $intf\n";
exit 1;
}
- if (is_ip_duplicate($addr_net)) {
+ if (is_ip_duplicate($intf, $addr_net)) {
print "Error: duplicate address/prefix [$addr_net]\n";
exit 1;
}