#include <linux/in.h> #include <linux/udp.h> // DNS resolverをポート54で動かす int dnsredirect (struct xdp_md *ctx) { void *data = (void *)(long)ctx->data; void *data_end = (void *)(long)ctx->data_end; struct ethhdr *eth = data; if ((void*)eth + sizeof(*eth) > data_end) { return XDP_PASS; } struct iphdr *ip = data + sizeof(*eth); if ((void*)ip + sizeof(*ip) > data_end) { return XDP_PASS; } if (ip->protocol == IPPROTO_UDP) { struct udphdr *udp = (void*)ip + sizeof(*ip); if ((void*)udp + sizeof(*udp) <= data_end) { if (udp->dest == ntohs(53)) { udp->dest = ntohs(54); } else if (udp->source == ntohs(54)) { udp->source = ntohs(53); } } } return XDP_PASS; } eBPF バイトコード 生成 verifier (検証) BPF XDP Kernel Land User Land 名前解決をport 54で行う