[PR #1083] [MERGED] DNS forwarder and common ebpf loader #13295

Closed
opened 2026-08-05 02:08:02 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/1083
Author: @pappz
Created: 8/15/2023
Status: Merged
Merged: 9/5/2023
Merged by: @mlsmaycon

Base: mainHead: common-ebpf-loader


📝 Commits (10+)

📊 Changes

23 files changed (+554 additions, -214 deletions)

View changed files

📝 client/internal/dns/server.go (+1 -1)
📝 client/internal/dns/service_listener.go (+56 -8)
📝 client/internal/ebpf/ebpf/bpf_bpfeb.go (+12 -3)
client/internal/ebpf/ebpf/bpf_bpfeb.o (+0 -0)
📝 client/internal/ebpf/ebpf/bpf_bpfel.go (+12 -3)
client/internal/ebpf/ebpf/bpf_bpfel.o (+0 -0)
client/internal/ebpf/ebpf/dns_fwd_linux.go (+51 -0)
client/internal/ebpf/ebpf/manager_linux.go (+116 -0)
client/internal/ebpf/ebpf/manager_linux_test.go (+40 -0)
client/internal/ebpf/ebpf/src/dns_fwd.c (+64 -0)
client/internal/ebpf/ebpf/src/prog.c (+66 -0)
client/internal/ebpf/ebpf/src/wg_proxy.c (+54 -0)
client/internal/ebpf/ebpf/wg_proxy_linux.go (+41 -0)
client/internal/ebpf/instantiater_linux.go (+15 -0)
client/internal/ebpf/instantiater_nonlinux.go (+10 -0)
client/internal/ebpf/manager/manager.go (+9 -0)
client/internal/wgproxy/ebpf/bpf_bpfeb.o (+0 -0)
client/internal/wgproxy/ebpf/bpf_bpfel.o (+0 -0)
client/internal/wgproxy/ebpf/loader.go (+0 -84)
client/internal/wgproxy/ebpf/loader_test.go (+0 -18)

...and 3 more files

📄 Description

Describe your changes

This PR contains multiple modifications.

In case the 53 UDP port is not option to bind then we hijack the DNS traffic with eBPF and we forward the traffic to the listener on a custom port. With this implementation we should be able to listen DNS queries on any address and still set the local host system to send queries to the custom address on port 53.

Because we tried to attach multiple xdp program to the same interface I did a refactor in the WG traffic forward code also.

NB-282

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/1083 **Author:** [@pappz](https://github.com/pappz) **Created:** 8/15/2023 **Status:** ✅ Merged **Merged:** 9/5/2023 **Merged by:** [@mlsmaycon](https://github.com/mlsmaycon) **Base:** `main` ← **Head:** `common-ebpf-loader` --- ### 📝 Commits (10+) - [`f185107`](https://github.com/netbirdio/netbird/commit/f18510726850c78711d7b41397a82f700dbf0dac) Add forwarder logic - [`32b7ced`](https://github.com/netbirdio/netbird/commit/32b7ced0f8fb79cc2afb0d80ac4802668b534d82) Fix build without import C - [`23a6d7e`](https://github.com/netbirdio/netbird/commit/23a6d7e5a9e8694db194d84b812bad4228934797) Fix map reading - [`666ecc5`](https://github.com/netbirdio/netbird/commit/666ecc580f55e7f6230a157cfc914b38832ca701) Add singleton eBPF loader - [`4b73828`](https://github.com/netbirdio/netbird/commit/4b73828c6dacecc2dca8e11e609c1253963a5f2c) Fix order of ports - [`5288506`](https://github.com/netbirdio/netbird/commit/5288506c90909d140673a0ac427c847af12ffd57) Fix runtime/listen port logic - [`9628839`](https://github.com/netbirdio/netbird/commit/9628839508c2df900b05aae8fc8b65b209fa516b) Clarify variable and func names - [`5687951`](https://github.com/netbirdio/netbird/commit/56879517f1cb731b237a7420fc8e458b2d9ea9a7) Fix eBPF apply logic - [`1c84d6b`](https://github.com/netbirdio/netbird/commit/1c84d6b3b6df733111f4d20b57e8c3ce674be437) Avoid ebpf lib usage on non Linux - [`7bf5c6b`](https://github.com/netbirdio/netbird/commit/7bf5c6bd53989f36ede8c95291489cd793488098) Fix error handling in attach ### 📊 Changes **23 files changed** (+554 additions, -214 deletions) <details> <summary>View changed files</summary> 📝 `client/internal/dns/server.go` (+1 -1) 📝 `client/internal/dns/service_listener.go` (+56 -8) 📝 `client/internal/ebpf/ebpf/bpf_bpfeb.go` (+12 -3) ➕ `client/internal/ebpf/ebpf/bpf_bpfeb.o` (+0 -0) 📝 `client/internal/ebpf/ebpf/bpf_bpfel.go` (+12 -3) ➕ `client/internal/ebpf/ebpf/bpf_bpfel.o` (+0 -0) ➕ `client/internal/ebpf/ebpf/dns_fwd_linux.go` (+51 -0) ➕ `client/internal/ebpf/ebpf/manager_linux.go` (+116 -0) ➕ `client/internal/ebpf/ebpf/manager_linux_test.go` (+40 -0) ➕ `client/internal/ebpf/ebpf/src/dns_fwd.c` (+64 -0) ➕ `client/internal/ebpf/ebpf/src/prog.c` (+66 -0) ➕ `client/internal/ebpf/ebpf/src/wg_proxy.c` (+54 -0) ➕ `client/internal/ebpf/ebpf/wg_proxy_linux.go` (+41 -0) ➕ `client/internal/ebpf/instantiater_linux.go` (+15 -0) ➕ `client/internal/ebpf/instantiater_nonlinux.go` (+10 -0) ➕ `client/internal/ebpf/manager/manager.go` (+9 -0) ➖ `client/internal/wgproxy/ebpf/bpf_bpfeb.o` (+0 -0) ➖ `client/internal/wgproxy/ebpf/bpf_bpfel.o` (+0 -0) ➖ `client/internal/wgproxy/ebpf/loader.go` (+0 -84) ➖ `client/internal/wgproxy/ebpf/loader_test.go` (+0 -18) _...and 3 more files_ </details> ### 📄 Description ## Describe your changes This PR contains multiple modifications. In case the 53 UDP port is not option to bind then we hijack the DNS traffic with eBPF and we forward the traffic to the listener on a custom port. With this implementation we should be able to listen DNS queries on any address and still set the local host system to send queries to the custom address on port 53. Because we tried to attach multiple xdp program to the same interface I did a refactor in the WG traffic forward code also. ## Issue ticket number and link NB-282 ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [x] It is a refactor - [ ] Created tests that fail without the change (if possible) - [ ] Extended the README / documentation, if necessary --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 02:08:02 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#13295