dns

package
v1.4.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 10 Imported by: 0

Documentation

Overview

Package dns edns provides EDNS options for DNS queries.

Index

Constants

View Source
const (
	EDNS0LLQ          = 0x1    // long lived queries: http://tools.ietf.org/html/draft-sekar-dns-llq-01
	EDNS0UL           = 0x2    // update lease draft: http://files.dns-sd.org/draft-sekar-dns-ul.txt
	EDNS0NSID         = 0x3    // nsid (See RFC 5001)
	EDNS0DAU          = 0x5    // DNSSEC Algorithm Understood
	EDNS0DHU          = 0x6    // DS Hash Understood
	EDNS0N3U          = 0x7    // NSEC3 Hash Understood
	EDNS0SUBNET       = 0x8    // client-subnet (See RFC 7871)
	EDNS0EXPIRE       = 0x9    // EDNS0 expire
	EDNS0COOKIE       = 0xa    // EDNS0 Cookie
	EDNS0TCPKEEPALIVE = 0xb    // EDNS0 tcp keep alive (See RFC 7828)
	EDNS0PADDING      = 0xc    // EDNS0 padding (See RFC 7830)
	EDNS0LOCALSTART   = 0xFDE9 // Beginning of range reserved for local/experimental use (See RFC 6891)
	EDNS0LOCALEND     = 0xFFFE // End of range reserved for local/experimental use (See RFC 6891)

)

EDNS0 Option codes.

View Source
const (

	// MinMsgSize UDP最小包长度
	MinMsgSize = 512
	// MaxMsgSize UDP最大包长度
	MaxMsgSize = 65535
)
View Source
const (
	TypeNone       uint16 = 0
	TypeA          uint16 = 1
	TypeNS         uint16 = 2
	TypeMD         uint16 = 3
	TypeMF         uint16 = 4
	TypeCNAME      uint16 = 5
	TypeSOA        uint16 = 6
	TypeMB         uint16 = 7
	TypeMG         uint16 = 8
	TypeMR         uint16 = 9
	TypeNULL       uint16 = 10
	TypePTR        uint16 = 12
	TypeHINFO      uint16 = 13
	TypeMINFO      uint16 = 14
	TypeMX         uint16 = 15
	TypeTXT        uint16 = 16
	TypeRP         uint16 = 17
	TypeAFSDB      uint16 = 18
	TypeX25        uint16 = 19
	TypeISDN       uint16 = 20
	TypeRT         uint16 = 21
	TypeNSAPPTR    uint16 = 23
	TypeSIG        uint16 = 24
	TypeKEY        uint16 = 25
	TypePX         uint16 = 26
	TypeGPOS       uint16 = 27
	TypeAAAA       uint16 = 28
	TypeLOC        uint16 = 29
	TypeNXT        uint16 = 30
	TypeEID        uint16 = 31
	TypeNIMLOC     uint16 = 32
	TypeSRV        uint16 = 33
	TypeATMA       uint16 = 34
	TypeNAPTR      uint16 = 35
	TypeKX         uint16 = 36
	TypeCERT       uint16 = 37
	TypeDNAME      uint16 = 39
	TypeOPT        uint16 = 41 // EDNS
	TypeAPL        uint16 = 42
	TypeDS         uint16 = 43
	TypeSSHFP      uint16 = 44
	TypeRRSIG      uint16 = 46
	TypeNSEC       uint16 = 47
	TypeDNSKEY     uint16 = 48
	TypeDHCID      uint16 = 49
	TypeNSEC3      uint16 = 50
	TypeNSEC3PARAM uint16 = 51
	TypeTLSA       uint16 = 52
	TypeSMIMEA     uint16 = 53
	TypeHIP        uint16 = 55
	TypeNINFO      uint16 = 56
	TypeRKEY       uint16 = 57
	TypeTALINK     uint16 = 58
	TypeCDS        uint16 = 59
	TypeCDNSKEY    uint16 = 60
	TypeOPENPGPKEY uint16 = 61
	TypeCSYNC      uint16 = 62
	TypeSPF        uint16 = 99
	TypeUINFO      uint16 = 100
	TypeUID        uint16 = 101
	TypeGID        uint16 = 102
	TypeUNSPEC     uint16 = 103
	TypeNID        uint16 = 104
	TypeL32        uint16 = 105
	TypeL64        uint16 = 106
	TypeLP         uint16 = 107
	TypeEUI48      uint16 = 108
	TypeEUI64      uint16 = 109
	TypeURI        uint16 = 256
	TypeCAA        uint16 = 257
	TypeAVC        uint16 = 258

	TypeTKEY uint16 = 249
	TypeTSIG uint16 = 250

	// TypeIXFR valid Question.Qtype only
	TypeIXFR  uint16 = 251
	TypeAXFR  uint16 = 252
	TypeMAILB uint16 = 253
	TypeMAILA uint16 = 254
	TypeANY   uint16 = 255

	// TypePackCtrl polaris
	TypePackCtrl             uint16 = 10000
	TypePolarisDetailErrInfo uint16 = 10001
	TypePolarsHead           uint16 = 10002

	TypePolarisResource        uint16 = 10003 // for question
	TypePolarisSideCarLocation uint16 = 10004
	TypePolarisResponse        uint16 = 10005
	TypePolarisInstance        uint16 = 10006
	TypePolarisStream          uint16 = 10007
	TypePolarisGetOneInstance  uint16 = 10008

	TypeTA       uint16 = 32768
	TypeDLV      uint16 = 32769
	TypeReserved uint16 = 65535

	// ClassINET valid Question.Qclass
	ClassINET   = 1
	ClassCSNET  = 2
	ClassCHAOS  = 3
	ClassHESIOD = 4
	ClassNONE   = 254
	ClassANY    = 255

	// RcodeSuccess Message Response Codes, see https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml
	RcodeSuccess        = 0  // NoError   - No Error                          [DNS]
	RcodeFormatError    = 1  // FormErr   - Format Error                      [DNS]
	RcodeServerFailure  = 2  // ServFail  - Server Failure                    [DNS]
	RcodeNameError      = 3  // NXDomain  - Non-Existent Domain               [DNS]
	RcodeNotImplemented = 4  // NotImp    - Not Implemented                   [DNS]
	RcodeRefused        = 5  // Refused   - Query Refused                     [DNS]
	RcodeYXDomain       = 6  // YXDomain  - Name Exists when it should not    [DNS Update]
	RcodeYXRrset        = 7  // YXRRSet   - RR Set Exists when it should not  [DNS Update]
	RcodeNXRrset        = 8  // NXRRSet   - RR Set that should exist does not [DNS Update]
	RcodeNotAuth        = 9  // NotAuth   - Server Not Authoritative for zone [DNS Update]
	RcodeNotZone        = 10 // NotZone   - Name not contained in zone        [DNS Update/TSIG]
	RcodeBadSig         = 16 // BADSIG    - TSIG Signature Failure            [TSIG]
	RcodeBadVers        = 16 // BADVERS   - Bad OPT Version                   [EDNS0]
	RcodeBadKey         = 17 // BADKEY    - Key not recognized                [TSIG]
	RcodeBadTime        = 18 // BADTIME   - Signature out of time window      [TSIG]
	RcodeBadMode        = 19 // BADMODE   - Bad TKEY Mode                     [TKEY]
	RcodeBadName        = 20 // BADNAME   - Duplicate key name                [TKEY]
	RcodeBadAlg         = 21 // BADALG    - Algorithm not supported           [TKEY]
	RcodeBadTrunc       = 22 // BADTRUNC  - Bad Truncation                    [TSIG]
	RcodeBadCookie      = 23 // BADCOOKIE - Bad/missing Server Cookie         [DNS Cookies]

	// OpcodeQuery Message Opcodes. There is no 3.
	OpcodeQuery  = 0
	OpcodeIQuery = 1
	OpcodeStatus = 2
	OpcodeNotify = 4
	OpcodeUpdate = 5

	OpCodePolarisGetOneInstance               = 7
	OpCodePolarisGetResource                  = 8
	OpCodePolarisBatchReportServiceCallResult = 9
	OpCodePolarisRegisterInstance             = 10
	OpCodePolarisDeregisterInstance           = 11
	OpCodePolarisHeartbeat                    = 12
	OpCodePolarisReportClient                 = 13
)

Wire constants and supported types.

View Source
const (
	HeaderSize = 12

	// Header.Bits
	QR_ = 1 << 15 // query/response (response=1)
	AA_ = 1 << 10 // authoritative
	TC_ = 1 << 9  // truncated
	RD_ = 1 << 8  // recursion desired
	RA_ = 1 << 7  // recursion available
	Z_  = 1 << 6  // Z
	AD_ = 1 << 5  // authenticated data
	CD_ = 1 << 4  // checking disabled

)
View Source
const (
	PackCtrlRRName = "packCtrl"
)

Variables

View Source
var (
	// ErrBuf ErrAuth indicates an error in the TSIG authentication.
	ErrBuf error = &Error{err: "buffer size too small"}
	// ErrConnEmpty indicates a connection is being used before it is initialized.
	ErrConnEmpty error = &Error{err: "conn has no connection"}
	// ErrExtendedRcode ...
	ErrExtendedRcode error = &Error{err: "bad extended rcode"}
	// ErrId indicates there is a mismatch with the message's ID.
	ErrId         error = &Error{err: "id mismatch"}
	ErrLongDomain error = &Error{err: fmt.Sprintf("domain name exceeded %d wire-format octets",
		maxDomainNameWireOctets)}
	ErrRCode error = &Error{err: "bad rcode"}
	ErrRData error = &Error{err: "bad rdata"}
	ErrRRSet error = &Error{err: "bad rrset"}
)

Errors defined in this package.

View Source
var ClassToString = map[uint16]string{
	ClassINET:   "IN",
	ClassCSNET:  "CS",
	ClassCHAOS:  "CH",
	ClassHESIOD: "HS",
	ClassNONE:   "NONE",
	ClassANY:    "ANY",
}

ClassToString is a maps Classes to strings for each CLASS wire type.

View Source
var OpcodeToString = map[int]string{
	OpcodeQuery:  "QUERY",
	OpcodeIQuery: "IQUERY",
	OpcodeStatus: "STATUS",
	OpcodeNotify: "NOTIFY",
	OpcodeUpdate: "UPDATE",
}

OpcodeToString maps Opcodes to strings.

View Source
var RcodeToString = map[int]string{
	RcodeSuccess:        "NOERROR",
	RcodeFormatError:    "FORMERR",
	RcodeServerFailure:  "SERVFAIL",
	RcodeNameError:      "NXDOMAIN",
	RcodeNotImplemented: "NOTIMP",
	RcodeRefused:        "REFUSED",
	RcodeYXDomain:       "YXDOMAIN",
	RcodeYXRrset:        "YXRRSET",
	RcodeNXRrset:        "NXRRSET",
	RcodeNotAuth:        "NOTAUTH",
	RcodeNotZone:        "NOTZONE",
	RcodeBadSig:         "BADSIG",

	RcodeBadKey:    "BADKEY",
	RcodeBadTime:   "BADTIME",
	RcodeBadMode:   "BADMODE",
	RcodeBadName:   "BADNAME",
	RcodeBadAlg:    "BADALG",
	RcodeBadTrunc:  "BADTRUNC",
	RcodeBadCookie: "BADCOOKIE",
}

RcodeToString maps Rcodes to strings.

View Source
var StringToClass = reverseInt16(ClassToString)

StringToClass is the reverse of ClassToString, needed for string parsing.

View Source
var StringToOpcode = reverseInt(OpcodeToString)

StringToOpcode is a map of opcodes to strings.

View Source
var StringToRcode = reverseInt(RcodeToString)

StringToRcode is a map of rcodes to strings.

View Source
var StringToType = reverseInt16(TypeToString)

StringToType is the reverse of TypeToString, needed for string parsing.

View Source
var TypeToQuestion = map[int]func() Question{
	OpcodeQuery:                     func() Question { return new(DNSQuestion) },
	OpCodePolarisGetOneInstance:     func() Question { return new(PolarisGetResourceQuestion) },
	OpCodePolarisGetResource:        func() Question { return new(PolarisGetResourceQuestion) },
	OpCodePolarisRegisterInstance:   func() Question { return new(PolarisInstanceQuestion) },
	OpCodePolarisDeregisterInstance: func() Question { return new(PolarisInstanceQuestion) },
	OpCodePolarisHeartbeat:          func() Question { return new(PolarisInstanceQuestion) },
	OpCodePolarisReportClient:       func() Question { return new(PolarisReportClientQuestion) },
}
View Source
var TypeToRR = map[uint16]func() RR{
	TypeA:                      func() RR { return new(A) },
	TypeAAAA:                   func() RR { return new(AAAA) },
	TypePackCtrl:               func() RR { return new(PackageCtrlRR) },
	TypePolarisStream:          func() RR { return new(StreamRR) },
	TypePolarisSideCarLocation: func() RR { return new(LocationRR) },
	TypePolarisDetailErrInfo:   func() RR { return new(DetailErrInfoRR) },
	TypePolarisResponse:        func() RR { return new(ResponseRR) },
	TypePolarsHead:             func() RR { return new(PolarisHeaderRR) },
	TypeOPT:                    func() RR { return new(OPT) },
}

TypeToRR RR new Map.

View Source
var TypeToString = map[uint16]string{
	TypeA:          "A",
	TypeAAAA:       "AAAA",
	TypeAFSDB:      "AFSDB",
	TypeANY:        "ANY",
	TypeAPL:        "APL",
	TypeATMA:       "ATMA",
	TypeAVC:        "AVC",
	TypeAXFR:       "AXFR",
	TypeCAA:        "CAA",
	TypeCDNSKEY:    "CDNSKEY",
	TypeCDS:        "CDS",
	TypeCERT:       "CERT",
	TypeCNAME:      "CNAME",
	TypeCSYNC:      "CSYNC",
	TypeDHCID:      "DHCID",
	TypeDLV:        "DLV",
	TypeDNAME:      "DNAME",
	TypeDNSKEY:     "DNSKEY",
	TypeDS:         "DS",
	TypeEID:        "EID",
	TypeEUI48:      "EUI48",
	TypeEUI64:      "EUI64",
	TypeGID:        "GID",
	TypeGPOS:       "GPOS",
	TypeHINFO:      "HINFO",
	TypeHIP:        "HIP",
	TypeISDN:       "ISDN",
	TypeIXFR:       "IXFR",
	TypeKEY:        "KEY",
	TypeKX:         "KX",
	TypeL32:        "L32",
	TypeL64:        "L64",
	TypeLOC:        "LOC",
	TypeLP:         "LP",
	TypeMAILA:      "MAILA",
	TypeMAILB:      "MAILB",
	TypeMB:         "MB",
	TypeMD:         "MD",
	TypeMF:         "MF",
	TypeMG:         "MG",
	TypeMINFO:      "MINFO",
	TypeMR:         "MR",
	TypeMX:         "MX",
	TypeNAPTR:      "NAPTR",
	TypeNID:        "NID",
	TypeNIMLOC:     "NIMLOC",
	TypeNINFO:      "NINFO",
	TypeNS:         "NS",
	TypeNSEC:       "NSEC",
	TypeNSEC3:      "NSEC3",
	TypeNSEC3PARAM: "NSEC3PARAM",
	TypeNULL:       "NULL",
	TypeNXT:        "NXT",
	TypeNone:       "None",
	TypeOPENPGPKEY: "OPENPGPKEY",
	TypeOPT:        "OPT",
	TypePTR:        "PTR",
	TypePX:         "PX",
	TypeRKEY:       "RKEY",
	TypeRP:         "RP",
	TypeRRSIG:      "RRSIG",
	TypeRT:         "RT",
	TypeReserved:   "Reserved",
	TypeSIG:        "SIG",
	TypeSMIMEA:     "SMIMEA",
	TypeSOA:        "SOA",
	TypeSPF:        "SPF",
	TypeSRV:        "SRV",
	TypeSSHFP:      "SSHFP",
	TypeTA:         "TA",
	TypeTALINK:     "TALINK",
	TypeTKEY:       "TKEY",
	TypeTLSA:       "TLSA",
	TypeTSIG:       "TSIG",
	TypeTXT:        "TXT",
	TypeUID:        "UID",
	TypeUINFO:      "UINFO",
	TypeUNSPEC:     "UNSPEC",
	TypeURI:        "URI",
	TypeX25:        "X25",
	TypeNSAPPTR:    "NSAP-PTR",
}

TypeToString is a map of strings for each RR type.

Functions

func PackRR

func PackRR(rr RR, buff *bytes.Buffer) (int, error)

PackRR RR序列化

func UnpackDomainName

func UnpackDomainName(msg []byte, off int) (string, int, error)

反序列化域名

Types

type A

type A struct {
	Hdr RR_Header
	A   net.IP `dns:"a"`
}

A 标准的DNS IPv4 RR

func (*A) Copy

func (rr *A) Copy() RR

Copy 深拷贝

func (*A) GetData

func (rr *A) GetData() []byte

GetData 获取RR data

func (*A) Header

func (rr *A) Header() *RR_Header

Header 返回header

func (*A) PackData

func (rr *A) PackData(buff *bytes.Buffer) (int, error)

PackData 序列化 RR data

func (*A) String

func (rr *A) String() string

String 打印string

func (*A) UnPackData

func (rr *A) UnPackData(msg []byte, off int) (int, error)

UnPackData 反序列化RR data

type AAAA

type AAAA struct {
	Hdr  RR_Header
	AAAA net.IP `dns:"aaaa"`
}

AAAA 标准的DNS IPv6 RR

func (*AAAA) Copy

func (rr *AAAA) Copy() RR

Copy 深拷贝

func (*AAAA) GetData

func (rr *AAAA) GetData() []byte

GetData 获取RR data

func (*AAAA) Header

func (rr *AAAA) Header() *RR_Header

Header 返回header

func (*AAAA) PackData

func (rr *AAAA) PackData(buff *bytes.Buffer) (int, error)

PackData 序列化 RR data

func (*AAAA) String

func (rr *AAAA) String() string

String 打印string

func (*AAAA) UnPackData

func (rr *AAAA) UnPackData(msg []byte, off int) (int, error)

UnPackData 反序列化RR data

type BaseEDNSData

type BaseEDNSData struct {
	Code       uint16
	OptionData []byte
}

BaseEDNSData Base edns data

func (*BaseEDNSData) Option

func (b *BaseEDNSData) Option() uint16

Option uint16 implements the EDNS0 interface.

func (*BaseEDNSData) PackData

func (b *BaseEDNSData) PackData() ([]byte, error)

PackData implements the EDNS0 interface.

func (*BaseEDNSData) UnpackData

func (b *BaseEDNSData) UnpackData(data []byte) error

UnpackData implements the EDNS0 interface.

type BasePolarisQuestion

type BasePolarisQuestion struct {
	Name   string `dns:"cdomain-name"` // "cdomain-name" specifies encoding (and may be compressed)
	Qtype  uint16
	Qclass uint16
	// contains filtered or unexported fields
}

BasePolarisQuestion base Polaris question

func (*BasePolarisQuestion) String

func (q *BasePolarisQuestion) String() (s string)

string打印

type Class

type Class uint16

Class is a DNS class.

func (Class) String

func (c Class) String() string

String returns the string representation for the class c.

type DNSQuestion

type DNSQuestion struct {
	Name   string `dns:"cdomain-name"` // "cdomain-name" specifies encoding (and may be compressed)
	Qtype  uint16
	Qclass uint16
}

DNSQuestion 标准的dns question

func (*DNSQuestion) String

func (q *DNSQuestion) String() (s string)

String 打印,便于调式等

type DetailErrInfoRR

type DetailErrInfoRR struct {
	Hdr     RR_Header
	ErrInfo *sidecarPb.DetailErrInfo
}

DetailErrInfoRR polaris 详细错误 RR

func (*DetailErrInfoRR) GetData

func (rr *DetailErrInfoRR) GetData() []byte

GetData 获取RR data

func (*DetailErrInfoRR) Header

func (rr *DetailErrInfoRR) Header() *RR_Header

Header 返回header

func (*DetailErrInfoRR) PackData

func (rr *DetailErrInfoRR) PackData(buff *bytes.Buffer) (int, error)

PackData 序列化 RR data

func (*DetailErrInfoRR) UnPackData

func (rr *DetailErrInfoRR) UnPackData(msg []byte, off int) (int, error)

UnPackData 反序列化RR data

type EDNS0

type EDNS0 interface {
	// Option returns the option code for the option.
	Option() uint16
	// PackData pack returns the bytes of the option data.
	PackData() ([]byte, error)
	// UnpackData unpack sets the data as found in the buffer. Is also sets
	// the length of the slice as the length of the option data.
	UnpackData([]byte) error
}

EDNS0 defines an EDNS0 Option. An OPT RR can have multiple options appended to it.

type EDNSDataCommon

type EDNSDataCommon struct {
	OptionCode   uint16
	OptionLength uint16
}

EDNSDataCommon Base EDNS data common

func (*EDNSDataCommon) Option

func (d *EDNSDataCommon) Option() uint16

Option implements the EDNS0 interface.

func (*EDNSDataCommon) Pack

func (d *EDNSDataCommon) Pack(buff *bytes.Buffer) error

Pack implements the EDNS0 interface.

func (*EDNSDataCommon) Unpack

func (d *EDNSDataCommon) Unpack(msg []byte, offset int) (int, error)

Unpack implements the EDNS0 interface.

type Error

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

Error connector错误定义

func (*Error) Error

func (e *Error) Error() string

Error 返回 err

type LocationRR

type LocationRR struct {
	StreamRR
	Hdr     RR_Header
	SideCar *namingpb.Client
}

LocationRR location RR

func (*LocationRR) Header

func (rr *LocationRR) Header() *RR_Header

Header 返回header

func (*LocationRR) PackData

func (rr *LocationRR) PackData(buff *bytes.Buffer) (int, error)

PackData 序列化 RR data

func (*LocationRR) UnPackData

func (rr *LocationRR) UnPackData(msg []byte, off int) (int, error)

UnPackData 反序列化RR data

type Msg

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.
}

Msg 完整的DNS协议

func PackStreamDataToDnsProto

func PackStreamDataToDnsProto(data []byte, id uint16, opCode int, rrType uint16) ([]*Msg, error)

PackStreamDataToDnsProto polaris 序列化(有4层分包逻辑).

func (*Msg) GetDetailErrRR

func (dns *Msg) GetDetailErrRR() *DetailErrInfoRR

GetDetailErrRR 获取详细错误RR(Polaris使用)

func (*Msg) GetPackControlRR

func (dns *Msg) GetPackControlRR() *PackageCtrlRR

GetPackControlRR 获取包控制RR

func (*Msg) Pack

func (dns *Msg) Pack() (*bytes.Buffer, error)

Pack 序列化

func (*Msg) SetDNSQuestion

func (dns *Msg) SetDNSQuestion(z string, t uint16) *Msg

SetDNSQuestion Set Question

func (*Msg) SetReply

func (dns *Msg) SetReply(request *Msg)

SetReply 设置返回

func (*Msg) SetReplyWithoutQuestions

func (dns *Msg) SetReplyWithoutQuestions(request *Msg)

SetReplyWithoutQuestions 设置返回,不拷贝question

func (*Msg) Unpack

func (dns *Msg) Unpack(msg []byte) (err error)

Unpack dns反序列化

func (*Msg) UnpackBody

func (dns *Msg) UnpackBody(msg []byte, off int) (err error)

UnpackBody 反序列化body

type MsgHdr

type MsgHdr struct {
	// dns session id
	Id uint16
	// 是否为应答
	Response bool
	// 操作code
	Opcode int
	// 是否为权威应答
	Authoritative bool
	// UDP应答是否被截断
	Truncated bool
	// 请求是否要求递归查询
	RecursionDesired bool
	// 递归查询是否启用
	RecursionAvailable bool
	Zero               bool
	AuthenticatedData  bool
	CheckingDisabled   bool
	// 返回code
	Rcode int
	// question数量, answer RR数量, 权威信息 RR数量, 额外信息 RR数量
	Qdcount, Ancount, Nscount, Arcount uint16
}

MsgHdr dns协议头

func (*MsgHdr) Copy

func (h *MsgHdr) Copy(dst *MsgHdr) error

Copy header 深拷贝函数

func (*MsgHdr) Pack

func (h *MsgHdr) Pack(buff *bytes.Buffer) (int, error)

Pack header序列化

func (*MsgHdr) SetDefaultValue

func (h *MsgHdr) SetDefaultValue(id uint16, opCode int)

SetDefaultValue header设置默认值

func (*MsgHdr) String

func (h *MsgHdr) String() string

返回 header的可读字符串,便于调式

func (*MsgHdr) Unpack

func (h *MsgHdr) Unpack(msg []byte) (int, error)

Unpack header反序列化

type Name

type Name string

Name is a DNS domain name.

type OPT

type OPT struct {
	Hdr    RR_Header
	Option []EDNS0 `dns:"opt"`
}

OPT is the EDNS0 RR appended to messages to convey extra (meta) information. See RFC 6891.

func (*OPT) GetData

func (o *OPT) GetData() []byte

GetData gets the data stored in the OPT record.

func (*OPT) Header

func (o *OPT) Header() *RR_Header

Header returns the header of the ens.

func (*OPT) PackData

func (o *OPT) PackData(buff *bytes.Buffer) (int, error)

PackData marshals the OPT record and returns the wire format.

func (*OPT) UnPackData

func (o *OPT) UnPackData(msg []byte, off int) (int, error)

UnPackData unmarshal the wire format into an OPT record.

type PackageCtrlRR

type PackageCtrlRR struct {
	Hdr          RR_Header
	TotalCount   uint16
	PackageIndex uint16
	SplitMode    uint8
}

PackageCtrlRR 用于大量数据,UDP分包控制

func (*PackageCtrlRR) Copy

func (rr *PackageCtrlRR) Copy() RR

Copy 深拷贝

func (*PackageCtrlRR) GetData

func (rr *PackageCtrlRR) GetData() []byte

GetData 获取RR data

func (*PackageCtrlRR) Header

func (rr *PackageCtrlRR) Header() *RR_Header

Header 返回header

func (*PackageCtrlRR) PackData

func (rr *PackageCtrlRR) PackData(buff *bytes.Buffer) (int, error)

PackData 序列化 RR data

func (*PackageCtrlRR) String

func (rr *PackageCtrlRR) String() string

String 打印string

func (*PackageCtrlRR) UnPackData

func (rr *PackageCtrlRR) UnPackData(msg []byte, off int) (int, error)

UnPackData 反序列化RR data

type PolarisGetResourceQuestion

type PolarisGetResourceQuestion struct {
	BasePolarisQuestion
	Req *v1.DiscoverRequest
}

PolarisGetResourceQuestion Polaris 获取Resource的question

type PolarisHeaderRR

type PolarisHeaderRR struct {
	Hdr RR_Header
}

PolarisHeaderRR polaris 自定义header RR (additional RR)

func (*PolarisHeaderRR) GetData

func (rr *PolarisHeaderRR) GetData() []byte

GetData GetData

func (*PolarisHeaderRR) Header

func (rr *PolarisHeaderRR) Header() *RR_Header

Header 返回header

func (*PolarisHeaderRR) PackData

func (rr *PolarisHeaderRR) PackData(buff *bytes.Buffer) (int, error)

PackData 序列化 RR data

func (*PolarisHeaderRR) UnPackData

func (rr *PolarisHeaderRR) UnPackData(_ []byte, off int) (int, error)

UnPackData 反序列化RR data

type PolarisInstanceQuestion

type PolarisInstanceQuestion struct {
	BasePolarisQuestion
	Req *v1.Instance
}

PolarisInstanceQuestion Polaris 注册、反注册、心跳 Question

type PolarisReportClientQuestion

type PolarisReportClientQuestion struct {
	BasePolarisQuestion
	Req *v1.Client
}

PolarisReportClientQuestion Polaris 客户端上报(获取SideCar地理位置)

type Question

type Question interface {
	String() string
	// contains filtered or unexported methods
}

Question dns Question interface定义

type RR

type RR interface {
	// Header 返回RR header
	Header() *RR_Header
	// PackData RR中data的序列化
	PackData(buff *bytes.Buffer) (int, error)
	// UnPackData RR中data的反序列化
	UnPackData(msg []byte, off int) (int, error)
	// GetData 获取RR data的二进制数据
	GetData() []byte
}

RR interface定义

func NewAAAARR

func NewAAAARR(name string, ip net.IP, ttl uint32) RR

NewAAAARR 创建一个AAAA RR

func NewARR

func NewARR(name string, ip net.IP, ttl uint32) RR

NewARR 创建一个A RR

func UnpackRR

func UnpackRR(msg []byte, off int) (RR, int, error)

UnpackRR RR反序列化

func UnpackRRWithRRHeader

func UnpackRRWithRRHeader(h RR_Header, msg []byte, off int) (RR, int, error)

UnpackRRWithRRHeader 通过RR header信息反序列化RR其他部分

type RR_Header

type RR_Header struct {
	Name     string `dns:"cdomain-name"`
	Rrtype   uint16
	Class    uint16
	Ttl      uint32
	Rdlength uint16 // Length of data after header.
}

RR_Header RR的header

func (*RR_Header) Header

func (h *RR_Header) Header() *RR_Header

Header 返回RR header

func (*RR_Header) String

func (h *RR_Header) String() string

String 为了调试输出,非必要实现

type ResponseRR

type ResponseRR struct {
	StreamRR
	Hdr      RR_Header
	Response *namingpb.Response
}

ResponseRR polaris 应答RR

func (*ResponseRR) GetData

func (rr *ResponseRR) GetData() []byte

GetData 获取RR data

func (*ResponseRR) Header

func (rr *ResponseRR) Header() *RR_Header

Header 返回header

func (*ResponseRR) PackData

func (rr *ResponseRR) PackData(buff *bytes.Buffer) (int, error)

PackData 序列化 RR data

func (*ResponseRR) UnPackData

func (rr *ResponseRR) UnPackData(msg []byte, off int) (int, error)

UnPackData 反序列化RR data

type SRV

type SRV struct {
	Hdr      RR_Header
	Priority uint16
	Weight   uint16
	Port     uint16
	Target   string `dns:"domain-name"`
}

SRV RR. See RFC 2782.

type StreamRR

type StreamRR struct {
	Hdr   RR_Header
	Bytes []byte
}

StreamRR polaris 二进制流RR 用于4层分包

func (*StreamRR) GetData

func (rr *StreamRR) GetData() []byte

GetData 获取RR data

func (*StreamRR) Header

func (rr *StreamRR) Header() *RR_Header

Header 返回header

func (*StreamRR) PackData

func (rr *StreamRR) PackData(buff *bytes.Buffer) (int, error)

PackData 序列化 RR data

func (*StreamRR) UnPackData

func (rr *StreamRR) UnPackData(msg []byte, off int) (int, error)

UnPackData 反序列化RR data

type Type

type Type uint16

Type is a DNS type.

func (Type) String

func (t Type) String() string

String returns the string representation for the type t.

Jump to

Keyboard shortcuts

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