Home | History | Annotate | Download | only in dns
      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 <mitch (at] jp.ibm.com>
     20 
     21 TCID=dns-stress
     22 TST_TOTAL=2
     23 TST_CLEANUP="cleanup"
     24 
     25 . test_net.sh
     26 
     27 # Minimum host ID in the zone file.
     28 # The ID is used as the host portion of the address
     29 MIN_ID=2
     30 # Maximum host ID in the zone file.
     31 MAX_ID=254
     32 # Domain name for testing
     33 DOMAIN="ltp-ns.org"
     34 
     35 cleanup()
     36 {
     37 	# Stop the dns daemon
     38 	test -s named.pid && kill -9 $(cat named.pid) > /dev/null
     39 	tst_rmdir
     40 }
     41 
     42 common_setup()
     43 {
     44 	tst_require_root
     45 	tst_check_cmds named dig
     46 
     47 	ipver=${TST_IPV6:-'4'}
     48 
     49 	if [ "$TST_IPV6" ]; then
     50 		record="AAAA"
     51 		net="fd00:cafe"
     52 		net_rev="0.0.0.0.0.0.0.0.e.f.a.c.0.0.d.f"
     53 	else
     54 		record="A"
     55 		net="10.23.0"
     56 		net_rev="0.23.10"
     57 	fi
     58 
     59 	trap "tst_brkm TBROK 'test interrupted'" INT
     60 
     61 	tst_tmpdir
     62 
     63 	ip6_opt=
     64 	[ "$TST_IPV6" ] && ip6_opt="listen-on-v6 { any; };"
     65 
     66 	ip_zone_opt="in-addr"
     67 	[ "$TST_IPV6" ] && ip_zone_opt="ip6"
     68 
     69 	cat << EOD > named.conf
     70 	options {
     71 		directory "$(pwd)";
     72 		pid-file "named.pid";
     73 		recursion no;
     74 		$ip6_opt
     75 	};
     76 
     77 	zone "$DOMAIN" {
     78 		type master;
     79 		file "ltp-ns.zone";
     80 	};
     81 
     82 	zone "$net_rev.$ip_zone_opt.arpa" {
     83 		type master;
     84 		file "ltp-ns.rev";
     85 	};
     86 EOD
     87 
     88 	# zone file
     89 	cat << EOD > ltp-ns.zone
     90 \$TTL 10
     91 @	IN	SOA dns.$DOMAIN. root.$DOMAIN. (
     92 	2005092701 ; serial
     93 	3600       ; dummy value
     94 	900        ; dummy value
     95 	604800     ; dummy value
     96 	86400      ; dummy value
     97 )
     98 	IN	NS	dns.$DOMAIN.
     99 EOD
    100 }
    101 
    102 setup_4()
    103 {
    104 	printf "dns\tIN\tA\t$net.1\n" >> ltp-ns.zone
    105 	local id=$MIN_ID
    106 	while [ $id -le $MAX_ID ]; do
    107 		printf "node$id\tIN\tA\t$net.$id\n" >> ltp-ns.zone
    108 		id=$(($id + 1))
    109 	done
    110 
    111 	# reverse zone file
    112 	cat << EOD > ltp-ns.rev
    113 \$TTL 10
    114 @	IN	SOA $DOMAIN. root.$DOMAIN. (
    115 	2005092701 ; serial
    116 	3600       ; dummy value
    117 	900        ; dummy value
    118 	604800     ; dummy value
    119 	86400      ; dummy value
    120 )
    121         IN      NS      dns.$DOMAIN.
    122 EOD
    123 
    124 	id=$MIN_ID
    125 	while [ $id -le $MAX_ID ]; do
    126 		printf "$id\tIN\tPTR\tnode$id.$DOMAIN.\n" >> ltp-ns.rev
    127 		id=$(($id + 1))
    128 	done
    129 }
    130 
    131 setup_6()
    132 {
    133 	printf "dns\tIN\tAAAA\t$net::1\n" >> ltp-ns.zone
    134 	local id=$MIN_ID
    135 	while [ $id -le $MAX_ID ]; do
    136 		printf "node$id\tIN\tAAAA\t$net::%x\n" $id >> ltp-ns.zone
    137 		id=$(($id + 1))
    138 	done
    139 
    140 	# reverse zone file
    141 	cat << EOD > ltp-ns.rev
    142 \$TTL 10
    143 @	IN	SOA $DOMAIN. root.$DOMAIN. (
    144 	2005092701 ; serial
    145 	3600       ; dummy value
    146 	900        ; dummy value
    147 	604800     ; dummy value
    148 	86400      ; dummy value
    149 )
    150         IN      NS      dns.$DOMAIN.
    151 EOD
    152 
    153 	id=$MIN_ID
    154 	local rev_ip="0.0.0.0.0.0.0.0.0.0.0.0.0.0"
    155 	while [ $id -le $MAX_ID ]; do
    156 		printf "%x.%x.$rev_ip\tIN\tPTR\tnode$id.$DOMAIN.\n" \
    157 			$(($id % 16)) $(($id / 16)) >> ltp-ns.rev
    158 		id=$(($id + 1))
    159 	done
    160 }
    161 
    162 start_named()
    163 {
    164 	chmod 770 .
    165 	chmod 660 ./*
    166 
    167 	port=$(tst_get_unused_port ipv${ipver} dgram)
    168 
    169 	tst_resm TINFO "Start named daemon, port $port"
    170 	named -$ipver -c named.conf -p $port || \
    171 		tst_brkm TBROK "Failed to run named daemon"
    172 
    173 	# Make sure named.pid is created.
    174 	while true ; do
    175 		test -s named.pid && break
    176 		tst_sleep 100ms
    177 	done
    178 }
    179 
    180 test01()
    181 {
    182 	tst_resm TINFO "Handling name lookup queries '$NS_TIMES' times"
    183 
    184 	tst_rhost_run -s -c "dns-stress01-rmt $ipver $(tst_ipaddr) $port \
    185 		$DOMAIN $MIN_ID $MAX_ID $NS_TIMES"
    186 
    187 	tst_resm TPASS "Test is finished successfully"
    188 }
    189 
    190 test02()
    191 {
    192 	tst_resm TINFO "Handling reverse lookup queries '$NS_TIMES' times"
    193 
    194 	tst_rhost_run -s -c "dns-stress02-rmt $ipver $(tst_ipaddr) $port $net \
    195 		$MIN_ID $MAX_ID $NS_TIMES"
    196 
    197 	tst_resm TPASS "Test is finished successfully"
    198 }
    199 
    200 common_setup
    201 
    202 setup_$ipver
    203 
    204 start_named
    205 
    206 test01
    207 test02
    208 
    209 tst_exit
    210