Repository navigation
fix: keep renamed first labels within 63 bytes on the wire - #554
Conversation
65c519b to
674afe4
Compare
|
Thank you for working on this. When it's ready for review, please click "Ready for review". Here are some preliminary comments:
|
…ister() Addresses review on keepsimple1#554. - check_hostname now rejects any label over MAX_LABEL_BYTES on the wire, the same condition write_name enforces per label. This fixes the pre-existing silent failure where a hostname with an oversized label registered fine and was never sent. Labels are measured via EscapedLabels + escaped_label_wire_len (de-cfg(test)) so \. and \\ resolve like parse_escaped_name. - register() now runs check_instance_label_length up front and returns the error directly, instead of only reporting it on the monitor channel from inside the daemon. The daemon-side check is kept for internal call paths. - Corrected the name_change/hostname_change comments: trailing whitespace and '-' are trimmed unconditionally, not only to fix a double-space/double-dash artifact. - Tests: check_hostname label cases (the previous 255-byte single-label "valid" case could never be written on the wire; replaced with an equal-length multi-label name), and register() rejecting oversized instance/hostname labels. AI assistance: Cognition Devin CLI agent (SWE-2 High).
|
Thanks for the preliminary review — all three points addressed in eadab8e.
(AI assistance: Cognition Devin CLI agent.) |
When a probe conflict triggers name_change/hostname_change, the appended ` (n)`/`-n` suffix can push the first label past MAX_LABEL_BYTES, after which write_name rejects every packet and the service silently vanishes. Shorten the base so the label with the new suffix still fits, like mDNSResponder: measure wire bytes via escape-aware helpers in dns_parser.rs (\. and \\ count as one byte, never cut inside a pair or a UTF-8 char), trim a trailing space/`-`, and recompute on every rename as ` (9)` -> ` (10)` grows the suffix. register_service now rejects an instance label over 63 wire bytes up front instead of failing silently on the network. Fixes keepsimple1#549. Rebased onto main @ e5ee843 (keepsimple1#553, keepsimple1#555): test imports union upstream's new_multicast_socket with this change's check_instance_label_length. AI assistance: Cognition Devin CLI agent (SWE-2 High).
…ister() Addresses review on keepsimple1#554. - check_hostname now rejects any label over MAX_LABEL_BYTES on the wire, the same condition write_name enforces per label. This fixes the pre-existing silent failure where a hostname with an oversized label registered fine and was never sent. Labels are measured via EscapedLabels + escaped_label_wire_len (de-cfg(test)) so \. and \\ resolve like parse_escaped_name. - register() now runs check_instance_label_length up front and returns the error directly, instead of only reporting it on the monitor channel from inside the daemon. The daemon-side check is kept for internal call paths. - Corrected the name_change/hostname_change comments: trailing whitespace and '-' are trimmed unconditionally, not only to fix a double-space/double-dash artifact. - Tests: check_hostname label cases (the previous 255-byte single-label "valid" case could never be written on the wire; replaced with an equal-length multi-label name), and register() rejecting oversized instance/hostname labels. Rebased onto main @ e5ee843. AI assistance: Cognition Devin CLI agent (SWE-2 High).
eadab8e to
cb4ab7c
Compare
Fix rustdoc `private_intra_doc_links` failure: drop the intra-doc link brackets around `MAX_LABEL_BYTES` in the public `register`/`resolve_hostname` error docs (the constant is pub(crate), so the links do not resolve under `-D warnings`). AI assistance: Cognition Devin CLI agent (SWE-2 High).
keepsimple1
left a comment
There was a problem hiding this comment.
Overall looks good! Please see inline comments, and consider refresh PR description once the diff updates. Thanks!
| /// - `hostname` is exactly `.local.` (the label before `.local.` is empty); | ||
| /// - `hostname` is longer than 255 bytes. | ||
| /// - `hostname` is longer than 255 bytes; | ||
| /// - a label of `hostname` is longer than `MAX_LABEL_BYTES` bytes on the wire. |
There was a problem hiding this comment.
nitpick: MAX_LABEL_BYTES is not public so the user cannot look it up. Writing 63 bytes would be clearer.
- Write the literal limit (63 bytes) in the public doc comments for register() and resolve_hostname() instead of the crate-private MAX_LABEL_BYTES, which users cannot look up. - Drop the redundant instance-label check inside register_service; register() now rejects oversized labels before the command reaches the daemon. - Delete first_label_wire_len, which duplicated escaped_label_wire_len; check_instance_label_length now uses split_first_label() + escaped_label_wire_len as suggested. AI assistance: Cognition Devin CLI agent (SWE-2 High).
|
Thanks for the review — all five comments addressed in 8a39320.
|
What
When a probe conflict triggers
name_change/hostname_change, the appended(n)/-nsuffix can push the first label past 63 bytes.write_namethen returnsNameTooLongfor every probe and announcement, so the renamed service never reaches the network and the app gets no error.This makes the rename shorten the base so the label with its new suffix still fits, like mDNSResponder does:
MAX_LABEL_BYTESis nowpub(crate)and reused byservice_daemon.dns_parser.rs, following the same rules asparse_escaped_name(\.and\\each count as one wire byte; any other\xkeeps its backslash literal):truncate_label_to_wire_len(never cuts inside an escape pair or a UTF-8 character) andescaped_label_wire_len.63 - suffix.len()wire bytes on every rename, since(9)->(10)and-9->-10grow the suffix. A trailing space (name_change) or-(hostname_change) left by the cut is trimmed, avoidingFoo (2)/foo--2.register()runscheck_instance_label_length(built onsplit_first_label+escaped_label_wire_len) and returns the error directly, so an instance label over 63 wire bytes fails at API time instead of silently at announcement time.check_hostnamenow rejects any label over 63 wire bytes — the same per-label conditionwrite_nameenforces — fixing a pre-existing gap where a hostname with an oversized label registered fine and was never sent. Coversregister()andresolve_hostname().Fixes #549.
Testing
New regressions in
service_daemon::testsanddns_parser::tests, all red before the fix:59 + " (2)";(9)->(10)at the limit trims one more base byte;-9->-10likewise.hostname_changewith a 63-byte first label; trailing-trimmed.check_instance_label_length: ok at 63, err at 64, and escaped-dot boundary cases.check_hostnamelabel cases, andregister()rejecting oversized instance / hostname labels.<= 63bytes.cargo test --lib117/117,cargo test --doc5/5,cargo clippy --all-targetsclean,cargo fmtapplied (cargo 1.97.1, macOS arm64). MSRV is Rust 1.71; only long-stable APIs are used, and MSRV CI covers it. Physical multi-host conflict renames are not covered here.Notes
EscapedLabels/split_first_label): label splitting and wire-length measurement share one escape-aware implementation.AI assistance: Cognition Devin CLI agent (SWE-2 High).