Merge branch 'master' of github.com:miekg/dns

This commit is contained in:
Miek Gieben 2013-10-15 20:35:35 +01:00
commit 2bc1cd1a2e
10 changed files with 32 additions and 70 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.6
tags
test.out
a.out

View File

@ -9,3 +9,4 @@
moderate hardware
* privatekey.Precompute() when signing?
* Last remaining RRs: APL, NIMLOC & EID, ATMA, A6, KEY, SIG and NXT
* CAA parsing is broken

View File

@ -223,18 +223,14 @@ func ReverseAddr(addr string) (arpa string, err error) {
func (t Type) String() string {
if t1, ok := TypeToString[uint16(t)]; ok {
return t1
} else {
return "TYPE" + strconv.Itoa(int(t))
}
panic("dns: not reached") // go < 1.1 compat
return "TYPE" + strconv.Itoa(int(t))
}
// String returns the string representation for the class c
func (c Class) String() string {
if c1, ok := ClassToString[uint16(c)]; ok {
return c1
} else {
return "CLASS" + strconv.Itoa(int(c))
}
panic("dns: not reached")
return "CLASS" + strconv.Itoa(int(c))
}

7
dns.go
View File

@ -8,7 +8,7 @@
// The package allows complete control over what is send out to the DNS. The package
// API follows the less-is-more principle, by presenting a small, clean interface.
//
// The package dns supports (asynchronous) querying/replying, incoming/outgoing AXFR/IXFR,
// The package dns supports (asynchronous) querying/replying, incoming/outgoing zone transfers,
// TSIG, EDNS0, dynamic updates, notifies and DNSSEC validation/signing.
// Note that domain names MUST be fully qualified, before sending them, unqualified
// names in a message will result in a packing failure.
@ -61,7 +61,7 @@
// c := new(Client)
// in, rtt, err := c.Exchange(m1, "127.0.0.1:53")
//
// For asynchronous queries it is easy to wrap Exchange() in a goroutine. Suppressing
// Suppressing
// multiple outstanding queries (with the same question, type and class) is as easy as setting:
//
// c.SingleInflight = true
@ -71,7 +71,8 @@
//
// in, err := dns.Exchange(m1, "127.0.0.1:53")
//
// A dns message consists out of four sections.
// When this functions returns you will get dns message. A dns message consists
// out of four sections.
// The question section: in.Question, the answer section: in.Answer,
// the authority section: in.Ns and the additional section: in.Extra.
//

65
edns.go
View File

@ -5,7 +5,7 @@
// EDNS0
//
// EDNS0 is an extension mechanism for the DNS defined in RFC 2671 and updated
// by RFC 6891. It defines a standard RR type, the OPT RR, which is then completely
// by RFC 6891. It defines an new RR type, the OPT RR, which is then completely
// abused.
// Basic use pattern for creating an (empty) OPT RR:
//
@ -150,10 +150,7 @@ func (rr *OPT) SetDo() {
}
// EDNS0 defines an EDNS0 Option. An OPT RR can have multiple options appended to
// it. Basic use pattern for adding an option to and OPT RR:
//
// // o is the OPT RR, e is the EDNS0 option
// o.Option = append(o.Option, e)
// it.
type EDNS0 interface {
// Option returns the option code for the option.
Option() uint16
@ -166,8 +163,8 @@ type EDNS0 interface {
String() string
}
// The nsid EDNS0 option is used to retrieve some sort of nameserver
// identifier. When seding a request Nsid must be set to the empty string
// The nsid EDNS0 option is used to retrieve a nameserver
// identifier. When sending a request Nsid must be set to the empty string
// The identifier is an opaque string encoded as hex.
// Basic use pattern for creating an nsid option:
//
@ -182,10 +179,6 @@ type EDNS0_NSID struct {
Nsid string // This string needs to be hex encoded
}
func (e *EDNS0_NSID) Option() uint16 {
return EDNS0NSID
}
func (e *EDNS0_NSID) pack() ([]byte, error) {
h, err := hex.DecodeString(e.Nsid)
if err != nil {
@ -194,13 +187,9 @@ func (e *EDNS0_NSID) pack() ([]byte, error) {
return h, nil
}
func (e *EDNS0_NSID) unpack(b []byte) {
e.Nsid = hex.EncodeToString(b)
}
func (e *EDNS0_NSID) String() string {
return string(e.Nsid)
}
func (e *EDNS0_NSID) Option() uint16 { return EDNS0NSID }
func (e *EDNS0_NSID) unpack(b []byte) { e.Nsid = hex.EncodeToString(b) }
func (e *EDNS0_NSID) String() string { return string(e.Nsid) }
// The subnet EDNS0 option is used to give the remote nameserver
// an idea of where the client lives. It can then give back a different
@ -344,10 +333,6 @@ type EDNS0_UL struct {
Lease uint32
}
func (e *EDNS0_UL) Option() uint16 {
return EDNS0UL
}
// Copied: http://golang.org/src/pkg/net/dnsmsg.go
func (e *EDNS0_UL) pack() ([]byte, error) {
b := make([]byte, 4)
@ -358,13 +343,11 @@ func (e *EDNS0_UL) pack() ([]byte, error) {
return b, nil
}
func (e *EDNS0_UL) Option() uint16 { return EDNS0UL }
func (e *EDNS0_UL) unpack(b []byte) {
e.Lease = uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
}
func (e *EDNS0_UL) String() string {
return strconv.FormatUint(uint64(e.Lease), 10)
}
func (e *EDNS0_UL) String() string { return strconv.FormatUint(uint64(e.Lease), 10) }
// Long Lived Queries: http://tools.ietf.org/html/draft-sekar-dns-llq-01
// Implemented for completeness, as the EDNS0 type code is assigned.
@ -377,9 +360,7 @@ type EDNS0_LLQ struct {
LeaseLife uint32
}
func (e *EDNS0_LLQ) Option() uint16 {
return EDNS0LLQ
}
func (e *EDNS0_LLQ) Option() uint16 { return EDNS0LLQ }
func (e *EDNS0_LLQ) pack() ([]byte, error) {
b := make([]byte, 18)
@ -450,16 +431,9 @@ type EDNS0_DHU struct {
AlgCode []uint8
}
func (e *EDNS0_DHU) Option() uint16 {
return EDNS0DHU
}
func (e *EDNS0_DHU) pack() ([]byte, error) {
return e.AlgCode, nil
}
func (e *EDNS0_DHU) unpack(b []byte) {
e.AlgCode = b
}
func (e *EDNS0_DHU) Option() uint16 { return EDNS0DHU }
func (e *EDNS0_DHU) pack() ([]byte, error) { return e.AlgCode, nil }
func (e *EDNS0_DHU) unpack(b []byte) { e.AlgCode = b }
func (e *EDNS0_DHU) String() string {
s := ""
@ -478,16 +452,9 @@ type EDNS0_N3U struct {
AlgCode []uint8
}
func (e *EDNS0_N3U) Option() uint16 {
return EDNS0N3U
}
func (e *EDNS0_N3U) pack() ([]byte, error) {
return e.AlgCode, nil
}
func (e *EDNS0_N3U) unpack(b []byte) {
e.AlgCode = b
}
func (e *EDNS0_N3U) Option() uint16 { return EDNS0N3U }
func (e *EDNS0_N3U) pack() ([]byte, error) { return e.AlgCode, nil }
func (e *EDNS0_N3U) unpack(b []byte) { e.AlgCode = b }
func (e *EDNS0_N3U) String() string {
// Re-use the hash map

View File

@ -161,9 +161,7 @@ func readPrivateKeyECDSA(m map[string]string) (PrivateKey, error) {
}
func readPrivateKeyGOST(m map[string]string) (PrivateKey, error) {
// p := new(ecdsa.PrivateKey)
// p.D = big.NewInt(0)
// Need to check if we have everything
/* TODO(miek)
for k, v := range m {
switch k {
case "gostasn1:":
@ -174,9 +172,10 @@ func readPrivateKeyGOST(m map[string]string) (PrivateKey, error) {
v1 = v1
//p.D.SetBytes(v1)
case "created:", "publish:", "activate:":
/* not used in Go (yet) */
// not used in Go (yet)
}
}
*/
return nil, nil
}

2
msg.go
View File

@ -141,7 +141,7 @@ var TypeToString = map[uint16]string{
TypeTLSA: "TLSA",
TypeTSIG: "TSIG", // Meta RR
TypeTXT: "TXT",
TypePX: "PX",
TypePX: "PX",
TypeUID: "UID",
TypeUINFO: "UINFO",
TypeUNSPEC: "UNSPEC",

View File

@ -596,8 +596,8 @@ func TestNSAPGPOS(t *testing.T) {
"foo.bar.com. IN NSAP 21 47000580ffff000000321099991111222233334444": "foo.bar.com.\t3600\tIN\tNSAP\t21 47000580ffff000000321099991111222233334444",
"host.school.de IN NSAP 17 39276f3100111100002222333344449876": "host.school.de.\t3600\tIN\tNSAP\t17 39276f3100111100002222333344449876",
"444433332222111199990123000000ff. NSAP-PTR foo.bar.com.": "444433332222111199990123000000ff.\t3600\tIN\tNSAP-PTR\tfoo.bar.com.",
"lillee. IN GPOS -32.6882 116.8652 10.0": "lillee.\t3600\tIN\tGPOS\t-32.6882 116.8652 10.0",
"hinault. IN GPOS -22.6882 116.8652 250.0": "hinault.\t3600\tIN\tGPOS\t-22.6882 116.8652 250.0",
"lillee. IN GPOS -32.6882 116.8652 10.0": "lillee.\t3600\tIN\tGPOS\t-32.6882 116.8652 10.0",
"hinault. IN GPOS -22.6882 116.8652 250.0": "hinault.\t3600\tIN\tGPOS\t-22.6882 116.8652 250.0",
}
for i, o := range dt {
rr, e := NewRR(i)
@ -617,7 +617,7 @@ func TestNSAPGPOS(t *testing.T) {
func TestPX(t *testing.T) {
dt := map[string]string{
"*.net2.it. IN PX 10 net2.it. PRMD-net2.ADMD-p400.C-it.": "*.net2.it.\t3600\tIN\tPX\t10 net2.it. PRMD-net2.ADMD-p400.C-it.",
"*.net2.it. IN PX 10 net2.it. PRMD-net2.ADMD-p400.C-it.": "*.net2.it.\t3600\tIN\tPX\t10 net2.it. PRMD-net2.ADMD-p400.C-it.",
"ab.net2.it. IN PX 10 ab.net2.it. O-ab.PRMD-net2.ADMDb.C-it.": "ab.net2.it.\t3600\tIN\tPX\t10 ab.net2.it. O-ab.PRMD-net2.ADMDb.C-it.",
}
for i, o := range dt {

View File

@ -156,8 +156,6 @@ func modToPrintf(s string) (string, int, string) {
return "", offset, "bad width in $GENERATE"
case width == 0:
return "%" + xs[1] + xs[2], offset, ""
default:
return "%0" + xs[1] + xs[2], offset, ""
}
panic("dns: not reached")
return "%0" + xs[1] + xs[2], offset, ""
}

View File

@ -2040,4 +2040,3 @@ func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
}
return rr, nil
}