xref: /openbmc/linux/include/net/sock_reuseport.h (revision 2dbb9b9e6df67d444fbe425c7f6014858d337adf)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2ef456144SCraig Gallek #ifndef _SOCK_REUSEPORT_H
3ef456144SCraig Gallek #define _SOCK_REUSEPORT_H
4ef456144SCraig Gallek 
5538950a1SCraig Gallek #include <linux/filter.h>
6538950a1SCraig Gallek #include <linux/skbuff.h>
7ef456144SCraig Gallek #include <linux/types.h>
8736b4602SMartin KaFai Lau #include <linux/spinlock.h>
9ef456144SCraig Gallek #include <net/sock.h>
10ef456144SCraig Gallek 
11736b4602SMartin KaFai Lau extern spinlock_t reuseport_lock;
12736b4602SMartin KaFai Lau 
13ef456144SCraig Gallek struct sock_reuseport {
14ef456144SCraig Gallek 	struct rcu_head		rcu;
15ef456144SCraig Gallek 
16ef456144SCraig Gallek 	u16			max_socks;	/* length of socks */
17ef456144SCraig Gallek 	u16			num_socks;	/* elements in socks */
1840a1227eSMartin KaFai Lau 	/* The last synq overflow event timestamp of this
1940a1227eSMartin KaFai Lau 	 * reuse->socks[] group.
2040a1227eSMartin KaFai Lau 	 */
2140a1227eSMartin KaFai Lau 	unsigned int		synq_overflow_ts;
22736b4602SMartin KaFai Lau 	/* ID stays the same even after the size of socks[] grows. */
23736b4602SMartin KaFai Lau 	unsigned int		reuseport_id;
24*2dbb9b9eSMartin KaFai Lau 	bool			bind_inany;
25538950a1SCraig Gallek 	struct bpf_prog __rcu	*prog;		/* optional BPF sock selector */
26ef456144SCraig Gallek 	struct sock		*socks[0];	/* array of sock pointers */
27ef456144SCraig Gallek };
28ef456144SCraig Gallek 
29*2dbb9b9eSMartin KaFai Lau extern int reuseport_alloc(struct sock *sk, bool bind_inany);
30*2dbb9b9eSMartin KaFai Lau extern int reuseport_add_sock(struct sock *sk, struct sock *sk2,
31*2dbb9b9eSMartin KaFai Lau 			      bool bind_inany);
32ef456144SCraig Gallek extern void reuseport_detach_sock(struct sock *sk);
33538950a1SCraig Gallek extern struct sock *reuseport_select_sock(struct sock *sk,
34538950a1SCraig Gallek 					  u32 hash,
35538950a1SCraig Gallek 					  struct sk_buff *skb,
36538950a1SCraig Gallek 					  int hdr_len);
37538950a1SCraig Gallek extern struct bpf_prog *reuseport_attach_prog(struct sock *sk,
38538950a1SCraig Gallek 					      struct bpf_prog *prog);
39736b4602SMartin KaFai Lau int reuseport_get_id(struct sock_reuseport *reuse);
40ef456144SCraig Gallek 
41ef456144SCraig Gallek #endif  /* _SOCK_REUSEPORT_H */
42