Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1293887pxm; Thu, 3 Mar 2022 14:29:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWlplJ3tFQnK/2c0EHFR+LrEOI8DIYoHJZmdp9Y+FmHxaW2o6QQB0v35tr8PbAsVdggSKl X-Received: by 2002:aa7:c7c9:0:b0:415:c6a5:1f68 with SMTP id o9-20020aa7c7c9000000b00415c6a51f68mr8013983eds.160.1646346541454; Thu, 03 Mar 2022 14:29:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646346541; cv=none; d=google.com; s=arc-20160816; b=SvB9SsjsHsW32rYYctFBoDEyPwJTkialRypg5U9dsfqR/YSJ/hoKaLVMgJh3MEYEBH E9NzKB+LoopRG1L82NVWfJx5C9DzcfktH+/l37xIEyKOvIq+an5HXKf3fDxWVwXb2R4C 9zqL9+F55M50V/R09JSqOUKXn8g1RT5H/bEG1rPF0FLQmmZFg0URiF4iuFgdlTfy6FWN 5+iGUb2HL20o3z0pJN7A3rmMJlbDF5SEtkLVIQNBhOYLlQQtJScfIhA8LsJnj3+i6BDZ jpDuHP/5vv7/RnZ3uFNHrs7hWxJMptcyv6hETk5RTBV1ZVbp5ptgafuYmGTctGMthVUb AreA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=B/wWxO70VsbRWbkBNYeysd8PjZWhNsydI8SGtYmrmUE=; b=EWS6Dzi1w0bkX8HQ9vENkYHXw+h6VIo5dZrSs5fjsc/83z5ZgYpwiAEG8lrD4KHAKB DKIf0y4T9Xk/jolt1tZX+LCwV1HeUdTIoktU1YB0Tb0XvZEL1yyh5H4YBjymMX70yesN hOCVHD5f1YElEm0Y6dlde/0S7AQREXIV0eCdcLeiNQB8S57eDLC3PTFakFtwc/H4ZFtB CBZRxYJ+DAy+8TnYmPQ33ClCiEuiI3LljYwVg3iGWRdAciLvbU7OsJ1nwl2+uEs7UXp1 T1nxp+XHBtJ2jPAUiHx1HHnY3ZkpB35edBez30uy+rkTRdeYYFOVJXsjqac/I8uu1i3l yZpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="OF7gv1/R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p24-20020aa7cc98000000b00410a101f172si2081168edt.472.2022.03.03.14.28.39; Thu, 03 Mar 2022 14:29:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="OF7gv1/R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236710AbiCCWBB (ORCPT + 99 others); Thu, 3 Mar 2022 17:01:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236709AbiCCWBA (ORCPT ); Thu, 3 Mar 2022 17:01:00 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 222754832F for ; Thu, 3 Mar 2022 14:00:12 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id d23so10839959lfv.13 for ; Thu, 03 Mar 2022 14:00:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=B/wWxO70VsbRWbkBNYeysd8PjZWhNsydI8SGtYmrmUE=; b=OF7gv1/RXdd0nABLes0yv4StAtx74Mo5Ug13VUe6weTNGjuV4E4T0W88MozzXiY0fI lV5XfBh4ZEzkEsC5SyBGXljO7ih/HoeEWLy64bQkjayhyNPqC/2F0mw879ii0ot5SPNb Vdw8eSYN4EHalFhIyOtGmdEizcKf8TzwXSgUHUqKr8OOVjho0Eiy+TGi6RFNZ/C8sFGg /N4V1k9mpLgY/stpOyklIbZdTzDgs085xW+qoG8ZhZKRvr7Am8hUo79RB+HA0gkivTmY QZ1OfPZMOGC6/sZ+mD3K6hbPUUAOgLE7mOq9kBmM3wrDdEPGMMR2Rmma0s6sgKai/AuG Gk6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B/wWxO70VsbRWbkBNYeysd8PjZWhNsydI8SGtYmrmUE=; b=SNy3jGOJ8jW81S5HXWQNfj+/AHKajxYPDtMyF0sblUByGkqNjPII83LRMdUncKLwDO mlQezRiDPuhbL0JZir6EP+DhKdso9WkUkrBnPf/pQx66zqr3CayxWmsCfkYepxqS+Mbo 7u/TQY5lVoHwrzIf+1YphbdTyX9zSc90NwRnbAOc9cKLI6u0Qzcmo751tKBUtV1y8vis rjET0tvGaP1CaHqwMx3e7IayNtHSHusO4NMsatk4XsMnVk6F0eVzsiYFcwmhXs9Q2WoU EdN+dpDF1c2cKcLnKLcYSB5HKu9Cll76Uy6zISouMXfp+q34A/dVMv4qMH8a8z6WdCKx ht4g== X-Gm-Message-State: AOAM533Kl3ehlPjvSfNVSBuxP+C9+8B0/0giCMP3YcMwdj0ePief+k/j 0H4Qzf76nK1pDZg7RGWJWFtlEJR+Mg/V2fjXI3QBuw== X-Received: by 2002:a05:6512:3d90:b0:437:73cb:8e76 with SMTP id k16-20020a0565123d9000b0043773cb8e76mr22691498lfv.187.1646344810110; Thu, 03 Mar 2022 14:00:10 -0800 (PST) MIME-Version: 1.0 References: <20220303003034.1906898-1-jeffreyjilinux@gmail.com> In-Reply-To: <20220303003034.1906898-1-jeffreyjilinux@gmail.com> From: Brian Vazquez Date: Thu, 3 Mar 2022 13:59:58 -0800 Message-ID: Subject: Re: [PATCH v2 net-next] net-core: add rx_otherhost_dropped counter To: Jeffrey Ji Cc: "David S . Miller" , Jakub Kicinski , Hideaki YOSHIFUJI , David Ahern , Eric Dumazet , Antoine Tenart , Sebastian Andrzej Siewior , Alexander Lobakin , Kumar Kartikeya Dwivedi , Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, jeffreyji Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-18.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org LGTM, thanks Jeffrey! Reviewed-by: Brian Vazquez On Wed, Mar 2, 2022 at 4:30 PM Jeffrey Ji wrote: > > From: jeffreyji > > 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.) > > changelog: > > v2: add kdoc comment > > Signed-off-by: jeffreyji > --- > include/linux/netdevice.h | 3 +++ > include/uapi/linux/if_link.h | 5 +++++ > net/core/dev.c | 2 ++ > net/ipv4/ip_input.c | 1 + > net/ipv6/ip6_input.c | 1 + > 5 files changed, 12 insertions(+) > > diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h > index c79ee2296296..e4073c38bd77 100644 > --- a/include/linux/netdevice.h > +++ b/include/linux/netdevice.h > @@ -1741,6 +1741,8 @@ enum netdev_ml_priv_type { > * do not use this in drivers > * @rx_nohandler: nohandler dropped packets by core network on > * inactive devices, do not use this in drivers > + * @rx_otherhost_dropped: Dropped packets due to mismatch in packet dest > + * MAC address > * @carrier_up_count: Number of times the carrier has been up > * @carrier_down_count: Number of times the carrier has been down > * > @@ -2025,6 +2027,7 @@ struct net_device { > atomic_long_t rx_dropped; > atomic_long_t tx_dropped; > atomic_long_t rx_nohandler; > + atomic_long_t rx_otherhost_dropped; > > /* Stats to monitor link on/off, flapping */ > atomic_t carrier_up_count; > diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h > index e315e53125f4..17e74385fca8 100644 > --- a/include/uapi/linux/if_link.h > +++ b/include/uapi/linux/if_link.h > @@ -211,6 +211,9 @@ struct rtnl_link_stats { > * @rx_nohandler: Number of packets received on the interface > * but dropped by the networking stack because the device is > * not designated to receive packets (e.g. backup link in a bond). > + * > + * @rx_otherhost_dropped: Number of packets dropped due to mismatch in > + * packet's destination MAC address. > */ > struct rtnl_link_stats64 { > __u64 rx_packets; > @@ -243,6 +246,8 @@ struct rtnl_link_stats64 { > __u64 rx_compressed; > __u64 tx_compressed; > __u64 rx_nohandler; > + > + __u64 rx_otherhost_dropped; > }; > > /* The struct should be in sync with struct ifmap */ > diff --git a/net/core/dev.c b/net/core/dev.c > index 2d6771075720..d039d8fdc16a 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -10037,6 +10037,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, > storage->rx_dropped += (unsigned long)atomic_long_read(&dev->rx_dropped); > storage->tx_dropped += (unsigned long)atomic_long_read(&dev->tx_dropped); > storage->rx_nohandler += (unsigned long)atomic_long_read(&dev->rx_nohandler); > + storage->rx_otherhost_dropped += > + (unsigned long)atomic_long_read(&dev->rx_otherhost_dropped); > return storage; > } > EXPORT_SYMBOL(dev_get_stats); > diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c > index d94f9f7e60c3..ef97b0a4c77f 100644 > --- a/net/ipv4/ip_input.c > +++ b/net/ipv4/ip_input.c > @@ -450,6 +450,7 @@ 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) { > + atomic_long_inc(&skb->dev->rx_otherhost_dropped); > drop_reason = SKB_DROP_REASON_OTHERHOST; > goto drop; > } > diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c > index d4b1e2c5aa76..3f0cbe126d82 100644 > --- a/net/ipv6/ip6_input.c > +++ b/net/ipv6/ip6_input.c > @@ -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) { > + atomic_long_inc(&skb->dev->rx_otherhost_dropped); > kfree_skb(skb); > return NULL; > } > -- > 2.35.1.616.g0bdcbb4464-goog >