netmgr http refactoring
- style, cleanup, and removal of unnecessary code - combine isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint() into one function, renamed isc_http_endpoint() - move isc_nm_http_connect_send_request() into doh_test.c as a helper function; remove it from the public API - renamed isc_http2 and isc_nm_http2 entities to just isc_http and isc_nm_http, for consistency with other existing names - shortened a number of long names - the caller is now responsible for determining the peer address in isc_nm_httpconnect(); this eliminates the need to parse the URI and the dependency on an external resolver. the caller is also now responsible for creating the SSL client context, for consistency with isc_nm_tlsdnsconnect().
This commit is contained in:
@@ -506,24 +506,6 @@ isc_nm_tlsdnsconnect(isc_nm_t *mgr, isc_nmiface_t *local, isc_nmiface_t *peer,
|
||||
* 'cb'.
|
||||
*/
|
||||
|
||||
typedef void (*isc_nm_http_cb_t)(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_region_t *data, void *cbarg);
|
||||
/*%<
|
||||
* Callback function to be used when receiving an HTTP request.
|
||||
*
|
||||
* 'handle' the handle that can be used to send back the answer.
|
||||
* 'eresult' the result of the event.
|
||||
* 'data' contains the received data, if any. It will be freed
|
||||
* after return by caller.
|
||||
* 'cbarg' the callback argument passed to listen function.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_nm_http_connect_send_request(isc_nm_t *mgr, const char *uri, bool POST,
|
||||
isc_region_t *message, isc_nm_recv_cb_t cb,
|
||||
void *cbarg, isc_tlsctx_t *ctx,
|
||||
unsigned int timeout);
|
||||
|
||||
isc_result_t
|
||||
isc_nm_httpconnect(isc_nm_t *mgr, isc_nmiface_t *local, isc_nmiface_t *peer,
|
||||
const char *uri, bool POST, isc_nm_cb_t cb, void *cbarg,
|
||||
@@ -540,11 +522,5 @@ isc_nm_listenhttp(isc_nm_t *mgr, isc_nmiface_t *iface, int backlog,
|
||||
isc_nmsocket_t **sockp);
|
||||
|
||||
isc_result_t
|
||||
isc_nm_http_add_endpoint(isc_nmsocket_t *sock, const char *uri,
|
||||
isc_nm_http_cb_t cb, void *cbarg,
|
||||
size_t extrahandlesize);
|
||||
|
||||
isc_result_t
|
||||
isc_nm_http_add_doh_endpoint(isc_nmsocket_t *sock, const char *uri,
|
||||
isc_nm_recv_cb_t cb, void *cbarg,
|
||||
size_t extrahandlesize);
|
||||
isc_nm_http_endpoint(isc_nmsocket_t *sock, const char *uri, isc_nm_recv_cb_t cb,
|
||||
void *cbarg, size_t extrahandlesize);
|
||||
|
||||
+221
-435
File diff suppressed because it is too large
Load Diff
+28
-26
@@ -156,7 +156,7 @@ isc__nm_dump_active(isc_nm_t *nm);
|
||||
#define isc__nmsocket_prep_destroy(sock) isc___nmsocket_prep_destroy(sock)
|
||||
#endif
|
||||
|
||||
typedef struct isc_nm_http2_session isc_nm_http2_session_t;
|
||||
typedef struct isc_nm_http_session isc_nm_http_session_t;
|
||||
|
||||
/*
|
||||
* Single network event loop worker.
|
||||
@@ -210,7 +210,7 @@ struct isc_nmhandle {
|
||||
isc_nmsocket_t *sock;
|
||||
size_t ah_pos; /* Position in the socket's 'active handles' array */
|
||||
|
||||
isc_nm_http2_session_t *httpsession;
|
||||
isc_nm_http_session_t *httpsession;
|
||||
|
||||
isc_sockaddr_t peer;
|
||||
isc_sockaddr_t local;
|
||||
@@ -302,20 +302,18 @@ typedef enum isc__netievent_type {
|
||||
|
||||
typedef union {
|
||||
isc_nm_recv_cb_t recv;
|
||||
isc_nm_http_cb_t http;
|
||||
isc_nm_cb_t send;
|
||||
isc_nm_cb_t connect;
|
||||
isc_nm_accept_cb_t accept;
|
||||
} isc__nm_cb_t;
|
||||
|
||||
typedef struct isc_nm_http2_server_handler isc_nm_http2_server_handler_t;
|
||||
|
||||
struct isc_nm_http2_server_handler {
|
||||
typedef struct isc_nm_httphandler isc_nm_httphandler_t;
|
||||
struct isc_nm_httphandler {
|
||||
char *path;
|
||||
isc_nm_http_cb_t cb;
|
||||
isc_nm_recv_cb_t cb;
|
||||
void *cbarg;
|
||||
size_t extrahandlesize;
|
||||
LINK(isc_nm_http2_server_handler_t) link;
|
||||
LINK(isc_nm_httphandler_t) link;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -674,7 +672,7 @@ typedef enum isc_nmsocket_type {
|
||||
isc_nm_tlsdnslistener,
|
||||
isc_nm_tlsdnssocket,
|
||||
isc_nm_httplistener,
|
||||
isc_nm_httpstream
|
||||
isc_nm_httpsocket
|
||||
} isc_nmsocket_type;
|
||||
|
||||
/*%
|
||||
@@ -710,19 +708,19 @@ typedef enum isc_doh_request_type {
|
||||
ISC_HTTP_REQ_GET,
|
||||
ISC_HTTP_REQ_POST,
|
||||
ISC_HTTP_REQ_UNSUPPORTED
|
||||
} isc_http2_request_type_t;
|
||||
} isc_http_request_type_t;
|
||||
|
||||
typedef enum isc_http2_scheme_type {
|
||||
typedef enum isc_http_scheme_type {
|
||||
ISC_HTTP_SCHEME_HTTP,
|
||||
ISC_HTTP_SCHEME_HTTP_SECURE,
|
||||
ISC_HTTP_SCHEME_UNSUPPORTED
|
||||
} isc_http2_scheme_type_t;
|
||||
} isc_http_scheme_type_t;
|
||||
|
||||
typedef struct isc_nm_http_doh_cbarg {
|
||||
typedef struct isc_nm_httpcbarg {
|
||||
isc_nm_recv_cb_t cb;
|
||||
void *cbarg;
|
||||
LINK(struct isc_nm_http_doh_cbarg) link;
|
||||
} isc_nm_http_doh_cbarg_t;
|
||||
LINK(struct isc_nm_httpcbarg) link;
|
||||
} isc_nm_httpcbarg_t;
|
||||
|
||||
typedef struct isc_nmsocket_h2 {
|
||||
isc_nmsocket_t *psock; /* owner of the structure */
|
||||
@@ -730,32 +728,33 @@ typedef struct isc_nmsocket_h2 {
|
||||
char *query_data;
|
||||
size_t query_data_len;
|
||||
bool query_too_large;
|
||||
isc_nm_http2_server_handler_t *handler;
|
||||
isc_nm_httphandler_t *handler;
|
||||
|
||||
uint8_t *buf;
|
||||
size_t bufsize;
|
||||
size_t bufpos;
|
||||
|
||||
int32_t stream_id;
|
||||
isc_nm_http2_session_t *session;
|
||||
isc_nm_http_session_t *session;
|
||||
|
||||
isc_nmsocket_t *httpserver;
|
||||
|
||||
isc_http2_request_type_t request_type;
|
||||
isc_http2_scheme_type_t request_scheme;
|
||||
isc_http_request_type_t request_type;
|
||||
isc_http_scheme_type_t request_scheme;
|
||||
|
||||
size_t content_length;
|
||||
char clenbuf[128];
|
||||
|
||||
bool content_type_verified;
|
||||
bool accept_type_verified;
|
||||
|
||||
isc_nm_http_cb_t handler_cb;
|
||||
void *handler_cbarg;
|
||||
isc_nm_recv_cb_t cb;
|
||||
void *cbarg;
|
||||
LINK(struct isc_nmsocket_h2) link;
|
||||
|
||||
ISC_LIST(isc_nm_http2_server_handler_t) handlers;
|
||||
ISC_LIST(isc_nm_http_doh_cbarg_t) handlers_cbargs;
|
||||
isc_rwlock_t handlers_lock;
|
||||
|
||||
char response_content_length_str[128];
|
||||
ISC_LIST(isc_nm_httphandler_t) handlers;
|
||||
ISC_LIST(isc_nm_httpcbarg_t) handler_cbargs;
|
||||
isc_rwlock_t lock;
|
||||
|
||||
struct isc_nmsocket_h2_connect_data {
|
||||
char *uri;
|
||||
@@ -1531,6 +1530,9 @@ void
|
||||
isc__nm_http_send(isc_nmhandle_t *handle, const isc_region_t *region,
|
||||
isc_nm_cb_t cb, void *cbarg);
|
||||
|
||||
void
|
||||
isc__nm_http_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg);
|
||||
|
||||
void
|
||||
isc__nm_http_close(isc_nmsocket_t *sock);
|
||||
|
||||
|
||||
+17
-25
@@ -1011,7 +1011,7 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) {
|
||||
|
||||
if (sock->type == isc_nm_httplistener) {
|
||||
isc__nm_http_clear_handlers(sock);
|
||||
isc_rwlock_destroy(&sock->h2.handlers_lock);
|
||||
isc_rwlock_destroy(&sock->h2.lock);
|
||||
}
|
||||
|
||||
if (sock->h2.request_path != NULL) {
|
||||
@@ -1149,7 +1149,7 @@ isc___nmsocket_prep_destroy(isc_nmsocket_t *sock FLARG) {
|
||||
case isc_nm_tlsdnssocket:
|
||||
isc__nm_tlsdns_close(sock);
|
||||
return;
|
||||
case isc_nm_httpstream:
|
||||
case isc_nm_httpsocket:
|
||||
isc__nm_http_close(sock);
|
||||
return;
|
||||
default:
|
||||
@@ -1259,7 +1259,7 @@ isc___nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
|
||||
case isc_nm_tcpdnslistener:
|
||||
case isc_nm_tlsdnssocket:
|
||||
case isc_nm_tlsdnslistener:
|
||||
case isc_nm_httpstream:
|
||||
case isc_nm_httpsocket:
|
||||
case isc_nm_httplistener:
|
||||
if (family == AF_INET) {
|
||||
sock->statsindex = tcp4statsindex;
|
||||
@@ -1290,28 +1290,17 @@ isc___nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
|
||||
|
||||
atomic_store(&sock->active_child_connections, 0);
|
||||
|
||||
sock->h2 = (isc_nmsocket_h2_t){
|
||||
.request_type = ISC_HTTP_REQ_UNSUPPORTED,
|
||||
.request_scheme = ISC_HTTP_SCHEME_UNSUPPORTED,
|
||||
};
|
||||
|
||||
if (type == isc_nm_httplistener) {
|
||||
ISC_LIST_INIT(sock->h2.handlers);
|
||||
ISC_LIST_INIT(sock->h2.handlers_cbargs);
|
||||
isc_rwlock_init(&sock->h2.handlers_lock, 0, 1);
|
||||
ISC_LIST_INIT(sock->h2.handler_cbargs);
|
||||
isc_rwlock_init(&sock->h2.lock, 0, 1);
|
||||
}
|
||||
|
||||
sock->h2.session = NULL;
|
||||
sock->h2.httpserver = NULL;
|
||||
sock->h2.query_data = NULL;
|
||||
sock->h2.query_data_len = 0;
|
||||
sock->h2.query_too_large = false;
|
||||
sock->h2.request_path = NULL;
|
||||
sock->h2.request_type = ISC_HTTP_REQ_UNSUPPORTED;
|
||||
sock->h2.request_scheme = ISC_HTTP_SCHEME_UNSUPPORTED;
|
||||
sock->h2.content_length = 0;
|
||||
sock->h2.content_type_verified = false;
|
||||
sock->h2.accept_type_verified = false;
|
||||
sock->h2.handler_cb = NULL;
|
||||
sock->h2.handler_cbarg = NULL;
|
||||
sock->h2.connect.uri = NULL;
|
||||
sock->h2.buf = NULL;
|
||||
|
||||
sock->magic = NMSOCK_MAGIC;
|
||||
}
|
||||
|
||||
@@ -1453,7 +1442,7 @@ isc___nmhandle_get(isc_nmsocket_t *sock, isc_sockaddr_t *peer,
|
||||
sock->statichandle = handle;
|
||||
}
|
||||
|
||||
if (sock->type == isc_nm_httpstream) {
|
||||
if (sock->type == isc_nm_httpsocket) {
|
||||
handle->httpsession = sock->h2.session;
|
||||
}
|
||||
|
||||
@@ -1762,7 +1751,7 @@ isc_nm_send(isc_nmhandle_t *handle, isc_region_t *region, isc_nm_cb_t cb,
|
||||
case isc_nm_tlsdnssocket:
|
||||
isc__nm_tlsdns_send(handle, region, cb, cbarg);
|
||||
break;
|
||||
case isc_nm_httpstream:
|
||||
case isc_nm_httpsocket:
|
||||
isc__nm_http_send(handle, region, cb, cbarg);
|
||||
break;
|
||||
default:
|
||||
@@ -1798,6 +1787,9 @@ isc_nm_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
|
||||
case isc_nm_tlsdnssocket:
|
||||
isc__nm_tlsdns_read(handle, cb, cbarg);
|
||||
break;
|
||||
case isc_nm_httpsocket:
|
||||
isc__nm_http_read(handle, cb, cbarg);
|
||||
break;
|
||||
default:
|
||||
INSIST(0);
|
||||
ISC_UNREACHABLE();
|
||||
@@ -2445,8 +2437,8 @@ nmsocket_type_totext(isc_nmsocket_type type) {
|
||||
return ("isc_nm_tlsdnssocket");
|
||||
case isc_nm_httplistener:
|
||||
return ("isc_nm_httplistener");
|
||||
case isc_nm_httpstream:
|
||||
return ("isc_nm_httpstream");
|
||||
case isc_nm_httpsocket:
|
||||
return ("isc_nm_httpsocket");
|
||||
default:
|
||||
INSIST(0);
|
||||
ISC_UNREACHABLE();
|
||||
|
||||
+95
-86
@@ -101,6 +101,63 @@ static SSL_CTX *server_ssl_ctx = NULL;
|
||||
#define X(v)
|
||||
#endif
|
||||
|
||||
typedef struct csdata {
|
||||
isc_nm_recv_cb_t reply_cb;
|
||||
void *cb_arg;
|
||||
isc_region_t region;
|
||||
} csdata_t;
|
||||
|
||||
static void
|
||||
connect_send_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
|
||||
csdata_t data;
|
||||
|
||||
REQUIRE(VALID_NMHANDLE(handle));
|
||||
|
||||
memmove(&data, arg, sizeof(data));
|
||||
isc_mem_put(handle->sock->mgr->mctx, arg, sizeof(data));
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
result = isc_nm_httprequest(handle, &data.region, data.reply_cb,
|
||||
data.cb_arg);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
isc_mem_put(handle->sock->mgr->mctx, data.region.base,
|
||||
data.region.length);
|
||||
return;
|
||||
error:
|
||||
data.reply_cb(handle, result, NULL, data.cb_arg);
|
||||
isc_mem_put(handle->sock->mgr->mctx, data.region.base,
|
||||
data.region.length);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
connect_send_request(isc_nm_t *mgr, const char *uri, bool post,
|
||||
isc_region_t *region, isc_nm_recv_cb_t cb, void *cbarg,
|
||||
bool tls, unsigned int timeout) {
|
||||
isc_result_t result;
|
||||
isc_region_t copy;
|
||||
csdata_t *data = NULL;
|
||||
SSL_CTX *ctx = NULL;
|
||||
|
||||
copy = (isc_region_t){ .base = isc_mem_get(mgr->mctx, region->length),
|
||||
.length = region->length };
|
||||
memmove(copy.base, region->base, region->length);
|
||||
data = isc_mem_get(mgr->mctx, sizeof(*data));
|
||||
*data = (csdata_t){ .reply_cb = cb, .cb_arg = cbarg, .region = copy };
|
||||
if (tls) {
|
||||
isc_tlsctx_createclient(&ctx);
|
||||
}
|
||||
|
||||
result = isc_nm_httpconnect(
|
||||
mgr, NULL, (isc_nmiface_t *)&tcp_listen_addr, uri, post,
|
||||
connect_send_cb, data, ctx, timeout, 0);
|
||||
return (result);
|
||||
}
|
||||
|
||||
static int
|
||||
setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) {
|
||||
isc_result_t result;
|
||||
@@ -261,7 +318,7 @@ nm_teardown(void **state) {
|
||||
}
|
||||
isc_mem_put(test_mctx, nm, MAX_NM * sizeof(nm[0]));
|
||||
|
||||
if (server_ssl_ctx) {
|
||||
if (server_ssl_ctx != NULL) {
|
||||
isc_tlsctx_free(&server_ssl_ctx);
|
||||
}
|
||||
|
||||
@@ -276,6 +333,7 @@ sockaddr_to_url(isc_sockaddr_t *sa, const bool https, char *outbuf,
|
||||
uint16_t port;
|
||||
char saddr[INET6_ADDRSTRLEN] = { 0 };
|
||||
int family;
|
||||
|
||||
if (sa == NULL || outbuf == NULL || outbuf_len == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -382,10 +440,6 @@ mock_doh_uv_tcp_bind(void **state) {
|
||||
isc_nm_t *listen_nm = nm[0];
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
isc_nmsocket_t *listen_sock = NULL;
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
WILL_RETURN(uv_tcp_bind, UV_EADDRINUSE);
|
||||
|
||||
@@ -404,17 +458,13 @@ doh_noop(void **state) {
|
||||
isc_nm_t *connect_nm = nm[1];
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
isc_nmsocket_t *listen_sock = NULL;
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
char req_url[256];
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
result = isc_nm_listenhttp(listen_nm, (isc_nmiface_t *)&tcp_listen_addr,
|
||||
0, NULL, NULL, &listen_sock);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
result = isc_nm_http_add_doh_endpoint(listen_sock, DOH_PATH,
|
||||
noop_read_cb, NULL, 0);
|
||||
result = isc_nm_http_endpoint(listen_sock, DOH_PATH, noop_read_cb, NULL,
|
||||
0);
|
||||
|
||||
isc_nm_stoplistening(listen_sock);
|
||||
isc_nmsocket_close(&listen_sock);
|
||||
@@ -422,11 +472,11 @@ doh_noop(void **state) {
|
||||
|
||||
sockaddr_to_url(&tcp_listen_addr, false, req_url, sizeof(req_url),
|
||||
DOH_PATH);
|
||||
(void)isc_nm_http_connect_send_request(
|
||||
(void)connect_send_request(
|
||||
connect_nm, req_url, atomic_load(&POST),
|
||||
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
||||
.length = send_msg.len },
|
||||
noop_read_cb, NULL, NULL, 30000);
|
||||
noop_read_cb, NULL, atomic_load(&use_TLS), 30000);
|
||||
|
||||
isc_nm_closedown(connect_nm);
|
||||
|
||||
@@ -455,27 +505,23 @@ doh_noresponse(void **state) {
|
||||
isc_nm_t *connect_nm = nm[1];
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
isc_nmsocket_t *listen_sock = NULL;
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
char req_url[256];
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
result = isc_nm_listenhttp(listen_nm, (isc_nmiface_t *)&tcp_listen_addr,
|
||||
0, NULL, NULL, &listen_sock);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_nm_http_add_doh_endpoint(listen_sock, DOH_PATH,
|
||||
noop_read_cb, NULL, 0);
|
||||
result = isc_nm_http_endpoint(listen_sock, DOH_PATH, noop_read_cb, NULL,
|
||||
0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
sockaddr_to_url(&tcp_listen_addr, false, req_url, sizeof(req_url),
|
||||
DOH_PATH);
|
||||
(void)isc_nm_http_connect_send_request(
|
||||
(void)connect_send_request(
|
||||
connect_nm, req_url, atomic_load(&POST),
|
||||
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
||||
.length = send_msg.len },
|
||||
noop_read_cb, NULL, NULL, 30000);
|
||||
noop_read_cb, NULL, atomic_load(&use_TLS), 30000);
|
||||
|
||||
isc_nm_stoplistening(listen_sock);
|
||||
isc_nmsocket_close(&listen_sock);
|
||||
@@ -535,20 +581,18 @@ doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
static isc_threadresult_t
|
||||
doh_connect_thread(isc_threadarg_t arg) {
|
||||
isc_nm_t *connect_nm = (isc_nm_t *)arg;
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
char req_url[256];
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
sockaddr_to_url(&tcp_listen_addr, atomic_load(&use_TLS), req_url,
|
||||
sizeof(req_url), DOH_PATH);
|
||||
|
||||
while (atomic_load(&nsends) > 0) {
|
||||
(void)isc_nm_http_connect_send_request(
|
||||
(void)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, NULL, 5000);
|
||||
doh_receive_send_reply_cb, NULL, atomic_load(&use_TLS),
|
||||
30000);
|
||||
}
|
||||
|
||||
return ((isc_threadresult_t)0);
|
||||
@@ -561,33 +605,26 @@ doh_recv_one(void **state) {
|
||||
isc_nm_t *connect_nm = nm[1];
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
isc_nmsocket_t *listen_sock = NULL;
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
char req_url[256];
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
atomic_store(&nsends, 1);
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
result = isc_nm_listenhttp(
|
||||
listen_nm, (isc_nmiface_t *)&tcp_listen_addr, 0, NULL,
|
||||
atomic_load(&use_TLS) ? server_ssl_ctx : NULL, &listen_sock);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_nm_http_add_doh_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
result = isc_nm_http_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
sockaddr_to_url(&tcp_listen_addr, atomic_load(&use_TLS), req_url,
|
||||
sizeof(req_url), DOH_PATH);
|
||||
result = isc_nm_http_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_reply_cb, NULL, NULL, 5000);
|
||||
doh_receive_reply_cb, NULL, atomic_load(&use_TLS), 30000);
|
||||
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
@@ -688,31 +725,31 @@ doh_recv_two(void **state) {
|
||||
isc_nm_t *connect_nm = nm[1];
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
isc_nmsocket_t *listen_sock = NULL;
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
char req_url[256];
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
SSL_CTX *ctx = NULL;
|
||||
|
||||
atomic_store(&nsends, 2);
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
result = isc_nm_listenhttp(
|
||||
listen_nm, (isc_nmiface_t *)&tcp_listen_addr, 0, NULL,
|
||||
atomic_load(&use_TLS) ? server_ssl_ctx : NULL, &listen_sock);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_nm_http_add_doh_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
result = isc_nm_http_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
sockaddr_to_url(&tcp_listen_addr, atomic_load(&use_TLS), req_url,
|
||||
sizeof(req_url), DOH_PATH);
|
||||
|
||||
if (atomic_load(&use_TLS)) {
|
||||
isc_tlsctx_createclient(&ctx);
|
||||
}
|
||||
|
||||
result = isc_nm_httpconnect(
|
||||
connect_nm, NULL, NULL, req_url, atomic_load(&POST),
|
||||
doh_connect_send_two_requests_cb, NULL, NULL, 5000, 0);
|
||||
connect_nm, NULL, (isc_nmiface_t *)&tcp_listen_addr, req_url,
|
||||
atomic_load(&POST), doh_connect_send_two_requests_cb, NULL, ctx,
|
||||
5000, 0);
|
||||
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
@@ -783,21 +820,14 @@ doh_recv_send(void **state) {
|
||||
isc_nmsocket_t *listen_sock = NULL;
|
||||
size_t nthreads = ISC_MAX(ISC_MIN(workers, 32), 1);
|
||||
isc_thread_t threads[32] = { 0 };
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
result = isc_nm_listenhttp(
|
||||
listen_nm, (isc_nmiface_t *)&tcp_listen_addr, 0, NULL,
|
||||
atomic_load(&use_TLS) ? server_ssl_ctx : NULL, &listen_sock);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_nm_http_add_doh_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
result = isc_nm_http_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
for (size_t i = 0; i < nthreads; i++) {
|
||||
@@ -859,21 +889,14 @@ doh_recv_half_send(void **state) {
|
||||
isc_nmsocket_t *listen_sock = NULL;
|
||||
size_t nthreads = ISC_MAX(ISC_MIN(workers, 32), 1);
|
||||
isc_thread_t threads[32] = { 0 };
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
result = isc_nm_listenhttp(
|
||||
listen_nm, (isc_nmiface_t *)&tcp_listen_addr, 0, NULL,
|
||||
atomic_load(&use_TLS) ? server_ssl_ctx : NULL, &listen_sock);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_nm_http_add_doh_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
result = isc_nm_http_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
for (size_t i = 0; i < nthreads; i++) {
|
||||
@@ -940,21 +963,14 @@ doh_half_recv_send(void **state) {
|
||||
isc_nmsocket_t *listen_sock = NULL;
|
||||
size_t nthreads = ISC_MAX(ISC_MIN(workers, 32), 1);
|
||||
isc_thread_t threads[32] = { 0 };
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
result = isc_nm_listenhttp(
|
||||
listen_nm, (isc_nmiface_t *)&tcp_listen_addr, 0, NULL,
|
||||
atomic_load(&use_TLS) ? server_ssl_ctx : NULL, &listen_sock);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_nm_http_add_doh_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
result = isc_nm_http_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
for (size_t i = 0; i < nthreads; i++) {
|
||||
@@ -1021,21 +1037,14 @@ doh_half_recv_half_send(void **state) {
|
||||
isc_nmsocket_t *listen_sock = NULL;
|
||||
size_t nthreads = ISC_MAX(ISC_MIN(workers, 32), 1);
|
||||
isc_thread_t threads[32] = { 0 };
|
||||
isc_sockaddr_t tcp_connect_addr;
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
tcp_connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||
isc_sockaddr_fromin6(&tcp_connect_addr, &in6addr_loopback, 0);
|
||||
|
||||
result = isc_nm_listenhttp(
|
||||
listen_nm, (isc_nmiface_t *)&tcp_listen_addr, 0, NULL,
|
||||
atomic_load(&use_TLS) ? server_ssl_ctx : NULL, &listen_sock);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_nm_http_add_doh_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
result = isc_nm_http_endpoint(listen_sock, DOH_PATH,
|
||||
doh_receive_request_cb, NULL, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
for (size_t i = 0; i < nthreads; i++) {
|
||||
@@ -1625,12 +1634,12 @@ doh_cloudflare(void **state) {
|
||||
isc_nm_t **nm = (isc_nm_t **)*state;
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
|
||||
result = isc_nm_http_connect_send_request(
|
||||
result = connect_send_request(
|
||||
nm[0], "https://cloudflare-dns.com/dns-query",
|
||||
atomic_load(&POST),
|
||||
&(isc_region_t){ .base = (uint8_t *)wikipedia_org_A,
|
||||
.length = sizeof(wikipedia_org_A) },
|
||||
doh_print_reply_cb, NULL, NULL, 5000);
|
||||
doh_print_reply_cb, NULL, atomic_load(&use_TLS), 30000);
|
||||
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
@@ -106,6 +108,23 @@ isc_tlsctx_free(isc_tlsctx_t **ctxp) {
|
||||
SSL_CTX_free(ctx);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_NEXTPROTONEG
|
||||
/*
|
||||
* NPN TLS extension client callback.
|
||||
*/
|
||||
static int
|
||||
select_next_proto_cb(SSL *ssl, unsigned char **out, unsigned char *outlen,
|
||||
const unsigned char *in, unsigned int inlen, void *arg) {
|
||||
UNUSED(ssl);
|
||||
UNUSED(arg);
|
||||
|
||||
if (nghttp2_select_next_protocol(out, outlen, in, inlen) <= 0) {
|
||||
return (SSL_TLSEXT_ERR_NOACK);
|
||||
}
|
||||
return (SSL_TLSEXT_ERR_OK);
|
||||
}
|
||||
#endif /* !OPENSSL_NO_NEXTPROTONEG */
|
||||
|
||||
isc_result_t
|
||||
isc_tlsctx_createclient(isc_tlsctx_t **ctxp) {
|
||||
unsigned long err;
|
||||
@@ -133,6 +152,15 @@ isc_tlsctx_createclient(isc_tlsctx_t **ctxp) {
|
||||
SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_NEXTPROTONEG
|
||||
SSL_CTX_set_next_proto_select_cb(ctx, select_next_proto_cb, NULL);
|
||||
#endif /* !OPENSSL_NO_NEXTPROTONEG */
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
||||
SSL_CTX_set_alpn_protos(ctx, (const unsigned char *)NGHTTP2_PROTO_ALPN,
|
||||
NGHTTP2_PROTO_ALPN_LEN);
|
||||
#endif /* OPENSSL_VERSION_NUMBER >= 0x10002000L */
|
||||
|
||||
*ctxp = ctx;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
@@ -448,9 +448,7 @@ isc_nm_cancelread
|
||||
isc_nm_closedown
|
||||
isc_nm_destroy
|
||||
isc_nm_detach
|
||||
isc_nm_http_add_doh_endpoint
|
||||
isc_nm_http_add_endpoint
|
||||
isc_nm_http_connect_send_request
|
||||
isc_nm_http_endpoint
|
||||
isc_nm_httpconnect
|
||||
isc_nm_httprequest
|
||||
isc_nm_listenhttp
|
||||
|
||||
@@ -556,9 +556,9 @@ ns_interface_listenhttp(ns_interface_t *ifp, isc_tlsctx_t *sslctx, char **eps,
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
for (i = 0; i < neps; i++) {
|
||||
result = isc_nm_http_add_doh_endpoint(
|
||||
sock, eps[i], ns__client_request, ifp,
|
||||
sizeof(ns_client_t));
|
||||
result = isc_nm_http_endpoint(sock, eps[i],
|
||||
ns__client_request, ifp,
|
||||
sizeof(ns_client_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user