2005-12-13 23:15:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2006-05-22 08:21:22 +00:00
|
|
|
# Test the capture engine of the Wireshark tools
|
2005-12-13 23:15:20 +00:00
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
2006-05-21 05:12:17 +00:00
|
|
|
# Wireshark - Network traffic analyzer
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
2005-12-13 23:15:20 +00:00
|
|
|
# Copyright 2005 Ulf Lamping
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2006-12-11 18:24:27 +00:00
|
|
|
# along with this program; if not, writeto the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-10-09 18:47:42 +00:00
|
|
|
#
|
2005-12-13 23:15:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
# common exit status values
|
|
|
|
EXIT_OK=0
|
|
|
|
EXIT_COMMAND_LINE=1
|
|
|
|
EXIT_ERROR=2
|
|
|
|
|
2013-03-18 15:39:12 +00:00
|
|
|
WIRESHARK_CMD="$WIRESHARK -o gui.update.enabled:FALSE -k"
|
2012-05-30 21:42:24 +00:00
|
|
|
|
2007-01-28 18:56:17 +00:00
|
|
|
capture_test_output_print() {
|
|
|
|
wait
|
|
|
|
for f in "$@"; do
|
|
|
|
if [[ -f "$f" ]]; then
|
2013-03-01 16:13:44 +00:00
|
|
|
printf " --> $f\n"
|
|
|
|
cat "$f"
|
|
|
|
printf "\n"
|
2007-01-28 18:56:17 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2006-12-11 18:24:27 +00:00
|
|
|
traffic_gen_ping() {
|
|
|
|
# Generate some traffic for quiet networks.
|
|
|
|
# This will have to be adjusted for non-Windows systems.
|
2011-05-26 20:23:38 +00:00
|
|
|
|
2008-04-13 18:50:45 +00:00
|
|
|
# the following will run in the background and return immediately
|
2007-05-17 02:43:38 +00:00
|
|
|
{
|
2007-11-08 16:59:30 +00:00
|
|
|
date
|
2008-04-13 18:50:45 +00:00
|
|
|
for (( x=28; x<=58; x++ )) # in effect: number the packets
|
2007-05-17 02:43:38 +00:00
|
|
|
do
|
2007-09-28 23:40:51 +00:00
|
|
|
# How does ping _not_ have a standard set of arguments?
|
|
|
|
case $WS_SYSTEM in
|
|
|
|
Windows)
|
|
|
|
ping -n 1 -l $x www.wireshark.org ;;
|
|
|
|
SunOS)
|
2007-11-29 08:17:44 +00:00
|
|
|
/usr/sbin/ping www.wireshark.org $x 1 ;;
|
2007-09-28 23:40:51 +00:00
|
|
|
*) # *BSD, Linux
|
|
|
|
ping -c 1 -s $x www.wireshark.org ;;
|
|
|
|
esac
|
2007-05-17 02:43:38 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
date
|
|
|
|
} > ./testout_ping.txt 2>&1 &
|
2007-01-28 18:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ping_cleanup() {
|
|
|
|
wait
|
|
|
|
rm -f ./testout_ping.txt
|
2006-12-11 18:24:27 +00:00
|
|
|
}
|
2005-12-13 23:15:20 +00:00
|
|
|
|
|
|
|
# capture exactly 10 packets
|
|
|
|
capture_step_10packets() {
|
2007-09-28 23:40:51 +00:00
|
|
|
if [ $SKIP_CAPTURE -ne 0 ] ; then
|
2006-12-11 18:24:27 +00:00
|
|
|
test_step_skipped
|
|
|
|
return
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2006-12-11 18:24:27 +00:00
|
|
|
traffic_gen_ping
|
2007-02-05 00:57:59 +00:00
|
|
|
|
|
|
|
date > ./testout.txt
|
2006-12-11 18:24:27 +00:00
|
|
|
$DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
|
|
|
|
-w ./testout.pcap \
|
|
|
|
-c 10 \
|
|
|
|
-a duration:$TRAFFIC_CAPTURE_DURATION \
|
2006-12-22 18:16:22 +00:00
|
|
|
-f icmp \
|
2007-02-05 00:57:59 +00:00
|
|
|
>> ./testout.txt 2>&1
|
2005-12-13 23:15:20 +00:00
|
|
|
RETURNVALUE=$?
|
2007-02-05 00:57:59 +00:00
|
|
|
date >> ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
|
2006-12-22 04:46:26 +00:00
|
|
|
echo
|
2007-01-28 18:56:17 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
# part of the Prerequisite checks
|
2006-12-22 04:46:26 +00:00
|
|
|
# wrong interface ? output the possible interfaces
|
2006-05-31 17:38:42 +00:00
|
|
|
$TSHARK -D
|
2006-12-22 04:46:26 +00:00
|
|
|
test_step_failed "exit status of $DUT: $RETURNVALUE"
|
2005-12-13 23:15:20 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# we should have an output file now
|
|
|
|
if [ ! -f "./testout.pcap" ]; then
|
2011-07-11 22:41:53 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
test_step_failed "No output file!"
|
|
|
|
return
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2005-12-13 23:15:20 +00:00
|
|
|
# ok, we got a capture file, does it contain exactly 10 packets?
|
2007-01-28 18:56:17 +00:00
|
|
|
$CAPINFOS ./testout.pcap > ./testout2.txt
|
2009-05-11 18:57:08 +00:00
|
|
|
grep -Ei 'Number of packets:[[:blank:]]+10' ./testout2.txt > /dev/null
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
test_step_ok
|
|
|
|
else
|
|
|
|
echo
|
2013-03-01 16:13:44 +00:00
|
|
|
$TSHARK -ta -r ./testout.pcap >> ./testout2.txt
|
2007-01-28 18:56:17 +00:00
|
|
|
capture_test_output_print ./testout_ping.txt ./testout.txt ./testout2.txt
|
2006-01-05 22:26:05 +00:00
|
|
|
# part of the Prerequisite checks
|
|
|
|
# probably wrong interface, output the possible interfaces
|
2006-05-31 17:38:42 +00:00
|
|
|
$TSHARK -D
|
2006-01-05 22:26:05 +00:00
|
|
|
test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# capture exactly 10 packets using "-w -" (piping to stdout)
|
|
|
|
capture_step_10packets_stdout() {
|
2013-03-01 16:13:44 +00:00
|
|
|
if [ $SKIP_CAPTURE -ne 0 ] ; then
|
|
|
|
test_step_skipped
|
|
|
|
return
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2006-12-11 18:24:27 +00:00
|
|
|
traffic_gen_ping
|
2007-02-05 00:57:59 +00:00
|
|
|
|
|
|
|
date > ./testout.txt
|
2006-12-11 18:24:27 +00:00
|
|
|
$DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
|
|
|
|
-c 10 \
|
|
|
|
-a duration:$TRAFFIC_CAPTURE_DURATION \
|
|
|
|
-w - \
|
2006-12-22 18:16:22 +00:00
|
|
|
-f icmp \
|
2007-02-05 00:57:59 +00:00
|
|
|
> ./testout.pcap 2>>./testout.txt
|
2006-01-05 22:26:05 +00:00
|
|
|
RETURNVALUE=$?
|
2007-02-05 00:57:59 +00:00
|
|
|
date >> ./testout.txt
|
2006-01-05 22:26:05 +00:00
|
|
|
if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
|
2006-12-22 13:00:40 +00:00
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2006-05-31 17:38:42 +00:00
|
|
|
$TSHARK -D
|
2006-12-22 04:46:26 +00:00
|
|
|
test_step_failed "exit status of $DUT: $RETURNVALUE"
|
2006-01-05 22:26:05 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# we should have an output file now
|
|
|
|
if [ ! -f "./testout.pcap" ]; then
|
|
|
|
test_step_failed "No output file!"
|
|
|
|
return
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2006-01-05 22:26:05 +00:00
|
|
|
# ok, we got a capture file, does it contain exactly 10 packets?
|
|
|
|
$CAPINFOS ./testout.pcap > ./testout2.txt 2>&1
|
2009-05-11 18:57:08 +00:00
|
|
|
grep -Ei 'Number of packets:[[:blank:]]+10' ./testout2.txt > /dev/null
|
2006-01-05 22:26:05 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
test_step_ok
|
|
|
|
else
|
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt ./testout2.txt
|
2006-05-31 17:38:42 +00:00
|
|
|
$TSHARK -D
|
2006-01-05 22:26:05 +00:00
|
|
|
test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
|
2005-12-13 23:15:20 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2006-10-08 22:57:32 +00:00
|
|
|
# capture packets via a fifo
|
|
|
|
capture_step_fifo() {
|
|
|
|
mkfifo 'fifo'
|
2012-03-30 18:19:35 +00:00
|
|
|
(cat "${CAPTURE_DIR}dhcp.pcap"; sleep 1; tail -c +25 "${CAPTURE_DIR}dhcp.pcap") > fifo &
|
2006-12-11 18:24:27 +00:00
|
|
|
$DUT -i fifo $TRAFFIC_CAPTURE_PROMISC \
|
|
|
|
-w ./testout.pcap \
|
|
|
|
-a duration:$TRAFFIC_CAPTURE_DURATION \
|
|
|
|
> ./testout.txt 2>&1
|
2006-10-08 22:57:32 +00:00
|
|
|
RETURNVALUE=$?
|
|
|
|
rm 'fifo'
|
|
|
|
if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2006-10-08 22:57:32 +00:00
|
|
|
test_step_failed "exit status of $DUT: $RETURNVALUE"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# we should have an output file now
|
|
|
|
if [ ! -f "./testout.pcap" ]; then
|
|
|
|
test_step_failed "No output file!"
|
|
|
|
return
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2006-10-08 22:57:32 +00:00
|
|
|
# ok, we got a capture file, does it contain exactly 8 packets?
|
|
|
|
$CAPINFOS ./testout.pcap > ./testout.txt
|
2009-05-11 18:57:08 +00:00
|
|
|
grep -Ei 'Number of packets:[[:blank:]]+8' ./testout.txt > /dev/null
|
2006-10-08 22:57:32 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
test_step_ok
|
|
|
|
else
|
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2006-10-08 22:57:32 +00:00
|
|
|
test_step_failed "No or not enough traffic captured."
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
}
|
2006-10-08 22:57:32 +00:00
|
|
|
|
2011-05-26 20:23:38 +00:00
|
|
|
# capture packets via a fifo
|
|
|
|
capture_step_stdin() {
|
2013-03-01 16:13:44 +00:00
|
|
|
CONSOLE_LOG_ARGS=""
|
|
|
|
if [ "$DUT" == "$WIRESHARK_CMD" -a "$WS_SYSTEM" == "Windows" ] ; then
|
|
|
|
CONSOLE_LOG_ARGS="-o console.log.level:127"
|
|
|
|
fi
|
2012-05-30 21:42:24 +00:00
|
|
|
|
2012-03-30 18:19:35 +00:00
|
|
|
(cat "${CAPTURE_DIR}dhcp.pcap"; sleep 1; tail -c +25 "${CAPTURE_DIR}dhcp.pcap") | \
|
2011-05-26 20:23:38 +00:00
|
|
|
$DUT -i - $TRAFFIC_CAPTURE_PROMISC \
|
|
|
|
-w ./testout.pcap \
|
|
|
|
-a duration:$TRAFFIC_CAPTURE_DURATION \
|
2013-03-01 16:13:44 +00:00
|
|
|
$CONSOLE_LOG_ARGS \
|
2012-05-30 21:42:24 +00:00
|
|
|
> ./testout.txt 2> ./testerr.txt
|
2011-05-26 20:23:38 +00:00
|
|
|
RETURNVALUE=$?
|
|
|
|
if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
|
2012-05-30 21:42:24 +00:00
|
|
|
capture_test_output_print ./testout.txt ./testerr.txt ./dumpcap_debug_log.tmp
|
|
|
|
test_step_failed "Exit status of $DUT: $RETURNVALUE"
|
2011-05-26 20:23:38 +00:00
|
|
|
return
|
|
|
|
fi
|
2013-03-01 06:20:41 +00:00
|
|
|
|
2013-03-01 16:13:44 +00:00
|
|
|
if [ -n "$CONSOLE_LOG_ARGS" ] ; then
|
|
|
|
grep "Wireshark is up and ready to go" ./testout.txt > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
test_step_failed "No startup message!"
|
|
|
|
fi
|
2012-05-30 21:42:24 +00:00
|
|
|
|
2013-03-01 16:13:44 +00:00
|
|
|
grep "Capture started" ./testerr.txt > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
test_step_failed "No capture started message!"
|
|
|
|
fi
|
2012-05-30 21:42:24 +00:00
|
|
|
|
2013-03-01 16:13:44 +00:00
|
|
|
grep "Capture stopped" ./testerr.txt > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
test_step_failed "No capture stopped message!"
|
|
|
|
fi
|
|
|
|
fi
|
2011-05-26 20:23:38 +00:00
|
|
|
|
|
|
|
# we should have an output file now
|
|
|
|
if [ ! -f "./testout.pcap" ]; then
|
|
|
|
test_step_failed "No output file!"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ok, we got a capture file, does it contain exactly 8 packets?
|
|
|
|
$CAPINFOS ./testout.pcap > ./testout.txt
|
|
|
|
grep -Ei 'Number of packets:[[:blank:]]+8' ./testout.txt > /dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
test_step_ok
|
|
|
|
else
|
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2011-05-26 20:23:38 +00:00
|
|
|
test_step_failed "No or not enough traffic captured."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2006-01-05 22:26:05 +00:00
|
|
|
# capture exactly 2 times 10 packets (multiple files)
|
2005-12-13 23:15:20 +00:00
|
|
|
capture_step_2multi_10packets() {
|
2013-03-01 16:13:44 +00:00
|
|
|
if [ $SKIP_CAPTURE -ne 0 ] ; then
|
|
|
|
test_step_skipped
|
|
|
|
return
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2006-12-11 18:24:27 +00:00
|
|
|
traffic_gen_ping
|
2007-02-05 00:57:59 +00:00
|
|
|
|
|
|
|
date > ./testout.txt
|
2006-12-11 18:24:27 +00:00
|
|
|
$DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
|
|
|
|
-w ./testout.pcap \
|
|
|
|
-c 10 \
|
|
|
|
-a duration:$TRAFFIC_CAPTURE_DURATION \
|
2006-12-22 18:16:22 +00:00
|
|
|
-f icmp \
|
2007-02-05 00:57:59 +00:00
|
|
|
>> ./testout.txt 2>&1
|
2006-12-11 18:24:27 +00:00
|
|
|
|
2005-12-13 23:15:20 +00:00
|
|
|
RETURNVALUE=$?
|
2007-02-05 00:57:59 +00:00
|
|
|
date >> ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
|
2006-12-22 13:00:40 +00:00
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
# part of the Prerequisite checks
|
|
|
|
# probably wrong interface, output the possible interfaces
|
2006-05-31 17:38:42 +00:00
|
|
|
$TSHARK -D
|
2006-12-22 04:46:26 +00:00
|
|
|
test_step_failed "exit status of $DUT: $RETURNVALUE"
|
2005-12-13 23:15:20 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# we should have an output file now
|
|
|
|
if [ ! -f "./testout.pcap" ]; then
|
|
|
|
test_step_failed "No output file!"
|
|
|
|
return
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2005-12-13 23:15:20 +00:00
|
|
|
# ok, we got a capture file, does it contain exactly 10 packets?
|
|
|
|
$CAPINFOS ./testout.pcap > ./testout.txt
|
2009-05-11 18:57:08 +00:00
|
|
|
grep -Ei 'Number of packets:[[:blank:]]+10' ./testout.txt > /dev/null
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
test_step_ok
|
|
|
|
else
|
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
test_step_failed "Probably the wrong interface (no traffic captured)!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# capture with a very unlikely read filter, packets must be zero afterwards
|
|
|
|
capture_step_read_filter() {
|
2013-03-01 16:13:44 +00:00
|
|
|
if [ $SKIP_CAPTURE -ne 0 ] ; then
|
|
|
|
test_step_skipped
|
|
|
|
return
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2006-12-11 18:24:27 +00:00
|
|
|
traffic_gen_ping
|
2007-02-05 00:57:59 +00:00
|
|
|
|
2005-12-13 23:15:20 +00:00
|
|
|
# valid, but very unlikely filter
|
2007-02-05 00:57:59 +00:00
|
|
|
date > ./testout.txt
|
2006-12-11 18:24:27 +00:00
|
|
|
$DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
|
|
|
|
-w ./testout.pcap \
|
|
|
|
-a duration:$TRAFFIC_CAPTURE_DURATION \
|
|
|
|
-R 'dcerpc.cn_call_id==123456' \
|
|
|
|
-c 10 \
|
2006-12-22 18:16:22 +00:00
|
|
|
-f icmp \
|
2007-02-05 00:57:59 +00:00
|
|
|
>> ./testout.txt 2>&1
|
2005-12-13 23:15:20 +00:00
|
|
|
RETURNVALUE=$?
|
2007-02-05 00:57:59 +00:00
|
|
|
date >> ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
|
2006-12-22 13:00:40 +00:00
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2006-12-22 13:00:40 +00:00
|
|
|
# part of the Prerequisite checks
|
|
|
|
# wrong interface ? output the possible interfaces
|
|
|
|
$TSHARK -D
|
2005-12-13 23:15:20 +00:00
|
|
|
test_step_failed "exit status: $RETURNVALUE"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# we should have an output file now
|
|
|
|
if [ ! -f "./testout.pcap" ]; then
|
|
|
|
test_step_failed "No output file!"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ok, we got a capture file, does it contain exactly 0 packets?
|
|
|
|
$CAPINFOS ./testout.pcap > ./testout.txt
|
2009-05-11 18:57:08 +00:00
|
|
|
grep -Ei 'Number of packets:[[:blank:]]+0' ./testout.txt > /dev/null
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
test_step_ok
|
|
|
|
else
|
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
test_step_failed "Capture file should contain zero packets!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# capture with a snapshot length
|
|
|
|
capture_step_snapshot() {
|
2013-03-01 06:20:41 +00:00
|
|
|
if [ $SKIP_CAPTURE -ne 0 ] ; then
|
|
|
|
test_step_skipped
|
|
|
|
return
|
|
|
|
fi
|
2006-10-09 18:47:42 +00:00
|
|
|
|
2006-12-11 18:24:27 +00:00
|
|
|
traffic_gen_ping
|
|
|
|
|
2005-12-13 23:15:20 +00:00
|
|
|
# capture with a snapshot length of 68 bytes for $TRAFFIC_CAPTURE_DURATION seconds
|
2007-05-17 02:43:38 +00:00
|
|
|
# this should result in no packets greater than 68 bytes
|
2007-02-05 00:57:59 +00:00
|
|
|
date > ./testout.txt
|
2006-12-11 18:24:27 +00:00
|
|
|
$DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
|
|
|
|
-w ./testout.pcap \
|
|
|
|
-s 68 \
|
2006-12-22 18:16:22 +00:00
|
|
|
-a duration:$TRAFFIC_CAPTURE_DURATION \
|
|
|
|
-f icmp \
|
2007-02-05 00:57:59 +00:00
|
|
|
>> ./testout.txt 2>&1
|
2005-12-13 23:15:20 +00:00
|
|
|
RETURNVALUE=$?
|
2007-02-05 00:57:59 +00:00
|
|
|
date >> ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
|
2006-12-22 13:00:40 +00:00
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2006-12-22 13:00:40 +00:00
|
|
|
# part of the Prerequisite checks
|
|
|
|
# wrong interface ? output the possible interfaces
|
|
|
|
$TSHARK -D
|
2005-12-13 23:15:20 +00:00
|
|
|
test_step_failed "exit status: $RETURNVALUE"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# we should have an output file now
|
|
|
|
if [ ! -f "./testout.pcap" ]; then
|
|
|
|
test_step_failed "No output file!"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2006-05-31 17:38:42 +00:00
|
|
|
# use tshark to filter out all packets, which are larger than 68 bytes
|
|
|
|
$TSHARK -r ./testout.pcap -w ./testout2.pcap -R 'frame.cap_len>68' > ./testout.txt 2>&1
|
2011-06-23 19:22:21 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2011-06-23 19:22:21 +00:00
|
|
|
test_step_failed "Problem running TShark!"
|
|
|
|
return
|
|
|
|
fi
|
2005-12-13 23:15:20 +00:00
|
|
|
|
|
|
|
# ok, we got a capture file, does it contain exactly 0 packets?
|
|
|
|
$CAPINFOS ./testout2.pcap > ./testout.txt
|
2009-05-11 18:57:08 +00:00
|
|
|
grep -Ei 'Number of packets:[[:blank:]]+0' ./testout.txt > /dev/null
|
2005-12-13 23:15:20 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
test_step_ok
|
|
|
|
else
|
|
|
|
echo
|
2011-06-28 23:08:05 +00:00
|
|
|
capture_test_output_print ./testout.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
test_step_failed "Capture file should contain zero packets!"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2006-06-17 11:49:03 +00:00
|
|
|
wireshark_capture_suite() {
|
2011-08-29 21:16:29 +00:00
|
|
|
# k: start capture immediately
|
|
|
|
# WIRESHARK_QUIT_AFTER_CAPTURE needs to be set.
|
2012-05-30 21:42:24 +00:00
|
|
|
DUT="$WIRESHARK_CMD"
|
2005-12-13 23:15:20 +00:00
|
|
|
test_step_add "Capture 10 packets" capture_step_10packets
|
2006-06-17 11:49:03 +00:00
|
|
|
# piping to stdout doesn't work with Wireshark and capturing!
|
2006-01-06 01:11:31 +00:00
|
|
|
#test_step_add "Capture 10 packets using stdout: -w -" capture_step_10packets_stdout
|
2011-05-31 18:34:24 +00:00
|
|
|
if [ $TEST_FIFO ]; then
|
|
|
|
test_step_add "Capture via fifo" capture_step_fifo
|
|
|
|
fi
|
|
|
|
test_step_add "Capture via stdin" capture_step_stdin
|
2006-06-17 11:49:03 +00:00
|
|
|
# read filter doesn't work with Wireshark and capturing!
|
2005-12-13 23:15:20 +00:00
|
|
|
#test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
|
|
|
|
test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
|
|
|
|
}
|
|
|
|
|
2006-05-31 17:38:42 +00:00
|
|
|
tshark_capture_suite() {
|
|
|
|
DUT=$TSHARK
|
2005-12-13 23:15:20 +00:00
|
|
|
test_step_add "Capture 10 packets" capture_step_10packets
|
2007-10-09 13:34:08 +00:00
|
|
|
test_step_add "Capture 10 packets using stdout: -w -" capture_step_10packets_stdout
|
2006-10-08 22:57:32 +00:00
|
|
|
if [ $TEST_FIFO ]; then
|
|
|
|
test_step_add "Capture via fifo" capture_step_fifo
|
|
|
|
fi
|
2011-05-26 20:23:38 +00:00
|
|
|
test_step_add "Capture via stdin" capture_step_stdin
|
2010-06-05 02:19:45 +00:00
|
|
|
# tshark now using dumpcap for capturing, read filters won't work by definition
|
2007-11-23 08:39:11 +00:00
|
|
|
#test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
|
2005-12-13 23:15:20 +00:00
|
|
|
test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
|
|
|
|
}
|
|
|
|
|
|
|
|
dumpcap_capture_suite() {
|
|
|
|
#DUT="$DUMPCAP -Q"
|
|
|
|
DUT=$DUMPCAP
|
|
|
|
test_step_add "Capture 10 packets" capture_step_10packets
|
2006-01-07 01:14:29 +00:00
|
|
|
test_step_add "Capture 10 packets using stdout: -w -" capture_step_10packets_stdout
|
2006-10-08 22:57:32 +00:00
|
|
|
if [ $TEST_FIFO ]; then
|
|
|
|
test_step_add "Capture via fifo" capture_step_fifo
|
|
|
|
fi
|
2011-05-26 20:23:38 +00:00
|
|
|
test_step_add "Capture via stdin" capture_step_stdin
|
2006-01-07 01:14:29 +00:00
|
|
|
# read (display) filters intentionally doesn't work with dumpcap!
|
2005-12-13 23:15:20 +00:00
|
|
|
#test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
|
|
|
|
test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
|
|
|
|
}
|
|
|
|
|
2006-01-05 22:26:05 +00:00
|
|
|
capture_cleanup_step() {
|
2007-01-28 18:56:17 +00:00
|
|
|
ping_cleanup
|
2005-12-13 23:15:20 +00:00
|
|
|
rm -f ./testout.txt
|
2012-05-30 21:42:24 +00:00
|
|
|
rm -f ./testerr.txt
|
2006-01-05 22:26:05 +00:00
|
|
|
rm -f ./testout2.txt
|
2005-12-13 23:15:20 +00:00
|
|
|
rm -f ./testout.pcap
|
|
|
|
rm -f ./testout2.pcap
|
|
|
|
}
|
|
|
|
|
|
|
|
capture_suite() {
|
2006-01-05 22:26:05 +00:00
|
|
|
test_step_set_pre capture_cleanup_step
|
|
|
|
test_step_set_post capture_cleanup_step
|
|
|
|
test_remark_add "Capture - need some traffic on interface: \"$TRAFFIC_CAPTURE_IFACE\""
|
2007-08-28 17:49:16 +00:00
|
|
|
test_suite_add "Dumpcap capture" dumpcap_capture_suite
|
|
|
|
test_suite_add "TShark capture" tshark_capture_suite
|
|
|
|
test_suite_add "Wireshark capture" wireshark_capture_suite
|
2005-12-13 23:15:20 +00:00
|
|
|
}
|
2013-03-01 16:13:44 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
#
|
|
|
|
# Local variables:
|
|
|
|
# c-basic-offset: 8
|
|
|
|
# tab-width: 8
|
|
|
|
# indent-tabs-mode: t
|
|
|
|
# End:
|
|
|
|
#
|
|
|
|
# vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
# :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
#
|