This patch adds a new socket option, SO_REUSEPORT_LB, which allow multiple programs or threads to bind to the same port and incoming connections will be load balanced using a hash function.
Most of the code was copied from a similar patch for DragonflyBSD.
However, in DragonflyBSD, load balancing is a global on/off setting and can not be set per socket. This patch allows for simultaneous use of both the current SO_REUSEPORT and the new SO_REUSEPORT_LB options on the same system.
Required changes to structures
Globally change so_options from 16 to 32 bit value to allow for more options.
Add hashtable in pcbinfo to hold all SO_REUSEPORT_LB sockets.
As DragonflyBSD, a load balance group is limited to 256 pcbs (256 programs or threads sharing the same socket).
If we want to avoid adding more options and changing so_options to a 32 bit value, can we use optvar argument to pass a flag (value other than 0 or 1) for load balancing or is that strictly used for setting the options on/off?
This is merely a draft, no effort has been made to test or implement for ipv6. Maybe someone more familiar with the IP stack can shed some light on what is needed for ipv6?
Even if I close the sockets properly at exit, when I restart the server test program bind() fails with “Address already in use” and I have to wait for it to timeout.