From c653e8502cbe311cc40c8a50e0b8025ab1aaef9c Mon Sep 17 00:00:00 2001 From: Christian Huitema Date: Wed, 22 Mar 2017 15:50:26 -0700 Subject: [PATCH] Minor fixes in MDNS code to make sure it does work after the recent loop tightening. Suppressing the warning about mapping the 64 bit timeout value to a 32 bit integer, based on the comments that the "maximum timeout used in practice is 6553500ms." If that really is the case, we do not need to support 64 bit integers in the dict structure. --- src/context.c | 8 +++++--- src/general.c | 3 ++- src/mdns.c | 4 ++-- src/util-internal.c | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/context.c b/src/context.c index efb5eca3..363ecf24 100644 --- a/src/context.c +++ b/src/context.c @@ -756,7 +756,7 @@ _getdns_upstream_shutdown(getdns_upstream *upstream) uint16_t conn_retries = upstream->upstreams->tls_connection_retries; /* [TLS1]TODO: This arbitrary logic at the moment - review and improve!*/ if (upstream->conn_setup_failed >= conn_retries - || (upstream->conn_shutdowns >= conn_retries*GETDNS_TRANSPORT_FAIL_MULT + || (upstream->conn_shutdowns >= conn_retries*((unsigned)GETDNS_TRANSPORT_FAIL_MULT) && upstream->total_responses == 0) || (upstream->conn_completed >= conn_retries && upstream->total_responses == 0 && @@ -3569,10 +3569,12 @@ _get_context_settings(getdns_context* context) return NULL; /* int fields */ + /* the timeouts are stored as uint64, but the value maximum used in + practice is 6553500ms, so we just trim the value to be on the safe side. */ if ( getdns_dict_set_int(result, "timeout", - context->timeout) + (context->timeout > 0xFFFFFFFFull)? 0xFFFFFFFF: (uint32_t) context->timeout) || getdns_dict_set_int(result, "idle_timeout", - context->idle_timeout) + (context->idle_timeout > 0xFFFFFFFFull) ? 0xFFFFFFFF : (uint32_t) context->idle_timeout) || getdns_dict_set_int(result, "limit_outstanding_queries", context->limit_outstanding_queries) || getdns_dict_set_int(result, "dnssec_allowed_skew", diff --git a/src/general.c b/src/general.c index 8d780eb7..d05d19ee 100644 --- a/src/general.c +++ b/src/general.c @@ -585,11 +585,12 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop, /* Check whether the name belongs in the MDNS space */ if (!(r = _getdns_mdns_namespace_check(req))) { - req->is_dns_request = 0; + req->is_dns_request = 1; // Submit the query to the MDNS transport. for (netreq_p = req->netreqs ; !r && (netreq = *netreq_p) ; netreq_p++) { + netreq->owner = req; if ((r = _getdns_submit_mdns_request(netreq))) { if (r == DNS_REQ_FINISHED) { if (return_netreq_p) diff --git a/src/mdns.c b/src/mdns.c index 8a63f013..1629fd14 100644 --- a/src/mdns.c +++ b/src/mdns.c @@ -1584,7 +1584,7 @@ static getdns_return_t mdns_initialize_continuous_request(getdns_network_req *ne { GETDNS_CLEAR_EVENT(dnsreq->loop, &netreq->event); GETDNS_SCHEDULE_EVENT( - dnsreq->loop, -1, dnsreq->context->timeout, + dnsreq->loop, -1, dnsreq->context->timeout*1000, getdns_eventloop_event_init(&netreq->event, netreq, NULL, NULL, mdns_mcast_timeout_cb)); } @@ -1813,7 +1813,7 @@ mdns_udp_write_cb(void *userarg) return; } GETDNS_SCHEDULE_EVENT( - dnsreq->loop, netreq->fd, dnsreq->context->timeout, + dnsreq->loop, netreq->fd, dnsreq->context->timeout*1000, getdns_eventloop_event_init(&netreq->event, netreq, mdns_udp_read_cb, NULL, mdns_timeout_cb)); } diff --git a/src/util-internal.c b/src/util-internal.c index fe05cd83..48242eb1 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -862,7 +862,7 @@ _getdns_create_call_reporting_dict( return NULL; } } else{ - uint32_t idle_timeout = netreq->upstream->keepalive_timeout; + uint32_t idle_timeout = (uint32_t) netreq->upstream->keepalive_timeout; if (getdns_dict_set_int( netreq_debug, "idle timeout in ms", idle_timeout)) { getdns_dict_destroy(netreq_debug); return NULL;