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

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

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 #
  4 # Run a couple of tests when route_localnet = 1.
  5 
  6 readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"
  7 
  8 setup() {
  9     ip netns add "${PEER_NS}"
 10     ip -netns "${PEER_NS}" link set dev lo up
 11     ip link add name veth0 type veth peer name veth1
 12     ip link set dev veth0 up
 13     ip link set dev veth1 netns "${PEER_NS}"
 14 
 15     # Enable route_localnet and delete useless route 127.0.0.0/8.
 16     sysctl -w net.ipv4.conf.veth0.route_localnet=1
 17     ip netns exec "${PEER_NS}" sysctl -w net.ipv4.conf.veth1.route_localnet=1
 18     ip route del 127.0.0.0/8 dev lo table local
 19     ip netns exec "${PEER_NS}" ip route del 127.0.0.0/8 dev lo table local
 20 
 21     ip address add 127.25.3.4/24 dev veth0
 22     ip link set dev veth0 up
 23     ip netns exec "${PEER_NS}" ip address add 127.25.3.14/24 dev veth1
 24     ip netns exec "${PEER_NS}" ip link set dev veth1 up
 25 
 26     ip route flush cache
 27     ip netns exec "${PEER_NS}" ip route flush cache
 28 }
 29 
 30 cleanup() {
 31     ip link del veth0
 32     ip route add local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
 33     local -r ns="$(ip netns list|grep $PEER_NS)"
 34     [ -n "$ns" ] && ip netns del $ns 2>/dev/null
 35 }
 36 
 37 # Run test when arp_announce = 2.
 38 run_arp_announce_test() {
 39     echo "run arp_announce test"
 40     setup
 41 
 42     sysctl -w net.ipv4.conf.veth0.arp_announce=2
 43     ip netns exec "${PEER_NS}" sysctl -w net.ipv4.conf.veth1.arp_announce=2
 44     ping -c5 -I veth0 127.25.3.14
 45     if [ $? -ne 0 ];then
 46         echo "failed"
 47     else
 48         echo "ok"
 49     fi
 50 
 51     cleanup
 52 }
 53 
 54 # Run test when arp_ignore = 3.
 55 run_arp_ignore_test() {
 56     echo "run arp_ignore test"
 57     setup
 58 
 59     sysctl -w net.ipv4.conf.veth0.arp_ignore=3
 60     ip netns exec "${PEER_NS}" sysctl -w net.ipv4.conf.veth1.arp_ignore=3
 61     ping -c5 -I veth0 127.25.3.14
 62     if [ $? -ne 0 ];then
 63         echo "failed"
 64     else
 65         echo "ok"
 66     fi
 67 
 68     cleanup
 69 }
 70 
 71 run_all_tests() {
 72     run_arp_announce_test
 73     run_arp_ignore_test
 74 }
 75 
 76 run_all_tests

~ [ 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