0001
0002 #ifndef _SOCK_REUSEPORT_H
0003 #define _SOCK_REUSEPORT_H
0004
0005 #include <linux/filter.h>
0006 #include <linux/skbuff.h>
0007 #include <linux/types.h>
0008 #include <linux/spinlock.h>
0009 #include <net/sock.h>
0010
0011 extern spinlock_t reuseport_lock;
0012
0013 struct sock_reuseport {
0014 struct rcu_head rcu;
0015
0016 u16 max_socks;
0017 u16 num_socks;
0018 u16 num_closed_socks;
0019
0020
0021
0022 unsigned int synq_overflow_ts;
0023
0024 unsigned int reuseport_id;
0025 unsigned int bind_inany:1;
0026 unsigned int has_conns:1;
0027 struct bpf_prog __rcu *prog;
0028 struct sock *socks[];
0029 };
0030
0031 extern int reuseport_alloc(struct sock *sk, bool bind_inany);
0032 extern int reuseport_add_sock(struct sock *sk, struct sock *sk2,
0033 bool bind_inany);
0034 extern void reuseport_detach_sock(struct sock *sk);
0035 void reuseport_stop_listen_sock(struct sock *sk);
0036 extern struct sock *reuseport_select_sock(struct sock *sk,
0037 u32 hash,
0038 struct sk_buff *skb,
0039 int hdr_len);
0040 struct sock *reuseport_migrate_sock(struct sock *sk,
0041 struct sock *migrating_sk,
0042 struct sk_buff *skb);
0043 extern int reuseport_attach_prog(struct sock *sk, struct bpf_prog *prog);
0044 extern int reuseport_detach_prog(struct sock *sk);
0045
0046 static inline bool reuseport_has_conns(struct sock *sk, bool set)
0047 {
0048 struct sock_reuseport *reuse;
0049 bool ret = false;
0050
0051 rcu_read_lock();
0052 reuse = rcu_dereference(sk->sk_reuseport_cb);
0053 if (reuse) {
0054 if (set)
0055 reuse->has_conns = 1;
0056 ret = reuse->has_conns;
0057 }
0058 rcu_read_unlock();
0059
0060 return ret;
0061 }
0062
0063 #endif