Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/net Use our own resolv.conf file simplifying ...



details:   https://anonhg.NetBSD.org/src/rev/c384fe01c8a2
branches:  trunk
changeset: 792584:c384fe01c8a2
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 09 02:18:10 2014 +0000

description:
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

diffstat:

 tests/lib/libc/net/Makefile       |   4 +-
 tests/lib/libc/net/h_dns_server.c |  83 +++++++++++++++++++++++++++++++++-----
 tests/lib/libc/net/h_hostent.c    |  17 +++++--
 tests/lib/libc/net/resolv.conf    |   1 +
 tests/lib/libc/net/t_hostent.sh   |  80 +++++++++++++++++--------------------
 5 files changed, 123 insertions(+), 62 deletions(-)

diffs (truncated from 427 to 300 lines):

diff -r 46ebe5404b45 -r c384fe01c8a2 tests/lib/libc/net/Makefile
--- a/tests/lib/libc/net/Makefile       Thu Jan 09 00:57:25 2014 +0000
+++ b/tests/lib/libc/net/Makefile       Thu Jan 09 02:18:10 2014 +0000
@@ -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 -r 46ebe5404b45 -r c384fe01c8a2 tests/lib/libc/net/h_dns_server.c
--- a/tests/lib/libc/net/h_dns_server.c Thu Jan 09 00:57:25 2014 +0000
+++ b/tests/lib/libc/net/h_dns_server.c Thu Jan 09 02:18:10 2014 +0000
@@ -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 @@
        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 @@
        }
 }
 
+#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 @@
        char pidfile_name[40];
        FILE *f;
        int one = 1;
+#ifdef DEBUG
+       char buf1[1024], buf2[1024];
+#endif
 
        daemon2_fork();
 
@@ -276,7 +313,11 @@
        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 @@
                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 @@
                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 -r 46ebe5404b45 -r c384fe01c8a2 tests/lib/libc/net/h_hostent.c
--- a/tests/lib/libc/net/h_hostent.c    Thu Jan 09 00:57:25 2014 +0000
+++ b/tests/lib/libc/net/h_hostent.c    Thu Jan 09 02:18:10 2014 +0000
@@ -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 @@
 
 #include "hostent.h"
 
+extern const char *__res_conf_name;
+
 static void
 phostent(const struct hostent *h)
 {
@@ -123,7 +125,7 @@
        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 @@
                case 'a':
                        byaddr++;
                        break;
+               case 'f':
+                       _hf_sethostsfile(optarg);
+                       break;
+               case 'r':
+                       __res_conf_name = optarg;
+                       break;
                case 't':
                        type = optarg;
                        break;
-               case 'f':
-                       _hf_sethostsfile(optarg);
-                       break;
                default:
                        usage();
                }
diff -r 46ebe5404b45 -r c384fe01c8a2 tests/lib/libc/net/resolv.conf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libc/net/resolv.conf    Thu Jan 09 02:18:10 2014 +0000
@@ -0,0 +1,1 @@
+nameserver 127.0.0.1
diff -r 46ebe5404b45 -r c384fe01c8a2 tests/lib/libc/net/t_hostent.sh
--- a/tests/lib/libc/net/t_hostent.sh   Thu Jan 09 00:57:25 2014 +0000
+++ b/tests/lib/libc/net/t_hostent.sh   Thu Jan 09 02:18:10 2014 +0000
@@ -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 @@
 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 @@
 
 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_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_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



Home | Main Index | Thread Index | Old Index