Skip to content

Commit 1328610

Browse files
committed
Update github.com/miekg/dns
1 parent ea18507 commit 1328610

File tree

10 files changed

+154
-49
lines changed

10 files changed

+154
-49
lines changed

vendor/manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"importpath": "github.com/miekg/dns",
66
"repository": "https://github.com/miekg/dns",
7-
"revision": "7864d445e5087e8d761dbefec43f29b92f7650eb",
7+
"revision": "ad7777796ea3016887696a887f16140cee2d7612",
88
"branch": "master"
99
}
1010
]

vendor/src/github.com/miekg/dns/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
118118
* 6605 - ECDSA
119119
* 6725 - IANA Registry Update
120120
* 6742 - ILNP DNS
121+
* 6844 - CAA record
121122
* 6891 - EDNS0 update
122123
* 6895 - DNS IANA considerations
123124
* 6975 - Algorithm Understanding in DNSSEC
@@ -138,6 +139,5 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
138139
* privatekey.Precompute() when signing?
139140
* Last remaining RRs: APL, ATMA, A6 and NXT and IPSECKEY;
140141
* Missing in parsing: ISDN, UNSPEC, ATMA;
141-
* CAA parsing is broken;
142142
* NSEC(3) cover/match/closest enclose;
143143
* Replies with TC bit are not parsed to the end;

vendor/src/github.com/miekg/dns/client.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (co *Conn) ReadMsg() (*Msg, error) {
194194
if _, ok := co.Conn.(*net.TCPConn); ok {
195195
p = make([]byte, MaxMsgSize)
196196
} else {
197-
if co.UDPSize >= 512 {
197+
if co.UDPSize > MinMsgSize {
198198
p = make([]byte, co.UDPSize)
199199
} else {
200200
p = make([]byte, MinMsgSize)
@@ -327,21 +327,3 @@ func DialTimeout(network, address string, timeout time.Duration) (conn *Conn, er
327327
}
328328
return conn, nil
329329
}
330-
331-
// Close implements the net.Conn Close method.
332-
func (co *Conn) Close() error { return co.Conn.Close() }
333-
334-
// LocalAddr implements the net.Conn LocalAddr method.
335-
func (co *Conn) LocalAddr() net.Addr { return co.Conn.LocalAddr() }
336-
337-
// RemoteAddr implements the net.Conn RemoteAddr method.
338-
func (co *Conn) RemoteAddr() net.Addr { return co.Conn.RemoteAddr() }
339-
340-
// SetDeadline implements the net.Conn SetDeadline method.
341-
func (co *Conn) SetDeadline(t time.Time) error { return co.Conn.SetDeadline(t) }
342-
343-
// SetReadDeadline implements the net.Conn SetReadDeadline method.
344-
func (co *Conn) SetReadDeadline(t time.Time) error { return co.Conn.SetReadDeadline(t) }
345-
346-
// SetWriteDeadline implements the net.Conn SetWriteDeadline method.
347-
func (co *Conn) SetWriteDeadline(t time.Time) error { return co.Conn.SetWriteDeadline(t) }

vendor/src/github.com/miekg/dns/dns_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,6 @@ func TestToRFC3597(t *testing.T) {
429429
func TestNoRdataPack(t *testing.T) {
430430
data := make([]byte, 1024)
431431
for typ, fn := range typeToRR {
432-
if typ == TypeCAA {
433-
continue // TODO(miek): known omission
434-
}
435432
r := fn()
436433
*r.Header() = RR_Header{Name: "miek.nl.", Rrtype: typ, Class: ClassINET, Ttl: 3600}
437434
_, err := PackRR(r, data, 0, nil, false)

vendor/src/github.com/miekg/dns/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ RFC 6895 sets aside a range of type codes for private use. This range
202202
is 65,280 - 65,534 (0xFF00 - 0xFFFE). When experimenting with new Resource Records these
203203
can be used, before requesting an official type code from IANA.
204204
205+
see http://miek.nl/posts/2014/Sep/21/Private%20RRs%20and%20IDN%20in%20Go%20DNS/ for more
206+
information.
207+
205208
EDNS0
206209
207210
EDNS0 is an extension mechanism for the DNS defined in RFC 2671 and updated

vendor/src/github.com/miekg/dns/msg.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,36 @@ func packTxtString(s string, msg []byte, offset int, tmp []byte) (int, error) {
543543
return offset, nil
544544
}
545545

546+
func packOctetString(s string, msg []byte, offset int, tmp []byte) (int, error) {
547+
if offset >= len(msg) {
548+
return offset, ErrBuf
549+
}
550+
bs := tmp[:len(s)]
551+
copy(bs, s)
552+
for i := 0; i < len(bs); i++ {
553+
if len(msg) <= offset {
554+
return offset, ErrBuf
555+
}
556+
if bs[i] == '\\' {
557+
i++
558+
if i == len(bs) {
559+
break
560+
}
561+
// check for \DDD
562+
if i+2 < len(bs) && isDigit(bs[i]) && isDigit(bs[i+1]) && isDigit(bs[i+2]) {
563+
msg[offset] = dddToByte(bs[i:])
564+
i += 2
565+
} else {
566+
msg[offset] = bs[i]
567+
}
568+
} else {
569+
msg[offset] = bs[i]
570+
}
571+
offset++
572+
}
573+
return offset, nil
574+
}
575+
546576
func unpackTxt(msg []byte, offset, rdend int) ([]string, int, error) {
547577
var err error
548578
var ss []string
@@ -890,6 +920,12 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str
890920
// length of string. String is RAW (not encoded in hex, nor base64)
891921
copy(msg[off:off+len(s)], s)
892922
off += len(s)
923+
case `dns:"octet"`:
924+
bytesTmp := make([]byte, 0)
925+
off, err = packOctetString(fv.String(), msg, off, bytesTmp)
926+
if err != nil {
927+
return lenmsg, err
928+
}
893929
case `dns:"txt"`:
894930
fallthrough
895931
case "":
@@ -1254,6 +1290,13 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
12541290
switch val.Type().Field(i).Tag {
12551291
default:
12561292
return lenmsg, &Error{"bad tag unpacking string: " + val.Type().Field(i).Tag.Get("dns")}
1293+
case `dns:"octet"`:
1294+
strend := lenrd
1295+
if strend > lenmsg {
1296+
return lenmsg, &Error{err: "overflow unpacking octet"}
1297+
}
1298+
s = string(msg[off:strend])
1299+
off = strend
12571300
case `dns:"hex"`:
12581301
hexend := lenrd
12591302
if val.FieldByName("Hdr").FieldByName("Rrtype").Uint() == uint64(TypeHIP) {

vendor/src/github.com/miekg/dns/parse_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,3 +1455,25 @@ func TestParseHINFO(t *testing.T) {
14551455
}
14561456
}
14571457
}
1458+
1459+
func TestParseCAA(t *testing.T) {
1460+
lt := map[string]string{
1461+
"example.net. CAA 0 issue \"symantec.com\"": "example.net.\t3600\tIN\tCAA\t0 issue \"symantec.com\"",
1462+
"example.net. CAA 0 issuewild \"symantec.com; stuff\"": "example.net.\t3600\tIN\tCAA\t0 issuewild \"symantec.com; stuff\"",
1463+
"example.net. CAA 128 tbs \"critical\"": "example.net.\t3600\tIN\tCAA\t128 tbs \"critical\"",
1464+
"example.net. CAA 2 auth \"0>09\\006\\010+\\006\\001\\004\\001\\214y\\002\\003\\001\\006\\009`\\134H\\001e\\003\\004\\002\\001\\004 y\\209\\012\\221r\\220\\156Q\\218\\150\\150{\\166\\245:\\231\\182%\\157:\\133\\179}\\1923r\\238\\151\\255\\128q\\145\\002\\001\\000\"": "example.net.\t3600\tIN\tCAA\t2 auth \"0>09\\006\\010+\\006\\001\\004\\001\\214y\\002\\003\\001\\006\\009`\\134H\\001e\\003\\004\\002\\001\\004 y\\209\\012\\221r\\220\\156Q\\218\\150\\150{\\166\\245:\\231\\182%\\157:\\133\\179}\\1923r\\238\\151\\255\\128q\\145\\002\\001\\000\"",
1465+
"example.net. TYPE257 0 issue \"symantec.com\"": "example.net.\t3600\tIN\tCAA\t0 issue \"symantec.com\"",
1466+
}
1467+
for i, o := range lt {
1468+
rr, err := NewRR(i)
1469+
if err != nil {
1470+
t.Error("failed to parse RR: ", err)
1471+
continue
1472+
}
1473+
if rr.String() != o {
1474+
t.Errorf("`%s' should be equal to\n`%s', but is `%s'", i, o, rr.String())
1475+
} else {
1476+
t.Logf("RR is OK: `%s'", rr.String())
1477+
}
1478+
}
1479+
}

vendor/src/github.com/miekg/dns/types.go

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,34 @@ func sprintName(s string) string {
501501
return string(dst)
502502
}
503503

504+
func sprintCAAValue(s string) string {
505+
src := []byte(s)
506+
dst := make([]byte, 0, len(src))
507+
dst = append(dst, '"')
508+
for i := 0; i < len(src); {
509+
if i+1 < len(src) && src[i] == '\\' && src[i+1] == '.' {
510+
dst = append(dst, src[i:i+2]...)
511+
i += 2
512+
} else {
513+
b, n := nextByte(src, i)
514+
if n == 0 {
515+
i++ // dangling back slash
516+
} else if b == '.' {
517+
dst = append(dst, b)
518+
} else {
519+
if b < ' ' || b > '~' {
520+
dst = appendByte(dst, b)
521+
} else {
522+
dst = append(dst, b)
523+
}
524+
}
525+
i += n
526+
}
527+
}
528+
dst = append(dst, '"')
529+
return string(dst)
530+
}
531+
504532
func sprintTxt(txt []string) string {
505533
var out []byte
506534
for i, s := range txt {
@@ -543,21 +571,24 @@ func appendTXTStringByte(s []byte, b byte) []byte {
543571
return append(s, '\\', b)
544572
}
545573
if b < ' ' || b > '~' {
546-
var buf [3]byte
547-
bufs := strconv.AppendInt(buf[:0], int64(b), 10)
548-
s = append(s, '\\')
549-
for i := 0; i < 3-len(bufs); i++ {
550-
s = append(s, '0')
551-
}
552-
for _, r := range bufs {
553-
s = append(s, r)
554-
}
555-
return s
556-
574+
return appendByte(s, b)
557575
}
558576
return append(s, b)
559577
}
560578

579+
func appendByte(s []byte, b byte) []byte {
580+
var buf [3]byte
581+
bufs := strconv.AppendInt(buf[:0], int64(b), 10)
582+
s = append(s, '\\')
583+
for i := 0; i < 3-len(bufs); i++ {
584+
s = append(s, '0')
585+
}
586+
for _, r := range bufs {
587+
s = append(s, r)
588+
}
589+
return s
590+
}
591+
561592
func nextByte(b []byte, offset int) (byte, int) {
562593
if offset >= len(b) {
563594
return 0, 0
@@ -1527,8 +1558,6 @@ func (rr *EUI64) copy() RR { return &EUI64{*rr.Hdr.copyHeader(), rr.Ad
15271558
func (rr *EUI64) String() string { return rr.Hdr.String() + euiToString(rr.Address, 64) }
15281559
func (rr *EUI64) len() int { return rr.Hdr.len() + 8 }
15291560

1530-
// Support in incomplete - just handle it as unknown record
1531-
/*
15321561
type CAA struct {
15331562
Hdr RR_Header
15341563
Flag uint8
@@ -1538,14 +1567,9 @@ type CAA struct {
15381567

15391568
func (rr *CAA) Header() *RR_Header { return &rr.Hdr }
15401569
func (rr *CAA) copy() RR { return &CAA{*rr.Hdr.copyHeader(), rr.Flag, rr.Tag, rr.Value} }
1541-
func (rr *CAA) len() int { return rr.Hdr.len() + 1 + len(rr.Tag) + 1 + len(rr.Value) }
1570+
func (rr *CAA) len() int { return rr.Hdr.len() + 1 + len(rr.Tag) + len(rr.Value)/2 }
1571+
func (rr *CAA) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Flag)) + " " + rr.Tag + " " + sprintCAAValue(rr.Value) }
15421572

1543-
func (rr *CAA) String() string {
1544-
s := rr.Hdr.String() + strconv.FormatInt(int64(rr.Flag), 10) + " " + rr.Tag
1545-
s += strconv.QuoteToASCII(rr.Value)
1546-
return s
1547-
}
1548-
*/
15491573

15501574
type UID struct {
15511575
Hdr RR_Header
@@ -1668,10 +1692,10 @@ func copyIP(ip net.IP) net.IP {
16681692

16691693
// Map of constructors for each RR type.
16701694
var typeToRR = map[uint16]func() RR{
1671-
TypeA: func() RR { return new(A) },
1672-
TypeAAAA: func() RR { return new(AAAA) },
1673-
TypeAFSDB: func() RR { return new(AFSDB) },
1674-
// TypeCAA: func() RR { return new(CAA) },
1695+
TypeA: func() RR { return new(A) },
1696+
TypeAAAA: func() RR { return new(AAAA) },
1697+
TypeAFSDB: func() RR { return new(AFSDB) },
1698+
TypeCAA: func() RR { return new(CAA) },
16751699
TypeCDS: func() RR { return new(CDS) },
16761700
TypeCERT: func() RR { return new(CERT) },
16771701
TypeCNAME: func() RR { return new(CNAME) },

vendor/src/github.com/miekg/dns/update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
func TestDynamicUpdateParsing(t *testing.T) {
99
prefix := "example.com. IN "
1010
for _, typ := range TypeToString {
11-
if typ == "CAA" || typ == "OPT" || typ == "AXFR" || typ == "IXFR" || typ == "ANY" || typ == "TKEY" ||
11+
if typ == "OPT" || typ == "AXFR" || typ == "IXFR" || typ == "ANY" || typ == "TKEY" ||
1212
typ == "TSIG" || typ == "ISDN" || typ == "UNSPEC" || typ == "NULL" || typ == "ATMA" {
1313
continue
1414
}

vendor/src/github.com/miekg/dns/zscan_rr.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,10 +2170,44 @@ func setIPSECKEY(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string)
21702170
return rr, nil, c1
21712171
}
21722172

2173+
func setCAA(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
2174+
rr := new(CAA)
2175+
rr.Hdr = h
2176+
l := <-c
2177+
if l.length == 0 {
2178+
return rr, nil, l.comment
2179+
}
2180+
i, err := strconv.Atoi(l.token)
2181+
if err != nil {
2182+
return nil, &ParseError{f, "bad CAA Flag", l}, ""
2183+
}
2184+
rr.Flag = uint8(i)
2185+
2186+
<-c // zBlank
2187+
l = <-c // zString
2188+
if l.value != zString {
2189+
return nil, &ParseError{f, "bad CAA Tag", l}, ""
2190+
}
2191+
rr.Tag = l.token
2192+
2193+
<-c // zBlank
2194+
s, e, c1 := endingToTxtSlice(c, "bad CAA Value", f)
2195+
if e != nil {
2196+
return nil, e, ""
2197+
}
2198+
if len(s) > 1 {
2199+
return nil, &ParseError{f, "bad CAA Value", l}, ""
2200+
} else {
2201+
rr.Value = s[0]
2202+
}
2203+
return rr, nil, c1
2204+
}
2205+
21732206
var typeToparserFunc = map[uint16]parserFunc{
21742207
TypeAAAA: parserFunc{setAAAA, false},
21752208
TypeAFSDB: parserFunc{setAFSDB, false},
21762209
TypeA: parserFunc{setA, false},
2210+
TypeCAA: parserFunc{setCAA, true},
21772211
TypeCDS: parserFunc{setCDS, true},
21782212
TypeCDNSKEY: parserFunc{setCDNSKEY, true},
21792213
TypeCERT: parserFunc{setCERT, true},

0 commit comments

Comments
 (0)