dns

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2018 License: GPL-3.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const (
	QTypeA    = 1  //ipv4
	QTypeAAAA = 28 ///ipv6
)

QType .

View Source
const HeaderLen = 12

HeaderLen is the length of dns msg header

View Source
const UDPMaxLen = 512

UDPMaxLen is the max size of udp dns request. https://tools.ietf.org/html/rfc1035#section-4.2.1 Messages carried by UDP are restricted to 512 bytes (not counting the IP or UDP headers). Longer messages are truncated and the TC bit is set in the header. TODO: If the request length > 512 then the client will send TCP packets instead, so we should also serve tcp requests.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnswerHandler

type AnswerHandler func(Domain, ip string) error

AnswerHandler function handles the dns TypeA or TypeAAAA answer

type DNS

type DNS struct {
	Tunnel bool

	DNSServer string

	DNSServerMap   map[string]string
	AnswerHandlers []AnswerHandler
	// contains filtered or unexported fields
}

DNS .

func NewDNS

func NewDNS(addr, raddr string, dialer proxy.Dialer, tunnel bool) (*DNS, error)

NewDNS returns a dns forwarder. client[dns.udp] -> glider[tcp] -> forwarder[dns.tcp] -> remote dns addr

func (*DNS) AddAnswerHandler

func (s *DNS) AddAnswerHandler(h AnswerHandler)

AddAnswerHandler .

func (*DNS) Exchange

func (s *DNS) Exchange(reqLen uint16, reqMsg []byte, addr string) (respLen uint16, respMsg []byte, err error)

Exchange handles request msg and returns response msg TODO: multiple questions support, parse header to get the number of questions

func (*DNS) GetServer

func (s *DNS) GetServer(domain string) string

GetServer .

func (*DNS) ListenAndServe

func (s *DNS) ListenAndServe()

ListenAndServe .

func (*DNS) ListenAndServeTCP

func (s *DNS) ListenAndServeTCP()

ListenAndServeTCP .

func (*DNS) ListenAndServeUDP

func (s *DNS) ListenAndServeUDP()

ListenAndServeUDP .

func (*DNS) ServeTCP

func (s *DNS) ServeTCP(c net.Conn)

ServeTCP .

func (*DNS) SetServer

func (s *DNS) SetServer(domain, server string)

SetServer .

type Question

type Question struct {
	QNAME  string
	QTYPE  uint16
	QCLASS uint16

	Offset int
}

Question format https://tools.ietf.org/html/rfc1035#section-4.1.2 The question section is used to carry the "question" in most queries, i.e., the parameters that define what is being asked. The section contains QDCOUNT (usually 1) entries, each of the following format:

                                1  1  1  1  1  1
  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                                               |
/                     QNAME                     /
/                                               /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                     QTYPE                     |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                     QCLASS                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

type RR

type RR struct {
	// NAME string
	TYPE     uint16
	CLASS    uint16
	TTL      uint32
	RDLENGTH uint16
	RDATA    []byte

	IP string
}

RR format https://tools.ietf.org/html/rfc1035#section-3.2.1 All RRs have the same top level format shown below:

                                1  1  1  1  1  1
  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                                               |
/                                               /
/                      NAME                     /
|                                               |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                      TYPE                     |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                     CLASS                     |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                      TTL                      |
|                                               |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                   RDLENGTH                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
/                     RDATA                     /
/                                               /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

Jump to

Keyboard shortcuts

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