summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStig Thormodsrud <stig@io.vyatta.com>2008-10-31 14:23:43 -0700
committerStig Thormodsrud <stig@io.vyatta.com>2008-10-31 14:23:43 -0700
commit69153fc9f6dcaa59e95847214fbab18f43992682 (patch)
treed690831b6dde0db8c99826bf281242c9d3b23630 /scripts
parentb83d5949749c5bceceefcd1dbe53fb5ee596089b (diff)
downloadvyatta-nat-69153fc9f6dcaa59e95847214fbab18f43992682.tar.gz
vyatta-nat-69153fc9f6dcaa59e95847214fbab18f43992682.zip
Fix "show nat translation monitor" to work with both snat & dnat.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/vyatta-nat-translations.pl18
1 files changed, 17 insertions, 1 deletions
diff --git a/scripts/vyatta-nat-translations.pl b/scripts/vyatta-nat-translations.pl
index abd5f5c..d156df8 100755
--- a/scripts/vyatta-nat-translations.pl
+++ b/scripts/vyatta-nat-translations.pl
@@ -33,7 +33,7 @@ use strict;
my $dump = 0;
my ($xml_file, $verbose, $proto, $stats, $ipaddr, $pipe);
-my $mode='both';
+my $mode;
my $verbose_format = "%-20s %-18s %-20s %-18s\n";
my $format = "%-20s %-20s %-4s %-4s %-8s";
@@ -61,6 +61,18 @@ sub print_xml {
print Dumper($data);
}
+sub guess_snat_dnat {
+ my ($src, $dst) = @_;
+
+ if ($src->{original} eq $dst->{reply}) {
+ return "dnat";
+ }
+ if ($dst->{original} eq $src->{reply}) {
+ return "snat";
+ }
+ return "unkn";
+}
+
sub nat_print_xml {
my ($data, $mode) = @_;
@@ -116,6 +128,9 @@ sub nat_print_xml {
if (defined $verbose) {
printf($verbose_format, $in_src, $in_dst, $out_src, $out_dst);
}
+ if (! defined $mode) {
+ $mode = guess_snat_dnat(\%src, \%dst);
+ }
if (defined $mode) {
my ($from, $to);
if ($mode eq 'snat') {
@@ -222,6 +237,7 @@ if (defined $xml_file) {
} else {
$proto = "";
}
+ $mode = 'both' if ! defined $mode;
if ($mode eq 'both' or $mode eq 'snat') {
my $ipopt = "";
if (defined $ipaddr) {