Merge pull request #1 from wtoorop/devel/fixed_eventloop

Devel/fixed eventloop
This commit is contained in:
Neil Cook 2016-12-15 11:20:45 +00:00 committed by GitHub
commit efb50939bc
14 changed files with 127 additions and 157 deletions

View File

@ -945,6 +945,14 @@ fi
#---- 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_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 ----- Start of "Things needed for gldns" section
@ -1061,6 +1069,12 @@ AC_DEFINE_UNQUOTED([MAX_CNAME_REFERRALS], [100], [The maximum number of cname re
AH_BOTTOM([
#ifdef HAVE___FUNC__
#define __FUNC__ __func__
#else
#define __FUNC__ __FUNCTION__
#endif
#ifdef GETDNS_ON_WINDOWS
/* On windows it is allowed to increase the FD_SETSIZE
* (and nescessary to make our custom eventloop work)

View File

@ -62,6 +62,11 @@ typedef unsigned short in_port_t;
#include <assert.h>
#include <ctype.h>
#ifdef HAVE_PTHREADS
#include <pthread.h>
#endif
#include <stdbool.h>
#include "config.h"
#ifdef HAVE_LIBUNBOUND
#include <unbound.h>
@ -85,6 +90,11 @@ typedef unsigned short in_port_t;
#define GETDNS_STR_PORT_DNS "53"
#define GETDNS_STR_PORT_DNS_OVER_TLS "853"
#ifdef HAVE_PTHREADS
static pthread_mutex_t ssl_init_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
static bool ssl_init=false;
void *plain_mem_funcs_user_arg = MF_PLAIN;
typedef struct host_name_addrs {
@ -152,7 +162,7 @@ add_WIN_cacerts_to_openssl_store(SSL_CTX* tls_ctx)
HCERTSTORE hSystemStore;
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");
/* load just once per context lifetime for this version of getdns
@ -181,7 +191,7 @@ add_WIN_cacerts_to_openssl_store(SSL_CTX* tls_ctx)
/* failure if the CA store is empty or the call fails */
if ((pTargetCert = CertEnumCertificatesInStore(
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.");
return 0;
}
@ -193,7 +203,7 @@ add_WIN_cacerts_to_openssl_store(SSL_CTX* tls_ctx)
pTargetCert->cbCertEncoded);
if (!cert1) {
/* 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",
ERR_get_error(), ERR_error_string(ERR_get_error(), NULL));
return 0;
@ -201,7 +211,7 @@ add_WIN_cacerts_to_openssl_store(SSL_CTX* tls_ctx)
else {
/* return error if a cert add to store fails */
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(),
ERR_error_string(ERR_get_error(), NULL));
return 0;
@ -1324,8 +1334,21 @@ getdns_context_create_with_extended_memory_functions(
/* Unbound needs SSL to be init'ed this early when TLS is used. However we
* don't know that till later so we will have to do this every time. */
if ((set_from_os & 2) == 0)
#ifdef HAVE_PTHREADS
pthread_mutex_lock(&ssl_init_lock);
#else
/* XXX implement Windows-style lock here */
#endif
/* Only initialise SSL once and ideally in a thread-safe manner */
if (ssl_init == false) {
SSL_library_init();
ssl_init = true;
}
#ifdef HAVE_PTHREADS
pthread_mutex_unlock(&ssl_init_lock);
#else
/* XXX implement Windows-style unlock here */
#endif
#ifdef HAVE_LIBUNBOUND
result->unbound_ctx = NULL;
@ -1525,7 +1548,7 @@ getdns_context_request_count_changed(getdns_context *context)
if (context->outbound_requests.count && ! context->ub_event.ev){
DEBUG_SCHED("gc_request_count_changed "
"-> 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
#ifdef HAVE_UNBOUND_EVENT_API
if (!_getdns_ub_loop_enabled(&context->ub_loop))
@ -1539,7 +1562,7 @@ getdns_context_request_count_changed(getdns_context *context)
context->ub_event.ev) {
DEBUG_SCHED("gc_request_count_changed "
"-> 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
#ifdef HAVE_UNBOUND_EVENT_API

View File

@ -80,7 +80,7 @@ default_eventloop_schedule(getdns_eventloop *loop,
size_t i;
DEBUG_SCHED( "%s(loop: %p, fd: %d, timeout: %"PRIu64", event: %p, max_fds: %d)\n"
, __FUNCTION__, loop, fd, timeout, event, default_loop->max_fds);
, __FUNC__, (void *)loop, fd, timeout, (void *)event, default_loop->max_fds);
if (!loop || !event)
return GETDNS_RETURN_INVALID_PARAMETER;
@ -102,11 +102,11 @@ default_eventloop_schedule(getdns_eventloop *loop,
if (fd_event->event == event) {
DEBUG_SCHED("WARNING: Event %p not cleared "
"before being rescheduled!\n"
, fd_event->event);
, (void *)fd_event->event);
} else {
DEBUG_SCHED("ERROR: A different event is "
"already present at fd slot: %p!\n"
, fd_event->event);
, (void *)fd_event->event);
}
}
#endif
@ -119,7 +119,7 @@ default_eventloop_schedule(getdns_eventloop *loop,
fd_event->event = event;
fd_event->timeout_time = get_now_plus(timeout);
add_event(&default_loop->fd_events, fd, fd_event);
event->ev = (void *) (intptr_t) fd + 1;
event->ev = (void *) (intptr_t) (fd + 1);
DEBUG_SCHED( "scheduled read/write at %d\n", fd);
return GETDNS_RETURN_GOOD;
@ -143,7 +143,7 @@ default_eventloop_schedule(getdns_eventloop *loop,
timeout_event->event = event;
timeout_event->timeout_time = get_now_plus(timeout);
add_event(&default_loop->timeout_events, i, timeout_event);
event->ev = (void *) (intptr_t) i + 1;
event->ev = (void *) (intptr_t) (i + 1);
DEBUG_SCHED( "scheduled timeout at %d\n", (int)i);
return GETDNS_RETURN_GOOD;
@ -162,7 +162,7 @@ default_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
if (!loop || !event)
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;
if (i < 0 || i > default_loop->max_fds) {
@ -174,7 +174,8 @@ default_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
if (timeout_event && timeout_event->event != event)
DEBUG_SCHED( "ERROR: Different/wrong event present at "
"timeout slot: %p!\n"
, timeout_event);
, (void *)timeout_event);
#endif
if (timeout_event) {
delete_event(&default_loop->timeout_events, timeout_event);
@ -186,7 +187,7 @@ default_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
if (fd_event && fd_event->event != event)
DEBUG_SCHED( "ERROR: Different/wrong event present at "
"fd slot: %p!\n"
, fd_event);
, (void *)fd_event);
#endif
if (fd_event) {
delete_event(&default_loop->fd_events, fd_event);
@ -211,7 +212,7 @@ default_read_cb(int fd, getdns_eventloop_event *event)
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#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);
}
@ -221,7 +222,7 @@ default_write_cb(int fd, getdns_eventloop_event *event)
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#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);
}
@ -231,7 +232,7 @@ default_timeout_cb(int fd, getdns_eventloop_event *event)
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#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);
}

View File

@ -419,7 +419,7 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
x = sk_X509_value(X509_STORE_CTX_get0_untrusted(store), i);
#if defined(STUB_DEBUG) && STUB_DEBUG
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);
fprintf(stderr, "\n");
#endif
@ -427,13 +427,13 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
len = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), NULL);
if (len > (int)sizeof(raw)) {
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;
}
i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), &next);
if (next - raw != len) {
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;
}
SHA256(raw, len, buf);
@ -442,11 +442,11 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
for (p = pinset; p; p = p->next)
if (0 == memcmp(buf, p->pin, sizeof(p->pin))) {
DEBUG_STUB("%s %-35s: Pubkey %d matched pin %p ("PRIsz")\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, p, sizeof(p->pin));
STUB_DEBUG_SETUP_TLS, __FUNC__, i, (void *)p, sizeof(p->pin));
return GETDNS_RETURN_GOOD;
} else
DEBUG_STUB("%s %-35s: Pubkey %d did not match pin %p\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, p);
STUB_DEBUG_SETUP_TLS, __FUNC__, i, (void *)p);
}
return ret;

View File

@ -472,7 +472,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
HMAC_CTX ctx_space;
#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,
(req->response - req->query))
; rr
@ -489,7 +489,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
if (request_mac_len != rdf->nxt - rdf->pos - 2)
return;
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;
@ -546,7 +546,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
if (response_mac_len != rdf->nxt - rdf->pos - 2)
return;
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;
if (!(rdf = _getdns_rdf_iter_next(rdf)) ||
@ -571,7 +571,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
/* TSIG found */
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_read_uint16(req->response + 10) - 1);
@ -612,7 +612,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
HMAC_Final(ctx, result_mac, &result_mac_len);
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 &&
memcmp(result_mac, response_mac, result_mac_len) == 0)
req->tsig_status = GETDNS_DNSSEC_SECURE;

View File

@ -247,7 +247,7 @@ match_edns_opt_rr(uint16_t code, uint8_t *response, size_t response_len,
(void) gldns_wire2str_rr_scan(
&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\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, str_spc);
STUB_DEBUG_CLEANUP, __FUNC__, str_spc);
#endif
/* OPT found, now search for the specified option */
@ -339,7 +339,7 @@ process_keepalive(
else {
upstream->keepalive_timeout = server_keepalive;
DEBUG_STUB("%s %-35s: FD: %d Server Keepalive used: %d ms\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd,
STUB_DEBUG_CLEANUP, __FUNC__, upstream->fd,
(int)server_keepalive);
}
}
@ -369,7 +369,7 @@ tcp_connect(getdns_upstream *upstream, getdns_transport_list_t transport)
{
int fd = -1;
DEBUG_STUB("%s %-35s: Creating TCP connection: %p\n", STUB_DEBUG_SETUP,
__FUNCTION__, upstream);
__FUNC__, (void *)upstream);
if ((fd = socket(upstream->addr.ss_family, SOCK_STREAM, IPPROTO_TCP)) == -1)
return -1;
@ -464,7 +464,7 @@ static void
stub_cleanup(getdns_network_req *netreq)
{
DEBUG_STUB("%s %-35s: MSG: %p\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, netreq);
STUB_DEBUG_CLEANUP, __FUNC__, (void *)netreq);
getdns_dns_req *dnsreq = netreq->owner;
getdns_network_req *r, *prev_r;
getdns_upstream *upstream;
@ -506,7 +506,7 @@ static int
tls_cleanup(getdns_upstream *upstream, int handshake_fail)
{
DEBUG_STUB("%s %-35s: FD: %d\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd);
STUB_DEBUG_CLEANUP, __FUNC__, upstream->fd);
if (upstream->tls_obj != NULL)
SSL_free(upstream->tls_obj);
upstream->tls_obj = NULL;
@ -526,7 +526,7 @@ static void
upstream_erred(getdns_upstream *upstream)
{
DEBUG_STUB("%s %-35s: FD: %d\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, upstream->fd);
STUB_DEBUG_CLEANUP, __FUNC__, upstream->fd);
getdns_network_req *netreq;
while ((netreq = upstream->write_queue)) {
@ -561,7 +561,7 @@ _getdns_cancel_stub_request(getdns_network_req *netreq)
/*static void
stub_erred(getdns_network_req *netreq)
{
DEBUG_STUB("*** %s\n", __FUNCTION__);
DEBUG_STUB("*** %s\n", __FUNC__);
stub_next_upstream(netreq);
stub_cleanup(netreq);
if (netreq->fd >= 0) close(netreq->fd);
@ -574,7 +574,7 @@ stub_timeout_cb(void *userarg)
{
getdns_network_req *netreq = (getdns_network_req *)userarg;
DEBUG_STUB("%s %-35s: MSG: %p\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, netreq);
STUB_DEBUG_CLEANUP, __FUNC__, (void *)netreq);
stub_next_upstream(netreq);
stub_cleanup(netreq);
if (netreq->fd >= 0)
@ -597,7 +597,7 @@ upstream_idle_timeout_cb(void *userarg)
{
getdns_upstream *upstream = (getdns_upstream *)userarg;
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);
upstream->event.timeout_cb = NULL;
upstream->event.read_cb = NULL;
@ -610,7 +610,7 @@ upstream_tls_timeout_cb(void *userarg)
{
getdns_upstream *upstream = (getdns_upstream *)userarg;
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 */
tls_cleanup(upstream, 1);
@ -638,7 +638,7 @@ stub_tls_timeout_cb(void *userarg)
getdns_network_req *netreq = (getdns_network_req *)userarg;
getdns_upstream *upstream = netreq->upstream;
DEBUG_STUB("%s %-35s: MSG: %p\n",
STUB_DEBUG_CLEANUP, __FUNCTION__, netreq);
STUB_DEBUG_CLEANUP, __FUNC__, (void *)netreq);
/* Clean up and trigger a write to let the fallback code to its job */
tls_cleanup(upstream, 0);
@ -773,7 +773,7 @@ stub_tcp_write(int fd, getdns_tcp_state *tcp, getdns_network_req *netreq)
netreq->owner->context->idle_timeout != 0) {
/* Add the keepalive option to the first query on this connection*/
DEBUG_STUB("%s %-35s: FD: %d Requesting keepalive \n",
STUB_DEBUG_WRITE, __FUNCTION__, fd);
STUB_DEBUG_WRITE, __FUNC__, fd);
if (attach_edns_keepalive(netreq))
return STUB_OUT_OF_OPTIONS;
netreq->keepalive_sent = 1;
@ -904,7 +904,7 @@ tls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
int err = X509_STORE_CTX_get_error(ctx);
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));
#endif
@ -912,19 +912,19 @@ tls_verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
/*Report if error is hostname mismatch*/
if (upstream && upstream->tls_fallback_ok && err == X509_V_ERR_HOSTNAME_MISMATCH)
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);
#endif
if (upstream && upstream->tls_pubkey_pinset)
pinset_ret = _getdns_verify_pinset_match(upstream->tls_pubkey_pinset, ctx);
if (pinset_ret != GETDNS_RETURN_GOOD) {
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;
upstream->tls_auth_failed = 1;
if (upstream->tls_fallback_ok)
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);
}
/* If fallback is allowed, proceed regardless of what the auth error is
(might not be hostname or pinset related) */
@ -961,7 +961,7 @@ tls_create_object(getdns_dns_req *dnsreq, int fd, getdns_upstream *upstream)
if (upstream->tls_auth_name[0] != '\0') {
/*Request certificate for the auth_name*/
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);
#ifdef HAVE_SSL_HN_AUTH
/* Set up native OpenSSL hostname verification*/
@ -973,7 +973,7 @@ tls_create_object(getdns_dns_req *dnsreq, int fd, getdns_upstream *upstream)
if (dnsreq->netreqs[0]->tls_auth_min == GETDNS_AUTHENTICATION_REQUIRED) {
/* TODO: Trigger post-handshake custom validation*/
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_auth_failed = 1;
return NULL;
@ -988,10 +988,10 @@ tls_create_object(getdns_dns_req *dnsreq, int fd, getdns_upstream *upstream)
if (dnsreq->netreqs[0]->tls_auth_min == GETDNS_AUTHENTICATION_REQUIRED) {
if (upstream->tls_pubkey_pinset) {
DEBUG_STUB("%s %-35s: Proceeding with only pubkey pinning authentication\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__);
STUB_DEBUG_SETUP_TLS, __FUNC__);
} else {
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_auth_failed = 1;
return NULL;
@ -999,7 +999,7 @@ tls_create_object(getdns_dns_req *dnsreq, int fd, getdns_upstream *upstream)
} else {
/* no hostname verification, so we will make opportunistic connections */
DEBUG_STUB("%s %-35s: Proceeding even though no hostname provided!\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__);
STUB_DEBUG_SETUP_TLS, __FUNC__);
upstream->tls_auth_failed = 1;
upstream->tls_fallback_ok = 1;
}
@ -1007,10 +1007,10 @@ tls_create_object(getdns_dns_req *dnsreq, int fd, getdns_upstream *upstream)
if (upstream->tls_fallback_ok) {
SSL_set_cipher_list(ssl, "DEFAULT");
DEBUG_STUB("%s %-35s: WARNING: Using Oppotunistic TLS (fallback allowed)!\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__);
STUB_DEBUG_SETUP_TLS, __FUNC__);
} else
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_connect_state(ssl);
@ -1022,7 +1022,7 @@ static int
tls_do_handshake(getdns_upstream *upstream)
{
DEBUG_STUB("%s %-35s: FD: %d \n", STUB_DEBUG_SETUP_TLS,
__FUNCTION__, upstream->fd);
__FUNC__, upstream->fd);
int r;
int want;
ERR_clear_error();
@ -1048,14 +1048,14 @@ tls_do_handshake(getdns_upstream *upstream)
return STUB_TCP_AGAIN;
default:
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);
return tls_cleanup(upstream, 1);
}
}
upstream->tls_hs_state = GETDNS_HS_DONE;
DEBUG_STUB("%s %-35s: FD: %d Handshake succeeded\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd);
STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->fd);
r = SSL_get_verify_result(upstream->tls_obj);
if (upstream->tls_auth_name[0])
#ifdef X509_V_ERR_HOSTNAME_MISMATCH
@ -1067,7 +1067,7 @@ tls_do_handshake(getdns_upstream *upstream)
#endif
upstream->tls_auth_failed = 1;
DEBUG_STUB("%s %-35s: FD: %d Session is %s\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd,
STUB_DEBUG_SETUP_TLS, __FUNC__, upstream->fd,
SSL_session_reused(upstream->tls_obj) ?"re-used":"new");
if (upstream->tls_session != NULL)
SSL_SESSION_free(upstream->tls_session);
@ -1242,7 +1242,7 @@ stub_tls_write(getdns_upstream *upstream, getdns_tcp_state *tcp,
/* Add the keepalive option to every nth query on this
connection */
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))
return STUB_OUT_OF_OPTIONS;
netreq->keepalive_sent = 1;
@ -1304,7 +1304,7 @@ stub_udp_read_cb(void *userarg)
getdns_upstream *upstream = netreq->upstream;
ssize_t read;
DEBUG_STUB("%s %-35s: MSG: %p \n", STUB_DEBUG_READ,
__FUNCTION__, netreq);
__FUNC__, (void *)netreq);
GETDNS_CLEAR_EVENT(dnsreq->loop, &netreq->event);
@ -1336,7 +1336,7 @@ stub_udp_read_cb(void *userarg)
#endif
while (GLDNS_TC_WIRE(netreq->response)) {
DEBUG_STUB("%s %-35s: MSG: %p TC bit set in response \n", STUB_DEBUG_READ,
__FUNCTION__, netreq);
__FUNC__, (void *)netreq);
if (!(netreq->transport_current < netreq->transport_count))
break;
getdns_transport_list_t next_transport =
@ -1370,7 +1370,7 @@ stub_udp_write_cb(void *userarg)
getdns_dns_req *dnsreq = netreq->owner;
size_t pkt_len;
DEBUG_STUB("%s %-35s: MSG: %p \n", STUB_DEBUG_WRITE,
__FUNCTION__, netreq);
__FUNC__, (void *)netreq);
GETDNS_CLEAR_EVENT(dnsreq->loop, &netreq->event);
@ -1436,7 +1436,7 @@ static void
upstream_read_cb(void *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);
getdns_network_req *netreq;
int q;
@ -1477,7 +1477,7 @@ upstream_read_cb(void *userarg)
}
DEBUG_STUB("%s %-35s: MSG: %p (read)\n",
STUB_DEBUG_READ, __FUNCTION__, netreq);
STUB_DEBUG_READ, __FUNC__, (void *)netreq);
netreq->state = NET_REQ_FINISHED;
netreq->response = upstream->tcp.read_buf;
netreq->response_len =
@ -1561,7 +1561,7 @@ upstream_write_cb(void *userarg)
/* TODO: think about TCP AGAIN */
netreq->debug_start_time = _getdns_get_time_as_uintt64();
DEBUG_STUB("%s %-35s: MSG: %p (writing)\n", STUB_DEBUG_WRITE,
__FUNCTION__, netreq);
__FUNC__, (void *)netreq);
if (tls_requested(netreq) && tls_should_write(upstream))
q = stub_tls_write(upstream, &upstream->tcp, netreq);
@ -1579,7 +1579,7 @@ upstream_write_cb(void *userarg)
case STUB_TCP_ERROR:
/* Problem with the TCP connection itself. Need to fallback.*/
DEBUG_STUB("%s %-35s: MSG: %p ERROR!\n", STUB_DEBUG_WRITE,
__FUNCTION__, ((getdns_network_req *)userarg));
__FUNC__, userarg);
upstream->tcp.write_error = 1;
/* Use policy of trying next upstream in this case. Need more work on
* TCP connection re-use.*/
@ -1672,14 +1672,14 @@ upstream_select(getdns_network_req *netreq, getdns_transport_list_t transport)
/* transport type and/or maintain separate current for transports?*/
i = upstreams->current;
DEBUG_STUB("%s %-35s: Starting from upstream: %d of %d available \n", STUB_DEBUG_SETUP,
__FUNCTION__, (int)i, (int)upstreams->count);
__FUNC__, (int)i, (int)upstreams->count);
do {
if (upstreams->upstreams[i].to_retry > 0 &&
upstream_transport_valid(&upstreams->upstreams[i], transport, netreq)) {
upstreams->current = i;
DEBUG_STUB("%s %-35s: Selected upstream: %d %p transport: %d\n",
STUB_DEBUG_SETUP, __FUNCTION__, (int)i,
&upstreams->upstreams[i], transport);
STUB_DEBUG_SETUP, __FUNC__, (int)i,
(void *)&upstreams->upstreams[i], transport);
return &upstreams->upstreams[i];
}
if (++i >= upstreams->count)
@ -1695,7 +1695,7 @@ upstream_select(getdns_network_req *netreq, getdns_transport_list_t transport)
/* Need to check again that the transport is valid */
if (!upstream_transport_valid(upstream, transport, netreq)) {
DEBUG_STUB("%s %-35s: No valid upstream available for transport %d!\n",
STUB_DEBUG_SETUP, __FUNCTION__, transport);
STUB_DEBUG_SETUP, __FUNC__, transport);
return NULL;
}
upstream->back_off++;
@ -1710,7 +1710,7 @@ upstream_connect(getdns_upstream *upstream, getdns_transport_list_t transport,
getdns_dns_req *dnsreq)
{
DEBUG_STUB("%s %-35s: Checking upstream connection: %p\n", STUB_DEBUG_SETUP,
__FUNCTION__, upstream);
__FUNC__, (void *)upstream);
int fd = -1;
switch(transport) {
case GETDNS_TRANSPORT_UDP:
@ -1771,7 +1771,7 @@ upstream_find_for_transport(getdns_network_req *netreq,
return NULL;
*fd = upstream_connect(upstream, transport, netreq->owner);
DEBUG_STUB("%s %-35s: FD: %d Connected for upstream: %p\n",
STUB_DEBUG_SETUP, __FUNCTION__, *fd, upstream);
STUB_DEBUG_SETUP, __FUNC__, *fd, (void *)upstream);
return upstream;
}
@ -1805,7 +1805,7 @@ fallback_on_write(getdns_network_req *netreq)
/* Deal with UDP and change error code*/
DEBUG_STUB("%s %-35s: MSG: %p FALLING BACK \n", STUB_DEBUG_SCHEDULE, __FUNCTION__, netreq);
DEBUG_STUB("%s %-35s: MSG: %p FALLING BACK \n", STUB_DEBUG_SCHEDULE, __FUNC__, (void *)netreq);
/* Try to find a fallback transport*/
getdns_return_t result = _getdns_submit_stub_request(netreq);
@ -1822,7 +1822,7 @@ static void
upstream_reschedule_events(getdns_upstream *upstream, uint64_t idle_timeout) {
DEBUG_STUB("%s %-35s: FD: %d \n", STUB_DEBUG_SCHEDULE,
__FUNCTION__, upstream->fd);
__FUNC__, upstream->fd);
GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event);
if (!upstream->write_queue && upstream->event.write_cb) {
upstream->event.write_cb = NULL;
@ -1841,7 +1841,7 @@ upstream_reschedule_events(getdns_upstream *upstream, uint64_t idle_timeout) {
upstream->fd, TIMEOUT_FOREVER, &upstream->event);
else {
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;
if (upstream->tcp.write_error != 0)
idle_timeout = 0;
@ -1853,7 +1853,7 @@ upstream_reschedule_events(getdns_upstream *upstream, uint64_t idle_timeout) {
static void
upstream_schedule_netreq(getdns_upstream *upstream, getdns_network_req *netreq)
{
DEBUG_STUB("%s %-35s: MSG: %p (schedule event)\n", STUB_DEBUG_SCHEDULE, __FUNCTION__, 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 */
assert(upstream->fd >= 0);
assert(upstream->loop);
@ -1906,8 +1906,8 @@ upstream_schedule_netreq(getdns_upstream *upstream, getdns_network_req *netreq)
getdns_return_t
_getdns_submit_stub_request(getdns_network_req *netreq)
{
DEBUG_STUB("%s %-35s: MSG: %p TYPE: %d\n", STUB_DEBUG_ENTRY, __FUNCTION__,
netreq, netreq->request_type);
DEBUG_STUB("%s %-35s: MSG: %p TYPE: %d\n", STUB_DEBUG_ENTRY, __FUNC__,
(void *)netreq, netreq->request_type);
int fd = -1;
getdns_dns_req *dnsreq = netreq->owner;

View File

@ -616,7 +616,7 @@ static void free_listen_set_when_done(listen_set *set)
if (!(mf = priv_getdns_context_mf(set->context)))
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++) {
listener *l = &set->items[i];
@ -627,7 +627,7 @@ static void free_listen_set_when_done(listen_set *set)
return;
}
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)
@ -761,8 +761,8 @@ getdns_return_t getdns_context_set_listen_addresses(getdns_context *context,
size_t i;
struct addrinfo hints;
DEBUG_SERVER("getdns_context_set_listen_addresses(%p, %p, %p)\n", context, request_handler,
listen_addresses);
DEBUG_SERVER("getdns_context_set_listen_addresses(%p, <func>, %p)\n",
(void *)context, (void *)listen_addresses);
if (!(mf = priv_getdns_context_mf(context)))
return GETDNS_RETURN_GENERIC_ERROR;
@ -796,7 +796,8 @@ getdns_return_t getdns_context_set_listen_addresses(getdns_context *context,
sizeof(listener) * new_set_count * n_transports)))
return GETDNS_RETURN_MEMORY_ERROR;
DEBUG_SERVER("New listen set: %p, current_set: %p\n", new_set, current_set);
DEBUG_SERVER("New listen set: %p, current_set: %p\n",
(void *)new_set, (void *)current_set);
new_set->context = context;
new_set->next = root;

View File

@ -1288,7 +1288,7 @@ static void request_cb(
(void)transaction_id;
#endif
DEBUG_SERVER("reply for: %p %"PRIu64" %d (edns0: %d, do: %d, ad: %d,"
" cd: %d)\n", msg, transaction_id, (int)callback_type,
" cd: %d)\n", (void *)msg, transaction_id, (int)callback_type,
msg->has_edns0, msg->do_bit, msg->ad_bit, msg->cd_bit);
assert(msg);
@ -1498,7 +1498,7 @@ static void incoming_request_handler(getdns_context *context,
getdns_get_errorstr_by_id(r));
else {
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);
return;
}

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
cd "${BUILDDIR}/build-event-loops"
make clean
make
make XTRA_CFLAGS=-Werror

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)
{
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)->added = 0;
if ((ev)->active) {
@ -157,7 +157,7 @@ static void clear_my_event(my_event *ev)
(ev)->active = NULL;
}
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)
@ -165,16 +165,16 @@ static getdns_return_t schedule_my_event(my_event *ev)
getdns_return_t r;
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 ((r = ev->loop->extension->vmt->schedule(
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;
}
ev->added = 1;
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);
}
return GETDNS_RETURN_GOOD;