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