Skip to content

Commit caf586e

Browse files
Eric Dumazetdavem330
authored andcommitted
net: add a core netdev->rx_dropped counter
In various situations, a device provides a packet to our stack and we drop it before it enters protocol stack : - softnet backlog full (accounted in /proc/net/softnet_stat) - bad vlan tag (not accounted) - unknown/unregistered protocol (not accounted) We can handle a per-device counter of such dropped frames at core level, and automatically adds it to the device provided stats (rx_dropped), so that standard tools can be used (ifconfig, ip link, cat /proc/net/dev) This is a generalization of commit 8990f46 (net: rx_dropped accounting), thus reverting it. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a00eac0 commit caf586e

File tree

11 files changed

+26
-34
lines changed

11 files changed

+26
-34
lines changed

drivers/net/loopback.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ struct pcpu_lstats {
6464
u64 packets;
6565
u64 bytes;
6666
struct u64_stats_sync syncp;
67-
unsigned long drops;
6867
};
6968

7069
/*
@@ -90,8 +89,7 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
9089
lb_stats->bytes += len;
9190
lb_stats->packets++;
9291
u64_stats_update_end(&lb_stats->syncp);
93-
} else
94-
lb_stats->drops++;
92+
}
9593

9694
return NETDEV_TX_OK;
9795
}
@@ -101,7 +99,6 @@ static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev,
10199
{
102100
u64 bytes = 0;
103101
u64 packets = 0;
104-
u64 drops = 0;
105102
int i;
106103

107104
for_each_possible_cpu(i) {
@@ -115,14 +112,11 @@ static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev,
115112
tbytes = lb_stats->bytes;
116113
tpackets = lb_stats->packets;
117114
} while (u64_stats_fetch_retry(&lb_stats->syncp, start));
118-
drops += lb_stats->drops;
119115
bytes += tbytes;
120116
packets += tpackets;
121117
}
122118
stats->rx_packets = packets;
123119
stats->tx_packets = packets;
124-
stats->rx_dropped = drops;
125-
stats->rx_errors = drops;
126120
stats->rx_bytes = bytes;
127121
stats->tx_bytes = bytes;
128122
return stats;

include/linux/netdevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,9 @@ struct net_device {
884884
int iflink;
885885

886886
struct net_device_stats stats;
887+
atomic_long_t rx_dropped; /* dropped packets by core network
888+
* Do not use this in drivers.
889+
*/
887890

888891
#ifdef CONFIG_WIRELESS_EXT
889892
/* List of functions to handle Wireless Extensions (instead of ioctl).

net/8021q/vlan.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ struct vlan_priority_tci_mapping {
2525
* @rx_multicast: number of received multicast packets
2626
* @syncp: synchronization point for 64bit counters
2727
* @rx_errors: number of errors
28-
* @rx_dropped: number of dropped packets
2928
*/
3029
struct vlan_rx_stats {
3130
u64 rx_packets;
3231
u64 rx_bytes;
3332
u64 rx_multicast;
3433
struct u64_stats_sync syncp;
3534
unsigned long rx_errors;
36-
unsigned long rx_dropped;
3735
};
3836

3937
/**

net/8021q/vlan_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
3333
return polling ? netif_receive_skb(skb) : netif_rx(skb);
3434

3535
drop:
36+
atomic_long_inc(&skb->dev->rx_dropped);
3637
dev_kfree_skb_any(skb);
3738
return NET_RX_DROP;
3839
}
@@ -123,6 +124,7 @@ vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
123124
return dev_gro_receive(napi, skb);
124125

125126
drop:
127+
atomic_long_inc(&skb->dev->rx_dropped);
126128
return GRO_DROP;
127129
}
128130

net/8021q/vlan_dev.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,15 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
225225
}
226226
}
227227

228-
if (unlikely(netif_rx(skb) == NET_RX_DROP)) {
229-
if (rx_stats)
230-
rx_stats->rx_dropped++;
231-
}
228+
netif_rx(skb);
229+
232230
rcu_read_unlock();
233231
return NET_RX_SUCCESS;
234232

235233
err_unlock:
236234
rcu_read_unlock();
237235
err_free:
236+
atomic_long_inc(&dev->rx_dropped);
238237
kfree_skb(skb);
239238
return NET_RX_DROP;
240239
}
@@ -846,15 +845,13 @@ static struct rtnl_link_stats64 *vlan_dev_get_stats64(struct net_device *dev, st
846845
accum.rx_packets += rxpackets;
847846
accum.rx_bytes += rxbytes;
848847
accum.rx_multicast += rxmulticast;
849-
/* rx_errors, rx_dropped are ulong, not protected by syncp */
848+
/* rx_errors is ulong, not protected by syncp */
850849
accum.rx_errors += p->rx_errors;
851-
accum.rx_dropped += p->rx_dropped;
852850
}
853851
stats->rx_packets = accum.rx_packets;
854852
stats->rx_bytes = accum.rx_bytes;
855853
stats->rx_errors = accum.rx_errors;
856854
stats->multicast = accum.rx_multicast;
857-
stats->rx_dropped = accum.rx_dropped;
858855
}
859856
return stats;
860857
}

net/core/dev.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,9 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
14831483
skb_orphan(skb);
14841484
nf_reset(skb);
14851485

1486-
if (!(dev->flags & IFF_UP) ||
1487-
(skb->len > (dev->mtu + dev->hard_header_len))) {
1486+
if (unlikely(!(dev->flags & IFF_UP) ||
1487+
(skb->len > (dev->mtu + dev->hard_header_len)))) {
1488+
atomic_long_inc(&dev->rx_dropped);
14881489
kfree_skb(skb);
14891490
return NET_RX_DROP;
14901491
}
@@ -2548,6 +2549,7 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
25482549

25492550
local_irq_restore(flags);
25502551

2552+
atomic_long_inc(&skb->dev->rx_dropped);
25512553
kfree_skb(skb);
25522554
return NET_RX_DROP;
25532555
}
@@ -2995,6 +2997,7 @@ static int __netif_receive_skb(struct sk_buff *skb)
29952997
if (pt_prev) {
29962998
ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
29972999
} else {
3000+
atomic_long_inc(&skb->dev->rx_dropped);
29983001
kfree_skb(skb);
29993002
/* Jamal, now you will not able to escape explaining
30003003
* me how you were going to use this. :-)
@@ -5429,14 +5432,14 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
54295432

54305433
if (ops->ndo_get_stats64) {
54315434
memset(storage, 0, sizeof(*storage));
5432-
return ops->ndo_get_stats64(dev, storage);
5433-
}
5434-
if (ops->ndo_get_stats) {
5435+
ops->ndo_get_stats64(dev, storage);
5436+
} else if (ops->ndo_get_stats) {
54355437
netdev_stats_to_stats64(storage, ops->ndo_get_stats(dev));
5436-
return storage;
5438+
} else {
5439+
netdev_stats_to_stats64(storage, &dev->stats);
5440+
dev_txq_stats_fold(dev, storage);
54375441
}
5438-
netdev_stats_to_stats64(storage, &dev->stats);
5439-
dev_txq_stats_fold(dev, storage);
5442+
storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
54405443
return storage;
54415444
}
54425445
EXPORT_SYMBOL(dev_get_stats);

net/ipv4/ip_gre.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,7 @@ static int ipgre_rcv(struct sk_buff *skb)
679679
skb_reset_network_header(skb);
680680
ipgre_ecn_decapsulate(iph, skb);
681681

682-
if (netif_rx(skb) == NET_RX_DROP)
683-
tunnel->dev->stats.rx_dropped++;
682+
netif_rx(skb);
684683

685684
rcu_read_unlock();
686685
return 0;

net/ipv4/ipip.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ static int ipip_rcv(struct sk_buff *skb)
414414

415415
ipip_ecn_decapsulate(iph, skb);
416416

417-
if (netif_rx(skb) == NET_RX_DROP)
418-
tunnel->dev->stats.rx_dropped++;
417+
netif_rx(skb);
419418

420419
rcu_read_unlock();
421420
return 0;

net/ipv6/ip6_tunnel.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,7 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
768768

769769
dscp_ecn_decapsulate(t, ipv6h, skb);
770770

771-
if (netif_rx(skb) == NET_RX_DROP)
772-
t->dev->stats.rx_dropped++;
771+
netif_rx(skb);
773772

774773
rcu_read_unlock();
775774
return 0;

net/ipv6/ip6mr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,7 @@ static int pim6_rcv(struct sk_buff *skb)
666666

667667
skb_tunnel_rx(skb, reg_dev);
668668

669-
if (netif_rx(skb) == NET_RX_DROP)
670-
reg_dev->stats.rx_dropped++;
669+
netif_rx(skb);
671670

672671
dev_put(reg_dev);
673672
return 0;

0 commit comments

Comments
 (0)