linux-stable/tools/testing/selftests/net/route_localnet.sh
Swarup Laxman Kotiaklapudi 37a38e439d selftests: net: change ifconfig with ip command
Change ifconfig with ip command, on a system where ifconfig is
not used this script will not work correcly.

Test result with this patchset:

sudo make TARGETS="net" kselftest
....
TAP version 13
1..1
 timeout set to 1500
 selftests: net: route_localnet.sh
 run arp_announce test
 net.ipv4.conf.veth0.route_localnet = 1
 net.ipv4.conf.veth1.route_localnet = 1
 net.ipv4.conf.veth0.arp_announce = 2
 net.ipv4.conf.veth1.arp_announce = 2
 PING 127.25.3.14 (127.25.3.14) from 127.25.3.4 veth0: 56(84)
  bytes of data.
 64 bytes from 127.25.3.14: icmp_seq=1 ttl=64 time=0.038 ms
 64 bytes from 127.25.3.14: icmp_seq=2 ttl=64 time=0.068 ms
 64 bytes from 127.25.3.14: icmp_seq=3 ttl=64 time=0.068 ms
 64 bytes from 127.25.3.14: icmp_seq=4 ttl=64 time=0.068 ms
 64 bytes from 127.25.3.14: icmp_seq=5 ttl=64 time=0.068 ms

 --- 127.25.3.14 ping statistics ---
 5 packets transmitted, 5 received, 0% packet loss, time 4073ms
 rtt min/avg/max/mdev = 0.038/0.062/0.068/0.012 ms
 ok
 run arp_ignore test
 net.ipv4.conf.veth0.route_localnet = 1
 net.ipv4.conf.veth1.route_localnet = 1
 net.ipv4.conf.veth0.arp_ignore = 3
 net.ipv4.conf.veth1.arp_ignore = 3
 PING 127.25.3.14 (127.25.3.14) from 127.25.3.4 veth0: 56(84)
  bytes of data.
 64 bytes from 127.25.3.14: icmp_seq=1 ttl=64 time=0.032 ms
 64 bytes from 127.25.3.14: icmp_seq=2 ttl=64 time=0.065 ms
 64 bytes from 127.25.3.14: icmp_seq=3 ttl=64 time=0.066 ms
 64 bytes from 127.25.3.14: icmp_seq=4 ttl=64 time=0.065 ms
 64 bytes from 127.25.3.14: icmp_seq=5 ttl=64 time=0.065 ms

 --- 127.25.3.14 ping statistics ---
 5 packets transmitted, 5 received, 0% packet loss, time 4092ms
 rtt min/avg/max/mdev = 0.032/0.058/0.066/0.013 ms
 ok
ok 1 selftests: net: route_localnet.sh
...

Signed-off-by: Swarup Laxman Kotiaklapudi <swarupkotikalapudi@gmail.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/20231023123422.2895-1-swarupkotikalapudi@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2023-10-24 13:53:39 -07:00

76 lines
1.9 KiB
Bash
Executable file

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Run a couple of tests when route_localnet = 1.
readonly PEER_NS="ns-peer-$(mktemp -u XXXXXX)"
setup() {
ip netns add "${PEER_NS}"
ip -netns "${PEER_NS}" link set dev lo up
ip link add name veth0 type veth peer name veth1
ip link set dev veth0 up
ip link set dev veth1 netns "${PEER_NS}"
# Enable route_localnet and delete useless route 127.0.0.0/8.
sysctl -w net.ipv4.conf.veth0.route_localnet=1
ip netns exec "${PEER_NS}" sysctl -w net.ipv4.conf.veth1.route_localnet=1
ip route del 127.0.0.0/8 dev lo table local
ip netns exec "${PEER_NS}" ip route del 127.0.0.0/8 dev lo table local
ip address add 127.25.3.4/24 dev veth0
ip link set dev veth0 up
ip netns exec "${PEER_NS}" ip address add 127.25.3.14/24 dev veth1
ip netns exec "${PEER_NS}" ip link set dev veth1 up
ip route flush cache
ip netns exec "${PEER_NS}" ip route flush cache
}
cleanup() {
ip link del veth0
ip route add local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
local -r ns="$(ip netns list|grep $PEER_NS)"
[ -n "$ns" ] && ip netns del $ns 2>/dev/null
}
# Run test when arp_announce = 2.
run_arp_announce_test() {
echo "run arp_announce test"
setup
sysctl -w net.ipv4.conf.veth0.arp_announce=2
ip netns exec "${PEER_NS}" sysctl -w net.ipv4.conf.veth1.arp_announce=2
ping -c5 -I veth0 127.25.3.14
if [ $? -ne 0 ];then
echo "failed"
else
echo "ok"
fi
cleanup
}
# Run test when arp_ignore = 3.
run_arp_ignore_test() {
echo "run arp_ignore test"
setup
sysctl -w net.ipv4.conf.veth0.arp_ignore=3
ip netns exec "${PEER_NS}" sysctl -w net.ipv4.conf.veth1.arp_ignore=3
ping -c5 -I veth0 127.25.3.14
if [ $? -ne 0 ];then
echo "failed"
else
echo "ok"
fi
cleanup
}
run_all_tests() {
run_arp_announce_test
run_arp_ignore_test
}
run_all_tests