summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2008-05-01 14:28:44 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2008-05-01 14:28:44 -0700
commit721439469c1146fd283ea219898f4d9b11c0db46 (patch)
treef9aad6723109fea84b91e313f463a6c17ade440c
parente1068de05de78e9a384b6f3740f8ee5bf5b3d41b (diff)
downloadvyatta-cfg-721439469c1146fd283ea219898f4d9b11c0db46.tar.gz
vyatta-cfg-721439469c1146fd283ea219898f4d9b11c0db46.zip
support "wildcard" ranking at boot time. only VRRP uses this for now.
-rwxr-xr-xscripts/VyattaConfigLoad.pm26
1 files changed, 26 insertions, 0 deletions
diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm
index 2efa81e..b69723a 100755
--- a/scripts/VyattaConfigLoad.pm
+++ b/scripts/VyattaConfigLoad.pm
@@ -44,9 +44,33 @@ my %config_rank = (
'vpn' => 80,
);
+my %wildcard_rank = (
+ 'interfaces ethernet * vrrp' => 50,
+ 'interfaces ethernet * vif * vrrp' => 50,
+);
+
my @all_nodes = ();
my @all_naked_nodes = ();
+# the wildcard matching could use some serious optimization. but probably
+# not when we only have a couple of entries.
+sub match_wildcard {
+ my ($pattern, $str) = @_;
+ $pattern =~ s/\*/\\S*/g;
+ $pattern =~ s/^(.*)$/\^$1\$/;
+ return ($str =~ m/$pattern/) ? 1 : 0;
+}
+
+sub get_wildcard_rank {
+ my ($str) = @_;
+ foreach (keys %wildcard_rank) {
+ if (match_wildcard($_, $str)) {
+ return $wildcard_rank{$_};
+ }
+ }
+ return undef;
+}
+
sub get_config_rank {
# longest prefix match
my @path = @_;
@@ -55,6 +79,8 @@ sub get_config_rank {
if (defined($config_rank{$path_str})) {
return ($config_rank{$path_str});
}
+ my $wrank = get_wildcard_rank($path_str);
+ return $wrank if (defined($wrank));
pop @path;
}
return $default_rank;