]> git.dujemihanovic.xyz Git - linux.git/commitdiff
net: pass back whether socket was empty post accept
authorJens Axboe <axboe@kernel.dk>
Thu, 9 May 2024 15:35:01 +0000 (09:35 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 14 May 2024 00:19:20 +0000 (18:19 -0600)
This adds an 'is_empty' argument to struct proto_accept_arg, which can
be used to pass back information on whether or not the given socket has
more connections to accept post the one just accepted.

To utilize this information, the caller should initialize the 'is_empty'
field to, eg, -1 and then check for 0/1 after the accept. If the field
has been set, the caller knows whether there are more pending connections
or not. If the field remains -1 after the accept call, the protocol
doesn't support passing back this information.

This patch wires it up for ipv4/6 TCP.

Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/net/sock.h
net/ipv4/inet_connection_sock.c

index 217079b3e3e82c91a1f4de2895c449f6e3f60934..5f4d0629348f3fcb7b8d5e5e0796a35a9b913101 100644 (file)
@@ -1197,6 +1197,7 @@ static inline void sk_prot_clear_nulls(struct sock *sk, int size)
 struct proto_accept_arg {
        int flags;
        int err;
+       int is_empty;
        bool kern;
 };
 
index 7734d189c66b80d2c8d259de7796463ed6a473f1..d81f74ce0f02e6a9432df49339b9a32a87965624 100644 (file)
@@ -692,6 +692,7 @@ struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg)
                        goto out_err;
        }
        req = reqsk_queue_remove(queue, sk);
+       arg->is_empty = reqsk_queue_empty(queue);
        newsk = req->sk;
 
        if (sk->sk_protocol == IPPROTO_TCP &&