summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--daemon/http.c5
-rw-r--r--daemon/http.h6
-rw-r--r--daemon/io.c4
-rw-r--r--daemon/io.h3
-rw-r--r--daemon/main.c11
-rw-r--r--daemon/proxyv2.c4
-rw-r--r--daemon/proxyv2.h3
-rw-r--r--daemon/tls.c3
-rw-r--r--daemon/tls.h3
-rw-r--r--daemon/worker.c15
10 files changed, 17 insertions, 40 deletions
diff --git a/daemon/http.c b/daemon/http.c
index 61ebcf9e..89b5e4c4 100644
--- a/daemon/http.c
+++ b/daemon/http.c
@@ -13,8 +13,6 @@
#include "daemon/session2.h"
#include "daemon/worker.h"
-#include "daemon/http.h"
-
/** Makes a `nghttp2_nv`. `K` is the key, `KS` is the key length,
* `V` is the value, `VS` is the value length. */
#define MAKE_NV(K, KS, V, VS) \
@@ -1030,7 +1028,8 @@ static void pl_http_request_init(struct session2 *session,
}
}
-void http_protolayers_init(void)
+__attribute__((constructor))
+static void http_protolayers_init(void)
{
protolayer_globals[PROTOLAYER_TYPE_HTTP] = (struct protolayer_globals) {
.sess_size = sizeof(struct pl_http_sess_data),
diff --git a/daemon/http.h b/daemon/http.h
deleted file mode 100644
index cf5eaaca..00000000
--- a/daemon/http.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/* Copyright (C) CZ.NIC, z.s.p.o. <knot-resolver@labs.nic.cz>
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-/** Initializes the protocol layers managed by http. */
-void http_protolayers_init(void);
diff --git a/daemon/io.c b/daemon/io.c
index b6b289ae..90c55e8c 100644
--- a/daemon/io.c
+++ b/daemon/io.c
@@ -19,7 +19,6 @@
#include "daemon/network.h"
#include "daemon/worker.h"
#include "daemon/tls.h"
-#include "daemon/http.h"
#include "daemon/session2.h"
#include "contrib/cleanup.h"
#include "lib/utils.h"
@@ -177,7 +176,8 @@ static enum protolayer_event_cb_result pl_tcp_event_wrap(
return PROTOLAYER_EVENT_PROPAGATE;
}
-void io_protolayers_init(void)
+__attribute__((constructor))
+static void io_protolayers_init(void)
{
protolayer_globals[PROTOLAYER_TYPE_UDP] = (struct protolayer_globals){
.event_wrap = pl_udp_event_wrap,
diff --git a/daemon/io.h b/daemon/io.h
index b03c6aae..268a8c9d 100644
--- a/daemon/io.h
+++ b/daemon/io.h
@@ -17,9 +17,6 @@ struct tls_ctx;
struct tls_client_ctx;
struct io_stream_data;
-/** Initializes the protocol layers managed by io. */
-void io_protolayers_init(void);
-
/** Bind address into a file-descriptor (only, no libuv). type is e.g. SOCK_DGRAM */
int io_bind(const struct sockaddr *addr, int type, const endpoint_flags_t *flags);
/** Initialize a UDP handle and start listening. */
diff --git a/daemon/main.c b/daemon/main.c
index 63cdd7f2..44b8ae4c 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -12,10 +12,6 @@
#include "daemon/udp_queue.h"
#include "daemon/worker.h"
-#ifdef ENABLE_DOH2
-#include "daemon/http.h"
-#endif
-
#include "lib/defines.h"
#include "lib/dnssec.h"
#include "lib/log.h"
@@ -584,13 +580,6 @@ int main(int argc, char **argv)
uv_strerror(ret));
}
- io_protolayers_init();
- tls_protolayers_init();
- proxy_protolayers_init();
-#ifdef ENABLE_DOH2
- http_protolayers_init();
-#endif
-
/* Start listening, in the sense of network_listen_fd(). */
if (start_listening(&the_args->fds) != 0) {
ret = EXIT_FAILURE;
diff --git a/daemon/proxyv2.c b/daemon/proxyv2.c
index d080d0c6..110d3415 100644
--- a/daemon/proxyv2.c
+++ b/daemon/proxyv2.c
@@ -450,8 +450,8 @@ static enum protolayer_iter_cb_result pl_proxyv2_stream_unwrap(
return protolayer_continue(ctx);
}
-
-void proxy_protolayers_init(void)
+__attribute__((constructor))
+static void proxy_protolayers_init(void)
{
protolayer_globals[PROTOLAYER_TYPE_PROXYV2_DGRAM] = (struct protolayer_globals){
.iter_size = sizeof(struct pl_proxyv2_dgram_iter_data),
diff --git a/daemon/proxyv2.h b/daemon/proxyv2.h
index 6a6bc179..d514cd62 100644
--- a/daemon/proxyv2.h
+++ b/daemon/proxyv2.h
@@ -30,6 +30,3 @@ struct proxy_result {
* the proxy is unencrypted. */
bool has_tls : 1;
};
-
-/** Initializes the protocol layers managed by the PROXYv2 "module". */
-void proxy_protolayers_init(void);
diff --git a/daemon/tls.c b/daemon/tls.c
index a5169ae3..daf6a7be 100644
--- a/daemon/tls.c
+++ b/daemon/tls.c
@@ -1332,7 +1332,8 @@ static void pl_tls_request_init(struct session2 *session,
req->qsource.comm_flags.tls = true;
}
-void tls_protolayers_init(void)
+__attribute__((constructor))
+static void tls_protolayers_init(void)
{
protolayer_globals[PROTOLAYER_TYPE_TLS] = (struct protolayer_globals){
.sess_size = sizeof(struct pl_tls_sess_data),
diff --git a/daemon/tls.h b/daemon/tls.h
index 9fd45fb6..ff1bbea2 100644
--- a/daemon/tls.h
+++ b/daemon/tls.h
@@ -103,9 +103,6 @@ int tls_credentials_release(struct tls_credentials *tls_credentials);
/*! Generate new ephemeral TLS credentials. */
struct tls_credentials * tls_get_ephemeral_credentials(void);
-/*! Initializes the protocol layers managed by tls. */
-void tls_protolayers_init(void);
-
/* Session tickets, server side. Implementation in ./tls_session_ticket-srv.c */
/*! Opaque struct used by tls_session_ticket_* functions. */
diff --git a/daemon/worker.c b/daemon/worker.c
index 562ebf07..2abaee07 100644
--- a/daemon/worker.c
+++ b/daemon/worker.c
@@ -2269,13 +2269,9 @@ static void pl_dns_stream_request_init(struct session2 *session,
req->qsource.comm_flags.tcp = true;
}
-int worker_init(void)
+__attribute__((constructor))
+static void worker_protolayers_init(void)
{
- if (kr_fails_assert(the_worker == NULL))
- return kr_error(EINVAL);
- kr_bindings_register(the_engine->L); // TODO move
-
- /* DNS protocol layers */
protolayer_globals[PROTOLAYER_TYPE_DNS_DGRAM] = (struct protolayer_globals){
.wire_buf_overhead_cb = pl_dns_dgram_wire_buf_overhead,
.wire_buf_max_overhead = KNOT_WIRE_MAX_PKTSIZE,
@@ -2303,6 +2299,13 @@ int worker_init(void)
protolayer_globals[PROTOLAYER_TYPE_DNS_MULTI_STREAM].sess_init = pl_dns_stream_sess_init;
protolayer_globals[PROTOLAYER_TYPE_DNS_SINGLE_STREAM] = stream_common;
protolayer_globals[PROTOLAYER_TYPE_DNS_SINGLE_STREAM].sess_init = pl_dns_single_stream_sess_init;
+}
+
+int worker_init(void)
+{
+ if (kr_fails_assert(the_worker == NULL))
+ return kr_error(EINVAL);
+ kr_bindings_register(the_engine->L); // TODO move
/* Create main worker. */
the_worker = &the_worker_value;