mirror of https://github.com/getdnsapi/getdns.git
Add trivial stub_debug functions.
This commit is contained in:
parent
9d967317d3
commit
9a7bfdd45b
69
src/stub.c
69
src/stub.c
|
@ -51,6 +51,8 @@
|
||||||
/* Don't currently have access to the context whilst doing handshake */
|
/* Don't currently have access to the context whilst doing handshake */
|
||||||
#define TIMEOUT_TLS 2500
|
#define TIMEOUT_TLS 2500
|
||||||
|
|
||||||
|
#define STUB_DEBUG 0
|
||||||
|
|
||||||
static time_t secret_rollover_time = 0;
|
static time_t secret_rollover_time = 0;
|
||||||
static uint32_t secret = 0;
|
static uint32_t secret = 0;
|
||||||
static uint32_t prev_secret = 0;
|
static uint32_t prev_secret = 0;
|
||||||
|
@ -69,6 +71,14 @@ static void stub_tcp_write_cb(void *userarg);
|
||||||
/* General utility functions */
|
/* General utility functions */
|
||||||
/*****************************/
|
/*****************************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
stub_debug(const char *function_name)
|
||||||
|
{
|
||||||
|
#ifdef STUB_DEBUG
|
||||||
|
fprintf(stderr,"[STUB DEBUG]: %s\n", function_name);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rollover_secret()
|
rollover_secret()
|
||||||
{
|
{
|
||||||
|
@ -292,12 +302,8 @@ is_starttls_response(getdns_network_req *netreq)
|
||||||
size_t starttls_name_len = 256, owner_name_len;
|
size_t starttls_name_len = 256, owner_name_len;
|
||||||
|
|
||||||
/* Servers that are not STARTTLS aware will refuse the CH query*/
|
/* Servers that are not STARTTLS aware will refuse the CH query*/
|
||||||
if (LDNS_RCODE_NOERROR !=
|
if (LDNS_RCODE_NOERROR != GLDNS_RCODE_WIRE(netreq->response))
|
||||||
GLDNS_RCODE_WIRE(netreq->response)) {
|
|
||||||
fprintf(stderr, "[TLS] STARTTLS response had error %d\n",
|
|
||||||
GLDNS_RCODE_WIRE(netreq->response));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (GLDNS_ANCOUNT(netreq->response) != 1)
|
if (GLDNS_ANCOUNT(netreq->response) != 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -327,15 +333,10 @@ is_starttls_response(getdns_network_req *netreq)
|
||||||
/* re-use the starttls_name for the response dname*/
|
/* re-use the starttls_name for the response dname*/
|
||||||
starttls_name = priv_getdns_rdf_if_or_as_decompressed(
|
starttls_name = priv_getdns_rdf_if_or_as_decompressed(
|
||||||
rdf_iter,starttls_name_space,&starttls_name_len);
|
rdf_iter,starttls_name_space,&starttls_name_len);
|
||||||
if (dname_equal(starttls_name, owner_name)) {
|
if (dname_equal(starttls_name, owner_name))
|
||||||
fprintf(stderr, "[TLS] STARTTLS response received :%s:\n",
|
|
||||||
(char*)starttls_name);
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
else
|
||||||
fprintf(stderr, "[TLS] NO_TLS response received :%s:\n",
|
|
||||||
(char*)starttls_name);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -364,7 +365,6 @@ getdns_sock_nonblock(int sockfd)
|
||||||
static int
|
static int
|
||||||
tcp_connect(getdns_upstream *upstream, getdns_base_transport_t transport)
|
tcp_connect(getdns_upstream *upstream, getdns_base_transport_t transport)
|
||||||
{
|
{
|
||||||
|
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
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;
|
||||||
|
@ -546,8 +546,7 @@ stub_timeout_cb(void *userarg)
|
||||||
static void
|
static void
|
||||||
upstream_tls_timeout_cb(void *userarg)
|
upstream_tls_timeout_cb(void *userarg)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"[TLS]: TIMEOUT(upstream_tls_timeout_cb)\n");
|
stub_debug(__FUNCTION__);
|
||||||
|
|
||||||
getdns_upstream *upstream = (getdns_upstream *)userarg;
|
getdns_upstream *upstream = (getdns_upstream *)userarg;
|
||||||
/* 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 */
|
||||||
tls_cleanup(upstream);
|
tls_cleanup(upstream);
|
||||||
|
@ -565,8 +564,6 @@ upstream_tls_timeout_cb(void *userarg)
|
||||||
tval.tv_usec = 0;
|
tval.tv_usec = 0;
|
||||||
ret = select(upstream->fd+1, NULL, &fds, NULL, &tval);
|
ret = select(upstream->fd+1, NULL, &fds, NULL, &tval);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
fprintf(stderr,"[TLS]: TIMEOUT(upstream_tls_timeout_cb)"
|
|
||||||
" upstream not selectable %d\n", ret);
|
|
||||||
while (upstream->write_queue)
|
while (upstream->write_queue)
|
||||||
upstream_write_cb(upstream);
|
upstream_write_cb(upstream);
|
||||||
}
|
}
|
||||||
|
@ -818,8 +815,7 @@ tls_create_object(getdns_context *context, int fd)
|
||||||
static int
|
static int
|
||||||
tls_do_handshake(getdns_upstream *upstream)
|
tls_do_handshake(getdns_upstream *upstream)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"[TLS]: TLS(tls_do_handshake)\n");
|
stub_debug(__FUNCTION__);
|
||||||
|
|
||||||
int r;
|
int r;
|
||||||
int want;
|
int want;
|
||||||
ERR_clear_error();
|
ERR_clear_error();
|
||||||
|
@ -828,7 +824,6 @@ tls_do_handshake(getdns_upstream *upstream)
|
||||||
want = SSL_get_error(upstream->tls_obj, r);
|
want = SSL_get_error(upstream->tls_obj, r);
|
||||||
switch (want) {
|
switch (want) {
|
||||||
case SSL_ERROR_WANT_READ:
|
case SSL_ERROR_WANT_READ:
|
||||||
fprintf(stderr,"[TLS]: SSL_ERROR_WANT_READ\n");
|
|
||||||
upstream->event.read_cb = upstream_read_cb;
|
upstream->event.read_cb = upstream_read_cb;
|
||||||
upstream->event.write_cb = NULL;
|
upstream->event.write_cb = NULL;
|
||||||
GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event);
|
GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event);
|
||||||
|
@ -837,7 +832,6 @@ tls_do_handshake(getdns_upstream *upstream)
|
||||||
upstream->tls_hs_state = GETDNS_HS_READ;
|
upstream->tls_hs_state = GETDNS_HS_READ;
|
||||||
return STUB_TCP_AGAIN;
|
return STUB_TCP_AGAIN;
|
||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_WRITE:
|
||||||
fprintf(stderr,"[TLS]: SSL_ERROR_WANT_WRITE\n");
|
|
||||||
upstream->event.read_cb = NULL;
|
upstream->event.read_cb = NULL;
|
||||||
upstream->event.write_cb = upstream_write_cb;
|
upstream->event.write_cb = upstream_write_cb;
|
||||||
GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event);
|
GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event);
|
||||||
|
@ -1210,6 +1204,7 @@ stub_tcp_write_cb(void *userarg)
|
||||||
static void
|
static void
|
||||||
upstream_read_cb(void *userarg)
|
upstream_read_cb(void *userarg)
|
||||||
{
|
{
|
||||||
|
stub_debug(__FUNCTION__);
|
||||||
getdns_upstream *upstream = (getdns_upstream *)userarg;
|
getdns_upstream *upstream = (getdns_upstream *)userarg;
|
||||||
getdns_network_req *netreq;
|
getdns_network_req *netreq;
|
||||||
getdns_dns_req *dnsreq;
|
getdns_dns_req *dnsreq;
|
||||||
|
@ -1217,9 +1212,6 @@ upstream_read_cb(void *userarg)
|
||||||
uint16_t query_id;
|
uint16_t query_id;
|
||||||
intptr_t query_id_intptr;
|
intptr_t query_id_intptr;
|
||||||
|
|
||||||
fprintf(stderr,"[TLS]: **********CALLBACK***********\n");
|
|
||||||
fprintf(stderr,"[TLS]: READ(upstream_read_cb): on %d\n", upstream->fd);
|
|
||||||
|
|
||||||
if (tls_should_read(upstream))
|
if (tls_should_read(upstream))
|
||||||
q = stub_tls_read(upstream, &upstream->tcp,
|
q = stub_tls_read(upstream, &upstream->tcp,
|
||||||
&upstream->upstreams->mf);
|
&upstream->upstreams->mf);
|
||||||
|
@ -1323,15 +1315,12 @@ netreq_upstream_read_cb(void *userarg)
|
||||||
static void
|
static void
|
||||||
upstream_write_cb(void *userarg)
|
upstream_write_cb(void *userarg)
|
||||||
{
|
{
|
||||||
|
stub_debug(__FUNCTION__);
|
||||||
getdns_upstream *upstream = (getdns_upstream *)userarg;
|
getdns_upstream *upstream = (getdns_upstream *)userarg;
|
||||||
getdns_network_req *netreq = upstream->write_queue;
|
getdns_network_req *netreq = upstream->write_queue;
|
||||||
getdns_dns_req *dnsreq = netreq->owner;
|
getdns_dns_req *dnsreq = netreq->owner;
|
||||||
int q;
|
int q;
|
||||||
|
|
||||||
fprintf(stderr,"[TLS]: **********CALLBACK***********\n");
|
|
||||||
fprintf(stderr,"[TLS]: WRITE(upstream_write_cb): upstream fd %d, SEND"
|
|
||||||
" netreq %p \n", upstream->fd, netreq);
|
|
||||||
|
|
||||||
if (tls_requested(netreq) && tls_should_write(upstream))
|
if (tls_requested(netreq) && tls_should_write(upstream))
|
||||||
q = stub_tls_write(upstream, &upstream->tcp, netreq);
|
q = stub_tls_write(upstream, &upstream->tcp, netreq);
|
||||||
else
|
else
|
||||||
|
@ -1347,17 +1336,12 @@ upstream_write_cb(void *userarg)
|
||||||
|
|
||||||
case STUB_TLS_SETUP_ERROR:
|
case STUB_TLS_SETUP_ERROR:
|
||||||
/* Could not complete the TLS set up. Need to fallback.*/
|
/* Could not complete the TLS set up. Need to fallback.*/
|
||||||
if (fallback_on_write(netreq) == STUB_TCP_ERROR) {
|
if (fallback_on_write(netreq) == STUB_TCP_ERROR)
|
||||||
fprintf(stderr,"[TLS]: Fallback failed.\n");
|
|
||||||
message_erred(netreq);
|
message_erred(netreq);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
netreq->query_id = (uint16_t) q;
|
netreq->query_id = (uint16_t) q;
|
||||||
fprintf(stderr, "[TLS]: WRITE(upstream_write_cb): successfull write:"
|
|
||||||
" on fd %d\n", upstream->fd);
|
|
||||||
|
|
||||||
/* Unqueue the netreq from the write_queue */
|
/* Unqueue the netreq from the write_queue */
|
||||||
if (!(upstream->write_queue = netreq->write_queue_tail)) {
|
if (!(upstream->write_queue = netreq->write_queue_tail)) {
|
||||||
upstream->write_queue_last = NULL;
|
upstream->write_queue_last = NULL;
|
||||||
|
@ -1478,6 +1462,7 @@ int
|
||||||
upstream_connect(getdns_upstream *upstream, getdns_base_transport_t transport,
|
upstream_connect(getdns_upstream *upstream, getdns_base_transport_t transport,
|
||||||
getdns_dns_req *dnsreq)
|
getdns_dns_req *dnsreq)
|
||||||
{
|
{
|
||||||
|
stub_debug(__FUNCTION__);
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
switch(transport) {
|
switch(transport) {
|
||||||
case GETDNS_BASE_TRANSPORT_UDP:
|
case GETDNS_BASE_TRANSPORT_UDP:
|
||||||
|
@ -1539,8 +1524,6 @@ upstream_connect(getdns_upstream *upstream, getdns_base_transport_t transport,
|
||||||
return -1;
|
return -1;
|
||||||
/* Nothing to do*/
|
/* Nothing to do*/
|
||||||
}
|
}
|
||||||
fprintf(stderr,"[TLS]: CONNECT(upstream_connect):"
|
|
||||||
" created new connection %d\n", fd);
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1583,10 +1566,8 @@ static int
|
||||||
move_netreq(getdns_network_req *netreq, getdns_upstream *upstream,
|
move_netreq(getdns_network_req *netreq, getdns_upstream *upstream,
|
||||||
getdns_upstream *new_upstream)
|
getdns_upstream *new_upstream)
|
||||||
{
|
{
|
||||||
|
stub_debug(__FUNCTION__);
|
||||||
/* Remove from queue, clearing event and fd if we are the last*/
|
/* Remove from queue, clearing event and fd if we are the last*/
|
||||||
|
|
||||||
fprintf(stderr,"[TLS]: FALLBACK(move_netreq)\n");
|
|
||||||
|
|
||||||
if (!(upstream->write_queue = netreq->write_queue_tail)) {
|
if (!(upstream->write_queue = netreq->write_queue_tail)) {
|
||||||
upstream->write_queue_last = NULL;
|
upstream->write_queue_last = NULL;
|
||||||
upstream->event.write_cb = NULL;
|
upstream->event.write_cb = NULL;
|
||||||
|
@ -1641,9 +1622,7 @@ move_netreq(getdns_network_req *netreq, getdns_upstream *upstream,
|
||||||
static int
|
static int
|
||||||
fallback_on_write(getdns_network_req *netreq)
|
fallback_on_write(getdns_network_req *netreq)
|
||||||
{
|
{
|
||||||
|
stub_debug(__FUNCTION__);
|
||||||
fprintf(stderr,"[TLS]: FALLBACK(fallback_on_write)\n");
|
|
||||||
|
|
||||||
/* TODO[TLS]: Fallback through all transports.*/
|
/* TODO[TLS]: Fallback through all transports.*/
|
||||||
getdns_base_transport_t next_transport =
|
getdns_base_transport_t next_transport =
|
||||||
netreq->dns_base_transports[netreq->transport + 1];
|
netreq->dns_base_transports[netreq->transport + 1];
|
||||||
|
@ -1653,7 +1632,6 @@ fallback_on_write(getdns_network_req *netreq)
|
||||||
if (netreq->dns_base_transports[netreq->transport] ==
|
if (netreq->dns_base_transports[netreq->transport] ==
|
||||||
GETDNS_BASE_TRANSPORT_STARTTLS &&
|
GETDNS_BASE_TRANSPORT_STARTTLS &&
|
||||||
next_transport == GETDNS_BASE_TRANSPORT_TCP) {
|
next_transport == GETDNS_BASE_TRANSPORT_TCP) {
|
||||||
fprintf(stderr,"[TLS]: FALLBACK(fallback_on_write) STARTTLS->TCP\n");
|
|
||||||
/* Special case where can stay on same upstream*/
|
/* Special case where can stay on same upstream*/
|
||||||
netreq->transport++;
|
netreq->transport++;
|
||||||
return netreq->upstream->fd;
|
return netreq->upstream->fd;
|
||||||
|
@ -1670,13 +1648,11 @@ fallback_on_write(getdns_network_req *netreq)
|
||||||
static void
|
static void
|
||||||
upstream_schedule_netreq(getdns_upstream *upstream, getdns_network_req *netreq)
|
upstream_schedule_netreq(getdns_upstream *upstream, getdns_network_req *netreq)
|
||||||
{
|
{
|
||||||
|
stub_debug(__FUNCTION__);
|
||||||
/* 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);
|
||||||
|
|
||||||
fprintf(stderr,"[TLS]: SCHEDULE(upstream_schedule_netreq): fd %d\n",
|
|
||||||
upstream->fd);
|
|
||||||
|
|
||||||
/* Append netreq to write_queue */
|
/* Append netreq to write_queue */
|
||||||
if (!upstream->write_queue) {
|
if (!upstream->write_queue) {
|
||||||
upstream->write_queue = upstream->write_queue_last = netreq;
|
upstream->write_queue = upstream->write_queue_last = netreq;
|
||||||
|
@ -1705,6 +1681,7 @@ upstream_schedule_netreq(getdns_upstream *upstream, getdns_network_req *netreq)
|
||||||
getdns_return_t
|
getdns_return_t
|
||||||
priv_getdns_submit_stub_request(getdns_network_req *netreq)
|
priv_getdns_submit_stub_request(getdns_network_req *netreq)
|
||||||
{
|
{
|
||||||
|
stub_debug(__FUNCTION__);
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
getdns_dns_req *dnsreq = netreq->owner;
|
getdns_dns_req *dnsreq = netreq->owner;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue