resolved

package
v5.2.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
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

func WithDialer(d *net.Dialer) resolverOption

WithDialer allow you to use a custom net.Dialer.

func WithProfile

func WithProfile(p *idna.Profile) resolverOption

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.

func (Address) String

func (a Address) String() string

type Conn

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

Conn represents a systemd-resolved dbus connection.

func NewConn

func NewConn() (*Conn, error)

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

func (c *Conn) Call(ctx context.Context, method string, args ...interface{}) *dbus.Call

Call wraps obj.CallWithContext by using 0 as flags and format the method with the dbus manager interface.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the current dbus connection.

func (*Conn) FlushCaches

func (c *Conn) FlushCaches(ctx context.Context) error

FlushCaches

func (c *Conn) GetLink(ctx context.Context, ifindex int) (path string, err error)

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

func (c *Conn) ResetServerFeatures(ctx context.Context) error

ResetServerFeatures

func (*Conn) ResetStatistics

func (c *Conn) ResetStatistics(ctx context.Context) error

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 (c *Conn) RevertLink(ctx context.Context, ifindex int) error

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

func (c *Conn) SetLinkDNS(ctx context.Context, ifindex int, addrs []LinkDNS) (err error)

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

func (c *Conn) SetLinkDNSEx(ctx context.Context, ifindex int, addrs []LinkDNSEx) error

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

func (c *Conn) SetLinkDNSOverTLS(ctx context.Context, ifindex int, mode string) error

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

func (c *Conn) SetLinkDNSSEC(ctx context.Context, ifindex int, mode string) error

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

func (c *Conn) SetLinkDefaultRoute(ctx context.Context, ifindex int, enable bool) error

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

func (c *Conn) SetLinkDomains(ctx context.Context, ifindex int, domains []LinkDomain) error

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

func (c *Conn) SetLinkLLMNR(ctx context.Context, ifindex int, mode string) error

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

func (c *Conn) SetLinkMulticastDNS(ctx context.Context, ifindex int, mode string) error

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".

func (*Conn) UnregisterService

func (c *Conn) UnregisterService(ctx context.Context, svcPath string) error

UnregisterService

type Link struct {
	// contains filtered or unexported fields
}
func NewLink(c *Conn, path string) Link

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 LinkDNSEx

type LinkDNSEx struct {
	Family  int    // can be either syscall.AF_INET or syscall.AF_INET6
	Address net.IP // binary address
	Port    uint16 // the port number
	Name    string // the DNS Name
}

type LinkDomain

type LinkDomain struct {
	Domain        string // the domain name
	RoutingDomain bool   // whether the specified domain shall be used as a search domain (false), or just as a routing domain (true).
}

type Name

type Name struct {
	IfIndex  int    // network interface index
	Hostname string // hostname
}

Name represents a hostname returned by ResolveAddress.

func (Name) String

func (n Name) String() string

type Resolver

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

Resolver represents the systemd-resolved resolver throught dbus connection.

func NewResolver

func NewResolver(opts ...resolverOption) (*Resolver, error)

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

func (r *Resolver) Close() error

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

func (r *Resolver) HTTPClient() *http.Client

HTTPClient returns a new http.Client with systemd-resolved as resolver and idle connections + keepalives disabled.

func (*Resolver) HTTPPooledClient

func (r *Resolver) HTTPPooledClient() *http.Client

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

func (r *Resolver) IsDomainName(name string) (string, bool)

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

func (r *Resolver) LookupAddr(ctx context.Context, addr string) (names []string, err error)

LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address.

func (*Resolver) LookupCNAME

func (r *Resolver) LookupCNAME(ctx context.Context, host string) (string, error)

LookupCNAME returns the canonical name for the given host.

func (*Resolver) LookupHost

func (r *Resolver) LookupHost(ctx context.Context, host string) (addrs []string, err error)

LookupHost looks up the given host using the systemd-resolved resolver. It returns a slice of that host's addresses.

func (*Resolver) LookupIP

func (r *Resolver) LookupIP(ctx context.Context, network, host string) ([]net.IP, error)

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

func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)

LookupIPAddr looks up host using the systemd-resolved resolver. It returns a slice of that host's IPv4 and IPv6 addresses.

func (*Resolver) LookupMX

func (r *Resolver) LookupMX(ctx context.Context, name string) ([]*net.MX, error)

LookupMX returns the DNS MX records for the given domain name sorted by preference.

func (*Resolver) LookupNS

func (r *Resolver) LookupNS(ctx context.Context, name string) ([]*net.NS, error)

LookupNS returns the DNS NS records for the given domain name.

func (*Resolver) LookupPort

func (r *Resolver) LookupPort(ctx context.Context, network, service string) (port int, err error)

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.

func (*Resolver) LookupTXT

func (r *Resolver) LookupTXT(ctx context.Context, name string) ([]string, error)

LookupTXT returns the DNS TXT records for the given domain name.

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

func (ResourceRecord) TXT

func (r ResourceRecord) TXT() (*dns.TXT, error)

TXT unpacks a ResourceRecord to *dns.TXT.

func (ResourceRecord) Unpack

func (r ResourceRecord) Unpack() (dns.RR, error)

Unpack unpacks a ResourceRecord to dns.RR interface.

type SRVRecord

type SRVRecord struct {
	Priority  uint16
	Weight    uint16
	Port      uint16
	Hostname  string
	Addresses []Address
	CNAME     string
}

SRVRecord represents an service record as it returned by ResolveService.

func (SRVRecord) String

func (r SRVRecord) String() string

type TXTRecord

type TXTRecord []byte

TXTRecord represents a raw TXT RR string

func (TXTRecord) String

func (r TXTRecord) String() string

Jump to

Keyboard shortcuts

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