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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/fib_nexthop_nongw.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 # ns: h1               | ns: h2
  5 #   192.168.0.1/24     |
  6 #            eth0      |
  7 #                      |       192.168.1.1/32
  8 #            veth0 <---|---> veth1
  9 # Validate source address selection for route without gateway
 10 
 11 source lib.sh
 12 PAUSE_ON_FAIL=no
 13 VERBOSE=0
 14 ret=0
 15 
 16 ################################################################################
 17 # helpers
 18 
 19 log_test()
 20 {
 21         local rc=$1
 22         local expected=$2
 23         local msg="$3"
 24 
 25         if [ ${rc} -eq ${expected} ]; then
 26                 printf "TEST: %-60s  [ OK ]\n" "${msg}"
 27                 nsuccess=$((nsuccess+1))
 28         else
 29                 ret=1
 30                 nfail=$((nfail+1))
 31                 printf "TEST: %-60s  [FAIL]\n" "${msg}"
 32                 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
 33                         echo
 34                         echo "hit enter to continue, 'q' to quit"
 35                         read a
 36                         [ "$a" = "q" ] && exit 1
 37                 fi
 38         fi
 39 
 40         [ "$VERBOSE" = "1" ] && echo
 41 }
 42 
 43 run_cmd()
 44 {
 45         local cmd="$*"
 46         local out
 47         local rc
 48 
 49         if [ "$VERBOSE" = "1" ]; then
 50                 echo "COMMAND: $cmd"
 51         fi
 52 
 53         out=$(eval $cmd 2>&1)
 54         rc=$?
 55         if [ "$VERBOSE" = "1" -a -n "$out" ]; then
 56                 echo "$out"
 57         fi
 58 
 59         [ "$VERBOSE" = "1" ] && echo
 60 
 61         return $rc
 62 }
 63 
 64 ################################################################################
 65 # config
 66 setup()
 67 {
 68         setup_ns h1 h2
 69 
 70         # Add a fake eth0 to support an ip address
 71         ip -n $h1 link add name eth0 type dummy
 72         ip -n $h1 link set eth0 up
 73         ip -n $h1 address add 192.168.0.1/24 dev eth0
 74 
 75         # Configure veths (same @mac, arp off)
 76         ip -n $h1 link add name veth0 type veth peer name veth1 netns $h2
 77         ip -n $h1 link set veth0 up
 78 
 79         ip -n $h2 link set veth1 up
 80 
 81         # Configure @IP in the peer netns
 82         ip -n $h2 address add 192.168.1.1/32 dev veth1
 83         ip -n $h2 route add default dev veth1
 84 
 85         # Add a nexthop without @gw and use it in a route
 86         ip -n $h1 nexthop add id 1 dev veth0
 87         ip -n $h1 route add 192.168.1.1 nhid 1
 88 }
 89 
 90 cleanup()
 91 {
 92         cleanup_ns $h1 $h2
 93 }
 94 
 95 trap cleanup EXIT
 96 
 97 ################################################################################
 98 # main
 99 
100 while getopts :pv o
101 do
102         case $o in
103                 p) PAUSE_ON_FAIL=yes;;
104                 v) VERBOSE=1;;
105         esac
106 done
107 
108 setup
109 
110 run_cmd ip -netns $h1 route get 192.168.1.1
111 log_test $? 0 "nexthop: get route with nexthop without gw"
112 run_cmd ip netns exec $h1 ping -c1 192.168.1.1
113 log_test $? 0 "nexthop: ping through nexthop without gw"
114 
115 exit $ret

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