A conventional server owns one listening socket for a local address and port. SO_REUSEPORT changes that ownership boundary: multiple eligible sockets can bind the same address, and Linux selects a member of the reuseport group when traffic arrives.
The option is useful when several worker threads or processes should receive traffic without sharing one accept or receive queue. It changes kernel-side socket selection, not the transport protocol carried on the network.
Every member opts in before bind
Linux has supported SO_REUSEPORT for IPv4 and IPv6 sockets since kernel 3.9. Each socket, including the first one, must enable the option before bind().
int one = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) == -1) {
/* handle error */
}
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
/* handle error */
}The rule is stricter than merely finding an address that another socket already occupies. Linux also requires processes binding the same reuseport address to have the same effective UID, a guard against an unrelated process joining the group and receiving traffic intended for the service.
SO_REUSEPORT is distinct from SO_REUSEADDR. The latter relaxes selected address-reuse checks, while reuseport explicitly permits multiple participating sockets to share an identical local endpoint under its group rules.
TCP distributes connections before accept
For TCP servers, each worker can own a separate listening socket bound to the same address. Incoming connections are assigned to one listener, and that listener’s accept queue receives the connection.
This removes the requirement for all workers to contend on one listening file descriptor. It also avoids an architecture where one acceptor receives every connection and hands accepted descriptors to other workers.
The selection happens before the application calls accept(). Once a connection belongs to a listener and is accepted, normal TCP connection semantics apply. Reuseport does not split bytes from one established connection across several sockets.
UDP distributes datagrams among group members
UDP uses the same option to let multiple sockets bind one local endpoint. Incoming datagrams are assigned to sockets in the group rather than forcing all workers to compete on one receive queue.
That assignment does not duplicate each datagram to every member. A reuseport group is a distribution mechanism, not a broadcast mechanism. Software that requires a specific mapping policy needs an explicit selector rather than relying on incidental implementation behavior.
BPF can replace the default selector
Linux exposes SO_ATTACH_REUSEPORT_CBPF and SO_ATTACH_REUSEPORT_EBPF for reuseport groups. An attached program can select the receiving socket by returning a valid group index. An invalid index from the classic or socket-filter eBPF selector falls back to ordinary reuseport selection.
Sockets are indexed in group order. For UDP, that order follows bind() calls; for TCP, it follows listen() calls. When a socket is removed, Linux can move the last member into the vacated index, so a selector must not assume that an index permanently names one process.
UDP support for reuseport BPF selection arrived in Linux 4.5, with TCP support in Linux 4.6. BPF_PROG_TYPE_SK_REUSEPORT, available from Linux 4.19, provides a reuseport-specific program type and can use bpf_sk_select_reuseport for socket selection.
Group membership is part of server topology
A reuseport design moves part of request distribution into the kernel. That can reduce shared-queue contention, but it also makes socket lifecycle part of load-balancing behavior.
Starting or stopping workers changes group membership. A BPF selector must remain valid as membership changes, and operational metrics should be collected per worker as well as across the whole service.
The option does not provide application health checks. A process that remains in the group while failing to make useful progress can still affect service behavior. Worker lifecycle, readiness, draining, and failure handling remain application or supervisor responsibilities.
SO_REUSEPORT is a socket-demultiplexing primitive with a narrow contract: multiple eligible sockets may own one local endpoint, and Linux chooses a recipient for incoming work. Explicit BPF selection is available when the default distribution policy is not sufficient.