Merge remote-tracking branch 'upstream/develop' into features/create_dict_with_json

This commit is contained in:
Willem Toorop 2016-05-25 15:12:48 +02:00
commit e25e697970
12 changed files with 363 additions and 175 deletions

View File

@ -655,6 +655,8 @@ _getdns_upstreams_dereference(getdns_upstreams *upstreams)
dnsreq->trans_id, 1); dnsreq->trans_id, 1);
} }
if (upstream->tls_obj != NULL) { if (upstream->tls_obj != NULL) {
if (upstream->tls_session != NULL)
SSL_SESSION_free(upstream->tls_session);
SSL_shutdown(upstream->tls_obj); SSL_shutdown(upstream->tls_obj);
SSL_free(upstream->tls_obj); SSL_free(upstream->tls_obj);
} }
@ -810,6 +812,7 @@ upstream_init(getdns_upstream *upstream,
/* For sharing a socket to this upstream with TCP */ /* For sharing a socket to this upstream with TCP */
upstream->fd = -1; upstream->fd = -1;
upstream->tls_obj = NULL; upstream->tls_obj = NULL;
upstream->tls_session = NULL;
upstream->transport = GETDNS_TRANSPORT_TCP; upstream->transport = GETDNS_TRANSPORT_TCP;
upstream->tls_hs_state = GETDNS_HS_NONE; upstream->tls_hs_state = GETDNS_HS_NONE;
upstream->tls_auth_failed = 0; upstream->tls_auth_failed = 0;
@ -1656,7 +1659,7 @@ getdns_context_set_namespaces(getdns_context *context,
else if (namespaces[i] != GETDNS_NAMESPACE_DNS && else if (namespaces[i] != GETDNS_NAMESPACE_DNS &&
namespaces[i] != GETDNS_NAMESPACE_LOCALNAMES) namespaces[i] != GETDNS_NAMESPACE_LOCALNAMES)
return GETDNS_RETURN_INVALID_PARAMETER; return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
} }
GETDNS_FREE(context->my_mf, context->namespaces); GETDNS_FREE(context->my_mf, context->namespaces);
@ -1679,7 +1682,8 @@ getdns_set_base_dns_transports(
size_t i; size_t i;
getdns_transport_list_t *new_transports; getdns_transport_list_t *new_transports;
if (!context || transport_count == 0 || transports == NULL) RETURN_IF_NULL(context, GETDNS_RETURN_INVALID_PARAMETER);
if (transport_count == 0 || !transports)
return GETDNS_RETURN_INVALID_PARAMETER; return GETDNS_RETURN_INVALID_PARAMETER;
/* Check for valid transports and that they are used only once*/ /* Check for valid transports and that they are used only once*/
@ -1690,11 +1694,11 @@ getdns_set_base_dns_transports(
case GETDNS_TRANSPORT_UDP: u++; break; case GETDNS_TRANSPORT_UDP: u++; break;
case GETDNS_TRANSPORT_TCP: t++; break; case GETDNS_TRANSPORT_TCP: t++; break;
case GETDNS_TRANSPORT_TLS: l++; break; case GETDNS_TRANSPORT_TLS: l++; break;
default: return GETDNS_RETURN_INVALID_PARAMETER; default: return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
} }
} }
if ( u>1 || t>1 || l>1) if ( u>1 || t>1 || l>1)
return GETDNS_RETURN_INVALID_PARAMETER; return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
if (!(new_transports = GETDNS_XMALLOC(context->my_mf, if (!(new_transports = GETDNS_XMALLOC(context->my_mf,
getdns_transport_list_t, transport_count))) getdns_transport_list_t, transport_count)))
@ -1767,18 +1771,17 @@ getdns_context_set_dns_transport(
size_t count = 2; size_t count = 2;
getdns_transport_list_t *new_transports; getdns_transport_list_t *new_transports;
RETURN_IF_NULL(context, GETDNS_RETURN_INVALID_PARAMETER);
if (value == GETDNS_TRANSPORT_UDP_ONLY || if (value == GETDNS_TRANSPORT_UDP_ONLY ||
value == GETDNS_TRANSPORT_TCP_ONLY || value == GETDNS_TRANSPORT_TCP_ONLY ||
value == GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN || value == GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN ||
value == GETDNS_TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN) value == GETDNS_TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN)
count = 1; count = 1;
if (!context)
return GETDNS_RETURN_INVALID_PARAMETER;
if (!(new_transports = GETDNS_XMALLOC( if (!(new_transports = GETDNS_XMALLOC(
context->my_mf, getdns_transport_list_t, count))) context->my_mf, getdns_transport_list_t, count)))
return GETDNS_RETURN_CONTEXT_UPDATE_FAIL; return GETDNS_RETURN_CONTEXT_UPDATE_FAIL;
if (context->dns_transports) if (context->dns_transports)
GETDNS_FREE(context->my_mf, context->dns_transports); GETDNS_FREE(context->my_mf, context->dns_transports);

View File

@ -127,6 +127,7 @@ typedef struct getdns_upstream {
int fd; int fd;
getdns_transport_list_t transport; getdns_transport_list_t transport;
SSL* tls_obj; SSL* tls_obj;
SSL_SESSION* tls_session;
getdns_tls_hs_state_t tls_hs_state; getdns_tls_hs_state_t tls_hs_state;
getdns_eventloop_event event; getdns_eventloop_event event;
getdns_eventloop *loop; getdns_eventloop *loop;

View File

@ -320,15 +320,13 @@ process_keepalive(
uint16_t option_len = 0; uint16_t option_len = 0;
int found = match_edns_opt_rr(GLDNS_EDNS_KEEPALIVE, response, int found = match_edns_opt_rr(GLDNS_EDNS_KEEPALIVE, response,
response_len, &position, &option_len); response_len, &position, &option_len);
if (found != 2) { if (found != 2 || option_len != 2) {
if (netreq->keepalive_sent == 1) if (netreq->keepalive_sent == 1)
/* If no keepalive sent back, then we must use 0 idle timeout /* If no keepalive sent back, then we must use 0 idle timeout
as server does not support it.*/ as server does not support it.*/
upstream->keepalive_timeout = 0; upstream->keepalive_timeout = 0;
return; return;
} }
if (option_len != 2)
return; /* FORMERR */
/* Use server sent value unless the client specified a shorter one. /* Use server sent value unless the client specified a shorter one.
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;
@ -1036,6 +1034,12 @@ tls_do_handshake(getdns_upstream *upstream)
* tls_auth_fail. */ * tls_auth_fail. */
#endif #endif
upstream->tls_auth_failed = 1; upstream->tls_auth_failed = 1;
DEBUG_STUB("%s %-35s: FD: %d Session is %s\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, upstream->fd,
SSL_session_reused(upstream->tls_obj) ?"re-used":"new");
if (upstream->tls_session != NULL)
SSL_SESSION_free(upstream->tls_session);
upstream->tls_session = SSL_get1_session(upstream->tls_obj);
/* Reset timeout on success*/ /* Reset timeout on success*/
GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event); GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event);
upstream->event.read_cb = NULL; upstream->event.read_cb = NULL;
@ -1696,6 +1700,9 @@ upstream_connect(getdns_upstream *upstream, getdns_transport_list_t transport,
close(fd); close(fd);
return -1; return -1;
} }
if (upstream->tls_session != NULL)
SSL_set_session(upstream->tls_obj, upstream->tls_session);
upstream->tls_hs_state = GETDNS_HS_WRITE; upstream->tls_hs_state = GETDNS_HS_WRITE;
upstream->loop = dnsreq->loop; upstream->loop = dnsreq->loop;
upstream->is_sync_loop = dnsreq->is_sync_request; upstream->is_sync_loop = dnsreq->is_sync_request;

View File

@ -247,7 +247,7 @@ check_getdns.lo check_getdns.o: $(srcdir)/check_getdns.c ../getdns/getdns.h $(sr
$(srcdir)/check_getdns_context_set_timeout.h \ $(srcdir)/check_getdns_context_set_timeout.h \
$(srcdir)/check_getdns_context_set_upstream_recursive_servers.h \ $(srcdir)/check_getdns_context_set_upstream_recursive_servers.h \
$(srcdir)/check_getdns_service.h $(srcdir)/check_getdns_service_sync.h \ $(srcdir)/check_getdns_service.h $(srcdir)/check_getdns_service_sync.h \
$(srcdir)/check_getdns_transport.h $(srcdir)/check_getdns_transport.h $(srcdir)/check_getdns_context_set_dns_transport.h
check_getdns_common.lo check_getdns_common.o: $(srcdir)/check_getdns_common.c ../getdns/getdns.h \ check_getdns_common.lo check_getdns_common.o: $(srcdir)/check_getdns_common.c ../getdns/getdns.h \
../config.h $(srcdir)/check_getdns_common.h ../getdns/getdns_extra.h \ ../config.h $(srcdir)/check_getdns_common.h ../getdns/getdns_extra.h \
$(srcdir)/check_getdns_eventloop.h $(srcdir)/check_getdns_eventloop.h

View File

@ -33,125 +33,129 @@
#include <check.h> #include <check.h>
#include "getdns/getdns.h" #include "getdns/getdns.h"
#include "check_getdns_common.h" #include "check_getdns_common.h"
#include "check_getdns_general.h"
#include "check_getdns_general_sync.h"
#include "check_getdns_address.h" #include "check_getdns_address.h"
#include "check_getdns_address_sync.h" #include "check_getdns_address_sync.h"
#include "check_getdns_hostname.h" #include "check_getdns_cancel_callback.h"
#include "check_getdns_hostname_sync.h"
#include "check_getdns_context_create.h" #include "check_getdns_context_create.h"
#include "check_getdns_context_destroy.h" #include "check_getdns_context_destroy.h"
#include "check_getdns_cancel_callback.h"
#include "check_getdns_list_get_length.h"
#include "check_getdns_list_get_data_type.h"
#include "check_getdns_list_get_dict.h"
#include "check_getdns_list_get_list.h"
#include "check_getdns_list_get_int.h"
#include "check_getdns_list_get_bindata.h"
#include "check_getdns_dict_get_names.h"
#include "check_getdns_dict_get_data_type.h"
#include "check_getdns_dict_get_dict.h"
#include "check_getdns_dict_get_list.h"
#include "check_getdns_dict_get_bindata.h"
#include "check_getdns_dict_get_int.h"
#include "check_getdns_dict_destroy.h"
#include "check_getdns_dict_set_dict.h"
#include "check_getdns_dict_set_list.h"
#include "check_getdns_dict_set_bindata.h"
#include "check_getdns_dict_set_int.h"
#include "check_getdns_convert_ulabel_to_alabel.h"
#include "check_getdns_convert_alabel_to_ulabel.h"
#include "check_getdns_pretty_print_dict.h"
#include "check_getdns_display_ip_address.h"
#include "check_getdns_context_set_context_update_callback.h" #include "check_getdns_context_set_context_update_callback.h"
#include "check_getdns_context_set_dns_transport.h"
#include "check_getdns_context_set_timeout.h" #include "check_getdns_context_set_timeout.h"
#include "check_getdns_context_set_upstream_recursive_servers.h" #include "check_getdns_context_set_upstream_recursive_servers.h"
#include "check_getdns_convert_alabel_to_ulabel.h"
#include "check_getdns_convert_ulabel_to_alabel.h"
#include "check_getdns_dict_destroy.h"
#include "check_getdns_dict_get_bindata.h"
#include "check_getdns_dict_get_data_type.h"
#include "check_getdns_dict_get_dict.h"
#include "check_getdns_dict_get_int.h"
#include "check_getdns_dict_get_list.h"
#include "check_getdns_dict_get_names.h"
#include "check_getdns_dict_set_bindata.h"
#include "check_getdns_dict_set_dict.h"
#include "check_getdns_dict_set_int.h"
#include "check_getdns_dict_set_list.h"
#include "check_getdns_display_ip_address.h"
#include "check_getdns_general.h"
#include "check_getdns_general_sync.h"
#include "check_getdns_hostname.h"
#include "check_getdns_hostname_sync.h"
#include "check_getdns_list_get_bindata.h"
#include "check_getdns_list_get_data_type.h"
#include "check_getdns_list_get_dict.h"
#include "check_getdns_list_get_int.h"
#include "check_getdns_list_get_length.h"
#include "check_getdns_list_get_list.h"
#include "check_getdns_pretty_print_dict.h"
#include "check_getdns_service.h" #include "check_getdns_service.h"
#include "check_getdns_service_sync.h" #include "check_getdns_service_sync.h"
#include "check_getdns_transport.h" #include "check_getdns_transport.h"
int int
main (int argc, char** argv) main (int argc, char** argv)
{ {
int number_failed; int number_failed;
SRunner *sr ; SRunner *sr ;
Suite *getdns_general_suite(void);
Suite *getdns_general_sync_suite(void);
Suite *getdns_address_suite(void); Suite *getdns_address_suite(void);
Suite *getdns_address_sync_suite(void); Suite *getdns_address_sync_suite(void);
Suite *getdns_hostname_suite(void); Suite *getdns_cancel_callback_suite(void);
Suite *getdns_hostname_sync_suite(void);
Suite *getdns_context_create_suite(void); Suite *getdns_context_create_suite(void);
Suite *getdns_context_destroy_suite(void); Suite *getdns_context_destroy_suite(void);
Suite *getdns_cancel_callback_suite(void); Suite *getdns_context_set_context_update_callback_suite(void);
Suite *getdns_list_get_length_suite(void); Suite *getdns_context_set_dns_transport_suite(void);
Suite *getdns_list_get_dict_suite(void); Suite *getdns_context_set_timeout_suite(void);
Suite *getdns_list_get_list_suite(void); Suite *getdns_context_set_upstream_recursive_servers_suite(void);
Suite *getdns_list_get_int_suite(void); Suite *getdns_convert_alabel_to_ulabel_suite(void);
Suite *getdns_list_get_data_type_suite(void); Suite *getdns_convert_ulabel_to_alabel_suite(void);
Suite *getdns_list_get_bindata_suite(void); Suite *getdns_dict_destroy_suite(void);
Suite *getdns_dict_get_names_suite(void); Suite *getdns_dict_get_bindata_suite(void);
Suite *getdns_dict_get_data_type_suite(void); Suite *getdns_dict_get_data_type_suite(void);
Suite *getdns_dict_get_dict_suite(void); Suite *getdns_dict_get_dict_suite(void);
Suite *getdns_dict_get_list_suite(void);
Suite *getdns_dict_get_dict_suite(void);
Suite *getdns_dict_get_bindata_suite(void);
Suite *getdns_dict_get_int_suite(void); Suite *getdns_dict_get_int_suite(void);
Suite *getdns_dict_destroy_suite(void); Suite *getdns_dict_get_list_suite(void);
Suite *getdns_dict_set_dict_suite(void); Suite *getdns_dict_get_names_suite(void);
Suite *getdns_dict_set_list_suite(void);
Suite *getdns_dict_set_bindata_suite(void); Suite *getdns_dict_set_bindata_suite(void);
Suite *getdns_dict_set_dict_suite(void);
Suite *getdns_dict_set_int_suite(void); Suite *getdns_dict_set_int_suite(void);
Suite *getdns_convert_ulabel_to_alabel_suite(void); Suite *getdns_dict_set_list_suite(void);
Suite *getdns_convert_alabel_to_ulabel_suite(void);
Suite *getdns_pretty_print_dict_suite(void);
Suite *getdns_display_ip_address_suite(void); Suite *getdns_display_ip_address_suite(void);
Suite *getdns_context_set_context_update_callback_suite(void); Suite *getdns_general_suite(void);
Suite *getdns_context_set_upstream_recursive_servers_suite(void); Suite *getdns_general_sync_suite(void);
Suite *getdns_hostname_suite(void);
Suite *getdns_hostname_sync_suite(void);
Suite *getdns_list_get_bindata_suite(void);
Suite *getdns_list_get_data_type_suite(void);
Suite *getdns_list_get_dict_suite(void);
Suite *getdns_list_get_int_suite(void);
Suite *getdns_list_get_length_suite(void);
Suite *getdns_list_get_list_suite(void);
Suite *getdns_pretty_print_dict_suite(void);
Suite *getdns_service_suite(void); Suite *getdns_service_suite(void);
Suite *getdns_service_sync_suite(void); Suite *getdns_service_sync_suite(void);
Suite *getdns_context_set_timeout_suite(void);
Suite *getdns_transport_suite(void); Suite *getdns_transport_suite(void);
sr = srunner_create(getdns_general_suite()); sr = srunner_create(getdns_address_suite());
srunner_add_suite(sr, getdns_general_sync_suite());
srunner_add_suite(sr, getdns_address_suite());
srunner_add_suite(sr, getdns_address_sync_suite()); srunner_add_suite(sr, getdns_address_sync_suite());
srunner_add_suite(sr, getdns_hostname_suite()); srunner_add_suite(sr, getdns_cancel_callback_suite());
srunner_add_suite(sr, getdns_hostname_sync_suite());
srunner_add_suite(sr, getdns_context_create_suite()); srunner_add_suite(sr, getdns_context_create_suite());
srunner_add_suite(sr, getdns_context_destroy_suite()); srunner_add_suite(sr, getdns_context_destroy_suite());
srunner_add_suite(sr, getdns_cancel_callback_suite()); srunner_add_suite(sr, getdns_context_set_context_update_callback_suite());
srunner_add_suite(sr, getdns_list_get_length_suite()); srunner_add_suite(sr, getdns_context_set_dns_transport_suite());
srunner_add_suite(sr, getdns_list_get_data_type_suite()); srunner_add_suite(sr, getdns_context_set_timeout_suite());
srunner_add_suite(sr, getdns_list_get_dict_suite()); srunner_add_suite(sr, getdns_context_set_upstream_recursive_servers_suite());
srunner_add_suite(sr, getdns_list_get_list_suite()); srunner_add_suite(sr, getdns_convert_alabel_to_ulabel_suite());
srunner_add_suite(sr, getdns_list_get_int_suite()); srunner_add_suite(sr, getdns_convert_ulabel_to_alabel_suite());
srunner_add_suite(sr, getdns_list_get_bindata_suite()); srunner_add_suite(sr, getdns_dict_destroy_suite());
srunner_add_suite(sr, getdns_dict_get_names_suite()); srunner_add_suite(sr, getdns_dict_get_bindata_suite());
srunner_add_suite(sr, getdns_dict_get_data_type_suite()); srunner_add_suite(sr, getdns_dict_get_data_type_suite());
srunner_add_suite(sr, getdns_dict_get_dict_suite()); srunner_add_suite(sr, getdns_dict_get_dict_suite());
srunner_add_suite(sr, getdns_dict_get_list_suite());
srunner_add_suite(sr, getdns_dict_get_bindata_suite());
srunner_add_suite(sr, getdns_dict_get_int_suite()); srunner_add_suite(sr, getdns_dict_get_int_suite());
srunner_add_suite(sr, getdns_dict_destroy_suite()); srunner_add_suite(sr, getdns_dict_get_list_suite());
srunner_add_suite(sr, getdns_dict_set_dict_suite()); srunner_add_suite(sr, getdns_dict_get_names_suite());
srunner_add_suite(sr, getdns_dict_set_list_suite());
srunner_add_suite(sr, getdns_dict_set_bindata_suite()); srunner_add_suite(sr, getdns_dict_set_bindata_suite());
srunner_add_suite(sr, getdns_dict_set_dict_suite());
srunner_add_suite(sr, getdns_dict_set_int_suite()); srunner_add_suite(sr, getdns_dict_set_int_suite());
srunner_add_suite(sr, getdns_convert_ulabel_to_alabel_suite()); srunner_add_suite(sr, getdns_dict_set_list_suite());
srunner_add_suite(sr, getdns_convert_alabel_to_ulabel_suite()); srunner_add_suite(sr, getdns_display_ip_address_suite());
srunner_add_suite(sr, getdns_general_suite());
srunner_add_suite(sr, getdns_general_sync_suite());
srunner_add_suite(sr, getdns_hostname_suite());
srunner_add_suite(sr, getdns_hostname_sync_suite());
srunner_add_suite(sr, getdns_list_get_bindata_suite());
srunner_add_suite(sr, getdns_list_get_data_type_suite());
srunner_add_suite(sr, getdns_list_get_dict_suite());
srunner_add_suite(sr, getdns_list_get_int_suite());
srunner_add_suite(sr, getdns_list_get_length_suite());
srunner_add_suite(sr, getdns_list_get_list_suite());
srunner_add_suite(sr, getdns_pretty_print_dict_suite()); srunner_add_suite(sr, getdns_pretty_print_dict_suite());
srunner_add_suite(sr,getdns_display_ip_address_suite()); srunner_add_suite(sr, getdns_service_suite());
srunner_add_suite(sr,getdns_context_set_context_update_callback_suite()); srunner_add_suite(sr, getdns_service_sync_suite());
srunner_add_suite(sr,getdns_context_set_timeout_suite()); srunner_add_suite(sr, getdns_transport_suite());
srunner_add_suite(sr,getdns_context_set_upstream_recursive_servers_suite());
srunner_add_suite(sr,getdns_service_suite());
srunner_add_suite(sr,getdns_service_sync_suite());
srunner_add_suite(sr,getdns_transport_suite());
srunner_run_all(sr, CK_NORMAL); srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr); number_failed = srunner_ntests_failed(sr);
srunner_free(sr); srunner_free(sr);

View File

@ -412,7 +412,28 @@
} }
END_TEST END_TEST
START_TEST (getdns_context_set_context_update_callback_22)
{
/*
* value is NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_context *context = NULL;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_context_update_callback()");
expected_changed_item = GETDNS_CONTEXT_CODE_IDLE_TIMEOUT;
ASSERT_RC(getdns_context_set_idle_timeout(context, 100),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_timeout()");
CONTEXT_DESTROY;
}
END_TEST
Suite * Suite *
getdns_context_set_context_update_callback_suite (void) getdns_context_set_context_update_callback_suite (void)
@ -440,6 +461,7 @@
tcase_add_test(tc_pos, getdns_context_set_context_update_callback_19); tcase_add_test(tc_pos, getdns_context_set_context_update_callback_19);
tcase_add_test(tc_pos, getdns_context_set_context_update_callback_20); tcase_add_test(tc_pos, getdns_context_set_context_update_callback_20);
tcase_add_test(tc_pos, getdns_context_set_context_update_callback_21); tcase_add_test(tc_pos, getdns_context_set_context_update_callback_21);
tcase_add_test(tc_pos, getdns_context_set_context_update_callback_22);
suite_add_tcase(s, tc_pos); suite_add_tcase(s, tc_pos);
return s; return s;

View File

@ -30,7 +30,7 @@
/* /*
************************************************************************** **************************************************************************
* * * *
* T E S T S F O R G E T D N S _ C O N T E X T _ S E T _ C O N T E X T _ U P D A T E _ C A L L B A C K * * T E S T S F O R G E T D N S _ C O N T E X T _ S E T _ D N S _ T R A N S P O R T *
* * * *
************************************************************************** **************************************************************************
*/ */
@ -46,7 +46,7 @@
uint16_t value = 302; uint16_t value = 302;
ASSERT_RC(getdns_context_set_dns_transport(context, value), ASSERT_RC(getdns_context_set_dns_transport(context, value),
GETDNS_RETURN_BAD_CONTEXT, "Return code from getdns_context_set_dns_transport()"); GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_set_dns_transport()");
} }
END_TEST END_TEST
@ -71,108 +71,228 @@
} }
END_TEST END_TEST
START_TEST (getdns_context_set_dns_transport_3) START_TEST (getdns_context_set_dns_transport_list_3)
{ {
/* /*
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_UDP_ONLY * context is NULL
* Define a callback routine for context changes and call getdns_context_set_context_update_callback() so that it gets called when there are context changes * expect: GETDNS_RETURN_INVALID_PARAMETER
* getdns_context_set_resolution_type() to GETDNS_RESOLUTION_STUB */
* expect: GETDNS_CONTEXT_CODE_RESOLUTION_TYPE
*/
struct getdns_context *context = NULL;
struct getdns_dict *response = NULL;
uint32_t ancount;
uint32_t arcount;
uint32_t nscount;
uint32_t tcp_ancount;
uint32_t tcp_arcount;
uint32_t tcp_nscount;
int udp_sum;
int tcp_sum;
CONTEXT_CREATE(TRUE);
struct getdns_context *context = NULL;
getdns_transport_list_t transports[1];
transports[0] = GETDNS_TRANSPORT_UDP;
size_t transport_count = sizeof(transports);
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_UDP_ONLY), ASSERT_RC(getdns_context_set_dns_transport_list(context, transport_count, transports),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()"); GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_general_sync(context, "google.com", 255, NULL, &response), }
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()"); END_TEST
EXTRACT_RESPONSE; START_TEST (getdns_context_set_dns_transport_list_4)
{
/*
* list is invalid
* expect: GETDNS_RETURN_CONTEXT_UPDATE_FAIL
*/
struct getdns_context *context = NULL;
getdns_transport_list_t transports[1];
transports[0] = GETDNS_TRANSPORT_UDP;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_dict_get_int(ex_response.header, "ancount", &ancount), ASSERT_RC(getdns_context_set_dns_transport_list(context, 0, NULL),
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\""); GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_dns_transport_list(context, 1, NULL),
ASSERT_RC(getdns_dict_get_int(ex_response.header, "arcount", &arcount), GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_dns_transport()");
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\""); ASSERT_RC(getdns_context_set_dns_transport_list(context, 0, transports),
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_dict_get_int(ex_response.header, "nscount", &nscount), ASSERT_RC(getdns_context_set_dns_transport_list(context, 2, transports),
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\""); GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_dns_transport()");
printf("the resp is %s\n", getdns_pretty_print_dict(response)); CONTEXT_DESTROY;
printf("the ancount is %d\n", ancount);
printf("the arcount is %d\n", arcount); }
printf("the nscount is %d\n", nscount); END_TEST
udp_sum = ancount + arcount + nscount;
printf("the udp_sum is %d\n", udp_sum); START_TEST (getdns_context_set_dns_transport_stub_5)
{
//tcp count /*
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_TCP_ONLY), * Request answer larger then 512 bytes but set UDP payload to that
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()"); * Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_UDP_ONLY
* expect: Message uses UDP but is truncated
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_TCP_ONLY
ASSERT_RC(getdns_general_sync(context, "google.com", 255, NULL, &response), * expect: Message uses TCP and is not truncated
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()"); * Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP
* expect: Message uses TCP and is not truncated
struct extracted_response ex_response1; */
extract_response(response, &ex_response1); struct getdns_context *context = NULL;
struct getdns_dict *response = NULL;
ASSERT_RC(getdns_dict_get_int(ex_response1.header, "ancount", &tcp_ancount), struct getdns_dict *extensions = getdns_dict_create();
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\""); uint32_t tc;
uint32_t transport;
ASSERT_RC(getdns_dict_get_int(ex_response1.header, "arcount", &tcp_arcount),
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\""); /* Note that stricly this test just establishes that the requested transport
and the reported transport are consistent, it does not guarentee which
ASSERT_RC(getdns_dict_get_int(ex_response1.header, "nscount", &tcp_nscount), transport is used on the wire...*/
GETDNS_RETURN_GOOD, "Failed to extract \"nscount\"");
CONTEXT_CREATE(TRUE);
printf("the resp is %s\n", getdns_pretty_print_dict(response));
ASSERT_RC(getdns_context_set_resolution_type(context, GETDNS_RESOLUTION_STUB),
printf("the tcp_ancount is %d\n", tcp_ancount); GETDNS_RETURN_GOOD, "Return code from getdns_context_set_resolution_type()");
printf("the tcp_arcount is %d\n", tcp_arcount); ASSERT_RC(getdns_dict_set_int(extensions,"return_call_reporting", GETDNS_EXTENSION_TRUE),
printf("the tcp_nscount is %d\n", tcp_nscount); GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
tcp_sum = tcp_ancount + tcp_arcount + tcp_nscount;
printf("the tcp_sum is %d\n", udp_sum); /* Request a response that should be truncated over UDP */
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_UDP_ONLY),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
ASSERT_RC(getdns_context_set_edns_do_bit(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_do_bit()");
ASSERT_RC(getdns_general_sync(context, "large.getdnsapi.net", GETDNS_RRTYPE_TXT, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/transport", &transport),
GETDNS_RETURN_GOOD, "Failed to extract \"transport\"");
ASSERT_RC(transport, GETDNS_TRANSPORT_UDP, "Query did not go over UDP");
ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc),
GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 1, "Packet not trucated as expected");
/* Re-do over TCP */
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_TCP_ONLY),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_general_sync(context, "large.getdnsapi.net", GETDNS_RRTYPE_TXT, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/transport", &transport),
GETDNS_RETURN_GOOD, "Failed to extract \"transport\"");
ASSERT_RC(transport, GETDNS_TRANSPORT_TCP, "Query did not go over TCP");
ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc),
GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 0, "Packet trucated - not as expected");
/* Now let it fall back to TCP */
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_general_sync(context, "large.getdnsapi.net", GETDNS_RRTYPE_TXT, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
ASSERT_RC(getdns_dict_get_int(response, "/call_reporting/0/transport", &transport),
GETDNS_RETURN_GOOD, "Failed to extract \"transport\"");
ASSERT_RC(transport, GETDNS_TRANSPORT_TCP, "Query did not go over TCP");
ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc),
GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 0, "Packet trucated - not as expected");
CONTEXT_DESTROY;
}
END_TEST
START_TEST (getdns_context_set_dns_transport_recursing_6)
{
/*
* Request answer larger then 512 bytes but set UDP payload to that
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_UDP_ONLY
* expect: No response returned
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_TCP_ONLY
* expect: Response returned
* Call getdns_context_set_dns_transport() with value = GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP
* expect: Response returned
*/
struct getdns_context *context = NULL;
struct getdns_dict *response = NULL;
struct getdns_dict *extensions = getdns_dict_create();
uint32_t status;
uint32_t tc;
/* Recursive mode does not report the transport used and does not answer
if the response is trucated. Also, transport can't be changed on a ub ctx.*/
CONTEXT_CREATE(TRUE);
/* Need to explicit check as we may be compiled stub-only*/
getdns_resolution_t resolution_type;
ASSERT_RC(getdns_context_get_resolution_type(context, &resolution_type),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_resolution_type()");
if (resolution_type == GETDNS_RESOLUTION_RECURSING) {
/* Request a response that should be truncated over UDP */
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_UDP_ONLY),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
ASSERT_RC(getdns_dict_get_int(response, "status", &status),
GETDNS_RETURN_GOOD, "Failed to extract \"status\"");
/* TODO: INVESTIGATE THIS AS IT SHOULDN'T BE A TIMEOUT...*/
ASSERT_RC(status, GETDNS_RESPSTATUS_ALL_TIMEOUT, "Status not as expected");
CONTEXT_DESTROY;
CONTEXT_CREATE(TRUE);
/* Re-do over TCP */
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_TCP_ONLY),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc),
GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 0, "Packet trucated - not as expected");
CONTEXT_DESTROY;
CONTEXT_CREATE(TRUE);
/* Now let it fall back to TCP */
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
ASSERT_RC(getdns_general_sync(context, "getdnsapi.net", 48, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
ASSERT_RC(getdns_dict_get_int(response, "/replies_tree/0/header/tc", &tc),
GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 0, "Packet trucated - not as expected");
}
CONTEXT_DESTROY; CONTEXT_DESTROY;
} }
END_TEST END_TEST
Suite * Suite *
getdns_context_set_dns_transport_suite (void) getdns_context_set_dns_transport_suite (void)
{ {
Suite *s = suite_create ("getdns_context_set_dns_transport()"); Suite *s = suite_create ("getdns_context_set_dns_transport()");
/* Negative test caseis */ /* Negative test cases */
TCase *tc_neg = tcase_create("Negative"); TCase *tc_neg = tcase_create("Negative");
tcase_add_test(tc_neg, getdns_context_set_dns_transport_1); tcase_add_test(tc_neg, getdns_context_set_dns_transport_1);
tcase_add_test(tc_neg, getdns_context_set_dns_transport_2); tcase_add_test(tc_neg, getdns_context_set_dns_transport_2);
tcase_add_test(tc_neg, getdns_context_set_dns_transport_list_3);
tcase_add_test(tc_neg, getdns_context_set_dns_transport_list_4);
/* TODO: Test which specific lists are not supported */
suite_add_tcase(s, tc_neg); suite_add_tcase(s, tc_neg);
/* Positive test cases */ /* Positive test cases */
TCase *tc_pos = tcase_create("Positive"); TCase *tc_pos = tcase_create("Positive");
tcase_add_test(tc_pos, getdns_context_set_dns_transport_3); /* TODO: Test which specific lists are supported */
tcase_add_test(tc_pos, getdns_context_set_dns_transport_stub_5);
tcase_add_test(tc_pos, getdns_context_set_dns_transport_recursing_6);
/* TODO: TLS... */
suite_add_tcase(s, tc_pos); suite_add_tcase(s, tc_pos);
return s; return s;

View File

@ -12,3 +12,4 @@ cp -p ${SRCROOT}/src/libgetdns.symbols libgetdns.symbols.orig
cp -p ${SRCROOT}/src/libgetdns.symbols libgetdns.symbols.new cp -p ${SRCROOT}/src/libgetdns.symbols libgetdns.symbols.new
cp -p libgetdns.symbols.orig ${SRCROOT}/src/libgetdns.symbols cp -p libgetdns.symbols.orig ${SRCROOT}/src/libgetdns.symbols
diff libgetdns.symbols.orig libgetdns.symbols.new diff libgetdns.symbols.orig libgetdns.symbols.new

View File

@ -3,15 +3,25 @@
export SRCDIR=`dirname $0` export SRCDIR=`dirname $0`
. `dirname $0`/setup-env.sh . `dirname $0`/setup-env.sh
control_c()
# run if user hits control-c
{
echo -en "\n*** Exiting ***\n"
exit $?
}
LCOV_MERGE="" LCOV_MERGE=""
for TEST_PKG in ${SRCDIR}/*.tpkg for TEST_PKG in ${SRCDIR}/*.tpkg
do do
# when we run our test, we need to compile with profiling # when we run our test, we need to compile with profiling
CFLAGS="-fprofile-arcs -ftest-coverage -O0" "${TPKG}" $* exe "${TEST_PKG}" CFLAGS="-fprofile-arcs -ftest-coverage -O0" "${TPKG}" $* exe "${TEST_PKG}"
# after the test is complete, we need to collect the coverage data # after the test is complete, we need to collect the coverage data
INFO_FILE=`echo $TEST_PKG | sed 's/.tpkg$//'`.info INFO_FILE=`echo $TEST_PKG | sed 's/.tpkg$//'`.info
geninfo $SRCDIR/.. -o $INFO_FILE geninfo $SRCDIR/.. -o $INFO_FILE
[ -s $INFO_FILE ] && LCOV_MERGE="$LCOV_MERGE -a $INFO_FILE" [ -s $INFO_FILE ] && LCOV_MERGE="$LCOV_MERGE -a $INFO_FILE"
# trap keyboard interrupt (control-c)
trap control_c 2
done done
lcov $LCOV_MERGE -o run-all.info lcov $LCOV_MERGE -o run-all.info
genhtml run-all.info --output-directory coverage-html genhtml run-all.info --output-directory coverage-html

View File

@ -3,8 +3,18 @@
export SRCDIR=`dirname $0` export SRCDIR=`dirname $0`
. `dirname $0`/setup-env.sh . `dirname $0`/setup-env.sh
control_c()
# run if user hits control-c
{
echo -en "\n*** Exiting ***\n"
exit $?
}
for TEST_PKG in ${SRCDIR}/*.tpkg for TEST_PKG in ${SRCDIR}/*.tpkg
do do
"${TPKG}" $* exe "${TEST_PKG}" "${TPKG}" $* exe "${TEST_PKG}"
# trap keyboard interrupt (control-c)
trap control_c 2
done done
"${TPKG}" r "${TPKG}" r

10
src/test/tpkg/run-one.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
export SRCDIR=`dirname $0`
. `dirname $0`/setup-env.sh
# pass a single test name as the first paramter (without .tpgk extension)
ONE_TEST=$1
shift
"${TPKG}" $* exe ${SRCDIR}/${ONE_TEST}.tpkg

View File

@ -1119,7 +1119,7 @@ getdns_apply_network_result(getdns_network_req* netreq,
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;
} }
if (rcode == GETDNS_RCODE_SERVFAIL) { if (rcode == GETDNS_RCODE_SERVFAIL) {
/* Likely to be caused by timeout from a synchronous /* Likely to be caused by timeout from a synchronous
* lookup. Don't forge a packet. * lookup. Don't forge a packet.
*/ */