From 1b8212fe55cc9d83601acc52b43d3e7116542eda Mon Sep 17 00:00:00 2001 From: "David S. Madole" Date: Sun, 27 Sep 2009 15:29:17 -0400 Subject: Add VRRP capability to bonding interfaces and vifs of bonding interfaces. --- scripts/keepalived/vyatta-clear-vrrp.pl | 75 ++++++----- scripts/keepalived/vyatta-keepalived.pl | 225 +++++++++++++++++--------------- scripts/keepalived/vyatta-show-vrrp.pl | 14 +- 3 files changed, 168 insertions(+), 146 deletions(-) (limited to 'scripts/keepalived') diff --git a/scripts/keepalived/vyatta-clear-vrrp.pl b/scripts/keepalived/vyatta-clear-vrrp.pl index 17dedc59..ba5d569b 100644 --- a/scripts/keepalived/vyatta-clear-vrrp.pl +++ b/scripts/keepalived/vyatta-clear-vrrp.pl @@ -109,47 +109,50 @@ sub get_vrrp_intf_group { # return an array of hashes that contains all the intf/group pairs # - my $config = new Vyatta::Config; - $config->setLevel('interfaces ethernet'); - my @eths = $config->listOrigNodes(); - foreach my $eth (@eths) { - my $path = "interfaces ethernet $eth"; - $config->setLevel($path); - if ($config->existsOrig("vrrp")) { - $path = "$path vrrp vrrp-group"; + foreach my $type (("ethernet", "bonding")) { + + my $config = new Vyatta::Config; + $config->setLevel("interfaces $type"); + my @eths = $config->listOrigNodes(); + foreach my $eth (@eths) { + my $path = "interfaces $type $eth"; $config->setLevel($path); - my @groups = $config->listOrigNodes(); - foreach my $group (@groups) { - my %hash; - $hash{'intf'} = $eth; - $hash{'group'} = $group; - $hash{'path'} = "$path $group"; - push @array, {%hash}; + if ($config->existsOrig("vrrp")) { + $path = "$path vrrp vrrp-group"; + $config->setLevel($path); + my @groups = $config->listOrigNodes(); + foreach my $group (@groups) { + my %hash; + $hash{'intf'} = $eth; + $hash{'group'} = $group; + $hash{'path'} = "$path $group"; + push @array, {%hash}; + } } - } - $path = "interfaces ethernet $eth"; - $config->setLevel($path); - if ($config->existsOrig('vif')) { - my $path = "$path vif"; + $path = "interfaces $type $eth"; $config->setLevel($path); - my @vifs = $config->listOrigNodes(); - foreach my $vif (@vifs) { - my $vif_intf = $eth . '.' . $vif; - my $vif_path = "$path $vif"; - $config->setLevel($vif_path); - if ($config->existsOrig('vrrp')) { - $vif_path = "$vif_path vrrp vrrp-group"; + if ($config->existsOrig('vif')) { + my $path = "$path vif"; + $config->setLevel($path); + my @vifs = $config->listOrigNodes(); + foreach my $vif (@vifs) { + my $vif_intf = $eth . '.' . $vif; + my $vif_path = "$path $vif"; $config->setLevel($vif_path); - my @groups = $config->listOrigNodes(); - foreach my $group (@groups) { - my %hash; - $hash{'intf'} = $vif_intf; - $hash{'group'} = $group; - $hash{'path'} = "$path $group"; - push @array, {%hash}; - } - } + if ($config->existsOrig('vrrp')) { + $vif_path = "$vif_path vrrp vrrp-group"; + $config->setLevel($vif_path); + my @groups = $config->listOrigNodes(); + foreach my $group (@groups) { + my %hash; + $hash{'intf'} = $vif_intf; + $hash{'group'} = $group; + $hash{'path'} = "$path $group"; + push @array, {%hash}; + } + } + } } } } diff --git a/scripts/keepalived/vyatta-keepalived.pl b/scripts/keepalived/vyatta-keepalived.pl index f7d3a652..842f8bc3 100755 --- a/scripts/keepalived/vyatta-keepalived.pl +++ b/scripts/keepalived/vyatta-keepalived.pl @@ -235,61 +235,64 @@ sub vrrp_find_changes { my $config = new Vyatta::Config; my $vrrp_instances = 0; - $config->setLevel("interfaces ethernet"); - my @eths = $config->listNodes(); - foreach my $eth (@eths) { - my $path = "interfaces ethernet $eth"; - $config->setLevel($path); - if ($config->exists("vrrp")) { - my %vrrp_status_hash = $config->listNodeStatus("vrrp"); - my ($vrrp, $vrrp_status) = each(%vrrp_status_hash); - if ($vrrp_status ne "static") { - push @list, $eth; - vrrp_log("$vrrp_status found $eth"); - } - } - if ($config->exists("vif")) { - my $path = "interfaces ethernet $eth vif"; + foreach my $type (("ethernet", "bonding")) { + + $config->setLevel("interfaces $type"); + my @eths = $config->listNodes(); + foreach my $eth (@eths) { + my $path = "interfaces $type $eth"; $config->setLevel($path); - my @vifs = $config->listNodes(); - foreach my $vif (@vifs) { - my $vif_intf = $eth . "." . $vif; - my $vif_path = "$path $vif"; - $config->setLevel($vif_path); - if ($config->exists("vrrp")) { - my %vrrp_status_hash = $config->listNodeStatus("vrrp"); - my ($vrrp, $vrrp_status) = each(%vrrp_status_hash); - if ($vrrp_status ne "static") { - push @list, "$eth.$vif"; - vrrp_log("$vrrp_status found $eth.$vif"); + if ($config->exists("vrrp")) { + my %vrrp_status_hash = $config->listNodeStatus("vrrp"); + my ($vrrp, $vrrp_status) = each(%vrrp_status_hash); + if ($vrrp_status ne "static") { + push @list, $eth; + vrrp_log("$vrrp_status found $eth"); + } + } + if ($config->exists("vif")) { + my $path = "interfaces $type $eth vif"; + $config->setLevel($path); + my @vifs = $config->listNodes(); + foreach my $vif (@vifs) { + my $vif_intf = $eth . "." . $vif; + my $vif_path = "$path $vif"; + $config->setLevel($vif_path); + if ($config->exists("vrrp")) { + my %vrrp_status_hash = $config->listNodeStatus("vrrp"); + my ($vrrp, $vrrp_status) = each(%vrrp_status_hash); + if ($vrrp_status ne "static") { + push @list, "$eth.$vif"; + vrrp_log("$vrrp_status found $eth.$vif"); + } } } } } - } - # - # Now look for deleted from the origin tree - # - $config->setLevel("interfaces ethernet"); - @eths = $config->listOrigNodes(); - foreach my $eth (@eths) { - my $path = "interfaces ethernet $eth"; - $config->setLevel($path); - if ($config->isDeleted("vrrp")) { + # + # Now look for deleted from the origin tree + # + $config->setLevel("interfaces $type"); + @eths = $config->listOrigNodes(); + foreach my $eth (@eths) { + my $path = "interfaces $type $eth"; + $config->setLevel($path); + if ($config->isDeleted("vrrp")) { push @list, $eth; vrrp_log("Delete found $eth"); - } - $config->setLevel("$path vif"); - my @vifs = $config->listOrigNodes(); - foreach my $vif (@vifs) { - my $vif_intf = $eth . "." . $vif; - my $vif_path = "$path vif $vif"; - $config->setLevel($vif_path); - if ($config->isDeleted("vrrp")) { - push @list, "$eth.$vif"; - vrrp_log("Delete found $eth.$vif"); - } + } + $config->setLevel("$path vif"); + my @vifs = $config->listOrigNodes(); + foreach my $vif (@vifs) { + my $vif_intf = $eth . "." . $vif; + my $vif_path = "$path vif $vif"; + $config->setLevel($vif_path); + if ($config->isDeleted("vrrp")) { + push @list, "$eth.$vif"; + vrrp_log("Delete found $eth.$vif"); + } + } } } @@ -339,47 +342,51 @@ sub vrrp_update_config { my $output = "#\n# autogenerated by $0 on $date\n#\n\n"; my $config = new Vyatta::Config; - - $config->setLevel("interfaces ethernet"); - my @eths = $config->listNodes(); my $vrrp_instances = 0; - foreach my $eth (@eths) { - my $path = "interfaces ethernet $eth"; - $config->setLevel($path); - if ($config->exists("vrrp")) { - my ($inst_output, @inst_errs) = keepalived_get_values($eth, $path); - if (scalar(@inst_errs)) { - push @errs, @inst_errs; - } else { - $output .= $inst_output; - $vrrp_instances++; - } - } - if ($config->exists("vif")) { - my $path = "interfaces ethernet $eth vif"; + + for my $type (("ethernet", "bonding")) { + + $config->setLevel("interfaces $type"); + my @eths = $config->listNodes(); + foreach my $eth (@eths) { + my $path = "interfaces $type $eth"; $config->setLevel($path); - my @vifs = $config->listNodes(); - foreach my $vif (@vifs) { - my $vif_path = "$path $vif"; - $config->setLevel($vif_path); - if ($config->exists("vrrp")) { - # - # keepalived gets real grumpy with interfaces that don't - # exist, so skip vlans that haven't been instantiated - # yet (typically occurs at boot up). - # - my $vif_intf = $eth . "." . $vif; - if (!(-d "/sys/class/net/$vif_intf")) { - push @errs, "vlan doesn't exist $vif_intf"; - next; - } - my ($inst_output, @inst_errs) = - keepalived_get_values($vif_intf, $vif_path); - if (scalar(@inst_errs)) { - push @errs, @inst_errs; - } else { - $output .= $inst_output; - $vrrp_instances++; + if ($config->exists("vrrp")) { + my ($inst_output, @inst_errs) = + keepalived_get_values($eth, $path); + if (scalar(@inst_errs)) { + push @errs, @inst_errs; + } else { + $output .= $inst_output; + $vrrp_instances++; + } + } + if ($config->exists("vif")) { + my $path = "interfaces $type $eth vif"; + $config->setLevel($path); + my @vifs = $config->listNodes(); + foreach my $vif (@vifs) { + my $vif_path = "$path $vif"; + $config->setLevel($vif_path); + if ($config->exists("vrrp")) { + # + # keepalived gets real grumpy with interfaces that + # don't exist, so skip vlans that haven't been + # instantiated yet (typically occurs at boot up). + # + my $vif_intf = $eth . "." . $vif; + if (!(-d "/sys/class/net/$vif_intf")) { + push @errs, "vlan doesn't exist $vif_intf"; + next; + } + my ($inst_output, @inst_errs) = + keepalived_get_values($vif_intf, $vif_path); + if (scalar(@inst_errs)) { + push @errs, @inst_errs; + } else { + $output .= $inst_output; + $vrrp_instances++; + } } } } @@ -408,21 +415,24 @@ sub list_vrrp_intf { my $config = new Vyatta::Config; my @intfs = (); - $config->setLevel("interfaces ethernet"); - my @eths = $config->listOrigNodes(); - foreach my $eth (@eths) { - my $path = "interfaces ethernet $eth"; - $config->setLevel($path); - push @intfs, $eth if $config->existsOrig("vrrp"); - if ($config->existsOrig("vif")) { - my $path = "interfaces ethernet $eth vif"; + foreach my $type (("ethernet", "bonding")) { + + $config->setLevel("interfaces $type"); + my @eths = $config->listOrigNodes(); + foreach my $eth (@eths) { + my $path = "interfaces $type $eth"; $config->setLevel($path); - my @vifs = $config->listOrigNodes(); - foreach my $vif (@vifs) { - my $vif_intf = $eth . "." . $vif; - my $vif_path = "$path $vif"; - $config->setLevel($vif_path); - push @intfs, $vif_intf if $config->existsOrig("vrrp"); + push @intfs, $eth if $config->existsOrig("vrrp"); + if ($config->existsOrig("vif")) { + my $path = "interfaces $type $eth vif"; + $config->setLevel($path); + my @vifs = $config->listOrigNodes(); + foreach my $vif (@vifs) { + my $vif_intf = $eth . "." . $vif; + my $vif_path = "$path $vif"; + $config->setLevel($vif_path); + push @intfs, $vif_intf if $config->existsOrig("vrrp"); + } } } } @@ -431,11 +441,18 @@ sub list_vrrp_intf { sub list_vrrp_group { my ($name) = @_; - my $config = new Vyatta::Config; - my $path = "interfaces ethernet $name"; - if ($name =~ /(eth\d+)\.(\d+)/) { - $path = "interfaces ethernet $1 vif $2"; + my $path; + if ($name =~ /bond/) { + $path = "interfaces bonding $name"; + if ($name =~ /(bond\d+)\.(\d+)/) { + $path = "interfaces bonding $1 vif $2"; + } + } else { + $path = "interfaces ethernet $name"; + if ($name =~ /(eth\d+)\.(\d+)/) { + $path = "interfaces ethernet $1 vif $2"; + } } $path .= " vrrp vrrp-group"; $config->setLevel($path); diff --git a/scripts/keepalived/vyatta-show-vrrp.pl b/scripts/keepalived/vyatta-show-vrrp.pl index 3015bc92..5ec2e8ad 100755 --- a/scripts/keepalived/vyatta-show-vrrp.pl +++ b/scripts/keepalived/vyatta-show-vrrp.pl @@ -129,7 +129,7 @@ sub get_master_info { my $source_ip = (vrrp_get_config($intf, $group))[0]; # arping doesn't seem to work for vlans - if ($intf =~ /(eth\d+).\d+/) { + if ($intf =~ /(eth\d+|bond\d+).\d+/) { $intf = $1; } system("/usr/bin/arping -c1 -f -I $intf -s $source_ip $vip > $arp_file"); @@ -251,7 +251,7 @@ sub vrrp_show { # # main # -my $intf = "eth"; +my @intfs = ("eth", "bond"); my $group = "all"; my $showsummary = 0; @@ -259,7 +259,7 @@ if ($#ARGV >= 0) { if ($ARGV[0] eq "summary") { $showsummary = 1; } else { - $intf = $ARGV[0]; + @intfs = ($ARGV[0]); } } @@ -284,9 +284,11 @@ if ($showsummary == 1) { $display_func = \&vrrp_show; } -my @state_files = Vyatta::Keepalived::get_state_files($intf, $group); -foreach my $state_file (@state_files) { - &$display_func($state_file); +foreach my $intf (@intfs) { + my @state_files = Vyatta::Keepalived::get_state_files($intf, $group); + foreach my $state_file (@state_files) { + &$display_func($state_file); + } } exit 0; -- cgit v1.2.3 From f197d4eebd25f3bcbd0f6b5589ce9370a2f501da Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 1 Nov 2009 10:02:49 -0800 Subject: Convert keepalived to use Interface infrastructure. --- scripts/keepalived/vyatta-clear-vrrp.pl | 65 ++++-------- scripts/keepalived/vyatta-keepalived.pl | 176 +++++++++----------------------- scripts/keepalived/vyatta-show-vrrp.pl | 24 ++--- scripts/keepalived/vyatta-vrrp-state.pl | 6 +- 4 files changed, 84 insertions(+), 187 deletions(-) (limited to 'scripts/keepalived') diff --git a/scripts/keepalived/vyatta-clear-vrrp.pl b/scripts/keepalived/vyatta-clear-vrrp.pl index ba5d569b..3a9733ed 100644 --- a/scripts/keepalived/vyatta-clear-vrrp.pl +++ b/scripts/keepalived/vyatta-clear-vrrp.pl @@ -25,6 +25,9 @@ use lib '/opt/vyatta/share/perl5/'; use Vyatta::Keepalived; +use Vyatta::Interface; +use Vyatta::Misc; + use Getopt::Long; use Sys::Syslog qw(:standard :macros); @@ -108,51 +111,23 @@ sub get_vrrp_intf_group { # # return an array of hashes that contains all the intf/group pairs # - - foreach my $type (("ethernet", "bonding")) { - - my $config = new Vyatta::Config; - $config->setLevel("interfaces $type"); - my @eths = $config->listOrigNodes(); - foreach my $eth (@eths) { - my $path = "interfaces $type $eth"; - $config->setLevel($path); - if ($config->existsOrig("vrrp")) { - $path = "$path vrrp vrrp-group"; - $config->setLevel($path); - my @groups = $config->listOrigNodes(); - foreach my $group (@groups) { - my %hash; - $hash{'intf'} = $eth; - $hash{'group'} = $group; - $hash{'path'} = "$path $group"; - push @array, {%hash}; - } - } - - $path = "interfaces $type $eth"; + my $config = new Vyatta::Config; + + foreach my $name ( getInterfaces() ) { + my $intf = new Vyatta::Interface($name); + next unless $intf; + my $path = $intf->path(); + $config->setLevel($path); + if ($config->existsOrig('vrrp')) { + $path = "$path vrrp vrrp-group"; $config->setLevel($path); - if ($config->existsOrig('vif')) { - my $path = "$path vif"; - $config->setLevel($path); - my @vifs = $config->listOrigNodes(); - foreach my $vif (@vifs) { - my $vif_intf = $eth . '.' . $vif; - my $vif_path = "$path $vif"; - $config->setLevel($vif_path); - if ($config->existsOrig('vrrp')) { - $vif_path = "$vif_path vrrp vrrp-group"; - $config->setLevel($vif_path); - my @groups = $config->listOrigNodes(); - foreach my $group (@groups) { - my %hash; - $hash{'intf'} = $vif_intf; - $hash{'group'} = $group; - $hash{'path'} = "$path $group"; - push @array, {%hash}; - } - } - } + my @groups = $config->listOrigNodes(); + foreach my $group (@groups) { + my %hash; + $hash{'intf'} = $name; + $hash{'group'} = $group; + $hash{'path'} = "$path $group"; + push @array, {%hash}; } } } @@ -207,7 +182,7 @@ my $login = getlogin(); # # clear_process # -if ($action eq "clear_process") { +if ($action eq 'clear_process') { syslog('warning', "clear vrrp process requested by $login"); if (Vyatta::Keepalived::is_running()) { print "Restarting VRRP...\n"; diff --git a/scripts/keepalived/vyatta-keepalived.pl b/scripts/keepalived/vyatta-keepalived.pl index 842f8bc3..e87c9f64 100755 --- a/scripts/keepalived/vyatta-keepalived.pl +++ b/scripts/keepalived/vyatta-keepalived.pl @@ -235,65 +235,30 @@ sub vrrp_find_changes { my $config = new Vyatta::Config; my $vrrp_instances = 0; - foreach my $type (("ethernet", "bonding")) { - - $config->setLevel("interfaces $type"); - my @eths = $config->listNodes(); - foreach my $eth (@eths) { - my $path = "interfaces $type $eth"; - $config->setLevel($path); - if ($config->exists("vrrp")) { - my %vrrp_status_hash = $config->listNodeStatus("vrrp"); - my ($vrrp, $vrrp_status) = each(%vrrp_status_hash); - if ($vrrp_status ne "static") { - push @list, $eth; - vrrp_log("$vrrp_status found $eth"); - } - } - if ($config->exists("vif")) { - my $path = "interfaces $type $eth vif"; - $config->setLevel($path); - my @vifs = $config->listNodes(); - foreach my $vif (@vifs) { - my $vif_intf = $eth . "." . $vif; - my $vif_path = "$path $vif"; - $config->setLevel($vif_path); - if ($config->exists("vrrp")) { - my %vrrp_status_hash = $config->listNodeStatus("vrrp"); - my ($vrrp, $vrrp_status) = each(%vrrp_status_hash); - if ($vrrp_status ne "static") { - push @list, "$eth.$vif"; - vrrp_log("$vrrp_status found $eth.$vif"); - } - } - } + foreach my $name ( getInterfaces() ) { + my $intf = new Vyatta::Interface($name); + next unless $intf; + my $path = $intf->path(); + $config->setLevel($path); + if ($config->exists("vrrp")) { + my %vrrp_status_hash = $config->listNodeStatus("vrrp"); + my ($vrrp, $vrrp_status) = each(%vrrp_status_hash); + if ($vrrp_status ne "static") { + push @list, $name; + vrrp_log("$vrrp_status found $name"); } } # # Now look for deleted from the origin tree # - $config->setLevel("interfaces $type"); - @eths = $config->listOrigNodes(); - foreach my $eth (@eths) { - my $path = "interfaces $type $eth"; - $config->setLevel($path); - if ($config->isDeleted("vrrp")) { - push @list, $eth; - vrrp_log("Delete found $eth"); - } - $config->setLevel("$path vif"); - my @vifs = $config->listOrigNodes(); - foreach my $vif (@vifs) { - my $vif_intf = $eth . "." . $vif; - my $vif_path = "$path vif $vif"; - $config->setLevel($vif_path); - if ($config->isDeleted("vrrp")) { - push @list, "$eth.$vif"; - vrrp_log("Delete found $eth.$vif"); - } - } + $config->setLevel($path); + if ($config->isDeleted("vrrp")) { + push @list, $name; + vrrp_log("Delete found $name"); } + + } my $num = scalar(@list); @@ -344,51 +309,28 @@ sub vrrp_update_config { my $config = new Vyatta::Config; my $vrrp_instances = 0; - for my $type (("ethernet", "bonding")) { - - $config->setLevel("interfaces $type"); - my @eths = $config->listNodes(); - foreach my $eth (@eths) { - my $path = "interfaces $type $eth"; - $config->setLevel($path); - if ($config->exists("vrrp")) { - my ($inst_output, @inst_errs) = - keepalived_get_values($eth, $path); - if (scalar(@inst_errs)) { - push @errs, @inst_errs; - } else { - $output .= $inst_output; - $vrrp_instances++; - } + foreach my $name ( getInterfaces() ) { + my $intf = new Vyatta::Interface($name); + next unless $intf; + my $path = $intf->path(); + $config->setLevel($path); + if ($config->exists("vrrp")) { + # + # keepalived gets real grumpy with interfaces that + # don't exist, so skip vlans that haven't been + # instantiated yet (typically occurs at boot up). + # + if (!(-d "/sys/class/net/$name")) { + push @errs, "$name doesn't exist"; + next; } - if ($config->exists("vif")) { - my $path = "interfaces $type $eth vif"; - $config->setLevel($path); - my @vifs = $config->listNodes(); - foreach my $vif (@vifs) { - my $vif_path = "$path $vif"; - $config->setLevel($vif_path); - if ($config->exists("vrrp")) { - # - # keepalived gets real grumpy with interfaces that - # don't exist, so skip vlans that haven't been - # instantiated yet (typically occurs at boot up). - # - my $vif_intf = $eth . "." . $vif; - if (!(-d "/sys/class/net/$vif_intf")) { - push @errs, "vlan doesn't exist $vif_intf"; - next; - } - my ($inst_output, @inst_errs) = - keepalived_get_values($vif_intf, $vif_path); - if (scalar(@inst_errs)) { - push @errs, @inst_errs; - } else { - $output .= $inst_output; - $vrrp_instances++; - } - } - } + my ($inst_output, @inst_errs) = + keepalived_get_values($name, $path); + if (scalar(@inst_errs)) { + push @errs, @inst_errs; + } else { + $output .= $inst_output; + $vrrp_instances++; } } } @@ -415,27 +357,14 @@ sub list_vrrp_intf { my $config = new Vyatta::Config; my @intfs = (); - foreach my $type (("ethernet", "bonding")) { - - $config->setLevel("interfaces $type"); - my @eths = $config->listOrigNodes(); - foreach my $eth (@eths) { - my $path = "interfaces $type $eth"; - $config->setLevel($path); - push @intfs, $eth if $config->existsOrig("vrrp"); - if ($config->existsOrig("vif")) { - my $path = "interfaces $type $eth vif"; - $config->setLevel($path); - my @vifs = $config->listOrigNodes(); - foreach my $vif (@vifs) { - my $vif_intf = $eth . "." . $vif; - my $vif_path = "$path $vif"; - $config->setLevel($vif_path); - push @intfs, $vif_intf if $config->existsOrig("vrrp"); - } - } - } + foreach my $name ( getInterfaces() ) { + my $intf = new Vyatta::Interface($name); + next unless $intf; + my $path = $intf->path(); + $config->setLevel($path); + push @intfs, $name if $config->existsOrig("vrrp"); } + return @intfs; } @@ -443,17 +372,10 @@ sub list_vrrp_group { my ($name) = @_; my $config = new Vyatta::Config; my $path; - if ($name =~ /bond/) { - $path = "interfaces bonding $name"; - if ($name =~ /(bond\d+)\.(\d+)/) { - $path = "interfaces bonding $1 vif $2"; - } - } else { - $path = "interfaces ethernet $name"; - if ($name =~ /(eth\d+)\.(\d+)/) { - $path = "interfaces ethernet $1 vif $2"; - } - } + + my $intf = new Vyatta::Interface($name); + next unless $intf; + $path = $intf->path(); $path .= " vrrp vrrp-group"; $config->setLevel($path); my @groups = $config->listOrigNodes(); diff --git a/scripts/keepalived/vyatta-show-vrrp.pl b/scripts/keepalived/vyatta-show-vrrp.pl index 5ec2e8ad..521abc7f 100755 --- a/scripts/keepalived/vyatta-show-vrrp.pl +++ b/scripts/keepalived/vyatta-show-vrrp.pl @@ -24,6 +24,7 @@ # use lib "/opt/vyatta/share/perl5/"; use Vyatta::Keepalived; +use Vyatta::Interface; use strict; use warnings; @@ -65,23 +66,22 @@ sub elapse_time { } sub get_state_link { - my $intf = shift; + my $intf_name = shift; - my $IFF_UP = 0x1; + my $intf = new Vyatta::Interface($intf_name); + die "Unknown interface [$intf_name]" unless $intf; + my ($state, $link); - my $flags = `cat /sys/class/net/$intf/flags 2> /dev/null`; - my $carrier = `cat /sys/class/net/$intf/carrier 2> /dev/null`; - chomp $flags; chomp $carrier; - my $hex_flags = hex($flags); - if ($hex_flags & $IFF_UP) { - $state = "up"; + if ($intf->up()) { + $state = 'up'; } else { - $state = "admin down"; + $state = 'admin down'; } - if ($carrier eq "1") { - $link = "up"; + + if ($intf->carrier()) { + $link = 'up'; } else { - $link = "down"; + $link = 'down'; } return ($state, $link); } diff --git a/scripts/keepalived/vyatta-vrrp-state.pl b/scripts/keepalived/vyatta-vrrp-state.pl index 930c7cd0..9bb54a0c 100755 --- a/scripts/keepalived/vyatta-vrrp-state.pl +++ b/scripts/keepalived/vyatta-vrrp-state.pl @@ -66,10 +66,10 @@ if (defined $old_state and $vrrp_state eq $old_state) { Vyatta::Keepalived::vrrp_log("$vrrp_intf $vrrp_group transition to $vrrp_state"); vrrp_state_log($vrrp_state, $vrrp_intf, $vrrp_group); -if ($vrrp_state eq "backup") { +if ($vrrp_state eq 'backup') { Vyatta::Keepalived::snoop_for_master($vrrp_intf, $vrrp_group, $vrrp_vips[0], 60); -} elsif ($vrrp_state eq "master") { +} elsif ($vrrp_state eq 'master') { # # keepalived will send gratuitous arp requests on master transition # but some hosts do not update their arp cache for gratuitous arp @@ -87,7 +87,7 @@ if ($vrrp_state eq "backup") { system("rm -f $mfile"); } -if (!($vrrp_transitionscript eq "null")){ +if (!($vrrp_transitionscript eq 'null')){ exec("$vrrp_transitionscript"); } -- cgit v1.2.3 From 2fe988d11ef39bab3351fed3e9df341c94c5773d Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 1 Nov 2009 11:27:52 -0800 Subject: Fix interface carrier status. --- scripts/keepalived/vyatta-show-vrrp.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/keepalived') diff --git a/scripts/keepalived/vyatta-show-vrrp.pl b/scripts/keepalived/vyatta-show-vrrp.pl index 521abc7f..545e0e5c 100755 --- a/scripts/keepalived/vyatta-show-vrrp.pl +++ b/scripts/keepalived/vyatta-show-vrrp.pl @@ -78,7 +78,7 @@ sub get_state_link { $state = 'admin down'; } - if ($intf->carrier()) { + if ($intf->carrier() == 1) { $link = 'up'; } else { $link = 'down'; -- cgit v1.2.3 From 68b78c10964589e1d8bff35403e6d9b8e2d7378d Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 1 Nov 2009 12:43:24 -0800 Subject: Fix 'show vrrp summary' showing last vip 1st --- scripts/keepalived/vyatta-show-vrrp.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/keepalived') diff --git a/scripts/keepalived/vyatta-show-vrrp.pl b/scripts/keepalived/vyatta-show-vrrp.pl index 545e0e5c..d23d0472 100755 --- a/scripts/keepalived/vyatta-show-vrrp.pl +++ b/scripts/keepalived/vyatta-show-vrrp.pl @@ -188,7 +188,7 @@ sub vrrp_showsummary { my ($primary_addr, $priority, $preempt, $advert_int, $auth_type, @vips) = Vyatta::Keepalived::vrrp_get_config($intf, $group); my $format = "\n%-16s%-8s%-8s%-16s%-16s%-16s"; - my $vip = pop @vips; + my $vip = shift @vips; printf($format, $intf, $group, 'vip', $vip, $link, $state); foreach my $vip (@vips){ printf("\n%-24s%-8s%-16s", ' ', 'vip', $vip); -- cgit v1.2.3 From 8856e639e86ff6da29d7d8e7b4003dd8c585afaf Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 1 Nov 2009 14:19:45 -0800 Subject: Using Interface.pm infrastructure to detect vif on eth|bond interface. --- scripts/keepalived/vyatta-show-vrrp.pl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'scripts/keepalived') diff --git a/scripts/keepalived/vyatta-show-vrrp.pl b/scripts/keepalived/vyatta-show-vrrp.pl index d23d0472..bcc6ca29 100755 --- a/scripts/keepalived/vyatta-show-vrrp.pl +++ b/scripts/keepalived/vyatta-show-vrrp.pl @@ -96,7 +96,7 @@ sub parse_arping { my @lines = <$FD>; close $FD; - my $mac = ''; + my $mac = undef; foreach my $line (@lines) { # regex for xx:xx:xx:xx:xx:xx if ($line =~ /(([0-9A-Fa-f]{1,2}:){5}[0-9A-Fa-f]{1,2})/) { @@ -128,11 +128,13 @@ sub get_master_info { my $arp_file = "$master_file.arp"; my $source_ip = (vrrp_get_config($intf, $group))[0]; - # arping doesn't seem to work for vlans - if ($intf =~ /(eth\d+|bond\d+).\d+/) { - $intf = $1; + my $interface = new Vyatta::Interface($intf); + my $arp_intf = $intf; + if ($interface->vif()) { + $arp_intf = $interface->physicalDevice(); } - system("/usr/bin/arping -c1 -f -I $intf -s $source_ip $vip > $arp_file"); + my $cmd = "/usr/bin/arping -c1 -f -I $arp_intf -s $source_ip $vip"; + system("$cmd > $arp_file"); my $arp_mac = parse_arping($arp_file); if ( ! -f $master_file) { @@ -149,7 +151,7 @@ sub get_master_info { $master_mac =~ /show=\"(([0-9A-Fa-f]{1,2}:){5}[0-9A-Fa-f]{1,2})/) { $master_mac = uc($1); - if ($arp_mac ne $master_mac) { + if (defined($arp_mac) and ($arp_mac ne $master_mac)) { Vyatta::Keepalived::snoop_for_master($intf, $group, $vip, 2); $master_ip = `grep ip.src $master_file 2> /dev/null`; } @@ -172,7 +174,7 @@ sub get_master_info { $priority = "unknown"; } - return ($master_ip, $priority, $arp_mac); + return ($master_ip, $priority, $master_mac); } else { return ('unknown', 'unknown', ''); } -- cgit v1.2.3