diff options
author | David S. Miller <davem@davemloft.net> | 2020-08-05 12:19:52 -0700 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2020-08-05 12:19:52 -0700 |
commit | 273d405b4d5657dd2ad9aa6381e94ef63bb71423 (patch) | |
tree | 6ad38dd8f878d015d35e6785416c4043070a4aec /net/ipv6/addrconf.c | |
parent | 5845589ed652da9b65833044bd2d0bcb1d676ed0 (diff) | |
parent | 5a6f6f579178dbeb33002d93b4f646c31348fac9 (diff) |
Merge branch 'net-fix-a-mcast-issue-for-tipc-udp-media'
Xin Long says:
====================
net: fix a mcast issue for tipc udp media
Patch 1 is to add a function to get the dev by source address,
which will be used by Patch 2.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/addrconf.c')
-rw-r--r-- | net/ipv6/addrconf.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 0acf6a9796ca..8e761b8c47c6 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1983,6 +1983,45 @@ int ipv6_chk_prefix(const struct in6_addr *addr, struct net_device *dev) } EXPORT_SYMBOL(ipv6_chk_prefix); +/** + * ipv6_dev_find - find the first device with a given source address. + * @net: the net namespace + * @addr: the source address + * + * The caller should be protected by RCU, or RTNL. + */ +struct net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr) +{ + unsigned int hash = inet6_addr_hash(net, addr); + struct inet6_ifaddr *ifp, *result = NULL; + struct net_device *dev = NULL; + + rcu_read_lock(); + hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) { + if (net_eq(dev_net(ifp->idev->dev), net) && + ipv6_addr_equal(&ifp->addr, addr)) { + result = ifp; + break; + } + } + + if (!result) { + struct rt6_info *rt; + + rt = rt6_lookup(net, addr, NULL, 0, NULL, 0); + if (rt) { + dev = rt->dst.dev; + ip6_rt_put(rt); + } + } else { + dev = result->idev->dev; + } + rcu_read_unlock(); + + return dev; +} +EXPORT_SYMBOL(ipv6_dev_find); + struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr, struct net_device *dev, int strict) { |