* [PATCH] inet: ping: Fix icmp out counting
@ 2025-12-24 6:31 yuan.gao
2025-12-24 16:08 ` Ido Schimmel
0 siblings, 1 reply; 3+ messages in thread
From: yuan.gao @ 2025-12-24 6:31 UTC (permalink / raw)
To: davem, dsahern, edumazet, kuba, pabeni, horms, segoon; +Cc: netdev, yuan.gao
From: "yuan.gao" <yuan.gao@ucloud.cn>
When the ping program uses an IPPROTO_ICMP socket to send ICMP_ECHO
messages, ICMP_MIB_OUTMSGS is counted twice.
ping_v4_sendmsg
ping_v4_push_pending_frames
ip_push_pending_frames
ip_finish_skb
__ip_make_skb
icmp_out_count(net, icmp_type); // first count
icmp_out_count(sock_net(sk), user_icmph.type); // second count
However, when the ping program uses an IPPROTO_RAW socket,
ICMP_MIB_OUTMSGS is counted correctly only once.
Therefore, the first count should be removed.
Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind")
Signed-off-by: yuan.gao <yuan.gao@ucloud.cn>
---
net/ipv4/ping.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 4cb0c896c..c662d6821 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -833,10 +833,8 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
out_free:
if (free)
kfree(ipc.opt);
- if (!err) {
- icmp_out_count(sock_net(sk), user_icmph.type);
+ if (!err)
return len;
- }
return err;
do_confirm:
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] inet: ping: Fix icmp out counting
2025-12-24 6:31 [PATCH] inet: ping: Fix icmp out counting yuan.gao
@ 2025-12-24 16:08 ` Ido Schimmel
2025-12-25 6:39 ` yuan.gao
0 siblings, 1 reply; 3+ messages in thread
From: Ido Schimmel @ 2025-12-24 16:08 UTC (permalink / raw)
To: yuan.gao; +Cc: davem, dsahern, edumazet, kuba, pabeni, horms, segoon, netdev
Next time, please tag the patch as [PATCH net]. See:
https://docs.kernel.org/process/maintainer-netdev.html
On Wed, Dec 24, 2025 at 02:31:45PM +0800, yuan.gao@ucloud.cn wrote:
> From: "yuan.gao" <yuan.gao@ucloud.cn>
>
> When the ping program uses an IPPROTO_ICMP socket to send ICMP_ECHO
> messages, ICMP_MIB_OUTMSGS is counted twice.
>
> ping_v4_sendmsg
> ping_v4_push_pending_frames
> ip_push_pending_frames
> ip_finish_skb
> __ip_make_skb
> icmp_out_count(net, icmp_type); // first count
> icmp_out_count(sock_net(sk), user_icmph.type); // second count
>
> However, when the ping program uses an IPPROTO_RAW socket,
> ICMP_MIB_OUTMSGS is counted correctly only once.
>
> Therefore, the first count should be removed.
Looks correct.
Before:
# sysctl -wq net.ipv4.ping_group_range="0 4294967294"
# nstat -z -j | jq '.[]["IcmpOutEchos"]'
0
# ping -c1 127.0.0.1 &> /dev/null
# nstat -z -j | jq '.[]["IcmpOutEchos"]'
2
After:
# sysctl -wq net.ipv4.ping_group_range="0 4294967294"
# nstat -z -j | jq '.[]["IcmpOutEchos"]'
0
# ping -c1 127.0.0.1 &> /dev/null
# nstat -z -j | jq '.[]["IcmpOutEchos"]'
1
And it's consistent with IPv6:
# sysctl -wq net.ipv4.ping_group_range="0 4294967294"
# nstat -z -j | jq '.[]["Icmp6OutEchos"]'
0
# ping -c1 ::1 &> /dev/null
# nstat -z -j | jq '.[]["Icmp6OutEchos"]'
1
>
> Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind")
> Signed-off-by: yuan.gao <yuan.gao@ucloud.cn>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] inet: ping: Fix icmp out counting
2025-12-24 16:08 ` Ido Schimmel
@ 2025-12-25 6:39 ` yuan.gao
0 siblings, 0 replies; 3+ messages in thread
From: yuan.gao @ 2025-12-25 6:39 UTC (permalink / raw)
To: Ido Schimmel
Cc: davem, dsahern, edumazet, kuba, pabeni, horms, segoon, netdev
On Wed, Dec 24, 2025 at 06:08:47PM +0200, Ido Schimmel wrote:
> Next time, please tag the patch as [PATCH net]. See:
>
> https://docs.kernel.org/process/maintainer-netdev.html
>
> On Wed, Dec 24, 2025 at 02:31:45PM +0800, yuan.gao@ucloud.cn wrote:
> > From: "yuan.gao" <yuan.gao@ucloud.cn>
> >
> > When the ping program uses an IPPROTO_ICMP socket to send ICMP_ECHO
> > messages, ICMP_MIB_OUTMSGS is counted twice.
> >
> > ping_v4_sendmsg
> > ping_v4_push_pending_frames
> > ip_push_pending_frames
> > ip_finish_skb
> > __ip_make_skb
> > icmp_out_count(net, icmp_type); // first count
> > icmp_out_count(sock_net(sk), user_icmph.type); // second count
> >
> > However, when the ping program uses an IPPROTO_RAW socket,
> > ICMP_MIB_OUTMSGS is counted correctly only once.
> >
> > Therefore, the first count should be removed.
>
> Looks correct.
>
> Before:
>
> # sysctl -wq net.ipv4.ping_group_range="0 4294967294"
> # nstat -z -j | jq '.[]["IcmpOutEchos"]'
> 0
> # ping -c1 127.0.0.1 &> /dev/null
> # nstat -z -j | jq '.[]["IcmpOutEchos"]'
> 2
>
> After:
>
> # sysctl -wq net.ipv4.ping_group_range="0 4294967294"
> # nstat -z -j | jq '.[]["IcmpOutEchos"]'
> 0
> # ping -c1 127.0.0.1 &> /dev/null
> # nstat -z -j | jq '.[]["IcmpOutEchos"]'
> 1
>
> And it's consistent with IPv6:
>
> # sysctl -wq net.ipv4.ping_group_range="0 4294967294"
> # nstat -z -j | jq '.[]["Icmp6OutEchos"]'
> 0
> # ping -c1 ::1 &> /dev/null
> # nstat -z -j | jq '.[]["Icmp6OutEchos"]'
> 1
>
> >
> > Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind")
> > Signed-off-by: yuan.gao <yuan.gao@ucloud.cn>
>
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>
> Tested-by: Ido Schimmel <idosch@nvidia.com>
Thanks for the reminder!
Cheers,
Yuan Gao
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-25 6:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-24 6:31 [PATCH] inet: ping: Fix icmp out counting yuan.gao
2025-12-24 16:08 ` Ido Schimmel
2025-12-25 6:39 ` yuan.gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).