dnsx

package
v0.0.0-...-b33dbb8 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MPL-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Copyright (c) 2022 RethinkDNS and its authors.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Index

Constants

View Source
const (
	Start          = x.Start
	Complete       = x.Complete
	SendFailed     = x.SendFailed
	NoResponse     = x.NoResponse
	BadQuery       = x.BadQuery
	BadResponse    = x.BadResponse
	InternalError  = x.InternalError
	TransportError = x.TransportError
	ClientError    = x.ClientError
	Paused         = x.Paused
	Unpaused       = x.Unpaused
	DEnd           = x.DEnd
	Unknown        = x.Unknown
)
View Source
const (
	EB32 = x.EB32
	EB64 = x.EB64
)

encoding type, base32 or base64

View Source
const (
	// DNS transport types
	DOH      = x.DOH
	DNSCrypt = x.DNSCrypt
	DNS53    = x.DNS53
	DOT      = x.DOT
	ODOH     = x.ODOH

	// DNS decorators
	CT = x.CT

	// DNS transport IDs
	Goos      = x.Goos
	System    = x.System
	Local     = x.Local
	Default   = x.Default
	Preferred = x.Preferred
	Preset    = x.Preset
	Fixed     = x.Fixed
	BlockFree = x.BlockFree
	Bootstrap = x.Bootstrap
	BlockAll  = x.BlockAll
	Alg       = x.Alg
	DcProxy   = x.DcProxy
	Plus      = x.Plus
	IpMapper  = x.IpMapper
	NoDNS     = ""

	// DNS request origin indicator:
	// OriginInternal flags requests by firestack or its owner uid.
	OriginInternal = x.OriginInternal
	// OriginTunnel flags requests by tunnel read (presumably from another app,
	// or firestack or its owner uid if Loopback mode is turned on).
	OriginTunnel = x.OriginTunnel

	// preferred network to use with t.Query
	NetTypeUDP = "udp"
	NetTypeTCP = "tcp"
	// preferred forwarding network, if any
	// ipn.Base is treated as a no-proxy
	NetBaseProxy = x.Base
	NetAutoProxy = x.Auto
	NetNoProxy   = x.Block
	NetExitProxy = x.Exit

	// pseudo transport ID to tag dns64 responses
	AlgDNS64 = "dns64"
)
View Source
const AnyResolver = "__anyresolver"
View Source
const Local464Resolver = "__local464" // preset "forced" DNS64/NAT64
View Source
const Rfc7050WKN = "ipv4only.arpa."

ref: datatracker.ietf.org/doc/html/rfc8880

View Source
const StdlibResolver = "__stdlib" // "net.DefaultResolver" dnsx.Goos
View Source
const UnderlayResolver = "__underlay" // used by transport dnsx.System

Variables

View Source
var (
	ErrNoAns      = errNoAnswer
	ErrNoHost     = errors.New("no hostname")
	ErrNoNet      = errors.New("unknown network")
	ErrQueryParse = errors.New("cannot parse dns query")
)
View Source
var (
	ErrNotDefaultTransport = errors.New("dns: not a default transport")
	ErrNoDcProxy           = errors.New("dns: no dnscrypt-proxy")
	ErrNoProxyProvider     = errors.New("dns: no proxy provider")
	ErrNoProxyDNS          = errors.New("dns: no proxy")
	ErrAddFailed           = errors.New("dns: add failed")
)
View Source
var (
	NoIPPort []netip.AddrPort = nil
)

Functions

func CanUseProxy

func CanUseProxy(id string) bool

CanUseProxy returns true if transport with id can be safely proxied over another network. For example, Goos, Local, System cannot be. Preset is a transport that needn't be. Default and Bootstrap can be proxied if they are not mapped to System/Goos, or if proxying is allowed (via setting) for Default.

func ChooseHealthyProxy

func ChooseHealthyProxy(who, proto string, ipps []netip.AddrPort, pids []string, px ipn.ProxyProvider) (pid string)

func ChooseHealthyProxyHostPort

func ChooseHealthyProxyHostPort(who, proto string, host string, port uint16, pids []string, px ipn.ProxyProvider) (pid string)

func CryptoPrefix

func CryptoPrefix(nopki, ech bool) string

func Csv2Netip

func Csv2Netip(csv string) (ips []netip.Addr)

func Fastest

func Fastest(a, b Transport) int

func GetIPCsv

func GetIPCsv(t Transport) string

GetIPCsv converts a slice of AddrPort to a csv string.

func IsAutoProxy

func IsAutoProxy(pid string) bool

return true ipn.Auto

func IsEncrypted

func IsEncrypted(t Transport) bool

func IsLocalProxy

func IsLocalProxy(pid string) bool

meta proxies like pid == Auto are not considered local.

func Netip2Csv

func Netip2Csv(ips []netip.Addr) (csv string)

func NewDNSGateway

func NewDNSGateway(pctx context.Context, fakeaddrs []netip.AddrPort, outer RdnsResolver, dns64 NatPt) (t *dnsgateway)

NewDNSGateway returns a DNS ALG, ready for use.

func NewResolver

func NewResolver(pctx context.Context, fakeaddrs string, dtr x.DNSTransport, l x.DNSListener, pt NatPt) *resolver

func NewXdomains

func NewXdomains(tid, uid string, pri []string, ttl time.Time) *xdomains

NewXdomains returns a new xdomains object keyed by tid+uid.

func NewXips

func NewXips(tid, uid string, pri, sec []netip.Addr, ttl time.Time) *xips

NewXips returns a new xips object with primary and secondary ips. May return nil if tid is empty.

func OverrideStatusFrom

func OverrideStatusFrom(p x.Proxy) (bool, int32)

func Perf

func Perf(t Transport, mid string, n, seconds int32) *x.DNSMeasurement

Perf measures DNS transport performance by sending batches of n parallel queries for the specified number of seconds. One batch of n queries completes before the next batch starts. Returns a DNSMeasurement with latency statistics (P50, P95, min, max, jitter) and success rate.

func RegisterAddrs

func RegisterAddrs(id, hostname string, ipps []string) (ok bool)

RegisterAddrs registers IP ports with all dialers for a given hostname. If id is dnsx.Bootstrap, the hostname is "protected" from re-resolutions. hostname is a domain name, and as a special case, can be protect.Selfhost or protect.Systemhost. See also: dialers.For.

func Req

func Req(t Transport, network string, q *dns.Msg, smm *x.DNSSummary) (*dns.Msg, error)

Req sends q to transport t and returns the answer, if any; errors are unset if answer is not servfail or empty; smm, the in/out parameter, is dns summary as got from t.

func Status2Str

func Status2Str(status int32) string

func TransportPrefix

func TransportPrefix(id string) string

Types

type Cacher

type Cacher interface {
	Transport
	Clear()
}

type DNS64

type DNS64 interface {
	// Add64 registers DNS64 resolver f to id.
	Add64(id string) bool
	// Remove64 deregisters any current resolver from id.
	Remove64(id string) bool
	// ResetNat64Prefix sets the NAT64 prefix for transport id to ip6prefix.
	ResetNat64Prefix(ip6prefix string) bool
	// D64 synthesizes ans64 (AAAA) from ans6 if required, using resolver f.
	// Returned ans64 is nil if no DNS64 synthesis is needed (not AAAA).
	// Returned ans64 is ans6 if it already has AAAA records.
	D64(network, id, uid string, ans6 *dns.Msg) *dns.Msg
}

type Gateway

type Gateway interface {
	// given an alg or real ip, retrieves assoc real ips as csv, if any
	X(maybeAlg netip.Addr, uid string, tids ...string) (realips []netip.Addr, undidAlg bool)
	// given an alg or real ip, retrieves assoc dns names as csv, if any
	PTR(maybeAlg netip.Addr, uid, tid string, force bool) (domaincsv string, didForce bool)
	// given domain, retrieve assoc alg ips or real ips as csv, if any
	RESOLV(domain, uid, tid string) []netip.Addr
	// given an alg or real ip, retrieve assoc blocklists as csv, if any
	RDNSBL(maybeAlg netip.Addr) (blocklistcsv string)

	// S reveals internal state for debugging
	S() string
	// contains filtered or unexported methods
}

type MDNSTransport

type MDNSTransport interface {
	Transport
	RefreshProto(protos string)
}

type NAT64

type NAT64 interface {
	// Returns true if ip6 is a NAT64 address from transport id.
	IsNat64(id string, ip6 netip.Addr) bool
	// Returns NAT64 prefixes as csv for transport id, if any.
	GetNat64(id string) (csv string)
	// Translates ip6 to IPv4 using the NAT64 prefix for transport id.
	// As a special case, ip6 is zero addr, output is always IPv4 zero addr.
	X64(id string, ip6 netip.Addr) (ip4 netip.Addr)
	// Translates ip4 to IPv6 using the NAT64 prefix for transport id.
	// As a special case, ip4 is zero addr, output is always IPv6 zero addr.
	X46(id string, ip4 netip.Addr) (ip6 netip.Addr)
}

type NatPt

type NatPt interface {
	DNS64
	NAT64
}

type QueryError

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

func NewBadQueryError

func NewBadQueryError(err error) *QueryError

func NewBadResponseQueryError

func NewBadResponseQueryError(err error) *QueryError

func NewClientQueryError

func NewClientQueryError(err error) *QueryError

with http, for 4xx errors

func NewEndQueryError

func NewEndQueryError() *QueryError

func NewInternalQueryError

func NewInternalQueryError(err error) *QueryError

func NewNoResponseQueryError

func NewNoResponseQueryError(err error) *QueryError

func NewPausedQueryError

func NewPausedQueryError() *QueryError

func NewSendFailedQueryError

func NewSendFailedQueryError(err error) *QueryError

func NewTransportQueryError

func NewTransportQueryError(err error) *QueryError

with http, for 5xx errors

func WillErr

func WillErr(t Transport) *QueryError

WillErr fetches current status and returns if t will error out due to dnsx.DEnd or dnsx.Paused states. It always calls into t.Status(), which has a chance to rectify if its entered incorrect states, if any.

func (*QueryError) Error

func (e *QueryError) Error() string

func (*QueryError) Status

func (e *QueryError) Status() int32

func (*QueryError) String

func (e *QueryError) String() string

func (*QueryError) Unwrap

func (e *QueryError) Unwrap() error

type RDNS

type RDNS interface {
	x.RDNS
	OnDeviceBlock() bool // Mode
	// contains filtered or unexported methods
}

type RdnsResolver

type RdnsResolver interface {
	x.RDNSResolver
	// IsDnsAddrPort returns true if the ip:port is resolver's fake endpoint
	IsDnsAddrPort(ipport netip.AddrPort) bool
	// IsDnsAddr returns true if the ip is resolver's fake endpoint
	IsDnsAddr(ip netip.Addr) bool
	// contains filtered or unexported methods
}

type Resolver

type Resolver interface {
	x.DNSTransportMult
	x.DNSStatusProvider
	TransportProviderInternal
	TransportMultProviderInternal
	ResolverSelf
	RdnsResolver
	NatPt

	// Serve reads DNS query from conn and writes DNS answer to conn.
	// fid is the flow ID that spawned this DNS query, if Origin is "tunnel".
	Serve(proto string, conn protect.Conn, uid, fid string) (rx, tx int64, errs []error)

	// Gateway implements a DNS ALG transport
	Gateway() Gateway
	// MDNS returns the mdns transport, if available; error otherwise.
	MDNS() (MDNSTransport, error)

	// StopAll stops all transports.
	StopAll()

	// S reveals internal state for debugging
	S() string
}

type ResolverSelf

type ResolverSelf interface {
	ipmap.IPMapper
	// contains filtered or unexported methods
}

ResolverSelf is for internal resolution needs.

type Transport

type Transport interface {
	x.DNSTransport
	// Given a DNS query (including ID), returns a DNS response with matching
	// ID, or an error if no response was received.  The error may be accompanied
	// by a SERVFAIL response if appropriate.
	Query(network string, q *dns.Msg, summary *x.DNSSummary) (*dns.Msg, error)
	// IPPorts returns all ip:ports of this server.
	IPPorts() []netip.AddrPort
	// Relaying returns true if this transport always uses a relay (proxy).
	Relaying() bool
	// Stop closes the transport.
	Stop() error
}

Transport represents a DNS query transport. This interface is exported by gobind, so it has to be very simple.

func Categorize

func Categorize(ts []Transport) (remote, rerecov, best, preferred, recoverables, errored, ended []Transport)

func NewCachingTransport

func NewCachingTransport(pctx context.Context, t Transport, ttl time.Duration) Transport

func NewDefaultCachingTransport

func NewDefaultCachingTransport(t Transport) Transport

func NewPlusTransport

func NewPlusTransport(ctx context.Context, r TransportProviderInternal, ts ...Transport) Transport

type TransportMult

type TransportMult interface {
	x.DNSTransportMult
	Transport
	TransportProviderInternal
}

TransportMult is a hybrid: transport and a multi-transport.

type TransportMultProviderInternal

type TransportMultProviderInternal interface {
	x.DNSTransportMultProvider
	// GetMultInternal returns multi-transport, if available
	GetMultInternal(id string) (TransportMult, error)
}

type TransportProviderInternal

type TransportProviderInternal interface {
	x.DNSTransportProvider
	// GetInternal returns the internal transport interface for the given ID.
	GetInternal(id string) (Transport, error)
}

Jump to

Keyboard shortcuts

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