* SPDX-License-Identifier: GPL-3.0-or-later
*/
-#include <nghttp2/nghttp2.h>
-#include <uv.h>
-
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#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). */
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
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) {
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. */
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);
}
return sent;
}
+#endif
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) {
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);
}
_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");
'bindings/worker.c',
'engine.c',
'ffimodule.c',
- 'http.c',
'io.c',
'main.c',
'network.c',
'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 += [
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. */
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));
}
return tls_ctx;
}
+#ifdef ENABLE_DOH2
struct http_ctx *session_http_get_server_ctx(const struct session *session)
{
return session->http_ctx;
{
session->http_ctx = ctx;
}
+#endif
uv_handle_t *session_get_handle(struct session *session)
{
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);
* 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);
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;
/* 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;
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);
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)
## Optional dependencies
message('--- optional dependencies ---')
+nghttp2 = dependency('libnghttp2', required: false)
openssl = dependency('openssl', required: false)
have_asprintf = meson.get_compiler('c').has_function('asprintf',
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',
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 =======================
sendmmsg: @0@'''.format(s_sendmmsg) + '''
openssl debug: @0@'''.format(s_openssl) + '''
capng: @0@'''.format(s_capng) + '''
+ doh2: @0@'''.format(s_doh2) + '''
=======================================================