Commit 11ed7aac authored by Artem Boldariev's avatar Artem Boldariev
Browse files

TLS code refactoring, fixes and unit-tests

This commit fixes numerous stability issues with TLS transport code as
well as adds unit tests for it.
parent 01cd3104
......@@ -816,23 +816,22 @@ struct isc_nmsocket {
/*% TLS stuff */
struct tlsstream {
bool server;
BIO *app_bio;
BIO *bio_in;
BIO *bio_out;
isc_tls_t *tls;
isc_tlsctx_t *ctx;
BIO *ssl_bio;
isc_nmsocket_t *tlslistener;
isc_nmiface_t server_iface;
isc_nmiface_t local_iface;
bool connect_from_networker;
atomic_bool result_updated;
enum {
TLS_INIT,
TLS_HANDSHAKE,
TLS_IO,
TLS_CLOSING,
TLS_CLOSED
} state; /*%< The order of these is significant */
size_t nsending;
bool reading;
} tlsstream;
isc_nmsocket_h2_t h2;
......
This diff is collapsed.
......@@ -47,7 +47,8 @@ TESTS = \
task_test \
taskpool_test \
time_test \
timer_test
timer_test \
tls_test
check_PROGRAMS = \
$(TESTS)
......@@ -91,6 +92,16 @@ netmgr_test_LDADD = \
$(LDADD) \
$(LIBUV_LIBS)
tls_test_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(LIBUV_CFLAGS) \
$(OPENSSL_CFLAGS)
tls_test_LDADD = \
$(LDADD) \
$(LIBUV_LIBS) \
$(OPENSSL_LIBS)
unit-local: check
EXTRA_DIST = testdata
......
......@@ -65,7 +65,7 @@ static atomic_uint_fast64_t creads;
static atomic_bool was_error;
static unsigned int workers = 1;
static unsigned int workers = 0;
static bool reuse_supported = true;
......@@ -227,9 +227,18 @@ setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) {
static int
_setup(void **state) {
char *p = NULL;
UNUSED(state);
workers = isc_os_ncpus();
if (workers == 0) {
workers = isc_os_ncpus();
}
p = getenv("ISC_TASK_WORKERS");
if (p != NULL) {
workers = atoi(p);
}
INSIST(workers != 0);
if (isc_test_begin(NULL, false, workers) != ISC_R_SUCCESS) {
return (-1);
......@@ -587,17 +596,25 @@ static isc_threadresult_t
doh_connect_thread(isc_threadarg_t arg) {
isc_nm_t *connect_nm = (isc_nm_t *)arg;
char req_url[256];
isc_result_t result;
sockaddr_to_url(&tcp_listen_addr, atomic_load(&use_TLS), req_url,
sizeof(req_url), DOH_PATH);
while (atomic_load(&nsends) > 0) {
(void)connect_send_request(
result = connect_send_request(
connect_nm, req_url, atomic_load(&POST),
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
.length = send_msg.len },
doh_receive_send_reply_cb, NULL, atomic_load(&use_TLS),
30000);
/* protection against "too many open files" */
#ifndef _WIN32
if (result != ISC_R_SUCCESS) {
INSIST(result == ISC_R_TOOMANYOPENFILES);
usleep(1000 * workers);
}
#endif
}
return ((isc_threadresult_t)0);
......
......@@ -80,14 +80,13 @@ create_managers(unsigned int workers) {
if (workers == 0) {
workers = isc_os_ncpus();
}
p = getenv("ISC_TASK_WORKERS");
if (p != NULL) {
workers = atoi(p);
}
INSIST(workers != 0);
isc_hp_init(4 * workers);
isc_hp_init(6 * workers);
netmgr = isc_nm_start(test_mctx, workers);
CHECK(isc_taskmgr_create(test_mctx, workers, 0, netmgr, &taskmgr));
......
......@@ -60,7 +60,7 @@ static uv_buf_t stop_msg = { .base = (char *)&stop_magic,
.len = sizeof(stop_magic) };
static atomic_bool do_send = ATOMIC_VAR_INIT(false);
static unsigned int workers = 1;
static unsigned int workers = 0;
static atomic_int_fast64_t nsends;
static int_fast64_t esends; /* expected sends */
......@@ -172,9 +172,11 @@ static bool skip_long_tests = false;
static int
_setup(void **state __attribute__((unused))) {
char *p;
char *p = NULL;
workers = isc_os_ncpus();
if (workers == 0) {
workers = isc_os_ncpus();
}
p = getenv("ISC_TASK_WORKERS");
if (p != NULL) {
workers = atoi(p);
......
This diff is collapsed.
......@@ -2014,6 +2014,7 @@
./lib/isc/tests/testdata/file/keep X 2014,2018,2019,2020,2021
./lib/isc/tests/time_test.c C 2014,2015,2016,2018,2019,2020,2021
./lib/isc/tests/timer_test.c C 2018,2019,2020,2021
./lib/isc/tests/tls_test.c C 2021
./lib/isc/tests/uv_wrap.h C 2020,2021
./lib/isc/timer.c C 1998,1999,2000,2001,2002,2004,2005,2007,2008,2009,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021
./lib/isc/tls.c C 2021
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment