summaryrefslogtreecommitdiffstats
path: root/ttcn3-tcpdump-start.sh
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2019-03-18 14:18:31 +0100
committerMax <msuraev@sysmocom.de>2019-03-19 10:28:46 +0000
commit81487c8b36be124b25dd725d06e3dde7dc3cc5f4 (patch)
treeaf5f1e0f0a15ed7a7dce3bd24fde050d53a10a88 /ttcn3-tcpdump-start.sh
parent59e0c6f764138c835d0e2f336f950440e510db96 (diff)
Use dumpcap for ttcn3-tcpdump-*.sh if available
Check if dumpcap is installed (either as suid or with appropriate capabilities) and use it for packet capture instead of 'sudo tcpdump' if available. This makes it easier to use TTCN-3 testsuite as regular user without altering sudoers. Change-Id: I77df04d51a469c924cf727f0596cc33565909746
Diffstat (limited to 'ttcn3-tcpdump-start.sh')
-rwxr-xr-xttcn3-tcpdump-start.sh16
1 files changed, 16 insertions, 0 deletions
diff --git a/ttcn3-tcpdump-start.sh b/ttcn3-tcpdump-start.sh
index b8ad01a..9bf3c0a 100755
--- a/ttcn3-tcpdump-start.sh
+++ b/ttcn3-tcpdump-start.sh
@@ -2,6 +2,7 @@
PIDFILE=/tmp/dumper.pid
TCPDUMP=/usr/sbin/tcpdump
+DUMPCAP=/usr/bin/dumpcap
TESTCASE=$1
echo "------ $TESTCASE ------"
@@ -23,6 +24,21 @@ else
# "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
CMD="sudo $TCPDUMP -U"
fi
+
+if [ -x $DUMPCAP ]; then
+ CAP_ERR="1"
+ if [ -x /sbin/setcap ]; then
+ # N. B: this check requires libcap2-bin package
+ setcap -q -v 'cap_net_admin,cap_net_raw=pie' $DUMPCAP
+ CAP_ERR="$?"
+ fi
+ if [ -u $DUMPCAP -o "$CAP_ERR" = "0" ]; then
+ CMD="$DUMPCAP -q"
+ else
+ echo "NOTE: unable to use dumpcap due to missing capabilities or suid bit"
+ fi
+fi
+
$CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout 2>&1 &
PID=$!
echo $PID > $PIDFILE