From cc1eee4f5188a8174f10ab86da273fee50aa481a Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Wed, 21 Jun 2000 01:28:44 +0000 Subject: [PATCH] Add lwresd test --- bin/tests/system/lwresd/Makefile.in | 49 +++ bin/tests/system/lwresd/lwresd1/resolv.conf | 2 + bin/tests/system/lwresd/lwtest.c | 280 ++++++++++++++++++ .../lwresd/ns1/10.10.10.in-addr.arpa.db | 13 + bin/tests/system/lwresd/ns1/example1.db | 15 + bin/tests/system/lwresd/ns1/example2.db | 14 + bin/tests/system/lwresd/ns1/ip6.int.db | 12 + bin/tests/system/lwresd/ns1/named.conf | 35 +++ bin/tests/system/lwresd/ns1/root.db | 16 + bin/tests/system/lwresd/resolv.conf | 3 + bin/tests/system/lwresd/tests.sh | 36 +++ 11 files changed, 475 insertions(+) create mode 100644 bin/tests/system/lwresd/Makefile.in create mode 100644 bin/tests/system/lwresd/lwresd1/resolv.conf create mode 100644 bin/tests/system/lwresd/lwtest.c create mode 100644 bin/tests/system/lwresd/ns1/10.10.10.in-addr.arpa.db create mode 100644 bin/tests/system/lwresd/ns1/example1.db create mode 100644 bin/tests/system/lwresd/ns1/example2.db create mode 100644 bin/tests/system/lwresd/ns1/ip6.int.db create mode 100644 bin/tests/system/lwresd/ns1/named.conf create mode 100644 bin/tests/system/lwresd/ns1/root.db create mode 100644 bin/tests/system/lwresd/resolv.conf create mode 100644 bin/tests/system/lwresd/tests.sh diff --git a/bin/tests/system/lwresd/Makefile.in b/bin/tests/system/lwresd/Makefile.in new file mode 100644 index 0000000000..8a898f2688 --- /dev/null +++ b/bin/tests/system/lwresd/Makefile.in @@ -0,0 +1,49 @@ +# Copyright (C) 2000 Internet Software Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS +# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE +# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR +# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +# SOFTWARE. + +srcdir = @srcdir@ +VPATH = @srcdir@ +top_srcdir = @top_srcdir@ + +@BIND9_VERSION@ + +@BIND9_INCLUDES@ + +CINCLUDES = ${LWRES_INCLUDES} ${ISC_INCLUDES} + +CDEFINES = +CWARNINGS = + +LWRESLIBS = ${top_srcdir}/lib/lwres/liblwres.@A@ + +LWRESDEPLIBS = ${top_srcdir}/lib/lwres/liblwres.@A@ + +DEPLIBS = ${LWRESDEPLIBS} + +LIBS = ${LWRESLIBS} @LIBS@ + +TARGETS = lwtest + +OBJS = lwtest.@O@ + +SRCS = lwtest.c + +@BIND9_MAKE_RULES@ + +lwtest: ${OBJS} ${DEPLIBS} + ${LIBTOOL} ${CC} ${CFLAGS} -o $@ ${OBJS} ${UOBJS} ${LIBS} + +clean distclean:: + rm -f ${TARGETS} diff --git a/bin/tests/system/lwresd/lwresd1/resolv.conf b/bin/tests/system/lwresd/lwresd1/resolv.conf new file mode 100644 index 0000000000..376b224d10 --- /dev/null +++ b/bin/tests/system/lwresd/lwresd1/resolv.conf @@ -0,0 +1,2 @@ +nameserver 10.53.0.1 +search example1. diff --git a/bin/tests/system/lwresd/lwtest.c b/bin/tests/system/lwresd/lwtest.c new file mode 100644 index 0000000000..cfdf26583c --- /dev/null +++ b/bin/tests/system/lwresd/lwtest.c @@ -0,0 +1,280 @@ +/* + * Copyright (C) 2000 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include + +#include +#include + +#include + +#include + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +static int fails = 0; + +static void +CHECK(int val, const char *msg) { + if (val != 0) { + printf("I: %s returned %d\n", msg, val); + exit(1); + } +} + +#if 0 +static void +hexdump(const char *msg, void *base, size_t len) { + unsigned char *p; + unsigned int cnt; + + p = base; + cnt = 0; + + printf("*** %s (%u bytes @ %p)\n", msg, len, base); + + while (cnt < len) { + if (cnt % 16 == 0) + printf("%p: ", p); + else if (cnt % 8 == 0) + printf(" |"); + printf(" %02x", *p++); + cnt++; + + if (cnt % 16 == 0) + printf("\n"); + } + + if (cnt % 16 != 0) + printf("\n"); +} +#endif + +static char TESTSTRING[] = "This is a test. This is only a test. !!!"; +static lwres_context_t *ctx; + +static void +test_noop() { + int ret; + lwres_lwpacket_t pkt, pkt2; + lwres_nooprequest_t nooprequest, *nooprequest2; + lwres_noopresponse_t noopresponse, *noopresponse2; + lwres_buffer_t b; + + pkt.pktflags = 0; + pkt.serial = 0x11223344; + pkt.recvlength = 0x55667788; + pkt.result = 0; + + nooprequest.datalength = strlen(TESTSTRING); + nooprequest.data = TESTSTRING; + ret = lwres_nooprequest_render(ctx, &nooprequest, &pkt, &b); + CHECK(ret, "lwres_nooprequest_render"); + + /* + * Now, parse it into a new structure. + */ + lwres_buffer_first(&b); + ret = lwres_lwpacket_parseheader(&b, &pkt2); + CHECK(ret, "lwres_lwpacket_parseheader"); + + nooprequest2 = NULL; + ret = lwres_nooprequest_parse(ctx, &b, &pkt2, &nooprequest2); + CHECK(ret, "lwres_nooprequest_parse"); + + assert(nooprequest.datalength == nooprequest2->datalength); + assert(memcmp(nooprequest.data, nooprequest2->data, + nooprequest.datalength) == 0); + + lwres_nooprequest_free(ctx, &nooprequest2); + + lwres_context_freemem(ctx, b.base, b.length); + b.base = NULL; + b.length = 0; + + pkt.pktflags = 0; + pkt.serial = 0x11223344; + pkt.recvlength = 0x55667788; + pkt.result = 0xdeadbeef; + + noopresponse.data = TESTSTRING; + ret = lwres_noopresponse_render(ctx, &noopresponse, &pkt, &b); + CHECK(ret, "lwres_noopresponse_render"); + + /* + * Now, parse it into a new structure. + */ + lwres_buffer_first(&b); + ret = lwres_lwpacket_parseheader(&b, &pkt2); + CHECK(ret, "lwres_lwpacket_parseheader"); + + noopresponse2 = NULL; + ret = lwres_noopresponse_parse(ctx, &b, &pkt2, &noopresponse2); + CHECK(ret, "lwres_noopresponse_parse"); + + assert(noopresponse.datalength == noopresponse2->datalength); + assert(memcmp(noopresponse.data, noopresponse2->data, + noopresponse.datalength) == 0); + + lwres_noopresponse_free(ctx, &noopresponse2); + + lwres_context_freemem(ctx, b.base, b.length); + b.base = NULL; + b.length = 0; +} + +static void +test_gabn(const char *target, int pass) { + lwres_gabnresponse_t *res; +#if 0 + lwres_addr_t *addr; + unsigned int i; + char outbuf[64]; +#endif + int ret; + + res = NULL; + ret = lwres_getaddrsbyname(ctx, target, + LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6, + &res); + if ((pass && ret != LWRES_R_SUCCESS) || + (!pass && ret != LWRES_R_NOTFOUND)) + { + printf("I: gabn(%s) failed: %d\n", target, ret); + if (res != NULL) + lwres_gabnresponse_free(ctx, &res); + fails++; + return; + } +#if 0 + printf("Returned real name: (%u, %s)\n", + res->realnamelen, res->realname); + printf("%u aliases:\n", res->naliases); + for (i = 0 ; i < res->naliases ; i++) + printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]); + printf("%u addresses:\n", res->naddrs); + addr = LWRES_LIST_HEAD(res->addrs); + for (i = 0 ; i < res->naddrs ; i++) { + if (addr->family == LWRES_ADDRTYPE_V4) + (void)inet_ntop(AF_INET, addr->address, + outbuf, sizeof(outbuf)); + else + (void)inet_ntop(AF_INET6, addr->address, + outbuf, sizeof(outbuf)); + printf("\tAddr len %u family %08x %s\n", + addr->length, addr->family, outbuf); + addr = LWRES_LIST_NEXT(addr, link); + } +#endif + if (res != NULL) + lwres_gabnresponse_free(ctx, &res); +} + +static void +test_gnba(const char *target, lwres_uint32_t af, int pass) { + lwres_gnbaresponse_t *res; + int ret; +#if 0 + unsigned int i; +#endif + unsigned char addrbuf[16]; + unsigned int len; + + if (af == LWRES_ADDRTYPE_V4) { + len = 4; + ret = inet_pton(AF_INET, target, addrbuf); + assert(ret == 1); + } else { + len = 16; + ret = inet_pton(AF_INET6, target, addrbuf); + assert(ret == 1); + } + + res = NULL; + ret = lwres_getnamebyaddr(ctx, af, len, addrbuf, &res); + if ((pass && ret != LWRES_R_SUCCESS) || + (!pass && ret != LWRES_R_NOTFOUND)) + { + printf("I: gnba(%s) failed: %d\n", target, ret); + if (res != NULL) + lwres_gnbaresponse_free(ctx, &res); + fails++; + return; + } +#if 0 + printf("Returned real name: (%u, %s)\n", + res->realnamelen, res->realname); + printf("%u aliases:\n", res->naliases); + for (i = 0 ; i < res->naliases ; i++) + printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]); +#endif + if (res != NULL) + lwres_gnbaresponse_free(ctx, &res); +} + +int +main() { + lwres_result_t ret; + + lwres_udp_port = 9210; + + ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0); + CHECK(ret, "lwres_context_create"); + + ret = lwres_conf_parse(ctx, "resolv.conf"); + CHECK(ret, "lwres_conf_parse"); + + test_noop(); + + test_gabn("a.example1", TRUE); + test_gabn("a.example1.", TRUE); + test_gabn("a.example2", TRUE); + test_gabn("a.example2.", TRUE); + test_gabn("a.example3", FALSE); + test_gabn("a.example3.", FALSE); + test_gabn("a", TRUE); + test_gabn("a.", FALSE); + + test_gabn("b.example1", TRUE); + test_gabn("b.example1.", TRUE); + test_gabn("b.example2", TRUE); + test_gabn("b.example2.", TRUE); + test_gabn("b.example3", FALSE); + test_gabn("b.example3.", FALSE); + test_gabn("b", TRUE); + test_gabn("b.", FALSE); + + test_gabn("d.example1", FALSE); + + test_gabn("x", TRUE); + test_gabn("x.", TRUE); + + test_gnba("10.10.10.1", LWRES_ADDRTYPE_V4, TRUE); + test_gnba("10.10.10.17", LWRES_ADDRTYPE_V4, FALSE); + test_gnba("0123:4567:89ab:cdef:0123:4567:89ab:cdef", + LWRES_ADDRTYPE_V6, TRUE); + test_gnba("0123:4567:89ab:cdef:0123:4567:89ab:cde0", + LWRES_ADDRTYPE_V6, FALSE); + + return (fails); +} diff --git a/bin/tests/system/lwresd/ns1/10.10.10.in-addr.arpa.db b/bin/tests/system/lwresd/ns1/10.10.10.in-addr.arpa.db new file mode 100644 index 0000000000..3b620cc711 --- /dev/null +++ b/bin/tests/system/lwresd/ns1/10.10.10.in-addr.arpa.db @@ -0,0 +1,13 @@ +$TTL 300 ; 5 minutes +@ IN SOA mname1. . ( + 2000062001 ; serial + 20 ; refresh (20 seconds) + 20 ; retry (20 seconds) + 1814400 ; expire (3 weeks) + 3600 ; minimum (1 hour) + ) + NS ns +ns A 10.53.0.1 + +1 PTR test1.example +2 PTR test2.example diff --git a/bin/tests/system/lwresd/ns1/example1.db b/bin/tests/system/lwresd/ns1/example1.db new file mode 100644 index 0000000000..daf4989903 --- /dev/null +++ b/bin/tests/system/lwresd/ns1/example1.db @@ -0,0 +1,15 @@ +$TTL 300 ; 5 minutes +@ IN SOA mname1. . ( + 2000062001 ; serial + 20 ; refresh (20 seconds) + 20 ; retry (20 seconds) + 1814400 ; expire (3 weeks) + 3600 ; minimum (1 hour) + ) + NS ns +ns A 10.53.0.1 + +a A 10.0.1.1 +b A6 64 ::ffff:ffff:ffff:ffff c +c A6 0 eeee:eeee:eeee:eeee:: +d A6 64 ::ffff:ffff:ffff:ffff e diff --git a/bin/tests/system/lwresd/ns1/example2.db b/bin/tests/system/lwresd/ns1/example2.db new file mode 100644 index 0000000000..6eb92e69d3 --- /dev/null +++ b/bin/tests/system/lwresd/ns1/example2.db @@ -0,0 +1,14 @@ +$TTL 300 ; 5 minutes +@ IN SOA mname1. . ( + 2000062001 ; serial + 20 ; refresh (20 seconds) + 20 ; retry (20 seconds) + 1814400 ; expire (3 weeks) + 3600 ; minimum (1 hour) + ) + NS ns +ns A 10.53.0.1 + +a A 10.0.2.1 +b A6 64 ::ffff:ffff:ffff:ffff c +c A6 0 eeee:eeee:eeee:eeee:: diff --git a/bin/tests/system/lwresd/ns1/ip6.int.db b/bin/tests/system/lwresd/ns1/ip6.int.db new file mode 100644 index 0000000000..dee844874b --- /dev/null +++ b/bin/tests/system/lwresd/ns1/ip6.int.db @@ -0,0 +1,12 @@ +$TTL 300 ; 5 minutes +@ IN SOA mname1. . ( + 2000062001 ; serial + 20 ; refresh (20 seconds) + 20 ; retry (20 seconds) + 1814400 ; expire (3 weeks) + 3600 ; minimum (1 hour) + ) + NS ns +ns A 10.53.0.1 + +f.e.d.c.b.a.9.8.7.6.5.4.3.2.1.0.f.e.d.c.b.a.9.8.7.6.5.4.3.2.1.0 PTR test.example. diff --git a/bin/tests/system/lwresd/ns1/named.conf b/bin/tests/system/lwresd/ns1/named.conf new file mode 100644 index 0000000000..ecf0218fd8 --- /dev/null +++ b/bin/tests/system/lwresd/ns1/named.conf @@ -0,0 +1,35 @@ +options { + query-source address 10.53.0.1; + port 5300; + directory "."; + pid-file "named.pid"; + listen-on { 10.53.0.1; }; + listen-on-v6 {none;}; + recursion no; + notify no; +}; + +zone "." { + type master; + file "root.db"; +}; + +zone "example1." { + type master; + file "example1.db"; +}; + +zone "example2." { + type master; + file "example2.db"; +}; + +zone "10.10.10.in-addr.arpa." { + type master; + file "10.10.10.in-addr.arpa.db"; +}; + +zone "ip6.int." { + type master; + file "ip6.int.db"; +}; diff --git a/bin/tests/system/lwresd/ns1/root.db b/bin/tests/system/lwresd/ns1/root.db new file mode 100644 index 0000000000..37023674cc --- /dev/null +++ b/bin/tests/system/lwresd/ns1/root.db @@ -0,0 +1,16 @@ +$TTL 300 +. IN SOA gson.nominum.com. a.root.servers.nil. ( + 2000042100 ; serial + 600 ; refresh + 600 ; retry + 1200 ; expire + 600 ; minimum + ) +. NS a.root-servers.nil. +a.root-servers.nil. A 10.53.0.1 + +example1. NS ns.example1. +ns.example1. A 10.53.0.2 +example2. NS ns.example2. +ns.example2. A 10.53.0.2 +x A 10.1.10.1 diff --git a/bin/tests/system/lwresd/resolv.conf b/bin/tests/system/lwresd/resolv.conf new file mode 100644 index 0000000000..3b1f74b3de --- /dev/null +++ b/bin/tests/system/lwresd/resolv.conf @@ -0,0 +1,3 @@ +nameserver 10.53.0.1 +search example1. +ndots 1 diff --git a/bin/tests/system/lwresd/tests.sh b/bin/tests/system/lwresd/tests.sh new file mode 100644 index 0000000000..a308b9434b --- /dev/null +++ b/bin/tests/system/lwresd/tests.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# +# Copyright (C) 2000 Internet Software Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS +# ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE +# CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR +# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +# SOFTWARE. + +SYSTEMTESTTOP=.. +. $SYSTEMTESTTOP/conf.sh + +# +# Perform tests +# + +sleep 5 + +status=0; +./lwtest +status=`expr $status + $?` + + +if [ $status != 0 ]; then + echo "R:FAIL" +else + echo "R:PASS" +fi