2015-10-07 14:33:08 +11:00
|
|
|
//+build ignore
|
|
|
|
|
2015-10-07 22:57:24 +11:00
|
|
|
// types_generate.go is meant to run with go generate. It will use
|
2015-10-08 04:24:55 +11:00
|
|
|
// go/{importer,types} to track down all the RR struct types. Then for each type
|
2015-10-17 03:01:49 +11:00
|
|
|
// it will generate conversion tables (TypeToRR and TypeToString) and banal
|
2015-10-07 22:57:24 +11:00
|
|
|
// methods (len, Header, copy) based on the struct tags. The generated source is
|
|
|
|
// written to ztypes.go, and is meant to be checked into git.
|
2015-10-07 14:33:08 +11:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"go/format"
|
2015-10-08 04:24:55 +11:00
|
|
|
"go/types"
|
2015-10-07 14:33:08 +11:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
2019-12-30 22:25:57 +11:00
|
|
|
|
|
|
|
"golang.org/x/tools/go/packages"
|
2015-10-07 14:33:08 +11:00
|
|
|
)
|
|
|
|
|
|
|
|
var skipLen = map[string]struct{}{
|
2016-06-13 03:31:50 +10:00
|
|
|
"NSEC": {},
|
|
|
|
"NSEC3": {},
|
|
|
|
"OPT": {},
|
Implement CSYNC (#585)
Implement the CSYNC record.
Fixes #290
Long overdue, lets add this record. Similar in vain as NSEC/NSEC3, we
need to implement len() our selves. Presentation format parsing and
tests are done as well.
This is CoreDNS running with CSYNC support, `dig` doesn't support this
at the moment, so:
~~~
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40323
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;csync.example.org. IN TYPE62
;; ANSWER SECTION:
csync.example.org. 10 IN TYPE62 \# 12 000335240042000460000008
;; AUTHORITY SECTION:
example.org. 10 IN NS a.iana-servers.net.
example.org. 10 IN NS b.iana-servers.net.
~~~
2017-11-25 19:19:06 +11:00
|
|
|
"CSYNC": {},
|
2015-10-07 14:33:08 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
var packageHdr = `
|
2017-12-06 21:02:47 +11:00
|
|
|
// Code generated by "go run types_generate.go"; DO NOT EDIT.
|
2015-10-07 14:33:08 +11:00
|
|
|
|
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
`
|
|
|
|
|
2015-10-17 03:01:49 +11:00
|
|
|
var TypeToRR = template.Must(template.New("TypeToRR").Parse(`
|
|
|
|
// TypeToRR is a map of constructors for each RR type.
|
|
|
|
var TypeToRR = map[uint16]func() RR{
|
2015-10-07 14:33:08 +11:00
|
|
|
{{range .}}{{if ne . "RFC3597"}} Type{{.}}: func() RR { return new({{.}}) },
|
|
|
|
{{end}}{{end}} }
|
|
|
|
|
|
|
|
`))
|
|
|
|
|
|
|
|
var typeToString = template.Must(template.New("typeToString").Parse(`
|
2015-10-17 03:01:49 +11:00
|
|
|
// TypeToString is a map of strings for each RR type.
|
2015-10-07 14:33:08 +11:00
|
|
|
var TypeToString = map[uint16]string{
|
|
|
|
{{range .}}{{if ne . "NSAPPTR"}} Type{{.}}: "{{.}}",
|
|
|
|
{{end}}{{end}} TypeNSAPPTR: "NSAP-PTR",
|
|
|
|
}
|
|
|
|
|
|
|
|
`))
|
|
|
|
|
|
|
|
var headerFunc = template.Must(template.New("headerFunc").Parse(`
|
|
|
|
{{range .}} func (rr *{{.}}) Header() *RR_Header { return &rr.Hdr }
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
`))
|
|
|
|
|
2015-10-07 22:57:24 +11:00
|
|
|
// getTypeStruct will take a type and the package scope, and return the
|
|
|
|
// (innermost) struct if the type is considered a RR type (currently defined as
|
|
|
|
// those structs beginning with a RR_Header, could be redefined as implementing
|
|
|
|
// the RR interface). The bool return value indicates if embedded structs were
|
|
|
|
// resolved.
|
2015-10-07 14:33:08 +11:00
|
|
|
func getTypeStruct(t types.Type, scope *types.Scope) (*types.Struct, bool) {
|
|
|
|
st, ok := t.Underlying().(*types.Struct)
|
|
|
|
if !ok {
|
|
|
|
return nil, false
|
|
|
|
}
|
Implement SVCB (#1067)
* Implement SVCB
* Fix serialization and deserialization of double quotes
* More effort (?)
4 months old commit
* DEBUG
* _
* Presentation format serialization/deserialization
* _
Remove generated
* Progress on presentation format parse & write
* _
* Finish parsing presentation format
* Regenerate
* Pack unpack
* Move to svcb.go
Scan_rr.go and types.go should be untouched now
* :bug:
Thanks ghedo
* Definitions
* TypeHTTPSSVC
* Generated
and isDuplicate
* Goodbye lenient functions
Now private key=value pairs have to be defined as structs too. They are no longer automatically named as KeyNNNNN
* Encode/decode
* Experimental svc
* Read method
* Implement some of the methods, use trick...
to report where the error is while reading it. This should be applied to EDNS too. Todo: Find if case can only contain e := new(SVC_ALPN) and rest moved out
Also fix two compile errors
* Add SVC_LOCAL methods, reorder, remove alpn value, bugs
* Errors
* Alpn, make it build
* Correct testsuite
* Fully implement parser
Change from keeping a state variable to reading in one iteration until the key=value pair is fully consumed
* Simplify and document
EDNS should be simplified too
* Attempt to fix fuzzer
And Alpn bug
* A bug and change type values to match @ghedo's implementation
* IP bug
Also there are two ip duplicating patterns, one with copy, one with append. Maybe change it to be consistent.
* Check for strictly increasing keys as required
* Don't panic on invalid alpn
* Redundant check, don't modify original array
* Size calculation
* Fix the fuzzer, match the style
* 65535 is reserved too, don't delay errors
* Check keyNNN, check for aliasform having values
* IPvNHint is an array
* Fix ipvNHint
* Rename everything
* Unrecognized keys according to the updated specification
* Skip zero-length structs in generators. Fix CI
* Doc cleanup
* Off by one
* Add parse tests
* Check if private key doesn't collide with known key, invalid tests
* Disallow IPv4 as IPv6. More tests.
Related #1107
* Style fixes
* More consistency, more tests
* :bug: Deep copy as in the documentation
a := make([]net.IP, 1)
a[0] = net.ParseIP("1.1.1.1").To4()
b := append(make([]net.IP, 0, 1), a...)
b[0] = net.ParseIP("3.1.1.1").To4()
fmt.Println(a[0][0])
* Make tests readable
* Move valid parse tests to different file
* :bug: One of previous commits not fully committed
* Test binary single value encoding/decoding and full encode/decode
* Add worst-case grows to builders, :bug: Wrong visible character range, redundant tests
* Testing improvements
And don't convert to IPv4 twice
* Doc update only
* Document worst case allocations
and ipv6 can be at most of length 39, not 40
* Redundant IP copy, consistent IPv6 behavior, fix deep copy
* isDuplicate for SVCB
* Optimizations
* echoconfig
* Svc => SVCB
* Fix CI
* Regenerate after REBASE (2)
Rebased twice on 15th and 20th May
* Rename svc, use escapeByte.
* Fix parsing whitespaces between quotes, rename ECHOHOConfig
* resolve
Remove svcbFieldLen
Use reverseInt
Uppercase SVCB
Rename key_value
"invalid" => bad
Alpn comments
> 65535 check
Unneeded slices
* a little more
read => parse
IP array meaning
Force pushed because forgot to change read in svcb_test.go
* HTTPSSVC -> HTTPS
* Use new values
* mandatory code
https://github.com/MikeBishop/dns-alt-svc/pull/205
* Resolve comments
Rename svcb-pairs
Remove SVCB_PRIVATE ranges
Comment on SVCB_KEY65535
ParseError return l.token
rename svcbKeyToString and svcbStringToKey
privatize SVCBKeyToString, SVCBStringToKey
* Refactor 1
Rename sorted, originalPairs
Use append instead of copy
Use svcb_RESERVED instead of 65535, with it now being private
"type SVCBKey uint16"
* Refactor 2
svcbKeyToString as method
svcbStringToKey updated after key 0
:bug: mandatory has missing key
Rename str
idx < 0
* Refactor 3
Use l.token as z
var key, value string
Comment wrap
0:
Sentences with '.'
keyValue => kv
* Refactor 4
* Refactor 5
len() int
* Refactor 6
* Refactor 7
* Test remove parsing
* Error messages
* Rewrite two estimate comments
* parse shouldn't modify original array :bug:
* Remove two unneeded comments
* Address review comments
Push 2 because can't build fuzzer python
Push 3 to try again
* Simplify argument duplication as per tmthrgd's suggestion
And add the relevant test
Force push edit: Make sorting code fit into one line
* Rewrite ECHConfig and address the review
* Remove the optional tab
* Add To4() Check
* More cleanup and fix mandatory not sorting bug
2020-10-11 18:09:36 +11:00
|
|
|
if st.NumFields() == 0 {
|
|
|
|
return nil, false
|
|
|
|
}
|
2015-10-07 14:33:08 +11:00
|
|
|
if st.Field(0).Type() == scope.Lookup("RR_Header").Type() {
|
|
|
|
return st, false
|
|
|
|
}
|
|
|
|
if st.Field(0).Anonymous() {
|
|
|
|
st, _ := getTypeStruct(st.Field(0).Type(), scope)
|
|
|
|
return st, true
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
2019-12-30 22:25:57 +11:00
|
|
|
// loadModule retrieves package description for a given module.
|
|
|
|
func loadModule(name string) (*types.Package, error) {
|
|
|
|
conf := packages.Config{Mode: packages.NeedTypes | packages.NeedTypesInfo}
|
|
|
|
pkgs, err := packages.Load(&conf, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return pkgs[0].Types, nil
|
|
|
|
}
|
|
|
|
|
2015-10-07 14:33:08 +11:00
|
|
|
func main() {
|
2015-10-08 04:24:55 +11:00
|
|
|
// Import and type-check the package
|
2019-12-30 22:25:57 +11:00
|
|
|
pkg, err := loadModule("github.com/miekg/dns")
|
2015-10-07 14:33:08 +11:00
|
|
|
fatalIfErr(err)
|
2015-10-08 04:24:55 +11:00
|
|
|
scope := pkg.Scope()
|
2015-10-07 14:33:08 +11:00
|
|
|
|
|
|
|
// Collect constants like TypeX
|
|
|
|
var numberedTypes []string
|
|
|
|
for _, name := range scope.Names() {
|
|
|
|
o := scope.Lookup(name)
|
|
|
|
if o == nil || !o.Exported() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
b, ok := o.Type().(*types.Basic)
|
|
|
|
if !ok || b.Kind() != types.Uint16 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !strings.HasPrefix(o.Name(), "Type") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
name := strings.TrimPrefix(o.Name(), "Type")
|
2016-06-13 03:31:50 +10:00
|
|
|
if name == "PrivateRR" {
|
2015-10-07 14:33:08 +11:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
numberedTypes = append(numberedTypes, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect actual types (*X)
|
|
|
|
var namedTypes []string
|
|
|
|
for _, name := range scope.Names() {
|
|
|
|
o := scope.Lookup(name)
|
|
|
|
if o == nil || !o.Exported() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if st, _ := getTypeStruct(o.Type(), scope); st == nil {
|
|
|
|
continue
|
|
|
|
}
|
2016-06-13 03:31:50 +10:00
|
|
|
if name == "PrivateRR" {
|
2015-10-07 14:33:08 +11:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if corresponding TypeX exists
|
|
|
|
if scope.Lookup("Type"+o.Name()) == nil && o.Name() != "RFC3597" {
|
|
|
|
log.Fatalf("Constant Type%s does not exist.", o.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
namedTypes = append(namedTypes, o.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
b := &bytes.Buffer{}
|
|
|
|
b.WriteString(packageHdr)
|
|
|
|
|
2015-10-17 03:01:49 +11:00
|
|
|
// Generate TypeToRR
|
|
|
|
fatalIfErr(TypeToRR.Execute(b, namedTypes))
|
2015-10-07 14:33:08 +11:00
|
|
|
|
|
|
|
// Generate typeToString
|
|
|
|
fatalIfErr(typeToString.Execute(b, numberedTypes))
|
|
|
|
|
|
|
|
// Generate headerFunc
|
|
|
|
fatalIfErr(headerFunc.Execute(b, namedTypes))
|
|
|
|
|
|
|
|
// Generate len()
|
|
|
|
fmt.Fprint(b, "// len() functions\n")
|
|
|
|
for _, name := range namedTypes {
|
|
|
|
if _, ok := skipLen[name]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
o := scope.Lookup(name)
|
|
|
|
st, isEmbedded := getTypeStruct(o.Type(), scope)
|
|
|
|
if isEmbedded {
|
|
|
|
continue
|
|
|
|
}
|
2018-11-30 10:33:41 +11:00
|
|
|
fmt.Fprintf(b, "func (rr *%s) len(off int, compression map[string]struct{}) int {\n", name)
|
|
|
|
fmt.Fprintf(b, "l := rr.Hdr.len(off, compression)\n")
|
2015-10-07 14:33:08 +11:00
|
|
|
for i := 1; i < st.NumFields(); i++ {
|
|
|
|
o := func(s string) { fmt.Fprintf(b, s, st.Field(i).Name()) }
|
|
|
|
|
|
|
|
if _, ok := st.Field(i).Type().(*types.Slice); ok {
|
|
|
|
switch st.Tag(i) {
|
|
|
|
case `dns:"-"`:
|
|
|
|
// ignored
|
2018-11-30 10:33:41 +11:00
|
|
|
case `dns:"cdomain-name"`:
|
|
|
|
o("for _, x := range rr.%s { l += domainNameLen(x, off+l, compression, true) }\n")
|
|
|
|
case `dns:"domain-name"`:
|
|
|
|
o("for _, x := range rr.%s { l += domainNameLen(x, off+l, compression, false) }\n")
|
|
|
|
case `dns:"txt"`:
|
2015-10-07 14:33:08 +11:00
|
|
|
o("for _, x := range rr.%s { l += len(x) + 1 }\n")
|
2020-01-03 23:41:45 +11:00
|
|
|
case `dns:"apl"`:
|
|
|
|
o("for _, x := range rr.%s { l += x.len() }\n")
|
Implement SVCB (#1067)
* Implement SVCB
* Fix serialization and deserialization of double quotes
* More effort (?)
4 months old commit
* DEBUG
* _
* Presentation format serialization/deserialization
* _
Remove generated
* Progress on presentation format parse & write
* _
* Finish parsing presentation format
* Regenerate
* Pack unpack
* Move to svcb.go
Scan_rr.go and types.go should be untouched now
* :bug:
Thanks ghedo
* Definitions
* TypeHTTPSSVC
* Generated
and isDuplicate
* Goodbye lenient functions
Now private key=value pairs have to be defined as structs too. They are no longer automatically named as KeyNNNNN
* Encode/decode
* Experimental svc
* Read method
* Implement some of the methods, use trick...
to report where the error is while reading it. This should be applied to EDNS too. Todo: Find if case can only contain e := new(SVC_ALPN) and rest moved out
Also fix two compile errors
* Add SVC_LOCAL methods, reorder, remove alpn value, bugs
* Errors
* Alpn, make it build
* Correct testsuite
* Fully implement parser
Change from keeping a state variable to reading in one iteration until the key=value pair is fully consumed
* Simplify and document
EDNS should be simplified too
* Attempt to fix fuzzer
And Alpn bug
* A bug and change type values to match @ghedo's implementation
* IP bug
Also there are two ip duplicating patterns, one with copy, one with append. Maybe change it to be consistent.
* Check for strictly increasing keys as required
* Don't panic on invalid alpn
* Redundant check, don't modify original array
* Size calculation
* Fix the fuzzer, match the style
* 65535 is reserved too, don't delay errors
* Check keyNNN, check for aliasform having values
* IPvNHint is an array
* Fix ipvNHint
* Rename everything
* Unrecognized keys according to the updated specification
* Skip zero-length structs in generators. Fix CI
* Doc cleanup
* Off by one
* Add parse tests
* Check if private key doesn't collide with known key, invalid tests
* Disallow IPv4 as IPv6. More tests.
Related #1107
* Style fixes
* More consistency, more tests
* :bug: Deep copy as in the documentation
a := make([]net.IP, 1)
a[0] = net.ParseIP("1.1.1.1").To4()
b := append(make([]net.IP, 0, 1), a...)
b[0] = net.ParseIP("3.1.1.1").To4()
fmt.Println(a[0][0])
* Make tests readable
* Move valid parse tests to different file
* :bug: One of previous commits not fully committed
* Test binary single value encoding/decoding and full encode/decode
* Add worst-case grows to builders, :bug: Wrong visible character range, redundant tests
* Testing improvements
And don't convert to IPv4 twice
* Doc update only
* Document worst case allocations
and ipv6 can be at most of length 39, not 40
* Redundant IP copy, consistent IPv6 behavior, fix deep copy
* isDuplicate for SVCB
* Optimizations
* echoconfig
* Svc => SVCB
* Fix CI
* Regenerate after REBASE (2)
Rebased twice on 15th and 20th May
* Rename svc, use escapeByte.
* Fix parsing whitespaces between quotes, rename ECHOHOConfig
* resolve
Remove svcbFieldLen
Use reverseInt
Uppercase SVCB
Rename key_value
"invalid" => bad
Alpn comments
> 65535 check
Unneeded slices
* a little more
read => parse
IP array meaning
Force pushed because forgot to change read in svcb_test.go
* HTTPSSVC -> HTTPS
* Use new values
* mandatory code
https://github.com/MikeBishop/dns-alt-svc/pull/205
* Resolve comments
Rename svcb-pairs
Remove SVCB_PRIVATE ranges
Comment on SVCB_KEY65535
ParseError return l.token
rename svcbKeyToString and svcbStringToKey
privatize SVCBKeyToString, SVCBStringToKey
* Refactor 1
Rename sorted, originalPairs
Use append instead of copy
Use svcb_RESERVED instead of 65535, with it now being private
"type SVCBKey uint16"
* Refactor 2
svcbKeyToString as method
svcbStringToKey updated after key 0
:bug: mandatory has missing key
Rename str
idx < 0
* Refactor 3
Use l.token as z
var key, value string
Comment wrap
0:
Sentences with '.'
keyValue => kv
* Refactor 4
* Refactor 5
len() int
* Refactor 6
* Refactor 7
* Test remove parsing
* Error messages
* Rewrite two estimate comments
* parse shouldn't modify original array :bug:
* Remove two unneeded comments
* Address review comments
Push 2 because can't build fuzzer python
Push 3 to try again
* Simplify argument duplication as per tmthrgd's suggestion
And add the relevant test
Force push edit: Make sorting code fit into one line
* Rewrite ECHConfig and address the review
* Remove the optional tab
* Add To4() Check
* More cleanup and fix mandatory not sorting bug
2020-10-11 18:09:36 +11:00
|
|
|
case `dns:"pairs"`:
|
|
|
|
o("for _, x := range rr.%s { l += 4 + int(x.len()) }\n")
|
2015-10-07 14:33:08 +11:00
|
|
|
default:
|
|
|
|
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-06-13 03:31:50 +10:00
|
|
|
switch {
|
|
|
|
case st.Tag(i) == `dns:"-"`:
|
2015-10-07 14:33:08 +11:00
|
|
|
// ignored
|
2018-11-30 10:33:41 +11:00
|
|
|
case st.Tag(i) == `dns:"cdomain-name"`:
|
|
|
|
o("l += domainNameLen(rr.%s, off+l, compression, true)\n")
|
|
|
|
case st.Tag(i) == `dns:"domain-name"`:
|
|
|
|
o("l += domainNameLen(rr.%s, off+l, compression, false)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"octet"`:
|
2015-10-07 14:33:08 +11:00
|
|
|
o("l += len(rr.%s)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case strings.HasPrefix(st.Tag(i), `dns:"size-base64`):
|
|
|
|
fallthrough
|
|
|
|
case st.Tag(i) == `dns:"base64"`:
|
2015-10-07 14:33:08 +11:00
|
|
|
o("l += base64.StdEncoding.DecodedLen(len(rr.%s))\n")
|
2017-12-07 08:41:53 +11:00
|
|
|
case strings.HasPrefix(st.Tag(i), `dns:"size-hex:`): // this has an extra field where the length is stored
|
|
|
|
o("l += len(rr.%s)/2\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"hex"`:
|
2019-04-30 18:14:07 +10:00
|
|
|
o("l += len(rr.%s)/2\n")
|
2018-12-30 20:45:18 +11:00
|
|
|
case st.Tag(i) == `dns:"any"`:
|
|
|
|
o("l += len(rr.%s)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"a"`:
|
2019-03-29 08:53:54 +11:00
|
|
|
o("if len(rr.%s) != 0 { l += net.IPv4len }\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"aaaa"`:
|
2019-03-29 08:53:54 +11:00
|
|
|
o("if len(rr.%s) != 0 { l += net.IPv6len }\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"txt"`:
|
2015-10-07 14:33:08 +11:00
|
|
|
o("for _, t := range rr.%s { l += len(t) + 1 }\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"uint48"`:
|
2015-10-07 14:33:08 +11:00
|
|
|
o("l += 6 // %s\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == "":
|
2015-10-07 14:33:08 +11:00
|
|
|
switch st.Field(i).Type().(*types.Basic).Kind() {
|
|
|
|
case types.Uint8:
|
2017-02-16 07:40:16 +11:00
|
|
|
o("l++ // %s\n")
|
2015-10-07 14:33:08 +11:00
|
|
|
case types.Uint16:
|
|
|
|
o("l += 2 // %s\n")
|
|
|
|
case types.Uint32:
|
|
|
|
o("l += 4 // %s\n")
|
|
|
|
case types.Uint64:
|
|
|
|
o("l += 8 // %s\n")
|
|
|
|
case types.String:
|
|
|
|
o("l += len(rr.%s) + 1\n")
|
|
|
|
default:
|
|
|
|
log.Fatalln(name, st.Field(i).Name())
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Fprintf(b, "return l }\n")
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:06:31 +11:00
|
|
|
// Generate copy()
|
|
|
|
fmt.Fprint(b, "// copy() functions\n")
|
|
|
|
for _, name := range namedTypes {
|
|
|
|
o := scope.Lookup(name)
|
|
|
|
st, isEmbedded := getTypeStruct(o.Type(), scope)
|
2020-05-18 22:54:09 +10:00
|
|
|
fmt.Fprintf(b, "func (rr *%s) copy() RR {\n", name)
|
|
|
|
fields := make([]string, 0, st.NumFields())
|
2015-10-07 15:06:31 +11:00
|
|
|
if isEmbedded {
|
2020-05-18 22:54:09 +10:00
|
|
|
a, _ := o.Type().Underlying().(*types.Struct)
|
|
|
|
parent := a.Field(0).Name()
|
|
|
|
fields = append(fields, "*rr."+parent+".copy().(*"+parent+")")
|
|
|
|
goto WriteCopy
|
2015-10-07 15:06:31 +11:00
|
|
|
}
|
2020-05-18 22:54:09 +10:00
|
|
|
fields = append(fields, "rr.Hdr")
|
2015-10-07 15:06:31 +11:00
|
|
|
for i := 1; i < st.NumFields(); i++ {
|
|
|
|
f := st.Field(i).Name()
|
|
|
|
if sl, ok := st.Field(i).Type().(*types.Slice); ok {
|
|
|
|
t := sl.Underlying().String()
|
|
|
|
t = strings.TrimPrefix(t, "[]")
|
2016-04-14 17:48:01 +10:00
|
|
|
if strings.Contains(t, ".") {
|
|
|
|
splits := strings.Split(t, ".")
|
|
|
|
t = splits[len(splits)-1]
|
|
|
|
}
|
2019-01-31 05:11:33 +11:00
|
|
|
// For the EDNS0 interface (used in the OPT RR), we need to call the copy method on each element.
|
|
|
|
if t == "EDNS0" {
|
|
|
|
fmt.Fprintf(b, "%s := make([]%s, len(rr.%s));\nfor i,e := range rr.%s {\n %s[i] = e.copy()\n}\n",
|
|
|
|
f, t, f, f, f)
|
|
|
|
fields = append(fields, f)
|
|
|
|
continue
|
|
|
|
}
|
2020-01-03 23:41:45 +11:00
|
|
|
if t == "APLPrefix" {
|
2020-05-18 22:54:09 +10:00
|
|
|
fmt.Fprintf(b, "%s := make([]%s, len(rr.%s));\nfor i,e := range rr.%s {\n %s[i] = e.copy()\n}\n",
|
|
|
|
f, t, f, f, f)
|
2020-01-03 23:41:45 +11:00
|
|
|
fields = append(fields, f)
|
|
|
|
continue
|
|
|
|
}
|
Implement SVCB (#1067)
* Implement SVCB
* Fix serialization and deserialization of double quotes
* More effort (?)
4 months old commit
* DEBUG
* _
* Presentation format serialization/deserialization
* _
Remove generated
* Progress on presentation format parse & write
* _
* Finish parsing presentation format
* Regenerate
* Pack unpack
* Move to svcb.go
Scan_rr.go and types.go should be untouched now
* :bug:
Thanks ghedo
* Definitions
* TypeHTTPSSVC
* Generated
and isDuplicate
* Goodbye lenient functions
Now private key=value pairs have to be defined as structs too. They are no longer automatically named as KeyNNNNN
* Encode/decode
* Experimental svc
* Read method
* Implement some of the methods, use trick...
to report where the error is while reading it. This should be applied to EDNS too. Todo: Find if case can only contain e := new(SVC_ALPN) and rest moved out
Also fix two compile errors
* Add SVC_LOCAL methods, reorder, remove alpn value, bugs
* Errors
* Alpn, make it build
* Correct testsuite
* Fully implement parser
Change from keeping a state variable to reading in one iteration until the key=value pair is fully consumed
* Simplify and document
EDNS should be simplified too
* Attempt to fix fuzzer
And Alpn bug
* A bug and change type values to match @ghedo's implementation
* IP bug
Also there are two ip duplicating patterns, one with copy, one with append. Maybe change it to be consistent.
* Check for strictly increasing keys as required
* Don't panic on invalid alpn
* Redundant check, don't modify original array
* Size calculation
* Fix the fuzzer, match the style
* 65535 is reserved too, don't delay errors
* Check keyNNN, check for aliasform having values
* IPvNHint is an array
* Fix ipvNHint
* Rename everything
* Unrecognized keys according to the updated specification
* Skip zero-length structs in generators. Fix CI
* Doc cleanup
* Off by one
* Add parse tests
* Check if private key doesn't collide with known key, invalid tests
* Disallow IPv4 as IPv6. More tests.
Related #1107
* Style fixes
* More consistency, more tests
* :bug: Deep copy as in the documentation
a := make([]net.IP, 1)
a[0] = net.ParseIP("1.1.1.1").To4()
b := append(make([]net.IP, 0, 1), a...)
b[0] = net.ParseIP("3.1.1.1").To4()
fmt.Println(a[0][0])
* Make tests readable
* Move valid parse tests to different file
* :bug: One of previous commits not fully committed
* Test binary single value encoding/decoding and full encode/decode
* Add worst-case grows to builders, :bug: Wrong visible character range, redundant tests
* Testing improvements
And don't convert to IPv4 twice
* Doc update only
* Document worst case allocations
and ipv6 can be at most of length 39, not 40
* Redundant IP copy, consistent IPv6 behavior, fix deep copy
* isDuplicate for SVCB
* Optimizations
* echoconfig
* Svc => SVCB
* Fix CI
* Regenerate after REBASE (2)
Rebased twice on 15th and 20th May
* Rename svc, use escapeByte.
* Fix parsing whitespaces between quotes, rename ECHOHOConfig
* resolve
Remove svcbFieldLen
Use reverseInt
Uppercase SVCB
Rename key_value
"invalid" => bad
Alpn comments
> 65535 check
Unneeded slices
* a little more
read => parse
IP array meaning
Force pushed because forgot to change read in svcb_test.go
* HTTPSSVC -> HTTPS
* Use new values
* mandatory code
https://github.com/MikeBishop/dns-alt-svc/pull/205
* Resolve comments
Rename svcb-pairs
Remove SVCB_PRIVATE ranges
Comment on SVCB_KEY65535
ParseError return l.token
rename svcbKeyToString and svcbStringToKey
privatize SVCBKeyToString, SVCBStringToKey
* Refactor 1
Rename sorted, originalPairs
Use append instead of copy
Use svcb_RESERVED instead of 65535, with it now being private
"type SVCBKey uint16"
* Refactor 2
svcbKeyToString as method
svcbStringToKey updated after key 0
:bug: mandatory has missing key
Rename str
idx < 0
* Refactor 3
Use l.token as z
var key, value string
Comment wrap
0:
Sentences with '.'
keyValue => kv
* Refactor 4
* Refactor 5
len() int
* Refactor 6
* Refactor 7
* Test remove parsing
* Error messages
* Rewrite two estimate comments
* parse shouldn't modify original array :bug:
* Remove two unneeded comments
* Address review comments
Push 2 because can't build fuzzer python
Push 3 to try again
* Simplify argument duplication as per tmthrgd's suggestion
And add the relevant test
Force push edit: Make sorting code fit into one line
* Rewrite ECHConfig and address the review
* Remove the optional tab
* Add To4() Check
* More cleanup and fix mandatory not sorting bug
2020-10-11 18:09:36 +11:00
|
|
|
if t == "SVCBKeyValue" {
|
|
|
|
fmt.Fprintf(b, "%s := make([]%s, len(rr.%s));\nfor i,e := range rr.%s {\n %s[i] = e.copy()\n}\n",
|
|
|
|
f, t, f, f, f)
|
|
|
|
fields = append(fields, f)
|
|
|
|
continue
|
|
|
|
}
|
2015-10-07 15:06:31 +11:00
|
|
|
fmt.Fprintf(b, "%s := make([]%s, len(rr.%s)); copy(%s, rr.%s)\n",
|
|
|
|
f, t, f, f, f)
|
|
|
|
fields = append(fields, f)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if st.Field(i).Type().String() == "net.IP" {
|
|
|
|
fields = append(fields, "copyIP(rr."+f+")")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fields = append(fields, "rr."+f)
|
|
|
|
}
|
2020-05-18 22:54:09 +10:00
|
|
|
WriteCopy:
|
2015-10-07 15:06:31 +11:00
|
|
|
fmt.Fprintf(b, "return &%s{%s}\n", name, strings.Join(fields, ","))
|
|
|
|
fmt.Fprintf(b, "}\n")
|
|
|
|
}
|
|
|
|
|
2015-10-07 22:57:24 +11:00
|
|
|
// gofmt
|
2015-10-07 14:33:08 +11:00
|
|
|
res, err := format.Source(b.Bytes())
|
2015-10-07 15:06:31 +11:00
|
|
|
if err != nil {
|
|
|
|
b.WriteTo(os.Stderr)
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2015-10-07 14:33:08 +11:00
|
|
|
|
2015-10-07 22:57:24 +11:00
|
|
|
// write result
|
|
|
|
f, err := os.Create("ztypes.go")
|
2015-10-07 14:33:08 +11:00
|
|
|
fatalIfErr(err)
|
|
|
|
defer f.Close()
|
|
|
|
f.Write(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func fatalIfErr(err error) {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|