Repository navigation
pbr-1.2.4: count Tor connections only after all rule matches - #191
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Thanks for this, and for the thorough testing. The fix is right: counting has to happen after the port match, directly before For transparency: we had an equivalent fix for #188 on a local branch, built as Independent confirmation on real hardware (OpenWrt 25.12, nftables 1.1.6), with a Tor policy for a real LAN client and a burst of 3 DNS queries, 2 HTTP connections and 1 HTTPS connection:
One detail that complements your 36-vs-1 finding: on a real router the released counters aren't all equal, they step down. One request before merging: could you drop With that removed, this is good to go from our side. The CI run here passes as well. |
The Tor emitter puts counter before family and address matches, so unrelated connections increment every visited rule. Moving it only past the address still counts unmatched protocols and ports. Place it after the final dport match and before redirect. Add a 24-check regression using the existing emitter and test runner, covering IPv4 and IPv6 rules. It passes only 14/24 checks without the fix. Keep privileged kernel integration testing in independent validation records rather than the upstream unit-test tree. Signed-off-by: Yuen Su <zypulsecore@gmail.com>
5ebe0ee to
e33109b
Compare
|
Thanks ! |
Thanks for the review and helpful feedback! Glad I could contribute. |
With nft_rule_counter enabled, the Tor NAT rules increment their counters before checking the address, transport protocol and destination port. Unrelated connections therefore increment every rule they reach. Move rule_params after the final protocol/dport match, immediately before redirect; the redirect targets and counter-disabled output stay unchanged.
Keep the 24-check IPv4/IPv6 emitter regression in the existing unit-test runner. As requested, this revision removes tests/kernel/ and the TOR_COUNTER_EMIT mode from the ordinary test. The PR now changes only the emitter and its unit test.
Validation:
The earlier isolated kernel validation and original integration-test source remain available as independent records outside this PR's diff. That run exercised the ten actual emitted IPv4/IPv6 rules with 36 controlled connections and reproduced the original failure. The production emitter in this revision is byte-for-byte identical to that tested fix. NAT-chain counters here count connections; this was not a Tor-daemon or deployed-router test.
Developed with AI assistance; validation claims above refer to executed tests.
Fixes #188