diff options
author | Daniel Salzman <daniel.salzman@nic.cz> | 2024-12-31 20:01:25 +0100 |
---|---|---|
committer | Daniel Salzman <daniel.salzman@nic.cz> | 2025-01-03 19:44:20 +0100 |
commit | 2391550cee00351ccffedc7a32dd46fd3f48e268 (patch) | |
tree | 988abfde7bbce14af70337908fd66f9a8cd82bc2 | |
parent | tls: call gnutls_bye() when closing a TLS connection (diff) | |
download | knot-2391550cee00351ccffedc7a32dd46fd3f48e268.tar.xz knot-2391550cee00351ccffedc7a32dd46fd3f48e268.zip |
xdp: refactor access checks to be uniform with the other checks
-rw-r--r-- | src/libknot/xdp/bpf-kernel.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/libknot/xdp/bpf-kernel.c b/src/libknot/xdp/bpf-kernel.c index 97192bc9f..95e7f0c9c 100644 --- a/src/libknot/xdp/bpf-kernel.c +++ b/src/libknot/xdp/bpf-kernel.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> +/* Copyright (C) 2025 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -89,7 +89,6 @@ int xdp_redirect_dns_func(struct xdp_md *ctx) const void *ip_hdr; const struct iphdr *ip4; const struct ipv6hdr *ip6; - const void *l4_hdr; __u8 ipv4; __u8 ip_proto; __u8 fragmented = 0; @@ -138,7 +137,7 @@ int xdp_redirect_dns_func(struct xdp_md *ctx) fragmented = 1; } ip_proto = ip4->protocol; - l4_hdr = data + ip4->ihl * 4; + data += ip4->ihl * 4; ipv4 = 1; break; case __constant_htons(ETH_P_IPV6): @@ -167,7 +166,6 @@ int xdp_redirect_dns_func(struct xdp_md *ctx) ip_proto = frag->nexthdr; data += sizeof(*frag); } - l4_hdr = data; ipv4 = 0; break; default: @@ -184,8 +182,8 @@ int xdp_redirect_dns_func(struct xdp_md *ctx) switch (ip_proto) { case IPPROTO_TCP: /* Parse TCP header. */ - tcp = l4_hdr; - if (l4_hdr + sizeof(*tcp) > data_end) { + tcp = data; + if ((void *)tcp + sizeof(*tcp) > data_end) { return XDP_DROP; } @@ -200,8 +198,8 @@ int xdp_redirect_dns_func(struct xdp_md *ctx) break; case IPPROTO_UDP: /* Parse UDP header. */ - udp = l4_hdr; - if (l4_hdr + sizeof(*udp) > data_end) { + udp = data; + if ((void *)udp + sizeof(*udp) > data_end) { return XDP_DROP; } |