From patchwork Fri Aug 2 10:21:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13751408 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 B897D14B962 for ; Fri, 2 Aug 2024 10:21:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594084; cv=none; b=FPJQDajPcG+P65URCeT1pm8NdZx580Gpk5aboZ7Cny3c4VbXocrsNCQar6VMg757sF1KIowvs0JI6VJpNZRqlGaXZGSV8KfnoDfq8byRcPGGeyAhMx7VdSmjT7abqspvaYK1MEqu3QDv0njjOYIEKDBmJeNuhqfnye3DtpE2gD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594084; c=relaxed/simple; bh=xmrNaBt5a2CwB7pE8jwMkJ9DwMXjVuJmHd6iM+Z0v4Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IiBZf2Xix8yQJL3zRsq42AVM6dz94wj5OgTzMq5yatrGtSSSNBoYQLA37qQtKlQJCqeNsIXeP6dgTazdJL9c880eKm9NzvjNDX7Hrffv2fB92RXPN/4Lqx4PL+MH0lHg0SCZgseHSjHnnJEXYYewRIIWOK18yIkb7O2KqTk4vOA= 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=bzAUtB8D; arc=none smtp.client-ip=209.85.210.175 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="bzAUtB8D" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-70eb0ae23e4so5850985b3a.0 for ; Fri, 02 Aug 2024 03:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722594082; x=1723198882; 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=bzAUtB8Dnxovg/M3y037Tgtt2ZbsNc4oGYfB+dtRPtz5VW7LKktDaHSFnd+Rzy1oKp Hw1+Va6PdW9Svk6bVl3GMxiHXqyOYKpSFzNqL2CRJX1P+abDfvGWJXLkODSoP8Ny/KvQ 3x/OIYegUSmcZk1f5mobE00L05HMXhhQttOiisvz9HimbNZpGZBZsvXBJScv0US1l69z QnAx4mYJXxd1g7gmX50SKipAKxOKPQ/d57DMzcJxjW1oi3ONdASgxaGUYwSshuJq5VDl ZeXioM5UMKsgiNHnXLVHgDs7dQmFxWFYXq+joOnBZApXQ09C177PoeWvR3WnA5oMSTxZ 2qDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722594082; x=1723198882; 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=dIHBcDKMcJGdLu7bmlX91aXYK8eo3cGVUtZivgovo6JMw13+/4WaSe2UoGWAZrZecf 6LjSVZtsMqdNLVzdPly3ua5SfAAfY3bgXmvA1bTDYQmUY1foAXxXiLkZMvGpluYoV95f JN9NCHph0b2fE1u/rccb4E/urr6peoH61Zj0ECVtliMgg5IAFLW6KxuaLIY/pdb0Fzds IPgDLKoTL4vnZav00LuKyio592g6+GDWgxFTEiFRKNpumKGVHIN5ClMVUzE/PnzEE1QK F46VYU49MdqiJ625T9FosEmeKRMSljpCErou6vR+GRpBe4Ifaui92+zPxIhb8Aq5LrDH abGg== X-Gm-Message-State: AOJu0YxanWBbVqt8qF3L1mZBz+4Zz7ihDiQcPMrK+Taz1HOET5IjmZJM DTrxUnMhOBQHgVNga69aOUkIw2YlRnWqd0t+eNT3EXZiSBaN8vUd X-Google-Smtp-Source: AGHT+IGPEAV7vuWRdz++sY7EpAHIYk8Dv7YlXghHrfrlcpE77Jomiif7BDDK3UkY1R1lakeWaOHn+g== X-Received: by 2002:a05:6a00:c86:b0:706:3329:5533 with SMTP id d2e1a72fcca58-7106d02fae3mr3669516b3a.24.1722594081841; Fri, 02 Aug 2024 03:21:21 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b763469e79sm1109050a12.26.2024.08.02.03.21.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 03:21:21 -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 v4 1/7] tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_CLOSE for active reset Date: Fri, 2 Aug 2024 18:21:06 +0800 Message-Id: <20240802102112.9199-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240802102112.9199-1-kerneljasonxing@gmail.com> References: <20240802102112.9199-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 Fri Aug 2 10:21:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13751409 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 0D47914B962 for ; Fri, 2 Aug 2024 10:21:25 +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=1722594087; cv=none; b=rjo0CDQiDQYIdt65cHMtBgbdCs7/UazMmQCyeEpRMXUUVSlPQBFEs978aYDe9Smu/aSwuz5aGOFR8KISTHUqKa2sMA0DPIiC8CFGTAnFEU+SsnS4jxdb3LZ5/UQKHI4sR1+ikuW13M1dg4JNo6KSwSWyPGwRxqq2jZp0T1LOh2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594087; c=relaxed/simple; bh=bB5quX6hf5roJw3OqlmFW9vud3KXLMbEWmO1V3KzOcQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LB7W4+7iTssFVpXJat//F8vSz619ufJ1ObZaxI8Q/tosMU6SWhFU3XIGkeYrf7S5l5+hbJfGSe8QAP/UzW5dktqUPZBRKfHZXmW5zYc5qHvoL5VUCmDV9NtYiYCtJiSz6u6ex2v6tOm9hhvwAegfz/HOl1c/ZMCwoM3BDRIJKmE= 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=GO22HZTr; 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="GO22HZTr" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-70d150e8153so2114539b3a.0 for ; Fri, 02 Aug 2024 03:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722594085; x=1723198885; 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=GO22HZTrYoHqPzixAf0tl6i0vvp5fVG2daRAOtdStGj6e2C/HZ3qE5zhHupD0wdNX7 TbkV72Vc7ORkEv7CbWAHLEzU6o0c7GTDPDfvcr+oU8dAKmMYTd5gONIPW4l4t5sTkkKg jmOBYwoWM5XA57orsTeJfEmRZjnA/gPFmi8OrhVedAEu2QK3MneLtJQdnVgDxODiANXB RG5U2QWymImp+HBGuHVHx4z5+3ZweF3JNBsnqoHUBNFUqxK2sbKFaX7HVaVMTye89dYm LQ94c8/B1iI/LD2t00jVA63uNfgEkcj7IFhj7WB5vWodykU30RHo4Wpykl1gxqvOl/CU BIMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722594085; x=1723198885; 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=fbLhD1l/JXcovbTkAxufaFx8v9sHRuWMveqfZmpf6+UbKTVPfKesd5uxDNKN6Z2Awv hP2nprulubXaMDxcuZ4oyK2sgd7XV41vsS3X9xYwJ7aSwFog9OEizOVBb+YvW4GGqYK9 R7w8eT7RZ5fmFFw08DDMp2HLA4TcJBR5Do1Q94l/LhrW5IGrL2yjQ6TZtTQrKnIHKy3+ oCDbNr0EazfF2YQhNFTAmVWLGMvyMdiz1Yq44lFunj1Xz9CrB4sjfSeu0upapRmIe0Lv oWhBwQngMx5VGlGsb1ka0hlFflWkE2ME1O9rpiAq52jyVUCFfUGupOu+jp/rpIVPOMa7 PxXg== X-Gm-Message-State: AOJu0YyDdIceAd2QIBnPXZYbENMEVwf/XTEflFFbJyGP9ovCNXcNVICf R0/jEWQ0IJIuoodDcWQLcwPnryCBCg66vxFydLtpbzdMw6cxY9EN X-Google-Smtp-Source: AGHT+IEsBu+JISJoGDT4pX/YiVo6orwMLVWkQcMBQgYj8Acv3ftrY26Ad6R+2LyeUPP8WXp1W3+N/A== X-Received: by 2002:a05:6a00:9150:b0:70e:cee8:264a with SMTP id d2e1a72fcca58-71065de1a9bmr6973560b3a.1.1722594085056; Fri, 02 Aug 2024 03:21:25 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b763469e79sm1109050a12.26.2024.08.02.03.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 03:21:24 -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 v4 2/7] tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_LINGER for active reset Date: Fri, 2 Aug 2024 18:21:07 +0800 Message-Id: <20240802102112.9199-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240802102112.9199-1-kerneljasonxing@gmail.com> References: <20240802102112.9199-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 Fri Aug 2 10:21:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13751410 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 23AE114B962 for ; Fri, 2 Aug 2024 10:21:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594090; cv=none; b=rmeXGtvAQo+nbxUcQS3Fb8gRIp9+26N9aSPidn2KrxfTiDz7x59INTnb+P5AmFuYX1uZA1tIyEfJdMk2m1QO/RB6d6JMAF4E+z93iKFL+7u30E2Xm+BYUIbPZv0RxZ39pR0ywlBt/JFUjyOczgtRgoV+KZWQdXeuRsRf5d/aego= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594090; c=relaxed/simple; bh=g3fhbhumzkeNAkIMtG7+6lCFSXQXdNT2W0/nZ/J6upk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ga6hLwvxA9GIu5nOabogUrmWx3j2VTRcaDo7MZ3k0ZC4L//kFrhhc+xImqT0pEEEdWENLQFGmZenlwbEu9DtbfCJoXk4VpGMbUTfDQSFExHPdJpLCa+Yo93z0dBDbquhRTp+0Gz479ECUoEKFgyMIG6fHOmgZFdT4FCerfOVVqk= 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=ZfCkuxoX; arc=none smtp.client-ip=209.85.210.44 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="ZfCkuxoX" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-70949118d26so5070433a34.0 for ; Fri, 02 Aug 2024 03:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722594088; x=1723198888; 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=ZfCkuxoXC27xqF0bzYCWctplPJqLr/oCzmzyArEKclzo+uHKvOrQv71kQQKW9HI338 8kkIZ7iQNSCw5e8NTME8k7F/5uZ7PIyg2JcnlwhdMPX8IdcVfcNWgZImMEDK+6u9BKVM wGCMsBZxT3XwwbaSPQ+e/tiPo/E70oeceh9qWRRzLu6O4SsSU/alZq8Y8Y9S0hC27k8V 53XKQPDp9250yf7TqdPskCqAXyxrGNkrpjDQHojNWqdgrX7YfI2kJKh8PZifVugiGIFI BFC0T7kNcDvhViurWhlOKAWgaKCytGZDIyAosm5iJSe9213VwpeGf7IHMcRFKyoF2HBM MllQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722594088; x=1723198888; 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=Aul23cF4hfL9Bja7InBrWFWbnwOTcHCEpgauxa4GUSzDUjUJZp8Fn2LAXPVsELbexN s9lyQLiUT5V78aQsNtsV1k2UGnJe6OY31SFpw6sOM1iKZ2r0gUZ5U8VduBTjb6pKF6ar 0hBr8jumo9UGGA8p/T9LMcVyF4VYJFnAQ4ec9sCgZZIfYkel4s8AsNkayC60qWDjP1It HmIST0HIGn22el95W9u20SvXwyLwwvCfYgtzc5aUaP+5BTPnnl3K1X8rZEOxHrIjNCRl PR1hgf1es2or3AICi84zO8HUG0YFIu66HOqaQRwifrbzR1vyxnG1iWxhk2wAlNA+7zkU 2yLQ== X-Gm-Message-State: AOJu0YxwnGWespytwauYk6ngKcOWuyFKEthEvSdjq517+wuYFE9dpynD 5JUT2wNepcWgWsR57gf85oKDH5eEahWKIhxdPbL6ou6Kyr56RXd+ X-Google-Smtp-Source: AGHT+IET/33mmYN6obSl+jHVmzARlT53MPo74lmdQMyigs/AbTItDJ6Zi4PeYMF6jw6oHvBQmugXLg== X-Received: by 2002:a05:6830:6585:b0:709:3e50:f24b with SMTP id 46e09a7af769-709b323eaa3mr3331137a34.20.1722594088078; Fri, 02 Aug 2024 03:21:28 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b763469e79sm1109050a12.26.2024.08.02.03.21.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 03:21:27 -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 v4 3/7] tcp: rstreason: introduce SK_RST_REASON_TCP_ABORT_ON_MEMORY for active reset Date: Fri, 2 Aug 2024 18:21:08 +0800 Message-Id: <20240802102112.9199-4-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240802102112.9199-1-kerneljasonxing@gmail.com> References: <20240802102112.9199-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 Fri Aug 2 10:21:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13751411 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.46]) (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 2FFB63FE4A for ; Fri, 2 Aug 2024 10:21:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594094; cv=none; b=TmBIezrQL2yJqF0n1p25LIpCXGYFCv8lsy+87hxI61csc1yNXnYB3HKs2C//uCgTM55wl57Wjn9+LpUTNF6fOeMc98TzgPJNCqSE0/X0iA0U6yHsBWj7VaJMsPkf5iqwFI9E1VRylRq/amUfP/7AKCtHDX4aJ6Y99cZK5Q9kBGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594094; c=relaxed/simple; bh=vUy6ppz3XH81EZK2zrGj89sqmf15Y97Pw0B1juU9Dvk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OZ1mHHkWhPBk7kol+hFL91zDQJwrYHOZHmBEqLX9Ktqt5enZrw29azTVJAFOM+DT6wXsKBXUWHJr9yKT/EDl/6uMOTe6MryFd798jnbhOd+hdLyDuwhW2kFsYUOlo2QZS93VC689nhCS1mbEp2pcaCRrEADrOiPPWNiWysqWFko= 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=gsG95LsJ; arc=none smtp.client-ip=209.85.160.46 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="gsG95LsJ" Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-2610623f445so5251283fac.1 for ; Fri, 02 Aug 2024 03:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722594091; x=1723198891; 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=Yh/nFJhVgDc7iu6LZb/1AqpfqlML4cdyZgKqK3RH2OI=; b=gsG95LsJcR8OvWOgwF71RBIR88jZ07A2lzkuY3ZsK7cxWt5QBuHFcaKXgNb6432YOZ I7/PmU6rqgrjL3JGmsq9oyYd+0cXwMS4tn1SsARCNbGzH61EfXYHSBFKWwZOoBITQPFE uCeJM8TQimttafrFTg7UTiIyADz/jBUHJ8f7xJOa7I1kf0ZWcPTogeWq1JjLtVPxdlBQ lAmUqBTeiXUcv0p75mA4A3oljjKe5vgNJHUutisxeFZRnEVj+EaWzA/C/4qtkXY7wB4K rFI7c3FHVK3cHChvlDt9wvTlwIjc2WCLmzM89yNHRERs93d2ifXD60aBmJQDVbNiy1df FYJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722594091; x=1723198891; 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=Yh/nFJhVgDc7iu6LZb/1AqpfqlML4cdyZgKqK3RH2OI=; b=N39M6FaxRYYDXliedUq+oKRKYz8uo5IQGqCNOeZmgS6yvJnWml4APEZD0DbhViWTmk 4aWP8W1DAecVSTpszihfuLtlt0RojqzyyqlKtU0bNu0hbpU0SWI74+xppsg+TnUmVGnP dM1I64kQiTG+8weIXf0O8MyZHaWDTaBFLw0GajwQOaZ75q6fIoUEhLygd0Zp9gYJ3bM8 O5JqQeyqfQGg42Yg+nlOZ1/8YOG/qVG4JJn1g94SjeyEdru0xkm+DKYY/2fAFUCh/Bck 5ohXNdM+LKL0aaMXyhC9kQWW4pcY7aKOI+N92R7nXmVUUVGMVDhMlqy+guFBiFzCgcrh QRLA== X-Gm-Message-State: AOJu0YxvazqsFR2amuhwBohQR8ffIkj9aJtZBCkAFsP7gKDAS36ZHJA0 mfyHIu/V4yANhOjsKxdLtG51/V+IMwBSXiI+B2PPo15Aufie0HwU X-Google-Smtp-Source: AGHT+IGNTVYYsVdhj11YxxEWpprJ8U4bnxjDp8amL2LTvKdoTjG/8DwPOci+G41rYmjXgZvZa7eWmw== X-Received: by 2002:a05:6870:968c:b0:261:2c4:f7a0 with SMTP id 586e51a60fabf-26891f41374mr3098353fac.51.1722594091114; Fri, 02 Aug 2024 03:21:31 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b763469e79sm1109050a12.26.2024.08.02.03.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 03:21:30 -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 v4 4/7] tcp: rstreason: introduce SK_RST_REASON_TCP_STATE for active reset Date: Fri, 2 Aug 2024 18:21:09 +0800 Message-Id: <20240802102112.9199-5-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240802102112.9199-1-kerneljasonxing@gmail.com> References: <20240802102112.9199-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 Fri Aug 2 10:21:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13751412 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 1664A14B962 for ; Fri, 2 Aug 2024 10:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594096; cv=none; b=bOQmQ8u4W+I3XaaVnrGGJ65z+XIRSNCtNcssDCIT65SewwJiBIzmDu2k0Ya1tzyYKsQurtpQIoaBoTB5m813stVXsjcu1+7OqizGvO6lI64/NCD8z/ikxoRj91kVjKmEKduV4FK1CKtGGz3Q3yhttVDMA2/6t7j5fz9Z+5x7WIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594096; c=relaxed/simple; bh=TAf7vSMPjg9YoUJQxzY3quR/+whtotVL+zF3O5FIKY0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VbL49s75nU6+CTjhi+FS/6MlIdjLUxZxtMNeXbmumOL2dUvMd+CmQS+HIT8ikiNP/gnK4RAcP59f1DLA7zwx2AUnZk7xtJKNWJSkMuEnqDI00vsUkFaPXzrxfSfBh0J5B5Myn6SenHz4ZGyj15Y0LDK2AHzcntnOJ/WR8lw+tfI= 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=Ndm5H5Hl; arc=none smtp.client-ip=209.85.210.45 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="Ndm5H5Hl" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-70938328a0aso3597469a34.1 for ; Fri, 02 Aug 2024 03:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722594094; x=1723198894; 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=8o8y3DpLGZWl/CzpBkARBWumRB0/ZAK66arUOn9zZFw=; b=Ndm5H5Hl/SfUwLPnIvcxPNNytKSimxa/4Yu2iSmPfMnJxN88ZshywMjSUlhsyy+jiV zE5LzTPko30MYgt+wT+E56Frv36s/bskV+I2pN0SSz7ARp0nlhJGLWOy5/4Ql0L9mrTA 1JrMzHU7y8OueeiSlpC5voS/oKEIxWZdyL/22X6J37OKBiDawXR1Mcnuzsi3eS7MbtJM NrjoxTKC80z8VQldI2Vxoa1RpAf5aASGLqbKCX1RqVbWDMGo+u0G1Pu++k5BvjXvnQW5 oJBuNbcUIe7xBtBeiTZz/txa1cTzdiEovD1OeEHBuZVJcmfTft+f/RFOP9Yh5OLg8tgh Xv4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722594094; x=1723198894; 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=8o8y3DpLGZWl/CzpBkARBWumRB0/ZAK66arUOn9zZFw=; b=iU62YN94Q8nl52PDTip0hiJru117Gz2Y58Pzmf9PqXwCwk3AI0IDwRipJYmxrrPttf kQkx1t81OOUh/K4V6xvqAfwzF8HqNBpigt+Trju2Bh7WIorX4hPLv14c01K/5t+8OFR7 zo51Luc2ju2ZvfxP7NKob7eThzL2oCM29y+qUGvBAK6uSDG88FtPXWRV+WFpSSTpwEYh fNMVf0o5fa+zWgdcHknF7g6exix1Jhm5501j2r4arPX71Mi3OEnYdpAsWk6O9ADbbrPy /8P0+CjIUOjh48/7dOiyRGZq5sarE8gpvZZwkJ23JfQxI+ZEAzPM69L0y3trHG249ogK 4MJA== X-Gm-Message-State: AOJu0YxuC3pESRguM6ZI6D8YGv2L9Ysi5su6F/4IXCHKOPnaCJmceTyB RsLB9PA1bv8OjT/ohhdSyu3d5asO5DDxN35Mc+qqpTpyA3CcLYku X-Google-Smtp-Source: AGHT+IEHCVVBr/5LhrU7dEMEy7rnBwOSkPjeiGaE+tfAl2mxTr4jfKWjpaHgYbM3srt/pMx4mgbGnw== X-Received: by 2002:a05:6830:7006:b0:709:48bd:b150 with SMTP id 46e09a7af769-709b3218eeamr3720825a34.14.1722594094126; Fri, 02 Aug 2024 03:21:34 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b763469e79sm1109050a12.26.2024.08.02.03.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 03:21:33 -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 v4 5/7] tcp: rstreason: introduce SK_RST_REASON_TCP_KEEPALIVE_TIMEOUT for active reset Date: Fri, 2 Aug 2024 18:21:10 +0800 Message-Id: <20240802102112.9199-6-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240802102112.9199-1-kerneljasonxing@gmail.com> References: <20240802102112.9199-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 this to show the users the reason of keepalive timeout. 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 Fri Aug 2 10:21:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13751413 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 3050C1DD38C for ; Fri, 2 Aug 2024 10:21:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594099; cv=none; b=uDDBJzZ3K4QtOOG3wA6u/tfeQMznClIXPbfs0OH0eFDDq3pXhBpFday7rUjVm7OdDmfDR2SW8fxIIzW/fssrUrgEI+IVREC1f6Iea5lP3ewLIb7E/rINtN00OEU84AVWpHIcKd3Hd4XxMup4gx1aBfS/4482zAkbHkDUx0P7JIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594099; c=relaxed/simple; bh=aLmR9AtcQnoMEso4BgolU96go//pa4IzcLIKCgZT8co=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nwf5M1ruVtmV1UynkY+M1i4zRwbsTubOx13F3dbiH2TgWqiXmzXxZS5YdFB23lk/wmi0EwYrJ70ie19mTKoySrZS7tm7xxMdW0mYfrpLK0Ro8mCSCWsukczKcnlwMhYspf36nJNxlhbX5z83Y9Utd0BPtMw1Gi5vNlZtCMuyNa0= 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=kMFg9I+e; arc=none smtp.client-ip=209.85.210.48 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="kMFg9I+e" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-70936061d0dso5266181a34.2 for ; Fri, 02 Aug 2024 03:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722594097; x=1723198897; 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=EwHm92BbLGHRx6QTtSopvfWeZrLAi9o2tWG1Id2MUAA=; b=kMFg9I+ePbovXvt3+Ectvr6Dbs4qCwJXCYELghGLZ1m/PJTlGkWhlZngueGdpoJaf9 mSe/4zLxCtCRfu1wGJn9MYiI8u5MkkzLRCEvju8Ql0J8KdcQiOCOi4zZOFcBXp9tO/9r 262ZECyen9a0zAmK+Yq1mr6o0eyWo5EVoEuqrm1Rt04SmlrbzLV4/X1AkjLnAdj0oPh7 vQphQe4u3ewJf24urwXkGB8X9X9lYWM9Cr9604rGxx58TidHqWD+q9ynKCGfkFmR7jwc AtrAlMyrwJCcxZ/0WCEqN81kBRnDpPs0bTdOQdLDfFDhTNXwwygqGu+lQW1+BMfHcume 5rug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722594097; x=1723198897; 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=EwHm92BbLGHRx6QTtSopvfWeZrLAi9o2tWG1Id2MUAA=; b=AR2dfEiI8QBbezmaE+BWCBcYGGHp/4NXAvOUqbm69CqPCcr3/xwMNmUppQM0r/Ulg+ ZLSCg/gNju+etfDRb0gLhlUNtIvBlC+o6UxLWA1vUtqcFi9ra1Sj7oM5xop99QgaOQ4F IG/Y+JkSAkvJmCf4O/FOf8gngClDKxVuQB54mlzvJjchJ+G902p3RPH83HEj/STDff/o rLd6+rUmLUiCjGyphS5ly7PVqD7WC01tKXS29rBb8JIDjQxS4HMbfzd9PNGtxQQkuW8M rewHOm8lYgwPZTfZIC9TtQZ2oVdBPvuqmWYdGoIL4ecZCPvhY3bZfcorBicdEUWtslqq CnRg== X-Gm-Message-State: AOJu0Yy91qRE2AiHrsLmhbFFphIQkcLxeFZUCp7OM+EYcBoLmLN4LgBA tZTolsvY6eEcS0zqUrQkeDFWZng5H4oxWle9MrGHA1FrcPJdgoaD X-Google-Smtp-Source: AGHT+IHj45lsLr+ftoSo7knhUgc/3P4AxLTtg5yOwL3yNVxzSFOn/BzRPJu0pMu3PLEIDkDzdXfh1g== X-Received: by 2002:a05:6830:b90:b0:709:4279:8347 with SMTP id 46e09a7af769-709b3205ae7mr3070460a34.8.1722594097153; Fri, 02 Aug 2024 03:21:37 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b763469e79sm1109050a12.26.2024.08.02.03.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 03:21:36 -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 v4 6/7] tcp: rstreason: introduce SK_RST_REASON_TCP_DISCONNECT_WITH_DATA for active reset Date: Fri, 2 Aug 2024 18:21:11 +0800 Message-Id: <20240802102112.9199-7-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240802102112.9199-1-kerneljasonxing@gmail.com> References: <20240802102112.9199-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 should tell users about this reset reason. 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 Fri Aug 2 10:21:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13751414 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 27E9F1DD38C for ; Fri, 2 Aug 2024 10:21:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594102; cv=none; b=Tlrt3fyIWOUnWzmXK0h3wjNcdRrru48vcvMUJ2OWAvz2vF7dmJMibvcH/R/1KUM7DgHZhmsZv3sJB5N5zvtdIgM0NDrp7HeFv85FjadLeDIOu95/ofrvl68ExiYH5Tb1nTMYrUPrcTiuZBhxDL+j79Bkrg5W9NEjmhEgPdlCqeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722594102; c=relaxed/simple; bh=8me7hWGnMh/VI+UQkp9dSUxUyotRWeAqroXVQfOCJqU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oTbXWtPu9Dsdfp5MJ0Cza9W2JgDrOKLTQn4ayPvtgfxNp6Nyhs8h2w+oVFe9iHezHmpamAYpFZdV1QBt/uLeAyHIi1tguIhp8vKyskpszAJqKsGbkr6UIhAgy5pBEXH1sp26bBH5An6POIZ5jk2HydAU452B0jUV4FuZNRbVf9c= 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=PQEa6q2y; arc=none smtp.client-ip=209.85.210.44 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="PQEa6q2y" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-7093705c708so8162809a34.1 for ; Fri, 02 Aug 2024 03:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722594100; x=1723198900; 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=E+NqjpnrLZwyJlHFfnhFSzF8pukIZ9OTEsJHNfMKwUQ=; b=PQEa6q2ymYE0Fs+1DGvYR4DH0K0VdHCP9kciflB/PHHq4iBqP+lWO5RW3FS4CWiyf3 5bqRG8pydFr+1xg2qiUfZLisGFbwlh8CsmIV25/JqMc3H9YeL90aUDFeeWYObaRZln1s xlokCCQYHrUKkk2wrif6JGoYzncRYxJ7dEymhwyGbfQvERIKTs2fYHzGsLyzlvo6veR9 3cVRbOtfErAhzXijD6pAhCEB8AGLnmhM7ihkq7FJJdXYadgbNqdScmS6eeABRtrUgZaA I41iNHKsOaqM9ch4ohdMC0brIQIeIVFcmraZvKpSNklyN++6GlRzqM1TBl2vmPSh3QBw X3mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722594100; x=1723198900; 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=E+NqjpnrLZwyJlHFfnhFSzF8pukIZ9OTEsJHNfMKwUQ=; b=aBhnHv58xVlu3hgXN5O9f7XYL5tmkbdkY0GT6hVOc7DqpKtOJ/SS6YoZPMwMVoBZyJ aqiKv/ZqnduLBdLP30sAd26oC4sSTaOk6KOMkOHff1s4/t7nlWMrmyHKXar7LCmE6tkB Y1ohWTR+j93wfIZx8PzZaqdFEovQ+O5XBBPEaJ8jEwm9fHc6fpoYnAhOeDPdBuQR0XdX Br72ojibdPVG+rvU8eheJQO4iF5ZsH1K0+/VtZF96p6AEwppZOLGd9ikXndqYTJ/90Au aQHMU3zmUT4PDoZa/ohUin0Cu/PV6BrhcXkUcdRuIKlb5oJxa6ZWluA4Y6Fn9WYHM1KC MKEw== X-Gm-Message-State: AOJu0Yxafm96sLEisJGoC5jMKcIFvXMq0lSNGkZA8aqvp5r2E1rENF7a 2DwE+EzRa3pKleT/9lrGiD9R/MF5SLdkgft2xfxtLWlG204FUrH/ X-Google-Smtp-Source: AGHT+IE6eZi93fKtOkzS/4J34wbHFwNuRaECCzbFVcHBmYwOxeAW9/eZekHepDUmtgb7hEpV2qN50g== X-Received: by 2002:a05:6830:6dc5:b0:703:6311:7798 with SMTP id 46e09a7af769-709aa00b761mr3939285a34.5.1722594100338; Fri, 02 Aug 2024 03:21:40 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b763469e79sm1109050a12.26.2024.08.02.03.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 03:21:39 -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 v4 7/7] tcp: rstreason: let it work finally in tcp_send_active_reset() Date: Fri, 2 Aug 2024 18:21:12 +0800 Message-Id: <20240802102112.9199-8-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240802102112.9199-1-kerneljasonxing@gmail.com> References: <20240802102112.9199-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.