#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,
* 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
#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) {
* 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,
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++)
PROTOLAYER_EVENT_COUNT
};
+/** Maps event IDs to names. */
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,
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
* 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 {
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
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);
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);
}
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);
}
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)
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,
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;
/** 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.
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);