dns

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion        = 0x00001000
	DefaultUpstreamMtuSize = 0xFF
)

Variables

View Source
var (
	ErrHandshakeNotCompleted = errors.New("no initialization data available - handshake was most likely not completed")
	ErrConnectionFailed      = errors.Errorf("No suitable DNS query type found. Are you connected to a network?")
)
View Source
var ConnectionTimeout = 5 * time.Minute // ConnectionTimeout specifies that connections will timeout 2 minutes after we've seen the last contact from the user
View Source
var OldConnectionTimeout = 6 * ConnectionTimeout // Old connections will also timeout after a certain time

Functions

func MustResolveNetworkAddress

func MustResolveNetworkAddress(network, server, defaultPort string) net.Addr

func ResolveNetworkAddress

func ResolveNetworkAddress(network, server, defaultPort string) (net.Addr, error)

ResolveNetworkAddress will generate an address, optionally adding the specified port if not in the initial string. The function will only work for TCP and UDP addresses.

Types

type AddressList

type AddressList []net.Addr

func (*AddressList) ResolveAndAddAddress

func (l *AddressList) ResolveAndAddAddress(address string)

ResolveAndAddAddress will try to resolve the provide string as a TCP an UDP address. And if any of these succeeed, it will add the address to the list

type ClientCommunicator

type ClientCommunicator interface {
	io.Closer
	streams.Closed

	// Send a message to DNS and get a response
	SendAndReceive(m *dns.Msg, timeout *time.Duration) (r *dns.Msg, rtt time.Duration, err error)

	// LocalAddr returns the local network address.
	LocalAddr() net.Addr

	// RemoteAddr returns the remote network address.
	RemoteAddr() net.Addr

	// SetDeadline sets the read and write deadlines associated with the connection.
	SetDeadline(t time.Time) error

	// SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call.
	// A zero value for t means Read will not time out.
	SetReadDeadline(t time.Time) error

	// SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call.
	// A zero value for t means Write will not time out.
	SetWriteDeadline(t time.Time) error
}

ClientCommunicator is an anbstract interface which executes a communication with the upstream DNS server. We are using this abstraction to make it possible to do high-level communication with DNS over multiple different connections -- e.g. UDP, TCP, pipe or (for testing) directly by sending the DNS messages to the upstream server.

type ClientConfig

type ClientConfig struct {
	Servers AddressList
}

ClientConfig is the configuration for the ClientCommunicator

type ClientDnsConnection

type ClientDnsConnection struct {
	Communicator ClientCommunicator
	Serializer   commands.Serializer
	// contains filtered or unexported fields
}

ClientDnsConnection will simulate connections over a DNS server request/response loop

func NewClientDnsConnection

func NewClientDnsConnection(topDomain string, communicator ClientCommunicator) (*ClientDnsConnection, error)

NewClientDnsConnection will create a new packet connection which will wrap a packet connection over DNS

func (*ClientDnsConnection) AutoDetectQueryType

func (dc *ClientDnsConnection) AutoDetectQueryType() error

func (*ClientDnsConnection) AutodetectEdns0Extension

func (dc *ClientDnsConnection) AutodetectEdns0Extension()

func (*ClientDnsConnection) AutodetectEncodingDowntream

func (dc *ClientDnsConnection) AutodetectEncodingDowntream()

func (*ClientDnsConnection) AutodetectEncodingUpstream

func (dc *ClientDnsConnection) AutodetectEncodingUpstream()

AutodetectEncodingUpstream will try to guess the most efficient upstream encoding by gradually going from the most efficient to the least efficient encoding

func (*ClientDnsConnection) AutodetectFragmentSize

func (dc *ClientDnsConnection) AutodetectFragmentSize() (uint32, error)

func (*ClientDnsConnection) AutodetectLazyMode

func (dc *ClientDnsConnection) AutodetectLazyMode()

func (*ClientDnsConnection) CheckFragmentSizeResponse

func (dc *ClientDnsConnection) CheckFragmentSizeResponse(in []byte) error

func (*ClientDnsConnection) Close

func (dc *ClientDnsConnection) Close() error

Close will close the underlying stream. If the Close has already been called, it will do nothing

func (*ClientDnsConnection) Closed

func (dc *ClientDnsConnection) Closed() bool

Closed will return `true` if SafeStream.Close has been called at least once

func (*ClientDnsConnection) EncodingTestUpstream

func (dc *ClientDnsConnection) EncodingTestUpstream(testPattern []byte) error

EncodingTestUpstream will test different encodings and see if upstream supports them or not

func (*ClientDnsConnection) Handshake

func (dc *ClientDnsConnection) Handshake() error

func (*ClientDnsConnection) LocalAddr

func (dc *ClientDnsConnection) LocalAddr() net.Addr

func (*ClientDnsConnection) Query

Query is a low-level function which will take the (already calculated) full hostname and execute a DNS lookup query using the given type. It will not do any transcoding / encoding. It is expected from the caller to have already done appropriate conversion. If the call succeeds, it returns a (low-level) DNS reply, which is exptected to be parsed by the caller.

func (*ClientDnsConnection) QueryWithData

func (dc *ClientDnsConnection) QueryWithData(req commands.Request, timeout time.Duration, qt dnsmessage.Type, upstream, downstream enc.Encoder) (commands.Response, error)

Query is a low-level function which will take the (already calculated) full hostname and execute a DNS lookup query using the given type. It will not do any transcoding / encoding. It is expected from the caller to have already done appropriate conversion. If the call succeeds, it returns a (low-level) DNS reply, which is exptected to be parsed by the caller.

func (*ClientDnsConnection) Read

func (dc *ClientDnsConnection) Read(b []byte) (n int, err error)

func (*ClientDnsConnection) RemoteAddr

func (dc *ClientDnsConnection) RemoteAddr() net.Addr

func (*ClientDnsConnection) SendAndReceive

func (dc *ClientDnsConnection) SendAndReceive(chunk *util.Packet) error

SendAndReceive will send a chunk of data to the server (if available). If not it will "just" send a ping and receive any data waiting for the client.

func (*ClientDnsConnection) SendEncodingTestDownstream

func (dc *ClientDnsConnection) SendEncodingTestDownstream(downenc enc.Encoder, timeout time.Duration) (*commands.TestDownstreamEncoderResponse, error)

SendEncodingTestDownstream will send a specific downstream encoder to the server and expect a pre-determined response. We know that the encoder works properly because we will match the response to what we have on file. If the strings match -- encoder works.

func (*ClientDnsConnection) SendEncodingTestUpstream

func (dc *ClientDnsConnection) SendEncodingTestUpstream(pattern []byte, timeout time.Duration) (*commands.TestUpstreamEncoderResponse, error)

func (*ClientDnsConnection) SendFragmentSizeTest

func (dc *ClientDnsConnection) SendFragmentSizeTest(fragsize uint32, timeout time.Duration) (*commands.TestDownstreamFragmentSizeResponse, error)

SendFragmentSizeTest will send a request for a "junk" fragment of specified size. This will allow us to check if the (response) fragment of that size can pass through the DNS or not

func (*ClientDnsConnection) SendQueryTypeTest

func (dc *ClientDnsConnection) SendQueryTypeTest(q dnsmessage.Type, timeout time.Duration) error

func (*ClientDnsConnection) SendSetDownstreamFragmentSize

func (dc *ClientDnsConnection) SendSetDownstreamFragmentSize(fragsize uint32, timeout time.Duration) (*commands.SetOptionsResponse, error)

func (*ClientDnsConnection) SendSetEncodingDownstream

func (dc *ClientDnsConnection) SendSetEncodingDownstream(timeout time.Duration) (*commands.SetOptionsResponse, error)

func (*ClientDnsConnection) SendSetEncodingUpstream

func (dc *ClientDnsConnection) SendSetEncodingUpstream(timeout time.Duration) (*commands.SetOptionsResponse, error)

func (*ClientDnsConnection) SetDeadline

func (dc *ClientDnsConnection) SetDeadline(t time.Time) error

func (*ClientDnsConnection) SetEncodingDownstream

func (dc *ClientDnsConnection) SetEncodingDownstream() error

func (*ClientDnsConnection) SetEncodingUpstream

func (dc *ClientDnsConnection) SetEncodingUpstream() error

func (*ClientDnsConnection) SetReadDeadline

func (dc *ClientDnsConnection) SetReadDeadline(t time.Time) error

func (*ClientDnsConnection) SetWriteDeadline

func (dc *ClientDnsConnection) SetWriteDeadline(t time.Time) error

func (*ClientDnsConnection) SwitchFragmentSize

func (dc *ClientDnsConnection) SwitchFragmentSize(requested uint32) error

func (*ClientDnsConnection) TestDownstreamEncoder

func (dc *ClientDnsConnection) TestDownstreamEncoder(trycodec enc.Encoder) error

func (*ClientDnsConnection) VersionHandshake

func (dc *ClientDnsConnection) VersionHandshake() (err error)

func (*ClientDnsConnection) Write

func (dc *ClientDnsConnection) Write(b []byte) (n int, err error)

type NetConnectionClientCommunicator

type NetConnectionClientCommunicator struct {
	Client *dns.Client
	Conn   *dns.Conn
	// contains filtered or unexported fields
}

func NewNetConnectionClientCommunicator

func NewNetConnectionClientCommunicator(config *ClientConfig) (*NetConnectionClientCommunicator, error)

func (*NetConnectionClientCommunicator) Close

func (*NetConnectionClientCommunicator) Closed

func (*NetConnectionClientCommunicator) LocalAddr

func (sc *NetConnectionClientCommunicator) LocalAddr() net.Addr

func (*NetConnectionClientCommunicator) RemoteAddr

func (sc *NetConnectionClientCommunicator) RemoteAddr() net.Addr

func (*NetConnectionClientCommunicator) SendAndReceive

func (sc *NetConnectionClientCommunicator) SendAndReceive(m *dns.Msg, timeout *time.Duration) (r *dns.Msg, rtt time.Duration, err error)

func (*NetConnectionClientCommunicator) SetDeadline

func (sc *NetConnectionClientCommunicator) SetDeadline(t time.Time) error

func (*NetConnectionClientCommunicator) SetReadDeadline

func (sc *NetConnectionClientCommunicator) SetReadDeadline(t time.Time) error

func (*NetConnectionClientCommunicator) SetWriteDeadline

func (sc *NetConnectionClientCommunicator) SetWriteDeadline(t time.Time) error

type NetConnectionServerCommunicator

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

func NewNetConnectionServerCommunicator

func NewNetConnectionServerCommunicator(server *dns.Server) (*NetConnectionServerCommunicator, error)

func (*NetConnectionServerCommunicator) Close

func (n *NetConnectionServerCommunicator) Close() (err error)

func (*NetConnectionServerCommunicator) Closed

func (*NetConnectionServerCommunicator) LocalAddr

func (n *NetConnectionServerCommunicator) LocalAddr() net.Addr

func (*NetConnectionServerCommunicator) RegisterAccept

func (n *NetConnectionServerCommunicator) RegisterAccept(messageFunc OnMessage)

type OnMessage

type OnMessage func(m *dns.Msg, remoteAddr net.Addr) (*dns.Msg, error)

OnMessage is a funnction that's called when a message is received

type ServerCommunicator

type ServerCommunicator interface {
	io.Closer
	streams.Closed

	// Register a callback function that will be executed when a packet is received
	RegisterAccept(messageFunc OnMessage)

	// LocalAddr returns the local network address.
	LocalAddr() net.Addr
}

ServerCommunicator is an an interface to accept DNS requests from a multiconnection interface implementation.

type ServerDnsListener

type ServerDnsListener struct {
	Communicator      ServerCommunicator  // Communictor does IO. This allows us to abstract away the connection logic
	DefaultSerializer commands.Serializer // The default serializer that's used when no user-specific serializer can be applied
	// contains filtered or unexported fields
}

ServerDnsListener will simulate connections over a DNS server request/response loop

func NewServerDnsListener

func NewServerDnsListener(topDomain string, comm ServerCommunicator) *ServerDnsListener

func (*ServerDnsListener) Accept

func (s *ServerDnsListener) Accept() (net.Conn, error)

func (*ServerDnsListener) Addr

func (s *ServerDnsListener) Addr() net.Addr

func (*ServerDnsListener) Close

func (s *ServerDnsListener) Close() error

Close will close the underlying stream. If the Close has already been called, it will do nothing

func (*ServerDnsListener) Closed

func (s *ServerDnsListener) Closed() bool

Closed will return `true` if SafeStream.Close has been called at least once

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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