From: Michał Kępień Date: Tue, 8 Jan 2019 10:17:39 +0000 (+0100) Subject: Refactor code sending a query to the next server upon a timeout X-Git-Tag: v9.13.6~71^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c108fc5c6e318184f32dae306baa57ef3ad545c0;p=thirdparty%2Fbind9.git Refactor code sending a query to the next server upon a timeout 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. --- diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 400fcaf34fe..2f980ab4744 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -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;