diff options
author | Mohit Mehta <mohit.mehta@vyatta.com> | 2010-02-03 16:35:29 -0800 |
---|---|---|
committer | Mohit Mehta <mohit.mehta@vyatta.com> | 2010-02-03 16:35:29 -0800 |
commit | cf6127d4091e50b3c7817e78947529ca599e6781 (patch) | |
tree | fab0daefd9fc9a7b5ed302bfb2b42a49811328d8 /scripts/vyatta-clear-nat-counters.pl | |
parent | 19c6713d5d505cde98eee49031e7d7403bdad994 (diff) | |
download | vyatta-nat-cf6127d4091e50b3c7817e78947529ca599e6781.tar.gz vyatta-nat-cf6127d4091e50b3c7817e78947529ca599e6781.zip |
fix bug 4115 'clear nat translations' does not clear nat translations
* removed command 'clear nat translations'. connection tracking entries
can be flushed using 'clear connection-tracking' command
* use perl api to get currently active NAT rules
Diffstat (limited to 'scripts/vyatta-clear-nat-counters.pl')
-rwxr-xr-x | scripts/vyatta-clear-nat-counters.pl | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/scripts/vyatta-clear-nat-counters.pl b/scripts/vyatta-clear-nat-counters.pl index 53a0be3..90aea55 100755 --- a/scripts/vyatta-clear-nat-counters.pl +++ b/scripts/vyatta-clear-nat-counters.pl @@ -35,6 +35,22 @@ my %chain_hash = ( 'source' => 'POSTROUTING', 'destination' => 'PREROUTING', 'masquerade' => 'POSTROUTING'); +sub numerically { $a <=> $b; } + +sub get_nat_rules { + my $config = new Vyatta::Config; + $config->setLevel("service nat rule"); + my @rules = sort numerically $config->listOrigNodes(); + return @rules; +} + +sub print_nat_rules { + my @rules = get_nat_rules(); + my $rule_string = join(" ",@rules); + print $rule_string; + return; +} + sub clear_rule { my $clirule = shift; my $error = undef; @@ -45,15 +61,20 @@ sub clear_rule { return "error clearing NAT rule counters" if $error; } else { # clear counters for a specific NAT rule - my $config = new Vyatta::Config; - $config->setLevel("service nat rule"); - my @rules = $config->listOrigNodes(); + my @rules = get_nat_rules(); # validate that it's a legit CLI rule if (!((scalar(grep(/^$clirule$/, @rules)) > 0))) { return "Invalid NAT rule number \"$clirule\""; } + my $config = new Vyatta::Config; + $config->setLevel("service nat rule"); + + # make sure rule is enabled + my $is_rule_disabled = $config->existsOrig("$clirule disable"); + return "NAT rule $clirule is disabled" if defined $is_rule_disabled; + # determine rule type my $rule_type = $config->returnOrigValue("$clirule type"); @@ -77,14 +98,19 @@ sub clear_rule { # main # -my ($clirulenum); -GetOptions("clirule=s" => \$clirulenum); +my ($action, $clirulenum); + +GetOptions( "action=s" => \$action, + "clirule=s" => \$clirulenum); +die "undefined action" if ! defined $action; die "undefined rule number" if ! defined $clirulenum; my ($error, $warning); -($error, $warning) = clear_rule($clirulenum); +($error, $warning) = clear_rule($clirulenum) if $action eq 'clear-counters'; + +($error, $warning) = print_nat_rules() if $action eq 'print-nat-rules'; if (defined $warning) { print "$warning\n"; |