Documentation
¶
Index ¶
- Constants
- type AnswerHandler
- type DNS
- func (s *DNS) AddAnswerHandler(h AnswerHandler)
- func (s *DNS) Exchange(reqLen uint16, reqMsg []byte, addr string) (respLen uint16, respMsg []byte, err error)
- func (s *DNS) GetServer(domain string) string
- func (s *DNS) ListenAndServe()
- func (s *DNS) ListenAndServeTCP()
- func (s *DNS) ListenAndServeUDP()
- func (s *DNS) ServeTCP(c net.Conn)
- func (s *DNS) SetServer(domain, server string)
- type Question
- type RR
Constants ¶
const ( QTypeA = 1 //ipv4 QTypeAAAA = 28 ///ipv6 )
QType .
const HeaderLen = 12
HeaderLen is the length of dns msg header
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 ¶
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 ¶
NewDNS returns a dns forwarder. client[dns.udp] -> glider[tcp] -> forwarder[dns.tcp] -> remote dns addr
type Question ¶
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 / / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+