From fe238c4d57c81297e610326d3e94a3cd6f6a9c32 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Wed, 8 Jul 2009 17:27:57 -0700 Subject: load requires additional environment variables --- scripts/vyatta-cfg-cmd-wrapper | 2 ++ 1 file changed, 2 insertions(+) (limited to 'scripts') diff --git a/scripts/vyatta-cfg-cmd-wrapper b/scripts/vyatta-cfg-cmd-wrapper index 7496f96..8a73d17 100755 --- a/scripts/vyatta-cfg-cmd-wrapper +++ b/scripts/vyatta-cfg-cmd-wrapper @@ -152,6 +152,8 @@ case "$1" in RET_STATUS=$? ;; load) + export vyatta_sysconfdir=/opt/vyatta/etc + export vyatta_sbindir=/opt/vyatta/sbin /opt/vyatta/sbin/vyatta-load-config.pl "${@:2}" RET_STATUS=$? ;; -- cgit v1.2.3 From ac272fe8d44860c3f25f262d365ff2ce946f2286 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Tue, 14 Jul 2009 14:55:59 -0700 Subject: Fix 4722: Output inconsistent from 'save' and 'load' commands (cherry picked from commit abc33133b79759a629b14b81e6a65eed0fa23e8a) --- scripts/vyatta-load-config.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index a3cf6ef..f0dbaf1 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -175,7 +175,7 @@ syslog( "warning", "Load config [$orig_load_file] by $login" ); # do config migration system("$sbindir/vyatta_config_migrate.pl $load_file"); -print "Loading config file $load_file...\n"; +print "Loading configuration from '$load_file'...\n"; my %cfg_hier = Vyatta::ConfigLoad::loadConfigHierarchy($load_file,$merge); if ( scalar( keys %cfg_hier ) == 0 ) { print "The specified file does not contain any configuration.\n"; -- cgit v1.2.3 From 138cfe3b7213fa19c91d16114f3b377b8587d095 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Tue, 28 Jul 2009 17:07:00 -0700 Subject: alter rename rule option to work for firewall and nat rules --- scripts/vyatta-cfg-cmd-wrapper | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-cfg-cmd-wrapper b/scripts/vyatta-cfg-cmd-wrapper index 8a73d17..53a3fcc 100755 --- a/scripts/vyatta-cfg-cmd-wrapper +++ b/scripts/vyatta-cfg-cmd-wrapper @@ -157,18 +157,28 @@ case "$1" in /opt/vyatta/sbin/vyatta-load-config.pl "${@:2}" RET_STATUS=$? ;; - firewall-rule-rename) - # this option is to be used for renaming firewall rules only - # usage for this option specified on the next line - - # firewall-rule-rename $firewall_ruleset rule $rule_num to rule $rename_rulenum + rule-rename) + # this option is to be used for renaming firewall and nat rules only + # usage for this option specified on the next two lines - + # rule-rename firewall $firewall_ruleset rule $rule_num to rule $rename_rulenum + # rule-rename nat rule $rule_num to rule $rename_rulenum - VYATTA_TEMPLATE_LEVEL=/firewall/name/node.tag; - VYATTA_EDIT_LEVEL="/firewall/name/$2"; + if [ "$2" == "firewall" ]; then + VYATTA_TEMPLATE_LEVEL=/firewall/name/node.tag; + VYATTA_EDIT_LEVEL="/firewall/name/$3"; + elif [ "$2" == "nat" ]; then + VYATTA_TEMPLATE_LEVEL=/service/nat; + VYATTA_EDIT_LEVEL=/service/nat; + fi _mpath=${VYATTA_TEMP_CONFIG_DIR}/${VYATTA_EDIT_LEVEL} _tpath=${VYATTA_CONFIG_TEMPLATE}/${VYATTA_TEMPLATE_LEVEL} VYATTA_EDIT_LEVEL="${_mpath#$VYATTA_TEMP_CONFIG_DIR}/" VYATTA_TEMPLATE_LEVEL="${_tpath#$VYATTA_CONFIG_TEMPLATE}/" - mvcp rename Rename mv "${@:3}" + if [ $2 == "firewall" ]; then + mvcp rename Rename mv "${@:4}" + elif [ $2 == "nat" ]; then + mvcp rename Rename mv "${@:3}" + fi RET_STATUS=$? ;; *) -- cgit v1.2.3 From f3744da98332e55d0487d8619ceb8ae7a0db3ac3 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Wed, 29 Jul 2009 12:00:32 -0700 Subject: update cli-expand-var script to match current variable reference syntax. --- scripts/vyatta-cli-expand-var.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/vyatta-cli-expand-var.pl b/scripts/vyatta-cli-expand-var.pl index f690f0b..f3bda2d 100755 --- a/scripts/vyatta-cli-expand-var.pl +++ b/scripts/vyatta-cli-expand-var.pl @@ -34,7 +34,7 @@ $_ = $ARGV[0]; # basic format check: # '(' ')' not allowed in reference. # only allow absolute path for now. -if (!/^\$\(\/([^()]+)\)$/) { +if (!/^\$VAR\(\/([^()]+)\)$/) { print STDERR "invalid variable reference (invalid format)\n"; exit 1; } -- cgit v1.2.3 From 9c2f8965e28bd4af5f8773b85dbee0511f447ec3 Mon Sep 17 00:00:00 2001 From: slioch Date: Fri, 31 Jul 2009 15:07:36 -0700 Subject: cleaned out more of the islavista rank code. closing bug 4473 as a result --- lib/Vyatta/ConfigLoad.pm | 95 ++++----------------------------------- scripts/vyatta-config-gen-sets.pl | 9 ---- scripts/vyatta-config-loader.pl | 15 +------ 3 files changed, 9 insertions(+), 110 deletions(-) (limited to 'scripts') 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/scripts/vyatta-config-gen-sets.pl b/scripts/vyatta-config-gen-sets.pl index 2fe4ac6..566570e 100755 --- a/scripts/vyatta-config-gen-sets.pl +++ b/scripts/vyatta-config-gen-sets.pl @@ -32,23 +32,14 @@ my $conf_file = '/opt/vyatta/etc/config/config.boot'; $conf_file = $ARGV[0] if defined $ARGV[0]; # get a list of all config statement in the startup config file -# (sorted by rank). my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($conf_file); if (scalar(@all_nodes) == 0) { # no config statements exit 1; } -my $cur_rank = ${$all_nodes[0]}[1]; my $ret = 0; -# higher-ranked statements committed before lower-ranked. foreach (@all_nodes) { - my ($path_ref, $rank) = @$_; - if ($rank != $cur_rank) { - # commit all nodes with the same rank together. - print "commit\n"; - $cur_rank = $rank; - } my $cmd = "set " . (join ' ', @$path_ref); print "$cmd\n"; } diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl index a32d1fc..61eafa5 100755 --- a/scripts/vyatta-config-loader.pl +++ b/scripts/vyatta-config-loader.pl @@ -46,14 +46,12 @@ sub restore_fds { } # get a list of all config statement in the startup config file -# (sorted by rank). my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0]); if (scalar(@all_nodes) == 0) { # no config statements restore_fds(); exit 1; } -my $cur_rank = ${$all_nodes[0]}[1]; # set up the config environment my $CWRAPPER = '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper'; @@ -69,20 +67,9 @@ if ($? >> 8) { my $commit_cmd = "$CWRAPPER commit"; my $cleanup_cmd = "$CWRAPPER cleanup"; my $ret = 0; -# higher-ranked statements committed before lower-ranked. +my $rank; #not used foreach (@all_nodes) { my ($path_ref, $rank) = @$_; - if ($rank != $cur_rank) { - # commit all nodes with the same rank together. - $ret = 0; #system("$commit_cmd"); - if ($ret >> 8) { - print OLDOUT "Commit failed at rank $cur_rank\n"; - print WARN "Commit failed at rank $cur_rank\n"; - system("$cleanup_cmd"); - # continue after cleanup (or should we abort?) - } - $cur_rank = $rank; - } my $cmd = "$CWRAPPER set " . (join ' ', @$path_ref); # this debug file should be deleted before release system("echo [$cmd] >> /tmp/foo"); -- cgit v1.2.3 From 29662246b32dd27b2540ae766684f2c634e8d044 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 24 Aug 2009 12:15:06 -0700 Subject: Add a small script to test for node existance This does the same thing as vyatta-quagga-utils.pl --exists, but it is generally useful (outside quagga) and has less overhead than a perl compile. --- Makefile.am | 1 + scripts/vyatta-exists | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100755 scripts/vyatta-exists (limited to 'scripts') diff --git a/Makefile.am b/Makefile.am index f7096af..217de7e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,6 +56,7 @@ sbin_SCRIPTS += scripts/vyatta-cfg-notify sbin_SCRIPTS += scripts/vyatta-interfaces.pl sbin_SCRIPTS += scripts/vyatta-irqaffin sbin_SCRIPTS += scripts/vyatta-check-typeless-node.pl +sbin_SCRIPTS += scripts/vyatta-exists share_perl5_DATA = lib/Vyatta/Config.pm share_perl5_DATA += lib/Vyatta/Misc.pm diff --git a/scripts/vyatta-exists b/scripts/vyatta-exists new file mode 100755 index 0000000..ef2dea3 --- /dev/null +++ b/scripts/vyatta-exists @@ -0,0 +1,14 @@ +#! /bin/bash + +# Test if given node exists in Vyatta config hierarchy +# +# if vyatta-exists interfaces wireless + +if [ -z "$VYATTA_TEMP_CONFIG_DIR" ]; then + echo "$0: not in configuration mode" 1>&2; + exit 1; +fi +IFS=/ +node=$* +IFS= +exec test -d $VYATTA_TEMP_CONFIG_DIR/$node -- cgit v1.2.3 From a84810d27eb4bbc721c0ee326fe64589ffcf2f3c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 27 Aug 2009 09:54:36 -0700 Subject: Failure to set address should fail the commit The script was hiding any error exit codes from 'ip' command. Switch to using exec so that error exits fail the commit. Discovered when testing with IPV6 disabled. --- scripts/vyatta-interfaces.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index 86410c1..567e3b7 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -260,10 +260,12 @@ sub update_eth_addrs { } if ($version == 4) { - return system("ip addr add $addr broadcast + dev $intf"); + exec (qw(ip addr add),$addr,qw(broadcast + dev), $intf) + or die "ip addr command failed: $!"; } if ($version == 6) { - return system("ip -6 addr add $addr dev $intf"); + exec (qw(ip -6 addr add), $addr, 'dev', $intf) + or die "ip addr command failed: $!"; } die "Error: Invalid address/prefix [$addr] for interface $intf\n"; } @@ -316,7 +318,8 @@ sub update_mac { system "sudo ip link set $intf up" and die "Could not set $intf up ($!)\n"; } else { - exec "sudo ip link set $intf address $mac"; + system "sudo ip link set $intf address $mac" + and die "Could not set $intf address ($!)\n"; } exit 0; } -- cgit v1.2.3