summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/Vyatta/Keepalived.pm44
1 files changed, 32 insertions, 12 deletions
diff --git a/lib/Vyatta/Keepalived.pm b/lib/Vyatta/Keepalived.pm
index 15f2db2..7ded8a5 100755
--- a/lib/Vyatta/Keepalived.pm
+++ b/lib/Vyatta/Keepalived.pm
@@ -29,7 +29,8 @@ our @EXPORT = qw(get_conf_file get_state_script get_state_file
vrrp_log vrrp_get_init_state get_changes_file
start_daemon restart_daemon stop_daemon
vrrp_get_config list_vrrp_intf list_vrrp_group
- list_vrrp_sync_group list_all_vrrp_sync_grps);
+ list_vrrp_sync_group list_all_vrrp_sync_grps
+ vrrp_get_primary_addr);
use base qw(Exporter);
use Vyatta::Config;
@@ -186,15 +187,11 @@ sub get_state_files {
return @state_files;
}
-#
-# this is meant to be called from op mode, so Orig functions are used.
-#
-sub vrrp_get_config {
- my ($intf, $group) = @_;
+sub vrrp_get_primary_addr {
+ my ($intf) = @_;
my $path;
my $config = new Vyatta::Config;
-
my $interface = new Vyatta::Interface($intf);
die "Unknown interface type: $intf" unless $interface;
@@ -202,15 +199,38 @@ sub vrrp_get_config {
$config->setLevel($path);
# don't use getIP() to get IP addresses because we only
# want configured addresses, not vrrp VIP addresses.
- my @addr = $config->returnOrigValues('address');
- my $primary_addr = shift @addr;
- if (!defined $primary_addr or $primary_addr eq 'dhcp') {
- $primary_addr = "0.0.0.0";
+ my @addrs = ();
+ if ($config->inSession) {
+ @addrs = $config->returnValues('address');
+ } else {
+ @addrs = $config->returnOrigValues('address');
}
- if ($primary_addr =~ m/(\d+\.\d+\.\d+\.\d+)\/\d+/) {
+ my $primary_addr = shift @addrs;
+
+ if (defined $primary_addr and
+ $primary_addr =~ m/(\d+\.\d+\.\d+\.\d+)\/\d+/) {
$primary_addr = $1; # strip /mask
}
+ return $primary_addr;
+}
+#
+# this is meant to be called from op mode, so Orig functions are used.
+#
+sub vrrp_get_config {
+ my ($intf, $group) = @_;
+
+ my $path;
+ my $config = new Vyatta::Config;
+ my $interface = new Vyatta::Interface($intf);
+ die "Unknown interface type: $intf" unless $interface;
+
+ my $primary_addr = vrrp_get_primary_addr($intf);
+ if (!defined $primary_addr or $primary_addr eq 'dhcp') {
+ $primary_addr = "0.0.0.0";
+ }
+
+ $path = $interface->path();
$config->setLevel("$path vrrp vrrp-group $group");
my $source_addr = $config->returnOrigValue("hello-source-address");
$primary_addr = $source_addr if defined $source_addr;