net: fix IPSTATS_MIB_OUTPKGS increment in OutForwDatagrams.
Subsystems (3)
PATCH 1/1 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.
--- include/uapi/linux/snmp.h | 3 ++- net/ipv4/ip_output.c | 2 ++ net/ipv4/proc.c | 3 ++- net/ipv6/ip6_output.c | 6 ++++-- net/ipv6/mcast.c | 5 ++--- net/ipv6/ndisc.c | 2 +- net/ipv6/proc.c | 3 ++- net/ipv6/raw.c | 2 +- net/mpls/af_mpls.c | 6 +++--- 9 files changed, 19 insertions(+), 13 deletions(-)
include/uapi/linux/snmp.h +2 -1
@@ -24,7 +24,7 @@ enumIPSTATS_MIB_INOCTETS ,/* InOctets */ IPSTATS_MIB_INDELIVERS ,/* InDelivers */ IPSTATS_MIB_OUTFORWDATAGRAMS ,/* OutForwDatagrams */ -IPSTATS_MIB_OUTPKTS ,/* OutRequests */ +IPSTATS_MIB_OUTREQUESTS ,/* OutRequests */ IPSTATS_MIB_OUTOCTETS ,/* OutOctets */ /* other fields */ IPSTATS_MIB_INHDRERRORS, /* InHdrErrors */
@@ -57,6 +57,7 @@ enumIPSTATS_MIB_ECT0PKTS ,/* InECT0Pkts */ IPSTATS_MIB_CEPKTS ,/* InCEPkts */ IPSTATS_MIB_REASM_OVERLAPS ,/* ReasmOverlaps */ +IPSTATS_MIB_OUTPKTS ,/* OutTransmits */ __IPSTATS_MIB_MAX };
net/ipv4/ip_output.c +2 -0
@@ -101,6 +101,8 @@ int __ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb) {struct iphdr *iph =ip_hdr (skb); +IP_INC_STATS (net,IPSTATS_MIB_OUTREQUESTS ); +iph_set_totlen (iph, skb->len);ip_send_check (iph);
net/ipv4/proc.c +2 -1
@@ -83,7 +83,7 @@ static const struct snmp_mib snmp4_ipstats_list[] = {SNMP_MIB_ITEM ("InUnknownProtos" ,IPSTATS_MIB_INUNKNOWNPROTOS ),SNMP_MIB_ITEM ("InDiscards" ,IPSTATS_MIB_INDISCARDS ),SNMP_MIB_ITEM ("InDelivers" ,IPSTATS_MIB_INDELIVERS ), -SNMP_MIB_ITEM ("OutRequests" ,IPSTATS_MIB_OUTPKTS ), +SNMP_MIB_ITEM ("OutRequests" ,IPSTATS_MIB_OUTREQUESTS ),SNMP_MIB_ITEM ("OutDiscards" ,IPSTATS_MIB_OUTDISCARDS ),SNMP_MIB_ITEM ("OutNoRoutes" ,IPSTATS_MIB_OUTNOROUTES ), SNMP_MIB_ITEM("ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
@@ -93,6 +93,7 @@ static const struct snmp_mib snmp4_ipstats_list[] = {SNMP_MIB_ITEM ("FragOKs" ,IPSTATS_MIB_FRAGOKS ),SNMP_MIB_ITEM ("FragFails" ,IPSTATS_MIB_FRAGFAILS ),SNMP_MIB_ITEM ("FragCreates" ,IPSTATS_MIB_FRAGCREATES ), +SNMP_MIB_ITEM ("OutTransmits" ,IPSTATS_MIB_OUTPKTS ), SNMP_MIB_SENTINEL };
net/ipv6/ip6_output.c +4 -2
@@ -117,6 +117,8 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *return res; } +IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +rcu_read_lock (); nexthop =rt6_nexthop ((struct rt6_info *)dst, daddr); neigh =__ipv6_neigh_lookup_noref (dev, nexthop);
@@ -329,7 +331,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, mtu =dst_mtu (dst);if ((skb->len <= mtu) || skb->ignore_df ||skb_is_gso (skb)) { -IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS );/* if egress device is enslaved to an L3 master device pass the * skb to its handler for processing
@@ -1978,7 +1980,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, skb->tstamp = cork->base.transmit_time;ip6_cork_steal_dst (skb, cork); -IP6_UPD_PO_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUTREQUESTS );if (proto ==IPPROTO_ICMPV6 ) {struct inet6_dev *idev =ip6_dst_idev (skb_dst (skb));u8 icmp6_type;
net/ipv6/mcast.c +2 -3
@@ -1791,7 +1791,7 @@ static void mld_sendpack(struct sk_buff *skb)rcu_read_lock (); idev =__in6_dev_get (skb->dev); -IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS ); payload_len = (skb_tail_pointer (skb) -skb_network_header (skb)) -sizeof (*pip6);
@@ -2149,8 +2149,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) full_len =sizeof (struct ipv6hdr ) + payload_len;rcu_read_lock (); -IP6_UPD_PO_STATS (net,__in6_dev_get (dev), -IPSTATS_MIB_OUT , full_len); +IP6_INC_STATS (net,__in6_dev_get (dev),IPSTATS_MIB_OUTREQUESTS );rcu_read_unlock (); skb =sock_alloc_send_skb (sk, hlen + tlen + full_len,1 , &err);
net/ipv6/ndisc.c +1 -1
@@ -504,7 +504,7 @@ void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,rcu_read_lock (); idev =__in6_dev_get (dst->dev); -IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS ); err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk, skb, NULL, dst->dev,
net/ipv6/proc.c +2 -1
@@ -61,7 +61,7 @@ static const struct snmp_mib snmp6_ipstats_list[] = {SNMP_MIB_ITEM ("Ip6InDiscards" ,IPSTATS_MIB_INDISCARDS ),SNMP_MIB_ITEM ("Ip6InDelivers" ,IPSTATS_MIB_INDELIVERS ),SNMP_MIB_ITEM ("Ip6OutForwDatagrams" ,IPSTATS_MIB_OUTFORWDATAGRAMS ), -SNMP_MIB_ITEM ("Ip6OutRequests" ,IPSTATS_MIB_OUTPKTS ), +SNMP_MIB_ITEM ("Ip6OutRequests" ,IPSTATS_MIB_OUTREQUESTS ),SNMP_MIB_ITEM ("Ip6OutDiscards" ,IPSTATS_MIB_OUTDISCARDS ),SNMP_MIB_ITEM ("Ip6OutNoRoutes" ,IPSTATS_MIB_OUTNOROUTES ), SNMP_MIB_ITEM("Ip6ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
@@ -84,6 +84,7 @@ static const struct snmp_mib snmp6_ipstats_list[] = {SNMP_MIB_ITEM ("Ip6InECT1Pkts" ,IPSTATS_MIB_ECT1PKTS ),SNMP_MIB_ITEM ("Ip6InECT0Pkts" ,IPSTATS_MIB_ECT0PKTS ),SNMP_MIB_ITEM ("Ip6InCEPkts" ,IPSTATS_MIB_CEPKTS ), +SNMP_MIB_ITEM ("Ip6OutTransmits" ,IPSTATS_MIB_OUTPKTS ), SNMP_MIB_SENTINEL };
net/ipv6/raw.c +1 -1
@@ -652,7 +652,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,* have been queued for deletion. */ rcu_read_lock (); -IP6_UPD_PO_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUTREQUESTS ); err =NF_HOOK (NFPROTO_IPV6 ,NF_INET_LOCAL_OUT , net, sk, skb,NULL , rt->dst.dev, dst_output);if (err >0 )
net/mpls/af_mpls.c +3 -3
@@ -141,14 +141,14 @@ void mpls_stats_inc_outucastpkts(struct net_device *dev, tx_packets, tx_bytes); }else if (skb->protocol ==htons (ETH_P_IP )) { -IP_UPD_PO_STATS (dev_net (dev),IPSTATS_MIB_OUT , skb->len); +IP_INC_STATS (dev_net (dev),IPSTATS_MIB_OUTREQUESTS );#if IS_ENABLED (CONFIG_IPV6 ) } else if (skb->protocol == htons(ETH_P_IPV6)) {struct inet6_dev *in6dev =__in6_dev_get (dev);if (in6dev) -IP6_UPD_PO_STATS (dev_net (dev), in6dev, -IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (dev_net (dev), in6dev, +IPSTATS_MIB_OUTREQUESTS );#endif } }
Signature · 1 line
2.25.1
Jakub Kicinski
maintainernet/ipv6/mcast.c static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) · line 2152
Quoted 1 line · On Tue, 17 Oct 2023 14:28:38 +0800 Heng Guo wrote:
net/ipv6/mcast.c +1
-0+IP6_INC_STATS (net,__in6_dev_get (dev),IPSTATS_MIB_OUTREQUESTS );
nit: checkpatch points out you're missing a space after a comma here.
Signature · 1 line
pw-bot: cr
PATCH v2 1/1 net: fix IPSTATS_MIB_OUTPKGS increment in OutForwDatagrams.
In reply to Heng GuoReproduce 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.
---
V2: fix the missing space after a comma.
include/uapi/linux/snmp.h | 3 ++- net/ipv4/ip_output.c | 2 ++ net/ipv4/proc.c | 3 ++- net/ipv6/ip6_output.c | 6 ++++-- net/ipv6/mcast.c | 5 ++--- net/ipv6/ndisc.c | 2 +- net/ipv6/proc.c | 3 ++- net/ipv6/raw.c | 2 +- net/mpls/af_mpls.c | 6 +++--- 9 files changed, 19 insertions(+), 13 deletions(-)
include/uapi/linux/snmp.h +2 -1
@@ -24,7 +24,7 @@ enumIPSTATS_MIB_INOCTETS ,/* InOctets */ IPSTATS_MIB_INDELIVERS ,/* InDelivers */ IPSTATS_MIB_OUTFORWDATAGRAMS ,/* OutForwDatagrams */ -IPSTATS_MIB_OUTPKTS ,/* OutRequests */ +IPSTATS_MIB_OUTREQUESTS ,/* OutRequests */ IPSTATS_MIB_OUTOCTETS ,/* OutOctets */ /* other fields */ IPSTATS_MIB_INHDRERRORS, /* InHdrErrors */
@@ -57,6 +57,7 @@ enumIPSTATS_MIB_ECT0PKTS ,/* InECT0Pkts */ IPSTATS_MIB_CEPKTS ,/* InCEPkts */ IPSTATS_MIB_REASM_OVERLAPS ,/* ReasmOverlaps */ +IPSTATS_MIB_OUTPKTS ,/* OutTransmits */ __IPSTATS_MIB_MAX };
net/ipv4/ip_output.c +2 -0
@@ -101,6 +101,8 @@ int __ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb) {struct iphdr *iph =ip_hdr (skb); +IP_INC_STATS (net,IPSTATS_MIB_OUTREQUESTS ); +iph_set_totlen (iph, skb->len);ip_send_check (iph);
net/ipv4/proc.c +2 -1
@@ -83,7 +83,7 @@ static const struct snmp_mib snmp4_ipstats_list[] = {SNMP_MIB_ITEM ("InUnknownProtos" ,IPSTATS_MIB_INUNKNOWNPROTOS ),SNMP_MIB_ITEM ("InDiscards" ,IPSTATS_MIB_INDISCARDS ),SNMP_MIB_ITEM ("InDelivers" ,IPSTATS_MIB_INDELIVERS ), -SNMP_MIB_ITEM ("OutRequests" ,IPSTATS_MIB_OUTPKTS ), +SNMP_MIB_ITEM ("OutRequests" ,IPSTATS_MIB_OUTREQUESTS ),SNMP_MIB_ITEM ("OutDiscards" ,IPSTATS_MIB_OUTDISCARDS ),SNMP_MIB_ITEM ("OutNoRoutes" ,IPSTATS_MIB_OUTNOROUTES ), SNMP_MIB_ITEM("ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
@@ -93,6 +93,7 @@ static const struct snmp_mib snmp4_ipstats_list[] = {SNMP_MIB_ITEM ("FragOKs" ,IPSTATS_MIB_FRAGOKS ),SNMP_MIB_ITEM ("FragFails" ,IPSTATS_MIB_FRAGFAILS ),SNMP_MIB_ITEM ("FragCreates" ,IPSTATS_MIB_FRAGCREATES ), +SNMP_MIB_ITEM ("OutTransmits" ,IPSTATS_MIB_OUTPKTS ), SNMP_MIB_SENTINEL };
net/ipv6/ip6_output.c +4 -2
@@ -117,6 +117,8 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *return res; } +IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +rcu_read_lock (); nexthop =rt6_nexthop ((struct rt6_info *)dst, daddr); neigh =__ipv6_neigh_lookup_noref (dev, nexthop);
@@ -329,7 +331,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, mtu =dst_mtu (dst);if ((skb->len <= mtu) || skb->ignore_df ||skb_is_gso (skb)) { -IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS );/* if egress device is enslaved to an L3 master device pass the * skb to its handler for processing
@@ -1989,7 +1991,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, skb->tstamp = cork->base.transmit_time;ip6_cork_steal_dst (skb, cork); -IP6_UPD_PO_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUTREQUESTS );if (proto ==IPPROTO_ICMPV6 ) {struct inet6_dev *idev =ip6_dst_idev (skb_dst (skb));u8 icmp6_type;
net/ipv6/mcast.c +2 -3
@@ -1789,7 +1789,7 @@ static void mld_sendpack(struct sk_buff *skb)rcu_read_lock (); idev =__in6_dev_get (skb->dev); -IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS ); payload_len = (skb_tail_pointer (skb) -skb_network_header (skb)) -sizeof (*pip6);
@@ -2147,8 +2147,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) full_len =sizeof (struct ipv6hdr ) + payload_len;rcu_read_lock (); -IP6_UPD_PO_STATS (net,__in6_dev_get (dev), -IPSTATS_MIB_OUT , full_len); +IP6_INC_STATS (net,__in6_dev_get (dev),IPSTATS_MIB_OUTREQUESTS );rcu_read_unlock (); skb =sock_alloc_send_skb (sk, hlen + tlen + full_len,1 , &err);
net/ipv6/ndisc.c +1 -1
@@ -504,7 +504,7 @@ void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,rcu_read_lock (); idev =__in6_dev_get (dst->dev); -IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS ); err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk, skb, NULL, dst->dev,
net/ipv6/proc.c +2 -1
@@ -61,7 +61,7 @@ static const struct snmp_mib snmp6_ipstats_list[] = {SNMP_MIB_ITEM ("Ip6InDiscards" ,IPSTATS_MIB_INDISCARDS ),SNMP_MIB_ITEM ("Ip6InDelivers" ,IPSTATS_MIB_INDELIVERS ),SNMP_MIB_ITEM ("Ip6OutForwDatagrams" ,IPSTATS_MIB_OUTFORWDATAGRAMS ), -SNMP_MIB_ITEM ("Ip6OutRequests" ,IPSTATS_MIB_OUTPKTS ), +SNMP_MIB_ITEM ("Ip6OutRequests" ,IPSTATS_MIB_OUTREQUESTS ),SNMP_MIB_ITEM ("Ip6OutDiscards" ,IPSTATS_MIB_OUTDISCARDS ),SNMP_MIB_ITEM ("Ip6OutNoRoutes" ,IPSTATS_MIB_OUTNOROUTES ), SNMP_MIB_ITEM("Ip6ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
@@ -84,6 +84,7 @@ static const struct snmp_mib snmp6_ipstats_list[] = {SNMP_MIB_ITEM ("Ip6InECT1Pkts" ,IPSTATS_MIB_ECT1PKTS ),SNMP_MIB_ITEM ("Ip6InECT0Pkts" ,IPSTATS_MIB_ECT0PKTS ),SNMP_MIB_ITEM ("Ip6InCEPkts" ,IPSTATS_MIB_CEPKTS ), +SNMP_MIB_ITEM ("Ip6OutTransmits" ,IPSTATS_MIB_OUTPKTS ), SNMP_MIB_SENTINEL };
net/ipv6/raw.c +1 -1
@@ -651,7 +651,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,* have been queued for deletion. */ rcu_read_lock (); -IP6_UPD_PO_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUTREQUESTS ); err =NF_HOOK (NFPROTO_IPV6 ,NF_INET_LOCAL_OUT , net, sk, skb,NULL , rt->dst.dev, dst_output);if (err >0 )
net/mpls/af_mpls.c +3 -3
@@ -141,14 +141,14 @@ void mpls_stats_inc_outucastpkts(struct net_device *dev, tx_packets, tx_bytes); }else if (skb->protocol ==htons (ETH_P_IP )) { -IP_UPD_PO_STATS (dev_net (dev),IPSTATS_MIB_OUT , skb->len); +IP_INC_STATS (dev_net (dev),IPSTATS_MIB_OUTREQUESTS );#if IS_ENABLED (CONFIG_IPV6 ) } else if (skb->protocol == htons(ETH_P_IPV6)) {struct inet6_dev *in6dev =__in6_dev_get (dev);if (in6dev) -IP6_UPD_PO_STATS (dev_net (dev), in6dev, -IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (dev_net (dev), in6dev, +IPSTATS_MIB_OUTREQUESTS );#endif } }
Signature · 1 line
2.35.2
David Ahern
maintainerQuoted 12 lines · Heng Guo
net/mpls/af_mpls.c +1
-1@@ -141,14 +141,14 @@ void mpls_stats_inc_outucastpkts(struct net_device *dev, tx_packets, tx_bytes); }else if (skb->protocol ==htons (ETH_P_IP )) { -IP_UPD_PO_STATS (dev_net (dev),IPSTATS_MIB_OUT , skb->len); +IP_INC_STATS (dev_net (dev),IPSTATS_MIB_OUTREQUESTS );#if IS_ENABLED (CONFIG_IPV6 ) } else if (skb->protocol == htons(ETH_P_IPV6)) {
net/mpls/af_mpls.c void mpls_stats_inc_outucastpkts(struct net_device *dev, · line 154
Quoted 10 lines
net/mpls/af_mpls.c +2
-2struct inet6_dev *in6dev =__in6_dev_get (dev);if (in6dev) -IP6_UPD_PO_STATS (dev_net (dev), in6dev, -IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (dev_net (dev), in6dev, +IPSTATS_MIB_OUTREQUESTS );#endif } }
mpls_stats_inc_outucastpkts is called for both forward and local output use cases.
PATCH v3 1/1 net: fix IPSTATS_MIB_OUTPKGS increment in OutForwDatagrams.
In reply to Heng GuoReproduce 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.
---
V2: fix the missing space after a comma.
V3: keep original counter in mpls_stats_inc_outucastpkts(), because both forward and local outputs are in it.
include/uapi/linux/snmp.h | 3 ++- net/ipv4/ip_output.c | 2 ++ net/ipv4/proc.c | 3 ++- net/ipv6/ip6_output.c | 6 ++++-- net/ipv6/mcast.c | 5 ++--- net/ipv6/ndisc.c | 2 +- net/ipv6/proc.c | 3 ++- net/ipv6/raw.c | 2 +- 8 files changed, 16 insertions(+), 10 deletions(-)
include/uapi/linux/snmp.h +2 -1
@@ -24,7 +24,7 @@ enumIPSTATS_MIB_INOCTETS ,/* InOctets */ IPSTATS_MIB_INDELIVERS ,/* InDelivers */ IPSTATS_MIB_OUTFORWDATAGRAMS ,/* OutForwDatagrams */ -IPSTATS_MIB_OUTPKTS ,/* OutRequests */ +IPSTATS_MIB_OUTREQUESTS ,/* OutRequests */ IPSTATS_MIB_OUTOCTETS ,/* OutOctets */ /* other fields */ IPSTATS_MIB_INHDRERRORS, /* InHdrErrors */
@@ -57,6 +57,7 @@ enumIPSTATS_MIB_ECT0PKTS ,/* InECT0Pkts */ IPSTATS_MIB_CEPKTS ,/* InCEPkts */ IPSTATS_MIB_REASM_OVERLAPS ,/* ReasmOverlaps */ +IPSTATS_MIB_OUTPKTS ,/* OutTransmits */ __IPSTATS_MIB_MAX };
net/ipv4/ip_output.c +2 -0
@@ -101,6 +101,8 @@ int __ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb) {struct iphdr *iph =ip_hdr (skb); +IP_INC_STATS (net,IPSTATS_MIB_OUTREQUESTS ); +iph_set_totlen (iph, skb->len);ip_send_check (iph);
net/ipv4/proc.c +2 -1
@@ -83,7 +83,7 @@ static const struct snmp_mib snmp4_ipstats_list[] = {SNMP_MIB_ITEM ("InUnknownProtos" ,IPSTATS_MIB_INUNKNOWNPROTOS ),SNMP_MIB_ITEM ("InDiscards" ,IPSTATS_MIB_INDISCARDS ),SNMP_MIB_ITEM ("InDelivers" ,IPSTATS_MIB_INDELIVERS ), -SNMP_MIB_ITEM ("OutRequests" ,IPSTATS_MIB_OUTPKTS ), +SNMP_MIB_ITEM ("OutRequests" ,IPSTATS_MIB_OUTREQUESTS ),SNMP_MIB_ITEM ("OutDiscards" ,IPSTATS_MIB_OUTDISCARDS ),SNMP_MIB_ITEM ("OutNoRoutes" ,IPSTATS_MIB_OUTNOROUTES ), SNMP_MIB_ITEM("ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
@@ -93,6 +93,7 @@ static const struct snmp_mib snmp4_ipstats_list[] = {SNMP_MIB_ITEM ("FragOKs" ,IPSTATS_MIB_FRAGOKS ),SNMP_MIB_ITEM ("FragFails" ,IPSTATS_MIB_FRAGFAILS ),SNMP_MIB_ITEM ("FragCreates" ,IPSTATS_MIB_FRAGCREATES ), +SNMP_MIB_ITEM ("OutTransmits" ,IPSTATS_MIB_OUTPKTS ), SNMP_MIB_SENTINEL };
net/ipv6/ip6_output.c +4 -2
@@ -117,6 +117,8 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *return res; } +IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +rcu_read_lock (); nexthop =rt6_nexthop ((struct rt6_info *)dst, daddr); neigh =__ipv6_neigh_lookup_noref (dev, nexthop);
@@ -329,7 +331,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, mtu =dst_mtu (dst);if ((skb->len <= mtu) || skb->ignore_df ||skb_is_gso (skb)) { -IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS );/* if egress device is enslaved to an L3 master device pass the * skb to its handler for processing
@@ -1989,7 +1991,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, skb->tstamp = cork->base.transmit_time;ip6_cork_steal_dst (skb, cork); -IP6_UPD_PO_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUTREQUESTS );if (proto ==IPPROTO_ICMPV6 ) {struct inet6_dev *idev =ip6_dst_idev (skb_dst (skb));u8 icmp6_type;
net/ipv6/mcast.c +2 -3
@@ -1789,7 +1789,7 @@ static void mld_sendpack(struct sk_buff *skb)rcu_read_lock (); idev =__in6_dev_get (skb->dev); -IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS ); payload_len = (skb_tail_pointer (skb) -skb_network_header (skb)) -sizeof (*pip6);
@@ -2147,8 +2147,7 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) full_len =sizeof (struct ipv6hdr ) + payload_len;rcu_read_lock (); -IP6_UPD_PO_STATS (net,__in6_dev_get (dev), -IPSTATS_MIB_OUT , full_len); +IP6_INC_STATS (net,__in6_dev_get (dev),IPSTATS_MIB_OUTREQUESTS );rcu_read_unlock (); skb =sock_alloc_send_skb (sk, hlen + tlen + full_len,1 , &err);
net/ipv6/ndisc.c +1 -1
@@ -504,7 +504,7 @@ void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,rcu_read_lock (); idev =__in6_dev_get (dst->dev); -IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS ); err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk, skb, NULL, dst->dev,
net/ipv6/proc.c +2 -1
@@ -61,7 +61,7 @@ static const struct snmp_mib snmp6_ipstats_list[] = {SNMP_MIB_ITEM ("Ip6InDiscards" ,IPSTATS_MIB_INDISCARDS ),SNMP_MIB_ITEM ("Ip6InDelivers" ,IPSTATS_MIB_INDELIVERS ),SNMP_MIB_ITEM ("Ip6OutForwDatagrams" ,IPSTATS_MIB_OUTFORWDATAGRAMS ), -SNMP_MIB_ITEM ("Ip6OutRequests" ,IPSTATS_MIB_OUTPKTS ), +SNMP_MIB_ITEM ("Ip6OutRequests" ,IPSTATS_MIB_OUTREQUESTS ),SNMP_MIB_ITEM ("Ip6OutDiscards" ,IPSTATS_MIB_OUTDISCARDS ),SNMP_MIB_ITEM ("Ip6OutNoRoutes" ,IPSTATS_MIB_OUTNOROUTES ), SNMP_MIB_ITEM("Ip6ReasmTimeout", IPSTATS_MIB_REASMTIMEOUT),
@@ -84,6 +84,7 @@ static const struct snmp_mib snmp6_ipstats_list[] = {SNMP_MIB_ITEM ("Ip6InECT1Pkts" ,IPSTATS_MIB_ECT1PKTS ),SNMP_MIB_ITEM ("Ip6InECT0Pkts" ,IPSTATS_MIB_ECT0PKTS ),SNMP_MIB_ITEM ("Ip6InCEPkts" ,IPSTATS_MIB_CEPKTS ), +SNMP_MIB_ITEM ("Ip6OutTransmits" ,IPSTATS_MIB_OUTPKTS ), SNMP_MIB_SENTINEL };
net/ipv6/raw.c +1 -1
@@ -651,7 +651,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,* have been queued for deletion. */ rcu_read_lock (); -IP6_UPD_PO_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUT , skb->len); +IP6_INC_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUTREQUESTS ); err =NF_HOOK (NFPROTO_IPV6 ,NF_INET_LOCAL_OUT , net, sk, skb,NULL , rt->dst.dev, dst_output);if (err >0 )
Signature · 1 line
2.35.2
Quoted 105 lines · Heng Guo
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 1500Reproduce:
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 withIPSTATS_MIB_OUTOCTETS("OutOctets") inip_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 defineIPSTATS_MIB_OUTPKTSto "OutTransmits" and addIPSTATS_MIB_OUTREQUESTSfor "OutRequests".
AddIPSTATS_MIB_OUTREQUESTScounter in__ip_local_out()for ipv4 and addIPSTATS_MIB_OUTcounter inip6_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]>---
V2: fix the missing space after a comma.
V3: keep original counter inmpls_stats_inc_outucastpkts(), because both forward and local outputs are in it.
Quoted 10 lines
include/uapi/linux/snmp.h | 3 ++- net/ipv4/ip_output.c | 2 ++ net/ipv4/proc.c | 3 ++- net/ipv6/ip6_output.c | 6 ++++-- net/ipv6/mcast.c | 5 ++--- net/ipv6/ndisc.c | 2 +- net/ipv6/proc.c | 3 ++- net/ipv6/raw.c | 2 +- 8 files changed, 16 insertions(+), 10 deletions(-)