Skip to content

Commit 794c24e

Browse files
gfantomkuba-moo
authored andcommitted
net-core: rx_otherhost_dropped to core_stats
Increment rx_otherhost_dropped counter when packet dropped due to mismatched dest MAC addr. An example when this drop can occur is when manually crafting raw packets that will be consumed by a user space application via a tap device. For testing purposes local traffic was generated using trafgen for the client and netcat to start a server Tested: Created 2 netns, sent 1 packet using trafgen from 1 to the other with "{eth(daddr=$INCORRECT_MAC...}", verified that iproute2 showed the counter was incremented. (Also had to modify iproute2 to show the stat, additional patch for that coming next.) Signed-off-by: Jeffrey Ji <jeffreyji@google.com> Reviewed-by: Brian Vazquez <brianvv@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20220406172600.1141083-1-jeffreyjilinux@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 4d242a1 commit 794c24e

File tree

5 files changed

+10
-0
lines changed

5 files changed

+10
-0
lines changed

include/linux/netdevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ struct net_device_core_stats {
203203
local_t rx_dropped;
204204
local_t tx_dropped;
205205
local_t rx_nohandler;
206+
local_t rx_otherhost_dropped;
206207
} __aligned(4 * sizeof(local_t));
207208

208209
#include <linux/cache.h>
@@ -3837,6 +3838,7 @@ static inline void dev_core_stats_##FIELD##_inc(struct net_device *dev) \
38373838
DEV_CORE_STATS_INC(rx_dropped)
38383839
DEV_CORE_STATS_INC(tx_dropped)
38393840
DEV_CORE_STATS_INC(rx_nohandler)
3841+
DEV_CORE_STATS_INC(rx_otherhost_dropped)
38403842

38413843
static __always_inline int ____dev_forward_skb(struct net_device *dev,
38423844
struct sk_buff *skb,

include/uapi/linux/if_link.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ struct rtnl_link_stats {
211211
* @rx_nohandler: Number of packets received on the interface
212212
* but dropped by the networking stack because the device is
213213
* not designated to receive packets (e.g. backup link in a bond).
214+
*
215+
* @rx_otherhost_dropped: Number of packets dropped due to mismatch
216+
* in destination MAC address.
214217
*/
215218
struct rtnl_link_stats64 {
216219
__u64 rx_packets;
@@ -243,6 +246,8 @@ struct rtnl_link_stats64 {
243246
__u64 rx_compressed;
244247
__u64 tx_compressed;
245248
__u64 rx_nohandler;
249+
250+
__u64 rx_otherhost_dropped;
246251
};
247252

248253
/* Subset of link stats useful for in-HW collection. Meaning of the fields is as

net/core/dev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10358,6 +10358,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
1035810358
storage->rx_dropped += local_read(&core_stats->rx_dropped);
1035910359
storage->tx_dropped += local_read(&core_stats->tx_dropped);
1036010360
storage->rx_nohandler += local_read(&core_stats->rx_nohandler);
10361+
storage->rx_otherhost_dropped += local_read(&core_stats->rx_otherhost_dropped);
1036110362
}
1036210363
}
1036310364
return storage;

net/ipv4/ip_input.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
451451
* that it receives, do not try to analyse it.
452452
*/
453453
if (skb->pkt_type == PACKET_OTHERHOST) {
454+
dev_core_stats_rx_otherhost_dropped_inc(skb->dev);
454455
drop_reason = SKB_DROP_REASON_OTHERHOST;
455456
goto drop;
456457
}

net/ipv6/ip6_input.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
150150
struct inet6_dev *idev;
151151

152152
if (skb->pkt_type == PACKET_OTHERHOST) {
153+
dev_core_stats_rx_otherhost_dropped_inc(skb->dev);
153154
kfree_skb(skb);
154155
return NULL;
155156
}

0 commit comments

Comments
 (0)