1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Bridge FDB entries can be offloaded to DSA switches without holding the
5# rtnl_mutex. Traditionally this mutex has conferred drivers implicit
6# serialization, which means their code paths are not well tested in the
7# presence of concurrency.
8# This test creates a background task that stresses the FDB by adding and
9# deleting an entry many times in a row without the rtnl_mutex held.
10# It then tests the driver resistance to concurrency by calling .ndo_fdb_dump
11# (with rtnl_mutex held) from a foreground task.
12# Since either the FDB dump or the additions/removals can fail, but the
13# additions and removals are performed in deferred as opposed to process
14# context, we cannot simply check for user space error codes.
15
16WAIT_TIME=1
17NUM_NETIFS=1
18REQUIRE_JQ="no"
19REQUIRE_MZ="no"
20NETIF_CREATE="no"
21lib_dir=$(dirname "$0")
22source "$lib_dir"/../../../net/forwarding/lib.sh
23
24cleanup() {
25	echo "Cleaning up"
26	kill $pid && wait $pid &> /dev/null
27	ip link del br0
28	echo "Please check kernel log for errors"
29}
30trap 'cleanup' EXIT
31
32eth=${NETIFS[p1]}
33
34ip link del br0 2>&1 >/dev/null || :
35ip link add br0 type bridge && ip link set $eth master br0
36
37(while :; do
38	bridge fdb add 00:01:02:03:04:05 dev $eth master static
39	bridge fdb del 00:01:02:03:04:05 dev $eth master static
40done) &
41pid=$!
42
43for i in $(seq 1 50); do
44	bridge fdb show > /dev/null
45	sleep 3
46	echo "$((${i} * 2))% complete..."
47done
48