Skip to content

Commit

Permalink
Merge branch 'net-fix-a-mcast-issue-for-tipc-udp-media'
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
davem330 committed Aug 5, 2020
2 parents 5845589 + 5a6f6f5 commit 273d405
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/net/addrconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ bool ipv6_chk_custom_prefix(const struct in6_addr *addr,

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

struct net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr);

struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net,
const struct in6_addr *addr,
struct net_device *dev, int strict);
Expand Down
39 changes: 39 additions & 0 deletions net/ipv6/addrconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 8 additions & 0 deletions net/tipc/udp_media.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,21 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
b->mtu = b->media->mtu;
#if IS_ENABLED(CONFIG_IPV6)
} else if (local.proto == htons(ETH_P_IPV6)) {
struct net_device *dev;

dev = ipv6_dev_find(net, &local.ipv6);
if (!dev) {
err = -ENODEV;
goto err;
}
udp_conf.family = AF_INET6;
udp_conf.use_udp6_tx_checksums = true;
udp_conf.use_udp6_rx_checksums = true;
if (rmcast)
udp_conf.local_ip6 = in6addr_any;
else
udp_conf.local_ip6 = local.ipv6;
ub->ifindex = dev->ifindex;
b->mtu = 1280;
#endif
} else {
Expand Down

0 comments on commit 273d405

Please sign in to comment.