2 # SPDX-License-Identifier: GPL-2.0
4 readonly FLUSH_PATH
="/sys/class/net/${dev}/gro_flush_timeout"
5 readonly IRQ_PATH
="/sys/class/net/${dev}/napi_defer_hard_irqs"
6 readonly FLUSH_TIMEOUT
="$(< ${FLUSH_PATH})"
7 readonly HARD_IRQS
="$(< ${IRQ_PATH})"
8 readonly server_ns
=$
(mktemp
-u server-XXXXXXXX
)
9 readonly client_ns
=$
(mktemp
-u client-XXXXXXXX
)
11 netdev_check_for_carrier
() {
15 carrier
="$(cat /sys/class/net/${dev}/carrier)"
16 if [[ "${carrier}" -ne 1 ]] ; then
17 echo "carrier not ready yet..." >&2
20 echo "carrier ready" >&2
27 # Assumes that there is no existing ipvlan device on the physical device
28 setup_loopback_environment
() {
31 # Fail hard if cannot turn on loopback mode for current NIC
32 ethtool
-K "${dev}" loopback on ||
exit 1
35 # Check for the carrier
36 carrier
=$
(netdev_check_for_carrier
${dev})
37 if [[ "${carrier}" -ne 1 ]] ; then
38 echo "setup_loopback_environment failed"
44 local -r link_dev
="$1"
50 ip link add link
"${link_dev}" dev
"${ns_dev}" \
51 address
"${ns_mac}" type macvlan
53 if [[ "${exit_code}" -ne 0 ]]; then
54 echo "setup_macvlan_ns failed"
58 [[ -e /var
/run
/netns
/"${ns_name}" ]] || ip netns add
"${ns_name}"
59 ip link
set dev
"${ns_dev}" netns
"${ns_name}"
60 ip
-netns "${ns_name}" link
set dev
"${ns_dev}" up
61 if [[ -n "${addr}" ]]; then
62 ip
-netns "${ns_name}" addr add dev "${ns_dev}" "${addr}"
69 while (( $# >= 2 )); do
72 ip
-netns "${ns_name}" link del dev
"${ns_dev}"
73 ip netns del
"${ns_name}"
81 ethtool
-K "${dev}" loopback off
84 # Check for the carrier
85 carrier
=$
(netdev_check_for_carrier
${dev})
86 if [[ "${carrier}" -ne 1 ]] ; then
87 echo "setup_loopback_environment failed"
93 # Use timer on host to trigger the network stack
94 # Also disable device interrupt to not depend on NIC interrupt
95 # Reduce test flakiness caused by unexpected interrupts
96 echo 100000 >"${FLUSH_PATH}"
97 echo 50 >"${IRQ_PATH}"
101 # Set up server_ns namespace and client_ns namespace
102 setup_macvlan_ns
"${dev}" ${server_ns} server "${SERVER_MAC}"
103 setup_macvlan_ns
"${dev}" ${client_ns} client "${CLIENT_MAC}"
107 cleanup_macvlan_ns
${server_ns} server
${client_ns} client
111 setup_loopback_environment
"${dev}"
116 cleanup_loopback
"${dev}"
118 echo "${FLUSH_TIMEOUT}" >"${FLUSH_PATH}"
119 echo "${HARD_IRQS}" >"${IRQ_PATH}"