Skip to contentSkip to conversation

net-core: add InMacErrors counter

PATCH Superseded Jeffrey Ji 2 participants 2 messages Jan 25, 2022

Subsystems (3)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Jeffrey Ji

author
#0 lore raw

PATCH v2 1/1 net-core: add InMacErrors counter

From: jeffreyji <[email protected]>

Increment InMacErrors counter when packet dropped due to incorrect 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

example output from nstat:
\~# nstat -a | grep InMac

Ip6InMacErrors                  0                  0.0
IpExtInMacErrors                1                  0.0

Tested: Created 2 netns, sent 1 packet using trafgen from 1 to the other with "{eth(daddr=$INCORRECT_MAC...}", verified that nstat showed the counter was incremented.

---
 include/uapi/linux/snmp.h | 1 +
 net/ipv4/ip_input.c       | 4 +++-
 net/ipv4/proc.c           | 1 +
 net/ipv6/ip6_input.c      | 1 +
 net/ipv6/proc.c           | 1 +
 5 files changed, 7 insertions(+), 1 deletion(-)
include/uapi/linux/snmp.h +1 -0
index 904909d020e2..ac2fac12dd7d 100644
@@ -57,6 +57,7 @@ enum
 	IPSTATS_MIB_ECT0PKTS,			/* InECT0Pkts */
 	IPSTATS_MIB_CEPKTS,			/* InCEPkts */
 	IPSTATS_MIB_REASM_OVERLAPS,		/* ReasmOverlaps */
+	IPSTATS_MIB_INMACERRORS,		/* InMacErrors */
 	__IPSTATS_MIB_MAX
 };
 
net/ipv4/ip_input.c +3 -1
index 3a025c011971..0961585f7c02 100644
@@ -441,8 +441,10 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
 	/* When the interface is in promisc. mode, drop all the crap
 	 * that it receives, do not try to analyse it.
 	 */
-	if (skb->pkt_type == PACKET_OTHERHOST)
+	if (skb->pkt_type == PACKET_OTHERHOST) {
+		__IP_INC_STATS(net, IPSTATS_MIB_INMACERRORS);
 		goto drop;
+	}
 
 	__IP_UPD_PO_STATS(net, IPSTATS_MIB_IN, skb->len);
 
net/ipv4/proc.c +1 -0
index f30273afb539..dfe0a1dbf8e9 100644
@@ -117,6 +117,7 @@ static const struct snmp_mib snmp4_ipextstats_list[] = {
 	SNMP_MIB_ITEM("InECT0Pkts", IPSTATS_MIB_ECT0PKTS),
 	SNMP_MIB_ITEM("InCEPkts", IPSTATS_MIB_CEPKTS),
 	SNMP_MIB_ITEM("ReasmOverlaps", IPSTATS_MIB_REASM_OVERLAPS),
+	SNMP_MIB_ITEM("InMacErrors", IPSTATS_MIB_INMACERRORS),
 	SNMP_MIB_SENTINEL
 };
 
net/ipv6/ip6_input.c +1 -0
index 80256717868e..2903869274ca 100644
@@ -150,6 +150,7 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
 	struct inet6_dev *idev;
 
 	if (skb->pkt_type == PACKET_OTHERHOST) {
+		__IP6_INC_STATS(net, idev, IPSTATS_MIB_INMACERRORS);
 		kfree_skb(skb);
 		return NULL;
 	}
net/ipv6/proc.c +1 -0
index d6306aa46bb1..76e6119ba558 100644
@@ -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("Ip6InMacErrors", IPSTATS_MIB_INMACERRORS),
 	SNMP_MIB_SENTINEL
 };
 
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
maintainer
#1 lore raw
Quoted 24 lines · On Tue, 25 Jan 2022 19:07:17 +0000 Jeffrey Ji wrote:

From: jeffreyji <[email protected]>

Increment InMacErrors counter when packet dropped due to incorrect 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

example output from nstat:
\~# nstat -a | grep InMac

Ip6InMacErrors                  0                  0.0
IpExtInMacErrors                1                  0.0

Tested: Created 2 netns, sent 1 packet using trafgen from 1 to the other with "{eth(daddr=$INCORRECT_MAC...}", verified that nstat showed the counter was incremented.

net/ipv6/ip6_input.c +0 -0
index 80256717868e..2903869274ca 100644

net/ipv6/ip6_input.c static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev, · line 153

Quoted 4 lines
net/ipv6/ip6_input.c +1 -0
@@ -150,6 +150,7 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
 	struct inet6_dev *idev;
 
 	if (skb->pkt_type == PACKET_OTHERHOST) {
+		__IP6_INC_STATS(net, idev, IPSTATS_MIB_INMACERRORS);

Clang points out idev is not initialized at this point, yet.