OSDN Git Service

selftests: net: bridge: factor out mcast_packet_test
authorNikolay Aleksandrov <nikolay@nvidia.com>
Tue, 3 Nov 2020 17:23:57 +0000 (19:23 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 5 Nov 2020 00:55:47 +0000 (16:55 -0800)
Factor out mcast_packet_test into lib.sh so it can be later extended and
reused by MLDv2 tests.

Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/forwarding/bridge_igmp.sh
tools/testing/selftests/net/forwarding/lib.sh

index 0e71abd..50a48ce 100755 (executable)
@@ -105,38 +105,6 @@ cleanup()
        vrf_cleanup
 }
 
-# return 0 if the packet wasn't seen on host2_if or 1 if it was
-mcast_packet_test()
-{
-       local mac=$1
-       local src_ip=$2
-       local ip=$3
-       local host1_if=$4
-       local host2_if=$5
-       local seen=0
-
-       # Add an ACL on `host2_if` which will tell us whether the packet
-       # was received by it or not.
-       tc qdisc add dev $host2_if ingress
-       tc filter add dev $host2_if ingress protocol ip pref 1 handle 101 \
-               flower ip_proto udp dst_mac $mac action drop
-
-       $MZ $host1_if -c 1 -p 64 -b $mac -A $src_ip -B $ip -t udp "dp=4096,sp=2048" -q
-       sleep 1
-
-       tc -j -s filter show dev $host2_if ingress \
-               | jq -e ".[] | select(.options.handle == 101) \
-               | select(.options.actions[0].stats.packets == 1)" &> /dev/null
-       if [[ $? -eq 0 ]]; then
-               seen=1
-       fi
-
-       tc filter del dev $host2_if ingress protocol ip pref 1 handle 101 flower
-       tc qdisc del dev $host2_if ingress
-
-       return $seen
-}
-
 v2reportleave_test()
 {
        RET=0
index 927f9ba..bb3ccc6 100644 (file)
@@ -1270,3 +1270,35 @@ tcpdump_show()
 {
        tcpdump -e -n -r $capfile 2>&1
 }
+
+# return 0 if the packet wasn't seen on host2_if or 1 if it was
+mcast_packet_test()
+{
+       local mac=$1
+       local src_ip=$2
+       local ip=$3
+       local host1_if=$4
+       local host2_if=$5
+       local seen=0
+
+       # Add an ACL on `host2_if` which will tell us whether the packet
+       # was received by it or not.
+       tc qdisc add dev $host2_if ingress
+       tc filter add dev $host2_if ingress protocol ip pref 1 handle 101 \
+               flower ip_proto udp dst_mac $mac action drop
+
+       $MZ $host1_if -c 1 -p 64 -b $mac -A $src_ip -B $ip -t udp "dp=4096,sp=2048" -q
+       sleep 1
+
+       tc -j -s filter show dev $host2_if ingress \
+               | jq -e ".[] | select(.options.handle == 101) \
+               | select(.options.actions[0].stats.packets == 1)" &> /dev/null
+       if [[ $? -eq 0 ]]; then
+               seen=1
+       fi
+
+       tc filter del dev $host2_if ingress protocol ip pref 1 handle 101 flower
+       tc qdisc del dev $host2_if ingress
+
+       return $seen
+}