t_hostent.sh revision 1.5 1 # $NetBSD: t_hostent.sh,v 1.5 2014/01/09 02:18:10 christos 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 EXP{res}S 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. Also hijack file system
49 # call to /etc, mapping them to the root file system of the rump
50 # server, so that we can control the contents of /etc/resolv.conf.
51
52 start_dns_server() {
53 export RUMP_SERVER=unix:///tmp/rumpserver
54 rump_server -lrumpdev -lrumpnet \
55 -lrumpnet_net -lrumpnet_netinet -lrumpnet_local \
56 $RUMP_SERVER
57 HIJACK_DNS="LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK='socket=inet:inet6'"
58 eval $HIJACK_DNS ${dir}/h_dns_server $1
59 }
60
61 stop_dns_server() {
62 kill $(cat dns_server_$1.pid)
63 rump.halt
64 }
65
66 atf_test_case gethostbyname4
67 gethostbyname4_head()
68 {
69 atf_set "descr" "Checks gethostbyname2(3) for AF_INET (auto, as determined by nsswitch.conf(5)"
70 }
71 gethostbyname4_body()
72 {
73 start_dns_server 4
74 atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent $res -t auto -4 $n4"
75 stop_dns_server 4
76 }
77
78 atf_test_case gethostbyname6
79 gethostbyname6_head()
80 {
81 atf_set "descr" "Checks gethostbyname2(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)"
82 }
83 gethostbyname6_body()
84 {
85 start_dns_server 4
86 atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -6 $n6"
87 stop_dns_server 4
88 }
89
90 atf_test_case gethostbyaddr4
91 gethostbyaddr4_head()
92 {
93 atf_set "descr" "Checks gethostbyaddr(3) for AF_INET (auto, as determined by nsswitch.conf(5)"
94 }
95 gethostbyaddr4_body()
96 {
97 start_dns_server 4
98 atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a4"
99 stop_dns_server 4
100 }
101
102 atf_test_case gethostbyaddr6
103 gethostbyaddr6_head()
104 {
105 atf_set "descr" "Checks gethostbyaddr(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)"
106 }
107 gethostbyaddr6_body()
108 {
109 start_dns_server 4
110 atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent -t auto -a $a6"
111 stop_dns_server 4
112 }
113
114 atf_test_case hostsbynamelookup4
115 hostsbynamelookup4_head()
116 {
117 atf_set "descr" "Checks /etc/hosts name lookup for AF_INET"
118 }
119 hostsbynamelookup4_body()
120 {
121 atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 $l4"
122 }
123
124 atf_test_case hostsbynamelookup6
125 hostsbynamelookup6_head()
126 {
127 atf_set "descr" "Checks /etc/hosts name lookup for AF_INET6"
128 }
129 hostsbynamelookup6_body()
130 {
131 atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 $l6"
132 }
133
134 atf_test_case hostsbyaddrlookup4
135 hostsbyaddrlookup4_head()
136 {
137 atf_set "descr" "Checks /etc/hosts address lookup for AF_INET"
138 }
139 hostsbyaddrlookup4_body()
140 {
141 atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 -a $al4"
142 }
143
144 atf_test_case hostsbyaddrlookup6
145 hostsbyaddrlookup6_head()
146 {
147 atf_set "descr" "Checks /etc/hosts address lookup for AF_INET6"
148 }
149 hostsbyaddrlookup6_body()
150 {
151 atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 -a $al6"
152 }
153
154 atf_test_case dnsbynamelookup4
155 dnsbynamelookup4_head()
156 {
157 atf_set "descr" "Checks DNS name lookup for AF_INET"
158 }
159 dnsbynamelookup4_body()
160 {
161 start_dns_server 4
162 atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 $n4"
163 stop_dns_server 4
164 }
165
166 atf_test_case dnsbynamelookup6
167 dnsbynamelookup6_head()
168 {
169 atf_set "descr" "Checks DNS name lookup for AF_INET6"
170 }
171 dnsbynamelookup6_body()
172 {
173 start_dns_server 4
174 atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 $n6"
175 stop_dns_server 4
176 }
177
178 atf_test_case dnsbyaddrlookup4
179 dnsbyaddrlookup4_head()
180 {
181 atf_set "descr" "Checks DNS address lookup for AF_INET"
182 }
183 dnsbyaddrlookup4_body()
184 {
185 start_dns_server 4
186 atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 -a $a4"
187 stop_dns_server 4
188 }
189
190 atf_test_case dnsbyaddrlookup6
191 dnsbyaddrlookup6_head()
192 {
193 atf_set "descr" "Checks dns address lookup for AF_INET6"
194 }
195 dnsbyaddrlookup6_body()
196 {
197 start_dns_server 4
198 atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 -a $a6"
199 stop_dns_server 4
200 }
201
202 atf_init_test_cases()
203 {
204 atf_add_test_case gethostbyname4
205 atf_add_test_case gethostbyname6
206 atf_add_test_case gethostbyaddr4
207 atf_add_test_case gethostbyaddr6
208
209 atf_add_test_case hostsbynamelookup4
210 atf_add_test_case hostsbynamelookup6
211 atf_add_test_case hostsbyaddrlookup4
212 atf_add_test_case hostsbyaddrlookup6
213
214 atf_add_test_case dnsbynamelookup4
215 atf_add_test_case dnsbynamelookup6
216 atf_add_test_case dnsbyaddrlookup4
217 atf_add_test_case dnsbyaddrlookup6
218 }
219