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