dns

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LookupIP

func LookupIP(host string) ([]string, error)

func ResolveSRVHttp

func ResolveSRVHttp(uri string) string

func SetConfig

func SetConfig(newConfig ResolverConfig)

func UpdateNameservers

func UpdateNameservers(nameservers []string)

Global convenience functions that use the default resolver

Types

type CacheEntry

type CacheEntry struct {
	Records   []DNSRecord
	ExpiresAt time.Time
}

type DNSRecord

type DNSRecord struct {
	Type     string // "A", "AAAA", "CNAME", "MX", "SRV", "TXT"
	Name     string // fully qualified domain name (normalized)
	Target   string // IP for A/AAAA, FQDN for CNAME/MX/SRV, target for SRV, value for TXT
	Port     int    // only for SRV records
	Priority int    // for SRV and MX records
	Weight   int    // only for SRV records
	TTL      int    // time to live
}

type DNSResolver

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

func GetDefaultResolver

func GetDefaultResolver() *DNSResolver

func NewDNSResolver

func NewDNSResolver(config ResolverConfig) *DNSResolver

NewDNSResolver creates a new DNS resolver with the given nameservers

func (*DNSResolver) ClearCache

func (r *DNSResolver) ClearCache()

ClearCache clears the upstream DNS cache

func (*DNSResolver) LookupIP

func (r *DNSResolver) LookupIP(host string) ([]string, error)

func (*DNSResolver) LookupSRV

func (r *DNSResolver) LookupSRV(service string) ([]HostPort, error)

Legacy functions for backward compatibility with existing SRV/IP lookup functionality

func (*DNSResolver) QueryUpstream

func (r *DNSResolver) QueryUpstream(name string, recordType string) ([]DNSRecord, error)

QueryUpstream queries the upstream resolver for records using parallel DNS forwarding

func (*DNSResolver) ResolveSRVHttp

func (r *DNSResolver) ResolveSRVHttp(uri string) string

func (*DNSResolver) SetConfig

func (r *DNSResolver) SetConfig(newConfig ResolverConfig)

func (*DNSResolver) Stop

func (r *DNSResolver) Stop()

Stop stops the resolver and cleans up resources

func (*DNSResolver) UpdateNameservers

func (r *DNSResolver) UpdateNameservers(nameservers []string)

UpdateNameservers updates the resolver's nameservers Format:

nameserver         -> default nameserver, port 53
nameserver:port    -> default nameserver with custom port
domain/nameserver  -> domain-specific nameserver, port 53
domain/nameserver:port -> domain-specific nameserver with custom port

type DNSServer

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

func NewDNSServer

func NewDNSServer(config DNSServerConfig) (*DNSServer, error)

NewDNSServer creates a new DNS server with the given configuration

func (*DNSServer) LookupRecords

func (s *DNSServer) LookupRecords(name string, recordType string) ([]DNSRecord, error)

LookupRecords performs a DNS lookup, checking local records first, then upstream

func (*DNSServer) Start

func (s *DNSServer) Start() error

Start starts the DNS server

func (*DNSServer) Stop

func (s *DNSServer) Stop() error

Stop stops the DNS server

func (*DNSServer) UpdateRecords

func (s *DNSServer) UpdateRecords(records []string) error

UpdateRecords updates the DNS records and reparses them

type DNSServerConfig

type DNSServerConfig struct {
	ListenAddr string       // Address to listen on (e.g., ":53", "127.0.0.1:5353")
	Records    []string     // DNS records in BIND-style format
	DefaultTTL int          // Default TTL when not specified in records
	Resolver   *DNSResolver // Optional upstream resolver
}

type HostPort

type HostPort struct {
	Host string
	Port string
}

func LookupSRV

func LookupSRV(service string) ([]HostPort, error)

type ResolverConfig

type ResolverConfig struct {
	QueryTimeout time.Duration // Timeout for upstream queries, 0 uses 2s default
	EnableCache  bool          // Enable/disable upstream DNS cache
	MaxCacheTTL  int           // Maximum cache TTL in seconds (0 = unlimited)
}

Jump to

Keyboard shortcuts

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