Skip to content

Commit b4a11b2

Browse files
hguo3davem330
authored andcommitted
net: fix IPSTATS_MIB_OUTPKGS increment in OutForwDatagrams.
Reproduce environment: network with 3 VM linuxs is connected as below: VM1<---->VM2(latest kernel 6.5.0-rc7)<---->VM3 VM1: eth0 ip: 192.168.122.207 MTU 1500 VM2: eth0 ip: 192.168.122.208, eth1 ip: 192.168.123.224 MTU 1500 VM3: eth0 ip: 192.168.123.240 MTU 1500 Reproduce: VM1 send 1400 bytes UDP data to VM3 using tools scapy with flags=0. scapy command: send(IP(dst="192.168.123.240",flags=0)/UDP()/str('0'*1400),count=1, inter=1.000000) Result: Before IP data is sent. ---------------------------------------------------------------------- root@qemux86-64:~# cat /proc/net/snmp Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates Ip: 1 64 11 0 3 4 0 0 4 7 0 0 0 0 0 0 0 0 0 ...... ---------------------------------------------------------------------- After IP data is sent. ---------------------------------------------------------------------- root@qemux86-64:~# cat /proc/net/snmp Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates Ip: 1 64 12 0 3 5 0 0 4 8 0 0 0 0 0 0 0 0 0 ...... ---------------------------------------------------------------------- "ForwDatagrams" increase from 4 to 5 and "OutRequests" also increase from 7 to 8. Issue description and patch: IPSTATS_MIB_OUTPKTS("OutRequests") is counted with IPSTATS_MIB_OUTOCTETS ("OutOctets") in ip_finish_output2(). According to RFC 4293, it is "OutOctets" counted with "OutTransmits" but not "OutRequests". "OutRequests" does not include any datagrams counted in "ForwDatagrams". ipSystemStatsOutOctets OBJECT-TYPE DESCRIPTION "The total number of octets in IP datagrams delivered to the lower layers for transmission. Octets from datagrams counted in ipIfStatsOutTransmits MUST be counted here. ipSystemStatsOutRequests OBJECT-TYPE DESCRIPTION "The total number of IP datagrams that local IP user- protocols (including ICMP) supplied to IP in requests for transmission. Note that this counter does not include any datagrams counted in ipSystemStatsOutForwDatagrams. So do patch to define IPSTATS_MIB_OUTPKTS to "OutTransmits" and add IPSTATS_MIB_OUTREQUESTS for "OutRequests". Add IPSTATS_MIB_OUTREQUESTS counter in __ip_local_out() for ipv4 and add IPSTATS_MIB_OUT counter in ip6_finish_output2() for ipv6. Test result with patch: Before IP data is sent. ---------------------------------------------------------------------- root@qemux86-64:~# cat /proc/net/snmp Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates OutTransmits Ip: 1 64 9 0 5 1 0 0 3 3 0 0 0 0 0 0 0 0 0 4 ...... root@qemux86-64:~# cat /proc/net/netstat ...... IpExt: InNoRoutes InTruncatedPkts InMcastPkts OutMcastPkts InBcastPkts OutBcastPkts InOctets OutOctets InMcastOctets OutMcastOctets InBcastOctets OutBcastOctets InCsumErrors InNoECTPkts InECT1Pkts InECT0Pkts InCEPkts ReasmOverlaps IpExt: 0 0 0 0 0 0 2976 1896 0 0 0 0 0 9 0 0 0 0 ---------------------------------------------------------------------- After IP data is sent. ---------------------------------------------------------------------- root@qemux86-64:~# cat /proc/net/snmp Ip: Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs ReasmFails FragOKs FragFails FragCreates OutTransmits Ip: 1 64 10 0 5 2 0 0 3 3 0 0 0 0 0 0 0 0 0 5 ...... root@qemux86-64:~# cat /proc/net/netstat ...... IpExt: InNoRoutes InTruncatedPkts InMcastPkts OutMcastPkts InBcastPkts OutBcastPkts InOctets OutOctets InMcastOctets OutMcastOctets InBcastOctets OutBcastOctets InCsumErrors InNoECTPkts InECT1Pkts InECT0Pkts InCEPkts ReasmOverlaps IpExt: 0 0 0 0 0 0 4404 3324 0 0 0 0 0 10 0 0 0 0 ---------------------------------------------------------------------- "ForwDatagrams" increase from 1 to 2 and "OutRequests" is keeping 3. "OutTransmits" increase from 4 to 5 and "OutOctets" increase 1428. Signed-off-by: Heng Guo <[email protected]> Reviewed-by: Kun Song <[email protected]> Reviewed-by: Filip Pudak <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 095c3ea commit b4a11b2

File tree

8 files changed

+16
-10
lines changed

8 files changed

+16
-10
lines changed

include/uapi/linux/snmp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ enum
2424
IPSTATS_MIB_INOCTETS, /* InOctets */
2525
IPSTATS_MIB_INDELIVERS, /* InDelivers */
2626
IPSTATS_MIB_OUTFORWDATAGRAMS, /* OutForwDatagrams */
27-
IPSTATS_MIB_OUTPKTS, /* OutRequests */
27+
IPSTATS_MIB_OUTREQUESTS, /* OutRequests */
2828
IPSTATS_MIB_OUTOCTETS, /* OutOctets */
2929
/* other fields */
3030
IPSTATS_MIB_INHDRERRORS, /* InHdrErrors */
@@ -57,6 +57,7 @@ enum
5757
IPSTATS_MIB_ECT0PKTS, /* InECT0Pkts */
5858
IPSTATS_MIB_CEPKTS, /* InCEPkts */
5959
IPSTATS_MIB_REASM_OVERLAPS, /* ReasmOverlaps */
60+
IPSTATS_MIB_OUTPKTS, /* OutTransmits */
6061
__IPSTATS_MIB_MAX
6162
};
6263

net/ipv4/ip_output.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ int __ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb)
101101
{
102102
struct iphdr *iph = ip_hdr(skb);
103103

104+
IP_INC_STATS(net, IPSTATS_MIB_OUTREQUESTS);
105+
104106
iph_set_totlen(iph, skb->len);
105107
ip_send_check(iph);
106108

net/ipv4/proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static const struct snmp_mib snmp4_ipstats_list[] = {
8383
SNMP_MIB_ITEM("InUnknownProtos", IPSTATS_MIB_INUNKNOWNPROTOS),
8484
SNMP_MIB_ITEM("InDiscards", IPSTATS_MIB_INDISCARDS),
8585
SNMP_MIB_ITEM("InDelivers", IPSTATS_MIB_INDELIVERS),
86-
SNMP_MIB_ITEM("OutRequests", IPSTATS_MIB_OUTPKTS),
86+
SNMP_MIB_ITEM("OutRequests", IPSTATS_MIB_OUTREQUESTS),
8787
SNMP_MIB_ITEM("OutDiscards", IPSTATS_MIB_OUTDISCARDS),
8888
SNMP_MIB_ITEM("OutNoRoutes", IPSTATS_MIB_OUTNOROUTES),
8989
SNMP_MIB_ITEM("ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
@@ -93,6 +93,7 @@ static const struct snmp_mib snmp4_ipstats_list[] = {
9393
SNMP_MIB_ITEM("FragOKs", IPSTATS_MIB_FRAGOKS),
9494
SNMP_MIB_ITEM("FragFails", IPSTATS_MIB_FRAGFAILS),
9595
SNMP_MIB_ITEM("FragCreates", IPSTATS_MIB_FRAGCREATES),
96+
SNMP_MIB_ITEM("OutTransmits", IPSTATS_MIB_OUTPKTS),
9697
SNMP_MIB_SENTINEL
9798
};
9899

net/ipv6/ip6_output.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
117117
return res;
118118
}
119119

120+
IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len);
121+
120122
rcu_read_lock();
121123
nexthop = rt6_nexthop((struct rt6_info *)dst, daddr);
122124
neigh = __ipv6_neigh_lookup_noref(dev, nexthop);
@@ -328,7 +330,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
328330

329331
mtu = dst_mtu(dst);
330332
if ((skb->len <= mtu) || skb->ignore_df || skb_is_gso(skb)) {
331-
IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len);
333+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
332334

333335
/* if egress device is enslaved to an L3 master device pass the
334336
* skb to its handler for processing
@@ -1987,7 +1989,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk,
19871989
skb->tstamp = cork->base.transmit_time;
19881990

19891991
ip6_cork_steal_dst(skb, cork);
1990-
IP6_UPD_PO_STATS(net, rt->rt6i_idev, IPSTATS_MIB_OUT, skb->len);
1992+
IP6_INC_STATS(net, rt->rt6i_idev, IPSTATS_MIB_OUTREQUESTS);
19911993
if (proto == IPPROTO_ICMPV6) {
19921994
struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
19931995
u8 icmp6_type;

net/ipv6/mcast.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ static void mld_sendpack(struct sk_buff *skb)
17891789

17901790
rcu_read_lock();
17911791
idev = __in6_dev_get(skb->dev);
1792-
IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len);
1792+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
17931793

17941794
payload_len = (skb_tail_pointer(skb) - skb_network_header(skb)) -
17951795
sizeof(*pip6);
@@ -2147,8 +2147,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
21472147
full_len = sizeof(struct ipv6hdr) + payload_len;
21482148

21492149
rcu_read_lock();
2150-
IP6_UPD_PO_STATS(net, __in6_dev_get(dev),
2151-
IPSTATS_MIB_OUT, full_len);
2150+
IP6_INC_STATS(net, __in6_dev_get(dev), IPSTATS_MIB_OUTREQUESTS);
21522151
rcu_read_unlock();
21532152

21542153
skb = sock_alloc_send_skb(sk, hlen + tlen + full_len, 1, &err);

net/ipv6/ndisc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,
504504

505505
rcu_read_lock();
506506
idev = __in6_dev_get(dst->dev);
507-
IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len);
507+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
508508

509509
err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT,
510510
net, sk, skb, NULL, dst->dev,

net/ipv6/proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static const struct snmp_mib snmp6_ipstats_list[] = {
6161
SNMP_MIB_ITEM("Ip6InDiscards", IPSTATS_MIB_INDISCARDS),
6262
SNMP_MIB_ITEM("Ip6InDelivers", IPSTATS_MIB_INDELIVERS),
6363
SNMP_MIB_ITEM("Ip6OutForwDatagrams", IPSTATS_MIB_OUTFORWDATAGRAMS),
64-
SNMP_MIB_ITEM("Ip6OutRequests", IPSTATS_MIB_OUTPKTS),
64+
SNMP_MIB_ITEM("Ip6OutRequests", IPSTATS_MIB_OUTREQUESTS),
6565
SNMP_MIB_ITEM("Ip6OutDiscards", IPSTATS_MIB_OUTDISCARDS),
6666
SNMP_MIB_ITEM("Ip6OutNoRoutes", IPSTATS_MIB_OUTNOROUTES),
6767
SNMP_MIB_ITEM("Ip6ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
@@ -84,6 +84,7 @@ static const struct snmp_mib snmp6_ipstats_list[] = {
8484
SNMP_MIB_ITEM("Ip6InECT1Pkts", IPSTATS_MIB_ECT1PKTS),
8585
SNMP_MIB_ITEM("Ip6InECT0Pkts", IPSTATS_MIB_ECT0PKTS),
8686
SNMP_MIB_ITEM("Ip6InCEPkts", IPSTATS_MIB_CEPKTS),
87+
SNMP_MIB_ITEM("Ip6OutTransmits", IPSTATS_MIB_OUTPKTS),
8788
SNMP_MIB_SENTINEL
8889
};
8990

net/ipv6/raw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
651651
* have been queued for deletion.
652652
*/
653653
rcu_read_lock();
654-
IP6_UPD_PO_STATS(net, rt->rt6i_idev, IPSTATS_MIB_OUT, skb->len);
654+
IP6_INC_STATS(net, rt->rt6i_idev, IPSTATS_MIB_OUTREQUESTS);
655655
err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk, skb,
656656
NULL, rt->dst.dev, dst_output);
657657
if (err > 0)

0 commit comments

Comments
 (0)