Skip to content

feat: limit generated packet size per RFC 6762 section 17 - #487

Open
keepsimple1 wants to merge 3 commits into
mainfrom
max-packet-size
Open

feat: limit generated packet size per RFC 6762 section 17#487
keepsimple1 wants to merge 3 commits into
mainfrom
max-packet-size

Conversation

@keepsimple1

@keepsimple1 keepsimple1 commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Fixes #468

  • The default max packet size for outgoing messages are now 1452 bytes that fits Ethernet MTU.
  • A new API ServiceDaemon::set_max_packet_size() to change that value for given interface(s).

Also on the receive side:

  • IPv4 and IPv6 are handled separately to meet 9000 bytes max per RFC.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated packets could be too big

1 participant