Commit 8b57fd1e authored by Gao Feng's avatar Gao Feng Committed by David S. Miller

net: Eliminate duplicated codes by creating one new function in_dev_select_addr

There are two duplicated loops codes which used to select right
address in current codes. Now eliminate these codes by creating
one new function in_dev_select_addr.
Signed-off-by: default avatarGao Feng <fgao@ikuai8.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 81663bee
...@@ -1192,6 +1192,18 @@ static int inet_gifconf(struct net_device *dev, char __user *buf, int len) ...@@ -1192,6 +1192,18 @@ static int inet_gifconf(struct net_device *dev, char __user *buf, int len)
return done; return done;
} }
static __be32 in_dev_select_addr(const struct in_device *in_dev,
int scope)
{
for_primary_ifa(in_dev) {
if (ifa->ifa_scope != RT_SCOPE_LINK &&
ifa->ifa_scope <= scope)
return ifa->ifa_local;
} endfor_ifa(in_dev);
return 0;
}
__be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
{ {
__be32 addr = 0; __be32 addr = 0;
...@@ -1228,13 +1240,9 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) ...@@ -1228,13 +1240,9 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
if (master_idx && if (master_idx &&
(dev = dev_get_by_index_rcu(net, master_idx)) && (dev = dev_get_by_index_rcu(net, master_idx)) &&
(in_dev = __in_dev_get_rcu(dev))) { (in_dev = __in_dev_get_rcu(dev))) {
for_primary_ifa(in_dev) { addr = in_dev_select_addr(in_dev, scope);
if (ifa->ifa_scope != RT_SCOPE_LINK && if (addr)
ifa->ifa_scope <= scope) { goto out_unlock;
addr = ifa->ifa_local;
goto out_unlock;
}
} endfor_ifa(in_dev);
} }
/* Not loopback addresses on loopback should be preferred /* Not loopback addresses on loopback should be preferred
...@@ -1249,13 +1257,9 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) ...@@ -1249,13 +1257,9 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
if (!in_dev) if (!in_dev)
continue; continue;
for_primary_ifa(in_dev) { addr = in_dev_select_addr(in_dev, scope);
if (ifa->ifa_scope != RT_SCOPE_LINK && if (addr)
ifa->ifa_scope <= scope) { goto out_unlock;
addr = ifa->ifa_local;
goto out_unlock;
}
} endfor_ifa(in_dev);
} }
out_unlock: out_unlock:
rcu_read_unlock(); rcu_read_unlock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment