Skip to content

Commit 273d405

Browse files
committed
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 <[email protected]>
2 parents 5845589 + 5a6f6f5 commit 273d405

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

include/net/addrconf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ bool ipv6_chk_custom_prefix(const struct in6_addr *addr,
9797

9898
int ipv6_chk_prefix(const struct in6_addr *addr, struct net_device *dev);
9999

100+
struct net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr);
101+
100102
struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net,
101103
const struct in6_addr *addr,
102104
struct net_device *dev, int strict);

net/ipv6/addrconf.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,45 @@ int ipv6_chk_prefix(const struct in6_addr *addr, struct net_device *dev)
19831983
}
19841984
EXPORT_SYMBOL(ipv6_chk_prefix);
19851985

1986+
/**
1987+
* ipv6_dev_find - find the first device with a given source address.
1988+
* @net: the net namespace
1989+
* @addr: the source address
1990+
*
1991+
* The caller should be protected by RCU, or RTNL.
1992+
*/
1993+
struct net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr)
1994+
{
1995+
unsigned int hash = inet6_addr_hash(net, addr);
1996+
struct inet6_ifaddr *ifp, *result = NULL;
1997+
struct net_device *dev = NULL;
1998+
1999+
rcu_read_lock();
2000+
hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
2001+
if (net_eq(dev_net(ifp->idev->dev), net) &&
2002+
ipv6_addr_equal(&ifp->addr, addr)) {
2003+
result = ifp;
2004+
break;
2005+
}
2006+
}
2007+
2008+
if (!result) {
2009+
struct rt6_info *rt;
2010+
2011+
rt = rt6_lookup(net, addr, NULL, 0, NULL, 0);
2012+
if (rt) {
2013+
dev = rt->dst.dev;
2014+
ip6_rt_put(rt);
2015+
}
2016+
} else {
2017+
dev = result->idev->dev;
2018+
}
2019+
rcu_read_unlock();
2020+
2021+
return dev;
2022+
}
2023+
EXPORT_SYMBOL(ipv6_dev_find);
2024+
19862025
struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr,
19872026
struct net_device *dev, int strict)
19882027
{

net/tipc/udp_media.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,21 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
738738
b->mtu = b->media->mtu;
739739
#if IS_ENABLED(CONFIG_IPV6)
740740
} else if (local.proto == htons(ETH_P_IPV6)) {
741+
struct net_device *dev;
742+
743+
dev = ipv6_dev_find(net, &local.ipv6);
744+
if (!dev) {
745+
err = -ENODEV;
746+
goto err;
747+
}
741748
udp_conf.family = AF_INET6;
742749
udp_conf.use_udp6_tx_checksums = true;
743750
udp_conf.use_udp6_rx_checksums = true;
744751
if (rmcast)
745752
udp_conf.local_ip6 = in6addr_any;
746753
else
747754
udp_conf.local_ip6 = local.ipv6;
755+
ub->ifindex = dev->ifindex;
748756
b->mtu = 1280;
749757
#endif
750758
} else {

0 commit comments

Comments
 (0)