2016-05-15 02:56:20 +10:00
|
|
|
//+build ignore
|
|
|
|
|
|
|
|
// msg_generate.go is meant to run with go generate. It will use
|
|
|
|
// go/{importer,types} to track down all the RR struct types. Then for each type
|
|
|
|
// it will generate pack/unpack methods based on the struct tags. The generated source is
|
|
|
|
// written to zmsg.go, and is meant to be checked into git.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"go/format"
|
|
|
|
"go/types"
|
|
|
|
"log"
|
|
|
|
"os"
|
2016-06-13 03:31:50 +10:00
|
|
|
"strings"
|
2019-12-30 22:25:57 +11:00
|
|
|
|
|
|
|
"golang.org/x/tools/go/packages"
|
2016-05-15 02:56:20 +10:00
|
|
|
)
|
|
|
|
|
|
|
|
var packageHdr = `
|
2017-12-06 21:02:47 +11:00
|
|
|
// Code generated by "go run msg_generate.go"; DO NOT EDIT.
|
2016-05-15 02:56:20 +10:00
|
|
|
|
|
|
|
package dns
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
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
|
|
|
|
}
|
2016-05-15 02:56:20 +10: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
|
|
|
|
}
|
|
|
|
|
2016-05-15 02:56:20 +10:00
|
|
|
func main() {
|
|
|
|
// Import and type-check the package
|
2019-12-30 22:25:57 +11:00
|
|
|
pkg, err := loadModule("github.com/miekg/dns")
|
2016-05-15 02:56:20 +10:00
|
|
|
fatalIfErr(err)
|
|
|
|
scope := pkg.Scope()
|
|
|
|
|
|
|
|
// 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 06:06:46 +10:00
|
|
|
if name == "PrivateRR" {
|
2016-05-15 02:56:20 +10: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)
|
|
|
|
|
|
|
|
fmt.Fprint(b, "// pack*() functions\n\n")
|
|
|
|
for _, name := range namedTypes {
|
|
|
|
o := scope.Lookup(name)
|
2016-06-13 01:09:37 +10:00
|
|
|
st, _ := getTypeStruct(o.Type(), scope)
|
2016-05-15 02:56:20 +10:00
|
|
|
|
2019-01-04 10:39:14 +11:00
|
|
|
fmt.Fprintf(b, "func (rr *%s) pack(msg []byte, off int, compression compressionMap, compress bool) (off1 int, err error) {\n", name)
|
2016-05-15 02:56:20 +10:00
|
|
|
for i := 1; i < st.NumFields(); i++ {
|
|
|
|
o := func(s string) {
|
|
|
|
fmt.Fprintf(b, s, st.Field(i).Name())
|
|
|
|
fmt.Fprint(b, `if err != nil {
|
2019-01-04 10:39:14 +11:00
|
|
|
return off, err
|
2016-05-15 02:56:20 +10:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2016-06-05 16:53:12 +10:00
|
|
|
if _, ok := st.Field(i).Type().(*types.Slice); ok {
|
|
|
|
switch st.Tag(i) {
|
2016-06-13 01:09:37 +10:00
|
|
|
case `dns:"-"`: // ignored
|
2016-06-05 16:53:12 +10:00
|
|
|
case `dns:"txt"`:
|
|
|
|
o("off, err = packStringTxt(rr.%s, msg, off)\n")
|
2016-06-13 01:09:37 +10:00
|
|
|
case `dns:"opt"`:
|
|
|
|
o("off, err = packDataOpt(rr.%s, msg, off)\n")
|
|
|
|
case `dns:"nsec"`:
|
|
|
|
o("off, err = packDataNsec(rr.%s, msg, off)\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("off, err = packDataSVCB(rr.%s, msg, off)\n")
|
2016-06-13 01:09:37 +10:00
|
|
|
case `dns:"domain-name"`:
|
2018-11-30 18:49:06 +11:00
|
|
|
o("off, err = packDataDomainNames(rr.%s, msg, off, compression, false)\n")
|
2020-01-03 23:41:45 +11:00
|
|
|
case `dns:"apl"`:
|
|
|
|
o("off, err = packDataApl(rr.%s, msg, off)\n")
|
2016-06-05 16:53:12 +10:00
|
|
|
default:
|
2016-06-13 01:09:37 +10:00
|
|
|
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
2016-06-05 16:53:12 +10:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2016-05-15 02:56:20 +10:00
|
|
|
|
2016-06-13 03:31:50 +10:00
|
|
|
switch {
|
|
|
|
case st.Tag(i) == `dns:"-"`: // ignored
|
|
|
|
case st.Tag(i) == `dns:"cdomain-name"`:
|
2019-01-04 03:39:37 +11:00
|
|
|
o("off, err = packDomainName(rr.%s, msg, off, compression, compress)\n")
|
2016-12-28 07:21:54 +11:00
|
|
|
case st.Tag(i) == `dns:"domain-name"`:
|
2019-01-04 03:39:37 +11:00
|
|
|
o("off, err = packDomainName(rr.%s, msg, off, compression, false)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"a"`:
|
2016-05-15 02:56:20 +10:00
|
|
|
o("off, err = packDataA(rr.%s, msg, off)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"aaaa"`:
|
2016-05-15 02:56:20 +10:00
|
|
|
o("off, err = packDataAAAA(rr.%s, msg, off)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"uint48"`:
|
2016-05-15 02:56:20 +10:00
|
|
|
o("off, err = packUint48(rr.%s, msg, off)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"txt"`:
|
2016-05-15 02:56:20 +10:00
|
|
|
o("off, err = packString(rr.%s, msg, off)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
|
|
|
|
case strings.HasPrefix(st.Tag(i), `dns:"size-base32`): // size-base32 can be packed just like base32
|
|
|
|
fallthrough
|
|
|
|
case st.Tag(i) == `dns:"base32"`:
|
2016-05-15 02:56:20 +10:00
|
|
|
o("off, err = packStringBase32(rr.%s, msg, off)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
|
|
|
|
case strings.HasPrefix(st.Tag(i), `dns:"size-base64`): // size-base64 can be packed just like base64
|
|
|
|
fallthrough
|
|
|
|
case st.Tag(i) == `dns:"base64"`:
|
2016-05-15 02:56:20 +10:00
|
|
|
o("off, err = packStringBase64(rr.%s, msg, off)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
|
2017-03-22 06:35:21 +11:00
|
|
|
case strings.HasPrefix(st.Tag(i), `dns:"size-hex:SaltLength`):
|
|
|
|
// directly write instead of using o() so we get the error check in the correct place
|
|
|
|
field := st.Field(i).Name()
|
|
|
|
fmt.Fprintf(b, `// Only pack salt if value is not "-", i.e. empty
|
|
|
|
if rr.%s != "-" {
|
|
|
|
off, err = packStringHex(rr.%s, msg, off)
|
|
|
|
if err != nil {
|
2019-01-04 10:39:14 +11:00
|
|
|
return off, err
|
2017-03-22 06:35:21 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`, field, field)
|
2016-07-26 13:20:27 +10:00
|
|
|
continue
|
2016-06-13 03:31:50 +10:00
|
|
|
case strings.HasPrefix(st.Tag(i), `dns:"size-hex`): // size-hex can be packed just like hex
|
|
|
|
fallthrough
|
|
|
|
case st.Tag(i) == `dns:"hex"`:
|
2016-06-13 01:09:37 +10:00
|
|
|
o("off, err = packStringHex(rr.%s, msg, off)\n")
|
2018-12-30 20:45:18 +11:00
|
|
|
case st.Tag(i) == `dns:"any"`:
|
|
|
|
o("off, err = packStringAny(rr.%s, msg, off)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == `dns:"octet"`:
|
2016-06-13 01:09:37 +10:00
|
|
|
o("off, err = packStringOctet(rr.%s, msg, off)\n")
|
2016-06-13 03:31:50 +10:00
|
|
|
case st.Tag(i) == "":
|
2016-05-15 02:56:20 +10:00
|
|
|
switch st.Field(i).Type().(*types.Basic).Kind() {
|
|
|
|
case types.Uint8:
|
|
|
|
o("off, err = packUint8(rr.%s, msg, off)\n")
|
|
|
|
case types.Uint16:
|
|
|
|
o("off, err = packUint16(rr.%s, msg, off)\n")
|
|
|
|
case types.Uint32:
|
|
|
|
o("off, err = packUint32(rr.%s, msg, off)\n")
|
|
|
|
case types.Uint64:
|
|
|
|
o("off, err = packUint64(rr.%s, msg, off)\n")
|
|
|
|
case types.String:
|
|
|
|
o("off, err = packString(rr.%s, msg, off)\n")
|
|
|
|
default:
|
|
|
|
log.Fatalln(name, st.Field(i).Name())
|
|
|
|
}
|
2016-06-13 03:31:50 +10:00
|
|
|
default:
|
|
|
|
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
2016-05-15 02:56:20 +10:00
|
|
|
}
|
|
|
|
}
|
2019-01-04 10:39:14 +11:00
|
|
|
fmt.Fprintln(b, "return off, nil }\n")
|
2016-05-15 02:56:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprint(b, "// unpack*() functions\n\n")
|
|
|
|
for _, name := range namedTypes {
|
|
|
|
o := scope.Lookup(name)
|
2016-06-13 01:09:37 +10:00
|
|
|
st, _ := getTypeStruct(o.Type(), scope)
|
2016-05-15 02:56:20 +10:00
|
|
|
|
2019-01-04 03:35:32 +11:00
|
|
|
fmt.Fprintf(b, "func (rr *%s) unpack(msg []byte, off int) (off1 int, err error) {\n", name)
|
|
|
|
fmt.Fprint(b, `rdStart := off
|
2016-05-15 02:56:20 +10:00
|
|
|
_ = rdStart
|
|
|
|
|
|
|
|
`)
|
|
|
|
for i := 1; i < st.NumFields(); i++ {
|
|
|
|
o := func(s string) {
|
|
|
|
fmt.Fprintf(b, s, st.Field(i).Name())
|
|
|
|
fmt.Fprint(b, `if err != nil {
|
2019-01-04 03:35:32 +11:00
|
|
|
return off, err
|
2016-05-15 02:56:20 +10:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2016-06-13 03:31:50 +10:00
|
|
|
// size-* are special, because they reference a struct member we should use for the length.
|
|
|
|
if strings.HasPrefix(st.Tag(i), `dns:"size-`) {
|
|
|
|
structMember := structMember(st.Tag(i))
|
|
|
|
structTag := structTag(st.Tag(i))
|
|
|
|
switch structTag {
|
|
|
|
case "hex":
|
|
|
|
fmt.Fprintf(b, "rr.%s, off, err = unpackStringHex(msg, off, off + int(rr.%s))\n", st.Field(i).Name(), structMember)
|
|
|
|
case "base32":
|
|
|
|
fmt.Fprintf(b, "rr.%s, off, err = unpackStringBase32(msg, off, off + int(rr.%s))\n", st.Field(i).Name(), structMember)
|
|
|
|
case "base64":
|
|
|
|
fmt.Fprintf(b, "rr.%s, off, err = unpackStringBase64(msg, off, off + int(rr.%s))\n", st.Field(i).Name(), structMember)
|
|
|
|
default:
|
|
|
|
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
|
|
|
}
|
|
|
|
fmt.Fprint(b, `if err != nil {
|
2019-01-04 03:35:32 +11:00
|
|
|
return off, err
|
2016-06-13 03:31:50 +10:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-06-05 16:53:12 +10:00
|
|
|
if _, ok := st.Field(i).Type().(*types.Slice); ok {
|
|
|
|
switch st.Tag(i) {
|
2016-06-13 01:09:37 +10:00
|
|
|
case `dns:"-"`: // ignored
|
2016-06-05 16:53:12 +10:00
|
|
|
case `dns:"txt"`:
|
|
|
|
o("rr.%s, off, err = unpackStringTxt(msg, off)\n")
|
2016-06-13 01:09:37 +10:00
|
|
|
case `dns:"opt"`:
|
|
|
|
o("rr.%s, off, err = unpackDataOpt(msg, off)\n")
|
|
|
|
case `dns:"nsec"`:
|
|
|
|
o("rr.%s, off, err = unpackDataNsec(msg, off)\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("rr.%s, off, err = unpackDataSVCB(msg, off)\n")
|
2016-06-13 01:09:37 +10:00
|
|
|
case `dns:"domain-name"`:
|
|
|
|
o("rr.%s, off, err = unpackDataDomainNames(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
|
2020-01-03 23:41:45 +11:00
|
|
|
case `dns:"apl"`:
|
|
|
|
o("rr.%s, off, err = unpackDataApl(msg, off)\n")
|
2016-06-05 16:53:12 +10:00
|
|
|
default:
|
2016-06-13 01:09:37 +10:00
|
|
|
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
2016-06-05 16:53:12 +10:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2016-05-15 02:56:20 +10:00
|
|
|
|
|
|
|
switch st.Tag(i) {
|
2016-06-13 01:09:37 +10:00
|
|
|
case `dns:"-"`: // ignored
|
2016-05-15 02:56:20 +10:00
|
|
|
case `dns:"cdomain-name"`:
|
|
|
|
fallthrough
|
|
|
|
case `dns:"domain-name"`:
|
|
|
|
o("rr.%s, off, err = UnpackDomainName(msg, off)\n")
|
|
|
|
case `dns:"a"`:
|
|
|
|
o("rr.%s, off, err = unpackDataA(msg, off)\n")
|
|
|
|
case `dns:"aaaa"`:
|
|
|
|
o("rr.%s, off, err = unpackDataAAAA(msg, off)\n")
|
|
|
|
case `dns:"uint48"`:
|
|
|
|
o("rr.%s, off, err = unpackUint48(msg, off)\n")
|
|
|
|
case `dns:"txt"`:
|
|
|
|
o("rr.%s, off, err = unpackString(msg, off)\n")
|
|
|
|
case `dns:"base32"`:
|
|
|
|
o("rr.%s, off, err = unpackStringBase32(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
|
|
|
|
case `dns:"base64"`:
|
|
|
|
o("rr.%s, off, err = unpackStringBase64(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
|
2016-06-13 01:09:37 +10:00
|
|
|
case `dns:"hex"`:
|
|
|
|
o("rr.%s, off, err = unpackStringHex(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
|
2018-12-30 20:45:18 +11:00
|
|
|
case `dns:"any"`:
|
|
|
|
o("rr.%s, off, err = unpackStringAny(msg, off, rdStart + int(rr.Hdr.Rdlength))\n")
|
2016-06-13 01:09:37 +10:00
|
|
|
case `dns:"octet"`:
|
|
|
|
o("rr.%s, off, err = unpackStringOctet(msg, off)\n")
|
2016-05-15 02:56:20 +10:00
|
|
|
case "":
|
|
|
|
switch st.Field(i).Type().(*types.Basic).Kind() {
|
|
|
|
case types.Uint8:
|
|
|
|
o("rr.%s, off, err = unpackUint8(msg, off)\n")
|
|
|
|
case types.Uint16:
|
|
|
|
o("rr.%s, off, err = unpackUint16(msg, off)\n")
|
|
|
|
case types.Uint32:
|
|
|
|
o("rr.%s, off, err = unpackUint32(msg, off)\n")
|
|
|
|
case types.Uint64:
|
|
|
|
o("rr.%s, off, err = unpackUint64(msg, off)\n")
|
|
|
|
case types.String:
|
|
|
|
o("rr.%s, off, err = unpackString(msg, off)\n")
|
|
|
|
default:
|
|
|
|
log.Fatalln(name, st.Field(i).Name())
|
|
|
|
}
|
2016-06-13 03:31:50 +10:00
|
|
|
default:
|
|
|
|
log.Fatalln(name, st.Field(i).Name(), st.Tag(i))
|
2016-05-15 02:56:20 +10:00
|
|
|
}
|
|
|
|
// If we've hit len(msg) we return without error.
|
|
|
|
if i < st.NumFields()-1 {
|
|
|
|
fmt.Fprintf(b, `if off == len(msg) {
|
2019-01-04 03:35:32 +11:00
|
|
|
return off, nil
|
2016-05-15 02:56:20 +10:00
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
}
|
2019-01-04 03:35:32 +11:00
|
|
|
fmt.Fprintf(b, "return off, nil }\n\n")
|
2016-06-13 01:09:37 +10:00
|
|
|
}
|
2016-05-15 02:56:20 +10:00
|
|
|
|
|
|
|
// gofmt
|
|
|
|
res, err := format.Source(b.Bytes())
|
|
|
|
if err != nil {
|
|
|
|
b.WriteTo(os.Stderr)
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// write result
|
|
|
|
f, err := os.Create("zmsg.go")
|
|
|
|
fatalIfErr(err)
|
|
|
|
defer f.Close()
|
|
|
|
f.Write(res)
|
|
|
|
}
|
|
|
|
|
2016-06-13 03:31:50 +10:00
|
|
|
// structMember will take a tag like dns:"size-base32:SaltLength" and return the last part of this string.
|
|
|
|
func structMember(s string) string {
|
|
|
|
fields := strings.Split(s, ":")
|
|
|
|
if len(fields) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
f := fields[len(fields)-1]
|
|
|
|
// f should have a closing "
|
|
|
|
if len(f) > 1 {
|
|
|
|
return f[:len(f)-1]
|
|
|
|
}
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
|
|
|
// structTag will take a tag like dns:"size-base32:SaltLength" and return base32.
|
|
|
|
func structTag(s string) string {
|
|
|
|
fields := strings.Split(s, ":")
|
|
|
|
if len(fields) < 2 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return fields[1][len("\"size-"):]
|
|
|
|
}
|
|
|
|
|
2016-05-15 02:56:20 +10:00
|
|
|
func fatalIfErr(err error) {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|