1 # $NetBSD: t_hostent.sh,v 1.10 2014/01/13 11:08:14 gson Exp $ 2 # 3 # Copyright (c) 2008 The NetBSD Foundation, Inc. 4 # All rights reserved. 5 # 6 # Redistribution and use in source and binary forms, with or without 7 # modification, are permitted provided that the following conditions 8 # are met: 9 # 1. Redistributions of source code must retain the above copyright 10 # notice, this list of conditions and the following disclaimer. 11 # 2. Redistributions in binary form must reproduce the above copyright 12 # notice, this list of conditions and the following disclaimer in the 13 # documentation and/or other materials provided with the distribution. 14 # 15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 # POSSIBILITY OF SUCH DAMAGE. 26 # 27 28 n6="sixthavenue.astron.com" 29 a6="2620:106:3003:1f00:3e4a:92ff:fef4:e180" 30 ans6="name=$n6, length=16, addrtype=24, aliases=[] addr_list=[$a6]\n" 31 32 n4="sixthavenue.astron.com" 33 a4="38.117.134.16" 34 ans4="name=$n4, length=4, addrtype=2, aliases=[] addr_list=[$a4]\n" 35 36 l6="localhost" 37 al6="::1" 38 loc6="name=$l6, length=16, addrtype=24, aliases=[localhost. localhost.localdomain.] addr_list=[$al6]\n" 39 40 l4="localhost" 41 al4="127.0.0.1" 42 loc4="name=$l4, length=4, addrtype=2, aliases=[localhost. localhost.localdomain.] addr_list=[$al4]\n" 43 44 dir="$(atf_get_srcdir)" 45 res="-r ${dir}/resolv.conf" 46 47 # Hijack DNS traffic using a single rump server instance and a DNS 48 # server listening on its loopback address. 49 50 start_dns_server() { 51 export RUMP_SERVER=unix:///tmp/rumpserver 52 rump_server -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \ 53 -lrumpnet_netinet6 -lrumpnet_local $RUMP_SERVER 54 HIJACK_DNS="LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK='socket=inet:inet6'" 55 eval $HIJACK_DNS ${dir}/h_dns_server $1 56 } 57 58 stop_dns_server() { 59 export RUMP_SERVER=unix:///tmp/rumpserver 60 kill $(cat dns_server_$1.pid) 61 rump.halt 62 } 63 64 atf_test_case gethostbyname4 cleanup 65 gethostbyname4_head() 66 { 67 atf_set "descr" "Checks gethostbyname2(3) for AF_INET (auto, as determined by nsswitch.conf(5)" 68 } 69 gethostbyname4_body() 70 { 71 start_dns_server 4 72 atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -4 $n4" 73 } 74 gethostbyname4_cleanup() 75 { 76 stop_dns_server 4 77 } 78 79 atf_test_case gethostbyname6 cleanup cleanup 80 gethostbyname6_head() 81 { 82 atf_set "descr" "Checks gethostbyname2(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)" 83 } 84 gethostbyname6_body() 85 { 86 start_dns_server 4 87 atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -6 $n6" 88 } 89 gethostbyname6_cleanup() 90 { 91 stop_dns_server 4 92 } 93 94 atf_test_case gethostbyaddr4 cleanup 95 gethostbyaddr4_head() 96 { 97 atf_set "descr" "Checks gethostbyaddr(3) for AF_INET (auto, as determined by nsswitch.conf(5)" 98 } 99 gethostbyaddr4_body() 100 { 101 start_dns_server 4 102 atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a4" 103 } 104 gethostbyaddr4_cleanup() 105 { 106 stop_dns_server 4 107 } 108 109 atf_test_case gethostbyaddr6 cleanup 110 gethostbyaddr6_head() 111 { 112 atf_set "descr" "Checks gethostbyaddr(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)" 113 } 114 gethostbyaddr6_body() 115 { 116 start_dns_server 4 117 atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a6" 118 } 119 gethostbyaddr6_cleanup() 120 { 121 stop_dns_server 4 122 } 123 124 atf_test_case hostsbynamelookup4 125 hostsbynamelookup4_head() 126 { 127 atf_set "descr" "Checks /etc/hosts name lookup for AF_INET" 128 } 129 hostsbynamelookup4_body() 130 { 131 atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 $l4" 132 } 133 134 atf_test_case hostsbynamelookup6 135 hostsbynamelookup6_head() 136 { 137 atf_set "descr" "Checks /etc/hosts name lookup for AF_INET6" 138 } 139 hostsbynamelookup6_body() 140 { 141 atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 $l6" 142 } 143 144 atf_test_case hostsbyaddrlookup4 145 hostsbyaddrlookup4_head() 146 { 147 atf_set "descr" "Checks /etc/hosts address lookup for AF_INET" 148 } 149 hostsbyaddrlookup4_body() 150 { 151 atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 -a $al4" 152 } 153 154 atf_test_case hostsbyaddrlookup6 155 hostsbyaddrlookup6_head() 156 { 157 atf_set "descr" "Checks /etc/hosts address lookup for AF_INET6" 158 } 159 hostsbyaddrlookup6_body() 160 { 161 atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 -a $al6" 162 } 163 164 atf_test_case dnsbynamelookup4 cleanup 165 dnsbynamelookup4_head() 166 { 167 atf_set "descr" "Checks DNS name lookup for AF_INET" 168 } 169 dnsbynamelookup4_body() 170 { 171 start_dns_server 4 172 atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 $n4" 173 } 174 dnsbynamelookup4_cleanup() 175 { 176 stop_dns_server 4 177 } 178 179 atf_test_case dnsbynamelookup6 cleanup 180 dnsbynamelookup6_head() 181 { 182 atf_set "descr" "Checks DNS name lookup for AF_INET6" 183 } 184 dnsbynamelookup6_body() 185 { 186 start_dns_server 4 187 atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 $n6" 188 } 189 dnsbynamelookup6_cleanup() 190 { 191 stop_dns_server 4 192 } 193 194 atf_test_case dnsbyaddrlookup4 cleanup 195 dnsbyaddrlookup4_head() 196 { 197 atf_set "descr" "Checks DNS address lookup for AF_INET" 198 } 199 dnsbyaddrlookup4_body() 200 { 201 start_dns_server 4 202 atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 -a $a4" 203 } 204 dnsbyaddrlookup4_cleanup() 205 { 206 stop_dns_server 4 207 } 208 209 atf_test_case dnsbyaddrlookup6 cleanup 210 dnsbyaddrlookup6_head() 211 { 212 atf_set "descr" "Checks dns address lookup for AF_INET6" 213 } 214 dnsbyaddrlookup6_body() 215 { 216 start_dns_server 4 217 atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 -a $a6" 218 } 219 dnsbyaddrlookup6_cleanup() 220 { 221 stop_dns_server 4 222 } 223 224 atf_init_test_cases() 225 { 226 atf_add_test_case gethostbyname4 227 atf_add_test_case gethostbyname6 228 atf_add_test_case gethostbyaddr4 229 atf_add_test_case gethostbyaddr6 230 231 atf_add_test_case hostsbynamelookup4 232 atf_add_test_case hostsbynamelookup6 233 atf_add_test_case hostsbyaddrlookup4 234 atf_add_test_case hostsbyaddrlookup6 235 236 atf_add_test_case dnsbynamelookup4 237 atf_add_test_case dnsbynamelookup6 238 atf_add_test_case dnsbyaddrlookup4 239 atf_add_test_case dnsbyaddrlookup6 240 } 241