~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/setup_loopback.sh

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/net/setup_loopback.sh (Version linux-6.11.5) and /tools/testing/selftests/net/setup_loopback.sh (Version linux-5.17.15)


  1 #!/bin/bash                                         1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3                                                     3 
  4 readonly FLUSH_PATH="/sys/class/net/${dev}/gro      4 readonly FLUSH_PATH="/sys/class/net/${dev}/gro_flush_timeout"
  5 readonly IRQ_PATH="/sys/class/net/${dev}/napi_      5 readonly IRQ_PATH="/sys/class/net/${dev}/napi_defer_hard_irqs"
  6 readonly FLUSH_TIMEOUT="$(< ${FLUSH_PATH})"         6 readonly FLUSH_TIMEOUT="$(< ${FLUSH_PATH})"
  7 readonly HARD_IRQS="$(< ${IRQ_PATH})"               7 readonly HARD_IRQS="$(< ${IRQ_PATH})"
  8 readonly server_ns=$(mktemp -u server-XXXXXXXX << 
  9 readonly client_ns=$(mktemp -u client-XXXXXXXX << 
 10                                                     8 
 11 netdev_check_for_carrier() {                        9 netdev_check_for_carrier() {
 12         local -r dev="$1"                          10         local -r dev="$1"
 13                                                    11 
 14         for i in {1..5}; do                        12         for i in {1..5}; do
 15                 carrier="$(cat /sys/class/net/     13                 carrier="$(cat /sys/class/net/${dev}/carrier)"
 16                 if [[ "${carrier}" -ne 1 ]] ;      14                 if [[ "${carrier}" -ne 1 ]] ; then
 17                         echo "carrier not read     15                         echo "carrier not ready yet..." >&2
 18                         sleep 1                    16                         sleep 1
 19                 else                               17                 else
 20                         echo "carrier ready" >     18                         echo "carrier ready" >&2
 21                         break                      19                         break
 22                 fi                                 20                 fi
 23         done                                       21         done
 24         echo "${carrier}"                          22         echo "${carrier}"
 25 }                                                  23 }
 26                                                    24 
 27 # Assumes that there is no existing ipvlan dev     25 # Assumes that there is no existing ipvlan device on the physical device
 28 setup_loopback_environment() {                     26 setup_loopback_environment() {
 29         local dev="$1"                             27         local dev="$1"
 30                                                    28 
 31         # Fail hard if cannot turn on loopback     29         # Fail hard if cannot turn on loopback mode for current NIC
 32         ethtool -K "${dev}" loopback on || exi     30         ethtool -K "${dev}" loopback on || exit 1
 33         sleep 1                                    31         sleep 1
 34                                                    32 
 35         # Check for the carrier                    33         # Check for the carrier
 36         carrier=$(netdev_check_for_carrier ${d     34         carrier=$(netdev_check_for_carrier ${dev})
 37         if [[ "${carrier}" -ne 1 ]] ; then         35         if [[ "${carrier}" -ne 1 ]] ; then
 38                 echo "setup_loopback_environme     36                 echo "setup_loopback_environment failed"
 39                 exit 1                             37                 exit 1
 40         fi                                         38         fi
 41 }                                                  39 }
 42                                                    40 
 43 setup_macvlan_ns(){                                41 setup_macvlan_ns(){
 44         local -r link_dev="$1"                     42         local -r link_dev="$1"
 45         local -r ns_name="$2"                      43         local -r ns_name="$2"
 46         local -r ns_dev="$3"                       44         local -r ns_dev="$3"
 47         local -r ns_mac="$4"                       45         local -r ns_mac="$4"
 48         local -r addr="$5"                         46         local -r addr="$5"
 49                                                    47 
 50         ip link add link "${link_dev}" dev "${     48         ip link add link "${link_dev}" dev "${ns_dev}" \
 51                 address "${ns_mac}" type macvl     49                 address "${ns_mac}" type macvlan
 52         exit_code=$?                               50         exit_code=$?
 53         if [[ "${exit_code}" -ne 0 ]]; then        51         if [[ "${exit_code}" -ne 0 ]]; then
 54                 echo "setup_macvlan_ns failed"     52                 echo "setup_macvlan_ns failed"
 55                 exit $exit_code                    53                 exit $exit_code
 56         fi                                         54         fi
 57                                                    55 
 58         [[ -e /var/run/netns/"${ns_name}" ]] |     56         [[ -e /var/run/netns/"${ns_name}" ]] || ip netns add "${ns_name}"
 59         ip link set dev "${ns_dev}" netns "${n     57         ip link set dev "${ns_dev}" netns "${ns_name}"
 60         ip -netns "${ns_name}" link set dev "$     58         ip -netns "${ns_name}" link set dev "${ns_dev}" up
 61         if [[ -n "${addr}" ]]; then                59         if [[ -n "${addr}" ]]; then
 62                 ip -netns "${ns_name}" addr ad     60                 ip -netns "${ns_name}" addr add dev "${ns_dev}" "${addr}"
 63         fi                                         61         fi
 64                                                    62 
 65         sleep 1                                    63         sleep 1
 66 }                                                  64 }
 67                                                    65 
 68 cleanup_macvlan_ns(){                              66 cleanup_macvlan_ns(){
 69         while (( $# >= 2 )); do                    67         while (( $# >= 2 )); do
 70                 ns_name="$1"                       68                 ns_name="$1"
 71                 ns_dev="$2"                        69                 ns_dev="$2"
 72                 ip -netns "${ns_name}" link de     70                 ip -netns "${ns_name}" link del dev "${ns_dev}"
 73                 ip netns del "${ns_name}"          71                 ip netns del "${ns_name}"
 74                 shift 2                            72                 shift 2
 75         done                                       73         done
 76 }                                                  74 }
 77                                                    75 
 78 cleanup_loopback(){                                76 cleanup_loopback(){
 79         local -r dev="$1"                          77         local -r dev="$1"
 80                                                    78 
 81         ethtool -K "${dev}" loopback off           79         ethtool -K "${dev}" loopback off
 82         sleep 1                                    80         sleep 1
 83                                                    81 
 84         # Check for the carrier                    82         # Check for the carrier
 85         carrier=$(netdev_check_for_carrier ${d     83         carrier=$(netdev_check_for_carrier ${dev})
 86         if [[ "${carrier}" -ne 1 ]] ; then         84         if [[ "${carrier}" -ne 1 ]] ; then
 87                 echo "setup_loopback_environme     85                 echo "setup_loopback_environment failed"
 88                 exit 1                             86                 exit 1
 89         fi                                         87         fi
 90 }                                                  88 }
 91                                                    89 
 92 setup_interrupt() {                                90 setup_interrupt() {
 93         # Use timer on  host to trigger the ne     91         # Use timer on  host to trigger the network stack
 94         # Also disable device interrupt to not     92         # Also disable device interrupt to not depend on NIC interrupt
 95         # Reduce test flakiness caused by unex     93         # Reduce test flakiness caused by unexpected interrupts
 96         echo 100000 >"${FLUSH_PATH}"               94         echo 100000 >"${FLUSH_PATH}"
 97         echo 50 >"${IRQ_PATH}"                     95         echo 50 >"${IRQ_PATH}"
 98 }                                                  96 }
 99                                                    97 
100 setup_ns() {                                       98 setup_ns() {
101         # Set up server_ns namespace and clien     99         # Set up server_ns namespace and client_ns namespace
102         setup_macvlan_ns "${dev}" ${server_ns} !! 100         setup_macvlan_ns "${dev}" server_ns server "${SERVER_MAC}"
103         setup_macvlan_ns "${dev}" ${client_ns} !! 101         setup_macvlan_ns "${dev}" client_ns client "${CLIENT_MAC}"
104 }                                                 102 }
105                                                   103 
106 cleanup_ns() {                                    104 cleanup_ns() {
107         cleanup_macvlan_ns ${server_ns} server !! 105         cleanup_macvlan_ns server_ns server client_ns client
108 }                                                 106 }
109                                                   107 
110 setup() {                                         108 setup() {
111         setup_loopback_environment "${dev}"       109         setup_loopback_environment "${dev}"
112         setup_interrupt                           110         setup_interrupt
113 }                                                 111 }
114                                                   112 
115 cleanup() {                                       113 cleanup() {
116         cleanup_loopback "${dev}"                 114         cleanup_loopback "${dev}"
117                                                   115 
118         echo "${FLUSH_TIMEOUT}" >"${FLUSH_PATH    116         echo "${FLUSH_TIMEOUT}" >"${FLUSH_PATH}"
119         echo "${HARD_IRQS}" >"${IRQ_PATH}"        117         echo "${HARD_IRQS}" >"${IRQ_PATH}"
120 }                                                 118 }
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php