netaddr_test \
parse_test \
proxyheader_test \
+ proxystream_test \
quota_test \
radix_test \
random_test \
proxyheader_test.c \
proxyheader_test_data.h
+proxystream_test_CPPFLAGS = \
+ $(AM_CPPFLAGS)
+
+proxystream_test_LDADD = \
+ $(LDADD)
+
+proxystream_test_SOURCES = \
+ proxystream_test.c \
+ netmgr_common.h \
+ netmgr_common.c \
+ stream_shutdown.c
+
random_test_LDADD = \
$(LDADD) \
-lm
bool allow_send_back = false;
bool noanswer = false;
bool stream_use_TLS = false;
+bool stream_use_PROXY = false;
bool stream = false;
in_port_t stream_port = 0;
isc_nm_recv_cb_t connect_readcb = NULL;
+isc_nm_proxyheader_info_t proxy_info_data;
+isc_nm_proxyheader_info_t *proxy_info = NULL;
+isc_sockaddr_t proxy_src;
+isc_sockaddr_t proxy_dst;
+
int
setup_netmgr_test(void **state) {
+ struct in_addr in;
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
tcp_listen_addr = (isc_sockaddr_t){ .length = 0 };
isc_sockaddr_fromin6(&tcp_listen_addr, &in6addr_loopback, stream_port);
+ RUNTIME_CHECK(inet_pton(AF_INET, "1.2.3.4", &in) == 1);
+ isc_sockaddr_fromin(&proxy_src, &in, 1234);
+ RUNTIME_CHECK(inet_pton(AF_INET, "4.3.2.1", &in) == 1);
+ isc_sockaddr_fromin(&proxy_dst, &in, 4321);
+ isc_nm_proxyheader_info_init(&proxy_info_data, &proxy_src, &proxy_dst,
+ NULL);
+
esends = NSENDS * workers;
atomic_store(&nsends, esends);
isc_refcount_destroy(&active_ssends);
isc_refcount_destroy(&active_sreads);
+ proxy_info = NULL;
+
return (0);
}
return;
}
+ if (stream_use_PROXY) {
+ assert_true(isc_nm_is_proxy_handle(handle));
+ }
+
/* We are finished, initiate the shutdown */
if (have_expected_cconnects(atomic_fetch_add(&cconnects, 1) + 1)) {
do_cconnects_shutdown(loopmgr);
do_saccepts_shutdown(loopmgr);
}
+ if (stream_use_PROXY) {
+ assert_true(isc_nm_is_proxy_handle(handle));
+ }
+
isc_refcount_increment0(&active_sreads);
isc_nmhandle_attach(handle, &readhandle);
tcp_tlsctx_client_sess_cache, T_CONNECT);
}
+isc_nm_proxyheader_info_t *
+get_proxyheader_info(void) {
+ if (proxy_info != NULL) {
+ return (proxy_info);
+ }
+
+ /*
+ * There is 50% chance to get the info: so we can test LOCAL headers,
+ * too.
+ */
+ if (isc_random_uniform(2)) {
+ return (&proxy_info_data);
+ }
+
+ return (NULL);
+}
+
+static void
+proxystream_connect(isc_nm_t *nm) {
+ isc_nm_proxystreamconnect(nm, &tcp_connect_addr, &tcp_listen_addr,
+ connect_connect_cb, NULL, T_CONNECT,
+ get_proxyheader_info());
+}
+
stream_connect_function
get_stream_connect_function(void) {
if (stream_use_TLS) {
return (tls_connect);
+ } else if (stream_use_PROXY) {
+ return (proxystream_connect);
+ } else {
+ return (tcp_connect);
}
- return (tcp_connect);
+
+ UNREACHABLE();
}
isc_result_t
accept_cbarg, backlog, quota,
tcp_listen_tlsctx, sockp);
return (result);
+ } else if (stream_use_PROXY) {
+ result = isc_nm_listenproxystream(
+ listen_nm, ISC_NM_LISTEN_ALL, &tcp_listen_addr,
+ accept_cb, accept_cbarg, backlog, quota, sockp);
+ return (result);
+ } else {
+ result = isc_nm_listentcp(listen_nm, ISC_NM_LISTEN_ALL,
+ &tcp_listen_addr, accept_cb,
+ accept_cbarg, backlog, quota, sockp);
+ return (result);
}
- result = isc_nm_listentcp(listen_nm, ISC_NM_LISTEN_ALL,
- &tcp_listen_addr, accept_cb, accept_cbarg,
- backlog, quota, sockp);
- return (result);
+ UNREACHABLE();
}
void
tcp_connect_tlsctx,
tcp_tlsctx_client_sess_cache, timeout);
return;
+ } else if (stream_use_PROXY) {
+ isc_nm_proxystreamconnect(connect_nm, &tcp_connect_addr,
+ &tcp_listen_addr, cb, cbarg, timeout,
+ get_proxyheader_info());
+ return;
+ } else {
+ isc_nm_tcpconnect(connect_nm, &tcp_connect_addr,
+ &tcp_listen_addr, cb, cbarg, timeout);
+ return;
}
- isc_nm_tcpconnect(connect_nm, &tcp_connect_addr, &tcp_listen_addr, cb,
- cbarg, timeout);
+ UNREACHABLE();
}
void
* Pick unused port outside the ephemeral port range, so we don't clash with
* connected sockets.
*/
-#define UDP_TEST_PORT 9153
-#define TCP_TEST_PORT 9154
-#define TLS_TEST_PORT 9155
-#define TCPDNS_TEST_PORT 9156
-#define TLSDNS_TEST_PORT 9157
+#define UDP_TEST_PORT 9153
+#define TCP_TEST_PORT 9154
+#define TLS_TEST_PORT 9155
+#define TCPDNS_TEST_PORT 9156
+#define TLSDNS_TEST_PORT 9157
+#define PROXYSTREAM_TEST_PORT 9158
typedef void (*stream_connect_function)(isc_nm_t *nm);
typedef void (*connect_func)(isc_nm_t *);
extern bool allow_send_back;
extern bool noanswer;
extern bool stream_use_TLS;
+extern bool stream_use_PROXY;
extern bool stream;
extern in_port_t stream_port;
void
stream_connect(isc_nm_cb_t cb, void *cbarg, unsigned int timeout);
+isc_nm_proxyheader_info_t *
+get_proxyheader_info(void);
+
int
stream_noop_setup(void **state ISC_ATTR_UNUSED);
void
--- /dev/null
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#include <sched.h> /* IWYU pragma: keep */
+#include <setjmp.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+/*
+ * As a workaround, include an OpenSSL header file before including cmocka.h,
+ * because OpenSSL 3.1.0 uses __attribute__(malloc), conflicting with a
+ * redefined malloc in cmocka.h.
+ */
+#include <openssl/err.h>
+
+#define UNIT_TESTING
+#include <cmocka.h>
+
+#include <isc/loop.h>
+#include <isc/nonce.h>
+#include <isc/os.h>
+#include <isc/quota.h>
+#include <isc/refcount.h>
+#include <isc/sockaddr.h>
+#include <isc/thread.h>
+#include <isc/util.h>
+#include <isc/uv.h>
+
+#include "uv_wrap.h"
+#define KEEP_BEFORE
+
+#include "netmgr/tcp.c"
+#include "netmgr_common.h"
+
+#include <tests/isc.h>
+
+/* TCP */
+ISC_LOOP_TEST_IMPL(proxystream_noop) {
+ stream_noop(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_noresponse) {
+ stream_noresponse(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_shutdownconnect) {
+ stream_shutdownconnect(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_shutdownread) {
+ stream_shutdownread(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_timeout_recovery) {
+ stream_timeout_recovery(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_recv_one) {
+ stream_recv_one(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_recv_two) {
+ stream_recv_two(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_recv_send) {
+ stream_recv_send(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_recv_send_sendback) {
+ allow_send_back = true;
+ stream_recv_send(arg);
+ return;
+}
+
+/* TCP Quota */
+
+ISC_LOOP_TEST_IMPL(proxystream_recv_one_quota) {
+ atomic_store(&check_listener_quota, true);
+ stream_recv_one(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_recv_two_quota) {
+ atomic_store(&check_listener_quota, true);
+ stream_recv_two(arg);
+ return;
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_recv_send_quota) {
+ atomic_store(&check_listener_quota, true);
+ stream_recv_send(arg);
+}
+
+ISC_LOOP_TEST_IMPL(proxystream_recv_send_quota_sendback) {
+ atomic_store(&check_listener_quota, true);
+ allow_send_back = true;
+ stream_recv_send(arg);
+}
+
+ISC_TEST_LIST_START
+
+/* Stream */
+ISC_TEST_ENTRY_CUSTOM(proxystream_noop, stream_noop_setup, stream_noop_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_noresponse, stream_noresponse_setup,
+ stream_noresponse_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_shutdownconnect, stream_shutdownconnect_setup,
+ stream_shutdownconnect_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_shutdownread, stream_shutdownread_setup,
+ stream_shutdownread_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_timeout_recovery,
+ stream_timeout_recovery_setup,
+ stream_timeout_recovery_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_recv_one, stream_recv_one_setup,
+ stream_recv_one_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_recv_two, stream_recv_two_setup,
+ stream_recv_two_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_recv_send, stream_recv_send_setup,
+ stream_recv_send_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_recv_send_sendback, stream_recv_send_setup,
+ stream_recv_send_teardown)
+
+/* Stream Quota */
+ISC_TEST_ENTRY_CUSTOM(proxystream_recv_one_quota, stream_recv_one_setup,
+ stream_recv_one_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_recv_two_quota, stream_recv_two_setup,
+ stream_recv_two_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_recv_send_quota, stream_recv_send_setup,
+ stream_recv_send_teardown)
+ISC_TEST_ENTRY_CUSTOM(proxystream_recv_send_quota_sendback,
+ stream_recv_send_setup, stream_recv_send_teardown)
+
+ISC_TEST_LIST_END
+
+static int
+proxystream_setup(void **state ISC_ATTR_UNUSED) {
+ stream_port = PROXYSTREAM_TEST_PORT;
+ stream_use_TLS = false;
+ stream_use_PROXY = true;
+ stream = true;
+
+ return (0);
+}
+
+ISC_TEST_MAIN_CUSTOM(proxystream_setup, NULL)