netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: luoshijie <luoshijie1@huawei.com>
To: <davem@davemloft.net>, <tgraf@suug.ch>, <dsahern@gmail.com>
Cc: <netdev@vger.kernel.org>, <liuzhiqiang26@huawei.com>,
	<wangxiaogang3@huawei.com>, <mingfangsen@huawei.com>,
	<zhoukang7@huawei.com>
Subject: [PATCH v2 2/3] ipv4: fix confirm_addr_indev() when enable route_localnet
Date: Tue, 18 Jun 2019 15:14:04 +0000	[thread overview]
Message-ID: <1560870845-172395-3-git-send-email-luoshijie1@huawei.com> (raw)
In-Reply-To: <1560870845-172395-1-git-send-email-luoshijie1@huawei.com>

From: Shijie Luo <luoshijie1@huawei.com>

When arp_ignore=3, the NIC won't reply for scope host addresses, but
if enable route_locanet, we need to reply ip address with head 127 and
scope RT_SCOPE_HOST.

Fixes: d0daebc3d622 ("ipv4: Add interface option to enable routing of 127.0.0.0/8")

Signed-off-by: Shijie Luo <luoshijie1@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
 net/ipv4/devinet.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 08c6c7c41749..cfef8df59373 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1321,13 +1321,18 @@ EXPORT_SYMBOL(inet_select_addr);
 static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst,
 			      __be32 local, int scope)
 {
+	unsigned char localnet_scope = RT_SCOPE_HOST;
 	int same = 0;
 	__be32 addr = 0;
 
+	if (unlikely(IN_DEV_ROUTE_LOCALNET(in_dev)))
+		localnet_scope = RT_SCOPE_LINK;
+
 	for_ifa(in_dev) {
+		unsigned char min_scope = min(ifa->ifa_scope, localnet_scope);
 		if (!addr &&
 		    (local == ifa->ifa_local || !local) &&
-		    ifa->ifa_scope <= scope) {
+		    min_scope <= scope) {
 			addr = ifa->ifa_local;
 			if (same)
 				break;
@@ -1342,7 +1347,7 @@ static __be32 confirm_addr_indev(struct in_device *in_dev, __be32 dst,
 				if (inet_ifa_match(addr, ifa))
 					break;
 				/* No, then can we use new local src? */
-				if (ifa->ifa_scope <= scope) {
+				if (min_scope <= scope) {
 					addr = ifa->ifa_local;
 					break;
 				}
-- 
2.19.1


  parent reply	other threads:[~2019-06-18 13:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-18 15:14 [PATCH v2 0/3] fix bugs when enable route_localnet luoshijie
2019-06-18 15:14 ` [PATCH v2 1/3] ipv4: fix inet_select_addr() " luoshijie
2019-06-18 15:14 ` luoshijie [this message]
2019-06-18 15:14 ` [PATCH v2 3/3] selftests: add route_localnet test script luoshijie
2019-06-22  8:41 ` [PATCH v2 0/3] fix bugs when enable route_localnet Zhiqiang Liu
2019-06-22 12:46   ` David Miller
2019-06-24  1:19     ` Zhiqiang Liu
2019-06-24  3:47     ` David Ahern
2019-06-24 16:03 ` David Miller
2019-06-25  1:25   ` Zhiqiang Liu
2019-06-25  1:50   ` Luoshijie (Poincare Lab)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1560870845-172395-3-git-send-email-luoshijie1@huawei.com \
    --to=luoshijie1@huawei.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=liuzhiqiang26@huawei.com \
    --cc=mingfangsen@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    --cc=wangxiaogang3@huawei.com \
    --cc=zhoukang7@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).