From patchwork Tue Feb 16 23:48:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lamparter X-Patchwork-Id: 583772 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id AC173140C17 for ; Wed, 17 Feb 2016 10:48:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933337AbcBPXsm (ORCPT ); Tue, 16 Feb 2016 18:48:42 -0500 Received: from eidolon.nox.tf ([85.239.127.252]:43490 "EHLO eidolon.nox.tf" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933243AbcBPXsl (ORCPT ); Tue, 16 Feb 2016 18:48:41 -0500 X-Greylist: delayed 439 seconds by postgrey-1.27 at vger.kernel.org; Tue, 16 Feb 2016 18:48:41 EST Received: from equinox by eidolon.nox.tf with local (Exim 4.86) (envelope-from ) id 1aVpME-002sZZ-17; Wed, 17 Feb 2016 00:48:39 +0100 From: David Lamparter To: netdev@vger.kernel.org Cc: David Lamparter , David Ahern Subject: [net-next] net: l3mdev: prefer VRF master for source address selection Date: Wed, 17 Feb 2016 00:48:28 +0100 Message-Id: <1455666508-672875-1-git-send-email-equinox@diac24.net> X-Mailer: git-send-email 2.4.10 In-Reply-To: <20160216234115.GI659150@eidolon> References: <20160216234115.GI659150@eidolon> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. Cc: David Ahern Signed-off-by: David Lamparter --- This patch applies on top of the one by dsa@ in the root of this thread. --- net/ipv4/devinet.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 614904c..4ba5790 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -1217,6 +1217,24 @@ __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.