Merge pull request #243 from wtoorop/bugfix/1.1.0-alpha3/replace__FUNCTION__

Use __func__ var when supported
This commit is contained in:
wtoorop 2016-12-15 08:25:51 +01:00 committed by GitHub
commit be29a01b20
14 changed files with 99 additions and 155 deletions

View File

@ -971,6 +971,14 @@ fi
#---- check for pthreads library #---- check for pthreads library
AC_SEARCH_LIBS([pthread_mutex_init],[pthread],[AC_DEFINE([HAVE_PTHREADS], [1], [Have pthreads library])], [AC_MSG_WARN([pthreads not available])]) AC_SEARCH_LIBS([pthread_mutex_init],[pthread],[AC_DEFINE([HAVE_PTHREADS], [1], [Have pthreads library])], [AC_MSG_WARN([pthreads not available])])
AC_MSG_CHECKING([whether the C compiler (${CC-cc}) supports the __func__ variable])
AC_LANG_PUSH(C)
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[char*s=__func__;]],[[]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE___FUNC__, [1], [Whether the C compiler support the __func__ variable])],
[AC_MSG_RESULT([no])])
AC_LANG_POP(C)
dnl ----- dnl -----
dnl ----- Start of "Things needed for gldns" section dnl ----- Start of "Things needed for gldns" section
@ -1087,6 +1095,12 @@ AC_DEFINE_UNQUOTED([MAX_CNAME_REFERRALS], [100], [The maximum number of cname re
AH_BOTTOM([ AH_BOTTOM([
#ifdef HAVE___FUNC__
#define __FUNC__ __func__
#else
#define __FUNC__ __FUNCTION__
#endif
#ifdef GETDNS_ON_WINDOWS #ifdef GETDNS_ON_WINDOWS
/* On windows it is allowed to increase the FD_SETSIZE /* On windows it is allowed to increase the FD_SETSIZE
* (and nescessary to make our custom eventloop work) * (and nescessary to make our custom eventloop work)

View File

@ -155,7 +155,7 @@ add_WIN_cacerts_to_openssl_store(SSL_CTX* tls_ctx)
HCERTSTORE hSystemStore; HCERTSTORE hSystemStore;
PCCERT_CONTEXT pTargetCert = NULL; PCCERT_CONTEXT pTargetCert = NULL;
DEBUG_STUB("%s %-35s: %s\n", STUB_DEBUG_SETUP_TLS, __FUNCTION__, DEBUG_STUB("%s %-35s: %s\n", STUB_DEBUG_SETUP_TLS, __FUNC__,
"Adding Windows certificates to CA store"); "Adding Windows certificates to CA store");
/* load just once per context lifetime for this version of getdns /* load just once per context lifetime for this version of getdns
@ -184,7 +184,7 @@ add_WIN_cacerts_to_openssl_store(SSL_CTX* tls_ctx)
/* failure if the CA store is empty or the call fails */ /* failure if the CA store is empty or the call fails */
if ((pTargetCert = CertEnumCertificatesInStore( if ((pTargetCert = CertEnumCertificatesInStore(
hSystemStore, pTargetCert)) == 0) { hSystemStore, pTargetCert)) == 0) {
DEBUG_STUB("%s %-35s: %s\n", STUB_DEBUG_SETUP_TLS, __FUNCTION__, DEBUG_STUB("%s %-35s: %s\n", STUB_DEBUG_SETUP_TLS, __FUNC__,
"CA certificate store for Windows is empty."); "CA certificate store for Windows is empty.");
return 0; return 0;
} }
@ -196,7 +196,7 @@ add_WIN_cacerts_to_openssl_store(SSL_CTX* tls_ctx)
pTargetCert->cbCertEncoded); pTargetCert->cbCertEncoded);
if (!cert1) { if (!cert1) {
/* return error if a cert fails */ /* return error if a cert fails */
DEBUG_STUB("%s %-35s: %s %d:%s\n", STUB_DEBUG_SETUP_TLS, __FUNCTION__, DEBUG_STUB("%s %-35s: %s %d:%s\n", STUB_DEBUG_SETUP_TLS, __FUNC__,
"Unable to parse certificate in memory", "Unable to parse certificate in memory",
ERR_get_error(), ERR_error_string(ERR_get_error(), NULL)); ERR_get_error(), ERR_error_string(ERR_get_error(), NULL));
return 0; return 0;
@ -204,7 +204,7 @@ add_WIN_cacerts_to_openssl_store(SSL_CTX* tls_ctx)
else { else {
/* return error if a cert add to store fails */ /* return error if a cert add to store fails */
if (X509_STORE_add_cert(store, cert1) == 0) { if (X509_STORE_add_cert(store, cert1) == 0) {
DEBUG_STUB("%s %-35s: %s %d:%s\n", STUB_DEBUG_SETUP_TLS, __FUNCTION__, DEBUG_STUB("%s %-35s: %s %d:%s\n", STUB_DEBUG_SETUP_TLS, __FUNC__,
"Error adding certificate", ERR_get_error(), "Error adding certificate", ERR_get_error(),
ERR_error_string(ERR_get_error(), NULL)); ERR_error_string(ERR_get_error(), NULL));
return 0; return 0;
@ -1633,7 +1633,7 @@ getdns_context_request_count_changed(getdns_context *context)
if (context->outbound_requests.count && ! context->ub_event.ev){ if (context->outbound_requests.count && ! context->ub_event.ev){
DEBUG_SCHED("gc_request_count_changed " DEBUG_SCHED("gc_request_count_changed "
"-> ub schedule(el_ev = %p, el_ev->ev = %p)\n", "-> ub schedule(el_ev = %p, el_ev->ev = %p)\n",
&context->ub_event, context->ub_event.ev); (void *)&context->ub_event, (void *)context->ub_event.ev);
#ifndef USE_WINSOCK #ifndef USE_WINSOCK
#ifdef HAVE_UNBOUND_EVENT_API #ifdef HAVE_UNBOUND_EVENT_API
if (!_getdns_ub_loop_enabled(&context->ub_loop)) if (!_getdns_ub_loop_enabled(&context->ub_loop))
@ -1647,7 +1647,7 @@ getdns_context_request_count_changed(getdns_context *context)
context->ub_event.ev) { context->ub_event.ev) {
DEBUG_SCHED("gc_request_count_changed " DEBUG_SCHED("gc_request_count_changed "
"-> ub clear(el_ev = %p, el_ev->ev = %p)\n", "-> ub clear(el_ev = %p, el_ev->ev = %p)\n",
&context->ub_event, context->ub_event.ev); (void *)&context->ub_event, (void *)context->ub_event.ev);
#ifndef USE_WINSOCK #ifndef USE_WINSOCK
#ifdef HAVE_UNBOUND_EVENT_API #ifdef HAVE_UNBOUND_EVENT_API

View File

@ -54,7 +54,7 @@ default_eventloop_schedule(getdns_eventloop *loop,
size_t i; size_t i;
DEBUG_SCHED( "%s(loop: %p, fd: %d, timeout: %"PRIu64", event: %p, FD_SETSIZE: %d)\n" DEBUG_SCHED( "%s(loop: %p, fd: %d, timeout: %"PRIu64", event: %p, FD_SETSIZE: %d)\n"
, __FUNCTION__, loop, fd, timeout, event, FD_SETSIZE); , __FUNC__, (void *)loop, fd, timeout, (void *)event, FD_SETSIZE);
if (!loop || !event) if (!loop || !event)
return GETDNS_RETURN_INVALID_PARAMETER; return GETDNS_RETURN_INVALID_PARAMETER;
@ -75,11 +75,11 @@ default_eventloop_schedule(getdns_eventloop *loop,
if (default_loop->fd_events[fd] == event) { if (default_loop->fd_events[fd] == event) {
DEBUG_SCHED("WARNING: Event %p not cleared " DEBUG_SCHED("WARNING: Event %p not cleared "
"before being rescheduled!\n" "before being rescheduled!\n"
, default_loop->fd_events[fd]); , (void *)default_loop->fd_events[fd]);
} else { } else {
DEBUG_SCHED("ERROR: A different event is " DEBUG_SCHED("ERROR: A different event is "
"already present at fd slot: %p!\n" "already present at fd slot: %p!\n"
, default_loop->fd_events[fd]); , (void *)default_loop->fd_events[fd]);
} }
} }
#endif #endif
@ -123,7 +123,7 @@ default_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
if (!loop || !event) if (!loop || !event)
return GETDNS_RETURN_INVALID_PARAMETER; return GETDNS_RETURN_INVALID_PARAMETER;
DEBUG_SCHED( "%s(loop: %p, event: %p)\n", __FUNCTION__, loop, event); DEBUG_SCHED( "%s(loop: %p, event: %p)\n", __FUNC__, (void *)loop, (void *)event);
i = (intptr_t)event->ev - 1; i = (intptr_t)event->ev - 1;
if (i < 0 || i >= FD_SETSIZE) { if (i < 0 || i >= FD_SETSIZE) {
@ -134,7 +134,7 @@ default_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
if (default_loop->timeout_events[i] != event) if (default_loop->timeout_events[i] != event)
DEBUG_SCHED( "ERROR: Different/wrong event present at " DEBUG_SCHED( "ERROR: Different/wrong event present at "
"timeout slot: %p!\n" "timeout slot: %p!\n"
, default_loop->timeout_events[i]); , (void *)default_loop->timeout_events[i]);
#endif #endif
default_loop->timeout_events[i] = NULL; default_loop->timeout_events[i] = NULL;
} else { } else {
@ -142,7 +142,7 @@ default_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
if (default_loop->fd_events[i] != event) if (default_loop->fd_events[i] != event)
DEBUG_SCHED( "ERROR: Different/wrong event present at " DEBUG_SCHED( "ERROR: Different/wrong event present at "
"fd slot: %p!\n" "fd slot: %p!\n"
, default_loop->fd_events[i]); , (void *)default_loop->fd_events[i]);
#endif #endif
default_loop->fd_events[i] = NULL; default_loop->fd_events[i] = NULL;
} }
@ -162,7 +162,7 @@ default_read_cb(int fd, getdns_eventloop_event *event)
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG #if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd; (void)fd;
#endif #endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNCTION__, fd, event); DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->read_cb(event->userarg); event->read_cb(event->userarg);
} }
@ -172,7 +172,7 @@ default_write_cb(int fd, getdns_eventloop_event *event)
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG #if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd; (void)fd;
#endif #endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNCTION__, fd, event); DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->write_cb(event->userarg); event->write_cb(event->userarg);
} }
@ -182,7 +182,7 @@ default_timeout_cb(int fd, getdns_eventloop_event *event)
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG #if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd; (void)fd;
#endif #endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNCTION__, fd, event); DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->timeout_cb(event->userarg); event->timeout_cb(event->userarg);
} }

View File

@ -412,7 +412,7 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
x = sk_X509_value(X509_STORE_CTX_get0_untrusted(store), i); x = sk_X509_value(X509_STORE_CTX_get0_untrusted(store), i);
#if defined(STUB_DEBUG) && STUB_DEBUG #if defined(STUB_DEBUG) && STUB_DEBUG
DEBUG_STUB("%s %-35s: Name of cert: %d ", DEBUG_STUB("%s %-35s: Name of cert: %d ",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i); STUB_DEBUG_SETUP_TLS, __FUNC__, i);
X509_NAME_print_ex_fp(stderr, X509_get_subject_name(x), 1, XN_FLAG_ONELINE); X509_NAME_print_ex_fp(stderr, X509_get_subject_name(x), 1, XN_FLAG_ONELINE);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
#endif #endif
@ -422,14 +422,14 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
int verified; int verified;
if (!pkey) { if (!pkey) {
DEBUG_STUB("%s %-35s: Could not get pubkey from cert %d (%p)\n", DEBUG_STUB("%s %-35s: Could not get pubkey from cert %d (%p)\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, (void*)x); STUB_DEBUG_SETUP_TLS, __FUNC__, i, (void*)x);
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
verified = X509_verify(prev, pkey); verified = X509_verify(prev, pkey);
EVP_PKEY_free(pkey); EVP_PKEY_free(pkey);
if (!verified) { if (!verified) {
DEBUG_STUB("%s %-35s: cert %d (%p) was not signed by cert %d\n", DEBUG_STUB("%s %-35s: cert %d (%p) was not signed by cert %d\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i-1, (void*)prev, i); STUB_DEBUG_SETUP_TLS, __FUNC__, i-1, (void*)prev, i);
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
} }
} }
@ -438,14 +438,14 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
len = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), NULL); len = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), NULL);
if (len > (int)sizeof(raw)) { if (len > (int)sizeof(raw)) {
DEBUG_STUB("%s %-35s: Pubkey %d is larger than "PRIsz" octets\n", DEBUG_STUB("%s %-35s: Pubkey %d is larger than "PRIsz" octets\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, sizeof(raw)); STUB_DEBUG_SETUP_TLS, __FUNC__, i, sizeof(raw));
continue; continue;
} }
next = raw; next = raw;
i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), &next); i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), &next);
if (next - raw != len) { if (next - raw != len) {
DEBUG_STUB("%s %-35s: Pubkey %d claimed it needed %d octets, really needed "PRIsz"\n", DEBUG_STUB("%s %-35s: Pubkey %d claimed it needed %d octets, really needed "PRIsz"\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, len, next - raw); STUB_DEBUG_SETUP_TLS, __FUNC__, i, len, next - raw);
continue; continue;
} }
SHA256(raw, len, buf); SHA256(raw, len, buf);
@ -454,11 +454,11 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
for (p = pinset; p; p = p->next) for (p = pinset; p; p = p->next)
if (0 == memcmp(buf, p->pin, sizeof(p->pin))) { if (0 == memcmp(buf, p->pin, sizeof(p->pin))) {
DEBUG_STUB("%s %-35s: Pubkey %d matched pin %p ("PRIsz")\n", DEBUG_STUB("%s %-35s: Pubkey %d matched pin %p ("PRIsz")\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, (void*)p, sizeof(p->pin)); STUB_DEBUG_SETUP_TLS, __FUNC__, i, (void*)p, sizeof(p->pin));
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} else } else
DEBUG_STUB("%s %-35s: Pubkey %d did not match pin %p\n", DEBUG_STUB("%s %-35s: Pubkey %d did not match pin %p\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, (void*)p); STUB_DEBUG_SETUP_TLS, __FUNC__, i, (void*)p);
} }
return ret; return ret;

View File

@ -474,7 +474,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
HMAC_CTX ctx_space; HMAC_CTX ctx_space;
#endif #endif
DEBUG_STUB("%s %-35s: Validate TSIG\n", STUB_DEBUG_TSIG, __FUNCTION__); DEBUG_STUB("%s %-35s: Validate TSIG\n", STUB_DEBUG_TSIG, __FUNC__);
for ( rr = _getdns_rr_iter_init(&rr_spc, req->query, for ( rr = _getdns_rr_iter_init(&rr_spc, req->query,
(req->response - req->query)) (req->response - req->query))
; rr ; rr
@ -491,7 +491,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
if (request_mac_len != rdf->nxt - rdf->pos - 2) if (request_mac_len != rdf->nxt - rdf->pos - 2)
return; return;
DEBUG_STUB("%s %-35s: Request MAC found length %d\n", DEBUG_STUB("%s %-35s: Request MAC found length %d\n",
STUB_DEBUG_TSIG, __FUNCTION__, (int)(request_mac_len)); STUB_DEBUG_TSIG, __FUNC__, (int)(request_mac_len));
request_mac = rdf->pos + 2; request_mac = rdf->pos + 2;
@ -548,7 +548,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
if (response_mac_len != rdf->nxt - rdf->pos - 2) if (response_mac_len != rdf->nxt - rdf->pos - 2)
return; return;
DEBUG_STUB("%s %-35s: Response MAC found length: %d\n", DEBUG_STUB("%s %-35s: Response MAC found length: %d\n",
STUB_DEBUG_TSIG, __FUNCTION__, (int)(response_mac_len)); STUB_DEBUG_TSIG, __FUNC__, (int)(response_mac_len));
response_mac = rdf->pos + 2; response_mac = rdf->pos + 2;
if (!(rdf = _getdns_rdf_iter_next(rdf)) || if (!(rdf = _getdns_rdf_iter_next(rdf)) ||
@ -573,7 +573,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
/* TSIG found */ /* TSIG found */
DEBUG_STUB("%s %-35s: TSIG found, original ID: %d\n", DEBUG_STUB("%s %-35s: TSIG found, original ID: %d\n",
STUB_DEBUG_TSIG, __FUNCTION__, (int)original_id); STUB_DEBUG_TSIG, __FUNC__, (int)original_id);
gldns_write_uint16(req->response + 10, gldns_write_uint16(req->response + 10,
gldns_read_uint16(req->response + 10) - 1); gldns_read_uint16(req->response + 10) - 1);
@ -614,7 +614,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
HMAC_Final(ctx, result_mac, &result_mac_len); HMAC_Final(ctx, result_mac, &result_mac_len);
DEBUG_STUB("%s %-35s: Result MAC length: %d\n", DEBUG_STUB("%s %-35s: Result MAC length: %d\n",
STUB_DEBUG_TSIG, __FUNCTION__, (int)(result_mac_len)); STUB_DEBUG_TSIG, __FUNC__, (int)(result_mac_len));
if (result_mac_len == response_mac_len && if (result_mac_len == response_mac_len &&
memcmp(result_mac, response_mac, result_mac_len) == 0) memcmp(result_mac, response_mac, result_mac_len) == 0)
req->tsig_status = GETDNS_DNSSEC_SECURE; req->tsig_status = GETDNS_DNSSEC_SECURE;

View File

@ -655,7 +655,7 @@ static void free_listen_set_when_done(listen_set *set)
if (!(mf = &set->context->mf)) if (!(mf = &set->context->mf))
return; return;
DEBUG_SERVER("To free listen set: %p\n", set); DEBUG_SERVER("To free listen set: %p\n", (void *)set);
for (i = 0; i < set->count; i++) { for (i = 0; i < set->count; i++) {
listener *l = &set->items[i]; listener *l = &set->items[i];
@ -666,7 +666,7 @@ static void free_listen_set_when_done(listen_set *set)
return; return;
} }
GETDNS_FREE(*mf, set); GETDNS_FREE(*mf, set);
DEBUG_SERVER("Listen set: %p freed\n", set); DEBUG_SERVER("Listen set: %p freed\n", (void *)set);
} }
static void remove_listeners(listen_set *set) static void remove_listeners(listen_set *set)
@ -809,10 +809,9 @@ getdns_return_t getdns_context_set_listen_addresses(
size_t i; size_t i;
struct addrinfo hints; struct addrinfo hints;
DEBUG_SERVER("getdns_context_set_listen_addresses(%p, %p, %p)\n", DEBUG_SERVER("getdns_context_set_listen_addresses(%p, <func>, %p)\n",
context, request_handler, (void *)context, (void *)listen_addresses);
listen_addresses);
if (!(mf = &context->mf)) if (!(mf = &context->mf))
return GETDNS_RETURN_GENERIC_ERROR; return GETDNS_RETURN_GENERIC_ERROR;
@ -849,7 +848,7 @@ getdns_return_t getdns_context_set_listen_addresses(
_getdns_rbtree_init(&new_set->connections_set, ptr_cmp); _getdns_rbtree_init(&new_set->connections_set, ptr_cmp);
DEBUG_SERVER("New listen set: %p, current_set: %p\n", DEBUG_SERVER("New listen set: %p, current_set: %p\n",
new_set, current_set); (void *)new_set, (void *)current_set);
new_set->context = context; new_set->context = context;
new_set->handler = request_handler; new_set->handler = request_handler;

View File

@ -252,7 +252,7 @@ match_edns_opt_rr(uint16_t code, uint8_t *response, size_t response_len,
(void) gldns_wire2str_rr_scan( (void) gldns_wire2str_rr_scan(
&data, &data_len, &str, &str_len, (uint8_t *)rr_iter->pkt, rr_iter->pkt_end - rr_iter->pkt); &data, &data_len, &str, &str_len, (uint8_t *)rr_iter->pkt, rr_iter->pkt_end - rr_iter->pkt);
DEBUG_STUB("%s %-35s: OPT RR: %s", DEBUG_STUB("%s %-35s: OPT RR: %s",
STUB_DEBUG_READ, __FUNCTION__, str_spc); STUB_DEBUG_READ, __FUNC__, str_spc);
#endif #endif
/* OPT found, now search for the specified option */ /* OPT found, now search for the specified option */
@ -343,7 +343,7 @@ process_keepalive(
Convert to ms first (wire value has units of 100ms) */ Convert to ms first (wire value has units of 100ms) */
uint64_t server_keepalive = ((uint64_t)gldns_read_uint16(position))*100; uint64_t server_keepalive = ((uint64_t)gldns_read_uint16(position))*100;
DEBUG_STUB("%s %-35s: FD: %d Server Keepalive recieved: %d ms\n", DEBUG_STUB("%s %-35s: FD: %d Server Keepalive recieved: %d ms\n",
STUB_DEBUG_READ, __FUNCTION__, upstream->fd, STUB_DEBUG_READ, __FUNC__, upstream->fd,
(int)server_keepalive); (int)server_keepalive);
if (netreq->owner->context->idle_timeout < server_keepalive) if (netreq->owner->context->idle_timeout < server_keepalive)
upstream->keepalive_timeout = netreq->owner->context->idle_timeout; upstream->keepalive_timeout = netreq->owner->context->idle_timeout;
@ -355,7 +355,7 @@ process_keepalive(
} }
upstream->keepalive_timeout = server_keepalive; upstream->keepalive_timeout = server_keepalive;
DEBUG_STUB("%s %-35s: FD: %d Server Keepalive used: %d ms\n", DEBUG_STUB("%s %-35s: FD: %d Server Keepalive used: %d ms\n",
STUB_DEBUG_READ, __FUNCTION__, upstream->fd, STUB_DEBUG_READ, __FUNC__, upstream->fd,
(int)server_keepalive); (int)server_keepalive);
} }
} }
@ -385,7 +385,7 @@ tcp_connect(getdns_upstream *upstream, getdns_transport_list_t transport)
{ {
int fd = -1; int fd = -1;
DEBUG_STUB("%s %-35s: Creating TCP connection: %p\n", STUB_DEBUG_SETUP, DEBUG_STUB("%s %-35s: Creating TCP connection: %p\n", STUB_DEBUG_SETUP,
__FUNCTION__, (void*)upstream); __FUNC__, (void*)upstream);
if ((fd = socket(upstream->addr.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1) if ((fd = socket(upstream->addr.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1)
return -1; return -1;
@ -481,7 +481,7 @@ static void
stub_cleanup(getdns_network_req *netreq) stub_cleanup(getdns_network_req *netreq)
{ {
DEBUG_STUB("%s %-35s: MSG: %p\n", DEBUG_STUB("%s %-35s: MSG: %p\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, (void*)netreq); STUB_DEBUG_CLEANUP, __FUNC__, (void*)netreq);
getdns_dns_req *dnsreq = netreq->owner; getdns_dns_req *dnsreq = netreq->owner;
getdns_network_req *r, *prev_r; getdns_network_req *r, *prev_r;
getdns_upstream *upstream; getdns_upstream *upstream;
@ -521,7 +521,7 @@ static void
upstream_failed(getdns_upstream *upstream, int during_setup) upstream_failed(getdns_upstream *upstream, int during_setup)
{ {
DEBUG_STUB("%s %-35s: FD: %d During setup = %d\n", DEBUG_STUB("%s %-35s: FD: %d During setup = %d\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd, during_setup); STUB_DEBUG_CLEANUP, __FUNC__, upstream->fd, during_setup);
/* Fallback code should take care of queue queries and then close conn /* Fallback code should take care of queue queries and then close conn
when idle.*/ when idle.*/
/* [TLS1]TODO: Work out how to re-open the connection and re-try /* [TLS1]TODO: Work out how to re-open the connection and re-try
@ -562,7 +562,7 @@ void
_getdns_cancel_stub_request(getdns_network_req *netreq) _getdns_cancel_stub_request(getdns_network_req *netreq)
{ {
DEBUG_STUB("%s %-35s: MSG: %p\n", DEBUG_STUB("%s %-35s: MSG: %p\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, (void*)netreq); STUB_DEBUG_CLEANUP, __FUNC__, (void*)netreq);
stub_cleanup(netreq); stub_cleanup(netreq);
if (netreq->fd >= 0) { if (netreq->fd >= 0) {
#ifdef USE_WINSOCK #ifdef USE_WINSOCK
@ -578,7 +578,7 @@ stub_timeout_cb(void *userarg)
{ {
getdns_network_req *netreq = (getdns_network_req *)userarg; getdns_network_req *netreq = (getdns_network_req *)userarg;
DEBUG_STUB("%s %-35s: MSG: %p\n", DEBUG_STUB("%s %-35s: MSG: %p\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, (void*)netreq); STUB_DEBUG_CLEANUP, __FUNC__, (void*)netreq);
stub_cleanup(netreq); stub_cleanup(netreq);
netreq->state = NET_REQ_TIMED_OUT; netreq->state = NET_REQ_TIMED_OUT;
/* Handle upstream*/ /* Handle upstream*/
@ -612,7 +612,7 @@ upstream_idle_timeout_cb(void *userarg)
{ {
getdns_upstream *upstream = (getdns_upstream *)userarg; getdns_upstream *upstream = (getdns_upstream *)userarg;
DEBUG_STUB("%s %-35s: FD: %d Closing connection\n", DEBUG_STUB("%s %-35s: FD: %d Closing connection\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd); STUB_DEBUG_CLEANUP, __FUNC__, upstream->fd);
GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event); GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event);
upstream->event.timeout_cb = NULL; upstream->event.timeout_cb = NULL;
upstream->event.read_cb = NULL; upstream->event.read_cb = NULL;
@ -625,7 +625,7 @@ upstream_setup_timeout_cb(void *userarg)
{ {
getdns_upstream *upstream = (getdns_upstream *)userarg; getdns_upstream *upstream = (getdns_upstream *)userarg;
DEBUG_STUB("%s %-35s: FD: %d\n", DEBUG_STUB("%s %-35s: FD: %d\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd); STUB_DEBUG_CLEANUP, __FUNC__, upstream->fd);
/* Clean up and trigger a write to let the fallback code to its job */ /* Clean up and trigger a write to let the fallback code to its job */
upstream_failed(upstream, 1); upstream_failed(upstream, 1);
@ -643,7 +643,7 @@ upstream_setup_timeout_cb(void *userarg)
ret = select(upstream->fd+1, NULL, &fds, NULL, &tval); ret = select(upstream->fd+1, NULL, &fds, NULL, &tval);
if (ret == 0) { if (ret == 0) {
DEBUG_STUB("%s %-35s: FD: %d Cleaning up dangling queue\n", DEBUG_STUB("%s %-35s: FD: %d Cleaning up dangling queue\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd); STUB_DEBUG_CLEANUP, __FUNC__, upstream->fd);
while (upstream->write_queue) while (upstream->write_queue)
upstream_write_cb(upstream); upstream_write_cb(upstream);
} }
@ -763,7 +763,7 @@ stub_tcp_write(int fd, getdns_tcp_state *tcp, getdns_network_req *netreq)
netreq->owner->context->idle_timeout != 0) { netreq->owner->context->idle_timeout != 0) {
/* Add the keepalive option to the first query on this connection*/ /* Add the keepalive option to the first query on this connection*/
DEBUG_STUB("%s %-35s: FD: %d Requesting keepalive \n", DEBUG_STUB("%s %-35s: FD: %d Requesting keepalive \n",
STUB_DEBUG_WRITE, __FUNCTION__, fd); STUB_DEBUG_WRITE, __FUNC__, fd);
if (attach_edns_keepalive(netreq)) if (attach_edns_keepalive(netreq))
return STUB_OUT_OF_OPTIONS; return STUB_OUT_OF_OPTIONS;
netreq->keepalive_sent = 1; netreq->keepalive_sent = 1;
@ -865,7 +865,7 @@ tls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
int err = X509_STORE_CTX_get_error(ctx); int err = X509_STORE_CTX_get_error(ctx);
#if defined(STUB_DEBUG) && STUB_DEBUG #if defined(STUB_DEBUG) && STUB_DEBUG
DEBUG_STUB("%s %-35s: FD: %d Verify result: (%d) \"%s\"\n", DEBUG_STUB("%s %-35s: FD: %d Verify result: (%d) \"%s\"\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd, err, STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->fd, err,
X509_verify_cert_error_string(err)); X509_verify_cert_error_string(err));
#endif #endif
@ -874,7 +874,7 @@ tls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
/*Report if error is hostname mismatch*/ /*Report if error is hostname mismatch*/
if (err == X509_V_ERR_HOSTNAME_MISMATCH && upstream->tls_fallback_ok) if (err == X509_V_ERR_HOSTNAME_MISMATCH && upstream->tls_fallback_ok)
DEBUG_STUB("%s %-35s: FD: %d WARNING: Proceeding even though hostname validation failed!\n", DEBUG_STUB("%s %-35s: FD: %d WARNING: Proceeding even though hostname validation failed!\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd); STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->fd);
#else #else
/* if we weren't built against OpenSSL with hostname matching we /* if we weren't built against OpenSSL with hostname matching we
* could not have matched the hostname, so this would be an automatic * could not have matched the hostname, so this would be an automatic
@ -891,12 +891,12 @@ tls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
if (pinset_ret != GETDNS_RETURN_GOOD) { if (pinset_ret != GETDNS_RETURN_GOOD) {
DEBUG_STUB("%s %-35s: FD: %d, WARNING: Pinset validation failure!\n", DEBUG_STUB("%s %-35s: FD: %d, WARNING: Pinset validation failure!\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd); STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->fd);
preverify_ok = 0; preverify_ok = 0;
upstream->tls_auth_state = GETDNS_AUTH_FAILED; upstream->tls_auth_state = GETDNS_AUTH_FAILED;
if (upstream->tls_fallback_ok) if (upstream->tls_fallback_ok)
DEBUG_STUB("%s %-35s: FD: %d, WARNING: Proceeding even though pinset validation failed!\n", DEBUG_STUB("%s %-35s: FD: %d, WARNING: Proceeding even though pinset validation failed!\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd); STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->fd);
} else { } else {
/* If we _only_ had a pinset and it is good then force succesful /* If we _only_ had a pinset and it is good then force succesful
authentication when the cert self-signed */ authentication when the cert self-signed */
@ -905,7 +905,7 @@ tls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)) { err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)) {
preverify_ok = 1; preverify_ok = 1;
DEBUG_STUB("%s %-35s: FD: %d, Allowing self-signed (%d) cert since pins match\n", DEBUG_STUB("%s %-35s: FD: %d, Allowing self-signed (%d) cert since pins match\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd, err); STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->fd, err);
} }
} }
@ -950,7 +950,7 @@ tls_create_object(getdns_dns_req *dnsreq, int fd, getdns_upstream *upstream)
if (upstream->tls_auth_name[0] != '\0') { if (upstream->tls_auth_name[0] != '\0') {
/*Request certificate for the auth_name*/ /*Request certificate for the auth_name*/
DEBUG_STUB("%s %-35s: Hostname verification requested for: %s\n", DEBUG_STUB("%s %-35s: Hostname verification requested for: %s\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->tls_auth_name); STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->tls_auth_name);
SSL_set_tlsext_host_name(ssl, upstream->tls_auth_name); SSL_set_tlsext_host_name(ssl, upstream->tls_auth_name);
#ifdef HAVE_SSL_HN_AUTH #ifdef HAVE_SSL_HN_AUTH
/* Set up native OpenSSL hostname verification*/ /* Set up native OpenSSL hostname verification*/
@ -961,7 +961,7 @@ tls_create_object(getdns_dns_req *dnsreq, int fd, getdns_upstream *upstream)
#else #else
if (dnsreq->netreqs[0]->tls_auth_min == GETDNS_AUTHENTICATION_REQUIRED) { if (dnsreq->netreqs[0]->tls_auth_min == GETDNS_AUTHENTICATION_REQUIRED) {
DEBUG_STUB("%s %-35s: ERROR: TLS Authentication functionality not available\n", DEBUG_STUB("%s %-35s: ERROR: TLS Authentication functionality not available\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__); STUB_DEBUG_SETUP_TLS, __FUNC__);
upstream->tls_hs_state = GETDNS_HS_FAILED; upstream->tls_hs_state = GETDNS_HS_FAILED;
return NULL; return NULL;
} }
@ -975,27 +975,27 @@ tls_create_object(getdns_dns_req *dnsreq, int fd, getdns_upstream *upstream)
if (dnsreq->netreqs[0]->tls_auth_min == GETDNS_AUTHENTICATION_REQUIRED) { if (dnsreq->netreqs[0]->tls_auth_min == GETDNS_AUTHENTICATION_REQUIRED) {
if (upstream->tls_pubkey_pinset) { if (upstream->tls_pubkey_pinset) {
DEBUG_STUB("%s %-35s: Proceeding with only pubkey pinning authentication\n", DEBUG_STUB("%s %-35s: Proceeding with only pubkey pinning authentication\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__); STUB_DEBUG_SETUP_TLS, __FUNC__);
} else { } else {
DEBUG_STUB("%s %-35s: ERROR: No host name or pubkey pinset provided for TLS authentication\n", DEBUG_STUB("%s %-35s: ERROR: No host name or pubkey pinset provided for TLS authentication\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__); STUB_DEBUG_SETUP_TLS, __FUNC__);
upstream->tls_hs_state = GETDNS_HS_FAILED; upstream->tls_hs_state = GETDNS_HS_FAILED;
return NULL; return NULL;
} }
} else { } else {
/* no hostname verification, so we will make opportunistic connections */ /* no hostname verification, so we will make opportunistic connections */
DEBUG_STUB("%s %-35s: Proceeding even though no hostname provided!\n", DEBUG_STUB("%s %-35s: Proceeding even though no hostname provided!\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__); STUB_DEBUG_SETUP_TLS, __FUNC__);
upstream->tls_fallback_ok = 1; upstream->tls_fallback_ok = 1;
} }
} }
if (upstream->tls_fallback_ok) { if (upstream->tls_fallback_ok) {
SSL_set_cipher_list(ssl, "DEFAULT"); SSL_set_cipher_list(ssl, "DEFAULT");
DEBUG_STUB("%s %-35s: WARNING: Using Oppotunistic TLS (fallback allowed)!\n", DEBUG_STUB("%s %-35s: WARNING: Using Oppotunistic TLS (fallback allowed)!\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__); STUB_DEBUG_SETUP_TLS, __FUNC__);
} else } else
DEBUG_STUB("%s %-35s: Using Strict TLS \n", STUB_DEBUG_SETUP_TLS, DEBUG_STUB("%s %-35s: Using Strict TLS \n", STUB_DEBUG_SETUP_TLS,
__FUNCTION__); __FUNC__);
SSL_set_verify(ssl, SSL_VERIFY_PEER, tls_verify_callback); SSL_set_verify(ssl, SSL_VERIFY_PEER, tls_verify_callback);
SSL_set_connect_state(ssl); SSL_set_connect_state(ssl);
@ -1010,7 +1010,7 @@ tls_create_object(getdns_dns_req *dnsreq, int fd, getdns_upstream *upstream)
upstream->tls_fallback_ok == 1) { upstream->tls_fallback_ok == 1) {
SSL_set_session(ssl, upstream->tls_session); SSL_set_session(ssl, upstream->tls_session);
DEBUG_STUB("%s %-35s: Attempting session re-use\n", STUB_DEBUG_SETUP_TLS, DEBUG_STUB("%s %-35s: Attempting session re-use\n", STUB_DEBUG_SETUP_TLS,
__FUNCTION__); __FUNC__);
} }
} }
@ -1021,7 +1021,7 @@ static int
tls_do_handshake(getdns_upstream *upstream) tls_do_handshake(getdns_upstream *upstream)
{ {
DEBUG_STUB("%s %-35s: FD: %d \n", STUB_DEBUG_SETUP_TLS, DEBUG_STUB("%s %-35s: FD: %d \n", STUB_DEBUG_SETUP_TLS,
__FUNCTION__, upstream->fd); __FUNC__, upstream->fd);
int r; int r;
int want; int want;
ERR_clear_error(); ERR_clear_error();
@ -1047,7 +1047,7 @@ tls_do_handshake(getdns_upstream *upstream)
return STUB_TCP_AGAIN; return STUB_TCP_AGAIN;
default: default:
DEBUG_STUB("%s %-35s: FD: %d Handshake failed %d\n", DEBUG_STUB("%s %-35s: FD: %d Handshake failed %d\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd, STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->fd,
want); want);
return STUB_SETUP_ERROR; return STUB_SETUP_ERROR;
} }
@ -1059,7 +1059,7 @@ tls_do_handshake(getdns_upstream *upstream)
if (SSL_session_reused(upstream->tls_obj)) if (SSL_session_reused(upstream->tls_obj))
upstream->tls_auth_state = upstream->last_tls_auth_state; upstream->tls_auth_state = upstream->last_tls_auth_state;
DEBUG_STUB("%s %-35s: FD: %d Handshake succeeded with auth state %s. Session is %s.\n", DEBUG_STUB("%s %-35s: FD: %d Handshake succeeded with auth state %s. Session is %s.\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd, STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->fd,
_getdns_auth_str(upstream->tls_auth_state), _getdns_auth_str(upstream->tls_auth_state),
SSL_session_reused(upstream->tls_obj) ?"re-used":"new"); SSL_session_reused(upstream->tls_obj) ?"re-used":"new");
if (upstream->tls_session != NULL) if (upstream->tls_session != NULL)
@ -1235,7 +1235,7 @@ stub_tls_write(getdns_upstream *upstream, getdns_tcp_state *tcp,
/* Add the keepalive option to every nth query on this /* Add the keepalive option to every nth query on this
connection */ connection */
DEBUG_STUB("%s %-35s: FD: %d Requesting keepalive \n", DEBUG_STUB("%s %-35s: FD: %d Requesting keepalive \n",
STUB_DEBUG_SETUP, __FUNCTION__, upstream->fd); STUB_DEBUG_SETUP, __FUNC__, upstream->fd);
if (attach_edns_keepalive(netreq)) if (attach_edns_keepalive(netreq))
return STUB_OUT_OF_OPTIONS; return STUB_OUT_OF_OPTIONS;
netreq->keepalive_sent = 1; netreq->keepalive_sent = 1;
@ -1297,7 +1297,7 @@ stub_udp_read_cb(void *userarg)
getdns_upstream *upstream = netreq->upstream; getdns_upstream *upstream = netreq->upstream;
ssize_t read; ssize_t read;
DEBUG_STUB("%s %-35s: MSG: %p \n", STUB_DEBUG_READ, DEBUG_STUB("%s %-35s: MSG: %p \n", STUB_DEBUG_READ,
__FUNCTION__, (void*)netreq); __FUNC__, (void*)netreq);
GETDNS_CLEAR_EVENT(dnsreq->loop, &netreq->event); GETDNS_CLEAR_EVENT(dnsreq->loop, &netreq->event);
@ -1330,7 +1330,7 @@ stub_udp_read_cb(void *userarg)
#endif #endif
while (GLDNS_TC_WIRE(netreq->response)) { while (GLDNS_TC_WIRE(netreq->response)) {
DEBUG_STUB("%s %-35s: MSG: %p TC bit set in response \n", STUB_DEBUG_READ, DEBUG_STUB("%s %-35s: MSG: %p TC bit set in response \n", STUB_DEBUG_READ,
__FUNCTION__, (void*)netreq); __FUNC__, (void*)netreq);
if (!(netreq->transport_current < netreq->transport_count)) if (!(netreq->transport_current < netreq->transport_count))
break; break;
getdns_transport_list_t next_transport = getdns_transport_list_t next_transport =
@ -1372,7 +1372,7 @@ stub_udp_write_cb(void *userarg)
getdns_dns_req *dnsreq = netreq->owner; getdns_dns_req *dnsreq = netreq->owner;
size_t pkt_len; size_t pkt_len;
DEBUG_STUB("%s %-35s: MSG: %p \n", STUB_DEBUG_WRITE, DEBUG_STUB("%s %-35s: MSG: %p \n", STUB_DEBUG_WRITE,
__FUNCTION__, (void*)netreq); __FUNC__, (void *)netreq);
GETDNS_CLEAR_EVENT(dnsreq->loop, &netreq->event); GETDNS_CLEAR_EVENT(dnsreq->loop, &netreq->event);
@ -1438,7 +1438,7 @@ static void
upstream_read_cb(void *userarg) upstream_read_cb(void *userarg)
{ {
getdns_upstream *upstream = (getdns_upstream *)userarg; getdns_upstream *upstream = (getdns_upstream *)userarg;
DEBUG_STUB("%s %-35s: FD: %d \n", STUB_DEBUG_READ, __FUNCTION__, DEBUG_STUB("%s %-35s: FD: %d \n", STUB_DEBUG_READ, __FUNC__,
upstream->fd); upstream->fd);
getdns_network_req *netreq; getdns_network_req *netreq;
int q; int q;
@ -1479,7 +1479,7 @@ upstream_read_cb(void *userarg)
} }
DEBUG_STUB("%s %-35s: MSG: %p (read)\n", DEBUG_STUB("%s %-35s: MSG: %p (read)\n",
STUB_DEBUG_READ, __FUNCTION__, (void*)netreq); STUB_DEBUG_READ, __FUNC__, (void*)netreq);
netreq->state = NET_REQ_FINISHED; netreq->state = NET_REQ_FINISHED;
netreq->response = upstream->tcp.read_buf; netreq->response = upstream->tcp.read_buf;
netreq->response_len = netreq->response_len =
@ -1560,7 +1560,7 @@ upstream_write_cb(void *userarg)
netreq->debug_start_time = _getdns_get_time_as_uintt64(); netreq->debug_start_time = _getdns_get_time_as_uintt64();
DEBUG_STUB("%s %-35s: MSG: %p (writing)\n", STUB_DEBUG_WRITE, DEBUG_STUB("%s %-35s: MSG: %p (writing)\n", STUB_DEBUG_WRITE,
__FUNCTION__, (void*)netreq); __FUNC__, (void*)netreq);
/* Health checks on current connection */ /* Health checks on current connection */
if (upstream->conn_state == GETDNS_CONN_TEARDOWN) if (upstream->conn_state == GETDNS_CONN_TEARDOWN)
@ -1585,7 +1585,7 @@ upstream_write_cb(void *userarg)
case STUB_SETUP_ERROR: case STUB_SETUP_ERROR:
/* Could not complete the set up. Need to fallback.*/ /* Could not complete the set up. Need to fallback.*/
DEBUG_STUB("%s %-35s: Upstream: %p ERROR = %d\n", STUB_DEBUG_WRITE, DEBUG_STUB("%s %-35s: Upstream: %p ERROR = %d\n", STUB_DEBUG_WRITE,
__FUNCTION__, (void*)userarg, q); __FUNC__, (void*)userarg, q);
upstream_failed(upstream, (q == STUB_TCP_ERROR ? 0:1)); upstream_failed(upstream, (q == STUB_TCP_ERROR ? 0:1));
/* Fall through */ /* Fall through */
case STUB_CONN_GONE: case STUB_CONN_GONE:
@ -1741,7 +1741,7 @@ upstream_select_stateful(getdns_network_req *netreq, getdns_transport_list_t tra
will be better communicated to the user when we have better error codes*/ will be better communicated to the user when we have better error codes*/
for (i = 0; i < upstreams->count; i++) { for (i = 0; i < upstreams->count; i++) {
DEBUG_STUB("%s %-35s: Testing upstreams %d %d\n", STUB_DEBUG_SETUP, DEBUG_STUB("%s %-35s: Testing upstreams %d %d\n", STUB_DEBUG_SETUP,
__FUNCTION__, (int)i, (int)upstreams->upstreams[i].conn_state); __FUNC__, (int)i, (int)upstreams->upstreams[i].conn_state);
if (upstream_valid(&upstreams->upstreams[i], transport, netreq)) { if (upstream_valid(&upstreams->upstreams[i], transport, netreq)) {
upstream = &upstreams->upstreams[i]; upstream = &upstreams->upstreams[i];
break; break;
@ -1800,7 +1800,7 @@ upstream_connect(getdns_upstream *upstream, getdns_transport_list_t transport,
getdns_dns_req *dnsreq) getdns_dns_req *dnsreq)
{ {
DEBUG_STUB("%s %-35s: Getting upstream connection: %p\n", STUB_DEBUG_SETUP, DEBUG_STUB("%s %-35s: Getting upstream connection: %p\n", STUB_DEBUG_SETUP,
__FUNCTION__, (void*)upstream); __FUNC__, (void*)upstream);
int fd = -1; int fd = -1;
switch(transport) { switch(transport) {
case GETDNS_TRANSPORT_UDP: case GETDNS_TRANSPORT_UDP:
@ -1874,7 +1874,7 @@ upstream_find_for_transport(getdns_network_req *netreq,
*fd = upstream_connect(upstream, transport, netreq->owner); *fd = upstream_connect(upstream, transport, netreq->owner);
} while (*fd == -1); } while (*fd == -1);
DEBUG_STUB("%s %-35s: FD: %d Connecting to upstream: %p No: %d\n", DEBUG_STUB("%s %-35s: FD: %d Connecting to upstream: %p No: %d\n",
STUB_DEBUG_SETUP, __FUNCTION__, *fd, (void*)upstream, STUB_DEBUG_SETUP, __FUNC__, *fd, (void*)upstream,
(int)(upstream - netreq->owner->context->upstreams->upstreams)); (int)(upstream - netreq->owner->context->upstreams->upstreams));
} }
return upstream; return upstream;
@ -1898,7 +1898,7 @@ upstream_find_for_netreq(getdns_network_req *netreq)
return fd; return fd;
} }
/* Handle better, will give generic error*/ /* Handle better, will give generic error*/
DEBUG_STUB("%s %-35s: MSG: %p No valid upstream! \n", STUB_DEBUG_SCHEDULE, __FUNCTION__, (void*)netreq); DEBUG_STUB("%s %-35s: MSG: %p No valid upstream! \n", STUB_DEBUG_SCHEDULE, __FUNC__, (void*)netreq);
#if defined(DAEMON_DEBUG) && DAEMON_DEBUG #if defined(DAEMON_DEBUG) && DAEMON_DEBUG
DEBUG_DAEMON("%s *FAILURE* no valid transports or upstreams available!\n", DEBUG_DAEMON("%s *FAILURE* no valid transports or upstreams available!\n",
STUB_DEBUG_DAEMON); STUB_DEBUG_DAEMON);
@ -1915,7 +1915,7 @@ fallback_on_write(getdns_network_req *netreq)
{ {
/* Deal with UDP one day*/ /* Deal with UDP one day*/
DEBUG_STUB("%s %-35s: MSG: %p FALLING BACK \n", STUB_DEBUG_SCHEDULE, __FUNCTION__, (void*)netreq); DEBUG_STUB("%s %-35s: MSG: %p FALLING BACK \n", STUB_DEBUG_SCHEDULE, __FUNC__, (void*)netreq);
/* Try to find a fallback transport*/ /* Try to find a fallback transport*/
getdns_return_t result = _getdns_submit_stub_request(netreq); getdns_return_t result = _getdns_submit_stub_request(netreq);
@ -1932,7 +1932,7 @@ static void
upstream_reschedule_events(getdns_upstream *upstream, uint64_t idle_timeout) { upstream_reschedule_events(getdns_upstream *upstream, uint64_t idle_timeout) {
DEBUG_STUB("%s %-35s: FD: %d \n", STUB_DEBUG_SCHEDULE, DEBUG_STUB("%s %-35s: FD: %d \n", STUB_DEBUG_SCHEDULE,
__FUNCTION__, upstream->fd); __FUNC__, upstream->fd);
GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event); GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event);
if (!upstream->write_queue && upstream->event.write_cb) { if (!upstream->write_queue && upstream->event.write_cb) {
upstream->event.write_cb = NULL; upstream->event.write_cb = NULL;
@ -1951,7 +1951,7 @@ upstream_reschedule_events(getdns_upstream *upstream, uint64_t idle_timeout) {
upstream->fd, TIMEOUT_FOREVER, &upstream->event); upstream->fd, TIMEOUT_FOREVER, &upstream->event);
else { else {
DEBUG_STUB("%s %-35s: FD: %d Connection idle - timeout is %d\n", DEBUG_STUB("%s %-35s: FD: %d Connection idle - timeout is %d\n",
STUB_DEBUG_SCHEDULE, __FUNCTION__, upstream->fd, (int)idle_timeout); STUB_DEBUG_SCHEDULE, __FUNC__, upstream->fd, (int)idle_timeout);
upstream->event.timeout_cb = upstream_idle_timeout_cb; upstream->event.timeout_cb = upstream_idle_timeout_cb;
if (upstream->conn_state != GETDNS_CONN_OPEN) if (upstream->conn_state != GETDNS_CONN_OPEN)
idle_timeout = 0; idle_timeout = 0;
@ -1963,7 +1963,7 @@ upstream_reschedule_events(getdns_upstream *upstream, uint64_t idle_timeout) {
static void static void
upstream_schedule_netreq(getdns_upstream *upstream, getdns_network_req *netreq) upstream_schedule_netreq(getdns_upstream *upstream, getdns_network_req *netreq)
{ {
DEBUG_STUB("%s %-35s: MSG: %p (schedule event)\n", STUB_DEBUG_SCHEDULE, __FUNCTION__, (void*)netreq); DEBUG_STUB("%s %-35s: MSG: %p (schedule event)\n", STUB_DEBUG_SCHEDULE, __FUNC__, (void*)netreq);
/* We have a connected socket and a global event loop */ /* We have a connected socket and a global event loop */
assert(upstream->fd >= 0); assert(upstream->fd >= 0);
assert(upstream->loop); assert(upstream->loop);
@ -2014,7 +2014,7 @@ upstream_schedule_netreq(getdns_upstream *upstream, getdns_network_req *netreq)
getdns_return_t getdns_return_t
_getdns_submit_stub_request(getdns_network_req *netreq) _getdns_submit_stub_request(getdns_network_req *netreq)
{ {
DEBUG_STUB("%s %-35s: MSG: %p TYPE: %d\n", STUB_DEBUG_ENTRY, __FUNCTION__, DEBUG_STUB("%s %-35s: MSG: %p TYPE: %d\n", STUB_DEBUG_ENTRY, __FUNC__,
(void*)netreq, netreq->request_type); (void*)netreq, netreq->request_type);
int fd = -1; int fd = -1;
getdns_dns_req *dnsreq = netreq->owner; getdns_dns_req *dnsreq = netreq->owner;

View File

@ -1,16 +0,0 @@
BaseName: 315-event-loops-compile
Version: 1.0
Description: Compile
CreationDate: do 8 dec 2016 23:38:18 CET
Maintainer: Willem Toorop
Category:
Component:
CmdDepends:
Depends: 300-event-loops-configure.tpkg
Help:
Pre: 315-event-loops-compile.pre
Post: 315-event-loops-compile.post
Test: 315-event-loops-compile.test
AuxFiles:
Passed:
Failure:

View File

@ -1,20 +0,0 @@
# #-- 315-event-loops-compile.post --#
# source the master var file when it's there
if [ -f ../.tpkg.var.master ]
then
source ../.tpkg.var.master
else
(
cd ..
[ -f "${TPKG_SRCDIR}/setup-env.sh" ] \
&& sh "${TPKG_SRCDIR}/setup-env.sh"
) && source ../.tpkg.var.master
fi
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test
for f in `cat restore-srcdir-configure-settings`
do
mv "${SRCROOT}/${f}.build-event-loops" "${SRCROOT}/${f}"
done

View File

@ -1,24 +0,0 @@
# #-- 315-event-loops-compile.pre--#
# source the master var file when it's there
if [ -f ../.tpkg.var.master ]
then
source ../.tpkg.var.master
else
(
cd ..
[ -f "${TPKG_SRCDIR}/setup-env.sh" ] \
&& sh "${TPKG_SRCDIR}/setup-env.sh"
) && source ../.tpkg.var.master
fi
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test
echo "" > restore-srcdir-configure-settings
for f in `grep 'CONFIG_[FH][IE][LA][ED][SE]' "${SRCROOT}/configure.ac" | sed -e 's/^.*(\[//g' -e 's/\])//g'`
do
if [ -f "${SRCROOT}/$f" ]
then
mv "${SRCROOT}/${f}" "${SRCROOT}/${f}.build-event-loops" && \
echo "$f" >> restore-srcdir-configure-settings
fi
done

View File

@ -1,8 +0,0 @@
# #-- 315-event-loops-compile.test --#
# source the master var file when it's there
[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test
cd "${BUILDDIR}/build-event-loops"
make XTRA_CFLAGS='-Werror'

View File

@ -5,5 +5,4 @@
[ -f .tpkg.var.test ] && source .tpkg.var.test [ -f .tpkg.var.test ] && source .tpkg.var.test
cd "${BUILDDIR}/build-event-loops" cd "${BUILDDIR}/build-event-loops"
make clean make XTRA_CFLAGS=-Werror
make

View File

@ -1367,7 +1367,7 @@ static void request_cb(
qname_str = unknown_qname; qname_str = unknown_qname;
DEBUG_SERVER("reply for: %p %"PRIu64" %d (edns0: %d, do: %d, ad: %d," DEBUG_SERVER("reply for: %p %"PRIu64" %d (edns0: %d, do: %d, ad: %d,"
" cd: %d, qname: %s)\n", msg, transaction_id, (int)callback_type, " cd: %d, qname: %s)\n", (void *)msg, transaction_id, (int)callback_type,
msg->has_edns0, msg->do_bit, msg->ad_bit, msg->cd_bit, qname_str); msg->has_edns0, msg->do_bit, msg->ad_bit, msg->cd_bit, qname_str);
if (qname_str != unknown_qname) if (qname_str != unknown_qname)
@ -1584,7 +1584,7 @@ static void incoming_request_handler(getdns_context *context,
getdns_get_errorstr_by_id(r)); getdns_get_errorstr_by_id(r));
else { else {
DEBUG_SERVER("scheduled: %p %"PRIu64" for %s %d\n", DEBUG_SERVER("scheduled: %p %"PRIu64" for %s %d\n",
msg, transaction_id, qname_str, (int)qtype); (void *)msg, transaction_id, qname_str, (int)qtype);
free(qname_str); free(qname_str);
return; return;
} }

View File

@ -149,7 +149,7 @@ static int my_event_base_loopexit(struct ub_event_base* base, struct timeval* tv
static void clear_my_event(my_event *ev) static void clear_my_event(my_event *ev)
{ {
DEBUG_SCHED("UB_LOOP: to clear %p(%d, %d, %"PRIu64"), total: %d\n" DEBUG_SCHED("UB_LOOP: to clear %p(%d, %d, %"PRIu64"), total: %d\n"
, ev, ev->fd, ev->bits, ev->timeout, ev->loop->n_events); , (void *)ev, ev->fd, ev->bits, ev->timeout, ev->loop->n_events);
(ev)->loop->extension->vmt->clear((ev)->loop->extension, &(ev)->gev); (ev)->loop->extension->vmt->clear((ev)->loop->extension, &(ev)->gev);
(ev)->added = 0; (ev)->added = 0;
if ((ev)->active) { if ((ev)->active) {
@ -157,7 +157,7 @@ static void clear_my_event(my_event *ev)
(ev)->active = NULL; (ev)->active = NULL;
} }
DEBUG_SCHED("UB_LOOP: %p(%d, %d, %"PRIu64") cleared, total: %d\n" DEBUG_SCHED("UB_LOOP: %p(%d, %d, %"PRIu64") cleared, total: %d\n"
, ev, ev->fd, ev->bits, ev->timeout, --ev->loop->n_events); , (void *)ev, ev->fd, ev->bits, ev->timeout, --ev->loop->n_events);
} }
static getdns_return_t schedule_my_event(my_event *ev) static getdns_return_t schedule_my_event(my_event *ev)
@ -165,16 +165,16 @@ static getdns_return_t schedule_my_event(my_event *ev)
getdns_return_t r; getdns_return_t r;
DEBUG_SCHED("UB_LOOP: to schedule %p(%d, %d, %"PRIu64"), total: %d\n" DEBUG_SCHED("UB_LOOP: to schedule %p(%d, %d, %"PRIu64"), total: %d\n"
, ev, ev->fd, ev->bits, ev->timeout, ev->loop->n_events); , (void *)ev, ev->fd, ev->bits, ev->timeout, ev->loop->n_events);
if (ev->gev.read_cb || ev->gev.write_cb || ev->gev.timeout_cb) { if (ev->gev.read_cb || ev->gev.write_cb || ev->gev.timeout_cb) {
if ((r = ev->loop->extension->vmt->schedule( if ((r = ev->loop->extension->vmt->schedule(
ev->loop->extension, ev->fd, ev->timeout, &ev->gev))) { ev->loop->extension, ev->fd, ev->timeout, &ev->gev))) {
DEBUG_SCHED("UB_LOOP ERROR: scheduling event: %p\n", ev); DEBUG_SCHED("UB_LOOP ERROR: scheduling event: %p\n", (void *)ev);
return r; return r;
} }
ev->added = 1; ev->added = 1;
DEBUG_SCHED("UB_LOOP: event %p(%d, %d, %"PRIu64") scheduled, " DEBUG_SCHED("UB_LOOP: event %p(%d, %d, %"PRIu64") scheduled, "
"total: %d\n", ev, ev->fd, ev->bits, ev->timeout "total: %d\n", (void *)ev, ev->fd, ev->bits, ev->timeout
, ++ev->loop->n_events); , ++ev->loop->n_events);
} }
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;