Change in osmo-ttcn3-hacks[master]: Use dumpcap for ttcn3-tcpdump-*.sh if available

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Tue Mar 19 10:28:46 UTC 2019


Max has submitted this change and it was merged. ( https://gerrit.osmocom.org/13253 )

Change subject: Use dumpcap for ttcn3-tcpdump-*.sh if available
......................................................................

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
---
M ttcn3-tcpdump-start.sh
M ttcn3-tcpdump-stop.sh
2 files changed, 18 insertions(+), 1 deletion(-)

Approvals:
  Harald Welte: Looks good to me, approved
  osmith: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



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 @@
 # "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
diff --git a/ttcn3-tcpdump-stop.sh b/ttcn3-tcpdump-stop.sh
index f53cf5d..c1ab9d0 100755
--- a/ttcn3-tcpdump-stop.sh
+++ b/ttcn3-tcpdump-stop.sh
@@ -32,7 +32,8 @@
 done
 
 if [ -e $PIDFILE ]; then
-	if [ "$(id -u)" = "0" ]; then
+        DUMPER="$(ps -q "$(cat "$PIDFILE")" -o comm=)"
+	if [ "$DUMPER" != "sudo" ]; then
 		kill "$(cat "$PIDFILE")"
 	else
 	# NOTE: This requires you to be root or something like

-- 
To view, visit https://gerrit.osmocom.org/13253
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I77df04d51a469c924cf727f0596cc33565909746
Gerrit-Change-Number: 13253
Gerrit-PatchSet: 6
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Daniel Willmann <dwillmann at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: tnt <tnt at 246tNt.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190319/61178b66/attachment.htm>


More information about the gerrit-log mailing list