diff options
Diffstat (limited to 'lib/Vyatta')
-rwxr-xr-x | lib/Vyatta/Config.pm | 38 | ||||
-rwxr-xr-x | lib/Vyatta/ConfigLoad.pm | 95 | ||||
-rwxr-xr-x | lib/Vyatta/Interface.pm | 12 | ||||
-rwxr-xr-x | lib/Vyatta/Misc.pm | 26 | ||||
-rwxr-xr-x | lib/Vyatta/TypeChecker.pm | 6 |
5 files changed, 85 insertions, 92 deletions
diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm index fd0222f..c97152c 100755 --- a/lib/Vyatta/Config.pm +++ b/lib/Vyatta/Config.pm @@ -98,6 +98,31 @@ sub listNodes { return @nodes_modified; } +## isActive("path") +# return true|false based on whether node path has +# been processed or is active +sub isActive { + my ($self, $path) = @_; + my @nodes = (); + + my @comp_node = split " ", $path; + + my $comp_node = pop(@comp_node); + if (!defined $comp_node) { + return 1; + } + + my $rel_path = join(" ",@comp_node); + + my @nodes_modified = $self->listOrigPlusComNodes($rel_path); + foreach my $node (@nodes_modified) { + if ($node eq $comp_node) { + return 0; + } + } + return 1; +} + ## listNodes("level") # return array of all nodes (active plus currently committed) at "level" # level is relative @@ -105,7 +130,7 @@ sub listOrigPlusComNodes { my ($self, $path) = @_; my @nodes = (); - my @nodes_modified = $self->listNodes(); + my @nodes_modified = $self->listNodes($path); #convert array to hash my %coll; @@ -113,6 +138,9 @@ sub listOrigPlusComNodes { @coll{@nodes_modified} = @nodes_modified; my $level = $self->{_level}; + if (! defined $level) { + $level = ""; + } #now test against the inprocess file in the system # my $com_file = "/tmp/.changes_$$"; @@ -125,6 +153,9 @@ sub listOrigPlusComNodes { #$coll is of the form: blah my $dir_path = $level; + if (defined $path) { + $dir_path .= " " . $path; + } $dir_path =~ s/ /\//g; $dir_path = "/".$dir_path; @@ -143,8 +174,13 @@ sub listOrigPlusComNodes { $tmp = $node[1]; } + if (!defined $tmp || $tmp eq '') { + next; + } + my @child = split "/",$tmp; my $child; + # print("tmp: $tmp, $child[0], $child[1]\n"); if ($child[0] =~ /^\s*$/ || !defined $child[0] || $child[0] eq '') { shift(@child); diff --git a/lib/Vyatta/ConfigLoad.pm b/lib/Vyatta/ConfigLoad.pm index 09bd627..8ffc9c0 100755 --- a/lib/Vyatta/ConfigLoad.pm +++ b/lib/Vyatta/ConfigLoad.pm @@ -27,55 +27,6 @@ use lib "/opt/vyatta/share/perl5"; use XorpConfigParser; use Vyatta::Config; -# configuration ordering. higher rank configured before lower rank. -my $default_rank = 0; -my %config_rank = ( - 'qos-policy' => 1110, - 'firewall group' => 1100, - 'firewall' => 1090, - 'service nat' => 1080, - 'system host-name' => 1070, - 'protocols ospf parameters' => 1060, - 'protocols ospf' => 1055, - 'protocols rip interface' => 905, - 'protocols rip' => 1050, - 'interfaces' => 1000, - 'interfaces bonding' => 995, - 'interfaces bridge' => 990, - 'interfaces ethernet' => 980, - 'interfaces tunnel' => 910, - 'zone-policy zone' => 900, - 'system gateway-address' => 890, - 'system name-server' => 880, - 'system login user' => 870, - 'system' => 860, - 'protocols static' => 850, - 'service ssh' => 840, - 'service telnet' => 830, - 'service webproxy' => 828, - 'service http' => 827, - 'service dhcp-relay' => 826, - 'service dhcp-server' => 825, - 'service dns' => 824, - 'service nat' => 823, - 'policy' => 820, - 'protocols bgp' => 790, - 'vpn' => 600, -); - -my %regex_rank = ( - 'interfaces ethernet \S* vrrp' => 500, - 'interfaces ethernet \S* vif \S* vrrp' => 500, - 'interfaces ethernet \S* pppo[ea]' => 400, - 'protocols bgp \d+ parameters' => 810, - 'protocols bgp \d+ neighbor \d+\.\d+\.\d+\.\d+' => 800, - 'protocols bgp \d+ neighbor \w+' => 801, - 'interfaces bridge \S* address' => 920, - 'zone-policy zone \S* interface' => 899, - 'zone-policy zone \S* local-zone' => 899, - 'zone-policy zone \S* from' => 898, -); - my @all_nodes = (); my @all_naked_nodes = (); @@ -85,30 +36,6 @@ sub match_regex { return ($str =~ m/$pattern/) ? 1 : 0; } -sub get_regex_rank { - my ($str) = @_; - foreach (keys %regex_rank) { - if (match_regex($_, $str)) { - return $regex_rank{$_}; - } - } - return; # undef if no match -} - -sub get_config_rank { - # longest prefix match - my @path = @_; - while ((scalar @path) > 0) { - my $path_str = join ' ', @path; - if (defined($config_rank{$path_str})) { - return ($config_rank{$path_str}); - } - my $wrank = get_regex_rank($path_str); - return $wrank if (defined($wrank)); - pop @path; - } - return $default_rank; -} sub applySingleQuote { my @return = (); @@ -161,12 +88,12 @@ sub enumerate_branch { } push @all_naked_nodes, [ @cur_path ]; my @qpath = applySingleQuote(@cur_path); - push @all_nodes, [\@qpath, get_config_rank(@cur_path)]; + push @all_nodes, [\@qpath, 0]; } } # $0: config file to load -# return: list of all config statement sorted by rank +# return: list of all config statement sub getStartupConfigStatements { # clean up the lists first @all_nodes = (); @@ -185,7 +112,6 @@ sub getStartupConfigStatements { } enumerate_branch($root, ( )); - @all_nodes = sort { ${$b}[1] <=> ${$a}[1] } @all_nodes; return @all_nodes; } @@ -280,8 +206,7 @@ sub getSortedMultiValues { my $key = "$path_str $_"; push @list, [ $_, $node_order{$key} ]; } - my @slist = sort { ${$a}[1] <=> ${$b}[1] } @list; - @slist = map { ${$_}[0] } @slist; + my @slist = map { ${$_}[0] } @list; return @slist; } @@ -309,7 +234,7 @@ sub findDeletedValues { my %comp_hash = $active_cfg->compareValueLists(\@ovals, \@nvals); foreach (@{$comp_hash{'deleted'}}) { my @plist = applySingleQuote(@active_path, $_); - push @delete_list, [\@plist, get_config_rank(@active_path, $_)]; + push @delete_list, [\@plist, 0]; } } else { # do nothing. if a single-value leaf node is deleted, it should have @@ -336,7 +261,7 @@ sub findDeletedNodes { } if (!defined($new_ref->{$_})) { my @plist = applySingleQuote(@active_path, $_); - push @delete_list, [\@plist, get_config_rank(@active_path, $_)]; + push @delete_list, [\@plist, 0]; } else { findDeletedNodes($new_ref->{$_}, [ @active_path, $_ ]); } @@ -364,7 +289,7 @@ sub findSetValues { my %comp_hash = $active_cfg->compareValueLists(\@ovals, \@nvals); foreach (@{$comp_hash{'added'}}) { my @plist = applySingleQuote(@active_path, $_); - push @set_list, [\@plist, get_config_rank(@active_path, $_)]; + push @set_list, [\@plist, 0]; } } else { my @nvals = keys %{$new_ref}; @@ -375,7 +300,7 @@ sub findSetValues { my $oval = $active_cfg->returnOrigValue(''); if (!defined($oval) || ($nval ne $oval)) { my @plist = applySingleQuote(@active_path, $nval); - push @set_list, [\@plist, get_config_rank(@active_path, $nval)]; + push @set_list, [\@plist, 0]; } } } @@ -400,7 +325,7 @@ sub findSetNodes { # check if we need to add this node. if (!defined($active_hash{$_})) { my @plist = applySingleQuote(@active_path, $_); - push @set_list, [\@plist, get_config_rank(@active_path, $_)]; + push @set_list, [\@plist, 0]; } else { # node already present. do nothing. } @@ -423,10 +348,6 @@ sub getConfigDiff { @delete_list = (); findDeletedNodes($new_cfg_ref, [ ]); findSetNodes($new_cfg_ref, [ ]); - # don't really need to sort the lists by rank since we have to commit - # everything together anyway. - @delete_list = sort { ${$a}[1] <=> ${$b}[1] } @delete_list; - @set_list = sort { ${$b}[1] <=> ${$a}[1] } @set_list; # need to filter out deletions of nodes with default values my @new_delete_list = (); diff --git a/lib/Vyatta/Interface.pm b/lib/Vyatta/Interface.pm index 96429c0..97ef7f7 100755 --- a/lib/Vyatta/Interface.pm +++ b/lib/Vyatta/Interface.pm @@ -222,6 +222,18 @@ sub flags { return hex($val); } +sub hw_address { + my $self = shift; + + open my $addrf, '<', "/sys/class/net/$self->{name}/address" + or return; + my $address = <$addrf>; + close $addrf; + + chomp $address if $address; + return $address; +} + sub is_broadcast { my $self = shift; return $self->flags() & IFF_BROADCAST; diff --git a/lib/Vyatta/Misc.pm b/lib/Vyatta/Misc.pm index 01f1537..6089361 100755 --- a/lib/Vyatta/Misc.pm +++ b/lib/Vyatta/Misc.pm @@ -93,11 +93,18 @@ sub generate_dhclient_intf_files { } +# get list of interfaces on the system via sysfs +# skip dot files (and any interfaces name .xxx) +# and bond_masters file used by bonding +# and wireless control interfaces sub getInterfaces { opendir( my $sys_class, '/sys/class/net' ) or die "can't open /sys/class/net: $!"; - my @interfaces = - grep { ( !/^\./ ) && ( $_ ne 'bonding_masters' ) } readdir $sys_class; + my @interfaces = grep { ( !/^\./ ) && + ( $_ ne 'bonding_masters' ) && + ! ( $_ =~ '^mon.wlan\d$') && + ! ( $_ =~ '^wmaster\d+$') + } readdir $sys_class; closedir $sys_class; return @interfaces; } @@ -225,7 +232,10 @@ sub isClusterIP { my @services = $vc->returnValues("cluster group $cluster_group service"); foreach my $service (@services) { - if ( $ip eq substr( $service, 0, index( $service, '/' ) ) ) { + if ($service =~ /\//) { + $service = substr( $service, 0, index( $service, '/' )); + } + if ( $ip eq $service ) { return 1; } } @@ -355,7 +365,15 @@ sub getPortRuleString { return ( undef, $err ); } } - ( $success, $err ) = isValidPortName( $port_spec, $proto ); + if ($proto eq 'tcp_udp') { + ( $success, $err ) = isValidPortName( $port_spec, 'tcp' ); + if (defined $success) { + # only do udp test if the tcp test was a success + ( $success, $err ) = isValidPortName( $port_spec, 'udp' ) + } + } else { + ( $success, $err ) = isValidPortName( $port_spec, $proto ); + } if ( defined($success) ) { $num_ports += 1; next; diff --git a/lib/Vyatta/TypeChecker.pm b/lib/Vyatta/TypeChecker.pm index 27d9e03..c13ef4b 100755 --- a/lib/Vyatta/TypeChecker.pm +++ b/lib/Vyatta/TypeChecker.pm @@ -91,6 +91,12 @@ sub validate_ipv4range { return 0 if (!/^([^-]+)-([^-]+)$/); my ($a1, $a2) = ($1, $2); return 0 if (!validate_ipv4($a1) || !validate_ipv4($a2)); + #need to check that range is in ascending order + $a1 =~ m/^(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)/; + my $v1 = $1*256*256*256+$2*256*256+$3*256+$4; + $a2 =~ m/^(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)\.(\d\d?\d?)/; + my $v2 = $1*256*256*256+$2*256*256+$3*256+$4; + return 0 if ($v1 > $v2); return 1; } |