Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultCfResolver() i.DnsResolver
- func MsgToBuffer(msg *d.Msg) (*buf.Buffer, error)
- func NewDnsConnImpl(tag string, rrCache *rrCache, send func(*dns.Msg) error) *dnsConnImpl
- func NewRrCache(setting RrCacheSetting) *rrCache
- func UnFqdn(domain string) string
- type AllDnsServers
- type AllFakeDns
- type ConcurrentDnsServers
- type Condition
- type ConditionDnsServer
- type DnsConn
- type DnsHandler
- func (s *DnsHandler) HandleFlow(ctx context.Context, dst net.Destination, rw buf.ReaderWriter) error
- func (s *DnsHandler) HandlePacketConn(ctx context.Context, dst net.Destination, rw udp.PacketReaderWriter) error
- func (s *DnsHandler) Tag() string
- func (s *DnsHandler) WithDns(dns dnsServer) *DnsHandler
- func (s *DnsHandler) WithTag(tag string) *DnsHandler
- type DnsMsgMeta
- type DnsRule
- type DnsServer
- type DnsServerConcurrent
- func (ns *DnsServerConcurrent) Close() error
- func (ns *DnsServerConcurrent) HandleQuery(ctx context.Context, msg *dns.Msg, tcp bool) (*dns.Msg, error)
- func (ns DnsServerConcurrent) ReadPacket() (*udp.Packet, error)
- func (d *DnsServerConcurrent) RemoveDest(remove net.AddressPort, fallback []net.AddressPort)
- func (d *DnsServerConcurrent) SetDests(dests []net.AddressPort)
- func (ns *DnsServerConcurrent) Start() error
- func (ns DnsServerConcurrent) WritePacket(p *udp.Packet) error
- type DnsServerConcurrentOption
- type DnsServerSerial
- func (d *DnsServerSerial) Close() error
- func (d *DnsServerSerial) HandleQuery(ctx context.Context, msg *dns.Msg, tcp bool) (*dns.Msg, error)
- func (d *DnsServerSerial) RemoveDest(toBeRemoved net.AddressPort, fallback []net.AddressPort)
- func (d *DnsServerSerial) ReplaceDests(dests []net.AddressPort)
- func (d *DnsServerSerial) Start() error
- type DnsServerToResolver
- func (d *DnsServerToResolver) LookupECH(ctx context.Context, domain string) ([]byte, error)
- func (d *DnsServerToResolver) LookupIP(ctx context.Context, host string) ([]net.IP, error)
- func (d *DnsServerToResolver) LookupIPPrefer4(ctx context.Context, host string) ([]net.IP, error)
- func (d *DnsServerToResolver) LookupIPSpeed(ctx context.Context, host string) ([]net.IP, error)
- func (d *DnsServerToResolver) LookupIPv4(ctx context.Context, host string) ([]net.IP, error)
- func (d *DnsServerToResolver) LookupIPv6(ctx context.Context, host string) ([]net.IP, error)
- type DnsServerToResolverOption
- type DoHNameServer
- type DoHNameServerOption
- type DomainAndResolver
- type EmptyDnsResolver
- type ExcludeDomainCondition
- type FakeDns
- func (*FakeDns) Close() error
- func (f *FakeDns) GetDomainFromFakeDNS(ip net.Address) string
- func (f *FakeDns) GetResolver(domain string, ip net.Address) (string, bool)
- func (f *FakeDns) HandleQuery(ctx context.Context, msg *dns.Msg, _ bool) (*dns.Msg, error)
- func (f *FakeDns) IsIPInIPPool(ip net.Address) bool
- func (*FakeDns) Name() string
- func (*FakeDns) Start() error
- type GoDnsResolver
- func (d *GoDnsResolver) Close() error
- func (d *GoDnsResolver) HandleQuery(ctx context.Context, msg *dns.Msg, tcp bool) (*dns.Msg, error)
- func (d *GoDnsResolver) LookupIP(ctx context.Context, host string) ([]net.IP, error)
- func (d *GoDnsResolver) LookupIPPrefer4(ctx context.Context, host string) ([]net.IP, error)
- func (d *GoDnsResolver) LookupIPSpeed(ctx context.Context, host string) ([]net.IP, error)
- func (d *GoDnsResolver) LookupIPv4(ctx context.Context, host string) ([]net.IP, error)
- func (d *GoDnsResolver) LookupIPv6(ctx context.Context, host string) ([]net.IP, error)
- func (d *GoDnsResolver) Start() error
- type GoDnsResolverOption
- type HasSrcCondition
- type HijackDns
- func (dsp *HijackDns) Close() error
- func (dsp *HijackDns) GetFakeDnsEnabled() bool
- func (d *HijackDns) HandleQuery(ctx context.Context, msg *DnsMsgMeta, tcp bool) (*dns.Msg, error)
- func (dsp *HijackDns) ReadPacket() (*udp.Packet, error)
- func (dsp *HijackDns) SetFakeDnsEnabled(enabled bool)
- func (dsp *HijackDns) Start() error
- func (dsp *HijackDns) WritePacket(p *udp.Packet) error
- type HijackDnsToDnsServer
- type IPOption
- type IPToDomain
- type IncludedTypesCondition
- type InternalDns
- func (d *InternalDns) LookupECH(ctx context.Context, domain string) ([]byte, error)
- func (d *InternalDns) LookupIP(ctx context.Context, host string) ([]net.IP, error)
- func (d *InternalDns) LookupIPSpeed(ctx context.Context, host string) ([]net.IP, error)
- func (d *InternalDns) LookupIPv4(ctx context.Context, host string) ([]net.IP, error)
- func (d *InternalDns) LookupIPv6(ctx context.Context, host string) ([]net.IP, error)
- type IpOptionDnsServer
- type MsgRewriter
- type MsgRewriterOption
- type Pool
- type PoolConfig
- type Pools
- type Prefer4IPResolver
- type PreferDomainCondition
- type QUICNameServer
- type QuicNameServerOption
- type ResolverGetter
- type RrCacheSetting
- type SerialDnsServers
- type StaticDnsServer
Constants ¶
const NextProtoDQ = "doq"
NextProtoDQ - During connection establishment, DNS/QUIC support is indicated by selecting the ALPN token "doq" in the crypto handshake.
Variables ¶
var ErrAllServersFailed = errors.New("all dns servers failed")
var ErrConditionNotMatch = errors.New("condition not match")
var ErrNoQuestion = errors.New("no question in dns query")
var ErrNotFound = errors.New("not found")
Functions ¶
func DefaultCfResolver ¶ added in v1.1.0
func DefaultCfResolver() i.DnsResolver
func NewDnsConnImpl ¶
func NewRrCache ¶
func NewRrCache(setting RrCacheSetting) *rrCache
Types ¶
type AllDnsServers ¶ added in v1.2.3
type AllDnsServers struct {
// contains filtered or unexported fields
}
func NewAllDnsServers ¶ added in v1.2.3
func NewAllDnsServers(dnsServers []DnsServer) *AllDnsServers
func (*AllDnsServers) Close ¶ added in v1.2.3
func (dsp *AllDnsServers) Close() error
func (*AllDnsServers) GetDomainFromFakeDNS ¶ added in v1.2.3
func (dsp *AllDnsServers) GetDomainFromFakeDNS(ip net.Address) string
func (*AllDnsServers) IsIPInIPPool ¶ added in v1.2.3
func (dsp *AllDnsServers) IsIPInIPPool(ip net.Address) bool
func (*AllDnsServers) Start ¶ added in v1.2.3
func (dsp *AllDnsServers) Start() error
type AllFakeDns ¶
type AllFakeDns struct {
// contains filtered or unexported fields
}
func (*AllFakeDns) AddFakeDns ¶
func (a *AllFakeDns) AddFakeDns(fakeDns *FakeDns)
func (*AllFakeDns) GetDomainFromFakeDNS ¶
func (a *AllFakeDns) GetDomainFromFakeDNS(ip net.Address) string
func (*AllFakeDns) IsIPInIPPool ¶
func (a *AllFakeDns) IsIPInIPPool(ip net.Address) bool
type ConcurrentDnsServers ¶ added in v1.2.3
type ConcurrentDnsServers struct {
DnsServers []DnsServer
}
ConcurrentDnsServers fans out a query to all underlying [DnsServer]s in parallel and returns the first definitive response. A definitive response is NOERROR with at least one answer record. NXDOMAIN and NODATA (NOERROR with empty answer) are kept as fallbacks and only returned if no server produces a definitive answer. SERVFAIL/REFUSED/transport errors are ignored entirely.
func NewConcurrentDnsServers ¶ added in v1.2.3
func NewConcurrentDnsServers(servers ...DnsServer) *ConcurrentDnsServers
func (*ConcurrentDnsServers) Close ¶ added in v1.2.3
func (c *ConcurrentDnsServers) Close() error
func (*ConcurrentDnsServers) HandleQuery ¶ added in v1.2.3
func (*ConcurrentDnsServers) Start ¶ added in v1.2.3
func (c *ConcurrentDnsServers) Start() error
type Condition ¶
type Condition interface {
Match(msg *DnsMsgMeta) bool
}
type ConditionDnsServer ¶
type ConditionDnsServer struct {
DnsServer
// contains filtered or unexported fields
}
func NewConditionDnsServer ¶
func NewConditionDnsServer(dnsServer DnsServer, conditions ...Condition) *ConditionDnsServer
func (*ConditionDnsServer) MatchConditions ¶
func (d *ConditionDnsServer) MatchConditions(msg *DnsMsgMeta) bool
type DnsHandler ¶
type DnsHandler struct {
// contains filtered or unexported fields
}
intercept dns queries and send back dns responses
func NewHandlerV ¶
func NewHandlerV() *DnsHandler
func (*DnsHandler) HandleFlow ¶
func (s *DnsHandler) HandleFlow(ctx context.Context, dst net.Destination, rw buf.ReaderWriter) error
implements i.FlowHandler
func (*DnsHandler) HandlePacketConn ¶
func (s *DnsHandler) HandlePacketConn(ctx context.Context, dst net.Destination, rw udp.PacketReaderWriter) error
func (*DnsHandler) Tag ¶
func (s *DnsHandler) Tag() string
func (*DnsHandler) WithDns ¶
func (s *DnsHandler) WithDns(dns dnsServer) *DnsHandler
func (*DnsHandler) WithTag ¶
func (s *DnsHandler) WithTag(tag string) *DnsHandler
type DnsMsgMeta ¶
type DnsMsgMeta struct {
*dns.Msg
Src *net.Destination
}
type DnsServerConcurrent ¶
type DnsServerConcurrent struct {
// contains filtered or unexported fields
}
reuse conn for dns query
func NewDnsServerConcurrent ¶
func NewDnsServerConcurrent(opts DnsServerConcurrentOption) *DnsServerConcurrent
func (*DnsServerConcurrent) Close ¶
func (ns *DnsServerConcurrent) Close() error
func (*DnsServerConcurrent) HandleQuery ¶
func (ns *DnsServerConcurrent) HandleQuery(ctx context.Context, msg *dns.Msg, tcp bool) (*dns.Msg, error)
msg should be standard dns query message: has only one question, opcode is QUERY
func (DnsServerConcurrent) ReadPacket ¶
func (*DnsServerConcurrent) RemoveDest ¶
func (d *DnsServerConcurrent) RemoveDest(remove net.AddressPort, fallback []net.AddressPort)
func (*DnsServerConcurrent) SetDests ¶
func (d *DnsServerConcurrent) SetDests(dests []net.AddressPort)
func (*DnsServerConcurrent) Start ¶
func (ns *DnsServerConcurrent) Start() error
func (DnsServerConcurrent) WritePacket ¶
msg should be standard dns query message: has only one question, opcode is QUERY
type DnsServerConcurrentOption ¶
type DnsServerConcurrentOption struct {
Name string
NameserverAddrs []net.AddressPort
Handler i.FlowHandler
IPToDomain *IPToDomain
Tls bool
ClientIp net.IP
Dispatcher packetDispatcher
RrCache *rrCache
Rewriter MsgRewriter
}
type DnsServerSerial ¶
does not reuse conn for dns query
func NewDnsServerSerial ¶
func NewDnsServerSerial(dests []net.AddressPort, dialer i.Dialer, ipToDomain *IPToDomain) *DnsServerSerial
func (*DnsServerSerial) Close ¶
func (d *DnsServerSerial) Close() error
func (*DnsServerSerial) HandleQuery ¶
func (*DnsServerSerial) RemoveDest ¶
func (d *DnsServerSerial) RemoveDest(toBeRemoved net.AddressPort, fallback []net.AddressPort)
func (*DnsServerSerial) ReplaceDests ¶
func (d *DnsServerSerial) ReplaceDests(dests []net.AddressPort)
func (*DnsServerSerial) Start ¶
func (d *DnsServerSerial) Start() error
type DnsServerToResolver ¶
func NewDnsServerToResolver ¶
func NewDnsServerToResolver(opts DnsServerToResolverOption) *DnsServerToResolver
func (*DnsServerToResolver) LookupIPPrefer4 ¶
func (*DnsServerToResolver) LookupIPSpeed ¶ added in v1.1.0
func (*DnsServerToResolver) LookupIPv4 ¶
func (*DnsServerToResolver) LookupIPv6 ¶
type DnsServerToResolverOption ¶ added in v1.2.3
type DoHNameServer ¶
DoHNameServer implemented DNS over HTTPS (RFC8484) Wire Format, which is compatible with traditional dns over udp(RFC1035), thus most of the DOH implementation is copied from udpns.go
func NewDoHNameServer ¶
func NewDoHNameServer(option DoHNameServerOption) (*DoHNameServer, error)
NewDoHNameServer creates DOH server object for remote resolving.
func (*DoHNameServer) Close ¶
func (d *DoHNameServer) Close() error
func (*DoHNameServer) HandleQuery ¶
func (*DoHNameServer) Name ¶
func (d *DoHNameServer) Name() string
func (*DoHNameServer) Start ¶
func (d *DoHNameServer) Start() error
type DoHNameServerOption ¶
type DoHNameServerOption struct {
ClientIP net.IP
Handler i.FlowHandler
Name string
Url string
IpToDomain *IPToDomain
Tls *tls.Config
RrCache *rrCache
Rewriter MsgRewriter
}
type DomainAndResolver ¶
type EmptyDnsResolver ¶ added in v1.2.3
type EmptyDnsResolver struct{}
func (*EmptyDnsResolver) Close ¶ added in v1.2.3
func (e *EmptyDnsResolver) Close() error
func (*EmptyDnsResolver) HandleQuery ¶ added in v1.2.3
func (*EmptyDnsResolver) Start ¶ added in v1.2.3
func (e *EmptyDnsResolver) Start() error
type ExcludeDomainCondition ¶
type FakeDns ¶
type FakeDns struct {
// contains filtered or unexported fields
}
func NewFakeDns ¶
func (*FakeDns) GetDomainFromFakeDNS ¶
func (*FakeDns) GetResolver ¶
func (*FakeDns) HandleQuery ¶
type GoDnsResolver ¶ added in v1.2.3
func NewGoIpResolver ¶
func NewGoIpResolver(option GoDnsResolverOption) *GoDnsResolver
func (*GoDnsResolver) Close ¶ added in v1.2.3
func (d *GoDnsResolver) Close() error
func (*GoDnsResolver) HandleQuery ¶ added in v1.2.3
func (*GoDnsResolver) LookupIPPrefer4 ¶ added in v1.2.3
func (*GoDnsResolver) LookupIPSpeed ¶ added in v1.2.3
func (*GoDnsResolver) LookupIPv4 ¶ added in v1.2.3
func (*GoDnsResolver) LookupIPv6 ¶ added in v1.2.3
func (*GoDnsResolver) Start ¶ added in v1.2.3
func (d *GoDnsResolver) Start() error
type GoDnsResolverOption ¶ added in v1.2.3
type GoDnsResolverOption struct {
Cache *rrCache
IpToDomain *IPToDomain
Rewriter MsgRewriter
}
type HasSrcCondition ¶
type HasSrcCondition struct{}
func (*HasSrcCondition) Match ¶
func (h *HasSrcCondition) Match(msg *DnsMsgMeta) bool
type HijackDns ¶ added in v1.2.3
type HijackDns struct {
// contains filtered or unexported fields
}
func NewHijackDns ¶ added in v1.2.3
func NewHijackDns(local *StaticDnsServer, rules []*DnsRule, enableDns bool) *HijackDns
func (*HijackDns) GetFakeDnsEnabled ¶ added in v1.2.3
func (*HijackDns) HandleQuery ¶ added in v1.2.3
func (*HijackDns) ReadPacket ¶ added in v1.2.3
func (*HijackDns) SetFakeDnsEnabled ¶ added in v1.2.3
type HijackDnsToDnsServer ¶ added in v1.2.3
type HijackDnsToDnsServer struct {
*HijackDns
}
type IPToDomain ¶
type IPToDomain struct {
// contains filtered or unexported fields
}
func NewIPToDomain ¶
func NewIPToDomain(size int, maxDomainAndResolversPerIp int) *IPToDomain
func (*IPToDomain) GetResolvers ¶
type IncludedTypesCondition ¶
type IncludedTypesCondition struct {
Types []uint16
}
func (*IncludedTypesCondition) Match ¶
func (i *IncludedTypesCondition) Match(msg *DnsMsgMeta) bool
type InternalDns ¶
type InternalDns struct {
StaticDns *StaticDnsServer
Resolver i.DnsResolver
}
for dialer to lookup ip when dialing
func (*InternalDns) LookupIPSpeed ¶
func (*InternalDns) LookupIPv4 ¶
func (*InternalDns) LookupIPv6 ¶
type IpOptionDnsServer ¶
if ip option conflicts, return a response with no answer
type MsgRewriter ¶ added in v1.1.0
func NewMsgRewriter ¶ added in v1.1.0
func NewMsgRewriter(opts MsgRewriterOption) MsgRewriter
type MsgRewriterOption ¶ added in v1.1.0
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
func (*Pool) GetDomainFromFakeIP ¶
GetDomainFromFakeIP checks if an IP is a fake IP and have corresponding domain name
func (*Pool) GetFakeIPForDomain ¶
GetFakeIPForDomain checks if there is already an ip for domain first, if so returns the ip; if not generate a new fake IP for domain
type PoolConfig ¶
type Pools ¶
type Pools []*Pool
no two pool should have same ip type, since if there are two pools have same ip type, the first pool will always be used.
func (Pools) GetDomainFromFakeDNS ¶
type Prefer4IPResolver ¶
type Prefer4IPResolver struct {
i.IPResolver
}
type PreferDomainCondition ¶
type PreferDomainCondition struct {
DomainSet i.DomainSet
// contains filtered or unexported fields
}
func (*PreferDomainCondition) Match ¶
func (p *PreferDomainCondition) Match(msg *DnsMsgMeta) bool
type QUICNameServer ¶
QUICNameServer implemented DNS over QUIC
func NewQUICNameServer ¶
func NewQUICNameServer(option QuicNameServerOption) (*QUICNameServer, error)
NewQUICNameServer creates DNS-over-QUIC client object for local resolving
func (*QUICNameServer) Close ¶
func (s *QUICNameServer) Close() error
func (*QUICNameServer) HandleQuery ¶
QueryIP is called from dns.Server->queryIPTimeout
func (*QUICNameServer) Name ¶
func (s *QUICNameServer) Name() string
func (*QUICNameServer) Start ¶
func (s *QUICNameServer) Start() error
type QuicNameServerOption ¶
type QuicNameServerOption struct {
Name string
Destination net.Destination
ClientIp net.IP
Handler i.PacketHandler
IpToDomain *IPToDomain
IPResolver i.IPResolver
RrCache *rrCache
Rewriter MsgRewriter
}
type ResolverGetter ¶
type RrCacheSetting ¶ added in v1.0.2
type RrCacheSetting struct {
Duration uint32
}
type SerialDnsServers ¶ added in v1.2.3
SerialDnsServers queries each DnsServer in order, kicking off the next one after Interval if no definitive answer has arrived. Earlier queries keep running in the background and can still win if it returns a result before the current DnsServer returns a result, so a slow-but-correct upstream is not wasted.
Definitive answer = NOERROR with at least one answer record (returned immediately). NXDOMAIN and NODATA (NOERROR with empty answer) are held as fallbacks and only returned if no server produces a definitive answer. SERVFAIL/REFUSED/transport errors are ignored.
func NewSerialDnsServers ¶ added in v1.2.3
func NewSerialDnsServers(interval time.Duration, servers ...DnsServer) *SerialDnsServers
func (*SerialDnsServers) Close ¶ added in v1.2.3
func (s *SerialDnsServers) Close() error
func (*SerialDnsServers) HandleQuery ¶ added in v1.2.3
func (*SerialDnsServers) Start ¶ added in v1.2.3
func (s *SerialDnsServers) Start() error
type StaticDnsServer ¶
type StaticDnsServer struct {
// contains filtered or unexported fields
}
func NewStaticDnsServer ¶
func NewStaticDnsServer(records []*configs.Record, recordStrings ...string) *StaticDnsServer
Source Files
¶
- concurrent_dns_servers.go
- condition.go
- dns.go
- dns_conn.go
- dns_fake.go
- dns_hijack.go
- dns_server.go
- dns_server_concurrent.go
- dns_server_local.go
- dns_server_serial.go
- dns_server_to_resolver.go
- dnshandler.go
- empty_dns_resolver.go
- go_dns_resolver.go
- internal_dns.go
- ip_to_domain.go
- nameserver_doh.go
- nameserver_quic.go
- pool.go
- rewriter.go
- rrcache.go
- serial_dns_servers.go