]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: make nghttp2 optional
authorTomas Krizek <tomas.krizek@nic.cz>
Wed, 30 Sep 2020 12:10:23 +0000 (14:10 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 13 Oct 2020 10:55:29 +0000 (12:55 +0200)
daemon/http.c
daemon/http.h
daemon/io.c
daemon/meson.build
daemon/session.c
daemon/session.h
daemon/worker.c
meson.build

index 1c8f0f937af2f0826d1ab0146c71ba8317ffa289..66fc885f40f63b783bd9b0f88aef57265d8ce32e 100644 (file)
@@ -6,9 +6,6 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
-#include <nghttp2/nghttp2.h>
-#include <uv.h>
-
 #include <assert.h>
 #include <errno.h>
 #include <stdio.h>
index 07bda4a303dc7919cc249592f51dba135a6343a9..d2c440c4c6949eb5be033da5047d0063a8852f6f 100644 (file)
@@ -9,9 +9,12 @@
 #pragma once
 
 #include <uv.h>
-#include <nghttp2/nghttp2.h>
 #include <libknot/packet/pkt.h>
 
+#ifdef ENABLE_DOH2
+#include <nghttp2/nghttp2.h>
+#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
index fff465ba2495fc2269d7c90e1347f78db150219e..f64ead4f8d5206b44bf190cd22f5970adaac8f03 100644 (file)
@@ -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");
index 52fad30f88d9ce29d105746a69d959995af29848..5a95e2598ba692a50bccc34463f5181ef161efb1 100644 (file)
@@ -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 += [
index 978230483d1a57517f49e3399c2d373064e0c143..41ae34358a692511601281aea029e3d77a7a196d 100644 (file)
@@ -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);
index 22a86e90feb3e9863079dc46fbdda9ba99e469b1..3e651ebeee25878a9daa10be65ab0126e7017078 100644 (file)
@@ -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);
index c1aa13d35b0818cdf85c7ed7465c16d180276fcc..796e2cdb0fe21ef6fe26a02acfe54a137d61bcb9 100644 (file)
@@ -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);
index 58abd209d2ecd187e4b0f59ca579c63ecd81cd80..1148e6a9cb00e43df52b2e21d64c33b392755d63 100644 (file)
@@ -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) + '''
 
 =======================================================