From nobody Sat May 18 18:27:45 2024 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.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 208D314A4F8 for ; Thu, 11 Apr 2024 11:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836618; cv=none; b=ZGGShT2vqL7ZQa0SNxRSAOgfnkPZvKfV2ODBWNl3ud4KJex4BeyR0AQqTyq8s/k97JraoJ1rNDXbypnqNCRgRb6Gbp6tlal83sKKdJoDn8KJJ8I+gFoCGXs1klPpr3HQAIGe3qU7BzIzhYV2YA2Y2OwNfbb8te0Ihd1TnWJ+3/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836618; c=relaxed/simple; bh=QxQkbOA3Br0WuU9xk+KkTMUYboegP7NLcOJy3FqX37Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wcf47shTKzglCRJpXiRkdEyPk5gTeKTyIxZ7oVC8mCd1H5ziOfHipZAs1o/Y4EPtbPz+JK/SWXZg6vPIxhRczv+8mRylkgjPHcnXjt5d3dzW4z2aVDmsMwCkjGpy0V2K03tZkupjoEoRVmtqgavtPLoxVO4IDO0Eqw8fdyglutk= 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=frDisODg; arc=none smtp.client-ip=209.85.214.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="frDisODg" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1e3e56c9d2cso42525365ad.1 for ; Thu, 11 Apr 2024 04:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712836616; x=1713441416; 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=/wNq7bsOsSHUvUgQxtlzRzCIsQGI1JY3zE4kdWaFaxI=; b=frDisODglo6fHKmvxmUp72oIj+4bm8xBRpJRgbHTuzM1xRoURRNuU87jRZwnWmVKS9 qaz6yTU2XOpbeAIw5GAZa7++dRMIuK3uHYuYy2Q32lZkr9ePQYYHHfPymPxnQOHUeS3B ZexXIdLXRMys+yq+W70RfOmNSt/4ySibcSZCHDQiLtHgIPEzjptW0Pme2vk8RRtZCvNl Bw2mZsGqG0OwuaTGBYLR2LydEaTdIIEM6HLjuEYvY5JMhEHo/UsDFiZCdNT8er4EQWsz 9wojZgdPPs/DJcOdhOMs4fyl6HW+G9+XHkWIrlymGfbG9qDWZtasuFjGF6SGNbIbjNKZ Msaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712836616; x=1713441416; 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=/wNq7bsOsSHUvUgQxtlzRzCIsQGI1JY3zE4kdWaFaxI=; b=PmYU46CTSS8lUG5EWV5vP4/RaBSpHBl4i1c+PSURmF0jtBsmwihg03q+I5f2veEq8r Mu/vXVorP/nY32ZDKriwy/0/Ezg/X4VrLR3BIid9m4dq18FsvFQkuJFx3/4TFPK2kFHE BKSEQXRuGqRL5OmFPG4D237iG5i4FF54JSXMjYWNJ/kxd0XlsBTAV35/GhxK2uy2NZEP ueSmkBxrbG4/XaGCPt7KYWoXsI6B6VjKg3lmRlW9yBi3JlehjKqo/psFQYIB8tn/bbZr xgBRfGvvVOigwTLHpTXaEmr5VXawoTTP5IYTCIV1vqDtxZe6KUJ3KPfm6mCKF0SgJyor 8Wjw== X-Gm-Message-State: AOJu0Yxzg5qeIY61KBB4zH2to//UZ7iI0Tg6fm6eh112hUOWt32joILZ Be3OoEKSoT+1XIHX0OkrHtcZZpBdlXKI8y344Qnj4h911pxgZVGG X-Google-Smtp-Source: AGHT+IGyXv62vTZgAWeVT5K1y+w5IROp+DapcU3nqzzTDYNrLxfKRPDd+wwWLWwBtlc+nds4IBalWg== X-Received: by 2002:a17:902:f542:b0:1e2:7717:d34e with SMTP id h2-20020a170902f54200b001e27717d34emr6303712plf.58.1712836616449; Thu, 11 Apr 2024 04:56:56 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id u11-20020a170902e5cb00b001e20587b552sm1011840plf.163.2024.04.11.04.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 04:56:55 -0700 (PDT) From: Jason Xing To: edumazet@google.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, atenart@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 1/6] net: introduce rstreason to detect why the RST is sent Date: Thu, 11 Apr 2024 19:56:25 +0800 Message-Id: <20240411115630.38420-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240411115630.38420-1-kerneljasonxing@gmail.com> References: <20240411115630.38420-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..38c39d32a961 --- /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 enum sk_rst_reason convert_mptcp_reason(int reason) +{ + return reason +=3D RST_REASON_START; +} +#endif --=20 2.37.3 From nobody Sat May 18 18:27:45 2024 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 7C2D513FD9F for ; Thu, 11 Apr 2024 11:57:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836623; cv=none; b=Cov6cedlekUYaWHRzJIz3y8NXKFNLvAAL7q+bHKZrRBhhoIGyKIcSwPnNrIK9w42B2kYBdquwUjPYKy3iqW9jHQo3iyeUD7D7TJtAoC/L+SIjYywz2cZcn/gwxWUzhU5vkFnAGcilsv5ypOxxfbxYibjbb1Y/K4U4I+fHJqYGWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836623; c=relaxed/simple; bh=PH0t0uQxPHpHTnOZNvi9SxZmiLnATkh0wsu80tL1a5I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U8WilfWSDcFhWNFZX1juvqfdnCiTYMD6T7DStQSTfFNgqpKfHQhuAm1PhatcrlZ+qxEi/qZxkaa8S2kKHKBtgEJ+jo7eHwLD/gvzC+FE3eJtvHH1+1gnRywc3fbWiqapjj5wAWmpCJwhzsOZMrq0ZpcnTWQ6Zd87kvaXBsZsUjo= 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=g1w7eyHG; arc=none smtp.client-ip=209.85.215.170 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="g1w7eyHG" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5dbd519bde6so5592192a12.1 for ; Thu, 11 Apr 2024 04:57:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712836621; x=1713441421; 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=GZLRkIDF/aQki4JRqdF4sjfFGCD9QXnJCAeTRcuS4w0=; b=g1w7eyHG+z1VugiWMQPmjpRfBRaeElPrxKhh03DBMb5I/wbQ/WtG0HuQWd6TeCQRt5 mPsC0elHJRr8v5obLLvyCYVrXSpYDwuA9ZXCuUM7bR/bfA8GChIrXoAUIdx3VRN1sjVs cqXXz/dbnrqwJp53eGuR6vOb5DcQnJTi2+kTgDwqgi9LZJxY5vqugUpkFhFLez32L+mQ WCb/8Ou+1W9Q3+OBqdUjK9OmuIFo9eOsUwk0o1T2Psbu6VQ1gaNpLPDyNB3EqyvbWNgJ yWCICjIFiQScByvMole3Y2OwSIxNs4tZJdeRJRIuKSTKwaT3i9j3muATu8K5kqCvtfUA j7GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712836621; x=1713441421; 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=GZLRkIDF/aQki4JRqdF4sjfFGCD9QXnJCAeTRcuS4w0=; b=UaxLxt4EIk1vYwj3nMZ6Dm06winNiSv4i/JsBYz3EDchKU7XAPWDGU1mRj2tWeqWjy fbbpvc/9nxKE9kFeX955lnmruO/OhWgc6MuGf0z0toXLGx7a142yBuhbbl+CIc6+y2Q9 hCcXgZWazNrYp3vARGoa59pynBRBcTlq4wGDlsxn5M5W9ARuU7Cv3eHQ1UgHJexcSBCF /J5dB4ptB18fGu5kmXiUaKyXhqImzpu0JDzNHYb+1vGYdi9MLt7LuF4WIlZLNSxuhtFG EadEhS9U6e76SQTpS1rdAO53XT4IHxp7L16EVann77c5tBvU0RuatnoVxU6dEAWKxxfN LFDg== X-Gm-Message-State: AOJu0YwvooSjogyg2Z6pPZcia7Cf4zHfwj0smzySmdHMfDT0k1Clxrak Vl9JL/nKQ/giyfG0ZhD8Mqhu5FdP1Bj7iP9PNGt6MDsjR84EML22 X-Google-Smtp-Source: AGHT+IFVfRizPmPMWnS9jU6CV3veUN8cJrkadY6/j21/YXZP+QB1AF29K/OvnOzGhL2RcH7zvz9Wkw== X-Received: by 2002:a05:6a20:1582:b0:1a8:3607:6939 with SMTP id h2-20020a056a20158200b001a836076939mr6467692pzj.57.1712836620657; Thu, 11 Apr 2024 04:57:00 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id u11-20020a170902e5cb00b001e20587b552sm1011840plf.163.2024.04.11.04.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 04:57:00 -0700 (PDT) From: Jason Xing To: edumazet@google.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, atenart@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 2/6] rstreason: prepare for passive reset Date: Thu, 11 Apr 2024 19:56:26 +0800 Message-Id: <20240411115630.38420-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240411115630.38420-1-kerneljasonxing@gmail.com> References: <20240411115630.38420-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 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 | 4 +++- 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, 40 insertions(+), 25 deletions(-) diff --git a/include/net/request_sock.h b/include/net/request_sock.h index 004e651e6067..bdc737832da6 100644 --- a/include/net/request_sock.h +++ b/include/net/request_sock.h @@ -18,6 +18,7 @@ #include =20 #include +#include =20 struct request_sock; struct sk_buff; @@ -34,7 +35,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, + enum sk_rst_reason 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..ff41bd6f99c3 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, + enum sk_rst_reason 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..85f4b8fdbe5e 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, + enum sk_rst_reason 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 52963c3bb8ca..441134aebc51 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, + enum sk_rst_reason 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 @@ -2276,7 +2278,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); @@ -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); } =20 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 =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..6cad32430a12 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, + enum sk_rst_reason 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, + enum sk_rst_reason 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 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" =20 @@ -307,7 +309,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 @@ -374,7 +376,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 @@ -909,7 +911,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 18:27:45 2024 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 D87A414A4E7 for ; Thu, 11 Apr 2024 11:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836627; cv=none; b=BYgm8NN6ftz68TPkUmVdEHtaJaypI11nZhanD8mYboPUfCIYHpSQOO7zKFOPdH2gjYvi19HBTrkp4SizZ/kArFNVhacje+HBefyzKcOfCZC7xYBtD9ilDQ+c9qZo5UWAOng7LHwIzJIoPR3ofjQK/cSwLnqp7iud4rFQU2MiZDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836627; c=relaxed/simple; bh=QDXdQSkDHuzteTkECNBAUoiAbWoEZw3XHYbmwYsfO/s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZAbBlasDP9gUM5GxloZHASoYyMcJFn+gt4ccuzNCVW7LrhTwbCYCX0AQg5xpHJj+yMaCCoqdFS0nUTR33VhDmrRnncrdJnj3hpKN9IfyxrLu0H8OTJAm0eDoYNvGHuaAcQYFEnkyaV9vRmLlZM2rKXeBK3w0mXBWMqwn0UGqq2Q= 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=RUe38NX2; arc=none smtp.client-ip=209.85.214.178 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="RUe38NX2" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1e4c4fb6af3so4831585ad.0 for ; Thu, 11 Apr 2024 04:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712836625; x=1713441425; 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=oPE7p2vpZRESzfBUla5/6tIKNhBdR4JbczrIhUlcUwQ=; b=RUe38NX2qkO6BhN0DQ1eV2lmdSstkL2u2up8x6njMWaNjXEUDM0a2jUCn6RpjUuqu8 ekS1baGVPgKT9jO6ILIJH4t+pNE6L6qk++IzQ7ajILAXyI0f0J7g/SA/4bf9JaR/l6EQ ZI7vlSQ8LqrU17eF4e3J164UdkgK1UT+MTuNmz0tgJV82lMUhDI5TLj8AbYg/li4KfgE 8HxKDlRfjfU/ZSWQDUeuPu+ehRcesll8kAg4QMrt4WFRzhPcUpwEt6OToke29bRuZsHN Pe6S8XDyrKFT286NeyTYNKB9hGuvkTTbdDEBarDeVQFjYic4cOwkhaHU/wBoVnABcf4e Kqeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712836625; x=1713441425; 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=oPE7p2vpZRESzfBUla5/6tIKNhBdR4JbczrIhUlcUwQ=; b=q8b1gOuLmHxv/zBewibXMmib2i/zAXrDmVycgGwq1Tqao639Fu0Dyg90GsQFuCxcrH 992RbSKXEXD3iRJEHZpfy2NgZoN/kTAXtCrohiU8LpwBQjnSKNpqQwoEN2D6TVltUYtK G12TKBK87VXorm0i/sTf6uWGEJ36EEXl0sKv8jacCISJI3s4ZIjdvlaOR1DUh0icM6IB 7coX4axq8vp4OxYzXnu2qk805PCHV/CLbf4CucEk2IOmSnsgQtEwjb+MpSkL/vEDxUXU 2rVLuSYRytCThS23F66F7VZmhTUKJQKy45f2O6QEkS/shmjwrSgjjPuHr0cWHbGQd81M YT6Q== X-Gm-Message-State: AOJu0YywfzLjiENpGP/rE8vJKW3Iy8wXaU8oSWdv56urS9BsWO3G06jX uR67+ese5Cxrgw7TQO2YiLjBFV3h/IdSif35ryy4I+V+LIMc9M1T X-Google-Smtp-Source: AGHT+IEnWLdRp6y5YQYFyXjtgFPi9LgrTw2PLGs4+BSEqPfRQp9KwMntd5c3g2sr28lxT57Xa94yAg== X-Received: by 2002:a17:902:ce86:b0:1e5:62:7a81 with SMTP id f6-20020a170902ce8600b001e500627a81mr2599800plg.22.1712836625205; Thu, 11 Apr 2024 04:57:05 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id u11-20020a170902e5cb00b001e20587b552sm1011840plf.163.2024.04.11.04.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 04:57:04 -0700 (PDT) From: Jason Xing To: edumazet@google.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, atenart@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 3/6] rstreason: prepare for active reset Date: Thu, 11 Apr 2024 19:56:27 +0800 Message-Id: <20240411115630.38420-4-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240411115630.38420-1-kerneljasonxing@gmail.com> References: <20240411115630.38420-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 suggested-by tag because I also want to make every patch clean and --- include/net/tcp.h | 3 ++- net/ipv4/tcp.c | 15 ++++++++++----- net/ipv4/tcp_output.c | 3 ++- net/ipv4/tcp_timer.c | 9 ++++++--- net/mptcp/protocol.c | 4 +++- net/mptcp/subflow.c | 5 +++-- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 9ab5b37e9d53..aa40913870e1 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -667,7 +667,8 @@ 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, + enum sk_rst_reason 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 =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 9282fafc0e61..5d8eab15f462 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3585,7 +3585,8 @@ 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, + enum sk_rst_reason 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 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) =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 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); =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); @@ -1348,7 +1348,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 18:27:45 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 372F214AD36 for ; Thu, 11 Apr 2024 11:57:10 +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=1712836631; cv=none; b=r+fNb68ObMiNg5/PyT2VUgNMVutIiOrsuS3Zj1XjfAFmCXG5rSgdaFcyeshQCcnBFmrGdZMfQoWiePnKtHn3uZV25TyHpmfJv1MEF52QGa+n6P++jpFlV/8omeIuWsybujSe6fnzVaYc7kBiUQ93ejIXWtsRUYP/Jqv14EKVJmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836631; c=relaxed/simple; bh=YYAstX7ppQWMuzdq68g4kGdGP/fDG5Hqbg/nseaU7LQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C+nu6Iq17+pGkvPk4Dm5o3np6bT/FjTpjE7/rZv7oiMcl+xNEtxE2J9I9O4CzOMvgJatc/ZM4hw2brsVVt46XX7BOyG96fkujkxuvOy/7KJS6c3mnmZUrRzE7nAsMklCCLIBxU6VKLLwNyGE/TCAX4YrXaagzruWmsx4gE3ZSrk= 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=jCP26k/a; 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="jCP26k/a" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1e3ca546d40so47173465ad.3 for ; Thu, 11 Apr 2024 04:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712836629; x=1713441429; 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=qzPPT37X9CCukMbb90HnYaZ5ZonWT01Ndh8y/YWgYrg=; b=jCP26k/aKNx0PCZovfjwKMVbSpiixxTjggr9IsyLE4uv1TvsjzPmAPwOSv8KJ3zqOb NhfodUccFLWOF/uxgKxdOJVVCOEBYYXuXmKcKvVovcfsoy8Pi/kP66vb44PC2lns2EsE Yq2izaLY5uYptVCiJIthFID6KYahe6jgu6SfaM+Bx+ef5DXuZpnE7GoOMnXxavs0y7ES Kp/ROMVlT9+KLAAQkE1L4cH280gFswuiKMbmBixdCidelhiOm0O5ZotasqP2xfFQj22N g0QLjru0NVfuNFUnrR/UJls9J0YJhUJA9/0maA08pJM0StGpEd9x44Gw+2vvXafH8r2J VZzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712836629; x=1713441429; 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=qzPPT37X9CCukMbb90HnYaZ5ZonWT01Ndh8y/YWgYrg=; b=Fq3hGF0J2jzw1El0r28cmgZ+LZwarX7EHe3ly/qSN8AzHB33L4GblPf+DZPeiqXMvT QRb8dpmol1rRdxyrJB6IakO3sJNjhKazedfcWojyEfw4Tmloo2wxhR8oh6bHIhe2EbaZ lASzltLduL+nNwSRXEhGgy/lVbN6bS7wF+RpYN2PSGbcwFXjEWXWPxydqZ0cknbKjc3c MHvwC3YFnt0YlNRym1GGPCirwZ+PgbwOlUJPjrPKYnfVKCGgLiNOy9P6JwlzfeAqKDxb eD5UWxsIAPp9q4sB6vwjM/n1ePeqElZWp1ZEejB+k0ApGHZoj4vB79UYyG8hhqVqSijH /YNA== X-Gm-Message-State: AOJu0YxWVyZzam5BCfgkQuo+extSND3NKHhzbm/Pptow+fzL/swRs/MO rusihjKxweT+hXwSyXEKZL1IIC9xuoG33lroZ/ZVo1qIwt77jAR3/glyfA== X-Google-Smtp-Source: AGHT+IHka4LqGg39XwLYMiisy6zHtStylD20DZX/IFHR0ajxOiOQ/ecEmfO2dan9iz62T8YrNr1nuw== X-Received: by 2002:a17:903:1105:b0:1e2:9ddc:f72d with SMTP id n5-20020a170903110500b001e29ddcf72dmr6191779plh.26.1712836629380; Thu, 11 Apr 2024 04:57:09 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id u11-20020a170902e5cb00b001e20587b552sm1011840plf.163.2024.04.11.04.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 04:57:08 -0700 (PDT) From: Jason Xing To: edumazet@google.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, atenart@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 4/6] tcp: support rstreason for passive reset Date: Thu, 11 Apr 2024 19:56:28 +0800 Message-Id: <20240411115630.38420-5-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240411115630.38420-1-kerneljasonxing@gmail.com> References: <20240411115630.38420-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 441134aebc51..863397c2a47b 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, (u32)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 =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, (u32)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, (u32)drop_reason); } =20 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, (u32)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 6cad32430a12..ba9d9ceb7e89 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, (u32)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, (u32)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, (u32)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, (u32)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 18:27:45 2024 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 6973314AD26 for ; Thu, 11 Apr 2024 11:57:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836635; cv=none; b=CQ/repZYg5lLKqCc2uj73mRFT412QcJb65WGIWSKi/o5QrZ4X5mW7qovPHIGAmRw8vAZS61CrjASc+Oqs/Zw6QDPQWGNxHMUvGr5O36Mg4xRl34jDiUf1aIdPqiQBEwNyArGK8yfnFruNIPvvK81nYIgofzV1MkAgvbCGMjzOVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836635; c=relaxed/simple; bh=hWy3YGmkxWsTcp/zGL5RAIH6IGzWY2P3DpM0v8axmXw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NTZV6ZSggUz+L2WbgopTVs8i248+claHP59zQk6/VTAnkd7jMyzTZG1AEkV8453hx8GNMsupv6/282XM+C8BoSNdC1WzIBGotZf6Ozl6mhpi/lDZYYuwZbjgqMUuTXrVENjfsIerrguyE7WxgQdvAD9RMEqhcgWbag6iv0ynXu0= 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=EXbMcvDH; arc=none smtp.client-ip=209.85.214.178 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="EXbMcvDH" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1e51398cc4eso12292455ad.2 for ; Thu, 11 Apr 2024 04:57:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712836634; x=1713441434; 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=o+ZpBqN9wkpehzV9bwSaxvgN0i8FpFSb8wa56tsf7uE=; b=EXbMcvDHYunXNACvG8W0n0S9p//mjia9a+ikifkTlL9XCgIfg1hzQX9s/OYJQANSHz RaTBKBO2Noo5/f4GlWtJ5pCuOoAEDdVjL1K8WzAquQ7fJv219mLf2iriTRMaXxnAcJJb KjgpQfcLO0ZshXamo7oLN4xu1dxl9WiT4vzBI4LRTePxLSGtV2nKoutRoHcySkaY+Ymz dX2xj4HJiJJ3IJV3qaczQR4zo6FK2zEbdE+fYXAqHeNFwEvUBBzyJtjnvwpO+PMfzA/U qpvr0eh50/AOmruyut1QhFKARskn9EpBT+PN98oj8zrUu0iyeRQsD6idkXRZb8dvbjDM EQsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712836634; x=1713441434; 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=o+ZpBqN9wkpehzV9bwSaxvgN0i8FpFSb8wa56tsf7uE=; b=O3d+s+ICFAMAQwkJUP474bzPRtvQx/9ZZmGiybUOHg2oUu+JOGHlbS8MG1wYPNGoDh yVNUpP0htx2YAq0MobH+V8jP8ZSTUVWgJowco5di0HEEOqmElM8emG4y0JypI7CQsqtH U5TOobFcuAS6MhKpnuX+thTRyXP0BJQLxGkGewfjv/CDPGtHxFlpLcY9T0ehmozx/t1C 1RRPxpi7VXIvb1fRBM/B/eB3gOIUD4i7TX0aW1mWJJANyWi4av4REQQtw+48Xrz6YEC5 qkKxpAf2gBwwcpU1C8mYeisZXF19ct7aLWxa1xbUO7Z6aXJRFZVBPd5sN91vE6giuvDq pOPw== X-Gm-Message-State: AOJu0Yz172Tm+lNP/anWZKQj0Bohpl0Z/nLM7HgmyWwZQNotmQ01gB+b sGRXmbgj7F9bpMQJRLXBR4nz0/5eRsg414Xb8HWV+YOUkmYCgbZt X-Google-Smtp-Source: AGHT+IE0GsoNBivZ1/ktea9PqQlxiMwaMWZZIv74Staw/lpFZm33RXkHsdNOCFeaAdnOkZ2h5KSZlQ== X-Received: by 2002:a17:903:11cd:b0:1e4:b1c7:9a7a with SMTP id q13-20020a17090311cd00b001e4b1c79a7amr7510161plh.22.1712836633768; Thu, 11 Apr 2024 04:57:13 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id u11-20020a170902e5cb00b001e20587b552sm1011840plf.163.2024.04.11.04.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 04:57:13 -0700 (PDT) From: Jason Xing To: edumazet@google.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, atenart@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 5/6] mptcp: support rstreason for passive reset Date: Thu, 11 Apr 2024 19:56:29 +0800 Message-Id: <20240411115630.38420-6-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240411115630.38420-1-kerneljasonxing@gmail.com> References: <20240411115630.38420-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 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 | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index ba0a252c113f..25eaad94cb79 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -308,8 +308,12 @@ static struct dst_entry *subflow_v4_route_req(const st= ruct sock *sk, return dst; =20 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 =3D mptcp_get_ext(skb); + enum sk_rst_reason reason =3D convert_mptcp_reason(mpext->reset_reason); + + tcp_request_sock_ops.send_reset(sk, skb, reason); + } return NULL; } =20 @@ -375,8 +379,12 @@ static struct dst_entry *subflow_v6_route_req(const st= ruct sock *sk, return dst; =20 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 =3D mptcp_get_ext(skb); + enum sk_rst_reason reason =3D convert_mptcp_reason(mpext->reset_reason); + + tcp6_request_sock_ops.send_reset(sk, skb, reason); + } return NULL; } #endif @@ -783,6 +791,7 @@ static struct sock *subflow_syn_recv_sock(const struct = sock *sk, bool fallback, fallback_is_fatal; struct mptcp_sock *owner; struct sock *child; + enum sk_rst_reason reason; =20 pr_debug("listener=3D%p, req=3D%p, conn=3D%p", listener, req, listener->c= onn); =20 @@ -911,7 +920,8 @@ 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); + reason =3D convert_mptcp_reason(mptcp_get_ext(skb)->reset_reason); + req->rsk_ops->send_reset(sk, skb, reason); =20 /* The last child reference will be released by the caller */ return child; --=20 2.37.3 From nobody Sat May 18 18:27:45 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 C581514A096 for ; Thu, 11 Apr 2024 11:57:18 +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=1712836640; cv=none; b=hhUZj+uV5cd/w8P4LvFrDQV4daHFVzsgLOQ2dxzOwwLQiNCByfDogUFie+iv7KgdiD6US/UjrgGmcwZycXc8731+prqRlwCD0T3WKlj/XyzsaV/9mYiKf94tWeG+grge5EDHGlgJfYHE0qV6VELvsXev8eoRnEfrVZH05eILTz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712836640; c=relaxed/simple; bh=vTP3QZ7Mb+YJeA+LCWJ0BN539kxVD/c229G2uXJNsqI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X3eFKf7BBUFGr8AVvxQBUutUGtHA5sATvn4HbFwnGU/0NxpdoR8YVe37UiWDpFwKA9opBEmiiVC8uobUOEpISf5matAZBEfrQ1Qmz+opkG5jTWB6G2qaLgZm9/qySjDcAMQ5OY/4Pt0xh8G+JajjKSAuswKiU6uzpkpCkPdR15Q= 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=DnobkaMP; 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="DnobkaMP" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1e4149e7695so33378185ad.0 for ; Thu, 11 Apr 2024 04:57:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712836638; x=1713441438; 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=QWEXT88lioNnr4qYEuDUqPtJMEDt8QzYuw3n5cZfxZ0=; b=DnobkaMPeKf0/lT2UO2hsCWarPqDyh2oo9uCjQltseUdm3QD10SKqukBC5dTUxSmfF KgE/YLdXYyt07MtEa5WQmvu2bgueVJVP/uTUZylzEl5gKGhsbk1VaZzf36b6d/c5Jjsb /6IoSWOP/HB433XCSW+JgDMEsj4helIu51uoOAufmDFvcOycC6Q5JRKUWel9aCCZnk/e BnNBdPs4U8hcPnLH/aWKnjrP2P48uf9cdHoRCni9l5EQOMMR7E4gtLYjAufvT/keaCCI +ZFTVjfCF7rMj5s4QP3E3UQu3bvkwsZhGG5uT/a9xJCdCj6mJayDI/ZNLM1ntL9HEC/u bCGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712836638; x=1713441438; 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=QWEXT88lioNnr4qYEuDUqPtJMEDt8QzYuw3n5cZfxZ0=; b=Q5k0Feqw7AcUNGwGS7fDxJzH4DXr9d/znSGlWaJoXNSupgZ2MJNe6pO7zv3WZfoQKi UxzvJFLFvgVTItAChKGI7lmlomqsG24nqciflzSsw7YTAT6tCg37oodVLUAj1uG1SDHB io7lJLw0Toxd2ob/6c2jA5k/gYysxNUoFBQspFfPLobSjStljKVGXs/U4hqJndHKgeCX 7kltrqkXlJ3qhz/xKXDaVjMM9bmnCqUWgmUocrJXlcWWbHEGTIxDZGQ4IHr4JL2UXgd8 8V9JQXDstEMMQbbyCLj4/eCQwlORdz/sTls3xKmZY+RTBlCnu7c/IIKQBnbrqXQwhX1b HpzA== X-Gm-Message-State: AOJu0YwVdh6ZWjjWVvQ9Ru510EjZne+Ff08i0o2e/Q/pU7q3j9P/Nn+r iyMtfXxVdHyXNVHLMt7rz+BAecIxIQRTRmHuFu2UaCmnNDNtaON9 X-Google-Smtp-Source: AGHT+IFqYXTgNjL4+xx66eG3U7c7lQ2V9mgdJIUFQU1kPnie++FZVWqY6URtyzRTXyxxVGKyXrx0jA== X-Received: by 2002:a17:902:7ec1:b0:1e0:e85b:b9ca with SMTP id p1-20020a1709027ec100b001e0e85bb9camr4216746plb.21.1712836638082; Thu, 11 Apr 2024 04:57:18 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.25]) by smtp.gmail.com with ESMTPSA id u11-20020a170902e5cb00b001e20587b552sm1011840plf.163.2024.04.11.04.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 04:57:17 -0700 (PDT) From: Jason Xing To: edumazet@google.com, dsahern@kernel.org, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, atenart@kernel.org Cc: mptcp@lists.linux.dev, netdev@vger.kernel.org, kerneljasonxing@gmail.com, Jason Xing Subject: [PATCH net-next v4 6/6] rstreason: make it work in trace world Date: Thu, 11 Apr 2024 19:56:30 +0800 Message-Id: <20240411115630.38420-7-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240411115630.38420-1-kerneljasonxing@gmail.com> References: <20240411115630.38420-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 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..b1455cbc0634 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 enum sk_rst_reason 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(enum sk_rst_reason, 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 863397c2a47b..b35bb4a52464 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 5d8eab15f462..196c25194acc 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3611,7 +3611,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t pri= ority, /* 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 ba9d9ceb7e89..1dfe5b99476b 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