Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp141202lqg; Wed, 10 Apr 2024 19:34:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhuS5d8UQwU1y23fst27OroY0JxyDXjtQQ85iFKDDFTeuN9kyaUkaRootFgwICtR4PlJu7v0XHPLzDuxWYdcykmdlYRGlk+slctUolIw== X-Google-Smtp-Source: AGHT+IFrPSNAui6qEWDSxv5gnQFRWZoDe9cQSxFR1DfD4QYIoFB5roQ39yaASTQcAUGNIIqaSLU0 X-Received: by 2002:a05:6808:20a3:b0:3c5:f831:5f33 with SMTP id s35-20020a05680820a300b003c5f8315f33mr5228691oiw.16.1712802855171; Wed, 10 Apr 2024 19:34:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712802855; cv=pass; d=google.com; s=arc-20160816; b=si3Q29r9c6+kk5t6OAGHkkLdaqBQNinDuoVvxDhHuwr4n1zBP5HYX++YJWaDaHkbFd ZGVjC8OIjPNg9XdEWtojxKlBsjfgXT/oNU9hl84cTLahdI1D6rtTVXCcexc9N5FHO2VN 5UdS5z219gfYKdSVGMrA/YoLTSCcNzlIyOJWrw6yhlNt/vmvkCN6h3eCzfikkd/X9yxt 6+qar3tO0e9/uAluCgXyYaZMw98KOhit/QSHh1DycTv8QjHFyQ12lWFOLEFx+5ol2Mai B4w0ggfHBmtFZXYolIvTZ/KGVFKd4yjlFF/UelabggSwMASDih1YQUKLir8wU33f0sAQ MU4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=166/9c+ZR3QEyTBHtTV+6dvgcOnbYCqdPwSXzWFrUQI=; fh=w951Qo59NxQgCP9XF/127xOy0up0+Bk2DkwLLkWteeQ=; b=Q9QzYEPlpiLInpTfRjzEWwbJB0qscgqN26Wxyrzb2kCj0bKr7wWZcgMc0QIr7ID8+Q so9TNZWy8i3ZmdHugBfm85vcuDx36rJN8PxByplRmUcwXRynZMA4K4LjxfBSW5QhbC8p Un/kFNCs40j8ul7jJGdWGb/6zq+pb/GE+LkQyI1YYTHbzs9nZSK3EPrxBfQJVSqt1Ixa Xg/nJ1jScbugPHcQcj9VLSEz4SiqsnNJnC6l2lZ99BekCnrOzyNKyb59kBmm+wAFkmm0 +vwCJnXHCP4q4jg1WwU6hY4Qw6TvJjGKGv3veUYvlR6UF9u+24KxeDCBYjH4NHgA/prM CTmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=OpaP7yaP; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-139655-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139655-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o19-20020ac87c53000000b00432b6a633f4si576739qtv.321.2024.04.10.19.34.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 19:34:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139655-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=OpaP7yaP; arc=pass (i=1 spf=pass spfdomain=163.com dkim=pass dkdomain=163.com dmarc=pass fromdomain=163.com); spf=pass (google.com: domain of linux-kernel+bounces-139655-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139655-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8C4561C227E0 for ; Thu, 11 Apr 2024 02:34:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E708413B296; Thu, 11 Apr 2024 02:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="OpaP7yaP" Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6377353E22; Thu, 11 Apr 2024 02:33:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712802842; cv=none; b=kKZEEvXVZH0fPc+rS1tk8mQ4OzS0mMzgaUbblb3babq8A03ejJ1wK2wT+Of3xs6+UCKtHEM2mfCqOPZiDVAoOC902pwDbLqy61BlZTc3kY4Ej/IffY6RcXGNvceIeBj7xoL1qDxmEpTTFuI8+GsnVef25LEA2AxV4uNf+vQxO7k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712802842; c=relaxed/simple; bh=lNif+lKEoqBkvswjoiZ8yhsUzffxXtJV4yw8YqoSU7c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SlLNDCxIgLtK7wcvjh1JBKz8F0m3nbq41k5NHjPmKFF76i8dLhAa+HE3zZonw2Qs/q8Xl/tA07IupKxdhNRoksv7rDe0Y+e9djMlrygeuXU/GlkPlCRAKFoYSRx1WVINYnsJaxU0Dm6poHytH9+ZjZOB8rrAEB24eo3cv+nsl1I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=OpaP7yaP; arc=none smtp.client-ip=220.197.31.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=166/9 c+ZR3QEyTBHtTV+6dvgcOnbYCqdPwSXzWFrUQI=; b=OpaP7yaPtYlKaj1rmHB+G MfR1LCHY/JT13BB3Jg6V8d5/rYUlQWoCl1My9tXQLDAZwX3lyw2ON95+bEu725pQ jsPtevyiS1HIiuwncSuPXEvKoTRWcJn1wm+TreFIgalLGzG6tT8x15RMBsrwhdxF rZEI65drrvUvuXnt6/Swj8= Received: from localhost.localdomain (unknown [193.203.214.57]) by gzga-smtp-mta-g3-3 (Coremail) with SMTP id _____wD3P67sSxdmgI5MAA--.7719S2; Thu, 11 Apr 2024 10:33:18 +0800 (CST) From: Peilin He To: kerneljasonxing@gmail.com Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com, fan.yu9@zte.com.cn, he.peilin@zte.com.cn, jiang.xuexin@zte.com.cn, kuba@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, liu.chun2@zte.com.cn, mhiramat@kernel.org, netdev@vger.kernel.org, peilinhe2020@163.com, qiu.yutan@zte.com.cn, rostedt@goodmis.org, xu.xin16@zte.com.cn, yang.yang29@zte.com.cn, zhang.yunkai@zte.com.cn Subject: Re: Re: Re: Subject: [PATCH net-next v4] net/ipv4: add tracepoint for icmp_send Date: Thu, 11 Apr 2024 02:33:16 +0000 Message-Id: <20240411023316.137800-1-peilinhe2020@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wD3P67sSxdmgI5MAA--.7719S2 X-Coremail-Antispam: 1Uf129KBjvJXoW3ArWUXFWruFy5Kw48WFyxGrg_yoWxXrykpF yjyFnYkr4DJr47CryI93ySqFnav3y8Wryjgr17Ww1akw1qqr17JFZ2qr1YkrykArs8Krya vF1jy343Ca45ZrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRFtCwUUUUU= X-CM-SenderInfo: xshlzxhqkhjiisq6il2tof0z/1tbiZRS9sWXAlFS6fgAAsc >[...] >> >I think my understanding based on what Eric depicted differs from you: >> >we're supposed to filter out those many invalid cases and only trace >> >the valid action of sending a icmp, so where to add a new tracepoint >> >is important instead of adding more checks in the tracepoint itself. >> >Please refer to what trace_tcp_retransmit_skb() does :) >> > >> >Thanks, >> >Jason >> Okay, thank you for your suggestion. In order to avoid filtering out >> those many invalid cases and only tracing the valid action of sending >> a icmp, the next patch will add udd_fail_no_port trancepoint to the >> include/trace/events/udp.h. This will solve the problem you mentioned >> very well. At this point, only UDP protocol exceptions will be tracked, >> without the need to track them in icmp_send. > >I'm not against what you did (tracing all the icmp_send() for UDP) in >your original patch. I was suggesting that you could put >trace_icmp_send() in the right place, then you don't have to check the >possible error condition (like if the skb->head is valid or not, ...) >in your trace function. > >One example that can avoid various checks existing in the >__icmp_send() function: >diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c >index e63a3bf99617..2c9f7364de45 100644 >--- a/net/ipv4/icmp.c >+++ b/net/ipv4/icmp.c >@@ -767,6 +767,7 @@ void __icmp_send(struct sk_buff *skb_in, int type, >int code, __be32 info, > if (!fl4.saddr) > fl4.saddr = htonl(INADDR_DUMMY); > >+ trace_icmp_send(skb_in, type, code); > icmp_push_reply(sk, &icmp_param, &fl4, &ipc, &rt); > ende: > ip_rt_put(rt); > >If we go here, it means we are ready to send the ICMP skb because >we're done extracting the right information in the 'struct sk_buff >skb_in'. Simpler and easier, right? > >Thanks, >Jason I may not fully agree with this viewpoint. When trace_icmp_send is placed in this position, it cannot guarantee that all skbs in icmp are UDP protocols (UDP needs to be distinguished based on the proto_4!=IPPROTO_UDP condition), nor can it guarantee the legitimacy of udphdr (*uh legitimacy check is required). With best wishes Peilin He >> >> >> 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_tnUwqHuFQTJvJsv= >> >-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 >> >> Reviewed-by: xu xin >> >> Reviewed-by: Yunkai Zhang >> >> Cc: Yang Yang >> >> Cc: Liu Chun >> >> Cc: Xuexin Jiang >> >> --- >> >> include/trace/events/icmp.h | 65 +++++++++++++++++++++++++++++++++++++ >> >> net/ipv4/icmp.c | 4 +++ >> >> 2 files changed, 69 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..7d5190f48a28 >> >> --- /dev/null >> >> +++ b/include/trace/events/icmp.h >> >> @@ -0,0 +1,65 @@ >> >> +/* 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); >> >> + if (proto_4 !=3D IPPROTO_UDP || (u8 *)uh < skb->h= >> >ead || >> >> + (u8 *)uh + sizeof(struct udphdr) > skb_ta= >> >il_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); >> >> + } >> >> + >> >> + p32 =3D (__be32 *) __entry->saddr; >> >> + *p32 =3D iph->saddr; >> >> + >> >> + p32 =3D (__be32 *) __entry->daddr; >> >> + *p32 =3D iph->daddr; >> >> + ), >> >> + >> >> + TP_printk("icmp_send: type=3D%d, code=3D%d. From %pI4:%u = >> >to %pI4:%u ulen=3D%d skbaddr=3D%p", >> >> + __entry->type, __entry->code, >> >> + __entry->saddr, __entry->sport, __entry->daddr, >> >> + __entry->dport, __entry->ulen, __entry->skbaddr) >> >> +); >> >> + >> >> +#endif /* _TRACE_ICMP_H */ >> >> + >> >> +/* This part must be outside protection */ >> >> +#include >> >> \ No newline at end of file >> >> diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c >> >> index 8cebb476b3ab..224551d75c02 100644 >> >> --- a/net/ipv4/icmp.c >> >> +++ b/net/ipv4/icmp.c >> >> @@ -92,6 +92,8 @@ >> >> #include >> >> #include >> >> #include >> >> +#define CREATE_TRACE_POINTS >> >> +#include >> >> >> >> /* >> >> * Build xmit assembly blocks >> >> @@ -672,6 +674,8 @@ void __icmp_send(struct sk_buff *skb_in, int type, in= >> >t code, __be32 info, >> >> } >> >> } >> >> >> >> + trace_icmp_send(skb_in, type, code); >> >> + >> >> /* Needed by both icmp_global_allow and icmp_xmit_lock */ >> >> local_bh_disable(); >> >> >> >> -- >> >> 2.25.1