Create dummy gsmtap sink with netcat

otherwise ICMP messages appear in pcap files and some messages are lost
since they seem to be dropped by the kernel.

Change-Id: Id69d98db63f8260067ad6bc1525fb05c936912f2
This commit is contained in:
Pau Espin 2019-10-02 13:00:51 +02:00 committed by pespin
parent 02f77d8807
commit ad931f236b
2 changed files with 39 additions and 18 deletions

View File

@ -1,10 +1,22 @@
#!/bin/sh #!/bin/sh
PIDFILE=/tmp/dumper.pid PIDFILE_PCAP=/tmp/pcap.pid
TCPDUMP=/usr/sbin/tcpdump TCPDUMP=/usr/sbin/tcpdump
DUMPCAP=/usr/bin/dumpcap DUMPCAP=/usr/bin/dumpcap
PIDFILE_NETCAT=/tmp/netcat.pid
NETCAT=/bin/nc
GSMTAP_PORT=4729
TESTCASE=$1 TESTCASE=$1
kill_rm_pidfile() {
if [ -e $1 ]; then
kill "$(cat "$1")"
rm $1
fi
}
echo "------ $TESTCASE ------" echo "------ $TESTCASE ------"
date date
@ -12,10 +24,8 @@ if [ "z$TTCN3_PCAP_PATH" = "z" ]; then
TTCN3_PCAP_PATH=/tmp TTCN3_PCAP_PATH=/tmp
fi fi
if [ -e $PIDFILE ]; then kill_rm_pidfile $PIDFILE_NETCAT
kill "$(cat "$PIDFILE")" kill_rm_pidfile $PIDFILE_PCAP
rm $PIDFILE
fi
if [ "$(id -u)" = "0" ]; then if [ "$(id -u)" = "0" ]; then
CMD="$TCPDUMP -U" CMD="$TCPDUMP -U"
@ -39,9 +49,14 @@ if [ -x $DUMPCAP ]; then
fi fi
fi fi
# Create a dummy sink for GSMTAP packets
$NETCAT -l -u -k -p $GSMTAP_PORT >/dev/null 2>$TESTCASE.netcat.stderr &
PID=$!
echo $PID > $PIDFILE_NETCAT
$CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout 2>&1 & $CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout 2>&1 &
PID=$! PID=$!
echo $PID > $PIDFILE echo $PID > $PIDFILE_PCAP
# Wait until packet dumper creates the pcap file and starts recording. # Wait until packet dumper creates the pcap file and starts recording.
# We generate some traffic until we see packet dumper catches it. # We generate some traffic until we see packet dumper catches it.

View File

@ -1,9 +1,24 @@
#!/bin/sh #!/bin/sh
PIDFILE=/tmp/dumper.pid PIDFILE_PCAP=/tmp/pcap.pid
PIDFILE_NETCAT=/tmp/netcat.pid
TESTCASE=$1 TESTCASE=$1
VERDICT="$2" VERDICT="$2"
kill_rm_pidfile() {
if [ -e $1 ]; then
PSNAME="$(ps -q "$(cat "$1")" -o comm=)"
if [ "$PSNAME" != "sudo" ]; then
kill "$(cat "$1")"
else
# NOTE: This requires you to be root or something like
# "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
sudo kill "$(cat "$1")"
fi
rm $1
fi
}
date date
if [ x"$VERDICT" = x"pass" ]; then if [ x"$VERDICT" = x"pass" ]; then
@ -31,14 +46,5 @@ do
i=$((i+1)) i=$((i+1))
done done
if [ -e $PIDFILE ]; then kill_rm_pidfile "$PIDFILE_PCAP"
DUMPER="$(ps -q "$(cat "$PIDFILE")" -o comm=)" kill_rm_pidfile "$PIDFILE_NETCAT"
if [ "$DUMPER" != "sudo" ]; then
kill "$(cat "$PIDFILE")"
else
# NOTE: This requires you to be root or something like
# "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
sudo kill "$(cat "$PIDFILE")"
fi
rm $PIDFILE
fi