summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2014-01-09 02:18:10 +0000
committerchristos <christos@NetBSD.org>2014-01-09 02:18:10 +0000
commit81f6f38ec8b44c03f0f0bbcd71e1fe5dfdae5c01 (patch)
treef58ba7a00461c2515a7cae8ae9707466f6473e95
parentf2286531482fd87bdf43756471bec2796508d6c7 (diff)
Use our own resolv.conf file simplifying the test to not need rump_vfs.
Add debugging on the dns server One test fails (gethostbyaddr6) why? It runs without rump
-rw-r--r--tests/lib/libc/net/Makefile4
-rw-r--r--tests/lib/libc/net/h_dns_server.c83
-rw-r--r--tests/lib/libc/net/h_hostent.c17
-rw-r--r--tests/lib/libc/net/resolv.conf1
-rw-r--r--tests/lib/libc/net/t_hostent.sh80
5 files changed, 123 insertions, 62 deletions
diff --git a/tests/lib/libc/net/Makefile b/tests/lib/libc/net/Makefile
index a428eb34742..c9c7fe76bc2 100644
--- a/tests/lib/libc/net/Makefile
+++ b/tests/lib/libc/net/Makefile
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile,v 1.9 2014/01/06 14:50:32 gson Exp $
+# $NetBSD: Makefile,v 1.10 2014/01/09 02:18:10 christos Exp $
.include <bsd.own.mk>
MKMAN= no
TESTS_SUBDIRS+= getaddrinfo
-FILES+=hosts
+FILES+=hosts resolv.conf
TESTSDIR= ${TESTSBASE}/lib/libc/net
diff --git a/tests/lib/libc/net/h_dns_server.c b/tests/lib/libc/net/h_dns_server.c
index c738559781f..d8c173dcd4a 100644
--- a/tests/lib/libc/net/h_dns_server.c
+++ b/tests/lib/libc/net/h_dns_server.c
@@ -1,4 +1,4 @@
-/* $NetBSD: h_dns_server.c,v 1.2 2014/01/06 16:42:57 gson Exp $ */
+/* $NetBSD: h_dns_server.c,v 1.3 2014/01/09 02:18:10 christos Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: h_dns_server.c,v 1.2 2014/01/06 16:42:57 gson Exp $");
+__RCSID("$NetBSD: h_dns_server.c,v 1.3 2014/01/09 02:18:10 christos Exp $");
#include <ctype.h>
#include <err.h>
@@ -58,6 +58,12 @@ union sockaddr_either {
struct sockaddr_in6 sin6;
};
+#ifdef DEBUG
+#define DPRINTF(...) fprintf(stderr, __VA_ARGS__)
+#else
+#define DPRINTF(...)
+#endif
+
/* A DNS question and its corresponding answer */
struct dns_data {
@@ -131,6 +137,34 @@ name_eq(const unsigned char *a, const unsigned char *b) {
}
}
+#ifdef DEBUG
+static char *
+name2str(const void *v, char *buf, size_t buflen) {
+ const unsigned char *a = v;
+ char *b = buf;
+ char *eb = buf + buflen;
+
+#define ADDC(c) do { \
+ if (b < eb) \
+ *b++ = c; \
+ else \
+ return NULL; \
+ } while (/*CONSTCOND*/0)
+ for (int did = 0;; did++) {
+ int lena = *a++;
+ if (lena == 0) {
+ ADDC('\0');
+ return buf;
+ }
+ if (did)
+ ADDC('.');
+ for (int i = 0; i < lena; i++)
+ ADDC(a[i]);
+ a += lena;
+ }
+}
+#endif
+
/* XXX the daemon2_* functions should be in a library */
int __daemon2_detach_pipe[2];
@@ -237,6 +271,9 @@ int main(int argc, char **argv) {
char pidfile_name[40];
FILE *f;
int one = 1;
+#ifdef DEBUG
+ char buf1[1024], buf2[1024];
+#endif
daemon2_fork();
@@ -276,7 +313,11 @@ int main(int argc, char **argv) {
f = fopen(pidfile_name, "w");
fprintf(f, "%d", getpid());
fclose(f);
+#ifdef DEBUG
+ daemon2_detach(0, 1);
+#else
daemon2_detach(0, 0);
+#endif
for (;;) {
unsigned char buf[512];
@@ -289,28 +330,47 @@ int main(int argc, char **argv) {
nrecv = recvfrom(s, buf, sizeof buf, 0, &from.s, &fromlen);
if (nrecv < 0)
err(1, "recvfrom");
- if (nrecv < 12)
- continue; /* Too short */
- if ((buf[2] & 0x80) != 0)
- continue; /* Not a query */
- if (!(buf[4] == 0 && buf[5] == 1))
- continue; /* QDCOUNT is not 1 */
+ if (nrecv < 12) {
+ DPRINTF("Too short %zd\n", nrecv);
+ continue;
+ }
+ if ((buf[2] & 0x80) != 0) {
+ DPRINTF("Not a query 0x%x\n", buf[2]);
+ continue;
+ }
+ if (!(buf[4] == 0 && buf[5] == 1)) {
+ DPRINTF("QCOUNT is not 1 0x%x 0x%x\n", buf[4], buf[5]);
+ continue; /* QDCOUNT is not 1 */
+ }
for (dp = data; dp->qname_size != 0; dp++) {
int qtype, qclass;
p = buf + 12; /* Point to QNAME */
int n = name_eq(p, (const unsigned char *) dp->qname);
- if (n == 0)
+ if (n == 0) {
+ DPRINTF("no match name %s != %s\n",
+ name2str(p, buf1, sizeof(buf1)),
+ name2str(dp->qname, buf2, sizeof(buf2)));
continue; /* Name does not match */
+ }
+ DPRINTF("match name %s\n",
+ name2str(p, buf1, sizeof(buf1)));
p += n; /* Skip QNAME */
qtype = *p++ << 8;
qtype |= *p++;
- if (qtype != dp->qtype)
+ if (qtype != dp->qtype) {
+ DPRINTF("no match name 0x%x != 0x%x\n",
+ qtype, dp->qtype);
continue;
+ }
+ DPRINTF("match type 0x%x\n", qtype);
qclass = *p++ << 8;
qclass |= *p++;
- if (qclass != 1) /* IN */
+ if (qclass != 1) { /* IN */
+ DPRINTF("no match class %d != 1\n", qclass);
continue;
+ }
+ DPRINTF("match class %d\n", qclass);
goto found;
}
continue;
@@ -332,6 +392,7 @@ int main(int argc, char **argv) {
memcpy(p, dp->answer, dp->answer_size);
p += dp->answer_size;
nsent = sendto(s, buf, p - buf, 0, &from.s, fromlen);
+ DPRINTF("sent %zd\n", nsent);
if (nsent != p - buf)
warn("sendto");
}
diff --git a/tests/lib/libc/net/h_hostent.c b/tests/lib/libc/net/h_hostent.c
index bfcdd0db4a8..4a7292320f3 100644
--- a/tests/lib/libc/net/h_hostent.c
+++ b/tests/lib/libc/net/h_hostent.c
@@ -1,4 +1,4 @@
-/* $NetBSD: h_hostent.c,v 1.1 2013/08/16 15:29:45 christos Exp $ */
+/* $NetBSD: h_hostent.c,v 1.2 2014/01/09 02:18:10 christos Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: h_hostent.c,v 1.1 2013/08/16 15:29:45 christos Exp $");
+__RCSID("$NetBSD: h_hostent.c,v 1.2 2014/01/09 02:18:10 christos Exp $");
#include <stdio.h>
#include <string.h>
@@ -47,6 +47,8 @@ __RCSID("$NetBSD: h_hostent.c,v 1.1 2013/08/16 15:29:45 christos Exp $");
#include "hostent.h"
+extern const char *__res_conf_name;
+
static void
phostent(const struct hostent *h)
{
@@ -123,7 +125,7 @@ main(int argc, char *argv[])
info.buflen = sizeof(buf);
info.he = &e;
- while ((c = getopt(argc, argv, "46af:t:")) != -1) {
+ while ((c = getopt(argc, argv, "46af:r:t:")) != -1) {
switch (c) {
case '4':
af = AF_INET;
@@ -134,12 +136,15 @@ main(int argc, char *argv[])
case 'a':
byaddr++;
break;
- case 't':
- type = optarg;
- break;
case 'f':
_hf_sethostsfile(optarg);
break;
+ case 'r':
+ __res_conf_name = optarg;
+ break;
+ case 't':
+ type = optarg;
+ break;
default:
usage();
}
diff --git a/tests/lib/libc/net/resolv.conf b/tests/lib/libc/net/resolv.conf
new file mode 100644
index 00000000000..bbc8559cd54
--- /dev/null
+++ b/tests/lib/libc/net/resolv.conf
@@ -0,0 +1 @@
+nameserver 127.0.0.1
diff --git a/tests/lib/libc/net/t_hostent.sh b/tests/lib/libc/net/t_hostent.sh
index 8a3e58bf01e..88421c7be9c 100644
--- a/tests/lib/libc/net/t_hostent.sh
+++ b/tests/lib/libc/net/t_hostent.sh
@@ -1,4 +1,4 @@
-# $NetBSD: t_hostent.sh,v 1.4 2014/01/06 14:50:32 gson Exp $
+# $NetBSD: t_hostent.sh,v 1.5 2014/01/09 02:18:10 christos Exp $
#
# Copyright (c) 2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -13,7 +13,7 @@
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# ``AS IS'' AND ANY EXP{res}S OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
@@ -41,6 +41,9 @@ l4="localhost"
al4="127.0.0.1"
loc4="name=$l4, length=4, addrtype=2, aliases=[localhost. localhost.localdomain.] addr_list=[$al4]\n"
+dir="$(atf_get_srcdir)"
+res="-r ${dir}/resolv.conf"
+
# Hijack DNS traffic using a single rump server instance and a DNS
# server listening on its loopback address. Also hijack file system
# call to /etc, mapping them to the root file system of the rump
@@ -48,16 +51,15 @@ loc4="name=$l4, length=4, addrtype=2, aliases=[localhost. localhost.localdomain.
start_dns_server() {
export RUMP_SERVER=unix:///tmp/rumpserver
- rump_server -lrumpvfs -lrumpdev -lrumpnet \
+ rump_server -lrumpdev -lrumpnet \
-lrumpnet_net -lrumpnet_netinet -lrumpnet_local \
$RUMP_SERVER
- HIJACK_DNS="LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK='path=/etc,socket=inet:inet6'"
- eval $HIJACK_DNS sh -c 'echo nameserver 127.0.0.1 >/etc/resolv.conf'
- eval $HIJACK_DNS $(atf_get_srcdir)/h_dns_server 4
+ HIJACK_DNS="LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK='socket=inet:inet6'"
+ eval $HIJACK_DNS ${dir}/h_dns_server $1
}
stop_dns_server() {
- kill $(cat dns_server_4.pid)
+ kill $(cat dns_server_$1.pid)
rump.halt
}
@@ -68,9 +70,9 @@ gethostbyname4_head()
}
gethostbyname4_body()
{
- start_dns_server
- atf_check -o inline:"$ans4" -x "$HIJACK_DNS $(atf_get_srcdir)/h_hostent -t auto -4 $n4"
- stop_dns_server
+ start_dns_server 4
+ atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent $res -t auto -4 $n4"
+ stop_dns_server 4
}
atf_test_case gethostbyname6
@@ -80,9 +82,9 @@ gethostbyname6_head()
}
gethostbyname6_body()
{
- start_dns_server
- atf_check -o inline:"$ans6" -x "$HIJACK_DNS $(atf_get_srcdir)/h_hostent -t auto -6 $n6"
- stop_dns_server
+ start_dns_server 4
+ atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -6 $n6"
+ stop_dns_server 4
}
atf_test_case gethostbyaddr4
@@ -92,9 +94,9 @@ gethostbyaddr4_head()
}
gethostbyaddr4_body()
{
- start_dns_server
- atf_check -o inline:"$ans4" -x "$HIJACK_DNS $(atf_get_srcdir)/h_hostent -t auto -a $a4"
- stop_dns_server
+ start_dns_server 4
+ atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a4"
+ stop_dns_server 4
}
atf_test_case gethostbyaddr6
@@ -104,9 +106,9 @@ gethostbyaddr6_head()
}
gethostbyaddr6_body()
{
- start_dns_server
- atf_check -o inline:"$ans6" -x "$HIJACK_DNS $(atf_get_srcdir)/h_hostent -t auto -a $a6"
- stop_dns_server
+ start_dns_server 4
+ atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent -t auto -a $a6"
+ stop_dns_server 4
}
atf_test_case hostsbynamelookup4
@@ -116,8 +118,7 @@ hostsbynamelookup4_head()
}
hostsbynamelookup4_body()
{
- local dir=$(atf_get_srcdir)
- atf_check -o inline:"$loc4" -x "$dir/h_hostent -f $dir/hosts -t file -4 $l4"
+ atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 $l4"
}
atf_test_case hostsbynamelookup6
@@ -127,8 +128,7 @@ hostsbynamelookup6_head()
}
hostsbynamelookup6_body()
{
- local dir=$(atf_get_srcdir)
- atf_check -o inline:"$loc6" -x "$dir/h_hostent -f $dir/hosts -t file -6 $l6"
+ atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 $l6"
}
atf_test_case hostsbyaddrlookup4
@@ -138,8 +138,7 @@ hostsbyaddrlookup4_head()
}
hostsbyaddrlookup4_body()
{
- local dir=$(atf_get_srcdir)
- atf_check -o inline:"$loc4" -x "$dir/h_hostent -f $dir/hosts -t file -4 -a $al4"
+ atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 -a $al4"
}
atf_test_case hostsbyaddrlookup6
@@ -149,8 +148,7 @@ hostsbyaddrlookup6_head()
}
hostsbyaddrlookup6_body()
{
- local dir=$(atf_get_srcdir)
- atf_check -o inline:"$loc6" -x "$dir/h_hostent -f $dir/hosts -t file -6 -a $al6"
+ atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 -a $al6"
}
atf_test_case dnsbynamelookup4
@@ -160,10 +158,9 @@ dnsbynamelookup4_head()
}
dnsbynamelookup4_body()
{
- local dir=$(atf_get_srcdir)
- start_dns_server
- atf_check -o inline:"$ans4" -x "$HIJACK_DNS $dir/h_hostent -t dns -4 $n4"
- stop_dns_server
+ start_dns_server 4
+ atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 $n4"
+ stop_dns_server 4
}
atf_test_case dnsbynamelookup6
@@ -173,10 +170,9 @@ dnsbynamelookup6_head()
}
dnsbynamelookup6_body()
{
- local dir=$(atf_get_srcdir)
- start_dns_server
- atf_check -o inline:"$ans6" -x "$HIJACK_DNS $dir/h_hostent -t dns -6 $n6"
- stop_dns_server
+ start_dns_server 4
+ atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 $n6"
+ stop_dns_server 4
}
atf_test_case dnsbyaddrlookup4
@@ -186,10 +182,9 @@ dnsbyaddrlookup4_head()
}
dnsbyaddrlookup4_body()
{
- local dir=$(atf_get_srcdir)
- start_dns_server
- atf_check -o inline:"$ans4" -x "$HIJACK_DNS $dir/h_hostent -t dns -4 -a $a4"
- stop_dns_server
+ start_dns_server 4
+ atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 -a $a4"
+ stop_dns_server 4
}
atf_test_case dnsbyaddrlookup6
@@ -199,10 +194,9 @@ dnsbyaddrlookup6_head()
}
dnsbyaddrlookup6_body()
{
- local dir=$(atf_get_srcdir)
- start_dns_server
- atf_check -o inline:"$ans6" -x "$HIJACK_DNS $dir/h_hostent -t dns -6 -a $a6"
- stop_dns_server
+ start_dns_server 4
+ atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 -a $a6"
+ stop_dns_server 4
}
atf_init_test_cases()