From 6dae0ea064866ed0fc4a09da716601435c2f318b Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 30 Nov 2010 11:14:55 -0800 Subject: Add duplicate address check on commit Perl is no longer used for syntax checks, instead put duplicate address check into commit. --- scripts/vyatta-interfaces.pl | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'scripts') 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); -- cgit v1.2.3