summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaurav <gaurav.sinha@vyatta.com>2012-04-09 18:06:33 -0700
committerGaurav <gaurav.sinha@vyatta.com>2012-04-09 18:06:33 -0700
commit187fff2adcf5b0e54ac7d5fec9289f4a3a025a5e (patch)
tree17701beee088483aa50f19f2a5260615aa8f8aca
parentab7c9cc58a8b6d2e31c54956293e72998dd1ff10 (diff)
downloadvyatta-conntrack-187fff2adcf5b0e54ac7d5fec9289f4a3a025a5e.tar.gz
vyatta-conntrack-187fff2adcf5b0e54ac7d5fec9289f4a3a025a5e.zip
fixing bug 7861, resolve protocol name from /etc/protocols.
-rw-r--r--lib/Vyatta/Conntrack/ConntrackUtil.pm18
-rwxr-xr-xscripts/vyatta-show-conntrack.pl9
2 files changed, 24 insertions, 3 deletions
diff --git a/lib/Vyatta/Conntrack/ConntrackUtil.pm b/lib/Vyatta/Conntrack/ConntrackUtil.pm
index 8f529c2..104f237 100644
--- a/lib/Vyatta/Conntrack/ConntrackUtil.pm
+++ b/lib/Vyatta/Conntrack/ConntrackUtil.pm
@@ -25,7 +25,23 @@
package Vyatta::Conntrack::ConntrackUtil;
use base qw(Exporter);
-our @EXPORT = qw(check_for_conntrack_hooks);
+our @EXPORT = qw(check_for_conntrack_hooks,
+ process_protocols);
+
+sub process_protocols {
+ my $proto = undef;
+ my %proto_hash = ();
+ my $PROTO_FILE = '/etc/protocols';
+ # do nothing if can't open
+ return if (!open($proto, $PROTO_FILE));
+ while (<$proto>) {
+ next if (/^\s*#/);
+ next if (!/^\S+\s+(\d+)\s+(\S+)\s/);
+ $proto_hash{$1} = $2;
+ }
+ close $proto;
+ return \%proto_hash;
+}
#function to find if connection tracking is enabled.
#looks in the iptables to see if any of the features introduced
diff --git a/scripts/vyatta-show-conntrack.pl b/scripts/vyatta-show-conntrack.pl
index 57a9799..e5b2629 100755
--- a/scripts/vyatta-show-conntrack.pl
+++ b/scripts/vyatta-show-conntrack.pl
@@ -36,8 +36,9 @@ use strict;
use Switch;
use Vyatta::TypeChecker;
-my $format = "%-10s %-22s %-22s %-12s %-20s\n";
-my $format_IPv6 = "%-10s %-40s %-40s %-12s %-20s\n";
+my $format = "%-10s %-22s %-22s %-16s %-20s\n";
+my $format_IPv6 = "%-10s %-40s %-40s %-16s %-20s\n";
+my $href; #reference to hash containing protocol-num to name key-value pairs
sub print_xml {
my ($data, $cache, $family) = @_;
@@ -45,6 +46,7 @@ sub print_xml {
my %flowh;
my $tcount = 0;
+ $href = process_protocols();
while (1) {
my $meta = 0;
last if ! defined $data->{flow}[$flow];
@@ -67,6 +69,9 @@ sub print_xml {
$dport{$dir} = $l4_ref->{dport}[0];
$proto{$dir} = $l4_ref->{protoname};
$protonum{$dir} = $l4_ref->{protonum};
+ if (($proto{$dir} eq 'unknown') and (defined($protonum{$dir}))) {
+ $proto{$dir} = lc(${$href}{$protonum{$dir}});
+ }
}
}
} elsif ($dir eq 'independent') {