]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: nits
authorOto Šťáva <oto.stava@nic.cz>
Thu, 6 Oct 2022 07:15:35 +0000 (09:15 +0200)
committerOto Šťáva <oto.stava@nic.cz>
Thu, 26 Jan 2023 11:56:08 +0000 (12:56 +0100)
daemon/session2.c
daemon/session2.h
daemon/worker.c
daemon/worker.h

index e584373f5920956ede66116015feb3fe32934486..9328aded92246b86c5d21bf5baa1c7e4ae56cc33 100644 (file)
 #include "daemon/session2.h"
 
 
-static int session2_transport_pushv(struct session2 *s,
-                                    struct iovec *iov, int iovcnt,
-                                    const void *target,
-                                    protolayer_finished_cb cb, void *baton);
-static inline int session2_transport_push(struct session2 *s,
-                                          char *buf, size_t buf_len,
-                                          const void *target,
-                                          protolayer_finished_cb cb, void *baton);
-static int session2_transport_event(struct session2 *s,
-                                    enum protolayer_event_type event,
-                                    void *baton);
-
 struct protolayer_globals protolayer_globals[PROTOLAYER_PROTOCOL_COUNT] = {{0}};
 
-
-static enum protolayer_protocol protolayer_grp_doudp[] = {
+static const enum protolayer_protocol protolayer_grp_doudp[] = {
        PROTOLAYER_UDP,
        PROTOLAYER_DNS_DGRAM,
        PROTOLAYER_NULL
 };
 
-static enum protolayer_protocol protolayer_grp_dotcp[] = {
+static const enum protolayer_protocol protolayer_grp_dotcp[] = {
        PROTOLAYER_TCP,
        PROTOLAYER_DNS_MULTI_STREAM,
        PROTOLAYER_NULL
 };
 
-static enum protolayer_protocol protolayer_grp_dot[] = {
+static const enum protolayer_protocol protolayer_grp_dot[] = {
        PROTOLAYER_TCP,
        PROTOLAYER_TLS,
        PROTOLAYER_DNS_MULTI_STREAM,
        PROTOLAYER_NULL
 };
 
-static enum protolayer_protocol protolayer_grp_doh[] = {
+static const enum protolayer_protocol protolayer_grp_doh[] = {
        PROTOLAYER_TCP,
        PROTOLAYER_TLS,
        PROTOLAYER_HTTP,
@@ -72,7 +59,7 @@ const char *protolayer_protocol_names[PROTOLAYER_PROTOCOL_COUNT] = {
  * the end of the list of protocol layers. The array name's suffix must be the
  * one defined as *Variable name* (2nd parameter) in the `PROTOLAYER_GRP_MAP`
  * macro. */
-static enum protolayer_protocol *protolayer_grps[PROTOLAYER_GRP_COUNT] = {
+static const enum protolayer_protocol *protolayer_grps[PROTOLAYER_GRP_COUNT] = {
 #define XX(cid, vid, name) [PROTOLAYER_GRP_##cid] = protolayer_grp_##vid,
        PROTOLAYER_GRP_MAP(XX)
 #undef XX
@@ -102,6 +89,21 @@ const char *protolayer_payload_names[PROTOLAYER_PAYLOAD_COUNT] = {
 #undef XX
 };
 
+
+/* Forward decls. */
+static int session2_transport_pushv(struct session2 *s,
+                                    struct iovec *iov, int iovcnt,
+                                    const void *target,
+                                    protolayer_finished_cb cb, void *baton);
+static inline int session2_transport_push(struct session2 *s,
+                                          char *buf, size_t buf_len,
+                                          const void *target,
+                                          protolayer_finished_cb cb, void *baton);
+static int session2_transport_event(struct session2 *s,
+                                    enum protolayer_event_type event,
+                                    void *baton);
+
+
 size_t protolayer_payload_size(const struct protolayer_payload *payload)
 {
        if (payload->type == PROTOLAYER_PAYLOAD_BUFFER) {
@@ -419,9 +421,9 @@ static int protolayer_step(struct protolayer_iter_ctx *ctx)
  * specified protolayer manager. The sequence will be processed in the
  * specified direction.
  *
- * Returns 0 when all layers have finished, 1 when some layers are asynchronous
- * and waiting for continuation, 2 when a layer is waiting for more data,
- * or a negative number for errors (kr_error). */
+ * Returns PROTOLAYER_RET_NORMAL when all layers have finished,
+ * PROTOLAYER_RET_ASYNC when some layers are asynchronous and waiting for
+ * continuation, or a negative number for errors (kr_error). */
 static int protolayer_manager_submit(
                struct protolayer_manager *manager,
                enum protolayer_direction direction, size_t layer_ix,
@@ -496,10 +498,10 @@ static struct protolayer_manager *protolayer_manager_new(
        size_t manager_size = sizeof(struct protolayer_manager);
        size_t cb_ctx_size = sizeof(struct protolayer_iter_ctx);
 
-       enum protolayer_protocol *protocols = protolayer_grps[grp];
+       const enum protolayer_protocol *protocols = protolayer_grps[grp];
        if (kr_fails_assert(protocols))
                return NULL;
-       enum protolayer_protocol *p = protocols;
+       const enum protolayer_protocol *p = protocols;
 
        /* Space for offset index */
        for (; *p; p++)
index f381774134a416a00e68500b0254c90d8ba0ba14..604a295035c09559cda9f19bfc2cebd88d214d51 100644 (file)
@@ -219,6 +219,7 @@ enum protolayer_event_type {
        PROTOLAYER_EVENT_COUNT
 };
 
+/** Maps event IDs to names. */
 extern const char *protolayer_event_names[];
 
 
@@ -232,8 +233,8 @@ extern const char *protolayer_event_names[];
        XX(IOVEC, "IOVec") \
        XX(WIRE_BUF, "Wire buffer")
 
-/** Defines whether the data for a `struct protolayer_cb_ctx` is represented
- * by a single buffer, an array of `struct iovec`, or an `enum protolayer_event`. */
+/** Determines which union member of `struct protolayer_payload` is currently
+ * valid. */
 enum protolayer_payload_type {
        PROTOLAYER_PAYLOAD_NULL = 0,
 #define XX(cid, name) PROTOLAYER_PAYLOAD_##cid,
@@ -242,6 +243,7 @@ enum protolayer_payload_type {
        PROTOLAYER_PAYLOAD_COUNT
 };
 
+/** Maps payload type IDs to human-readable names. */
 extern const char *protolayer_payload_names[];
 
 /** Data processed by the sequence of layers. All pointed-to memory is always
@@ -250,7 +252,7 @@ extern const char *protolayer_payload_names[];
  * is ever (de-)allocated by the protolayer manager! */
 struct protolayer_payload {
        enum protolayer_payload_type type;
-       unsigned int ttl; /**< time-to-live hint (for e.g. HTTP Cache-Control) */
+       unsigned int ttl; /**< time-to-live hint (e.g. for HTTP Cache-Control) */
        union {
                /** Only valid if `type` is `_BUFFER`. */
                struct {
@@ -583,10 +585,12 @@ struct wire_buf {
        size_t end; /**< Index at which the valid data of the buffer ends (exclusive). */
 };
 
-/** Allocates the wire buffer with the specified `initial_size`. */
+/** Initializes the wire buffer with the specified `initial_size` and allocates
+ * the underlying memory. */
 int wire_buf_init(struct wire_buf *wb, size_t initial_size);
 
-/** De-allocates the wire buffer. */
+/** De-allocates the wire buffer's underlying memory (the struct itself is left
+ * intact). */
 void wire_buf_deinit(struct wire_buf *wb);
 
 /** Ensures that the wire buffer's size is at least `size`. `*wb` must be
index f7c0603cae43d642b9c0fabb33e3564361bf96a1..fc62d825f1d1e945f85803180bf1c75e9d2967d1 100644 (file)
@@ -104,7 +104,14 @@ static int qr_task_send(struct qr_task *task, struct session2 *session,
                        const struct sockaddr *addr, knot_pkt_t *pkt);
 static int qr_task_finalize(struct qr_task *task, int state);
 static void qr_task_complete(struct qr_task *task);
-static int worker_add_tcp_waiting(const struct sockaddr* addr, struct session2 *session);
+static int worker_add_tcp_connected(const struct sockaddr* addr, struct session2 *session);
+static int worker_del_tcp_connected(const struct sockaddr* addr);
+static struct session2* worker_find_tcp_connected(const struct sockaddr* addr);
+static int worker_add_tcp_waiting(const struct sockaddr* addr,
+                                 struct session2 *session);
+static int worker_del_tcp_waiting(const struct sockaddr* addr);
+static struct session2* worker_find_tcp_waiting(const struct sockaddr* addr);
+
 static void subreq_finalize(struct qr_task *task, const struct sockaddr *packet_source, knot_pkt_t *pkt);
 
 
@@ -1471,17 +1478,17 @@ static struct session2 *trie_find_tcp_session(trie_t *trie,
        return val ? *val : NULL;
 }
 
-int worker_add_tcp_connected(const struct sockaddr* addr, struct session2 *session)
+static int worker_add_tcp_connected(const struct sockaddr* addr, struct session2 *session)
 {
        return trie_add_tcp_session(the_worker->tcp_connected, addr, session);
 }
 
-int worker_del_tcp_connected(const struct sockaddr* addr)
+static int worker_del_tcp_connected(const struct sockaddr* addr)
 {
        return trie_del_tcp_session(the_worker->tcp_connected, addr);
 }
 
-struct session2* worker_find_tcp_connected(const struct sockaddr* addr)
+static struct session2* worker_find_tcp_connected(const struct sockaddr* addr)
 {
        return trie_find_tcp_session(the_worker->tcp_connected, addr);
 }
@@ -1492,12 +1499,12 @@ static int worker_add_tcp_waiting(const struct sockaddr* addr,
        return trie_add_tcp_session(the_worker->tcp_waiting, addr, session);
 }
 
-int worker_del_tcp_waiting(const struct sockaddr* addr)
+static int worker_del_tcp_waiting(const struct sockaddr* addr)
 {
        return trie_del_tcp_session(the_worker->tcp_waiting, addr);
 }
 
-struct session2* worker_find_tcp_waiting(const struct sockaddr* addr)
+static struct session2* worker_find_tcp_waiting(const struct sockaddr* addr)
 {
        return trie_find_tcp_session(the_worker->tcp_waiting, addr);
 }
@@ -1621,15 +1628,10 @@ int worker_task_finalize(struct qr_task *task, int state)
        return qr_task_finalize(task, state);
 }
 
- int worker_task_step(struct qr_task *task, const struct sockaddr *packet_source,
-                     knot_pkt_t *packet)
- {
-        return qr_task_step(task, packet_source, packet);
- }
-
-void worker_task_complete(struct qr_task *task)
+int worker_task_step(struct qr_task *task, const struct sockaddr *packet_source,
+                     knot_pkt_t *packet)
 {
-       qr_task_complete(task);
+        return qr_task_step(task, packet_source, packet);
 }
 
 void worker_task_ref(struct qr_task *task)
@@ -1652,11 +1654,6 @@ knot_pkt_t *worker_task_get_pktbuf(const struct qr_task *task)
        return task->pktbuf;
 }
 
-struct request_ctx *worker_task_get_request(struct qr_task *task)
-{
-       return task->ctx;
-}
-
 struct session2 *worker_request_get_source_session(const struct kr_request *req)
 {
        static_assert(offsetof(struct request_ctx, req) == 0,
index 233aa290d1b95e4f1a3c04a771089485e8c6b855..1cfb0f42ad2f77a7da5e7e59b4383712081268f3 100644 (file)
@@ -15,8 +15,6 @@ struct qr_task;
 struct worker_ctx;
 /** Transport session (opaque). */
 struct session2;
-/** Zone import context (opaque). */
-struct zone_import_ctx;
 /** Data about the communication (defined in io.h). */
 struct comm_info;
 
@@ -30,18 +28,6 @@ int worker_init();
 /** Destroy the worker (free memory). */
 void worker_deinit();
 
-/**
- * Process an incoming packet (query from a client or answer from upstream).
- *
- * @param session     session the packet came from, or NULL (not from network)
- * @param comm        IO communication data (see `struct io_comm_data` docs)
- * @param eth_*       MAC addresses or NULL (they're useful for XDP)
- * @param pkt         the packet, or NULL (an error from the transport layer)
- * @return 0 or an error code
- */
-int worker_submit(struct session2 *session, struct comm_info *comm,
-                  const uint8_t *eth_from, const uint8_t *eth_to, knot_pkt_t *pkt);
-
 /**
  * End current DNS/TCP session, this disassociates pending tasks from this session
  * which may be freely closed afterwards.
@@ -93,15 +79,8 @@ void worker_task_unref(struct qr_task *task);
 
 void worker_task_timeout_inc(struct qr_task *task);
 
-int worker_add_tcp_connected(const struct sockaddr *addr, struct session2 *session);
-int worker_del_tcp_connected(const struct sockaddr *addr);
-int worker_del_tcp_waiting(const struct sockaddr* addr);
-struct session2* worker_find_tcp_waiting(const struct sockaddr* addr);
-struct session2* worker_find_tcp_connected(const struct sockaddr* addr);
 knot_pkt_t *worker_task_get_pktbuf(const struct qr_task *task);
 
-struct request_ctx *worker_task_get_request(struct qr_task *task);
-
 /** Note: source session is NULL in case the request hasn't come over network. */
 KR_EXPORT struct session2 *worker_request_get_source_session(const struct kr_request *req);