diff options
19 files changed, 67 insertions, 3 deletions
diff --git a/scripts/vyatta-tshark-interface-port.pl b/scripts/vyatta-tshark-interface-port.pl index 4eff322..aa750e5 100644 --- a/scripts/vyatta-tshark-interface-port.pl +++ b/scripts/vyatta-tshark-interface-port.pl @@ -28,12 +28,39 @@ use lib "/opt/vyatta/share/perl5/"; use strict; use warnings; +sub check_if_interface_is_tsharkable { + my $interface = shift; + + my @grep_tshark_interfaces = `sudo /usr/bin/tshark -D | grep $interface`; + my $any_interface; + + for my $count (0 .. $#grep_tshark_interfaces) { + my @temp = split(/ /,$grep_tshark_interfaces[$count]); + chomp $temp[1]; + $grep_tshark_interfaces[$count] = $temp[1]; + } + + my $exact_match = 0; + for my $count (0 .. $#grep_tshark_interfaces) { + if ($grep_tshark_interfaces[$count] eq $interface) { + $exact_match = 1; + $any_interface = $grep_tshark_interfaces[$count]; + } + } + if ($exact_match == 0 || $any_interface eq 'any') { + print "Unable to capture traffic on $interface\n"; + exit 1; + } +} + # # main # my $intf = $ARGV[0]; +check_if_interface_is_tsharkable($intf); + if ($#ARGV > 0){ my $port = $ARGV[1]; my $not_port = $ARGV[2]; @@ -43,9 +70,11 @@ if ($#ARGV > 0){ } else { if (($port > 0) and ($port < 65536)){ if ($not_port == 0){ - exec "sudo /usr/bin/tshark -n -i $intf port $port"; + print "Capturing traffic on $intf port $port ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf port $port 2> /dev/null"; } else { - exec "sudo /usr/bin/tshark -n -i $intf not port $port"; + print "Capturing traffic on $intf excluding port $port ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf not port $port 2> /dev/null"; } } else { print "Invalid port number. Allowed values: <1-65535>\n"; @@ -54,7 +83,8 @@ if ($#ARGV > 0){ } } else { - exec "sudo /usr/bin/tshark -n -i $intf"; + print "Capturing traffic on $intf ...\n"; + exec "sudo /usr/bin/tshark -n -i $intf 2> /dev/null"; } exit 0; diff --git a/templates/show/interfaces/bridge/node.tag/capture/node.def b/templates/show/interfaces/bridge/node.tag/capture/node.def new file mode 100644 index 0000000..ef86b9c --- /dev/null +++ b/templates/show/interfaces/bridge/node.tag/capture/node.def @@ -0,0 +1,2 @@ +help: Show captured traffic on specified bridge interface +run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4" diff --git a/templates/show/interfaces/bridge/node.tag/capture/not/node.def b/templates/show/interfaces/bridge/node.tag/capture/not/node.def new file mode 100644 index 0000000..ecae454 --- /dev/null +++ b/templates/show/interfaces/bridge/node.tag/capture/not/node.def @@ -0,0 +1 @@ +help: Show captured traffic excluding the specified bridge interface port diff --git a/templates/show/interfaces/bridge/node.tag/capture/not/port/node.def b/templates/show/interfaces/bridge/node.tag/capture/not/port/node.def new file mode 100644 index 0000000..ecae454 --- /dev/null +++ b/templates/show/interfaces/bridge/node.tag/capture/not/port/node.def @@ -0,0 +1 @@ +help: Show captured traffic excluding the specified bridge interface port diff --git a/templates/show/interfaces/bridge/node.tag/capture/not/port/node.tag/node.def b/templates/show/interfaces/bridge/node.tag/capture/not/port/node.tag/node.def new file mode 100644 index 0000000..271106c --- /dev/null +++ b/templates/show/interfaces/bridge/node.tag/capture/not/port/node.tag/node.def @@ -0,0 +1,4 @@ +help: Show captured traffic excluding the specified bridge interface port +run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4" "$8" 1 +allowed: echo -n '<1-65535>' + diff --git a/templates/show/interfaces/bridge/node.tag/capture/port/node.def b/templates/show/interfaces/bridge/node.tag/capture/port/node.def new file mode 100644 index 0000000..43d1b9c --- /dev/null +++ b/templates/show/interfaces/bridge/node.tag/capture/port/node.def @@ -0,0 +1 @@ +help: Show captured traffic on specified bridge interface port diff --git a/templates/show/interfaces/bridge/node.tag/capture/port/node.tag/node.def b/templates/show/interfaces/bridge/node.tag/capture/port/node.tag/node.def new file mode 100644 index 0000000..7ad54b7 --- /dev/null +++ b/templates/show/interfaces/bridge/node.tag/capture/port/node.tag/node.def @@ -0,0 +1,3 @@ +help: Show captured traffic on specified bridge interface port +run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4" "$7" 0 +allowed: echo -n '<1-65535>' diff --git a/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/node.def b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/node.def new file mode 100644 index 0000000..190fd2f --- /dev/null +++ b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/node.def @@ -0,0 +1,2 @@ +help: Show captured traffic on specified ethernet virtual interface +run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4.$6" diff --git a/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/not/node.def b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/not/node.def new file mode 100644 index 0000000..7328773 --- /dev/null +++ b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/not/node.def @@ -0,0 +1 @@ +help: Show captured traffic excluding the specified ethernet virtual interface port diff --git a/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/not/port/node.def b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/not/port/node.def new file mode 100644 index 0000000..7328773 --- /dev/null +++ b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/not/port/node.def @@ -0,0 +1 @@ +help: Show captured traffic excluding the specified ethernet virtual interface port diff --git a/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/not/port/node.tag/node.def b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/not/port/node.tag/node.def new file mode 100644 index 0000000..258c6dc --- /dev/null +++ b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/not/port/node.tag/node.def @@ -0,0 +1,3 @@ +help: Show captured traffic excluding the specified ethernet interface port +run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4.$6" "${10}" 1 +allowed: echo -n '<1-65535>' diff --git a/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/port/node.def b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/port/node.def new file mode 100644 index 0000000..d61d229 --- /dev/null +++ b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/port/node.def @@ -0,0 +1 @@ +help: Show captured traffic on specified ethernet virtual interface port diff --git a/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/port/node.tag/node.def b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/port/node.tag/node.def new file mode 100644 index 0000000..4090508 --- /dev/null +++ b/templates/show/interfaces/ethernet/node.tag/vif/node.tag/capture/port/node.tag/node.def @@ -0,0 +1,3 @@ +help: Show captured traffic on specified ethernet virtual interface port +run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4.$6" "$9" 0 +allowed: echo -n '<1-65535>' diff --git a/templates/show/interfaces/loopback/node.tag/capture/node.def b/templates/show/interfaces/loopback/node.tag/capture/node.def new file mode 100644 index 0000000..231ea09 --- /dev/null +++ b/templates/show/interfaces/loopback/node.tag/capture/node.def @@ -0,0 +1,2 @@ +help: Show captured traffic on loopback interface +run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4" diff --git a/templates/show/interfaces/loopback/node.tag/capture/not/node.def b/templates/show/interfaces/loopback/node.tag/capture/not/node.def new file mode 100644 index 0000000..b5bd2e6 --- /dev/null +++ b/templates/show/interfaces/loopback/node.tag/capture/not/node.def @@ -0,0 +1 @@ +help: Show captured traffic excluding loopback interface port diff --git a/templates/show/interfaces/loopback/node.tag/capture/not/port/node.def b/templates/show/interfaces/loopback/node.tag/capture/not/port/node.def new file mode 100644 index 0000000..b5bd2e6 --- /dev/null +++ b/templates/show/interfaces/loopback/node.tag/capture/not/port/node.def @@ -0,0 +1 @@ +help: Show captured traffic excluding loopback interface port diff --git a/templates/show/interfaces/loopback/node.tag/capture/not/port/node.tag/node.def b/templates/show/interfaces/loopback/node.tag/capture/not/port/node.tag/node.def new file mode 100644 index 0000000..b8d8ff2 --- /dev/null +++ b/templates/show/interfaces/loopback/node.tag/capture/not/port/node.tag/node.def @@ -0,0 +1,3 @@ +help: Show captured traffic excluding loopback interface port +run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4" "$8" 1 +allowed: echo -n '<1-65535>' diff --git a/templates/show/interfaces/loopback/node.tag/capture/port/node.def b/templates/show/interfaces/loopback/node.tag/capture/port/node.def new file mode 100644 index 0000000..e46cf42 --- /dev/null +++ b/templates/show/interfaces/loopback/node.tag/capture/port/node.def @@ -0,0 +1 @@ +help: Show captured traffic on loopback interface port diff --git a/templates/show/interfaces/loopback/node.tag/capture/port/node.tag/node.def b/templates/show/interfaces/loopback/node.tag/capture/port/node.tag/node.def new file mode 100644 index 0000000..f1aedc4 --- /dev/null +++ b/templates/show/interfaces/loopback/node.tag/capture/port/node.tag/node.def @@ -0,0 +1,3 @@ +help: Show captured traffic on specified ethernet interface port +run: /opt/vyatta/bin/vyatta-tshark-interface-port.pl "$4" "$7" 0 +allowed: echo -n '<1-65535>' |