netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexis Bauvin <abauvin@scaleway.com>
To: dsa@cumulusnetworks.com, roopa@cumulusnetworks.com,
	stephen@networkplumber.org
Cc: netdev@vger.kernel.org, abauvin@scaleway.com, akherbouche@scaleway.com
Subject: [PATCH v5 4/6] netdev: add netdev_is_upper_master
Date: Tue, 27 Nov 2018 02:03:55 +0100	[thread overview]
Message-ID: <20181127010357.59070-5-abauvin@scaleway.com> (raw)
In-Reply-To: <20181127010357.59070-1-abauvin@scaleway.com>

In preparation of next patch, this function allows to check if a device
is a master, be it direct or indirect, of another one. It walks up the
master chain until it finds the device, or there is no more master.

This allows to check e.g. if br-blue is a master of eth0:

   +----------+
   | vrf-blue |
   +----+-----+
        |
   +----+----+
   | br-blue |
   +----+----+
        |
    +---+---+
    | bond0 |
    +--+-+--+
       | |
    +--+ +--+
    |       |
+---+--+ +--+---+
| eth0 | | eth1 |
+------+ +------+

Signed-off-by: Alexis Bauvin <abauvin@scaleway.com>
Reviewed-by: Amine Kherbouche <akherbouche@scaleway.com>
Tested-by: Amine Kherbouche <akherbouche@scaleway.com>
---
 include/linux/netdevice.h |  1 +
 net/core/dev.c            | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d837dad24b4c..102f79337d7c 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -4212,6 +4212,7 @@ void *netdev_lower_dev_get_private(struct net_device *dev,
 				   struct net_device *lower_dev);
 void netdev_lower_state_changed(struct net_device *lower_dev,
 				void *lower_state_info);
+bool netdev_is_upper_master(struct net_device *dev, struct net_device *master);
 
 /* RSS keys are 40 or 52 bytes long */
 #define NETDEV_RSS_KEY_LEN 52
diff --git a/net/core/dev.c b/net/core/dev.c
index 93243479085f..9222434a5332 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7225,6 +7225,23 @@ void netdev_lower_state_changed(struct net_device *lower_dev,
 }
 EXPORT_SYMBOL(netdev_lower_state_changed);
 
+/**
+ * netdev_is_upper_master - Test if a device is a master, direct or indirect,
+ *                          of another one.
+ * @dev: device to start looking from
+ * @master: device to test if master of dev
+ */
+bool netdev_is_upper_master(struct net_device *dev, struct net_device *master)
+{
+	if (!dev)
+		return false;
+
+	if (dev == master)
+		return true;
+	return netdev_is_upper_master(netdev_master_upper_dev_get(dev), master);
+}
+EXPORT_SYMBOL(netdev_is_upper_master);
+
 static void dev_change_rx_flags(struct net_device *dev, int flags)
 {
 	const struct net_device_ops *ops = dev->netdev_ops;
-- 

  parent reply	other threads:[~2018-11-27 12:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27  1:03 [PATCH v5 0/6] Add VRF support for VXLAN underlay Alexis Bauvin
2018-11-27  1:03 ` [PATCH v5 1/6] udp_tunnel: add config option to bind to a device Alexis Bauvin
2018-11-27  1:03 ` [PATCH v5 2/6] l3mdev: add function to retreive upper master Alexis Bauvin
2018-11-27  1:03 ` [PATCH v5 3/6] vxlan: add support for underlay in non-default VRF Alexis Bauvin
2018-11-27  1:03 ` Alexis Bauvin [this message]
2018-11-27  1:03 ` [PATCH v5 5/6] vxlan: handle underlay VRF changes Alexis Bauvin
2018-11-27  5:58   ` Roopa Prabhu
2018-11-27 12:55     ` Alexis Bauvin
2018-11-27  1:03 ` [PATCH v5 6/6] test/net: Add script for VXLAN underlay in a VRF Alexis Bauvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181127010357.59070-5-abauvin@scaleway.com \
    --to=abauvin@scaleway.com \
    --cc=akherbouche@scaleway.com \
    --cc=dsa@cumulusnetworks.com \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@cumulusnetworks.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).