Page MenuHomeFreeBSD

pf: Fix rule and state counters
ClosedPublic

Authored by vegeta_tuxpowered.net on Sep 9 2025, 1:22 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 10, 10:09 PM
Unknown Object (File)
Fri, Oct 10, 10:09 PM
Unknown Object (File)
Fri, Oct 10, 10:09 PM
Unknown Object (File)
Fri, Oct 10, 10:09 PM
Unknown Object (File)
Fri, Oct 10, 4:13 PM
Unknown Object (File)
Fri, Oct 3, 4:46 PM
Unknown Object (File)
Thu, Oct 2, 5:03 PM
Unknown Object (File)
Sun, Sep 28, 3:22 PM

Details

Summary

Increasing counters on "match" rules causes the 1st packet making a
connection to be double-counted, but only for rule counters, not rules'
tables, because those are not increased at all during rule parsing. Remove
"match" rule counter handling during rule parsing, do it only in
pf_counters_inc().

NAT can be performed either by "nat" rules in the NAT ruleset or by "match"
rules. Rules before the NAT rule, and the NAT rule itself match on pre-NAT
addresses, and later rules match on post-NAT addresses. When increasing
counters go over rules in the same order as a packet would and use source
and destination addresses for updating table counters from appropriate state
key, taking into consideration on which rule NAT happens.

Use AF from state key, so that table counters can be properly updated for
af-to rules.

Synchronize match rule updating behaviour to that of OpenBSD: if rules
match, but state is not created, don't update counters.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/netpfil/pf/pf.c
5795

This line is identical in if and else, perhaps it belongs outside the if block?

vegeta_tuxpowered.net marked an inline comment as done.
vegeta_tuxpowered.net added inline comments.
sys/netpfil/pf/pf.c
5795

Fixed.

This revision is now accepted and ready to land.Wed, Sep 24, 11:38 AM
This revision was automatically updated to reflect the committed changes.
vegeta_tuxpowered.net marked an inline comment as done.