summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorOto Šťáva <oto.stava@nic.cz>2023-02-07 10:15:43 +0100
committerOto Šťáva <oto.stava@nic.cz>2023-02-07 10:15:43 +0100
commit9025d74812604a0ec3ea85856a81b94c5a0412f0 (patch)
tree780d83854c83192ca82be08d4e774a0939f16cc6 /daemon
parentMerge remote-tracking branch 'origin/master' into daemon-refactor-2 (diff)
downloadknot-resolver-9025d74812604a0ec3ea85856a81b94c5a0412f0.tar.xz
knot-resolver-9025d74812604a0ec3ea85856a81b94c5a0412f0.zip
daemon/session2: use enum for consuming/propagating events instead of bool
Diffstat (limited to 'daemon')
-rw-r--r--daemon/http.c13
-rw-r--r--daemon/io.c26
-rw-r--r--daemon/session2.h19
-rw-r--r--daemon/tls.c44
-rw-r--r--daemon/tls_ephemeral_credentials.c2
-rw-r--r--daemon/worker.c61
6 files changed, 84 insertions, 81 deletions
diff --git a/daemon/http.c b/daemon/http.c
index e88e908a..d297971f 100644
--- a/daemon/http.c
+++ b/daemon/http.c
@@ -996,19 +996,18 @@ static enum protolayer_iter_cb_result pl_http_wrap(
return protolayer_async();
}
-static bool pl_http_event_unwrap(enum protolayer_event_type event,
- void **baton,
- struct protolayer_manager *manager,
- void *sess_data)
+static enum protolayer_event_cb_result pl_http_event_unwrap(
+ enum protolayer_event_type event, void **baton,
+ struct protolayer_manager *manager, void *sess_data)
{
struct pl_http_sess_data *http = sess_data;
if (event == PROTOLAYER_EVENT_MALFORMED) {
http_send_status(http, HTTP_STATUS_BAD_REQUEST);
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
static void pl_http_request_init(struct protolayer_manager *manager,
@@ -1028,7 +1027,7 @@ static void pl_http_request_init(struct protolayer_manager *manager,
}
}
-void http_protolayers_init()
+void http_protolayers_init(void)
{
protolayer_globals[PROTOLAYER_HTTP] = (struct protolayer_globals) {
.sess_size = sizeof(struct pl_http_sess_data),
diff --git a/daemon/io.c b/daemon/io.c
index e6b8ca00..a7b05774 100644
--- a/daemon/io.c
+++ b/daemon/io.c
@@ -201,20 +201,19 @@ static enum protolayer_iter_cb_result pl_udp_unwrap(
return protolayer_continue(ctx);
}
-static bool pl_udp_event_wrap(enum protolayer_event_type event,
- void **baton,
- struct protolayer_manager *manager,
- void *sess_data)
+static enum protolayer_event_cb_result pl_udp_event_wrap(
+ enum protolayer_event_type event, void **baton,
+ struct protolayer_manager *manager, void *sess_data)
{
if (event == PROTOLAYER_EVENT_STATS_SEND_ERR) {
the_worker->stats.err_udp += 1;
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
} else if (event == PROTOLAYER_EVENT_STATS_QRY_OUT) {
the_worker->stats.udp += 1;
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
}
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
@@ -340,20 +339,19 @@ static enum protolayer_iter_cb_result pl_tcp_unwrap(
return protolayer_continue(ctx);
}
-static bool pl_tcp_event_wrap(enum protolayer_event_type event,
- void **baton,
- struct protolayer_manager *manager,
- void *sess_data)
+static enum protolayer_event_cb_result pl_tcp_event_wrap(
+ enum protolayer_event_type event, void **baton,
+ struct protolayer_manager *manager, void *sess_data)
{
if (event == PROTOLAYER_EVENT_STATS_SEND_ERR) {
the_worker->stats.err_tcp += 1;
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
} else if (event == PROTOLAYER_EVENT_STATS_QRY_OUT) {
the_worker->stats.tcp += 1;
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
}
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
void io_protolayers_init(void)
diff --git a/daemon/session2.h b/daemon/session2.h
index 27ffb86a..d3c94544 100644
--- a/daemon/session2.h
+++ b/daemon/session2.h
@@ -444,6 +444,13 @@ typedef enum protolayer_iter_cb_result (*protolayer_iter_cb)(
void *iter_data,
struct protolayer_iter_ctx *ctx);
+/** Return value of `protolayer_event_cb` callbacks. Controls the flow of
+ * events. See `protolayer_event_cb` for details. */
+enum protolayer_event_cb_result {
+ PROTOLAYER_EVENT_CONSUME = 0,
+ PROTOLAYER_EVENT_PROPAGATE = 1
+};
+
/** Function type for `struct protolayer_globals::event_wrap` and `struct
* protolayer_globals::event_unwrap` callbacks of layers. The `baton` parameter
* points to the mutable, iteration-specific baton pointer, initialized by the
@@ -451,12 +458,12 @@ typedef enum protolayer_iter_cb_result (*protolayer_iter_cb)(
* value of `baton` may be modified to accommodate for the next layer in the
* sequence.
*
- * When `true` is returned, iteration over the sequence of layers continues.
- * When `false` is returned, iteration stops. */
-typedef bool (*protolayer_event_cb)(enum protolayer_event_type event,
- void **baton,
- struct protolayer_manager *manager,
- void *sess_data);
+ * When `PROTOLAYER_EVENT_PROPAGATE` is returned, iteration over the sequence
+ * of layers continues. When `PROTOLAYER_EVENT_CONSUME` is returned, iteration
+ * stops. */
+typedef enum protolayer_event_cb_result (*protolayer_event_cb)(
+ enum protolayer_event_type event, void **baton,
+ struct protolayer_manager *manager, void *sess_data);
/** Function type for initialization callbacks of layer session data.
*
diff --git a/daemon/tls.c b/daemon/tls.c
index b1782c86..56bcad50 100644
--- a/daemon/tls.c
+++ b/daemon/tls.c
@@ -70,7 +70,7 @@ struct pl_tls_sess_data {
};
-struct tls_credentials * tls_get_ephemeral_credentials();
+struct tls_credentials * tls_get_ephemeral_credentials(void);
void tls_credentials_log_pins(struct tls_credentials *tls_credentials);
static int client_verify_certificate(gnutls_session_t tls_session);
static struct tls_credentials *tls_credentials_reserve(struct tls_credentials *tls_credentials);
@@ -623,7 +623,7 @@ void tls_client_params_free(tls_client_params_t *params)
trie_free(params);
}
-tls_client_param_t * tls_client_param_new()
+tls_client_param_t * tls_client_param_new(void)
{
tls_client_param_t *e = calloc(1, sizeof(*e));
if (kr_fails_assert(e))
@@ -1237,14 +1237,14 @@ static enum protolayer_iter_cb_result pl_tls_wrap(void *sess_data, void *iter_da
return protolayer_async();
}
-static bool pl_tls_client_connect_start(struct pl_tls_sess_data *tls,
- struct session2 *session)
+static enum protolayer_event_cb_result pl_tls_client_connect_start(
+ struct pl_tls_sess_data *tls, struct session2 *session)
{
if (tls->handshake_state != TLS_HS_NOT_STARTED)
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
if (kr_fails_assert(session->outgoing))
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
gnutls_session_set_ptr(tls->tls_session, tls);
gnutls_handshake_set_timeout(tls->tls_session, the_network->tcp.tls_handshake_timeout);
@@ -1267,28 +1267,27 @@ static bool pl_tls_client_connect_start(struct pl_tls_sess_data *tls,
PROTOLAYER_EVENT_GENERAL_TIMEOUT,
MAX_TCP_INACTIVITY, MAX_TCP_INACTIVITY);
}
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
}
}
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
}
-static bool pl_tls_event_unwrap(enum protolayer_event_type event,
- void **baton,
- struct protolayer_manager *manager,
- void *sess_data)
+static enum protolayer_event_cb_result pl_tls_event_unwrap(
+ enum protolayer_event_type event, void **baton,
+ struct protolayer_manager *manager, void *sess_data)
{
struct session2 *s = manager->session;
struct pl_tls_sess_data *tls = sess_data;
if (event == PROTOLAYER_EVENT_CLOSE) {
tls_close(tls, s, true); /* WITH gnutls_bye */
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
if (event == PROTOLAYER_EVENT_FORCE_CLOSE) {
tls_close(tls, s, false); /* WITHOUT gnutls_bye */
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
if (tls->client_side) {
@@ -1298,27 +1297,26 @@ static bool pl_tls_event_unwrap(enum protolayer_event_type event,
if (event == PROTOLAYER_EVENT_CONNECT) {
/* TLS sends its own _CONNECT event when the handshake
* is finished. */
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
}
}
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
-static bool pl_tls_event_wrap(enum protolayer_event_type event,
- void **baton,
- struct protolayer_manager *manager,
- void *sess_data)
+static enum protolayer_event_cb_result pl_tls_event_wrap(
+ enum protolayer_event_type event, void **baton,
+ struct protolayer_manager *manager, void *sess_data)
{
if (event == PROTOLAYER_EVENT_STATS_SEND_ERR) {
the_worker->stats.err_tls += 1;
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
} else if (event == PROTOLAYER_EVENT_STATS_QRY_OUT) {
the_worker->stats.tls += 1;
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
}
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
static void pl_tls_request_init(struct protolayer_manager *manager,
diff --git a/daemon/tls_ephemeral_credentials.c b/daemon/tls_ephemeral_credentials.c
index dc9cb23b..669580bd 100644
--- a/daemon/tls_ephemeral_credentials.c
+++ b/daemon/tls_ephemeral_credentials.c
@@ -51,7 +51,7 @@ static void _lock_unlock(lock_t *lock, const char *fname)
}
}
-static gnutls_x509_privkey_t get_ephemeral_privkey ()
+static gnutls_x509_privkey_t get_ephemeral_privkey (void)
{
gnutls_x509_privkey_t privkey = NULL;
int err;
diff --git a/daemon/worker.c b/daemon/worker.c
index eee174f5..65754fc0 100644
--- a/daemon/worker.c
+++ b/daemon/worker.c
@@ -1714,24 +1714,23 @@ static inline knot_pkt_t *produce_packet(char *buf, size_t buf_len)
return knot_pkt_new(buf, buf_len, &the_worker->pkt_pool);
}
-static bool pl_dns_dgram_event_unwrap(enum protolayer_event_type event,
- void **baton,
- struct protolayer_manager *manager,
- void *sess_data)
+static enum protolayer_event_cb_result pl_dns_dgram_event_unwrap(
+ enum protolayer_event_type event, void **baton,
+ struct protolayer_manager *manager, void *sess_data)
{
if (event != PROTOLAYER_EVENT_GENERAL_TIMEOUT)
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
struct session2 *session = manager->session;
if (session2_tasklist_get_len(session) != 1 ||
!session2_waitinglist_is_empty(session))
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
session2_timer_stop(session);
struct qr_task *task = session2_tasklist_get_first(session);
if (!task)
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
if (task->leading && task->pending_count > 0) {
struct kr_query *qry = array_tail(task->ctx->req.rplan.pending);
@@ -1742,7 +1741,7 @@ static bool pl_dns_dgram_event_unwrap(enum protolayer_event_type event,
the_worker->stats.timeout += 1;
qr_task_step(task, NULL, NULL);
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
static enum protolayer_iter_cb_result pl_dns_dgram_unwrap(
@@ -1836,10 +1835,11 @@ static int pl_dns_stream_iter_deinit(struct protolayer_manager *manager,
return kr_ok();
}
-static bool pl_dns_stream_resolution_timeout(struct session2 *s)
+static enum protolayer_event_cb_result pl_dns_stream_resolution_timeout(
+ struct session2 *s)
{
if (kr_fails_assert(!s->closing))
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
if (!session2_tasklist_is_empty(s)) {
int finalized = session2_tasklist_finalize_expired(s);
@@ -1848,7 +1848,7 @@ static bool pl_dns_stream_resolution_timeout(struct session2 *s)
* If session is a source session and there were IO errors,
* worker_task_finalize() can finalize all tasks and close session. */
if (s->closing)
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
if (!session2_tasklist_is_empty(s)) {
@@ -1866,7 +1866,7 @@ static bool pl_dns_stream_resolution_timeout(struct session2 *s)
worker_task_unref(t);
the_worker->stats.timeout += 1;
if (s->closing)
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
uint64_t idle_in_timeout = the_network->tcp.in_idle_timeout;
uint64_t idle_time = kr_now() - s->last_activity;
@@ -1888,13 +1888,14 @@ static bool pl_dns_stream_resolution_timeout(struct session2 *s)
}
}
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
-static bool pl_dns_stream_connected(struct session2 *session)
+static enum protolayer_event_cb_result pl_dns_stream_connected(
+ struct session2 *session)
{
if (session->connected)
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
session->connected = true;
@@ -1905,15 +1906,15 @@ static bool pl_dns_stream_connected(struct session2 *session)
session2_waitinglist_finalize(session, KR_STATE_FAIL);
kr_assert(session2_tasklist_is_empty(session));
session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
- return false;
+ return PROTOLAYER_EVENT_CONSUME;
}
worker_add_tcp_connected(peer, session);
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
-static bool pl_dns_stream_connection_fail(struct session2 *session,
- enum kr_selection_error sel_err)
+static enum protolayer_event_cb_result pl_dns_stream_connection_fail(
+ struct session2 *session, enum kr_selection_error sel_err)
{
session2_timer_stop(session);
@@ -1928,7 +1929,7 @@ static bool pl_dns_stream_connection_fail(struct session2 *session,
const char *peer_str = kr_straddr(peer);
VERBOSE_MSG(NULL, "=> connection to '%s' failed, empty waitinglist\n",
peer_str ? peer_str : "");
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
struct kr_query *qry = task_get_last_pending_query(task);
@@ -1955,13 +1956,14 @@ static bool pl_dns_stream_connection_fail(struct session2 *session,
* If no, most likely this is timed out connection even if
* it was successful. */
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
-static bool pl_dns_stream_disconnected(struct session2 *session)
+static enum protolayer_event_cb_result pl_dns_stream_disconnected(
+ struct session2 *session)
{
if (!session->connected)
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
struct sockaddr *peer = session2_get_peer(session);
worker_del_tcp_waiting(peer);
@@ -2007,17 +2009,16 @@ static bool pl_dns_stream_disconnected(struct session2 *session)
worker_task_unref(task);
}
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
-static bool pl_dns_stream_event_unwrap(enum protolayer_event_type event,
- void **baton,
- struct protolayer_manager *manager,
- void *sess_data)
+static enum protolayer_event_cb_result pl_dns_stream_event_unwrap(
+ enum protolayer_event_type event, void **baton,
+ struct protolayer_manager *manager, void *sess_data)
{
struct session2 *session = manager->session;
if (session->closing)
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
if (event == PROTOLAYER_EVENT_GENERAL_TIMEOUT) {
return pl_dns_stream_resolution_timeout(manager->session);
@@ -2037,7 +2038,7 @@ static bool pl_dns_stream_event_unwrap(enum protolayer_event_type event,
return pl_dns_stream_connection_fail(manager->session, err);
}
- return true;
+ return PROTOLAYER_EVENT_PROPAGATE;
}
static knot_pkt_t *produce_stream_packet(struct wire_buf *wb)