Skip to content

Helper function bpf_sk_select_reuseport


The socket select reuse port helper select which socket to send an incoming request to when multiple sockets are bound to the same port.


Copyright (c) 2015 The Libbpf Authors. All rights reserved.

Returns 0 on success, or a negative error in case of failure.

static long (* const bpf_sk_select_reuseport)(struct sk_reuseport_md *reuse, void *map, void *key, __u64 flags) = (void *) 82;


In v3.9 the SO_REUSEPORT socket option was added which allows multiple sockets to listen to the same port on the same host. The original purpose of the feature being that this allows for high-efficient distribution of traffic across threads which would normally have to be done in userspace causing unnecessary delay.

By default, incoming connections and datagrams are distributed to the server sockets using a hash based on the 4-tuple of the connection—that is, the peer IP address and port plus the local IP address and port.

With the introduction of BPF_PROG_TYPE_SK_REUSEPORT programs and this helper we can replace the default distribution behavior with a BPF program. This helper does the actual assigning of an incoming request to a socket in a BPF_MAP_TYPE_REUSEPORT_SOCKARRAY map.

Since v5.8 BPF_MAP_TYPE_SOCKHASH and BPF_MAP_TYPE_SOCKMAP maps can also be used with this helper.

Program types

This helper call can be used in the following program types:

Map types

This helper call can be used with the following map types:


Docs could be improved

This part of the docs is incomplete, contributions are very welcome