diff options
author | rbalocca <rbalocca@vyatta.com> | 2008-04-04 10:27:45 -0700 |
---|---|---|
committer | rbalocca <rbalocca@vyatta.com> | 2008-04-04 10:27:45 -0700 |
commit | 18b7f9a1d068b7f1261f692db30ea54955691abe (patch) | |
tree | 8691c1f7f54e6687f24c93eeb1039599f8e2f64b /scripts | |
parent | f71417e0209a48bb88fb614acb186109e0573941 (diff) | |
parent | 41b4c40773d3fdc7dc9a204973038b1992107031 (diff) | |
download | vyatta-cfg-18b7f9a1d068b7f1261f692db30ea54955691abe.tar.gz vyatta-cfg-18b7f9a1d068b7f1261f692db30ea54955691abe.zip |
Merge branch 'glendale' into hollywood
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/VyattaConfigLoad.pm | 1 | ||||
-rwxr-xr-x | scripts/vyatta-interfaces.pl | 85 | ||||
-rwxr-xr-x | scripts/vyatta-watchlink-exclude.pl | 16 |
3 files changed, 72 insertions, 30 deletions
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, ); diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index c60288a..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; @@ -325,6 +328,22 @@ 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; + + return $ifindex; +} + +sub htonl { + return unpack('L',pack('N',shift)); +} + sub delete_eth_addrs { my ($addr, $intf) = @_; @@ -335,41 +354,49 @@ 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 interface has address than delete it if (is_ip_configured($intf, $addr)) { - 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"; + # Link is up, so just delete address + # Zebra is watching for netlink events and will handle it + exec 'ip', 'addr', 'del', $addr, 'dev', $intf + or die "Could not 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 $statusfile = '/var/linkstatus/' . if_nametoindex($intf); - 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; + # 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 - die "Can't exec vtysh"; + 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; } sub update_mac { 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 { |