Page MenuHomeFreeBSD

divert: Define semantics for SO_REUSEPORT_LB on divert sockets
ClosedPublic

Authored by markj on Apr 21 2026, 7:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Aug 13, 1:37 AM
Unknown Object (File)
Tue, Aug 11, 6:23 PM
Unknown Object (File)
Tue, Aug 11, 7:03 AM
Unknown Object (File)
Mon, Aug 10, 7:35 AM
Unknown Object (File)
Sun, Aug 9, 11:54 PM
Unknown Object (File)
Sun, Aug 9, 6:31 PM
Unknown Object (File)
Sat, Aug 8, 4:07 PM
Unknown Object (File)
Sat, Aug 8, 9:31 AM

Details

Summary

Allow SO_REUSEPORT_LB to be set on divert sockets. If set, then bind()
will add the socket to a "load-balancing group". When a divert-to rule
matches a port with an associated group, the corresponding state ID is
used to select a specific socket from the group. Packets without an
associated state are simply forwarded to the first socket in the group.
For now I only pass a state ID from pf, as I couldn't see a useful
identifier on the ipfw side.

This implementation is simple but has some caveats, the main one being
that if sockets are added to the group while flows are being processed,
the size of the group will change and this changes the mapping of state
IDs to sockets. So, to get a consistent mapping, the divert socket
application must bind all of its sockets before any traffic is processed
by pf.

Diff Detail

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