From bc8f7bf80fa66cbc263b86d4b7a01f7a2fda07f5 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 15 Oct 2013 13:22:35 +0000 Subject: [PATCH 1/4] gitignore update --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 45cc90bb..776cd950 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.6 +tags test.out a.out From 1c343223b5950bd74e23be0e6209f70f16d5d665 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 15 Oct 2013 13:42:24 +0000 Subject: [PATCH 2/4] Go over the documentation again --- TODO.markdown | 1 + dns.go | 7 +++--- edns.go | 65 +++++++++++++-------------------------------------- 3 files changed, 21 insertions(+), 52 deletions(-) diff --git a/TODO.markdown b/TODO.markdown index 6269aa92..1850d8eb 100644 --- a/TODO.markdown +++ b/TODO.markdown @@ -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 diff --git a/dns.go b/dns.go index 8c746264..60914df5 100644 --- a/dns.go +++ b/dns.go @@ -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. // diff --git a/edns.go b/edns.go index 8852ae28..e65ceed0 100644 --- a/edns.go +++ b/edns.go @@ -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 From 79cce8e6c86a6456364dffd1c7860dbe0dd26a34 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 15 Oct 2013 14:21:32 +0000 Subject: [PATCH 3/4] Small go vet issues --- defaults.go | 10 +++------- kscan.go | 7 +++---- zgenerate.go | 4 +--- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/defaults.go b/defaults.go index f4b80341..81e0d85d 100644 --- a/defaults.go +++ b/defaults.go @@ -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)) } diff --git a/kscan.go b/kscan.go index 95d5a01c..22492c27 100644 --- a/kscan.go +++ b/kscan.go @@ -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 } diff --git a/zgenerate.go b/zgenerate.go index 5f3c0a4d..fb8b113a 100644 --- a/zgenerate.go +++ b/zgenerate.go @@ -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, "" } From b435d836c68df05018acfaa859b05014b21b9b99 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 15 Oct 2013 14:21:47 +0000 Subject: [PATCH 4/4] gofmt --- defaults.go | 2 +- msg.go | 2 +- parse_test.go | 6 +++--- zscan_rr.go | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/defaults.go b/defaults.go index 81e0d85d..95c05cf7 100644 --- a/defaults.go +++ b/defaults.go @@ -223,7 +223,7 @@ func ReverseAddr(addr string) (arpa string, err error) { func (t Type) String() string { if t1, ok := TypeToString[uint16(t)]; ok { return t1 - } + } return "TYPE" + strconv.Itoa(int(t)) } diff --git a/msg.go b/msg.go index d378aeb1..0f917172 100644 --- a/msg.go +++ b/msg.go @@ -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", diff --git a/parse_test.go b/parse_test.go index 7623b421..6f850348 100644 --- a/parse_test.go +++ b/parse_test.go @@ -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 { diff --git a/zscan_rr.go b/zscan_rr.go index ce2022a4..7e623bac 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -2040,4 +2040,3 @@ func setPX(h RR_Header, c chan lex, o, f string) (RR, *ParseError) { } return rr, nil } -