tests-fuzz: update knotd_wrap

This commit is contained in:
Daniel Salzman 2026-03-05 15:07:48 +01:00
parent 662ab50690
commit 479099ce9d

View file

@ -9,9 +9,8 @@
#include "knot/common/log.h"
typedef struct {
struct iovec iov[NBUFS];
uint8_t buf[NBUFS][KNOT_WIRE_MAX_PKTSIZE];
sockaddr_t addr;
network_dns_request_manager_t *req_mgr;
network_dns_request_t *req;
bool afl_persistent;
} udp_stdin_t;
@ -24,21 +23,26 @@ static inline void next(udp_stdin_t *rq)
}
}
static void *udp_stdin_init(_unused_ udp_context_t *ctx, _unused_ void *xdp_sock)
static void *udp_stdin_init(udp_context_t *ctx, _unused_ void *xdp_sock)
{
udp_stdin_t *rq = calloc(1, sizeof(*rq));
udp_stdin_t *rq = ctx->req_mgr->allocate_mem_func(ctx->req_mgr, sizeof(*rq));
if (rq == NULL) {
return NULL;
}
memset(rq, 0, sizeof(*rq));
rq->req_mgr = ctx->req_mgr;
for (unsigned i = 0; i < NBUFS; ++i) {
rq->iov[i].iov_base = rq->buf[i];
rq->iov[i].iov_len = sizeof(rq->buf[i]);
network_dns_request_t *req = ctx->req_mgr->allocate_network_request_func(ctx->req_mgr);
if (req == NULL) {
rq->req_mgr->free_mem_func(rq->req_mgr, rq);
return NULL;
}
rq->addr.ip4.sin_family = AF_INET;
rq->addr.ip4.sin_addr.s_addr = IN_LOOPBACKNET;
rq->addr.ip4.sin_port = 42;
if (sockaddr_set(&req->dns_req.req_data.source_addr, AF_INET, "127.0.0.0", 42) != KNOT_EOK) {
rq->req_mgr->free_network_request_func(rq->req_mgr, req);
rq->req_mgr->free_mem_func(rq->req_mgr, rq);
return NULL;
}
rq->afl_persistent = getenv("AFL_PERSISTENT") != NULL;
@ -47,27 +51,31 @@ static void *udp_stdin_init(_unused_ udp_context_t *ctx, _unused_ void *xdp_sock
static void udp_stdin_deinit(void *d)
{
free(d);
udp_stdin_t *rq = d;
rq->req_mgr->free_network_request_func(rq->req_mgr, rq->req);
rq->req_mgr->free_mem_func(rq->req_mgr, rq);
}
static int udp_stdin_recv(_unused_ int fd, void *d)
{
udp_stdin_t *rq = (udp_stdin_t *)d;
rq->iov[RX].iov_len = fread(rq->iov[RX].iov_base, 1,
sizeof(rq->buf[RX]), stdin);
if (rq->iov[RX].iov_len == 0) {
udp_stdin_t *rq = d;
rq->req->iov[RX].iov_len = fread(rq->req->iov[RX].iov_base, 1,
rq->req->iov[RX].iov_len, stdin);
if (rq->req->iov[RX].iov_len == 0) {
next(rq);
}
return rq->iov[RX].iov_len;
return rq->req->iov[RX].iov_len;
}
static void udp_stdin_handle(udp_context_t *ctx, _unused_ const iface_t *iface, void *d)
{
udp_stdin_t *rq = (udp_stdin_t *)d;
knotd_qdata_params_t params = params_init(KNOTD_QUERY_PROTO_UDP, &rq->addr,
&iface->addr, STDIN_FILENO, NULL, 0);
udp_handler(ctx, &params, &rq->iov[RX], &rq->iov[TX]);
udp_stdin_t *rq = d;
init_dns_request(&ctx->dns_handler, &rq->req->dns_req, STDIN_FILENO, KNOTD_QUERY_PROTO_UDP);
udp_handler(ctx, rq->req);
}
static void udp_stdin_send(void *d)