dns

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DNSPort = 53
)

Variables

This section is empty.

Functions

func IPToReverseDNS added in v1.4.2

func IPToReverseDNS(ip net.IP) string

IPToReverseDNS converts an IP address to reverse DNS format Returns the domain name for PTR queries (e.g., "1.0.0.127.in-addr.arpa.")

func PickIPFromSubnet

func PickIPFromSubnet(subnet string) (netip.Addr, error)

Types

type DNSProxy

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

DNSProxy implements a DNS proxy using gvisor netstack

func NewDNSProxy

func NewDNSProxy(middleDevice *device.MiddleDevice, mtu int, utilitySubnet string, upstreamDns []string, tunnelDns bool, tunnelIP string) (*DNSProxy, error)

NewDNSProxy creates a new DNS proxy

func (*DNSProxy) AddDNSRecord

func (p *DNSProxy) AddDNSRecord(domain string, ip net.IP, siteId int) error

AddDNSRecord adds a DNS record to the local store domain should be a domain name (e.g., "example.com" or "example.com.") ip should be a valid IPv4 or IPv6 address

func (*DNSProxy) ClearDNSRecords

func (p *DNSProxy) ClearDNSRecords()

ClearDNSRecords removes all DNS records from the local store

func (*DNSProxy) GetDNSRecords

func (p *DNSProxy) GetDNSRecords(domain string, recordType RecordType) ([]net.IP, bool)

GetDNSRecords returns all IP addresses for a domain and record type. The second return value indicates whether the domain exists.

func (*DNSProxy) GetProxyIP

func (p *DNSProxy) GetProxyIP() netip.Addr

func (*DNSProxy) RemoveDNSRecord

func (p *DNSProxy) RemoveDNSRecord(domain string, ip net.IP)

RemoveDNSRecord removes a DNS record from the local store If ip is nil, removes all records for the domain

func (*DNSProxy) SetJITHandler added in v1.4.4

func (p *DNSProxy) SetJITHandler(handler func(siteId int))

SetJITHandler registers a callback that is invoked whenever a local DNS record is resolved for an A or AAAA query. The siteId identifies which site owns the record. The handler is called in its own goroutine so it must be safe to call concurrently. Pass nil to disable JIT notifications.

func (*DNSProxy) Start

func (p *DNSProxy) Start() error

Start starts the DNS proxy and registers with the filter

func (*DNSProxy) Stop

func (p *DNSProxy) Stop()

Stop stops the DNS proxy

type DNSRecordStore

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

DNSRecordStore manages local DNS records for A, AAAA, and PTR queries. Exact domains are stored in a map; wildcard patterns are in a separate map.

func NewDNSRecordStore

func NewDNSRecordStore() *DNSRecordStore

NewDNSRecordStore creates a new DNS record store

func (*DNSRecordStore) AddPTRRecord added in v1.4.2

func (s *DNSRecordStore) AddPTRRecord(ip net.IP, domain string) error

AddPTRRecord adds a PTR record mapping an IP address to a domain name ip should be a valid IPv4 or IPv6 address domain should be in FQDN format (e.g., "example.com.")

func (*DNSRecordStore) AddRecord

func (s *DNSRecordStore) AddRecord(domain string, ip net.IP, siteId int) error

AddRecord adds a DNS record mapping (A or AAAA) domain should be in FQDN format (e.g., "example.com.") domain can contain wildcards: * (0+ chars) and ? (exactly 1 char) ip should be a valid IPv4 or IPv6 address siteId is the site that owns this alias/domain Automatically adds a corresponding PTR record for non-wildcard domains

func (*DNSRecordStore) Clear

func (s *DNSRecordStore) Clear()

Clear removes all records from the store

func (*DNSRecordStore) GetPTRRecord added in v1.4.2

func (s *DNSRecordStore) GetPTRRecord(domain string) (string, bool)

GetPTRRecord returns the domain name for a PTR record query domain should be in reverse DNS format (e.g., "1.0.0.127.in-addr.arpa.")

func (*DNSRecordStore) GetRecords

func (s *DNSRecordStore) GetRecords(domain string, recordType RecordType) ([]net.IP, bool)

GetRecords returns all IP addresses for a domain and record type. The second return value indicates whether the domain exists at all (true = domain exists, use NODATA if no records; false = NXDOMAIN).

func (*DNSRecordStore) GetSiteIdForDomain added in v1.4.4

func (s *DNSRecordStore) GetSiteIdForDomain(domain string) (int, bool)

GetSiteIdForDomain returns the siteId associated with the given domain. It checks exact matches first, then wildcard patterns. The second return value is false if the domain is not found in local records.

func (*DNSRecordStore) HasPTRRecord added in v1.4.2

func (s *DNSRecordStore) HasPTRRecord(domain string) bool

HasPTRRecord checks if a PTR record exists for the given reverse DNS domain

func (*DNSRecordStore) HasRecord

func (s *DNSRecordStore) HasRecord(domain string, recordType RecordType) bool

HasRecord checks if a domain has any records of the specified type Checks both exact matches and wildcard patterns

func (*DNSRecordStore) RemovePTRRecord added in v1.4.2

func (s *DNSRecordStore) RemovePTRRecord(ip net.IP)

RemovePTRRecord removes a PTR record for an IP address

func (*DNSRecordStore) RemoveRecord

func (s *DNSRecordStore) RemoveRecord(domain string, ip net.IP)

RemoveRecord removes a specific DNS record mapping If ip is nil, removes all records for the domain (including wildcards) Automatically removes corresponding PTR records for non-wildcard domains

type RecordType

type RecordType uint16

RecordType represents the type of DNS record

const (
	RecordTypeA    RecordType = RecordType(dns.TypeA)
	RecordTypeAAAA RecordType = RecordType(dns.TypeAAAA)
	RecordTypePTR  RecordType = RecordType(dns.TypePTR)
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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