k3s/vendor/github.com/miekg/dns/scan_rr.go

1938 lines
43 KiB
Go
Raw Normal View History

2019-01-12 04:58:27 +00:00
package dns
import (
"encoding/base64"
"net"
"strconv"
"strings"
)
// Parse the rdata of each rrtype.
// All data from the channel c is either zString or zBlank.
// After the rdata there may come a zBlank and then a zNewline
// or immediately a zNewline. If this is not the case we flag
// an *ParseError: garbage after rdata.
2019-09-27 21:51:53 +00:00
func setRR(h RR_Header, c *zlexer, o, f string) (RR, *ParseError) {
var rr RR
if newFn, ok := TypeToRR[h.Rrtype]; ok && canParseAsRR(h.Rrtype) {
rr = newFn()
*rr.Header() = h
} else {
rr = &RFC3597{Hdr: h}
}
err := rr.parse(c, o, f)
if err != nil {
return nil, err
}
return rr, nil
}
// canParseAsRR returns true if the record type can be parsed as a
// concrete RR. It blacklists certain record types that must be parsed
// according to RFC 3597 because they lack a presentation format.
func canParseAsRR(rrtype uint16) bool {
switch rrtype {
case TypeANY, TypeNULL, TypeOPT, TypeTSIG:
return false
default:
return true
2019-01-12 04:58:27 +00:00
}
}
// A remainder of the rdata with embedded spaces, return the parsed string (sans the spaces)
// or an error
2019-09-27 21:51:53 +00:00
func endingToString(c *zlexer, errstr, f string) (string, *ParseError) {
var s string
l, _ := c.Next() // zString
2019-01-12 04:58:27 +00:00
for l.value != zNewline && l.value != zEOF {
if l.err {
2019-09-27 21:51:53 +00:00
return s, &ParseError{f, errstr, l}
2019-01-12 04:58:27 +00:00
}
switch l.value {
case zString:
s += l.token
case zBlank: // Ok
default:
2019-09-27 21:51:53 +00:00
return "", &ParseError{f, errstr, l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
return s, nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
// A remainder of the rdata with embedded spaces, split on unquoted whitespace
// and return the parsed string slice or an error
func endingToTxtSlice(c *zlexer, errstr, f string) ([]string, *ParseError) {
2019-01-12 04:58:27 +00:00
// Get the remaining data until we see a zNewline
2019-09-27 21:51:53 +00:00
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
if l.err {
2019-09-27 21:51:53 +00:00
return nil, &ParseError{f, errstr, l}
}
// Build the slice
s := make([]string, 0)
quote := false
empty := false
for l.value != zNewline && l.value != zEOF {
if l.err {
return nil, &ParseError{f, errstr, l}
}
switch l.value {
case zString:
empty = false
if len(l.token) > 255 {
// split up tokens that are larger than 255 into 255-chunks
sx := []string{}
p, i := 0, 255
for {
if i <= len(l.token) {
sx = append(sx, l.token[p:i])
} else {
sx = append(sx, l.token[p:])
break
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
p, i = p+255, i+255
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
s = append(s, sx...)
break
}
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
s = append(s, l.token)
case zBlank:
if quote {
// zBlank can only be seen in between txt parts.
return nil, &ParseError{f, errstr, l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
case zQuote:
if empty && quote {
s = append(s, "")
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
quote = !quote
empty = true
default:
return nil, &ParseError{f, errstr, l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
}
if quote {
return nil, &ParseError{f, errstr, l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
return s, nil
}
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
func (rr *A) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
2019-01-12 04:58:27 +00:00
rr.A = net.ParseIP(l.token)
if rr.A == nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad A A", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *AAAA) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
2019-01-12 04:58:27 +00:00
rr.AAAA = net.ParseIP(l.token)
if rr.AAAA == nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad AAAA AAAA", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *NS) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Ns = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad NS Ns", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Ns = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *PTR) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Ptr = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad PTR Ptr", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Ptr = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *NSAPPTR) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Ptr = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad NSAP-PTR Ptr", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Ptr = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *RP) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Mbox = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
mbox, mboxOk := toAbsoluteName(l.token, o)
if l.err || !mboxOk {
return &ParseError{f, "bad RP Mbox", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Mbox = mbox
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
rr.Txt = l.token
2019-09-27 21:51:53 +00:00
txt, txtOk := toAbsoluteName(l.token, o)
if l.err || !txtOk {
return &ParseError{f, "bad RP Txt", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Txt = txt
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
}
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
func (rr *MR) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Mr = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad MR Mr", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Mr = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *MB) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Mb = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad MB Mb", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Mb = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *MG) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Mg = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad MG Mg", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Mg = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *HINFO) parse(c *zlexer, o, f string) *ParseError {
chunks, e := endingToTxtSlice(c, "bad HINFO Fields", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
if ln := len(chunks); ln == 0 {
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
} else if ln == 1 {
// Can we split it?
if out := strings.Fields(chunks[0]); len(out) > 1 {
chunks = out
} else {
chunks = append(chunks, "")
}
}
rr.Cpu = chunks[0]
rr.Os = strings.Join(chunks[1:], " ")
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *MINFO) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Rmail = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rmail, rmailOk := toAbsoluteName(l.token, o)
if l.err || !rmailOk {
return &ParseError{f, "bad MINFO Rmail", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Rmail = rmail
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
rr.Email = l.token
2019-09-27 21:51:53 +00:00
email, emailOk := toAbsoluteName(l.token, o)
if l.err || !emailOk {
return &ParseError{f, "bad MINFO Email", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Email = email
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
}
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
func (rr *MF) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Mf = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad MF Mf", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Mf = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *MD) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Md = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad MD Md", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Md = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *MX) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad MX Pref", l}
2019-01-12 04:58:27 +00:00
}
rr.Preference = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Mx = l.token
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad MX Mx", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Mx = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *RT) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RT Preference", l}
2019-01-12 04:58:27 +00:00
}
rr.Preference = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Host = l.token
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad RT Host", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Host = name
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
}
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
func (rr *AFSDB) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad AFSDB Subtype", l}
2019-01-12 04:58:27 +00:00
}
rr.Subtype = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Hostname = l.token
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad AFSDB Hostname", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Hostname = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *X25) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
2019-01-12 04:58:27 +00:00
if l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad X25 PSDNAddress", l}
2019-01-12 04:58:27 +00:00
}
rr.PSDNAddress = l.token
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *KX) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad KX Pref", l}
2019-01-12 04:58:27 +00:00
}
rr.Preference = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Exchanger = l.token
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad KX Exchanger", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Exchanger = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *CNAME) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Target = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad CNAME Target", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Target = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *DNAME) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Target = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad DNAME Target", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Target = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *SOA) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.Ns = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
ns, nsOk := toAbsoluteName(l.token, o)
if l.err || !nsOk {
return &ParseError{f, "bad SOA Ns", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Ns = ns
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
rr.Mbox = l.token
2019-09-27 21:51:53 +00:00
mbox, mboxOk := toAbsoluteName(l.token, o)
if l.err || !mboxOk {
return &ParseError{f, "bad SOA Mbox", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Mbox = mbox
c.Next() // zBlank
2019-01-12 04:58:27 +00:00
var (
v uint32
ok bool
)
for i := 0; i < 5; i++ {
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad SOA zone parameter", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
if j, e := strconv.ParseUint(l.token, 10, 32); e != nil {
2019-01-12 04:58:27 +00:00
if i == 0 {
2019-09-27 21:51:53 +00:00
// Serial must be a number
return &ParseError{f, "bad SOA zone parameter", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
// We allow other fields to be unitful duration strings
if v, ok = stringToTTL(l.token); !ok {
return &ParseError{f, "bad SOA zone parameter", l}
2019-01-12 04:58:27 +00:00
}
} else {
v = uint32(j)
}
switch i {
case 0:
rr.Serial = v
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
2019-01-12 04:58:27 +00:00
case 1:
rr.Refresh = v
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
2019-01-12 04:58:27 +00:00
case 2:
rr.Retry = v
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
2019-01-12 04:58:27 +00:00
case 3:
rr.Expire = v
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
2019-01-12 04:58:27 +00:00
case 4:
rr.Minttl = v
}
}
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *SRV) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad SRV Priority", l}
2019-01-12 04:58:27 +00:00
}
rr.Priority = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
i, e = strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad SRV Weight", l}
2019-01-12 04:58:27 +00:00
}
rr.Weight = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
i, e = strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad SRV Port", l}
2019-01-12 04:58:27 +00:00
}
rr.Port = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Target = l.token
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad SRV Target", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Target = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *NAPTR) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Order", l}
2019-01-12 04:58:27 +00:00
}
rr.Order = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
i, e = strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Preference", l}
2019-01-12 04:58:27 +00:00
}
rr.Preference = uint16(i)
2019-09-27 21:51:53 +00:00
2019-01-12 04:58:27 +00:00
// Flags
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // _QUOTE
2019-01-12 04:58:27 +00:00
if l.value != zQuote {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Flags", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
l, _ = c.Next() // Either String or Quote
2019-01-12 04:58:27 +00:00
if l.value == zString {
rr.Flags = l.token
2019-09-27 21:51:53 +00:00
l, _ = c.Next() // _QUOTE
2019-01-12 04:58:27 +00:00
if l.value != zQuote {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Flags", l}
2019-01-12 04:58:27 +00:00
}
} else if l.value == zQuote {
rr.Flags = ""
} else {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Flags", l}
2019-01-12 04:58:27 +00:00
}
// Service
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // _QUOTE
2019-01-12 04:58:27 +00:00
if l.value != zQuote {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Service", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
l, _ = c.Next() // Either String or Quote
2019-01-12 04:58:27 +00:00
if l.value == zString {
rr.Service = l.token
2019-09-27 21:51:53 +00:00
l, _ = c.Next() // _QUOTE
2019-01-12 04:58:27 +00:00
if l.value != zQuote {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Service", l}
2019-01-12 04:58:27 +00:00
}
} else if l.value == zQuote {
rr.Service = ""
} else {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Service", l}
2019-01-12 04:58:27 +00:00
}
// Regexp
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // _QUOTE
2019-01-12 04:58:27 +00:00
if l.value != zQuote {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Regexp", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
l, _ = c.Next() // Either String or Quote
2019-01-12 04:58:27 +00:00
if l.value == zString {
rr.Regexp = l.token
2019-09-27 21:51:53 +00:00
l, _ = c.Next() // _QUOTE
2019-01-12 04:58:27 +00:00
if l.value != zQuote {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Regexp", l}
2019-01-12 04:58:27 +00:00
}
} else if l.value == zQuote {
rr.Regexp = ""
} else {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NAPTR Regexp", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
2019-01-12 04:58:27 +00:00
// After quote no space??
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Replacement = l.token
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad NAPTR Replacement", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Replacement = name
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *TALINK) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.PreviousName = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
previousName, previousNameOk := toAbsoluteName(l.token, o)
if l.err || !previousNameOk {
return &ParseError{f, "bad TALINK PreviousName", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.PreviousName = previousName
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
rr.NextName = l.token
2019-09-27 21:51:53 +00:00
nextName, nextNameOk := toAbsoluteName(l.token, o)
if l.err || !nextNameOk {
return &ParseError{f, "bad TALINK NextName", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.NextName = nextName
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *LOC) parse(c *zlexer, o, f string) *ParseError {
2019-01-12 04:58:27 +00:00
// Non zero defaults for LOC record, see RFC 1876, Section 3.
rr.HorizPre = 165 // 10000
rr.VertPre = 162 // 10
rr.Size = 18 // 1
ok := false
2019-09-27 21:51:53 +00:00
2019-01-12 04:58:27 +00:00
// North
2019-09-27 21:51:53 +00:00
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 32)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC Latitude", l}
2019-01-12 04:58:27 +00:00
}
rr.Latitude = 1000 * 60 * 60 * uint32(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
2019-01-12 04:58:27 +00:00
// Either number, 'N' or 'S'
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok {
goto East
}
2019-09-27 21:51:53 +00:00
i, e = strconv.ParseUint(l.token, 10, 32)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC Latitude minutes", l}
2019-01-12 04:58:27 +00:00
}
rr.Latitude += 1000 * 60 * uint32(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if i, e := strconv.ParseFloat(l.token, 32); e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC Latitude seconds", l}
2019-01-12 04:58:27 +00:00
} else {
rr.Latitude += uint32(1000 * i)
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
2019-01-12 04:58:27 +00:00
// Either number, 'N' or 'S'
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok {
goto East
}
// If still alive, flag an error
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC Latitude North/South", l}
2019-01-12 04:58:27 +00:00
East:
// East
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
if i, e := strconv.ParseUint(l.token, 10, 32); e != nil || l.err {
return &ParseError{f, "bad LOC Longitude", l}
2019-01-12 04:58:27 +00:00
} else {
rr.Longitude = 1000 * 60 * 60 * uint32(i)
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
2019-01-12 04:58:27 +00:00
// Either number, 'E' or 'W'
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok {
goto Altitude
}
2019-09-27 21:51:53 +00:00
if i, e := strconv.ParseUint(l.token, 10, 32); e != nil || l.err {
return &ParseError{f, "bad LOC Longitude minutes", l}
2019-01-12 04:58:27 +00:00
} else {
rr.Longitude += 1000 * 60 * uint32(i)
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if i, e := strconv.ParseFloat(l.token, 32); e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC Longitude seconds", l}
2019-01-12 04:58:27 +00:00
} else {
rr.Longitude += uint32(1000 * i)
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
2019-01-12 04:58:27 +00:00
// Either number, 'E' or 'W'
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok {
goto Altitude
}
// If still alive, flag an error
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC Longitude East/West", l}
2019-01-12 04:58:27 +00:00
Altitude:
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
if len(l.token) == 0 || l.err {
return &ParseError{f, "bad LOC Altitude", l}
2019-01-12 04:58:27 +00:00
}
if l.token[len(l.token)-1] == 'M' || l.token[len(l.token)-1] == 'm' {
l.token = l.token[0 : len(l.token)-1]
}
if i, e := strconv.ParseFloat(l.token, 32); e != nil {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC Altitude", l}
2019-01-12 04:58:27 +00:00
} else {
rr.Altitude = uint32(i*100.0 + 10000000.0 + 0.5)
}
// And now optionally the other values
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
count := 0
for l.value != zNewline && l.value != zEOF {
switch l.value {
case zString:
switch count {
case 0: // Size
e, m, ok := stringToCm(l.token)
if !ok {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC Size", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Size = e&0x0f | m<<4&0xf0
2019-01-12 04:58:27 +00:00
case 1: // HorizPre
e, m, ok := stringToCm(l.token)
if !ok {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC HorizPre", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.HorizPre = e&0x0f | m<<4&0xf0
2019-01-12 04:58:27 +00:00
case 2: // VertPre
e, m, ok := stringToCm(l.token)
if !ok {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC VertPre", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.VertPre = e&0x0f | m<<4&0xf0
2019-01-12 04:58:27 +00:00
}
count++
case zBlank:
// Ok
default:
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LOC Size, HorizPre or VertPre", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *HIP) parse(c *zlexer, o, f string) *ParseError {
2019-01-12 04:58:27 +00:00
// HitLength is not represented
2019-09-27 21:51:53 +00:00
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad HIP PublicKeyAlgorithm", l}
2019-01-12 04:58:27 +00:00
}
rr.PublicKeyAlgorithm = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
if len(l.token) == 0 || l.err {
return &ParseError{f, "bad HIP Hit", l}
2019-01-12 04:58:27 +00:00
}
rr.Hit = l.token // This can not contain spaces, see RFC 5205 Section 6.
rr.HitLength = uint8(len(rr.Hit)) / 2
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
if len(l.token) == 0 || l.err {
return &ParseError{f, "bad HIP PublicKey", l}
2019-01-12 04:58:27 +00:00
}
rr.PublicKey = l.token // This cannot contain spaces
rr.PublicKeyLength = uint16(base64.StdEncoding.DecodedLen(len(rr.PublicKey)))
// RendezvousServers (if any)
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
var xs []string
for l.value != zNewline && l.value != zEOF {
switch l.value {
case zString:
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad HIP RendezvousServers", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
xs = append(xs, name)
2019-01-12 04:58:27 +00:00
case zBlank:
// Ok
default:
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad HIP RendezvousServers", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
2019-01-12 04:58:27 +00:00
rr.RendezvousServers = xs
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *CERT) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
2019-01-12 04:58:27 +00:00
if v, ok := StringToCertType[l.token]; ok {
rr.Type = v
2019-09-27 21:51:53 +00:00
} else if i, e := strconv.ParseUint(l.token, 10, 16); e != nil {
return &ParseError{f, "bad CERT Type", l}
2019-01-12 04:58:27 +00:00
} else {
rr.Type = uint16(i)
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad CERT KeyTag", l}
2019-01-12 04:58:27 +00:00
}
rr.KeyTag = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
if v, ok := StringToAlgorithm[l.token]; ok {
rr.Algorithm = v
2019-09-27 21:51:53 +00:00
} else if i, e := strconv.ParseUint(l.token, 10, 8); e != nil {
return &ParseError{f, "bad CERT Algorithm", l}
2019-01-12 04:58:27 +00:00
} else {
rr.Algorithm = uint8(i)
}
2019-09-27 21:51:53 +00:00
s, e1 := endingToString(c, "bad CERT Certificate", f)
2019-01-12 04:58:27 +00:00
if e1 != nil {
2019-09-27 21:51:53 +00:00
return e1
2019-01-12 04:58:27 +00:00
}
rr.Certificate = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *OPENPGPKEY) parse(c *zlexer, o, f string) *ParseError {
s, e := endingToString(c, "bad OPENPGPKEY PublicKey", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
rr.PublicKey = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *CSYNC) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
}
j, e := strconv.ParseUint(l.token, 10, 32)
if e != nil {
// Serial must be a number
return &ParseError{f, "bad CSYNC serial", l}
}
rr.Serial = uint32(j)
c.Next() // zBlank
l, _ = c.Next()
j, e = strconv.ParseUint(l.token, 10, 16)
if e != nil {
// Serial must be a number
return &ParseError{f, "bad CSYNC flags", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Flags = uint16(j)
rr.TypeBitMap = make([]uint16, 0)
var (
k uint16
ok bool
)
l, _ = c.Next()
for l.value != zNewline && l.value != zEOF {
switch l.value {
case zBlank:
// Ok
case zString:
tokenUpper := strings.ToUpper(l.token)
if k, ok = StringToType[tokenUpper]; !ok {
if k, ok = typeToInt(l.token); !ok {
return &ParseError{f, "bad CSYNC TypeBitMap", l}
}
}
rr.TypeBitMap = append(rr.TypeBitMap, k)
default:
return &ParseError{f, "bad CSYNC TypeBitMap", l}
}
l, _ = c.Next()
}
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *SIG) parse(c *zlexer, o, f string) *ParseError {
return rr.RRSIG.parse(c, o, f)
}
func (rr *RRSIG) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
tokenUpper := strings.ToUpper(l.token)
if t, ok := StringToType[tokenUpper]; !ok {
if strings.HasPrefix(tokenUpper, "TYPE") {
t, ok = typeToInt(l.token)
2019-01-12 04:58:27 +00:00
if !ok {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RRSIG Typecovered", l}
2019-01-12 04:58:27 +00:00
}
rr.TypeCovered = t
} else {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RRSIG Typecovered", l}
2019-01-12 04:58:27 +00:00
}
} else {
rr.TypeCovered = t
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, err := strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if err != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RRSIG Algorithm", l}
2019-01-12 04:58:27 +00:00
}
rr.Algorithm = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, err = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if err != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RRSIG Labels", l}
2019-01-12 04:58:27 +00:00
}
rr.Labels = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, err = strconv.ParseUint(l.token, 10, 32)
2019-01-12 04:58:27 +00:00
if err != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RRSIG OrigTtl", l}
2019-01-12 04:58:27 +00:00
}
rr.OrigTtl = uint32(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if i, err := StringToTime(l.token); err != nil {
// Try to see if all numeric and use it as epoch
if i, err := strconv.ParseInt(l.token, 10, 64); err == nil {
// TODO(miek): error out on > MAX_UINT32, same below
rr.Expiration = uint32(i)
} else {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RRSIG Expiration", l}
2019-01-12 04:58:27 +00:00
}
} else {
rr.Expiration = i
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if i, err := StringToTime(l.token); err != nil {
if i, err := strconv.ParseInt(l.token, 10, 64); err == nil {
rr.Inception = uint32(i)
} else {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RRSIG Inception", l}
2019-01-12 04:58:27 +00:00
}
} else {
rr.Inception = i
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, err = strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if err != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RRSIG KeyTag", l}
2019-01-12 04:58:27 +00:00
}
rr.KeyTag = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
rr.SignerName = l.token
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad RRSIG SignerName", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.SignerName = name
s, e := endingToString(c, "bad RRSIG Signature", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
rr.Signature = s
2019-09-27 21:51:53 +00:00
return nil
}
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
func (rr *NSEC) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
rr.NextDomain = l.token
2019-09-27 21:51:53 +00:00
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad NSEC NextDomain", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.NextDomain = name
2019-01-12 04:58:27 +00:00
rr.TypeBitMap = make([]uint16, 0)
var (
k uint16
ok bool
)
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
for l.value != zNewline && l.value != zEOF {
switch l.value {
case zBlank:
// Ok
case zString:
2019-09-27 21:51:53 +00:00
tokenUpper := strings.ToUpper(l.token)
if k, ok = StringToType[tokenUpper]; !ok {
if k, ok = typeToInt(l.token); !ok {
return &ParseError{f, "bad NSEC TypeBitMap", l}
2019-01-12 04:58:27 +00:00
}
}
rr.TypeBitMap = append(rr.TypeBitMap, k)
default:
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC TypeBitMap", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *NSEC3) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC3 Hash", l}
2019-01-12 04:58:27 +00:00
}
rr.Hash = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC3 Flags", l}
2019-01-12 04:58:27 +00:00
}
rr.Flags = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC3 Iterations", l}
2019-01-12 04:58:27 +00:00
}
rr.Iterations = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next()
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if len(l.token) == 0 || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC3 Salt", l}
}
if l.token != "-" {
rr.SaltLength = uint8(len(l.token)) / 2
rr.Salt = l.token
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
c.Next()
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
if len(l.token) == 0 || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC3 NextDomain", l}
2019-01-12 04:58:27 +00:00
}
rr.HashLength = 20 // Fix for NSEC3 (sha1 160 bits)
rr.NextDomain = l.token
rr.TypeBitMap = make([]uint16, 0)
var (
k uint16
ok bool
)
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
for l.value != zNewline && l.value != zEOF {
switch l.value {
case zBlank:
// Ok
case zString:
2019-09-27 21:51:53 +00:00
tokenUpper := strings.ToUpper(l.token)
if k, ok = StringToType[tokenUpper]; !ok {
if k, ok = typeToInt(l.token); !ok {
return &ParseError{f, "bad NSEC3 TypeBitMap", l}
2019-01-12 04:58:27 +00:00
}
}
rr.TypeBitMap = append(rr.TypeBitMap, k)
default:
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC3 TypeBitMap", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *NSEC3PARAM) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC3PARAM Hash", l}
2019-01-12 04:58:27 +00:00
}
rr.Hash = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC3PARAM Flags", l}
2019-01-12 04:58:27 +00:00
}
rr.Flags = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NSEC3PARAM Iterations", l}
2019-01-12 04:58:27 +00:00
}
rr.Iterations = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next()
l, _ = c.Next()
if l.token != "-" {
rr.SaltLength = uint8(len(l.token))
rr.Salt = l.token
}
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *EUI48) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
if len(l.token) != 17 || l.err {
return &ParseError{f, "bad EUI48 Address", l}
2019-01-12 04:58:27 +00:00
}
addr := make([]byte, 12)
dash := 0
for i := 0; i < 10; i += 2 {
addr[i] = l.token[i+dash]
addr[i+1] = l.token[i+1+dash]
dash++
if l.token[i+1+dash] != '-' {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad EUI48 Address", l}
2019-01-12 04:58:27 +00:00
}
}
addr[10] = l.token[15]
addr[11] = l.token[16]
i, e := strconv.ParseUint(string(addr), 16, 48)
if e != nil {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad EUI48 Address", l}
2019-01-12 04:58:27 +00:00
}
rr.Address = i
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *EUI64) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
if len(l.token) != 23 || l.err {
return &ParseError{f, "bad EUI64 Address", l}
2019-01-12 04:58:27 +00:00
}
addr := make([]byte, 16)
dash := 0
for i := 0; i < 14; i += 2 {
addr[i] = l.token[i+dash]
addr[i+1] = l.token[i+1+dash]
dash++
if l.token[i+1+dash] != '-' {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad EUI64 Address", l}
2019-01-12 04:58:27 +00:00
}
}
addr[14] = l.token[21]
addr[15] = l.token[22]
i, e := strconv.ParseUint(string(addr), 16, 64)
if e != nil {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad EUI68 Address", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Address = i
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *SSHFP) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad SSHFP Algorithm", l}
2019-01-12 04:58:27 +00:00
}
rr.Algorithm = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad SSHFP Type", l}
2019-01-12 04:58:27 +00:00
}
rr.Type = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
s, e1 := endingToString(c, "bad SSHFP Fingerprint", f)
2019-01-12 04:58:27 +00:00
if e1 != nil {
2019-09-27 21:51:53 +00:00
return e1
2019-01-12 04:58:27 +00:00
}
rr.FingerPrint = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *DNSKEY) parseDNSKEY(c *zlexer, o, f, typ string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad " + typ + " Flags", l}
2019-01-12 04:58:27 +00:00
}
rr.Flags = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad " + typ + " Protocol", l}
2019-01-12 04:58:27 +00:00
}
rr.Protocol = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad " + typ + " Algorithm", l}
2019-01-12 04:58:27 +00:00
}
rr.Algorithm = uint8(i)
2019-09-27 21:51:53 +00:00
s, e1 := endingToString(c, "bad "+typ+" PublicKey", f)
2019-01-12 04:58:27 +00:00
if e1 != nil {
2019-09-27 21:51:53 +00:00
return e1
2019-01-12 04:58:27 +00:00
}
rr.PublicKey = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *DNSKEY) parse(c *zlexer, o, f string) *ParseError {
return rr.parseDNSKEY(c, o, f, "DNSKEY")
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *KEY) parse(c *zlexer, o, f string) *ParseError {
return rr.parseDNSKEY(c, o, f, "KEY")
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *CDNSKEY) parse(c *zlexer, o, f string) *ParseError {
return rr.parseDNSKEY(c, o, f, "CDNSKEY")
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *RKEY) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RKEY Flags", l}
2019-01-12 04:58:27 +00:00
}
rr.Flags = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RKEY Protocol", l}
2019-01-12 04:58:27 +00:00
}
rr.Protocol = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RKEY Algorithm", l}
2019-01-12 04:58:27 +00:00
}
rr.Algorithm = uint8(i)
2019-09-27 21:51:53 +00:00
s, e1 := endingToString(c, "bad RKEY PublicKey", f)
2019-01-12 04:58:27 +00:00
if e1 != nil {
2019-09-27 21:51:53 +00:00
return e1
2019-01-12 04:58:27 +00:00
}
rr.PublicKey = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *EID) parse(c *zlexer, o, f string) *ParseError {
s, e := endingToString(c, "bad EID Endpoint", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
rr.Endpoint = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *NIMLOC) parse(c *zlexer, o, f string) *ParseError {
s, e := endingToString(c, "bad NIMLOC Locator", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
rr.Locator = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *GPOS) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
2019-01-12 04:58:27 +00:00
_, e := strconv.ParseFloat(l.token, 64)
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad GPOS Longitude", l}
2019-01-12 04:58:27 +00:00
}
rr.Longitude = l.token
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
_, e = strconv.ParseFloat(l.token, 64)
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad GPOS Latitude", l}
2019-01-12 04:58:27 +00:00
}
rr.Latitude = l.token
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
_, e = strconv.ParseFloat(l.token, 64)
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad GPOS Altitude", l}
2019-01-12 04:58:27 +00:00
}
rr.Altitude = l.token
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *DS) parseDS(c *zlexer, o, f, typ string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad " + typ + " KeyTag", l}
2019-01-12 04:58:27 +00:00
}
rr.KeyTag = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
if i, e = strconv.ParseUint(l.token, 10, 8); e != nil {
tokenUpper := strings.ToUpper(l.token)
i, ok := StringToAlgorithm[tokenUpper]
2019-01-12 04:58:27 +00:00
if !ok || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad " + typ + " Algorithm", l}
2019-01-12 04:58:27 +00:00
}
rr.Algorithm = i
} else {
rr.Algorithm = uint8(i)
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad " + typ + " DigestType", l}
2019-01-12 04:58:27 +00:00
}
rr.DigestType = uint8(i)
2019-09-27 21:51:53 +00:00
s, e1 := endingToString(c, "bad "+typ+" Digest", f)
2019-01-12 04:58:27 +00:00
if e1 != nil {
2019-09-27 21:51:53 +00:00
return e1
2019-01-12 04:58:27 +00:00
}
rr.Digest = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *DS) parse(c *zlexer, o, f string) *ParseError {
return rr.parseDS(c, o, f, "DS")
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *DLV) parse(c *zlexer, o, f string) *ParseError {
return rr.parseDS(c, o, f, "DLV")
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *CDS) parse(c *zlexer, o, f string) *ParseError {
return rr.parseDS(c, o, f, "CDS")
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *TA) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad TA KeyTag", l}
2019-01-12 04:58:27 +00:00
}
rr.KeyTag = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
if i, e := strconv.ParseUint(l.token, 10, 8); e != nil {
tokenUpper := strings.ToUpper(l.token)
i, ok := StringToAlgorithm[tokenUpper]
2019-01-12 04:58:27 +00:00
if !ok || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad TA Algorithm", l}
2019-01-12 04:58:27 +00:00
}
rr.Algorithm = i
} else {
rr.Algorithm = uint8(i)
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad TA DigestType", l}
2019-01-12 04:58:27 +00:00
}
rr.DigestType = uint8(i)
2019-09-27 21:51:53 +00:00
s, err := endingToString(c, "bad TA Digest", f)
if err != nil {
return err
2019-01-12 04:58:27 +00:00
}
rr.Digest = s
2019-09-27 21:51:53 +00:00
return nil
}
func (rr *TLSA) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
}
i, e := strconv.ParseUint(l.token, 10, 8)
if e != nil || l.err {
return &ParseError{f, "bad TLSA Usage", l}
}
rr.Usage = uint8(i)
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 8)
if e != nil || l.err {
return &ParseError{f, "bad TLSA Selector", l}
}
rr.Selector = uint8(i)
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 8)
if e != nil || l.err {
return &ParseError{f, "bad TLSA MatchingType", l}
}
rr.MatchingType = uint8(i)
// So this needs be e2 (i.e. different than e), because...??t
s, e2 := endingToString(c, "bad TLSA Certificate", f)
if e2 != nil {
return e2
}
rr.Certificate = s
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *SMIMEA) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad SMIMEA Usage", l}
2019-01-12 04:58:27 +00:00
}
rr.Usage = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad SMIMEA Selector", l}
2019-01-12 04:58:27 +00:00
}
rr.Selector = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad SMIMEA MatchingType", l}
2019-01-12 04:58:27 +00:00
}
rr.MatchingType = uint8(i)
// So this needs be e2 (i.e. different than e), because...??t
2019-09-27 21:51:53 +00:00
s, e2 := endingToString(c, "bad SMIMEA Certificate", f)
2019-01-12 04:58:27 +00:00
if e2 != nil {
2019-09-27 21:51:53 +00:00
return e2
2019-01-12 04:58:27 +00:00
}
rr.Certificate = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *RFC3597) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
2019-01-12 04:58:27 +00:00
if l.token != "\\#" {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RFC3597 Rdata", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
2019-01-12 04:58:27 +00:00
rdlength, e := strconv.Atoi(l.token)
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RFC3597 Rdata ", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
s, e1 := endingToString(c, "bad RFC3597 Rdata", f)
2019-01-12 04:58:27 +00:00
if e1 != nil {
2019-09-27 21:51:53 +00:00
return e1
2019-01-12 04:58:27 +00:00
}
if rdlength*2 != len(s) {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad RFC3597 Rdata", l}
2019-01-12 04:58:27 +00:00
}
rr.Rdata = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *SPF) parse(c *zlexer, o, f string) *ParseError {
s, e := endingToTxtSlice(c, "bad SPF Txt", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
rr.Txt = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *AVC) parse(c *zlexer, o, f string) *ParseError {
s, e := endingToTxtSlice(c, "bad AVC Txt", f)
if e != nil {
return e
}
rr.Txt = s
return nil
}
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
func (rr *TXT) parse(c *zlexer, o, f string) *ParseError {
2019-01-12 04:58:27 +00:00
// no zBlank reading here, because all this rdata is TXT
2019-09-27 21:51:53 +00:00
s, e := endingToTxtSlice(c, "bad TXT Txt", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
rr.Txt = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
// identical to setTXT
2019-09-27 21:51:53 +00:00
func (rr *NINFO) parse(c *zlexer, o, f string) *ParseError {
s, e := endingToTxtSlice(c, "bad NINFO ZSData", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
rr.ZSData = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *URI) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad URI Priority", l}
2019-01-12 04:58:27 +00:00
}
rr.Priority = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next()
i, e = strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad URI Weight", l}
2019-01-12 04:58:27 +00:00
}
rr.Weight = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
s, err := endingToTxtSlice(c, "bad URI Target", f)
2019-01-12 04:58:27 +00:00
if err != nil {
2019-09-27 21:51:53 +00:00
return err
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
if len(s) != 1 {
return &ParseError{f, "bad URI Target", l}
2019-01-12 04:58:27 +00:00
}
rr.Target = s[0]
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *DHCID) parse(c *zlexer, o, f string) *ParseError {
2019-01-12 04:58:27 +00:00
// awesome record to parse!
2019-09-27 21:51:53 +00:00
s, e := endingToString(c, "bad DHCID Digest", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
rr.Digest = s
2019-09-27 21:51:53 +00:00
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *NID) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad NID Preference", l}
2019-01-12 04:58:27 +00:00
}
rr.Preference = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
u, err := stringToNodeID(l)
if err != nil || l.err {
2019-09-27 21:51:53 +00:00
return err
2019-01-12 04:58:27 +00:00
}
rr.NodeID = u
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *L32) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad L32 Preference", l}
2019-01-12 04:58:27 +00:00
}
rr.Preference = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Locator32 = net.ParseIP(l.token)
if rr.Locator32 == nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad L32 Locator", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *LP) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad LP Preference", l}
2019-01-12 04:58:27 +00:00
}
rr.Preference = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Fqdn = l.token
2019-09-27 21:51:53 +00:00
name, nameOk := toAbsoluteName(l.token, o)
if l.err || !nameOk {
return &ParseError{f, "bad LP Fqdn", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Fqdn = name
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
}
2019-01-12 04:58:27 +00:00
2019-09-27 21:51:53 +00:00
func (rr *L64) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad L64 Preference", l}
2019-01-12 04:58:27 +00:00
}
rr.Preference = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
u, err := stringToNodeID(l)
if err != nil || l.err {
2019-09-27 21:51:53 +00:00
return err
2019-01-12 04:58:27 +00:00
}
rr.Locator64 = u
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *UID) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 32)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad UID Uid", l}
2019-01-12 04:58:27 +00:00
}
rr.Uid = uint32(i)
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *GID) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 32)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad GID Gid", l}
2019-01-12 04:58:27 +00:00
}
rr.Gid = uint32(i)
2019-09-27 21:51:53 +00:00
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *UINFO) parse(c *zlexer, o, f string) *ParseError {
s, e := endingToTxtSlice(c, "bad UINFO Uinfo", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
}
if ln := len(s); ln == 0 {
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Uinfo = s[0] // silently discard anything after the first character-string
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *PX) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, e := strconv.ParseUint(l.token, 10, 16)
2019-01-12 04:58:27 +00:00
if e != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad PX Preference", l}
2019-01-12 04:58:27 +00:00
}
rr.Preference = uint16(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Map822 = l.token
2019-09-27 21:51:53 +00:00
map822, map822Ok := toAbsoluteName(l.token, o)
if l.err || !map822Ok {
return &ParseError{f, "bad PX Map822", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Map822 = map822
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
rr.Mapx400 = l.token
2019-09-27 21:51:53 +00:00
mapx400, mapx400Ok := toAbsoluteName(l.token, o)
if l.err || !mapx400Ok {
return &ParseError{f, "bad PX Mapx400", l}
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
rr.Mapx400 = mapx400
return slurpRemainder(c, f)
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
func (rr *CAA) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
if len(l.token) == 0 { // dynamic update rr.
return nil
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
i, err := strconv.ParseUint(l.token, 10, 8)
2019-01-12 04:58:27 +00:00
if err != nil || l.err {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad CAA Flag", l}
2019-01-12 04:58:27 +00:00
}
rr.Flag = uint8(i)
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
l, _ = c.Next() // zString
2019-01-12 04:58:27 +00:00
if l.value != zString {
2019-09-27 21:51:53 +00:00
return &ParseError{f, "bad CAA Tag", l}
2019-01-12 04:58:27 +00:00
}
rr.Tag = l.token
2019-09-27 21:51:53 +00:00
c.Next() // zBlank
s, e := endingToTxtSlice(c, "bad CAA Value", f)
2019-01-12 04:58:27 +00:00
if e != nil {
2019-09-27 21:51:53 +00:00
return e
2019-01-12 04:58:27 +00:00
}
2019-09-27 21:51:53 +00:00
if len(s) != 1 {
return &ParseError{f, "bad CAA Value", l}
2019-01-12 04:58:27 +00:00
}
rr.Value = s[0]
2019-09-27 21:51:53 +00:00
return nil
}
func (rr *TKEY) parse(c *zlexer, o, f string) *ParseError {
l, _ := c.Next()
// Algorithm
if l.value != zString {
return &ParseError{f, "bad TKEY algorithm", l}
}
rr.Algorithm = l.token
c.Next() // zBlank
// Get the key length and key values
l, _ = c.Next()
i, err := strconv.ParseUint(l.token, 10, 8)
if err != nil || l.err {
return &ParseError{f, "bad TKEY key length", l}
}
rr.KeySize = uint16(i)
c.Next() // zBlank
l, _ = c.Next()
if l.value != zString {
return &ParseError{f, "bad TKEY key", l}
}
rr.Key = l.token
c.Next() // zBlank
// Get the otherdata length and string data
l, _ = c.Next()
i, err = strconv.ParseUint(l.token, 10, 8)
if err != nil || l.err {
return &ParseError{f, "bad TKEY otherdata length", l}
}
rr.OtherLen = uint16(i)
c.Next() // zBlank
l, _ = c.Next()
if l.value != zString {
return &ParseError{f, "bad TKEY otherday", l}
}
rr.OtherData = l.token
return nil
2019-01-12 04:58:27 +00:00
}