xref: /aosp_15_r20/external/ltp/testcases/network/stress/route/route-redirect.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2006 International Business Machines  Corp.
4# Copyright (c) 2020 Joerg Vehlow <[email protected]>
5# Copyright (c) 2022 Petr Vorel <[email protected]>
6# Author: Mitsuru Chinen <[email protected]>
7#
8# Verify the kernel is not crashed when the route is modified by
9# ICMP Redirects frequently
10
11TST_SETUP=setup
12TST_CLEANUP=cleanup
13TST_TESTFUNC=do_test
14TST_NEEDS_ROOT=1
15TST_NEEDS_CMDS="ip"
16
17DST_HOST=
18DST_PORT="7"
19
20setup()
21{
22	local lhost_ifname=$(tst_iface lhost)
23	local rhost_ifname=$(tst_iface rhost)
24	local rhost_net="$(tst_ipaddr_un -p 1)"
25
26	DST_HOST="$(tst_ipaddr_un 1 5)"
27
28	# Remove the link-local address of the remote host
29	tst_rhost_run -s -c "ip addr flush dev $rhost_ifname"
30
31	# Add route to the initial gateway
32	ip route add $rhost_net dev $lhost_ifname
33
34	# Make sure the sysctl value is set for accepting the redirect
35	sysctl -w net.ipv${TST_IPVER}.conf.${lhost_ifname}.accept_redirects=1 > /dev/null
36	[ ! "$TST_IPV6" ] && sysctl -w net.ipv4.conf.${lhost_ifname}.secure_redirects=0 > /dev/null
37
38	tst_rhost_run -s -c "ns-icmp_redirector -I $rhost_ifname -b"
39}
40
41cleanup()
42{
43	tst_rhost_run -c "killall -SIGHUP ns-icmp_redirector"
44	route_cleanup
45}
46
47do_test()
48{
49	local cnt=0
50
51	tst_res TINFO "modify route by ICMP redirects $NS_TIMES times"
52
53	while [ $cnt -lt $NS_TIMES ]; do
54		ROD ns-udpsender -f $TST_IPVER -D $DST_HOST -p $DST_PORT -o -s 8
55		cnt=$((cnt+1))
56	done
57
58	tst_res TPASS "test finished successfully"
59}
60
61. route-lib.sh
62tst_run
63