-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Instead of removing all RRs on Truncated, attempt to unpack #281
Conversation
Nice!
So if a server sends a truncated response, but it just happens to fall within an RRset boundery no error is returned? If think in that case we should still return ErrTruncated... |
I've updated the PR and made it so it will return an I've updated the tests to test for both of those cases. |
@@ -1396,6 +1399,32 @@ func UnpackRR(msg []byte, off int) (rr RR, off1 int, err error) { | |||
return rr, off, err | |||
} | |||
|
|||
// UnpackRRArr unpacks msg[off:] into an []RR. | |||
// If we cannot unpack the whole array, then it will return nil | |||
func UnpackRRArr(l int, msg []byte, off int) (dst1 []RR, off1 int, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unpackRRslice? Also don't think this needs to be exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, I only exported it because UnpackRR
was exported.
Okay I just updated the PR and addressed your comments. |
Instead of removing all RRs on Truncated, attempt to unpack
I'm not so sure that erroring on a correctly-decoded response that the server declared to be truncated is correct. Suppose someone is using DNS for load-spreading, and has many machines behind the same name; do you want users of your library to receive an error purely dependent on the value of 'many' compared to the size of their UDP buffer? |
But if you don't make it an error you can get the situation where a response happens to be correctly decoded (because the last RR just ended on byte 512 for example), while in other cases the parsing would fail and you would return an error. I don't understand your example. |
OK, maybe I misunderstand the behaviour of DNS servers; does the |
I'm not sure actually. Think it is left to the server implementation which could do either. This is one of those times when (DNS) people do the "Let's see what BIND does" |
From RFC2181
So clients should not be looking at the contents when TC is set. No idea whether that reflects reality. |
A partial RRset means the packet should be completely valid. Dunno... think the current approach is most sensible @bboreham. Willing to drop the if truncated then err, but I think that is more complex than just always returning |
says who? |
I think I read that in "the partial RRSet", i.e the RRset is partial, but the RRs in the set are complete. |
This Pull Request fixes the
TODO(miek): this isn't the best strategy!
regardingTruncated
messages received. Instead of just returning no RRs it's now attempting to do as many RRs as possible until it gets an error then returningErrTruncated
along with the partial response. This allows someone to naively just checkerr != nil
if they didn't know about truncated messages or someone could check iferr == ErrTruncated
additionally and proceed with the truncated response if they're okay with a truncated response.More realistically, I don't think servers will be returning partial responses (like how skydns removes the
Extra
first), but it supports that. If a non-partial response is returned (that was truncated) then no error is returned. I can make it still return aErrTruncated
but since there was no error unpacking the message, I didn't think it made sense to return an error.