summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStig Thormodsrud <stig@vyatta.com>2007-12-18 09:53:24 -0800
committerStig Thormodsrud <stig@vyatta.com>2007-12-18 09:53:24 -0800
commit1802eb010fb9b382dde4d3e1574fd578027c7dc0 (patch)
treee4ca0eb10e1a7bb0dedcf5c5a145200f802436f0 /scripts
parent36af5914de982f2770fba137c4beea9077cc6adb (diff)
downloadvyatta-cfg-quagga-1802eb010fb9b382dde4d3e1574fd578027c7dc0.tar.gz
vyatta-cfg-quagga-1802eb010fb9b382dde4d3e1574fd578027c7dc0.zip
- Add support for multiple vrrp groups per interface.
- Add support for multiple VIPs per vrrp group.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/keepalived/VyattaKeepalived.pm17
-rwxr-xr-xscripts/keepalived/vyatta-keepalived.pl121
-rwxr-xr-xscripts/keepalived/vyatta-show-vrrp.pl21
3 files changed, 91 insertions, 68 deletions
diff --git a/scripts/keepalived/VyattaKeepalived.pm b/scripts/keepalived/VyattaKeepalived.pm
index c2d446e4..e0e84af3 100755
--- a/scripts/keepalived/VyattaKeepalived.pm
+++ b/scripts/keepalived/VyattaKeepalived.pm
@@ -129,6 +129,17 @@ sub get_state_files {
return @state_files;
}
+sub get_vips_per_intf {
+ my ($intf) = @_;
+
+ my $config = new VyattaConfig;
+ my @groups = ();
+
+ $config->setLevel("interfaces ethernet $intf vrrp vrrp-group");
+ @groups = $config->listOrigNodes();
+ return scalar(@groups);
+}
+
sub vrrp_get_config {
my ($intf, $group) = @_;
@@ -144,8 +155,8 @@ sub vrrp_get_config {
$primary_addr = $1;
}
- $config->setLevel("interfaces ethernet $intf vrrp");
- my $vip = $config->returnOrigValue("virtual-address");
+ $config->setLevel("interfaces ethernet $intf vrrp vrrp-group $group");
+ my @vips = $config->returnOrigValues("virtual-address");
my $priority = $config->returnOrigValue("priority");
if (!defined $priority) {
$priority = 1;
@@ -165,7 +176,7 @@ sub vrrp_get_config {
} else {
$auth_type = uc($auth_type);
}
- return ($primary_addr, $vip, $priority, $preempt, $advert_int, $auth_type);
+ return ($primary_addr, $priority, $preempt, $advert_int, $auth_type, @vips);
}
sub vrrp_state_parse {
diff --git a/scripts/keepalived/vyatta-keepalived.pl b/scripts/keepalived/vyatta-keepalived.pl
index 15346855..e9df03df 100755
--- a/scripts/keepalived/vyatta-keepalived.pl
+++ b/scripts/keepalived/vyatta-keepalived.pl
@@ -38,72 +38,75 @@ use warnings;
sub keepalived_get_values {
my ($intf) = @_;
- my $output;
+ my $output = '';
my $config = new VyattaConfig;
- $config->setLevel("interfaces ethernet $intf vrrp");
- my $group = $config->returnValue("vrrp-group");
- if (!defined $group) {
- $group = 1;
- }
- my $vip = $config->returnValue("virtual-address");
- if (!defined $vip) {
- print "must define a virtual-address for vrrp-group $group\n";
- exit 1;
- }
- my $priority = $config->returnValue("priority");
- if (!defined $priority) {
- $priority = 1;
- }
- my $preempt = $config->returnValue("preempt");
- if (!defined $preempt) {
- $preempt = "true";
- }
- my $advert_int = $config->returnValue("advertise-interval");
- if (!defined $advert_int) {
- $advert_int = 1;
- }
- $config->setLevel("interfaces ethernet $intf vrrp authentication");
- my $auth_type = $config->returnValue("type");
- my $auth_pass;
- if (defined $auth_type) {
- $auth_type = uc($auth_type);
- $auth_pass = $config->returnValue("password");
- if (! defined $auth_pass) {
- print "vrrp authentication password not set";
+ my $state_transition_script = VyattaKeepalived::get_state_script();
+
+ $config->setLevel("interfaces ethernet $intf vrrp vrrp-group");
+ my @groups = $config->listNodes();
+ foreach my $group (@groups) {
+ $config->setLevel("interfaces ethernet $intf vrrp vrrp-group $group");
+ my @vips = $config->returnValues("virtual-address");
+ if (scalar(@vips) == 0) {
+ print "must define a virtual-address for vrrp-group $group\n";
exit 1;
}
- }
- my $state_transition_script = VyattaKeepalived::get_state_script();
+ my $priority = $config->returnValue("priority");
+ if (!defined $priority) {
+ $priority = 1;
+ }
+ my $preempt = $config->returnValue("preempt");
+ if (!defined $preempt) {
+ $preempt = "true";
+ }
+ my $advert_int = $config->returnValue("advertise-interval");
+ if (!defined $advert_int) {
+ $advert_int = 1;
+ }
+ $config->setLevel("interfaces ethernet $intf vrrp vrrp-group $group authentication");
+ my $auth_type = $config->returnValue("type");
+ my $auth_pass;
+ if (defined $auth_type) {
+ $auth_type = uc($auth_type);
+ $auth_pass = $config->returnValue("password");
+ if (! defined $auth_pass) {
+ print "vrrp authentication password not set";
+ exit 1;
+ }
+ }
- $output = "vrrp_instance vyatta-$intf-$group \{\n";
- if ($preempt eq "false") {
- $output .= "\tstate BACKUP\n";
- } else {
- $output .= "\tstate MASTER\n";
+ $output .= "vrrp_instance vyatta-$intf-$group \{\n";
+ if ($preempt eq "false") {
+ $output .= "\tstate BACKUP\n";
+ } else {
+ $output .= "\tstate MASTER\n";
}
- $output .= "\tinterface $intf\n";
- $output .= "\tvirtual_router_id $group\n";
- $output .= "\tpriority $priority\n";
- if ($preempt eq "false") {
- $output .= "\tnopreempt\n";
- }
- $output .= "\tadvert_int $advert_int\n";
- if (defined $auth_type) {
- $output .= "\tauthentication {\n";
- $output .= "\t\tauth_type $auth_type\n";
- $output .= "\t\tauth_pass $auth_pass\n\t}\n";
+ $output .= "\tinterface $intf\n";
+ $output .= "\tvirtual_router_id $group\n";
+ $output .= "\tpriority $priority\n";
+ if ($preempt eq "false") {
+ $output .= "\tnopreempt\n";
+ }
+ $output .= "\tadvert_int $advert_int\n";
+ if (defined $auth_type) {
+ $output .= "\tauthentication {\n";
+ $output .= "\t\tauth_type $auth_type\n";
+ $output .= "\t\tauth_pass $auth_pass\n\t}\n";
+ }
+ $output .= "\tvirtual_ipaddress \{\n";
+ foreach my $vip (@vips) {
+ $output .= "\t\t$vip\n";
+ }
+ $output .= "\t\}\n";
+ $output .= "\tnotify_master ";
+ $output .= "\"$state_transition_script master $intf $group @vips\" \n";
+ $output .= "\tnotify_backup ";
+ $output .= "\"$state_transition_script backup $intf $group @vips\" \n";
+ $output .= "\t notify_fault ";
+ $output .= "\"$state_transition_script fault $intf $group @vips\" \n";
+ $output .= "\}\n";
}
- $output .= "\tvirtual_ipaddress \{\n";
- $output .= "\t\t$vip\n";
- $output .= "\t\}\n";
- $output .= "\tnotify_master ";
- $output .= "\"$state_transition_script master $intf $group $vip\" \n";
- $output .= "\tnotify_backup ";
- $output .= "\"$state_transition_script backup $intf $group $vip\" \n";
- $output .= "\t notify_fault ";
- $output .= "\"$state_transition_script fault $intf $group $vip\" \n";
- $output .= "\}\n";
return $output;
}
diff --git a/scripts/keepalived/vyatta-show-vrrp.pl b/scripts/keepalived/vyatta-show-vrrp.pl
index 6540eaf5..934808f6 100755
--- a/scripts/keepalived/vyatta-show-vrrp.pl
+++ b/scripts/keepalived/vyatta-show-vrrp.pl
@@ -81,7 +81,7 @@ sub link_updown {
}
sub get_master_info {
- my ($intf, $group, $vip) = @_;
+ my ($intf, $group) = @_;
my $file = VyattaKeepalived::get_master_file($intf, $group);
if ( -f $file) {
@@ -113,18 +113,27 @@ sub vrrp_show {
VyattaKeepalived::vrrp_state_parse($file);
my $link = link_updown($intf);
if ($state eq "master" || $state eq "backup" || $state eq "fault") {
- my ($primary_addr, $vip, $priority, $preempt, $advert_int, $auth_type) =
- VyattaKeepalived::vrrp_get_config($intf, $group);
+ my ($primary_addr, $priority, $preempt, $advert_int, $auth_type,
+ @vips) = VyattaKeepalived::vrrp_get_config($intf, $group);
print "Physical interface: $intf, Address $primary_addr\n";
print " Interface state: $link, Group $group, State: $state\n";
print " Priority: $priority, Advertisement interval: $advert_int, ";
print "Authentication type: $auth_type\n";
- print " Preempt: $preempt, VIP count: 1, VIP: $vip\n";
+ my $vip_count = scalar(@vips);
+ my $string = " Preempt: $preempt, VIP count: $vip_count, VIP: ";
+ my $strlen = length($string);
+ print $string;
+ foreach my $vip (@vips) {
+ if ($vip_count != scalar(@vips)) {
+ print " " x $strlen;
+ }
+ print "$vip\n";
+ $vip_count--;
+ }
if ($state eq "master") {
print " Master router: $primary_addr\n";
} elsif ($state eq "backup") {
- my ($master_rtr, $master_prio) = get_master_info($intf,
- $group, $vip);
+ my ($master_rtr, $master_prio) = get_master_info($intf, $group);
print " Master router: $master_rtr, ";
print "Master Priority: $master_prio\n";
}