resolver

package
v1.19.33-clash.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: GPL-3.0 Imports: 21 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 DefaultDnsReadTimeout = time.Second * 10
View Source
const DefaultDnsRelayTimeout = time.Second * 5
View Source
const SafeDnsPacketSize = 2 * 1024 // safe size which is 1232 from https://dnsflagday.net/2020/, so 2048 is enough

Variables

View Source
var (
	DisableSystemHosts, _ = strconv.ParseBool(os.Getenv("DISABLE_SYSTEM_HOSTS"))
	UseSystemHosts        bool
)
View Source
var (
	// DefaultResolver aim to resolve ip
	DefaultResolver Resolver

	// ProxyServerHostResolver resolve ip for proxies server host, only nil when DefaultResolver is nil
	ProxyServerHostResolver Resolver

	// DirectHostResolver resolve ip for direct outbound host, only nil when DefaultResolver is nil
	DirectHostResolver Resolver

	// SystemResolver always using system dns, and was init in dns module
	SystemResolver Resolver

	// DisableIPv6 means don't resolve ipv6 host
	// default value is true
	DisableIPv6 = true

	// DefaultHosts aim to resolve hosts
	DefaultHosts = NewHosts(trie.New[HostValue]())

	// DefaultDNSTimeout defined the default dns request timeout
	DefaultDNSTimeout = time.Second * 5
)
View Source
var (
	ErrIPNotFound   = errors.New("couldn't find ip")
	ErrIPVersion    = errors.New("ip version error")
	ErrIPv6Disabled = errors.New("ipv6 disabled")
)

Functions

func AddSystemDnsBlacklist

func AddSystemDnsBlacklist(names ...string)

func ClearCache

func ClearCache()

func ClearCacheNow

func ClearCacheNow()

func CloseQueries

func CloseQueries()

func FakeIPEnabled

func FakeIPEnabled() bool

func FindHostByIP

func FindHostByIP(ip netip.Addr) (string, bool)

func FlushFakeIP

func FlushFakeIP() error

func GetIP4PEnable

func GetIP4PEnable() bool

func InsertHostByIP

func InsertHostByIP(ip netip.Addr, host string)

func IsExistFakeIP

func IsExistFakeIP(ip netip.Addr) bool

func IsFakeBroadcastIP

func IsFakeBroadcastIP(ip netip.Addr) bool

func IsFakeIP

func IsFakeIP(ip netip.Addr) bool

func IsSystemDnsBlacklisted

func IsSystemDnsBlacklisted(names ...string) bool

func LookupIP

func LookupIP(ctx context.Context, host string) ([]netip.Addr, error)

LookupIP with a host, return ip

func LookupIP4P

func LookupIP4P(addr netip.Addr, port string) (netip.Addr, string)

func LookupIPWithPolicy

func LookupIPWithPolicy(ctx context.Context, host string, r Resolver, p IPQueryPolicy) ([]netip.Addr, error)

func LookupIPWithResolver

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

LookupIPWithResolver same as LookupIP, but with a resolver

func LookupIPv4

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

LookupIPv4 with a host, return ipv4 list

func LookupIPv4WithResolver

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

LookupIPv4WithResolver same as LookupIPv4, but with a resolver

func LookupIPv6

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

LookupIPv6 with a host, return ipv6 list

func LookupIPv6WithResolver

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

LookupIPv6WithResolver same as LookupIPv6, but with a resolver

func MappingEnabled

func MappingEnabled() bool

func RelayDnsConn

func RelayDnsConn(ctx context.Context, conn net.Conn, readTimeout time.Duration) error

func RelayDnsPacket

func RelayDnsPacket(ctx context.Context, payload []byte, target []byte) ([]byte, error)

RelayDnsPacket will truncate udp message up to SafeDnsPacketSize

func RemoveSystemDnsBlacklist

func RemoveSystemDnsBlacklist(names ...string)

func RequestUDPSize

func RequestUDPSize(msg *D.Msg) int

RequestUDPSize returns the UDP payload size a reply to msg may occupy: the client's advertised EDNS0 buffer size, or 512 (D.MinMsgSize) without an OPT record.

func ResetConnection

func ResetConnection()

func ResolveECH

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

func ResolveECHWithResolver

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

func ResolveIP

func ResolveIP(ctx context.Context, host string) (netip.Addr, error)

ResolveIP with a host, return ip and priority return TypeA

func ResolveIPPrefer6

func ResolveIPPrefer6(ctx context.Context, host string) (netip.Addr, error)

ResolveIPPrefer6 with a host, return ip and priority return TypeAAAA

func ResolveIPPrefer6WithResolver

func ResolveIPPrefer6WithResolver(ctx context.Context, host string, r Resolver) (netip.Addr, error)

ResolveIPPrefer6WithResolver same as ResolveIP, but with a resolver

func ResolveIPWithPolicy

func ResolveIPWithPolicy(ctx context.Context, host string, r Resolver, p IPQueryPolicy) (netip.Addr, error)

func ResolveIPWithResolver

func ResolveIPWithResolver(ctx context.Context, host string, r Resolver) (netip.Addr, error)

ResolveIPWithResolver same as ResolveIP, but with a resolver

func ResolveIPv4

func ResolveIPv4(ctx context.Context, host string) (netip.Addr, error)

ResolveIPv4 with a host, return ipv4

func ResolveIPv4WithResolver

func ResolveIPv4WithResolver(ctx context.Context, host string, r Resolver) (netip.Addr, error)

ResolveIPv4WithResolver same as ResolveIPv4, but with a resolver

func ResolveIPv6

func ResolveIPv6(ctx context.Context, host string) (netip.Addr, error)

func ResolveIPv6WithResolver

func ResolveIPv6WithResolver(ctx context.Context, host string, r Resolver) (netip.Addr, error)

ResolveIPv6WithResolver same as ResolveIPv6, but with a resolver

func ServeMsg

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

ServeMsg with a dns.Msg, return resolve dns.Msg

func SetIP4PEnable

func SetIP4PEnable(enableIP4PConvert bool)

func SetIPQueryPolicy

func SetIPQueryPolicy(p IPQueryPolicy)

func SortationAddr

func SortationAddr(ips []netip.Addr) (ipv4s, ipv6s []netip.Addr)

func StoreFakePoolState

func StoreFakePoolState()

Types

type Enhancer

type Enhancer interface {
	FakeIPEnabled() bool
	MappingEnabled() bool
	IsFakeIP(netip.Addr) bool
	IsFakeBroadcastIP(netip.Addr) bool
	IsExistFakeIP(netip.Addr) bool
	FindHostByIP(netip.Addr) (string, bool)
	FlushFakeIP() error
	InsertHostByIP(netip.Addr, string)
	StoreFakePoolState()
}
var DefaultHostMapper Enhancer

type HostValue

type HostValue struct {
	IsDomain bool
	IPs      []netip.Addr
	Domain   string
}

func NewHostValue

func NewHostValue(value []string) (HostValue, error)

func NewHostValueByDomain

func NewHostValueByDomain(domain string) (HostValue, error)

func NewHostValueByIPs

func NewHostValueByIPs(ips []netip.Addr) (HostValue, error)

func (HostValue) RandIP

func (hv HostValue) RandIP() (netip.Addr, error)

type Hosts

type Hosts struct {
	*trie.DomainTrie[HostValue]
}

func NewHosts

func NewHosts(hosts *trie.DomainTrie[HostValue]) Hosts

func (*Hosts) Search

func (h *Hosts) Search(domain string, isDomain bool) (*HostValue, bool)

Return the search result and whether to match the parameter `isDomain`

type IPQueryPolicy

type IPQueryPolicy uint32
const (
	IPQueryLegacy IPQueryPolicy = iota
	IPQueryIPv4Only
	IPQueryDualStack
	IPQueryPreferIPv4
	IPQueryPreferIPv6
	IPQueryIPv6Only
)

func CurrentIPQueryPolicy

func CurrentIPQueryPolicy() IPQueryPolicy

func ParseIPQueryPolicy

func ParseIPQueryPolicy(value string) (IPQueryPolicy, error)

func (IPQueryPolicy) AllowsAddress

func (p IPQueryPolicy) AllowsAddress(ip netip.Addr) bool

func (IPQueryPolicy) AllowsQueryType

func (p IPQueryPolicy) AllowsQueryType(qtype uint16) bool

func (IPQueryPolicy) String

func (p IPQueryPolicy) String() string

type Resolver

type Resolver interface {
	LookupIP(ctx context.Context, host string) (ips []netip.Addr, err error)
	LookupIPv4(ctx context.Context, host string) (ips []netip.Addr, err error)
	LookupIPv6(ctx context.Context, host string) (ips []netip.Addr, err error)
	ResolveECH(ctx context.Context, host string) ([]byte, error)
	ExchangeContext(ctx context.Context, m *dns.Msg) (msg *dns.Msg, err error)
	Invalid() bool
	ClearCache()
	ResetConnection()
}

type ResolverAggregate

type ResolverAggregate interface {
	ContainsResolver(Resolver) bool
}

type Service

type Service interface {
	ServeMsg(ctx context.Context, msg *D.Msg) (*D.Msg, error)
}
var DefaultService Service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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