bc5dde
diff -up bind-9.9.4/bin/dig/dighost.c.send_buffers bind-9.9.4/bin/dig/dighost.c
bc5dde
--- bind-9.9.4/bin/dig/dighost.c.send_buffers	2013-10-31 14:22:20.296811613 +0100
bc5dde
+++ bind-9.9.4/bin/dig/dighost.c	2013-10-31 14:57:00.336400190 +0100
bc5dde
@@ -194,6 +194,7 @@ isc_boolean_t validated = ISC_TRUE;
bc5dde
 isc_entropy_t *entp = NULL;
bc5dde
 isc_mempool_t *commctx = NULL;
bc5dde
 isc_boolean_t debugging = ISC_FALSE;
bc5dde
+isc_boolean_t debugtiming = ISC_FALSE;
bc5dde
 isc_boolean_t memdebugging = ISC_FALSE;
bc5dde
 char *progname = NULL;
bc5dde
 isc_mutex_t lookup_lock;
bc5dde
@@ -553,6 +554,12 @@ debug(const char *format, ...) {
bc5dde
 
bc5dde
 	if (debugging) {
bc5dde
 		fflush(stdout);
bc5dde
+		if (debugtiming) {
bc5dde
+			struct timeval tv;
bc5dde
+			(void)gettimeofday(&tv, NULL);
bc5dde
+			fprintf(stderr, "%ld.%06ld: ", (long)tv.tv_sec,
bc5dde
+				(long)tv.tv_usec);
bc5dde
+		}
bc5dde
 		va_start(args, format);
bc5dde
 		vfprintf(stderr, format, args);
bc5dde
 		va_end(args);
bc5dde
@@ -2416,8 +2423,10 @@ send_done(isc_task_t *_task, isc_event_t
bc5dde
 
bc5dde
 	for  (b = ISC_LIST_HEAD(sevent->bufferlist);
bc5dde
 	      b != NULL;
bc5dde
-	      b = ISC_LIST_HEAD(sevent->bufferlist))
bc5dde
+	      b = ISC_LIST_HEAD(sevent->bufferlist)) {
bc5dde
 		ISC_LIST_DEQUEUE(sevent->bufferlist, b, link);
bc5dde
+		isc_mem_free(mctx, b);
bc5dde
+	}
bc5dde
 
bc5dde
 	query = event->ev_arg;
bc5dde
 	query->waiting_senddone = ISC_FALSE;
bc5dde
@@ -2609,6 +2618,17 @@ send_tcp_connect(dig_query_t *query) {
bc5dde
 	}
bc5dde
 }
bc5dde
 
bc5dde
+static isc_buffer_t *
bc5dde
+clone_buffer(isc_buffer_t *source) {
bc5dde
+	isc_buffer_t *buffer;
bc5dde
+	buffer = isc_mem_allocate(mctx, sizeof(*buffer));
bc5dde
+	if (buffer == NULL)
bc5dde
+		fatal("memory allocation failure in %s:%d",
bc5dde
+		      __FILE__, __LINE__);
bc5dde
+	*buffer = *source;
bc5dde
+	return (buffer);
bc5dde
+}
bc5dde
+
bc5dde
 /*%
bc5dde
  * Send a UDP packet to the remote nameserver, possible starting the
bc5dde
  * recv action as well.  Also make sure that the timer is running and
bc5dde
@@ -2618,6 +2638,7 @@ static void
bc5dde
 send_udp(dig_query_t *query) {
bc5dde
 	dig_lookup_t *l = NULL;
bc5dde
 	isc_result_t result;
bc5dde
+	isc_buffer_t *sendbuf;
bc5dde
 
bc5dde
 	debug("send_udp(%p)", query);
bc5dde
 
bc5dde
@@ -2664,14 +2685,16 @@ send_udp(dig_query_t *query) {
bc5dde
 		debug("recvcount=%d", recvcount);
bc5dde
 	}
bc5dde
 	ISC_LIST_INIT(query->sendlist);
bc5dde
-	ISC_LIST_ENQUEUE(query->sendlist, &query->sendbuf, link);
bc5dde
+	sendbuf = clone_buffer(&query->sendbuf);
bc5dde
+	ISC_LIST_ENQUEUE(query->sendlist, sendbuf, link);
bc5dde
 	debug("sending a request");
bc5dde
 	TIME_NOW(&query->time_sent);
bc5dde
 	INSIST(query->sock != NULL);
bc5dde
 	query->waiting_senddone = ISC_TRUE;
bc5dde
-	result = isc_socket_sendtov(query->sock, &query->sendlist,
bc5dde
-				    global_task, send_done, query,
bc5dde
-				    &query->sockaddr, NULL);
bc5dde
+	result = isc_socket_sendtov2(query->sock, &query->sendlist,
bc5dde
+				     global_task, send_done, query,
bc5dde
+				     &query->sockaddr, NULL,
bc5dde
+				     ISC_SOCKFLAG_NORETRY);
bc5dde
 	check_result(result, "isc_socket_sendtov");
bc5dde
 	sendcount++;
bc5dde
 }
bc5dde
@@ -2838,6 +2861,7 @@ static void
bc5dde
 launch_next_query(dig_query_t *query, isc_boolean_t include_question) {
bc5dde
 	isc_result_t result;
bc5dde
 	dig_lookup_t *l;
bc5dde
+	isc_buffer_t *buffer;
bc5dde
 
bc5dde
 	INSIST(!free_now);
bc5dde
 
bc5dde
@@ -2861,9 +2885,15 @@ launch_next_query(dig_query_t *query, is
bc5dde
 	isc_buffer_putuint16(&query->slbuf, (isc_uint16_t) query->sendbuf.used);
bc5dde
 	ISC_LIST_INIT(query->sendlist);
bc5dde
 	ISC_LINK_INIT(&query->slbuf, link);
bc5dde
-	ISC_LIST_ENQUEUE(query->sendlist, &query->slbuf, link);
bc5dde
-	if (include_question)
bc5dde
-		ISC_LIST_ENQUEUE(query->sendlist, &query->sendbuf, link);
bc5dde
+	if (!query->first_soa_rcvd) {
bc5dde
+		buffer = clone_buffer(&query->slbuf);
bc5dde
+		ISC_LIST_ENQUEUE(query->sendlist, buffer, link);
bc5dde
+		if (include_question) {
bc5dde
+			buffer = clone_buffer(&query->sendbuf);
bc5dde
+			ISC_LIST_ENQUEUE(query->sendlist, buffer, link);
bc5dde
+		}
bc5dde
+	}
bc5dde
+
bc5dde
 	ISC_LINK_INIT(&query->lengthbuf, link);
bc5dde
 	ISC_LIST_ENQUEUE(query->lengthlist, &query->lengthbuf, link);
bc5dde
 
bc5dde
diff -up bind-9.9.4/bin/dig/host.c.send_buffers bind-9.9.4/bin/dig/host.c
bc5dde
--- bind-9.9.4/bin/dig/host.c.send_buffers	2013-10-31 14:22:20.270811568 +0100
bc5dde
+++ bind-9.9.4/bin/dig/host.c	2013-10-31 14:22:20.328811669 +0100
bc5dde
@@ -638,6 +638,8 @@ pre_parse_args(int argc, char **argv) {
bc5dde
 		case 'w': break;
bc5dde
 		case 'C': break;
bc5dde
 		case 'D':
bc5dde
+			if (debugging)
bc5dde
+				debugtiming = ISC_TRUE;
bc5dde
 			debugging = ISC_TRUE;
bc5dde
 			break;
bc5dde
 		case 'N': break;
bc5dde
diff -up bind-9.9.4/bin/dig/include/dig/dig.h.send_buffers bind-9.9.4/bin/dig/include/dig/dig.h
bc5dde
--- bind-9.9.4/bin/dig/include/dig/dig.h.send_buffers	2013-10-31 14:22:20.270811568 +0100
bc5dde
+++ bind-9.9.4/bin/dig/include/dig/dig.h	2013-10-31 14:22:20.328811669 +0100
bc5dde
@@ -275,7 +275,7 @@ extern isc_boolean_t validated;
bc5dde
 extern isc_taskmgr_t *taskmgr;
bc5dde
 extern isc_task_t *global_task;
bc5dde
 extern isc_boolean_t free_now;
bc5dde
-extern isc_boolean_t debugging, memdebugging;
bc5dde
+extern isc_boolean_t debugging, debugtiming, memdebugging;
bc5dde
 
bc5dde
 extern char *progname;
bc5dde
 extern int tries;
bc5dde
diff -up bind-9.9.4/lib/isc/include/isc/namespace.h.send_buffers bind-9.9.4/lib/isc/include/isc/namespace.h
bc5dde
--- bind-9.9.4/lib/isc/include/isc/namespace.h.send_buffers	2013-09-05 07:09:08.000000000 +0200
bc5dde
+++ bind-9.9.4/lib/isc/include/isc/namespace.h	2013-10-31 14:22:20.328811669 +0100
bc5dde
@@ -106,6 +106,7 @@
bc5dde
 #define isc_socket_sendv isc__socket_sendv
bc5dde
 #define isc_socket_sendtov isc__socket_sendtov
bc5dde
 #define isc_socket_sendto2 isc__socket_sendto2
bc5dde
+#define isc_socket_sendtov2 isc__socket_sendtov2
bc5dde
 #define isc_socket_cleanunix isc__socket_cleanunix
bc5dde
 #define isc_socket_permunix isc__socket_permunix
bc5dde
 #define isc_socket_bind isc__socket_bind
bc5dde
diff -up bind-9.9.4/lib/isc/include/isc/socket.h.send_buffers bind-9.9.4/lib/isc/include/isc/socket.h
bc5dde
--- bind-9.9.4/lib/isc/include/isc/socket.h.send_buffers	2013-09-05 07:09:08.000000000 +0200
bc5dde
+++ bind-9.9.4/lib/isc/include/isc/socket.h	2013-10-31 14:22:20.328811669 +0100
bc5dde
@@ -866,6 +866,11 @@ isc_socket_sendtov(isc_socket_t *sock, i
bc5dde
 		   isc_task_t *task, isc_taskaction_t action, const void *arg,
bc5dde
 		   isc_sockaddr_t *address, struct in6_pktinfo *pktinfo);
bc5dde
 isc_result_t
bc5dde
+isc_socket_sendtov2(isc_socket_t *sock, isc_bufferlist_t *buflist,
bc5dde
+		    isc_task_t *task, isc_taskaction_t action, const void *arg,
bc5dde
+		    isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
bc5dde
+		    unsigned int flags);
bc5dde
+isc_result_t
bc5dde
 isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region,
bc5dde
 		   isc_task_t *task,
bc5dde
 		   isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
bc5dde
diff -up bind-9.9.4/lib/isc/unix/socket.c.send_buffers bind-9.9.4/lib/isc/unix/socket.c
bc5dde
--- bind-9.9.4/lib/isc/unix/socket.c.send_buffers	2013-10-31 14:22:20.293811608 +0100
bc5dde
+++ bind-9.9.4/lib/isc/unix/socket.c	2013-10-31 14:22:20.330811673 +0100
bc5dde
@@ -510,6 +510,11 @@ isc__socket_sendtov(isc_socket_t *sock,
bc5dde
 		    isc_task_t *task, isc_taskaction_t action, const void *arg,
bc5dde
 		    isc_sockaddr_t *address, struct in6_pktinfo *pktinfo);
bc5dde
 ISC_SOCKETFUNC_SCOPE isc_result_t
bc5dde
+isc__socket_sendtov2(isc_socket_t *sock, isc_bufferlist_t *buflist,
bc5dde
+		     isc_task_t *task, isc_taskaction_t action, const void *arg,
bc5dde
+		     isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
bc5dde
+		     unsigned int flags);
bc5dde
+ISC_SOCKETFUNC_SCOPE isc_result_t
bc5dde
 isc__socket_sendto2(isc_socket_t *sock, isc_region_t *region,
bc5dde
 		    isc_task_t *task,
bc5dde
 		    isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
bc5dde
@@ -4796,15 +4801,25 @@ ISC_SOCKETFUNC_SCOPE isc_result_t
bc5dde
 isc__socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist,
bc5dde
 		  isc_task_t *task, isc_taskaction_t action, const void *arg)
bc5dde
 {
bc5dde
-	return (isc__socket_sendtov(sock, buflist, task, action, arg, NULL,
bc5dde
-				    NULL));
bc5dde
+	return (isc__socket_sendtov2(sock, buflist, task, action, arg, NULL,
bc5dde
+				     NULL, 0));
bc5dde
 }
bc5dde
 
bc5dde
 ISC_SOCKETFUNC_SCOPE isc_result_t
bc5dde
-isc__socket_sendtov(isc_socket_t *sock0, isc_bufferlist_t *buflist,
bc5dde
+isc__socket_sendtov(isc_socket_t *sock, isc_bufferlist_t *buflist,
bc5dde
 		    isc_task_t *task, isc_taskaction_t action, const void *arg,
bc5dde
 		    isc_sockaddr_t *address, struct in6_pktinfo *pktinfo)
bc5dde
 {
bc5dde
+	return (isc__socket_sendtov2(sock, buflist, task, action, arg, address,
bc5dde
+				     pktinfo, 0));
bc5dde
+}
bc5dde
+
bc5dde
+ISC_SOCKETFUNC_SCOPE isc_result_t
bc5dde
+isc__socket_sendtov2(isc_socket_t *sock0, isc_bufferlist_t *buflist,
bc5dde
+		     isc_task_t *task, isc_taskaction_t action, const void *arg,
bc5dde
+		     isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
bc5dde
+		     unsigned int flags)
bc5dde
+{
bc5dde
 	isc__socket_t *sock = (isc__socket_t *)sock0;
bc5dde
 	isc_socketevent_t *dev;
bc5dde
 	isc__socketmgr_t *manager;
bc5dde
@@ -4837,7 +4852,7 @@ isc__socket_sendtov(isc_socket_t *sock0,
bc5dde
 		buffer = ISC_LIST_HEAD(*buflist);
bc5dde
 	}
bc5dde
 
bc5dde
-	return (socket_send(sock, dev, task, address, pktinfo, 0));
bc5dde
+	return (socket_send(sock, dev, task, address, pktinfo, flags));
bc5dde
 }
bc5dde
 
bc5dde
 ISC_SOCKETFUNC_SCOPE isc_result_t