Skip to content

Keep a valid RFC 5837 object when a malformed one claims its role first - #175

Merged
lance0 merged 2 commits into
masterfrom
fix/rfc5837-parser-edge-cases
Nov 14, 2026
Merged

lance0 merged 2 commits into
masterfrom
fix/rfc5837-parser-edge-cases

Conversation

@lance0

@lance0 lance0 commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Symptom

A router that sends a malformed RFC 5837 Interface Information Object followed by a well-formed object with the same role loses both. With the fake router sending a broken incoming-role object ahead of the real one, hop 1 shows only the outgoing interface.

Root cause

parse_icmp_extensions keeps the first object per role and ignores repeats (a deliberate leniency vs RFC 5837 §4.5). It set the role bit in seen_roles before parsing the object. A first object that turned out malformed (truncated ifIndex/IP/name/MTU, or unknown AFI) was dropped but still held the role, so the valid repeat was skipped too. That contradicts the comment's intent of keeping trace data from a buggy router.

Fix

Set the role bit only when the object is pushed. Two-line move plus a comment line.

Tests

  • test_rfc5837_malformed_first_does_not_block_duplicate_role: a role-0 object that claims ifIndex + IP but carries only the ifIndex, then a valid role-0 object with ifIndex 200. Fails on master (interface_info is None), passes with the fix.
  • test_rfc5837_role_only_object: pins current behavior for a C-Type with only role bits set (header-only object). It produces one entry with every field None, and the JSON is {"role":"outgoing_ip"}. The TUI hop detail and the text report already render this as (no details). No behavior change.
  • fmt, clippy (default and --no-default-features), and cargo test all pass.

End-to-end (scripts/fakertr)

Added FAKERTR_BAD_FIRST=1 to the fake router, which puts a malformed incoming-role object (ifIndex 99, IP flag set but no IP) ahead of the valid one. --json, hop 1 interface_info:

  • master: outgoing_ip Ethernet2@fake-rt1 only; the incoming interface is lost
  • this branch: incoming_ip Ethernet1@fake-rt1 (ifIndex 1, MTU 1500) + outgoing_ip Ethernet2@fake-rt1
  • control without the toggle: both interfaces on this branch, same as before

Not changed: per-field salvage

I considered keeping the fields that come before a broken sub-object (for example ifIndex and IP when the name length overruns), but decided against it. A length mismatch means the C-Type flags and the payload disagree. That makes the earlier bytes untrustworthy as well, since a wrong flag shifts every offset. A partial entry would also show name as absent, which looks the same as a router that never sent a name. Dropping the whole object is the honest result, and with this fix a well-formed repeat still gets through.

The parser keeps the first Interface Information Object per role and
ignores repeats, but it set the role bit before parsing the object. A
truncated first object (or one with an unknown AFI) was dropped and still
blocked a well-formed repeat. Claim the role only when the object is pushed.

Add a regression test for malformed-then-valid, pin the role-only C-Type
(no field flags) behavior, and add a FAKERTR_BAD_FIRST toggle to the fake
router for an end-to-end check.
@lance0
lance0 marked this pull request as ready for review November 14, 2026 20:17
@lance0
lance0 merged commit 66140ab into master Nov 14, 2026
7 checks passed
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.

1 participant