Received: by 2002:ab2:3c46:0:b0:1f5:f2ab:c469 with SMTP id x6csp136300lqf; Fri, 26 Apr 2024 01:56:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrT8NCIawb346Xq9kBndR+g1WoJq2yi/M+wMg/4wK8ndJGTFabj+DsVuY9HrE/LRAnB4xbLjVrvQqfHz5djMxUCZncXaUoOQ19sTyARw== X-Google-Smtp-Source: AGHT+IGMjWSQbNbzdnFIbosrZsrCaXyLvuc+utC8sEb/NLX029QGKhLjFbAGKjyoco33l/mHSnHJ X-Received: by 2002:a05:6808:985:b0:3c8:2bb9:1511 with SMTP id a5-20020a056808098500b003c82bb91511mr2114683oic.2.1714121765214; Fri, 26 Apr 2024 01:56:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714121765; cv=pass; d=google.com; s=arc-20160816; b=mTElmyb5v1eWIFlcEKlvgKKScDseJpc/MOwmOYjsfGLX6vYSO6RNF1p09aCVzHtFnN fw0JxvkmrttO9tnCfH/eXJmRaJfI1u32XtmnxTTLubODB8AojH96Q9y2U7zYOYpQygKh +K1aNrJa2L/2CG2erK74M02+/NF0VQC32+VpGUQYyDxy+BkghuoCWvi8TYkf69L1tOSL gvBrryPNduoDUcEds42wSRhiMryuSXrYSs5f//DqeL2qatCwYwQsw29O5Y/NoYdycRbk Xz0D8iYguImsGrLKY691RuRNZlchznKexFYqaHSgMvi2fEKTG67HaWEzXtpMcMxw4xRA dnew== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=fc+ioe2m0sqBtoVQtiXkBUwqMXmEVFtjvfR7brjhWPc=; fh=TcBc88fHzHnOdHZWAf6TV1RW23nBrRKy76v45G6lCmM=; b=LoFwu/J4TnVpGHv8J3D+i41AM0JhvKNI/I7i0PTA00DDL6mXS0jjDksQrDEkDXM744 o/oRGsJ0VuG4WAcFEM4FgM7SxgflMbV0+pONw7MYEzkrdK+5if+Z1CeaFkmuWI9XUU1t IkJuI3OndIL2VnN+Dx2cx0iK+SrG3M8Mm3895mLAzazcRKbwbgrxolQJit/XAo9SKS4f G/4LxqpBGMdhg2GrDn+kiN/Pq6bRuhJR/TDMqVj2KiSDjqRT89GCfIWhCE2Or+Gf4fRT JGSReVLBTepK8sI6Hh/L9yJnif7fKmb3ksYcW93jOVXvTKVwvGWs9GAOaaN/bjILFUqf GMwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=reLWl8wF; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-159732-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159732-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k136-20020a636f8e000000b005fcf80ba059si10622474pgc.496.2024.04.26.01.56.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 01:56:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159732-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=reLWl8wF; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-159732-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159732-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B21082812EF for ; Fri, 26 Apr 2024 08:56:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43F1113D2B7; Fri, 26 Apr 2024 08:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="reLWl8wF" Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 B465A5B5BE for ; Fri, 26 Apr 2024 08:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714121756; cv=none; b=EMarur8Nar82rGIcr7ujIloqAUXPNQ6QNvqmmGWPDYVASFu2M4GFSkTyMuetDIRA0RMMiZ/HBoRHXDesQKFS+XxIAkhnUcCxmEWIw8ONY7JiX+1ANieZvfQfWFu2osCSg5sybAeOYbJIUH4t1uCZBdMwoutS+aAj9pWNFq1UhEA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714121756; c=relaxed/simple; bh=4dCOVkO6+jaZbxpgg0GQvgunFe90UaVu5W4VrEP3Jx0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Z4ZlpeeIaCvXE4NVHTl/eNnQKZ5e/PBVJTn2elUiLt2YhGXUR4OUUNY49Ff2aVKHwRS4FUeVIhsCTVPn1j7M5+3iDD8ng5tQivQEeKUgajabsN3jvpkS5C1jnLkWGGaM8CWbJXlN+oaNsmB+Ly3RbeTby2bfKaXpQrCbUwg/RCM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=reLWl8wF; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-571e13cd856so9977a12.0 for ; Fri, 26 Apr 2024 01:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714121752; x=1714726552; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=fc+ioe2m0sqBtoVQtiXkBUwqMXmEVFtjvfR7brjhWPc=; b=reLWl8wFsimmKcL33xUvB+fXA+4UPNotH8gAJq01TJ7OTkKICq4o5fZaRwhBZA67XM vuohr8/XtS5oOgJTSRGOyiRXbt2Eou3nfNRB6Bu9/GNECBWsC/AYrWdV4+Ylp4JDJGap Um0LbyWA3aGNPbBI4aMBFUuYX20okyWmDZvp1DfwQFUCWo+II+jJLMmkgn/NR1Wt9Ee8 TRJg2TAKLVff5Z2CKGE0Qvenz9HzIJfmzUWCgs0gcAMGrZmnTDNVYv+lpTGqP+QXMmi4 qkonNyQhZt6mMMZ0SRL894OkYinSGZMsueTF7ypHZIwXhIXrCSSJoo/d5aYp2riGxQlh LHFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714121752; x=1714726552; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fc+ioe2m0sqBtoVQtiXkBUwqMXmEVFtjvfR7brjhWPc=; b=h7y58Ikj/HHRdJra345+xA3qXirpxNStJ9LkBsDwukvtkDXZcwnmQGMzr2s2E2aYbO AE7PGtqMw0rEL4oQyQyF83URe6tta6nr+uRm94rD8YLZlwYK+u4oGCFDrKXg5mzPLyi0 VIIEGZXyZHjR+HtW2e9CAmKY0+qt9PLTcY9euZQjac8mmFxyLjD0gaf3anbuz5TptDEf p3rDJ/SUu846ubGW2uvFzKjWpELhlkGQi/RxYsqGeFCMAtrY/DRE7iOgwQV36o6SrGKa 4CULLsqHgKIGyGdV9OqjbTzC059S3u1Ui+ufCVkD9kwArc4cKCHppywAkCDW5mkM1Jf8 ZnoQ== X-Forwarded-Encrypted: i=1; AJvYcCWa8GtRiRSPxr5L4+v7jcTpc41KadM/EL4uc0zUPNOerUfSeYq5icnZe2IXK2YihcbKbGkNdqYSv+H+7lJp3Iah7CazDRObSZ0MOs0n X-Gm-Message-State: AOJu0YzRp+b3esMdb39VnMxtSYkG1/rZKoL1fDKDrE1t7UO8SYT9FNTa zzhImZ8IJKsWOO07Swnp4aGKLbG4/hFOn4l0VAbUbJTk+9/7h260/jXcvjs/YjncfOleayGphSX onQgk8E4hAoUn3LeA38KTK2N6ORHdB0pVAdNU X-Received: by 2002:a05:6402:26cc:b0:572:57d8:4516 with SMTP id x12-20020a05640226cc00b0057257d84516mr55281edd.2.1714121751704; Fri, 26 Apr 2024 01:55:51 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240426164730214uXfxoyj3x703nsAdqnGSr@zte.com.cn> In-Reply-To: <20240426164730214uXfxoyj3x703nsAdqnGSr@zte.com.cn> From: Eric Dumazet Date: Fri, 26 Apr 2024 10:55:40 +0200 Message-ID: Subject: Re: [PATCH net-next v7] net/ipv4: add tracepoint for icmp_send To: xu.xin16@zte.com.cn Cc: horms@kernel.org, davem@davemloft.net, rostedt@goodmis.org, mhiramat@kernel.org, dsahern@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, yang.yang29@zte.com.cn, he.peilin@zte.com.cn, liu.chun2@zte.com.cn, jiang.xuexin@zte.com.cn, zhang.yunkai@zte.com.cn, kerneljasonxing@gmail.com, fan.yu9@zte.com.cn, qiu.yutan@zte.com.cn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 26, 2024 at 10:47=E2=80=AFAM wrote: > > From: Peilin He > > Introduce a tracepoint for icmp_send, which can help users to get more > detail information conveniently when icmp abnormal events happen. > > 1. Giving an usecase example: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > When an application experiences packet loss due to an unreachable UDP > destination port, the kernel will send an exception message through the > icmp_send function. By adding a trace point for icmp_send, developers or > system administrators can obtain detailed information about the UDP > packet loss, including the type, code, source address, destination addres= s, > source port, and destination port. This facilitates the trouble-shooting > of UDP packet loss issues especially for those network-service > applications. > > 2. Operation Instructions: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D > Switch to the tracing directory. > cd /sys/kernel/tracing > Filter for destination port unreachable. > echo "type=3D=3D3 && code=3D=3D3" > events/icmp/icmp_send/filter > Enable trace event. > echo 1 > events/icmp/icmp_send/enable > > 3. Result View: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > udp_client_erro-11370 [002] ...s.12 124.728002: > icmp_send: icmp_send: type=3D3, code=3D3. > From 127.0.0.1:41895 to 127.0.0.1:6666 ulen=3D23 > skbaddr=3D00000000589b167a > > Change log: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > v6->v7: > Some fixes according to > https://lore.kernel.org/all/20240425081210.720a4cd9@kernel.org/ > 1. Fix patch format issues. > > v5->v6: > Some fixes according to > https://lore.kernel.org/all/20240413161319.GA853376@kernel.org/ > 1.Resubmit patches based on the latest net-next code. > > v4->v5: > Some fixes according to > https://lore.kernel.org/all/CAL+tcoDeXXh+zcRk4PHnUk8ELnx=3DCE2pc > Cqs7sFm0y9aK-Eehg@mail.gmail.com/ > 1.Adjust the position of trace_icmp_send() to before icmp_push_reply(). > > v3->v4: > Some fixes according to > https://lore.kernel.org/all/CANn89i+EFEr7VHXNdOi59Ba_R1nFKSBJz > BzkJFVgCTdXBx=3DYBg@mail.gmail.com/ > 1.Add legality check for UDP header in SKB. > 2.Target this patch for net-next. > > v2->v3: > Some fixes according to > https://lore.kernel.org/all/20240319102549.7f7f6f53@gandalf.local.home/ > 1. Change the tracking directory to/sys/kernel/tracking. > 2. Adjust the layout of the TP-STRUCT_entry parameter structure. > > v1->v2: > Some fixes according to > https://lore.kernel.org/all/CANn89iL-y9e_VFpdw=3DsZtRnKRu_tnUwqHu > FQTJvJsv-nz1xPDw@mail.gmail.com/ > 1. adjust the trace_icmp_send() to more protocols than UDP. > 2. move the calling of trace_icmp_send after sanity checks > in __icmp_send(). > > Signed-off-by: Peilin He > Signed-off-by: xu xin > Reviewed-by: Yunkai Zhang > Cc: Yang Yang > Cc: Liu Chun > Cc: Xuexin Jiang > --- > include/trace/events/icmp.h | 68 +++++++++++++++++++++++++++++++++++++ > net/ipv4/icmp.c | 4 +++ > 2 files changed, 72 insertions(+) > create mode 100644 include/trace/events/icmp.h > > diff --git a/include/trace/events/icmp.h b/include/trace/events/icmp.h > new file mode 100644 > index 000000000000..cff33aaee44e > --- /dev/null > +++ b/include/trace/events/icmp.h > @@ -0,0 +1,68 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#undef TRACE_SYSTEM > +#define TRACE_SYSTEM icmp > + > +#if !defined(_TRACE_ICMP_H) || defined(TRACE_HEADER_MULTI_READ) > +#define _TRACE_ICMP_H > + > +#include > +#include > + > +TRACE_EVENT(icmp_send, > + > + TP_PROTO(const struct sk_buff *skb, int type, int code), > + > + TP_ARGS(skb, type, code), > + > + TP_STRUCT__entry( > + __field(const void *, skbaddr) > + __field(int, type) > + __field(int, code) > + __array(__u8, saddr, 4) > + __array(__u8, daddr, 4) > + __field(__u16, sport) > + __field(__u16, dport) > + __field(unsigned short, ulen) > + ), > + > + TP_fast_assign( > + struct iphdr *iph =3D ip_hdr(skb); > + int proto_4 =3D iph->protocol; > + __be32 *p32; > + > + __entry->skbaddr =3D skb; > + __entry->type =3D type; > + __entry->code =3D code; > + > + struct udphdr *uh =3D udp_hdr(skb); Please move this line up., perhaps after the "struct iphdr *iph =3D ip_hdr(skb);" one We group all variable definitions together, we do not mix code and variable= s. > + > + if (proto_4 !=3D IPPROTO_UDP || (u8 *)uh < skb->h= ead || > + (u8 *)uh + sizeof(struct udphdr) > + > skb_tail_pointer(skb)) { > + __entry->sport =3D 0; > + __entry->dport =3D 0; > + __entry->ulen =3D 0; > + } else { > + __entry->sport =3D ntohs(uh->source); > + __entry->dport =3D ntohs(uh->dest); > + __entry->ulen =3D ntohs(uh->len); > + } > +