xref: /aosp_15_r20/external/ltp/testcases/network/stress/dns/dns-stress.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# Copyright (c) 2015-2017 Oracle and/or its affiliates. All Rights Reserved.
3# Copyright (c) International Business Machines  Corp., 2005
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License as
7# published by the Free Software Foundation; either version 2 of
8# the License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it would be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write the Free Software Foundation,
17# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18#
19# Author: Mitsuru Chinen <[email protected]>
20
21TCID=dns-stress
22TST_TOTAL=2
23TST_CLEANUP="cleanup"
24
25TST_USE_LEGACY_API=1
26
27# Minimum host ID in the zone file.
28# The ID is used as the host portion of the address
29MIN_ID=2
30# Maximum host ID in the zone file.
31MAX_ID=254
32# Domain name for testing
33DOMAIN="ltp-ns.org"
34
35cleanup()
36{
37	# Stop the dns daemon
38	test -s named.pid && kill -9 $(cat named.pid) > /dev/null
39	tst_rmdir
40}
41
42common_setup()
43{
44	tst_require_root
45	tst_require_cmds named dig
46
47	if [ "$TST_IPV6" ]; then
48		record="AAAA"
49		net="fd00:cafe"
50		net_rev="0.0.0.0.0.0.0.0.e.f.a.c.0.0.d.f"
51	else
52		record="A"
53		net="10.23.0"
54		net_rev="0.23.10"
55	fi
56
57	trap "tst_brkm TBROK 'test interrupted'" INT
58
59	tst_tmpdir
60
61	ip6_opt=
62	[ "$TST_IPV6" ] && ip6_opt="listen-on-v6 { any; };"
63
64	ip_zone_opt="in-addr"
65	[ "$TST_IPV6" ] && ip_zone_opt="ip6"
66
67	cat << EOD > named.conf
68	options {
69		directory "$(pwd)";
70		pid-file "named.pid";
71		recursion no;
72		$ip6_opt
73	};
74
75	zone "$DOMAIN" {
76		type master;
77		file "ltp-ns.zone";
78	};
79
80	zone "$net_rev.$ip_zone_opt.arpa" {
81		type master;
82		file "ltp-ns.rev";
83	};
84EOD
85
86	# zone file
87	cat << EOD > ltp-ns.zone
88\$TTL 10
89@	IN	SOA dns.$DOMAIN. root.$DOMAIN. (
90	2005092701 ; serial
91	3600       ; dummy value
92	900        ; dummy value
93	604800     ; dummy value
94	86400      ; dummy value
95)
96	IN	NS	dns.$DOMAIN.
97EOD
98}
99
100setup_4()
101{
102	printf "dns\tIN\tA\t$net.1\n" >> ltp-ns.zone
103	local id=$MIN_ID
104	while [ $id -le $MAX_ID ]; do
105		printf "node$id\tIN\tA\t$net.$id\n" >> ltp-ns.zone
106		id=$(($id + 1))
107	done
108
109	# reverse zone file
110	cat << EOD > ltp-ns.rev
111\$TTL 10
112@	IN	SOA $DOMAIN. root.$DOMAIN. (
113	2005092701 ; serial
114	3600       ; dummy value
115	900        ; dummy value
116	604800     ; dummy value
117	86400      ; dummy value
118)
119        IN      NS      dns.$DOMAIN.
120EOD
121
122	id=$MIN_ID
123	while [ $id -le $MAX_ID ]; do
124		printf "$id\tIN\tPTR\tnode$id.$DOMAIN.\n" >> ltp-ns.rev
125		id=$(($id + 1))
126	done
127}
128
129setup_6()
130{
131	printf "dns\tIN\tAAAA\t$net::1\n" >> ltp-ns.zone
132	local id=$MIN_ID
133	while [ $id -le $MAX_ID ]; do
134		printf "node$id\tIN\tAAAA\t$net::%x\n" $id >> ltp-ns.zone
135		id=$(($id + 1))
136	done
137
138	# reverse zone file
139	cat << EOD > ltp-ns.rev
140\$TTL 10
141@	IN	SOA $DOMAIN. root.$DOMAIN. (
142	2005092701 ; serial
143	3600       ; dummy value
144	900        ; dummy value
145	604800     ; dummy value
146	86400      ; dummy value
147)
148        IN      NS      dns.$DOMAIN.
149EOD
150
151	id=$MIN_ID
152	local rev_ip="0.0.0.0.0.0.0.0.0.0.0.0.0.0"
153	while [ $id -le $MAX_ID ]; do
154		printf "%x.%x.$rev_ip\tIN\tPTR\tnode$id.$DOMAIN.\n" \
155			$(($id % 16)) $(($id / 16)) >> ltp-ns.rev
156		id=$(($id + 1))
157	done
158}
159
160start_named()
161{
162	chmod 770 .
163	chmod 660 ./*
164
165	port=$(tst_get_unused_port ipv${TST_IPVER} dgram)
166
167	tst_resm TINFO "Start named daemon, port $port"
168	named -$TST_IPVER -c named.conf -p $port || \
169		tst_brkm TBROK "Failed to run named daemon"
170
171	# Make sure named.pid is created.
172	while true ; do
173		test -s named.pid && break
174		tst_sleep 100ms
175	done
176}
177
178test01()
179{
180	tst_resm TINFO "Handling name lookup queries '$NS_TIMES' times"
181
182	tst_rhost_run -s -c "dns-stress01-rmt.sh $TST_IPVER $(tst_ipaddr) $port \
183		$DOMAIN $MIN_ID $MAX_ID $NS_TIMES"
184
185	tst_resm TPASS "Test is finished successfully"
186}
187
188test02()
189{
190	tst_resm TINFO "Handling reverse lookup queries '$NS_TIMES' times"
191
192	tst_rhost_run -s -c "dns-stress02-rmt.sh $TST_IPVER $(tst_ipaddr) $port $net \
193		$MIN_ID $MAX_ID $NS_TIMES"
194
195	tst_resm TPASS "Test is finished successfully"
196}
197
198. tst_net.sh
199common_setup
200setup_$TST_IPVER
201start_named
202test01
203test02
204tst_exit
205