Linux 4.19.133
[linux/fpc-iii.git] / tools / testing / selftests / bpf / test_sock_addr.sh
blob9832a875a828979be26b8756cbd589d5cf5e44f1
1 #!/bin/sh
3 set -eu
5 ping_once()
7 ping -${1} -q -c 1 -W 1 ${2%%/*} >/dev/null 2>&1
10 wait_for_ip()
12 local _i
13 echo -n "Wait for testing IPv4/IPv6 to become available "
14 for _i in $(seq ${MAX_PING_TRIES}); do
15 echo -n "."
16 if ping_once 4 ${TEST_IPv4} && ping_once 6 ${TEST_IPv6}; then
17 echo " OK"
18 return
20 done
21 echo 1>&2 "ERROR: Timeout waiting for test IP to become available."
22 exit 1
25 setup()
27 # Create testing interfaces not to interfere with current environment.
28 ip link add dev ${TEST_IF} type veth peer name ${TEST_IF_PEER}
29 ip link set ${TEST_IF} up
30 ip link set ${TEST_IF_PEER} up
32 ip -4 addr add ${TEST_IPv4} dev ${TEST_IF}
33 ip -6 addr add ${TEST_IPv6} dev ${TEST_IF}
34 wait_for_ip
37 cleanup()
39 ip link del ${TEST_IF} 2>/dev/null || :
40 ip link del ${TEST_IF_PEER} 2>/dev/null || :
43 main()
45 trap cleanup EXIT 2 3 6 15
46 setup
47 ./test_sock_addr setup_done
50 BASENAME=$(basename $0 .sh)
51 TEST_IF="${BASENAME}1"
52 TEST_IF_PEER="${BASENAME}2"
53 TEST_IPv4="127.0.0.4/8"
54 TEST_IPv6="::6/128"
55 MAX_PING_TRIES=5
57 main