Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2216037ybl; Thu, 29 Aug 2019 05:20:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZmk7w/C1zA8k5dukwsQn+07rVW+b54hrPrHQXm7Mv5ph4xULLVRJBBexTWl9bFDr/2NeK X-Received: by 2002:a17:902:9b86:: with SMTP id y6mr9565441plp.217.1567081246242; Thu, 29 Aug 2019 05:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567081246; cv=none; d=google.com; s=arc-20160816; b=ocSWUH6TBjTHGRqBmia4bQDTnpbyB1MHzNTZUxIjkLDZ9Q6yopEE7WjI4mqsmhgoAO oOCcISNDkvzHrn1mVQWSyjoQhUvTTJtvIStL4XvaMavlwDxsHBN92TuOGeo5eUlEuqXi qMwEDbpu7TI+bl19DVmoWiqwwigwU6UoyweymNFOXA1Pgq3zVozenbrK9VJfUDy/1wga 876wykDXcjN0/2Nc4pa0JefsxpPOAu3jYBppmjjgsvSsNlWd5SoWrIRi8xQE0PA2aZux ELgokaUoCfU/B8K8fj6K2LpRsrsmtGvJ2A/7lyYbjdF1tvUktznIdkeSGjM8gaWFqZTx ZZuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pFWLKMGVr3USsr0a1cWm+DfSSpAfEVTSRCcxqOxrU7I=; b=ipxiMm8Ls2+K/dyEHmVcDs9j1UH4lS/wCLEl1/tdRZodysNGcDEPC0JFZDTsaPeZJk WvD9llwbYjUqlA5Zg8atv1k3aoIOEuBMSUPz4bY0ph+u7t6dMwd0vs3fBOylxtJA5C7J nLD9FoFCgK6dYwAGS6YlbK1gE4mG3SN7PHVmIej2RDd6/O9NK1jkB2X7UBNI8/sFlQ2J D8C0x/ia5U+VW0aZfA4c7H+5kQhG1RKI3qM2dnPBcYnRDIISf7KLbcsyx0rPeOnaD8QP co83iATLUxrKriXfXekq3NZ5PLTZanuu/QK3HnATTDKYdh7bqwmb6nj5ceDML0nUOWY5 IJ4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=wmtgKbFm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cu10si2023771pjb.16.2019.08.29.05.20.27; Thu, 29 Aug 2019 05:20:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=wmtgKbFm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727420AbfH2MSP (ORCPT + 99 others); Thu, 29 Aug 2019 08:18:15 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40233 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727317AbfH2MSO (ORCPT ); Thu, 29 Aug 2019 08:18:14 -0400 Received: by mail-wm1-f67.google.com with SMTP id t9so3613828wmi.5 for ; Thu, 29 Aug 2019 05:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pFWLKMGVr3USsr0a1cWm+DfSSpAfEVTSRCcxqOxrU7I=; b=wmtgKbFmXIVzs79+qMDp0xCzdOv8uq28M4avUrOGEYSn/W+dSFiqQbF9ogfUOoKHqn 2J0T4FfqNpP8v3my/Wr4FmY0rI+FisIHK30ccr5XS/L2BPwQDKDYtVc9CUQa7Bz7o0by Kr2kUMXXSWVMASAKsTv6W358JnLNitrYIi9eliUV+yU1BEWnvBjOH8DgZwox3JSAVIMH nkreeicyyLO0/BbL1xc7BTNLquY90pmSuIIyqe+qpW0cPxN/hvuxeMOZ6JeAdP3ltpTP zZp0nVPM9j6oqwJVT2D9Gl22+M0NdHvidANEaVAi0CAKJyalJ+IJFUIMTrLvM9jY7NbS MTNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=pFWLKMGVr3USsr0a1cWm+DfSSpAfEVTSRCcxqOxrU7I=; b=U1O1DEtFVh94hYf8Egf2+skOEE/GfvsNUf4mTAVsxzNKhI3TPrP+5+nb5wvAlmwH21 Ojs9G6br7jdp4tMhamcXOYuRkpyzRvV8MS02eFqLKHhiLD+f/CCcBLKFw+u/jd0g2w0v wyAWk7lOSiPOmVhO/3SSm7Fx/jrFKvQmc4KwwgsSHmLHtyM0iH3fuuVIciGqPN/qaCnk /o6wJp1hL92jvXRjwKoETi+zptyKOfH6XeC7MNEYQAtfaxYXKVAfEH7kz/axiGdxKqeF Ll3YApV4hgjx31fdINhgTOU7fAaf8DQr+VTQ6Cq0rd2OXQNs09UGU6O746kEPBf9Dl0n n1XQ== X-Gm-Message-State: APjAAAXKtISv1AM/FbsBgu24YOTB21LJBwZr/Xm1XatiQ0+7CyixBH8X CuSNAhSIf/aZfx4zotsqrzzTjA== X-Received: by 2002:a05:600c:254c:: with SMTP id e12mr10949332wma.72.1567081092640; Thu, 29 Aug 2019 05:18:12 -0700 (PDT) Received: from localhost (ip-78-45-163-186.net.upcbroadband.cz. [78.45.163.186]) by smtp.gmail.com with ESMTPSA id a17sm2726450wmm.47.2019.08.29.05.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 05:18:12 -0700 (PDT) Date: Thu, 29 Aug 2019 14:18:11 +0200 From: Jiri Pirko To: Horatiu Vultur Cc: alexandre.belloni@bootlin.com, UNGLinuxDriver@microchip.com, davem@davemloft.net, andrew@lunn.ch, allan.nielsen@microchip.com, ivecera@redhat.com, f.fainelli@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/2] net: core: Notify on changes to dev->promiscuity. Message-ID: <20190829121811.GI2312@nanopsycho> References: <1567070549-29255-1-git-send-email-horatiu.vultur@microchip.com> <1567070549-29255-2-git-send-email-horatiu.vultur@microchip.com> <20190829095100.GH2312@nanopsycho> <20190829105650.btgvytgja63sx6wx@soft-dev3.microsemi.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190829105650.btgvytgja63sx6wx@soft-dev3.microsemi.net> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thu, Aug 29, 2019 at 12:56:54PM CEST, horatiu.vultur@microchip.com wrote: >The 08/29/2019 11:51, Jiri Pirko wrote: >> External E-Mail >> >> >> Thu, Aug 29, 2019 at 11:22:28AM CEST, horatiu.vultur@microchip.com wrote: >> >Add the SWITCHDEV_ATTR_ID_PORT_PROMISCUITY switchdev notification type, >> >used to indicate whenever the dev promiscuity counter is changed. >> > >> >The notification doesn't use any switchdev_attr attribute because in the >> >notifier callbacks is it possible to get the dev and read directly >> >the promiscuity value. >> > >> >Signed-off-by: Horatiu Vultur >> >--- >> > include/net/switchdev.h | 1 + >> > net/core/dev.c | 9 +++++++++ >> > 2 files changed, 10 insertions(+) >> > >> >diff --git a/include/net/switchdev.h b/include/net/switchdev.h >> >index aee86a1..14b1617 100644 >> >--- a/include/net/switchdev.h >> >+++ b/include/net/switchdev.h >> >@@ -40,6 +40,7 @@ enum switchdev_attr_id { >> > SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING, >> > SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED, >> > SWITCHDEV_ATTR_ID_BRIDGE_MROUTER, >> >+ SWITCHDEV_ATTR_ID_PORT_PROMISCUITY, >> > }; >> > >> > struct switchdev_attr { >> >diff --git a/net/core/dev.c b/net/core/dev.c >> >index 49589ed..40c74f2 100644 >> >--- a/net/core/dev.c >> >+++ b/net/core/dev.c >> >@@ -142,6 +142,7 @@ >> > #include >> > #include >> > #include >> >+#include >> > >> > #include "net-sysfs.h" >> > >> >@@ -7377,6 +7378,11 @@ static void dev_change_rx_flags(struct net_device *dev, int flags) >> > static int __dev_set_promiscuity(struct net_device *dev, int inc, bool notify) >> > { >> > unsigned int old_flags = dev->flags; >> >+ struct switchdev_attr attr = { >> >+ .orig_dev = dev, >> >+ .id = SWITCHDEV_ATTR_ID_PORT_PROMISCUITY, >> >+ .flags = SWITCHDEV_F_DEFER, >> > >Hi Jiri, > >> NACK >> >> This is invalid usecase for switchdev infra. Switchdev is there for >> bridge offload purposes only. >> >> For promiscuity changes, the infrastructure is already present in the >> code. See __dev_notify_flags(). it calls: >> call_netdevice_notifiers_info(NETDEV_CHANGE, &change_info.info) >> and you can actually see the changed flag in ".flags_changed". >Yes, you are right. But in case the port is part of a bridge and then >enable promisc mode by a user space application(tpcdump) then the drivers If the promisc is on, it is on. Why do you need to know who enabled it? Or do you want to use this to ask driver to ask hw to trap packets to kernel? If yes, I don't think it is correct. If you want to "steal" some packets from the hw forwarding datapath, use TC action "trap". >will not be notified. The reason is that the dev->flags will still be the >same(because IFF_PROMISC was already set) and only promiscuity will be >changed. > >One fix could be to call __dev_notify_flags() no matter when the >promisc is enable or disabled. > >> >> You just have to register netdev notifier block in your driver. Grep >> for: register_netdevice_notifier >> >> >> >+ }; >> > kuid_t uid; >> > kgid_t gid; >> > >> >@@ -7419,6 +7425,9 @@ static int __dev_set_promiscuity(struct net_device *dev, int inc, bool notify) >> > } >> > if (notify) >> > __dev_notify_flags(dev, old_flags, IFF_PROMISC); >> >+ >> >+ switchdev_port_attr_set(dev, &attr); >> >+ >> > return 0; >> > } >> > >> >-- >> >2.7.4 >> > >> > >-- >/Horatiu