From patchwork Thu Aug 1 14:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13750617 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1027C1A721D for ; Thu, 1 Aug 2024 14:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524095; cv=none; b=m2V4Mb5DwmF+KjxGDfP4wdaGas7MzonAnRhHyVdJsvP5WDJ4hIp6G1uho1l+W+XnF83BKiHD9ff8CbBD4nh/uPDe7s0b6A7dmvbhUttPvtjTEyPzUX79yYOHOrxVqWlAaI9fwFUZYtg16yt63OioU98gvxpD8QNzC8JXDE+tJck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524095; c=relaxed/simple; bh=xmrNaBt5a2CwB7pE8jwMkJ9DwMXjVuJmHd6iM+Z0v4Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Cb0hWrbzBJaYkY4Txly/sUVnzcl1pDd2/Te4L/TdxZ6gF/MhectNIh6vzwLM0LjykY/4lhJXoDMIpLLLMD0jLCAHoAPDl1/2a7DBkMZwFVw+NKDVq9/74L7ZPA4RBd6BPG6BOnxMjVsV/g3erHS23m1lw01oxJzv/mINzLlr9SE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IGpjRZYj; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IGpjRZYj" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-70d1cbbeeaeso5178046b3a.0 for ; Thu, 01 Aug 2024 07:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722524093; x=1723128893; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=65OKnjJuPQeRm+91VoYodiWcGDqklxrBSmzt5OD+SFE=; b=IGpjRZYjrWSgN10wW+C38sLVwbJ/Yp3hOL4mAIy+VIsQ+SmBDHbto7rFYsaVsi5ho8 BecyyBbJwdpm6E/i8Buk8vex7flfbwc1ip+kV6DcITgMBTpo1huAbe8pADR2P12h/BA2 WkCjBzoE76Zn43tdepWcjnSc40Z7xz7dQmgYpsnzBNr/jRvZDKf1rrZW6KOVcD/mf/oO utWHSfxqtE/HuebXlIMeJHA48ty6XfLsIpj6to6rqGzCENzAGJ+IfXH77RV+XHCsujgP K7XfmaJz7u4f7n+on025DG8vkK/bjikIOSxVI7cJVqUez49afFsWjST4kXm+l2i+1y9n tIuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524093; x=1723128893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=65OKnjJuPQeRm+91VoYodiWcGDqklxrBSmzt5OD+SFE=; b=mDFBIgOh8RYB6a7lE1dLojx/5ABWj4T/V7vIcSzpi12LGaUUctZ8WhAf2/Uac4pl+B MkP+I0sm2jIIvz8jU1eDD+2Mn3M1biRPWYUkN+L0c7gY8zWTCG+weOEx3WNVFgKqy+e4 y3XTZd2pkuOKt5uEdj2HIjkHQb+rqbqomctcwSj6d3bVE8n4mTxTS8u8SitqsgwRLJWZ /8xti2bcxoAHOqGhzGlU5R4i3XyUVHpSwp8f/Gb2PeyIy1m1ScCUjZLVIWiEcQNX2CDZ stqWOJUh5AaZgGYCv8D61v9uuD8onSbnlcR2KmkMUpfBsuSLuD2QNXuzBUKjDQbrtx7D wLtg== X-Gm-Message-State: AOJu0YxZ3MiSf7nWI0lve83e6tyWIdVwzqUrfvvHjTSRUp9Rfr3F/Fox uxvub4h/DDBT/ZvGitBVp6Hpqao0o6lZrCIL7QUX2eUUssS/CHZi X-Google-Smtp-Source: AGHT+IGssBqver1tybT/h8eyfbIFdrbQ17zTZkT3e2d3ufWoFW0Dsx87sXC8VSfru1rHaN7E6m85MQ== X-Received: by 2002:a05:6a20:9191:b0:1c4:8293:76d0 with SMTP id adf61e73a8af0-1c69953c7camr828950637.4.1722524093146; Thu, 01 Aug 2024 07:54:53 -0700 (PDT) Received: from KERNELXING-MC1.tencent.com ([114.253.36.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead8a35c7sm11611739b3a.200.2024.08.01.07.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:54:52 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 1/7] tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_CLOSE for active reset Date: Thu, 1 Aug 2024 22:54:38 +0800 Message-Id: <20240801145444.22988-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240801145444.22988-1-kerneljasonxing@gmail.com> References: <20240801145444.22988-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Introducing a new type TCP_ABORT_ON_CLOSE for tcp reset reason to handle the case where more data is unread in closing phase. Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet --- include/net/rstreason.h | 6 ++++++ net/ipv4/tcp.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/net/rstreason.h b/include/net/rstreason.h index 2575c85d7f7a..fa6bfd0d7d69 100644 --- a/include/net/rstreason.h +++ b/include/net/rstreason.h @@ -17,6 +17,7 @@ FN(TCP_ABORT_ON_DATA) \ FN(TCP_TIMEWAIT_SOCKET) \ FN(INVALID_SYN) \ + FN(TCP_ABORT_ON_CLOSE) \ FN(MPTCP_RST_EUNSPEC) \ FN(MPTCP_RST_EMPTCP) \ FN(MPTCP_RST_ERESOURCE) \ @@ -84,6 +85,11 @@ enum sk_rst_reason { * an error, send a reset" */ SK_RST_REASON_INVALID_SYN, + /** + * @SK_RST_REASON_TCP_ABORT_ON_CLOSE: abort on close + * corresponding to LINUX_MIB_TCPABORTONCLOSE + */ + SK_RST_REASON_TCP_ABORT_ON_CLOSE, /* Copy from include/uapi/linux/mptcp.h. * These reset fields will not be changed since they adhere to diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index e03a342c9162..2e010add0317 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2833,7 +2833,7 @@ void __tcp_close(struct sock *sk, long timeout) NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONCLOSE); tcp_set_state(sk, TCP_CLOSE); tcp_send_active_reset(sk, sk->sk_allocation, - SK_RST_REASON_NOT_SPECIFIED); + SK_RST_REASON_TCP_ABORT_ON_CLOSE); } else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) { /* Check zero linger _after_ checking for unread data. */ sk->sk_prot->disconnect(sk, 0); From patchwork Thu Aug 1 14:54:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13750618 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9DA41A721D for ; Thu, 1 Aug 2024 14:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524098; cv=none; b=EfA2ELlH8Phwi+OkMMFStuD3kscQ1xes64OoQOhClxbv8iT6/F0KnzEJhHu/+qTEy7ThdNKR5j2vVTAkO8JLcMPeh9wabKeByScejy5thVAaBAk9zZcYb8L4axKkr1BDiVJsmNg/GJfDHhnTc+uSmXn5+xz2oev1igH9Giq2j+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524098; c=relaxed/simple; bh=bB5quX6hf5roJw3OqlmFW9vud3KXLMbEWmO1V3KzOcQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=auKXvALvoYMYYj+MKdxigDO6JKKt9MZcS3Y1F+wGF0WKOZ0iaVH8EaPCt0rldVUXufGfz1H+JDB8FQnmEHk1NZNEeZsdHtpMvTpOzJIGjORT+HaRqt2+shw1Kg+8PhFGfIw2kz0S9dc+IS4oiVnsHINMNOcMe4iM04OPb7cv+LE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=a9NCXcwX; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a9NCXcwX" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7104f93a20eso1708869b3a.1 for ; Thu, 01 Aug 2024 07:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722524096; x=1723128896; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Zgif6oVSTEITP/o4l4CprEQozCE/rlgITlHxlm8H5hI=; b=a9NCXcwXfPeZnxYPvEFhuMiaH+vUv/RbvTk5DgjwK5v6NcDt5Mmc+Fi9Of8yd2d9Yy nq/gQcKdgvbYy+7Wez2EZnxYVTGM2lZ8O1fJVUgWs01BOY9gre203KR/Y7jEFd5OUaWB Xvu2t5U2HVs78mkgfm6XY9wbM0EuYkvgJqlh5sRjn9pN4P6sIMnPRa+nfNkt5OkwC/4q pItTO60gpn2yh60NywM5og+f9esqz2+7h1kV6mtGrDgK07M8ebuoept9dGu516VgU2EJ jkCwLe64OUaJHhyKbCdnIAyBi+0mYICLcjjl1pvmiNl4dcjIuXrMtpjbta25tSBVoQCD kkTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524096; x=1723128896; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zgif6oVSTEITP/o4l4CprEQozCE/rlgITlHxlm8H5hI=; b=to/9C2U8LQzwzPhgXNpnDNe4aTI3bv628iZLqzSccM1uAq+JiibUWEirN6X9FpRuQV cXRHGQoYCFZ8Ti5ZiNUXyKQSNpZUpjgmYHcxxcLhCdRuT7oN9dVQgS7AnxW0TcSt9Mz9 GwUtdmBUaS/xa5C90U84sG3UlwEEExSpSM44TjCRX0szVaKd5/fis57TvZhnsIu6DUxO wTIIlhphh6V8tMakQDH77g6HwYRbeuCFaOhWNvQFOlbQZSoDR7G/AmVHlVcapajQAmoA JY9S4cZBjVzM72iEjyXT57hbLFCZOiBlCp+Gdpx/4/SthPNc0NRloDz9DSq+gI85d3eU kTtg== X-Gm-Message-State: AOJu0Yy429aMftMNxnq5COn8rjWgjzavc/pXQ4oEQQX3BvKxlmvamgUq 9NFIUOa2bTX0hsQb4ufsAFjOM9WFvI5r+a5doU+JM+RhLA/hFF72 X-Google-Smtp-Source: AGHT+IFA/tVLS0S7f5lqvQ3rAPMEjGQbDz39hpmfeWpo/ug1qIbm9Ag1TN1g4zyJlID7I6ktGAaMMQ== X-Received: by 2002:a05:6a20:2d26:b0:1c4:c4cc:fa67 with SMTP id adf61e73a8af0-1c699624ee6mr554581637.39.1722524096042; Thu, 01 Aug 2024 07:54:56 -0700 (PDT) Received: from KERNELXING-MC1.tencent.com ([114.253.36.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead8a35c7sm11611739b3a.200.2024.08.01.07.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:54:55 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 2/7] tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_LINGER for active reset Date: Thu, 1 Aug 2024 22:54:39 +0800 Message-Id: <20240801145444.22988-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240801145444.22988-1-kerneljasonxing@gmail.com> References: <20240801145444.22988-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Introducing a new type TCP_ABORT_ON_LINGER for tcp reset reason to handle negative linger value case. Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet --- include/net/rstreason.h | 6 ++++++ net/ipv4/tcp.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/net/rstreason.h b/include/net/rstreason.h index fa6bfd0d7d69..fbbaeb969e6a 100644 --- a/include/net/rstreason.h +++ b/include/net/rstreason.h @@ -18,6 +18,7 @@ FN(TCP_TIMEWAIT_SOCKET) \ FN(INVALID_SYN) \ FN(TCP_ABORT_ON_CLOSE) \ + FN(TCP_ABORT_ON_LINGER) \ FN(MPTCP_RST_EUNSPEC) \ FN(MPTCP_RST_EMPTCP) \ FN(MPTCP_RST_ERESOURCE) \ @@ -90,6 +91,11 @@ enum sk_rst_reason { * corresponding to LINUX_MIB_TCPABORTONCLOSE */ SK_RST_REASON_TCP_ABORT_ON_CLOSE, + /** + * @SK_RST_REASON_TCP_ABORT_ON_LINGER: abort on linger + * corresponding to LINUX_MIB_TCPABORTONLINGER + */ + SK_RST_REASON_TCP_ABORT_ON_LINGER, /* Copy from include/uapi/linux/mptcp.h. * These reset fields will not be changed since they adhere to diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 2e010add0317..5b0f1d1fc697 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2908,7 +2908,7 @@ void __tcp_close(struct sock *sk, long timeout) if (READ_ONCE(tp->linger2) < 0) { tcp_set_state(sk, TCP_CLOSE); tcp_send_active_reset(sk, GFP_ATOMIC, - SK_RST_REASON_NOT_SPECIFIED); + SK_RST_REASON_TCP_ABORT_ON_LINGER); __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONLINGER); } else { From patchwork Thu Aug 1 14:54:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13750619 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5FF81A99E1 for ; Thu, 1 Aug 2024 14:54:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524101; cv=none; b=DWtANLNPYanIjDUJ9CMxGd3nDqUzqMwEkAv4LOB9gO1jY4FHd5/EwQ8HIpclMPgl4zH5Y0hk+4NI26HlsyjqntlEH3ahNBZntWYnBCf48NvT0GYk2WSP9etA64ORccDV+pVtETkgaWA5VHKxq1GVLB3OOXEACYPQZVf+kvV5p3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524101; c=relaxed/simple; bh=g3fhbhumzkeNAkIMtG7+6lCFSXQXdNT2W0/nZ/J6upk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SeXABqzgGAGGc2q886IkXUZ1m6oSBJbvCiZeRR2i2m5Np5gURj67v3dOidfLVgtDDM2ByJmbdzdREQZzBP27AbL2p2PQTZ52HgOgW7A4FM6q72pSdfe+q45P2YUgE85tWayN5R0QyrQEuoGK+jQBbDrof+EHfnkp3vY9HV7qQC0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JWy1T46h; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JWy1T46h" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-70eb0ae23e4so5121910b3a.0 for ; Thu, 01 Aug 2024 07:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722524099; x=1723128899; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e2L42Y3fxOPDIWwTt7ZYcTgRSPw4dmgExss+Yxe/O+A=; b=JWy1T46hkp1IraMxAxF4Z/L1NtG/4cTtIyTxhHcBtRLLCtIJz+W/+yyvkliYKhH9Od Vb19IofoqENHnEw/BmPw/YS5QaV5Z39D/XzoHT72t07g+DpWS53B11Ian1IjxnmKI3kV JKmSKlR8FEX5A5JC6rxu8OHN8EtjjeOpUd6ZbGE0PoTvk1eiDgqYQnR0f1reoOlKNrkR m5+n1LSUJM8HGbhMyFVPeS3yi3qTW6lhKYC+gA1lmUh86JB+CHPsW5jZCty77W5wuRM+ ypzic97P1RMaKqb8ScSOOPA8mDAUV4VZOcP+GdAl98J9u6vQOqd9BOBJjJr8Qg/MktBs 9IcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524099; x=1723128899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e2L42Y3fxOPDIWwTt7ZYcTgRSPw4dmgExss+Yxe/O+A=; b=NaSVUjmSeU0Djt26EIs1GI+dA3uZRekt0le/qXZOZlHZrSda/SIZS5NFNAkwkol+k+ BUKOf6DaFw7g/w1t8pHKHgjukLP5MIR6bV8hF3tx83ga+jkg7JCjtAE2GVezZop7/y12 Fu70VZzXfkQv2Zsb/v8sD+arlxIGBBTeD+nzXG3rEfmdu1fO+1J6zOUGgrC3JVm50eqx 2Qm7WC+ybx4j5yT00uFkLOuiW7gz6DJZRAX7fIDaxyNKF7oPMfjBPTmoYRN2UsWTNmHE 7DzFR0G8TUblrxZZPxSc1+3wpoBZa/09Gox0oNeRqiFN4VmMVvwqzS6ZwGQ8lQfziJEr 684g== X-Gm-Message-State: AOJu0YzNG6GvxsRhbTIJOBCehU5UfXqSW09M3u4fqfnopEU0aXbYINz5 nOGWJH34lzsbcP8PXzP3rix58ngda5B1ULxSzB+IezpZhwgp5ND3 X-Google-Smtp-Source: AGHT+IEfb1BQlvGorvjcIt/yNR/Vgh8S1hYEMvgHG6C/7E/qf25T3D9Pa/r4uHBlMIbyeABm3fGO4g== X-Received: by 2002:a05:6a00:1744:b0:706:8066:5cd8 with SMTP id d2e1a72fcca58-7106cfa3081mr579986b3a.11.1722524099037; Thu, 01 Aug 2024 07:54:59 -0700 (PDT) Received: from KERNELXING-MC1.tencent.com ([114.253.36.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead8a35c7sm11611739b3a.200.2024.08.01.07.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:54:58 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 3/7] tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_MEMORY for active reset Date: Thu, 1 Aug 2024 22:54:40 +0800 Message-Id: <20240801145444.22988-4-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240801145444.22988-1-kerneljasonxing@gmail.com> References: <20240801145444.22988-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Introducing a new type TCP_ABORT_ON_MEMORY for tcp reset reason to handle out of memory case. Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet --- include/net/rstreason.h | 6 ++++++ net/ipv4/tcp.c | 2 +- net/ipv4/tcp_timer.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/net/rstreason.h b/include/net/rstreason.h index fbbaeb969e6a..eef658da8952 100644 --- a/include/net/rstreason.h +++ b/include/net/rstreason.h @@ -19,6 +19,7 @@ FN(INVALID_SYN) \ FN(TCP_ABORT_ON_CLOSE) \ FN(TCP_ABORT_ON_LINGER) \ + FN(TCP_ABORT_ON_MEMORY) \ FN(MPTCP_RST_EUNSPEC) \ FN(MPTCP_RST_EMPTCP) \ FN(MPTCP_RST_ERESOURCE) \ @@ -96,6 +97,11 @@ enum sk_rst_reason { * corresponding to LINUX_MIB_TCPABORTONLINGER */ SK_RST_REASON_TCP_ABORT_ON_LINGER, + /** + * @SK_RST_REASON_TCP_ABORT_ON_MEMORY: abort on memory + * corresponding to LINUX_MIB_TCPABORTONMEMORY + */ + SK_RST_REASON_TCP_ABORT_ON_MEMORY, /* Copy from include/uapi/linux/mptcp.h. * These reset fields will not be changed since they adhere to diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 5b0f1d1fc697..fd928c447ce8 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2927,7 +2927,7 @@ void __tcp_close(struct sock *sk, long timeout) if (tcp_check_oom(sk, 0)) { tcp_set_state(sk, TCP_CLOSE); tcp_send_active_reset(sk, GFP_ATOMIC, - SK_RST_REASON_NOT_SPECIFIED); + SK_RST_REASON_TCP_ABORT_ON_MEMORY); __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY); } else if (!check_net(sock_net(sk))) { diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 4d40615dc8fc..0fba4a4fb988 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -125,7 +125,7 @@ static int tcp_out_of_resources(struct sock *sk, bool do_reset) do_reset = true; if (do_reset) tcp_send_active_reset(sk, GFP_ATOMIC, - SK_RST_REASON_NOT_SPECIFIED); + SK_RST_REASON_TCP_ABORT_ON_MEMORY); tcp_done(sk); __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY); return 1; From patchwork Thu Aug 1 14:54:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13750620 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF3D21A99CA for ; Thu, 1 Aug 2024 14:55:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524104; cv=none; b=B5ZEaT9J0E5m4GEGXTcDclnqHLsgzhhMnj5vNw11e49Rkpuob98a60pANYRSAGgCET7jaAyDrz4XhbIV+d0pqGCcXFsRceMLylOsCnSqV/pyonl9ricJtx24HnY6IIirxfzdj0IzFCN3UOjWJnR8t1X679wAkajJy+gKzf5oKJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524104; c=relaxed/simple; bh=40qsXruOSw79gTHVXcGlmBLPZGor8ZQ+cJwFxP9+6Z4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yb0kUVYfBb+uad110BMiHz9+J1oE99Ob3EO7yg57bUdmGo2mVGpKHJ406KYye4ymxST9gIXb89KMpw9KtNCxUeZuXtR95Y0KK1SzDX64m4c+WIAu+qWS3AWriJ92w3i3A9AU/hps6SZLEzNxvWTC/fYOZXBL+lZWVn6iBrIzkR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TKkOi7oD; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TKkOi7oD" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70d1a74a43bso5212198b3a.1 for ; Thu, 01 Aug 2024 07:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722524102; x=1723128902; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BbIhvip/hguhyYk7xdPEmCjiRFpey3/NxNJuPwFxjx8=; b=TKkOi7oDGcanhnOYSB18vp2FXZVKMbtDvrg/WmhSOApdxtiIagcgR+WmZVS6Ig909z G1zjEe1ENwTRz7zDxC/X8AN8ukQGDM4ckF69oa9smnH4HlybrBxi7XTCr2/WcTp050Rl M7jAhUHF0AFCOYQgqiizk78aZAV01WhBIuCs8niyl1yI8l5xzQDrMrbyqvUh9zdj6JxI r0Efhy4TbPOeE6THobq1bxyrq0f+Uwo00NT+6jGK3/WzBysFJz+jMb2YQ2kwSGy16WnT aPra/Qd2cFV7meNWzV6H/ci9msnOaIwd9SAdzguw8+BiBh89PWdeSiFmWP6w6Fd28s3X b6uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524102; x=1723128902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BbIhvip/hguhyYk7xdPEmCjiRFpey3/NxNJuPwFxjx8=; b=sRZtNCuSCu7wBmCrQ20y89v4/HxDepHGUB0779sNDRwQ3cejY+KbfQq5zBRO5WR/T+ MNAOSqrE+QpcuwW5KY91oPobW75nfCaN5dkqDS+w3j5Ocf1E0nLBlFJ4J0BzQesTISV0 nq4rP7QV7rXgW/Mt3uP3qkNj4y7Hq0YaLbGqzpfaC5uBVwGMqkuB8d9uhij3Vx9wfaOh sJ9nImQcqNB4QGXaH1KtjY6mXS74MvhXbcx4C3ESLITZkI4xQ4keFsXMFAzG4Qjy/Pae 65Kld8LCgeqE8aF0ZzhS/Fnh4AQ8Vyc8Dckwi2Xss8VA030HYdDPleb0Ki7iTWubIa91 cwQg== X-Gm-Message-State: AOJu0YyoIyTv8Tv86BXgervm+vOjiOJcWyrccFRGQWhumky1c1zvSXZg mXpEbpzv15tKjPzIbK+PYxx7H5a0Erie65TUsFc959snisgx0ITpFTmbQ7Fn X-Google-Smtp-Source: AGHT+IFq/L1buLhI2/mon5LWC3XFVkMYBfgKtMPcxiQwBlnlvLQPNcFp3DRMXYWGm7T0CwzUnP99oQ== X-Received: by 2002:a05:6a21:78a7:b0:1c0:f5fa:d1e9 with SMTP id adf61e73a8af0-1c69955f4c8mr759738637.15.1722524102020; Thu, 01 Aug 2024 07:55:02 -0700 (PDT) Received: from KERNELXING-MC1.tencent.com ([114.253.36.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead8a35c7sm11611739b3a.200.2024.08.01.07.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:55:01 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 4/7] tcp: rstreason: introduce SK_RST_REASON_TCP_STATE for active reset Date: Thu, 1 Aug 2024 22:54:41 +0800 Message-Id: <20240801145444.22988-5-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240801145444.22988-1-kerneljasonxing@gmail.com> References: <20240801145444.22988-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Introducing a new type TCP_STATE to handle some reset conditions appearing in RFC 793 due to its socket state. Actually, we can look into RFC 9293 which has no discrepancy about this part. Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet --- v3 Link: https://lore.kernel.org/all/20240731120955.23542-5-kerneljasonxing@gmail.com/ 1. remove one case from tcp_disconnect, which will be separately categorized as another reason in the later patch (Eric) V2 Link: https://lore.kernel.org/all/20240730200633.93761-1-kuniyu@amazon.com/ 1. use RFC 9293 instead of RFC 793 which is too old (Kuniyuki) --- include/net/rstreason.h | 6 ++++++ net/ipv4/tcp.c | 10 ++++++---- net/ipv4/tcp_timer.c | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/net/rstreason.h b/include/net/rstreason.h index eef658da8952..bbf20d0bbde7 100644 --- a/include/net/rstreason.h +++ b/include/net/rstreason.h @@ -20,6 +20,7 @@ FN(TCP_ABORT_ON_CLOSE) \ FN(TCP_ABORT_ON_LINGER) \ FN(TCP_ABORT_ON_MEMORY) \ + FN(TCP_STATE) \ FN(MPTCP_RST_EUNSPEC) \ FN(MPTCP_RST_EMPTCP) \ FN(MPTCP_RST_ERESOURCE) \ @@ -102,6 +103,11 @@ enum sk_rst_reason { * corresponding to LINUX_MIB_TCPABORTONMEMORY */ SK_RST_REASON_TCP_ABORT_ON_MEMORY, + /** + * @SK_RST_REASON_TCP_STATE: abort on tcp state + * Please see RFC 9293 for all possible reset conditions + */ + SK_RST_REASON_TCP_STATE, /* Copy from include/uapi/linux/mptcp.h. * These reset fields will not be changed since they adhere to diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index fd928c447ce8..24777e48bcc8 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3025,9 +3025,11 @@ int tcp_disconnect(struct sock *sk, int flags) inet_csk_listen_stop(sk); } else if (unlikely(tp->repair)) { WRITE_ONCE(sk->sk_err, ECONNABORTED); - } else if (tcp_need_reset(old_state) || - (tp->snd_nxt != tp->write_seq && - (1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK))) { + } else if (tcp_need_reset(old_state)) { + tcp_send_active_reset(sk, gfp_any(), SK_RST_REASON_TCP_STATE); + WRITE_ONCE(sk->sk_err, ECONNRESET); + } else if (tp->snd_nxt != tp->write_seq && + (1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK)) { /* The last check adjusts for discrepancy of Linux wrt. RFC * states */ @@ -4649,7 +4651,7 @@ int tcp_abort(struct sock *sk, int err) if (!sock_flag(sk, SOCK_DEAD)) { if (tcp_need_reset(sk->sk_state)) tcp_send_active_reset(sk, GFP_ATOMIC, - SK_RST_REASON_NOT_SPECIFIED); + SK_RST_REASON_TCP_STATE); tcp_done_with_error(sk, err); } diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 0fba4a4fb988..3910f6d8614e 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -779,7 +779,7 @@ static void tcp_keepalive_timer (struct timer_list *t) goto out; } } - tcp_send_active_reset(sk, GFP_ATOMIC, SK_RST_REASON_NOT_SPECIFIED); + tcp_send_active_reset(sk, GFP_ATOMIC, SK_RST_REASON_TCP_STATE); goto death; } From patchwork Thu Aug 1 14:54:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13750621 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B61EC1A99CA for ; Thu, 1 Aug 2024 14:55:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524107; cv=none; b=inM6OO04cqxossSaiK/gLEW+Rvnb5/6wihS3dFnCcq9m4Msucm7QZlHlXoiclZWSbLoCaDQDmV2SJknh1Tm793KK3HAc5LXqn5AEnPHeH7A9+vKuDj9QppCvFBCYf/y7QVOvpdkaQ1SZMRBOmzWxY3od9m5aYbzqDKUBT1TQafQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524107; c=relaxed/simple; bh=iQsBHPMzej199XDiMCLFw43+eqvJaB7M6OST/YxggWQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u2wIWbn97OCk1Pf/XttsOeisCijkGVA2YxBF9Ms4JvPGZalP9+cMXGbUsfsVTpwihDwKxTWLJjvyDUS/cleHhXrP0ZRtUwNyRoNMcLTWaacIicR6VEVBUNYg1AYv69/6rVMW1DR3izqwTnBPBoNwxr1H8wIHpAfwbSn9ctk9y50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YV5SugVD; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YV5SugVD" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70d162eef54so5034055b3a.3 for ; Thu, 01 Aug 2024 07:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722524105; x=1723128905; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=seZowJq8ofBZm4njTpyFIqdU4PxpR5t/1YZH579mLPs=; b=YV5SugVD803ckbfuJ8J5dLRjfkJNhh1BB7rAlU9vEfjgrpFxaFNUKAFuXk5E0LcBi/ NGv52uT4ZgOXqmXU5LknRBwDPMIQQc5CbSUEr3gkPuicMD9LvJdriMgB7MLpTv9t+F7N 1iXokPzYbKHq9mNgUlkz56OdxNioXQoSj+uXDyKm0EVFCtJoSjEq7sKk3+wyreu7KhzM Wm8iCKSufT1ORIBaojo96XzR+BYsVMigHiK8EsqZx4L1eOa8HO2sbsEYQ42PnE86zkQ3 EfWrZa9Os/6fcxytMZlnPgqcbPtZE0lwvjTQbps79AKW0PBD6L+kmxo0qpt4tjzcYc1u QxuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524105; x=1723128905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=seZowJq8ofBZm4njTpyFIqdU4PxpR5t/1YZH579mLPs=; b=XM/kgs0wcQgHMQqEPUrC2yjuvK8gqEOtj1ajeJcG/Xsk3Yz4k5Nun+DGteQKGzcImi CtZMDl7d0imgR7CofY6AXzUoYCcPfPmQsQ4gAB5ZW4YGNagCTFKs2vaRhVRN4mIZPxBi TgNxjU7jaFB8DKtX/0e+6AuFTQKkMYebkdouLdTUbO3SzSw1w46CCdFxXWqt8J8YtC0c 0PfOFVNysAFxNOTL2B+Gw88NV/6bdyrgFeDnzmHg8EYteCEk8h4025UWWJJVPXuYT+Xf z2xmuQ8oL4A/x9khQoraJv/r85J0YVatFllJNEC7mx4L3iIZCjnA6gHZiwS5232Sy69A biVg== X-Gm-Message-State: AOJu0YyHl+bH8ULXcncO18OHmFMF6J8xqowT7boiUPrj3nROOLIhXEtY O7tIrVSNDCmWwoLPdXh8lbFcKpeilznq55BLBsv6tmqW/X3KFnAo X-Google-Smtp-Source: AGHT+IFGND89cl8kNZyHN67YgyFDE/praYii3Hg5newbqz6TBtczxfMSl9t2BYCiA9OkdupqPSdU/A== X-Received: by 2002:a05:6a21:4a4c:b0:1bd:253e:28e with SMTP id adf61e73a8af0-1c699559f00mr539656637.16.1722524104928; Thu, 01 Aug 2024 07:55:04 -0700 (PDT) Received: from KERNELXING-MC1.tencent.com ([114.253.36.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead8a35c7sm11611739b3a.200.2024.08.01.07.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:55:04 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 5/7] tcp: rstreason: introduce SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT for active reset Date: Thu, 1 Aug 2024 22:54:42 +0800 Message-Id: <20240801145444.22988-6-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240801145444.22988-1-kerneljasonxing@gmail.com> References: <20240801145444.22988-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing When we find keepalive timeout here, we should send an RST to the other side. Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet --- v3 Link: https://lore.kernel.org/all/20240731120955.23542-6-kerneljasonxing@gmail.com/ 1. chose a better reason name (Eric) v2 Link: https://lore.kernel.org/all/CAL+tcoB-12pUS0adK8M_=C97aXewYYmDA6rJKLXvAXEHvEsWjA@mail.gmail.com/ 1. correct the comment and changelog --- include/net/rstreason.h | 7 +++++++ net/ipv4/tcp_timer.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/net/rstreason.h b/include/net/rstreason.h index bbf20d0bbde7..9c0c46df0e73 100644 --- a/include/net/rstreason.h +++ b/include/net/rstreason.h @@ -21,6 +21,7 @@ FN(TCP_ABORT_ON_LINGER) \ FN(TCP_ABORT_ON_MEMORY) \ FN(TCP_STATE) \ + FN(TCP_KEEPALIVE_TIMEOUT) \ FN(MPTCP_RST_EUNSPEC) \ FN(MPTCP_RST_EMPTCP) \ FN(MPTCP_RST_ERESOURCE) \ @@ -108,6 +109,12 @@ enum sk_rst_reason { * Please see RFC 9293 for all possible reset conditions */ SK_RST_REASON_TCP_STATE, + /** + * @SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT: time to timeout + * When we have already run out of all the chances, which means + * keepalive timeout, we have to reset the connection + */ + SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT, /* Copy from include/uapi/linux/mptcp.h. * These reset fields will not be changed since they adhere to diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 3910f6d8614e..86169127e4d1 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -807,7 +807,7 @@ static void tcp_keepalive_timer (struct timer_list *t) (user_timeout == 0 && icsk->icsk_probes_out >= keepalive_probes(tp))) { tcp_send_active_reset(sk, GFP_ATOMIC, - SK_RST_REASON_NOT_SPECIFIED); + SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT); tcp_write_err(sk); goto out; } From patchwork Thu Aug 1 14:54:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13750622 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0E6F1A99CA for ; Thu, 1 Aug 2024 14:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524110; cv=none; b=uEgl1BZMhIJLkIK738ECQ+tL+e/jkwQnKjZIgUxgWP89BvU9w121DYxF47FLU+xlQ+4jvEcV+eOjeuCPKKqNF+yABPMQjV/8+pKN0LZrPT90WSFDgbeYvSMWBwlLsSlVfKs1Zt+vlXS//y/C++RkVDwwT4yo3fm4XRjxjYN7WeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524110; c=relaxed/simple; bh=Dmj0V8OgWfrKhtt5PsVnzjpF+7ohbvzn4v0q56t8OwY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JhHEshEiPYU5myDYnXeQL3OxyocUAEst52cckJYptH4poa4sqt1bmtPuMiMENnu3MPvf/lwJgCN0AdLzV62LhfuWteZe+ZEvshmIjrbo0MD0s8aFpi9bccNQjqcfjmJVhfbmf1fLjkCybjorGpaL4q96MBBW8YaOJoPGZaB6y08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l6U84JfE; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l6U84JfE" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-70d18d4b94cso5258540b3a.2 for ; Thu, 01 Aug 2024 07:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722524108; x=1723128908; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q2rLibpd7acGhdAc2vkJkolLEgSRjykoNKK1O8+4F18=; b=l6U84JfEFkEdlRasTCumvSGgp7IH3H67yRMa0ORCO0BWtQjc9PJGRh+oAYYmoL4Dnz sOwtCmA29Hg00NgxnBtTQr3rvythON+Le76QPZ38s5wSEDcRDyk+7hIWtoiJIhX7DWEP T1OETtYS+LgNwR68V4HUWtB2CKqgHCZCRNjiMjPfVdRoO11pfm2BE3nhx2p/E3G6sAk8 L1/9/8hYQADFw5q5AF5Pu+FL292+JUkhpDOPaYD/0+oI83spZCY3c7npdw+zokBGdozD FXRPWJX9Qg7MohUYUqu3m3HhiD9caML/woZhDohdw3PYOGJsYZhxQzVbN9JAZyUmiHSn lhrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524108; x=1723128908; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q2rLibpd7acGhdAc2vkJkolLEgSRjykoNKK1O8+4F18=; b=J+Ufupn4IFQiqs1V61pE1EAOwZ4LlW76tK8IcS0rfMs6y9aI/3dhU7UVMFEc9qjfBG OVgQBZbG8PWU7FX3FU/tN78GOU7zMD3eXd9mf1z5fmL+Yr25E99hdE4zZj58u031xR6/ y1Cg65n88fn0Wrg1zhamvuLw/MiVFT0SWeqvoiIfpkfAGo8MM/e4ZN3T0PIaAuywDP2p QPQGWNIANp1CDf0Kq6/hlSH76aN3ff19TLYAi0xU3LaHlQQGMVc19z6scbAaOxsR0TTc 4ofp92u1TclH6PE5ZNWRWQKSWMZ16CzY3LFptFEZwaTwXJKstIRh7MwJKXsqr+4rZCyS 8rlA== X-Gm-Message-State: AOJu0YwZ9Tqdr1omZgjWaeYvLOnSmp05HAcRi+esqA8QZVzBigqS5baA wsVYh4wabS8UyLUeioOTcgLwQUXGL9zO7C0wSr9jyh59OjKMH8Ho X-Google-Smtp-Source: AGHT+IGwS437Iu3RZC5sYlLHe8H882zxhiDATHA3LoBUAiz5+I4lczDU7tl6ckCVbzVoxUqIAZi07g== X-Received: by 2002:a05:6a21:e8d:b0:1c4:17e1:14d0 with SMTP id adf61e73a8af0-1c69966a6dbmr498208637.47.1722524108006; Thu, 01 Aug 2024 07:55:08 -0700 (PDT) Received: from KERNELXING-MC1.tencent.com ([114.253.36.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead8a35c7sm11611739b3a.200.2024.08.01.07.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:55:07 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 6/7] tcp: rstreason: introduce SK_RST_REASON_TCP_DISCONNECT_WITH_DATA for active reset Date: Thu, 1 Aug 2024 22:54:43 +0800 Message-Id: <20240801145444.22988-7-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240801145444.22988-1-kerneljasonxing@gmail.com> References: <20240801145444.22988-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing When user tries to disconnect a socket and there are more data written into tcp write queue, we have to send an RST. Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet --- v3 Link: Link: https://lore.kernel.org/all/20240731120955.23542-5-kerneljasonxing@gmail.com/ 1. This case is different from previous patch, so we need to write it into a new patch. (Eric) --- include/net/rstreason.h | 8 ++++++++ net/ipv4/tcp.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/net/rstreason.h b/include/net/rstreason.h index 9c0c46df0e73..69cb2e52b7da 100644 --- a/include/net/rstreason.h +++ b/include/net/rstreason.h @@ -22,6 +22,7 @@ FN(TCP_ABORT_ON_MEMORY) \ FN(TCP_STATE) \ FN(TCP_KEEPALIVE_TIMEOUT) \ + FN(TCP_DISCONNECT_WITH_DATA) \ FN(MPTCP_RST_EUNSPEC) \ FN(MPTCP_RST_EMPTCP) \ FN(MPTCP_RST_ERESOURCE) \ @@ -115,6 +116,13 @@ enum sk_rst_reason { * keepalive timeout, we have to reset the connection */ SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT, + /** + * @SK_RST_REASON_TCP_DISCONNECT_WITH_DATA: disconnect when write + * queue is not empty + * It means user has written data into the write queue when doing + * disconnecting, so we have to send an RST. + */ + SK_RST_REASON_TCP_DISCONNECT_WITH_DATA, /* Copy from include/uapi/linux/mptcp.h. * These reset fields will not be changed since they adhere to diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 24777e48bcc8..8514257f4ecd 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3033,7 +3033,8 @@ int tcp_disconnect(struct sock *sk, int flags) /* The last check adjusts for discrepancy of Linux wrt. RFC * states */ - tcp_send_active_reset(sk, gfp_any(), SK_RST_REASON_NOT_SPECIFIED); + tcp_send_active_reset(sk, gfp_any(), + SK_RST_REASON_TCP_DISCONNECT_WITH_DATA); WRITE_ONCE(sk->sk_err, ECONNRESET); } else if (old_state == TCP_SYN_SENT) WRITE_ONCE(sk->sk_err, ECONNRESET); From patchwork Thu Aug 1 14:54:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13750623 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE93A1AC442 for ; Thu, 1 Aug 2024 14:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524113; cv=none; b=GjjhwUOyLK8uqzps7iTBgx0jKaJOJynaDd78DDZRv96qSTN/6I8r2bWQUNxMkyU44k9jp77a64Cnxz/pJVkLfx4tmfCaykk6xmvWrTA9f5BDGUeqkVhWsEyfgLWIOQ36eu4Y2RqIb6Eo0qhKlZI0vNWQMzPQyQ6Br7jAeeIIII4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722524113; c=relaxed/simple; bh=TJhLBE/1dDFmQcXMCrFDSflxqCoEQKoFBZolCz3PYeQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kV66rpXSgOSIy16+z1w5Fzknz4ey8TFKEV2PEq/aFiCtwwkUeE72917IDT9Xf3oECycjXAYTteF7T1EO1hMTjAoC1SRXFxZAqTFW0BrlL1V6d721fVQLenP235bBKqFLnTdXWT8RE2vaBBaqBFD0egxE4ySAydJbjaLVlcGqlNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XYRDvaWJ; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XYRDvaWJ" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70b703eda27so4546863b3a.3 for ; Thu, 01 Aug 2024 07:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722524111; x=1723128911; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2lFhtVGvFg8VrMx6un0IDEAfYudNTjtIlz6cdmYL4D8=; b=XYRDvaWJvDc/78QidRB6woDAyhsd3rDbIljjkcnG3dKZBwdgQQ1WvFk0wPfO3SVTdP Ay/5YJTQ8XmlVIzvx0tr17IR/fdS/JknN9pM/kIgEo3ryszYq7y4AyRUlsKGAoazFhmG v0MQgOqHzopq3Ka1SvfHu6QA+IL9UUv1624dY90dFgSl1qXHzPcVq8muJABYr2vyuuKE uxPp6P87UmWN5A9o+4bvI1SHw7CeQrRrftWEmAkKxT2rLVhUkubBo6oRwn6kpM0jW8Eg CxtqjVCjSky44eHOMLVaCGbAJnHMVfvtY/Ee+8PQ6kRhIWXLeB+rSz5kZXNNG4aeo5Af 1gTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524111; x=1723128911; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2lFhtVGvFg8VrMx6un0IDEAfYudNTjtIlz6cdmYL4D8=; b=PQobonuFViZ1FlcknYfC4Qp8HLtv1BtYeM/mcjEQgHsnW6fFv6HcUu8CRcVMclTAAm PBPLJUofx0+TOkqzdYHo2Hos3ZPkMgVGOrpS9iCamwyB/Tl2dhKx7JL2ijgXiZcUuoqj 8lxOmT2QrVdUKIULrVJzwejf3ylxPzmdHz9iMyvXD9UrfHb8wO0K5Bmmhu1sQMkbaJg+ S+Kcya82lARndYlIhEKtJ3BVB4ZT3BCbU+jd61tBmsDqu/Zq4d0bP8i/5WwyNxjmtp1E Q5RILjKaKbUfAZHoTiyU2ul6A8+woWPA7XPByVoDEOotTkdgyvy2eW/eyQEzk4FYZkHl lXPQ== X-Gm-Message-State: AOJu0YwaDbxQpqVs1VgccAF0QU+ejlsyAUFnB9kxbuQD5fHoUkCyOaRq 5Vr5lXhYfTcSMkSd6/hzla/oVp/bYYBEwBEU21IpasJHLWknxJOv X-Google-Smtp-Source: AGHT+IHajkU4oU+FKFJ2XtUm1UsJVmIOT6dTTQqFRX/q/P21f7AmoFlQfLzQAYRdQRPpm4Ki1pVlgA== X-Received: by 2002:a05:6a20:d501:b0:1c4:81a0:3783 with SMTP id adf61e73a8af0-1c699550da4mr427605637.11.1722524110900; Thu, 01 Aug 2024 07:55:10 -0700 (PDT) Received: from KERNELXING-MC1.tencent.com ([114.253.36.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead8a35c7sm11611739b3a.200.2024.08.01.07.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:55:10 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, kuniyu@amazon.com Cc: netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 7/7] tcp: rstreason: let it work finally in tcp_send_active_reset() Date: Thu, 1 Aug 2024 22:54:44 +0800 Message-Id: <20240801145444.22988-8-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240801145444.22988-1-kerneljasonxing@gmail.com> References: <20240801145444.22988-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Now it's time to let it work by using the 'reason' parameter in the trace world :) Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet --- net/ipv4/tcp_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 16c48df8df4c..cdd0def14427 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3649,7 +3649,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority, /* skb of trace_tcp_send_reset() keeps the skb that caused RST, * skb here is different to the troublesome skb, so use NULL */ - trace_tcp_send_reset(sk, NULL, SK_RST_REASON_NOT_SPECIFIED); + trace_tcp_send_reset(sk, NULL, reason); } /* Send a crossed SYN-ACK during socket establishment.