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