xref: /openbmc/linux/include/net/sock_reuseport.h (revision 99f3a064bc2e4bd5fe50218646c5be342f2ad18c)
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;
242dbb9b9eSMartin 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 
292dbb9b9eSMartin KaFai Lau extern int reuseport_alloc(struct sock *sk, bool bind_inany);
302dbb9b9eSMartin KaFai Lau extern int reuseport_add_sock(struct sock *sk, struct sock *sk2,
312dbb9b9eSMartin 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);
378217ca65SMartin KaFai Lau extern int reuseport_attach_prog(struct sock *sk, struct bpf_prog *prog);
38*99f3a064SMartin KaFai Lau extern int reuseport_detach_prog(struct sock *sk);
39*99f3a064SMartin KaFai Lau 
40736b4602SMartin KaFai Lau int reuseport_get_id(struct sock_reuseport *reuse);
41ef456144SCraig Gallek 
42ef456144SCraig Gallek #endif  /* _SOCK_REUSEPORT_H */
43