From c74bfb53392ea3575253e1f37dec16bee1b1fc66 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Wed, 15 Jun 2016 11:04:11 +0200 Subject: [PATCH 1/8] Pass NULL to select when timeout is infinite --- src/test/getdns_query.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/getdns_query.c b/src/test/getdns_query.c index bce8294d..9fd025d6 100644 --- a/src/test/getdns_query.c +++ b/src/test/getdns_query.c @@ -204,11 +204,12 @@ void my_eventloop_run_once(getdns_eventloop *loop, int blocking) if (! blocking || now > timeout) { tv.tv_sec = 0; tv.tv_usec = 0; - } else { + } else if (timeout != (uint64_t)-1) { tv.tv_sec = (timeout - now) / 1000000; tv.tv_usec = (timeout - now) % 1000000; } - if (select(max_fd + 1, &readfds, &writefds, NULL, &tv) < 0) { + if (select(max_fd + 1, &readfds, &writefds, NULL, + (timeout == ((uint64_t)-1) ? NULL : &tv)) < 0) { perror("select() failed"); exit(EXIT_FAILURE); } From c0187a19ea0da5332b66cc4fba5e00d96ad96705 Mon Sep 17 00:00:00 2001 From: Sara Dickinson Date: Wed, 15 Jun 2016 17:05:58 +0100 Subject: [PATCH 2/8] Quick fix for TLS timeouts not re-using a connection. Better solution is needed. Also minor fixes in getdns_query: - spurious semicolon (caused build warning) - build warning for initialised variable - have getdns_query honour the CLASS in the incoming query --- src/stub.c | 25 ++++++++++++++----------- src/test/getdns_query.c | 13 +++++++++++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/stub.c b/src/stub.c index 61e18b57..2962b3fb 100644 --- a/src/stub.c +++ b/src/stub.c @@ -495,14 +495,17 @@ stub_cleanup(getdns_network_req *netreq) } static int -tls_cleanup(getdns_upstream *upstream) +tls_cleanup(getdns_upstream *upstream, int handshake_fail) { DEBUG_STUB("%s %-35s: FD: %d\n", STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd); if (upstream->tls_obj != NULL) SSL_free(upstream->tls_obj); upstream->tls_obj = NULL; - upstream->tls_hs_state = GETDNS_HS_FAILED; + /* This will prevent the connection from being tried again for the cases + where we know it didn't work. Otherwise leave it to try again.*/ + if (handshake_fail) + upstream->tls_hs_state = GETDNS_HS_FAILED; /* Reset timeout on failure*/ GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event); GETDNS_SCHEDULE_EVENT(upstream->loop, upstream->fd, TIMEOUT_FOREVER, @@ -514,6 +517,8 @@ tls_cleanup(getdns_upstream *upstream) static void upstream_erred(getdns_upstream *upstream) { + DEBUG_STUB("%s %-35s: FD: %d\n", + STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd); getdns_network_req *netreq; while ((netreq = upstream->write_queue)) { @@ -588,7 +593,7 @@ upstream_tls_timeout_cb(void *userarg) DEBUG_STUB("%s %-35s: FD: %d\n", STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd); /* Clean up and trigger a write to let the fallback code to its job */ - tls_cleanup(upstream); + tls_cleanup(upstream, 1); /* Need to handle the case where the far end doesn't respond to a * TCP SYN and doesn't do a reset (as is the case with e.g. 8.8.8.8@853). @@ -616,7 +621,7 @@ stub_tls_timeout_cb(void *userarg) DEBUG_STUB("%s %-35s: MSG: %p\n", STUB_DEBUG_CLEANUP, __FUNCTION__, netreq); /* Clean up and trigger a write to let the fallback code to its job */ - tls_cleanup(upstream); + tls_cleanup(upstream, 0); /* Need to handle the case where the far end doesn't respond to a * TCP SYN and doesn't do a reset (as is the case with e.g. 8.8.8.8@853). @@ -1021,7 +1026,7 @@ tls_do_handshake(getdns_upstream *upstream) DEBUG_STUB("%s %-35s: FD: %d Handshake failed %d\n", STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd, want); - return tls_cleanup(upstream); + return tls_cleanup(upstream, 1); } } upstream->tls_hs_state = GETDNS_HS_DONE; @@ -1069,7 +1074,7 @@ tls_connected(getdns_upstream* upstream) int q = tcp_connected(upstream); if (q != 0) { if (q == STUB_TCP_ERROR) - tls_cleanup(upstream); + tls_cleanup(upstream, 0); return q; } @@ -1798,8 +1803,8 @@ upstream_reschedule_events(getdns_upstream *upstream, size_t idle_timeout) { GETDNS_SCHEDULE_EVENT(upstream->loop, upstream->fd, TIMEOUT_FOREVER, &upstream->event); else { - DEBUG_STUB("%s %-35s: FD: %d Connection idle \n", - STUB_DEBUG_SCHEDULE, __FUNCTION__, upstream->fd); + DEBUG_STUB("%s %-35s: FD: %d Connection idle - timeout is %d\n", + STUB_DEBUG_SCHEDULE, __FUNCTION__, upstream->fd, (int)idle_timeout); upstream->event.timeout_cb = upstream_idle_timeout_cb; if (upstream->tcp.write_error != 0) idle_timeout = 0; @@ -1890,7 +1895,6 @@ _getdns_submit_stub_request(getdns_network_req *netreq) case GETDNS_TRANSPORT_TLS: case GETDNS_TRANSPORT_TCP: upstream_schedule_netreq(netreq->upstream, netreq); - /* TODO[TLS]: Change scheduling for sync calls. */ /* For TLS, set a short timeout to catch setup problems. This is reset when the connection is successful.*/ GETDNS_CLEAR_EVENT(dnsreq->loop, &netreq->event); @@ -1958,8 +1962,7 @@ _getdns_submit_stub_request(getdns_network_req *netreq) GETDNS_SCHEDULE_EVENT( dnsreq->loop, -1, - ( transport == GETDNS_TRANSPORT_TLS - ? dnsreq->context->timeout /2 : dnsreq->context->timeout), + dnsreq->context->timeout, getdns_eventloop_event_init( &netreq->event, netreq, NULL, NULL, diff --git a/src/test/getdns_query.c b/src/test/getdns_query.c index 9fd025d6..640e0b59 100644 --- a/src/test/getdns_query.c +++ b/src/test/getdns_query.c @@ -2207,7 +2207,7 @@ void servfail(dns_msg *msg, getdns_dict **resp_p) return; if (!getdns_dict_get_dict(msg->query, "header", &dict)) getdns_dict_set_dict(*resp_p, "header", dict); - if (!getdns_dict_get_dict(msg->query, "question", &dict)); + if (!getdns_dict_get_dict(msg->query, "question", &dict)) getdns_dict_set_dict(*resp_p, "question", dict); (void) getdns_dict_set_int( *resp_p, "/header/rcode", GETDNS_RCODE_SERVFAIL); @@ -2332,12 +2332,13 @@ getdns_return_t schedule_request(dns_msg *msg) getdns_bindata *qname; char *qname_str = NULL; uint32_t qtype; + uint32_t qclass; getdns_return_t r; getdns_dict *header; uint32_t n; getdns_list *list; getdns_transaction_t transaction_id; - getdns_dict *qext; + getdns_dict *qext = NULL; if (!query_extensions_spc && !(query_extensions_spc = getdns_dict_create())) @@ -2418,6 +2419,14 @@ getdns_return_t schedule_request(dns_msg *msg) fprintf(stderr, "Could get qtype from query: %s\n", getdns_get_errorstr_by_id(r)); + else if ((r=getdns_dict_get_int(msg->query,"/question/qclass",&qclass))) + fprintf(stderr, "Could get qclass from query: %s\n", + getdns_get_errorstr_by_id(r)); + + else if ((r = getdns_dict_set_int(qext, "specify_class", qclass))) + fprintf(stderr, "Could set class from query: %s\n", + getdns_get_errorstr_by_id(r)); + else if ((r = getdns_general(context, qname_str, qtype, qext, msg, &transaction_id, request_cb))) fprintf(stderr, "Could not schedule query: %s\n", From 3c7758fdbc0cd07ee4d3e1c5d988fff39df3736d Mon Sep 17 00:00:00 2001 From: Sara Dickinson Date: Thu, 16 Jun 2016 10:47:43 +0100 Subject: [PATCH 3/8] Minor testing updates: - add option to use IPv6 for manual transport tests - add recursion mode to call_reporting --- src/dict.c | 1 + src/test/check_getdns_context_set_dns_transport.h | 12 +++++++++++- src/test/tests_transports.sh | 11 +++++++---- src/util-internal.c | 13 ++++++++++--- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/dict.c b/src/dict.c index 8e7eec8f..07d80e51 100644 --- a/src/dict.c +++ b/src/dict.c @@ -1054,6 +1054,7 @@ getdns_pp_dict(gldns_buffer * buf, size_t indent, strcmp(item->node.key, "append_name") == 0 || strcmp(item->node.key, "follow_redirects") == 0 || strcmp(item->node.key, "transport") == 0 || + strcmp(item->node.key, "resolution_mode") == 0 || strcmp(item->node.key, "resolution_type") == 0 || strcmp(item->node.key, "tls_authentication") == 0 ) && (strval = diff --git a/src/test/check_getdns_context_set_dns_transport.h b/src/test/check_getdns_context_set_dns_transport.h index c1135045..af5f7fe6 100644 --- a/src/test/check_getdns_context_set_dns_transport.h +++ b/src/test/check_getdns_context_set_dns_transport.h @@ -131,6 +131,7 @@ struct getdns_dict *extensions = getdns_dict_create(); uint32_t tc; uint32_t transport; + uint32_t mode; /* Note that stricly this test just establishes that the requested transport and the reported transport are consistent, it does not guarentee which @@ -157,6 +158,9 @@ ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/transport", &transport), GETDNS_RETURN_GOOD, "Failed to extract \"transport\""); ASSERT_RC(transport, GETDNS_TRANSPORT_UDP, "Query did not go over UDP"); + ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_mode", &mode), + GETDNS_RETURN_GOOD, "Failed to extract \"resolution_mode\""); + ASSERT_RC(mode, GETDNS_RESOLUTION_STUB, "Query did not use stub mode"); ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc), GETDNS_RETURN_GOOD, "Failed to extract \"tc\""); ASSERT_RC(tc, 1, "Packet not trucated as expected"); @@ -208,6 +212,7 @@ struct getdns_dict *response = NULL; struct getdns_dict *extensions = getdns_dict_create(); uint32_t status; + uint32_t mode; uint32_t tc; /* Recursive mode does not report the transport used and does not answer @@ -239,13 +244,18 @@ CONTEXT_CREATE(TRUE); /* Re-do over TCP */ + ASSERT_RC(getdns_dict_set_int(extensions,"return_call_reporting", GETDNS_EXTENSION_TRUE), + GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()"); ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_TCP_ONLY), GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()"); ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512), GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()"); ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response), GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()"); - + + ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_mode", &mode), + GETDNS_RETURN_GOOD, "Failed to extract \"resolution_mode\""); + ASSERT_RC(mode, GETDNS_RESOLUTION_RECURSING, "Query did not use Recursive mode"); ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc), GETDNS_RETURN_GOOD, "Failed to extract \"tc\""); ASSERT_RC(tc, 0, "Packet trucated - not as expected"); diff --git a/src/test/tests_transports.sh b/src/test/tests_transports.sh index 68b80568..13e5b6b6 100755 --- a/src/test/tests_transports.sh +++ b/src/test/tests_transports.sh @@ -2,7 +2,9 @@ DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) SERVER_IP="8.8.8.8" +SERVER_IPv6="2001:4860:4860::8888" TLS_SERVER_IP="185.49.141.38~getdnsapi.net" +TLS_SERVER_IPv6="2a04:b900:0:100::38~getdnsapi.net" TLS_SERVER_KEY="foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc9S=" TLS_SERVER_WRONG_KEY="foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc1S=" GOOD_RESULT_SYNC="Status was: At least one response was returned" @@ -62,21 +64,22 @@ usage () { echo " -t server configured for TLS, TCP and UDP" echo " (This must include the hostname e.g. 185.49.141.38~getdnsapi.net)" echo " -k SPKI pin for server configured for TLS, TCP and UDP" + echo " -i Use IPv6 addresses (when using default servers)" } -while getopts ":p:s:t:k:dh" opt; do +while getopts ":p:s:t:k:idh" opt; do case $opt in - d ) set -x ;; + d ) set -x ; echo "DEBUG mode set" ;; p ) DIR=$OPTARG ;; s ) SERVER_IP=$OPTARG ; echo "Setting server to $OPTARG" ;; t ) TLS_SERVER_IP=$OPTARG ; echo "Setting TLS server to $OPTARG" ;; k ) TLS_SERVER_KEY=$OPTARG ; echo "Setting TLS server key to $OPTARG" ;; + i ) SERVER_IP=$SERVER_IPv6; TLS_SERVER_IP=$TLS_SERVER_IPv6 ; echo "Using IPv6" ;; h ) usage ; exit ;; esac done TLS_SERVER_IP_NO_NAME=`echo ${TLS_SERVER_IP%~*}` -echo $TLS_SERVER_IP_NO_NAME TLS_SERVER_IP_WRONG_NAME=`echo ${TLS_SERVER_IP::${#TLS_SERVER_IP}-1}` GOOD_QUERIES=( @@ -100,7 +103,7 @@ NOT_AVAILABLE_QUERIES=( "-s -A -q getdnsapi.net -l L @${SERVER_IP}" "-s -A -q getdnsapi.net -l L -m @${TLS_SERVER_IP_WRONG_NAME}" "-s -A -q getdnsapi.net -l L -m @${TLS_SERVER_IP_NO_NAME}" -"-s -A -q getdnsapi.net -l L -m @${TLS_SERVER_IP_NO_NAME} ${TLS_SERVER_WRONG_KEY}") +"-s -A -q getdnsapi.net -l L -m @${TLS_SERVER_IP_NO_NAME} -K pin-sha256=\"${TLS_SERVER_WRONG_KEY}\"") echo "Starting transport test" diff --git a/src/util-internal.c b/src/util-internal.c index aa255e0e..ae3f071b 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -812,12 +812,19 @@ _getdns_create_call_reporting_dict( getdns_dict_destroy(netreq_debug); return NULL; - } else if (!netreq->upstream) - + } else if (!netreq->upstream) { + if (getdns_dict_set_int( netreq_debug, "resolution_mode", GETDNS_RESOLUTION_RECURSING)) { + getdns_dict_destroy(netreq_debug); + return NULL; + } /* Nothing more for full recursion */ return netreq_debug; + } - + if (getdns_dict_set_int( netreq_debug, "resolution_mode", GETDNS_RESOLUTION_STUB)) { + getdns_dict_destroy(netreq_debug); + return NULL; + } /* Stub resolver debug data */ _getdns_sockaddr_to_dict( context, &netreq->upstream->addr, &address_debug); From 497d87a028289ab569e3c180b73f7b8395db0db6 Mon Sep 17 00:00:00 2001 From: Sara Dickinson Date: Fri, 17 Jun 2016 11:25:21 +0100 Subject: [PATCH 4/8] Correct the name to resolution_type --- src/dict.c | 3 +-- src/test/check_getdns_context_set_dns_transport.h | 8 ++++---- src/util-internal.c | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/dict.c b/src/dict.c index 07d80e51..e7294e62 100644 --- a/src/dict.c +++ b/src/dict.c @@ -1053,8 +1053,7 @@ getdns_pp_dict(gldns_buffer * buf, size_t indent, strcmp(item->node.key, "status") == 0 || strcmp(item->node.key, "append_name") == 0 || strcmp(item->node.key, "follow_redirects") == 0 || - strcmp(item->node.key, "transport") == 0 || - strcmp(item->node.key, "resolution_mode") == 0 || + strcmp(item->node.key, "transport") == 0 || strcmp(item->node.key, "resolution_type") == 0 || strcmp(item->node.key, "tls_authentication") == 0 ) && (strval = diff --git a/src/test/check_getdns_context_set_dns_transport.h b/src/test/check_getdns_context_set_dns_transport.h index af5f7fe6..1985eac6 100644 --- a/src/test/check_getdns_context_set_dns_transport.h +++ b/src/test/check_getdns_context_set_dns_transport.h @@ -158,8 +158,8 @@ ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/transport", &transport), GETDNS_RETURN_GOOD, "Failed to extract \"transport\""); ASSERT_RC(transport, GETDNS_TRANSPORT_UDP, "Query did not go over UDP"); - ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_mode", &mode), - GETDNS_RETURN_GOOD, "Failed to extract \"resolution_mode\""); + ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_type", &mode), + GETDNS_RETURN_GOOD, "Failed to extract \"resolution_type\""); ASSERT_RC(mode, GETDNS_RESOLUTION_STUB, "Query did not use stub mode"); ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc), GETDNS_RETURN_GOOD, "Failed to extract \"tc\""); @@ -253,8 +253,8 @@ ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response), GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()"); - ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_mode", &mode), - GETDNS_RETURN_GOOD, "Failed to extract \"resolution_mode\""); + ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/resolution_type", &mode), + GETDNS_RETURN_GOOD, "Failed to extract \"resolution_type\""); ASSERT_RC(mode, GETDNS_RESOLUTION_RECURSING, "Query did not use Recursive mode"); ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc), GETDNS_RETURN_GOOD, "Failed to extract \"tc\""); diff --git a/src/util-internal.c b/src/util-internal.c index ae3f071b..ca04c7f5 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -813,7 +813,7 @@ _getdns_create_call_reporting_dict( return NULL; } else if (!netreq->upstream) { - if (getdns_dict_set_int( netreq_debug, "resolution_mode", GETDNS_RESOLUTION_RECURSING)) { + if (getdns_dict_set_int( netreq_debug, "resolution_type", GETDNS_RESOLUTION_RECURSING)) { getdns_dict_destroy(netreq_debug); return NULL; } @@ -821,7 +821,7 @@ _getdns_create_call_reporting_dict( return netreq_debug; } - if (getdns_dict_set_int( netreq_debug, "resolution_mode", GETDNS_RESOLUTION_STUB)) { + if (getdns_dict_set_int( netreq_debug, "resolution_type", GETDNS_RESOLUTION_STUB)) { getdns_dict_destroy(netreq_debug); return NULL; } From 3634fff4dd42857c1a270746c4a260771a9c8777 Mon Sep 17 00:00:00 2001 From: Robert Groenenberg Date: Mon, 20 Jun 2016 18:39:15 +0200 Subject: [PATCH 5/8] Return call_reporting info in case of timeout, so that we can see which server did not respond. --- src/stub.c | 7 +++++-- src/types-internal.h | 3 ++- src/util-internal.c | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/stub.c b/src/stub.c index 2962b3fb..488da2fd 100644 --- a/src/stub.c +++ b/src/stub.c @@ -91,6 +91,7 @@ static int upstream_connect(getdns_upstream *upstream, static int fallback_on_write(getdns_network_req *netreq); static void stub_timeout_cb(void *userarg); +static uint64_t _getdns_get_time_as_uintt64() /*****************************/ /* General utility functions */ /*****************************/ @@ -564,9 +565,11 @@ stub_timeout_cb(void *userarg) stub_next_upstream(netreq); stub_cleanup(netreq); if (netreq->fd >= 0) close(netreq->fd); - if (netreq->owner->user_callback) + if (netreq->owner->user_callback) { + netreq->state = NET_REQ_TIMED_OUT; + netreq->debug_end_time = _getdns_get_time_as_uintt64(); (void) _getdns_context_request_timed_out(netreq->owner); - else { + } else { netreq->state = NET_REQ_FINISHED; _getdns_check_dns_req_complete(netreq->owner); } diff --git a/src/types-internal.h b/src/types-internal.h index f63fde13..a43bd8f6 100644 --- a/src/types-internal.h +++ b/src/types-internal.h @@ -157,7 +157,8 @@ typedef enum network_req_state_enum NET_REQ_NOT_SENT, NET_REQ_IN_FLIGHT, NET_REQ_FINISHED, - NET_REQ_CANCELED + NET_REQ_CANCELED, + NET_REQ_TIMED_OUT } network_req_state; diff --git a/src/util-internal.c b/src/util-internal.c index ca04c7f5..f3295ec4 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -1189,6 +1189,25 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request) netreq->response_len, netreq->response)) goto error; } + if (!nreplies && call_reporting) { + for ( netreq_p = completed_request->netreqs + ; (netreq = *netreq_p) ; netreq_p++) { + /* Add call_reporting info for timed out request */ + if (netreq->state == NET_REQ_TIMED_OUT) { + if (!(netreq_debug = + _getdns_create_call_reporting_dict(context,netreq))) + goto error; + + if (_getdns_list_append_this_dict( + call_reporting, netreq_debug)) { + + getdns_dict_destroy(netreq_debug); + goto error; + } + } + } + } + if (_getdns_dict_set_this_list(result, "replies_tree", replies_tree)) goto error; replies_tree = NULL; From 60c6c8d8ca66f3f64dfc41c2f66dc539bbd8fd53 Mon Sep 17 00:00:00 2001 From: Robert Groenenberg Date: Tue, 21 Jun 2016 13:19:11 +0200 Subject: [PATCH 6/8] Fixed build --- src/stub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stub.c b/src/stub.c index 488da2fd..2126ee21 100644 --- a/src/stub.c +++ b/src/stub.c @@ -91,7 +91,7 @@ static int upstream_connect(getdns_upstream *upstream, static int fallback_on_write(getdns_network_req *netreq); static void stub_timeout_cb(void *userarg); -static uint64_t _getdns_get_time_as_uintt64() +static uint64_t _getdns_get_time_as_uintt64(); /*****************************/ /* General utility functions */ /*****************************/ From 03fcfc006f5379d8be137b7848ae632263bce75a Mon Sep 17 00:00:00 2001 From: Robert Groenenberg Date: Wed, 22 Jun 2016 14:40:21 +0200 Subject: [PATCH 7/8] Build fails with autoconf 2.63, works with 2.68. Found on CentOS 6.6. With autoconf268 (available from EPEL repo) it works. Looking at the update description of autoconf 2.64, the problem _might_ be fixed with that version already. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 0807f012..82a27f14 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -AC_PREREQ([2.56]) +AC_PREREQ([2.68]) AC_CONFIG_MACRO_DIRS([m4]) sinclude(./m4/acx_openssl.m4) sinclude(./m4/acx_getaddrinfo.m4) From a435932b04c4cc124863899525063b85c3ada969 Mon Sep 17 00:00:00 2001 From: wtoorop Date: Thu, 23 Jun 2016 14:02:55 +0200 Subject: [PATCH 8/8] Features/call reporting timeout (#1) * Timed out and canceled netreqs are finished too * Minor code duplication elemination * Blah typo * Embarrassing logic error --- src/dnssec.c | 12 +++--------- src/general.c | 3 +-- src/stub.c | 8 +++----- src/types-internal.h | 16 +++++++++------- src/util-internal.c | 45 ++++++++++++-------------------------------- 5 files changed, 28 insertions(+), 56 deletions(-) diff --git a/src/dnssec.c b/src/dnssec.c index 95c8cbbf..2e6425fb 100644 --- a/src/dnssec.c +++ b/src/dnssec.c @@ -2776,19 +2776,13 @@ static size_t count_outstanding_requests(chain_head *head) count += node->lock; - if (node->dnskey_req && - node->dnskey_req->state != NET_REQ_FINISHED && - node->dnskey_req->state != NET_REQ_CANCELED) + if (!_getdns_netreq_finished(node->dnskey_req)) count++; - if (node->ds_req && - node->ds_req->state != NET_REQ_FINISHED && - node->ds_req->state != NET_REQ_CANCELED) + if (!_getdns_netreq_finished(node->ds_req)) count++; - if (node->soa_req && - node->soa_req->state != NET_REQ_FINISHED && - node->soa_req->state != NET_REQ_CANCELED) + if (!_getdns_netreq_finished(node->soa_req)) count++; } return count + count_outstanding_requests(head->next); diff --git a/src/general.c b/src/general.c index 4b80dbdd..9de39116 100644 --- a/src/general.c +++ b/src/general.c @@ -104,8 +104,7 @@ _getdns_check_dns_req_complete(getdns_dns_req *dns_req) int results_found = 0, r; for (netreq_p = dns_req->netreqs; (netreq = *netreq_p); netreq_p++) - if (netreq->state != NET_REQ_FINISHED && - netreq->state != NET_REQ_CANCELED) + if (!_getdns_netreq_finished(netreq)) return; else if (netreq->response_len > 0) results_found = 1; diff --git a/src/stub.c b/src/stub.c index 2126ee21..4aa14dae 100644 --- a/src/stub.c +++ b/src/stub.c @@ -565,14 +565,12 @@ stub_timeout_cb(void *userarg) stub_next_upstream(netreq); stub_cleanup(netreq); if (netreq->fd >= 0) close(netreq->fd); - if (netreq->owner->user_callback) { - netreq->state = NET_REQ_TIMED_OUT; + netreq->state = NET_REQ_TIMED_OUT; + if (netreq->owner->user_callback) { netreq->debug_end_time = _getdns_get_time_as_uintt64(); (void) _getdns_context_request_timed_out(netreq->owner); - } else { - netreq->state = NET_REQ_FINISHED; + } else _getdns_check_dns_req_complete(netreq->owner); - } } diff --git a/src/types-internal.h b/src/types-internal.h index a43bd8f6..6f7d99ea 100644 --- a/src/types-internal.h +++ b/src/types-internal.h @@ -154,11 +154,12 @@ priv_getdns_context_mf(getdns_context *context); typedef enum network_req_state_enum { - NET_REQ_NOT_SENT, - NET_REQ_IN_FLIGHT, - NET_REQ_FINISHED, - NET_REQ_CANCELED, - NET_REQ_TIMED_OUT + NET_REQ_NOT_SENT = 0, + NET_REQ_IN_FLIGHT = 1, + NET_REQ_FINISHED = 2, /* Finish type in bits 2 and 3 */ + NET_REQ_CANCELED = 6, /* 2 + (1 << 2) */ + NET_REQ_TIMED_OUT = 10, /* 2 + (2 << 2) */ + NET_REQ_ERRORED = 14 /* 2 + (3 << 2) */ } network_req_state; @@ -256,11 +257,12 @@ typedef struct getdns_network_req uint8_t *response; size_t wire_data_sz; uint8_t wire_data[]; - - } getdns_network_req; +static inline int _getdns_netreq_finished(getdns_network_req *req) +{ return !req || (req->state & NET_REQ_FINISHED); } + /** * dns request - manages a number of network requests and * the initial data passed to getdns_general diff --git a/src/util-internal.c b/src/util-internal.c index f3295ec4..3a70f81c 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -1109,6 +1109,18 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request) for ( netreq_p = completed_request->netreqs ; (netreq = *netreq_p) ; netreq_p++) { + if (call_reporting && ( netreq->response_len + || netreq->state == NET_REQ_TIMED_OUT)) { + if (!(netreq_debug = + _getdns_create_call_reporting_dict(context,netreq))) + goto error; + + if (_getdns_list_append_this_dict( + call_reporting, netreq_debug)) + goto error; + + netreq_debug = NULL; + } if (! netreq->response_len) continue; @@ -1171,43 +1183,10 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request) getdns_dict_destroy(reply); goto error; } - - if (call_reporting) { - if (!(netreq_debug = - _getdns_create_call_reporting_dict(context,netreq))) - goto error; - - if (_getdns_list_append_this_dict( - call_reporting, netreq_debug)) { - - getdns_dict_destroy(netreq_debug); - goto error; - } - } - if (_getdns_list_append_const_bindata(replies_full, netreq->response_len, netreq->response)) goto error; } - if (!nreplies && call_reporting) { - for ( netreq_p = completed_request->netreqs - ; (netreq = *netreq_p) ; netreq_p++) { - /* Add call_reporting info for timed out request */ - if (netreq->state == NET_REQ_TIMED_OUT) { - if (!(netreq_debug = - _getdns_create_call_reporting_dict(context,netreq))) - goto error; - - if (_getdns_list_append_this_dict( - call_reporting, netreq_debug)) { - - getdns_dict_destroy(netreq_debug); - goto error; - } - } - } - } - if (_getdns_dict_set_this_list(result, "replies_tree", replies_tree)) goto error; replies_tree = NULL;