Page MenuHomeFreeBSD

Refactor ipfw dynamic states in preparation for new features (and slighlty optimize)
Needs ReviewPublic

Authored by lev on Jul 6 2019, 6:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Nov 24 2024, 1:16 PM
Unknown Object (File)
Oct 5 2024, 9:54 PM
Unknown Object (File)
Oct 5 2024, 9:40 AM
Unknown Object (File)
Oct 2 2024, 11:11 PM
Unknown Object (File)
Oct 2 2024, 5:18 PM
Unknown Object (File)
Oct 1 2024, 10:35 PM
Unknown Object (File)
Sep 22 2024, 3:24 AM
Unknown Object (File)
Sep 11 2024, 3:30 PM
Subscribers

Details

Summary

This change is functional no-op, but it change way of representing and processing dynamic states in IPFW.
New code is OOP-like and creates states from set of structures, such "header", "IPv4 addresses", "state data", which are assembled to state size by enclosing struct. It looks like ipfw_insn_* structures we have now. It allows to have more generic code and save several pointer dereferences, as all data now stored in state structure itself, and not in separately allocated structures referenced by state.
Also, this code is more type-safe, as there are less void * casts.
Unfortunately, not all indirections and void * casts are eliminated, some data is still passed as pointer-to-struct into leaf functions.

All data, needed for state look-up is packed into front of state struct and is always fit into 64 bytes (typical cache line) in worst case: IPv6 on 64 bit system.

Together this changes provide small but visible performance boost in case when buckets are full and contains more than one state. My measurements on low-end hardware shows, that single-rule firewall allow udp from any to any keep-state have forwarding performance (numbers are KPps) under traffic with 17780 UDP flows like this:

BucketsDefaultPatched
16384305307
8192303307
4096292299
2048281288

Results on high-end systems, where memory accesses are more expensive relative to CPU work, results could be even better for new code.

I want to land these changes because IMHO, this code after this refactoring is easier to extend with new state types. I plan to add NAT implementation in near future, and it looks much simpler with this code.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Regenerate against new git repository