From nobody Sat May 18 20:15:24 2024 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14CBC1CFB9 for ; Thu, 4 Apr 2024 07:21:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215271; cv=none; b=HnS2kNeCRLsZc55r4+O3+nyjrc6nnsvydoR67ZwHSk9AR2cT4E02uYXARTb8xCpGFCANdSDX/0/3B31jZ9sJaqgFqDBR4mH4H3qpkORoH1HvEScezqHtUyZXgI0RyJuF5eRQ/swdWnE4alCHuG6zlVnEIqCdEeL851nAjQwryHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215271; c=relaxed/simple; bh=mlfxcIg4+Phml4qIdFRVfQLahA9cOJbdd5MjdoBa8Vs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JpDnYQ8LIaoy8sEXlptOGNbuWx9rMQum20COabt0ge31UJZJ9A3Ht5RgRa++YA8ztesqFOReb593MA47qJuhwVWjX+C84L04CR9PoERdKX7Y/kAdRZaaGG1l+nQrUj5ioVkZ+221mXEzfuNSsYxO/tZOqtUyKMJo+mEIbwFc4A4= 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=M2YXkAbn; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M2YXkAbn" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1e24c889618so5636025ad.2 for ; Thu, 04 Apr 2024 00:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712215269; x=1712820069; darn=lists.linux.dev; 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=M2YXkAbn7RWp5rtn+5DeM856BRSu+Bg5Q5e4nAJkoL3/DELrbnlKnHP1MMmHP0b1Vi 6iLwfDwqFpP35KRpdjzONWRqcjRLK1yjbGYM4oGkWh+OK2mVGZXY6cA2Y6wZ+zDSRWkz 7PQ97JeW0HL4bor5oSbinjPZSOJcYS64oBIANKIkxdpdlpk84QW6Xag5ONHlT8BH53Qg 67mujGid4oRze8VMEqiypnBI4Up5tAUselfy/wG1C0ogaecBaRHHAzdJ+XUegn1+zpYO BkhoS6lp7abIG9bfITU2IS2o4K16zDpp8tKP4YSxnQdnZMlb6nMSo6tbgZA5Lc8L0AmN qbQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712215269; x=1712820069; 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=Qrj8FP6cdC8ispKoYlNTXS1u1Zezt9s9vbtJPM+sXhOy+wBv0daVzK+xmAIKetigo0 e7HPjd+OViXFDEI9zrwtnHcNG5bSbMkuqnGOj2sUdmPJCI78STORo5fq5ZDoJFpu2vd2 MYSHAA7vXSKy+mJs4LNfdcR4JWwNkXlB5eY8CSBiA+YpVoqu/bJj9aPWf7nlQ2Q8R9hs Y1UYUpvyE2ZN/mFcXABfM1wCVTnpRMtFgluObauvzp9Xqy0ZCI6yZJGVIFHDvv6QCBKX a/HAfxO4Vt+GX+BCrjRLLhAMX2+X5F501PALYHRRO4eWYiA5QVvwrRPo3ps7Bk91xc/p 4JKw== X-Gm-Message-State: AOJu0Yy71r/pmS+YtT+tMwPLg4wXRok8UxtWMfPKU5P7v6Hv9OXk5weB caeZ3zFzhuo2tcRbCX65H0PAbIUPdEz+TAbtnhkpiuQvUDYLerql X-Google-Smtp-Source: AGHT+IFqACoDiCGh47ZlFyQWHCBFfEQL6pgRBMfAWw1iIHgA/ggpEsgoSQPWZh/7MXUCK0bkoNY9lA== X-Received: by 2002:a17:903:228a:b0:1e0:b62a:c0a2 with SMTP id b10-20020a170903228a00b001e0b62ac0a2mr1834529plh.51.1712215269320; Thu, 04 Apr 2024 00:21:09 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.28.7]) by smtp.gmail.com with ESMTPSA id w2-20020a1709029a8200b001db5b39635dsm14606399plp.277.2024.04.04.00.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 00:21:08 -0700 (PDT) From: Jason Xing To: edumazet@google.com, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, rostedt@goodmis.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v2 1/6] net: introduce rstreason to detect why the RST is sent Date: Thu, 4 Apr 2024 15:20:42 +0800 Message-Id: <20240404072047.11490-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240404072047.11490-1-kerneljasonxing@gmail.com> References: <20240404072047.11490-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 T= CP + * 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 =3D 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 +=3D RST_REASON_START; +} +#endif --=20 2.37.3 From nobody Sat May 18 20:15:24 2024 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 1F3DF55C13 for ; Thu, 4 Apr 2024 07:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215278; cv=none; b=hNyQT4U5OeAJH8t4SYlrXHBgAeC6iVwCR5/ddXVjFkNsKry0mO0+ix9xXscAgFDdgg8cq70ZaEQyooxn35jG6T+d5KW4HoE6SJd3kH1FJ0dyTNXHpr3JBQ9GpH7qeWVwDxcCqM6m+eSdZBZp8XPyBGsiFrz+NxsdiMD8ThfyPco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215278; c=relaxed/simple; bh=ZuRrbDQ3V9poIN0zQATnoHKcZLgJipojYuOtKLG9mDc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FYWtg/WrQrn1cxgqD0F3zxeKEHfpxvEPaD3qZEDzgLzb+VNkot6DlGxgvDWk1hbe9HSR5+OZ6mw/OUfHWSJCIiz4ISLl38hJ4vh+JXgkHh34RHB1sYyq/AvsgvaQOoskRoTaX2r0qW4D3LrVDkw2ATwp1VtFkvS4UfIK1PtaYoc= 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=LScElV2L; arc=none smtp.client-ip=209.85.214.179 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="LScElV2L" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1e252f2bf23so5467835ad.2 for ; Thu, 04 Apr 2024 00:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712215276; x=1712820076; darn=lists.linux.dev; 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=ErSoXPsRmj3WIO9IrRcKp2t9zH04ARuHBxEb2fYZVr8=; b=LScElV2L4V+oDdvv9TjByvesQJlcdQoZsRRIBVw1ApPQR6YV0O6g27cPB1UfTsWya0 oekFp/syR0VUtWiThGVvTV1xbjeOFXQiOrUF6a8j9Li1QhWZoSSZ7w4uwoFo6K5364Kv Nci+w/qThVMrUqjDRQYNYpydG9WUvMZJEK2xp1g57uyC118fqXgFgFLGKg3O5ifQxQox A6Q/Li/kd6F3VCxOHI9f0wZc2RGmH8ygvDBZpeNFcSJT7OkW3w37E78UL2WzIRD74Omo 2gj2m+w/adtaAzP+dCg2464Bs9839QKK9fbQ9RZEl1QJZZtlJ2lWy+aw3qPJ11G5ciFJ LYDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712215276; x=1712820076; 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=ErSoXPsRmj3WIO9IrRcKp2t9zH04ARuHBxEb2fYZVr8=; b=UgYrz52LI6hILkpOXcfYTwTdSCcws12kAYjb0aeOqm43O6Diqzld8wuUNv70ZjZ/Q6 WcAZCtYyTSey23vpN3zuE8Y5MzMRpf+VUix3R9lTTgC4UG2+Vv4pbv+4TG8DqWXu+wfi 8myj1oLWYe5+LgDe4tzYt3vLR5QTOuu2ZpuQ2c4vvxNluj3kCDm9R5QUFgDO2OMbCoYN ZdXXzMvBP2COgqqMXNKkXPJcrA35LvMG+YYT14n5J5yW2t9k97ylMF+WZ7nrfRiwAAGh IB4zna0rlY1sV+aJEU8ctQ43usD9h3Qvf8yU1jY8u8BGFEtT5D2GFidCZwS7lbiKTcgC ulJA== X-Gm-Message-State: AOJu0YxhXmchSBhfGuQNUe30d+jqBhvST36TIhnpG+8gcRER3hglzyeo GDoTe3TRSCSk1rNcPXGjzvNOiCO+A8Y/yg2DPoRqwxTt3Wlm5aXW X-Google-Smtp-Source: AGHT+IGMVSo4L6SYC/yNVfOYZx4++1NoVqIM9L7oLee3/oZhs+nmwKripBJBS9LnbHkObx/FVCPPbg== X-Received: by 2002:a17:903:2288:b0:1e2:a197:7b3f with SMTP id b8-20020a170903228800b001e2a1977b3fmr1832738plh.31.1712215276227; Thu, 04 Apr 2024 00:21:16 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.28.7]) by smtp.gmail.com with ESMTPSA id w2-20020a1709029a8200b001db5b39635dsm14606399plp.277.2024.04.04.00.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 00:21:15 -0700 (PDT) From: Jason Xing To: edumazet@google.com, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, rostedt@goodmis.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v2 2/6] rstreason: prepare for passive reset Date: Thu, 4 Apr 2024 15:20:43 +0800 Message-Id: <20240404072047.11490-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240404072047.11490-1-kerneljasonxing@gmail.com> References: <20240404072047.11490-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jason Xing Adjust the paramenter 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 =20 #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; } =20 -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; =20 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 =3D=3D 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 !=3D DCCP_PKT_RESET) { DCCP_SKB_CB(skb)->dccpd_reset_code =3D DCCP_RESET_CODE_NO_CONNECTION; - dccp_v4_ctl_send_reset(sk, skb); + dccp_v4_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); } =20 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 =20 #include "dccp.h" #include "ipv6.h" @@ -256,7 +257,8 @@ static void dccp_v6_reqsk_destructor(struct request_soc= k *req) kfree_skb(inet_rsk(req)->pktopts); } =20 -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_bu= ff *skb) return 0; =20 reset: - dccp_v6_ctl_send_reset(sk, skb); + dccp_v6_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); discard: if (opt_skb !=3D NULL) __kfree_skb(opt_skb); @@ -762,7 +764,7 @@ static int dccp_v6_rcv(struct sk_buff *skb) if (nsk =3D=3D 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 !=3D DCCP_PKT_RESET) { DCCP_SKB_CB(skb)->dccpd_reset_code =3D DCCP_RESET_CODE_NO_CONNECTION; - dccp_v6_ctl_send_reset(sk, skb); + dccp_v6_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); } =20 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 =20 #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 =3D DCCP_RESET_CODE_TOO_BUSY; drop: if (dccp_hdr(skb)->dccph_type !=3D DCCP_PKT_RESET) - req->rsk_ops->send_reset(sk, skb); + req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); =20 inet_csk_reqsk_queue_drop(sk, req); out: diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 56b75efcfd12..d8d98db8f58e 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -70,6 +70,7 @@ #include #include #include +#include =20 #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. */ =20 -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 =3D tcp_hdr(skb); struct { @@ -1933,7 +1935,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *sk= b) return 0; =20 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 @@ -2278,7 +2280,7 @@ int tcp_v4_rcv(struct sk_buff *skb) } else { drop_reason =3D 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); @@ -2356,7 +2358,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); } =20 discard_it: @@ -2407,7 +2409,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 =20 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_b= uff *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 =20 #include #include @@ -69,7 +70,8 @@ =20 #include =20 -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 *s= kb, struct request_sock *req); =20 @@ -1006,7 +1008,8 @@ static void tcp_v6_send_response(const struct sock *s= k, struct sk_buff *skb, u32 kfree_skb(buff); } =20 -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 =3D tcp_hdr(skb); struct ipv6hdr *ipv6h =3D ipv6_hdr(skb); @@ -1675,7 +1678,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *sk= b) return 0; =20 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 =3D 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); } =20 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 1626dd20c68f..3b1c13136908 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" =20 @@ -302,7 +304,7 @@ static struct dst_entry *subflow_v4_route_req(const str= uct sock *sk, =20 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; } =20 @@ -369,7 +371,7 @@ static struct dst_entry *subflow_v6_route_req(const str= uct sock *sk, =20 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 @@ -899,7 +901,7 @@ static struct sock *subflow_syn_recv_sock(const struct = sock *sk, tcp_rsk(req)->drop_req =3D 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); =20 /* The last child reference will be released by the caller */ return child; --=20 2.37.3 From nobody Sat May 18 20:15:24 2024 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.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 21B975675F for ; Thu, 4 Apr 2024 07:21:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215284; cv=none; b=jdJ7GoHEQJRfGW91WCNhlDAEOljm+7WUrHHHhF7PoQbwPh7YUKoztYla1pnNyxudtdmDDqTW1nD2jkS11BexnsiDW2eA0+H++MO3j/BElsvgUHIvTUBBPbm8EUGCuf44n6ODJXt3GveunrEWyMHZEmA4V0Wr5nF1X+y1C0jZugw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215284; c=relaxed/simple; bh=YgH7PNDq2UKgRlZCizRqIh8Ox9j5Glvhxit1f34YJOA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pWS6mF7tdSFuOlqqTZfc2JFs5sbYh/dPc0kC+6n8khj3qZGrnEjt6WeA6Fg/tBoW23wPX1ExGX/VpYDdx793Hs2jNMh0Q339zfLiUCLawIfJORNiuwLgZPFD2Utnip7aXYGlypNkAxzHsyNuw+14lfZ6+zHOmc76x1BK+LvZaMw= 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=frjQZKNS; arc=none smtp.client-ip=209.85.214.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="frjQZKNS" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1e2232e30f4so5741645ad.2 for ; Thu, 04 Apr 2024 00:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712215282; x=1712820082; darn=lists.linux.dev; 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=kPoCku/Cj+pJg+VDGr/a/+x9R0CpfMJJYCKZx5paLck=; b=frjQZKNSJyQ6i7fj9mM2JiYYjTIG6kEyDrHLNO25DA5Kqrs9lhIjd0+4Q4LibU0LNx nLUKA/mzXTHH9RcqC4uHYDNHk3zxOUMjk9BTytj8GnMkIhkfbp5H/ay3pUb7rrPaFZjn GnASBMWW4dYUiVFoLhn7rigLCJU1/C0AdyqvcWfmzW6vhoEwN63BovRjO99fJy4I7mFF 5aGB3MUCFZFbeZRmNRGu1ritM54ZrCJNw6pFygfWd6kFzciSDtbsPKbNMigujxa8ktfr tTAqFJ7ACyJbGYBFqo1A5F6d1HBMcNnCtIuUPrRkv3XVRnsdVOhArdhGWQb0o8ZF6p2k yZ/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712215282; x=1712820082; 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=kPoCku/Cj+pJg+VDGr/a/+x9R0CpfMJJYCKZx5paLck=; b=a4uWt1lH/oAn/AMKRUclt8TbkUTTfh/Dm/Y3DIDPnEREc5noesHgP55xKUdXmsczWF 1PPX/i2/die6hZ6KcocKaI+3jm6Ho75crCCQlTXxS4lKX0xRaHjidKOKRXxgLcm/gP/J Taii+M2oyfZlM4C2SHOoBcBd1m5TdtJwIkuuhp+dDv4qO3fU0BmCcYMow/392pzxaUY2 5HYJND/0VbJh4YTkgmjB2mRtVpdrrUfds1vOBFjfpPgqF/haV3GCxLxP5cnS7mmA7jXs Gw36XEOCiLhPpRoIE7+M5+tHNZdSabmxX3ojchyzsyC3q9+I4EuXHUF2qlexTym4e8Ch k2IA== X-Gm-Message-State: AOJu0Yx3J1RoQDlJmCDFRJhxCoegWSZFrGgPKWHRWyZGIa9+TtSgDx7U YcicIz9OYbrrEHcp+um26gJo+Uzr9mrc2+RdYRYn+SZP5F5bMx0Z X-Google-Smtp-Source: AGHT+IH6JbvcvXpnmsgCrgIsfcpqjjyYJH9gAn+c7kSaILqCvMyZhf4X/rygtxqAe0AuAaJzibPDUw== X-Received: by 2002:a17:902:d2c1:b0:1e0:b87f:beb4 with SMTP id n1-20020a170902d2c100b001e0b87fbeb4mr1449318plc.30.1712215282488; Thu, 04 Apr 2024 00:21:22 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.28.7]) by smtp.gmail.com with ESMTPSA id w2-20020a1709029a8200b001db5b39635dsm14606399plp.277.2024.04.04.00.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 00:21:21 -0700 (PDT) From: Jason Xing To: edumazet@google.com, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, rostedt@goodmis.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v2 3/6] rstreason: prepare for active reset Date: Thu, 4 Apr 2024 15:20:44 +0800 Message-Id: <20240404072047.11490-4-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240404072047.11490-1-kerneljasonxing@gmail.com> References: <20240404072047.11490-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_qu= eue, 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 e767721b3a58..eacfe0012977 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -275,6 +275,7 @@ #include #include #include +#include =20 #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 =3D 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 !=3D 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 =3D=3D 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); } =20 diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index e3167ad96567..18fbbad2028a 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3583,7 +3583,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; =20 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 =20 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 d= o_reset) (!tp->snd_wnd && !tp->packets_out)) do_reset =3D 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; } =20 @@ -795,7 +797,8 @@ static void tcp_keepalive_timer (struct timer_list *t) icsk->icsk_probes_out > 0) || (user_timeout =3D=3D 0 && icsk->icsk_probes_out >=3D 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 3a1967bc7bad..836fd054eca4 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) =20 slow =3D lock_sock_fast(tcp_sk); if (tcp_sk->sk_state !=3D 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 3b1c13136908..a68d5d0f3e2a 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -407,7 +407,7 @@ void mptcp_subflow_reset(struct sock *ssk) /* must hold: tcp_done() could drop last reference on parent */ sock_hold(sk); =20 - 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); @@ -1336,7 +1336,8 @@ static bool subflow_check_data_avail(struct sock *ssk) tcp_set_state(ssk, TCP_CLOSE); while ((skb =3D 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; } --=20 2.37.3 From nobody Sat May 18 20:15:24 2024 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 5AE365810C for ; Thu, 4 Apr 2024 07:21:29 +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=1712215290; cv=none; b=FHL0UGwoqRpC/hn1uIBSz3iF/GP3DEDzw/LbLOAtJKGql3waxjqFL4CLlcrt2Q19V5smmwlcgkqDoLv3OKtnzjLx9elw4WyGXbAhc1ySeJ+qHbaO0Np4WJKpRKfqPadOZheJnqdDWTVu4saqza7MwTsMpkjV2hpj0pKsEVEQoto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215290; c=relaxed/simple; bh=XwQdJ1YaaAMtdXN9npqhQhlx7+lFvpeEOH+8E1BGeKA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jF4e6b/xwxRfoXCdX6cEb/ooSvulY3A22ofwg2azfXOVDcJRDlTCM1woap7i08tF7KfUkd35EYUA8Lr3salTk1/jEXBguTX8HP+WunfAcILxwBdT3f6Kowo/mvn7Apk6/XhuUFcnOccSFuFc6CpGUtHnFP0x78efS1uh7Lw5W2w= 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=BemOKF8R; 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="BemOKF8R" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6ecee1f325bso264765b3a.2 for ; Thu, 04 Apr 2024 00:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712215288; x=1712820088; darn=lists.linux.dev; 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=bItfs35jBJwYsVcRlz2Ak3QufL1GUraVsJFxf8+lDvM=; b=BemOKF8Ri1iSV5SXqpAYvjkY70BdhoQBuILvRJtA6iXjqt+AI6kqU5nqogCD6Nuc8W 8ffijvwXRIiy6wmReqFh7hgmPlfa1Md04YhHgx0fwWzjCQl1JgYTqCf3ClqC+Z8MhPUt qW7iP5JPUG9g2sm1yhEy84gW0aFFlL9Pq3xERsT+Dux9L5VJ4QocemCIQc6x7loH6RyT fHJBx52yYFEtHWDmUde0XW/h6S7epeOMd9DFZRGCI911BJTn7utzSXQ/n2bJV+e97Fpt 3mGBU55KHRQDez92iaX55NyG6MmpoI2GcBWHbnUbBIAnIwtcDoFdnCHLK69wB2jW42x9 yIKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712215288; x=1712820088; 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=bItfs35jBJwYsVcRlz2Ak3QufL1GUraVsJFxf8+lDvM=; b=rKnTqe/C7ZYb2j14gU7z1ouJZFjLzpzOBQIdFrthCBlDKOvhcBVzltRzFb7HHkZ+Xr z26kStvdQCFp8NrwMlWnVpvPSy7jkBVS3ctJgU2zx8kehLunifuRKA3V/FKq3oE2gCGw oW92lP5Wqd8yL1j6BKnleNPQZgcCSwrmk7kjpiIDKeWX4jtC9UJzQRZt18NyKjTe8NH3 cBfuJMJ1gyl7w1KIxqNdGlhCzUJGFMUSk9DEjNkVS72DBGYj1szOlirY6ArJWyY51V72 XLT9n2SmRTq1O67MIKkBpwdl43gkP/dbAgJ0ZCcDzclPrSmH5xo5xmItPQbNRtpFRXzR Tr/g== X-Gm-Message-State: AOJu0YxALy6N3gj7ggdCMAJNMAgByQU4B+cbkEJbAIo7Z3ffmoYWQApM c+n5CCfKKDY0pqujB/F5gXYmGLQIKFs9fmq8CylYn6sbDl2u+8cK X-Google-Smtp-Source: AGHT+IE21WwNiERpBlyk4bHmJSIsioNkuIjxFf5RmkSh4ep+Z1Hr7F/8youhW3d0v7pmPe+U1uTOIw== X-Received: by 2002:a05:6a20:c70e:b0:1a3:6474:3953 with SMTP id hi14-20020a056a20c70e00b001a364743953mr1961611pzb.35.1712215288667; Thu, 04 Apr 2024 00:21:28 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.28.7]) by smtp.gmail.com with ESMTPSA id w2-20020a1709029a8200b001db5b39635dsm14606399plp.277.2024.04.04.00.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 00:21:28 -0700 (PDT) From: Jason Xing To: edumazet@google.com, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, rostedt@goodmis.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v2 4/6] tcp: support rstreason for passive reset Date: Thu, 4 Apr 2024 15:20:45 +0800 Message-Id: <20240404072047.11490-5-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240404072047.11490-1-kerneljasonxing@gmail.com> References: <20240404072047.11490-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 d8d98db8f58e..1ae2716f0c34 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 *sk= b) return 0; =20 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 @@ -2280,7 +2280,7 @@ int tcp_v4_rcv(struct sk_buff *skb) } else { drop_reason =3D 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); @@ -2358,7 +2358,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); } =20 discard_it: @@ -2409,7 +2409,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 *sk= b) return 0; =20 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 =3D 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); } =20 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: --=20 2.37.3 From nobody Sat May 18 20:15:24 2024 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 9BE0054BF0 for ; Thu, 4 Apr 2024 07:21:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215297; cv=none; b=IinTGwcajrLuR/xVAT8cEMubdQqOjjRkHl4vxqO4sFz7xlceZvCJlkGS7FuWm3S5RdLVwL6bj1emHIFWBAXLzUW2aJvthuMp7uwShnMed2dCbpbUhfiqz7nPmtShoa4pT5Xe7r9cWsufsDUfHI5RpYdXeknhstKSoKxhjoYW+9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215297; c=relaxed/simple; bh=YJHF94tDUSTWCiWPr7aQkKYgxgeg1GDBFAggrN+81Uk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j6AM+jYaa6lHi30aQOqNABipEHWk3ocSMIGSHv1LiqXcvyuvbCtLsxoFBflKPoAfe8gUfHf+sMpnmyQ3c7AsX+iw07lyNqnuB5u2Zhxd4DaahdM8uNpYOOy0uId+o7VRgPRp+qqQXZYdBa5VIi2yadzQF45bANB8VmltCZTfe7g= 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=jtHLbX36; arc=none smtp.client-ip=209.85.214.172 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="jtHLbX36" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1e0edd0340fso5885105ad.2 for ; Thu, 04 Apr 2024 00:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712215295; x=1712820095; darn=lists.linux.dev; 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=/zCgjlonmz37DPEbA0Oytli/YhfsEeASyIn4O2vwvxk=; b=jtHLbX36G5bLxXGSdZftsv27xqFt8oHzq6CLRo5lE/yOB1m7/lHD1+0fgXp8UREUxu bJO/77E2hhUcxvM2q52crTeX2PjNZQhd7JIUA/bZOGZC18uOLMVWVHBvmIFWf9kKTplR IkCBUHEcRimtL2PicQLmPFZ4683xYOewidHbIrofKt8XlI5K5opp/JEY2BgpCK1geARl qONa7EwuGcS3l1DLZkZLCWC9N42YPx6W7a+K9qQ0myyTkiad0yrSGB3+LeF6BloEi2fH y+QUOlQZg5lhAccBDH0l3UslJe8K26MK3HyBshcyKpAEKCf8azQQIHr91DhqdehejZQv mJMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712215295; x=1712820095; 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=/zCgjlonmz37DPEbA0Oytli/YhfsEeASyIn4O2vwvxk=; b=AT2CBcnSIWNV5VMv29w5wWjnsMN4gUi1OFFXLC5gealYGPLUjYuk4QyY79qKIzdExL 9ya3WXbo2WOF3sTD4sJSVno78iGKOQlS9yMQqk9OoYgiygxhfjeIu4Sj7ELOeoo6WXFd DiFv9AlnO+ASygztVy05p282RI/0MikS8zl7KUTxG1AzeW99RKVMMBYGdpydKV6zbP1X LI0b+3lmEeLDASMvMOg7FrF0NiaH0Wy+1WgGJRgLhOGyCR1dB6W7tb7AzQuQUcre/nMO JjGnvJwfovWUrKnWRyfgAqMDf9JzPF3Og2jjMYeQEm+y6ZmxkMdoLsHISPzLPCRdEhjl WOxw== X-Gm-Message-State: AOJu0YyPbckDZwV2GXNe6s8fkK06kKlsqKjQ4x7vWQP++iRSgZsR2LS1 RwO7hk78HeRVK2vhowrVmn3LpzHWuSn487GiAHlNX8rw87br0W6O X-Google-Smtp-Source: AGHT+IEa5+T77JAdTma2XOgWwr9eA4re9vQQ278n8wGaPTDE+cp9slsp+aNVcEu07OClKPDzo6pJhA== X-Received: by 2002:a17:902:ecd0:b0:1e0:e8b7:1fa2 with SMTP id a16-20020a170902ecd000b001e0e8b71fa2mr1782922plh.21.1712215294850; Thu, 04 Apr 2024 00:21:34 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.28.7]) by smtp.gmail.com with ESMTPSA id w2-20020a1709029a8200b001db5b39635dsm14606399plp.277.2024.04.04.00.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 00:21:34 -0700 (PDT) From: Jason Xing To: edumazet@google.com, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, rostedt@goodmis.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v2 5/6] mptcp: support rstreason for passive reset Date: Thu, 4 Apr 2024 15:20:46 +0800 Message-Id: <20240404072047.11490-6-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240404072047.11490-1-kerneljasonxing@gmail.com> References: <20240404072047.11490-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jason Xing It relys on what reset options in MPTCP does as rfc8684 says. Reusing this logic can save us much energy. This patch replaces all the prior NOT_SPECIFIED reasons. Signed-off-by: Jason Xing --- net/mptcp/subflow.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index a68d5d0f3e2a..24668d3020aa 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -304,7 +304,10 @@ static struct dst_entry *subflow_v4_route_req(const st= ruct sock *sk, =20 dst_release(dst); if (!req->syncookie) - tcp_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); + /* According to RFC 8684, 3.2. Starting a New Subflow, + * we should use an "MPTCP specific error" reason code. + */ + tcp_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_MPTCP_RST_EMPTCP); return NULL; } =20 @@ -371,7 +374,10 @@ static struct dst_entry *subflow_v6_route_req(const st= ruct sock *sk, =20 dst_release(dst); if (!req->syncookie) - tcp6_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); + /* According to RFC 8684, 3.2. Starting a New Subflow, + * we should use an "MPTCP specific error" reason code. + */ + tcp6_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_MPTCP_RST_EMPTCP= ); return NULL; } #endif @@ -778,6 +784,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; =20 pr_debug("listener=3D%p, req=3D%p, conn=3D%p", listener, req, listener->c= onn); =20 @@ -833,7 +840,8 @@ static struct sock *subflow_syn_recv_sock(const struct = sock *sk, */ if (!ctx || fallback) { if (fallback_is_fatal) { - subflow_add_reset_reason(skb, MPTCP_RST_EMPTCP); + reason =3D MPTCP_RST_EMPTCP; + subflow_add_reset_reason(skb, reason); goto dispose_child; } goto fallback; @@ -861,7 +869,8 @@ static struct sock *subflow_syn_recv_sock(const struct = sock *sk, } else if (ctx->mp_join) { owner =3D subflow_req->msk; if (!owner) { - subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT); + reason =3D MPTCP_RST_EPROHIBIT; + subflow_add_reset_reason(skb, reason); goto dispose_child; } =20 @@ -875,13 +884,18 @@ static struct sock *subflow_syn_recv_sock(const struc= t sock *sk, ntohs(inet_sk((struct sock *)owner)->inet_sport)); if (!mptcp_pm_sport_in_anno_list(owner, sk)) { SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MISMATCHPORTACKRX); + reason =3D MPTCP_RST_EUNSPEC; goto dispose_child; } SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINPORTACKRX); } =20 - if (!mptcp_finish_join(child)) + if (!mptcp_finish_join(child)) { + struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(sk); + + reason =3D subflow->reset_reason; goto dispose_child; + } =20 SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINACKRX); tcp_rsk(req)->drop_req =3D true; @@ -901,7 +915,7 @@ static struct sock *subflow_syn_recv_sock(const struct = sock *sk, tcp_rsk(req)->drop_req =3D true; inet_csk_prepare_for_destroy_sock(child); tcp_done(child); - req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED); + req->rsk_ops->send_reset(sk, skb, convert_mptcp_reason(reason)); =20 /* The last child reference will be released by the caller */ return child; --=20 2.37.3 From nobody Sat May 18 20:15:24 2024 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D45215677D for ; Thu, 4 Apr 2024 07:21:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215303; cv=none; b=BZf0y5SsAjGrbHa28c5grbwmXtVrqSXAn4mrbx/+wZY6GwohTqK5x8Hrfbld0w/O7h0QlQ+g6QAzP9bGBJBjTHaCF3osy93kzn9ooGrtVI9Gx2zhi6MR+YRV9+B3lr6fJfiW1hme5y6rWBit8JvBwvIFwiQODfQE9CiBwbAlpEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712215303; c=relaxed/simple; bh=oZv1Wez/4+bqsLmNS3FVMB20C3FjVPxQSLIEYsk1Hlc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CMxMyptOu7x9QcsquV8O5DC2ADyVKW1VcocrHiLAw0X5M30ivpxS/2jg9003yHNOdmZ//qy61fwtO1HtLloNkshgVdVGWK6rv6oH48/BbI1Q1H1nBMRhurm5uGMLERyvZDXjnrAD0Fg8okS2l6ZWQpUzMApWRIMP862stxKpVFE= 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=kiSnPwC5; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kiSnPwC5" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1e27fadbbe1so5668855ad.1 for ; Thu, 04 Apr 2024 00:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712215301; x=1712820101; darn=lists.linux.dev; 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=oGOhlg//3F0S9mUwjG1Z9GiuJGTOaECWxukxpME741g=; b=kiSnPwC5pluMx8nkFyQ4rZa7EztGEp+oxsTfweK9bhaixfFtjgZDSmH47O/UOyAmY0 CyGpOHCYbIYBlQ5zwVEJTJGS9ONjomfYUHDAo7McVGxNjvSe9N3pPriIfLo+6iCohgLo QFT4i7AC+BqpYvaIser8BoKU8OV80ScLEF8C0unLZX+aWA/sQpZO5b7iG2atO6y2jHDz SglBisQLMG6IclktbNEkAOEJbF2f74u+sYVxnQNZqvIEQK2xs82Unh4EiMOwiyimGj+5 XkNbI5KnGavRkygCUKw5Xl9i/i6mJeBUBLfrcIka/qqewc5nTlq0QH2W3By0IkWMdXIb cfYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712215301; x=1712820101; 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=oGOhlg//3F0S9mUwjG1Z9GiuJGTOaECWxukxpME741g=; b=EK2iYjQZLAXIx9K4yb84CTNnVk8odO0gPpJGXlCrkeQ3wRCrH3iuJFgI7tk0RO4yO6 6I02ROI1hZ8wR2BTJ7qG6oKxmdzzNiqFfmxXmAaYOzR09i3b9RQP6CfffPTX3YJfCl1g ngsrF+WF1511NXunHgYKYsny6fjgtqnhAw/oqgkOgqEC42tMsV6fk/RdEwSB0LA9kla8 vqlcqv4myqRpKbK162TnuYScDxFxtLPt9QNbcuaGyTQJvIVUE48TjHKF0pU0uAQpAab8 YbqVvLywbbXOuj51kWOuxLgO+jqSkROaY0FcLvShQA7/oj1X4YpNtF4xkm6zRoYEGj0P mDbA== X-Gm-Message-State: AOJu0YyshKj1KH2sIIAf9thP8qjAP/xf/MSoROn8++VbT7slmXHKo7qX YwbU9kwH9LB2CCNpp0OiyXLAdjVp8j4rmOaVmkom8a40qp37trux X-Google-Smtp-Source: AGHT+IH66YdB2sVgkmH1xvgv4I+C6smt2MXPHmHm4S0q+JrLyLlx88yXDouok+cyXGNV6azCdk+JZw== X-Received: by 2002:a17:902:f38c:b0:1e2:7462:b97b with SMTP id f12-20020a170902f38c00b001e27462b97bmr1010177ple.67.1712215301155; Thu, 04 Apr 2024 00:21:41 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([111.201.28.7]) by smtp.gmail.com with ESMTPSA id w2-20020a1709029a8200b001db5b39635dsm14606399plp.277.2024.04.04.00.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 00:21:40 -0700 (PDT) From: Jason Xing To: edumazet@google.com, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, rostedt@goodmis.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v2 6/6] rstreason: make it work in trace world Date: Thu, 4 Apr 2024 15:20:47 +0800 Message-Id: <20240404072047.11490-7-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240404072047.11490-1-kerneljasonxing@gmail.com> References: <20240404072047.11490-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3Dxxx skaddr=3Dxxx src=3Dxxx dest=3Dxxx state=3DTCP_ESTABLISHED reason=3DNOT_SPECIFIED Signed-off-by: Jason Xing --- 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 =20 /* * tcp event with arguments sk and skb @@ -74,20 +75,38 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb, TP_ARGS(sk, skb) ); =20 +#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, =20 - 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), =20 - TP_ARGS(sk, skb), + TP_ARGS(sk, skb, reason), =20 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 =3D reason; ), =20 - TP_printk("skbaddr=3D%p skaddr=3D%p src=3D%pISpc dest=3D%pISpc state=3D%s= ", + TP_printk("skbaddr=3D%p skaddr=3D%p src=3D%pISpc dest=3D%pISpc state=3D%s= reason=3D%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))) ); =20 +#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 1ae2716f0c34..9c52a4a74842 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, st= ruct sk_buff *skb, if (sk) arg.bound_dev_if =3D sk->sk_bound_dev_if; =20 - trace_tcp_send_reset(sk, skb); + trace_tcp_send_reset(sk, skb, reason); =20 BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) !=3D offsetof(struct inet_timewait_sock, tw_bound_dev_if)); diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 18fbbad2028a..d5a7ecfcc1b3 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3608,7 +3608,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t pri= ority, 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); } =20 /* 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 =3D ip6_flowlabel(ipv6h); } =20 - trace_tcp_send_reset(sk, skb); + trace_tcp_send_reset(sk, skb, reason); =20 tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, 1, ipv6_get_dsfield(ipv6h), label, priority, txhash, --=20 2.37.3