From 721439469c1146fd283ea219898f4d9b11c0db46 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Thu, 1 May 2008 14:28:44 -0700 Subject: support "wildcard" ranking at boot time. only VRRP uses this for now. --- scripts/VyattaConfigLoad.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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; -- cgit v1.2.3