Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b343734

Browse files
vladimirolteandavem330
authored andcommitted
selftests: forwarding: add option to run tests with stable MAC addresses
By default, DSA switch ports inherit their MAC address from the DSA master. This works well for practical situations, but some selftests like bridge_vlan_unaware.sh loop back 2 standalone DSA ports with 2 bridged DSA ports, and require the bridge to forward packets between the standalone ports. Due to the bridge seeing that the MAC DA it needs to forward is present as a local FDB entry (it coincides with the MAC address of the bridge ports), the test packets are not forwarded, but terminated locally on br0. In turn, this makes the ping and ping6 tests fail. Address this by introducing an option to have stable MAC addresses. When mac_addr_prepare is called, the current addresses of the netifs are saved and replaced with 00:01:02:03:04:${netif number}. Then when mac_addr_restore is called at the end of the test, the original MAC addresses are restored. This ensures that the MAC addresses are unique, which makes the test pass even for DSA ports. The usage model is for the behavior to be opt-in via STABLE_MAC_ADDRS, which DSA should set to true, all others behave as before. By hooking the calls to mac_addr_prepare and mac_addr_restore within the forwarding lib itself, we do not need to patch each individual selftest, the only requirement is that pre_cleanup is called. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 988998a commit b343734

File tree

1 file changed

+36
-0
lines changed
  • tools/testing/selftests/net/forwarding

1 file changed

+36
-0
lines changed

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ INTERFACE_TIMEOUT=${INTERFACE_TIMEOUT:=600}
2727
LOW_AGEING_TIME=${LOW_AGEING_TIME:=1000}
2828
REQUIRE_JQ=${REQUIRE_JQ:=yes}
2929
REQUIRE_MZ=${REQUIRE_MZ:=yes}
30+
STABLE_MAC_ADDRS=${STABLE_MAC_ADDRS:=no}
3031

3132
relative_path="${BASH_SOURCE%/*}"
3233
if [[ "$relative_path" == "${BASH_SOURCE}" ]]; then
@@ -214,10 +215,41 @@ create_netif()
214215
esac
215216
}
216217

218+
declare -A MAC_ADDR_ORIG
219+
mac_addr_prepare()
220+
{
221+
local new_addr=
222+
local dev=
223+
224+
for ((i = 1; i <= NUM_NETIFS; ++i)); do
225+
dev=${NETIFS[p$i]}
226+
new_addr=$(printf "00:01:02:03:04:%02x" $i)
227+
228+
MAC_ADDR_ORIG["$dev"]=$(ip -j link show dev $dev | jq -e '.[].address')
229+
# Strip quotes
230+
MAC_ADDR_ORIG["$dev"]=${MAC_ADDR_ORIG["$dev"]//\"/}
231+
ip link set dev $dev address $new_addr
232+
done
233+
}
234+
235+
mac_addr_restore()
236+
{
237+
local dev=
238+
239+
for ((i = 1; i <= NUM_NETIFS; ++i)); do
240+
dev=${NETIFS[p$i]}
241+
ip link set dev $dev address ${MAC_ADDR_ORIG["$dev"]}
242+
done
243+
}
244+
217245
if [[ "$NETIF_CREATE" = "yes" ]]; then
218246
create_netif
219247
fi
220248

249+
if [[ "$STABLE_MAC_ADDRS" = "yes" ]]; then
250+
mac_addr_prepare
251+
fi
252+
221253
for ((i = 1; i <= NUM_NETIFS; ++i)); do
222254
ip link show dev ${NETIFS[p$i]} &> /dev/null
223255
if [[ $? -ne 0 ]]; then
@@ -503,6 +535,10 @@ pre_cleanup()
503535
echo "Pausing before cleanup, hit any key to continue"
504536
read
505537
fi
538+
539+
if [[ "$STABLE_MAC_ADDRS" = "yes" ]]; then
540+
mac_addr_restore
541+
fi
506542
}
507543

508544
vrf_prepare()

0 commit comments

Comments
 (0)