mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
ipv6: some fixes for ipv6_dev_find()
This patch is to do 3 things for ipv6_dev_find():
As David A. noticed,
- rt6_lookup() is not really needed. Different from __ip_dev_find(),
ipv6_dev_find() doesn't have a compatibility problem, so remove it.
As Hideaki suggested,
- "valid" (non-tentative) check for the address is also needed.
ipv6_chk_addr() calls ipv6_chk_addr_and_flags(), which will
traverse the address hash list, but it's heavy to be called
inside ipv6_dev_find(). This patch is to reuse the code of
ipv6_chk_addr_and_flags() for ipv6_dev_find().
- dev parameter is passed into ipv6_dev_find(), as link-local
addresses from user space has sin6_scope_id set and the dev
lookup needs it.
Fixes: 81f6cb3122
("ipv6: add ipv6_dev_find()")
Suggested-by: YOSHIFUJI Hideaki <hideaki.yoshifuji@miraclelinux.com>
Reported-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
0410d07190
commit
4ef1a7cb08
@@ -97,7 +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);
|
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 net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr,
|
||||||
|
struct net_device *dev);
|
||||||
|
|
||||||
struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net,
|
struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net,
|
||||||
const struct in6_addr *addr,
|
const struct in6_addr *addr,
|
||||||
|
@@ -1893,12 +1893,13 @@ EXPORT_SYMBOL(ipv6_chk_addr);
|
|||||||
* 2. does the address exist on the specific device
|
* 2. does the address exist on the specific device
|
||||||
* (skip_dev_check = false)
|
* (skip_dev_check = false)
|
||||||
*/
|
*/
|
||||||
int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
|
static struct net_device *
|
||||||
const struct net_device *dev, bool skip_dev_check,
|
__ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
|
||||||
int strict, u32 banned_flags)
|
const struct net_device *dev, bool skip_dev_check,
|
||||||
|
int strict, u32 banned_flags)
|
||||||
{
|
{
|
||||||
unsigned int hash = inet6_addr_hash(net, addr);
|
unsigned int hash = inet6_addr_hash(net, addr);
|
||||||
const struct net_device *l3mdev;
|
struct net_device *l3mdev, *ndev;
|
||||||
struct inet6_ifaddr *ifp;
|
struct inet6_ifaddr *ifp;
|
||||||
u32 ifp_flags;
|
u32 ifp_flags;
|
||||||
|
|
||||||
@@ -1909,10 +1910,11 @@ int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
|
|||||||
dev = NULL;
|
dev = NULL;
|
||||||
|
|
||||||
hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
|
hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
|
||||||
if (!net_eq(dev_net(ifp->idev->dev), net))
|
ndev = ifp->idev->dev;
|
||||||
|
if (!net_eq(dev_net(ndev), net))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (l3mdev_master_dev_rcu(ifp->idev->dev) != l3mdev)
|
if (l3mdev_master_dev_rcu(ndev) != l3mdev)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Decouple optimistic from tentative for evaluation here.
|
/* Decouple optimistic from tentative for evaluation here.
|
||||||
@@ -1923,15 +1925,23 @@ int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
|
|||||||
: ifp->flags;
|
: ifp->flags;
|
||||||
if (ipv6_addr_equal(&ifp->addr, addr) &&
|
if (ipv6_addr_equal(&ifp->addr, addr) &&
|
||||||
!(ifp_flags&banned_flags) &&
|
!(ifp_flags&banned_flags) &&
|
||||||
(!dev || ifp->idev->dev == dev ||
|
(!dev || ndev == dev ||
|
||||||
!(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
|
!(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
return 1;
|
return ndev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
return 0;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
|
||||||
|
const struct net_device *dev, bool skip_dev_check,
|
||||||
|
int strict, u32 banned_flags)
|
||||||
|
{
|
||||||
|
return __ipv6_chk_addr_and_flags(net, addr, dev, skip_dev_check,
|
||||||
|
strict, banned_flags) ? 1 : 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(ipv6_chk_addr_and_flags);
|
EXPORT_SYMBOL(ipv6_chk_addr_and_flags);
|
||||||
|
|
||||||
@@ -1990,35 +2000,11 @@ EXPORT_SYMBOL(ipv6_chk_prefix);
|
|||||||
*
|
*
|
||||||
* The caller should be protected by RCU, or RTNL.
|
* The caller should be protected by RCU, or RTNL.
|
||||||
*/
|
*/
|
||||||
struct net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr)
|
struct net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr,
|
||||||
|
struct net_device *dev)
|
||||||
{
|
{
|
||||||
unsigned int hash = inet6_addr_hash(net, addr);
|
return __ipv6_chk_addr_and_flags(net, addr, dev, !dev, 1,
|
||||||
struct inet6_ifaddr *ifp, *result = NULL;
|
IFA_F_TENTATIVE);
|
||||||
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);
|
EXPORT_SYMBOL(ipv6_dev_find);
|
||||||
|
|
||||||
|
@@ -660,6 +660,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
|
|||||||
struct udp_tunnel_sock_cfg tuncfg = {NULL};
|
struct udp_tunnel_sock_cfg tuncfg = {NULL};
|
||||||
struct nlattr *opts[TIPC_NLA_UDP_MAX + 1];
|
struct nlattr *opts[TIPC_NLA_UDP_MAX + 1];
|
||||||
u8 node_id[NODE_ID_LEN] = {0,};
|
u8 node_id[NODE_ID_LEN] = {0,};
|
||||||
|
struct net_device *dev;
|
||||||
int rmcast = 0;
|
int rmcast = 0;
|
||||||
|
|
||||||
ub = kzalloc(sizeof(*ub), GFP_ATOMIC);
|
ub = kzalloc(sizeof(*ub), GFP_ATOMIC);
|
||||||
@@ -714,8 +715,6 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
|
|||||||
rcu_assign_pointer(ub->bearer, b);
|
rcu_assign_pointer(ub->bearer, b);
|
||||||
tipc_udp_media_addr_set(&b->addr, &local);
|
tipc_udp_media_addr_set(&b->addr, &local);
|
||||||
if (local.proto == htons(ETH_P_IP)) {
|
if (local.proto == htons(ETH_P_IP)) {
|
||||||
struct net_device *dev;
|
|
||||||
|
|
||||||
dev = __ip_dev_find(net, local.ipv4.s_addr, false);
|
dev = __ip_dev_find(net, local.ipv4.s_addr, false);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
@@ -738,9 +737,8 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
|
|||||||
b->mtu = b->media->mtu;
|
b->mtu = b->media->mtu;
|
||||||
#if IS_ENABLED(CONFIG_IPV6)
|
#if IS_ENABLED(CONFIG_IPV6)
|
||||||
} else if (local.proto == htons(ETH_P_IPV6)) {
|
} else if (local.proto == htons(ETH_P_IPV6)) {
|
||||||
struct net_device *dev;
|
dev = ub->ifindex ? __dev_get_by_index(net, ub->ifindex) : NULL;
|
||||||
|
dev = ipv6_dev_find(net, &local.ipv6, dev);
|
||||||
dev = ipv6_dev_find(net, &local.ipv6);
|
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto err;
|
goto err;
|
||||||
|
Reference in New Issue
Block a user