Repository navigation
Description
The rule for where a label ends in an escaped name (RFC 6763 §4.3) is now written out in two places:
DnsOutPacket::parse_escaped_name(src/dns_parser.rs) splits a name into unescaped labels forwrite_name. It treats only\.and\\as escapes. Any other\xstays as a literal backslash followed byx.split_first_label(src/service_daemon.rs, added in fix: keep escaped dots inside first label in name_change/hostname_change (fix #546) #547) finds the first unescaped dot forname_changeandhostname_change. It treats a backslash as escaping whatever character follows it.
Today both give the same label boundaries for every input. The two scanners disagree only on \ followed by a character other than . or \, and that never decides where a label ends. But they agree by coincidence, not by design. If one changes (for example, to support RFC 1035 \DDD decimal escapes) and the other doesn't, the rename code and the wire encoder will split names differently. That is the failure #546 fixed: a renamed record goes out with an extra label.
#549 would add a third function that needs the same rules: measuring a label's length on the wire so a renamed label can be cut to 63 bytes.
Why not call parse_escaped_name from split_first_label?
- It returns unescaped labels.
name_changeneeds the escaped form and its byte offsets so it can keep the rest of the name exactly as it is. Escaping the output again doesn't give the original back: a non-standard\xcomes back as\\x, which changes the stored name. - It drops empty labels. For
._lara._tcp.local.it reports_laraas the first label instead of"".
Suggested approach
Add one pub(crate) helper in dns_parser.rs that works on the escaped string and returns where each label starts and ends. It could be an iterator over escaped label slices, or a function that returns the byte offset of each unescaped dot. Each part of the escape rules then lives in exactly one place:
parse_escaped_nameunescapes each slice and skips the empty ones.split_first_labeltakes the first boundary (or is replaced by the helper).- The label-length check from name_change/hostname_change can make a first label longer than 63 bytes #549 adds up the wire length of each slice.
Tests
- Both callers find the same unescaped-dot positions for
a\.b,a\\.b,a\x.b,a\\\.b, a trailing\, a leading., and... (parse_escaped_namethen drops the empty labels.) - Existing
test_name_change,test_hostname_changeandwrite_nametests still pass.
Activity
refactor: share one escape-aware label splitter
keepsimple1 commentedon Nov 19, 2026
Fixed by #547