From patchwork Tue Apr 9 10:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13622115 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 3DFC27EEF6; Tue, 9 Apr 2024 10:10:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657414; cv=none; b=EaOvzJE+baXHYnYwsgpJ4dSokhfBc3rSloUS6w835KbchLL54ee16UHa6RtRkh2I1WDs8lO26DgguCiSaZLGAah18enzjlap7cv+XH51GP97Wzxnpvs1qR4lUTe+SdoP0+tMgdT5BPvre3HvCuD9mTaftA3jC2VzrtBCDtWpBeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657414; c=relaxed/simple; bh=mlfxcIg4+Phml4qIdFRVfQLahA9cOJbdd5MjdoBa8Vs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uIgni6xQIX4LJECLurXeTV49nEDmftGWBUVlmpwrCvPISM3UO9jKVAqbvv4DKUlxa5DAQmevLxDvWsUoE0NPHBOW6+mEibZHHyxUHzxoUG5rftVNGmyAmqENjjyNyUJw7wNVEfegqC/MYIBuYSPI9Hmwuggynl5UObBspO7OcVs= 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=MtARYJJ3; arc=none smtp.client-ip=209.85.161.42 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="MtARYJJ3" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5aa20adda1dso2032679eaf.1; Tue, 09 Apr 2024 03:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712657412; x=1713262212; 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=PS2aNr/EX+hXSh4C6UyaT13e9lWbB8QJ2EHpJCpiGRg=; b=MtARYJJ3breDyv7AUxOTsK69nQXJmSxHvJBLbXcvvn1xCfI7JTAIqnu5FHDlpHMyp6 93/f72U0FRMXvf1LLLgpxW6lWGZvFI1k4efjmY7FV41HTMQd1nfeJ3vltZCqZYK6nVCq itQjRnyv8HuDsAp5al+W3dNDv4QdBhgJaopigYt/c9oxoQNnfwXFGg/0OtJLLBPyPrJP 0j/kg4gG8mHBhnvkxMrPIeLg2SsChq4lmWu7GyM28Tly5vHwblsNnwpS7gpOo1hqR8VW sy3MVUotQL0hfc5hzWWaMnSKFc6BIvFOJIOOMv2DzAFJ6tJxxNC+eX8Z+gQ+tpTG5zf3 4u2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712657412; x=1713262212; 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=PS2aNr/EX+hXSh4C6UyaT13e9lWbB8QJ2EHpJCpiGRg=; b=NssLg4KPdxQpuiAHyugykTYPe3HoqPUJgurqDApghgIQYrV8H/tRRQNW/Ff5Zvgf9k /j/g6eqAv00KCPbeCJoPpsnw6v/WdA7FoZ25aZ5pFXFFx/H6ME5mYPtVDh5/RgATPDbC lkLZzPJtCAfWuEQGH6clwMPnVI+EpCATdcoqRBN4RoidEkN1ymuBS5kywmB2o0OJpQw3 TptsGpNMlCKvDp3FGn89ZOJDRrcGGLGNF3tPr7QpnIOHK+SwRulBpRjfh9I6G2ga4Aht QqfNhDH7h/kxFWDe1HHU7vxr9jhGFUD4sx3FHe2WBHPK+IrrHd3nCM4gaFB10k7Y9naH geRg== X-Forwarded-Encrypted: i=1; AJvYcCXQ19iUoaUodPTli+9sOyr2xU67ceNsv02uThpN6eyVdtZK02nVBHSGghyadsnG50Ua+cveivaJ4F5JhTiGbiJ9dzfWiFmVokZ7HugAeLH62Mn2b4fg/JRH2J3SiV3SzdnUNFJQMx1DrQRw X-Gm-Message-State: AOJu0YyVve/fyJ/n3AJ6MFBPCJycHq8No+hyJI9x+8xSy5xHdp7KZUhn UwSFSgM4Adv7xHEH35ouJ5AWBZISBwB7Z3m8Fe8d07XY5bgihiEK X-Google-Smtp-Source: AGHT+IGAfyUuL5DqUrOODFzjKEsh3f6feDS348foF0B094yjqIPM8WrzuwwtI8F7juk8jb+VSRXq9Q== X-Received: by 2002:a05:6358:c92:b0:186:1193:8ccd with SMTP id o18-20020a0563580c9200b0018611938ccdmr9710915rwj.23.1712657412155; Tue, 09 Apr 2024 03:10:12 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.26.66]) by smtp.gmail.com with ESMTPSA id fn12-20020a056a002fcc00b006e5597994c8sm7959130pfb.5.2024.04.09.03.10.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:10:11 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 1/6] net: introduce rstreason to detect why the RST is sent Date: Tue, 9 Apr 2024 18:09:29 +0800 Message-Id: <20240409100934.37725-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240409100934.37725-1-kerneljasonxing@gmail.com> References: <20240409100934.37725-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 Add a new standalone file for the easy future extension to support both active reset and passive reset in the TCP/DCCP/MPTCP protocols. This patch only does the preparations for reset reason mechanism, nothing else changes. The reset reasons are divided into three parts: 1) reuse drop reasons for passive reset in TCP 2) reuse MP_TCPRST option for MPTCP 3) our own reasons I will implement the basic codes of active/passive reset reason in those three protocols, which is not complete for this moment. But it provides a new chance to let other people add more reasons into it:) Signed-off-by: Jason Xing --- include/net/rstreason.h | 93 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 include/net/rstreason.h diff --git a/include/net/rstreason.h b/include/net/rstreason.h new file mode 100644 index 000000000000..24d098a78a60 --- /dev/null +++ b/include/net/rstreason.h @@ -0,0 +1,93 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef _LINUX_RSTREASON_H +#define _LINUX_RSTREASON_H +#include + +#define DEFINE_RST_REASON(FN, FNe) \ + FN(MPTCP_RST_EUNSPEC) \ + FN(MPTCP_RST_EMPTCP) \ + FN(MPTCP_RST_ERESOURCE) \ + FN(MPTCP_RST_EPROHIBIT) \ + FN(MPTCP_RST_EWQ2BIG) \ + FN(MPTCP_RST_EBADPERF) \ + FN(MPTCP_RST_EMIDDLEBOX) \ + FN(NOT_SPECIFIED) \ + FNe(MAX) + +#define RST_REASON_START (SKB_DROP_REASON_MAX + 1) + +/* There are three parts in order: + * 1) 0 - SKB_DROP_REASON_MAX: rely on drop reasons for passive reset in TCP + * 2) SKB_DROP_REASON_MAX + 1 - MPTCP_RST_EMIDDLEBOX: for MPTCP use + * 3) MPTCP_RST_EMIDDLEBOX - SK_RST_REASON_MAX: independent reset reason + */ +enum sk_rst_reason { + /* Leave this 'blank' part (0-SKB_DROP_REASON_MAX) for the reuse + * of skb drop reason because rst reason relies on what drop reason + * indicates exactly why it could happen. + */ + + /* Copy from include/uapi/linux/mptcp.h. + * These reset fields will not be changed since they adhere to + * RFC 8684. So do not touch them. I'm going to list each definition + * of them respectively. + */ + /* Unspecified error. + * This is the default error; it implies that the subflow is no + * longer available. The presence of this option shows that the + * RST was generated by an MPTCP-aware device. + */ + SK_RST_REASON_MPTCP_RST_EUNSPEC = RST_REASON_START, + /* MPTCP-specific error. + * An error has been detected in the processing of MPTCP options. + * This is the usual reason code to return in the cases where a RST + * is being sent to close a subflow because of an invalid response. + */ + SK_RST_REASON_MPTCP_RST_EMPTCP, + /* Lack of resources. + * This code indicates that the sending host does not have enough + * resources to support the terminated subflow. + */ + SK_RST_REASON_MPTCP_RST_ERESOURCE, + /* Administratively prohibited. + * This code indicates that the requested subflow is prohibited by + * the policies of the sending host. + */ + SK_RST_REASON_MPTCP_RST_EPROHIBIT, + /* Too much outstanding data. + * This code indicates that there is an excessive amount of data + * that needs to be transmitted over the terminated subflow while + * having already been acknowledged over one or more other subflows. + * This may occur if a path has been unavailable for a short period + * and it is more efficient to reset and start again than it is to + * retransmit the queued data. + */ + SK_RST_REASON_MPTCP_RST_EWQ2BIG, + /* Unacceptable performance. + * This code indicates that the performance of this subflow was + * too low compared to the other subflows of this Multipath TCP + * connection. + */ + SK_RST_REASON_MPTCP_RST_EBADPERF, + /* Middlebox interference. + * Middlebox interference has been detected over this subflow, + * making MPTCP signaling invalid. For example, this may be sent + * if the checksum does not validate. + */ + SK_RST_REASON_MPTCP_RST_EMIDDLEBOX, + + /* For the real standalone socket reset reason, we start from here */ + SK_RST_REASON_NOT_SPECIFIED, + + /* Maximum of socket reset reasons. + * It shouldn't be used as a real 'reason'. + */ + SK_RST_REASON_MAX, +}; + +static inline int convert_mptcp_reason(int reason) +{ + return reason += RST_REASON_START; +} +#endif From patchwork Tue Apr 9 10:09:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13622116 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.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 86F1381216; Tue, 9 Apr 2024 10:10:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657421; cv=none; b=KLWfh2Nz024NWgUVIxecNQK+uTz6wGmvO/Zi3WEQu/22Rp6gCrpwe1Uz8jNe6He9KxG8wMhnm+iTblukci4b1uZLXD6EUja37NVIKc4r4fTaIPR7UXhE99qTQEJZO7ENKXdNFnZqXRVJtqesKC1k1YCh9K2bmUIub/PK/3MKtoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657421; c=relaxed/simple; bh=Ryk2a8gMrUQEYLfBH105b0dEWTWnzZ7PkMnJukIRdOo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N5HuHnD0JxoqDweWh3jLvd+GMQnsjKMKRdDyIt1ooRFFaUZG6pmNMWNSyKMS53hBMPqgssC+AyBDmOPp87Me3MLMu8IBldqA6HtCL4snzNzRivHRHdsNd/SkpXK9B1+JuWLpvnSeYMupx4ipnebHvmpOUYT+gZKK5W8PRrQx9GE= 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=cOY+ryPr; arc=none smtp.client-ip=209.85.160.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="cOY+ryPr" Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-22edbef3b4eso1009906fac.3; Tue, 09 Apr 2024 03:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712657418; x=1713262218; 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=8XnBPbBMi0eQ6f9JNdFgvEfMZSS6E4GsppVTC90HjhY=; b=cOY+ryPrnUxyoTnngZoKE9QGl3LR0mIO7r1XuKA1SHJfljcq1S9GDPEqMafdUn0Dk7 UqCy6hh/11XqUcxyfyJ620AtFZotb4iLFOa90HzB6/sX83H4aQq6LrQcdmqLqAF2u3tw ZJltbKJKuniLHwrW0nFTmlkBKkaZYNsQmd4hRUytKn6DzaajiBJHw+8z0b/4WPDtca8O PfQ/f9zC7iKqd8O0Ii1OtD855Ocd8WculAIhJmAF3mY/Vf8A38yRln7VLQ8ouA/2UPfa iSTi5ZZbbm7TAACLy6RJ9RzEdxSTCaQrX7f53NWy5ALUc5AOgmnxbg5QhYe23c0d4Uyb jX+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712657418; x=1713262218; 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=8XnBPbBMi0eQ6f9JNdFgvEfMZSS6E4GsppVTC90HjhY=; b=g8rih/WFvuaVM7XdLK0ti2sXR6gECiPbNyqi8N022aVl9kuaSEEC7y7VQwOrGbaJJv qL64IxDL+dX6jwbbt9aN9terl7SBoC2sFwdRBguF5vHexWzaAZtDVVuaSb/qJ9hi+F3/ XSvktQG7stTemqM+YpjTzmfWlR8awL0d9+M6qChSpJi1Ruz53LAVHeUZLBvVzl/vGsXK nE7POJO3uZHmzAjIb+/os5Z0hNa5yEnEUsEmDpdNA9mwB/doYAccbO7CX0+zFjcghQ1b PrcnQo9wE6ORnLh05T5mlPdSSVoxPzzMcTDZHqUCtzREnyejK3yBxwj1Y+yvRJyzChdY k7tA== X-Forwarded-Encrypted: i=1; AJvYcCU5NM11AW6lTwrbqmiORUB4vaLjTsXNNWjtSwqS02zg5ulDIO1VyQmZcT/iNLV4dA/X62VdZBYpnm2B/UD/ZuPyj5P9/x0UpehfrKV/SmC4S7d1d5H99ysnXPtzKLFYZwFzVkTCkAg4Bg6r X-Gm-Message-State: AOJu0YyH/wGqXEjQsdSgsJbgqBeJBfT9ZudHcPep4oq9Uz90FqyXKlfh i16hPPhMElz8JkDuXPq3vVdirvDW0xs1nG5DG/GqV8VjAT3f3FyI X-Google-Smtp-Source: AGHT+IFpjTJFTQ1CaX2jFpRxNaI+9m4JTX0XaRS/52gaBNYsPCwyWZ5r929Bx+68Oo2omMN3sL3jiw== X-Received: by 2002:a05:6870:1609:b0:22e:d20d:1274 with SMTP id b9-20020a056870160900b0022ed20d1274mr13307070oae.9.1712657418534; Tue, 09 Apr 2024 03:10:18 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.26.66]) by smtp.gmail.com with ESMTPSA id fn12-20020a056a002fcc00b006e5597994c8sm7959130pfb.5.2024.04.09.03.10.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:10:18 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 2/6] rstreason: prepare for passive reset Date: Tue, 9 Apr 2024 18:09:30 +0800 Message-Id: <20240409100934.37725-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240409100934.37725-1-kerneljasonxing@gmail.com> References: <20240409100934.37725-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 Adjust the parameter and support passing reason of reset which is for now NOT_SPECIFIED. No functional changes. Signed-off-by: Jason Xing --- include/net/request_sock.h | 3 ++- net/dccp/ipv4.c | 10 ++++++---- net/dccp/ipv6.c | 10 ++++++---- net/dccp/minisocks.c | 3 ++- net/ipv4/tcp_ipv4.c | 12 +++++++----- net/ipv4/tcp_minisocks.c | 3 ++- net/ipv6/tcp_ipv6.c | 15 +++++++++------ net/mptcp/subflow.c | 8 +++++--- 8 files changed, 39 insertions(+), 25 deletions(-) diff --git a/include/net/request_sock.h b/include/net/request_sock.h index 004e651e6067..93f9fee7e52f 100644 --- a/include/net/request_sock.h +++ b/include/net/request_sock.h @@ -34,7 +34,8 @@ struct request_sock_ops { void (*send_ack)(const struct sock *sk, struct sk_buff *skb, struct request_sock *req); void (*send_reset)(const struct sock *sk, - struct sk_buff *skb); + struct sk_buff *skb, + int reason); void (*destructor)(struct request_sock *req); void (*syn_ack_timeout)(const struct request_sock *req); }; diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c index 9fc9cea4c251..11b8d14be3e2 100644 --- a/net/dccp/ipv4.c +++ b/net/dccp/ipv4.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "ackvec.h" #include "ccid.h" @@ -521,7 +522,8 @@ static int dccp_v4_send_response(const struct sock *sk, struct request_sock *req return err; } -static void dccp_v4_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb) +static void dccp_v4_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb, + int reason) { int err; const struct iphdr *rxiph; @@ -706,7 +708,7 @@ int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) return 0; reset: - dccp_v4_ctl_send_reset(sk, skb); + dccp_v4_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); kfree_skb(skb); return 0; } @@ -869,7 +871,7 @@ static int dccp_v4_rcv(struct sk_buff *skb) if (nsk == sk) { reqsk_put(req); } else if (dccp_child_process(sk, nsk, skb)) { - dccp_v4_ctl_send_reset(sk, skb); + dccp_v4_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); goto discard_and_relse; } else { sock_put(sk); @@ -909,7 +911,7 @@ static int dccp_v4_rcv(struct sk_buff *skb) if (dh->dccph_type != DCCP_PKT_RESET) { DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION; - dccp_v4_ctl_send_reset(sk, skb); + dccp_v4_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); } discard_it: diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c index c8ca703dc331..232092dc3887 100644 --- a/net/dccp/ipv6.c +++ b/net/dccp/ipv6.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "dccp.h" #include "ipv6.h" @@ -256,7 +257,8 @@ static void dccp_v6_reqsk_destructor(struct request_sock *req) kfree_skb(inet_rsk(req)->pktopts); } -static void dccp_v6_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb) +static void dccp_v6_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb, + int reason) { const struct ipv6hdr *rxip6h; struct sk_buff *skb; @@ -656,7 +658,7 @@ static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) return 0; reset: - dccp_v6_ctl_send_reset(sk, skb); + dccp_v6_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); discard: if (opt_skb != NULL) __kfree_skb(opt_skb); @@ -762,7 +764,7 @@ static int dccp_v6_rcv(struct sk_buff *skb) if (nsk == sk) { reqsk_put(req); } else if (dccp_child_process(sk, nsk, skb)) { - dccp_v6_ctl_send_reset(sk, skb); + dccp_v6_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); goto discard_and_relse; } else { sock_put(sk); @@ -801,7 +803,7 @@ static int dccp_v6_rcv(struct sk_buff *skb) if (dh->dccph_type != DCCP_PKT_RESET) { DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION; - dccp_v6_ctl_send_reset(sk, skb); + dccp_v6_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); } discard_it: diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c index 64d805b27add..251a57cf5822 100644 --- a/net/dccp/minisocks.c +++ b/net/dccp/minisocks.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "ackvec.h" #include "ccid.h" @@ -202,7 +203,7 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb, DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_TOO_BUSY; drop: if (dccp_hdr(skb)->dccph_type != DCCP_PKT_RESET) - req->rsk_ops->send_reset(sk, skb); + req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); inet_csk_reqsk_queue_drop(sk, req); out: diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 52963c3bb8ca..21fa69445f7a 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -70,6 +70,7 @@ #include #include #include +#include #include #include @@ -723,7 +724,8 @@ static bool tcp_v4_ao_sign_reset(const struct sock *sk, struct sk_buff *skb, * Exception: precedence violation. We do not implement it in any case. */ -static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb) +static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb, + int reason) { const struct tcphdr *th = tcp_hdr(skb); struct { @@ -1933,7 +1935,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) return 0; reset: - tcp_v4_send_reset(rsk, skb); + tcp_v4_send_reset(rsk, skb, SK_RST_REASON_NOT_SPECIFIED); discard: kfree_skb_reason(skb, reason); /* Be careful here. If this function gets more complicated and @@ -2276,7 +2278,7 @@ int tcp_v4_rcv(struct sk_buff *skb) } else { drop_reason = tcp_child_process(sk, nsk, skb); if (drop_reason) { - tcp_v4_send_reset(nsk, skb); + tcp_v4_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED); goto discard_and_relse; } sock_put(sk); @@ -2354,7 +2356,7 @@ int tcp_v4_rcv(struct sk_buff *skb) bad_packet: __TCP_INC_STATS(net, TCP_MIB_INERRS); } else { - tcp_v4_send_reset(NULL, skb); + tcp_v4_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED); } discard_it: @@ -2405,7 +2407,7 @@ int tcp_v4_rcv(struct sk_buff *skb) tcp_v4_timewait_ack(sk, skb); break; case TCP_TW_RST: - tcp_v4_send_reset(sk, skb); + tcp_v4_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); inet_twsk_deschedule_put(inet_twsk(sk)); goto discard_it; case TCP_TW_SUCCESS:; diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 5b21a07ddf9a..2d7d81428c07 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -22,6 +22,7 @@ #include #include #include +#include static bool tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win) { @@ -879,7 +880,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, * avoid becoming vulnerable to outside attack aiming at * resetting legit local connections. */ - req->rsk_ops->send_reset(sk, skb); + req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); } else if (fastopen) { /* received a valid RST pkt */ reqsk_fastopen_remove(sk, req, true); tcp_reset(sk, skb); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index cffebaec66f1..7e591521b193 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -69,7 +70,8 @@ #include -static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb); +static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb, + int reason); static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb, struct request_sock *req); @@ -1006,7 +1008,8 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 kfree_skb(buff); } -static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb) +static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb, + int reason) { const struct tcphdr *th = tcp_hdr(skb); struct ipv6hdr *ipv6h = ipv6_hdr(skb); @@ -1675,7 +1678,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) return 0; reset: - tcp_v6_send_reset(sk, skb); + tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); discard: if (opt_skb) __kfree_skb(opt_skb); @@ -1861,7 +1864,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) } else { drop_reason = tcp_child_process(sk, nsk, skb); if (drop_reason) { - tcp_v6_send_reset(nsk, skb); + tcp_v6_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED); goto discard_and_relse; } sock_put(sk); @@ -1937,7 +1940,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) bad_packet: __TCP_INC_STATS(net, TCP_MIB_INERRS); } else { - tcp_v6_send_reset(NULL, skb); + tcp_v6_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED); } discard_it: @@ -1992,7 +1995,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) tcp_v6_timewait_ack(sk, skb); break; case TCP_TW_RST: - tcp_v6_send_reset(sk, skb); + tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); inet_twsk_deschedule_put(inet_twsk(sk)); goto discard_it; case TCP_TW_SUCCESS: diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 162b218d9858..744c87b6d5a4 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -20,6 +20,8 @@ #include #endif #include +#include + #include "protocol.h" #include "mib.h" @@ -307,7 +309,7 @@ static struct dst_entry *subflow_v4_route_req(const struct sock *sk, dst_release(dst); if (!req->syncookie) - tcp_request_sock_ops.send_reset(sk, skb); + tcp_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); return NULL; } @@ -374,7 +376,7 @@ static struct dst_entry *subflow_v6_route_req(const struct sock *sk, dst_release(dst); if (!req->syncookie) - tcp6_request_sock_ops.send_reset(sk, skb); + tcp6_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); return NULL; } #endif @@ -909,7 +911,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, tcp_rsk(req)->drop_req = true; inet_csk_prepare_for_destroy_sock(child); tcp_done(child); - req->rsk_ops->send_reset(sk, skb); + req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); /* The last child reference will be released by the caller */ return child; From patchwork Tue Apr 9 10:09:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13622117 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 C657D81216; Tue, 9 Apr 2024 10:10:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657427; cv=none; b=mCGZKhfwoxkHJmAM4CjCGo8a4TNNetwJSxRqPvJtdQkg45SxlcITCzSZBEIoiTUqgSb7DoxaXc95EnYvFwifvR539IZ2XX6aBcm9bwufbOVBX8xxrUeoJBtgm09FADxhM1oJcY8fiJPKypXjqcGbdcCrFImvwGgfnyI2kJsjZS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657427; c=relaxed/simple; bh=fHgork83N1CmeoPQUYdDdCjzJfawCToD+1ihJN6iHOc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dSdV2407cBczHq1HsTTOfaxFT3wUaqYJZ7K+fawpuvMICB/ktQNxWCsHWHWZpU7Pcq/31JykTwATa7INk4ucbLasml7jwaUSJ8zBNP4hkIv+axpNTUyxNH/W/fQerTR9OO2p9I1n1giJYe7IiIEYUo5Rj1EyJO/axLjggZ2Nmag= 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=ZOYEMBlP; arc=none smtp.client-ip=209.85.210.169 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="ZOYEMBlP" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6ed20fb620fso1925061b3a.2; Tue, 09 Apr 2024 03:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712657425; x=1713262225; 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=e7NTfCqGbM0sO5jjmpkTXDVXDPu910aVMjScLXweJ9U=; b=ZOYEMBlPWDKTM2f3OcD0mjR+uSGbSCYhiyivjKmAmGXYz6Jlo25BCXulIA9zrR5Q/z r+xbEsM+bRU6InMiiRIzq0uO/v/CZ4LgYzsud6GmzblAKpl8F7X9OxfM7cO3u3jDdMJk F8ushbkB2A2qhH2oZxdpCCL80YRjFQE8M0oAh5aMbjvZxmcoPILB54eenACM8mJ8KjSY kCht+PgchWdpz91ZsDv610xiOdEduePWWxMfZ6cDuTu3U3VogFIw6UHf3vBJN++jGlp2 IUDUCGTmXG70O1wiY8dyfKPqPFcbJmds3ozINZ/HEtTDIvNPICK/UK5qyl2uqEQzFzNp m/Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712657425; x=1713262225; 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=e7NTfCqGbM0sO5jjmpkTXDVXDPu910aVMjScLXweJ9U=; b=OopycEWiJ1JO0jbmEUcraqHxQlhcwv3M4Hm4tZ+l1C6YpjDv6Kw64fdw2HJJ3UKERs +J5/omrfK0zTaUkc/N2/JuxCDuEEh0DVhD1GpLtsufcWYFQ39sImEeJJ2z6EH6eoLg9u 0TTOzOKsn404mN5TSWF4uOdSFZYmaNP8ubjuWrIsVNjo1uLttYbsG6lttBzDX8Ijywy2 5KwVTQ7Y+CbP+PtF1NBAvQzYZm1CS8DWpl2/r9IQwFqkJmtUsoktKMkx9ZTs66+6VMKK 9g9shKhYCiZfOXuwxO+KKuOB5Q1RIGeSWce1Ad7L9IFR1/PXo7zCW4Ux+zGaJNeCfegM W7fg== X-Forwarded-Encrypted: i=1; AJvYcCXUBtd8cBfli1ciWGcdiz05Z2V7ggOztwUYphSjvAX5bwXIci2dnroNVdesRzu5RvkAyz2peyu2vTttLpxvdJ5A7E4GIbyDmpP48yTXWdJGsM89FYnIOyzcfAMWZgglWWRPxPs5I7FYWtfd X-Gm-Message-State: AOJu0YwGxGmS9MArx10RcpI8SEP+0UoglRvuvanbt0lI4W3B3xY16CQQ aYEczgpx75L/HY/15639Kw8owGA02K0xZ5LVoTFZ/gMNHuFue0Pc X-Google-Smtp-Source: AGHT+IFjHQ7g38MBiWpt7hJt/JfVol6t2RHrPKyK5QXyGWhwVD+eV2fhsZ0diVKA4F4hrcOgYTvDnQ== X-Received: by 2002:a05:6a00:2d87:b0:6e7:3939:505e with SMTP id fb7-20020a056a002d8700b006e73939505emr11919081pfb.2.1712657424981; Tue, 09 Apr 2024 03:10:24 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.26.66]) by smtp.gmail.com with ESMTPSA id fn12-20020a056a002fcc00b006e5597994c8sm7959130pfb.5.2024.04.09.03.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:10:24 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 3/6] rstreason: prepare for active reset Date: Tue, 9 Apr 2024 18:09:31 +0800 Message-Id: <20240409100934.37725-4-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240409100934.37725-1-kerneljasonxing@gmail.com> References: <20240409100934.37725-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 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 --- include/net/tcp.h | 2 +- net/ipv4/tcp.c | 15 ++++++++++----- net/ipv4/tcp_output.c | 2 +- net/ipv4/tcp_timer.c | 9 ++++++--- net/mptcp/protocol.c | 4 +++- net/mptcp/subflow.c | 5 +++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 9ab5b37e9d53..67ab4dbf7805 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -667,7 +667,7 @@ int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue, void tcp_send_probe0(struct sock *); int tcp_write_wakeup(struct sock *, int mib); void tcp_send_fin(struct sock *sk); -void tcp_send_active_reset(struct sock *sk, gfp_t priority); +void tcp_send_active_reset(struct sock *sk, gfp_t priority, int reason); int tcp_send_synack(struct sock *); void tcp_push_one(struct sock *, unsigned int mss_now); void __tcp_send_ack(struct sock *sk, u32 rcv_nxt); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 664c8ecb076b..d1610d4deb8f 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -275,6 +275,7 @@ #include #include #include +#include #include #include @@ -2805,7 +2806,8 @@ void __tcp_close(struct sock *sk, long timeout) /* Unread data was tossed, zap the connection. */ NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONCLOSE); tcp_set_state(sk, TCP_CLOSE); - tcp_send_active_reset(sk, sk->sk_allocation); + tcp_send_active_reset(sk, sk->sk_allocation, + SK_RST_REASON_NOT_SPECIFIED); } else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) { /* Check zero linger _after_ checking for unread data. */ sk->sk_prot->disconnect(sk, 0); @@ -2879,7 +2881,8 @@ void __tcp_close(struct sock *sk, long timeout) struct tcp_sock *tp = tcp_sk(sk); if (READ_ONCE(tp->linger2) < 0) { tcp_set_state(sk, TCP_CLOSE); - tcp_send_active_reset(sk, GFP_ATOMIC); + tcp_send_active_reset(sk, GFP_ATOMIC, + SK_RST_REASON_NOT_SPECIFIED); __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONLINGER); } else { @@ -2897,7 +2900,8 @@ void __tcp_close(struct sock *sk, long timeout) if (sk->sk_state != TCP_CLOSE) { if (tcp_check_oom(sk, 0)) { tcp_set_state(sk, TCP_CLOSE); - tcp_send_active_reset(sk, GFP_ATOMIC); + tcp_send_active_reset(sk, GFP_ATOMIC, + SK_RST_REASON_NOT_SPECIFIED); __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY); } else if (!check_net(sock_net(sk))) { @@ -3001,7 +3005,7 @@ 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()); + tcp_send_active_reset(sk, gfp_any(), SK_RST_REASON_NOT_SPECIFIED); WRITE_ONCE(sk->sk_err, ECONNRESET); } else if (old_state == TCP_SYN_SENT) WRITE_ONCE(sk->sk_err, ECONNRESET); @@ -4557,7 +4561,8 @@ int tcp_abort(struct sock *sk, int err) smp_wmb(); sk_error_report(sk); if (tcp_need_reset(sk->sk_state)) - tcp_send_active_reset(sk, GFP_ATOMIC); + tcp_send_active_reset(sk, GFP_ATOMIC, + SK_RST_REASON_NOT_SPECIFIED); tcp_done(sk); } diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 9282fafc0e61..6d807b5c1b9c 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3585,7 +3585,7 @@ void tcp_send_fin(struct sock *sk) * was unread data in the receive queue. This behavior is recommended * by RFC 2525, section 2.17. -DaveM */ -void tcp_send_active_reset(struct sock *sk, gfp_t priority) +void tcp_send_active_reset(struct sock *sk, gfp_t priority, int reason) { struct sk_buff *skb; diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 976db57b95d4..83fe7f62f7f1 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -22,6 +22,7 @@ #include #include #include +#include static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk) { @@ -127,7 +128,8 @@ static int tcp_out_of_resources(struct sock *sk, bool do_reset) (!tp->snd_wnd && !tp->packets_out)) do_reset = true; if (do_reset) - tcp_send_active_reset(sk, GFP_ATOMIC); + tcp_send_active_reset(sk, GFP_ATOMIC, + SK_RST_REASON_NOT_SPECIFIED); tcp_done(sk); __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY); return 1; @@ -768,7 +770,7 @@ static void tcp_keepalive_timer (struct timer_list *t) goto out; } } - tcp_send_active_reset(sk, GFP_ATOMIC); + tcp_send_active_reset(sk, GFP_ATOMIC, SK_RST_REASON_NOT_SPECIFIED); goto death; } @@ -795,7 +797,8 @@ static void tcp_keepalive_timer (struct timer_list *t) icsk->icsk_probes_out > 0) || (user_timeout == 0 && icsk->icsk_probes_out >= keepalive_probes(tp))) { - tcp_send_active_reset(sk, GFP_ATOMIC); + tcp_send_active_reset(sk, GFP_ATOMIC, + SK_RST_REASON_NOT_SPECIFIED); tcp_write_err(sk); goto out; } diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 995b53cd021c..212a1db3b2e3 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -21,6 +21,7 @@ #endif #include #include +#include #include #include "protocol.h" #include "mib.h" @@ -2565,7 +2566,8 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk) slow = lock_sock_fast(tcp_sk); if (tcp_sk->sk_state != TCP_CLOSE) { - tcp_send_active_reset(tcp_sk, GFP_ATOMIC); + tcp_send_active_reset(tcp_sk, GFP_ATOMIC, + SK_RST_REASON_NOT_SPECIFIED); tcp_set_state(tcp_sk, TCP_CLOSE); } unlock_sock_fast(tcp_sk, slow); diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 744c87b6d5a4..ba0a252c113f 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -412,7 +412,7 @@ void mptcp_subflow_reset(struct sock *ssk) /* must hold: tcp_done() could drop last reference on parent */ sock_hold(sk); - tcp_send_active_reset(ssk, GFP_ATOMIC); + tcp_send_active_reset(ssk, GFP_ATOMIC, SK_RST_REASON_NOT_SPECIFIED); tcp_done(ssk); if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &mptcp_sk(sk)->flags)) mptcp_schedule_work(sk); @@ -1348,7 +1348,8 @@ static bool subflow_check_data_avail(struct sock *ssk) tcp_set_state(ssk, TCP_CLOSE); while ((skb = skb_peek(&ssk->sk_receive_queue))) sk_eat_skb(ssk, skb); - tcp_send_active_reset(ssk, GFP_ATOMIC); + tcp_send_active_reset(ssk, GFP_ATOMIC, + SK_RST_REASON_NOT_SPECIFIED); WRITE_ONCE(subflow->data_avail, false); return false; } From patchwork Tue Apr 9 10:09:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13622118 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 F12C57EEF6; Tue, 9 Apr 2024 10:10:31 +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=1712657433; cv=none; b=idxNU/bNV54BNVQc9MDLYsAe6nDk528/ODuGZB9YWmQNvSvO/vQXZUwayX7TtD0pbBbGXTWt8a2KJIUiqleWkse+TG9xOe/L5Sw10meYqDzT6Dxw9TYhz0Ii1/xJIU/P31ihH+X8Cdp7s6AByg11FPESUCaKiP4cvmt0h2NicT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657433; c=relaxed/simple; bh=fnNRKmJnrR34kKc3z1CwBEQVAqIXILit5SjBo6YWcyY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AERG+l6pY7te4qlLSlHOXL+zomMyyc/mNbrXQrqHUdKA+7zHIyIhKEedZ02TTSA/oTUWwZl9piA2vGLvr9ZYeaZ9ArY1GNNK3EOw45JonaJsqsZTMc8I5nLFfpRwL9O//RsTrAumWwwb5c3dotin9WbwMAD4S7T/2771jqZED7s= 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=lB5/znp4; 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="lB5/znp4" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6ecf406551aso3762231b3a.2; Tue, 09 Apr 2024 03:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712657431; x=1713262231; 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=x8sgb1tDatwNXV1+CdBq8b0fZ/5liYZefyIkuO0GI+8=; b=lB5/znp4nr3kTwgQURz0ujOSGV72Ih6587IxQaLTi8/DmB37/0H0Sg0HV9CdGrWqpD 2vib39rfDqln3bJDjgsGHz35hESItPXxF5rM+bCYzly6U/v/lnvzUFlfgLCOPLZSUSxU DbrZ5tJj4y4xAZcfIVVPFpjl2irLbJReqM6H7fnICIldnZUX49mnjtftMV830WDigJur hPHOMOBiw+Bo7Ow6cwou+1WqvfQ6qi4JnskeErXC+VVY9PV8SxIv+6YbciXLij7TTkrK NDUeuJRhXrFxsJxeK5Xp91RvJ39I8sS2gfESKF8xRm0S6EPrzqIcYcrDf/wqd7NWC80J havw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712657431; x=1713262231; 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=x8sgb1tDatwNXV1+CdBq8b0fZ/5liYZefyIkuO0GI+8=; b=HV7/8P/YDXdU5fkHJJEmp3CsLCkKyE/4bHVhUl2mEciqQKdZ3g6TGDni7TDIaD4AZT rU43aldW7d4qyXEPUPJjh6ieaHmwFh8K/dPkAYTW5+MLixGYOLTihWaRgP3ICtKZ3cVj 9pco9YjmZSxTsKDl2QhrIz4eqDEapJoIYE3+kEj5VMP3DPFbLrZZpVDj6ZB/XGiBefHX 5qOdUkuTBa43+aCYqzJkdihxPy8Fs5MZHe10tlTQOcMvV/ddHtPWQPw7PlezQh60CqH2 AU/FHr4Wl7LsRd+todHbVg8/+tpt4/Y3U2tsRrzFAU8WCbI9JeGxhDK0JlxzTcJ7BLp5 XVww== X-Forwarded-Encrypted: i=1; AJvYcCXOkPUbQz3jeWvsZ6Mzkl1KVAmggvQ4No1Qc/mZZiIvYjM2qa11lWeXaeSRrxC2rKGX3GoU9RenypbIeoKY05HUK26OmG6f8nd/6BMpscmkxhVZ/DoP6UB1HnaRRvrpPOMNnpyMwmtdqxjK X-Gm-Message-State: AOJu0Yx8d0amtoiC/HCWabBM0GhLPanLgh3EYlEB22TZORFXSd+84v34 dAQboS1AhIUeGyGZqFryDjGjHv9HZo1fvKm/Uihf1MrXAP1+t2/c X-Google-Smtp-Source: AGHT+IF8oO9jcgQhJsIeCO/PBSwIMNI6Dx+dhCnqdC1k6DGvxwvZNsBpwSqfg85Ihj6o+CQnYRIK9g== X-Received: by 2002:a05:6a00:3c8e:b0:6ea:c4e7:26aa with SMTP id lm14-20020a056a003c8e00b006eac4e726aamr13121693pfb.13.1712657431215; Tue, 09 Apr 2024 03:10:31 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.26.66]) by smtp.gmail.com with ESMTPSA id fn12-20020a056a002fcc00b006e5597994c8sm7959130pfb.5.2024.04.09.03.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:10:30 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 4/6] tcp: support rstreason for passive reset Date: Tue, 9 Apr 2024 18:09:32 +0800 Message-Id: <20240409100934.37725-5-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240409100934.37725-1-kerneljasonxing@gmail.com> References: <20240409100934.37725-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 Reuse the dropreason logic to show the exact reason of tcp reset, so we don't need to implement those duplicated reset reasons. This patch replaces all the prior NOT_SPECIFIED reasons. Signed-off-by: Jason Xing --- net/ipv4/tcp_ipv4.c | 8 ++++---- net/ipv6/tcp_ipv6.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 21fa69445f7a..03c5af9decbf 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1935,7 +1935,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) return 0; reset: - tcp_v4_send_reset(rsk, skb, SK_RST_REASON_NOT_SPECIFIED); + tcp_v4_send_reset(rsk, skb, reason); discard: kfree_skb_reason(skb, reason); /* Be careful here. If this function gets more complicated and @@ -2278,7 +2278,7 @@ int tcp_v4_rcv(struct sk_buff *skb) } else { drop_reason = tcp_child_process(sk, nsk, skb); if (drop_reason) { - tcp_v4_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED); + tcp_v4_send_reset(nsk, skb, drop_reason); goto discard_and_relse; } sock_put(sk); @@ -2356,7 +2356,7 @@ int tcp_v4_rcv(struct sk_buff *skb) bad_packet: __TCP_INC_STATS(net, TCP_MIB_INERRS); } else { - tcp_v4_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED); + tcp_v4_send_reset(NULL, skb, drop_reason); } discard_it: @@ -2407,7 +2407,7 @@ int tcp_v4_rcv(struct sk_buff *skb) tcp_v4_timewait_ack(sk, skb); break; case TCP_TW_RST: - tcp_v4_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); + tcp_v4_send_reset(sk, skb, drop_reason); inet_twsk_deschedule_put(inet_twsk(sk)); goto discard_it; case TCP_TW_SUCCESS:; diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 7e591521b193..6889ea70c760 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1678,7 +1678,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) return 0; reset: - tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); + tcp_v6_send_reset(sk, skb, reason); discard: if (opt_skb) __kfree_skb(opt_skb); @@ -1864,7 +1864,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) } else { drop_reason = tcp_child_process(sk, nsk, skb); if (drop_reason) { - tcp_v6_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED); + tcp_v6_send_reset(nsk, skb, drop_reason); goto discard_and_relse; } sock_put(sk); @@ -1940,7 +1940,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) bad_packet: __TCP_INC_STATS(net, TCP_MIB_INERRS); } else { - tcp_v6_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED); + tcp_v6_send_reset(NULL, skb, drop_reason); } discard_it: @@ -1995,7 +1995,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) tcp_v6_timewait_ack(sk, skb); break; case TCP_TW_RST: - tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); + tcp_v6_send_reset(sk, skb, drop_reason); inet_twsk_deschedule_put(inet_twsk(sk)); goto discard_it; case TCP_TW_SUCCESS: From patchwork Tue Apr 9 10:09:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13622119 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 43FDA81723; Tue, 9 Apr 2024 10:10:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657439; cv=none; b=TxxJH2RTO+7L5q/mzq8doNvi+qHWPhQmOrxKee3TRMzqyTuexHgIrgwbhAip3gCrsa9HfoJLJNEZF0ZHjayoHuMXlu5QJhahIG7K56QPRukPZbXlTi6WF7yZORXQENhH335mLpmB+MfxTQS4JTMhbVIRMGCACfJOrSqnVfwZ4MM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657439; c=relaxed/simple; bh=vR6kbHqFQ3srkxogKcDP7Nt5k/mLa5xmK4UC1zZj96o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hlIwbT46r+i6eZ2MCuPTJcwR3j8PxGXbeWpfGU0MSX6IoxJEyxFRhUQL//o074N1Vk8Uu7GQWBASVT3TzC6vd67O4jkB4yOc6avijA8YCsms1QhYfz/BgdduinToqwxG2U5q27ogu1e3UAREJQx+jHplGcU96G5Hp1Y+0U1IVHo= 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=DQfZHH7V; arc=none smtp.client-ip=209.85.210.174 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="DQfZHH7V" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6ed32341906so1530611b3a.1; Tue, 09 Apr 2024 03:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712657437; x=1713262237; 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=W9njs262BXZ+KTO0nKZYKjQcAI0Rd6Xl4cj8uA5zuCE=; b=DQfZHH7VdBmXZXIjSXm38eTBc/PCvzjJq4ybC8aBff3urIUt0dz5T0empSHCRStzGN 33SnA6/7AhLPiPqC1mh49OaMbE1NNhOuYHmcytMmt2Bc2JEWDvUEhpYrEeTyBH+O3Nu2 NO6adVh0ZOCpl6ExsiVNW0K9ZQDz7b7cVR63GxRyso8/FX4eBUexfWcyyojKy8HAga/M d6iPg6mulDY929Y7pkEhuO0dkyPiPvTsnA0RTU2QjEGdY4vrk0xNcJRjHDmN9+W62BR1 pfYVbV8L9ld3tSYglqiM2rh7/Cl+qGArTs73xSRoZy8DlN1q9TvZjILAXirbHVZidHei WiLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712657437; x=1713262237; 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=W9njs262BXZ+KTO0nKZYKjQcAI0Rd6Xl4cj8uA5zuCE=; b=OSEN7Fp4+XtUSiHIuYAlNYbJOjx1rmlh9mvrgC1ruXH46HDLRbkHg5qcu7NP7ljaTh 5JZizqOkcZlqL8i6/Wkju/QSDVTmv7POhZ2+gCNPLoldnVr7dSpHCH/3ArHY7ZmlSSf8 jtyL1vdbFnL87oJkDl0SLCEcoBxr9lJ+RaFsGu0YivxXrXfB6JJO0hXrDQdSb4I7Daop h4G22UC8x2iOFqruhQvXf9AiFDn7rlAyMttJ6iMzscnI1+6G9r/JrUpuxkKehIHxczls 9eG6fjO3/Snmq3dS9fYq233fdncvlQ6Kea0kNFcyCxsEV/B0IgVFruSfjiEUU0LFT6Gy XJtQ== X-Forwarded-Encrypted: i=1; AJvYcCW1Vuwqa3jp6p5gEBP8M1g2BgqLtxHbQutz+6rUNotOl14edg4Bkjm23MUqet6m2HdJCJRc0XG5gkXfF1S6849Y/AKea68Lkfks8yhRKVEd+/RHr2pYcz6QFZtJkuomQKK+PbKnuQ8FujWd X-Gm-Message-State: AOJu0YxiQwP8L2mHrFLbYi5BKnLRtKMWU4FYOQ411RgY/H5I944f8LQV nPtoxZ6LTeWGznH3MXw3CqzNamiFn+POltYfrlTc7urYjiD6Z26H X-Google-Smtp-Source: AGHT+IGbDsK36pQYj/QkFCTE5pr2kBpve2qdJTIHdWw40y+MVtCjE2g6UTnZJRWLuyK348NB8A+fsQ== X-Received: by 2002:a05:6a00:4fca:b0:6ed:4288:68bc with SMTP id le10-20020a056a004fca00b006ed428868bcmr4068922pfb.19.1712657437479; Tue, 09 Apr 2024 03:10:37 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.26.66]) by smtp.gmail.com with ESMTPSA id fn12-20020a056a002fcc00b006e5597994c8sm7959130pfb.5.2024.04.09.03.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:10:37 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 5/6] mptcp: support rstreason for passive reset Date: Tue, 9 Apr 2024 18:09:33 +0800 Message-Id: <20240409100934.37725-6-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240409100934.37725-1-kerneljasonxing@gmail.com> References: <20240409100934.37725-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 It relys on what reset options in the skb are as rfc8684 says. Reusing this logic can save us much energy. This patch replaces most of the prior NOT_SPECIFIED reasons. Signed-off-by: Jason Xing --- net/mptcp/subflow.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index ba0a252c113f..4f2be72d5b02 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -308,8 +308,11 @@ static struct dst_entry *subflow_v4_route_req(const struct sock *sk, return dst; dst_release(dst); - if (!req->syncookie) - tcp_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); + if (!req->syncookie) { + struct mptcp_ext *mpext = mptcp_get_ext(skb); + + tcp_request_sock_ops.send_reset(sk, skb, mpext->reset_reason); + } return NULL; } @@ -375,8 +378,11 @@ static struct dst_entry *subflow_v6_route_req(const struct sock *sk, return dst; dst_release(dst); - if (!req->syncookie) - tcp6_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); + if (!req->syncookie) { + struct mptcp_ext *mpext = mptcp_get_ext(skb); + + tcp6_request_sock_ops.send_reset(sk, skb, mpext->reset_reason); + } return NULL; } #endif @@ -783,6 +789,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, bool fallback, fallback_is_fatal; struct mptcp_sock *owner; struct sock *child; + int reason; pr_debug("listener=%p, req=%p, conn=%p", listener, req, listener->conn); @@ -911,7 +918,8 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, tcp_rsk(req)->drop_req = true; inet_csk_prepare_for_destroy_sock(child); tcp_done(child); - req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); + reason = mptcp_get_ext(skb)->reset_reason; + req->rsk_ops->send_reset(sk, skb, convert_mptcp_reason(reason)); /* The last child reference will be released by the caller */ return child; From patchwork Tue Apr 9 10:09:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13622120 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 5F9EA1E89D; Tue, 9 Apr 2024 10:10:44 +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=1712657445; cv=none; b=oktBM4LO5H8aRmwqleeAVPYD5phOiQLbzbbtB17q8qtzbgsOIZB28cnAgV9Ely99C0Vr2vSMprMrIKzhsbW8RROVrt1dRu+GMNKOgjCmAPjTMtkTi3WVzCjQfpZljr8zYot40ljgnMcZYtSGdogdGgqjIlx62p0V8BdebXVBfa0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657445; c=relaxed/simple; bh=Y/8HgQQjlovau521QIfVwKJBdTaDRD9zhXD5pUNy9N4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZiFVcc/hDaNjUmdwpLqkZ+z3RIa35+77JDwJO4x4hjZsbNTyfORV9EXFKf14JmCMxqOuPnIYaNjQ2DZtmVw5LeSND9JRISTFpX4kaKDmueZWmFNu9CKgHwMhnFMBivPfLJqix0hX8IAcI/bNVkCvKajPvF0ksn/cORiC304WbhY= 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=X/ikWSYT; 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="X/ikWSYT" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6ecfeefe94cso2672451b3a.0; Tue, 09 Apr 2024 03:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712657444; x=1713262244; 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=IyP0X0s/RRDLWOFYnS+O0fVDoFb4YMkN1n74QkjCNuk=; b=X/ikWSYT/lWiH92bnLuyH44DoyKvpbYUr4RsKOHd8heei7KrxGB5KYjQXoKXy+rYwH r0wkBqpNO9rsnZ97dnFhOxvkTOvWnSlgMkDk0xwV15RHDjntYjtuBSlX+BcbLw/yN1AW Q0fHI7+0ohcbyJ1tvns9/5EMa5r2apIGhD/X+LpRp4sUqCz6r/fqWtQHbnJAOQmExkuR JWDw1I+5vKYheen/5mdXsuOlctS/A08dAwRiD8Rqeag/I13c3SXbHDvDNmdETbP5W1b5 0d1z+7uxyfrOD7t6w0x1jaijq7QymM/7oM6bshwgHJH6hp1yXqgxB7kEPQLeztgA79a0 oZ6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712657444; x=1713262244; 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=IyP0X0s/RRDLWOFYnS+O0fVDoFb4YMkN1n74QkjCNuk=; b=nFBEVu0K1D6XyjWntzmZ0jNp4tcXMszCmlXOZ52q9WuO+qDbjTJI+TfZP3W/VlCmKa p/sLjNLWXssezQ6bGZzm0BUQBrexKFnJ9Lz3sKAMGeJyfK/LKKMR5afky4q3JbAQGyXK ZhoPtdkKdkbgaidcwaucC2oLoTaqYmfmAE1ETjuRonTr8ddEqyChhEMNRT95Wqrs9/M8 PZTJzsMru4UP0xlzXIh97BSDzmYLwQI8K8Svl/L+linHTPMQMsxMqgwyEgkYyGfAGqAY Eb4EbqtPi+iFiHj5Hv9JA7pQN328x8G2ejmEzBvPckX6r10op7leheVD4Ppur+iP6RIe I7FQ== X-Forwarded-Encrypted: i=1; AJvYcCXBl/pbkOKRhNdhcgC8NO94DGaKCl9cL1Zu0+roeO5877TkKqIZHgVCiDR0XhhSNh1EuP7MqNf4euiBspUlnQxtWUWlJ4OcWR0Fpfyng4wZT7YozV1KGCUT50ZpiI8Y+LQI8GXZT4kOyuIG X-Gm-Message-State: AOJu0YyLW2sDk8IQVWf0IDvQxzUzSvFaVJHEXIUJ7CIftKkPMH2D8xbd u1CqUw/aGiGt8LAZXezesiBBOliqqYRox8W6OjcpodB1sOq8uLB2 X-Google-Smtp-Source: AGHT+IHYp3yQASFgSLFWBPFE5s3oxcfZtkD+LHZnpUnEDTeZwpGM4uHWT8Jayb/o9K/S1NF5FlZr/A== X-Received: by 2002:a05:6a20:a11f:b0:1a7:5102:c09a with SMTP id q31-20020a056a20a11f00b001a75102c09amr3345928pzk.26.1712657443798; Tue, 09 Apr 2024 03:10:43 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.26.66]) by smtp.gmail.com with ESMTPSA id fn12-20020a056a002fcc00b006e5597994c8sm7959130pfb.5.2024.04.09.03.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:10:43 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v3 6/6] rstreason: make it work in trace world Date: Tue, 9 Apr 2024 18:09:34 +0800 Message-Id: <20240409100934.37725-7-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240409100934.37725-1-kerneljasonxing@gmail.com> References: <20240409100934.37725-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 At last, we should let it work by introducing this reset reason in trace world. One of the possible expected outputs is: ... tcp_send_reset: skbaddr=xxx skaddr=xxx src=xxx dest=xxx state=TCP_ESTABLISHED reason=NOT_SPECIFIED Signed-off-by: Jason Xing Reviewed-by: Steven Rostedt (Google) --- include/trace/events/tcp.h | 37 +++++++++++++++++++++++++++++++++---- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_output.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h index 5c04a61a11c2..9bed9e63c9c5 100644 --- a/include/trace/events/tcp.h +++ b/include/trace/events/tcp.h @@ -11,6 +11,7 @@ #include #include #include +#include /* * tcp event with arguments sk and skb @@ -74,20 +75,38 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb, TP_ARGS(sk, skb) ); +#undef FN1 +#define FN1(reason) TRACE_DEFINE_ENUM(SK_RST_REASON_##reason); +#undef FN2 +#define FN2(reason) TRACE_DEFINE_ENUM(SKB_DROP_REASON_##reason); +DEFINE_RST_REASON(FN1, FN1) + +#undef FN1 +#undef FNe1 +#define FN1(reason) { SK_RST_REASON_##reason, #reason }, +#define FNe1(reason) { SK_RST_REASON_##reason, #reason } + +#undef FN2 +#undef FNe2 +#define FN2(reason) { SKB_DROP_REASON_##reason, #reason }, +#define FNe2(reason) { SKB_DROP_REASON_##reason, #reason } /* * skb of trace_tcp_send_reset is the skb that caused RST. In case of * active reset, skb should be NULL */ TRACE_EVENT(tcp_send_reset, - TP_PROTO(const struct sock *sk, const struct sk_buff *skb), + TP_PROTO(const struct sock *sk, + const struct sk_buff *skb, + const int reason), - TP_ARGS(sk, skb), + TP_ARGS(sk, skb, reason), TP_STRUCT__entry( __field(const void *, skbaddr) __field(const void *, skaddr) __field(int, state) + __field(int, reason) __array(__u8, saddr, sizeof(struct sockaddr_in6)) __array(__u8, daddr, sizeof(struct sockaddr_in6)) ), @@ -113,14 +132,24 @@ TRACE_EVENT(tcp_send_reset, */ TP_STORE_ADDR_PORTS_SKB(skb, th, entry->daddr, entry->saddr); } + __entry->reason = reason; ), - TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s", + TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s reason=%s", __entry->skbaddr, __entry->skaddr, __entry->saddr, __entry->daddr, - __entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN") + __entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN", + __entry->reason < RST_REASON_START ? + __print_symbolic(__entry->reason, DEFINE_DROP_REASON(FN2, FNe2)) : + __print_symbolic(__entry->reason, DEFINE_RST_REASON(FN1, FNe1))) ); +#undef FN1 +#undef FNe1 + +#undef FN2 +#undef FNe2 + /* * tcp event with arguments sk * diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 03c5af9decbf..4889fccbf754 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -871,7 +871,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb, if (sk) arg.bound_dev_if = sk->sk_bound_dev_if; - trace_tcp_send_reset(sk, skb); + trace_tcp_send_reset(sk, skb, reason); BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) != offsetof(struct inet_timewait_sock, tw_bound_dev_if)); diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 6d807b5c1b9c..710922f7d4d6 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3610,7 +3610,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority, int reason) /* 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); + trace_tcp_send_reset(sk, NULL, SK_RST_REASON_NOT_SPECIFIED); } /* Send a crossed SYN-ACK during socket establishment. diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 6889ea70c760..3c995eff6e52 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1131,7 +1131,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb, label = ip6_flowlabel(ipv6h); } - trace_tcp_send_reset(sk, skb); + trace_tcp_send_reset(sk, skb, reason); tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, 1, ipv6_get_dsfield(ipv6h), label, priority, txhash,