diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-11-30 11:14:55 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-11-30 13:42:26 -0800 |
commit | 6dae0ea064866ed0fc4a09da716601435c2f318b (patch) | |
tree | 65d78d86e717f515375e52ac5462276c3a752873 /scripts/vyatta-interfaces.pl | |
parent | 535038b0a269f19c58ed1be3b4aafba66877ae2e (diff) | |
download | vyatta-cfg-quagga-6dae0ea064866ed0fc4a09da716601435c2f318b.tar.gz vyatta-cfg-quagga-6dae0ea064866ed0fc4a09da716601435c2f318b.zip |
Add duplicate address check on commit
Perl is no longer used for syntax checks, instead put duplicate address check
into commit.
Diffstat (limited to 'scripts/vyatta-interfaces.pl')
-rwxr-xr-x | scripts/vyatta-interfaces.pl | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index 5a17be04..cf74a7d8 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -41,6 +41,7 @@ use Getopt::Long; use POSIX; use NetAddr::IP; use Fcntl; +use Socket; use strict; use warnings; @@ -114,6 +115,10 @@ sub is_ip_configured { return ($found > 0); } +sub is_ipv4 { + return index($_[0],':') < 0; +} + sub is_ip_duplicate { my ($intf, $ip) = @_; @@ -465,9 +470,22 @@ sub is_valid_addr_commit { die "Can't configure address on interface that is slaved to bonding interface.\n" if (defined($bond)); - my $dhcp = grep { /^dhcp$/ } @addrs; - my $static_v4 = grep { my $v = is_ip_v4_or_v6($_); - defined($v) && $v == 4 } @addrs; + # Map of all the ip addresses + my %ipaddr_hash = map { $_ => 1 } getIP(); + + 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)) { + die "Error: duplicate address [$addr]\n"; + } elsif ( is_ipv4($addr) ) { + $static_v4 = 1; + } + } + die "Can't configure static IPv4 address and DHCP on the same interface.\n" if ($static_v4 && $dhcp); |