From patchwork Wed Apr 3 07:31:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13615123 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.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 11C6358AAC; Wed, 3 Apr 2024 07:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712129547; cv=none; b=KcJSs5tE30mfPswL3KhMKngAXNNkFeaktloUgq641ASs6zUdVfgTPgPgRFv1FZqu91orR+9gVLL0yuRg28yjMI4P8VtvrG2TU9qTMflsuRZ4bjYJTXiuvkiu9nz6KRsrYOYUuXbd05Rr6mhOZ3SAxMVxptmt+UnSwYzNFR7AydM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712129547; c=relaxed/simple; bh=dhr20NlXym21jxcUBtm15qO3ecWrc1+nGKu06T5S1F4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=igfMFz82U5RMJLJZSUSuuckrVmA+MNfZTA2CF+EqBDvchLyoCDLgad1ZKwT6E2ATPi7NwXTyI2eTcIYnIaJrOIkeDfhmKMShgZ2KgSfILddE7eGDiMDMzBeTqHtCEAx7Go+AR6yS7YUSzj1lidREMiuZ6RCBPdsm/Gr/BJd1tiA= 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=Eaw6y8J1; arc=none smtp.client-ip=209.85.214.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="Eaw6y8J1" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1e0f2798cd8so50031265ad.3; Wed, 03 Apr 2024 00:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712129545; x=1712734345; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5vrHVrVIAv5qKWLWtp8W87NymAjBJdA0Vdn2EBkz+R8=; b=Eaw6y8J1z5FvAAj9KpUPQnnEkLiID2Av8+5+oxhwsaTAjQqZTavY8Xlzy3sF3XZhpE qdzEQc6f4DaEvTqCLjSrK6qpFKxv+wTdv+jJYc+VPcuHcExi7OApe0T2eYvj0jPWcoNk vB5pSk1VAVBbafWmyrgXL5O6CgLCsAhl2AXM4+4j/j3t45ZOFnaW4Z5CCvKI6QdpLQSV i2wgyyUJD/t5LhMRRe/HoITXVJvRAr41b+awMR0YqSpzkuZIMlaQpjCN4hKp7klHCw4E uQL4Vd6MWMVCwE+QIgi6N86IR2Y4RAJ3kyDwAbDwTLyiZ6lO3AoXf7kZdJtePal6JlbU axMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712129545; x=1712734345; 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=5vrHVrVIAv5qKWLWtp8W87NymAjBJdA0Vdn2EBkz+R8=; b=DCqiD4lSyTSrulafhOWSR2/s+dgPL/z3Rrg7TZZztWztFCDG41Aw/T2vlT8fkgNL3G FI4ciMRhnhU2yE/kEYgW1eKhmE970gIBjKXnFzsWfNL1GQwuTVmduq2AATI8p7jtDiK8 vX8MSaO9h0zF6OeWMIsXNdDmhpSHGTZNElGRwW97Q5U+YhyzWKZpIzKE0UiZvEwxCH+J C7ur97WdeF+TXGPGl/boaSoieOjU1kWkUIovxPX8UrPWYdNINbzE1IxHvglY0BcpKMEP RGjCc1+Nah7LeCgaYkB8GgBZUESoWJmIKJ5FIGFukijuZi10a9RNsQfMdGrgyITwcG+u rO3g== X-Forwarded-Encrypted: i=1; AJvYcCWfwVrOaY0FAAAqjweOMDsS64Va1QqHXmQIvWTZCFF0zCFAaVs8wkXEUaz3YeLez75dw8bPJVYdC8d6s34LyBHlG4WNrX7BkQFQ1TeKO0fepiBkVitgpWPRK7x3383NyIV9+CPy77op7Hf0 X-Gm-Message-State: AOJu0Yxihx00G6ayYo1lxzWQoJfgbxrQO/KXuotTo02km/fM39/X1C4V mCTiLiiZp3dDrPqrgtS+6kEX9ytniwDZKrLsetaE2dotD7xw4aIo X-Google-Smtp-Source: AGHT+IHzHTTqtYEhfFYeOamoZ5u74pZJXjUbNXhFBG1Yza+j3UOjZa/bn+SZS6NfP8fkZkAJfIFLUA== X-Received: by 2002:a17:902:ea04:b0:1e2:8bf2:f67d with SMTP id s4-20020a170902ea0400b001e28bf2f67dmr1945804plg.10.1712129545436; Wed, 03 Apr 2024 00:32:25 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id c2-20020a170902d48200b001e03b2f7ab1sm12563067plg.92.2024.04.03.00.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 00:32:24 -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 6/6] rstreason: make it work in trace world Date: Wed, 3 Apr 2024 15:31:44 +0800 Message-Id: <20240403073144.35036-7-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240403073144.35036-1-kerneljasonxing@gmail.com> References: <20240403073144.35036-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jason Xing At last, we should let it work by introducing this reset reason in trace world. One of the possible expected outputs is: ... tcp_send_reset: skbaddr=xxx skaddr=xxx src=xxx dest=xxx state=TCP_ESTABLISHED reason=NOT_SPECIFIED Signed-off-by: Jason Xing --- include/trace/events/tcp.h | 37 +++++++++++++++++++++++++++++++++---- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_output.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h index 5c04a61a11c2..9bed9e63c9c5 100644 --- a/include/trace/events/tcp.h +++ b/include/trace/events/tcp.h @@ -11,6 +11,7 @@ #include #include #include +#include /* * tcp event with arguments sk and skb @@ -74,20 +75,38 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_retransmit_skb, TP_ARGS(sk, skb) ); +#undef FN1 +#define FN1(reason) TRACE_DEFINE_ENUM(SK_RST_REASON_##reason); +#undef FN2 +#define FN2(reason) TRACE_DEFINE_ENUM(SKB_DROP_REASON_##reason); +DEFINE_RST_REASON(FN1, FN1) + +#undef FN1 +#undef FNe1 +#define FN1(reason) { SK_RST_REASON_##reason, #reason }, +#define FNe1(reason) { SK_RST_REASON_##reason, #reason } + +#undef FN2 +#undef FNe2 +#define FN2(reason) { SKB_DROP_REASON_##reason, #reason }, +#define FNe2(reason) { SKB_DROP_REASON_##reason, #reason } /* * skb of trace_tcp_send_reset is the skb that caused RST. In case of * active reset, skb should be NULL */ TRACE_EVENT(tcp_send_reset, - TP_PROTO(const struct sock *sk, const struct sk_buff *skb), + TP_PROTO(const struct sock *sk, + const struct sk_buff *skb, + const int reason), - TP_ARGS(sk, skb), + TP_ARGS(sk, skb, reason), TP_STRUCT__entry( __field(const void *, skbaddr) __field(const void *, skaddr) __field(int, state) + __field(int, reason) __array(__u8, saddr, sizeof(struct sockaddr_in6)) __array(__u8, daddr, sizeof(struct sockaddr_in6)) ), @@ -113,14 +132,24 @@ TRACE_EVENT(tcp_send_reset, */ TP_STORE_ADDR_PORTS_SKB(skb, th, entry->daddr, entry->saddr); } + __entry->reason = reason; ), - TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s", + TP_printk("skbaddr=%p skaddr=%p src=%pISpc dest=%pISpc state=%s reason=%s", __entry->skbaddr, __entry->skaddr, __entry->saddr, __entry->daddr, - __entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN") + __entry->state ? show_tcp_state_name(__entry->state) : "UNKNOWN", + __entry->reason < RST_REASON_START ? + __print_symbolic(__entry->reason, DEFINE_DROP_REASON(FN2, FNe2)) : + __print_symbolic(__entry->reason, DEFINE_RST_REASON(FN1, FNe1))) ); +#undef FN1 +#undef FNe1 + +#undef FN2 +#undef FNe2 + /* * tcp event with arguments sk * diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 35b0f3bbf596..3aee7cb35ee4 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -871,7 +871,7 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb, if (sk) arg.bound_dev_if = sk->sk_bound_dev_if; - trace_tcp_send_reset(sk, skb); + trace_tcp_send_reset(sk, skb, reason); BUILD_BUG_ON(offsetof(struct sock, sk_bound_dev_if) != offsetof(struct inet_timewait_sock, tw_bound_dev_if)); diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 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 priority, int reason) /* skb of trace_tcp_send_reset() keeps the skb that caused RST, * skb here is different to the troublesome skb, so use NULL */ - trace_tcp_send_reset(sk, NULL); + trace_tcp_send_reset(sk, NULL, SK_RST_REASON_NOT_SPECIFIED); } /* Send a crossed SYN-ACK during socket establishment. diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index cfcfa2626899..da2f70ad89b5 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1131,7 +1131,7 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb, label = ip6_flowlabel(ipv6h); } - trace_tcp_send_reset(sk, skb); + trace_tcp_send_reset(sk, skb, reason); tcp_v6_send_response(sk, skb, seq, ack_seq, 0, 0, 0, oif, 1, ipv6_get_dsfield(ipv6h), label, priority, txhash,