From db1b44563e05c1eb1f5d8bd475c3ed1250307aeb Mon Sep 17 00:00:00 2001 From: "David S. Madole" Date: Sun, 27 Sep 2009 15:27:54 -0400 Subject: Add VRRP capability to bonding interfaces and vifs of bonding interfaces. --- lib/Vyatta/Keepalived.pm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Keepalived.pm b/lib/Vyatta/Keepalived.pm index 96d4fe9..c34d277 100755 --- a/lib/Vyatta/Keepalived.pm +++ b/lib/Vyatta/Keepalived.pm @@ -153,10 +153,18 @@ sub vrrp_get_config { my $path; my $config = new Vyatta::Config; - if ($intf =~ m/(eth\d+)\.(\d+)/) { - $path = "interfaces ethernet $1 vif $2"; + if ($intf =~ m/bond/) { + if ($intf =~ m/(bond\d+)\.(\d+)/) { + $path = "interfaces bonding $1 vif $2"; + } else { + $path = "interfaces bonding $intf"; + } } else { - $path = "interfaces ethernet $intf"; + if ($intf =~ m/(eth\d+)\.(\d+)/) { + $path = "interfaces ethernet $1 vif $2"; + } else { + $path = "interfaces ethernet $intf"; + } } $config->setLevel($path); -- cgit v1.2.3 From 07219b06b85cf401a661075f289df5d01421b5c7 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 1 Nov 2009 09:55:20 -0800 Subject: Add method to retrieve carrier value. --- lib/Vyatta/Interface.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index 97ef7f7..8107eff 100755 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -222,6 +222,17 @@ sub flags { return hex($val); } +sub carrier { + my $self = shift; + open my $carrier, '<', "/sys/class/net/$self->{name}/carrier" + or return; + + my $val = <$carrier>; + chomp $val; + close $carrier; + return $carrier; +} + sub hw_address { my $self = shift; -- cgit v1.2.3 From b6d02c359796ac0c47a4214a2fee827ad5d61d47 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 1 Nov 2009 09:58:19 -0800 Subject: Convert keepalived to use Interface infrastructure. --- lib/Vyatta/Keepalived.pm | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Keepalived.pm b/lib/Vyatta/Keepalived.pm index c34d277..13966c5 100755 --- a/lib/Vyatta/Keepalived.pm +++ b/lib/Vyatta/Keepalived.pm @@ -152,21 +152,11 @@ sub vrrp_get_config { my $path; my $config = new Vyatta::Config; - - if ($intf =~ m/bond/) { - if ($intf =~ m/(bond\d+)\.(\d+)/) { - $path = "interfaces bonding $1 vif $2"; - } else { - $path = "interfaces bonding $intf"; - } - } else { - if ($intf =~ m/(eth\d+)\.(\d+)/) { - $path = "interfaces ethernet $1 vif $2"; - } else { - $path = "interfaces ethernet $intf"; - } - } + my $interface = new Vyatta::Interface($intf); + die "Unknown interface type: $intf" unless $interface; + + $path = $interface->path(); $config->setLevel($path); my $primary_addr = $config->returnOrigValue("address"); if (!defined $primary_addr) { -- cgit v1.2.3 From 664bb2cd4f4cd1a9597cfb32962a582b0f56e39a Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 1 Nov 2009 11:48:08 -0800 Subject: Fix carrier method. --- lib/Vyatta/Interface.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index 8107eff..90880c7 100755 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -230,7 +230,7 @@ sub carrier { my $val = <$carrier>; chomp $val; close $carrier; - return $carrier; + return $var; } sub hw_address { -- cgit v1.2.3 From 20512f3b1ce6fc6464b14f49b113fe010c37d375 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 1 Nov 2009 11:49:00 -0800 Subject: Add natural order sort. --- lib/Vyatta/Keepalived.pm | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Keepalived.pm b/lib/Vyatta/Keepalived.pm index 13966c5..6d6a153 100755 --- a/lib/Vyatta/Keepalived.pm +++ b/lib/Vyatta/Keepalived.pm @@ -125,21 +125,56 @@ sub get_master_file { return $file; } +sub alphanum_split { + my ($str) = @_; + my @list = split m/(?=(?<=\D)\d|(?<=\d)\D)/, $str; + return @list; +} + +sub natural_order { + my ($a, $b) = @_; + my @a = alphanum_split($a); + my @b = alphanum_split($b); + + while (@a && @b) { + my $a_seg = shift @a; + my $b_seg = shift @b; + my $val; + if (($a_seg =~ /\d/) && ($b_seg =~ /\d/)) { + $val = $a_seg <=> $b_seg; + } elsif (($a_seg eq '.') && ($b_seg eq '_')) { + return 1; + } else { + $val = $a_seg cmp $b_seg; + } + if ($val != 0) { + return $val; + } + } + return @a <=> @b; +} + +sub intf_sort { + my @a = @_; + my @new_a = sort { natural_order($a,$b) } @a; + return @new_a; +} + sub get_state_files { my ($intf, $group) = @_; - # todo: fix sorting for ethX > 9 my @state_files; my $LS; if ($group eq "all") { - open($LS,"ls $state_dir |grep '^vrrpd_$intf.*\.state\$' | sort |"); + open($LS,"ls $state_dir |grep '^vrrpd_$intf.*\.state\$' |"); } else { my $intf_group = $intf . "_" . $group . ".state"; open($LS, - "ls $state_dir |grep '^vrrpd_$intf_group\$' | sort |"); + "ls $state_dir |grep '^vrrpd_$intf_group\$' |"); } @state_files = <$LS>; close($LS); + @state_files = intf_sort(@state_files); foreach my $i (0 .. $#state_files) { $state_files[$i] = "$state_dir/$state_files[$i]"; } -- cgit v1.2.3 From 34d2d13c3763ae8c603195dd97d78da5f8e9a5ce Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Sun, 1 Nov 2009 12:44:17 -0800 Subject: Fix spelling error in carrier method. --- lib/Vyatta/Interface.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index 90880c7..924058a 100755 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -230,7 +230,7 @@ sub carrier { my $val = <$carrier>; chomp $val; close $carrier; - return $var; + return $val; } sub hw_address { -- cgit v1.2.3 From 70ba0c76a9c7c7699e1b2f612277d56d99828a49 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Tue, 3 Nov 2009 11:21:23 -0800 Subject: Fix uninitialized variable when reading carrier on admin down interface. --- lib/Vyatta/Interface.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index 924058a..ce909f0 100755 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -228,6 +228,7 @@ sub carrier { or return; my $val = <$carrier>; + $val = 0 if ! defined $val # proc entry not readable on down interface chomp $val; close $carrier; return $val; -- cgit v1.2.3 From 198f9a033a8d9cdb2220579cc2df1484476b2c93 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Wed, 4 Nov 2009 08:15:57 -0800 Subject: Fix missing semicolon. --- lib/Vyatta/Interface.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index ce909f0..513f686 100755 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -228,7 +228,7 @@ sub carrier { or return; my $val = <$carrier>; - $val = 0 if ! defined $val # proc entry not readable on down interface + $val = 0 if ! defined $val; # proc entry not readable on down interface chomp $val; close $carrier; return $val; -- cgit v1.2.3