diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:59:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:59:48 +0000 |
commit | 3b9b6d0b8e7f798023c9d109c490449d528fde80 (patch) | |
tree | 2e1c188dd7b8d7475cd163de9ae02c428343669b /bin/tests/system/pipelined | |
parent | Initial commit. (diff) | |
download | bind9-0cd617f6bad00b68e380aeb0024ef4dc1985191c.tar.xz bind9-0cd617f6bad00b68e380aeb0024ef4dc1985191c.zip |
Adding upstream version 1:9.18.19.upstream/1%9.18.19upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'bin/tests/system/pipelined')
-rw-r--r-- | bin/tests/system/pipelined/ans5/ans.py | 212 | ||||
-rw-r--r-- | bin/tests/system/pipelined/clean.sh | 19 | ||||
-rw-r--r-- | bin/tests/system/pipelined/input | 8 | ||||
-rw-r--r-- | bin/tests/system/pipelined/inputb | 8 | ||||
-rw-r--r-- | bin/tests/system/pipelined/ns1/named.conf.in | 39 | ||||
-rw-r--r-- | bin/tests/system/pipelined/ns1/root.db | 27 | ||||
-rw-r--r-- | bin/tests/system/pipelined/ns2/examplea.db | 32 | ||||
-rw-r--r-- | bin/tests/system/pipelined/ns2/named.conf.in | 45 | ||||
-rw-r--r-- | bin/tests/system/pipelined/ns3/exampleb.db | 32 | ||||
-rw-r--r-- | bin/tests/system/pipelined/ns3/named.conf.in | 45 | ||||
-rw-r--r-- | bin/tests/system/pipelined/ns4/named.conf.in | 41 | ||||
-rw-r--r-- | bin/tests/system/pipelined/pipequeries.c | 303 | ||||
-rw-r--r-- | bin/tests/system/pipelined/ref | 8 | ||||
-rw-r--r-- | bin/tests/system/pipelined/refb | 8 | ||||
-rw-r--r-- | bin/tests/system/pipelined/setup.sh | 21 | ||||
-rw-r--r-- | bin/tests/system/pipelined/tests.sh | 82 | ||||
-rw-r--r-- | bin/tests/system/pipelined/tests_sh_pipelined.py | 14 |
17 files changed, 944 insertions, 0 deletions
diff --git a/bin/tests/system/pipelined/ans5/ans.py b/bin/tests/system/pipelined/ans5/ans.py new file mode 100644 index 0000000..bac5ed3 --- /dev/null +++ b/bin/tests/system/pipelined/ans5/ans.py @@ -0,0 +1,212 @@ +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +############################################################################ +# +# This tool acts as a TCP/UDP proxy and delays all incoming packets by 500 +# milliseconds. +# +# We use it to check pipelining - a client sents 8 questions over a +# pipelined connection - that require asking a normal (examplea) and a +# slow-responding (exampleb) servers: +# a.examplea +# a.exampleb +# b.examplea +# b.exampleb +# c.examplea +# c.exampleb +# d.examplea +# d.exampleb +# +# If pipelining works properly the answers will be returned out of order +# with all answers from examplea returned first, and then all answers +# from exampleb. +# +############################################################################ + +from __future__ import print_function + +import datetime +import os +import select +import signal +import socket +import sys +import time +import threading +import struct + +DELAY = 0.5 +THREADS = [] + + +def log(msg): + print(datetime.datetime.now().strftime("%d-%b-%Y %H:%M:%S.%f ") + msg) + + +def sigterm(*_): + log("SIGTERM received, shutting down") + for thread in THREADS: + thread.close() + thread.join() + os.remove("ans.pid") + sys.exit(0) + + +class TCPDelayer(threading.Thread): + """For a given TCP connection conn we open a connection to (ip, port), + and then we delay each incoming packet by DELAY by putting it in a + queue. + In the pipelined test TCP should not be used, but it's here for + completnes. + """ + + def __init__(self, conn, ip, port): + threading.Thread.__init__(self) + self.conn = conn + self.cconn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.cconn.connect((ip, port)) + self.queue = [] + self.running = True + + def close(self): + self.running = False + + def run(self): + while self.running: + curr_timeout = 0.5 + try: + curr_timeout = self.queue[0][0] - time.time() + except StopIteration: + pass + if curr_timeout > 0: + if curr_timeout == 0: + curr_timeout = 0.5 + rfds, _, _ = select.select( + [self.conn, self.cconn], [], [], curr_timeout + ) + if self.conn in rfds: + data = self.conn.recv(65535) + if not data: + return + self.queue.append((time.time() + DELAY, data)) + if self.cconn in rfds: + data = self.cconn.recv(65535) + if not data == 0: + return + self.conn.send(data) + try: + while self.queue[0][0] - time.time() < 0: + _, data = self.queue.pop(0) + self.cconn.send(data) + except StopIteration: + pass + + +class UDPDelayer(threading.Thread): + """Every incoming UDP packet is put in a queue for DELAY time, then + it's sent to (ip, port). We remember the query id to send the + response we get to a proper source, responses are not delayed. + """ + + def __init__(self, usock, ip, port): + threading.Thread.__init__(self) + self.sock = usock + self.csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.dst = (ip, port) + self.queue = [] + self.qid_mapping = {} + self.running = True + + def close(self): + self.running = False + + def run(self): + while self.running: + curr_timeout = 0.5 + if self.queue: + curr_timeout = self.queue[0][0] - time.time() + if curr_timeout >= 0: + if curr_timeout == 0: + curr_timeout = 0.5 + rfds, _, _ = select.select( + [self.sock, self.csock], [], [], curr_timeout + ) + if self.sock in rfds: + data, addr = self.sock.recvfrom(65535) + if not data: + return + self.queue.append((time.time() + DELAY, data)) + qid = struct.unpack(">H", data[:2])[0] + log("Received a query from %s, queryid %d" % (str(addr), qid)) + self.qid_mapping[qid] = addr + if self.csock in rfds: + data, addr = self.csock.recvfrom(65535) + if not data: + return + qid = struct.unpack(">H", data[:2])[0] + dst = self.qid_mapping.get(qid) + if dst is not None: + self.sock.sendto(data, dst) + log( + "Received a response from %s, queryid %d, sending to %s" + % (str(addr), qid, str(dst)) + ) + while self.queue and self.queue[0][0] - time.time() < 0: + _, data = self.queue.pop(0) + qid = struct.unpack(">H", data[:2])[0] + log("Sending a query to %s, queryid %d" % (str(self.dst), qid)) + self.csock.sendto(data, self.dst) + + +def main(): + signal.signal(signal.SIGTERM, sigterm) + signal.signal(signal.SIGINT, sigterm) + + with open("ans.pid", "w") as pidfile: + print(os.getpid(), file=pidfile) + + listenip = "10.53.0.5" + serverip = "10.53.0.2" + + try: + port = int(os.environ["PORT"]) + except KeyError: + port = 5300 + + log("Listening on %s:%d" % (listenip, port)) + + usock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + usock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + usock.bind((listenip, port)) + thread = UDPDelayer(usock, serverip, port) + thread.start() + THREADS.append(thread) + + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind((listenip, port)) + sock.listen(1) + sock.settimeout(1) + + while True: + try: + (clientsock, _) = sock.accept() + log("Accepted connection from %s" % clientsock) + thread = TCPDelayer(clientsock, serverip, port) + thread.start() + THREADS.append(thread) + except socket.timeout: + pass + + +if __name__ == "__main__": + main() diff --git a/bin/tests/system/pipelined/clean.sh b/bin/tests/system/pipelined/clean.sh new file mode 100644 index 0000000..12c1733 --- /dev/null +++ b/bin/tests/system/pipelined/clean.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +rm -f */named.conf +rm -f */named.memstats +rm -f */named.run +rm -f raw* output* +rm -f ns*/named.lock +rm -f ns*/managed-keys.bind* diff --git a/bin/tests/system/pipelined/input b/bin/tests/system/pipelined/input new file mode 100644 index 0000000..485cf81 --- /dev/null +++ b/bin/tests/system/pipelined/input @@ -0,0 +1,8 @@ +a.examplea +a.exampleb +b.examplea +b.exampleb +c.examplea +c.exampleb +d.examplea +d.exampleb diff --git a/bin/tests/system/pipelined/inputb b/bin/tests/system/pipelined/inputb new file mode 100644 index 0000000..6ea367e --- /dev/null +++ b/bin/tests/system/pipelined/inputb @@ -0,0 +1,8 @@ +e.examplea +e.exampleb +f.examplea +f.exampleb +g.examplea +g.exampleb +h.examplea +h.exampleb diff --git a/bin/tests/system/pipelined/ns1/named.conf.in b/bin/tests/system/pipelined/ns1/named.conf.in new file mode 100644 index 0000000..6cfac77 --- /dev/null +++ b/bin/tests/system/pipelined/ns1/named.conf.in @@ -0,0 +1,39 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + query-source address 10.53.0.1; + notify-source 10.53.0.1; + transfer-source 10.53.0.1; + port @PORT@; + pid-file "named.pid"; + listen-on { 10.53.0.1; }; + listen-on-v6 { none; }; + recursion no; + dnssec-validation no; + notify yes; +}; + +key rndc_key { + secret "1234abcd8765"; + algorithm @DEFAULT_HMAC@; +}; + +controls { + inet 10.53.0.1 port @CONTROLPORT@ allow { any; } keys { rndc_key; }; +}; + +zone "." { + type primary; + file "root.db"; +}; diff --git a/bin/tests/system/pipelined/ns1/root.db b/bin/tests/system/pipelined/ns1/root.db new file mode 100644 index 0000000..f2819a1 --- /dev/null +++ b/bin/tests/system/pipelined/ns1/root.db @@ -0,0 +1,27 @@ +; Copyright (C) Internet Systems Consortium, Inc. ("ISC") +; +; SPDX-License-Identifier: MPL-2.0 +; +; This Source Code Form is subject to the terms of the Mozilla Public +; License, v. 2.0. If a copy of the MPL was not distributed with this +; file, you can obtain one at https://mozilla.org/MPL/2.0/. +; +; See the COPYRIGHT file distributed with this work for additional +; information regarding copyright ownership. + +$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 + +examplea. NS ns2.examplea. +ns2.examplea. A 10.53.0.5 + +exampleb. NS ns3.exampleb. +ns3.exampleb. A 10.53.0.3 diff --git a/bin/tests/system/pipelined/ns2/examplea.db b/bin/tests/system/pipelined/ns2/examplea.db new file mode 100644 index 0000000..1be2d11 --- /dev/null +++ b/bin/tests/system/pipelined/ns2/examplea.db @@ -0,0 +1,32 @@ +; Copyright (C) Internet Systems Consortium, Inc. ("ISC") +; +; SPDX-License-Identifier: MPL-2.0 +; +; This Source Code Form is subject to the terms of the Mozilla Public +; License, v. 2.0. If a copy of the MPL was not distributed with this +; file, you can obtain one at https://mozilla.org/MPL/2.0/. +; +; See the COPYRIGHT file distributed with this work for additional +; information regarding copyright ownership. + +$ORIGIN . +$TTL 300 ; 5 minutes +examplea IN SOA mname1. . ( + 1 ; serial + 20 ; refresh (20 seconds) + 20 ; retry (20 seconds) + 1814400 ; expire (3 weeks) + 3600 ; minimum (1 hour) + ) +examplea. NS ns2.examplea. +ns2.examplea. A 10.53.0.5 + +$ORIGIN examplea. +a A 10.0.1.1 +b A 10.0.1.2 +c A 10.0.1.3 +d A 10.0.1.4 +e A 10.0.1.5 +f A 10.0.1.6 +g A 10.0.1.7 +h A 10.0.1.8 diff --git a/bin/tests/system/pipelined/ns2/named.conf.in b/bin/tests/system/pipelined/ns2/named.conf.in new file mode 100644 index 0000000..3679e97 --- /dev/null +++ b/bin/tests/system/pipelined/ns2/named.conf.in @@ -0,0 +1,45 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + query-source address 10.53.0.2; + notify-source 10.53.0.2; + transfer-source 10.53.0.2; + port @PORT@; + pid-file "named.pid"; + listen-on { 10.53.0.2; }; + listen-on-v6 { none; }; + recursion yes; + dnssec-validation yes; + notify yes; +}; + +key rndc_key { + secret "1234abcd8765"; + algorithm @DEFAULT_HMAC@; +}; + +controls { + inet 10.53.0.2 port @CONTROLPORT@ allow { any; } keys { rndc_key; }; +}; + +zone "." { + type hint; + file "../../common/root.hint"; +}; + +zone "examplea" { + type primary; + file "examplea.db"; + allow-update { any; }; +}; diff --git a/bin/tests/system/pipelined/ns3/exampleb.db b/bin/tests/system/pipelined/ns3/exampleb.db new file mode 100644 index 0000000..91b94c3 --- /dev/null +++ b/bin/tests/system/pipelined/ns3/exampleb.db @@ -0,0 +1,32 @@ +; Copyright (C) Internet Systems Consortium, Inc. ("ISC") +; +; SPDX-License-Identifier: MPL-2.0 +; +; This Source Code Form is subject to the terms of the Mozilla Public +; License, v. 2.0. If a copy of the MPL was not distributed with this +; file, you can obtain one at https://mozilla.org/MPL/2.0/. +; +; See the COPYRIGHT file distributed with this work for additional +; information regarding copyright ownership. + +$ORIGIN . +$TTL 300 ; 5 minutes +exampleb IN SOA mname1. . ( + 1 ; serial + 20 ; refresh (20 seconds) + 20 ; retry (20 seconds) + 1814400 ; expire (3 weeks) + 3600 ; minimum (1 hour) + ) +exampleb. NS ns3.exampleb. +ns3.exampleb. A 10.53.0.3 + +$ORIGIN exampleb. +a A 10.0.2.1 +b A 10.0.2.2 +c A 10.0.2.3 +d A 10.0.2.4 +e A 10.0.2.5 +f A 10.0.2.6 +g A 10.0.2.7 +h A 10.0.2.8 diff --git a/bin/tests/system/pipelined/ns3/named.conf.in b/bin/tests/system/pipelined/ns3/named.conf.in new file mode 100644 index 0000000..d8943d5 --- /dev/null +++ b/bin/tests/system/pipelined/ns3/named.conf.in @@ -0,0 +1,45 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + query-source address 10.53.0.3; + notify-source 10.53.0.3; + transfer-source 10.53.0.3; + port @PORT@; + pid-file "named.pid"; + listen-on { 10.53.0.3; }; + listen-on-v6 { none; }; + recursion yes; + dnssec-validation yes; + notify yes; +}; + +key rndc_key { + secret "1234abcd8765"; + algorithm @DEFAULT_HMAC@; +}; + +controls { + inet 10.53.0.3 port @CONTROLPORT@ allow { any; } keys { rndc_key; }; +}; + +zone "." { + type hint; + file "../../common/root.hint"; +}; + +zone "exampleb" { + type primary; + file "exampleb.db"; + allow-update { any; }; +}; diff --git a/bin/tests/system/pipelined/ns4/named.conf.in b/bin/tests/system/pipelined/ns4/named.conf.in new file mode 100644 index 0000000..5d4be1c --- /dev/null +++ b/bin/tests/system/pipelined/ns4/named.conf.in @@ -0,0 +1,41 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +options { + query-source address 10.53.0.4; + notify-source 10.53.0.4; + transfer-source 10.53.0.4; + port @PORT@; + directory "."; + pid-file "named.pid"; + listen-on { 10.53.0.4; }; + listen-on-v6 { none; }; + keep-response-order { 10.53.0.7/32; }; + recursion yes; + dnssec-validation yes; + notify yes; +}; + +key rndc_key { + secret "1234abcd8765"; + algorithm @DEFAULT_HMAC@; +}; + +controls { + inet 10.53.0.4 port @CONTROLPORT@ allow { any; } keys { rndc_key; }; +}; + +zone "." { + type hint; + file "../../common/root.hint"; +}; diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c new file mode 100644 index 0000000..7419d22 --- /dev/null +++ b/bin/tests/system/pipelined/pipequeries.c @@ -0,0 +1,303 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#include <inttypes.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <isc/app.h> +#include <isc/base64.h> +#include <isc/commandline.h> +#include <isc/hash.h> +#include <isc/log.h> +#include <isc/managers.h> +#include <isc/mem.h> +#include <isc/net.h> +#include <isc/netmgr.h> +#include <isc/parseint.h> +#include <isc/print.h> +#include <isc/result.h> +#include <isc/sockaddr.h> +#include <isc/task.h> +#include <isc/util.h> + +#include <dns/dispatch.h> +#include <dns/events.h> +#include <dns/fixedname.h> +#include <dns/message.h> +#include <dns/name.h> +#include <dns/rdataset.h> +#include <dns/request.h> +#include <dns/resolver.h> +#include <dns/result.h> +#include <dns/types.h> +#include <dns/view.h> + +#define CHECK(str, x) \ + { \ + if ((x) != ISC_R_SUCCESS) { \ + fprintf(stderr, "I:%s: %s\n", (str), \ + isc_result_totext(x)); \ + exit(-1); \ + } \ + } + +#define RUNCHECK(x) RUNTIME_CHECK((x) == ISC_R_SUCCESS) + +#define PORT 5300 +#define TIMEOUT 30 + +static isc_mem_t *mctx = NULL; +static dns_requestmgr_t *requestmgr = NULL; +static bool have_src = false; +static isc_sockaddr_t srcaddr; +static isc_sockaddr_t dstaddr; +static int onfly; + +static void +recvresponse(isc_task_t *task, isc_event_t *event) { + dns_requestevent_t *reqev = (dns_requestevent_t *)event; + isc_result_t result; + dns_message_t *query = NULL; + dns_message_t *response = NULL; + isc_buffer_t outbuf; + char output[1024]; + + UNUSED(task); + + REQUIRE(reqev != NULL); + + if (reqev->result != ISC_R_SUCCESS) { + fprintf(stderr, "I:request event result: %s\n", + isc_result_totext(reqev->result)); + exit(-1); + } + + query = reqev->ev_arg; + + dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response); + + result = dns_request_getresponse(reqev->request, response, + DNS_MESSAGEPARSE_PRESERVEORDER); + CHECK("dns_request_getresponse", result); + + if (response->rcode != dns_rcode_noerror) { + result = dns_result_fromrcode(response->rcode); + fprintf(stderr, "I:response rcode: %s\n", + isc_result_totext(result)); + exit(-1); + } + if (response->counts[DNS_SECTION_ANSWER] != 1U) { + fprintf(stderr, "I:response answer count (%u!=1)\n", + response->counts[DNS_SECTION_ANSWER]); + } + + isc_buffer_init(&outbuf, output, sizeof(output)); + result = dns_message_sectiontotext( + response, DNS_SECTION_ANSWER, &dns_master_style_simple, + DNS_MESSAGETEXTFLAG_NOCOMMENTS, &outbuf); + CHECK("dns_message_sectiontotext", result); + printf("%.*s", (int)isc_buffer_usedlength(&outbuf), + (char *)isc_buffer_base(&outbuf)); + fflush(stdout); + + dns_message_detach(&query); + dns_message_detach(&response); + dns_request_destroy(&reqev->request); + isc_event_free(&event); + + if (--onfly == 0) { + isc_app_shutdown(); + } + return; +} + +static isc_result_t +sendquery(isc_task_t *task) { + dns_request_t *request = NULL; + dns_message_t *message = NULL; + dns_name_t *qname = NULL; + dns_rdataset_t *qrdataset = NULL; + isc_result_t result; + dns_fixedname_t queryname; + isc_buffer_t buf; + static char host[256]; + int c; + + c = scanf("%255s", host); + if (c == EOF) { + return (ISC_R_NOMORE); + } + + onfly++; + + dns_fixedname_init(&queryname); + isc_buffer_init(&buf, host, strlen(host)); + isc_buffer_add(&buf, strlen(host)); + result = dns_name_fromtext(dns_fixedname_name(&queryname), &buf, + dns_rootname, 0, NULL); + CHECK("dns_name_fromtext", result); + + dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message); + + message->opcode = dns_opcode_query; + message->flags |= DNS_MESSAGEFLAG_RD; + message->rdclass = dns_rdataclass_in; + message->id = (unsigned short)(random() & 0xFFFF); + + result = dns_message_gettempname(message, &qname); + CHECK("dns_message_gettempname", result); + + result = dns_message_gettemprdataset(message, &qrdataset); + CHECK("dns_message_gettemprdataset", result); + + dns_name_clone(dns_fixedname_name(&queryname), qname); + dns_rdataset_makequestion(qrdataset, dns_rdataclass_in, + dns_rdatatype_a); + ISC_LIST_APPEND(qname->list, qrdataset, link); + dns_message_addname(message, qname, DNS_SECTION_QUESTION); + + result = dns_request_create(requestmgr, message, + have_src ? &srcaddr : NULL, &dstaddr, + DNS_REQUESTOPT_TCP, NULL, TIMEOUT, 0, 0, + task, recvresponse, message, &request); + CHECK("dns_request_create", result); + + return (ISC_R_SUCCESS); +} + +static void +sendqueries(isc_task_t *task, isc_event_t *event) { + isc_result_t result; + + isc_event_free(&event); + + do { + result = sendquery(task); + } while (result == ISC_R_SUCCESS); + + if (onfly == 0) { + isc_app_shutdown(); + } + return; +} + +int +main(int argc, char *argv[]) { + isc_sockaddr_t bind_any; + struct in_addr inaddr; + isc_result_t result; + isc_log_t *lctx = NULL; + isc_logconfig_t *lcfg = NULL; + isc_nm_t *netmgr = NULL; + isc_taskmgr_t *taskmgr = NULL; + isc_task_t *task = NULL; + dns_dispatchmgr_t *dispatchmgr = NULL; + dns_dispatch_t *dispatchv4 = NULL; + dns_view_t *view = NULL; + uint16_t port = PORT; + int c; + + RUNCHECK(isc_app_start()); + + isc_commandline_errprint = false; + while ((c = isc_commandline_parse(argc, argv, "p:r:")) != -1) { + switch (c) { + case 'p': + result = isc_parse_uint16(&port, + isc_commandline_argument, 10); + if (result != ISC_R_SUCCESS) { + fprintf(stderr, "bad port '%s'\n", + isc_commandline_argument); + exit(1); + } + break; + case 'r': + fprintf(stderr, "The -r option has been deprecated.\n"); + break; + case '?': + fprintf(stderr, "%s: invalid argument '%c'", argv[0], + c); + break; + default: + break; + } + } + + argc -= isc_commandline_index; + argv += isc_commandline_index; + POST(argv); + + if (argc > 0) { + have_src = true; + } + + isc_sockaddr_any(&bind_any); + + result = ISC_R_FAILURE; + if (inet_pton(AF_INET, "10.53.0.7", &inaddr) != 1) { + CHECK("inet_pton", result); + } + isc_sockaddr_fromin(&srcaddr, &inaddr, 0); + + result = ISC_R_FAILURE; + if (inet_pton(AF_INET, "10.53.0.4", &inaddr) != 1) { + CHECK("inet_pton", result); + } + isc_sockaddr_fromin(&dstaddr, &inaddr, port); + + isc_mem_create(&mctx); + + isc_log_create(mctx, &lctx, &lcfg); + + RUNCHECK(dst_lib_init(mctx, NULL)); + + isc_managers_create(mctx, 1, 0, &netmgr, &taskmgr, NULL); + RUNCHECK(isc_task_create(taskmgr, 0, &task)); + RUNCHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr)); + + RUNCHECK(dns_dispatch_createudp( + dispatchmgr, have_src ? &srcaddr : &bind_any, &dispatchv4)); + RUNCHECK(dns_requestmgr_create(mctx, taskmgr, dispatchmgr, dispatchv4, + NULL, &requestmgr)); + + RUNCHECK(dns_view_create(mctx, 0, "_test", &view)); + RUNCHECK(isc_app_onrun(mctx, task, sendqueries, NULL)); + + (void)isc_app_run(); + + dns_view_detach(&view); + + dns_requestmgr_shutdown(requestmgr); + dns_requestmgr_detach(&requestmgr); + + dns_dispatch_detach(&dispatchv4); + dns_dispatchmgr_detach(&dispatchmgr); + + isc_task_shutdown(task); + isc_task_detach(&task); + + isc_managers_destroy(&netmgr, &taskmgr, NULL); + + dst_lib_destroy(); + + isc_log_destroy(&lctx); + + isc_mem_destroy(&mctx); + + isc_app_finish(); + + return (0); +} diff --git a/bin/tests/system/pipelined/ref b/bin/tests/system/pipelined/ref new file mode 100644 index 0000000..fe123f6 --- /dev/null +++ b/bin/tests/system/pipelined/ref @@ -0,0 +1,8 @@ +a.examplea. 10.0.1.1 +a.exampleb. 10.0.2.1 +b.examplea. 10.0.1.2 +b.exampleb. 10.0.2.2 +c.examplea. 10.0.1.3 +c.exampleb. 10.0.2.3 +d.examplea. 10.0.1.4 +d.exampleb. 10.0.2.4 diff --git a/bin/tests/system/pipelined/refb b/bin/tests/system/pipelined/refb new file mode 100644 index 0000000..a24c6bc --- /dev/null +++ b/bin/tests/system/pipelined/refb @@ -0,0 +1,8 @@ +e.examplea. 10.0.1.5 +e.exampleb. 10.0.2.5 +f.examplea. 10.0.1.6 +f.exampleb. 10.0.2.6 +g.examplea. 10.0.1.7 +g.exampleb. 10.0.2.7 +h.examplea. 10.0.1.8 +h.exampleb. 10.0.2.8 diff --git a/bin/tests/system/pipelined/setup.sh b/bin/tests/system/pipelined/setup.sh new file mode 100644 index 0000000..49a6426 --- /dev/null +++ b/bin/tests/system/pipelined/setup.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +. ../conf.sh + +$SHELL clean.sh + +copy_setports ns1/named.conf.in ns1/named.conf +copy_setports ns2/named.conf.in ns2/named.conf +copy_setports ns3/named.conf.in ns3/named.conf +copy_setports ns4/named.conf.in ns4/named.conf diff --git a/bin/tests/system/pipelined/tests.sh b/bin/tests/system/pipelined/tests.sh new file mode 100644 index 0000000..26c0d31 --- /dev/null +++ b/bin/tests/system/pipelined/tests.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +set -e + +. ../conf.sh + +MDIGOPTS="-p ${PORT}" +RNDCCMD="$RNDC -c ../common/rndc.conf -p ${CONTROLPORT} -s" + +status=0 + +echo_i "check pipelined TCP queries" +ret=0 +$PIPEQUERIES -p ${PORT} < input > raw || ret=1 +awk '{ print $1 " " $5 }' < raw > output +sort < output > output-sorted +diff ref output-sorted || { ret=1 ; echo_i "diff sorted failed"; } +diff ref output > /dev/null && { ret=1 ; echo_i "diff out of order failed"; } +if [ $ret != 0 ]; then echo_i "failed"; fi +status=$((status + ret)) + +echo_i "check pipelined TCP queries using mdig" +ret=0 +$RNDCCMD 10.53.0.4 flush +sleep 1 +$MDIG $MDIGOPTS +noall +answer +vc -f input -b 10.53.0.4 @10.53.0.4 > raw.mdig +awk '{ print $1 " " $5 }' < raw.mdig > output.mdig +sort < output.mdig > output-sorted.mdig +diff ref output-sorted.mdig || { ret=1 ; echo_i "diff sorted failed"; } +diff ref output.mdig > /dev/null && { ret=1 ; echo_i "diff out of order failed"; } +if [ $ret != 0 ]; then echo_i "failed"; fi +status=$((status + ret)) + +echo_i "check keep-response-order" +ret=0 +$RNDCCMD 10.53.0.4 flush +sleep 1 +$PIPEQUERIES -p ${PORT} ++ < inputb > rawb || ret=1 +awk '{ print $1 " " $5 }' < rawb > outputb +diff refb outputb || ret=1 +if [ $ret != 0 ]; then echo_i "failed"; fi +status=$((status + ret)) + +echo_i "check keep-response-order using mdig" +ret=0 +$RNDCCMD 10.53.0.4 flush +sleep 1 +$MDIG $MDIGOPTS +noall +answer +vc -f inputb -b 10.53.0.7 @10.53.0.4 > rawb.mdig +awk '{ print $1 " " $5 }' < rawb.mdig > outputb.mdig +diff refb outputb.mdig || ret=1 +if [ $ret != 0 ]; then echo_i "failed"; fi +status=$((status + ret)) + +echo_i "check mdig -4 -6" +ret=0 +$RNDCCMD 10.53.0.4 flush +sleep 1 +$MDIG $MDIGOPTS -4 -6 -f input @10.53.0.4 > output46.mdig 2>&1 && ret=1 +grep "only one of -4 and -6 allowed" output46.mdig > /dev/null || ret=1 +if [ $ret != 0 ]; then echo_i "failed"; fi +status=$((status + ret)) + +echo_i "check mdig -4 with an IPv6 server address" +ret=0 +$MDIG $MDIGOPTS -4 -f input @fd92:7065:b8e:ffff::2 > output4.mdig 2>&1 && ret=1 +grep "address family not supported" output4.mdig > /dev/null || ret=1 +if [ $ret != 0 ]; then echo_i "failed"; fi +status=$((status + ret)) + +echo_i "exit status: $status" +[ $status -eq 0 ] || exit 1 diff --git a/bin/tests/system/pipelined/tests_sh_pipelined.py b/bin/tests/system/pipelined/tests_sh_pipelined.py new file mode 100644 index 0000000..2d7fb92 --- /dev/null +++ b/bin/tests/system/pipelined/tests_sh_pipelined.py @@ -0,0 +1,14 @@ +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# SPDX-License-Identifier: MPL-2.0 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, you can obtain one at https://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + + +def test_pipelined(run_tests_sh): + run_tests_sh() |