dnscache

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalECS added in v1.5.5

func CanonicalECS(msg *dns.Msg) string

CanonicalECS returns a canonical string form of the EDNS Client Subnet (ECS, EDNS option 8) carried by msg, suitable for partitioning cache and singleflight keys. A request with no ECS option returns "", so all ECS-less queries share one partition and behave as before.

A request that DOES carry an ECS option is never mapped to "", even at SOURCE PREFIX-LENGTH 0: the /0 query is forwarded with an ECS option, may draw different upstream data than an ECS-less query, and its answer (with the echoed option) must not be served to a client that sent no ECS — RFC 7871 §7.3.1 requires /0-cached data to remain distinguishable. The family is part of the token, so an IPv4 /0 and an IPv6 /0 stay distinct too.

The address is masked to its source prefix length so only the significant subnet bits contribute to the key: two clients in the same subnet share a partition, while different subnets (or address families) never do. The response-only SCOPE PREFIX-LENGTH is deliberately excluded — it is not part of what the client asked for.

Types

type Cacher

type Cacher interface {
	Get(Key) *Value
	Add(Key, *Value)
	Purge()
}

Cacher is the interface for caching DNS response.

type Key

type Key struct {
	Qtype    uint16
	Qclass   uint16
	Name     string
	Upstream string
	ECS      string
}

Key is the caching key for DNS message.

ECS partitions the cache by EDNS Client Subnet so an answer resolved for one subnet is never served to a client in a different subnet. Answer records are scoped to the network that generated them (RFC 7871 §7.3), so they must not be shared across subnets even when the question is otherwise identical.

func NewKey

func NewKey(msg *dns.Msg, upstream string) Key

NewKey creates a new cache key for given DNS message.

type LRUCache

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

LRUCache implements Cacher interface.

func NewLRUCache

func NewLRUCache(size int) (*LRUCache, error)

NewLRUCache creates a new LRUCache instance with given size.

func (*LRUCache) Add

func (l *LRUCache) Add(key Key, value *Value)

Add adds a value to cache.

func (*LRUCache) Get

func (l *LRUCache) Get(key Key) *Value

Get looks up key's value from cache.

func (*LRUCache) Purge added in v1.3.6

func (l *LRUCache) Purge()

Purge clears the cache.

type Value

type Value struct {
	Expire time.Time
	Msg    *dns.Msg
}

func NewValue

func NewValue(msg *dns.Msg, expire time.Time) *Value

NewValue creates a new cache value for given DNS message.

Jump to

Keyboard shortcuts

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