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