feat: limit generated packet size per RFC 6762 section 17 - #487
Open
keepsimple1 wants to merge 3 commits into
Open
feat: limit generated packet size per RFC 6762 section 17#487keepsimple1 wants to merge 3 commits into
keepsimple1 wants to merge 3 commits into
Conversation
Generated packets were capped only by MAX_MSG_ABSOLUTE (8972 bytes), well past a typical 1500-byte MTU. Such a packet is fragmented by the IP layer, which section 17 forbids for a multi-record message: "A Multicast DNS packet larger than the interface MTU, which is sent using fragments, MUST NOT contain more than one resource record." Fragments are also widely dropped, as "many simple devices do not reassemble fragmented IP datagrams". Outgoing messages are now limited to MAX_MSG_MTU_SAFE (1452 bytes = 1500 - 40 IPv6 header - 8 UDP header), with ServiceDaemon::set_max_packet_size() to raise it on links known to carry bigger frames. Lowering the limit made overflow routine, so the encoder had to stop discarding what did not fit. to_packets() previously dropped any question, answer, or authority that overflowed, and only spilled additionals, for queries alone. It is now a fill-and-flush loop over all four sections: an item that does not fit is retried in a fresh packet, so nothing is lost. A single record too big for an otherwise empty packet is sent alone in an oversized packet, as section 17 both permits and requires. The TC bit is now set on every packet but the last of a multi-packet query, per section 7.2, and never on a response, per section 18.5: "In multicast response messages, the TC bit MUST be zero on transmission." The previous TC path was unreachable, since known answers go to the answer section while only the additionals loop split. Also on the receive side: - MAX_MSG_ABSOLUTE is now 8952, computed with the IPv6 header (9000 - 40 - 8) rather than the IPv4 one. Section 17's 9000-byte cap includes the IP and UDP headers, so 8972 let an IPv6 packet reach 9008 bytes. This also makes the outgoing send guards compliant over IPv6. - An incoming datagram over the limit is dropped instead of parsed. The socket layer truncates it, and a truncated message does not fail cleanly: names run into whatever bytes follow, yielding bogus records or confusing parse errors. The receive buffer is one byte larger than the limit so that an over-sized datagram can be told apart from a legal one exactly at it. One deliberate behavior change: a response now spills its additional records into another packet rather than dropping them, per RFC 6763 section 12. Closes #468
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #468
ServiceDaemon::set_max_packet_size()to change that value for given interface(s).Also on the receive side: