lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1314908454-14359-1-git-send-email-jeff_harris@kentrox.com>
Date:	Thu,  1 Sep 2011 16:20:54 -0400
From:	Jeff Harris <jeff_harris@...trox.com>
To:	"David S. Miller" <davem@...emloft.net>,
	Alexey Kuznetsov <kuznet@....inr.ac.ru>,
	James Morris <jmorris@...ei.org>,
	Hideaki YOSHIFUJI <yoshfuji@...ux-ipv6.org>,
	Patrick McHardy <kaber@...sh.net>, netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc:	Jeff Harris <jeff_harris@...trox.com>
Subject: [PATCH] net: Prefer non link-local source addresses

Section 2.6.1 of RFC 3927 specifies that if link-local and routable addresses
are available on an interface, a routable address is preferred.  Update the
IPv4 source address selection algorithm to use a 169.254.x.x address only if
another matching address is not found.

Tested combinations of configured IP addresses with and without link-local to
verify a link-local address was chosen only if no routable address was
present.

Signed-off-by: Jeff Harris <jeff_harris@...trox.com>
---
 net/ipv4/devinet.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index bc19bd0..70ddf37 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -965,6 +965,8 @@ out:
 __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
 {
 	__be32 addr = 0;
+	__be32 lladdr = 0;
+	__be32 firstaddr = 0;
 	struct in_device *in_dev;
 	struct net *net = dev_net(dev);
 
@@ -977,15 +979,27 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
 		if (ifa->ifa_scope > scope)
 			continue;
 		if (!dst || inet_ifa_match(dst, ifa)) {
+			if (ipv4_is_linklocal_169(ifa->ifa_address)) {
+				lladdr = ifa->ifa_local;
+				continue;
+			}
 			addr = ifa->ifa_local;
 			break;
 		}
-		if (!addr)
-			addr = ifa->ifa_local;
+		if (!firstaddr)
+			firstaddr = ifa->ifa_local;
 	} endfor_ifa(in_dev);
 
 	if (addr)
 		goto out_unlock;
+	if (lladdr) {
+		addr = lladdr;
+		goto out_unlock;
+	}
+	if (firstaddr) {
+		addr = firstaddr;
+		goto out_unlock;
+	}
 no_in_dev:
 
 	/* Not loopback addresses on loopback should be preferred
-- 
1.7.0.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ