summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJames Davidson <james.davidson@vyatta.com>2013-04-25 15:29:09 -0700
committerJames Davidson <james.davidson@vyatta.com>2013-04-26 11:41:44 -0700
commit05903883b79ab3b23f51bd69458ca292fb0b3437 (patch)
tree0434ce0e90e71e99a86d33a5f9432fca1304a193 /scripts
parent88a21f1388a8e0599864d31c36edb42c738c7978 (diff)
downloadvyatta-op-05903883b79ab3b23f51bd69458ca292fb0b3437.tar.gz
vyatta-op-05903883b79ab3b23f51bd69458ca292fb0b3437.zip
Add size and files options to "traffic save"
Bug 8020 The total storage used by a traffic capture can be bounded by using the size and files options.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/vyatta-tshark.pl51
1 files changed, 44 insertions, 7 deletions
diff --git a/scripts/vyatta-tshark.pl b/scripts/vyatta-tshark.pl
index c065cbe..5423cfc 100755
--- a/scripts/vyatta-tshark.pl
+++ b/scripts/vyatta-tshark.pl
@@ -54,16 +54,48 @@ sub check_if_interface_is_tsharkable {
}
}
+my ($detail,$filter,$intf,$unlimited,$save,$files,$size);
+
+#
+# The size parameter can have one of the following
+# unit suffixes:
+#
+# - [kK] KiB (1024 bytes)
+# - [mM] MiB (1048576 bytes)
+# - [gG] GiB (1073741824 bytes)
+# - [tT] TiB (109951162778 bytes)
+#
+# Note: tshark's default size unit is KiB
+sub parse_size {
+ my ( $name, $parm ) = @_;
+ my %mult = ('T' => 1073741824, 't' => 1073741824,
+ 'G' => 1048576, 'g' => 1048576,
+ 'M' => 1024, 'm' => 1024,
+ 'K' => 1, 'k' => 1);
+
+ die "Invalid parameter: $name" if ($name ne "size");
+ my ( $value, $unit ) = $parm =~ m/^([0-9]+)([kKmMgGtT])?$/;
+ die "Invalid size specified" unless $value;
+ $unit = "K" unless $unit;
+ $size = $value * $mult{$unit};
+}
+
#
# main
#
-my ($detail,$filter,$intf,$unlimited,$save);
-GetOptions("detail!" => \$detail,
- "filter=s" => \$filter,
- "save=s" => \$save,
- "intf=s" => \$intf,
- "unlimited!" => \$unlimited);
+my $result = GetOptions("detail!" => \$detail,
+ "filter=s" => \$filter,
+ "save=s" => \$save,
+ "intf=s" => \$intf,
+ "unlimited!" => \$unlimited,
+ "files=i" => \$files,
+ "size=s" => \&parse_size);
+
+if (! $result) {
+ print "Invalid option specifications\n";
+ exit 1;
+}
check_if_interface_is_tsharkable($intf);
@@ -72,7 +104,12 @@ if (defined($save)){
print("Please name your file <filename>.pcap\n");
exit 1;
}
- exec "/usr/bin/tshark -i $intf -w '$save'";
+ my $options = "";
+
+ # the CLI will make sure that files is not defined w/o size also
+ $options .= " -a filesize:$size" if defined($size);
+ $options .= " -b files:$files" if defined($files);
+ exec "/usr/bin/tshark -i $intf -w '$save' $options";
exit 0;
}