IPFlowPortHash() - selecting ephemeral ports for reverse NAT
June 23, 2026
IPFlowPortHash() #
If you are interested and somewhat into C - here’s a closer look. This is the IPFlowPortHash() function in place with BNG V7 RNAT. It returns a port within the ephemeral port range 49152-65535 (RFC 6335 and IANA).
For ICMP echo requests and replies the ICMP_IDENTIFIER is used instead (since a port is missing here). The host-to-network and network-to-host conversions make the result independent from CPU endianness. Theoretical possible collisions are detected (and reported) within the calling RNAT module (module_rnat) - the resulting IP flow is created anyway.
One thing to mention: The so called “modulo bias” is just ignored here (but existent).
Here’s the source code from BalanceNG V7 as it is (with the lower bound parametrized) - overall a nice application of the f2568() tabular hashing function:
|
|