sock_reuseport.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _SOCK_REUSEPORT_H
  3. #define _SOCK_REUSEPORT_H
  4. #include <linux/filter.h>
  5. #include <linux/skbuff.h>
  6. #include <linux/types.h>
  7. #include <linux/spinlock.h>
  8. #include <net/sock.h>
  9. extern spinlock_t reuseport_lock;
  10. struct sock_reuseport {
  11. struct rcu_head rcu;
  12. u16 max_socks; /* length of socks */
  13. u16 num_socks; /* elements in socks */
  14. u16 num_closed_socks; /* closed elements in socks */
  15. u16 incoming_cpu;
  16. /* The last synq overflow event timestamp of this
  17. * reuse->socks[] group.
  18. */
  19. unsigned int synq_overflow_ts;
  20. /* ID stays the same even after the size of socks[] grows. */
  21. unsigned int reuseport_id;
  22. unsigned int bind_inany:1;
  23. unsigned int has_conns:1;
  24. struct bpf_prog __rcu *prog; /* optional BPF sock selector */
  25. struct sock *socks[] __counted_by(max_socks);
  26. };
  27. extern int reuseport_alloc(struct sock *sk, bool bind_inany);
  28. extern int reuseport_add_sock(struct sock *sk, struct sock *sk2,
  29. bool bind_inany);
  30. extern void reuseport_detach_sock(struct sock *sk);
  31. void reuseport_stop_listen_sock(struct sock *sk);
  32. extern struct sock *reuseport_select_sock(struct sock *sk,
  33. u32 hash,
  34. struct sk_buff *skb,
  35. int hdr_len);
  36. struct sock *reuseport_migrate_sock(struct sock *sk,
  37. struct sock *migrating_sk,
  38. struct sk_buff *skb);
  39. extern int reuseport_attach_prog(struct sock *sk, struct bpf_prog *prog);
  40. extern int reuseport_detach_prog(struct sock *sk);
  41. static inline bool reuseport_has_conns(struct sock *sk)
  42. {
  43. struct sock_reuseport *reuse;
  44. bool ret = false;
  45. rcu_read_lock();
  46. reuse = rcu_dereference(sk->sk_reuseport_cb);
  47. if (reuse && reuse->has_conns)
  48. ret = true;
  49. rcu_read_unlock();
  50. return ret;
  51. }
  52. void reuseport_has_conns_set(struct sock *sk);
  53. void reuseport_update_incoming_cpu(struct sock *sk, int val);
  54. #endif /* _SOCK_REUSEPORT_H */