ctdb-tests: Allow tcptickle_sniff_wait_show() to filter by MAC address
authorMartin Schwenke <martin@meltin.net>
Mon, 7 Mar 2016 23:03:12 +0000 (10:03 +1100)
committerAmitay Isaacs <amitay@samba.org>
Thu, 10 Mar 2016 02:34:18 +0000 (03:34 +0100)
tcpdump does not support filtering on MAC address when reading from a
file.  Therefore, this is implemented by conditionally using grep to
filter the output of tcpdump.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/complex/scripts/local.bash

index 103a71f5919d581d122a8b2af7ecbc5709b990c3..7787de8f111dc4b1551ae3d4fbcaa7e931e3dbda 100644 (file)
@@ -126,8 +126,23 @@ tcpdump_wait ()
 
        tcpdump_check ()
        {
-               local found=$(tcpdump -n -r $tcpdump_filename \
-                                     "$filter" 2>/dev/null | wc -l)
+               # It would be much nicer to add "ether src
+               # $releasing_mac" to the filter.  However, tcpdump
+               # does not allow MAC filtering unless an ethernet
+               # interface is specified with -i.  It doesn't work
+               # with "-i any" and it doesn't work when reading from
+               # a file.  :-(
+               local found
+               if [ -n "$releasing_mac" ] ; then
+                       found=$(tcpdump -n -e -r "$tcpdump_filename" \
+                                       "$filter" 2>/dev/null |
+                                              grep -c "In ${releasing_mac}")
+               else
+                       found=$(tcpdump -n -e -r "$tcpdump_filename" \
+                                       "$filter" 2>/dev/null |
+                                              wc -l)
+               fi
+
                [ $found -ge $count ]
        }
 
@@ -196,6 +211,8 @@ tcptickle_sniff_start ()
 
 tcptickle_sniff_wait_show ()
 {
+       local releasing_mac="$1"  # optional, used by tcpdump_wait()
+
        tcpdump_wait 1 "$tcptickle_reset"
 
        echo "GOOD: here are some TCP tickle packets:"