diff options
author | Gao Feng <fgao@ikuai8.com> | 2017-03-10 12:38:47 +0800 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-03-12 23:27:09 -0700 |
commit | 8b57fd1ec13e22b3e722891ff7a6e6ccaf286779 (patch) | |
tree | 7e051e9e2239617718f634c8aeda8f7aca8164b5 /net/ipv4/devinet.c | |
parent | 81663bee1676d1ecbd3281e2c752a1b6f6e133b9 (diff) | |
download | op-kernel-dev-8b57fd1ec13e22b3e722891ff7a6e6ccaf286779.zip op-kernel-dev-8b57fd1ec13e22b3e722891ff7a6e6ccaf286779.tar.gz |
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: Gao Feng <fgao@ikuai8.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/devinet.c')
-rw-r--r-- | net/ipv4/devinet.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index cebedd5..927f1d4 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -1192,6 +1192,18 @@ out: 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 addr = 0; @@ -1228,13 +1240,9 @@ no_in_dev: if (master_idx && (dev = dev_get_by_index_rcu(net, master_idx)) && (in_dev = __in_dev_get_rcu(dev))) { - for_primary_ifa(in_dev) { - if (ifa->ifa_scope != RT_SCOPE_LINK && - ifa->ifa_scope <= scope) { - addr = ifa->ifa_local; - goto out_unlock; - } - } endfor_ifa(in_dev); + addr = in_dev_select_addr(in_dev, scope); + if (addr) + goto out_unlock; } /* Not loopback addresses on loopback should be preferred @@ -1249,13 +1257,9 @@ no_in_dev: if (!in_dev) continue; - for_primary_ifa(in_dev) { - if (ifa->ifa_scope != RT_SCOPE_LINK && - ifa->ifa_scope <= scope) { - addr = ifa->ifa_local; - goto out_unlock; - } - } endfor_ifa(in_dev); + addr = in_dev_select_addr(in_dev, scope); + if (addr) + goto out_unlock; } out_unlock: rcu_read_unlock(); |