]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Refactor code sending a query to the next server upon a timeout
authorMichał Kępień <michal@isc.org>
Tue, 8 Jan 2019 10:17:39 +0000 (11:17 +0100)
committerMichał Kępień <michal@isc.org>
Tue, 8 Jan 2019 10:17:39 +0000 (11:17 +0100)
When a query times out and another server is available for querying
within the same lookup, the timeout handler - connect_timeout() - is
responsible for sending the query to the next server.  Extract the
relevant part of connect_timeout() to a separate function in order to
improve code readability.

bin/dig/dighost.c

index 400fcaf34fe81cef02c31ac6d87bc5db1a4cf33e..2f980ab47446eb07b1ef56dd78e7421b72c16d72 100644 (file)
@@ -2880,6 +2880,36 @@ send_udp(dig_query_t *query) {
        sendcount++;
 }
 
+/*%
+ * If there are more servers available for querying within 'lookup', initiate a
+ * TCP or UDP query to the next available server and return true; otherwise,
+ * return false.
+ */
+static bool
+try_next_server(dig_lookup_t *lookup) {
+       dig_query_t *current_query, *next_query;
+
+       current_query = lookup->current_query;
+       if (current_query == NULL || !ISC_LINK_LINKED(current_query, link)) {
+               return (false);
+       }
+
+       next_query = ISC_LIST_NEXT(current_query, link);
+       if (next_query == NULL) {
+               return (false);
+       }
+
+       debug("trying next server...");
+
+       if (lookup->tcp_mode) {
+               send_tcp_connect(next_query);
+       } else {
+               send_udp(next_query);
+       }
+
+       return (true);
+}
+
 /*%
  * IO timeout handler, used for both connect and recv timeouts.  If
  * retries are still allowed, either resend the UDP packet or queue a
@@ -2888,7 +2918,7 @@ send_udp(dig_query_t *query) {
 static void
 connect_timeout(isc_task_t *task, isc_event_t *event) {
        dig_lookup_t *l = NULL;
-       dig_query_t *query = NULL, *cq;
+       dig_query_t *query = NULL;
 
        UNUSED(task);
        REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE);
@@ -2908,18 +2938,12 @@ connect_timeout(isc_task_t *task, isc_event_t *event) {
                return;
        }
 
-       if ((query != NULL) && (query->lookup->current_query != NULL) &&
-           ISC_LINK_LINKED(query->lookup->current_query, link) &&
-           (ISC_LIST_NEXT(query->lookup->current_query, link) != NULL)) {
-               debug("trying next server...");
-               cq = query->lookup->current_query;
-               if (!l->tcp_mode)
-                       send_udp(ISC_LIST_NEXT(cq, link));
-               else {
-                       if (query->sock != NULL)
+       if (try_next_server(l)) {
+               if (l->tcp_mode) {
+                       if (query->sock != NULL) {
                                isc_socket_cancel(query->sock, NULL,
                                                  ISC_SOCKCANCEL_ALL);
-                       send_tcp_connect(ISC_LIST_NEXT(cq, link));
+                       }
                }
                UNLOCK_LOOKUP;
                return;