Skip to content

Commit

Permalink
Clear socket write queue and send RST if connection is dropped
Browse files Browse the repository at this point in the history
Connection can be dropped by calling `ss_conn_drop_guard_exit`
from several places:
- from `tcp_done, when socket is already DEAD
- from `__sk_close_locked` if all data is already sent
- from `ss_linkerror`

In all places socket write queue is already empty, except one
place, when we call `ss_linkerror` for already shutdowned connection.
In this case we should close socket using TCP RST, because we can't
send any more data after connection will be dropped, moreover sequence
numbers of skbs in socket write queue is not correct (they should be
corrected during tls encryption, but appropriate function will never
called for already dropped connection).

Part of #2267
  • Loading branch information
EvgeniiMekhanik committed Nov 11, 2024
1 parent 69fd6e1 commit f45e7b1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions fw/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,9 @@ ss_close_not_connected_socket(struct sock *sk)
* for server sockets.
*/
static void
ss_linkerror(struct sock *sk)
ss_linkerror(struct sock *sk, int flags)
{
ss_do_close(sk, 0);
ss_do_close(sk, flags);
/*
* In case when ss_do_close is called for TCP_FIN_WAIT2
* tcp_done() is called from tcp_time_wait() and connection
Expand Down Expand Up @@ -1142,7 +1142,7 @@ ss_tcp_state_change(struct sock *sk)
*/
if (!sk->sk_user_data)
ss_active_guard_exit(SS_V_ACT_LIVECONN);
ss_linkerror(sk);
ss_linkerror(sk, 0);
ss_active_guard_exit(SS_V_ACT_NEWCONN);
return;
}
Expand Down Expand Up @@ -1195,7 +1195,7 @@ ss_tcp_state_change(struct sock *sk)
*/
if (!skb_queue_empty(&sk->sk_receive_queue))
ss_tcp_process_data(sk);
ss_linkerror(sk);
ss_linkerror(sk, 0);
}
}

Expand Down Expand Up @@ -1570,7 +1570,7 @@ ss_tx_action(void)
} else if (sk->sk_user_data
&& (SS_CONN_TYPE(sk) & Conn_Shutdown)) {
if (ss_is_closed_force(&sw))
ss_linkerror(sk);
ss_linkerror(sk, SS_F_ABORT);
bh_unlock_sock(sk);
goto dead_sock;
}
Expand Down

0 comments on commit f45e7b1

Please sign in to comment.