dns

package
v0.0.0-...-86901c9 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DNSDialer

func DNSDialer(port int) func(ctx context.Context, network, address string) (net.Conn, error)

DNSDialer will return a dialer function that ignores network and address and instead connects to the fixed address.

Apps may still use custom resolvers (including secure resolvers) so this does not work very well - setting resolv.conf or interception still better.

Types

type DmDns

type DmDns struct {
	UDPConn *net.UDPConn

	// UDP
	// Capture return - sends packets back to client app.
	// This is typically a netstack or TProxy
	UDPWriter UdpWriter

	// Client used for DNS-over-HTTPS requests.
	H2 *http.Client

	// Address and port for the DNS-over-https gateway. If empty, direct calls
	// using dnsUDPClient.
	BaseUrl string `json:"dohURL,omitempty"`

	Records map[string]*Record

	// Nameservers to use for direct calls, without a VPN.
	// Overriden from "DNS" env variable.
	Nameservers []string
	Port        int

	Mux *http.ServeMux

	Capture bool
	// contains filtered or unexported fields
}

func New

func New() *DmDns

func (*DmDns) AddRecord

func (s *DmDns) AddRecord(domain string, rtype uint16, rr dns.RR)

func (*DmDns) DNSOverTCP

func (s *DmDns) DNSOverTCP(in io.ReadCloser, out io.Writer) error

DNSOverTCP implements DNS over TCP protocol. Used in TCP capture, for port 53. TODO: also as a standalone server.

func (*DmDns) Do

func (s *DmDns) Do(req *dns.Msg) *dns.Msg

Do resolves a query by forwarding to a recursive nameserver or handling it locally. This is the main function - can be called from: - the real local UDP DNS (mike's) - DNS-over-TCP or TLS server - captured UDP:53 from TUN

Wrapps the real process method with stats gathering and builds a reverse map of IP to names

func (*DmDns) ForwardHttp

func (s *DmDns) ForwardHttp(req *dns.Msg) (*dns.Msg, error)

ForwardHttp forwards the req to a http server, using dmesh-specific DNS-over-HTTP Using GET method - see https://developers.cloudflare.com/1.1.1.1/dns-over-https/wireformat/ and https://cloudflare-dns.com/dns-query Appears to be supported on 1.1.1.1 ( also supports DNS-TLS)

Using DNS over http has hight overhead and doesn't make so much sense in a mesh where DOT can be used instead, with secure L4, or UDP with DNSSEC.

func (*DmDns) ForwardRealDNS

func (s *DmDns) ForwardRealDNS(req *dns.Msg) (*dns.Msg, error)

ForwardRealDNS sends the query to real nameservers.

func (*DmDns) HandleUdp

func (gw *DmDns) HandleUdp(dstAddr net.IP, dstPort uint16,
	localAddr net.IP, localPort uint16,
	data []byte)

Special capture for DNS with TUN or TPROXY. Will use the DNS VPN or direct calls.

func (*DmDns) HostByAddr

func (s *DmDns) HostByAddr(addr string) (string, bool)

HostByAddr returns the last lookup address for an IP, or the original address. The IP is expressed as a string ( ip.String() ).

func (*DmDns) IPResolve

func (s *DmDns) IPResolve(ip string) string

func (*DmDns) NameByAddr

func (s *DmDns) NameByAddr(addr string) (*DnsEntry, bool)

Given an IPv4 or IPv6 address, return the name if DNS was used.

func (*DmDns) Provision

func (d *DmDns) Provision(ctx context.Context) error

func (*DmDns) ServeDNS

func (s *DmDns) ServeDNS(req *dns.Msg, w dns.ResponseWriter) (int, error)

func (*DmDns) ServeHTTP

func (s *DmDns) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*DmDns) Start

func (s *DmDns) Start(ctx context.Context) error

type DnsEntry

type DnsEntry struct {

	// DNS name, with trailing .
	Name string

	IP net.IP

	// Number of times it was called.
	Count int

	RCount int

	// Latency on getting the entry
	Lat time.Duration
	// contains filtered or unexported fields
}

Info and stats about a DNS entry.

type Record

type Record map[string][]string

type UdpWriter

type UdpWriter interface {
	WriteTo(data []byte, dstAddr *net.UDPAddr, srcAddr *net.UDPAddr) (int, error)
}

UdpWriter is the interface implemented by the TunTransport, to send packets back to the virtual interface Set by TProxy and TUN capture. If missing, a regular UDP will be used, first with WriteMsgUdp and if it fails without preserving srcAddr.

Jump to

Keyboard shortcuts

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