dns

package
v1.19.34-clash.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: GPL-3.0 Imports: 49 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	IfaceTTL    = time.Second * 20
	DHCPTTL     = time.Hour
	DHCPTimeout = time.Minute
)
View Source
const (
	// QUICCodeNoError is used when the connection or stream needs to be closed,
	// but there is no error to signal.
	QUICCodeNoError = quic.ApplicationErrorCode(0)
	// QUICCodeInternalError signals that the DoQ implementation encountered
	// an internal error and is incapable of pursuing the transaction or the
	// connection.
	QUICCodeInternalError = quic.ApplicationErrorCode(1)
	// QUICKeepAlivePeriod is the value that we pass to *quic.Config and that
	// controls the period with with keep-alive frames are being sent to the
	// connection. We set it to 20s as it would be in the quic-go@v0.27.1 with
	// KeepAlive field set to true This value is specified in
	// https://pkg.go.dev/github.com/metacubex/quic-go/internal/protocol#MaxKeepAliveInterval.
	//
	// TODO(ameshkov):  Consider making it configurable.
	QUICKeepAlivePeriod = time.Second * 20
	DefaultTimeout      = time.Second * 5
)
View Source
const (
	ExplainSourceCache        = "cache"
	ExplainSourceRcode        = "rcode"
	ExplainSourcePolicy       = "policy"
	ExplainSourceFallback     = "fallback"
	ExplainSourceMain         = "main"
	ExplainSourceHosts        = "hosts"
	ExplainSourceFakeIP       = "fake-ip"
	ExplainSourceIPv6Disabled = "ipv6-disabled"
	ExplainSourceIPStack      = "ip-stack"
)
View Source
const (
	SystemDnsFlushTime   = 5 * time.Minute
	SystemDnsDeleteTimes = 12 // 12*5 = 60min
)
View Source
const (
	MaxMsgSize = 65535
)
View Source
const NextProtoDQ = "doq"
View Source
const RespectRules = tunnel.DnsRespectRules

Variables

View Source
var DefaultHTTPVersions = []C.HTTPVersion{C.HTTPVersion11, C.HTTPVersion2}
View Source
var ParseNameServer func(servers []string) ([]NameServer, error) // define in config/config.go

Functions

func ClashDefaultCacheMaxSize

func ClashDefaultCacheMaxSize() int

func ClashSetDefaultCacheMaxSize

func ClashSetDefaultCacheMaxSize(n int)

func IsLocalZone

func IsLocalZone(name string) bool

func MarkSystemSubstitutes

func MarkSystemSubstitutes(servers []string)

func ReCreateServer

func ReCreateServer(addr string, lc C.InboundListenConfig, service resolver.Service)

func RegisterEasyTierDnsClient

func RegisterEasyTierDnsClient(name string, client dnsClient) func()

func RegisterTailscaleDnsClient

func RegisterTailscaleDnsClient(name string, client dnsClient) func()

func SSIDPoliciesInForce

func SSIDPoliciesInForce() bool

func SetLocalZoneExchanger

func SetLocalZoneExchanger(exchange func(context.Context, *D.Msg) (*D.Msg, error))

func SetSystemResolverDefaults

func SetSystemResolverDefaults(servers []string)

func SetSystemSubstituteRefresh

func SetSystemSubstituteRefresh(refresh func())

func SetSystemSubstituteServers

func SetSystemSubstituteServers(servers []string) bool

func SetSystemSubstitutesStale

func SetSystemSubstitutesStale(stale bool) bool

func SystemResolverDefaultAddresses

func SystemResolverDefaultAddresses() []string

func SystemSubstituteServers

func SystemSubstituteServers() []string

func SystemSubstitutes

func SystemSubstitutes() []string

func SystemSubstitutesStale

func SystemSubstitutesStale() bool

Types

type Config

type Config struct {
	Main, Fallback       []NameServer
	Default              []NameServer
	ProxyServer          []NameServer
	DirectServer         []NameServer
	DirectFollowPolicy   bool
	IPv6                 bool
	IPv6Timeout          uint
	FallbackIPFilter     []C.IpMatcher
	FallbackDomainFilter []C.DomainMatcher
	FallbackLazyQuery    bool
	Policy               []Policy
	ProxyServerPolicy    []Policy
	SSIDPolicy           []SSIDPolicy
	CacheAlgorithm       string
	CacheMaxSize         int
}

type EnhancerConfig

type EnhancerConfig struct {
	IPv6          bool
	EnhancedMode  C.DNSMode
	FakeIPPool    *fakeip.Pool
	FakeIPPool6   *fakeip.Pool
	FakeIPSkipper *fakeip.Skipper
	FakeIPTTL     int
	UseHosts      bool
	QueryTypes    QueryTypes
}

type Explanation

type Explanation struct {
	Source         string
	MatchedRule    string
	Candidates     []string
	AnsweredBy     string
	Answer         *D.Msg
	CacheExpiresAt *time.Time
	CacheStale     bool
}

type NameServer

type NameServer struct {
	Net          string
	Addr         string
	ProxyAdapter C.ProxyAdapter
	ProxyName    string
	Params       map[string]string
	PreferH3     bool
}

func (NameServer) Equal

func (ns NameServer) Equal(ns2 NameServer) bool

type Policy

type Policy struct {
	Domain      string
	Matcher     C.DomainMatcher
	NameServers []NameServer
}

type QueryTypes

type QueryTypes struct {
	SVCB   *bool
	Others *bool
}

type Resolver

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

func NewResolverFromClient

func NewResolverFromClient(client dnsClient) *Resolver

func (*Resolver) ClearCache

func (r *Resolver) ClearCache()

func (*Resolver) CloseQueries

func (r *Resolver) CloseQueries()

func (*Resolver) ExchangeContext

func (r *Resolver) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error)

ExchangeContext a batch of dns request with context.Context, and it use cache

func (*Resolver) Explain

func (r *Resolver) Explain(ctx context.Context, m *D.Msg, probe bool) Explanation

func (*Resolver) HoldsAnswer

func (r *Resolver) HoldsAnswer(q D.Question) bool

func (*Resolver) Invalid

func (r *Resolver) Invalid() bool

Invalid return this resolver can or can't be used

func (*Resolver) LookupIP

func (r *Resolver) LookupIP(ctx context.Context, host string) (ips []netip.Addr, err error)

func (*Resolver) LookupIPPrimaryIPv4

func (r *Resolver) LookupIPPrimaryIPv4(ctx context.Context, host string) (ips []netip.Addr, err error)

func (*Resolver) LookupIPv4

func (r *Resolver) LookupIPv4(ctx context.Context, host string) ([]netip.Addr, error)

LookupIPv4 request with TypeA

func (*Resolver) LookupIPv6

func (r *Resolver) LookupIPv6(ctx context.Context, host string) ([]netip.Addr, error)

LookupIPv6 request with TypeAAAA

func (*Resolver) ResetConnection

func (r *Resolver) ResetConnection()

func (*Resolver) ResolveECH

func (r *Resolver) ResolveECH(ctx context.Context, host string) ([]byte, error)

type ResolverEnhancer

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

func NewEnhancer

func NewEnhancer(cfg EnhancerConfig) *ResolverEnhancer

func (*ResolverEnhancer) AnswersSVCB

func (h *ResolverEnhancer) AnswersSVCB() bool

func (*ResolverEnhancer) FakeIPEnabled

func (h *ResolverEnhancer) FakeIPEnabled() bool

func (*ResolverEnhancer) FindHostByIP

func (h *ResolverEnhancer) FindHostByIP(ip netip.Addr) (string, bool)

func (*ResolverEnhancer) FlushFakeIP

func (h *ResolverEnhancer) FlushFakeIP() error

func (*ResolverEnhancer) IPv6

func (h *ResolverEnhancer) IPv6() bool

func (*ResolverEnhancer) InsertHostByIP

func (h *ResolverEnhancer) InsertHostByIP(ip netip.Addr, host string)

func (*ResolverEnhancer) IsExistFakeIP

func (h *ResolverEnhancer) IsExistFakeIP(ip netip.Addr) bool

func (*ResolverEnhancer) IsFakeBroadcastIP

func (h *ResolverEnhancer) IsFakeBroadcastIP(ip netip.Addr) bool

func (*ResolverEnhancer) IsFakeIP

func (h *ResolverEnhancer) IsFakeIP(ip netip.Addr) bool

func (*ResolverEnhancer) MappingEnabled

func (h *ResolverEnhancer) MappingEnabled() bool

func (*ResolverEnhancer) PatchFrom

func (h *ResolverEnhancer) PatchFrom(o *ResolverEnhancer)

func (*ResolverEnhancer) ShouldSkipFakeIP

func (h *ResolverEnhancer) ShouldSkipFakeIP(host string) bool

func (*ResolverEnhancer) StoreFakePoolState

func (h *ResolverEnhancer) StoreFakePoolState()

func (*ResolverEnhancer) UseHosts

func (h *ResolverEnhancer) UseHosts() bool

type Resolvers

type Resolvers struct {
	*Resolver
	ProxyResolver  *Resolver
	DirectResolver *Resolver
}

func NewResolver

func NewResolver(config Config) (rs Resolvers)

func (Resolvers) ClearCache

func (rs Resolvers) ClearCache()

func (Resolvers) CloseQueries

func (rs Resolvers) CloseQueries()

func (Resolvers) ContainsResolver

func (rs Resolvers) ContainsResolver(r resolver.Resolver) bool

func (Resolvers) ResetConnection

func (rs Resolvers) ResetConnection()

type SSIDPolicy

type SSIDPolicy struct {
	SSID        string
	NameServers []NameServer
}

type Server

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

func (*Server) SetService

func (s *Server) SetService(service resolver.Service)

func (*Server) TCPHandler

func (s *Server) TCPHandler() D.Handler

func (*Server) UDPHandler

func (s *Server) UDPHandler() D.Handler

type Service

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

func NewService

func NewService(resolver resolver.Resolver, mapper *ResolverEnhancer) *Service

func (*Service) ServeMsg

func (s *Service) ServeMsg(ctx context.Context, msg *D.Msg) (*D.Msg, error)

ServeMsg implement resolver.Service ResolveMsg

type StandaloneClient

type StandaloneClient interface {
	ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error)
	ResetConnection()
}

func NewStandaloneClient

func NewStandaloneClient(server NameServer, r resolver.Resolver) StandaloneClient

Jump to

Keyboard shortcuts

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