refactor(dpi/mqtt): include UNSUBSCRIBE in flag-validation match#294
Merged
domcyrus merged 1 commit intoMay 20, 2026
Merged
Conversation
The flag-validation block in `is_mqtt_packet` listed UNSUBSCRIBE(10)
in the inner expected-flag table (`8 | 10 => 0x02`) but not in the
outer match arm, so packet type 10 never reached the inner table and
its required `0x02` flag bit was never checked. The fall-through
arm's comment ("PUBLISH(3), PUBREC(5) — flags carry DUP/QoS/RETAIN")
was inadvertently also accepting UNSUBSCRIBE despite that not being
the documented intent.
Add 10 to the outer match so the validation actually applies, and
reformat the inline comment so each entry has a single source of
truth. `is_mqtt_packet` still only returns true for CONNECT (the
only packet type with a port-independent signature), so this change
is invariant-preserving — it removes an unreachable branch and
restores the stated MQTT §2.1.2 invariant for callers that may later
relax that gate.
Owner
|
@obchain thanks a lot also for this PR. LGTM! |
This was referenced May 21, 2026
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.
Summary
Adds
10(UNSUBSCRIBE) to the outermatcharm inis_mqtt_packet(src/network/dpi/mqtt.rs:19) so the inner8 | 10 => 0x02flag-validation rule actually runs for that packet type.Closes #293.
Why
The outer arm previously listed
1 | 2 | 4 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14— note 10 missing. UNSUBSCRIBE fell into the_ => {}catch-all (intended for PUBLISH/PUBREC's flexible nibble), which silently accepted any flag value despite the inner table claiming UNSUBSCRIBE requires0x02. The10 => 0x02arm was unreachable.This is invariant-preserving:
is_mqtt_packetstill returns true only for CONNECT (the strong-signature gate at line 52 is unchanged), so no caller sees a behavior change today. It restores the MQTT §2.1.2 invariant the comment promises and removes a misleading unreachable arm, in the same spirit as the recentrefactor(dpi/...)cleanups (#279, #289, #290).I also reformatted the inline comment for readability — same content, one source of truth per packet type.
Test plan
cargo clippy --all-targets --all-features -- -D warnings— cleancargo fmt --check— cleancargo test --lib mqtt— 21 mqtt tests pass, no regressionscargo test --lib— full 361-test suite passes