diff mbox series

[v2,2/3] ipv4: fix confirm_addr_indev() when enable route_localnet

Message ID 1560870845-172395-3-git-send-email-luoshijie1@huawei.com
State Accepted
Delegated to: David Miller
Headers show
Series fix bugs when enable route_localnet | expand

Commit Message

Shijie Luo June 18, 2019, 3:14 p.m. UTC
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 mbox series

Patch

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;
 				}