dnsbpf

package
v0.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package dnsbpf is a CoreDNS plugin that intercepts DNS responses and populates the clawker eBPF dns_cache map with resolved IP → domain hash mappings. This enables the BPF connect4 program to route per-domain TCP traffic (e.g., SSH to github.com vs gitlab.com on port 22) to the correct Envoy listener.

The plugin uses nonwriter to capture responses from the next plugin in the chain (typically "forward"), extracts A records, and writes each resolved IP to the pinned BPF map at /sys/fs/bpf/clawker/dns_cache.

Corefile usage:

github.com {
    dnsbpf
    forward . 1.1.1.2 1.0.0.2
}

Index

Constants

View Source
const DefaultPinPath = clawkerebpf.PinPath + "/" + clawkerebpf.DNSCacheMapName

DefaultPinPath is where the eBPF manager pins the dns_cache map.

Variables

This section is empty.

Functions

This section is empty.

Types

type BPFMap

type BPFMap struct {
	// contains filtered or unexported fields
}

BPFMap wraps a pinned BPF hash map for dns_cache writes.

func OpenBPFMap

func OpenBPFMap(pinPath string) (*BPFMap, error)

OpenBPFMap opens the pinned dns_cache map.

func (*BPFMap) Close

func (b *BPFMap) Close() error

Close closes the BPF map file descriptor.

func (*BPFMap) Update

func (b *BPFMap) Update(ip, domainHash, ttlSeconds uint32)

Update writes an IP → domain_hash entry to the dns_cache map. ip must be in network byte order (from IPToUint32).

type Handler

type Handler struct {
	Next plugin.Handler
	Zone string    // Corefile zone this instance serves (e.g., "github.com.")
	Map  MapWriter // Shared BPF map writer (nil = skip writes)
}

Handler implements plugin.Handler by intercepting DNS responses and writing A record results to the BPF dns_cache map.

func (Handler) Name

func (h Handler) Name() string

Name returns the plugin name as registered with CoreDNS.

func (Handler) ServeDNS

func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS intercepts the DNS response from the next plugin and writes A record IPs to the BPF dns_cache map.

type MapWriter

type MapWriter interface {
	Update(ip, domainHash, ttlSeconds uint32)
}

MapWriter is the interface for writing to the BPF dns_cache map. Implemented by BPFMap for production; fakes can be injected for tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL