Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
[sfrench/cifs-2.6.git] / include / net / tcp.h
index 25bbada379c46add16fb7239733bd6571f10f680..963cd86d12ddb24899cd9b26777e78482c1ca1ca 100644 (file)
@@ -403,6 +403,7 @@ __poll_t tcp_poll(struct file *file, struct socket *sock,
                      struct poll_table_struct *wait);
 int tcp_getsockopt(struct sock *sk, int level, int optname,
                   char __user *optval, int __user *optlen);
+bool tcp_bpf_bypass_getsockopt(int level, int optname);
 int tcp_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval,
                   unsigned int optlen);
 void tcp_set_keepalive(struct sock *sk, int val);
@@ -1431,12 +1432,29 @@ void tcp_cleanup_rbuf(struct sock *sk, int copied);
  */
 static inline bool tcp_rmem_pressure(const struct sock *sk)
 {
-       int rcvbuf = READ_ONCE(sk->sk_rcvbuf);
-       int threshold = rcvbuf - (rcvbuf >> 3);
+       int rcvbuf, threshold;
+
+       if (tcp_under_memory_pressure(sk))
+               return true;
+
+       rcvbuf = READ_ONCE(sk->sk_rcvbuf);
+       threshold = rcvbuf - (rcvbuf >> 3);
 
        return atomic_read(&sk->sk_rmem_alloc) > threshold;
 }
 
+static inline bool tcp_epollin_ready(const struct sock *sk, int target)
+{
+       const struct tcp_sock *tp = tcp_sk(sk);
+       int avail = READ_ONCE(tp->rcv_nxt) - READ_ONCE(tp->copied_seq);
+
+       if (avail <= 0)
+               return false;
+
+       return (avail >= target) || tcp_rmem_pressure(sk) ||
+              (tcp_receive_window(tp) <= inet_csk(sk)->icsk_ack.rcv_mss);
+}
+
 extern void tcp_openreq_init_rwin(struct request_sock *req,
                                  const struct sock *sk_listener,
                                  const struct dst_entry *dst);