Skip to content

Commit

Permalink
net-core: add InMacErrors counter
Browse files Browse the repository at this point in the history
Increment InMacErrors counter when packet dropped due to incorrect dest
MAC addr.

example output from nstat:
\~# nstat -z "*InMac*"
\#kernel
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.

Signed-off-by: jeffreyji <jeffreyji@google.com>
  • Loading branch information
gfantom authored and intel-lab-lkp committed Jan 22, 2022
1 parent 8aaaf2f commit f8ea346
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/uapi/linux/snmp.h
Expand Up @@ -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
};

Expand Down
4 changes: 3 additions & 1 deletion net/ipv4/ip_input.c
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions net/ipv4/proc.c
Expand Up @@ -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
};

Expand Down
1 change: 1 addition & 0 deletions net/ipv6/ip6_input.c
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions net/ipv6/proc.c
Expand Up @@ -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
};

Expand Down

0 comments on commit f8ea346

Please sign in to comment.