Skip to content

Commit aef83a5

Browse files
committed
rstreason: prepare for active reset
JIRA: https://issues.redhat.com/browse/RHEL-48648 Upstream Status: linux.git Conflicts:\ - Context difference due to missing upstream commit e13ec3d ("tcp: annotate lockless access to sk->sk_err") in c9s. commit 5691276 Author: Jason Xing <kernelxing@tencent.com> Date: Thu Apr 25 11:13:36 2024 +0800 rstreason: prepare for active reset Like what we did to passive reset: only passing possible reset reason in each active reset path. No functional changes. Signed-off-by: Jason Xing <kernelxing@tencent.com> Acked-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent 25344d9 commit aef83a5

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

include/net/tcp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ void tcp_send_probe0(struct sock *);
614614
void tcp_send_partial(struct sock *);
615615
int tcp_write_wakeup(struct sock *, int mib);
616616
void tcp_send_fin(struct sock *sk);
617-
void tcp_send_active_reset(struct sock *sk, gfp_t priority);
617+
void tcp_send_active_reset(struct sock *sk, gfp_t priority,
618+
enum sk_rst_reason reason);
618619
int tcp_send_synack(struct sock *);
619620
void tcp_push_one(struct sock *, unsigned int mss_now);
620621
void __tcp_send_ack(struct sock *sk, u32 rcv_nxt);

net/ipv4/tcp.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
#include <net/xfrm.h>
276276
#include <net/ip.h>
277277
#include <net/sock.h>
278+
#include <net/rstreason.h>
278279

279280
#include <linux/uaccess.h>
280281
#include <asm/ioctls.h>
@@ -2973,7 +2974,8 @@ void __tcp_close(struct sock *sk, long timeout)
29732974
/* Unread data was tossed, zap the connection. */
29742975
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONCLOSE);
29752976
tcp_set_state(sk, TCP_CLOSE);
2976-
tcp_send_active_reset(sk, sk->sk_allocation);
2977+
tcp_send_active_reset(sk, sk->sk_allocation,
2978+
SK_RST_REASON_NOT_SPECIFIED);
29772979
} else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) {
29782980
/* Check zero linger _after_ checking for unread data. */
29792981
sk->sk_prot->disconnect(sk, 0);
@@ -3047,7 +3049,8 @@ void __tcp_close(struct sock *sk, long timeout)
30473049
struct tcp_sock *tp = tcp_sk(sk);
30483050
if (tp->linger2 < 0) {
30493051
tcp_set_state(sk, TCP_CLOSE);
3050-
tcp_send_active_reset(sk, GFP_ATOMIC);
3052+
tcp_send_active_reset(sk, GFP_ATOMIC,
3053+
SK_RST_REASON_NOT_SPECIFIED);
30513054
__NET_INC_STATS(sock_net(sk),
30523055
LINUX_MIB_TCPABORTONLINGER);
30533056
} else {
@@ -3065,7 +3068,8 @@ void __tcp_close(struct sock *sk, long timeout)
30653068
if (sk->sk_state != TCP_CLOSE) {
30663069
if (tcp_check_oom(sk, 0)) {
30673070
tcp_set_state(sk, TCP_CLOSE);
3068-
tcp_send_active_reset(sk, GFP_ATOMIC);
3071+
tcp_send_active_reset(sk, GFP_ATOMIC,
3072+
SK_RST_REASON_NOT_SPECIFIED);
30693073
__NET_INC_STATS(sock_net(sk),
30703074
LINUX_MIB_TCPABORTONMEMORY);
30713075
} else if (!check_net(sock_net(sk))) {
@@ -3169,7 +3173,7 @@ int tcp_disconnect(struct sock *sk, int flags)
31693173
/* The last check adjusts for discrepancy of Linux wrt. RFC
31703174
* states
31713175
*/
3172-
tcp_send_active_reset(sk, gfp_any());
3176+
tcp_send_active_reset(sk, gfp_any(), SK_RST_REASON_NOT_SPECIFIED);
31733177
sk->sk_err = ECONNRESET;
31743178
} else if (old_state == TCP_SYN_SENT)
31753179
sk->sk_err = ECONNRESET;
@@ -4748,7 +4752,8 @@ int tcp_abort(struct sock *sk, int err)
47484752
smp_wmb();
47494753
sk_error_report(sk);
47504754
if (tcp_need_reset(sk->sk_state))
4751-
tcp_send_active_reset(sk, GFP_ATOMIC);
4755+
tcp_send_active_reset(sk, GFP_ATOMIC,
4756+
SK_RST_REASON_NOT_SPECIFIED);
47524757
tcp_done(sk);
47534758
}
47544759

net/ipv4/tcp_output.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3506,7 +3506,8 @@ void tcp_send_fin(struct sock *sk)
35063506
* was unread data in the receive queue. This behavior is recommended
35073507
* by RFC 2525, section 2.17. -DaveM
35083508
*/
3509-
void tcp_send_active_reset(struct sock *sk, gfp_t priority)
3509+
void tcp_send_active_reset(struct sock *sk, gfp_t priority,
3510+
enum sk_rst_reason reason)
35103511
{
35113512
struct sk_buff *skb;
35123513

net/ipv4/tcp_timer.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/module.h>
2323
#include <linux/gfp.h>
2424
#include <net/tcp.h>
25+
#include <net/rstreason.h>
2526

2627
static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)
2728
{
@@ -121,7 +122,8 @@ static int tcp_out_of_resources(struct sock *sk, bool do_reset)
121122
(!tp->snd_wnd && !tp->packets_out))
122123
do_reset = true;
123124
if (do_reset)
124-
tcp_send_active_reset(sk, GFP_ATOMIC);
125+
tcp_send_active_reset(sk, GFP_ATOMIC,
126+
SK_RST_REASON_NOT_SPECIFIED);
125127
tcp_done(sk);
126128
__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
127129
return 1;
@@ -723,7 +725,7 @@ static void tcp_keepalive_timer (struct timer_list *t)
723725
goto out;
724726
}
725727
}
726-
tcp_send_active_reset(sk, GFP_ATOMIC);
728+
tcp_send_active_reset(sk, GFP_ATOMIC, SK_RST_REASON_NOT_SPECIFIED);
727729
goto death;
728730
}
729731

@@ -748,7 +750,8 @@ static void tcp_keepalive_timer (struct timer_list *t)
748750
icsk->icsk_probes_out > 0) ||
749751
(icsk->icsk_user_timeout == 0 &&
750752
icsk->icsk_probes_out >= keepalive_probes(tp))) {
751-
tcp_send_active_reset(sk, GFP_ATOMIC);
753+
tcp_send_active_reset(sk, GFP_ATOMIC,
754+
SK_RST_REASON_NOT_SPECIFIED);
752755
tcp_write_err(sk);
753756
goto out;
754757
}

net/mptcp/protocol.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#endif
2323
#include <net/mptcp.h>
2424
#include <net/xfrm.h>
25+
#include <net/rstreason.h>
2526
#include <asm/ioctls.h>
2627
#include "protocol.h"
2728
#include "mib.h"
@@ -2566,7 +2567,8 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
25662567

25672568
slow = lock_sock_fast(tcp_sk);
25682569
if (tcp_sk->sk_state != TCP_CLOSE) {
2569-
tcp_send_active_reset(tcp_sk, GFP_ATOMIC);
2570+
tcp_send_active_reset(tcp_sk, GFP_ATOMIC,
2571+
SK_RST_REASON_NOT_SPECIFIED);
25702572
tcp_set_state(tcp_sk, TCP_CLOSE);
25712573
}
25722574
unlock_sock_fast(tcp_sk, slow);

net/mptcp/subflow.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void mptcp_subflow_reset(struct sock *ssk)
409409
/* must hold: tcp_done() could drop last reference on parent */
410410
sock_hold(sk);
411411

412-
tcp_send_active_reset(ssk, GFP_ATOMIC);
412+
tcp_send_active_reset(ssk, GFP_ATOMIC, SK_RST_REASON_NOT_SPECIFIED);
413413
tcp_done(ssk);
414414
if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &mptcp_sk(sk)->flags))
415415
mptcp_schedule_work(sk);
@@ -1340,7 +1340,8 @@ static bool subflow_check_data_avail(struct sock *ssk)
13401340
tcp_set_state(ssk, TCP_CLOSE);
13411341
while ((skb = skb_peek(&ssk->sk_receive_queue)))
13421342
sk_eat_skb(ssk, skb);
1343-
tcp_send_active_reset(ssk, GFP_ATOMIC);
1343+
tcp_send_active_reset(ssk, GFP_ATOMIC,
1344+
SK_RST_REASON_NOT_SPECIFIED);
13441345
WRITE_ONCE(subflow->data_avail, false);
13451346
return false;
13461347
}

0 commit comments

Comments
 (0)