1*544eb112Sgson# $NetBSD: t_hostent.sh,v 1.10 2014/01/13 11:08:14 gson Exp $ 20f567347Schristos# 30f567347Schristos# Copyright (c) 2008 The NetBSD Foundation, Inc. 40f567347Schristos# All rights reserved. 50f567347Schristos# 60f567347Schristos# Redistribution and use in source and binary forms, with or without 70f567347Schristos# modification, are permitted provided that the following conditions 80f567347Schristos# are met: 90f567347Schristos# 1. Redistributions of source code must retain the above copyright 100f567347Schristos# notice, this list of conditions and the following disclaimer. 110f567347Schristos# 2. Redistributions in binary form must reproduce the above copyright 120f567347Schristos# notice, this list of conditions and the following disclaimer in the 130f567347Schristos# documentation and/or other materials provided with the distribution. 140f567347Schristos# 150f567347Schristos# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 160560f419Schristos# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 170f567347Schristos# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 180f567347Schristos# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 190f567347Schristos# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 200f567347Schristos# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 210f567347Schristos# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 220f567347Schristos# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 230f567347Schristos# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 240f567347Schristos# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 250f567347Schristos# POSSIBILITY OF SUCH DAMAGE. 260f567347Schristos# 270f567347Schristos 280f567347Schristosn6="sixthavenue.astron.com" 299a6b9e13Schristosa6="2620:106:3003:1f00:3e4a:92ff:fef4:e180" 300f567347Schristosans6="name=$n6, length=16, addrtype=24, aliases=[] addr_list=[$a6]\n" 310f567347Schristos 320f567347Schristosn4="sixthavenue.astron.com" 339a6b9e13Schristosa4="38.117.134.16" 340f567347Schristosans4="name=$n4, length=4, addrtype=2, aliases=[] addr_list=[$a4]\n" 350f567347Schristos 360f567347Schristosl6="localhost" 370f567347Schristosal6="::1" 380f567347Schristosloc6="name=$l6, length=16, addrtype=24, aliases=[localhost. localhost.localdomain.] addr_list=[$al6]\n" 390f567347Schristos 400f567347Schristosl4="localhost" 410f567347Schristosal4="127.0.0.1" 420f567347Schristosloc4="name=$l4, length=4, addrtype=2, aliases=[localhost. localhost.localdomain.] addr_list=[$al4]\n" 430f567347Schristos 44cca81d59Schristosdir="$(atf_get_srcdir)" 45cca81d59Schristosres="-r ${dir}/resolv.conf" 46cca81d59Schristos 47e54ff2dcSgson# Hijack DNS traffic using a single rump server instance and a DNS 48341c8e68Sgson# server listening on its loopback address. 49e54ff2dcSgson 50e54ff2dcSgsonstart_dns_server() { 51e54ff2dcSgson export RUMP_SERVER=unix:///tmp/rumpserver 520560f419Schristos rump_server -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \ 530560f419Schristos -lrumpnet_netinet6 -lrumpnet_local $RUMP_SERVER 54cca81d59Schristos HIJACK_DNS="LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK='socket=inet:inet6'" 55cca81d59Schristos eval $HIJACK_DNS ${dir}/h_dns_server $1 56e54ff2dcSgson} 57e54ff2dcSgson 58e54ff2dcSgsonstop_dns_server() { 59c0cdf73eSchristos export RUMP_SERVER=unix:///tmp/rumpserver 60cca81d59Schristos kill $(cat dns_server_$1.pid) 61e54ff2dcSgson rump.halt 62e54ff2dcSgson} 63e54ff2dcSgson 64c0cdf73eSchristosatf_test_case gethostbyname4 cleanup 650f567347Schristosgethostbyname4_head() 660f567347Schristos{ 670f567347Schristos atf_set "descr" "Checks gethostbyname2(3) for AF_INET (auto, as determined by nsswitch.conf(5)" 680f567347Schristos} 690f567347Schristosgethostbyname4_body() 700f567347Schristos{ 71cca81d59Schristos start_dns_server 4 72*544eb112Sgson atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -4 $n4" 73c0cdf73eSchristos} 74c0cdf73eSchristosgethostbyname4_cleanup() 75c0cdf73eSchristos{ 76cca81d59Schristos stop_dns_server 4 770f567347Schristos} 780f567347Schristos 79c0cdf73eSchristosatf_test_case gethostbyname6 cleanup cleanup 800f567347Schristosgethostbyname6_head() 810f567347Schristos{ 820f567347Schristos atf_set "descr" "Checks gethostbyname2(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)" 830f567347Schristos} 840f567347Schristosgethostbyname6_body() 850f567347Schristos{ 86cca81d59Schristos start_dns_server 4 87cca81d59Schristos atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -6 $n6" 88c0cdf73eSchristos} 89c0cdf73eSchristosgethostbyname6_cleanup() 90c0cdf73eSchristos{ 91cca81d59Schristos stop_dns_server 4 920f567347Schristos} 930f567347Schristos 94c0cdf73eSchristosatf_test_case gethostbyaddr4 cleanup 950f567347Schristosgethostbyaddr4_head() 960f567347Schristos{ 970f567347Schristos atf_set "descr" "Checks gethostbyaddr(3) for AF_INET (auto, as determined by nsswitch.conf(5)" 980f567347Schristos} 990f567347Schristosgethostbyaddr4_body() 1000f567347Schristos{ 101cca81d59Schristos start_dns_server 4 102cca81d59Schristos atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a4" 103c0cdf73eSchristos} 104c0cdf73eSchristosgethostbyaddr4_cleanup() 105c0cdf73eSchristos{ 106cca81d59Schristos stop_dns_server 4 1070f567347Schristos} 1080f567347Schristos 109c0cdf73eSchristosatf_test_case gethostbyaddr6 cleanup 1100f567347Schristosgethostbyaddr6_head() 1110f567347Schristos{ 1120f567347Schristos atf_set "descr" "Checks gethostbyaddr(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)" 1130f567347Schristos} 1140f567347Schristosgethostbyaddr6_body() 1150f567347Schristos{ 116cca81d59Schristos start_dns_server 4 117feb2d702Sgson atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a6" 118c0cdf73eSchristos} 119c0cdf73eSchristosgethostbyaddr6_cleanup() 120c0cdf73eSchristos{ 121cca81d59Schristos stop_dns_server 4 1220f567347Schristos} 1230f567347Schristos 1240f567347Schristosatf_test_case hostsbynamelookup4 1250f567347Schristoshostsbynamelookup4_head() 1260f567347Schristos{ 1270f567347Schristos atf_set "descr" "Checks /etc/hosts name lookup for AF_INET" 1280f567347Schristos} 1290f567347Schristoshostsbynamelookup4_body() 1300f567347Schristos{ 131cca81d59Schristos atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 $l4" 1320f567347Schristos} 1330f567347Schristos 1340f567347Schristosatf_test_case hostsbynamelookup6 1350f567347Schristoshostsbynamelookup6_head() 1360f567347Schristos{ 1370f567347Schristos atf_set "descr" "Checks /etc/hosts name lookup for AF_INET6" 1380f567347Schristos} 1390f567347Schristoshostsbynamelookup6_body() 1400f567347Schristos{ 141cca81d59Schristos atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 $l6" 1420f567347Schristos} 1430f567347Schristos 1440f567347Schristosatf_test_case hostsbyaddrlookup4 1450f567347Schristoshostsbyaddrlookup4_head() 1460f567347Schristos{ 1470f567347Schristos atf_set "descr" "Checks /etc/hosts address lookup for AF_INET" 1480f567347Schristos} 1490f567347Schristoshostsbyaddrlookup4_body() 1500f567347Schristos{ 151cca81d59Schristos atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 -a $al4" 1520f567347Schristos} 1530f567347Schristos 1540f567347Schristosatf_test_case hostsbyaddrlookup6 1550f567347Schristoshostsbyaddrlookup6_head() 1560f567347Schristos{ 1570f567347Schristos atf_set "descr" "Checks /etc/hosts address lookup for AF_INET6" 1580f567347Schristos} 1590f567347Schristoshostsbyaddrlookup6_body() 1600f567347Schristos{ 161cca81d59Schristos atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 -a $al6" 1620f567347Schristos} 1630f567347Schristos 164c0cdf73eSchristosatf_test_case dnsbynamelookup4 cleanup 1650f567347Schristosdnsbynamelookup4_head() 1660f567347Schristos{ 1670f567347Schristos atf_set "descr" "Checks DNS name lookup for AF_INET" 1680f567347Schristos} 1690f567347Schristosdnsbynamelookup4_body() 1700f567347Schristos{ 171cca81d59Schristos start_dns_server 4 172cca81d59Schristos atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 $n4" 173c0cdf73eSchristos} 174c0cdf73eSchristosdnsbynamelookup4_cleanup() 175c0cdf73eSchristos{ 176cca81d59Schristos stop_dns_server 4 1770f567347Schristos} 1780f567347Schristos 179c0cdf73eSchristosatf_test_case dnsbynamelookup6 cleanup 1800f567347Schristosdnsbynamelookup6_head() 1810f567347Schristos{ 1820f567347Schristos atf_set "descr" "Checks DNS name lookup for AF_INET6" 1830f567347Schristos} 1840f567347Schristosdnsbynamelookup6_body() 1850f567347Schristos{ 186cca81d59Schristos start_dns_server 4 187cca81d59Schristos atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 $n6" 188c0cdf73eSchristos} 189c0cdf73eSchristosdnsbynamelookup6_cleanup() 190c0cdf73eSchristos{ 191cca81d59Schristos stop_dns_server 4 1920f567347Schristos} 1930f567347Schristos 194c0cdf73eSchristosatf_test_case dnsbyaddrlookup4 cleanup 1950f567347Schristosdnsbyaddrlookup4_head() 1960f567347Schristos{ 1970f567347Schristos atf_set "descr" "Checks DNS address lookup for AF_INET" 1980f567347Schristos} 1990f567347Schristosdnsbyaddrlookup4_body() 2000f567347Schristos{ 201cca81d59Schristos start_dns_server 4 202cca81d59Schristos atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 -a $a4" 203c0cdf73eSchristos} 204c0cdf73eSchristosdnsbyaddrlookup4_cleanup() 205c0cdf73eSchristos{ 206cca81d59Schristos stop_dns_server 4 2070f567347Schristos} 2080f567347Schristos 209c0cdf73eSchristosatf_test_case dnsbyaddrlookup6 cleanup 2100f567347Schristosdnsbyaddrlookup6_head() 2110f567347Schristos{ 2120f567347Schristos atf_set "descr" "Checks dns address lookup for AF_INET6" 2130f567347Schristos} 2140f567347Schristosdnsbyaddrlookup6_body() 2150f567347Schristos{ 216cca81d59Schristos start_dns_server 4 217cca81d59Schristos atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 -a $a6" 218c0cdf73eSchristos} 219c0cdf73eSchristosdnsbyaddrlookup6_cleanup() 220c0cdf73eSchristos{ 221cca81d59Schristos stop_dns_server 4 2220f567347Schristos} 2230f567347Schristos 2240f567347Schristosatf_init_test_cases() 2250f567347Schristos{ 2260f567347Schristos atf_add_test_case gethostbyname4 2270f567347Schristos atf_add_test_case gethostbyname6 2280f567347Schristos atf_add_test_case gethostbyaddr4 2290f567347Schristos atf_add_test_case gethostbyaddr6 2300f567347Schristos 2310f567347Schristos atf_add_test_case hostsbynamelookup4 2320f567347Schristos atf_add_test_case hostsbynamelookup6 2330f567347Schristos atf_add_test_case hostsbyaddrlookup4 2340f567347Schristos atf_add_test_case hostsbyaddrlookup6 2350f567347Schristos 2360f567347Schristos atf_add_test_case dnsbynamelookup4 2370f567347Schristos atf_add_test_case dnsbynamelookup6 2380f567347Schristos atf_add_test_case dnsbyaddrlookup4 2390f567347Schristos atf_add_test_case dnsbyaddrlookup6 2400f567347Schristos} 241