From ac2527611ae57dd54edb2d08e26a2b54aeca9dc4 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 2 Apr 2008 16:04:40 -0700 Subject: stop watchlink when address is removed Kludge to work around address watchlink interaction: remove status file. This should fix bug 2802. There may still be problems when multiple addresses are assigned to an interface. The correct fix is to just get rid of the watchlink process and do the management in kernel or zebra. --- scripts/vyatta-interfaces.pl | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index c60288a..01ddd5e 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -325,6 +325,18 @@ sub update_eth_addrs { exit 1; } +sub if_nametoindex { + my ($intf) = @_; + + open my $sysfs, "<", "/sys/class/net/$intf/ifindex" + || die "Unknown interface $intf"; + my $ifindex = <$sysfs>; + close($sysfs) or die "read sysfs error\n"; + chomp $ifindex; + print "$intf = $ifindex\n"; + return $ifindex; +} + sub delete_eth_addrs { my ($addr, $intf) = @_; @@ -336,8 +348,9 @@ sub delete_eth_addrs { } my $version = is_ip_v4_or_v6($addr); - # If interface has address than delete it if (is_ip_configured($intf, $addr)) { + # Link is up, so just delete address + # Zebra is watching for netlink events and will handle it if ($version == 4) { exec 'ip', 'addr', 'del', $addr, 'dev', $intf; } elsif ($version == 6) { @@ -348,28 +361,12 @@ sub delete_eth_addrs { die "Can't exec ip"; } - # Interface address might have been removed by quagga link going down - # so tell quagga no to restore it on link-detect - my $vtysh; - if ( -x '/usr/bin/vyatta-vtysh' ) { - $vtysh = '/usr/bin/vyatta-vtysh'; - } else { - $vtysh = '/usr/bin/vtysh'; - } + # Destroy watchlink's internal status so it doesn't erronously + # restore the address when link is restored + my $status = '/var/linkstatus/' . if_nametoindex($intf); + unlink($status) or die "can't remove $status"; - my @cmd = (); - if ($version == 4) { - @cmd = ('vtysh', '-c', - "configure terminal; interface $intf; no ip address $intf" ); - } elsif ($version == 6) { - @cmd = ('vtysh', '-c', - "configure terminal; interface $intf; no ip6 address $intf" ); - } else { - die "Bad ip version"; - } - exec $vtysh, @cmd; - - die "Can't exec vtysh"; + exit 0; } sub update_mac { -- cgit v1.2.3 From ab870f61eec0e48c06ee1a5008e8aa0d77a0638e Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Wed, 2 Apr 2008 18:05:55 -0700 Subject: Add duplicate check to watchlink exclude file. --- scripts/vyatta-watchlink-exclude.pl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/vyatta-watchlink-exclude.pl b/scripts/vyatta-watchlink-exclude.pl index 048946c..eb9d280 100755 --- a/scripts/vyatta-watchlink-exclude.pl +++ b/scripts/vyatta-watchlink-exclude.pl @@ -112,6 +112,18 @@ sub remove_exclude_line { return @new_lines; } +sub is_exclude_dup { + my ($new_line, @lines) = @_; + + my $frag = substr($new_line, 0, index($new_line, ' #')); + foreach my $line (@lines) { + if (substr($line, 0, index($line, ' #')) eq $frag) { + return 1; + } + } + return 0; +} + # # main @@ -148,7 +160,9 @@ if (defined $opt_id) { } if ($opt_action eq "add") { - push @lines, $new_line; + if (! is_exclude_dup($new_line, @lines)) { + push @lines, $new_line; + } } elsif (defined $opt_intf) { @lines = remove_exclude_line($new_line, @lines); } else { -- cgit v1.2.3 From cac51df000d90b9723abde545450fde66d1d7865 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 3 Apr 2008 17:22:01 -0700 Subject: handle multiple address deletion when link is down More robust fix for Bug 2802. Handle case of multiple addresses and lines in the linkstatus file. Add locking to try and prevent multiple update. --- scripts/vyatta-interfaces.pl | 52 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index 01ddd5e..28b1c14 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -33,9 +33,12 @@ use lib "/opt/vyatta/share/perl5/"; use VyattaConfig; use VyattaMisc; + use Getopt::Long; use POSIX; use NetAddr::IP; +use Tie::File; +use Fcntl qw (:flock); use strict; use warnings; @@ -333,10 +336,14 @@ sub if_nametoindex { my $ifindex = <$sysfs>; close($sysfs) or die "read sysfs error\n"; chomp $ifindex; - print "$intf = $ifindex\n"; + return $ifindex; } +sub htonl { + return unpack('L',pack('N',shift)); +} + sub delete_eth_addrs { my ($addr, $intf) = @_; @@ -347,25 +354,48 @@ sub delete_eth_addrs { exit 0; } my $version = is_ip_v4_or_v6($addr); + if ($version == 6) { + exec 'ip', '-6', 'addr', 'del', $addr, 'dev', $intf + or die "Could not exec ip?"; + } + + ($version == 4) or die "Bad ip version"; if (is_ip_configured($intf, $addr)) { # Link is up, so just delete address # Zebra is watching for netlink events and will handle it - if ($version == 4) { - exec 'ip', 'addr', 'del', $addr, 'dev', $intf; - } elsif ($version == 6) { - exec 'ip', '-6', 'addr', 'del', $addr, 'dev', $intf; - } else { - die "Bad ip version"; - } - die "Can't exec ip"; + exec 'ip', 'addr', 'del', $addr, 'dev', $intf + or die "Could not exec ip?"; } + # Destroy watchlink's internal status so it doesn't erronously # restore the address when link is restored - my $status = '/var/linkstatus/' . if_nametoindex($intf); - unlink($status) or die "can't remove $status"; + my $statusfile = '/var/linkstatus/' . if_nametoindex($intf); + + # Use tie to treat file as array + my $tie = tie my @status, 'Tie::File', $statusfile + or die "can't open $statusfile"; + $tie->flock(LOCK_EX); # Block out watchlink + $tie = undef; # Drop reference so untie will work + + my $ip = NetAddr::IP->new($addr); + my $recno = 0; + foreach my $line (@status) { + chomp $line; + + # The format of watchlink file is host byte order (IPV6??) + my ($ifindex, $raddr, $bcast, $prefix) = split (/,/, $line); + my $laddr = htonl($raddr); + my $this = NetAddr::IP->new("$laddr/$prefix"); + if ($ip eq $this) { + splice @status, $recno, 1; # delete the line + } else { + $recno++; + } + } + untie @status; exit 0; } -- cgit v1.2.3 From 41b4c40773d3fdc7dc9a204973038b1992107031 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Thu, 3 Apr 2008 20:38:02 -0700 Subject: fix for bug 3090: commit "policy" before "protocols" at boot time. --- scripts/VyattaConfigLoad.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm index c4ce8bd..2efa81e 100755 --- a/scripts/VyattaConfigLoad.pm +++ b/scripts/VyattaConfigLoad.pm @@ -40,6 +40,7 @@ my %config_rank = ( 'protocols static' => 85, 'service ssh' => 84, 'service telnet' => 83, + 'policy' => 82, 'vpn' => 80, ); -- cgit v1.2.3