Documentation ¶
Index ¶
- Constants
- func WithConn(c *Conn) resolverOption
- func WithDialer(d *net.Dialer) resolverOption
- func WithProfile(p *idna.Profile) resolverOption
- type Address
- type Conn
- func (c *Conn) Call(ctx context.Context, method string, args ...interface{}) *dbus.Call
- func (c *Conn) Close() error
- func (c *Conn) FlushCaches(ctx context.Context) error
- func (c *Conn) GetLink(ctx context.Context, ifindex int) (path string, err error)
- func (c *Conn) RegisterService(ctx context.Context, name string, nameTemplate string, stype string, ...) (svcPath string, err error)
- func (c *Conn) ResetServerFeatures(ctx context.Context) error
- func (c *Conn) ResetStatistics(ctx context.Context) error
- func (c *Conn) ResolveAddress(ctx context.Context, ifindex int, family int, address net.IP, flags uint64) (names []Name, outflags uint64, err error)
- func (c *Conn) ResolveHostname(ctx context.Context, ifindex int, name string, family int, flags uint64) (addresses []Address, canonical string, outflags uint64, err error)
- func (c *Conn) ResolveRecord(ctx context.Context, ifindex int, name string, class dns.Class, rtype dns.Type, ...) (records []ResourceRecord, outflags uint64, err error)
- func (c *Conn) ResolveService(ctx context.Context, ifindex int, name string, stype string, domain string, ...) (srvData []SRVRecord, txtData []TXTRecord, canonicalName string, ...)
- func (c *Conn) RevertLink(ctx context.Context, ifindex int) error
- func (c *Conn) SetLinkDNS(ctx context.Context, ifindex int, addrs []LinkDNS) (err error)
- func (c *Conn) SetLinkDNSEx(ctx context.Context, ifindex int, addrs []LinkDNSEx) error
- func (c *Conn) SetLinkDNSOverTLS(ctx context.Context, ifindex int, mode string) error
- func (c *Conn) SetLinkDNSSEC(ctx context.Context, ifindex int, mode string) error
- func (c *Conn) SetLinkDNSSECNegativeTrustAnchors(ctx context.Context, ifindex int, names []string) error
- func (c *Conn) SetLinkDefaultRoute(ctx context.Context, ifindex int, enable bool) error
- func (c *Conn) SetLinkDomains(ctx context.Context, ifindex int, domains []LinkDomain) error
- func (c *Conn) SetLinkLLMNR(ctx context.Context, ifindex int, mode string) error
- func (c *Conn) SetLinkMulticastDNS(ctx context.Context, ifindex int, mode string) error
- func (c *Conn) UnregisterService(ctx context.Context, svcPath string) error
- type Link
- type LinkDNS
- type LinkDNSEx
- type LinkDomain
- type Name
- type Resolver
- func (r *Resolver) Close() error
- func (r *Resolver) DialContext(ctx context.Context, network string, address string) (net.Conn, error)
- func (r *Resolver) HTTPClient() *http.Client
- func (r *Resolver) HTTPPooledClient() *http.Client
- func (r *Resolver) IsDomainName(name string) (string, bool)
- func (r *Resolver) LookupAddr(ctx context.Context, addr string) (names []string, err error)
- func (r *Resolver) LookupCNAME(ctx context.Context, host string) (string, error)
- func (r *Resolver) LookupHost(ctx context.Context, host string) (addrs []string, err error)
- func (r *Resolver) LookupIP(ctx context.Context, network, host string) ([]net.IP, error)
- func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
- func (r *Resolver) LookupMX(ctx context.Context, name string) ([]*net.MX, error)
- func (r *Resolver) LookupNS(ctx context.Context, name string) ([]*net.NS, error)
- func (r *Resolver) LookupPort(ctx context.Context, network, service string) (port int, err error)
- func (r *Resolver) LookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*net.SRV, err error)
- func (r *Resolver) LookupTXT(ctx context.Context, name string) ([]string, error)
- type ResourceRecord
- func (r ResourceRecord) CNAME() (*dns.CNAME, error)
- func (r ResourceRecord) MX() (*dns.MX, error)
- func (r ResourceRecord) NS() (*dns.NS, error)
- func (r ResourceRecord) SRV() (*dns.SRV, error)
- func (r ResourceRecord) String() string
- func (r ResourceRecord) TXT() (*dns.TXT, error)
- func (r ResourceRecord) Unpack() (dns.RR, error)
- type SRVRecord
- type TXTRecord
Constants ¶
const ( SD_RESOLVED_DNS = uint64(1) << 0 SD_RESOLVED_LLMNR_IPV4 = uint64(1) << 1 SD_RESOLVED_LLMNR_IPV6 = uint64(1) << 2 SD_RESOLVED_MDNS_IPV4 = uint64(1) << 3 SD_RESOLVED_MDNS_IPV6 = uint64(1) << 4 SD_RESOLVED_NO_CNAME = uint64(1) << 5 SD_RESOLVED_NO_TXT = uint64(1) << 6 SD_RESOLVED_NO_ADDRESS = uint64(1) << 7 SD_RESOLVED_NO_SEARCH = uint64(1) << 8 SD_RESOLVED_AUTHENTICATED = uint64(1) << 9 )
ResolveHostname, ResolveAddress, ResolveRecord, ResolveService The four methods above accept and return a 64-bit flags value. In most cases passing 0 is sufficient and recommended. However, the following flags are defined to alter the look-up
Variables ¶
This section is empty.
Functions ¶
func WithConn ¶
func WithConn(c *Conn) resolverOption
WithConn allow you to use a custom systemd-resolved dbus connection.
func WithDialer ¶
WithDialer allow you to use a custom net.Dialer.
func WithProfile ¶
WithProfile allow you to use custom idna.Profile.
Types ¶
type Address ¶
type Address struct { IfIndex int // network interface index Family int // can be either syscall.AF_INET or syscall.AF_INET6 Address net.IP // binary address }
Address represents an address returned by ResolveHostname.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a systemd-resolved dbus connection.
func NewConn ¶
NewConn returns a new and ready to use dbus connection. You must close that connection when you have been done with it.
func (*Conn) Call ¶
Call wraps obj.CallWithContext by using 0 as flags and format the method with the dbus manager interface.
func (*Conn) GetLink ¶
GetLink takes a network interface index and returns the object path to the org.freedesktop.resolve1.Link object corresponding to it. ctx: Context to use ifindex: The network interface index to get link for
func (*Conn) RegisterService ¶
func (c *Conn) RegisterService(ctx context.Context, name string, nameTemplate string, stype string, svcPort uint16, svcPriority uint16, svcWeight uint16, txtData []TXTRecord) (svcPath string, err error)
RegisterService
func (*Conn) ResetServerFeatures ¶
ResetServerFeatures
func (*Conn) ResetStatistics ¶
ResetStatistics resets the various statistics counters that systemd-resolved maintains to zero.
func (*Conn) ResolveAddress ¶
func (c *Conn) ResolveAddress(ctx context.Context, ifindex int, family int, address net.IP, flags uint64) (names []Name, outflags uint64, err error)
ResolveAddress takes a DNS resource record (RR) type, class and name and retrieves the full resource record set (RRset), including the RDATA, for it. ctx: Context to use ifindex: Network interface index where to look (0 means any) family: Address family (syscall.AF_INET, syscall.AF_INET6) address: the binary address (4 or 16 bytes) flags: Input flags parameter
func (*Conn) ResolveHostname ¶
func (c *Conn) ResolveHostname(ctx context.Context, ifindex int, name string, family int, flags uint64) (addresses []Address, canonical string, outflags uint64, err error)
ResolveHostname takes a hostname and resolves it to one or more IP addresses. ctx: Context to use ifindex: Network interface index where to look (0 means any) name: Hostname family: Which address family to look for (syscall.AF_UNSPEC, syscall.AF_INET, syscall.AF_INET6) flags: Input flags parameter
func (*Conn) ResolveRecord ¶
func (c *Conn) ResolveRecord(ctx context.Context, ifindex int, name string, class dns.Class, rtype dns.Type, flags uint64) (records []ResourceRecord, outflags uint64, err error)
ResolveRecord takes a DNS resource record (RR) type, class and name, and retrieves the full resource record set (RRset), including the RDATA, for it. ctx: Context to use ifindex: Network interface index where to look (0 means any) name: Specifies the RR domain name to look up class: 16-bit dns class rtype: 16-bit dns type flags: Input flags parameter
func (*Conn) ResolveService ¶
func (c *Conn) ResolveService(ctx context.Context, ifindex int, name string, stype string, domain string, family int, flags uint64) (srvData []SRVRecord, txtData []TXTRecord, canonicalName string, canonicalType string, canonicalDomain string, outflags uint64, err error)
ResolveService resolves a DNS SRV service record, as well as the hostnames referenced in it and possibly an accompanying DNS-SD TXT record containing additional service metadata. ctx: Context to use ifindex: Network interface index where to look (0 means any) name: the service name stype: the service type (eg: _webdav._tcp) domain: the service domain family: Address family (syscall.AF_UNSPEC, syscall.AF_INET, syscall.AF_INET6) flags: Input flags parameter
func (*Conn) RevertLink ¶
RevertLink reverts all per-link settings to the defaults on a specific network interface. ctx: Context to use ifindex: The network interface index.
func (*Conn) SetLinkDNS ¶
SetLinkDNS sets the DNS servers to use on a specific interface. ctx: Context to use ifindex: The network interface index to set addrs: array of DNS server IP address records.
func (*Conn) SetLinkDNSEx ¶
SetLinkDNSEx is similar to SetLinkDNS(), but allows an IP port (instead of the default 53) and DNS name to be specified for each DNS server. The server name is used for Server Name Indication (SNI), which is useful when DNS-over-TLS is used. ctx: Context to use ifindex: The network interface index addrs: array of DNS server IP address records.
func (*Conn) SetLinkDNSOverTLS ¶
SetLinkDNSOverTLS enables or disables enables or disables DNS-over-TLS on a specific network interface. ctx: Context to use ifindex: The network interface index mode: either empty or one of "yes", "no", or "opportunistic"
func (*Conn) SetLinkDNSSEC ¶
SetLinkDNSSEC enables or disables DNSSEC validation on a specific network interface. ctx: Context to use ifindex: The network interface index mode: either empty or one of "yes", "no", or "allow-downgrade"
func (*Conn) SetLinkDNSSECNegativeTrustAnchors ¶
func (c *Conn) SetLinkDNSSECNegativeTrustAnchors(ctx context.Context, ifindex int, names []string) error
SetLinkDNSSECNegativeTrustAnchors configures DNSSEC Negative Trust Anchors (NTAs) for a specific network interface. ctx: Context to use ifindex: The network interface index names: array of domains
func (*Conn) SetLinkDefaultRoute ¶
SetLinkDefaultRoute specifies whether the link shall be used as the default route for name queries ctx: Context to use ifindex: The network interface index enable: enable/disable link as default route.
func (*Conn) SetLinkDomains ¶
SetLinkDomains sets the search and routing domains to use on a specific network interface for DNS look-ups. ctx: Context to use ifindex: The network interface index domains: array of domains
func (*Conn) SetLinkLLMNR ¶
SetLinkLLMNR enables or disables LLMNR support on a specific network interface. ctx: Context to use ifindex: The network interface index mode: either empty or one of "yes", "no" or "resolve".
func (*Conn) SetLinkMulticastDNS ¶
SetLinkMulticastDNS enables or disables MulticastDNS support on a specific interface. ctx: Context to use ifindex: The network interface index mode: either empty or one of "yes", "no" or "resolve".
type LinkDNS ¶
type LinkDNS struct { Family int // can be either syscall.AF_INET or syscall.AF_INET6 Address net.IP // binary address }
LinkDNS represents a DNS server address to use in SetLinkDNS method.
type LinkDomain ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver represents the systemd-resolved resolver throught dbus connection.
func NewResolver ¶
NewResolver returns a new systemd Resolver with an initialized dbus connection. it's up to you to close that connection when you have been done with the Resolver.
func (*Resolver) Close ¶
Close closes the current dbus connection. You need to close the connection when you've done with it.
func (*Resolver) DialContext ¶
func (r *Resolver) DialContext(ctx context.Context, network string, address string) (net.Conn, error)
DialContext resolves address using systemd-network and use internal dialer with the resolved ip address. It is useful when it comes to integration with go standard library.
func (*Resolver) HTTPClient ¶
HTTPClient returns a new http.Client with systemd-resolved as resolver and idle connections + keepalives disabled.
func (*Resolver) HTTPPooledClient ¶
HTTPPooledClient returns a new http.Client with systemd-resolved as resolver and similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).
func (*Resolver) IsDomainName ¶
IsDomainName tries to convert name to ASCII (IANA conversion) if name is not a strict domain name (see RFC 1035) It returns false if name is not a domain before and after ASCII conversion. It uses isDomainName from go standard library.
func (*Resolver) LookupAddr ¶
LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address.
func (*Resolver) LookupCNAME ¶
LookupCNAME returns the canonical name for the given host.
func (*Resolver) LookupHost ¶
LookupHost looks up the given host using the systemd-resolved resolver. It returns a slice of that host's addresses.
func (*Resolver) LookupIP ¶
LookupIP looks up host for the given network using the systemd-resolved resolver. It returns a slice of that host's IP addresses of the type specified by network. network must be one of "ip", "ip4" or "ip6".
func (*Resolver) LookupIPAddr ¶
LookupIPAddr looks up host using the systemd-resolved resolver. It returns a slice of that host's IPv4 and IPv6 addresses.
func (*Resolver) LookupMX ¶
LookupMX returns the DNS MX records for the given domain name sorted by preference.
func (*Resolver) LookupPort ¶
LookupPort looks up the port for the given network and service.
func (*Resolver) LookupSRV ¶
func (r *Resolver) LookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*net.SRV, err error)
LookupSRV tries to resolve an SRV query of the given service, protocol, and domain name. The proto is "tcp" or "udp". The returned records are sorted by priority.
type ResourceRecord ¶
type ResourceRecord struct { IfIndex int // network interface index Type dns.Type // dns type Class dns.Class // dns class // The raw RR data starts with the RR's domain name, in the original casing, followed by the RR type, class, // TTL and RDATA, in the binary format documented in RFC 1035. For RRs that support name compression in the payload // (such as MX or PTR), the compression is expanded in the returned data. Data []byte }
ResourceRecord represents a DNS RR as it returned by by ResolveRecord.
func (ResourceRecord) CNAME ¶
func (r ResourceRecord) CNAME() (*dns.CNAME, error)
CNAME unpacks a ResourceRecord to *dns.CNAME.
func (ResourceRecord) MX ¶
func (r ResourceRecord) MX() (*dns.MX, error)
MX unpacks a ResourceRecord to *dns.MX.
func (ResourceRecord) NS ¶
func (r ResourceRecord) NS() (*dns.NS, error)
NS unpacks a ResourceRecord to *dns.NS.
func (ResourceRecord) SRV ¶
func (r ResourceRecord) SRV() (*dns.SRV, error)
SRV unpacks a ResourceRecord to *dns.SRV.
func (ResourceRecord) String ¶
func (r ResourceRecord) String() string