Documentation
¶
Overview ¶
Package dns edns provides EDNS options for DNS queries.
Index ¶
- Constants
- Variables
- func PackRR(rr RR, buff *bytes.Buffer) (int, error)
- func UnpackDomainName(msg []byte, off int) (string, int, error)
- type A
- type AAAA
- type BaseEDNSData
- type BasePolarisQuestion
- type Class
- type DNSQuestion
- type DetailErrInfoRR
- type EDNS0
- type EDNSDataCommon
- type Error
- type LocationRR
- type Msg
- func (dns *Msg) GetDetailErrRR() *DetailErrInfoRR
- func (dns *Msg) GetPackControlRR() *PackageCtrlRR
- func (dns *Msg) Pack() (*bytes.Buffer, error)
- func (dns *Msg) SetDNSQuestion(z string, t uint16) *Msg
- func (dns *Msg) SetReply(request *Msg)
- func (dns *Msg) SetReplyWithoutQuestions(request *Msg)
- func (dns *Msg) Unpack(msg []byte) (err error)
- func (dns *Msg) UnpackBody(msg []byte, off int) (err error)
- type MsgHdr
- type Name
- type OPT
- type PackageCtrlRR
- type PolarisGetResourceQuestion
- type PolarisHeaderRR
- type PolarisInstanceQuestion
- type PolarisReportClientQuestion
- type Question
- type RR
- type RR_Header
- type ResponseRR
- type SRV
- type StreamRR
- type Type
Constants ¶
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.
const ( // MinMsgSize UDP最小包长度 MinMsgSize = 512 // MaxMsgSize UDP最大包长度 MaxMsgSize = 65535 )
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.
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 )
const (
PackCtrlRRName = "packCtrl"
)
Variables ¶
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.
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.
var OpcodeToString = map[int]string{ OpcodeQuery: "QUERY", OpcodeIQuery: "IQUERY", OpcodeStatus: "STATUS", OpcodeNotify: "NOTIFY", OpcodeUpdate: "UPDATE", }
OpcodeToString maps Opcodes to strings.
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.
var StringToClass = reverseInt16(ClassToString)
StringToClass is the reverse of ClassToString, needed for string parsing.
var StringToOpcode = reverseInt(OpcodeToString)
StringToOpcode is a map of opcodes to strings.
var StringToRcode = reverseInt(RcodeToString)
StringToRcode is a map of rcodes to strings.
var StringToType = reverseInt16(TypeToString)
StringToType is the reverse of TypeToString, needed for string parsing.
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) }, }
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.
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 ¶
Types ¶
type BaseEDNSData ¶
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
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
type DetailErrInfoRR ¶
type DetailErrInfoRR struct { Hdr RR_Header ErrInfo *sidecarPb.DetailErrInfo }
DetailErrInfoRR polaris 详细错误 RR
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 ¶
EDNSDataCommon Base EDNS data common
func (*EDNSDataCommon) Option ¶
func (d *EDNSDataCommon) Option() uint16
Option implements the EDNS0 interface.
type LocationRR ¶
LocationRR location RR
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 ¶
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) SetDNSQuestion ¶
SetDNSQuestion Set Question
func (*Msg) SetReplyWithoutQuestions ¶
SetReplyWithoutQuestions 设置返回,不拷贝question
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) SetDefaultValue ¶
SetDefaultValue header设置默认值
type OPT ¶
OPT is the EDNS0 RR appended to messages to convey extra (meta) information. See RFC 6891.
type PackageCtrlRR ¶
PackageCtrlRR 用于大量数据,UDP分包控制
func (*PackageCtrlRR) PackData ¶
func (rr *PackageCtrlRR) PackData(buff *bytes.Buffer) (int, error)
PackData 序列化 RR data
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) 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定义
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
type ResponseRR ¶
ResponseRR polaris 应答RR
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.