Debian Codegraph @

scan_rr.go

raw
1 package dns
2
3 import (
4 "strings"
5
6 "codeberg.org/miekg/dns/internal/ddd"
7 "codeberg.org/miekg/dns/internal/dnslex"
8 )
9
10 func (rr *A) parse(c *dnslex.Lexer, o string) error { return parseA(&rr.A, c, o) }
11 func (rr *AAAA) parse(c *dnslex.Lexer, o string) error { return parseAAAA(&rr.AAAA, c, o) }
12 func (rr *NS) parse(c *dnslex.Lexer, o string) error { return parseNS(&rr.NS, c, o) }
13 func (rr *PTR) parse(c *dnslex.Lexer, o string) error { return parsePTR(&rr.PTR, c, o) }
14 func (rr *NSAPPTR) parse(c *dnslex.Lexer, o string) error {
15 return parseNSAPPTR(&rr.NSAPPTR, c, o)
16 }
17 func (rr *RP) parse(c *dnslex.Lexer, o string) error { return parseRP(&rr.RP, c, o) }
18 func (rr *MR) parse(c *dnslex.Lexer, o string) error { return parseMR(&rr.MR, c, o) }
19 func (rr *MB) parse(c *dnslex.Lexer, o string) error { return parseMB(&rr.MB, c, o) }
20 func (rr *MG) parse(c *dnslex.Lexer, o string) error { return parseMG(&rr.MG, c, o) }
21 func (rr *HINFO) parse(c *dnslex.Lexer, o string) error { return parseHINFO(&rr.HINFO, c, o) }
22 func (rr *ISDN) parse(c *dnslex.Lexer, o string) error { return parseISDN(&rr.ISDN, c, o) }
23 func (rr *MINFO) parse(c *dnslex.Lexer, o string) error { return parseMINFO(&rr.MINFO, c, o) }
24 func (rr *MF) parse(c *dnslex.Lexer, o string) error { return parseMF(&rr.MF, c, o) }
25 func (rr *MD) parse(c *dnslex.Lexer, o string) error { return parseMD(&rr.MD, c, o) }
26 func (rr *MX) parse(c *dnslex.Lexer, o string) error { return parseMX(&rr.MX, c, o) }
27 func (rr *RT) parse(c *dnslex.Lexer, o string) error { return parseRT(&rr.RT, c, o) }
28 func (rr *AFSDB) parse(c *dnslex.Lexer, o string) error { return parseAFSDB(&rr.AFSDB, c, o) }
29 func (rr *X25) parse(c *dnslex.Lexer, o string) error { return parseX25(&rr.X25, c, o) }
30 func (rr *KX) parse(c *dnslex.Lexer, o string) error { return parseKX(&rr.KX, c, o) }
31 func (rr *CNAME) parse(c *dnslex.Lexer, o string) error { return parseCNAME(&rr.CNAME, c, o) }
32 func (rr *DNAME) parse(c *dnslex.Lexer, o string) error { return parseDNAME(&rr.DNAME, c, o) }
33 func (rr *SOA) parse(c *dnslex.Lexer, o string) error { return parseSOA(&rr.SOA, c, o) }
34 func (rr *SRV) parse(c *dnslex.Lexer, o string) error { return parseSRV(&rr.SRV, c, o) }
35 func (rr *NAPTR) parse(c *dnslex.Lexer, o string) error { return parseNAPTR(&rr.NAPTR, c, o) }
36 func (rr *TALINK) parse(c *dnslex.Lexer, o string) error { return parseTALINK(&rr.TALINK, c, o) }
37 func (rr *LOC) parse(c *dnslex.Lexer, o string) error { return parseLOC(&rr.LOC, c, o) }
38 func (rr *CERT) parse(c *dnslex.Lexer, o string) error { return parseCERT(&rr.CERT, c, o) }
39 func (rr *OPENPGPKEY) parse(c *dnslex.Lexer, o string) error {
40 return parseOPENPGPKEY(&rr.OPENPGPKEY, c, o)
41 }
42 func (rr *HIP) parse(c *dnslex.Lexer, o string) error { return parseHIP(&rr.HIP, c, o) }
43 func (rr *CSYNC) parse(c *dnslex.Lexer, o string) error { return parseCSYNC(&rr.CSYNC, c, o) }
44 func (rr *ZONEMD) parse(c *dnslex.Lexer, o string) error { return parseZONEMD(&rr.ZONEMD, c, o) }
45 func (rr *SIG) parse(c *dnslex.Lexer, o string) error { return parseRRSIG(&rr.RRSIG.RRSIG, c, o) }
46 func (rr *RRSIG) parse(c *dnslex.Lexer, o string) error { return parseRRSIG(&rr.RRSIG, c, o) }
47 func (rr *NXT) parse(c *dnslex.Lexer, o string) error { return parseNSEC(&rr.NSEC.NSEC, c, o) }
48 func (rr *NSEC) parse(c *dnslex.Lexer, o string) error { return parseNSEC(&rr.NSEC, c, o) }
49 func (rr *NSEC3) parse(c *dnslex.Lexer, o string) error { return parseNSEC3(&rr.NSEC3, c, o) }
50 func (rr *NSEC3PARAM) parse(c *dnslex.Lexer, o string) error {
51 return parseNSEC3PARAM(&rr.NSEC3PARAM, c, o)
52 }
53 func (rr *EUI48) parse(c *dnslex.Lexer, o string) error { return parseEUI48(&rr.EUI48, c, o) }
54 func (rr *EUI64) parse(c *dnslex.Lexer, o string) error { return parseEUI64(&rr.EUI64, c, o) }
55 func (rr *SSHFP) parse(c *dnslex.Lexer, o string) error { return parseSSHFP(&rr.SSHFP, c, o) }
56 func (rr *DNSKEY) parse(c *dnslex.Lexer, o string) error { return parseDNSKEY(&rr.DNSKEY, c, o) }
57 func (rr *KEY) parse(c *dnslex.Lexer, o string) error {
58 return parseDNSKEY(&rr.DNSKEY.DNSKEY, c, o)
59 }
60 func (rr *CDNSKEY) parse(c *dnslex.Lexer, o string) error {
61 return parseDNSKEY(&rr.DNSKEY.DNSKEY, c, o)
62 }
63 func (rr *DS) parse(c *dnslex.Lexer, o string) error { return parseDS(&rr.DS, c, o) }
64 func (rr *DLV) parse(c *dnslex.Lexer, o string) error { return parseDS(&rr.DS.DS, c, o) }
65 func (rr *CDS) parse(c *dnslex.Lexer, o string) error { return parseDS(&rr.DS.DS, c, o) }
66 func (rr *RKEY) parse(c *dnslex.Lexer, o string) error { return parseRKEY(&rr.RKEY, c, o) }
67 func (rr *EID) parse(c *dnslex.Lexer, o string) error { return parseEID(&rr.EID, c, o) }
68 func (rr *NIMLOC) parse(c *dnslex.Lexer, o string) error { return parseNIMLOC(&rr.NIMLOC, c, o) }
69 func (rr *GPOS) parse(c *dnslex.Lexer, o string) error { return parseGPOS(&rr.GPOS, c, o) }
70 func (rr *TA) parse(c *dnslex.Lexer, o string) error { return parseTA(&rr.TA, c, o) }
71 func (rr *TLSA) parse(c *dnslex.Lexer, o string) error { return parseTLSA(&rr.TLSA, c, o) }
72 func (rr *SMIMEA) parse(c *dnslex.Lexer, o string) error { return parseSMIMEA(&rr.SMIMEA, c, o) }
73 func (rr *RFC3597) parse(c *dnslex.Lexer, o string) error {
74 return parseRFC3597(&rr.RFC3597, c, o)
75 }
76 func (rr *SPF) parse(c *dnslex.Lexer, o string) error { return parseTXT(&rr.TXT.TXT, c, o) }
77 func (rr *AVC) parse(c *dnslex.Lexer, o string) error { return parseTXT(&rr.TXT.TXT, c, o) }
78 func (rr *TXT) parse(c *dnslex.Lexer, o string) error { return parseTXT(&rr.TXT, c, o) }
79 func (rr *NINFO) parse(c *dnslex.Lexer, o string) error { return parseNINFO(&rr.NINFO, c, o) }
80 func (rr *RESINFO) parse(c *dnslex.Lexer, o string) error { return parseTXT(&rr.TXT.TXT, c, o) }
81 func (rr *WALLET) parse(c *dnslex.Lexer, o string) error { return parseTXT(&rr.TXT.TXT, c, o) }
82 func (rr *CLA) parse(c *dnslex.Lexer, o string) error { return parseTXT(&rr.TXT.TXT, c, o) }
83 func (rr *IPN) parse(c *dnslex.Lexer, o string) error { return parseIPN(&rr.IPN, c, o) }
84 func (rr *URI) parse(c *dnslex.Lexer, o string) error { return parseURI(&rr.URI, c, o) }
85 func (rr *DHCID) parse(c *dnslex.Lexer, o string) error { return parseDHCID(&rr.DHCID, c, o) }
86 func (rr *NID) parse(c *dnslex.Lexer, o string) error { return parseNID(&rr.NID, c, o) }
87 func (rr *L32) parse(c *dnslex.Lexer, o string) error { return parseL32(&rr.L32, c, o) }
88 func (rr *LP) parse(c *dnslex.Lexer, o string) error { return parseLP(&rr.LP, c, o) }
89 func (rr *L64) parse(c *dnslex.Lexer, o string) error { return parseL64(&rr.L64, c, o) }
90 func (rr *UID) parse(c *dnslex.Lexer, o string) error { return parseUID(&rr.UID, c, o) }
91 func (rr *GID) parse(c *dnslex.Lexer, o string) error { return parseGID(&rr.GID, c, o) }
92 func (rr *UINFO) parse(c *dnslex.Lexer, o string) error { return parseUINFO(&rr.UINFO, c, o) }
93 func (rr *PX) parse(c *dnslex.Lexer, o string) error { return parsePX(&rr.PX, c, o) }
94 func (rr *CAA) parse(c *dnslex.Lexer, o string) error { return parseCAA(&rr.CAA, c, o) }
95 func (rr *TKEY) parse(c *dnslex.Lexer, o string) error { return parseTKEY(&rr.TKEY, c, o) }
96 func (rr *SVCB) parse(c *dnslex.Lexer, o string) error { return parseSVCB(&rr.SVCB, c, o) }
97 func (rr *HTTPS) parse(c *dnslex.Lexer, o string) error {
98 return parseSVCB(&rr.SVCB.SVCB, c, o)
99 }
100 func (rr *DELEG) parse(c *dnslex.Lexer, o string) error { return parseDELEG(&rr.DELEG, c, o) }
101 func (rr *DELEGPARAM) parse(c *dnslex.Lexer, o string) error {
102 return parseDELEG(&rr.DELEG.DELEG, c, o)
103 }
104 func (rr *DSYNC) parse(c *dnslex.Lexer, o string) error { return parseDSYNC(&rr.DSYNC, c, o) }
105
106 // escapedStringOffset finds the offset within a string (which may contain escape
107 // sequences) that corresponds to a certain byte offset. If the input offset is
108 // out of bounds, -1 is returned (which is *not* considered an error).
109 func escapedStringOffset(s string, desiredByteOffset int) (int, bool) {
110 if desiredByteOffset == 0 {
111 return 0, true
112 }
113
114 currentByteOffset, i := 0, 0
115
116 for i < len(s) {
117 currentByteOffset += 1
118
119 // Skip escape sequences
120 if s[i] != '\\' {
121 // Single plain byte, not an escape sequence.
122 i++
123 } else if ddd.Is(s[i+1:]) {
124 // Skip backslash and DDD.
125 i += 4
126 } else if len(s[i+1:]) < 1 {
127 // No character following the backslash; that's an error.
128 return 0, false
129 } else {
130 // Skip backslash and following byte.
131 i += 2
132 }
133
134 if currentByteOffset >= desiredByteOffset {
135 return i, true
136 }
137 }
138
139 return -1, true
140 }
141
142 // remainder returns a remainder of the rdata with embedded spaces, return the parsed string (sans the spaces)
143 // or an error
144 func remainder(c *dnslex.Lexer, errstr string) (string, error) {
145 sb := &strings.Builder{} // allocate on stack, no pooling
146 for {
147 l, _ := c.Next()
148 switch l.Value {
149 case dnslex.String:
150 sb.WriteString(l.Token)
151 case dnslex.Blank:
152 case dnslex.Newline, dnslex.EOF:
153 return sb.String(), nil
154 default:
155 return "", &ParseError{err: errstr, lex: l}
156 }
157 }
158 }
159
160 // remainderSlice returns a remainder of the rdata with embedded spaces, split on unquoted whitespace
161 // and return the parsed string slice or an error
162 func remainderSlice(c *dnslex.Lexer, errstr string) ([]string, error) {
163 l, _ := c.Next()
164 if l.Value == dnslex.Error {
165 return nil, &ParseError{err: errstr, lex: l}
166 }
167
168 // build the slice
169 s := make([]string, 0, 2)
170 quote := false
171 empty := false
172 for l.Value != dnslex.Newline && l.Value != dnslex.EOF {
173 if l.Value == dnslex.Error {
174 return nil, &ParseError{err: errstr, lex: l}
175 }
176 switch l.Value {
177 case dnslex.String:
178 empty = false
179 // split up tokens that are larger than 255 into 255-chunks
180 p := 0
181 for {
182 i, ok := escapedStringOffset(l.Token[p:], 255)
183 if !ok {
184 return nil, &ParseError{err: errstr, lex: l}
185 }
186 if i != -1 && p+i != len(l.Token) {
187 s = append(s, l.Token[p:p+i])
188 p += i
189 } else {
190 s = append(s, l.Token[p:])
191 break
192 }
193 }
194 case dnslex.Blank:
195 if quote {
196 // dnslex.Blank can only be seen in between txt parts.
197 return nil, &ParseError{err: errstr, lex: l}
198 }
199 case dnslex.Quote:
200 if empty && quote {
201 s = append(s, "")
202 }
203 quote = !quote
204 empty = true
205 default:
206 return nil, &ParseError{err: errstr, lex: l}
207 }
208 l, _ = c.Next()
209 }
210
211 if quote {
212 return nil, &ParseError{err: errstr, lex: l}
213 }
214
215 return s, nil
216 }