Blame SOURCES/bind-9.11-rt37821.patch

272df6
From 4d55e959839e1bc8e43124648742056ac2c802e7 Mon Sep 17 00:00:00 2001
272df6
From: Evan Hunt <each@isc.org>
272df6
Date: Tue, 20 Jan 2015 16:10:30 -0800
272df6
Subject: [PATCH] add TCP pipelining support
272df6
272df6
4040.	[func]		Added server-side support for pipelined TCP
272df6
			queries. TCP connections are no longer closed after
272df6
			the first query received from a client. (The new
272df6
			"keep-response-order" option allows clients to be
272df6
			specified for which the old behavior will still be
272df6
			used.) [RT #37821]
272df6
272df6
(cherry picked from commit 761d135ed686601f36fe3d0d4aaa6bf41287bb0f)
272df6
272df6
Modified default value of keep-response-order ACL to any, for best backward
272df6
compatibility. Upstream default is none;
272df6
---
272df6
 bin/named/client.c                            | 123 ++++++-
272df6
 bin/named/config.c                            |   3 +-
272df6
 bin/named/include/named/client.h              |   1 +
272df6
 bin/named/include/named/server.h              |   1 +
272df6
 bin/named/named.conf.docbook                  |   1 +
272df6
 bin/named/server.c                            |   8 +
272df6
 bin/tests/named.conf                          |   3 +-
272df6
 bin/tests/system/Makefile.in                  |   4 +-
272df6
 .../checkconf/bad-keep-response-order.conf    |  21 ++
272df6
 bin/tests/system/checkconf/bad-many.conf      |   3 +-
272df6
 bin/tests/system/checkconf/good.conf          |   3 +
272df6
 bin/tests/system/conf.sh.in                   |   2 +-
272df6
 bin/tests/system/pipelined/Makefile.in        |  51 +++
272df6
 bin/tests/system/pipelined/clean.sh           |  19 +
272df6
 bin/tests/system/pipelined/input              |   8 +
272df6
 bin/tests/system/pipelined/inputb             |   8 +
272df6
 bin/tests/system/pipelined/ns1/named.conf     |  43 +++
272df6
 bin/tests/system/pipelined/ns1/root.db        |  30 ++
272df6
 bin/tests/system/pipelined/ns2/examplea.db    |  35 ++
272df6
 bin/tests/system/pipelined/ns2/named.conf     |  49 +++
272df6
 bin/tests/system/pipelined/ns3/exampleb.db    |  35 ++
272df6
 bin/tests/system/pipelined/ns3/named.args     |   1 +
272df6
 bin/tests/system/pipelined/ns3/named.conf     |  49 +++
272df6
 bin/tests/system/pipelined/ns4/named.conf     |  45 +++
272df6
 bin/tests/system/pipelined/pipequeries.c      | 346 ++++++++++++++++++
272df6
 bin/tests/system/pipelined/ref                |   8 +
272df6
 bin/tests/system/pipelined/refb               |   8 +
272df6
 bin/tests/system/pipelined/setup.sh           |  22 ++
272df6
 bin/tests/system/pipelined/tests.sh           |  41 +++
272df6
 configure                                     |   1 +
272df6
 configure.in                                  |   1 +
272df6
 doc/arm/Bv9ARM-book.xml                       |  19 +-
272df6
 doc/misc/options                              |   1 +
272df6
 lib/bind9/check.c                             |   4 +-
272df6
 lib/dns/dispatch.c                            |  22 +-
272df6
 lib/isccfg/namedconf.c                        |   1 +
272df6
 36 files changed, 985 insertions(+), 35 deletions(-)
272df6
 create mode 100644 bin/tests/system/checkconf/bad-keep-response-order.conf
272df6
 create mode 100644 bin/tests/system/pipelined/Makefile.in
272df6
 create mode 100644 bin/tests/system/pipelined/clean.sh
272df6
 create mode 100644 bin/tests/system/pipelined/input
272df6
 create mode 100644 bin/tests/system/pipelined/inputb
272df6
 create mode 100644 bin/tests/system/pipelined/ns1/named.conf
272df6
 create mode 100644 bin/tests/system/pipelined/ns1/root.db
272df6
 create mode 100644 bin/tests/system/pipelined/ns2/examplea.db
272df6
 create mode 100644 bin/tests/system/pipelined/ns2/named.conf
272df6
 create mode 100644 bin/tests/system/pipelined/ns3/exampleb.db
272df6
 create mode 100644 bin/tests/system/pipelined/ns3/named.args
272df6
 create mode 100644 bin/tests/system/pipelined/ns3/named.conf
272df6
 create mode 100644 bin/tests/system/pipelined/ns4/named.conf
272df6
 create mode 100644 bin/tests/system/pipelined/pipequeries.c
272df6
 create mode 100644 bin/tests/system/pipelined/ref
272df6
 create mode 100644 bin/tests/system/pipelined/refb
272df6
 create mode 100644 bin/tests/system/pipelined/setup.sh
272df6
 create mode 100644 bin/tests/system/pipelined/tests.sh
272df6
272df6
diff --git a/bin/named/client.c b/bin/named/client.c
272df6
index 9adf36b..f014b61 100644
272df6
--- a/bin/named/client.c
272df6
+++ b/bin/named/client.c
272df6
@@ -233,6 +233,8 @@ static void client_request(isc_task_t *task, isc_event_t *event);
272df6
 static void ns_client_dumpmessage(ns_client_t *client, const char *reason);
272df6
 static isc_result_t get_client(ns_clientmgr_t *manager, ns_interface_t *ifp,
272df6
 			       dns_dispatch_t *disp, isc_boolean_t tcp);
272df6
+static isc_result_t get_worker(ns_clientmgr_t *manager, ns_interface_t *ifp,
272df6
+			       isc_socket_t *socket);
272df6
 
272df6
 void
272df6
 ns_client_recursing(ns_client_t *client) {
272df6
@@ -367,9 +369,13 @@ exit_check(ns_client_t *client) {
272df6
 		INSIST(client->recursionquota == NULL);
272df6
 
272df6
 		if (NS_CLIENTSTATE_READING == client->newstate) {
272df6
-			client_read(client);
272df6
-			client->newstate = NS_CLIENTSTATE_MAX;
272df6
-			return (ISC_TRUE); /* We're done. */
272df6
+			if (!client->pipelined) {
272df6
+				client_read(client);
272df6
+				client->newstate = NS_CLIENTSTATE_MAX;
272df6
+				return (ISC_TRUE); /* We're done. */
272df6
+			} else if (client->mortal) {
272df6
+				client->newstate = NS_CLIENTSTATE_INACTIVE;
272df6
+			}
272df6
 		}
272df6
 	}
272df6
 
272df6
@@ -406,6 +412,8 @@ exit_check(ns_client_t *client) {
272df6
 			client->timerset = ISC_FALSE;
272df6
 		}
272df6
 
272df6
+		client->pipelined = ISC_FALSE;
272df6
+
272df6
 		client->peeraddr_valid = ISC_FALSE;
272df6
 
272df6
 		client->state = NS_CLIENTSTATE_READY;
272df6
@@ -605,7 +613,11 @@ client_start(isc_task_t *task, isc_event_t *event) {
272df6
 		return;
272df6
 
272df6
 	if (TCP_CLIENT(client)) {
272df6
-		client_accept(client);
272df6
+		if (client->pipelined) {
272df6
+			client_read(client);
272df6
+		} else {
272df6
+			client_accept(client);
272df6
+		}
272df6
 	} else {
272df6
 		client_udprecv(client);
272df6
 	}
272df6
@@ -1638,6 +1650,24 @@ client_request(isc_task_t *task, isc_event_t *event) {
272df6
 		goto cleanup;
272df6
 	}
272df6
 
272df6
+	/*
272df6
+	 * Pipeline TCP query processing.
272df6
+	 */
272df6
+	if (client->message->opcode != dns_opcode_query)
272df6
+		client->pipelined = ISC_FALSE;
272df6
+	if (TCP_CLIENT(client) && client->pipelined) {
272df6
+		result = isc_quota_reserve(&ns_g_server->tcpquota);
272df6
+		if (result == ISC_R_SUCCESS)
272df6
+			result = ns_client_replace(client);
272df6
+		if (result != ISC_R_SUCCESS) {
272df6
+			ns_client_log(client, NS_LOGCATEGORY_CLIENT,
272df6
+				      NS_LOGMODULE_CLIENT, ISC_LOG_WARNING,
272df6
+				      "no more TCP clients(read): %s",
272df6
+				      isc_result_totext(result));
272df6
+			client->pipelined = ISC_FALSE;
272df6
+		}
272df6
+	}
272df6
+
272df6
 	dns_opcodestats_increment(ns_g_server->opcodestats,
272df6
 				  client->message->opcode);
272df6
 	switch (client->message->opcode) {
272df6
@@ -2138,6 +2168,7 @@ client_create(ns_clientmgr_t *manager, ns_client_t **clientp) {
272df6
 	client->signer = NULL;
272df6
 	dns_name_init(&client->signername, NULL);
272df6
 	client->mortal = ISC_FALSE;
272df6
+	client->pipelined = ISC_FALSE;
272df6
 	client->tcpquota = NULL;
272df6
 	client->recursionquota = NULL;
272df6
 	client->interface = NULL;
272df6
@@ -2326,6 +2357,7 @@ client_newconn(isc_task_t *task, isc_event_t *event) {
272df6
 		 * telnetting to port 53 (once per CPU) will
272df6
 		 * deny service to legitimate TCP clients.
272df6
 		 */
272df6
+		client->pipelined = ISC_FALSE;
272df6
 		result = isc_quota_attach(&ns_g_server->tcpquota,
272df6
 					  &client->tcpquota);
272df6
 		if (result == ISC_R_SUCCESS)
272df6
@@ -2333,8 +2365,12 @@ client_newconn(isc_task_t *task, isc_event_t *event) {
272df6
 		if (result != ISC_R_SUCCESS) {
272df6
 			ns_client_log(client, NS_LOGCATEGORY_CLIENT,
272df6
 				      NS_LOGMODULE_CLIENT, ISC_LOG_WARNING,
272df6
-				      "no more TCP clients: %s",
272df6
+				      "no more TCP clients(accept): %s",
272df6
 				      isc_result_totext(result));
272df6
+		} else if (ns_g_server->keepresporder == NULL ||
272df6
+			   !allowed(&netaddr, NULL, NULL, 0, NULL,
272df6
+				    ns_g_server->keepresporder)) {
272df6
+			client->pipelined = ISC_TRUE;
272df6
 		}
272df6
 
272df6
 		client_read(client);
272df6
@@ -2432,14 +2468,21 @@ ns_client_shuttingdown(ns_client_t *client) {
272df6
 isc_result_t
272df6
 ns_client_replace(ns_client_t *client) {
272df6
 	isc_result_t result;
272df6
+	isc_boolean_t tcp;
272df6
 
272df6
 	CTRACE("replace");
272df6
 
272df6
 	REQUIRE(client != NULL);
272df6
 	REQUIRE(client->manager != NULL);
272df6
 
272df6
-	result = get_client(client->manager, client->interface,
272df6
-			    client->dispatch, TCP_CLIENT(client));
272df6
+	tcp = TCP_CLIENT(client);
272df6
+	if (tcp && client->pipelined) {
272df6
+		result = get_worker(client->manager, client->interface,
272df6
+				    client->tcpsocket);
272df6
+	} else {
272df6
+		result = get_client(client->manager, client->interface,
272df6
+				    client->dispatch, tcp);
272df6
+	}
272df6
 	if (result != ISC_R_SUCCESS)
272df6
 		return (result);
272df6
 
272df6
@@ -2644,6 +2687,72 @@ get_client(ns_clientmgr_t *manager, ns_interface_t *ifp,
272df6
 	return (ISC_R_SUCCESS);
272df6
 }
272df6
 
272df6
+static isc_result_t
272df6
+get_worker(ns_clientmgr_t *manager, ns_interface_t *ifp, isc_socket_t *socket)
272df6
+{
272df6
+	isc_result_t result = ISC_R_SUCCESS;
272df6
+	isc_event_t *ev;
272df6
+	ns_client_t *client;
272df6
+	MTRACE("get worker");
272df6
+
272df6
+	REQUIRE(manager != NULL);
272df6
+
272df6
+	if (manager->exiting)
272df6
+		return (ISC_R_SHUTTINGDOWN);
272df6
+
272df6
+	/*
272df6
+	 * Allocate a client.  First try to get a recycled one;
272df6
+	 * if that fails, make a new one.
272df6
+	 */
272df6
+	client = NULL;
272df6
+	if (!ns_g_clienttest)
272df6
+		ISC_QUEUE_POP(manager->inactive, ilink, client);
272df6
+
272df6
+	if (client != NULL)
272df6
+		MTRACE("recycle");
272df6
+	else {
272df6
+		MTRACE("create new");
272df6
+
272df6
+		LOCK(&manager->lock);
272df6
+		result = client_create(manager, &client);
272df6
+		UNLOCK(&manager->lock);
272df6
+		if (result != ISC_R_SUCCESS)
272df6
+			return (result);
272df6
+
272df6
+		LOCK(&manager->listlock);
272df6
+		ISC_LIST_APPEND(manager->clients, client, link);
272df6
+		UNLOCK(&manager->listlock);
272df6
+	}
272df6
+
272df6
+	client->manager = manager;
272df6
+	ns_interface_attach(ifp, &client->interface);
272df6
+	client->newstate = client->state = NS_CLIENTSTATE_WORKING;
272df6
+	INSIST(client->recursionquota == NULL);
272df6
+	client->tcpquota = &ns_g_server->tcpquota;
272df6
+
272df6
+	client->dscp = ifp->dscp;
272df6
+
272df6
+	client->attributes |= NS_CLIENTATTR_TCP;
272df6
+	client->pipelined = ISC_TRUE;
272df6
+
272df6
+	isc_socket_attach(ifp->tcpsocket, &client->tcplistener);
272df6
+	isc_socket_attach(socket, &client->tcpsocket);
272df6
+	isc_socket_setname(client->tcpsocket, "worker-tcp", NULL);
272df6
+	(void)isc_socket_getpeername(client->tcpsocket, &client->peeraddr);
272df6
+	client->peeraddr_valid = ISC_TRUE;
272df6
+
272df6
+	INSIST(client->tcpmsg_valid == ISC_FALSE);
272df6
+	dns_tcpmsg_init(client->mctx, client->tcpsocket, &client->tcpmsg);
272df6
+	client->tcpmsg_valid = ISC_TRUE;
272df6
+
272df6
+	INSIST(client->nctls == 0);
272df6
+	client->nctls++;
272df6
+	ev = &client->ctlevent;
272df6
+	isc_task_send(client->task, &ev;;
272df6
+
272df6
+	return (ISC_R_SUCCESS);
272df6
+}
272df6
+
272df6
 isc_result_t
272df6
 ns_clientmgr_createclients(ns_clientmgr_t *manager, unsigned int n,
272df6
 			   ns_interface_t *ifp, isc_boolean_t tcp)
272df6
diff --git a/bin/named/config.c b/bin/named/config.c
272df6
index 22d8a85..f0db926 100644
272df6
--- a/bin/named/config.c
272df6
+++ b/bin/named/config.c
272df6
@@ -72,6 +72,7 @@ options {\n\
272df6
 	heartbeat-interval 60;\n\
272df6
 	host-statistics no;\n\
272df6
 	interface-interval 60;\n\
272df6
+#	keep-response-order {any;};\n\
272df6
 	listen-on {any;};\n\
272df6
 	listen-on-v6 {none;};\n\
272df6
 	match-mapped-addresses no;\n\
272df6
@@ -101,7 +102,7 @@ options {\n\
272df6
 	server-id none;\n\
272df6
 	statistics-file \"named.stats\";\n\
272df6
 	statistics-interval 60;\n\
272df6
-	tcp-clients 100;\n\
272df6
+	tcp-clients 150;\n\
272df6
 	tcp-listen-queue 10;\n\
272df6
 #	tkey-dhkey <none>\n\
272df6
 #	tkey-gssapi-credential <none>\n\
272df6
diff --git a/bin/named/include/named/client.h b/bin/named/include/named/client.h
272df6
index 98e79df..bf4d201 100644
272df6
--- a/bin/named/include/named/client.h
272df6
+++ b/bin/named/include/named/client.h
272df6
@@ -133,6 +133,7 @@ struct ns_client {
272df6
 	dns_name_t		signername;   /*%< [T]SIG key name */
272df6
 	dns_name_t *		signer;	      /*%< NULL if not valid sig */
272df6
 	isc_boolean_t		mortal;	      /*%< Die after handling request */
272df6
+	isc_boolean_t		pipelined;   /*%< TCP queries not in sequence */
272df6
 	isc_quota_t		*tcpquota;
272df6
 	isc_quota_t		*recursionquota;
272df6
 	ns_interface_t		*interface;
272df6
diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h
272df6
index 0107b51..5f36177 100644
272df6
--- a/bin/named/include/named/server.h
272df6
+++ b/bin/named/include/named/server.h
272df6
@@ -53,6 +53,7 @@ struct ns_server {
272df6
 	isc_quota_t		tcpquota;
272df6
 	isc_quota_t		recursionquota;
272df6
 	dns_acl_t		*blackholeacl;
272df6
+	dns_acl_t		*keepresporder;
272df6
 	char *			statsfile;	/*%< Statistics file name */
272df6
 	char *			dumpfile;	/*%< Dump file name */
272df6
 	char *			secrootsfile;	/*%< Secroots file name */
272df6
diff --git a/bin/named/named.conf.docbook b/bin/named/named.conf.docbook
272df6
index a8cd31e..4d502ac 100644
272df6
--- a/bin/named/named.conf.docbook
272df6
+++ b/bin/named/named.conf.docbook
272df6
@@ -209,6 +209,7 @@ options {
272df6
 	host-statistics-max <replaceable>number</replaceable>; // not implemented
272df6
 	hostname ( <replaceable>quoted_string</replaceable> | none );
272df6
 	interface-interval <replaceable>integer</replaceable>;
272df6
+	keep-response-order { <replaceable>address_match_element</replaceable>; ... };
272df6
 	listen-on <optional> port <replaceable>integer</replaceable> </optional> { <replaceable>address_match_element</replaceable>; ... };
272df6
 	listen-on-v6 <optional> port <replaceable>integer</replaceable> </optional> { <replaceable>address_match_element</replaceable>; ... };
272df6
 	match-mapped-addresses <replaceable>boolean</replaceable>;
272df6
diff --git a/bin/named/server.c b/bin/named/server.c
272df6
index e8f19d3..e30bf16 100644
272df6
--- a/bin/named/server.c
272df6
+++ b/bin/named/server.c
272df6
@@ -5207,6 +5207,10 @@ load_configuration(const char *filename, ns_server_t *server,
272df6
 		dns_dispatchmgr_setblackhole(ns_g_dispatchmgr,
272df6
 					     server->blackholeacl);
272df6
 
272df6
+	CHECK(configure_view_acl(NULL, config, "keep-response-order", NULL,
272df6
+				 ns_g_aclconfctx, ns_g_mctx,
272df6
+				 &server->keepresporder));
272df6
+
272df6
 	obj = NULL;
272df6
 	result = ns_config_get(maps, "match-mapped-addresses", &obj);
272df6
 	INSIST(result == ISC_R_SUCCESS);
272df6
@@ -6208,6 +6212,9 @@ shutdown_server(isc_task_t *task, isc_event_t *event) {
272df6
 		dns_name_free(&ns_g_sessionkeyname, server->mctx);
272df6
 	}
272df6
 
272df6
+	if (server->keepresporder != NULL)
272df6
+		dns_acl_detach(&server->keepresporder);
272df6
+
272df6
 	if (server->blackholeacl != NULL)
272df6
 		dns_acl_detach(&server->blackholeacl);
272df6
 
272df6
@@ -6259,6 +6266,7 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
272df6
 	ISC_LIST_INIT(server->viewlist);
272df6
 	server->in_roothints = NULL;
272df6
 	server->blackholeacl = NULL;
272df6
+	server->keepresporder = NULL;
272df6
 
272df6
 	/* Must be first. */
272df6
 	CHECKFATAL(dst_lib_init2(ns_g_mctx, ns_g_entropy,
272df6
diff --git a/bin/tests/named.conf b/bin/tests/named.conf
272df6
index 722d262..5b40045 100644
272df6
--- a/bin/tests/named.conf
272df6
+++ b/bin/tests/named.conf
272df6
@@ -1,5 +1,5 @@
272df6
 /*
272df6
- * Copyright (C) 2004, 2007, 2011  Internet Systems Consortium, Inc. ("ISC")
272df6
+ * Copyright (C) 2004, 2007, 2011, 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
  * Copyright (C) 1999-2001  Internet Software Consortium.
272df6
  *
272df6
  * Permission to use, copy, modify, and/or distribute this software for any
272df6
@@ -116,6 +116,7 @@ options {
272df6
 	allow-transfer { any; };
272df6
 	allow-recursion { !any; };
272df6
 	blackhole { 45/24; };
272df6
+	keep-response-order { 46/24; };
272df6
 
272df6
 	listen-on {
272df6
 		10/24;
272df6
diff --git a/bin/tests/system/Makefile.in b/bin/tests/system/Makefile.in
272df6
index afee71b..e7eaef7 100644
272df6
--- a/bin/tests/system/Makefile.in
272df6
+++ b/bin/tests/system/Makefile.in
272df6
@@ -21,8 +21,8 @@ top_srcdir =	@top_srcdir@
272df6
 
272df6
 @BIND9_MAKE_INCLUDES@
272df6
 
272df6
-SUBDIRS =	dlzexternal dyndb filter-aaaa geoip lwresd rpz rrl \
272df6
-		rsabigexponent tkey tsiggss
272df6
+SUBDIRS =	dlzexternal dyndb filter-aaaa geoip lwresd pipelined \
272df6
+		rpz rrl rsabigexponent tkey tsiggss
272df6
 CINCLUDES =	${ISC_INCLUDES} ${DNS_INCLUDES}
272df6
 
272df6
 CDEFINES =	@USE_GSSAPI@
272df6
diff --git a/bin/tests/system/checkconf/bad-keep-response-order.conf b/bin/tests/system/checkconf/bad-keep-response-order.conf
272df6
new file mode 100644
272df6
index 0000000..24c1f6c
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/checkconf/bad-keep-response-order.conf
272df6
@@ -0,0 +1,21 @@
272df6
+/*
272df6
+ * Copyright (C) 2015  Internet Systems Consortium, Inc. ("ISC")
272df6
+ *
272df6
+ * Permission to use, copy, modify, and/or distribute this software for any
272df6
+ * purpose with or without fee is hereby granted, provided that the above
272df6
+ * copyright notice and this permission notice appear in all copies.
272df6
+ *
272df6
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+ * PERFORMANCE OF THIS SOFTWARE.
272df6
+ */
272df6
+
272df6
+options {
272df6
+	keep-response-order {
272df6
+		does_not_exist;
272df6
+	};
272df6
+};
272df6
diff --git a/bin/tests/system/checkconf/bad-many.conf b/bin/tests/system/checkconf/bad-many.conf
272df6
index cfc4d02..09add87 100644
272df6
--- a/bin/tests/system/checkconf/bad-many.conf
272df6
+++ b/bin/tests/system/checkconf/bad-many.conf
272df6
@@ -1,5 +1,5 @@
272df6
 /*
272df6
- * Copyright (C) 2005, 2012  Internet Systems Consortium, Inc. ("ISC")
272df6
+ * Copyright (C) 2005, 2012, 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
  *
272df6
  * Permission to use, copy, modify, and/or distribute this software for any
272df6
  * purpose with or without fee is hereby granted, provided that the above
272df6
@@ -33,6 +33,7 @@ options {
272df6
 	host-statistics-max 100;
272df6
 	hostname none;
272df6
 	interface-interval 30;
272df6
+	keep-response-order { 10.0.0.10/24; };
272df6
 	listen-on port 90 { any; };
272df6
 	listen-on port 100 { 127.0.0.1; };
272df6
 	listen-on-v6 port 53 { none; };
272df6
diff --git a/bin/tests/system/checkconf/good.conf b/bin/tests/system/checkconf/good.conf
272df6
index cf7c745..43b0638 100644
272df6
--- a/bin/tests/system/checkconf/good.conf
272df6
+++ b/bin/tests/system/checkconf/good.conf
272df6
@@ -44,6 +44,9 @@ options {
272df6
 	host-statistics-max 100;
272df6
 	hostname none;
272df6
 	interface-interval 30;
272df6
+	keep-response-order {
272df6
+		10.0.0.10/24;
272df6
+	};
272df6
 	listen-on port 90 {
272df6
 		"any";
272df6
 	};
272df6
diff --git a/bin/tests/system/conf.sh.in b/bin/tests/system/conf.sh.in
272df6
index 420320c..0d966b3 100644
272df6
--- a/bin/tests/system/conf.sh.in
272df6
+++ b/bin/tests/system/conf.sh.in
272df6
@@ -68,7 +68,7 @@ SUBDIRS="acl additional allow_query addzone autosign builtin
272df6
 	 cacheclean checkconf @CHECKDS@ checknames checkzone @COVERAGE@ @KEYMGR@
272df6
          database digdelv dlv dlvauto dlz dlzexternal dname dns64 dnssec dyndb
272df6
          ecdsa formerr forward glue gost ixfr inline limits logfileconfig
272df6
-         lwresd masterfile masterformat metadata notify nsupdate pending
272df6
+         lwresd masterfile masterformat metadata notify nsupdate pending pipelined
272df6
 	 @PKCS11_TEST@ redirect resolver rndc rpz rrl rrsetorder rsabigexponent
272df6
 	 smartsign sortlist spf staticstub stub tkey tsig tsiggss unknown
272df6
 	 upforwd verify views wildcard xfer xferquota zero zonechecks geoip filter-aaaa"
272df6
diff --git a/bin/tests/system/pipelined/Makefile.in b/bin/tests/system/pipelined/Makefile.in
272df6
new file mode 100644
272df6
index 0000000..4d16d78
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/Makefile.in
272df6
@@ -0,0 +1,51 @@
272df6
+# Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+#
272df6
+# Permission to use, copy, modify, and/or distribute this software for any
272df6
+# purpose with or without fee is hereby granted, provided that the above
272df6
+# copyright notice and this permission notice appear in all copies.
272df6
+#
272df6
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+# PERFORMANCE OF THIS SOFTWARE.
272df6
+
272df6
+srcdir =	@srcdir@
272df6
+VPATH =		@srcdir@
272df6
+top_srcdir =	@top_srcdir@
272df6
+
272df6
+@BIND9_VERSION@
272df6
+
272df6
+@BIND9_MAKE_INCLUDES@
272df6
+
272df6
+CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES}
272df6
+
272df6
+CDEFINES =
272df6
+CWARNINGS =
272df6
+
272df6
+DNSLIBS =	../../../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
272df6
+ISCLIBS =	../../../../lib/isc/libisc.@A@
272df6
+
272df6
+DNSDEPLIBS =	../../../../lib/dns/libdns.@A@
272df6
+ISCDEPLIBS =	../../../../lib/isc/libisc.@A@
272df6
+
272df6
+DEPLIBS =	${DNSDEPLIBS} ${ISCDEPLIBS}
272df6
+
272df6
+LIBS =		${DNSLIBS} ${ISCLIBS} @LIBS@
272df6
+
272df6
+TARGETS =	pipequeries@EXEEXT@
272df6
+
272df6
+SRCS =		pipequeries.c
272df6
+
272df6
+@BIND9_MAKE_RULES@
272df6
+
272df6
+all: pipequeries@EXEEXT@
272df6
+
272df6
+pipequeries@EXEEXT@: pipequeries.@O@ ${DEPLIBS}
272df6
+	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ pipequeries.@O@ ${LIBS}
272df6
+
272df6
+clean distclean::
272df6
+	rm -f ${TARGETS}
272df6
+
272df6
diff --git a/bin/tests/system/pipelined/clean.sh b/bin/tests/system/pipelined/clean.sh
272df6
new file mode 100644
272df6
index 0000000..1cca633
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/clean.sh
272df6
@@ -0,0 +1,19 @@
272df6
+#!/bin/sh
272df6
+#
272df6
+# Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+#
272df6
+# Permission to use, copy, modify, and/or distribute this software for any
272df6
+# purpose with or without fee is hereby granted, provided that the above
272df6
+# copyright notice and this permission notice appear in all copies.
272df6
+#
272df6
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+# PERFORMANCE OF THIS SOFTWARE.
272df6
+
272df6
+rm -f */named.memstats
272df6
+rm -f */named.run
272df6
+rm -f raw* output*
272df6
diff --git a/bin/tests/system/pipelined/input b/bin/tests/system/pipelined/input
272df6
new file mode 100644
272df6
index 0000000..485cf81
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/input
272df6
@@ -0,0 +1,8 @@
272df6
+a.examplea
272df6
+a.exampleb
272df6
+b.examplea
272df6
+b.exampleb
272df6
+c.examplea
272df6
+c.exampleb
272df6
+d.examplea
272df6
+d.exampleb
272df6
diff --git a/bin/tests/system/pipelined/inputb b/bin/tests/system/pipelined/inputb
272df6
new file mode 100644
272df6
index 0000000..6ea367e
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/inputb
272df6
@@ -0,0 +1,8 @@
272df6
+e.examplea
272df6
+e.exampleb
272df6
+f.examplea
272df6
+f.exampleb
272df6
+g.examplea
272df6
+g.exampleb
272df6
+h.examplea
272df6
+h.exampleb
272df6
diff --git a/bin/tests/system/pipelined/ns1/named.conf b/bin/tests/system/pipelined/ns1/named.conf
272df6
new file mode 100644
272df6
index 0000000..1bbf401
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/ns1/named.conf
272df6
@@ -0,0 +1,43 @@
272df6
+/*
272df6
+ * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+ *
272df6
+ * Permission to use, copy, modify, and/or distribute this software for any
272df6
+ * purpose with or without fee is hereby granted, provided that the above
272df6
+ * copyright notice and this permission notice appear in all copies.
272df6
+ *
272df6
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+ * PERFORMANCE OF THIS SOFTWARE.
272df6
+ */
272df6
+
272df6
+controls { /* empty */ };
272df6
+
272df6
+options {
272df6
+	query-source address 10.53.0.1;
272df6
+	notify-source 10.53.0.1;
272df6
+	transfer-source 10.53.0.1;
272df6
+	port 5300;
272df6
+	pid-file "named.pid";
272df6
+	listen-on { 10.53.0.1; };
272df6
+	listen-on-v6 { none; };
272df6
+	recursion no;
272df6
+	notify yes;
272df6
+};
272df6
+
272df6
+key rndc_key {
272df6
+	secret "1234abcd8765";
272df6
+	algorithm hmac-sha256;
272df6
+};
272df6
+
272df6
+controls {
272df6
+	inet 10.53.0.1 port 9953 allow { any; } keys { rndc_key; };
272df6
+};
272df6
+
272df6
+zone "." {
272df6
+	type master;
272df6
+	file "root.db";
272df6
+};
272df6
diff --git a/bin/tests/system/pipelined/ns1/root.db b/bin/tests/system/pipelined/ns1/root.db
272df6
new file mode 100644
272df6
index 0000000..b5186e5
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/ns1/root.db
272df6
@@ -0,0 +1,30 @@
272df6
+; Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+;
272df6
+; Permission to use, copy, modify, and/or distribute this software for any
272df6
+; purpose with or without fee is hereby granted, provided that the above
272df6
+; copyright notice and this permission notice appear in all copies.
272df6
+;
272df6
+; THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+; REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+; AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+; INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+; LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+; PERFORMANCE OF THIS SOFTWARE.
272df6
+
272df6
+$TTL 300
272df6
+. 			IN SOA	gson.nominum.com. a.root.servers.nil. (
272df6
+				2000042100   	; serial
272df6
+				600         	; refresh
272df6
+				600         	; retry
272df6
+				1200    	; expire
272df6
+				600       	; minimum
272df6
+				)
272df6
+.			NS	a.root-servers.nil.
272df6
+a.root-servers.nil.	A	10.53.0.1
272df6
+
272df6
+examplea.		NS	ns2.examplea.
272df6
+ns2.examplea.		A	10.53.0.2
272df6
+
272df6
+exampleb.		NS	ns3.exampleb.
272df6
+ns3.exampleb.		A	10.53.0.3
272df6
diff --git a/bin/tests/system/pipelined/ns2/examplea.db b/bin/tests/system/pipelined/ns2/examplea.db
272df6
new file mode 100644
272df6
index 0000000..678034a
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/ns2/examplea.db
272df6
@@ -0,0 +1,35 @@
272df6
+; Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+;
272df6
+; Permission to use, copy, modify, and/or distribute this software for any
272df6
+; purpose with or without fee is hereby granted, provided that the above
272df6
+; copyright notice and this permission notice appear in all copies.
272df6
+;
272df6
+; THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+; REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+; AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+; INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+; LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+; PERFORMANCE OF THIS SOFTWARE.
272df6
+
272df6
+$ORIGIN .
272df6
+$TTL 300	; 5 minutes
272df6
+examplea		IN SOA	mname1. . (
272df6
+				1          ; serial
272df6
+				20         ; refresh (20 seconds)
272df6
+				20         ; retry (20 seconds)
272df6
+				1814400    ; expire (3 weeks)
272df6
+				3600       ; minimum (1 hour)
272df6
+				)
272df6
+examplea.		NS	ns2.examplea.
272df6
+ns2.examplea.		A	10.53.0.2
272df6
+
272df6
+$ORIGIN examplea.
272df6
+a			A	10.0.1.1
272df6
+b			A	10.0.1.2
272df6
+c			A	10.0.1.3
272df6
+d			A	10.0.1.4
272df6
+e			A	10.0.1.5
272df6
+f			A	10.0.1.6
272df6
+g			A	10.0.1.7
272df6
+h			A	10.0.1.8
272df6
diff --git a/bin/tests/system/pipelined/ns2/named.conf b/bin/tests/system/pipelined/ns2/named.conf
272df6
new file mode 100644
272df6
index 0000000..83a9ec7
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/ns2/named.conf
272df6
@@ -0,0 +1,49 @@
272df6
+/*
272df6
+ * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+ *
272df6
+ * Permission to use, copy, modify, and/or distribute this software for any
272df6
+ * purpose with or without fee is hereby granted, provided that the above
272df6
+ * copyright notice and this permission notice appear in all copies.
272df6
+ *
272df6
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+ * PERFORMANCE OF THIS SOFTWARE.
272df6
+ */
272df6
+
272df6
+controls { /* empty */ };
272df6
+
272df6
+options {
272df6
+	query-source address 10.53.0.2;
272df6
+	notify-source 10.53.0.2;
272df6
+	transfer-source 10.53.0.2;
272df6
+	port 5300;
272df6
+	pid-file "named.pid";
272df6
+	listen-on { 10.53.0.2; };
272df6
+	listen-on-v6 { none; };
272df6
+	recursion yes;
272df6
+	notify yes;
272df6
+};
272df6
+
272df6
+key rndc_key {
272df6
+	secret "1234abcd8765";
272df6
+	algorithm hmac-sha256;
272df6
+};
272df6
+
272df6
+controls {
272df6
+	inet 10.53.0.2 port 9953 allow { any; } keys { rndc_key; };
272df6
+};
272df6
+
272df6
+zone "." {
272df6
+	type hint;
272df6
+	file "../../common/root.hint";
272df6
+};
272df6
+
272df6
+zone "examplea" {
272df6
+	type master;
272df6
+	file "examplea.db";
272df6
+	allow-update { any; };
272df6
+};
272df6
diff --git a/bin/tests/system/pipelined/ns3/exampleb.db b/bin/tests/system/pipelined/ns3/exampleb.db
272df6
new file mode 100644
272df6
index 0000000..7d10493
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/ns3/exampleb.db
272df6
@@ -0,0 +1,35 @@
272df6
+; Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+;
272df6
+; Permission to use, copy, modify, and/or distribute this software for any
272df6
+; purpose with or without fee is hereby granted, provided that the above
272df6
+; copyright notice and this permission notice appear in all copies.
272df6
+;
272df6
+; THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+; REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+; AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+; INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+; LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+; PERFORMANCE OF THIS SOFTWARE.
272df6
+
272df6
+$ORIGIN .
272df6
+$TTL 300	; 5 minutes
272df6
+exampleb		IN SOA	mname1. . (
272df6
+				1          ; serial
272df6
+				20         ; refresh (20 seconds)
272df6
+				20         ; retry (20 seconds)
272df6
+				1814400    ; expire (3 weeks)
272df6
+				3600       ; minimum (1 hour)
272df6
+				)
272df6
+exampleb.		NS	ns3.exampleb.
272df6
+ns3.exampleb.		A	10.53.0.3
272df6
+
272df6
+$ORIGIN exampleb.
272df6
+a			A	10.0.2.1
272df6
+b			A	10.0.2.2
272df6
+c			A	10.0.2.3
272df6
+d			A	10.0.2.4
272df6
+e			A	10.0.2.5
272df6
+f			A	10.0.2.6
272df6
+g			A	10.0.2.7
272df6
+h			A	10.0.2.8
272df6
diff --git a/bin/tests/system/pipelined/ns3/named.args b/bin/tests/system/pipelined/ns3/named.args
272df6
new file mode 100644
272df6
index 0000000..a6b0f54
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/ns3/named.args
272df6
@@ -0,0 +1 @@
272df6
+-m record,size,mctx -c named.conf -d 99 -g -T delay=200
272df6
diff --git a/bin/tests/system/pipelined/ns3/named.conf b/bin/tests/system/pipelined/ns3/named.conf
272df6
new file mode 100644
272df6
index 0000000..8b15622
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/ns3/named.conf
272df6
@@ -0,0 +1,49 @@
272df6
+/*
272df6
+ * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+ *
272df6
+ * Permission to use, copy, modify, and/or distribute this software for any
272df6
+ * purpose with or without fee is hereby granted, provided that the above
272df6
+ * copyright notice and this permission notice appear in all copies.
272df6
+ *
272df6
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+ * PERFORMANCE OF THIS SOFTWARE.
272df6
+ */
272df6
+
272df6
+controls { /* empty */ };
272df6
+
272df6
+options {
272df6
+	query-source address 10.53.0.3;
272df6
+	notify-source 10.53.0.3;
272df6
+	transfer-source 10.53.0.3;
272df6
+	port 5300;
272df6
+	pid-file "named.pid";
272df6
+	listen-on { 10.53.0.3; };
272df6
+	listen-on-v6 { none; };
272df6
+	recursion yes;
272df6
+	notify yes;
272df6
+};
272df6
+
272df6
+key rndc_key {
272df6
+	secret "1234abcd8765";
272df6
+	algorithm hmac-sha256;
272df6
+};
272df6
+
272df6
+controls {
272df6
+	inet 10.53.0.3 port 9953 allow { any; } keys { rndc_key; };
272df6
+};
272df6
+
272df6
+zone "." {
272df6
+	type hint;
272df6
+	file "../../common/root.hint";
272df6
+};
272df6
+
272df6
+zone "exampleb" {
272df6
+	type master;
272df6
+	file "exampleb.db";
272df6
+	allow-update { any; };
272df6
+};
272df6
diff --git a/bin/tests/system/pipelined/ns4/named.conf b/bin/tests/system/pipelined/ns4/named.conf
272df6
new file mode 100644
272df6
index 0000000..7e7923a
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/ns4/named.conf
272df6
@@ -0,0 +1,45 @@
272df6
+/*
272df6
+ * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+ *
272df6
+ * Permission to use, copy, modify, and/or distribute this software for any
272df6
+ * purpose with or without fee is hereby granted, provided that the above
272df6
+ * copyright notice and this permission notice appear in all copies.
272df6
+ *
272df6
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+ * PERFORMANCE OF THIS SOFTWARE.
272df6
+ */
272df6
+
272df6
+controls { /* empty */ };
272df6
+
272df6
+options {
272df6
+	query-source address 10.53.0.4;
272df6
+	notify-source 10.53.0.4;
272df6
+	transfer-source 10.53.0.4;
272df6
+	port 5300;
272df6
+	directory ".";
272df6
+	pid-file "named.pid";
272df6
+	listen-on { 10.53.0.4; };
272df6
+	listen-on-v6 { none; };
272df6
+	keep-response-order { 10.53.0.7/32; };
272df6
+	recursion yes;
272df6
+	notify yes;
272df6
+};
272df6
+
272df6
+key rndc_key {
272df6
+	secret "1234abcd8765";
272df6
+	algorithm hmac-sha256;
272df6
+};
272df6
+
272df6
+controls {
272df6
+	inet 10.53.0.4 port 9953 allow { any; } keys { rndc_key; };
272df6
+};
272df6
+
272df6
+zone "." {
272df6
+	type hint;
272df6
+	file "../../common/root.hint";
272df6
+};
272df6
diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c
272df6
new file mode 100644
272df6
index 0000000..d34dedd
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/pipequeries.c
272df6
@@ -0,0 +1,346 @@
272df6
+/*
272df6
+ * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+ *
272df6
+ * Permission to use, copy, modify, and/or distribute this software for any
272df6
+ * purpose with or without fee is hereby granted, provided that the above
272df6
+ * copyright notice and this permission notice appear in all copies.
272df6
+ *
272df6
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+ * PERFORMANCE OF THIS SOFTWARE.
272df6
+ */
272df6
+
272df6
+#include <config.h>
272df6
+
272df6
+#include <stdlib.h>
272df6
+#include <string.h>
272df6
+#include <unistd.h>
272df6
+
272df6
+#include <isc/app.h>
272df6
+#include <isc/base64.h>
272df6
+#include <isc/entropy.h>
272df6
+#include <isc/hash.h>
272df6
+#include <isc/log.h>
272df6
+#include <isc/mem.h>
272df6
+#include <isc/sockaddr.h>
272df6
+#include <isc/socket.h>
272df6
+#include <isc/task.h>
272df6
+#include <isc/timer.h>
272df6
+#include <isc/util.h>
272df6
+
272df6
+#include <dns/dispatch.h>
272df6
+#include <dns/fixedname.h>
272df6
+#include <dns/message.h>
272df6
+#include <dns/name.h>
272df6
+#include <dns/request.h>
272df6
+#include <dns/result.h>
272df6
+#include <dns/view.h>
272df6
+
272df6
+#include <dns/events.h>
272df6
+#include <dns/rdataset.h>
272df6
+#include <dns/resolver.h>
272df6
+#include <dns/types.h>
272df6
+
272df6
+#include <dst/result.h>
272df6
+
272df6
+#define CHECK(str, x) { \
272df6
+	if ((x) != ISC_R_SUCCESS) { \
272df6
+		fprintf(stderr, "I:%s: %s\n", (str), isc_result_totext(x)); \
272df6
+		exit(-1); \
272df6
+	} \
272df6
+}
272df6
+
272df6
+#define RUNCHECK(x) RUNTIME_CHECK((x) == ISC_R_SUCCESS)
272df6
+
272df6
+#define PORT 5300
272df6
+#define TIMEOUT 30
272df6
+
272df6
+static isc_mem_t *mctx;
272df6
+static dns_requestmgr_t *requestmgr;
272df6
+isc_sockaddr_t address;
272df6
+static int onfly;
272df6
+
272df6
+static void
272df6
+recvresponse(isc_task_t *task, isc_event_t *event) {
272df6
+	dns_requestevent_t *reqev = (dns_requestevent_t *)event;
272df6
+	isc_result_t result;
272df6
+	dns_message_t *query, *response;
272df6
+	isc_buffer_t outbuf;
272df6
+	char output[1024];
272df6
+
272df6
+	UNUSED(task);
272df6
+
272df6
+	REQUIRE(reqev != NULL);
272df6
+
272df6
+	if (reqev->result != ISC_R_SUCCESS) {
272df6
+		fprintf(stderr, "I:request event result: %s\n",
272df6
+			isc_result_totext(reqev->result));
272df6
+		exit(-1);
272df6
+	}
272df6
+
272df6
+	query = reqev->ev_arg;
272df6
+
272df6
+	response = NULL;
272df6
+	result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
272df6
+	CHECK("dns_message_create", result);
272df6
+
272df6
+	result = dns_request_getresponse(reqev->request, response,
272df6
+					 DNS_MESSAGEPARSE_PRESERVEORDER);
272df6
+	CHECK("dns_request_getresponse", result);
272df6
+
272df6
+	if (response->rcode != dns_rcode_noerror) {
272df6
+		result = ISC_RESULTCLASS_DNSRCODE + response->rcode;
272df6
+		fprintf(stderr, "I:response rcode: %s\n",
272df6
+			isc_result_totext(result));
272df6
+			exit(-1);
272df6
+	}
272df6
+	if (response->counts[DNS_SECTION_ANSWER] != 1U) {
272df6
+		fprintf(stderr, "I:response answer count (%u!=1)\n",
272df6
+			response->counts[DNS_SECTION_ANSWER]);
272df6
+	}
272df6
+
272df6
+	isc_buffer_init(&outbuf, output, sizeof(output));
272df6
+	result = dns_message_sectiontotext(response, DNS_SECTION_ANSWER,
272df6
+					   &dns_master_style_simple,
272df6
+					   DNS_MESSAGETEXTFLAG_NOCOMMENTS,
272df6
+					   &outbuf);
272df6
+	CHECK("dns_message_sectiontotext", result);
272df6
+	printf("%.*s", (int)isc_buffer_usedlength(&outbuf),
272df6
+	       (char *)isc_buffer_base(&outbuf));
272df6
+	fflush(stdout);
272df6
+
272df6
+	dns_message_destroy(&query);
272df6
+	dns_message_destroy(&response);
272df6
+	dns_request_destroy(&reqev->request);
272df6
+	isc_event_free(&event);
272df6
+
272df6
+	if (--onfly == 0)
272df6
+		isc_app_shutdown();
272df6
+	return;
272df6
+}
272df6
+
272df6
+static isc_result_t
272df6
+sendquery(isc_task_t *task)
272df6
+{
272df6
+	dns_request_t *request;
272df6
+	dns_message_t *message;
272df6
+	dns_name_t *qname;
272df6
+	dns_rdataset_t *qrdataset;
272df6
+	isc_result_t result;
272df6
+	dns_fixedname_t queryname;
272df6
+	isc_buffer_t buf;
272df6
+	static char host[256];
272df6
+	int c;
272df6
+
272df6
+	c = scanf("%255s", host);
272df6
+	if (c == EOF)
272df6
+		return ISC_R_NOMORE;
272df6
+
272df6
+	onfly++;
272df6
+
272df6
+	dns_fixedname_init(&queryname);
272df6
+	isc_buffer_init(&buf, host, strlen(host));
272df6
+	isc_buffer_add(&buf, strlen(host));
272df6
+	result = dns_name_fromtext(dns_fixedname_name(&queryname), &buf,
272df6
+				   dns_rootname, 0, NULL);
272df6
+	CHECK("dns_name_fromtext", result);
272df6
+
272df6
+	message = NULL;
272df6
+	result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message);
272df6
+	CHECK("dns_message_create", result);
272df6
+
272df6
+	message->opcode = dns_opcode_query;
272df6
+	message->flags |= DNS_MESSAGEFLAG_RD;
272df6
+	message->rdclass = dns_rdataclass_in;
272df6
+	message->id = (unsigned short)(random() & 0xFFFF);
272df6
+
272df6
+	qname = NULL;
272df6
+	result = dns_message_gettempname(message, &qname);
272df6
+	CHECK("dns_message_gettempname", result);
272df6
+
272df6
+	qrdataset = NULL;
272df6
+	result = dns_message_gettemprdataset(message, &qrdataset);
272df6
+	CHECK("dns_message_gettemprdataset", result);
272df6
+
272df6
+	dns_name_init(qname, NULL);
272df6
+	dns_name_clone(dns_fixedname_name(&queryname), qname);
272df6
+	dns_rdataset_init(qrdataset);
272df6
+	dns_rdataset_makequestion(qrdataset, dns_rdataclass_in,
272df6
+				  dns_rdatatype_a);
272df6
+	ISC_LIST_APPEND(qname->list, qrdataset, link);
272df6
+	dns_message_addname(message, qname, DNS_SECTION_QUESTION);
272df6
+
272df6
+	request = NULL;
272df6
+	result = dns_request_create(requestmgr, message, &address,
272df6
+				    DNS_REQUESTOPT_TCP, NULL,
272df6
+				    TIMEOUT, task, recvresponse,
272df6
+				    message, &request);
272df6
+	CHECK("dns_request_create", result);
272df6
+
272df6
+	return ISC_R_SUCCESS;
272df6
+}
272df6
+
272df6
+static void
272df6
+sendqueries(isc_task_t *task, isc_event_t *event)
272df6
+{
272df6
+	isc_result_t result;
272df6
+
272df6
+	isc_event_free(&event);
272df6
+
272df6
+	do {
272df6
+		result = sendquery(task);
272df6
+	} while (result == ISC_R_SUCCESS);
272df6
+
272df6
+	if (onfly == 0)
272df6
+		isc_app_shutdown();
272df6
+	return;
272df6
+}
272df6
+
272df6
+static void
272df6
+connecting(isc_task_t *task, isc_event_t *event)
272df6
+{
272df6
+	isc_socket_t *sock = (isc_socket_t *)(event->ev_arg);
272df6
+
272df6
+	RUNCHECK(isc_socket_connect(sock, &address, task, sendqueries, NULL));
272df6
+
272df6
+	isc_event_free(&event);
272df6
+}
272df6
+
272df6
+int
272df6
+main(int argc, char *argv[])
272df6
+{
272df6
+	isc_taskmgr_t *taskmgr;
272df6
+	isc_timermgr_t *timermgr;
272df6
+	isc_socketmgr_t *socketmgr;
272df6
+	isc_socket_t *sock;
272df6
+	unsigned int attrs, attrmask;
272df6
+	isc_sockaddr_t bind_addr;
272df6
+	dns_dispatchmgr_t *dispatchmgr;
272df6
+	dns_dispatch_t *dispatchv4;
272df6
+	dns_dispatch_t *tcpdispatch;
272df6
+	dns_view_t *view;
272df6
+	isc_entropy_t *ectx;
272df6
+	isc_task_t *task;
272df6
+	isc_log_t *lctx;
272df6
+	isc_logconfig_t *lcfg;
272df6
+	struct in_addr inaddr;
272df6
+	isc_result_t result;
272df6
+
272df6
+	UNUSED(argv);
272df6
+
272df6
+	RUNCHECK(isc_app_start());
272df6
+
272df6
+	dns_result_register();
272df6
+
272df6
+	mctx = NULL;
272df6
+	RUNCHECK(isc_mem_create(0, 0, &mctx));
272df6
+
272df6
+	lctx = NULL;
272df6
+	lcfg = NULL;
272df6
+	RUNCHECK(isc_log_create(mctx, &lctx, &lcfg));
272df6
+
272df6
+	ectx = NULL;
272df6
+	RUNCHECK(isc_entropy_create(mctx, &ectx));
272df6
+	RUNCHECK(isc_entropy_createfilesource(ectx, "../random.data"));
272df6
+	RUNCHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE));
272df6
+
272df6
+	RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY));
272df6
+
272df6
+	taskmgr = NULL;
272df6
+	RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr));
272df6
+	task = NULL;
272df6
+	RUNCHECK(isc_task_create(taskmgr, 0, &task));
272df6
+	timermgr = NULL;
272df6
+
272df6
+	RUNCHECK(isc_timermgr_create(mctx, &timermgr));
272df6
+	socketmgr = NULL;
272df6
+	RUNCHECK(isc_socketmgr_create(mctx, &socketmgr));
272df6
+	dispatchmgr = NULL;
272df6
+	RUNCHECK(dns_dispatchmgr_create(mctx, ectx, &dispatchmgr));
272df6
+	if (argc == 1) {
272df6
+		isc_sockaddr_any(&bind_addr);
272df6
+	} else {
272df6
+		result = ISC_R_FAILURE;
272df6
+		if (inet_pton(AF_INET, "10.53.0.7", &inaddr) != 1)
272df6
+			CHECK("inet_pton", result);
272df6
+		isc_sockaddr_fromin(&bind_addr, &inaddr, 0);
272df6
+	}
272df6
+	attrs = DNS_DISPATCHATTR_UDP |
272df6
+		DNS_DISPATCHATTR_MAKEQUERY |
272df6
+		DNS_DISPATCHATTR_IPV4;
272df6
+	attrmask = DNS_DISPATCHATTR_UDP |
272df6
+		   DNS_DISPATCHATTR_TCP |
272df6
+		   DNS_DISPATCHATTR_IPV4 |
272df6
+		   DNS_DISPATCHATTR_IPV6;
272df6
+	dispatchv4 = NULL;
272df6
+	RUNCHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr,
272df6
+					  &bind_addr, 4096, 4, 2, 3, 5,
272df6
+					  attrs, attrmask, &dispatchv4));
272df6
+	requestmgr = NULL;
272df6
+	RUNCHECK(dns_requestmgr_create(mctx, timermgr, socketmgr, taskmgr,
272df6
+					    dispatchmgr, dispatchv4, NULL,
272df6
+					    &requestmgr));
272df6
+
272df6
+	view = NULL;
272df6
+	RUNCHECK(dns_view_create(mctx, 0, "_test", &view));
272df6
+
272df6
+	sock = NULL;
272df6
+	RUNCHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_tcp,
272df6
+				   &sock));
272df6
+	RUNCHECK(isc_socket_bind(sock, &bind_addr, 0));
272df6
+
272df6
+	result = ISC_R_FAILURE;
272df6
+	if (inet_pton(AF_INET, "10.53.0.4", &inaddr) != 1)
272df6
+		CHECK("inet_pton", result);
272df6
+	isc_sockaddr_fromin(&address, &inaddr, PORT);
272df6
+
272df6
+	attrs = 0;
272df6
+	attrs |= DNS_DISPATCHATTR_TCP;
272df6
+	attrs |= DNS_DISPATCHATTR_IPV4;
272df6
+	attrs |= DNS_DISPATCHATTR_MAKEQUERY;
272df6
+	attrs |= DNS_DISPATCHATTR_CONNECTED;
272df6
+	tcpdispatch = NULL;
272df6
+	RUNCHECK(dns_dispatch_createtcp2(dispatchmgr, sock, taskmgr,
272df6
+					 &bind_addr, &address,
272df6
+					 4096, 20, 10, 3, 5,
272df6
+					 attrs, &tcpdispatch));
272df6
+
272df6
+	RUNCHECK(isc_app_onrun(mctx, task, connecting, sock));
272df6
+
272df6
+	isc_socket_detach(&sock);
272df6
+
272df6
+	(void)isc_app_run();
272df6
+
272df6
+	dns_view_detach(&view);
272df6
+
272df6
+	dns_requestmgr_shutdown(requestmgr);
272df6
+	dns_requestmgr_detach(&requestmgr);
272df6
+
272df6
+	dns_dispatch_detach(&dispatchv4);
272df6
+	dns_dispatch_detach(&tcpdispatch);
272df6
+	dns_dispatchmgr_destroy(&dispatchmgr);
272df6
+
272df6
+	isc_socketmgr_destroy(&socketmgr);
272df6
+	isc_timermgr_destroy(&timermgr);
272df6
+
272df6
+	isc_task_shutdown(task);
272df6
+	isc_task_detach(&task);
272df6
+	isc_taskmgr_destroy(&taskmgr);
272df6
+
272df6
+	dst_lib_destroy();
272df6
+	isc_hash_destroy();
272df6
+	isc_entropy_detach(&ectx);
272df6
+
272df6
+	isc_log_destroy(&lctx);
272df6
+
272df6
+	isc_mem_destroy(&mctx);
272df6
+
272df6
+	isc_app_finish();
272df6
+
272df6
+	return (0);
272df6
+}
272df6
+
272df6
diff --git a/bin/tests/system/pipelined/ref b/bin/tests/system/pipelined/ref
272df6
new file mode 100644
272df6
index 0000000..fe123f6
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/ref
272df6
@@ -0,0 +1,8 @@
272df6
+a.examplea. 10.0.1.1
272df6
+a.exampleb. 10.0.2.1
272df6
+b.examplea. 10.0.1.2
272df6
+b.exampleb. 10.0.2.2
272df6
+c.examplea. 10.0.1.3
272df6
+c.exampleb. 10.0.2.3
272df6
+d.examplea. 10.0.1.4
272df6
+d.exampleb. 10.0.2.4
272df6
diff --git a/bin/tests/system/pipelined/refb b/bin/tests/system/pipelined/refb
272df6
new file mode 100644
272df6
index 0000000..a24c6bc
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/refb
272df6
@@ -0,0 +1,8 @@
272df6
+e.examplea. 10.0.1.5
272df6
+e.exampleb. 10.0.2.5
272df6
+f.examplea. 10.0.1.6
272df6
+f.exampleb. 10.0.2.6
272df6
+g.examplea. 10.0.1.7
272df6
+g.exampleb. 10.0.2.7
272df6
+h.examplea. 10.0.1.8
272df6
+h.exampleb. 10.0.2.8
272df6
diff --git a/bin/tests/system/pipelined/setup.sh b/bin/tests/system/pipelined/setup.sh
272df6
new file mode 100644
272df6
index 0000000..6fc981d
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/setup.sh
272df6
@@ -0,0 +1,22 @@
272df6
+#!/bin/sh
272df6
+#
272df6
+# Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+#
272df6
+# Permission to use, copy, modify, and/or distribute this software for any
272df6
+# purpose with or without fee is hereby granted, provided that the above
272df6
+# copyright notice and this permission notice appear in all copies.
272df6
+#
272df6
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+# PERFORMANCE OF THIS SOFTWARE.
272df6
+
272df6
+SYSTEMTESTTOP=..
272df6
+. $SYSTEMTESTTOP/conf.sh
272df6
+
272df6
+$SHELL clean.sh
272df6
+
272df6
+test -r $RANDFILE || $GENRANDOM 400 $RANDFILE
272df6
diff --git a/bin/tests/system/pipelined/tests.sh b/bin/tests/system/pipelined/tests.sh
272df6
new file mode 100644
272df6
index 0000000..a34e573
272df6
--- /dev/null
272df6
+++ b/bin/tests/system/pipelined/tests.sh
272df6
@@ -0,0 +1,41 @@
272df6
+#!/bin/sh
272df6
+#
272df6
+# Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
272df6
+#
272df6
+# Permission to use, copy, modify, and/or distribute this software for any
272df6
+# purpose with or without fee is hereby granted, provided that the above
272df6
+# copyright notice and this permission notice appear in all copies.
272df6
+#
272df6
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
272df6
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
272df6
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
272df6
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
272df6
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
272df6
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
272df6
+# PERFORMANCE OF THIS SOFTWARE.
272df6
+
272df6
+SYSTEMTESTTOP=..
272df6
+. $SYSTEMTESTTOP/conf.sh
272df6
+
272df6
+status=0
272df6
+
272df6
+echo "I:check pipelined TCP queries"
272df6
+ret=0
272df6
+./pipequeries < input > raw || ret=1
272df6
+awk '{ print $1 " " $5 }' < raw > output
272df6
+sort < output > output-sorted
272df6
+diff ref output-sorted || { ret=1 ; echo "I: diff sorted failed"; }
272df6
+diff ref output > /dev/null && { ret=1 ; echo "I: diff out of order failed"; }
272df6
+if [ $ret != 0 ]; then echo "I:failed"; fi
272df6
+status=`expr $status + $ret`
272df6
+
272df6
+echo "I:check keep response order"
272df6
+ret=0
272df6
+./pipequeries ++ < inputb > rawb || ret=1
272df6
+awk '{ print $1 " " $5 }' < rawb > outputb
272df6
+diff refb outputb || ret=1
272df6
+if [ $ret != 0 ]; then echo "I:failed"; fi
272df6
+status=`expr $status + $ret`
272df6
+
272df6
+echo "I:exit status: $status"
272df6
+exit $status
272df6
diff --git a/configure b/configure
272df6
index a299aac..7f5c7da 100755
272df6
--- a/configure
272df6
+++ b/configure
272df6
@@ -22330,6 +22330,7 @@ do
272df6
     "bin/tests/system/geoip/Makefile") CONFIG_FILES="$CONFIG_FILES bin/tests/system/geoip/Makefile" ;;
272df6
     "bin/tests/system/gost/prereq.sh") CONFIG_FILES="$CONFIG_FILES bin/tests/system/gost/prereq.sh" ;;
272df6
     "bin/tests/system/lwresd/Makefile") CONFIG_FILES="$CONFIG_FILES bin/tests/system/lwresd/Makefile" ;;
272df6
+    "bin/tests/system/pipelined/Makefile") CONFIG_FILES="$CONFIG_FILES bin/tests/system/pipelined/Makefile" ;;
272df6
     "bin/tests/system/rpz/Makefile") CONFIG_FILES="$CONFIG_FILES bin/tests/system/rpz/Makefile" ;;
272df6
     "bin/tests/system/rrl/Makefile") CONFIG_FILES="$CONFIG_FILES bin/tests/system/rrl/Makefile" ;;
272df6
     "bin/tests/system/rsabigexponent/Makefile") CONFIG_FILES="$CONFIG_FILES bin/tests/system/rsabigexponent/Makefile" ;;
272df6
diff --git a/configure.in b/configure.in
272df6
index ee38901..9c5a9db 100644
272df6
--- a/configure.in
272df6
+++ b/configure.in
272df6
@@ -4099,6 +4099,7 @@ AC_CONFIG_FILES([
272df6
 	bin/tests/system/geoip/Makefile
272df6
 	bin/tests/system/gost/prereq.sh
272df6
 	bin/tests/system/lwresd/Makefile
272df6
+	bin/tests/system/pipelined/Makefile
272df6
 	bin/tests/system/rpz/Makefile
272df6
 	bin/tests/system/rrl/Makefile
272df6
 	bin/tests/system/rsabigexponent/Makefile
272df6
diff --git a/doc/arm/Bv9ARM-book.xml b/doc/arm/Bv9ARM-book.xml
272df6
index af194d9..74394a0 100644
272df6
--- a/doc/arm/Bv9ARM-book.xml
272df6
+++ b/doc/arm/Bv9ARM-book.xml
272df6
@@ -3025,8 +3025,9 @@ $ORIGIN 0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.
272df6
 	    <command>allow-query-cache-on</command>,
272df6
 	    <command>allow-transfer</command>,
272df6
 	    <command>allow-update</command>,
272df6
-	    <command>allow-update-forwarding</command>, and
272df6
-	    <command>blackhole</command> all use address match
272df6
+	    <command>allow-update-forwarding</command>,
272df6
+	    <command>blackhole</command>, and
272df6
+	    <command>keep-response-order</command> all use address match
272df6
 	    lists.  Similarly, the <command>listen-on</command> option will cause the
272df6
 	    server to refuse queries on any of the machine's
272df6
 	    addresses which do not match the list.
272df6
@@ -4829,6 +4830,7 @@ badresp:1,adberr:0,findfail:0,valfail:0]
272df6
     <optional> try-tcp-refresh <replaceable>yes_or_no</replaceable>; </optional>
272df6
     <optional> allow-v6-synthesis { <replaceable>address_match_list</replaceable> }; </optional>
272df6
     <optional> blackhole { <replaceable>address_match_list</replaceable> }; </optional>
272df6
+    <optional> keep-response-order { <replaceable>address_match_list</replaceable> }; </optional>
272df6
     <optional> use-v4-udp-ports { <replaceable>port_list</replaceable> }; </optional>
272df6
     <optional> avoid-v4-udp-ports { <replaceable>port_list</replaceable> }; </optional>
272df6
     <optional> use-v6-udp-ports { <replaceable>port_list</replaceable> }; </optional>
272df6
@@ -7248,6 +7250,19 @@ options {
272df6
                   Specifies a list of addresses to which
272df6
 		  <command>filter-aaaa-on-v4</command>
272df6
                   is applies.  The default is <userinput>any</userinput>.
272df6
+		</para>
272df6
+	      </listitem>
272df6
+	    </varlistentry>
272df6
+
272df6
+	    <varlistentry>
272df6
+	      <term><command>keep-response-order</command></term>
272df6
+	      <listitem>
272df6
+		<para>
272df6
+		  Specifies a list of addresses to which the server
272df6
+		  will send responses to TCP queries in the same order
272df6
+		  in which they were received.  This disables the
272df6
+		  processing of TCP queries in parallel. The default
272df6
+		  is <userinput>any</userinput>.
272df6
                 </para>
272df6
               </listitem>
272df6
             </varlistentry>
272df6
diff --git a/doc/misc/options b/doc/misc/options
272df6
index 1827bd7..3c0f01f 100644
272df6
--- a/doc/misc/options
272df6
+++ b/doc/misc/options
272df6
@@ -147,6 +147,7 @@ options {
272df6
         inline-signing <boolean>;
272df6
         interface-interval <integer>;
272df6
         ixfr-from-differences <ixfrdiff>;
272df6
+	keep-response-order { <address_match_element>; ... };
272df6
         key-directory <quoted_string>;
272df6
         lame-ttl <integer>;
272df6
         listen-on [ port <integer> ] { <address_match_element>; ... };
272df6
diff --git a/lib/bind9/check.c b/lib/bind9/check.c
272df6
index 00c4b3e..d4803e2 100644
272df6
--- a/lib/bind9/check.c
272df6
+++ b/lib/bind9/check.c
272df6
@@ -403,8 +403,8 @@ check_viewacls(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions,
272df6
 
272df6
 	static const char *acls[] = { "allow-query", "allow-query-on",
272df6
 		"allow-query-cache", "allow-query-cache-on",
272df6
-		"blackhole", "match-clients", "match-destinations",
272df6
-		"sortlist", "filter-aaaa", NULL };
272df6
+		"blackhole", "keep-response-order", "match-clients",
272df6
+		"match-destinations", "sortlist", "filter-aaaa", NULL };
272df6
 
272df6
 	while (acls[i] != NULL) {
272df6
 		tresult = checkacl(acls[i++], actx, NULL, voptions, config,
272df6
diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c
272df6
index b9f34eb..088c500 100644
272df6
--- a/lib/dns/dispatch.c
272df6
+++ b/lib/dns/dispatch.c
272df6
@@ -2831,7 +2831,6 @@ dns_dispatch_gettcp(dns_dispatchmgr_t *mgr, isc_sockaddr_t *destaddr,
272df6
 	isc_result_t result;
272df6
 	isc_sockaddr_t peeraddr;
272df6
 	isc_sockaddr_t sockname;
272df6
-	isc_sockaddr_t any;
272df6
 	unsigned int attributes, mask;
272df6
 	isc_boolean_t match = ISC_FALSE;
272df6
 
272df6
@@ -2839,23 +2838,9 @@ dns_dispatch_gettcp(dns_dispatchmgr_t *mgr, isc_sockaddr_t *destaddr,
272df6
 	REQUIRE(destaddr != NULL);
272df6
 	REQUIRE(dispp != NULL && *dispp == NULL);
272df6
 
272df6
-	attributes = DNS_DISPATCHATTR_TCP;
272df6
+	attributes = DNS_DISPATCHATTR_TCP | DNS_DISPATCHATTR_CONNECTED;
272df6
 	mask = DNS_DISPATCHATTR_TCP | DNS_DISPATCHATTR_PRIVATE |
272df6
-	       DNS_DISPATCHATTR_EXCLUSIVE;
272df6
-
272df6
-	if (localaddr == NULL) {
272df6
-		switch (isc_sockaddr_pf(destaddr)) {
272df6
-		case AF_INET:
272df6
-			isc_sockaddr_any(&any;;
272df6
-			break;
272df6
-		case AF_INET6:
272df6
-			isc_sockaddr_any6(&any;;
272df6
-			break;
272df6
-		default:
272df6
-			return (ISC_R_NOTFOUND);
272df6
-		}
272df6
-		localaddr = &any;
272df6
-	}
272df6
+	       DNS_DISPATCHATTR_EXCLUSIVE | DNS_DISPATCHATTR_CONNECTED;
272df6
 
272df6
 	LOCK(&mgr->lock);
272df6
 	disp = ISC_LIST_HEAD(mgr->list);
272df6
@@ -2872,7 +2857,8 @@ dns_dispatch_gettcp(dns_dispatchmgr_t *mgr, isc_sockaddr_t *destaddr,
272df6
 								&peeraddr);
272df6
 			if (result == ISC_R_SUCCESS &&
272df6
 			    isc_sockaddr_equal(destaddr, &peeraddr) &&
272df6
-			    isc_sockaddr_eqaddr(localaddr, &sockname)) {
272df6
+			    (localaddr == NULL ||
272df6
+			     isc_sockaddr_eqaddr(localaddr, &sockname))) {
272df6
 				/* attach */
272df6
 				disp->refcount++;
272df6
 				*dispp = disp;
272df6
diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c
272df6
index d9b1df1..f357c63 100644
272df6
--- a/lib/isccfg/namedconf.c
272df6
+++ b/lib/isccfg/namedconf.c
272df6
@@ -959,6 +959,7 @@ options_clauses[] = {
272df6
 	{ "host-statistics-max", &cfg_type_uint32, CFG_CLAUSEFLAG_NOTIMP },
272df6
 	{ "hostname", &cfg_type_qstringornone, 0 },
272df6
 	{ "interface-interval", &cfg_type_uint32, 0 },
272df6
+	{ "keep-response-order", &cfg_type_bracketed_aml, 0 },
272df6
 	{ "listen-on", &cfg_type_listenon, CFG_CLAUSEFLAG_MULTI },
272df6
 	{ "listen-on-v6", &cfg_type_listenon, CFG_CLAUSEFLAG_MULTI },
272df6
 	{ "managed-keys-directory", &cfg_type_qstring, 0 },
272df6
-- 
272df6
2.20.1
272df6