Skip to content

Commit af9784d

Browse files
edumazetkuba-moo
authored andcommitted
tcp: diag: add support for TIME_WAIT sockets to tcp_abort()
Currently, "ss -K -ta ..." does not support TIME_WAIT sockets. Issue has been raised at least two times in the past [1] [2] it is time to fix it. [1] https://lore.kernel.org/netdev/ba65f579-4e69-ae0d-4770-bc6234beb428@gmail.com/ [2] https://lore.kernel.org/netdev/CANn89i+R9RgmD=AQ4vX1Vb_SQAj4c3fi7-ZtQz-inYY4Sq4CMQ@mail.gmail.com/T/ While we are at it, use inet_sk_state_load() while tcp_abort() does not hold a lock on the socket. Signed-off-by: Eric Dumazet <edumazet@google.com> Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Link: https://lore.kernel.org/r/20220627121038.226500-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f03c8a1 commit af9784d

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

net/ipv4/tcp.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4531,16 +4531,24 @@ EXPORT_SYMBOL_GPL(tcp_done);
45314531

45324532
int tcp_abort(struct sock *sk, int err)
45334533
{
4534-
if (!sk_fullsock(sk)) {
4535-
if (sk->sk_state == TCP_NEW_SYN_RECV) {
4536-
struct request_sock *req = inet_reqsk(sk);
4534+
int state = inet_sk_state_load(sk);
45374535

4538-
local_bh_disable();
4539-
inet_csk_reqsk_queue_drop(req->rsk_listener, req);
4540-
local_bh_enable();
4541-
return 0;
4542-
}
4543-
return -EOPNOTSUPP;
4536+
if (state == TCP_NEW_SYN_RECV) {
4537+
struct request_sock *req = inet_reqsk(sk);
4538+
4539+
local_bh_disable();
4540+
inet_csk_reqsk_queue_drop(req->rsk_listener, req);
4541+
local_bh_enable();
4542+
return 0;
4543+
}
4544+
if (state == TCP_TIME_WAIT) {
4545+
struct inet_timewait_sock *tw = inet_twsk(sk);
4546+
4547+
refcount_inc(&tw->tw_refcnt);
4548+
local_bh_disable();
4549+
inet_twsk_deschedule_put(tw);
4550+
local_bh_enable();
4551+
return 0;
45444552
}
45454553

45464554
/* Don't race with userspace socket closes such as tcp_close. */

0 commit comments

Comments
 (0)