diff options
-rw-r--r-- | lib/Vyatta/Quagga/Config.pm | 55 | ||||
-rwxr-xr-x | scripts/bgp/vyatta-bgp.pl | 14 |
2 files changed, 51 insertions, 18 deletions
diff --git a/lib/Vyatta/Quagga/Config.pm b/lib/Vyatta/Quagga/Config.pm index 356afeac..3f4cfa07 100644 --- a/lib/Vyatta/Quagga/Config.pm +++ b/lib/Vyatta/Quagga/Config.pm @@ -95,26 +95,26 @@ sub returnQuaggaCommands { # methods to send the commands to Quagga sub setConfigTree { - my ($self, $level) = @_; - if (_setConfigTree($level, 0, 0)) { return 1; } + my ($self, $level, @skip_list) = @_; + if (_setConfigTree($level, 0, 0, @skip_list)) { return 1; } return 0; } sub setConfigTreeRecursive { - my ($self, $level) = @_; - if (_setConfigTree($level, 0, 1)) { return 1; } + my ($self, $level, @skip_list) = @_; + if (_setConfigTree($level, 0, 1, @skip_list)) { return 1; } return 0; } sub deleteConfigTree { - my ($self, $level) = @_; - if (_setConfigTree($level, 1, 0)) { return 1; } + my ($self, $level, @skip_list) = @_; + if (_setConfigTree($level, 1, 0, @skip_list)) { return 1; } return 0; } sub deleteConfigTreeRecursive { - my ($self, $level) = @_; - if (_setConfigTree($level, 1, 1)) { return 1; } + my ($self, $level, @skip_list) = @_; + if (_setConfigTree($level, 1, 1, @skip_list)) { return 1; } return 0; } @@ -129,9 +129,11 @@ sub deleteConfigTreeRecursive { # input: $1 - level of the tree to start at # $2 - delete bool # $3 - recursive bool +# $4 - arrays of strings to skip # output: none, return failure if needed sub _setConfigTree { - my ($level, $delete, $recurse) = @_; + my ($level, $delete, $recurse, @skip_list) = @_; + my $qcom = $_qcomref; if ((! defined $level) || (! defined $delete) || @@ -148,18 +150,38 @@ sub _setConfigTree { $sortfunc = \&cmpb; } - if ($_DEBUG >= 3) { print "DEBUG: _setConfigTree - enter - level: $level\tdelete: $delete\trecurse: $recurse\n"; } + if ($_DEBUG >= 3) { + print "DEBUG: _setConfigTree - enter - level: $level\tdelete: $delete\trecurse: $recurse\tskip: "; + foreach my $key (@skip_list) { print "$key "; } + print "\n"; + } - my @keys; foreach my $key (sort $sortfunc keys %$vtyshref) { if ($_DEBUG >= 3) { print "DEBUG: _setConfigTree - key $key\n"; } + # skip parameters in skip_list + my $found = 0; + if ((scalar @skip_list) > 0) { + foreach my $node (@skip_list) { + if ($key =~ /$node/) { + $found = 1; + if ($_DEBUG >= 3) { print "DEBUG: _setConfigTree - key $node in skip list\n"; } + } + } + } + if ($found) { next; } + + # should we run the vtysh command with noerr? + my $noerr = ''; + if ($qcom->{$key}->{'noerr'}) { $noerr = 1; } + + # this conditional matches key to level exactly or if recurse, start of key to level if ((($recurse) && ($key =~ /^$level/)) || ((! $recurse) && ($key =~ /^$level$/))) { my $index = 0; foreach my $cmd (@{$vtyshref->{$key}}) { if ($_DEBUG >= 2) { print "DEBUG: _setConfigTree - key: $key \t cmd: $cmd\n"; } - if (! _sendQuaggaCommand("$cmd")) { return 0; } + if (! _sendQuaggaCommand("$cmd", "$noerr")) { return 0; } # remove this command so we don't hit it again in another Recurse call delete ${$vtyshref->{$key}}[$index]; $index++; @@ -178,8 +200,10 @@ sub cmpb { $b cmp $a } # input: $1 - qVarReplaced Quagga Command string # output: none, return failure if needed sub _sendQuaggaCommand { - my ($command) = @_; - my $args = "$_vtyshexe --noerr -c 'configure terminal' "; + my ($command, $noerr) = @_; + + if ($noerr) { $noerr = '--noerr'; } + my $args = "$_vtyshexe $noerr -c 'configure terminal' "; my @commands = split / ; /, $command; foreach my $section (@commands) { @@ -190,8 +214,7 @@ sub _sendQuaggaCommand { # TODO: need to fix this system call. split into command and args. system("$args"); if ($? != 0) { - # TODO: note that DEBUG will never happen here with --noerr as an argument. - # need to fix --noerr. Also probably need to code a way to conditionally use --noerr. + # TODO: need to fix to return error on output and error codes. if ($_DEBUG) { print "DEBUG: _sendQuaggaCommand - vtysh failure $? - $args\n"; print "\n"; diff --git a/scripts/bgp/vyatta-bgp.pl b/scripts/bgp/vyatta-bgp.pl index 12b1349f..b72deab9 100755 --- a/scripts/bgp/vyatta-bgp.pl +++ b/scripts/bgp/vyatta-bgp.pl @@ -148,7 +148,7 @@ my %qcom = ( del => undef, }, "protocols bgp var neighbor var" => { - set => "router bgp #3 ; neighbor #5", + set => undef, del => "router bgp #3 ; no neighbor #5", }, "protocols bgp var neighbor var address-family" => { @@ -1213,8 +1213,18 @@ sub main { #$qconfig->_reInitialize(); # deletes with priority + # TODO: need to put syntax check in remote-as + # delete everything in neighbhor except for the important nodes + my @skip_array = ('remote-as', 'route-map', 'filter-list', 'prefix-list', 'distribute-list', 'unsuppress-map'); + # notice the extra space in the level string. keeps the parent from being deleted. + $qconfig->deleteConfigTreeRecursive('protocols bgp var neighbor var ', @skip_array) || die "exiting $?\n"; + # now delete everything in neighbor except remote-as + @skip_array = ('remote-as'); + $qconfig->deleteConfigTreeRecursive('protocols bgp var neighbor var ', @skip_array) || die "exiting $?\n"; + # now finish off neighbor + $qconfig->deleteConfigTreeRecursive('protocols bgp var neighbor var') || die "exiting $?\n"; + # now delete everything else $qconfig->deleteConfigTreeRecursive('protocols bgp') || die "exiting $?\n"; - # would be cool if I could add a recursive delete such as everything but (protocols bgp var neigh var remote-as) # sets with priority $qconfig->setConfigTreeRecursive('protocols bgp var parameters') || die "exiting $?\n"; |