Merge tag 'timers-urgent-2024-04-14' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / include / net / sock_reuseport.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
ef456144
CG
2#ifndef _SOCK_REUSEPORT_H
3#define _SOCK_REUSEPORT_H
4
538950a1
CG
5#include <linux/filter.h>
6#include <linux/skbuff.h>
ef456144 7#include <linux/types.h>
736b4602 8#include <linux/spinlock.h>
ef456144
CG
9#include <net/sock.h>
10
736b4602
MKL
11extern spinlock_t reuseport_lock;
12
ef456144
CG
13struct sock_reuseport {
14 struct rcu_head rcu;
15
5c040eaf
KI
16 u16 max_socks; /* length of socks */
17 u16 num_socks; /* elements in socks */
18 u16 num_closed_socks; /* closed elements in socks */
b261eda8 19 u16 incoming_cpu;
40a1227e
MKL
20 /* The last synq overflow event timestamp of this
21 * reuse->socks[] group.
22 */
23 unsigned int synq_overflow_ts;
736b4602
MKL
24 /* ID stays the same even after the size of socks[] grows. */
25 unsigned int reuseport_id;
acdcecc6
WB
26 unsigned int bind_inany:1;
27 unsigned int has_conns:1;
538950a1 28 struct bpf_prog __rcu *prog; /* optional BPF sock selector */
2603c29e 29 struct sock *socks[]; /* array of sock pointers */
ef456144
CG
30};
31
2dbb9b9e
MKL
32extern int reuseport_alloc(struct sock *sk, bool bind_inany);
33extern int reuseport_add_sock(struct sock *sk, struct sock *sk2,
34 bool bind_inany);
ef456144 35extern void reuseport_detach_sock(struct sock *sk);
333bb73f 36void reuseport_stop_listen_sock(struct sock *sk);
538950a1
CG
37extern struct sock *reuseport_select_sock(struct sock *sk,
38 u32 hash,
39 struct sk_buff *skb,
40 int hdr_len);
1cd62c21
KI
41struct sock *reuseport_migrate_sock(struct sock *sk,
42 struct sock *migrating_sk,
43 struct sk_buff *skb);
8217ca65 44extern int reuseport_attach_prog(struct sock *sk, struct bpf_prog *prog);
99f3a064
MKL
45extern int reuseport_detach_prog(struct sock *sk);
46
69421bf9 47static inline bool reuseport_has_conns(struct sock *sk)
acdcecc6
WB
48{
49 struct sock_reuseport *reuse;
50 bool ret = false;
51
52 rcu_read_lock();
53 reuse = rcu_dereference(sk->sk_reuseport_cb);
69421bf9
KI
54 if (reuse && reuse->has_conns)
55 ret = true;
acdcecc6
WB
56 rcu_read_unlock();
57
58 return ret;
59}
60
69421bf9 61void reuseport_has_conns_set(struct sock *sk);
b261eda8 62void reuseport_update_incoming_cpu(struct sock *sk, int val);
69421bf9 63
ef456144 64#endif /* _SOCK_REUSEPORT_H */