summaryrefslogtreecommitdiff
path: root/net/ipv4/devinet.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2016-02-24 22:47:03 +0300
committerDavid S. Miller <davem@davemloft.net>2016-02-26 22:22:26 +0300
commit17b693cdd87635ae813ad61ad0b8a8458f4c3960 (patch)
treebcc1fba749c6ac53e1f4af1d5ccf8972ec5c8f45 /net/ipv4/devinet.c
parent3f2fb9a834cb1fcddbae22deca7fde136944dc89 (diff)
downloadlinux-17b693cdd87635ae813ad61ad0b8a8458f4c3960.tar.xz
net: l3mdev: prefer VRF master for source address selection
When selecting an address in context of a VRF, the vrf master should be preferred for address selection. If it isn't, the user has a hard time getting the system to select to their preference - the code will pick the address off the first in-VRF interface it can find, which on a router could well be a non-routable address. Signed-off-by: David Lamparter <equinox@diac24.net> Signed-off-by: David Ahern <dsa@cumulusnetworks.com> [dsa: Fixed comment style and removed extra blank link ] Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/devinet.c')
-rw-r--r--net/ipv4/devinet.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 18d510fa7ee2..8c3df2ccba45 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1217,6 +1217,23 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
no_in_dev:
master_idx = l3mdev_master_ifindex_rcu(dev);
+ /* For VRFs, the VRF device takes the place of the loopback device,
+ * with addresses on it being preferred. Note in such cases the
+ * loopback device will be among the devices that fail the master_idx
+ * equality check in the loop below.
+ */
+ 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);
+ }
+
/* Not loopback addresses on loopback should be preferred
in this case. It is important that lo is the first interface
in dev_base list.