diff mbox series

[v7,net-next] net-core: add InDropOtherhost counter

Message ID 20220207235714.1050160-1-jeffreyji@google.com (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series [v7,net-next] net-core: add InDropOtherhost counter | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5189 this patch: 5189
netdev/cc_maintainers warning 7 maintainers not CCed: linux-doc@vger.kernel.org kuniyu@amazon.co.jp ycheng@google.com corbet@lwn.net dsahern@kernel.org imagedong@tencent.com yoshfuji@linux-ipv6.org
netdev/build_clang success Errors and warnings before: 859 this patch: 859
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5343 this patch: 5343
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 65 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jeffrey Ji Feb. 7, 2022, 11:57 p.m. UTC
From: jeffreyji <jeffreyji@google.com>

Increment InDropOtherhost 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
Ip6InDropOtherhost                  0                  0.0
IpExtInDropOtherhost                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.

changelog:
v7: change InMacError -> InDropOtherhost

v6: rebase onto net-next

v5:
Change from SKB_DROP_REASON_BAD_DEST_MAC to SKB_DROP_REASON_OTHERHOST

v3-4:
Remove Change-Id

v2:
Use skb_free_reason() for tracing
Add real-life example in patch msg

Signed-off-by: Brian Vazquez <brianvv@google.com>
Signed-off-by: jeffreyji <jeffreyji@google.com>
---
 Documentation/networking/snmp_counter.rst |  5 +++++
 include/uapi/linux/snmp.h                 |  1 +
 net/ipv4/ip_input.c                       |  5 +++--
 net/ipv4/proc.c                           |  1 +
 net/ipv6/ip6_input.c                      | 12 +++++++-----
 net/ipv6/proc.c                           |  1 +
 6 files changed, 18 insertions(+), 7 deletions(-)

Comments

Jakub Kicinski Feb. 8, 2022, 3:51 a.m. UTC | #1
On Mon,  7 Feb 2022 23:57:14 +0000 Jeffrey Ji wrote:
> From: jeffreyji <jeffreyji@google.com>
> 
> Increment InDropOtherhost 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
> Ip6InDropOtherhost                  0                  0.0
> IpExtInDropOtherhost                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.

As far as I can tell nobody objected to my suggestion of making this 
a netdev counter, so please switch to working on that. Thanks.
Jeffrey Ji Feb. 18, 2022, 9:31 p.m. UTC | #2
Hi Jakub, I'll remove the MIB counters & instead add counters to
rtnl_link_stats64 and rtnl_link_stats, does that sound right? But keep
the sbk_free_drop_reason


On Mon, Feb 7, 2022 at 7:51 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Mon,  7 Feb 2022 23:57:14 +0000 Jeffrey Ji wrote:
> > From: jeffreyji <jeffreyji@google.com>
> >
> > Increment InDropOtherhost 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
> > Ip6InDropOtherhost                  0                  0.0
> > IpExtInDropOtherhost                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.
>
> As far as I can tell nobody objected to my suggestion of making this
> a netdev counter, so please switch to working on that. Thanks.
Jakub Kicinski Feb. 19, 2022, 4:12 a.m. UTC | #3
On Fri, 18 Feb 2022 13:31:03 -0800 Jeffrey Ji wrote:
> Hi Jakub, I'll remove the MIB counters & instead add counters to
> rtnl_link_stats64 and rtnl_link_stats, does that sound right? 

Yup! I'd ignore rtnl_link_stats, actually since it's legacy and just
add it to the 64-bit version of the stats.

> But keep the sbk_free_drop_reason

sounds good
diff mbox series

Patch

diff --git a/Documentation/networking/snmp_counter.rst b/Documentation/networking/snmp_counter.rst
index 423d138b5ff3..674f736e4e8b 100644
--- a/Documentation/networking/snmp_counter.rst
+++ b/Documentation/networking/snmp_counter.rst
@@ -214,6 +214,11 @@  wrong. Kernel verifies the checksum after updating the IcmpInMsgs and
 before updating IcmpMsgInType[N]. If a packet has bad checksum, the
 IcmpInMsgs would be updated but none of IcmpMsgInType[N] would be updated.
 
+* IcmpInDropOtherhost
+
+This counter indicates that the packet was dropped because the destination
+MAC address was incorrect.
+
 * IcmpInErrors and IcmpOutErrors
 
 Defined by `RFC1213 icmpInErrors`_ and `RFC1213 icmpOutErrors`_
diff --git a/include/uapi/linux/snmp.h b/include/uapi/linux/snmp.h
index 904909d020e2..4f247d406b1a 100644
--- a/include/uapi/linux/snmp.h
+++ b/include/uapi/linux/snmp.h
@@ -57,6 +57,7 @@  enum
 	IPSTATS_MIB_ECT0PKTS,			/* InECT0Pkts */
 	IPSTATS_MIB_CEPKTS,			/* InCEPkts */
 	IPSTATS_MIB_REASM_OVERLAPS,		/* ReasmOverlaps */
+	IPSTATS_MIB_INDROPOTHERHOST,		/* InDropOtherhost */
 	__IPSTATS_MIB_MAX
 };
 
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index d94f9f7e60c3..db4c36c008ff 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -450,8 +450,9 @@  static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net)
 	 * that it receives, do not try to analyse it.
 	 */
 	if (skb->pkt_type == PACKET_OTHERHOST) {
-		drop_reason = SKB_DROP_REASON_OTHERHOST;
-		goto drop;
+		__IP_INC_STATS(net, IPSTATS_MIB_INDROPOTHERHOST);
+		kfree_skb_reason(skb, SKB_DROP_REASON_OTHERHOST);
+		return NULL;
 	}
 
 	__IP_UPD_PO_STATS(net, IPSTATS_MIB_IN, skb->len);
diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c
index 28836071f0a6..2ffa43cff799 100644
--- a/net/ipv4/proc.c
+++ b/net/ipv4/proc.c
@@ -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("InDropOtherhost", IPSTATS_MIB_INDROPOTHERHOST),
 	SNMP_MIB_SENTINEL
 };
 
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index d4b1e2c5aa76..480896e13041 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -149,15 +149,17 @@  static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
 	u32 pkt_len;
 	struct inet6_dev *idev;
 
-	if (skb->pkt_type == PACKET_OTHERHOST) {
-		kfree_skb(skb);
-		return NULL;
-	}
-
 	rcu_read_lock();
 
 	idev = __in6_dev_get(skb->dev);
 
+	if (skb->pkt_type == PACKET_OTHERHOST) {
+		__IP6_INC_STATS(net, idev, IPSTATS_MIB_INDROPOTHERHOST);
+		rcu_read_unlock();
+		kfree_skb_reason(skb, SKB_DROP_REASON_OTHERHOST);
+		return NULL;
+	}
+
 	__IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_IN, skb->len);
 
 	if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL ||
diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
index d6306aa46bb1..c2d963122d1e 100644
--- a/net/ipv6/proc.c
+++ b/net/ipv6/proc.c
@@ -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("Ip6InDropOtherhost", IPSTATS_MIB_INDROPOTHERHOST),
 	SNMP_MIB_SENTINEL
 };