2018-05-01 23:45:06 +00:00
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
2024-10-17 20:09:39 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2018-05-01 23:45:06 +00:00
|
|
|
"net"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// A remainder of the rdata with embedded spaces, return the parsed string (sans the spaces)
|
|
|
|
// or an error
|
2020-02-21 15:53:11 +00:00
|
|
|
func endingToString(c *zlexer, errstr string) (string, *ParseError) {
|
2024-10-17 20:09:39 +00:00
|
|
|
var s strings.Builder
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
for l.value != zNewline && l.value != zEOF {
|
|
|
|
if l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return s.String(), &ParseError{err: errstr, lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
switch l.value {
|
|
|
|
case zString:
|
2024-10-17 20:09:39 +00:00
|
|
|
s.WriteString(l.token)
|
2018-05-01 23:45:06 +00:00
|
|
|
case zBlank: // Ok
|
|
|
|
default:
|
2024-10-17 20:09:39 +00:00
|
|
|
return "", &ParseError{err: errstr, lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
|
2024-10-17 20:09:39 +00:00
|
|
|
return s.String(), nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A remainder of the rdata with embedded spaces, split on unquoted whitespace
|
|
|
|
// and return the parsed string slice or an error
|
2020-02-21 15:53:11 +00:00
|
|
|
func endingToTxtSlice(c *zlexer, errstr string) ([]string, *ParseError) {
|
2018-05-01 23:45:06 +00:00
|
|
|
// Get the remaining data until we see a zNewline
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return nil, &ParseError{err: errstr, lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build the slice
|
|
|
|
s := make([]string, 0)
|
|
|
|
quote := false
|
|
|
|
empty := false
|
|
|
|
for l.value != zNewline && l.value != zEOF {
|
|
|
|
if l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return nil, &ParseError{err: errstr, lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
|
}
|
|
|
|
p, i = p+255, i+255
|
|
|
|
}
|
|
|
|
s = append(s, sx...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
s = append(s, l.token)
|
|
|
|
case zBlank:
|
|
|
|
if quote {
|
|
|
|
// zBlank can only be seen in between txt parts.
|
2024-10-17 20:09:39 +00:00
|
|
|
return nil, &ParseError{err: errstr, lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
case zQuote:
|
|
|
|
if empty && quote {
|
|
|
|
s = append(s, "")
|
|
|
|
}
|
|
|
|
quote = !quote
|
|
|
|
empty = true
|
|
|
|
default:
|
2024-10-17 20:09:39 +00:00
|
|
|
return nil, &ParseError{err: errstr, lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
|
2018-05-01 23:45:06 +00:00
|
|
|
if quote {
|
2024-10-17 20:09:39 +00:00
|
|
|
return nil, &ParseError{err: errstr, lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
return s, nil
|
|
|
|
}
|
2018-05-01 23:45:06 +00:00
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *A) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.A = net.ParseIP(l.token)
|
2019-04-17 17:15:55 +00:00
|
|
|
// IPv4 addresses cannot include ":".
|
|
|
|
// We do this rather than use net.IP's To4() because
|
|
|
|
// To4() treats IPv4-mapped IPv6 addresses as being
|
|
|
|
// IPv4.
|
|
|
|
isIPv4 := !strings.Contains(l.token, ":")
|
|
|
|
if rr.A == nil || !isIPv4 || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad A A", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *AAAA) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.AAAA = net.ParseIP(l.token)
|
2019-04-17 17:15:55 +00:00
|
|
|
// IPv6 addresses must include ":", and IPv4
|
|
|
|
// addresses cannot include ":".
|
|
|
|
isIPv6 := strings.Contains(l.token, ":")
|
|
|
|
if rr.AAAA == nil || !isIPv6 || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad AAAA AAAA", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *NS) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NS Ns", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Ns = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *PTR) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad PTR Ptr", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Ptr = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *NSAPPTR) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSAP-PTR Ptr", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Ptr = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *RP) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
mbox, mboxOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !mboxOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RP Mbox", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Mbox = mbox
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Txt = l.token
|
|
|
|
|
|
|
|
txt, txtOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !txtOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RP Txt", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Txt = txt
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *MR) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad MR Mr", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Mr = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *MB) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad MB Mb", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Mb = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *MG) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad MG Mg", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Mg = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *HINFO) parse(c *zlexer, o string) *ParseError {
|
|
|
|
chunks, e := endingToTxtSlice(c, "bad HINFO Fields")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ln := len(chunks); ln == 0 {
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +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:], " ")
|
2024-10-17 20:09:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// according to RFC 1183 the parsing is identical to HINFO, so just use that code.
|
|
|
|
func (rr *ISDN) parse(c *zlexer, o string) *ParseError {
|
|
|
|
chunks, e := endingToTxtSlice(c, "bad ISDN Fields")
|
|
|
|
if e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
if ln := len(chunks); ln == 0 {
|
|
|
|
return nil
|
|
|
|
} else if ln == 1 {
|
|
|
|
// Can we split it?
|
|
|
|
if out := strings.Fields(chunks[0]); len(out) > 1 {
|
|
|
|
chunks = out
|
|
|
|
} else {
|
|
|
|
chunks = append(chunks, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rr.Address = chunks[0]
|
|
|
|
rr.SubAddress = strings.Join(chunks[1:], " ")
|
2018-05-01 23:45:06 +00:00
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *MINFO) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
rmail, rmailOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !rmailOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad MINFO Rmail", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Rmail = rmail
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Email = l.token
|
|
|
|
|
|
|
|
email, emailOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !emailOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad MINFO Email", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Email = email
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *MF) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad MF Mf", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Mf = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *MD) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad MD Md", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Md = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *MX) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad MX Pref", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Preference = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Mx = l.token
|
|
|
|
|
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad MX Mx", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Mx = name
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *RT) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RT Preference", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Preference = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Host = l.token
|
|
|
|
|
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RT Host", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Host = name
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *AFSDB) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad AFSDB Subtype", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Subtype = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Hostname = l.token
|
|
|
|
|
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad AFSDB Hostname", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Hostname = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *X25) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad X25 PSDNAddress", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.PSDNAddress = l.token
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *KX) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad KX Pref", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Preference = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Exchanger = l.token
|
|
|
|
|
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad KX Exchanger", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Exchanger = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *CNAME) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CNAME Target", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Target = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *DNAME) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad DNAME Target", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Target = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *SOA) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
ns, nsOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nsOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SOA Ns", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Ns = ns
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Mbox = l.token
|
|
|
|
|
|
|
|
mbox, mboxOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !mboxOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SOA Mbox", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Mbox = mbox
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
v uint32
|
|
|
|
ok bool
|
|
|
|
)
|
|
|
|
for i := 0; i < 5; i++ {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SOA zone parameter", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2020-09-09 18:09:42 +00:00
|
|
|
if j, err := strconv.ParseUint(l.token, 10, 32); err != nil {
|
2018-05-01 23:45:06 +00:00
|
|
|
if i == 0 {
|
|
|
|
// Serial must be a number
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SOA zone parameter", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
// We allow other fields to be unitful duration strings
|
|
|
|
if v, ok = stringToTTL(l.token); !ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SOA zone parameter", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
v = uint32(j)
|
|
|
|
}
|
|
|
|
switch i {
|
|
|
|
case 0:
|
|
|
|
rr.Serial = v
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
case 1:
|
|
|
|
rr.Refresh = v
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
case 2:
|
|
|
|
rr.Retry = v
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
case 3:
|
|
|
|
rr.Expire = v
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
case 4:
|
|
|
|
rr.Minttl = v
|
|
|
|
}
|
|
|
|
}
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *SRV) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SRV Priority", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Priority = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SRV Weight", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Weight = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e2 := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e2 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SRV Port", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Port = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Target = l.token
|
|
|
|
|
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SRV Target", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Target = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *NAPTR) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Order", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Order = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Preference", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Preference = uint16(i)
|
|
|
|
|
|
|
|
// Flags
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // _QUOTE
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value != zQuote {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Flags", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next() // Either String or Quote
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value == zString {
|
|
|
|
rr.Flags = l.token
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next() // _QUOTE
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value != zQuote {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Flags", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
} else if l.value == zQuote {
|
|
|
|
rr.Flags = ""
|
|
|
|
} else {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Flags", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Service
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // _QUOTE
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value != zQuote {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Service", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next() // Either String or Quote
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value == zString {
|
|
|
|
rr.Service = l.token
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next() // _QUOTE
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value != zQuote {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Service", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
} else if l.value == zQuote {
|
|
|
|
rr.Service = ""
|
|
|
|
} else {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Service", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Regexp
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // _QUOTE
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value != zQuote {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Regexp", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next() // Either String or Quote
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value == zString {
|
|
|
|
rr.Regexp = l.token
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next() // _QUOTE
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value != zQuote {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Regexp", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
} else if l.value == zQuote {
|
|
|
|
rr.Regexp = ""
|
|
|
|
} else {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Regexp", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// After quote no space??
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Replacement = l.token
|
|
|
|
|
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NAPTR Replacement", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Replacement = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *TALINK) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
previousName, previousNameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !previousNameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TALINK PreviousName", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.PreviousName = previousName
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.NextName = l.token
|
|
|
|
|
|
|
|
nextName, nextNameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nextNameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TALINK NextName", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.NextName = nextName
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *LOC) parse(c *zlexer, o string) *ParseError {
|
2018-05-01 23:45:06 +00:00
|
|
|
// Non zero defaults for LOC record, see RFC 1876, Section 3.
|
2020-09-09 18:09:42 +00:00
|
|
|
rr.Size = 0x12 // 1e2 cm (1m)
|
|
|
|
rr.HorizPre = 0x16 // 1e6 cm (10000m)
|
|
|
|
rr.VertPre = 0x13 // 1e3 cm (10m)
|
2018-05-01 23:45:06 +00:00
|
|
|
ok := false
|
|
|
|
|
|
|
|
// North
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 32)
|
2022-01-25 13:15:24 +00:00
|
|
|
if e != nil || l.err || i > 90 {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Latitude", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Latitude = 1000 * 60 * 60 * uint32(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
// Either number, 'N' or 'S'
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok {
|
|
|
|
goto East
|
|
|
|
}
|
2022-01-25 13:15:24 +00:00
|
|
|
if i, err := strconv.ParseUint(l.token, 10, 32); err != nil || l.err || i > 59 {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Latitude minutes", lex: l}
|
2020-09-09 18:09:42 +00:00
|
|
|
} else {
|
|
|
|
rr.Latitude += 1000 * 60 * uint32(i)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2022-01-25 13:15:24 +00:00
|
|
|
if i, err := strconv.ParseFloat(l.token, 64); err != nil || l.err || i < 0 || i >= 60 {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Latitude seconds", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
} else {
|
|
|
|
rr.Latitude += uint32(1000 * i)
|
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
// Either number, 'N' or 'S'
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok {
|
|
|
|
goto East
|
|
|
|
}
|
|
|
|
// If still alive, flag an error
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Latitude North/South", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
East:
|
|
|
|
// East
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2022-01-25 13:15:24 +00:00
|
|
|
if i, err := strconv.ParseUint(l.token, 10, 32); err != nil || l.err || i > 180 {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Longitude", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
} else {
|
|
|
|
rr.Longitude = 1000 * 60 * 60 * uint32(i)
|
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
// Either number, 'E' or 'W'
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok {
|
|
|
|
goto Altitude
|
|
|
|
}
|
2022-01-25 13:15:24 +00:00
|
|
|
if i, err := strconv.ParseUint(l.token, 10, 32); err != nil || l.err || i > 59 {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Longitude minutes", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
} else {
|
|
|
|
rr.Longitude += 1000 * 60 * uint32(i)
|
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2022-01-25 13:15:24 +00:00
|
|
|
if i, err := strconv.ParseFloat(l.token, 64); err != nil || l.err || i < 0 || i >= 60 {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Longitude seconds", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
} else {
|
|
|
|
rr.Longitude += uint32(1000 * i)
|
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
// Either number, 'E' or 'W'
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok {
|
|
|
|
goto Altitude
|
|
|
|
}
|
|
|
|
// If still alive, flag an error
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Longitude East/West", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
Altitude:
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2022-01-25 13:15:24 +00:00
|
|
|
if l.token == "" || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Altitude", lex: l}
|
2018-05-01 23:45:06 +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]
|
|
|
|
}
|
2022-01-25 13:15:24 +00:00
|
|
|
if i, err := strconv.ParseFloat(l.token, 64); err != nil {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Altitude", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
} else {
|
|
|
|
rr.Altitude = uint32(i*100.0 + 10000000.0 + 0.5)
|
|
|
|
}
|
|
|
|
|
|
|
|
// And now optionally the other values
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
count := 0
|
|
|
|
for l.value != zNewline && l.value != zEOF {
|
|
|
|
switch l.value {
|
|
|
|
case zString:
|
|
|
|
switch count {
|
|
|
|
case 0: // Size
|
2020-09-09 18:09:42 +00:00
|
|
|
exp, m, ok := stringToCm(l.token)
|
2018-05-01 23:45:06 +00:00
|
|
|
if !ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Size", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2020-09-09 18:09:42 +00:00
|
|
|
rr.Size = exp&0x0f | m<<4&0xf0
|
2018-05-01 23:45:06 +00:00
|
|
|
case 1: // HorizPre
|
2020-09-09 18:09:42 +00:00
|
|
|
exp, m, ok := stringToCm(l.token)
|
2018-05-01 23:45:06 +00:00
|
|
|
if !ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC HorizPre", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2020-09-09 18:09:42 +00:00
|
|
|
rr.HorizPre = exp&0x0f | m<<4&0xf0
|
2018-05-01 23:45:06 +00:00
|
|
|
case 2: // VertPre
|
2020-09-09 18:09:42 +00:00
|
|
|
exp, m, ok := stringToCm(l.token)
|
2018-05-01 23:45:06 +00:00
|
|
|
if !ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC VertPre", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2020-09-09 18:09:42 +00:00
|
|
|
rr.VertPre = exp&0x0f | m<<4&0xf0
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
count++
|
|
|
|
case zBlank:
|
|
|
|
// Ok
|
|
|
|
default:
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LOC Size, HorizPre or VertPre", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *HIP) parse(c *zlexer, o string) *ParseError {
|
2018-05-01 23:45:06 +00:00
|
|
|
// HitLength is not represented
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad HIP PublicKeyAlgorithm", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.PublicKeyAlgorithm = uint8(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2022-01-25 13:15:24 +00:00
|
|
|
if l.token == "" || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad HIP Hit", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Hit = l.token // This can not contain spaces, see RFC 5205 Section 6.
|
|
|
|
rr.HitLength = uint8(len(rr.Hit)) / 2
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2022-01-25 13:15:24 +00:00
|
|
|
if l.token == "" || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad HIP PublicKey", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.PublicKey = l.token // This cannot contain spaces
|
2022-01-25 13:15:24 +00:00
|
|
|
decodedPK, decodedPKerr := base64.StdEncoding.DecodeString(rr.PublicKey)
|
|
|
|
if decodedPKerr != nil {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad HIP PublicKey", lex: l}
|
2022-01-25 13:15:24 +00:00
|
|
|
}
|
|
|
|
rr.PublicKeyLength = uint16(len(decodedPK))
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
// RendezvousServers (if any)
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
var xs []string
|
|
|
|
for l.value != zNewline && l.value != zEOF {
|
|
|
|
switch l.value {
|
|
|
|
case zString:
|
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad HIP RendezvousServers", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
xs = append(xs, name)
|
|
|
|
case zBlank:
|
|
|
|
// Ok
|
|
|
|
default:
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad HIP RendezvousServers", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.RendezvousServers = xs
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *CERT) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if v, ok := StringToCertType[l.token]; ok {
|
|
|
|
rr.Type = v
|
2020-09-09 18:09:42 +00:00
|
|
|
} else if i, err := strconv.ParseUint(l.token, 10, 16); err != nil {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CERT Type", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
} else {
|
|
|
|
rr.Type = uint16(i)
|
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CERT KeyTag", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.KeyTag = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
if v, ok := StringToAlgorithm[l.token]; ok {
|
|
|
|
rr.Algorithm = v
|
2020-09-09 18:09:42 +00:00
|
|
|
} else if i, err := strconv.ParseUint(l.token, 10, 8); err != nil {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CERT Algorithm", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
} else {
|
|
|
|
rr.Algorithm = uint8(i)
|
|
|
|
}
|
2020-02-21 15:53:11 +00:00
|
|
|
s, e1 := endingToString(c, "bad CERT Certificate")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e1 != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e1
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Certificate = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *OPENPGPKEY) parse(c *zlexer, o string) *ParseError {
|
|
|
|
s, e := endingToString(c, "bad OPENPGPKEY PublicKey")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.PublicKey = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *CSYNC) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
j, e := strconv.ParseUint(l.token, 10, 32)
|
|
|
|
if e != nil {
|
|
|
|
// Serial must be a number
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CSYNC serial", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Serial = uint32(j)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
j, e1 := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e1 != nil {
|
2018-05-01 23:45:06 +00:00
|
|
|
// Serial must be a number
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CSYNC flags", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Flags = uint16(j)
|
|
|
|
|
|
|
|
rr.TypeBitMap = make([]uint16, 0)
|
|
|
|
var (
|
|
|
|
k uint16
|
|
|
|
ok bool
|
|
|
|
)
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
for l.value != zNewline && l.value != zEOF {
|
|
|
|
switch l.value {
|
|
|
|
case zBlank:
|
|
|
|
// Ok
|
|
|
|
case zString:
|
2019-04-17 17:15:55 +00:00
|
|
|
tokenUpper := strings.ToUpper(l.token)
|
|
|
|
if k, ok = StringToType[tokenUpper]; !ok {
|
|
|
|
if k, ok = typeToInt(l.token); !ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CSYNC TypeBitMap", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rr.TypeBitMap = append(rr.TypeBitMap, k)
|
|
|
|
default:
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CSYNC TypeBitMap", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 13:15:24 +00:00
|
|
|
func (rr *ZONEMD) parse(c *zlexer, o string) *ParseError {
|
|
|
|
l, _ := c.Next()
|
|
|
|
i, e := strconv.ParseUint(l.token, 10, 32)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad ZONEMD Serial", lex: l}
|
2022-01-25 13:15:24 +00:00
|
|
|
}
|
|
|
|
rr.Serial = uint32(i)
|
|
|
|
|
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad ZONEMD Scheme", lex: l}
|
2022-01-25 13:15:24 +00:00
|
|
|
}
|
|
|
|
rr.Scheme = uint8(i)
|
|
|
|
|
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
|
|
|
i, err := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if err != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad ZONEMD Hash Algorithm", lex: l}
|
2022-01-25 13:15:24 +00:00
|
|
|
}
|
|
|
|
rr.Hash = uint8(i)
|
|
|
|
|
|
|
|
s, e2 := endingToString(c, "bad ZONEMD Digest")
|
|
|
|
if e2 != nil {
|
|
|
|
return e2
|
|
|
|
}
|
|
|
|
rr.Digest = s
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-09 18:09:42 +00:00
|
|
|
func (rr *SIG) parse(c *zlexer, o string) *ParseError { return rr.RRSIG.parse(c, o) }
|
2018-05-01 23:45:06 +00:00
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *RRSIG) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
|
|
|
tokenUpper := strings.ToUpper(l.token)
|
|
|
|
if t, ok := StringToType[tokenUpper]; !ok {
|
|
|
|
if strings.HasPrefix(tokenUpper, "TYPE") {
|
|
|
|
t, ok = typeToInt(l.token)
|
2018-05-01 23:45:06 +00:00
|
|
|
if !ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RRSIG Typecovered", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.TypeCovered = t
|
|
|
|
} else {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RRSIG Typecovered", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rr.TypeCovered = t
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2024-10-17 20:09:39 +00:00
|
|
|
if l.err {
|
|
|
|
return &ParseError{err: "bad RRSIG Algorithm", lex: l}
|
|
|
|
}
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 8)
|
2024-10-17 20:09:39 +00:00
|
|
|
rr.Algorithm = uint8(i) // if 0 we'll check the mnemonic in the if
|
|
|
|
if e != nil {
|
|
|
|
v, ok := StringToAlgorithm[l.token]
|
|
|
|
if !ok {
|
|
|
|
return &ParseError{err: "bad RRSIG Algorithm", lex: l}
|
|
|
|
}
|
|
|
|
rr.Algorithm = v
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RRSIG Labels", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Labels = uint8(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e2 := strconv.ParseUint(l.token, 10, 32)
|
|
|
|
if e2 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RRSIG OrigTtl", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.OrigTtl = uint32(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if i, err := StringToTime(l.token); err != nil {
|
|
|
|
// Try to see if all numeric and use it as epoch
|
2022-01-25 13:15:24 +00:00
|
|
|
if i, err := strconv.ParseUint(l.token, 10, 32); err == nil {
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Expiration = uint32(i)
|
|
|
|
} else {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RRSIG Expiration", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rr.Expiration = i
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if i, err := StringToTime(l.token); err != nil {
|
2022-01-25 13:15:24 +00:00
|
|
|
if i, err := strconv.ParseUint(l.token, 10, 32); err == nil {
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Inception = uint32(i)
|
|
|
|
} else {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RRSIG Inception", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rr.Inception = i
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e3 := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e3 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RRSIG KeyTag", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.KeyTag = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.SignerName = l.token
|
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RRSIG SignerName", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.SignerName = name
|
|
|
|
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e4 := endingToString(c, "bad RRSIG Signature")
|
|
|
|
if e4 != nil {
|
|
|
|
return e4
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Signature = s
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2024-10-17 20:09:39 +00:00
|
|
|
func (rr *NXT) parse(c *zlexer, o string) *ParseError { return rr.NSEC.parse(c, o) }
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *NSEC) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC NextDomain", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.NextDomain = name
|
|
|
|
|
|
|
|
rr.TypeBitMap = make([]uint16, 0)
|
|
|
|
var (
|
|
|
|
k uint16
|
|
|
|
ok bool
|
|
|
|
)
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
for l.value != zNewline && l.value != zEOF {
|
|
|
|
switch l.value {
|
|
|
|
case zBlank:
|
|
|
|
// Ok
|
|
|
|
case zString:
|
2019-04-17 17:15:55 +00:00
|
|
|
tokenUpper := strings.ToUpper(l.token)
|
|
|
|
if k, ok = StringToType[tokenUpper]; !ok {
|
|
|
|
if k, ok = typeToInt(l.token); !ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC TypeBitMap", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rr.TypeBitMap = append(rr.TypeBitMap, k)
|
|
|
|
default:
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC TypeBitMap", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *NSEC3) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3 Hash", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Hash = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3 Flags", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Flags = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e2 := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e2 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3 Iterations", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Iterations = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next()
|
|
|
|
l, _ = c.Next()
|
2022-01-25 13:15:24 +00:00
|
|
|
if l.token == "" || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3 Salt", lex: l}
|
2019-04-17 17:15:55 +00:00
|
|
|
}
|
|
|
|
if l.token != "-" {
|
|
|
|
rr.SaltLength = uint8(len(l.token)) / 2
|
|
|
|
rr.Salt = l.token
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next()
|
|
|
|
l, _ = c.Next()
|
2022-01-25 13:15:24 +00:00
|
|
|
if l.token == "" || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3 NextDomain", lex: l}
|
2018-05-01 23:45:06 +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-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
for l.value != zNewline && l.value != zEOF {
|
|
|
|
switch l.value {
|
|
|
|
case zBlank:
|
|
|
|
// Ok
|
|
|
|
case zString:
|
2019-04-17 17:15:55 +00:00
|
|
|
tokenUpper := strings.ToUpper(l.token)
|
|
|
|
if k, ok = StringToType[tokenUpper]; !ok {
|
|
|
|
if k, ok = typeToInt(l.token); !ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3 TypeBitMap", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rr.TypeBitMap = append(rr.TypeBitMap, k)
|
|
|
|
default:
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3 TypeBitMap", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *NSEC3PARAM) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3PARAM Hash", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Hash = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3PARAM Flags", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Flags = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e2 := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e2 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NSEC3PARAM Iterations", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Iterations = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next()
|
|
|
|
l, _ = c.Next()
|
|
|
|
if l.token != "-" {
|
2020-09-09 18:09:42 +00:00
|
|
|
rr.SaltLength = uint8(len(l.token) / 2)
|
2019-04-17 17:15:55 +00:00
|
|
|
rr.Salt = l.token
|
|
|
|
}
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *EUI48) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
|
|
|
if len(l.token) != 17 || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad EUI48 Address", lex: l}
|
2018-05-01 23:45:06 +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] != '-' {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad EUI48 Address", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
addr[10] = l.token[15]
|
|
|
|
addr[11] = l.token[16]
|
|
|
|
|
|
|
|
i, e := strconv.ParseUint(string(addr), 16, 48)
|
|
|
|
if e != nil {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad EUI48 Address", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Address = i
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *EUI64) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
|
|
|
if len(l.token) != 23 || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad EUI64 Address", lex: l}
|
2018-05-01 23:45:06 +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] != '-' {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad EUI64 Address", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
addr[14] = l.token[21]
|
|
|
|
addr[15] = l.token[22]
|
|
|
|
|
|
|
|
i, e := strconv.ParseUint(string(addr), 16, 64)
|
|
|
|
if e != nil {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad EUI68 Address", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
rr.Address = i
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *SSHFP) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SSHFP Algorithm", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Algorithm = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SSHFP Type", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Type = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e2 := endingToString(c, "bad SSHFP Fingerprint")
|
|
|
|
if e2 != nil {
|
|
|
|
return e2
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.FingerPrint = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *DNSKEY) parseDNSKEY(c *zlexer, o, typ string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad " + typ + " Flags", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Flags = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad " + typ + " Protocol", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Protocol = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e2 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e2 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad " + typ + " Algorithm", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Algorithm = uint8(i)
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e3 := endingToString(c, "bad "+typ+" PublicKey")
|
|
|
|
if e3 != nil {
|
|
|
|
return e3
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.PublicKey = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 18:09:42 +00:00
|
|
|
func (rr *DNSKEY) parse(c *zlexer, o string) *ParseError { return rr.parseDNSKEY(c, o, "DNSKEY") }
|
|
|
|
func (rr *KEY) parse(c *zlexer, o string) *ParseError { return rr.parseDNSKEY(c, o, "KEY") }
|
|
|
|
func (rr *CDNSKEY) parse(c *zlexer, o string) *ParseError { return rr.parseDNSKEY(c, o, "CDNSKEY") }
|
|
|
|
func (rr *DS) parse(c *zlexer, o string) *ParseError { return rr.parseDS(c, o, "DS") }
|
|
|
|
func (rr *DLV) parse(c *zlexer, o string) *ParseError { return rr.parseDS(c, o, "DLV") }
|
|
|
|
func (rr *CDS) parse(c *zlexer, o string) *ParseError { return rr.parseDS(c, o, "CDS") }
|
2018-05-01 23:45:06 +00:00
|
|
|
|
2024-10-17 20:09:39 +00:00
|
|
|
func (rr *IPSECKEY) parse(c *zlexer, o string) *ParseError {
|
|
|
|
l, _ := c.Next()
|
|
|
|
num, err := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if err != nil || l.err {
|
|
|
|
return &ParseError{err: "bad IPSECKEY value", lex: l}
|
|
|
|
}
|
|
|
|
rr.Precedence = uint8(num)
|
|
|
|
c.Next() // zBlank
|
|
|
|
|
|
|
|
l, _ = c.Next()
|
|
|
|
num, err = strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if err != nil || l.err {
|
|
|
|
return &ParseError{err: "bad IPSECKEY value", lex: l}
|
|
|
|
}
|
|
|
|
rr.GatewayType = uint8(num)
|
|
|
|
c.Next() // zBlank
|
|
|
|
|
|
|
|
l, _ = c.Next()
|
|
|
|
num, err = strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if err != nil || l.err {
|
|
|
|
return &ParseError{err: "bad IPSECKEY value", lex: l}
|
|
|
|
}
|
|
|
|
rr.Algorithm = uint8(num)
|
|
|
|
c.Next() // zBlank
|
|
|
|
|
|
|
|
l, _ = c.Next()
|
|
|
|
if l.err {
|
|
|
|
return &ParseError{err: "bad IPSECKEY gateway", lex: l}
|
|
|
|
}
|
|
|
|
|
|
|
|
rr.GatewayAddr, rr.GatewayHost, err = parseAddrHostUnion(l.token, o, rr.GatewayType)
|
|
|
|
if err != nil {
|
|
|
|
return &ParseError{wrappedErr: fmt.Errorf("IPSECKEY %w", err), lex: l}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Next() // zBlank
|
|
|
|
|
|
|
|
s, pErr := endingToString(c, "bad IPSECKEY PublicKey")
|
|
|
|
if pErr != nil {
|
|
|
|
return pErr
|
|
|
|
}
|
|
|
|
rr.PublicKey = s
|
|
|
|
return slurpRemainder(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rr *AMTRELAY) parse(c *zlexer, o string) *ParseError {
|
|
|
|
l, _ := c.Next()
|
|
|
|
num, err := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if err != nil || l.err {
|
|
|
|
return &ParseError{err: "bad AMTRELAY value", lex: l}
|
|
|
|
}
|
|
|
|
rr.Precedence = uint8(num)
|
|
|
|
c.Next() // zBlank
|
|
|
|
|
|
|
|
l, _ = c.Next()
|
|
|
|
if l.err || !(l.token == "0" || l.token == "1") {
|
|
|
|
return &ParseError{err: "bad discovery value", lex: l}
|
|
|
|
}
|
|
|
|
if l.token == "1" {
|
|
|
|
rr.GatewayType = 0x80
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Next() // zBlank
|
|
|
|
|
|
|
|
l, _ = c.Next()
|
|
|
|
num, err = strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if err != nil || l.err {
|
|
|
|
return &ParseError{err: "bad AMTRELAY value", lex: l}
|
|
|
|
}
|
|
|
|
rr.GatewayType |= uint8(num)
|
|
|
|
c.Next() // zBlank
|
|
|
|
|
|
|
|
l, _ = c.Next()
|
|
|
|
if l.err {
|
|
|
|
return &ParseError{err: "bad AMTRELAY gateway", lex: l}
|
|
|
|
}
|
|
|
|
|
|
|
|
rr.GatewayAddr, rr.GatewayHost, err = parseAddrHostUnion(l.token, o, rr.GatewayType&0x7f)
|
|
|
|
if err != nil {
|
|
|
|
return &ParseError{wrappedErr: fmt.Errorf("AMTRELAY %w", err), lex: l}
|
|
|
|
}
|
|
|
|
|
|
|
|
return slurpRemainder(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
// same constants and parsing between IPSECKEY and AMTRELAY
|
|
|
|
func parseAddrHostUnion(token, o string, gatewayType uint8) (addr net.IP, host string, err error) {
|
|
|
|
switch gatewayType {
|
|
|
|
case IPSECGatewayNone:
|
|
|
|
if token != "." {
|
|
|
|
return addr, host, errors.New("gateway type none with gateway set")
|
|
|
|
}
|
|
|
|
case IPSECGatewayIPv4, IPSECGatewayIPv6:
|
|
|
|
addr = net.ParseIP(token)
|
|
|
|
if addr == nil {
|
|
|
|
return addr, host, errors.New("gateway IP invalid")
|
|
|
|
}
|
|
|
|
if (addr.To4() == nil) == (gatewayType == IPSECGatewayIPv4) {
|
|
|
|
return addr, host, errors.New("gateway IP family mismatch")
|
|
|
|
}
|
|
|
|
case IPSECGatewayHost:
|
|
|
|
var ok bool
|
|
|
|
host, ok = toAbsoluteName(token, o)
|
|
|
|
if !ok {
|
|
|
|
return addr, host, errors.New("invalid gateway host")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return addr, host, nil
|
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *RKEY) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RKEY Flags", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Flags = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RKEY Protocol", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Protocol = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e2 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e2 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RKEY Algorithm", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Algorithm = uint8(i)
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e3 := endingToString(c, "bad RKEY PublicKey")
|
|
|
|
if e3 != nil {
|
|
|
|
return e3
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.PublicKey = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *EID) parse(c *zlexer, o string) *ParseError {
|
|
|
|
s, e := endingToString(c, "bad EID Endpoint")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Endpoint = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *NIMLOC) parse(c *zlexer, o string) *ParseError {
|
|
|
|
s, e := endingToString(c, "bad NIMLOC Locator")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Locator = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *GPOS) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
_, e := strconv.ParseFloat(l.token, 64)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad GPOS Longitude", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Longitude = l.token
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
_, e1 := strconv.ParseFloat(l.token, 64)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad GPOS Latitude", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Latitude = l.token
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
_, e2 := strconv.ParseFloat(l.token, 64)
|
|
|
|
if e2 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad GPOS Altitude", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Altitude = l.token
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *DS) parseDS(c *zlexer, o, typ string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad " + typ + " KeyTag", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.KeyTag = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
if i, err := strconv.ParseUint(l.token, 10, 8); err != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
tokenUpper := strings.ToUpper(l.token)
|
|
|
|
i, ok := StringToAlgorithm[tokenUpper]
|
2018-05-01 23:45:06 +00:00
|
|
|
if !ok || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad " + typ + " Algorithm", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Algorithm = i
|
|
|
|
} else {
|
|
|
|
rr.Algorithm = uint8(i)
|
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad " + typ + " DigestType", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.DigestType = uint8(i)
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e2 := endingToString(c, "bad "+typ+" Digest")
|
|
|
|
if e2 != nil {
|
|
|
|
return e2
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Digest = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *TA) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TA KeyTag", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.KeyTag = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
if i, err := strconv.ParseUint(l.token, 10, 8); err != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
tokenUpper := strings.ToUpper(l.token)
|
|
|
|
i, ok := StringToAlgorithm[tokenUpper]
|
2018-05-01 23:45:06 +00:00
|
|
|
if !ok || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TA Algorithm", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Algorithm = i
|
|
|
|
} else {
|
|
|
|
rr.Algorithm = uint8(i)
|
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TA DigestType", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.DigestType = uint8(i)
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e2 := endingToString(c, "bad TA Digest")
|
|
|
|
if e2 != nil {
|
|
|
|
return e2
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Digest = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *TLSA) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TLSA Usage", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Usage = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TLSA Selector", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Selector = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e2 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e2 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TLSA MatchingType", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.MatchingType = uint8(i)
|
|
|
|
// So this needs be e2 (i.e. different than e), because...??t
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e3 := endingToString(c, "bad TLSA Certificate")
|
|
|
|
if e3 != nil {
|
|
|
|
return e3
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Certificate = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *SMIMEA) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SMIMEA Usage", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Usage = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SMIMEA Selector", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Selector = uint8(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e2 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e2 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad SMIMEA MatchingType", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.MatchingType = uint8(i)
|
|
|
|
// So this needs be e2 (i.e. different than e), because...??t
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e3 := endingToString(c, "bad SMIMEA Certificate")
|
|
|
|
if e3 != nil {
|
|
|
|
return e3
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Certificate = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *RFC3597) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.token != "\\#" {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RFC3597 Rdata", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2022-01-25 13:15:24 +00:00
|
|
|
rdlength, e := strconv.ParseUint(l.token, 10, 16)
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RFC3597 Rdata ", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
s, e1 := endingToString(c, "bad RFC3597 Rdata")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e1 != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e1
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2022-01-25 13:15:24 +00:00
|
|
|
if int(rdlength)*2 != len(s) {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad RFC3597 Rdata", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Rdata = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *SPF) parse(c *zlexer, o string) *ParseError {
|
|
|
|
s, e := endingToTxtSlice(c, "bad SPF Txt")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Txt = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *AVC) parse(c *zlexer, o string) *ParseError {
|
|
|
|
s, e := endingToTxtSlice(c, "bad AVC Txt")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Txt = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *TXT) parse(c *zlexer, o string) *ParseError {
|
2018-05-01 23:45:06 +00:00
|
|
|
// no zBlank reading here, because all this rdata is TXT
|
2020-02-21 15:53:11 +00:00
|
|
|
s, e := endingToTxtSlice(c, "bad TXT Txt")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Txt = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// identical to setTXT
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *NINFO) parse(c *zlexer, o string) *ParseError {
|
|
|
|
s, e := endingToTxtSlice(c, "bad NINFO ZSData")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.ZSData = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *URI) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad URI Priority", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Priority = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad URI Weight", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Weight = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e2 := endingToTxtSlice(c, "bad URI Target")
|
|
|
|
if e2 != nil {
|
|
|
|
return e2
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
if len(s) != 1 {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad URI Target", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Target = s[0]
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *DHCID) parse(c *zlexer, o string) *ParseError {
|
2018-05-01 23:45:06 +00:00
|
|
|
// awesome record to parse!
|
2020-02-21 15:53:11 +00:00
|
|
|
s, e := endingToString(c, "bad DHCID Digest")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Digest = s
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *NID) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad NID Preference", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Preference = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2020-09-09 18:09:42 +00:00
|
|
|
u, e1 := stringToNodeID(l)
|
|
|
|
if e1 != nil || l.err {
|
|
|
|
return e1
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.NodeID = u
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *L32) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad L32 Preference", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Preference = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Locator32 = net.ParseIP(l.token)
|
|
|
|
if rr.Locator32 == nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad L32 Locator", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *LP) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LP Preference", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Preference = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Fqdn = l.token
|
|
|
|
name, nameOk := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !nameOk {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad LP Fqdn", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Fqdn = name
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *L64) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad L64 Preference", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Preference = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2020-09-09 18:09:42 +00:00
|
|
|
u, e1 := stringToNodeID(l)
|
|
|
|
if e1 != nil || l.err {
|
|
|
|
return e1
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Locator64 = u
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *UID) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 32)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad UID Uid", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Uid = uint32(i)
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *GID) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 32)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad GID Gid", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Gid = uint32(i)
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *UINFO) parse(c *zlexer, o string) *ParseError {
|
|
|
|
s, e := endingToTxtSlice(c, "bad UINFO Uinfo")
|
2018-05-01 23:45:06 +00:00
|
|
|
if e != nil {
|
2019-04-17 17:15:55 +00:00
|
|
|
return e
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
if ln := len(s); ln == 0 {
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Uinfo = s[0] // silently discard anything after the first character-string
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *PX) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 16)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad PX Preference", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Preference = uint16(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Map822 = l.token
|
|
|
|
map822, map822Ok := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !map822Ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad PX Map822", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Map822 = map822
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
rr.Mapx400 = l.token
|
|
|
|
mapx400, mapx400Ok := toAbsoluteName(l.token, o)
|
|
|
|
if l.err || !mapx400Ok {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad PX Mapx400", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Mapx400 = mapx400
|
2020-02-21 15:53:11 +00:00
|
|
|
return slurpRemainder(c)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *CAA) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CAA Flag", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Flag = uint8(i)
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next() // zString
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value != zString {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CAA Tag", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Tag = l.token
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2020-09-09 18:09:42 +00:00
|
|
|
s, e1 := endingToTxtSlice(c, "bad CAA Value")
|
|
|
|
if e1 != nil {
|
|
|
|
return e1
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
if len(s) != 1 {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad CAA Value", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Value = s[0]
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:53:11 +00:00
|
|
|
func (rr *TKEY) parse(c *zlexer, o string) *ParseError {
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ := c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
// Algorithm
|
|
|
|
if l.value != zString {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TKEY algorithm", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Algorithm = l.token
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
// Get the key length and key values
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TKEY key length", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.KeySize = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value != zString {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TKEY key", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.Key = l.token
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
2018-05-01 23:45:06 +00:00
|
|
|
|
|
|
|
// Get the otherdata length and string data
|
2019-04-17 17:15:55 +00:00
|
|
|
l, _ = c.Next()
|
2020-09-09 18:09:42 +00:00
|
|
|
i, e1 := strconv.ParseUint(l.token, 10, 8)
|
|
|
|
if e1 != nil || l.err {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TKEY otherdata length", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.OtherLen = uint16(i)
|
2019-04-17 17:15:55 +00:00
|
|
|
c.Next() // zBlank
|
|
|
|
l, _ = c.Next()
|
2018-05-01 23:45:06 +00:00
|
|
|
if l.value != zString {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "bad TKEY otherday", lex: l}
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
rr.OtherData = l.token
|
2019-04-17 17:15:55 +00:00
|
|
|
return nil
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
2020-02-21 15:53:11 +00:00
|
|
|
|
|
|
|
func (rr *APL) parse(c *zlexer, o string) *ParseError {
|
|
|
|
var prefixes []APLPrefix
|
|
|
|
|
|
|
|
for {
|
|
|
|
l, _ := c.Next()
|
|
|
|
if l.value == zNewline || l.value == zEOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if l.value == zBlank && prefixes != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if l.value != zString {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "unexpected APL field", lex: l}
|
2020-02-21 15:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Expected format: [!]afi:address/prefix
|
|
|
|
|
|
|
|
colon := strings.IndexByte(l.token, ':')
|
|
|
|
if colon == -1 {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "missing colon in APL field", lex: l}
|
2020-02-21 15:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
family, cidr := l.token[:colon], l.token[colon+1:]
|
|
|
|
|
|
|
|
var negation bool
|
|
|
|
if family != "" && family[0] == '!' {
|
|
|
|
negation = true
|
|
|
|
family = family[1:]
|
|
|
|
}
|
|
|
|
|
2020-09-09 18:09:42 +00:00
|
|
|
afi, e := strconv.ParseUint(family, 10, 16)
|
|
|
|
if e != nil {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{wrappedErr: fmt.Errorf("failed to parse APL family: %w", e), lex: l}
|
2020-02-21 15:53:11 +00:00
|
|
|
}
|
|
|
|
var addrLen int
|
|
|
|
switch afi {
|
|
|
|
case 1:
|
|
|
|
addrLen = net.IPv4len
|
|
|
|
case 2:
|
|
|
|
addrLen = net.IPv6len
|
|
|
|
default:
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "unrecognized APL family", lex: l}
|
2020-02-21 15:53:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-09 18:09:42 +00:00
|
|
|
ip, subnet, e1 := net.ParseCIDR(cidr)
|
|
|
|
if e1 != nil {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{wrappedErr: fmt.Errorf("failed to parse APL address: %w", e1), lex: l}
|
2020-02-21 15:53:11 +00:00
|
|
|
}
|
|
|
|
if !ip.Equal(subnet.IP) {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "extra bits in APL address", lex: l}
|
2020-02-21 15:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(subnet.IP) != addrLen {
|
2024-10-17 20:09:39 +00:00
|
|
|
return &ParseError{err: "address mismatch with the APL family", lex: l}
|
2020-02-21 15:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prefixes = append(prefixes, APLPrefix{
|
|
|
|
Negation: negation,
|
|
|
|
Network: *subnet,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
rr.Prefixes = prefixes
|
|
|
|
return nil
|
|
|
|
}
|