From 9273d3172d39360d019d3e3256d2c537d2b71d80 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Mon, 24 Mar 2008 18:26:53 -0700 Subject: Fix Bug 2825 Load should read config file from default location when no argument is provided. - 'load' reads config file from default location just as 'save' --- scripts/vyatta-load-config.pl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index a432d8c..f845c24 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -28,16 +28,19 @@ use VyattaConfigLoad; my $etcdir = $ENV{vyatta_sysconfdir}; my $sbindir = $ENV{vyatta_sbindir}; my $bootpath = $etcdir . "/config"; +my $load_file = $bootpath . "/config.boot"; -if ($#ARGV != 0) { +if ($#ARGV > 0) { print "Usage: load \n"; exit 1; } -my $load_file = $ARGV[0]; -if (!($load_file =~ /^\//)) { - # relative path - $load_file = "$bootpath/$load_file"; +if (defined($ARGV[0])) { + $load_file = $ARGV[0]; + if (!($load_file =~ /^\//)) { + # relative path + $load_file = "$bootpath/$load_file"; + } } # do config migration -- cgit v1.2.3 From 053d42ea27a5b89f0a19a09dd347bc37c6f07948 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Tue, 1 Apr 2008 10:08:14 -0700 Subject: fix for bug 2689: sort tag nodes appropriately --- debian/control | 1 + scripts/VyattaConfigOutput.pm | 3 +++ 2 files changed, 4 insertions(+) (limited to 'scripts') diff --git a/debian/control b/debian/control index 5a06588..2fdbcfe 100644 --- a/debian/control +++ b/debian/control @@ -18,6 +18,7 @@ Depends: sed (>= 4.1.5), dhcp3-client | vyatta-dhcp3-client, bsdutils (>=1:2.13), libc6 (>= 2.7-6), + libsort-versions-perl, vlan Replaces: vyatta-cfg-firewall Suggests: util-linux (>= 2.13-5), diff --git a/scripts/VyattaConfigOutput.pm b/scripts/VyattaConfigOutput.pm index b7c5499..2766b64 100755 --- a/scripts/VyattaConfigOutput.pm +++ b/scripts/VyattaConfigOutput.pm @@ -32,6 +32,7 @@ package VyattaConfigOutput; use strict; use lib '/opt/vyatta/share/perl5/'; use VyattaConfig; +use Sort::Versions; # whether to show default values my $show_all = 0; @@ -190,6 +191,7 @@ sub displayDeletedOrigChildren { $dont_show_as_deleted); } elsif (scalar($#cnames) >= 0) { if ($is_tag) { + @cnames = sort versioncmp @cnames; foreach my $cname (@cnames) { if ($cname eq 'node.val') { # should not happen @@ -244,6 +246,7 @@ sub displayChildren { displayValues([ @cur_path, $child ], $prefix, $child); } elsif (scalar($#cnames) >= 0) { if ($is_tag) { + @cnames = sort versioncmp @cnames; foreach my $cname (@cnames) { if ($cname eq 'node.val') { # should not happen -- cgit v1.2.3 From 3dfd14fbb84b14cfb632171cac15546bfea79a68 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Wed, 23 Apr 2008 10:42:45 -0700 Subject: mask out def markers in config script --- scripts/VyattaConfigOutput.pm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'scripts') diff --git a/scripts/VyattaConfigOutput.pm b/scripts/VyattaConfigOutput.pm index 2766b64..2c92132 100755 --- a/scripts/VyattaConfigOutput.pm +++ b/scripts/VyattaConfigOutput.pm @@ -189,6 +189,8 @@ sub displayDeletedOrigChildren { if ($#cnames == 0 && $cnames[0] eq 'node.val') { displayValues([ @cur_path, $child ], $prefix, $child, $dont_show_as_deleted); + } elsif ($cnames[0] eq 'def') { + #ignore } elsif (scalar($#cnames) >= 0) { if ($is_tag) { @cnames = sort versioncmp @cnames; @@ -244,6 +246,8 @@ sub displayChildren { my @cnames = sort keys %cnodes; if ($#cnames == 0 && $cnames[0] eq 'node.val') { displayValues([ @cur_path, $child ], $prefix, $child); + } elsif ($cnames[0] eq 'def') { + #skip } elsif (scalar($#cnames) >= 0) { if ($is_tag) { @cnames = sort versioncmp @cnames; @@ -286,6 +290,8 @@ sub displayChildren { my @onodes = $config->listOrigNodes(join ' ', (@cur_path, $child)); if ($#onodes == 0 && $onodes[0] eq 'node.val') { displayValues([ @cur_path, $child ], $prefix, $child); + } elsif ($onodes[0] eq 'def') { + #skip this } else { print "$diff$prefix$child {\n"; displayDeletedOrigChildren([ @cur_path, $child ], "$prefix "); @@ -312,6 +318,8 @@ sub outputNewConfig { if ($#rn == 0 && $rn[0] eq 'node.val') { # this is a leaf value-node displayValues([ @_ ], '', $_[$#_]); + } elsif ($rn[0] eq 'def') { + #skip } else { displayChildren(\%rnodes, [ @_ ], ''); } -- cgit v1.2.3 From 4d47c9ee564e5c865fed3b1a6374b9317528b357 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Wed, 23 Apr 2008 11:10:46 -0700 Subject: final checkin as fix for bug 1219. --- scripts/VyattaConfigOutput.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/VyattaConfigOutput.pm b/scripts/VyattaConfigOutput.pm index 2c92132..f492d5d 100755 --- a/scripts/VyattaConfigOutput.pm +++ b/scripts/VyattaConfigOutput.pm @@ -155,7 +155,8 @@ sub displayValues { $diff = '>'; } } - if (!defined($default) || $default ne $value || $show_all) { +# if (!defined($default) || $default ne $value || $show_all) { + if (!defined($default) || !$config->exists('def') || $show_all) { if ($is_password && $hide_password) { $value = $HIDE_PASSWORD; } -- cgit v1.2.3 From ea82e707fed342ef019b5fd5e2e359eebb337b03 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Wed, 23 Apr 2008 12:19:27 -0700 Subject: backing out show cmd change for now on existence of def --- scripts/VyattaConfigOutput.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/VyattaConfigOutput.pm b/scripts/VyattaConfigOutput.pm index f492d5d..e67e7f3 100755 --- a/scripts/VyattaConfigOutput.pm +++ b/scripts/VyattaConfigOutput.pm @@ -155,8 +155,8 @@ sub displayValues { $diff = '>'; } } -# if (!defined($default) || $default ne $value || $show_all) { - if (!defined($default) || !$config->exists('def') || $show_all) { +# if (!defined($default) || !$config->exists('def') || $show_all) { + if (!defined($default) || $default ne $value || $show_all) { if ($is_password && $hide_password) { $value = $HIDE_PASSWORD; } -- cgit v1.2.3 From 7cb99a90634ed0685eac3a61b7c3cfcd274d8fe1 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Thu, 24 Apr 2008 17:33:30 -0700 Subject: fix for show -all. note there is a change in how config files are saved--only set values are now save as opposed to set values plus all default values. set values will be saved now even if they match the default value. --- scripts/VyattaConfigOutput.pm | 48 ++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'scripts') diff --git a/scripts/VyattaConfigOutput.pm b/scripts/VyattaConfigOutput.pm index e67e7f3..5358c21 100755 --- a/scripts/VyattaConfigOutput.pm +++ b/scripts/VyattaConfigOutput.pm @@ -133,8 +133,12 @@ sub displayValues { $nval = "\"$nval\""; } } + + my %cnodes = $config->listNodeStatus(); + my @cnames = sort keys %cnodes; + if (defined($simple_show)) { - if (!defined($default) || $default ne $oval || $show_all) { + if (!$cnodes{'def'} || $show_all) { if ($is_password && $hide_password) { $oval = $HIDE_PASSWORD; } @@ -155,8 +159,7 @@ sub displayValues { $diff = '>'; } } -# if (!defined($default) || !$config->exists('def') || $show_all) { - if (!defined($default) || $default ne $value || $show_all) { + if (!$cnodes{'def'} || $show_all) { if ($is_password && $hide_password) { $value = $HIDE_PASSWORD; } @@ -187,7 +190,8 @@ sub displayDeletedOrigChildren { my $is_tag = $config->isTagNode([ @cur_path, $child ]); $config->setLevel(join ' ', (@cur_path, $child)); my @cnames = sort $config->listOrigNodes(); - if ($#cnames == 0 && $cnames[0] eq 'node.val') { + + if ($cnames[0] eq 'node.val') { displayValues([ @cur_path, $child ], $prefix, $child, $dont_show_as_deleted); } elsif ($cnames[0] eq 'def') { @@ -245,10 +249,21 @@ sub displayChildren { $config->setLevel(join ' ', (@cur_path, $child)); my %cnodes = $config->listNodeStatus(); my @cnames = sort keys %cnodes; - if ($#cnames == 0 && $cnames[0] eq 'node.val') { + + #if node.val exists and ct == 0 w/o def or ct ==1 w/ def + my $leaf = 0; + if ($cnodes{'def'}) { + if ($#cnames == 1 && $cnodes{'node.val'}) { + $leaf = 1; + } + } else { + if ($#cnames == 0 && $cnodes{'node.val'}) { + $leaf = 1; + } + } + + if ($leaf == 1) { displayValues([ @cur_path, $child ], $prefix, $child); - } elsif ($cnames[0] eq 'def') { - #skip } elsif (scalar($#cnames) >= 0) { if ($is_tag) { @cnames = sort versioncmp @cnames; @@ -291,8 +306,6 @@ sub displayChildren { my @onodes = $config->listOrigNodes(join ' ', (@cur_path, $child)); if ($#onodes == 0 && $onodes[0] eq 'node.val') { displayValues([ @cur_path, $child ], $prefix, $child); - } elsif ($onodes[0] eq 'def') { - #skip this } else { print "$diff$prefix$child {\n"; displayDeletedOrigChildren([ @cur_path, $child ], "$prefix "); @@ -316,11 +329,22 @@ sub outputNewConfig { my %rnodes = $config->listNodeStatus(); if (scalar(keys %rnodes) > 0) { my @rn = keys %rnodes; - if ($#rn == 0 && $rn[0] eq 'node.val') { + + #if node.val exists and ct == 0 w/o def or ct ==1 w/ def + my $leaf = 0; + if ($rnodes{'def'}) { + if ($#rn == 1 && $rnodes{'node.val'}) { + $leaf = 1; + } + } else { + if ($#rn == 0 && $rnodes{'node.val'}) { + $leaf = 1; + } + } + + if ($leaf == 1) { # this is a leaf value-node displayValues([ @_ ], '', $_[$#_]); - } elsif ($rn[0] eq 'def') { - #skip } else { displayChildren(\%rnodes, [ @_ ], ''); } -- cgit v1.2.3 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(+) (limited to 'scripts') 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 From 2471813598d00698701b5d6798c0a03d73288488 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Mon, 5 May 2008 14:46:30 -0700 Subject: Fix 3233 dhcp client doesn't work on bridge interface --- scripts/vyatta-interfaces.pl | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index aa82b78..020fe28 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -197,6 +197,21 @@ sub dhcp_get_interfaces { } } } + + $config->setLevel("interfaces bridge"); + my @brs = $config->listNodes(); + foreach my $br (@brs) { + $config->setLevel("interfaces bridge $br"); + if ($config->exists("address")) { + my @addrs = $config->returnValues("address"); + foreach my $addr (@addrs) { + if (defined $addr && $addr eq "dhcp") { + push @dhcp_intfs, $br; + } + } + } + } + return @dhcp_intfs; } @@ -205,10 +220,16 @@ sub is_dhcp_enabled { my $config = new VyattaConfig; - if ($intf =~ m/(\w+)\.(\d)/) { - $config->setLevel("interfaces ethernet $1 vif $2"); + if ($intf =~ m/^eth/) { + if ($intf =~ m/(\w+)\.(\d)/) { + $config->setLevel("interfaces ethernet $1 vif $2"); + } else { + $config->setLevel("interfaces ethernet $intf"); + } + } elsif ($intf =~ m/^br/) { + $config->setLevel("interfaces bridge $intf"); } else { - $config->setLevel("interfaces ethernet $intf"); + die "unsupported dhcp interface [$intf]"; } my @addrs = $config->returnOrigValues("address"); foreach my $addr (@addrs) { @@ -223,11 +244,17 @@ sub is_address_enabled { my $intf = shift; my $config = new VyattaConfig; - - if ($intf =~ m/(\w+)\.(\d)/) { - $config->setLevel("interfaces ethernet $1 vif $2"); + + if ($intf =~ m/^eth/) { + if ($intf =~ m/(\w+)\.(\d)/) { + $config->setLevel("interfaces ethernet $1 vif $2"); + } else { + $config->setLevel("interfaces ethernet $intf"); + } + } elsif ($intf =~ m/^br/) { + $config->setLevel("interfaces bridge $intf"); } else { - $config->setLevel("interfaces ethernet $intf"); + die "unsupported dhcp interface [$intf]"; } my @addrs = $config->returnOrigValues("address"); foreach my $addr (@addrs) { -- cgit v1.2.3 From 762315a293866b7b4c5fc3ca7c7470035a8e3854 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Tue, 6 May 2008 14:32:48 -0700 Subject: Only check for dhcp client on eth, vlan, and bridge. --- scripts/vyatta-interfaces.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index 020fe28..ec3a873 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -229,7 +229,11 @@ sub is_dhcp_enabled { } elsif ($intf =~ m/^br/) { $config->setLevel("interfaces bridge $intf"); } else { - die "unsupported dhcp interface [$intf]"; + # + # currently we only support dhcp on ethernet + # and bridge interfaces. + # + return 0; } my @addrs = $config->returnOrigValues("address"); foreach my $addr (@addrs) { -- cgit v1.2.3 From 07d3641ca62cfede93708d366bb3e5410feba519 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Thu, 8 May 2008 17:48:05 -0700 Subject: Add more granularity to config rank (commit rip, ospf, bgp separately). --- scripts/VyattaConfigLoad.pm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm index b69723a..a5c5b08 100755 --- a/scripts/VyattaConfigLoad.pm +++ b/scripts/VyattaConfigLoad.pm @@ -23,7 +23,7 @@ package VyattaConfigLoad; use strict; use sort 'stable'; use lib "/opt/vyatta/share/perl5/"; -use XorpConfigParser; +use XorpConfigParser; use VyattaConfig; # configuration ordering. higher rank configured before lower rank. @@ -36,16 +36,22 @@ my %config_rank = ( 'interfaces bridge' => 99, 'interfaces ethernet' => 98, 'interfaces tunnel' => 91, - 'system' => 90, + 'system gateway-address'=> 89, + 'system name-server' => 88, + 'system login user' => 87, + 'system' => 86, 'protocols static' => 85, 'service ssh' => 84, 'service telnet' => 83, 'policy' => 82, - 'vpn' => 80, + 'protocols bgp' => 79, + 'protocols ospf' => 78, + 'protocols rip' => 77, + 'vpn' => 60, ); my %wildcard_rank = ( - 'interfaces ethernet * vrrp' => 50, + 'interfaces ethernet * vrrp' => 50, 'interfaces ethernet * vif * vrrp' => 50, ); -- cgit v1.2.3 From 132e5c7b81bc308bfd66b23a7d619329ded829df Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Thu, 8 May 2008 21:11:13 -0700 Subject: fix for bug 3239: now support regex-based ordering for startup config loading. --- scripts/VyattaConfigLoad.pm | 60 ++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'scripts') diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm index a5c5b08..bf86e57 100755 --- a/scripts/VyattaConfigLoad.pm +++ b/scripts/VyattaConfigLoad.pm @@ -29,49 +29,47 @@ use VyattaConfig; # configuration ordering. higher rank configured before lower rank. my $default_rank = 0; my %config_rank = ( - 'qos-policy' => 110, - 'firewall' => 102, - 'service nat' => 101, - 'interfaces' => 100, - 'interfaces bridge' => 99, - 'interfaces ethernet' => 98, - 'interfaces tunnel' => 91, - 'system gateway-address'=> 89, - 'system name-server' => 88, - 'system login user' => 87, - 'system' => 86, - 'protocols static' => 85, - 'service ssh' => 84, - 'service telnet' => 83, - 'policy' => 82, - 'protocols bgp' => 79, - 'protocols ospf' => 78, - 'protocols rip' => 77, - 'vpn' => 60, + 'qos-policy' => 1100, + 'firewall' => 1020, + 'service nat' => 1010, + 'interfaces' => 1000, + 'interfaces bridge' => 990, + 'interfaces ethernet' => 980, + 'interfaces tunnel' => 910, + 'system gateway-address'=> 890, + 'system name-server' => 880, + 'system login user' => 870, + 'system' => 860, + 'protocols static' => 850, + 'service ssh' => 840, + 'service telnet' => 830, + 'policy' => 820, + 'protocols bgp' => 790, + 'protocols ospf' => 780, + 'protocols rip' => 770, + 'vpn' => 600, ); -my %wildcard_rank = ( - 'interfaces ethernet * vrrp' => 50, - 'interfaces ethernet * vif * vrrp' => 50, +my %regex_rank = ( + 'interfaces ethernet \S* vrrp' => 500, + 'interfaces ethernet \S* vif \S* vrrp' => 500, + 'protocols bgp \d+ neighbor \S*[^\d.]\S*' => 800, ); 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 { +sub match_regex { my ($pattern, $str) = @_; - $pattern =~ s/\*/\\S*/g; $pattern =~ s/^(.*)$/\^$1\$/; return ($str =~ m/$pattern/) ? 1 : 0; } -sub get_wildcard_rank { +sub get_regex_rank { my ($str) = @_; - foreach (keys %wildcard_rank) { - if (match_wildcard($_, $str)) { - return $wildcard_rank{$_}; + foreach (keys %regex_rank) { + if (match_regex($_, $str)) { + return $regex_rank{$_}; } } return undef; @@ -85,7 +83,7 @@ sub get_config_rank { if (defined($config_rank{$path_str})) { return ($config_rank{$path_str}); } - my $wrank = get_wildcard_rank($path_str); + my $wrank = get_regex_rank($path_str); return $wrank if (defined($wrank)); pop @path; } -- cgit v1.2.3 From 04f1b8990af194e436c8581f1ca1a7f60596899c Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Fri, 9 May 2008 17:50:05 -0700 Subject: Fix vlan regex. --- scripts/vyatta-interfaces.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index ec3a873..310ee0e 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -221,7 +221,7 @@ sub is_dhcp_enabled { my $config = new VyattaConfig; if ($intf =~ m/^eth/) { - if ($intf =~ m/(\w+)\.(\d)/) { + if ($intf =~ m/(\w+)\.(\d+)/) { $config->setLevel("interfaces ethernet $1 vif $2"); } else { $config->setLevel("interfaces ethernet $intf"); @@ -250,7 +250,7 @@ sub is_address_enabled { my $config = new VyattaConfig; if ($intf =~ m/^eth/) { - if ($intf =~ m/(\w+)\.(\d)/) { + if ($intf =~ m/(\w+)\.(\d+)/) { $config->setLevel("interfaces ethernet $1 vif $2"); } else { $config->setLevel("interfaces ethernet $intf"); -- cgit v1.2.3 From a6c714e9b6a8471f428824a310dae8c9fccb2908 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 14 May 2008 13:41:27 -0700 Subject: Remove unused dependencies No longer need Tie or flock, these were used when dealing with watchlink --- scripts/vyatta-interfaces.pl | 2 -- 1 file changed, 2 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index aa82b78..de82edd 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -37,8 +37,6 @@ use VyattaMisc; use Getopt::Long; use POSIX; use NetAddr::IP; -use Tie::File; -use Fcntl qw (:flock); use strict; use warnings; -- cgit v1.2.3 From e1c9d6128c973f9f32a41cec4332734e32430178 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Mon, 19 May 2008 15:59:27 -0700 Subject: Force "protocols ospf parameters" to be committed before other ospf config. This should fix bug 3272 at boot time, but we still need to fix quagga so that it doesn't crash if router-id is changed during convergence. --- scripts/VyattaConfigLoad.pm | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'scripts') diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm index bf86e57..d202938 100755 --- a/scripts/VyattaConfigLoad.pm +++ b/scripts/VyattaConfigLoad.pm @@ -29,25 +29,27 @@ use VyattaConfig; # configuration ordering. higher rank configured before lower rank. my $default_rank = 0; my %config_rank = ( - 'qos-policy' => 1100, - 'firewall' => 1020, - 'service nat' => 1010, - 'interfaces' => 1000, - 'interfaces bridge' => 990, - 'interfaces ethernet' => 980, - 'interfaces tunnel' => 910, - 'system gateway-address'=> 890, - 'system name-server' => 880, - 'system login user' => 870, - 'system' => 860, - 'protocols static' => 850, - 'service ssh' => 840, - 'service telnet' => 830, - 'policy' => 820, - 'protocols bgp' => 790, - 'protocols ospf' => 780, - 'protocols rip' => 770, - 'vpn' => 600, + 'qos-policy' => 1100, + 'firewall' => 1020, + 'service nat' => 1010, + 'interfaces' => 1000, + 'interfaces bridge' => 990, + 'interfaces ethernet' => 980, + 'interfaces tunnel' => 910, + 'system gateway-address' => 890, + 'system name-server' => 880, + 'system login user' => 870, + 'system' => 860, + 'protocols static' => 850, + 'service ssh' => 840, + 'service telnet' => 830, + 'policy' => 820, + 'protocols bgp' => 790, + 'protocols ospf parameters' => 785, + 'protocols ospf' => 780, + 'protocols rip' => 770, + 'vpn' => 600, + ); my %regex_rank = ( -- cgit v1.2.3 From aca9f66546b7018beb53a6357a4f2e381e2590a5 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Tue, 3 Jun 2008 12:34:08 -0700 Subject: Fix 920: System allows configuration of invalid IP Address for subnet --- scripts/vyatta-interfaces.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index dd71d7a..ad059c5 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -471,6 +471,18 @@ sub is_valid_addr { exit 1; } + my $ip = NetAddr::IP->new($addr_net); + my $network = $ip->network(); + my $bcast = $ip->broadcast(); + if ($ip->addr() eq $network->addr()) { + print "Can not assign network address as the IP address\n"; + exit 1; + } + if ($ip->addr() eq $bcast->addr()) { + print "Can not assign broadcast address as the IP address\n"; + exit 1; + } + if (is_dhcp_enabled($intf)) { print "Error: remove dhcp before adding static addresses for $intf\n"; exit 1; -- cgit v1.2.3 From bca0ace007667fb9c2e634e0debd120fc58525d4 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Wed, 4 Jun 2008 11:32:23 -0700 Subject: Add exception for /31 and /32 for ipv4 and /128 for ipv6 --- scripts/vyatta-interfaces.pl | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index ad059c5..b465476 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -474,13 +474,23 @@ sub is_valid_addr { my $ip = NetAddr::IP->new($addr_net); my $network = $ip->network(); my $bcast = $ip->broadcast(); - if ($ip->addr() eq $network->addr()) { - print "Can not assign network address as the IP address\n"; - exit 1; - } - if ($ip->addr() eq $bcast->addr()) { - print "Can not assign broadcast address as the IP address\n"; - exit 1; + + if ($ip->version == 4 and $ip->masklen() == 31) { + # + # RFC3021 allows for /31 to treat both address as host addresses + # + } elsif ($ip->masklen() != $ip->bits()) { + # + # allow /32 for ivp4 and /128 for ipv6 + # + if ($ip->addr() eq $network->addr()) { + print "Can not assign network address as the IP address\n"; + exit 1; + } + if ($ip->addr() eq $bcast->addr()) { + print "Can not assign broadcast address as the IP address\n"; + exit 1; + } } if (is_dhcp_enabled($intf)) { -- cgit v1.2.3 From 8f1c7d3f0eb43ca080acb83e880af7403117c9cd Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Tue, 17 Jun 2008 10:55:11 -0700 Subject: fix for bug 3347--skip def file.o --- scripts/VyattaConfigLoad.pm | 3 +++ 1 file changed, 3 insertions(+) (limited to 'scripts') diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm index d202938..90011f6 100755 --- a/scripts/VyattaConfigLoad.pm +++ b/scripts/VyattaConfigLoad.pm @@ -295,6 +295,9 @@ sub findDeletedNodes { $active_cfg->setLevel(join ' ', @active_path); my @active_nodes = $active_cfg->listOrigNodes(); foreach (@active_nodes) { + if ($_ eq 'def') { + next; + } if ($_ eq 'node.val') { findDeletedValues($new_ref, \@active_path); next; -- cgit v1.2.3 From c308c149bf09bc9b690672e6bdc80f00c5a84608 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 19 Jun 2008 06:48:20 +0000 Subject: -> redo the way dhcp client works. instead of using one daemon for all interfaces, use separate daemons for separate interfaces. when one daemon was handling all interfaces, a release/renew at one interface would release/renew all other interfaces as well before we brought them back to the state specified in vyatta config -> Also, Fix bug 3346 replaced the die command with print followed by exit 1 -> modified vyatta-interfaces.pl to remove code for handling op-command: 'clear dhcp client process' this command restarted the dhcp client daemon but now that we have separate daemons for separate interfaces, this is not useful. Also, this will be replaced by op-commands for 'dhcp client release lease' and 'dhcp client renew lease' commands in hollywood beta --- scripts/vyatta-interfaces.pl | 173 +++++++++++-------------------------------- 1 file changed, 45 insertions(+), 128 deletions(-) mode change 100755 => 100644 scripts/vyatta-interfaces.pl (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl old mode 100755 new mode 100644 index b465476..c35cfe0 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -42,16 +42,14 @@ use strict; use warnings; my $dhcp_daemon = '/sbin/dhclient'; -my $dhcp_conf = '/etc/dhcp3/dhclient.conf'; -my $dhcp_pid = '/var/run/dhclient.pid'; -my $dhcp_leases = '/var/lib/dhcp3/dhclient.leases'; +my $dhclient_dir = '/var/lib/dhcp3/'; -my ($eth_update, $eth_delete, $addr, $restart_dhclient, $dev, $mac, $mac_update); + +my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update); GetOptions("eth-addr-update=s" => \$eth_update, "eth-addr-delete=s" => \$eth_delete, "valid-addr=s" => \$addr, - "restart-dhclient!" => \$restart_dhclient, "dev=s" => \$dev, "valid-mac=s" => \$mac, "set-mac=s" => \$mac_update, @@ -62,7 +60,6 @@ if (defined $eth_delete) { delete_eth_addrs($eth_delete, $dev); } if (defined $addr) { is_valid_addr($addr, $dev); } if (defined $mac) { is_valid_mac($mac, $dev); } if (defined $mac_update) { update_mac($mac_update, $dev); } -if (defined $restart_dhclient) { dhcp_restart_daemon(); } sub is_ip_configured { my ($intf, $ip) = @_; @@ -97,54 +94,6 @@ sub is_ip_duplicate { } } -sub is_dhcp_running { - if (-f $dhcp_pid) { - my $pid = `cat $dhcp_pid`; - chomp $pid; - my $ps = `ps -p $pid -o comm=`; - - if (defined($ps) && $ps ne "") { - return 1; - } - } - return 0; -} - -sub dhcp_start_daemon { - my $cmd = "$dhcp_daemon -q -nw &"; - system($cmd); -} - -sub dhcp_stop_daemon { - if (is_dhcp_running()) { - my $pid = `cat $dhcp_pid`; - system("kill $pid"); - } - system("rm -f $dhcp_pid"); -} - -sub dhcp_restart_daemon { - # - # check if vyatta has generated the config file, otherwise - # an empty config will try to get new addresses for all - # interfaces - # - my $grep = `grep vyatta-interfaces.pl $dhcp_conf | wc -l`; - chomp $grep; - if (!defined $grep or $grep != 1) { - die "DHCP client not configured\n"; - } - if (is_dhcp_running()) { - dhcp_stop_daemon(); - } - dhcp_start_daemon(); -} - -sub dhcp_release_addr { - my $intf = shift; - my $cmd = "$dhcp_daemon -q -r $intf 2> /dev/null"; - system($cmd); -} sub dhcp_write_file { my ($file, $data) = @_; @@ -166,53 +115,6 @@ sub dhcp_conf_header { return $output; } -sub dhcp_get_interfaces { - my @dhcp_intfs; - - my $config = new VyattaConfig; - - $config->setLevel("interfaces ethernet"); - my @eths = $config->listNodes(); - foreach my $eth (@eths) { - $config->setLevel("interfaces ethernet $eth"); - if ($config->exists("address")) { - my @addrs = $config->returnValues("address"); - foreach my $addr (@addrs) { - if (defined $addr && $addr eq "dhcp") { - push @dhcp_intfs, $eth; - } - } - } - $config->setLevel("interfaces ethernet $eth vif"); - my @vifs = $config->listNodes(); - foreach my $vif (@vifs) { - $config->setLevel("interfaces ethernet $eth vif $vif"); - my @addrs = $config->returnValues("address"); - foreach my $addr (@addrs) { - if (defined $addr && $addr eq "dhcp") { - push @dhcp_intfs, "$eth.$vif"; - } - } - } - } - - $config->setLevel("interfaces bridge"); - my @brs = $config->listNodes(); - foreach my $br (@brs) { - $config->setLevel("interfaces bridge $br"); - if ($config->exists("address")) { - my @addrs = $config->returnValues("address"); - foreach my $addr (@addrs) { - if (defined $addr && $addr eq "dhcp") { - push @dhcp_intfs, $br; - } - } - } - } - - return @dhcp_intfs; -} - sub is_dhcp_enabled { my $intf = shift; @@ -256,7 +158,8 @@ sub is_address_enabled { } elsif ($intf =~ m/^br/) { $config->setLevel("interfaces bridge $intf"); } else { - die "unsupported dhcp interface [$intf]"; + print "unsupported dhcp interface [$intf]\n"; + exit 1; } my @addrs = $config->returnOrigValues("address"); foreach my $addr (@addrs) { @@ -275,34 +178,18 @@ sub get_hostname { } sub dhcp_update_config { + my ($conf_file, $intf) = @_; + my $output = dhcp_conf_header(); my $hostname = get_hostname(); - my $config = new VyattaConfig; - my $dhcp_instances = 0; - my @dhcp_intfs = dhcp_get_interfaces(); - foreach my $intf (@dhcp_intfs) { - $output .= "interface \"$intf\" {\n"; - if (defined($hostname)) { - $output .= "\tsend host-name \"$hostname\";\n"; - } - $output .= "}\n\n"; - $dhcp_instances++; + $output .= "interface \"$intf\" {\n"; + if (defined($hostname)) { + $output .= "\tsend host-name \"$hostname\";\n"; } + $output .= "}\n\n"; - if ($dhcp_instances > 0) { - my $conf_file = $dhcp_conf; - dhcp_write_file($conf_file, $output); - dhcp_restart_daemon(); - } - return $dhcp_instances; -} - -sub update_dhcp_client { - my $dhcp_instances = dhcp_update_config(); - if ($dhcp_instances == 0) { - dhcp_stop_daemon(); - } + dhcp_write_file($conf_file, $output); } sub is_ip_v4_or_v6 { @@ -328,11 +215,42 @@ sub is_ip_v4_or_v6 { return undef; } +sub generate_dhclient_intf_files { + my $intf = shift; + + $intf =~ s/\./_/g; + my $intf_config_file = $dhclient_dir . 'dhclient_' . $intf . '.conf'; + my $intf_process_id_file = $dhclient_dir . 'dhclient_' . $intf . '.pid'; + my $intf_leases_file = $dhclient_dir . 'dhclient_' . $intf . '.leases'; + return ($intf_config_file, $intf_process_id_file, $intf_leases_file); + +} + +sub run_dhclient { + my $intf = shift; + + my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = generate_dhclient_intf_files($intf); + dhcp_update_config($intf_config_file, $intf); + my $cmd = "$dhcp_daemon -q -nw -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file $intf 2> /dev/null &"; + # adding & at the end to make the process into a daemon immediately + system ($cmd); +} + +sub stop_dhclient { + my $intf = shift; + + my ($intf_config_file, $intf_process_id_file, $intf_leases_file) = generate_dhclient_intf_files($intf); + my $cmd = "$dhcp_daemon -q -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file -r $intf 2> /dev/null"; + system ($cmd); + system ("rm -f $intf_config_file"); + +} + sub update_eth_addrs { my ($addr, $intf) = @_; if ($addr eq "dhcp") { - update_dhcp_client(); + run_dhclient($intf); return; } my $version = is_ip_v4_or_v6($addr); @@ -377,8 +295,7 @@ sub delete_eth_addrs { my ($addr, $intf) = @_; if ($addr eq "dhcp") { - dhcp_release_addr($intf); - update_dhcp_client(); + stop_dhclient($intf); system("rm -f /var/lib/dhcp3/dhclient_$intf\_lease"); exit 0; } -- cgit v1.2.3 From 4219faf6dc245449b29184953d440fb83d6d3684 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Thu, 19 Jun 2008 17:18:52 -0700 Subject: Add a config ranking to prioritize bgp route-id ahead of neighbors. --- scripts/VyattaConfigLoad.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/VyattaConfigLoad.pm b/scripts/VyattaConfigLoad.pm index 90011f6..f1339c3 100755 --- a/scripts/VyattaConfigLoad.pm +++ b/scripts/VyattaConfigLoad.pm @@ -55,6 +55,7 @@ my %config_rank = ( my %regex_rank = ( 'interfaces ethernet \S* vrrp' => 500, 'interfaces ethernet \S* vif \S* vrrp' => 500, + 'protocols bgp \d+ parameters' => 810, 'protocols bgp \d+ neighbor \S*[^\d.]\S*' => 800, ); -- cgit v1.2.3 From bfc8a01de337eb28ea5a6597336635c107fafb63 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Fri, 20 Jun 2008 22:53:28 +0000 Subject: Fix bug 3059 Operator Level commands for DHCP client implemented op-mode commands for DHCP client: 'release dhcp interface <>' 'renew dhcp interface <>' --- scripts/vyatta-interfaces.pl | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index c35cfe0..6fdba14 100644 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -45,7 +45,7 @@ my $dhcp_daemon = '/sbin/dhclient'; my $dhclient_dir = '/var/lib/dhcp3/'; -my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update); +my ($eth_update, $eth_delete, $addr, $dev, $mac, $mac_update, $op_dhclient); GetOptions("eth-addr-update=s" => \$eth_update, "eth-addr-delete=s" => \$eth_delete, @@ -53,6 +53,7 @@ GetOptions("eth-addr-update=s" => \$eth_update, "dev=s" => \$dev, "valid-mac=s" => \$mac, "set-mac=s" => \$mac_update, + "op-command=s" => \$op_dhclient, ); if (defined $eth_update) { update_eth_addrs($eth_update, $dev); } @@ -60,6 +61,7 @@ if (defined $eth_delete) { delete_eth_addrs($eth_delete, $dev); } if (defined $addr) { is_valid_addr($addr, $dev); } if (defined $mac) { is_valid_mac($mac, $dev); } if (defined $mac_update) { update_mac($mac_update, $dev); } +if (defined $op_dhclient) { op_dhcp_command($op_dhclient, $dev); } sub is_ip_configured { my ($intf, $ip) = @_; @@ -243,7 +245,6 @@ sub stop_dhclient { my $cmd = "$dhcp_daemon -q -cf $intf_config_file -pf $intf_process_id_file -lf $intf_leases_file -r $intf 2> /dev/null"; system ($cmd); system ("rm -f $intf_config_file"); - } sub update_eth_addrs { @@ -433,6 +434,28 @@ sub is_valid_addr { exit 1; } +sub op_dhcp_command { + my ($op_command, $intf) = @_; + + if (!is_dhcp_enabled($intf)) { + print "$intf is not using DHCP to get an IP address\n"; + exit 1; + } + + if ($op_command eq "dhcp-release") { + print "Releasing DHCP lease on $intf ...\n"; + stop_dhclient($intf); + exit 0; + } elsif ($op_command eq "dhcp-renew") { + print "Renewing DHCP lease on $intf ...\n"; + run_dhclient($intf); + exit 0; + } + + exit 0; + +} + exit 0; # end of file -- cgit v1.2.3 From e30e8fe22035ebea101a88ead515a962936e6d31 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Sat, 21 Jun 2008 01:23:24 +0000 Subject: better handling of dhcp release/renew commands --- scripts/vyatta-interfaces.pl | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index 6fdba14..f1c6bbe 100644 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -252,6 +252,7 @@ sub update_eth_addrs { if ($addr eq "dhcp") { run_dhclient($intf); + system ("touch /var/lib/dhcp3/$intf\;"); return; } my $version = is_ip_v4_or_v6($addr); @@ -297,7 +298,7 @@ sub delete_eth_addrs { if ($addr eq "dhcp") { stop_dhclient($intf); - system("rm -f /var/lib/dhcp3/dhclient_$intf\_lease"); + system("rm -f /var/lib/dhcp3/dhclient_$intf\_lease; rm -f /var/lib/dhcp3/$intf\; rm -f /var/lib/dhcp3/$intf\_release;"); exit 0; } my $version = is_ip_v4_or_v6($addr); @@ -441,14 +442,22 @@ sub op_dhcp_command { print "$intf is not using DHCP to get an IP address\n"; exit 1; } - + + my $release_file = $dhclient_dir . $intf . '_release'; if ($op_command eq "dhcp-release") { - print "Releasing DHCP lease on $intf ...\n"; - stop_dhclient($intf); - exit 0; + if (-e $release_file) { + print "IP address for $intf has already been released.\n"; + exit 1; + } else { + print "Releasing DHCP lease on $intf ...\n"; + stop_dhclient($intf); + system ("touch $release_file\;"); + exit 0; + } } elsif ($op_command eq "dhcp-renew") { print "Renewing DHCP lease on $intf ...\n"; run_dhclient($intf); + system ("rm -f $release_file\;"); exit 0; } -- cgit v1.2.3 From 54b6ae5b4fe5717743e2ec7c0b9f622b8c0b45f4 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Sat, 21 Jun 2008 04:54:10 +0000 Subject: better handling of allowed values for 'release/renew dhcp interface <>' --- scripts/vyatta-interfaces.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index f1c6bbe..1511c12 100644 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -298,7 +298,7 @@ sub delete_eth_addrs { if ($addr eq "dhcp") { stop_dhclient($intf); - system("rm -f /var/lib/dhcp3/dhclient_$intf\_lease; rm -f /var/lib/dhcp3/$intf\; rm -f /var/lib/dhcp3/$intf\_release;"); + system("rm -f /var/lib/dhcp3/dhclient_$intf\_lease; rm -f /var/lib/dhcp3/$intf\; rm -f /var/lib/dhcp3/release_$intf\;"); exit 0; } my $version = is_ip_v4_or_v6($addr); @@ -443,7 +443,7 @@ sub op_dhcp_command { exit 1; } - my $release_file = $dhclient_dir . $intf . '_release'; + my $release_file = $dhclient_dir . 'release_' . $intf; if ($op_command eq "dhcp-release") { if (-e $release_file) { print "IP address for $intf has already been released.\n"; -- cgit v1.2.3 From 82c0cd30275f8cbfcec95cdc129e4f88cea12f0f Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Tue, 24 Jun 2008 17:32:50 -0700 Subject: Fix 3143: Unable to save/load config from a remote server. --- scripts/vyatta-load-config.pl | 76 ++++++++++++++++++++++++++++++++++++++----- scripts/vyatta-save-config.pl | 69 ++++++++++++++++++++++++++++++++------- 2 files changed, 125 insertions(+), 20 deletions(-) (limited to 'scripts') diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index 9513ffa..29d4dec 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -29,23 +29,83 @@ my $etcdir = $ENV{vyatta_sysconfdir}; my $sbindir = $ENV{vyatta_sbindir}; my $bootpath = $etcdir . "/config"; my $load_file = $bootpath . "/config.boot"; +my $url_tmp_file = $bootpath . "/config.boot.$$"; if ($#ARGV > 0) { print "Usage: load \n"; exit 1; } +my $mode = 'local'; +my $proto; + if (defined($ARGV[0])) { - $load_file = $ARGV[0]; - if (!($load_file =~ /^\//)) { - # relative path - $load_file = "$bootpath/$load_file"; - } + $load_file = $ARGV[0]; } -if (!open(CFG, "<$load_file")) { - print "Cannot open configuration file $load_file\n"; - exit 1; +if ($load_file =~ /^[^\/]\w+:\//) { + if ($load_file =~ /^(\w+):\/\/\w/) { + $mode = 'url'; + $proto = lc($1); + if ($proto eq 'tftp') { + } elsif ($proto eq 'ftp') { + } elsif ($proto eq 'http') { + } elsif ($proto eq 'scp') { + } else { + print "Invalid url protocol [$proto]\n"; + exit 1; + } + } else { + print "Invalid url [$load_file]\n"; + exit 1; + } +} + +if ($mode eq 'local' and !($load_file =~ /^\//)) { + # relative path + $load_file = "$bootpath/$load_file"; +} + +if ($mode eq 'local') { + if (!open(CFG, "<$load_file")) { + print "Cannot open configuration file $load_file\n"; + exit 1; + } +} elsif ($mode eq 'url') { + if (! -f '/usr/bin/curl') { + print "Package [curl] not installed\n"; + exit 1; + } + if ($proto eq 'http') { + # + # error codes are send back in html, so 1st try a header + # and look for "HTTP/1.1 200 OK" + # + my $rc = `curl -q -I $load_file 2>&1`; + if ($rc =~ /HTTP\/\d+\.?\d\s+(\d+)\s+(.*)$/mi) { + my $rc_code = $1; + my $rc_string = $2; + if ($rc_code == 200) { + # good resonse + } else { + print "http error: [$rc_code] $rc_string\n"; + exit 1; + } + } else { + print "Error: $rc\n"; + exit 1; + } + } + my $rc = system("curl -# -o $url_tmp_file $load_file"); + if ($rc) { + print "Can not open remote configuration file $load_file\n"; + exit 1; + } + if (!open(CFG, "<$url_tmp_file")) { + print "Cannot open configuration file $load_file\n"; + exit 1; + } + $load_file = $url_tmp_file; } while () { if (/\/\*XORP Configuration File, v1.0\*\//) { diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl index c759503..2c02766 100755 --- a/scripts/vyatta-save-config.pl +++ b/scripts/vyatta-save-config.pl @@ -26,6 +26,8 @@ use VyattaConfigOutput; my $etcdir = "/opt/vyatta/etc"; my $bootpath = $etcdir . "/config"; my $save_file = $bootpath . "/config.boot"; +my $url_tmp_file = $bootpath . "/config.boot.$$"; + if ($#ARGV > 0) { print "Usage: save [config_file_name]\n"; @@ -34,25 +36,68 @@ if ($#ARGV > 0) { if (defined($ARGV[0])) { $save_file = $ARGV[0]; - if (!($save_file =~ /^\//)) { - # relative path - $save_file = "$bootpath/$save_file"; +} + +my $mode = 'local'; +my $proto; + +if ($save_file =~ /^[^\/]\w+:\//) { + if ($save_file =~ /^(\w+):\/\/\w/) { + $mode = 'url'; + $proto = lc($1); + if ($proto eq 'tftp') { + } elsif ($proto eq 'ftp') { + } elsif ($proto eq 'scp') { + } else { + print "Invalid url protocol [$proto]\n"; + exit 1; + } + } else { + print "Invalid url [$save_file]\n"; + exit 1; } } -# this overwrites the file if it exists. we could create a backup first. -if (! open(SAVE, ">$save_file")) { - print "Cannot open file '$save_file': $!\n"; - exit 1; +if ($mode eq 'local' and !($save_file =~ /^\//)) { + # relative path + $save_file = "$bootpath/$save_file"; +} + +my $version_str = `/opt/vyatta/sbin/vyatta_current_conf_ver.pl`; +print "Saving configuration to '$save_file'...\n"; + +if ($mode eq 'local') { + # this overwrites the file if it exists. we could create a backup first. + if (! open(SAVE, ">$save_file")) { + print "Cannot open file '$save_file': $!\n"; + exit 1; + } +} elsif ($mode eq 'url') { + if (! -f '/usr/bin/curl') { + print "Package [curl] not installed\n"; + exit 1; + } + if (! open(SAVE, ">$url_tmp_file")) { + print "Cannot open file '$url_tmp_file': $!\n"; + exit 1; + } } -print "Saving configuration to '$save_file'..."; select SAVE; VyattaConfigOutput::set_show_all(1); VyattaConfigOutput::outputActiveConfig(); -my $version_str = `/opt/vyatta/sbin/vyatta_current_conf_ver.pl`; -print SAVE $version_str; -select STDOUT; -print "\nDone\n"; +print $version_str; close SAVE; +select STDOUT; + +if ($mode eq 'url') { + my $rc = system("curl -# -T $url_tmp_file $save_file"); + system("rm -f $url_tmp_file"); + if ($rc) { + print "Error saving $save_file\n"; + exit 1; + } +} + +print "Done\n"; exit 0; -- cgit v1.2.3 From 508087a450210fb6bfb4489f118c82f9515f61f5 Mon Sep 17 00:00:00 2001 From: Stig Thormodsrud Date: Tue, 24 Jun 2008 20:39:29 -0700 Subject: Fix 2619: Implement something similar to Juniper's "show | display set" functionality. --- Makefile.am | 1 + scripts/vyatta-config-gen-sets.pl | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 scripts/vyatta-config-gen-sets.pl (limited to 'scripts') diff --git a/Makefile.am b/Makefile.am index a309d34..7de4e17 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,6 +35,7 @@ sbin_SCRIPTS = scripts/vyatta-cfg-cmd-wrapper sbin_SCRIPTS += scripts/vyatta-validate-type.pl sbin_SCRIPTS += scripts/vyatta-find-type.pl sbin_SCRIPTS += scripts/vyatta-config-loader.pl +sbin_SCRIPTS += scripts/vyatta-config-gen-sets.pl sbin_SCRIPTS += scripts/vyatta-cli-expand-var.pl sbin_SCRIPTS += scripts/vyatta-output-config.pl sbin_SCRIPTS += scripts/vyatta-save-config.pl diff --git a/scripts/vyatta-config-gen-sets.pl b/scripts/vyatta-config-gen-sets.pl new file mode 100644 index 0000000..b9b083e --- /dev/null +++ b/scripts/vyatta-config-gen-sets.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +# Author: An-Cheng Huang +# Date: 2007 +# Description: hack of vyatta-config-load.pl to simple generate +# a list of the "set" commands from a config file. + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2006, 2007, 2008 Vyatta, Inc. +# All Rights Reserved. +# **** End License **** + +# Perl script for loading the startup config file. +# $0: startup config file. + +use strict; +use lib "/opt/vyatta/share/perl5/"; +use VyattaConfigLoad; + +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 = VyattaConfigLoad::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"; +} +print "commit\n"; + +exit 0; + -- cgit v1.2.3