[SRU,Xenial,1/2] net: l3mdev: Add master device lookup by index

Message ID 3cbb1c8a2a19856d7a40fccc57d3adf4c22ffe63.1516637203.git.joseph.salisbury@canonical.com
State New
Headers show
Series
  • Fixes for LP:1744078
Related show

Commit Message

Joseph Salisbury Feb. 1, 2018, 8:58 p.m.
From: David Ahern <dsa@cumulusnetworks.com>

BugLink: http://bugs.launchpad.net/bugs/1744078

Add helper to lookup l3mdev master index given a device index.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 1a8524794fc7c70f44ac28e3a6e8fd637bc41f14)
Signed-off-by: Joseph Salisbury <joseph.salisbury@canonical.com>
---
 include/net/l3mdev.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Patch

diff --git a/include/net/l3mdev.h b/include/net/l3mdev.h
index 5689a0c..5567d46 100644
--- a/include/net/l3mdev.h
+++ b/include/net/l3mdev.h
@@ -51,6 +51,24 @@  static inline int l3mdev_master_ifindex(struct net_device *dev)
 	return ifindex;
 }
 
+static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
+{
+	struct net_device *dev;
+	int rc = 0;
+
+	if (likely(ifindex)) {
+		rcu_read_lock();
+
+		dev = dev_get_by_index_rcu(net, ifindex);
+		if (dev)
+			rc = l3mdev_master_ifindex_rcu(dev);
+
+		rcu_read_unlock();
+	}
+
+	return rc;
+}
+
 /* get index of an interface to use for FIB lookups. For devices
  * enslaved to an L3 master device FIB lookups are based on the
  * master index
@@ -170,6 +188,11 @@  static inline int l3mdev_master_ifindex(struct net_device *dev)
 	return 0;
 }
 
+static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
+{
+	return 0;
+}
+
 static inline int l3mdev_fib_oif_rcu(struct net_device *dev)
 {
 	return dev ? dev->ifindex : 0;