From: Tomas Krizek Date: Wed, 30 Sep 2020 12:10:23 +0000 (+0200) Subject: daemon: make nghttp2 optional X-Git-Tag: v5.2.0~15^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=605a9af8dc35dd9946acc9608cd1083282173cfd;p=thirdparty%2Fknot-resolver.git daemon: make nghttp2 optional --- diff --git a/daemon/http.c b/daemon/http.c index 1c8f0f937..66fc885f4 100644 --- a/daemon/http.c +++ b/daemon/http.c @@ -6,9 +6,6 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -#include -#include - #include #include #include diff --git a/daemon/http.h b/daemon/http.h index 07bda4a30..d2c440c4c 100644 --- a/daemon/http.h +++ b/daemon/http.h @@ -9,9 +9,12 @@ #pragma once #include -#include #include +#ifdef ENABLE_DOH2 +#include +#endif + #include "lib/generic/queue.h" /** Transport session (opaque). */ @@ -35,8 +38,10 @@ struct http_ctx { ssize_t buf_size; }; +#ifdef ENABLE_DOH2 struct http_ctx* http_new(struct session *session, http_send_callback send_cb); ssize_t http_process_input_data(struct session *session, const uint8_t *buf, ssize_t nread); int http_write(uv_write_t *req, uv_handle_t *handle, knot_pkt_t* pkt, int32_t stream_id, uv_write_cb on_write); void http_free(struct http_ctx *ctx); +#endif diff --git a/daemon/io.c b/daemon/io.c index fff465ba2..f64ead4f8 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -306,6 +306,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) data = session_wirebuf_get_free_start(s); data_len = consumed; } +#ifdef ENABLE_DOH2 if (session_flags(s)->has_http) { consumed = http_process_input_data(s, data, data_len); if (consumed < 0) { @@ -324,6 +325,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) data = session_wirebuf_get_free_start(s); data_len = consumed; } +#endif /* data points to start of the free space in session wire buffer. Simple increase internal counter. */ @@ -339,6 +341,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) mp_flush(the_worker->pkt_pool.ctx); } +#ifdef ENABLE_DOH2 static ssize_t tls_send(const uint8_t *buf, const size_t len, struct session *session) { struct tls_ctx *ctx = session_tls_get_server_ctx(session); @@ -353,6 +356,7 @@ static ssize_t tls_send(const uint8_t *buf, const size_t len, struct session *se } return sent; } +#endif static void _tcp_accept(uv_stream_t *master, int status, bool tls, bool http) { @@ -452,6 +456,7 @@ static void _tcp_accept(uv_stream_t *master, int status, bool tls, bool http) session_tls_set_server_ctx(s, ctx); } } +#ifdef ENABLE_DOH2 if (http) { struct http_ctx *ctx = session_http_get_server_ctx(s); if (!ctx) { @@ -467,6 +472,7 @@ static void _tcp_accept(uv_stream_t *master, int status, bool tls, bool http) session_http_set_server_ctx(s, ctx); } } +#endif session_timer_start(s, tcp_timeout_trigger, timeout, idle_in_timeout); io_start_read((uv_handle_t *)client); } @@ -481,16 +487,18 @@ static void tls_accept(uv_stream_t *master, int status) _tcp_accept(master, status, true, false); } +#ifdef ENABLE_DOH2 static void https_accept(uv_stream_t *master, int status) { _tcp_accept(master, status, true, true); } +#endif int io_listen_tcp(uv_loop_t *loop, uv_tcp_t *handle, int fd, int tcp_backlog, bool has_tls, bool has_http) { uv_connection_cb connection; if (has_tls && has_http) { -#ifdef NGHTTP2_VERSION_NUM +#ifdef ENABLE_DOH2 connection = https_accept; #else kr_log_error("[ io ] kresd was compiled without libnghttp2 support"); diff --git a/daemon/meson.build b/daemon/meson.build index 52fad30f8..5a95e2598 100644 --- a/daemon/meson.build +++ b/daemon/meson.build @@ -10,7 +10,6 @@ kresd_src = files([ 'bindings/worker.c', 'engine.c', 'ffimodule.c', - 'http.c', 'io.c', 'main.c', 'network.c', @@ -18,11 +17,14 @@ kresd_src = files([ 'tls.c', 'tls_ephemeral_credentials.c', 'tls_session_ticket-srv.c', - 'http.c', 'udp_queue.c', 'worker.c', 'zimport.c', ]) +if nghttp2.found() + kresd_src += files(['http.c']) +endif + c_src_lint += kresd_src config_tests += [ diff --git a/daemon/session.c b/daemon/session.c index 978230483..41ae34358 100644 --- a/daemon/session.c +++ b/daemon/session.c @@ -36,7 +36,9 @@ struct session { struct tls_ctx *tls_ctx; /**< server side tls-related data. */ struct tls_client_ctx *tls_client_ctx; /**< client side tls-related data. */ +#ifdef ENABLE_DOH2 struct http_ctx *http_ctx; /**< server side http-related data. */ +#endif trie_t *tasks; /**< list of tasks assotiated with given session. */ queue_t(struct qr_task *) waiting; /**< list of tasks waiting for sending to upstream. */ @@ -87,7 +89,9 @@ void session_clear(struct session *session) queue_deinit(session->waiting); tls_free(session->tls_ctx); tls_client_ctx_free(session->tls_client_ctx); +#ifdef ENABLE_DOH2 http_free(session->http_ctx); +#endif memset(session, 0, sizeof(*session)); } @@ -291,6 +295,7 @@ struct tls_common_ctx *session_tls_get_common_ctx(const struct session *session) return tls_ctx; } +#ifdef ENABLE_DOH2 struct http_ctx *session_http_get_server_ctx(const struct session *session) { return session->http_ctx; @@ -300,6 +305,7 @@ void session_http_set_server_ctx(struct session *session, struct http_ctx *ctx) { session->http_ctx = ctx; } +#endif uv_handle_t *session_get_handle(struct session *session) { @@ -331,12 +337,14 @@ struct session *session_new(uv_handle_t *handle, bool has_tls, bool has_http) wire_buffer_size += TLS_CHUNK_SIZE; session->sflags.has_tls = true; } +#ifdef ENABLE_DOH2 if (has_http) { /* When decoding large packets, * HTTP/2 frames can be up to 16 KB by default. */ wire_buffer_size += HTTP_MAX_FRAME_SIZE; session->sflags.has_http = true; } +#endif uint8_t *wire_buf = malloc(wire_buffer_size); if (!wire_buf) { free(session); diff --git a/daemon/session.h b/daemon/session.h index 22a86e90f..3e651ebee 100644 --- a/daemon/session.h +++ b/daemon/session.h @@ -96,10 +96,12 @@ void session_tls_set_client_ctx(struct session *session, struct tls_client_ctx * * server and client. */ struct tls_common_ctx *session_tls_get_common_ctx(const struct session *session); +#ifdef ENABLE_DOH2 /** Get pointer to server-side http-related data. */ struct http_ctx *session_http_get_server_ctx(const struct session *session); /** Set pointer to server-side http-related data. */ void session_http_set_server_ctx(struct session *session, struct http_ctx *ctx); +#endif /** Get pointer to underlying libuv handle for IO operations. */ uv_handle_t *session_get_handle(struct session *session); diff --git a/daemon/worker.c b/daemon/worker.c index c1aa13d35..796e2cdb0 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -299,10 +299,12 @@ static struct request_ctx *request_create(struct worker_ctx *worker, req->qsource.flags.tls = session_flags(session)->has_tls; req->qsource.flags.http = session_flags(session)->has_http; req->qsource.stream_id = -1; +#ifdef ENABLE_DOH2 if (req->qsource.flags.http) { struct http_ctx *http_ctx = session_http_get_server_ctx(session); req->qsource.stream_id = queue_head(http_ctx->streams); } +#endif /* We need to store a copy of peer address. */ memcpy(&ctx->source.addr.ip, peer, kr_sockaddr_len(peer)); req->qsource.addr = &ctx->source.addr.ip; @@ -615,9 +617,13 @@ static int qr_task_send(struct qr_task *task, struct session *session, /* Send using given protocol */ assert(!session_flags(session)->closing); if (session_flags(session)->has_http) { +#ifdef ENABLE_DOH2 uv_write_t *write_req = (uv_write_t *)ioreq; write_req->data = task; ret = http_write(write_req, handle, pkt, ctx->req.qsource.stream_id, &on_write); +#else + ret = kr_error(ENOPROTOOPT); +#endif } else if (session_flags(session)->has_tls) { uv_write_t *write_req = (uv_write_t *)ioreq; write_req->data = task; @@ -1604,7 +1610,11 @@ int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt const bool is_query = (knot_wire_get_qr(pkt->wire) == 0); const bool is_outgoing = session_flags(session)->outgoing; - struct http_ctx *http_ctx = session_http_get_server_ctx(session); + + struct http_ctx *http_ctx = NULL; +#ifdef ENABLE_DOH2 + http_ctx = session_http_get_server_ctx(session); +#endif if (!is_outgoing && http_ctx && queue_len(http_ctx->streams) <= 0) return kr_error(ENOENT); diff --git a/meson.build b/meson.build index 58abd209d..1148e6a9c 100644 --- a/meson.build +++ b/meson.build @@ -29,7 +29,6 @@ if not lmdb.found() # darwin workaround: missing pkgconfig endif gnutls = dependency('gnutls') luajit = dependency('luajit') -nghttp2 = dependency('libnghttp2') # NOTE avoid using link_args for luajit due to a macOS issue # https://github.com/Homebrew/homebrew-core/issues/37169 luajit_inc = luajit.partial_dependency(compile_args: true, includes: true) @@ -88,6 +87,7 @@ group = get_option('group') ## Optional dependencies message('--- optional dependencies ---') +nghttp2 = dependency('libnghttp2', required: false) openssl = dependency('openssl', required: false) have_asprintf = meson.get_compiler('c').has_function('asprintf', @@ -171,6 +171,7 @@ conf_data.set('ENABLE_LIBSYSTEMD', libsystemd.found() ? 1 : 0) conf_data.set('NOVERBOSELOG', not verbose_log) conf_data.set('ENABLE_SENDMMSG', sendmmsg.to_int()) conf_data.set('ENABLE_CAP_NG', capng.found()) +conf_data.set('ENABLE_DOH2', nghttp2.found()) kresconfig = configure_file( output: 'kresconfig.h', @@ -286,6 +287,7 @@ s_install_kresd_conf = install_kresd_conf ? 'enabled' : 'disabled' s_sendmmsg = sendmmsg ? 'enabled': 'disabled' s_openssl = openssl.found() ? 'present': 'missing' s_capng = capng.found() ? 'enabled': 'disabled' +s_doh2 = nghttp2.found() ? 'enabled': 'disabled' message(''' ======================= SUMMARY ======================= @@ -322,6 +324,7 @@ message(''' sendmmsg: @0@'''.format(s_sendmmsg) + ''' openssl debug: @0@'''.format(s_openssl) + ''' capng: @0@'''.format(s_capng) + ''' + doh2: @0@'''.format(s_doh2) + ''' =======================================================