No description
Find a file
2024-07-02 12:01:37 +08:00
docs/images Update diagram 2024-07-02 12:01:37 +08:00
.gitignore Add necessary docs 2024-06-29 21:17:32 +08:00
ebpf_dns.c ignore udp checksum. 2024-06-29 20:31:17 +08:00
ebpf_dns.h read transacton id from cache data 2024-06-28 15:11:37 +08:00
gen.go Bring in ebpf-go 2024-06-18 12:50:51 +08:00
go.mod docs: go get install dependency 2024-07-01 15:15:12 +08:00
go.sum check cache expire time and packet size 2024-06-28 11:54:08 +08:00
handler.go Only set cache for A AAAA and CNAME query 2024-06-29 12:21:20 +08:00
main.go user space program work fine 2024-06-26 20:20:29 +08:00
Makefile ignore udp checksum. 2024-06-29 20:31:17 +08:00
README.md docs: go get install dependency 2024-07-01 15:15:12 +08:00

ebpf-dns

eBPF backend DNS cache server ebpf-dns

Dependencies

  • Linux kernel version 5.7 or later
  • Go 1.22.4
  • ebpf-go v0.15.0

Compile

First, install the Go dependency package in the current directory.

go get

Compile all

make all

Compile eBPF byte code and build go user space program, generate ebpf_dns.o and ebpf_dns executable file.

Compile eBPF bytecode

make

Compile eBPF byte code, support make debug, output more detaild ebpf logs.

Compile go program

make go

You can also run go build to directly generate a binary executable file in the current directory.

Run

sudo ./ebpf_dns

Running ./ebpf_dns, the program mainly does two things:

  1. Runs a user-space program. The user-space program listens on the local machine's port 53, receiving DNS requests from clients. It then forwards these requests to upstream recursive servers to obtain DNS response content. While returning the DNS response to the client, it simultaneously caches the results for A, AAAA, and CNAME requests in the eBPF MAP.
  2. Loads the XDP program into the kernel. The kernel program monitors DNS traffic. If it's an A, AAAA, or CNAME type request, it queries the eBPF MAP to check for cached records. If a cached record exists, it directly uses the cached result to construct a response packet and sends it back to the client using XDP_TX. This entire response process is completed within the kernel, without reaching the upstream user-space program, achieving high-performance queries. If there's no cached record in the eBPF MAP, it returns XDP_PASS, handing the request over to the upstream user-space program for processing.

Debug

User space program will output log to stdout directly. The logs of the kernel eBPF program can be viewed using the following command:

sudo cat /sys/kernel/debug/tracing/trace_pipe