From 0a599d63e02859bfba4a64e1bfb7f43606fd3bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= <vladimir.cunat@nic.cz> Date: Wed, 23 Mar 2022 12:36:12 +0100 Subject: [PATCH] xdp: make it work also with libknot 3.1 Somehow I did this wrong when porting to libknot 3.1. --- NEWS | 1 + daemon/worker.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/NEWS b/NEWS index 3957e9191..4c42d5940 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Knot Resolver 5.5.1 (2022-mm-dd) Bugfixes -------- - modules/dns64: fix incorrect packet writes for cached packets (#727, !1275) +- xdp: make it work also with libknot 3.1 (#735, !1276) Knot Resolver 5.5.0 (2022-03-15) diff --git a/daemon/worker.c b/daemon/worker.c index 167737e31..7397ca174 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -293,9 +293,11 @@ static uint8_t *alloc_wire_cb(struct kr_request *req, uint16_t *maxlen) return NULL; } *maxlen = MIN(*maxlen, out.payload.iov_len); +#if KNOT_VERSION_HEX < 0x030100 /* It's most convenient to fill the MAC addresses at this point. */ memcpy(out.eth_from, &ctx->source.eth_addrs[0], 6); memcpy(out.eth_to, &ctx->source.eth_addrs[1], 6); +#endif return out.payload.iov_base; } static void free_wire(const struct request_ctx *ctx) @@ -1325,6 +1327,15 @@ static int xdp_push(struct qr_task *task, const uv_handle_t *src_handle) return qr_task_on_send(task, src_handle, kr_error(EINVAL)); knot_xdp_msg_t msg; +#if KNOT_VERSION_HEX >= 0x030100 + /* We don't have a nice way of preserving the _msg_t from frame allocation, + * so we manually redo all other parts of knot_xdp_send_alloc() */ + memset(&msg, 0, sizeof(msg)); + bool ipv6 = ctx->source.addr.ip.sa_family == AF_INET6; + msg.flags = ipv6 ? KNOT_XDP_MSG_IPV6 : 0; + memcpy(msg.eth_from, &ctx->source.eth_addrs[0], 6); + memcpy(msg.eth_to, &ctx->source.eth_addrs[1], 6); +#endif const struct sockaddr *ip_from = &ctx->source.dst_addr.ip; const struct sockaddr *ip_to = &ctx->source.comm_addr.ip; memcpy(&msg.ip_from, ip_from, kr_sockaddr_len(ip_from)); -- GitLab