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