Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
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;      /* length of socks */
0017     u16         num_socks;      /* elements in socks */
0018     u16         num_closed_socks;   /* closed elements in socks */
0019     /* The last synq overflow event timestamp of this
0020      * reuse->socks[] group.
0021      */
0022     unsigned int        synq_overflow_ts;
0023     /* ID stays the same even after the size of socks[] grows. */
0024     unsigned int        reuseport_id;
0025     unsigned int        bind_inany:1;
0026     unsigned int        has_conns:1;
0027     struct bpf_prog __rcu   *prog;      /* optional BPF sock selector */
0028     struct sock     *socks[];   /* array of sock pointers */
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  /* _SOCK_REUSEPORT_H */