summaryrefslogtreecommitdiff
path: root/scripts/keepalived/vyatta-keepalived.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/keepalived/vyatta-keepalived.pl')
-rwxr-xr-xscripts/keepalived/vyatta-keepalived.pl225
1 files changed, 121 insertions, 104 deletions
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);