blob: d9112de852614ebaa07e4e584e2782c2706458c4 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Craig Gallekef456142016-01-04 17:41:45 -05002#ifndef _SOCK_REUSEPORT_H
3#define _SOCK_REUSEPORT_H
4
Craig Gallek538950a2016-01-04 17:41:47 -05005#include <linux/filter.h>
6#include <linux/skbuff.h>
Craig Gallekef456142016-01-04 17:41:45 -05007#include <linux/types.h>
Martin KaFai Lau736b4602018-08-08 01:01:22 -07008#include <linux/spinlock.h>
Craig Gallekef456142016-01-04 17:41:45 -05009#include <net/sock.h>
10
Martin KaFai Lau736b4602018-08-08 01:01:22 -070011extern spinlock_t reuseport_lock;
12
Craig Gallekef456142016-01-04 17:41:45 -050013struct sock_reuseport {
14 struct rcu_head rcu;
15
16 u16 max_socks; /* length of socks */
17 u16 num_socks; /* elements in socks */
Martin KaFai Lau40a12272018-08-08 01:01:21 -070018 /* The last synq overflow event timestamp of this
19 * reuse->socks[] group.
20 */
21 unsigned int synq_overflow_ts;
Martin KaFai Lau736b4602018-08-08 01:01:22 -070022 /* ID stays the same even after the size of socks[] grows. */
23 unsigned int reuseport_id;
Martin KaFai Lau2dbb9b92018-08-08 01:01:25 -070024 bool bind_inany;
Craig Gallek538950a2016-01-04 17:41:47 -050025 struct bpf_prog __rcu *prog; /* optional BPF sock selector */
Craig Gallekef456142016-01-04 17:41:45 -050026 struct sock *socks[0]; /* array of sock pointers */
27};
28
Martin KaFai Lau2dbb9b92018-08-08 01:01:25 -070029extern int reuseport_alloc(struct sock *sk, bool bind_inany);
30extern int reuseport_add_sock(struct sock *sk, struct sock *sk2,
31 bool bind_inany);
Craig Gallekef456142016-01-04 17:41:45 -050032extern void reuseport_detach_sock(struct sock *sk);
Craig Gallek538950a2016-01-04 17:41:47 -050033extern struct sock *reuseport_select_sock(struct sock *sk,
34 u32 hash,
35 struct sk_buff *skb,
36 int hdr_len);
Martin KaFai Lau8217ca62018-08-08 01:01:26 -070037extern int reuseport_attach_prog(struct sock *sk, struct bpf_prog *prog);
Martin KaFai Lau99f3a062019-06-13 15:00:01 -070038extern int reuseport_detach_prog(struct sock *sk);
39
Martin KaFai Lau736b4602018-08-08 01:01:22 -070040int reuseport_get_id(struct sock_reuseport *reuse);
Craig Gallekef456142016-01-04 17:41:45 -050041
42#endif /* _SOCK_REUSEPORT_H */