dns

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package dns provides DNS-related utilities, including DNS-over-HTTPS and IP reverse lookups.

Index

Constants

View Source
const DefaultTTL uint32 = 60

DefaultTTL is the DNS TTL used when a record does not specify one.

Variables

This section is empty.

Functions

func BlocklistLookupAddr

func BlocklistLookupAddr(addr string) (bool, error)

BlocklistLookupAddr checks if the given IP address is listed in the Spamhaus blocklist.

func ReverseIP

func ReverseIP(addr string) (string, error)

ReverseIP returns the reverse DNS notation for an IP address.

Types

type DNSRecord added in v0.63.0

type DNSRecord interface {
	// RecordPrefix returns the DNS owner label prefix relative to the base domain,
	// e.g. "_dmarc." or "" for the apex.
	RecordPrefix() string
	// RecordType returns the DNS record type string, e.g. "TXT" or "MX".
	RecordType() string
	// RecordValue returns the wire-ready record value for insertion into a
	// CoreDNS template answer line.
	RecordValue() string
}

DNSRecord is the canonical interface for DNS record types across this module. Existing smtp sub-package records implement it by structural compatibility; the coredns package imports this definition rather than defining its own.

type DOHClient

type DOHClient struct {
	Client *http.Client
	URL    *url.URL
}

DOHClient describes a DNS over HTTPS client.

func NewDOHClient

func NewDOHClient(url *url.URL) *DOHClient

NewDOHClient creates a new DNS over HTTPS client with the provided URL.

func (*DOHClient) Exchange

func (c *DOHClient) Exchange(msg *dns.Msg) (*dns.Msg, error)

Exchange performs a DNS query using DNS over HTTPS.

type TLSARecord added in v0.66.0

type TLSARecord struct {
	// CertPathTemplate is a Go template string (expanded against the data
	// passed to Render) for the path to the PEM-encoded certificate file
	// this record's value is derived from.
	CertPathTemplate string `mapstructure:"cert-path-template"`

	// Name is the DNS owner label this record targets, e.g. "mx" for a TLSA
	// record on a mail exchanger.
	Name string `mapstructure:"name"`

	// Port and Proto identify the service this TLSA record applies to,
	// e.g. Port 25, Proto "tcp" for SMTP.
	Port  uint8  `mapstructure:"port"`
	Proto string `mapstructure:"proto"`

	// Selector, MatchingType, and Usage are the TLSA record's own fields,
	// as defined in RFC 6698.
	Selector     uint8 `mapstructure:"selector"`
	MatchingType uint8 `mapstructure:"matching-type"`
	Usage        uint8 `mapstructure:"usage"`

	AutoRefresh              bool  `mapstructure:"auto-refresh"`
	AutoRefreshPeriodSeconds int64 `mapstructure:"auto-refresh-period-seconds"`
	// contains filtered or unexported fields
}

TLSARecord is a TLSA/DANE record whose value is computed from the X.509 certificate at a templated file path. Content is fetched lazily on first Render and, if AutoRefresh is set, kept fresh afterward by a background ticker running every AutoRefreshPeriodSeconds -- see refreshableContent.

func (*TLSARecord) Empty added in v0.66.0

func (r *TLSARecord) Empty() bool

Empty reports whether this record has no configuration and has not yet fetched any content.

func (*TLSARecord) RecordPrefix added in v0.66.0

func (r *TLSARecord) RecordPrefix() string

func (*TLSARecord) RecordType added in v0.66.0

func (r *TLSARecord) RecordType() string

func (*TLSARecord) RecordValue added in v0.66.0

func (r *TLSARecord) RecordValue() string

func (*TLSARecord) Render added in v0.66.0

func (r *TLSARecord) Render(data any) error

func (*TLSARecord) String added in v0.66.0

func (r *TLSARecord) String() string

type TXTRecord added in v0.63.0

type TXTRecord struct {
	// Name is the DNS owner label relative to the base domain. "" = apex.
	Name string `mapstructure:"name" json:"name,omitempty"`
	// Value is a Go template string for the TXT record content (e.g. "v=spf1 {{.OutboundIPList}} -all").
	Value string `mapstructure:"value" json:"value"`
	// TTL is the DNS TTL in seconds advertised to resolvers. Zero uses DefaultTTL.
	TTL uint32 `mapstructure:"ttl" json:"ttl,omitempty"`
}

TXTRecord is a generic DNS TXT record with optional Go template expansion in Value.

func (*TXTRecord) Empty added in v0.63.0

func (r *TXTRecord) Empty() bool

func (*TXTRecord) RecordPrefix added in v0.63.0

func (r *TXTRecord) RecordPrefix() string

func (*TXTRecord) RecordTTL added in v0.63.0

func (r *TXTRecord) RecordTTL() uint32

RecordTTL returns the TTL to use for this record, falling back to DefaultTTL.

func (*TXTRecord) RecordType added in v0.63.0

func (r *TXTRecord) RecordType() string

func (*TXTRecord) RecordValue added in v0.63.0

func (r *TXTRecord) RecordValue() string

func (*TXTRecord) Render added in v0.63.0

func (r *TXTRecord) Render(data any) error

Render expands Go template directives in Value (e.g. {{.Domain}}, {{.Email}}).

type TemplatedFileTXTRecord added in v0.66.0

type TemplatedFileTXTRecord struct {
	// PathTemplate is a Go template string (expanded against the data passed
	// to Render) for the path to the file this record's value is read from.
	PathTemplate string `mapstructure:"path-template"`

	// Name is the DNS owner label this record targets, e.g.
	// "default._domainkey" for a DKIM selector record. "" targets the apex.
	Name string `mapstructure:"name"`

	AutoRefresh              bool  `mapstructure:"auto-refresh"`
	AutoRefreshPeriodSeconds int64 `mapstructure:"auto-refresh-period-seconds"`
	// contains filtered or unexported fields
}

TemplatedFileTXTRecord is a DNS TXT record whose value is the contents of a file at a templated path. Content is fetched lazily on first Render and, if AutoRefresh is set, kept fresh afterward by a background ticker running every AutoRefreshPeriodSeconds -- see refreshableContent.

func (*TemplatedFileTXTRecord) Empty added in v0.66.0

func (r *TemplatedFileTXTRecord) Empty() bool

Empty reports whether this record has no configuration and has not yet fetched any content.

func (*TemplatedFileTXTRecord) RecordPrefix added in v0.66.0

func (r *TemplatedFileTXTRecord) RecordPrefix() string

func (*TemplatedFileTXTRecord) RecordType added in v0.66.0

func (r *TemplatedFileTXTRecord) RecordType() string

func (*TemplatedFileTXTRecord) RecordValue added in v0.66.0

func (r *TemplatedFileTXTRecord) RecordValue() string

func (*TemplatedFileTXTRecord) Render added in v0.66.0

func (r *TemplatedFileTXTRecord) Render(data any) error

func (*TemplatedFileTXTRecord) String added in v0.66.0

func (r *TemplatedFileTXTRecord) String() string

type TemplatedRecord added in v0.63.0

type TemplatedRecord interface {
	Render(data any) error
	Empty() bool
}

TemplatedRecord is satisfied by records whose field values contain Go template strings that must be expanded before the record is served. It matches the interface already defined in github.com/dioad/net/smtp.

Jump to

Keyboard shortcuts

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