Skip to content

Commit e4da8c7

Browse files
hguo3davem330
authored andcommitted
net: ipv4, ipv6: fix IPSTATS_MIB_OUTOCTETS increment duplicated
commit edf391f ("snmp: add missing counters for RFC 4293") had already added OutOctets for RFC 4293. In commit 2d8dbb0 ("snmp: fix OutOctets counter to include forwarded datagrams"), OutOctets was counted again, but not removed from ip_output(). According to RFC 4293 "3.2.3. IP Statistics Tables", ipipIfStatsOutTransmits is not equal to ipIfStatsOutForwDatagrams. So "IPSTATS_MIB_OUTOCTETS must be incremented when incrementing" is not accurate. And IPSTATS_MIB_OUTOCTETS should be counted after fragment. This patch reverts commit 2d8dbb0 ("snmp: fix OutOctets counter to include forwarded datagrams") and move IPSTATS_MIB_OUTOCTETS to ip_finish_output2 for ipv4. Reviewed-by: Filip Pudak <[email protected]> Signed-off-by: Heng Guo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bd6c11b commit e4da8c7

File tree

5 files changed

+3
-9
lines changed

5 files changed

+3
-9
lines changed

net/ipv4/ip_forward.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ static int ip_forward_finish(struct net *net, struct sock *sk, struct sk_buff *s
6767
struct ip_options *opt = &(IPCB(skb)->opt);
6868

6969
__IP_INC_STATS(net, IPSTATS_MIB_OUTFORWDATAGRAMS);
70-
__IP_ADD_STATS(net, IPSTATS_MIB_OUTOCTETS, skb->len);
7170

7271
#ifdef CONFIG_NET_SWITCHDEV
7372
if (skb->offload_l3_fwd_mark) {

net/ipv4/ip_output.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
207207
} else if (rt->rt_type == RTN_BROADCAST)
208208
IP_UPD_PO_STATS(net, IPSTATS_MIB_OUTBCAST, skb->len);
209209

210+
/* OUTOCTETS should be counted after fragment */
211+
IP_UPD_PO_STATS(net, IPSTATS_MIB_OUT, skb->len);
212+
210213
if (unlikely(skb_headroom(skb) < hh_len && dev->header_ops)) {
211214
skb = skb_expand_head(skb, hh_len);
212215
if (!skb)
@@ -366,8 +369,6 @@ int ip_mc_output(struct net *net, struct sock *sk, struct sk_buff *skb)
366369
/*
367370
* If the indicated interface is up and running, send the packet.
368371
*/
369-
IP_UPD_PO_STATS(net, IPSTATS_MIB_OUT, skb->len);
370-
371372
skb->dev = dev;
372373
skb->protocol = htons(ETH_P_IP);
373374

@@ -424,8 +425,6 @@ int ip_output(struct net *net, struct sock *sk, struct sk_buff *skb)
424425
{
425426
struct net_device *dev = skb_dst(skb)->dev, *indev = skb->dev;
426427

427-
IP_UPD_PO_STATS(net, IPSTATS_MIB_OUT, skb->len);
428-
429428
skb->dev = dev;
430429
skb->protocol = htons(ETH_P_IP);
431430

net/ipv4/ipmr.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,6 @@ static inline int ipmr_forward_finish(struct net *net, struct sock *sk,
18041804
struct ip_options *opt = &(IPCB(skb)->opt);
18051805

18061806
IP_INC_STATS(net, IPSTATS_MIB_OUTFORWDATAGRAMS);
1807-
IP_ADD_STATS(net, IPSTATS_MIB_OUTOCTETS, skb->len);
18081807

18091808
if (unlikely(opt->optlen))
18101809
ip_forward_options(skb);

net/ipv6/ip6_output.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ static inline int ip6_forward_finish(struct net *net, struct sock *sk,
451451
struct dst_entry *dst = skb_dst(skb);
452452

453453
__IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTFORWDATAGRAMS);
454-
__IP6_ADD_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTOCTETS, skb->len);
455454

456455
#ifdef CONFIG_NET_SWITCHDEV
457456
if (skb->offload_l3_fwd_mark) {

net/ipv6/ip6mr.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,8 +2010,6 @@ static inline int ip6mr_forward2_finish(struct net *net, struct sock *sk, struct
20102010
{
20112011
IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
20122012
IPSTATS_MIB_OUTFORWDATAGRAMS);
2013-
IP6_ADD_STATS(net, ip6_dst_idev(skb_dst(skb)),
2014-
IPSTATS_MIB_OUTOCTETS, skb->len);
20152013
return dst_output(net, sk, skb);
20162014
}
20172015

0 commit comments

Comments
 (0)