Documentation
¶
Overview ¶
Package upstream implements DNS clients for all known DNS encryption protocols.
Index ¶
Constants ¶
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/quic-go/quic-go/internal/protocol#MaxKeepAliveInterval. // // TODO(ameshkov): Consider making it configurable. QUICKeepAlivePeriod = time.Second * 20 )
const ErrNoUpstreams errors.Error = "no upstream specified"
ErrNoUpstreams is returned from the methods that expect at least a single upstream to work with when no upstreams specified.
const NextProtoDQ = "doq"
NextProtoDQ is the ALPN token for DoQ. During the connection establishment, DNS/QUIC support is indicated by selecting the ALPN token "doq" in the crypto handshake. The current draft version is https://datatracker.ietf.org/doc/rfc9250/.
Variables ¶
var CipherSuites []uint16
CipherSuites is a custom list of TLSv1.2 ciphers.
var DefaultHTTPVersions = []HTTPVersion{HTTPVersion11, HTTPVersion2}
DefaultHTTPVersions is the list of HTTPVersion that we use by default in the DNS-over-HTTPS client.
var RootCAs *x509.CertPool
RootCAs is the CertPool that must be used by all upstreams. Redefining RootCAs makes sense on iOS to overcome the 15MB memory limit of the NEPacketTunnelProvider. TODO(ameshkov): remove this and replace with an upstream option.
Functions ¶
Types ¶
type ExchangeAllResult ¶ added in v0.24.0
type ExchangeAllResult struct { // Resp is the response DNS request resolved into. Resp *dns.Msg // Upstream is the upstream that successfully resolved the request. Upstream Upstream }
ExchangeAllResult is the successful result of ExchangeAll for a single upstream.
func ExchangeAll ¶ added in v0.24.0
func ExchangeAll(ups []Upstream, req *dns.Msg) (res []ExchangeAllResult, err error)
ExchangeAll retunrs the responses from all of u. It returns an error only if all upstreams failed to exchange the request.
type HTTPVersion ¶ added in v0.45.0
type HTTPVersion string
HTTPVersion is an enumeration of the HTTP versions that we support. Values that we use in this enumeration are also used as ALPN values.
const ( // HTTPVersion11 is HTTP/1.1. HTTPVersion11 HTTPVersion = "http/1.1" // HTTPVersion2 is HTTP/2. HTTPVersion2 HTTPVersion = "h2" // HTTPVersion3 is HTTP/3. HTTPVersion3 HTTPVersion = "h3" )
type Options ¶ added in v0.11.0
type Options struct { // Bootstrap is a list of DNS servers to be used to resolve // DNS-over-HTTPS/DNS-over-TLS hostnames. Plain DNS, DNSCrypt, or // DNS-over-HTTPS/DNS-over-TLS with IP addresses (not hostnames) could be // used. Bootstrap []string // Timeout is the default upstream timeout. It's also used as a timeout for // bootstrap DNS requests. Zero value disables the timeout. Timeout time.Duration // List of IP addresses of the upstream DNS server. If not empty, bootstrap // DNS servers won't be used at all. ServerIPAddrs []net.IP // HTTPVersions is a list of HTTP versions that should be supported by the // DNS-over-HTTPS client. If not set, HTTP/1.1 and HTTP/2 will be used. HTTPVersions []HTTPVersion // VerifyServerCertificate is used to set the VerifyPeerCertificate property // of the *tls.Config for DNS-over-HTTPS, DNS-over-QUIC, and DNS-over-TLS. VerifyServerCertificate func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error // VerifyConnection is used to set the VerifyConnection property // of the *tls.Config for DNS-over-HTTPS, DNS-over-QUIC, and DNS-over-TLS. VerifyConnection func(state tls.ConnectionState) error // VerifyDNSCryptCertificate is the callback the DNSCrypt server certificate // will be passed to. It's called in dnsCrypt.exchangeDNSCrypt. // Upstream.Exchange method returns any error caused by it. VerifyDNSCryptCertificate func(cert *dnscrypt.Cert) error // QUICTracer is an optional object that allows tracing every QUIC // connection and logging every packet that goes through. QUICTracer logging.Tracer // InsecureSkipVerify disables verifying the server's certificate. InsecureSkipVerify bool // PreferIPv6 tells the bootstrapper to prefer IPv6 addresses for an // upstream. PreferIPv6 bool }
Options for AddressToUpstream func. With these options we can configure the upstream properties.
type Resolver ¶ added in v0.10.0
Resolver is an alias for bootstrap.Resolver to avoid the import cycle.
func NewResolver ¶ added in v0.10.0
NewResolver creates a Resolver. resolverAddress should be either a plain IP address or empty. If it is empty, the default net.Resolver is used, and sorting the resolved addresses is the caller's responsibility. Otherwise, it creates an Upstream using opts.
TODO(e.burkov): Require resolverAddress not being empty and rename into NewUpstreamResolver.
type Upstream ¶
type Upstream interface { // Exchange sends the DNS query m to this upstream and returns the response // that has been received or an error if something went wrong. Exchange(m *dns.Msg) (*dns.Msg, error) // Address returns the address of the upstream DNS resolver. Address() string // Closer used to close the upstreams properly. Exchange shouldn't be // called after calling Close. io.Closer }
Upstream is an interface for a DNS resolver.
func AddressToUpstream ¶
AddressToUpstream converts addr to an Upstream instance:
- 8.8.8.8:53 or udp://dns.adguard.com for plain DNS;
- tcp://8.8.8.8:53 for plain DNS-over-TCP;
- tls://1.1.1.1 for DNS-over-TLS;
- https://dns.adguard.com/dns-query for DNS-over-HTTPS;
- h3://dns.google for DNS-over-HTTPS that only works with HTTP/3;
- sdns://... for DNS stamp, see https://dnscrypt.info/stamps-specifications.
opts are applied to the u. nil is a valid value for opts.