Worker API reference


int worker_init(struct engine *engine, int worker_id, int worker_count)

Create and initialize the worker.


error code (ENOMEM)

void worker_deinit(void)

Destroy the worker (free memory).

int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt_t *query)

Process an incoming packet (query from a client or answer from upstream).


0 or an error code

  • session: session the packet came from

  • peer: address the packet came from

  • query: the packet, or NULL on an error from the transport layer

int worker_end_tcp(struct session *session)

End current DNS/TCP session, this disassociates pending tasks from this session which may be freely closed afterwards.

knot_pkt_t *worker_resolve_mk_pkt(const char *qname_str, uint16_t qtype, uint16_t qclass, const struct kr_qflags *options)

Create a packet suitable for worker_resolve_start().

All in malloc() memory.

struct qr_task *worker_resolve_start(knot_pkt_t *query, struct kr_qflags options)

Start query resolution with given query.


task or NULL

int worker_resolve_exec(struct qr_task *task, knot_pkt_t *query)
struct kr_request *worker_task_request(struct qr_task *task)


struct kr_request associated with opaque task

int worker_task_step(struct qr_task *task, const struct sockaddr *packet_source, knot_pkt_t *packet)
int worker_task_numrefs(const struct qr_task *task)
int worker_task_finalize(struct qr_task *task, int state)

Finalize given task.

void worker_task_complete(struct qr_task *task)
void worker_task_ref(struct qr_task *task)
void worker_task_unref(struct qr_task *task)
void worker_task_timeout_inc(struct qr_task *task)
int worker_add_tcp_connected(struct worker_ctx *worker, const struct sockaddr *addr, struct session *session)
int worker_del_tcp_connected(struct worker_ctx *worker, const struct sockaddr *addr)
int worker_del_tcp_waiting(struct worker_ctx *worker, 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)
struct session *worker_request_get_source_session(struct request_ctx*)
void worker_request_set_source_session(struct request_ctx*, struct session *session)
uint16_t worker_task_pkt_get_msgid(struct qr_task *task)
void worker_task_pkt_set_msgid(struct qr_task *task, uint16_t msgid)
uint64_t worker_task_creation_time(struct qr_task *task)
void worker_task_subreq_finalize(struct qr_task *task)
bool worker_task_finished(struct qr_task *task)
int qr_task_on_send(struct qr_task *task, uv_handle_t *handle, int status)

To be called after sending a DNS message.

It mainly deals with cleanups.


struct worker_ctx *the_worker

Pointer to the singleton worker.

NULL if not initialized.

struct worker_stats
#include <worker.h>

Various worker statistics.

Sync with wrk_stats()

Public Members

size_t queries

Total number of requests (from clients and internal ones).

size_t concurrent

The number of requests currently in processing.

size_t rconcurrent
size_t dropped

The number of requests dropped due to being badly formed.

See #471.

size_t timeout

Number of outbound queries that timed out.

size_t udp

Number of outbound queries over UDP.

size_t tcp

Number of outbound queries over TCP (excluding TLS).

size_t tls

Number of outbound queries over TLS.

size_t ipv4

Number of outbound queries over IPv4.

size_t ipv6

Number of outbound queries over IPv6.