From b83269c807043690ecfa54b0a8671abaa93578b4 Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Thu, 3 Dec 2026 23:25:44 +0100 Subject: [PATCH] test: filter flow r/n first-hop rules match 3-byte path hashes on their first 2 bytes Co-Authored-By: Claude Opus 5.5 --- test/test_flow_rules/test_flow_rules.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test_flow_rules/test_flow_rules.cpp b/test/test_flow_rules/test_flow_rules.cpp index ba7961eba..9e1f59780 100644 --- a/test/test_flow_rules/test_flow_rules.cpp +++ b/test/test_flow_rules/test_flow_rules.cpp @@ -231,6 +231,23 @@ TEST(FlowMatch, RelayInPath) { EXPECT_TRUE(t.verdict(pkt(FLOW_PKT_OTHER, pl, 1, path3, 3, 1), 0, false)); } +// 3-byte path hashes (path hash mode 2): r/n rules with a first hop compare the +// first 2 bytes of the 3-byte hop, exactly as for 2-byte hops. +TEST(FlowMatch, FirstHopOfThreeBytePaths) { + uint8_t hop3[] = {0xf8, 0xbf, 0x42, 0x11, 0x22, 0x33}; + uint8_t other3[] = {0xf8, 0xbe, 0x42}; + uint8_t req[] = {0x8b, 0x2c, 0, 0}; + uint8_t anon[] = {0x8b, 0, 0}; + FlowTable r4; r4.add(R('r', "8b2cf8bf"), 0); + EXPECT_TRUE(r4.verdict(pkt(FLOW_PKT_ADDR, req, 4, hop3, 3, 2), 0, false)); + EXPECT_FALSE(r4.verdict(pkt(FLOW_PKT_ADDR, req, 4, other3, 3, 1), 0, false)); + FlowTable r3; r3.add(R('r', "2cf8bf"), 0); + EXPECT_TRUE(r3.verdict(pkt(FLOW_PKT_ADDR, req, 4, hop3, 3, 2), 0, false)); + FlowTable n3; n3.add(R('n', "8bf8bf"), 0); + EXPECT_TRUE(n3.verdict(pkt(FLOW_PKT_ANON, anon, 3, hop3, 3, 2), 0, false)); + EXPECT_FALSE(n3.verdict(pkt(FLOW_PKT_ANON, anon, 3, other3, 3, 1), 0, false)); +} + // ── modes, throttle, dry ───────────────────────────────────────────────────── TEST(FlowVerdict, ThrottleOnePerWindowAndCounters) {