Update Godeps for github.com/skynetservices/skydns and github.com/miekg/dns

pull/6/head
Girish Kalele 2016-06-29 14:05:43 -07:00
parent 594e4d883c
commit 6de83d5853
65 changed files with 5165 additions and 1472 deletions

22
Godeps/Godeps.json generated
View File

@ -1319,7 +1319,7 @@
}, },
{ {
"ImportPath": "github.com/miekg/dns", "ImportPath": "github.com/miekg/dns",
"Rev": "c2b278e70f35902fd68b54b69238cd10bb1b7451" "Rev": "5d001d020961ae1c184f9f8152fdc73810481677"
}, },
{ {
"ImportPath": "github.com/mistifyio/go-zfs", "ImportPath": "github.com/mistifyio/go-zfs",
@ -1802,28 +1802,28 @@
}, },
{ {
"ImportPath": "github.com/skynetservices/skydns/cache", "ImportPath": "github.com/skynetservices/skydns/cache",
"Comment": "2.5.3a-32-gf7b6fb7", "Comment": "2.5.3a-41-g00ade30",
"Rev": "f7b6fb74bcfab300b4e7e0e27b1fe6c0ed555f78" "Rev": "00ade3024f047d26130abf161900e0adb72a06f1"
}, },
{ {
"ImportPath": "github.com/skynetservices/skydns/metrics", "ImportPath": "github.com/skynetservices/skydns/metrics",
"Comment": "2.5.3a-32-gf7b6fb7", "Comment": "2.5.3a-41-g00ade30",
"Rev": "f7b6fb74bcfab300b4e7e0e27b1fe6c0ed555f78" "Rev": "00ade3024f047d26130abf161900e0adb72a06f1"
}, },
{ {
"ImportPath": "github.com/skynetservices/skydns/msg", "ImportPath": "github.com/skynetservices/skydns/msg",
"Comment": "2.5.3a-32-gf7b6fb7", "Comment": "2.5.3a-41-g00ade30",
"Rev": "f7b6fb74bcfab300b4e7e0e27b1fe6c0ed555f78" "Rev": "00ade3024f047d26130abf161900e0adb72a06f1"
}, },
{ {
"ImportPath": "github.com/skynetservices/skydns/server", "ImportPath": "github.com/skynetservices/skydns/server",
"Comment": "2.5.3a-32-gf7b6fb7", "Comment": "2.5.3a-41-g00ade30",
"Rev": "f7b6fb74bcfab300b4e7e0e27b1fe6c0ed555f78" "Rev": "00ade3024f047d26130abf161900e0adb72a06f1"
}, },
{ {
"ImportPath": "github.com/skynetservices/skydns/singleflight", "ImportPath": "github.com/skynetservices/skydns/singleflight",
"Comment": "2.5.3a-32-gf7b6fb7", "Comment": "2.5.3a-41-g00ade30",
"Rev": "f7b6fb74bcfab300b4e7e0e27b1fe6c0ed555f78" "Rev": "00ade3024f047d26130abf161900e0adb72a06f1"
}, },
{ {
"ImportPath": "github.com/spf13/cobra", "ImportPath": "github.com/spf13/cobra",

0
vendor/github.com/armon/go-metrics/.gitignore generated vendored Normal file → Executable file
View File

0
vendor/github.com/armon/go-metrics/metrics.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/armon/go-metrics/sink.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/armon/go-metrics/start.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/armon/go-metrics/statsite.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/coreos/go-oidc/jose/sig.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/coreos/go-oidc/jose/sig_hmac.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/coreos/go-oidc/jose/sig_rsa.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/coreos/go-oidc/oidc/key.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/elazarl/goproxy/all.bash generated vendored Normal file → Executable file
View File

0
vendor/github.com/hashicorp/go-msgpack/codec/msgpack_test.py generated vendored Normal file → Executable file
View File

0
vendor/github.com/kr/pty/mktypes.bash generated vendored Normal file → Executable file
View File

View File

@ -12,7 +12,7 @@ can build servers and resolvers with it.
We try to keep the "master" branch as sane as possible and at the bleeding edge We try to keep the "master" branch as sane as possible and at the bleeding edge
of standards, avoiding breaking changes wherever reasonable. We support the last of standards, avoiding breaking changes wherever reasonable. We support the last
two versions of Go, currently: 1.4 and 1.5. two versions of Go, currently: 1.5 and 1.6.
# Goals # Goals
@ -48,6 +48,8 @@ A not-so-up-to-date-list-that-may-be-actually-current:
* https://github.com/miekg/unbound * https://github.com/miekg/unbound
* https://github.com/miekg/exdns * https://github.com/miekg/exdns
* https://dnslookup.org * https://dnslookup.org
* https://github.com/looterz/grimd
* https://github.com/phamhongviet/serf-dns
Send pull request if you want to be listed here. Send pull request if you want to be listed here.
@ -61,7 +63,7 @@ Send pull request if you want to be listed here.
* Server side programming (mimicking the net/http package); * Server side programming (mimicking the net/http package);
* Client side programming; * Client side programming;
* DNSSEC: signing, validating and key generation for DSA, RSA and ECDSA; * DNSSEC: signing, validating and key generation for DSA, RSA and ECDSA;
* EDNS0, NSID; * EDNS0, NSID, Cookies;
* AXFR/IXFR; * AXFR/IXFR;
* TSIG, SIG(0); * TSIG, SIG(0);
* DNS over TLS: optional encrypted connection between client and server; * DNS over TLS: optional encrypted connection between client and server;
@ -111,7 +113,6 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
* 340{1,2,3} - NAPTR record * 340{1,2,3} - NAPTR record
* 3445 - Limiting the scope of (DNS)KEY * 3445 - Limiting the scope of (DNS)KEY
* 3597 - Unknown RRs * 3597 - Unknown RRs
* 4025 - IPSECKEY
* 403{3,4,5} - DNSSEC + validation functions * 403{3,4,5} - DNSSEC + validation functions
* 4255 - SSHFP record * 4255 - SSHFP record
* 4343 - Case insensitivity * 4343 - Case insensitivity
@ -138,8 +139,9 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
* 7043 - EUI48/EUI64 records * 7043 - EUI48/EUI64 records
* 7314 - DNS (EDNS) EXPIRE Option * 7314 - DNS (EDNS) EXPIRE Option
* 7553 - URI record * 7553 - URI record
* 7858 - DNS over TLS: Initiation and Performance Considerations (draft)
* 7873 - Domain Name System (DNS) Cookies (draft-ietf-dnsop-cookies)
* xxxx - EDNS0 DNS Update Lease (draft) * xxxx - EDNS0 DNS Update Lease (draft)
* yyyy - DNS over TLS: Initiation and Performance Considerations (draft)
## Loosely based upon ## Loosely based upon
@ -147,11 +149,3 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
* `NSD` * `NSD`
* `Net::DNS` * `Net::DNS`
* `GRONG` * `GRONG`
## TODO
* privatekey.Precompute() when signing?
* Last remaining RRs: APL, ATMA, A6, NSAP and NXT.
* Missing in parsing: ISDN, UNSPEC, NSAP and ATMA.
* NSEC(3) cover/match/closest enclose.
* Replies with TC bit are not parsed to the end.

View File

@ -5,6 +5,7 @@ package dns
import ( import (
"bytes" "bytes"
"crypto/tls" "crypto/tls"
"encoding/binary"
"io" "io"
"net" "net"
"time" "time"
@ -28,9 +29,10 @@ type Client struct {
Net string // if "tcp" or "tcp-tls" (DNS over TLS) a TCP query will be initiated, otherwise an UDP one (default is "" for UDP) Net string // if "tcp" or "tcp-tls" (DNS over TLS) a TCP query will be initiated, otherwise an UDP one (default is "" for UDP)
UDPSize uint16 // minimum receive buffer for UDP messages UDPSize uint16 // minimum receive buffer for UDP messages
TLSConfig *tls.Config // TLS connection configuration TLSConfig *tls.Config // TLS connection configuration
DialTimeout time.Duration // net.DialTimeout, defaults to 2 seconds Timeout time.Duration // a cumulative timeout for dial, write and read, defaults to 0 (disabled) - overrides DialTimeout, ReadTimeout and WriteTimeout when non-zero
ReadTimeout time.Duration // net.Conn.SetReadTimeout value for connections, defaults to 2 seconds DialTimeout time.Duration // net.DialTimeout, defaults to 2 seconds - overridden by Timeout when that value is non-zero
WriteTimeout time.Duration // net.Conn.SetWriteTimeout value for connections, defaults to 2 seconds ReadTimeout time.Duration // net.Conn.SetReadTimeout value for connections, defaults to 2 seconds - overridden by Timeout when that value is non-zero
WriteTimeout time.Duration // net.Conn.SetWriteTimeout value for connections, defaults to 2 seconds - overridden by Timeout when that value is non-zero
TsigSecret map[string]string // secret(s) for Tsig map[<zonename>]<base64 secret>, zonename must be fully qualified TsigSecret map[string]string // secret(s) for Tsig map[<zonename>]<base64 secret>, zonename must be fully qualified
SingleInflight bool // if true suppress multiple outstanding queries for the same Qname, Qtype and Qclass SingleInflight bool // if true suppress multiple outstanding queries for the same Qname, Qtype and Qclass
group singleflight group singleflight
@ -129,6 +131,9 @@ func (c *Client) Exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err erro
} }
func (c *Client) dialTimeout() time.Duration { func (c *Client) dialTimeout() time.Duration {
if c.Timeout != 0 {
return c.Timeout
}
if c.DialTimeout != 0 { if c.DialTimeout != 0 {
return c.DialTimeout return c.DialTimeout
} }
@ -170,6 +175,11 @@ func (c *Client) exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err erro
} }
} }
var deadline time.Time
if c.Timeout != 0 {
deadline = time.Now().Add(c.Timeout)
}
if tls { if tls {
co, err = DialTimeoutWithTLS(network, a, c.TLSConfig, c.dialTimeout()) co, err = DialTimeoutWithTLS(network, a, c.TLSConfig, c.dialTimeout())
} else { } else {
@ -192,12 +202,12 @@ func (c *Client) exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err erro
} }
co.TsigSecret = c.TsigSecret co.TsigSecret = c.TsigSecret
co.SetWriteDeadline(time.Now().Add(c.writeTimeout())) co.SetWriteDeadline(deadlineOrTimeout(deadline, c.writeTimeout()))
if err = co.WriteMsg(m); err != nil { if err = co.WriteMsg(m); err != nil {
return nil, 0, err return nil, 0, err
} }
co.SetReadDeadline(time.Now().Add(c.readTimeout())) co.SetReadDeadline(deadlineOrTimeout(deadline, c.readTimeout()))
r, err = co.ReadMsg() r, err = co.ReadMsg()
if err == nil && r.Id != m.Id { if err == nil && r.Id != m.Id {
err = ErrId err = ErrId
@ -274,9 +284,11 @@ func (co *Conn) ReadMsgHeader(hdr *Header) ([]byte, error) {
p = p[:n] p = p[:n]
if hdr != nil { if hdr != nil {
if _, err = UnpackStruct(hdr, p, 0); err != nil { dh, _, err := unpackMsgHdr(p, 0)
if err != nil {
return nil, err return nil, err
} }
*hdr = dh
} }
return p, err return p, err
} }
@ -291,7 +303,7 @@ func tcpMsgLen(t io.Reader) (int, error) {
if n != 2 { if n != 2 {
return 0, ErrShortRead return 0, ErrShortRead
} }
l, _ := unpackUint16(p, 0) l := binary.BigEndian.Uint16(p)
if l == 0 { if l == 0 {
return 0, ErrShortRead return 0, ErrShortRead
} }
@ -383,7 +395,7 @@ func (co *Conn) Write(p []byte) (n int, err error) {
return 0, &Error{err: "message too large"} return 0, &Error{err: "message too large"}
} }
l := make([]byte, 2, lp+2) l := make([]byte, 2, lp+2)
l[0], l[1] = packUint16(uint16(lp)) binary.BigEndian.PutUint16(l, uint16(lp))
p = append(l, p...) p = append(l, p...)
n, err := io.Copy(w, bytes.NewReader(p)) n, err := io.Copy(w, bytes.NewReader(p))
return int(n), err return int(n), err
@ -434,3 +446,10 @@ func DialTimeoutWithTLS(network, address string, tlsConfig *tls.Config, timeout
} }
return conn, nil return conn, nil
} }
func deadlineOrTimeout(deadline time.Time, timeout time.Duration) time.Time {
if deadline.IsZero() {
return time.Now().Add(timeout)
}
return deadline
}

View File

@ -142,9 +142,13 @@ func (dns *Msg) IsTsig() *TSIG {
// record in the additional section will do. It returns the OPT record // record in the additional section will do. It returns the OPT record
// found or nil. // found or nil.
func (dns *Msg) IsEdns0() *OPT { func (dns *Msg) IsEdns0() *OPT {
for _, r := range dns.Extra { // EDNS0 is at the end of the additional section, start there.
if r.Header().Rrtype == TypeOPT { // We might want to change this to *only* look at the last two
return r.(*OPT) // records. So we see TSIG and/or OPT - this a slightly bigger
// change though.
for i := len(dns.Extra) - 1; i >= 0; i-- {
if dns.Extra[i].Header().Rrtype == TypeOPT {
return dns.Extra[i].(*OPT)
} }
} }
return nil return nil
@ -163,8 +167,8 @@ func IsDomainName(s string) (labels int, ok bool) {
return labels, err == nil return labels, err == nil
} }
// IsSubDomain checks if child is indeed a child of the parent. Both child and // IsSubDomain checks if child is indeed a child of the parent. If child and parent
// parent are *not* downcased before doing the comparison. // are the same domain true is returned as well.
func IsSubDomain(parent, child string) bool { func IsSubDomain(parent, child string) bool {
// Entire child is contained in parent // Entire child is contained in parent
return CompareDomainName(parent, child) == CountLabel(parent) return CompareDomainName(parent, child) == CountLabel(parent)

38
vendor/github.com/miekg/dns/dns.go generated vendored
View File

@ -3,17 +3,15 @@ package dns
import "strconv" import "strconv"
const ( const (
year68 = 1 << 31 // For RFC1982 (Serial Arithmetic) calculations in 32 bits. year68 = 1 << 31 // For RFC1982 (Serial Arithmetic) calculations in 32 bits.
// DefaultMsgSize is the standard default for messages larger than 512 bytes. defaultTtl = 3600 // Default internal TTL.
DefaultMsgSize = 4096
// MinMsgSize is the minimal size of a DNS packet. DefaultMsgSize = 4096 // DefaultMsgSize is the standard default for messages larger than 512 bytes.
MinMsgSize = 512 MinMsgSize = 512 // MinMsgSize is the minimal size of a DNS packet.
// MaxMsgSize is the largest possible DNS packet. MaxMsgSize = 65535 // MaxMsgSize is the largest possible DNS packet.
MaxMsgSize = 65535
defaultTtl = 3600 // Default internal TTL.
) )
// Error represents a DNS error // Error represents a DNS error.
type Error struct{ err string } type Error struct{ err string }
func (e *Error) Error() string { func (e *Error) Error() string {
@ -30,10 +28,13 @@ type RR interface {
Header() *RR_Header Header() *RR_Header
// String returns the text representation of the resource record. // String returns the text representation of the resource record.
String() string String() string
// copy returns a copy of the RR // copy returns a copy of the RR
copy() RR copy() RR
// len returns the length (in octets) of the uncompressed RR in wire format. // len returns the length (in octets) of the uncompressed RR in wire format.
len() int len() int
// pack packs an RR into wire format.
pack([]byte, int, map[string]int, bool) (int, error)
} }
// RR_Header is the header all DNS resource records share. // RR_Header is the header all DNS resource records share.
@ -42,13 +43,13 @@ type RR_Header struct {
Rrtype uint16 Rrtype uint16
Class uint16 Class uint16
Ttl uint32 Ttl uint32
Rdlength uint16 // length of data after header Rdlength uint16 // Length of data after header.
} }
// Header returns itself. This is here to make RR_Header implement the RR interface. // Header returns itself. This is here to make RR_Header implements the RR interface.
func (h *RR_Header) Header() *RR_Header { return h } func (h *RR_Header) Header() *RR_Header { return h }
// Just to imlement the RR interface. // Just to implement the RR interface.
func (h *RR_Header) copy() RR { return nil } func (h *RR_Header) copy() RR { return nil }
func (h *RR_Header) copyHeader() *RR_Header { func (h *RR_Header) copyHeader() *RR_Header {
@ -82,19 +83,22 @@ func (h *RR_Header) len() int {
return l return l
} }
// ToRFC3597 converts a known RR to the unknown RR representation // ToRFC3597 converts a known RR to the unknown RR representation from RFC 3597.
// from RFC 3597.
func (rr *RFC3597) ToRFC3597(r RR) error { func (rr *RFC3597) ToRFC3597(r RR) error {
buf := make([]byte, r.len()*2) buf := make([]byte, r.len()*2)
off, err := PackStruct(r, buf, 0) off, err := PackRR(r, buf, 0, nil, false)
if err != nil { if err != nil {
return err return err
} }
buf = buf[:off] buf = buf[:off]
rawSetRdlength(buf, 0, off) if int(r.Header().Rdlength) > off {
_, err = UnpackStruct(rr, buf, 0) return ErrBuf
}
rfc3597, _, err := unpackRFC3597(*r.Header(), buf, off-int(r.Header().Rdlength))
if err != nil { if err != nil {
return err return err
} }
*rr = *rfc3597.(*RFC3597)
return nil return nil
} }

View File

@ -13,6 +13,7 @@ import (
_ "crypto/sha256" _ "crypto/sha256"
_ "crypto/sha512" _ "crypto/sha512"
"encoding/asn1" "encoding/asn1"
"encoding/binary"
"encoding/hex" "encoding/hex"
"math/big" "math/big"
"sort" "sort"
@ -103,9 +104,7 @@ const (
ZONE = 1 << 8 ZONE = 1 << 8
) )
// The RRSIG needs to be converted to wireformat with some of // The RRSIG needs to be converted to wireformat with some of the rdata (the signature) missing.
// the rdata (the signature) missing. Use this struct to ease
// the conversion (and re-use the pack/unpack functions).
type rrsigWireFmt struct { type rrsigWireFmt struct {
TypeCovered uint16 TypeCovered uint16
Algorithm uint8 Algorithm uint8
@ -144,7 +143,7 @@ func (k *DNSKEY) KeyTag() uint16 {
// at the base64 values. But I'm lazy. // at the base64 values. But I'm lazy.
modulus, _ := fromBase64([]byte(k.PublicKey)) modulus, _ := fromBase64([]byte(k.PublicKey))
if len(modulus) > 1 { if len(modulus) > 1 {
x, _ := unpackUint16(modulus, len(modulus)-2) x := binary.BigEndian.Uint16(modulus[len(modulus)-2:])
keytag = int(x) keytag = int(x)
} }
default: default:
@ -154,7 +153,7 @@ func (k *DNSKEY) KeyTag() uint16 {
keywire.Algorithm = k.Algorithm keywire.Algorithm = k.Algorithm
keywire.PublicKey = k.PublicKey keywire.PublicKey = k.PublicKey
wire := make([]byte, DefaultMsgSize) wire := make([]byte, DefaultMsgSize)
n, err := PackStruct(keywire, wire, 0) n, err := packKeyWire(keywire, wire)
if err != nil { if err != nil {
return 0 return 0
} }
@ -192,7 +191,7 @@ func (k *DNSKEY) ToDS(h uint8) *DS {
keywire.Algorithm = k.Algorithm keywire.Algorithm = k.Algorithm
keywire.PublicKey = k.PublicKey keywire.PublicKey = k.PublicKey
wire := make([]byte, DefaultMsgSize) wire := make([]byte, DefaultMsgSize)
n, err := PackStruct(keywire, wire, 0) n, err := packKeyWire(keywire, wire)
if err != nil { if err != nil {
return nil return nil
} }
@ -289,7 +288,7 @@ func (rr *RRSIG) Sign(k crypto.Signer, rrset []RR) error {
// Create the desired binary blob // Create the desired binary blob
signdata := make([]byte, DefaultMsgSize) signdata := make([]byte, DefaultMsgSize)
n, err := PackStruct(sigwire, signdata, 0) n, err := packSigWire(sigwire, signdata)
if err != nil { if err != nil {
return err return err
} }
@ -407,7 +406,7 @@ func (rr *RRSIG) Verify(k *DNSKEY, rrset []RR) error {
sigwire.SignerName = strings.ToLower(rr.SignerName) sigwire.SignerName = strings.ToLower(rr.SignerName)
// Create the desired binary blob // Create the desired binary blob
signeddata := make([]byte, DefaultMsgSize) signeddata := make([]byte, DefaultMsgSize)
n, err := PackStruct(sigwire, signeddata, 0) n, err := packSigWire(sigwire, signeddata)
if err != nil { if err != nil {
return err return err
} }
@ -662,3 +661,61 @@ func rawSignatureData(rrset []RR, s *RRSIG) (buf []byte, err error) {
} }
return buf, nil return buf, nil
} }
func packSigWire(sw *rrsigWireFmt, msg []byte) (int, error) {
// copied from zmsg.go RRSIG packing
off, err := packUint16(sw.TypeCovered, msg, 0)
if err != nil {
return off, err
}
off, err = packUint8(sw.Algorithm, msg, off)
if err != nil {
return off, err
}
off, err = packUint8(sw.Labels, msg, off)
if err != nil {
return off, err
}
off, err = packUint32(sw.OrigTtl, msg, off)
if err != nil {
return off, err
}
off, err = packUint32(sw.Expiration, msg, off)
if err != nil {
return off, err
}
off, err = packUint32(sw.Inception, msg, off)
if err != nil {
return off, err
}
off, err = packUint16(sw.KeyTag, msg, off)
if err != nil {
return off, err
}
off, err = PackDomainName(sw.SignerName, msg, off, nil, false)
if err != nil {
return off, err
}
return off, nil
}
func packKeyWire(dw *dnskeyWireFmt, msg []byte) (int, error) {
// copied from zmsg.go DNSKEY packing
off, err := packUint16(dw.Flags, msg, 0)
if err != nil {
return off, err
}
off, err = packUint8(dw.Protocol, msg, off)
if err != nil {
return off, err
}
off, err = packUint8(dw.Algorithm, msg, off)
if err != nil {
return off, err
}
off, err = packStringBase64(dw.PublicKey, msg, off)
if err != nil {
return off, err
}
return off, nil
}

View File

@ -25,9 +25,9 @@ func (k *DNSKEY) NewPrivateKey(s string) (crypto.PrivateKey, error) {
// The public key must be known, because some cryptographic algorithms embed // The public key must be known, because some cryptographic algorithms embed
// the public inside the privatekey. // the public inside the privatekey.
func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, error) { func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, error) {
m, e := parseKey(q, file) m, err := parseKey(q, file)
if m == nil { if m == nil {
return nil, e return nil, err
} }
if _, ok := m["private-key-format"]; !ok { if _, ok := m["private-key-format"]; !ok {
return nil, ErrPrivKey return nil, ErrPrivKey
@ -42,16 +42,16 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, er
} }
switch uint8(algo) { switch uint8(algo) {
case DSA: case DSA:
priv, e := readPrivateKeyDSA(m) priv, err := readPrivateKeyDSA(m)
if e != nil { if err != nil {
return nil, e return nil, err
} }
pub := k.publicKeyDSA() pub := k.publicKeyDSA()
if pub == nil { if pub == nil {
return nil, ErrKey return nil, ErrKey
} }
priv.PublicKey = *pub priv.PublicKey = *pub
return priv, e return priv, nil
case RSAMD5: case RSAMD5:
fallthrough fallthrough
case RSASHA1: case RSASHA1:
@ -61,31 +61,31 @@ func (k *DNSKEY) ReadPrivateKey(q io.Reader, file string) (crypto.PrivateKey, er
case RSASHA256: case RSASHA256:
fallthrough fallthrough
case RSASHA512: case RSASHA512:
priv, e := readPrivateKeyRSA(m) priv, err := readPrivateKeyRSA(m)
if e != nil { if err != nil {
return nil, e return nil, err
} }
pub := k.publicKeyRSA() pub := k.publicKeyRSA()
if pub == nil { if pub == nil {
return nil, ErrKey return nil, ErrKey
} }
priv.PublicKey = *pub priv.PublicKey = *pub
return priv, e return priv, nil
case ECCGOST: case ECCGOST:
return nil, ErrPrivKey return nil, ErrPrivKey
case ECDSAP256SHA256: case ECDSAP256SHA256:
fallthrough fallthrough
case ECDSAP384SHA384: case ECDSAP384SHA384:
priv, e := readPrivateKeyECDSA(m) priv, err := readPrivateKeyECDSA(m)
if e != nil { if err != nil {
return nil, e return nil, err
} }
pub := k.publicKeyECDSA() pub := k.publicKeyECDSA()
if pub == nil { if pub == nil {
return nil, ErrKey return nil, ErrKey
} }
priv.PublicKey = *pub priv.PublicKey = *pub
return priv, e return priv, nil
default: default:
return nil, ErrPrivKey return nil, ErrPrivKey
} }

95
vendor/github.com/miekg/dns/edns.go generated vendored
View File

@ -1,6 +1,7 @@
package dns package dns
import ( import (
"encoding/binary"
"encoding/hex" "encoding/hex"
"errors" "errors"
"net" "net"
@ -17,6 +18,7 @@ const (
EDNS0N3U = 0x7 // NSEC3 Hash Understood EDNS0N3U = 0x7 // NSEC3 Hash Understood
EDNS0SUBNET = 0x8 // client-subnet (RFC6891) EDNS0SUBNET = 0x8 // client-subnet (RFC6891)
EDNS0EXPIRE = 0x9 // EDNS0 expire EDNS0EXPIRE = 0x9 // EDNS0 expire
EDNS0COOKIE = 0xa // EDNS0 Cookie
EDNS0SUBNETDRAFT = 0x50fa // Don't use! Use EDNS0SUBNET EDNS0SUBNETDRAFT = 0x50fa // Don't use! Use EDNS0SUBNET
EDNS0LOCALSTART = 0xFDE9 // Beginning of range reserved for local/experimental use (RFC6891) EDNS0LOCALSTART = 0xFDE9 // Beginning of range reserved for local/experimental use (RFC6891)
EDNS0LOCALEND = 0xFFFE // End of range reserved for local/experimental use (RFC6891) EDNS0LOCALEND = 0xFFFE // End of range reserved for local/experimental use (RFC6891)
@ -56,6 +58,8 @@ func (rr *OPT) String() string {
if o.(*EDNS0_SUBNET).DraftOption { if o.(*EDNS0_SUBNET).DraftOption {
s += " (draft)" s += " (draft)"
} }
case *EDNS0_COOKIE:
s += "\n; COOKIE: " + o.String()
case *EDNS0_UL: case *EDNS0_UL:
s += "\n; UPDATE LEASE: " + o.String() s += "\n; UPDATE LEASE: " + o.String()
case *EDNS0_LLQ: case *EDNS0_LLQ:
@ -96,13 +100,16 @@ func (rr *OPT) SetVersion(v uint8) {
} }
// ExtendedRcode returns the EDNS extended RCODE field (the upper 8 bits of the TTL). // ExtendedRcode returns the EDNS extended RCODE field (the upper 8 bits of the TTL).
func (rr *OPT) ExtendedRcode() uint8 { func (rr *OPT) ExtendedRcode() int {
return uint8((rr.Hdr.Ttl & 0xFF000000) >> 24) return int((rr.Hdr.Ttl&0xFF000000)>>24) + 15
} }
// SetExtendedRcode sets the EDNS extended RCODE field. // SetExtendedRcode sets the EDNS extended RCODE field.
func (rr *OPT) SetExtendedRcode(v uint8) { func (rr *OPT) SetExtendedRcode(v uint8) {
rr.Hdr.Ttl = rr.Hdr.Ttl&0x00FFFFFF | (uint32(v) << 24) if v < RcodeBadVers { // Smaller than 16.. Use the 4 bits you have!
return
}
rr.Hdr.Ttl = rr.Hdr.Ttl&0x00FFFFFF | (uint32(v-15) << 24)
} }
// UDPSize returns the UDP buffer size. // UDPSize returns the UDP buffer size.
@ -125,8 +132,7 @@ func (rr *OPT) SetDo() {
rr.Hdr.Ttl |= _DO rr.Hdr.Ttl |= _DO
} }
// EDNS0 defines an EDNS0 Option. An OPT RR can have multiple options appended to // EDNS0 defines an EDNS0 Option. An OPT RR can have multiple options appended to it.
// it.
type EDNS0 interface { type EDNS0 interface {
// Option returns the option code for the option. // Option returns the option code for the option.
Option() uint16 Option() uint16
@ -207,7 +213,7 @@ func (e *EDNS0_SUBNET) Option() uint16 {
func (e *EDNS0_SUBNET) pack() ([]byte, error) { func (e *EDNS0_SUBNET) pack() ([]byte, error) {
b := make([]byte, 4) b := make([]byte, 4)
b[0], b[1] = packUint16(e.Family) binary.BigEndian.PutUint16(b[0:], e.Family)
b[2] = e.SourceNetmask b[2] = e.SourceNetmask
b[3] = e.SourceScope b[3] = e.SourceScope
switch e.Family { switch e.Family {
@ -241,7 +247,7 @@ func (e *EDNS0_SUBNET) unpack(b []byte) error {
if len(b) < 4 { if len(b) < 4 {
return ErrBuf return ErrBuf
} }
e.Family, _ = unpackUint16(b, 0) e.Family = binary.BigEndian.Uint16(b)
e.SourceNetmask = b[2] e.SourceNetmask = b[2]
e.SourceScope = b[3] e.SourceScope = b[3]
switch e.Family { switch e.Family {
@ -283,6 +289,41 @@ func (e *EDNS0_SUBNET) String() (s string) {
return return
} }
// The Cookie EDNS0 option
//
// o := new(dns.OPT)
// o.Hdr.Name = "."
// o.Hdr.Rrtype = dns.TypeOPT
// e := new(dns.EDNS0_COOKIE)
// e.Code = dns.EDNS0COOKIE
// e.Cookie = "24a5ac.."
// o.Option = append(o.Option, e)
//
// The Cookie field consists out of a client cookie (RFC 7873 Section 4), that is
// always 8 bytes. It may then optionally be followed by the server cookie. The server
// cookie is of variable length, 8 to a maximum of 32 bytes. In other words:
//
// cCookie := o.Cookie[:16]
// sCookie := o.Cookie[16:]
//
// There is no guarantee that the Cookie string has a specific length.
type EDNS0_COOKIE struct {
Code uint16 // Always EDNS0COOKIE
Cookie string // Hex-encoded cookie data
}
func (e *EDNS0_COOKIE) pack() ([]byte, error) {
h, err := hex.DecodeString(e.Cookie)
if err != nil {
return nil, err
}
return h, nil
}
func (e *EDNS0_COOKIE) Option() uint16 { return EDNS0COOKIE }
func (e *EDNS0_COOKIE) unpack(b []byte) error { e.Cookie = hex.EncodeToString(b); return nil }
func (e *EDNS0_COOKIE) String() string { return e.Cookie }
// The EDNS0_UL (Update Lease) (draft RFC) option is used to tell the server to set // The EDNS0_UL (Update Lease) (draft RFC) option is used to tell the server to set
// an expiration on an update RR. This is helpful for clients that cannot clean // an expiration on an update RR. This is helpful for clients that cannot clean
// up after themselves. This is a draft RFC and more information can be found at // up after themselves. This is a draft RFC and more information can be found at
@ -306,10 +347,7 @@ func (e *EDNS0_UL) String() string { return strconv.FormatUint(uint64(e.Lease),
// Copied: http://golang.org/src/pkg/net/dnsmsg.go // Copied: http://golang.org/src/pkg/net/dnsmsg.go
func (e *EDNS0_UL) pack() ([]byte, error) { func (e *EDNS0_UL) pack() ([]byte, error) {
b := make([]byte, 4) b := make([]byte, 4)
b[0] = byte(e.Lease >> 24) binary.BigEndian.PutUint32(b, e.Lease)
b[1] = byte(e.Lease >> 16)
b[2] = byte(e.Lease >> 8)
b[3] = byte(e.Lease)
return b, nil return b, nil
} }
@ -317,7 +355,7 @@ func (e *EDNS0_UL) unpack(b []byte) error {
if len(b) < 4 { if len(b) < 4 {
return ErrBuf return ErrBuf
} }
e.Lease = uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3]) e.Lease = binary.BigEndian.Uint32(b)
return nil return nil
} }
@ -336,21 +374,11 @@ func (e *EDNS0_LLQ) Option() uint16 { return EDNS0LLQ }
func (e *EDNS0_LLQ) pack() ([]byte, error) { func (e *EDNS0_LLQ) pack() ([]byte, error) {
b := make([]byte, 18) b := make([]byte, 18)
b[0], b[1] = packUint16(e.Version) binary.BigEndian.PutUint16(b[0:], e.Version)
b[2], b[3] = packUint16(e.Opcode) binary.BigEndian.PutUint16(b[2:], e.Opcode)
b[4], b[5] = packUint16(e.Error) binary.BigEndian.PutUint16(b[4:], e.Error)
b[6] = byte(e.Id >> 56) binary.BigEndian.PutUint64(b[6:], e.Id)
b[7] = byte(e.Id >> 48) binary.BigEndian.PutUint32(b[14:], e.LeaseLife)
b[8] = byte(e.Id >> 40)
b[9] = byte(e.Id >> 32)
b[10] = byte(e.Id >> 24)
b[11] = byte(e.Id >> 16)
b[12] = byte(e.Id >> 8)
b[13] = byte(e.Id)
b[14] = byte(e.LeaseLife >> 24)
b[15] = byte(e.LeaseLife >> 16)
b[16] = byte(e.LeaseLife >> 8)
b[17] = byte(e.LeaseLife)
return b, nil return b, nil
} }
@ -358,12 +386,11 @@ func (e *EDNS0_LLQ) unpack(b []byte) error {
if len(b) < 18 { if len(b) < 18 {
return ErrBuf return ErrBuf
} }
e.Version, _ = unpackUint16(b, 0) e.Version = binary.BigEndian.Uint16(b[0:])
e.Opcode, _ = unpackUint16(b, 2) e.Opcode = binary.BigEndian.Uint16(b[2:])
e.Error, _ = unpackUint16(b, 4) e.Error = binary.BigEndian.Uint16(b[4:])
e.Id = uint64(b[6])<<56 | uint64(b[6+1])<<48 | uint64(b[6+2])<<40 | e.Id = binary.BigEndian.Uint64(b[6:])
uint64(b[6+3])<<32 | uint64(b[6+4])<<24 | uint64(b[6+5])<<16 | uint64(b[6+6])<<8 | uint64(b[6+7]) e.LeaseLife = binary.BigEndian.Uint32(b[14:])
e.LeaseLife = uint32(b[14])<<24 | uint32(b[14+1])<<16 | uint32(b[14+2])<<8 | uint32(b[14+3])
return nil return nil
} }
@ -459,7 +486,7 @@ func (e *EDNS0_EXPIRE) unpack(b []byte) error {
if len(b) < 4 { if len(b) < 4 {
return ErrBuf return ErrBuf
} }
e.Expire = uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3]) e.Expire = binary.BigEndian.Uint32(b)
return nil return nil
} }

View File

@ -69,15 +69,6 @@ func Field(r RR, i int) string {
s += " " + Type(d.Index(i).Uint()).String() s += " " + Type(d.Index(i).Uint()).String()
} }
return s return s
case `dns:"wks"`:
if d.Len() == 0 {
return ""
}
s := strconv.Itoa(int(d.Index(0).Uint()))
for i := 0; i < d.Len(); i++ {
s += " " + strconv.Itoa(int(d.Index(i).Uint()))
}
return s
default: default:
// if it does not have a tag its a string slice // if it does not have a tag its a string slice
fallthrough fallthrough

View File

@ -2,6 +2,7 @@ package dns
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
@ -25,7 +26,7 @@ func generate(l lex, c chan lex, t chan *Token, o string) string {
if i+1 == len(l.token) { if i+1 == len(l.token) {
return "bad step in $GENERATE range" return "bad step in $GENERATE range"
} }
if s, e := strconv.Atoi(l.token[i+1:]); e == nil { if s, err := strconv.Atoi(l.token[i+1:]); err == nil {
if s < 0 { if s < 0 {
return "bad step in $GENERATE range" return "bad step in $GENERATE range"
} }
@ -65,7 +66,7 @@ BuildRR:
escape bool escape bool
dom bytes.Buffer dom bytes.Buffer
mod string mod string
err string err error
offset int offset int
) )
@ -104,8 +105,8 @@ BuildRR:
return "bad modifier in $GENERATE" return "bad modifier in $GENERATE"
} }
mod, offset, err = modToPrintf(s[j+2 : j+2+sep]) mod, offset, err = modToPrintf(s[j+2 : j+2+sep])
if err != "" { if err != nil {
return err return err.Error()
} }
j += 2 + sep // Jump to it j += 2 + sep // Jump to it
} }
@ -119,9 +120,9 @@ BuildRR:
} }
} }
// Re-parse the RR and send it on the current channel t // Re-parse the RR and send it on the current channel t
rx, e := NewRR("$ORIGIN " + o + "\n" + dom.String()) rx, err := NewRR("$ORIGIN " + o + "\n" + dom.String())
if e != nil { if err != nil {
return e.(*ParseError).err return err.Error()
} }
t <- &Token{RR: rx} t <- &Token{RR: rx}
// Its more efficient to first built the rrlist and then parse it in // Its more efficient to first built the rrlist and then parse it in
@ -131,28 +132,28 @@ BuildRR:
} }
// Convert a $GENERATE modifier 0,0,d to something Printf can deal with. // Convert a $GENERATE modifier 0,0,d to something Printf can deal with.
func modToPrintf(s string) (string, int, string) { func modToPrintf(s string) (string, int, error) {
xs := strings.SplitN(s, ",", 3) xs := strings.SplitN(s, ",", 3)
if len(xs) != 3 { if len(xs) != 3 {
return "", 0, "bad modifier in $GENERATE" return "", 0, errors.New("bad modifier in $GENERATE")
} }
// xs[0] is offset, xs[1] is width, xs[2] is base // xs[0] is offset, xs[1] is width, xs[2] is base
if xs[2] != "o" && xs[2] != "d" && xs[2] != "x" && xs[2] != "X" { if xs[2] != "o" && xs[2] != "d" && xs[2] != "x" && xs[2] != "X" {
return "", 0, "bad base in $GENERATE" return "", 0, errors.New("bad base in $GENERATE")
} }
offset, err := strconv.Atoi(xs[0]) offset, err := strconv.Atoi(xs[0])
if err != nil || offset > 255 { if err != nil || offset > 255 {
return "", 0, "bad offset in $GENERATE" return "", 0, errors.New("bad offset in $GENERATE")
} }
width, err := strconv.Atoi(xs[1]) width, err := strconv.Atoi(xs[1])
if err != nil || width > 255 { if err != nil || width > 255 {
return "", offset, "bad width in $GENERATE" return "", offset, errors.New("bad width in $GENERATE")
} }
switch { switch {
case width < 0: case width < 0:
return "", offset, "bad width in $GENERATE" return "", offset, errors.New("bad width in $GENERATE")
case width == 0: case width == 0:
return "%" + xs[1] + xs[2], offset, "" return "%" + xs[1] + xs[2], offset, nil
} }
return "%0" + xs[1] + xs[2], offset, "" return "%0" + xs[1] + xs[2], offset, nil
} }

View File

@ -107,7 +107,7 @@ func CountLabel(s string) (labels int) {
// Split splits a name s into its label indexes. // Split splits a name s into its label indexes.
// www.miek.nl. returns []int{0, 4, 9}, www.miek.nl also returns []int{0, 4, 9}. // www.miek.nl. returns []int{0, 4, 9}, www.miek.nl also returns []int{0, 4, 9}.
// The root name (.) returns nil. Also see SplitDomainName. // The root name (.) returns nil. Also see SplitDomainName.
// s must be a syntactically valid domain name. // s must be a syntactically valid domain name.
func Split(s string) []int { func Split(s string) []int {
if s == "." { if s == "." {

1143
vendor/github.com/miekg/dns/msg.go generated vendored

File diff suppressed because it is too large Load Diff

337
vendor/github.com/miekg/dns/msg_generate.go generated vendored Normal file
View File

@ -0,0 +1,337 @@
//+build ignore
// msg_generate.go is meant to run with go generate. It will use
// go/{importer,types} to track down all the RR struct types. Then for each type
// it will generate pack/unpack methods based on the struct tags. The generated source is
// written to zmsg.go, and is meant to be checked into git.
package main
import (
"bytes"
"fmt"
"go/format"
"go/importer"
"go/types"
"log"
"os"
"strings"
)
var packageHdr = `
// *** DO NOT MODIFY ***
// AUTOGENERATED BY go generate from msg_generate.go
package dns
`
// getTypeStruct will take a type and the package scope, and return the
// (innermost) struct if the type is considered a RR type (currently defined as
// those structs beginning with a RR_Header, could be redefined as implementing
// the RR interface). The bool return value indicates if embedded structs were
// resolved.
func getTypeStruct(t types.Type, scope *types.Scope) (*types.Struct, bool) {
st, ok := t.Underlying().(*types.Struct)
if !ok {
return nil, false
}
if st.Field(0).Type() == scope.Lookup("RR_Header").Type() {
return st, false
}
if st.Field(0).Anonymous() {
st, _ := getTypeStruct(st.Field(0).Type(), scope)
return st, true
}
return nil, false
}
func main() {
// Import and type-check the package
pkg, err := importer.Default().Import("github.com/miekg/dns")
fatalIfErr(err)
scope := pkg.Scope()
// Collect actual types (*X)
var namedTypes []string
for _, name := range scope.Names() {
o := scope.Lookup(name)
if o == nil || !o.Exported() {
continue
}
if st, _ := getTypeStruct(o.Type(), scope); st == nil {
continue
}
if name == "PrivateRR" {
continue
}
// Check if corresponding TypeX exists
if scope.Lookup("Type"+o.Name()) == nil && o.Name() != "RFC3597" {
log.Fatalf("Constant Type%s does not exist.", o.Name())
}
namedTypes = append(namedTypes, o.Name())
}
b := &bytes.Buffer{}
b.WriteString(packageHdr)
fmt.Fprint(b, "// pack*() functions\n\n")
for _, name := range namedTypes {
o := scope.Lookup(name)
st, _ := getTypeStruct(o.Type(), scope)
fmt.Fprintf(b, "func (rr *%s) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) {\n", name)
fmt.Fprint(b, `off, err := rr.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
`)
for i := 1; i < st.NumFields(); i++ {
o := func(s string) {
fmt.Fprintf(b, s, st.Field(i).Name())
fmt.Fprint(b, `if err != nil {
return off, err
}
`)
}
if _, ok := st.Field(i).Type().(*types.Slice); ok {
switch st.Tag(i) {
case `dns:"-"`: // ignored
case `dns:"txt"`:
o("off, err = packStringTxt(rr.%s, msg, off)\n")
case `dns:"opt"`:
o("off, err = packDataOpt(rr.%s, msg, off)\n")
case `dns:"nsec"`:
o("off, err = packDataNsec(rr.%s, msg, off)\n")
case `dns:"domain-name"`:
o("off, err = packDataDomainNames(rr.%s, msg, off, compression, compress)\n")
default:
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
}
continue
}
switch {
case st.Tag(i) == `dns:"-"`: // ignored
case st.Tag(i) == `dns:"cdomain-name"`:
fallthrough
case st.Tag(i) == `dns:"domain-name"`:
o("off, err = PackDomainName(rr.%s, msg, off, compression, compress)\n")
case st.Tag(i) == `dns:"a"`:
o("off, err = packDataA(rr.%s, msg, off)\n")
case st.Tag(i) == `dns:"aaaa"`:
o("off, err = packDataAAAA(rr.%s, msg, off)\n")
case st.Tag(i) == `dns:"uint48"`:
o("off, err = packUint48(rr.%s, msg, off)\n")
case st.Tag(i) == `dns:"txt"`:
o("off, err = packString(rr.%s, msg, off)\n")
case strings.HasPrefix(st.Tag(i), `dns:"size-base32`): // size-base32 can be packed just like base32
fallthrough
case st.Tag(i) == `dns:"base32"`:
o("off, err = packStringBase32(rr.%s, msg, off)\n")
case strings.HasPrefix(st.Tag(i), `dns:"size-base64`): // size-base64 can be packed just like base64
fallthrough
case st.Tag(i) == `dns:"base64"`:
o("off, err = packStringBase64(rr.%s, msg, off)\n")
case strings.HasPrefix(st.Tag(i), `dns:"size-hex`): // size-hex can be packed just like hex
fallthrough
case st.Tag(i) == `dns:"hex"`:
o("off, err = packStringHex(rr.%s, msg, off)\n")
case st.Tag(i) == `dns:"octet"`:
o("off, err = packStringOctet(rr.%s, msg, off)\n")
case st.Tag(i) == "":
switch st.Field(i).Type().(*types.Basic).Kind() {
case types.Uint8:
o("off, err = packUint8(rr.%s, msg, off)\n")
case types.Uint16:
o("off, err = packUint16(rr.%s, msg, off)\n")
case types.Uint32:
o("off, err = packUint32(rr.%s, msg, off)\n")
case types.Uint64:
o("off, err = packUint64(rr.%s, msg, off)\n")
case types.String:
o("off, err = packString(rr.%s, msg, off)\n")
default:
log.Fatalln(name, st.Field(i).Name())
}
default:
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
}
}
// We have packed everything, only now we know the rdlength of this RR
fmt.Fprintln(b, "rr.Header().Rdlength = uint16(off- headerEnd)")
fmt.Fprintln(b, "return off, nil }\n")
}
fmt.Fprint(b, "// unpack*() functions\n\n")
for _, name := range namedTypes {
o := scope.Lookup(name)
st, _ := getTypeStruct(o.Type(), scope)
fmt.Fprintf(b, "func unpack%s(h RR_Header, msg []byte, off int) (RR, int, error) {\n", name)
fmt.Fprintf(b, "rr := new(%s)\n", name)
fmt.Fprint(b, "rr.Hdr = h\n")
fmt.Fprint(b, `if noRdata(h) {
return rr, off, nil
}
var err error
rdStart := off
_ = rdStart
`)
for i := 1; i < st.NumFields(); i++ {
o := func(s string) {
fmt.Fprintf(b, s, st.Field(i).Name())
fmt.Fprint(b, `if err != nil {
return rr, off, err
}
`)
}
// size-* are special, because they reference a struct member we should use for the length.
if strings.HasPrefix(st.Tag(i), `dns:"size-`) {
structMember := structMember(st.Tag(i))
structTag := structTag(st.Tag(i))
switch structTag {
case "hex":
fmt.Fprintf(b, "rr.%s, off, err = unpackStringHex(msg, off, off + int(rr.%s))\n", st.Field(i).Name(), structMember)
case "base32":
fmt.Fprintf(b, "rr.%s, off, err = unpackStringBase32(msg, off, off + int(rr.%s))\n", st.Field(i).Name(), structMember)
case "base64":
fmt.Fprintf(b, "rr.%s, off, err = unpackStringBase64(msg, off, off + int(rr.%s))\n", st.Field(i).Name(), structMember)
default:
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
}
fmt.Fprint(b, `if err != nil {
return rr, off, err
}
`)
continue
}
if _, ok := st.Field(i).Type().(*types.Slice); ok {
switch st.Tag(i) {
case `dns:"-"`: // ignored
case `dns:"txt"`:
o("rr.%s, off, err = unpackStringTxt(msg, off)\n")
case `dns:"opt"`:
o("rr.%s, off, err = unpackDataOpt(msg, off)\n")
case `dns:"nsec"`:
o("rr.%s, off, err = unpackDataNsec(msg, off)\n")
case `dns:"domain-name"`:
o("rr.%s, off, err = unpackDataDomainNames(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
default:
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
}
continue
}
switch st.Tag(i) {
case `dns:"-"`: // ignored
case `dns:"cdomain-name"`:
fallthrough
case `dns:"domain-name"`:
o("rr.%s, off, err = UnpackDomainName(msg, off)\n")
case `dns:"a"`:
o("rr.%s, off, err = unpackDataA(msg, off)\n")
case `dns:"aaaa"`:
o("rr.%s, off, err = unpackDataAAAA(msg, off)\n")
case `dns:"uint48"`:
o("rr.%s, off, err = unpackUint48(msg, off)\n")
case `dns:"txt"`:
o("rr.%s, off, err = unpackString(msg, off)\n")
case `dns:"base32"`:
o("rr.%s, off, err = unpackStringBase32(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
case `dns:"base64"`:
o("rr.%s, off, err = unpackStringBase64(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
case `dns:"hex"`:
o("rr.%s, off, err = unpackStringHex(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
case `dns:"octet"`:
o("rr.%s, off, err = unpackStringOctet(msg, off)\n")
case "":
switch st.Field(i).Type().(*types.Basic).Kind() {
case types.Uint8:
o("rr.%s, off, err = unpackUint8(msg, off)\n")
case types.Uint16:
o("rr.%s, off, err = unpackUint16(msg, off)\n")
case types.Uint32:
o("rr.%s, off, err = unpackUint32(msg, off)\n")
case types.Uint64:
o("rr.%s, off, err = unpackUint64(msg, off)\n")
case types.String:
o("rr.%s, off, err = unpackString(msg, off)\n")
default:
log.Fatalln(name, st.Field(i).Name())
}
default:
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
}
// If we've hit len(msg) we return without error.
if i < st.NumFields()-1 {
fmt.Fprintf(b, `if off == len(msg) {
return rr, off, nil
}
`)
}
}
fmt.Fprintf(b, "return rr, off, err }\n\n")
}
// Generate typeToUnpack map
fmt.Fprintln(b, "var typeToUnpack = map[uint16]func(RR_Header, []byte, int) (RR, int, error){")
for _, name := range namedTypes {
if name == "RFC3597" {
continue
}
fmt.Fprintf(b, "Type%s: unpack%s,\n", name, name)
}
fmt.Fprintln(b, "}\n")
// gofmt
res, err := format.Source(b.Bytes())
if err != nil {
b.WriteTo(os.Stderr)
log.Fatal(err)
}
// write result
f, err := os.Create("zmsg.go")
fatalIfErr(err)
defer f.Close()
f.Write(res)
}
// structMember will take a tag like dns:"size-base32:SaltLength" and return the last part of this string.
func structMember(s string) string {
fields := strings.Split(s, ":")
if len(fields) == 0 {
return ""
}
f := fields[len(fields)-1]
// f should have a closing "
if len(f) > 1 {
return f[:len(f)-1]
}
return f
}
// structTag will take a tag like dns:"size-base32:SaltLength" and return base32.
func structTag(s string) string {
fields := strings.Split(s, ":")
if len(fields) < 2 {
return ""
}
return fields[1][len("\"size-"):]
}
func fatalIfErr(err error) {
if err != nil {
log.Fatal(err)
}
}

630
vendor/github.com/miekg/dns/msg_helpers.go generated vendored Normal file
View File

@ -0,0 +1,630 @@
package dns
import (
"encoding/base32"
"encoding/base64"
"encoding/binary"
"encoding/hex"
"net"
"strconv"
)
// helper functions called from the generated zmsg.go
// These function are named after the tag to help pack/unpack, if there is no tag it is the name
// of the type they pack/unpack (string, int, etc). We prefix all with unpackData or packData, so packDataA or
// packDataDomainName.
func unpackDataA(msg []byte, off int) (net.IP, int, error) {
if off+net.IPv4len > len(msg) {
return nil, len(msg), &Error{err: "overflow unpacking a"}
}
a := append(make(net.IP, 0, net.IPv4len), msg[off:off+net.IPv4len]...)
off += net.IPv4len
return a, off, nil
}
func packDataA(a net.IP, msg []byte, off int) (int, error) {
// It must be a slice of 4, even if it is 16, we encode only the first 4
if off+net.IPv4len > len(msg) {
return len(msg), &Error{err: "overflow packing a"}
}
switch len(a) {
case net.IPv4len, net.IPv6len:
copy(msg[off:], a.To4())
off += net.IPv4len
case 0:
// Allowed, for dynamic updates.
default:
return len(msg), &Error{err: "overflow packing a"}
}
return off, nil
}
func unpackDataAAAA(msg []byte, off int) (net.IP, int, error) {
if off+net.IPv6len > len(msg) {
return nil, len(msg), &Error{err: "overflow unpacking aaaa"}
}
aaaa := append(make(net.IP, 0, net.IPv6len), msg[off:off+net.IPv6len]...)
off += net.IPv6len
return aaaa, off, nil
}
func packDataAAAA(aaaa net.IP, msg []byte, off int) (int, error) {
if off+net.IPv6len > len(msg) {
return len(msg), &Error{err: "overflow packing aaaa"}
}
switch len(aaaa) {
case net.IPv6len:
copy(msg[off:], aaaa)
off += net.IPv6len
case 0:
// Allowed, dynamic updates.
default:
return len(msg), &Error{err: "overflow packing aaaa"}
}
return off, nil
}
// unpackHeader unpacks an RR header, returning the offset to the end of the header and a
// re-sliced msg according to the expected length of the RR.
func unpackHeader(msg []byte, off int) (rr RR_Header, off1 int, truncmsg []byte, err error) {
hdr := RR_Header{}
if off == len(msg) {
return hdr, off, msg, nil
}
hdr.Name, off, err = UnpackDomainName(msg, off)
if err != nil {
return hdr, len(msg), msg, err
}
hdr.Rrtype, off, err = unpackUint16(msg, off)
if err != nil {
return hdr, len(msg), msg, err
}
hdr.Class, off, err = unpackUint16(msg, off)
if err != nil {
return hdr, len(msg), msg, err
}
hdr.Ttl, off, err = unpackUint32(msg, off)
if err != nil {
return hdr, len(msg), msg, err
}
hdr.Rdlength, off, err = unpackUint16(msg, off)
if err != nil {
return hdr, len(msg), msg, err
}
msg, err = truncateMsgFromRdlength(msg, off, hdr.Rdlength)
return hdr, off, msg, nil
}
// pack packs an RR header, returning the offset to the end of the header.
// See PackDomainName for documentation about the compression.
func (hdr RR_Header) pack(msg []byte, off int, compression map[string]int, compress bool) (off1 int, err error) {
if off == len(msg) {
return off, nil
}
off, err = PackDomainName(hdr.Name, msg, off, compression, compress)
if err != nil {
return len(msg), err
}
off, err = packUint16(hdr.Rrtype, msg, off)
if err != nil {
return len(msg), err
}
off, err = packUint16(hdr.Class, msg, off)
if err != nil {
return len(msg), err
}
off, err = packUint32(hdr.Ttl, msg, off)
if err != nil {
return len(msg), err
}
off, err = packUint16(hdr.Rdlength, msg, off)
if err != nil {
return len(msg), err
}
return off, nil
}
// helper helper functions.
// truncateMsgFromRdLength truncates msg to match the expected length of the RR.
// Returns an error if msg is smaller than the expected size.
func truncateMsgFromRdlength(msg []byte, off int, rdlength uint16) (truncmsg []byte, err error) {
lenrd := off + int(rdlength)
if lenrd > len(msg) {
return msg, &Error{err: "overflowing header size"}
}
return msg[:lenrd], nil
}
func fromBase32(s []byte) (buf []byte, err error) {
buflen := base32.HexEncoding.DecodedLen(len(s))
buf = make([]byte, buflen)
n, err := base32.HexEncoding.Decode(buf, s)
buf = buf[:n]
return
}
func toBase32(b []byte) string { return base32.HexEncoding.EncodeToString(b) }
func fromBase64(s []byte) (buf []byte, err error) {
buflen := base64.StdEncoding.DecodedLen(len(s))
buf = make([]byte, buflen)
n, err := base64.StdEncoding.Decode(buf, s)
buf = buf[:n]
return
}
func toBase64(b []byte) string { return base64.StdEncoding.EncodeToString(b) }
// dynamicUpdate returns true if the Rdlength is zero.
func noRdata(h RR_Header) bool { return h.Rdlength == 0 }
func unpackUint8(msg []byte, off int) (i uint8, off1 int, err error) {
if off+1 > len(msg) {
return 0, len(msg), &Error{err: "overflow unpacking uint8"}
}
return uint8(msg[off]), off + 1, nil
}
func packUint8(i uint8, msg []byte, off int) (off1 int, err error) {
if off+1 > len(msg) {
return len(msg), &Error{err: "overflow packing uint8"}
}
msg[off] = byte(i)
return off + 1, nil
}
func unpackUint16(msg []byte, off int) (i uint16, off1 int, err error) {
if off+2 > len(msg) {
return 0, len(msg), &Error{err: "overflow unpacking uint16"}
}
return binary.BigEndian.Uint16(msg[off:]), off + 2, nil
}
func packUint16(i uint16, msg []byte, off int) (off1 int, err error) {
if off+2 > len(msg) {
return len(msg), &Error{err: "overflow packing uint16"}
}
binary.BigEndian.PutUint16(msg[off:], i)
return off + 2, nil
}
func unpackUint32(msg []byte, off int) (i uint32, off1 int, err error) {
if off+4 > len(msg) {
return 0, len(msg), &Error{err: "overflow unpacking uint32"}
}
return binary.BigEndian.Uint32(msg[off:]), off + 4, nil
}
func packUint32(i uint32, msg []byte, off int) (off1 int, err error) {
if off+4 > len(msg) {
return len(msg), &Error{err: "overflow packing uint32"}
}
binary.BigEndian.PutUint32(msg[off:], i)
return off + 4, nil
}
func unpackUint48(msg []byte, off int) (i uint64, off1 int, err error) {
if off+6 > len(msg) {
return 0, len(msg), &Error{err: "overflow unpacking uint64 as uint48"}
}
// Used in TSIG where the last 48 bits are occupied, so for now, assume a uint48 (6 bytes)
i = (uint64(uint64(msg[off])<<40 | uint64(msg[off+1])<<32 | uint64(msg[off+2])<<24 | uint64(msg[off+3])<<16 |
uint64(msg[off+4])<<8 | uint64(msg[off+5])))
off += 6
return i, off, nil
}
func packUint48(i uint64, msg []byte, off int) (off1 int, err error) {
if off+6 > len(msg) {
return len(msg), &Error{err: "overflow packing uint64 as uint48"}
}
msg[off] = byte(i >> 40)
msg[off+1] = byte(i >> 32)
msg[off+2] = byte(i >> 24)
msg[off+3] = byte(i >> 16)
msg[off+4] = byte(i >> 8)
msg[off+5] = byte(i)
off += 6
return off, nil
}
func unpackUint64(msg []byte, off int) (i uint64, off1 int, err error) {
if off+8 > len(msg) {
return 0, len(msg), &Error{err: "overflow unpacking uint64"}
}
return binary.BigEndian.Uint64(msg[off:]), off + 8, nil
}
func packUint64(i uint64, msg []byte, off int) (off1 int, err error) {
if off+8 > len(msg) {
return len(msg), &Error{err: "overflow packing uint64"}
}
binary.BigEndian.PutUint64(msg[off:], i)
off += 8
return off, nil
}
func unpackString(msg []byte, off int) (string, int, error) {
if off+1 > len(msg) {
return "", off, &Error{err: "overflow unpacking txt"}
}
l := int(msg[off])
if off+l+1 > len(msg) {
return "", off, &Error{err: "overflow unpacking txt"}
}
s := make([]byte, 0, l)
for _, b := range msg[off+1 : off+1+l] {
switch b {
case '"', '\\':
s = append(s, '\\', b)
case '\t', '\r', '\n':
s = append(s, b)
default:
if b < 32 || b > 127 { // unprintable
var buf [3]byte
bufs := strconv.AppendInt(buf[:0], int64(b), 10)
s = append(s, '\\')
for i := 0; i < 3-len(bufs); i++ {
s = append(s, '0')
}
for _, r := range bufs {
s = append(s, r)
}
} else {
s = append(s, b)
}
}
}
off += 1 + l
return string(s), off, nil
}
func packString(s string, msg []byte, off int) (int, error) {
txtTmp := make([]byte, 256*4+1)
off, err := packTxtString(s, msg, off, txtTmp)
if err != nil {
return len(msg), err
}
return off, nil
}
func unpackStringBase32(msg []byte, off, end int) (string, int, error) {
if end > len(msg) {
return "", len(msg), &Error{err: "overflow unpacking base32"}
}
s := toBase32(msg[off:end])
return s, end, nil
}
func packStringBase32(s string, msg []byte, off int) (int, error) {
b32, err := fromBase32([]byte(s))
if err != nil {
return len(msg), err
}
if off+len(b32) > len(msg) {
return len(msg), &Error{err: "overflow packing base32"}
}
copy(msg[off:off+len(b32)], b32)
off += len(b32)
return off, nil
}
func unpackStringBase64(msg []byte, off, end int) (string, int, error) {
// Rest of the RR is base64 encoded value, so we don't need an explicit length
// to be set. Thus far all RR's that have base64 encoded fields have those as their
// last one. What we do need is the end of the RR!
if end > len(msg) {
return "", len(msg), &Error{err: "overflow unpacking base64"}
}
s := toBase64(msg[off:end])
return s, end, nil
}
func packStringBase64(s string, msg []byte, off int) (int, error) {
b64, err := fromBase64([]byte(s))
if err != nil {
return len(msg), err
}
if off+len(b64) > len(msg) {
return len(msg), &Error{err: "overflow packing base64"}
}
copy(msg[off:off+len(b64)], b64)
off += len(b64)
return off, nil
}
func unpackStringHex(msg []byte, off, end int) (string, int, error) {
// Rest of the RR is hex encoded value, so we don't need an explicit length
// to be set. NSEC and TSIG have hex fields with a length field.
// What we do need is the end of the RR!
if end > len(msg) {
return "", len(msg), &Error{err: "overflow unpacking hex"}
}
s := hex.EncodeToString(msg[off:end])
return s, end, nil
}
func packStringHex(s string, msg []byte, off int) (int, error) {
h, err := hex.DecodeString(s)
if err != nil {
return len(msg), err
}
if off+(len(h)) > len(msg) {
return len(msg), &Error{err: "overflow packing hex"}
}
copy(msg[off:off+len(h)], h)
off += len(h)
return off, nil
}
func unpackStringTxt(msg []byte, off int) ([]string, int, error) {
txt, off, err := unpackTxt(msg, off)
if err != nil {
return nil, len(msg), err
}
return txt, off, nil
}
func packStringTxt(s []string, msg []byte, off int) (int, error) {
txtTmp := make([]byte, 256*4+1) // If the whole string consists out of \DDD we need this many.
off, err := packTxt(s, msg, off, txtTmp)
if err != nil {
return len(msg), err
}
return off, nil
}
func unpackDataOpt(msg []byte, off int) ([]EDNS0, int, error) {
var edns []EDNS0
Option:
code := uint16(0)
if off+4 > len(msg) {
return nil, len(msg), &Error{err: "overflow unpacking opt"}
}
code = binary.BigEndian.Uint16(msg[off:])
off += 2
optlen := binary.BigEndian.Uint16(msg[off:])
off += 2
if off+int(optlen) > len(msg) {
return nil, len(msg), &Error{err: "overflow unpacking opt"}
}
switch code {
case EDNS0NSID:
e := new(EDNS0_NSID)
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
return nil, len(msg), err
}
edns = append(edns, e)
off += int(optlen)
case EDNS0SUBNET, EDNS0SUBNETDRAFT:
e := new(EDNS0_SUBNET)
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
return nil, len(msg), err
}
edns = append(edns, e)
off += int(optlen)
if code == EDNS0SUBNETDRAFT {
e.DraftOption = true
}
case EDNS0COOKIE:
e := new(EDNS0_COOKIE)
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
return nil, len(msg), err
}
edns = append(edns, e)
off += int(optlen)
case EDNS0UL:
e := new(EDNS0_UL)
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
return nil, len(msg), err
}
edns = append(edns, e)
off += int(optlen)
case EDNS0LLQ:
e := new(EDNS0_LLQ)
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
return nil, len(msg), err
}
edns = append(edns, e)
off += int(optlen)
case EDNS0DAU:
e := new(EDNS0_DAU)
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
return nil, len(msg), err
}
edns = append(edns, e)
off += int(optlen)
case EDNS0DHU:
e := new(EDNS0_DHU)
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
return nil, len(msg), err
}
edns = append(edns, e)
off += int(optlen)
case EDNS0N3U:
e := new(EDNS0_N3U)
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
return nil, len(msg), err
}
edns = append(edns, e)
off += int(optlen)
default:
e := new(EDNS0_LOCAL)
e.Code = code
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
return nil, len(msg), err
}
edns = append(edns, e)
off += int(optlen)
}
if off < len(msg) {
goto Option
}
return edns, off, nil
}
func packDataOpt(options []EDNS0, msg []byte, off int) (int, error) {
for _, el := range options {
b, err := el.pack()
if err != nil || off+3 > len(msg) {
return len(msg), &Error{err: "overflow packing opt"}
}
binary.BigEndian.PutUint16(msg[off:], el.Option()) // Option code
binary.BigEndian.PutUint16(msg[off+2:], uint16(len(b))) // Length
off += 4
if off+len(b) > len(msg) {
copy(msg[off:], b)
off = len(msg)
continue
}
// Actual data
copy(msg[off:off+len(b)], b)
off += len(b)
}
return off, nil
}
func unpackStringOctet(msg []byte, off int) (string, int, error) {
s := string(msg[off:])
return s, len(msg), nil
}
func packStringOctet(s string, msg []byte, off int) (int, error) {
txtTmp := make([]byte, 256*4+1)
off, err := packOctetString(s, msg, off, txtTmp)
if err != nil {
return len(msg), err
}
return off, nil
}
func unpackDataNsec(msg []byte, off int) ([]uint16, int, error) {
var nsec []uint16
length, window, lastwindow := 0, 0, -1
for off < len(msg) {
if off+2 > len(msg) {
return nsec, len(msg), &Error{err: "overflow unpacking nsecx"}
}
window = int(msg[off])
length = int(msg[off+1])
off += 2
if window <= lastwindow {
// RFC 4034: Blocks are present in the NSEC RR RDATA in
// increasing numerical order.
return nsec, len(msg), &Error{err: "out of order NSEC block"}
}
if length == 0 {
// RFC 4034: Blocks with no types present MUST NOT be included.
return nsec, len(msg), &Error{err: "empty NSEC block"}
}
if length > 32 {
return nsec, len(msg), &Error{err: "NSEC block too long"}
}
if off+length > len(msg) {
return nsec, len(msg), &Error{err: "overflowing NSEC block"}
}
// Walk the bytes in the window and extract the type bits
for j := 0; j < length; j++ {
b := msg[off+j]
// Check the bits one by one, and set the type
if b&0x80 == 0x80 {
nsec = append(nsec, uint16(window*256+j*8+0))
}
if b&0x40 == 0x40 {
nsec = append(nsec, uint16(window*256+j*8+1))
}
if b&0x20 == 0x20 {
nsec = append(nsec, uint16(window*256+j*8+2))
}
if b&0x10 == 0x10 {
nsec = append(nsec, uint16(window*256+j*8+3))
}
if b&0x8 == 0x8 {
nsec = append(nsec, uint16(window*256+j*8+4))
}
if b&0x4 == 0x4 {
nsec = append(nsec, uint16(window*256+j*8+5))
}
if b&0x2 == 0x2 {
nsec = append(nsec, uint16(window*256+j*8+6))
}
if b&0x1 == 0x1 {
nsec = append(nsec, uint16(window*256+j*8+7))
}
}
off += length
lastwindow = window
}
return nsec, off, nil
}
func packDataNsec(bitmap []uint16, msg []byte, off int) (int, error) {
if len(bitmap) == 0 {
return off, nil
}
var lastwindow, lastlength uint16
for j := 0; j < len(bitmap); j++ {
t := bitmap[j]
window := t / 256
length := (t-window*256)/8 + 1
if window > lastwindow && lastlength != 0 { // New window, jump to the new offset
off += int(lastlength) + 2
lastlength = 0
}
if window < lastwindow || length < lastlength {
return len(msg), &Error{err: "nsec bits out of order"}
}
if off+2+int(length) > len(msg) {
return len(msg), &Error{err: "overflow packing nsec"}
}
// Setting the window #
msg[off] = byte(window)
// Setting the octets length
msg[off+1] = byte(length)
// Setting the bit value for the type in the right octet
msg[off+1+int(length)] |= byte(1 << (7 - (t % 8)))
lastwindow, lastlength = window, length
}
off += int(lastlength) + 2
return off, nil
}
func unpackDataDomainNames(msg []byte, off, end int) ([]string, int, error) {
var (
servers []string
s string
err error
)
if end > len(msg) {
return nil, len(msg), &Error{err: "overflow unpacking domain names"}
}
for off < end {
s, off, err = UnpackDomainName(msg, off)
if err != nil {
return servers, len(msg), err
}
servers = append(servers, s)
}
return servers, off, nil
}
func packDataDomainNames(names []string, msg []byte, off int, compression map[string]int, compress bool) (int, error) {
var err error
for j := 0; j < len(names); j++ {
off, err = PackDomainName(names[j], msg, off, compression, false && compress)
if err != nil {
return len(msg), err
}
}
return off, nil
}

13
vendor/github.com/miekg/dns/nsecx.go generated vendored
View File

@ -11,13 +11,12 @@ type saltWireFmt struct {
Salt string `dns:"size-hex"` Salt string `dns:"size-hex"`
} }
// HashName hashes a string (label) according to RFC 5155. It returns the hashed string in // HashName hashes a string (label) according to RFC 5155. It returns the hashed string in uppercase.
// uppercase.
func HashName(label string, ha uint8, iter uint16, salt string) string { func HashName(label string, ha uint8, iter uint16, salt string) string {
saltwire := new(saltWireFmt) saltwire := new(saltWireFmt)
saltwire.Salt = salt saltwire.Salt = salt
wire := make([]byte, DefaultMsgSize) wire := make([]byte, DefaultMsgSize)
n, err := PackStruct(saltwire, wire, 0) n, err := packSaltWire(saltwire, wire)
if err != nil { if err != nil {
return "" return ""
} }
@ -110,3 +109,11 @@ func (rr *NSEC3) Match(name string) bool {
} }
return false return false
} }
func packSaltWire(sw *saltWireFmt, msg []byte) (int, error) {
off, err := packStringHex(sw.Salt, msg, 0)
if err != nil {
return off, err
}
return off, nil
}

View File

@ -65,6 +65,20 @@ func (r *PrivateRR) copy() RR {
} }
return rr return rr
} }
func (r *PrivateRR) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) {
off, err := r.Hdr.pack(msg, off, compression, compress)
if err != nil {
return off, err
}
headerEnd := off
n, err := r.Data.Pack(msg[off:])
if err != nil {
return len(msg), err
}
off += n
r.Header().Rdlength = uint16(off - headerEnd)
return off, nil
}
// PrivateHandle registers a private resource record type. It requires // PrivateHandle registers a private resource record type. It requires
// string and numeric representation of private RR type and generator function as argument. // string and numeric representation of private RR type and generator function as argument.
@ -75,19 +89,36 @@ func PrivateHandle(rtypestr string, rtype uint16, generator func() PrivateRdata)
TypeToString[rtype] = rtypestr TypeToString[rtype] = rtypestr
StringToType[rtypestr] = rtype StringToType[rtypestr] = rtype
typeToUnpack[rtype] = func(h RR_Header, msg []byte, off int) (RR, int, error) {
if noRdata(h) {
return &h, off, nil
}
var err error
rr := mkPrivateRR(h.Rrtype)
rr.Hdr = h
off1, err := rr.Data.Unpack(msg[off:])
off += off1
if err != nil {
return rr, off, err
}
return rr, off, err
}
setPrivateRR := func(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { setPrivateRR := func(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
rr := mkPrivateRR(h.Rrtype) rr := mkPrivateRR(h.Rrtype)
rr.Hdr = h rr.Hdr = h
var l lex var l lex
text := make([]string, 0, 2) // could be 0..N elements, median is probably 1 text := make([]string, 0, 2) // could be 0..N elements, median is probably 1
FETCH: Fetch:
for { for {
// TODO(miek): we could also be returning _QUOTE, this might or might not // TODO(miek): we could also be returning _QUOTE, this might or might not
// be an issue (basically parsing TXT becomes hard) // be an issue (basically parsing TXT becomes hard)
switch l = <-c; l.value { switch l = <-c; l.value {
case zNewline, zEOF: case zNewline, zEOF:
break FETCH break Fetch
case zString: case zString:
text = append(text, l.token) text = append(text, l.token)
} }
@ -112,6 +143,7 @@ func PrivateHandleRemove(rtype uint16) {
delete(TypeToString, rtype) delete(TypeToString, rtype)
delete(typeToparserFunc, rtype) delete(typeToparserFunc, rtype)
delete(StringToType, rtypestr) delete(StringToType, rtypestr)
delete(typeToUnpack, rtype)
} }
return return
} }

View File

@ -1,52 +1,6 @@
package dns package dns
// These raw* functions do not use reflection, they directly set the values import "encoding/binary"
// in the buffer. There are faster than their reflection counterparts.
// RawSetId sets the message id in buf.
func rawSetId(msg []byte, i uint16) bool {
if len(msg) < 2 {
return false
}
msg[0], msg[1] = packUint16(i)
return true
}
// rawSetQuestionLen sets the length of the question section.
func rawSetQuestionLen(msg []byte, i uint16) bool {
if len(msg) < 6 {
return false
}
msg[4], msg[5] = packUint16(i)
return true
}
// rawSetAnswerLen sets the length of the answer section.
func rawSetAnswerLen(msg []byte, i uint16) bool {
if len(msg) < 8 {
return false
}
msg[6], msg[7] = packUint16(i)
return true
}
// rawSetsNsLen sets the length of the authority section.
func rawSetNsLen(msg []byte, i uint16) bool {
if len(msg) < 10 {
return false
}
msg[8], msg[9] = packUint16(i)
return true
}
// rawSetExtraLen sets the length of the additional section.
func rawSetExtraLen(msg []byte, i uint16) bool {
if len(msg) < 12 {
return false
}
msg[10], msg[11] = packUint16(i)
return true
}
// rawSetRdlength sets the rdlength in the header of // rawSetRdlength sets the rdlength in the header of
// the RR. The offset 'off' must be positioned at the // the RR. The offset 'off' must be positioned at the
@ -90,6 +44,6 @@ Loop:
if rdatalen > 0xFFFF { if rdatalen > 0xFFFF {
return false return false
} }
msg[off], msg[off+1] = packUint16(uint16(rdatalen)) binary.BigEndian.PutUint16(msg[off:], uint16(rdatalen))
return true return true
} }

38
vendor/github.com/miekg/dns/reverse.go generated vendored Normal file
View File

@ -0,0 +1,38 @@
package dns
// StringToType is the reverse of TypeToString, needed for string parsing.
var StringToType = reverseInt16(TypeToString)
// StringToClass is the reverse of ClassToString, needed for string parsing.
var StringToClass = reverseInt16(ClassToString)
// Map of opcodes strings.
var StringToOpcode = reverseInt(OpcodeToString)
// Map of rcodes strings.
var StringToRcode = reverseInt(RcodeToString)
// Reverse a map
func reverseInt8(m map[uint8]string) map[string]uint8 {
n := make(map[string]uint8, len(m))
for u, s := range m {
n[s] = u
}
return n
}
func reverseInt16(m map[uint16]string) map[string]uint16 {
n := make(map[string]uint16, len(m))
for u, s := range m {
n[s] = u
}
return n
}
func reverseInt(m map[int]string) map[string]int {
n := make(map[string]int, len(m))
for u, s := range m {
n[s] = u
}
return n
}

View File

@ -377,8 +377,8 @@ func parseZone(r io.Reader, origin, f string, t chan *Token, include int) {
t <- &Token{Error: &ParseError{f, "expecting $GENERATE value, not this...", l}} t <- &Token{Error: &ParseError{f, "expecting $GENERATE value, not this...", l}}
return return
} }
if e := generate(l, c, t, origin); e != "" { if errMsg := generate(l, c, t, origin); errMsg != "" {
t <- &Token{Error: &ParseError{f, e, l}} t <- &Token{Error: &ParseError{f, errMsg, l}}
return return
} }
st = zExpectOwnerDir st = zExpectOwnerDir
@ -966,8 +966,8 @@ func stringToNodeID(l lex) (uint64, *ParseError) {
return 0, &ParseError{l.token, "bad NID/L64 NodeID/Locator64", l} return 0, &ParseError{l.token, "bad NID/L64 NodeID/Locator64", l}
} }
s := l.token[0:4] + l.token[5:9] + l.token[10:14] + l.token[15:19] s := l.token[0:4] + l.token[5:9] + l.token[10:14] + l.token[15:19]
u, e := strconv.ParseUint(s, 16, 64) u, err := strconv.ParseUint(s, 16, 64)
if e != nil { if err != nil {
return 0, &ParseError{l.token, "bad NID/L64 NodeID/Locator64", l} return 0, &ParseError{l.token, "bad NID/L64 NodeID/Locator64", l}
} }
return u, nil return u, nil

View File

@ -1443,64 +1443,6 @@ func setEUI64(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
return rr, nil, "" return rr, nil, ""
} }
func setWKS(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
rr := new(WKS)
rr.Hdr = h
l := <-c
if l.length == 0 {
return rr, nil, l.comment
}
rr.Address = net.ParseIP(l.token)
if rr.Address == nil || l.err {
return nil, &ParseError{f, "bad WKS Address", l}, ""
}
<-c // zBlank
l = <-c
proto := "tcp"
i, e := strconv.Atoi(l.token)
if e != nil || l.err {
return nil, &ParseError{f, "bad WKS Protocol", l}, ""
}
rr.Protocol = uint8(i)
switch rr.Protocol {
case 17:
proto = "udp"
case 6:
proto = "tcp"
default:
return nil, &ParseError{f, "bad WKS Protocol", l}, ""
}
<-c
l = <-c
rr.BitMap = make([]uint16, 0)
var (
k int
err error
)
for l.value != zNewline && l.value != zEOF {
switch l.value {
case zBlank:
// Ok
case zString:
if k, err = net.LookupPort(proto, l.token); err != nil {
i, e := strconv.Atoi(l.token) // If a number use that
if e != nil {
return nil, &ParseError{f, "bad WKS BitMap", l}, ""
}
rr.BitMap = append(rr.BitMap, uint16(i))
}
rr.BitMap = append(rr.BitMap, uint16(k))
default:
return nil, &ParseError{f, "bad WKS BitMap", l}, ""
}
l = <-c
}
return rr, nil, l.comment
}
func setSSHFP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { func setSSHFP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
rr := new(SSHFP) rr := new(SSHFP)
rr.Hdr = h rr.Hdr = h
@ -2103,73 +2045,6 @@ func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
return rr, nil, "" return rr, nil, ""
} }
func setIPSECKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
rr := new(IPSECKEY)
rr.Hdr = h
l := <-c
if l.length == 0 {
return rr, nil, l.comment
}
i, err := strconv.Atoi(l.token)
if err != nil || l.err {
return nil, &ParseError{f, "bad IPSECKEY Precedence", l}, ""
}
rr.Precedence = uint8(i)
<-c // zBlank
l = <-c
i, err = strconv.Atoi(l.token)
if err != nil || l.err {
return nil, &ParseError{f, "bad IPSECKEY GatewayType", l}, ""
}
rr.GatewayType = uint8(i)
<-c // zBlank
l = <-c
i, err = strconv.Atoi(l.token)
if err != nil || l.err {
return nil, &ParseError{f, "bad IPSECKEY Algorithm", l}, ""
}
rr.Algorithm = uint8(i)
// Now according to GatewayType we can have different elements here
<-c // zBlank
l = <-c
switch rr.GatewayType {
case 0:
fallthrough
case 3:
rr.GatewayName = l.token
if l.token == "@" {
rr.GatewayName = o
}
_, ok := IsDomainName(l.token)
if !ok || l.length == 0 || l.err {
return nil, &ParseError{f, "bad IPSECKEY GatewayName", l}, ""
}
if rr.GatewayName[l.length-1] != '.' {
rr.GatewayName = appendOrigin(rr.GatewayName, o)
}
case 1:
rr.GatewayA = net.ParseIP(l.token)
if rr.GatewayA == nil {
return nil, &ParseError{f, "bad IPSECKEY GatewayA", l}, ""
}
case 2:
rr.GatewayAAAA = net.ParseIP(l.token)
if rr.GatewayAAAA == nil {
return nil, &ParseError{f, "bad IPSECKEY GatewayAAAA", l}, ""
}
default:
return nil, &ParseError{f, "bad IPSECKEY GatewayType", l}, ""
}
s, e, c1 := endingToString(c, "bad IPSECKEY PublicKey", f)
if e != nil {
return nil, e, c1
}
rr.PublicKey = s
return rr, nil, c1
}
func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) { func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
rr := new(CAA) rr := new(CAA)
rr.Hdr = h rr.Hdr = h
@ -2224,7 +2099,6 @@ var typeToparserFunc = map[uint16]parserFunc{
TypeGPOS: {setGPOS, false}, TypeGPOS: {setGPOS, false},
TypeHINFO: {setHINFO, true}, TypeHINFO: {setHINFO, true},
TypeHIP: {setHIP, true}, TypeHIP: {setHIP, true},
TypeIPSECKEY: {setIPSECKEY, true},
TypeKX: {setKX, false}, TypeKX: {setKX, false},
TypeL32: {setL32, false}, TypeL32: {setL32, false},
TypeL64: {setL64, false}, TypeL64: {setL64, false},
@ -2265,6 +2139,5 @@ var typeToparserFunc = map[uint16]parserFunc{
TypeUID: {setUID, false}, TypeUID: {setUID, false},
TypeUINFO: {setUINFO, true}, TypeUINFO: {setUINFO, true},
TypeURI: {setURI, true}, TypeURI: {setURI, true},
TypeWKS: {setWKS, true},
TypeX25: {setX25, false}, TypeX25: {setX25, false},
} }

View File

@ -5,6 +5,7 @@ package dns
import ( import (
"bytes" "bytes"
"crypto/tls" "crypto/tls"
"encoding/binary"
"io" "io"
"net" "net"
"sync" "sync"
@ -320,20 +321,20 @@ func (srv *Server) ListenAndServe() error {
} }
switch srv.Net { switch srv.Net {
case "tcp", "tcp4", "tcp6": case "tcp", "tcp4", "tcp6":
a, e := net.ResolveTCPAddr(srv.Net, addr) a, err := net.ResolveTCPAddr(srv.Net, addr)
if e != nil { if err != nil {
return e return err
} }
l, e := net.ListenTCP(srv.Net, a) l, err := net.ListenTCP(srv.Net, a)
if e != nil { if err != nil {
return e return err
} }
srv.Listener = l srv.Listener = l
srv.started = true srv.started = true
srv.lock.Unlock() srv.lock.Unlock()
e = srv.serveTCP(l) err = srv.serveTCP(l)
srv.lock.Lock() // to satisfy the defer at the top srv.lock.Lock() // to satisfy the defer at the top
return e return err
case "tcp-tls", "tcp4-tls", "tcp6-tls": case "tcp-tls", "tcp4-tls", "tcp6-tls":
network := "tcp" network := "tcp"
if srv.Net == "tcp4-tls" { if srv.Net == "tcp4-tls" {
@ -342,24 +343,24 @@ func (srv *Server) ListenAndServe() error {
network = "tcp6" network = "tcp6"
} }
l, e := tls.Listen(network, addr, srv.TLSConfig) l, err := tls.Listen(network, addr, srv.TLSConfig)
if e != nil { if err != nil {
return e return err
} }
srv.Listener = l srv.Listener = l
srv.started = true srv.started = true
srv.lock.Unlock() srv.lock.Unlock()
e = srv.serveTCP(l) err = srv.serveTCP(l)
srv.lock.Lock() // to satisfy the defer at the top srv.lock.Lock() // to satisfy the defer at the top
return e return err
case "udp", "udp4", "udp6": case "udp", "udp4", "udp6":
a, e := net.ResolveUDPAddr(srv.Net, addr) a, err := net.ResolveUDPAddr(srv.Net, addr)
if e != nil { if err != nil {
return e return err
} }
l, e := net.ListenUDP(srv.Net, a) l, err := net.ListenUDP(srv.Net, a)
if e != nil { if err != nil {
return e return err
} }
if e := setUDPSocketOptions(l); e != nil { if e := setUDPSocketOptions(l); e != nil {
return e return e
@ -367,9 +368,9 @@ func (srv *Server) ListenAndServe() error {
srv.PacketConn = l srv.PacketConn = l
srv.started = true srv.started = true
srv.lock.Unlock() srv.lock.Unlock()
e = srv.serveUDP(l) err = srv.serveUDP(l)
srv.lock.Lock() // to satisfy the defer at the top srv.lock.Lock() // to satisfy the defer at the top
return e return err
} }
return &Error{err: "bad network"} return &Error{err: "bad network"}
} }
@ -473,21 +474,21 @@ func (srv *Server) serveTCP(l net.Listener) error {
rtimeout := srv.getReadTimeout() rtimeout := srv.getReadTimeout()
// deadline is not used here // deadline is not used here
for { for {
rw, e := l.Accept() rw, err := l.Accept()
if e != nil { if err != nil {
if neterr, ok := e.(net.Error); ok && neterr.Temporary() { if neterr, ok := err.(net.Error); ok && neterr.Temporary() {
continue continue
} }
return e return err
} }
m, e := reader.ReadTCP(rw, rtimeout) m, err := reader.ReadTCP(rw, rtimeout)
srv.lock.RLock() srv.lock.RLock()
if !srv.started { if !srv.started {
srv.lock.RUnlock() srv.lock.RUnlock()
return nil return nil
} }
srv.lock.RUnlock() srv.lock.RUnlock()
if e != nil { if err != nil {
continue continue
} }
srv.inFlight.Add(1) srv.inFlight.Add(1)
@ -516,14 +517,14 @@ func (srv *Server) serveUDP(l *net.UDPConn) error {
rtimeout := srv.getReadTimeout() rtimeout := srv.getReadTimeout()
// deadline is not used here // deadline is not used here
for { for {
m, s, e := reader.ReadUDP(l, rtimeout) m, s, err := reader.ReadUDP(l, rtimeout)
srv.lock.RLock() srv.lock.RLock()
if !srv.started { if !srv.started {
srv.lock.RUnlock() srv.lock.RUnlock()
return nil return nil
} }
srv.lock.RUnlock() srv.lock.RUnlock()
if e != nil { if err != nil {
continue continue
} }
srv.inFlight.Add(1) srv.inFlight.Add(1)
@ -596,8 +597,8 @@ Exit:
if srv.IdleTimeout != nil { if srv.IdleTimeout != nil {
idleTimeout = srv.IdleTimeout() idleTimeout = srv.IdleTimeout()
} }
m, e := reader.ReadTCP(w.tcp, idleTimeout) m, err = reader.ReadTCP(w.tcp, idleTimeout)
if e == nil { if err == nil {
q++ q++
goto Redo goto Redo
} }
@ -615,7 +616,7 @@ func (srv *Server) readTCP(conn net.Conn, timeout time.Duration) ([]byte, error)
} }
return nil, ErrShortRead return nil, ErrShortRead
} }
length, _ := unpackUint16(l, 0) length := binary.BigEndian.Uint16(l)
if length == 0 { if length == 0 {
return nil, ErrShortRead return nil, ErrShortRead
} }
@ -643,10 +644,10 @@ func (srv *Server) readTCP(conn net.Conn, timeout time.Duration) ([]byte, error)
func (srv *Server) readUDP(conn *net.UDPConn, timeout time.Duration) ([]byte, *SessionUDP, error) { func (srv *Server) readUDP(conn *net.UDPConn, timeout time.Duration) ([]byte, *SessionUDP, error) {
conn.SetReadDeadline(time.Now().Add(timeout)) conn.SetReadDeadline(time.Now().Add(timeout))
m := make([]byte, srv.UDPSize) m := make([]byte, srv.UDPSize)
n, s, e := ReadFromSessionUDP(conn, m) n, s, err := ReadFromSessionUDP(conn, m)
if e != nil || n == 0 { if err != nil || n == 0 {
if e != nil { if err != nil {
return nil, nil, e return nil, nil, err
} }
return nil, nil, ErrShortRead return nil, nil, ErrShortRead
} }
@ -690,7 +691,7 @@ func (w *response) Write(m []byte) (int, error) {
return 0, &Error{err: "message too large"} return 0, &Error{err: "message too large"}
} }
l := make([]byte, 2, 2+lm) l := make([]byte, 2, 2+lm)
l[0], l[1] = packUint16(uint16(lm)) binary.BigEndian.PutUint16(l, uint16(lm))
m = append(l, m...) m = append(l, m...)
n, err := io.Copy(w.tcp, bytes.NewReader(m)) n, err := io.Copy(w.tcp, bytes.NewReader(m))

25
vendor/github.com/miekg/dns/sig0.go generated vendored
View File

@ -5,6 +5,7 @@ import (
"crypto/dsa" "crypto/dsa"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/rsa" "crypto/rsa"
"encoding/binary"
"math/big" "math/big"
"strings" "strings"
"time" "time"
@ -67,13 +68,13 @@ func (rr *SIG) Sign(k crypto.Signer, m *Msg) ([]byte, error) {
} }
// Adjust sig data length // Adjust sig data length
rdoff := len(mbuf) + 1 + 2 + 2 + 4 rdoff := len(mbuf) + 1 + 2 + 2 + 4
rdlen, _ := unpackUint16(buf, rdoff) rdlen := binary.BigEndian.Uint16(buf[rdoff:])
rdlen += uint16(len(sig)) rdlen += uint16(len(sig))
buf[rdoff], buf[rdoff+1] = packUint16(rdlen) binary.BigEndian.PutUint16(buf[rdoff:], rdlen)
// Adjust additional count // Adjust additional count
adc, _ := unpackUint16(buf, 10) adc := binary.BigEndian.Uint16(buf[10:])
adc++ adc++
buf[10], buf[11] = packUint16(adc) binary.BigEndian.PutUint16(buf[10:], adc)
return buf, nil return buf, nil
} }
@ -103,10 +104,11 @@ func (rr *SIG) Verify(k *KEY, buf []byte) error {
hasher := hash.New() hasher := hash.New()
buflen := len(buf) buflen := len(buf)
qdc, _ := unpackUint16(buf, 4) qdc := binary.BigEndian.Uint16(buf[4:])
anc, _ := unpackUint16(buf, 6) anc := binary.BigEndian.Uint16(buf[6:])
auc, _ := unpackUint16(buf, 8) auc := binary.BigEndian.Uint16(buf[8:])
adc, offset := unpackUint16(buf, 10) adc := binary.BigEndian.Uint16(buf[10:])
offset := 12
var err error var err error
for i := uint16(0); i < qdc && offset < buflen; i++ { for i := uint16(0); i < qdc && offset < buflen; i++ {
_, offset, err = UnpackDomainName(buf, offset) _, offset, err = UnpackDomainName(buf, offset)
@ -127,7 +129,8 @@ func (rr *SIG) Verify(k *KEY, buf []byte) error {
continue continue
} }
var rdlen uint16 var rdlen uint16
rdlen, offset = unpackUint16(buf, offset) rdlen = binary.BigEndian.Uint16(buf[offset:])
offset += 2
offset += int(rdlen) offset += int(rdlen)
} }
if offset >= buflen { if offset >= buflen {
@ -149,9 +152,9 @@ func (rr *SIG) Verify(k *KEY, buf []byte) error {
if offset+4+4 >= buflen { if offset+4+4 >= buflen {
return &Error{err: "overflow unpacking signed message"} return &Error{err: "overflow unpacking signed message"}
} }
expire := uint32(buf[offset])<<24 | uint32(buf[offset+1])<<16 | uint32(buf[offset+2])<<8 | uint32(buf[offset+3]) expire := binary.BigEndian.Uint32(buf[offset:])
offset += 4 offset += 4
incept := uint32(buf[offset])<<24 | uint32(buf[offset+1])<<16 | uint32(buf[offset+2])<<8 | uint32(buf[offset+3]) incept := binary.BigEndian.Uint32(buf[offset:])
offset += 4 offset += 4
now := uint32(time.Now().Unix()) now := uint32(time.Now().Unix())
if now < incept || now > expire { if now < incept || now > expire {

View File

@ -78,9 +78,9 @@ func TLSAName(name, service, network string) (string, error) {
if !IsFqdn(name) { if !IsFqdn(name) {
return "", ErrFqdn return "", ErrFqdn
} }
p, e := net.LookupPort(network, service) p, err := net.LookupPort(network, service)
if e != nil { if err != nil {
return "", e return "", err
} }
return "_" + strconv.Itoa(p) + "._" + network + "." + name, nil return "_" + strconv.Itoa(p) + "._" + network + "." + name, nil
} }

156
vendor/github.com/miekg/dns/tsig.go generated vendored
View File

@ -6,6 +6,7 @@ import (
"crypto/sha1" "crypto/sha1"
"crypto/sha256" "crypto/sha256"
"crypto/sha512" "crypto/sha512"
"encoding/binary"
"encoding/hex" "encoding/hex"
"hash" "hash"
"io" "io"
@ -30,11 +31,11 @@ type TSIG struct {
TimeSigned uint64 `dns:"uint48"` TimeSigned uint64 `dns:"uint48"`
Fudge uint16 Fudge uint16
MACSize uint16 MACSize uint16
MAC string `dns:"size-hex"` MAC string `dns:"size-hex:MACSize"`
OrigId uint16 OrigId uint16
Error uint16 Error uint16
OtherLen uint16 OtherLen uint16
OtherData string `dns:"size-hex"` OtherData string `dns:"size-hex:OtherLen"`
} }
// TSIG has no official presentation format, but this will suffice. // TSIG has no official presentation format, but this will suffice.
@ -68,14 +69,13 @@ type tsigWireFmt struct {
// MACSize, MAC and OrigId excluded // MACSize, MAC and OrigId excluded
Error uint16 Error uint16
OtherLen uint16 OtherLen uint16
OtherData string `dns:"size-hex"` OtherData string `dns:"size-hex:OtherLen"`
} }
// If we have the MAC use this type to convert it to wiredata. // If we have the MAC use this type to convert it to wiredata. Section 3.4.3. Request MAC
// Section 3.4.3. Request MAC
type macWireFmt struct { type macWireFmt struct {
MACSize uint16 MACSize uint16
MAC string `dns:"size-hex"` MAC string `dns:"size-hex:MACSize"`
} }
// 3.3. Time values used in TSIG calculations // 3.3. Time values used in TSIG calculations
@ -141,7 +141,9 @@ func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, s
return nil, "", err return nil, "", err
} }
mbuf = append(mbuf, tbuf...) mbuf = append(mbuf, tbuf...)
rawSetExtraLen(mbuf, uint16(len(m.Extra)+1)) // Update the ArCount directly in the buffer.
binary.BigEndian.PutUint16(mbuf[10:], uint16(len(m.Extra)+1))
return mbuf, t.MAC, nil return mbuf, t.MAC, nil
} }
@ -212,7 +214,7 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b
m.MACSize = uint16(len(requestMAC) / 2) m.MACSize = uint16(len(requestMAC) / 2)
m.MAC = requestMAC m.MAC = requestMAC
buf = make([]byte, len(requestMAC)) // long enough buf = make([]byte, len(requestMAC)) // long enough
n, _ := PackStruct(m, buf, 0) n, _ := packMacWire(m, buf)
buf = buf[:n] buf = buf[:n]
} }
@ -221,7 +223,7 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b
tsig := new(timerWireFmt) tsig := new(timerWireFmt)
tsig.TimeSigned = rr.TimeSigned tsig.TimeSigned = rr.TimeSigned
tsig.Fudge = rr.Fudge tsig.Fudge = rr.Fudge
n, _ := PackStruct(tsig, tsigvar, 0) n, _ := packTimerWire(tsig, tsigvar)
tsigvar = tsigvar[:n] tsigvar = tsigvar[:n]
} else { } else {
tsig := new(tsigWireFmt) tsig := new(tsigWireFmt)
@ -234,7 +236,7 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b
tsig.Error = rr.Error tsig.Error = rr.Error
tsig.OtherLen = rr.OtherLen tsig.OtherLen = rr.OtherLen
tsig.OtherData = rr.OtherData tsig.OtherData = rr.OtherData
n, _ := PackStruct(tsig, tsigvar, 0) n, _ := packTsigWire(tsig, tsigvar)
tsigvar = tsigvar[:n] tsigvar = tsigvar[:n]
} }
@ -249,60 +251,54 @@ func tsigBuffer(msgbuf []byte, rr *TSIG, requestMAC string, timersOnly bool) []b
// Strip the TSIG from the raw message. // Strip the TSIG from the raw message.
func stripTsig(msg []byte) ([]byte, *TSIG, error) { func stripTsig(msg []byte) ([]byte, *TSIG, error) {
// Copied from msg.go's Unpack() // Copied from msg.go's Unpack() Header, but modified.
// Header. var (
var dh Header dh Header
var err error err error
dns := new(Msg) )
rr := new(TSIG) off, tsigoff := 0, 0
off := 0
tsigoff := 0 if dh, off, err = unpackMsgHdr(msg, off); err != nil {
if off, err = UnpackStruct(&dh, msg, off); err != nil {
return nil, nil, err return nil, nil, err
} }
if dh.Arcount == 0 { if dh.Arcount == 0 {
return nil, nil, ErrNoSig return nil, nil, ErrNoSig
} }
// Rcode, see msg.go Unpack() // Rcode, see msg.go Unpack()
if int(dh.Bits&0xF) == RcodeNotAuth { if int(dh.Bits&0xF) == RcodeNotAuth {
return nil, nil, ErrAuth return nil, nil, ErrAuth
} }
// Arrays. for i := 0; i < int(dh.Qdcount); i++ {
dns.Question = make([]Question, dh.Qdcount) _, off, err = unpackQuestion(msg, off)
dns.Answer = make([]RR, dh.Ancount) if err != nil {
dns.Ns = make([]RR, dh.Nscount) return nil, nil, err
dns.Extra = make([]RR, dh.Arcount) }
}
for i := 0; i < len(dns.Question); i++ { _, off, err = unpackRRslice(int(dh.Ancount), msg, off)
off, err = UnpackStruct(&dns.Question[i], msg, off) if err != nil {
if err != nil { return nil, nil, err
return nil, nil, err
}
} }
for i := 0; i < len(dns.Answer); i++ { _, off, err = unpackRRslice(int(dh.Nscount), msg, off)
dns.Answer[i], off, err = UnpackRR(msg, off) if err != nil {
if err != nil { return nil, nil, err
return nil, nil, err
}
} }
for i := 0; i < len(dns.Ns); i++ {
dns.Ns[i], off, err = UnpackRR(msg, off) rr := new(TSIG)
if err != nil { var extra RR
return nil, nil, err for i := 0; i < int(dh.Arcount); i++ {
}
}
for i := 0; i < len(dns.Extra); i++ {
tsigoff = off tsigoff = off
dns.Extra[i], off, err = UnpackRR(msg, off) extra, off, err = UnpackRR(msg, off)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
if dns.Extra[i].Header().Rrtype == TypeTSIG { if extra.Header().Rrtype == TypeTSIG {
rr = dns.Extra[i].(*TSIG) rr = extra.(*TSIG)
// Adjust Arcount. // Adjust Arcount.
arcount, _ := unpackUint16(msg, 10) arcount := binary.BigEndian.Uint16(msg[10:])
msg[10], msg[11] = packUint16(arcount - 1) binary.BigEndian.PutUint16(msg[10:], arcount-1)
break break
} }
} }
@ -318,3 +314,71 @@ func tsigTimeToString(t uint64) string {
ti := time.Unix(int64(t), 0).UTC() ti := time.Unix(int64(t), 0).UTC()
return ti.Format("20060102150405") return ti.Format("20060102150405")
} }
func packTsigWire(tw *tsigWireFmt, msg []byte) (int, error) {
// copied from zmsg.go TSIG packing
// RR_Header
off, err := PackDomainName(tw.Name, msg, 0, nil, false)
if err != nil {
return off, err
}
off, err = packUint16(tw.Class, msg, off)
if err != nil {
return off, err
}
off, err = packUint32(tw.Ttl, msg, off)
if err != nil {
return off, err
}
off, err = PackDomainName(tw.Algorithm, msg, off, nil, false)
if err != nil {
return off, err
}
off, err = packUint48(tw.TimeSigned, msg, off)
if err != nil {
return off, err
}
off, err = packUint16(tw.Fudge, msg, off)
if err != nil {
return off, err
}
off, err = packUint16(tw.Error, msg, off)
if err != nil {
return off, err
}
off, err = packUint16(tw.OtherLen, msg, off)
if err != nil {
return off, err
}
off, err = packStringHex(tw.OtherData, msg, off)
if err != nil {
return off, err
}
return off, nil
}
func packMacWire(mw *macWireFmt, msg []byte) (int, error) {
off, err := packUint16(mw.MACSize, msg, 0)
if err != nil {
return off, err
}
off, err = packStringHex(mw.MAC, msg, off)
if err != nil {
return off, err
}
return off, nil
}
func packTimerWire(tw *timerWireFmt, msg []byte) (int, error) {
off, err := packUint48(tw.TimeSigned, msg, 0)
if err != nil {
return off, err
}
off, err = packUint16(tw.Fudge, msg, off)
if err != nil {
return off, err
}
return off, nil
}

94
vendor/github.com/miekg/dns/types.go generated vendored
View File

@ -1,7 +1,6 @@
package dns package dns
import ( import (
"encoding/base64"
"fmt" "fmt"
"net" "net"
"strconv" "strconv"
@ -35,7 +34,6 @@ const (
TypeMG uint16 = 8 TypeMG uint16 = 8
TypeMR uint16 = 9 TypeMR uint16 = 9
TypeNULL uint16 = 10 TypeNULL uint16 = 10
TypeWKS uint16 = 11
TypePTR uint16 = 12 TypePTR uint16 = 12
TypeHINFO uint16 = 13 TypeHINFO uint16 = 13
TypeMINFO uint16 = 14 TypeMINFO uint16 = 14
@ -65,7 +63,6 @@ const (
TypeOPT uint16 = 41 // EDNS TypeOPT uint16 = 41 // EDNS
TypeDS uint16 = 43 TypeDS uint16 = 43
TypeSSHFP uint16 = 44 TypeSSHFP uint16 = 44
TypeIPSECKEY uint16 = 45
TypeRRSIG uint16 = 46 TypeRRSIG uint16 = 46
TypeNSEC uint16 = 47 TypeNSEC uint16 = 47
TypeDNSKEY uint16 = 48 TypeDNSKEY uint16 = 48
@ -136,6 +133,7 @@ const (
RcodeBadName = 20 RcodeBadName = 20
RcodeBadAlg = 21 RcodeBadAlg = 21
RcodeBadTrunc = 22 // TSIG RcodeBadTrunc = 22 // TSIG
RcodeBadCookie = 23 // DNS Cookies
// Message Opcodes. There is no 3. // Message Opcodes. There is no 3.
OpcodeQuery = 0 OpcodeQuery = 0
@ -871,57 +869,6 @@ func (rr *SSHFP) String() string {
" " + strings.ToUpper(rr.FingerPrint) " " + strings.ToUpper(rr.FingerPrint)
} }
type IPSECKEY struct {
Hdr RR_Header
Precedence uint8
// GatewayType: 1: A record, 2: AAAA record, 3: domainname.
// 0 is use for no type and GatewayName should be "." then.
GatewayType uint8
Algorithm uint8
// Gateway can be an A record, AAAA record or a domain name.
GatewayA net.IP `dns:"a"`
GatewayAAAA net.IP `dns:"aaaa"`
GatewayName string `dns:"domain-name"`
PublicKey string `dns:"base64"`
}
func (rr *IPSECKEY) String() string {
s := rr.Hdr.String() + strconv.Itoa(int(rr.Precedence)) +
" " + strconv.Itoa(int(rr.GatewayType)) +
" " + strconv.Itoa(int(rr.Algorithm))
switch rr.GatewayType {
case 0:
fallthrough
case 3:
s += " " + rr.GatewayName
case 1:
s += " " + rr.GatewayA.String()
case 2:
s += " " + rr.GatewayAAAA.String()
default:
s += " ."
}
s += " " + rr.PublicKey
return s
}
func (rr *IPSECKEY) len() int {
l := rr.Hdr.len() + 3 + 1
switch rr.GatewayType {
default:
fallthrough
case 0:
fallthrough
case 3:
l += len(rr.GatewayName)
case 1:
l += 4
case 2:
l += 16
}
return l + base64.StdEncoding.DecodedLen(len(rr.PublicKey))
}
type KEY struct { type KEY struct {
DNSKEY DNSKEY
} }
@ -973,9 +920,9 @@ type NSEC3 struct {
Flags uint8 Flags uint8
Iterations uint16 Iterations uint16
SaltLength uint8 SaltLength uint8
Salt string `dns:"size-hex"` Salt string `dns:"size-hex:SaltLength"`
HashLength uint8 HashLength uint8
NextDomain string `dns:"size-base32"` NextDomain string `dns:"size-base32:HashLength"`
TypeBitMap []uint16 `dns:"nsec"` TypeBitMap []uint16 `dns:"nsec"`
} }
@ -1105,8 +1052,8 @@ type HIP struct {
HitLength uint8 HitLength uint8
PublicKeyAlgorithm uint8 PublicKeyAlgorithm uint8
PublicKeyLength uint16 PublicKeyLength uint16
Hit string `dns:"hex"` Hit string `dns:"size-hex:HitLength"`
PublicKey string `dns:"base64"` PublicKey string `dns:"size-base64:PublicKeyLength"`
RendezvousServers []string `dns:"domain-name"` RendezvousServers []string `dns:"domain-name"`
} }
@ -1128,31 +1075,6 @@ type NINFO struct {
func (rr *NINFO) String() string { return rr.Hdr.String() + sprintTxt(rr.ZSData) } func (rr *NINFO) String() string { return rr.Hdr.String() + sprintTxt(rr.ZSData) }
type WKS struct {
Hdr RR_Header
Address net.IP `dns:"a"`
Protocol uint8
BitMap []uint16 `dns:"wks"`
}
func (rr *WKS) len() int {
// TODO: this is missing something...
return rr.Hdr.len() + net.IPv4len + 1
}
func (rr *WKS) String() (s string) {
s = rr.Hdr.String()
if rr.Address != nil {
s += rr.Address.String()
}
// TODO(miek): missing protocol here, see /etc/protocols
for i := 0; i < len(rr.BitMap); i++ {
// should lookup the port
s += " " + strconv.Itoa(int(rr.BitMap[i]))
}
return s
}
type NID struct { type NID struct {
Hdr RR_Header Hdr RR_Header
Preference uint16 Preference uint16
@ -1286,9 +1208,9 @@ func TimeToString(t uint32) string {
// string values like "20110403154150" to an 32 bit integer. // string values like "20110403154150" to an 32 bit integer.
// It takes serial arithmetic (RFC 1982) into account. // It takes serial arithmetic (RFC 1982) into account.
func StringToTime(s string) (uint32, error) { func StringToTime(s string) (uint32, error) {
t, e := time.Parse("20060102150405", s) t, err := time.Parse("20060102150405", s)
if e != nil { if err != nil {
return 0, e return 0, err
} }
mod := (t.Unix() / year68) - 1 mod := (t.Unix() / year68) - 1
if mod < 0 { if mod < 0 {

View File

@ -20,16 +20,14 @@ import (
) )
var skipLen = map[string]struct{}{ var skipLen = map[string]struct{}{
"NSEC": {}, "NSEC": {},
"NSEC3": {}, "NSEC3": {},
"OPT": {}, "OPT": {},
"WKS": {},
"IPSECKEY": {},
} }
var packageHdr = ` var packageHdr = `
// *** DO NOT MODIFY *** // *** DO NOT MODIFY ***
// AUTOGENERATED BY go generate // AUTOGENERATED BY go generate from type_generate.go
package dns package dns
@ -173,26 +171,30 @@ func main() {
continue continue
} }
switch st.Tag(i) { switch {
case `dns:"-"`: case st.Tag(i) == `dns:"-"`:
// ignored // ignored
case `dns:"cdomain-name"`, `dns:"domain-name"`: case st.Tag(i) == `dns:"cdomain-name"`, st.Tag(i) == `dns:"domain-name"`:
o("l += len(rr.%s) + 1\n") o("l += len(rr.%s) + 1\n")
case `dns:"octet"`: case st.Tag(i) == `dns:"octet"`:
o("l += len(rr.%s)\n") o("l += len(rr.%s)\n")
case `dns:"base64"`: case strings.HasPrefix(st.Tag(i), `dns:"size-base64`):
fallthrough
case st.Tag(i) == `dns:"base64"`:
o("l += base64.StdEncoding.DecodedLen(len(rr.%s))\n") o("l += base64.StdEncoding.DecodedLen(len(rr.%s))\n")
case `dns:"size-hex"`, `dns:"hex"`: case strings.HasPrefix(st.Tag(i), `dns:"size-hex`):
fallthrough
case st.Tag(i) == `dns:"hex"`:
o("l += len(rr.%s)/2 + 1\n") o("l += len(rr.%s)/2 + 1\n")
case `dns:"a"`: case st.Tag(i) == `dns:"a"`:
o("l += net.IPv4len // %s\n") o("l += net.IPv4len // %s\n")
case `dns:"aaaa"`: case st.Tag(i) == `dns:"aaaa"`:
o("l += net.IPv6len // %s\n") o("l += net.IPv6len // %s\n")
case `dns:"txt"`: case st.Tag(i) == `dns:"txt"`:
o("for _, t := range rr.%s { l += len(t) + 1 }\n") o("for _, t := range rr.%s { l += len(t) + 1 }\n")
case `dns:"uint48"`: case st.Tag(i) == `dns:"uint48"`:
o("l += 6 // %s\n") o("l += 6 // %s\n")
case "": case st.Tag(i) == "":
switch st.Field(i).Type().(*types.Basic).Kind() { switch st.Field(i).Type().(*types.Basic).Kind() {
case types.Uint8: case types.Uint8:
o("l += 1 // %s\n") o("l += 1 // %s\n")
@ -229,7 +231,10 @@ func main() {
if sl, ok := st.Field(i).Type().(*types.Slice); ok { if sl, ok := st.Field(i).Type().(*types.Slice); ok {
t := sl.Underlying().String() t := sl.Underlying().String()
t = strings.TrimPrefix(t, "[]") t = strings.TrimPrefix(t, "[]")
t = strings.TrimPrefix(t, "github.com/miekg/dns.") if strings.Contains(t, ".") {
splits := strings.Split(t, ".")
t = splits[len(splits)-1]
}
fmt.Fprintf(b, "%s := make([]%s, len(rr.%s)); copy(%s, rr.%s)\n", fmt.Fprintf(b, "%s := make([]%s, len(rr.%s)); copy(%s, rr.%s)\n",
f, t, f, f, f) f, t, f, f, f)
fields = append(fields, f) fields = append(fields, f)

4
vendor/github.com/miekg/dns/xfr.go generated vendored
View File

@ -162,8 +162,8 @@ func (t *Transfer) inIxfr(id uint16, c chan *Envelope) {
// //
// ch := make(chan *dns.Envelope) // ch := make(chan *dns.Envelope)
// tr := new(dns.Transfer) // tr := new(dns.Transfer)
// tr.Out(w, r, ch) // go tr.Out(w, r, ch)
// c <- &dns.Envelope{RR: []dns.RR{soa, rr1, rr2, rr3, soa}} // ch <- &dns.Envelope{RR: []dns.RR{soa, rr1, rr2, rr3, soa}}
// close(ch) // close(ch)
// w.Hijack() // w.Hijack()
// // w.Close() // Client closes connection // // w.Close() // Client closes connection

3462
vendor/github.com/miekg/dns/zmsg.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
// *** DO NOT MODIFY *** // *** DO NOT MODIFY ***
// AUTOGENERATED BY go generate // AUTOGENERATED BY go generate from type_generate.go
package dns package dns
@ -31,7 +31,6 @@ var TypeToRR = map[uint16]func() RR{
TypeGPOS: func() RR { return new(GPOS) }, TypeGPOS: func() RR { return new(GPOS) },
TypeHINFO: func() RR { return new(HINFO) }, TypeHINFO: func() RR { return new(HINFO) },
TypeHIP: func() RR { return new(HIP) }, TypeHIP: func() RR { return new(HIP) },
TypeIPSECKEY: func() RR { return new(IPSECKEY) },
TypeKEY: func() RR { return new(KEY) }, TypeKEY: func() RR { return new(KEY) },
TypeKX: func() RR { return new(KX) }, TypeKX: func() RR { return new(KX) },
TypeL32: func() RR { return new(L32) }, TypeL32: func() RR { return new(L32) },
@ -76,7 +75,6 @@ var TypeToRR = map[uint16]func() RR{
TypeUID: func() RR { return new(UID) }, TypeUID: func() RR { return new(UID) },
TypeUINFO: func() RR { return new(UINFO) }, TypeUINFO: func() RR { return new(UINFO) },
TypeURI: func() RR { return new(URI) }, TypeURI: func() RR { return new(URI) },
TypeWKS: func() RR { return new(WKS) },
TypeX25: func() RR { return new(X25) }, TypeX25: func() RR { return new(X25) },
} }
@ -105,7 +103,6 @@ var TypeToString = map[uint16]string{
TypeGPOS: "GPOS", TypeGPOS: "GPOS",
TypeHINFO: "HINFO", TypeHINFO: "HINFO",
TypeHIP: "HIP", TypeHIP: "HIP",
TypeIPSECKEY: "IPSECKEY",
TypeISDN: "ISDN", TypeISDN: "ISDN",
TypeIXFR: "IXFR", TypeIXFR: "IXFR",
TypeKEY: "KEY", TypeKEY: "KEY",
@ -158,7 +155,6 @@ var TypeToString = map[uint16]string{
TypeUINFO: "UINFO", TypeUINFO: "UINFO",
TypeUNSPEC: "UNSPEC", TypeUNSPEC: "UNSPEC",
TypeURI: "URI", TypeURI: "URI",
TypeWKS: "WKS",
TypeX25: "X25", TypeX25: "X25",
TypeNSAPPTR: "NSAP-PTR", TypeNSAPPTR: "NSAP-PTR",
} }
@ -185,7 +181,6 @@ func (rr *GID) Header() *RR_Header { return &rr.Hdr }
func (rr *GPOS) Header() *RR_Header { return &rr.Hdr } func (rr *GPOS) Header() *RR_Header { return &rr.Hdr }
func (rr *HINFO) Header() *RR_Header { return &rr.Hdr } func (rr *HINFO) Header() *RR_Header { return &rr.Hdr }
func (rr *HIP) Header() *RR_Header { return &rr.Hdr } func (rr *HIP) Header() *RR_Header { return &rr.Hdr }
func (rr *IPSECKEY) Header() *RR_Header { return &rr.Hdr }
func (rr *KEY) Header() *RR_Header { return &rr.Hdr } func (rr *KEY) Header() *RR_Header { return &rr.Hdr }
func (rr *KX) Header() *RR_Header { return &rr.Hdr } func (rr *KX) Header() *RR_Header { return &rr.Hdr }
func (rr *L32) Header() *RR_Header { return &rr.Hdr } func (rr *L32) Header() *RR_Header { return &rr.Hdr }
@ -231,7 +226,6 @@ func (rr *TXT) Header() *RR_Header { return &rr.Hdr }
func (rr *UID) Header() *RR_Header { return &rr.Hdr } func (rr *UID) Header() *RR_Header { return &rr.Hdr }
func (rr *UINFO) Header() *RR_Header { return &rr.Hdr } func (rr *UINFO) Header() *RR_Header { return &rr.Hdr }
func (rr *URI) Header() *RR_Header { return &rr.Hdr } func (rr *URI) Header() *RR_Header { return &rr.Hdr }
func (rr *WKS) Header() *RR_Header { return &rr.Hdr }
func (rr *X25) Header() *RR_Header { return &rr.Hdr } func (rr *X25) Header() *RR_Header { return &rr.Hdr }
// len() functions // len() functions
@ -688,9 +682,6 @@ func (rr *HIP) copy() RR {
copy(RendezvousServers, rr.RendezvousServers) copy(RendezvousServers, rr.RendezvousServers)
return &HIP{*rr.Hdr.copyHeader(), rr.HitLength, rr.PublicKeyAlgorithm, rr.PublicKeyLength, rr.Hit, rr.PublicKey, RendezvousServers} return &HIP{*rr.Hdr.copyHeader(), rr.HitLength, rr.PublicKeyAlgorithm, rr.PublicKeyLength, rr.Hit, rr.PublicKey, RendezvousServers}
} }
func (rr *IPSECKEY) copy() RR {
return &IPSECKEY{*rr.Hdr.copyHeader(), rr.Precedence, rr.GatewayType, rr.Algorithm, copyIP(rr.GatewayA), copyIP(rr.GatewayAAAA), rr.GatewayName, rr.PublicKey}
}
func (rr *KX) copy() RR { func (rr *KX) copy() RR {
return &KX{*rr.Hdr.copyHeader(), rr.Preference, rr.Exchanger} return &KX{*rr.Hdr.copyHeader(), rr.Preference, rr.Exchanger}
} }
@ -832,11 +823,6 @@ func (rr *UINFO) copy() RR {
func (rr *URI) copy() RR { func (rr *URI) copy() RR {
return &URI{*rr.Hdr.copyHeader(), rr.Priority, rr.Weight, rr.Target} return &URI{*rr.Hdr.copyHeader(), rr.Priority, rr.Weight, rr.Target}
} }
func (rr *WKS) copy() RR {
BitMap := make([]uint16, len(rr.BitMap))
copy(BitMap, rr.BitMap)
return &WKS{*rr.Hdr.copyHeader(), copyIP(rr.Address), rr.Protocol, BitMap}
}
func (rr *X25) copy() RR { func (rr *X25) copy() RR {
return &X25{*rr.Hdr.copyHeader(), rr.PSDNAddress} return &X25{*rr.Hdr.copyHeader(), rr.PSDNAddress}
} }

0
vendor/github.com/pborman/uuid/dce.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/pborman/uuid/doc.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/pborman/uuid/node.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/pborman/uuid/time.go generated vendored Normal file → Executable file
View File

0
vendor/github.com/pborman/uuid/uuid.go generated vendored Normal file → Executable file
View File

View File

@ -39,7 +39,7 @@ type Config struct {
RoundRobin bool `json:"round_robin,omitempty"` RoundRobin bool `json:"round_robin,omitempty"`
// Round robin selection of nameservers from among those listed, rather than have all forwarded requests try the first listed server first every time. // Round robin selection of nameservers from among those listed, rather than have all forwarded requests try the first listed server first every time.
NSRotate bool `json:"ns_rotate,omitempty"` NSRotate bool `json:"ns_rotate,omitempty"`
// List of ip:port, seperated by commas of recursive nameservers to forward queries to. // List of ip:port, separated by commas of recursive nameservers to forward queries to.
Nameservers []string `json:"nameservers,omitempty"` Nameservers []string `json:"nameservers,omitempty"`
// Never provide a recursive service. // Never provide a recursive service.
NoRec bool `json:"no_rec,omitempty"` NoRec bool `json:"no_rec,omitempty"`

View File

@ -102,7 +102,7 @@ Redo:
r, err := exchangeWithRetry(s.dnsUDPclient, m, s.config.Nameservers[nsid]) r, err := exchangeWithRetry(s.dnsUDPclient, m, s.config.Nameservers[nsid])
if err == nil { if err == nil {
if r.Rcode != dns.RcodeSuccess { if r.Rcode != dns.RcodeSuccess {
return nil, fmt.Errorf("rcode is not equal to success") return nil, fmt.Errorf("rcode %d is not equal to success", r.Rcode)
} }
// Reset TTLs to rcache TTL to make some of the other code // Reset TTLs to rcache TTL to make some of the other code
// and the tests not care about TTLs // and the tests not care about TTLs

View File

@ -200,7 +200,7 @@ func (s *server) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
} }
for zone, ns := range *s.config.stub { for zone, ns := range *s.config.stub {
if strings.HasSuffix(name, zone) { if strings.HasSuffix(name, "." + zone) || name == zone {
metrics.ReportRequestCount(req, metrics.Stub) metrics.ReportRequestCount(req, metrics.Stub)
resp := s.ServeDNSStubForward(w, req, ns) resp := s.ServeDNSStubForward(w, req, ns)
@ -232,7 +232,7 @@ func (s *server) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
return return
} }
if q.Qclass != dns.ClassCHAOS && !strings.HasSuffix(name, s.config.Domain) { if q.Qclass != dns.ClassCHAOS && !strings.HasSuffix(name, "." +s.config.Domain) && name != s.config.Domain {
metrics.ReportRequestCount(req, metrics.Rec) metrics.ReportRequestCount(req, metrics.Rec)
resp := s.ServeDNSForward(w, req) resp := s.ServeDNSForward(w, req)
@ -431,6 +431,7 @@ func (s *server) AddressRecords(q dns.Question, name string, previousRecords []d
case ip == nil: case ip == nil:
// Try to resolve as CNAME if it's not an IP, but only if we don't create loops. // Try to resolve as CNAME if it's not an IP, but only if we don't create loops.
if q.Name == dns.Fqdn(serv.Host) { if q.Name == dns.Fqdn(serv.Host) {
logf("CNAME loop detected: %q -> %q", q.Name, q.Name)
// x CNAME x is a direct loop, don't add those // x CNAME x is a direct loop, don't add those
continue continue
} }
@ -464,7 +465,7 @@ func (s *server) AddressRecords(q dns.Question, name string, previousRecords []d
} }
m1, e1 := s.Lookup(target, q.Qtype, bufsize, dnssec) m1, e1 := s.Lookup(target, q.Qtype, bufsize, dnssec)
if e1 != nil { if e1 != nil {
logf("incomplete CNAME chain: %s", e1) logf("incomplete CNAME chain from %q: %s", target, e1)
continue continue
} }
// Len(m1.Answer) > 0 here is well? // Len(m1.Answer) > 0 here is well?

0
vendor/github.com/ugorji/go/codec/prebuild.sh generated vendored Normal file → Executable file
View File

0
vendor/github.com/ugorji/go/codec/test.py generated vendored Normal file → Executable file
View File

0
vendor/github.com/ugorji/go/codec/tests.sh generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mkall.sh generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mkerrors.sh generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mksyscall.pl generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mksyscall_solaris.pl generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mksysnum_darwin.pl generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mksysnum_dragonfly.pl generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mksysnum_freebsd.pl generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mksysnum_linux.pl generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mksysnum_netbsd.pl generated vendored Normal file → Executable file
View File

0
vendor/golang.org/x/sys/unix/mksysnum_openbsd.pl generated vendored Normal file → Executable file
View File

0
vendor/google.golang.org/grpc/codegen.sh generated vendored Normal file → Executable file
View File

0
vendor/google.golang.org/grpc/coverage.sh generated vendored Normal file → Executable file
View File