]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add NS_CLIENT_MOCKREPLY - if defined, BIND will reply with empty wpk-mockreply
authorWitold Kręcicki <wpk@isc.org>
Mon, 26 Nov 2018 09:42:27 +0000 (10:42 +0100)
committerWitold Krecicki <wpk@isc.org>
Mon, 26 Nov 2018 10:42:38 +0000 (05:42 -0500)
answers to each query, without doing any processing. This can
be used to test network stack performance.

lib/ns/client.c

index 1f9f47218c7bbfc00742066f0d2ac8103e61ddfb..cd4a33a7e1bea14415a3201c7ff5bb7fb2d220e3 100644 (file)
@@ -1049,6 +1049,51 @@ ns_client_sendraw(ns_client_t *client, dns_message_t *message) {
        ns_client_next(client, result);
 }
 
+#ifdef NS_CLIENT_MOCKREPLY
+static isc_result_t
+client_mockreply(ns_client_t *client, uint16_t id) {
+       isc_result_t result;
+       unsigned char *data;
+       isc_buffer_t buffer;
+       isc_buffer_t tcpbuffer;
+       isc_region_t r;
+       unsigned char sendbuf[SEND_BUFFER_SIZE];
+       result = client_allocsendbuf(client, &buffer, &tcpbuffer, 0,
+                                    sendbuf, &data);
+       if (result != ISC_R_SUCCESS) {
+               goto done;
+       }
+
+       isc_buffer_putuint16(&buffer, id);
+       isc_buffer_putuint8(&buffer, 0x81);
+       isc_buffer_putuint8(&buffer, 0x80);
+       isc_buffer_putuint16(&buffer, 0);
+       isc_buffer_putuint16(&buffer, 0);
+       isc_buffer_putuint16(&buffer, 0);
+       isc_buffer_putuint16(&buffer, 0);
+       if (client->sendcb != NULL) {
+               client->sendcb(&buffer);
+       } else if (TCP_CLIENT(client)) {
+               isc_buffer_usedregion(&buffer, &r);
+               isc_buffer_putuint16(&tcpbuffer, (uint16_t) r.length);
+               isc_buffer_add(&tcpbuffer, r.length);
+               result = client_sendpkg(client, &tcpbuffer);
+       } else {
+               result = client_sendpkg(client, &buffer);
+       }
+       if (result == ISC_R_SUCCESS) {
+               return (ISC_R_SUCCESS);
+       }
+done:
+       if (client->tcpbuf != NULL) {
+               isc_mem_put(client->mctx, client->tcpbuf, TCP_BUFFER_SIZE);
+               client->tcpbuf = NULL;
+       }
+       ns_client_next(client, result);
+       return (ISC_R_SUCCESS);
+}
+#endif
+
 static void
 client_send(ns_client_t *client) {
        isc_result_t result;
@@ -2335,6 +2380,26 @@ ns__client_request(isc_task_t *task, isc_event_t *event) {
                return;
        }
 
+#ifdef NS_CLIENT_MOCKREPLY
+       result = dns_message_peekheader(buffer, &id, &flags);
+       if (result != ISC_R_SUCCESS) {
+               /*
+                * There isn't enough header to determine whether
+                * this was a request or a response.  Drop it.
+                */
+               ns_client_next(client, result);
+               return;
+       }
+       /*
+        * client_mockreply always return success, but we want to
+        * make the return conditional to fool compilers that the
+        * code below is reachable.
+        */
+       if (client_mockreply(client, id) == ISC_R_SUCCESS) {
+               return;
+       }
+#endif
+
        isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr);
 
 #if NS_CLIENT_DROPPORT