From 388d5ed2580bc9ef7ee7a8cdc1d75126ea97a53e Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Mon, 31 Mar 2008 16:11:47 -0700 Subject: Add utilitly script to add/removed entries to watchlink exclude file. --- Makefile.am | 1 + scripts/vyatta-watchlink-exclude.pl | 144 ++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100755 scripts/vyatta-watchlink-exclude.pl diff --git a/Makefile.am b/Makefile.am index a309d34..4496be6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,6 +43,7 @@ sbin_SCRIPTS += scripts/vyatta-cfg-notify sbin_SCRIPTS += scripts/vyatta-interfaces.pl sbin_SCRIPTS += scripts/vyatta-irqaffin sbin_SCRIPTS += scripts/vyatta-check-typeless-node.pl +sbin_SCRIPTS += scripts/vyatta-watchlink-exclude.pl share_perl5_SCRIPTS = scripts/VyattaConfig.pm share_perl5_SCRIPTS += scripts/VyattaConfigDOMTree.pm diff --git a/scripts/vyatta-watchlink-exclude.pl b/scripts/vyatta-watchlink-exclude.pl new file mode 100755 index 0000000..9805463 --- /dev/null +++ b/scripts/vyatta-watchlink-exclude.pl @@ -0,0 +1,144 @@ +#!/usr/bin/perl +# +# Module: vyatta-watchlink-exclude.pl +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# A copy of the GNU General Public License is available as +# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution +# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. +# You can also obtain it by writing to the Free Software Foundation, +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +# MA 02110-1301, USA. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Stig Thormodsrud +# Date: March 2008 +# Description: Script to update watchlink exclude file +# +# **** End License **** +# + +# +# parameters: +# --id="" : owner of exclude line (e.g. vrrp, ha) [required] +# --action="" : add or remove [required] +# --intf="" : interface [required] +# --ipaddr="" : ip address or network to execlude [optional] +# --signal : should watchlink get signaled [optional] +# +# Expected format of exclude file: +# +# [interface] ([ipv4addr]|ipv4net]) # id +# + +use Getopt::Long; +use POSIX; + +use strict; +use warnings; + +my $exclude_file = '/var/linkstatus/exclude'; +my $watchlink_pid = '/var/run/vyatta/quagga/watchlink.pid'; + +sub read_exclude_file { + my $FILE; + my @lines = (); + if (! -e $exclude_file) { + return @lines; + } + open($FILE, "<", $exclude_file) or die "Error: read() $!"; + @lines = <$FILE>; + close($FILE); + chomp @lines; + return @lines; +} + +sub write_exclude_file { + my @lines = @_; + + my $FILE; + open($FILE, ">", $exclude_file) or die "Error: write() $!"; + if (scalar(@lines) > 0) { + print $FILE join("\n", @lines), "\n"; + } + close($FILE); +} + +sub remove_exclude_line { + my ($remove_line, @lines) = @_; + + my @new_lines; + my $match = 0; + foreach my $line (@lines) { + if ($line eq $remove_line) { + $match++; + } else { + push @new_lines, $line; + } + } + if ($match < 1) { + die "Error: no match found for $remove_line"; + } + return @new_lines; +} + + +# +# main +# + +my ($opt_id, $opt_action, $opt_intf, $opt_ipaddr, $opt_ipnet, $opt_signal); + +GetOptions("id=s" => \$opt_id, + "action=s" => \$opt_action, + "intf=s" => \$opt_intf, + "ipaddr=s" => \$opt_ipaddr, + "signal!" => \$opt_signal, + ); + +if (!(defined $opt_id and defined $opt_action and defined $opt_intf) ) { + die "Error: parameters --id --intf --action must be set"; +} + +if ($opt_action ne "add" and $opt_action ne "remove") { + die "Error: --action must be \"add\" or \"remove\" "; +} + +my @lines = read_exclude_file(); +my $new_line = "$opt_intf "; +if (defined $opt_ipaddr) { + $new_line .= "$opt_ipaddr "; +} +if (defined $opt_id) { + $new_line .= "# $opt_id"; +} + +if ($opt_action eq "add") { + push @lines, $new_line; +} else { + @lines = remove_exclude_line($new_line, @lines); +} +write_exclude_file(@lines); + +if (defined $opt_signal) { + if (! -e $watchlink_pid) { + die "Error: missing pid file [$watchlink_pid]\n"; + } + my $pid = `cat $watchlink_pid`; + chomp $pid; + system("kill -10 $pid"); +} + +# end of file -- cgit v1.2.3 From 06702f2ed04408962d7e8e6323db97e29dd32669 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Mon, 31 Mar 2008 16:40:33 -0700 Subject: fix for bug 2675: correctly detect newly created config nodes. --- src/commit.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/commit.c b/src/commit.c index 980a98b..8fbc1d6 100644 --- a/src/commit.c +++ b/src/commit.c @@ -747,17 +747,16 @@ static boolean commit_delete_child(vtw_def *pdefp, char *child, mark_paths(&mark); if (!deleting) { int status; - /* are we marked with opaque */ push_path(&m_path, child); - push_path(&m_path, opaque_name); + switch_path(APATH); /* switch to active */ status = lstat(m_path.path, &statbuf); + switch_path(CPATH); /* back to changes */ pop_path(&m_path); - pop_path(&m_path); - if (status >= 0) { - /* brand new directory, nothing is - deleted there; - update will handle txn (both begin and end) - */ + if (status < 0) { + /* node doesn't exist in active config. it's newly created + * so we don't need to handle delete. update will handle the + * transaction (if any). + */ return TRUE; } } -- cgit v1.2.3 From 0a350b99308762f1eb180aa47b64db78b3187c7e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 31 Mar 2008 16:46:42 -0700 Subject: handle delete address request if address is already removed Quagga link-detect may have already removed address from interface. Check for missing address, and if not present just tell vtysh. This fixes bug 2802 --- scripts/vyatta-interfaces.pl | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index e3afe68..c60288a 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -332,18 +332,44 @@ sub delete_eth_addrs { dhcp_release_addr($intf); update_dhcp_client(); system("rm -f /var/lib/dhcp3/dhclient_$intf\_lease"); - return; + exit 0; } my $version = is_ip_v4_or_v6($addr); - if (!defined $version) { - exit 1; + + # 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"; } - if ($version == 4) { - return system("ip addr del $addr dev $intf"); + + # 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'; } - if ($version == 6) { - return system("ip -6 addr del $addr dev $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; + + die "Can't exec vtysh"; } sub update_mac { -- cgit v1.2.3 From 2ad53e3ae6bd073785df8f99121b89683df744a2 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 1 Apr 2008 11:07:06 -0700 Subject: add function to delete watchlink exclude entries based on ID. --- scripts/vyatta-watchlink-exclude.pl | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/scripts/vyatta-watchlink-exclude.pl b/scripts/vyatta-watchlink-exclude.pl index 9805463..048946c 100755 --- a/scripts/vyatta-watchlink-exclude.pl +++ b/scripts/vyatta-watchlink-exclude.pl @@ -34,13 +34,13 @@ # parameters: # --id="" : owner of exclude line (e.g. vrrp, ha) [required] # --action="" : add or remove [required] -# --intf="" : interface [required] +# --intf="" : interface [required for add] # --ipaddr="" : ip address or network to execlude [optional] # --signal : should watchlink get signaled [optional] # # Expected format of exclude file: # -# [interface] ([ipv4addr]|ipv4net]) # id +# [ | ] # id # use Getopt::Long; @@ -76,6 +76,24 @@ sub write_exclude_file { close($FILE); } +sub remove_exclude_id { + my ($id, @lines) = @_; + + my @new_lines; + my $match = 0; + foreach my $line (@lines) { + if ($line =~ /# $id$/) { + $match++; + } else { + push @new_lines, $line; + } + } + if ($match < 1) { + die "Error: no match found for $id"; + } + return @new_lines; +} + sub remove_exclude_line { my ($remove_line, @lines) = @_; @@ -108,14 +126,18 @@ GetOptions("id=s" => \$opt_id, "signal!" => \$opt_signal, ); -if (!(defined $opt_id and defined $opt_action and defined $opt_intf) ) { - die "Error: parameters --id --intf --action must be set"; +if (!(defined $opt_id and defined $opt_action)) { + die "Error: parameters --id --action must be set"; } if ($opt_action ne "add" and $opt_action ne "remove") { die "Error: --action must be \"add\" or \"remove\" "; } +if ($opt_action eq "add" and !defined($opt_intf)) { + die "Error: --intf must be set for \"add\""; +} + my @lines = read_exclude_file(); my $new_line = "$opt_intf "; if (defined $opt_ipaddr) { @@ -127,8 +149,10 @@ if (defined $opt_id) { if ($opt_action eq "add") { push @lines, $new_line; -} else { +} elsif (defined $opt_intf) { @lines = remove_exclude_line($new_line, @lines); +} else { + @lines = remove_exclude_id($opt_id, @lines); } write_exclude_file(@lines); -- cgit v1.2.3 From 35642e2e10aff32335690a5af2710bbb9ec3ea13 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 1 Apr 2008 12:37:35 -0700 Subject: fix for bug 2689: sort tag nodes appropriately --- debian/control | 4 +++- scripts/VyattaConfigOutput.pm | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 308105a..2fdbcfe 100644 --- a/debian/control +++ b/debian/control @@ -17,7 +17,9 @@ Depends: sed (>= 4.1.5), vyatta-config-migrate, dhcp3-client | vyatta-dhcp3-client, bsdutils (>=1:2.13), - libc6 (>= 2.7-6) + libc6 (>= 2.7-6), + libsort-versions-perl, + vlan Replaces: vyatta-cfg-firewall Suggests: util-linux (>= 2.13-5), net-tools, diff --git a/scripts/VyattaConfigOutput.pm b/scripts/VyattaConfigOutput.pm index b7c5499..2766b64 100755 --- a/scripts/VyattaConfigOutput.pm +++ b/scripts/VyattaConfigOutput.pm @@ -32,6 +32,7 @@ package VyattaConfigOutput; use strict; use lib '/opt/vyatta/share/perl5/'; use VyattaConfig; +use Sort::Versions; # whether to show default values my $show_all = 0; @@ -190,6 +191,7 @@ sub displayDeletedOrigChildren { $dont_show_as_deleted); } elsif (scalar($#cnames) >= 0) { if ($is_tag) { + @cnames = sort versioncmp @cnames; foreach my $cname (@cnames) { if ($cname eq 'node.val') { # should not happen @@ -244,6 +246,7 @@ sub displayChildren { displayValues([ @cur_path, $child ], $prefix, $child); } elsif (scalar($#cnames) >= 0) { if ($is_tag) { + @cnames = sort versioncmp @cnames; foreach my $cname (@cnames) { if ($cname eq 'node.val') { # should not happen -- cgit v1.2.3