CoreDNS 重要成分解析

dnsserver

request

func Proto

1
func Proto(w dns.ResponseWriter) string

传输所用的协议,udp或者tcp

type Request

1
2
3
4
5
6
7
8
type Request struct {
Req *dns.Msg
W dns.ResponseWriter

// Optional lowercased zone of this query.
Zone string
// contains filtered or unexported fields
}

func (*Request) IP

1
func (r *Request) IP() string

获取发起dns请求的客户端ip地址

func (*Request) LocalAddr

1
func (r *Request) LocalAddr() string

LocalAddr returns the net.Addr of the server handling the current request.

func (*Request) LocalIP

1
func (r *Request) LocalIP() string

LocalIP gets the (local) IP address of server handling the request.

func (*Request) LocalPort

1
func (r *Request) LocalPort() string

LocalPort gets the local port of the server handling the request.

func (*Request) Name

1
func (r *Request) Name() string

Name returns the name of the question in the request. Note this name will always have a closing dot and will be lower cased. After a call Name the value will be cached. To clear this caching call Clear. If the request is malformed the root zone is returned.

func (*Request) QName

1
func (r *Request) QName() string

QName returns the name of the question in the request. If the request is malformed the root zone is returned.

dns

type Msg

Msg 列举DNS信息

1
2
3
4
5
6
7
8
type Msg struct {
MsgHdr
Compress bool `json:"-"` // If true, the message will be compressed when converted to wire format.
Question []Question // Holds the RR(s) of the question section.
Answer []RR // Holds the RR(s) of the answer section.
Ns []RR // Holds the RR(s) of the authority section.
Extra []RR // Holds the RR(s) of the additional section.
}

type RR

RR(resource record) 资源记录

1
2
3
4
5
6
7
8
9

type RR interface {
// Header returns the header of an resource record. The header contains
// everything up to the rdata.
Header() *RR_Header
// String returns the text representation of the resource record.
String() string
// contains filtered or unexported methods
}

type MsgHdr

MsgHdr is a a manually-unpacked version of (id, bits).

1
2
3
4
5
6
7
8
9
10
11
12
13
type MsgHdr struct {
Id uint16
Response bool
Opcode int
Authoritative bool
Truncated bool
RecursionDesired bool
RecursionAvailable bool
Zero bool
AuthenticatedData bool
CheckingDisabled bool
Rcode int
}

type Question

question包含一个dns询问

1
2
3
4
5
type Question struct {
Name string `dns:"cdomain-name"` // "cdomain-name" specifies encoding (and may be compressed)
Qtype uint16
Qclass uint16
}

type Name

dns.name

1
2
3
4
5
type Name string
//Name is a DNS domain name.

func (n Name) String() string
//String returns the string representation for the name n.

type Server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
type Server struct {
// Address to listen on, ":dns" if empty.
Addr string
// if "tcp" or "tcp-tls" (DNS over TLS) it will invoke a TCP listener, otherwise an UDP one
Net string
// TCP Listener to use, this is to aid in systemd's socket activation.
Listener net.Listener
// TLS connection configuration
TLSConfig *tls.Config
// UDP "Listener" to use, this is to aid in systemd's socket activation.
PacketConn net.PacketConn
// Handler to invoke, dns.DefaultServeMux if nil.
Handler Handler
// Default buffer size to use to read incoming UDP messages. If not set
// it defaults to MinMsgSize (512 B).
UDPSize int
// The net.Conn.SetReadTimeout value for new connections, defaults to 2 * time.Second.
ReadTimeout time.Duration
// The net.Conn.SetWriteTimeout value for new connections, defaults to 2 * time.Second.
WriteTimeout time.Duration
// TCP idle timeout for multiple queries, if nil, defaults to 8 * time.Second (RFC 5966).
IdleTimeout func() time.Duration
// Secret(s) for Tsig map[<zonename>]<base64 secret>. The zonename must be in canonical form (lowercase, fqdn, see RFC 4034 Section 6.2).
TsigSecret map[string]string
// If NotifyStartedFunc is set it is called once the server has started listening.
NotifyStartedFunc func()
// DecorateReader is optional, allows customization of the process that reads raw DNS messages.
DecorateReader DecorateReader
// DecorateWriter is optional, allows customization of the process that writes raw DNS messages.
DecorateWriter DecorateWriter
// Maximum number of TCP queries before we close the socket. Default is maxTCPQueries (unlimited if -1).
MaxTCPQueries int
// Whether to set the SO_REUSEPORT socket option, allowing multiple listeners to be bound to a single address.
// It is only supported on go1.11+ and when using ListenAndServe.
ReusePort bool
// AcceptMsgFunc will check the incoming message and will reject it early in the process.
// By default DefaultMsgAcceptFunc will be used.
MsgAcceptFunc MsgAcceptFunc
// contains filtered or unexported fields
}