Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/net/dns/dnsmessage: use UnknownResource for an unrecognized DNS type #42128

Closed
ianlancetaylor opened this issue Oct 21, 2020 · 10 comments
Closed

Comments

@ianlancetaylor
Copy link
Contributor

This is a proposal for the already written https://golang.org/cl/262037. The proposal is to change methods like (*Parser).Answer and (*Parser).Additional such that when they see a resource that is not specifically recognized by the package, then rather than return an error, they return a Resource of type UnknownResource.

// An UnknownResource is a catch-all container for unknown record types.
type UnknownResource struct {
	Type uint16
	Data []byte
}

Filing a proposal as this is new API.

CC @iangudger

@ianlancetaylor ianlancetaylor added this to the Proposal milestone Oct 21, 2020
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Oct 21, 2020
@iangudger
Copy link
Contributor

LGTM

@tmthrgd
Copy link
Contributor

tmthrgd commented Oct 23, 2020

The Type field should be of type Type (say that quickly) rather than an untyped uint16. ResourceHeader already has:

type ResourceHeader struct {
...
    // Type is the type of DNS resource record.
    //
    // This field will be set automatically during packing.
    Type Type
...
}

It should also be possible to add an UnknownResource to a Builder, otherwise you can't parse and then reassemble a message containing an unknown RR using that API (only with Message?).

This is definitely a good addition though, miekg/dns (of which I contribute) has similar support for unknown RRs with a type RFC3597 struct that can be both packed and unpacked.

@dmcardle
Copy link

Thanks, Tom!

I've switched the uint16 to Type and added UnknownResource functions to Parser and Builder.

Here's the diff for those changes: https://go-review.googlesource.com/c/net/+/262037/6..8

@dmcardle
Copy link

It's been brought to my attention that this design might be a compatibility issue when adding support for new RR types.

Rather than adding an UnknownResource, we could add a Raw []byte field to ResourceHeader. When an RR is unparseable, the ResourceBody would just be nil.

Suppose a user of this API wants to support a new RR type, such as draft-ietf-dnsop-svcb-https-01. If the caller relies on UnknownResource to catch the new record, adding explicit support for the new record to dnsmessage would break the user's code.

If their code instead branched on Type == newRRType and read the ResourceHeader.Raw bytes, it would not be broken when dnsmessage adds support for the new RR type.

@iangudger
Copy link
Contributor

In my opinion, code that relies on UnknownResource like that should use the Parser. There is no compatibility guarantee for this package and the ResourceHeader.Raw solution will still likely break applications which don't follow best practices when adding RR types. I think the solution is to detail contracts and best practices in comments

@rsc rsc moved this from Incoming to Active in Proposals (old) Nov 18, 2020
@rsc
Copy link
Contributor

rsc commented Nov 18, 2020

Adding to minutes but it seems headed for likely accept.

@rsc
Copy link
Contributor

rsc commented Dec 2, 2020

Based on the discussion, this seems like a likely accept.

@rsc rsc moved this from Active to Likely Accept in Proposals (old) Dec 2, 2020
@rsc
Copy link
Contributor

rsc commented Dec 9, 2020

No change in consensus, so accepted.

@rsc rsc moved this from Likely Accept to Accepted in Proposals (old) Dec 9, 2020
@rsc rsc changed the title proposal: x/net/dns/dnsmessage: use UnknownResource for an unrecognized DNS type x/net/dns/dnsmessage: use UnknownResource for an unrecognized DNS type Dec 9, 2020
@rsc rsc modified the milestones: Proposal, Backlog Dec 9, 2020
@dmcardle
Copy link

I'm surprised this issue didn't get auto-closed yesterday when the change landed: golang/net@cd0ac97.

@ianlancetaylor
Copy link
Contributor Author

Whoops, the line in the CL should have been Fixes golang/go#42128.

@golang golang locked and limited conversation to collaborators Mar 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

6 participants