Skip to content

Commit 6a6d668

Browse files
Alexis Bauvindavem330
authored andcommitted
l3mdev: add function to retreive upper master
Existing functions to retreive the l3mdev of a device did not walk the master chain to find the upper master. This patch adds a function to find the l3mdev, even indirect through e.g. a bridge: +----------+ | | | vrf-blue | | | +----+-----+ | | +----+-----+ | | | br-blue | | | +----+-----+ | | +----+-----+ | | | eth0 | | | +----------+ This will properly resolve the l3mdev of eth0 to vrf-blue. Signed-off-by: Alexis Bauvin <abauvin@scaleway.com> Reviewed-by: Amine Kherbouche <akherbouche@scaleway.com> Reviewed-by: David Ahern <dsahern@gmail.com> Tested-by: Amine Kherbouche <akherbouche@scaleway.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent da5095d commit 6a6d668

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

include/net/l3mdev.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ struct net_device *l3mdev_master_dev_rcu(const struct net_device *_dev)
101101
return master;
102102
}
103103

104+
int l3mdev_master_upper_ifindex_by_index_rcu(struct net *net, int ifindex);
105+
static inline
106+
int l3mdev_master_upper_ifindex_by_index(struct net *net, int ifindex)
107+
{
108+
rcu_read_lock();
109+
ifindex = l3mdev_master_upper_ifindex_by_index_rcu(net, ifindex);
110+
rcu_read_unlock();
111+
112+
return ifindex;
113+
}
114+
104115
u32 l3mdev_fib_table_rcu(const struct net_device *dev);
105116
u32 l3mdev_fib_table_by_index(struct net *net, int ifindex);
106117
static inline u32 l3mdev_fib_table(const struct net_device *dev)
@@ -207,6 +218,17 @@ static inline int l3mdev_master_ifindex_by_index(struct net *net, int ifindex)
207218
return 0;
208219
}
209220

221+
static inline
222+
int l3mdev_master_upper_ifindex_by_index_rcu(struct net *net, int ifindex)
223+
{
224+
return 0;
225+
}
226+
static inline
227+
int l3mdev_master_upper_ifindex_by_index(struct net *net, int ifindex)
228+
{
229+
return 0;
230+
}
231+
210232
static inline
211233
struct net_device *l3mdev_master_dev_rcu(const struct net_device *dev)
212234
{

net/l3mdev/l3mdev.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ int l3mdev_master_ifindex_rcu(const struct net_device *dev)
4646
}
4747
EXPORT_SYMBOL_GPL(l3mdev_master_ifindex_rcu);
4848

49+
/**
50+
* l3mdev_master_upper_ifindex_by_index - get index of upper l3 master
51+
* device
52+
* @net: network namespace for device index lookup
53+
* @ifindex: targeted interface
54+
*/
55+
int l3mdev_master_upper_ifindex_by_index_rcu(struct net *net, int ifindex)
56+
{
57+
struct net_device *dev;
58+
59+
dev = dev_get_by_index_rcu(net, ifindex);
60+
while (dev && !netif_is_l3_master(dev))
61+
dev = netdev_master_upper_dev_get(dev);
62+
63+
return dev ? dev->ifindex : 0;
64+
}
65+
EXPORT_SYMBOL_GPL(l3mdev_master_upper_ifindex_by_index_rcu);
66+
4967
/**
5068
* l3mdev_fib_table - get FIB table id associated with an L3
5169
* master interface

0 commit comments

Comments
 (0)