dns/types.go

857 lines
18 KiB
Go
Raw Normal View History

2010-08-04 07:57:59 +10:00
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Extended and bugfixes by Miek Gieben
2010-08-04 07:57:59 +10:00
package dns
import (
2011-08-22 22:11:41 +10:00
"os"
2010-08-04 07:57:59 +10:00
"net"
"time"
2010-08-04 07:57:59 +10:00
"strconv"
2010-12-30 02:11:23 +11:00
"strings"
2010-08-04 07:57:59 +10:00
)
// Packet formats
2011-01-27 19:29:11 +11:00
// Wire constants and supported types.
2010-08-04 07:57:59 +10:00
const (
// valid RR_Header.Rrtype and Question.qtype
2011-08-22 22:11:41 +10:00
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
TypeWKS uint16 = 11
TypePTR uint16 = 12
TypeHINFO uint16 = 13
TypeMINFO uint16 = 14
TypeMX uint16 = 15
TypeTXT uint16 = 16
TypeAAAA uint16 = 28
TypeLOC uint16 = 29
TypeSRV uint16 = 33
TypeNAPTR uint16 = 35
TypeKX uint16 = 36
TypeCERT uint16 = 37
TypeDNAME uint16 = 39
2010-08-04 07:57:59 +10:00
// EDNS
2011-08-22 22:11:41 +10:00
TypeOPT uint16 = 41
TypeSIG uint16 = 24
TypeKEY uint16 = 25
TypeNXT uint16 = 30
TypeDS uint16 = 43
TypeSSHFP uint16 = 44
TypeIPSECKEY uint16 = 45 // No type implemented
TypeRRSIG uint16 = 46
TypeNSEC uint16 = 47
TypeDNSKEY uint16 = 48
TypeDHCID uint16 = 49
TypeNSEC3 uint16 = 50
TypeNSEC3PARAM uint16 = 51
TypeTALINK uint16 = 58
TypeSPF uint16 = 99
TypeTKEY uint16 = 249
TypeTSIG uint16 = 250
2011-03-25 21:19:35 +11:00
// valid Question.Qtype only
2011-08-22 22:11:41 +10:00
TypeIXFR uint16 = 251
TypeAXFR uint16 = 252
TypeMAILB uint16 = 253
TypeMAILA uint16 = 254
TypeANY uint16 = 255
TypeURI uint16 = 256
TypeTA uint16 = 32768
TypeDLV uint16 = 32769
2011-02-21 23:16:07 +11:00
2011-03-25 21:19:35 +11:00
// valid Question.Qclass
2010-08-04 07:57:59 +10:00
ClassINET = 1
ClassCSNET = 2
ClassCHAOS = 3
ClassHESIOD = 4
2011-07-23 17:21:24 +10:00
ClassNONE = 254
2010-08-04 07:57:59 +10:00
ClassANY = 255
// Msg.rcode
RcodeSuccess = 0
RcodeFormatError = 1
RcodeServerFailure = 2
RcodeNameError = 3
RcodeNotImplemented = 4
RcodeRefused = 5
2011-01-10 06:46:21 +11:00
RcodeYXDomain = 6
RcodeYXRrset = 7
RcodeNXRrset = 8
RcodeNotAuth = 9
RcodeNotZone = 10
2011-01-27 01:13:06 +11:00
RcodeBadSig = 16 // TSIG
RcodeBadKey = 17
RcodeBadTime = 18
RcodeBadMode = 19 // TKEY
RcodeBadName = 20
RcodeBadAlg = 21
RcodeBadTrunc = 22 // TSIG
2011-01-02 05:51:25 +11:00
// Opcode
OpcodeQuery = 0
OpcodeIQuery = 1
OpcodeStatus = 2
// There is no 3
OpcodeNotify = 4
2011-01-02 06:51:34 +11:00
OpcodeUpdate = 5
2010-08-04 07:57:59 +10:00
)
// The wire format for the DNS packet header.
type Header struct {
Id uint16
Bits uint16
Qdcount, Ancount, Nscount, Arcount uint16
}
const (
// 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 // authticated data
_CD = 1 << 4 // checking disabled
2010-08-04 07:57:59 +10:00
)
// DNS queries.
type Question struct {
2011-02-22 02:20:24 +11:00
Name string "domain-name" // "domain-name" specifies encoding
2010-08-04 07:57:59 +10:00
Qtype uint16
Qclass uint16
}
func (q *Question) String() string {
// prefix with ; (as in dig)
s := ";" + q.Name + "\t"
s = s + Class_str[q.Qclass] + "\t"
2011-03-08 08:47:20 +11:00
if _, ok := Rr_str[q.Qtype]; ok {
s += " " + Rr_str[q.Qtype]
} else {
s += " " + "TYPE" + strconv.Itoa(int(q.Qtype))
}
2010-08-04 07:57:59 +10:00
return s
}
2011-07-25 19:24:26 +10:00
// NewRRString returns the last RR contained in s.
func NewRRString(s string) (RR, os.Error) {
p := NewParser(strings.NewReader(s))
return p.First()
}
2011-07-25 19:24:26 +10:00
// NewRR returns a new RR with the hdr.Rrtype also set.
// If the type i is not known, nil is returned.
2011-08-08 18:35:16 +10:00
func NewRR(i uint16) RR {
2011-08-22 22:11:41 +10:00
r := rr_mk[i]()
r.Header().Rrtype = i
return r
2011-07-25 19:24:26 +10:00
}
2011-08-22 22:13:43 +10:00
type RR_ANY struct {
Hdr RR_Header
// Does not have any rdata
}
func (rr *RR_ANY) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_ANY) String() string {
return rr.Hdr.String()
}
2010-08-04 07:57:59 +10:00
type RR_CNAME struct {
Hdr RR_Header
Cname string "domain-name"
}
func (rr *RR_CNAME) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_CNAME) String() string {
return rr.Hdr.String() + rr.Cname
}
type RR_HINFO struct {
Hdr RR_Header
Cpu string
Os string
}
func (rr *RR_HINFO) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_HINFO) String() string {
return rr.Hdr.String() + rr.Cpu + " " + rr.Os
}
type RR_MB struct {
Hdr RR_Header
Mb string "domain-name"
}
func (rr *RR_MB) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_MB) String() string {
return rr.Hdr.String() + rr.Mb
}
type RR_MG struct {
Hdr RR_Header
Mg string "domain-name"
}
func (rr *RR_MG) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_MG) String() string {
return rr.Hdr.String() + rr.Mg
}
type RR_MINFO struct {
Hdr RR_Header
Rmail string "domain-name"
Email string "domain-name"
}
func (rr *RR_MINFO) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_MINFO) String() string {
return rr.Hdr.String() + rr.Rmail + " " + rr.Email
}
type RR_MR struct {
Hdr RR_Header
Mr string "domain-name"
}
func (rr *RR_MR) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_MR) String() string {
return rr.Hdr.String() + rr.Mr
}
type RR_MX struct {
Hdr RR_Header
Pref uint16
Mx string "domain-name"
}
func (rr *RR_MX) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_MX) String() string {
return rr.Hdr.String() + strconv.Itoa(int(rr.Pref)) + " " + rr.Mx
}
type RR_NS struct {
Hdr RR_Header
Ns string "domain-name"
}
func (rr *RR_NS) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_NS) String() string {
return rr.Hdr.String() + rr.Ns
}
type RR_PTR struct {
Hdr RR_Header
Ptr string "domain-name"
}
func (rr *RR_PTR) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_PTR) String() string {
return rr.Hdr.String() + rr.Ptr
}
type RR_SOA struct {
Hdr RR_Header
Ns string "domain-name"
Mbox string "domain-name"
Serial uint32
Refresh uint32
Retry uint32
Expire uint32
Minttl uint32
}
func (rr *RR_SOA) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_SOA) String() string {
return rr.Hdr.String() + rr.Ns + " " + rr.Mbox +
" " + strconv.Itoa(int(rr.Serial)) +
" " + strconv.Itoa(int(rr.Refresh)) +
" " + strconv.Itoa(int(rr.Retry)) +
" " + strconv.Itoa(int(rr.Expire)) +
" " + strconv.Itoa(int(rr.Minttl))
}
type RR_TXT struct {
Hdr RR_Header
Txt string "txt"
2010-08-04 07:57:59 +10:00
}
func (rr *RR_TXT) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_TXT) String() string {
return rr.Hdr.String() + "\"" + rr.Txt + "\""
}
type RR_SRV struct {
Hdr RR_Header
Priority uint16
Weight uint16
Port uint16
Target string "domain-name"
}
func (rr *RR_SRV) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_SRV) String() string {
return rr.Hdr.String() +
strconv.Itoa(int(rr.Priority)) + " " +
strconv.Itoa(int(rr.Weight)) + " " +
strconv.Itoa(int(rr.Port)) + " " + rr.Target
}
2010-12-31 06:50:31 +11:00
type RR_NAPTR struct {
Hdr RR_Header
Order uint16
Preference uint16
Flags string
Service string
Regexp string
2011-01-17 20:30:20 +11:00
Replacement string "domain-name"
2010-12-31 06:50:31 +11:00
}
func (rr *RR_NAPTR) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_NAPTR) String() string {
2011-01-18 02:03:06 +11:00
return rr.Hdr.String() +
2011-01-17 20:30:20 +11:00
strconv.Itoa(int(rr.Order)) + " " +
strconv.Itoa(int(rr.Preference)) + " " +
"\"" + rr.Flags + "\" " +
"\"" + rr.Service + "\" " +
"\"" + rr.Regexp + "\" " +
rr.Replacement
2010-12-31 06:50:31 +11:00
}
2011-02-25 02:13:23 +11:00
// See RFC 4398.
type RR_CERT struct {
Hdr RR_Header
Type uint16
KeyTag uint16
Algorithm uint8
Certificate string "base64"
}
func (rr *RR_CERT) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_CERT) String() string {
return rr.Hdr.String() + strconv.Itoa(int(rr.Type)) +
" " + strconv.Itoa(int(rr.KeyTag)) +
" " + strconv.Itoa(int(rr.Algorithm)) +
" " + rr.Certificate
}
2011-01-27 19:29:11 +11:00
// See RFC 2672.
2011-01-25 23:47:12 +11:00
type RR_DNAME struct {
Hdr RR_Header
Target string "domain-name"
2011-01-25 23:47:12 +11:00
}
func (rr *RR_DNAME) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_DNAME) String() string {
return rr.Hdr.String() + rr.Target
2011-01-25 23:47:12 +11:00
}
2010-08-04 07:57:59 +10:00
type RR_A struct {
Hdr RR_Header
A net.IP "A"
2010-08-04 07:57:59 +10:00
}
func (rr *RR_A) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_A) String() string {
return rr.Hdr.String() + rr.A.String()
}
type RR_AAAA struct {
Hdr RR_Header
AAAA net.IP "AAAA"
2010-08-04 07:57:59 +10:00
}
func (rr *RR_AAAA) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_AAAA) String() string {
return rr.Hdr.String() + rr.AAAA.String()
}
2010-12-31 06:55:25 +11:00
type RR_LOC struct {
Hdr RR_Header
Version uint8
Size uint8
HorizPre uint8
VertPre uint8
Latitude uint32
Longitude uint32
Altitude uint32
2010-12-31 06:55:25 +11:00
}
func (rr *RR_LOC) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_LOC) String() string {
// Version is not shown
2010-12-31 06:55:25 +11:00
return rr.Hdr.String() + "TODO"
}
2010-08-04 07:57:59 +10:00
type RR_RRSIG struct {
2010-12-23 21:02:01 +11:00
Hdr RR_Header
TypeCovered uint16
Algorithm uint8
Labels uint8
OrigTtl uint32
Expiration uint32
Inception uint32
KeyTag uint16
SignerName string "domain-name"
Signature string "base64"
2010-08-04 07:57:59 +10:00
}
func (rr *RR_RRSIG) Header() *RR_Header {
return &rr.Hdr
}
2010-08-04 07:57:59 +10:00
func (rr *RR_RRSIG) String() string {
2011-01-18 02:03:06 +11:00
return rr.Hdr.String() + Rr_str[rr.TypeCovered] +
2010-12-21 08:20:13 +11:00
" " + strconv.Itoa(int(rr.Algorithm)) +
" " + strconv.Itoa(int(rr.Labels)) +
" " + strconv.Itoa(int(rr.OrigTtl)) +
" " + timeToDate(rr.Expiration) +
" " + timeToDate(rr.Inception) +
2010-12-21 08:20:13 +11:00
" " + strconv.Itoa(int(rr.KeyTag)) +
" " + rr.SignerName +
" " + rr.Signature
2010-08-04 07:57:59 +10:00
}
type RR_NSEC struct {
Hdr RR_Header
2011-01-10 06:46:21 +11:00
NextDomain string "domain-name"
TypeBitMap []uint16 "NSEC"
2010-08-04 07:57:59 +10:00
}
func (rr *RR_NSEC) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_NSEC) String() string {
2011-01-18 02:03:06 +11:00
s := rr.Hdr.String() + rr.NextDomain
2011-01-17 20:30:20 +11:00
for i := 0; i < len(rr.TypeBitMap); i++ {
2011-02-25 02:22:14 +11:00
if _, ok := Rr_str[rr.TypeBitMap[i]]; ok {
s += " " + Rr_str[rr.TypeBitMap[i]]
} else {
s += " " + "TYPE" + strconv.Itoa(int(rr.TypeBitMap[i]))
}
2011-01-17 20:30:20 +11:00
}
return s
2010-08-04 07:57:59 +10:00
}
type RR_DS struct {
Hdr RR_Header
KeyTag uint16
Algorithm uint8
DigestType uint8
Digest string "hex"
}
func (rr *RR_DS) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_DS) String() string {
2011-01-18 02:03:06 +11:00
return rr.Hdr.String() + strconv.Itoa(int(rr.KeyTag)) +
" " + strconv.Itoa(int(rr.Algorithm)) +
2010-08-04 07:57:59 +10:00
" " + strconv.Itoa(int(rr.DigestType)) +
" " + strings.ToUpper(rr.Digest)
2010-08-04 07:57:59 +10:00
}
2011-02-21 23:16:07 +11:00
type RR_DLV struct {
Hdr RR_Header
KeyTag uint16
Algorithm uint8
DigestType uint8
Digest string "hex"
}
func (rr *RR_DLV) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_DLV) String() string {
return rr.Hdr.String() + strconv.Itoa(int(rr.KeyTag)) +
" " + strconv.Itoa(int(rr.Algorithm)) +
" " + strconv.Itoa(int(rr.DigestType)) +
" " + strings.ToUpper(rr.Digest)
}
2011-03-13 23:04:54 +11:00
type RR_KX struct {
2011-07-23 17:21:24 +10:00
Hdr RR_Header
Preference uint16
Exchanger string "domain-name"
2011-03-13 23:04:54 +11:00
}
func (rr *RR_KX) Header() *RR_Header {
2011-07-23 17:21:24 +10:00
return &rr.Hdr
2011-03-13 23:04:54 +11:00
}
func (rr *RR_KX) String() string {
2011-07-23 17:21:24 +10:00
return rr.Hdr.String() + strconv.Itoa(int(rr.Preference)) +
" " + rr.Exchanger
2011-03-13 23:04:54 +11:00
}
2011-02-21 23:16:07 +11:00
type RR_TA struct {
Hdr RR_Header
KeyTag uint16
Algorithm uint8
DigestType uint8
Digest string "hex"
}
func (rr *RR_TA) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_TA) String() string {
return rr.Hdr.String() + strconv.Itoa(int(rr.KeyTag)) +
" " + strconv.Itoa(int(rr.Algorithm)) +
" " + strconv.Itoa(int(rr.DigestType)) +
" " + strings.ToUpper(rr.Digest)
}
2011-01-17 20:30:20 +11:00
2011-02-21 23:24:45 +11:00
type RR_TALINK struct {
Hdr RR_Header
PreviousName string "domain"
NextName string "domain"
}
func (rr *RR_TALINK) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_TALINK) String() string {
return rr.Hdr.String() +
" " + rr.PreviousName + " " + rr.NextName
}
2011-01-17 20:30:20 +11:00
type RR_SSHFP struct {
Hdr RR_Header
Algorithm uint8
Type uint8
FingerPrint string "hex"
}
func (rr *RR_SSHFP) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_SSHFP) String() string {
2011-01-18 02:03:06 +11:00
return rr.Hdr.String() + strconv.Itoa(int(rr.Algorithm)) +
2011-01-17 20:30:20 +11:00
" " + strconv.Itoa(int(rr.Type)) +
" " + strings.ToUpper(rr.FingerPrint)
}
2010-08-04 07:57:59 +10:00
type RR_DNSKEY struct {
Hdr RR_Header
Flags uint16
Protocol uint8
Algorithm uint8
2011-01-26 00:07:01 +11:00
PublicKey string "base64"
2010-08-04 07:57:59 +10:00
}
func (rr *RR_DNSKEY) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_DNSKEY) String() string {
2011-01-18 02:03:06 +11:00
return rr.Hdr.String() + strconv.Itoa(int(rr.Flags)) +
2010-08-04 07:57:59 +10:00
" " + strconv.Itoa(int(rr.Protocol)) +
2010-12-21 08:20:13 +11:00
" " + strconv.Itoa(int(rr.Algorithm)) +
" " + rr.PublicKey
2010-08-04 07:57:59 +10:00
}
type RR_NSEC3 struct {
Hdr RR_Header
Hash uint8
Flags uint8
Iterations uint16
SaltLength uint8
2011-02-04 06:39:43 +11:00
Salt string "size-hex"
HashLength uint8
2011-02-04 06:39:43 +11:00
NextDomain string "size-base32"
2011-01-10 06:46:21 +11:00
TypeBitMap []uint16 "NSEC"
2010-08-04 07:57:59 +10:00
}
func (rr *RR_NSEC3) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_NSEC3) String() string {
2011-01-17 20:30:20 +11:00
s := rr.Hdr.String()
2011-01-18 02:03:06 +11:00
s += strconv.Itoa(int(rr.Hash)) +
2011-01-17 20:30:20 +11:00
" " + strconv.Itoa(int(rr.Flags)) +
" " + strconv.Itoa(int(rr.Iterations)) +
" " + strings.ToUpper(rr.Salt) +
2011-02-22 02:21:16 +11:00
" " + rr.NextDomain
2011-01-17 20:30:20 +11:00
for i := 0; i < len(rr.TypeBitMap); i++ {
2011-02-25 02:22:14 +11:00
if _, ok := Rr_str[rr.TypeBitMap[i]]; ok {
s += " " + Rr_str[rr.TypeBitMap[i]]
} else {
s += " " + "TYPE" + strconv.Itoa(int(rr.TypeBitMap[i]))
}
2011-01-17 20:30:20 +11:00
}
return s
2010-08-04 07:57:59 +10:00
}
type RR_NSEC3PARAM struct {
Hdr RR_Header
Hash uint8
Flags uint8
Iterations uint16
SaltLength uint8
2011-07-25 05:40:04 +10:00
Salt string "hex" // hexsize??
2010-08-04 07:57:59 +10:00
}
func (rr *RR_NSEC3PARAM) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_NSEC3PARAM) String() string {
2011-01-18 02:03:06 +11:00
s := rr.Hdr.String()
s += strconv.Itoa(int(rr.Hash)) +
" " + strconv.Itoa(int(rr.Flags)) +
" " + strconv.Itoa(int(rr.Iterations)) +
" " + strings.ToUpper(rr.Salt)
return s
2010-08-04 07:57:59 +10:00
}
2011-02-25 02:22:14 +11:00
// See RFC 4408.
2011-01-26 00:07:01 +11:00
type RR_SPF struct {
Hdr RR_Header
Txt string
}
func (rr *RR_SPF) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_SPF) String() string {
return rr.Hdr.String() + "\"" + rr.Txt + "\""
}
type RR_TKEY struct {
Hdr RR_Header
Algorithm string "domain-name"
Inception uint32
Expiration uint32
Mode uint16
Error uint16
KeySize uint16
Key string
Otherlen uint16
OtherData string
}
func (rr *RR_TKEY) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_TKEY) String() string {
2011-01-10 06:46:21 +11:00
// It has no presentation format
return ""
}
2011-02-22 01:19:52 +11:00
// Unknown RR representation
type RR_RFC3597 struct {
2011-02-25 02:22:14 +11:00
Hdr RR_Header
Rdata string "hex"
2011-02-22 01:19:52 +11:00
}
func (rr *RR_RFC3597) Header() *RR_Header {
2011-02-25 02:22:14 +11:00
return &rr.Hdr
2011-02-22 01:19:52 +11:00
}
func (rr *RR_RFC3597) String() string {
2011-02-25 02:22:14 +11:00
s := rr.Hdr.String()
s += "\\# " + strconv.Itoa(len(rr.Rdata)/2) + " " + rr.Rdata
return s
2011-02-22 01:19:52 +11:00
}
type RR_URI struct {
2011-02-25 02:22:14 +11:00
Hdr RR_Header
Priority uint16
Weight uint16
Target string
}
func (rr *RR_URI) Header() *RR_Header {
return &rr.Hdr
}
func (rr *RR_URI) String() string {
2011-02-25 02:22:14 +11:00
return rr.Hdr.String() + strconv.Itoa(int(rr.Priority)) +
" " + strconv.Itoa(int(rr.Weight)) +
" " + rr.Target
}
2011-03-13 23:11:11 +11:00
type RR_DHCID struct {
2011-07-23 17:21:24 +10:00
Hdr RR_Header
Digest string "base64"
2011-03-13 23:11:11 +11:00
}
func (rr *RR_DHCID) Header() *RR_Header {
2011-07-23 17:21:24 +10:00
return &rr.Hdr
2011-03-13 23:11:11 +11:00
}
func (rr *RR_DHCID) String() string {
2011-07-23 17:21:24 +10:00
return rr.Hdr.String() + rr.Digest
2011-03-13 23:11:11 +11:00
}
2011-03-21 20:51:28 +11:00
// RFC 2845.
type RR_TSIG struct {
2011-07-23 17:21:24 +10:00
Hdr RR_Header
Algorithm string "domain-name"
TimeSigned uint64
Fudge uint16
MACSize uint16
MAC string "size-hex"
OrigId uint16
Error uint16
OtherLen uint16
OtherData string "size-hex"
2011-03-21 20:51:28 +11:00
}
func (rr *RR_TSIG) Header() *RR_Header {
2011-07-23 17:21:24 +10:00
return &rr.Hdr
2011-03-21 20:51:28 +11:00
}
// TSIG has no official presentation format, but this will suffice.
func (rr *RR_TSIG) String() string {
2011-07-23 17:21:24 +10:00
return rr.Hdr.String() +
" " + rr.Algorithm +
" " + tsigTimeToDate(rr.TimeSigned) +
" " + strconv.Itoa(int(rr.Fudge)) +
" " + strconv.Itoa(int(rr.MACSize)) +
" " + strings.ToUpper(rr.MAC) +
" " + strconv.Itoa(int(rr.OrigId)) +
" " + strconv.Itoa(int(rr.Error)) + // BIND prints NOERROR
2011-07-23 17:21:24 +10:00
" " + strconv.Itoa(int(rr.OtherLen)) +
" " + rr.OtherData
2011-03-21 20:51:28 +11:00
}
// Translate the RRSIG's incep. and expir. time to the correct date.
// Taking into account serial arithmetic (RFC 1982)
func timeToDate(t uint32) string {
utc := time.UTC().Seconds()
mod := (int64(t) - utc) / Year68
// If needed assume wrap around(s)
ti := time.SecondsToUTC(int64(t) + (mod * Year68)) // abs()? TODO
2011-07-25 05:29:16 +10:00
return ti.Format("20060102150405")
}
// Translate the TSIG time signed into a date. There is no
// need for RFC1982 calculations as this date is 48 bits
func tsigTimeToDate(t uint64) string {
2011-01-10 01:54:23 +11:00
// only use the lower 48 bits, TODO(mg), check for 48 bit size
ti := time.SecondsToUTC(int64(t))
2011-07-25 05:29:16 +10:00
return ti.Format("20060102150405")
}
2010-08-04 07:57:59 +10:00
// Map of constructors for each RR wire type.
2011-08-04 23:13:10 +10:00
var rr_mk = map[uint16]func() RR{
2010-12-31 06:50:31 +11:00
TypeCNAME: func() RR { return new(RR_CNAME) },
TypeHINFO: func() RR { return new(RR_HINFO) },
TypeMB: func() RR { return new(RR_MB) },
TypeMG: func() RR { return new(RR_MG) },
TypeMINFO: func() RR { return new(RR_MINFO) },
TypeMR: func() RR { return new(RR_MR) },
TypeMX: func() RR { return new(RR_MX) },
TypeNS: func() RR { return new(RR_NS) },
TypePTR: func() RR { return new(RR_PTR) },
TypeSOA: func() RR { return new(RR_SOA) },
TypeTXT: func() RR { return new(RR_TXT) },
TypeSRV: func() RR { return new(RR_SRV) },
TypeNAPTR: func() RR { return new(RR_NAPTR) },
2011-01-25 23:47:12 +11:00
TypeDNAME: func() RR { return new(RR_DNAME) },
2010-12-31 06:50:31 +11:00
TypeA: func() RR { return new(RR_A) },
TypeAAAA: func() RR { return new(RR_AAAA) },
TypeLOC: func() RR { return new(RR_LOC) },
2010-12-31 06:50:31 +11:00
TypeOPT: func() RR { return new(RR_OPT) },
TypeDS: func() RR { return new(RR_DS) },
2011-07-23 17:21:24 +10:00
TypeCERT: func() RR { return new(RR_CERT) },
TypeKX: func() RR { return new(RR_KX) },
TypeSPF: func() RR { return new(RR_SPF) },
2011-02-21 23:24:45 +11:00
TypeTALINK: func() RR { return new(RR_TALINK) },
2011-01-17 20:30:20 +11:00
TypeSSHFP: func() RR { return new(RR_SSHFP) },
2010-12-31 06:50:31 +11:00
TypeRRSIG: func() RR { return new(RR_RRSIG) },
TypeNSEC: func() RR { return new(RR_NSEC) },
TypeDNSKEY: func() RR { return new(RR_DNSKEY) },
TypeNSEC3: func() RR { return new(RR_NSEC3) },
2011-07-23 17:21:24 +10:00
TypeDHCID: func() RR { return new(RR_DHCID) },
2010-12-31 06:50:31 +11:00
TypeNSEC3PARAM: func() RR { return new(RR_NSEC3PARAM) },
TypeTKEY: func() RR { return new(RR_TKEY) },
TypeTSIG: func() RR { return new(RR_TSIG) },
2011-02-25 02:22:14 +11:00
TypeURI: func() RR { return new(RR_URI) },
2011-02-21 23:16:07 +11:00
TypeTA: func() RR { return new(RR_TA) },
TypeDLV: func() RR { return new(RR_DLV) },
2010-08-04 07:57:59 +10:00
}