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>] [day] [month] [year] [list]
Date:   Fri, 10 Mar 2017 10:53:06 +0800
From:   fgao@...ai8.com
To:     davem@...emloft.net, kuznet@....inr.ac.ru, jmorris@...ei.org,
        kaber@...sh.net, netdev@...r.kernel.org, gfree.wind@...il.com
Cc:     Gao Feng <fgao@...ai8.com>
Subject: [PATCH v3 net-next 2/2] net: Eliminate duplicated codes by creating one new function in_dev_select_addr

From: Gao Feng <fgao@...ai8.com>

There are two duplicated loops codes which used to select right
address in current codes. Now eliminate these codes by creating
one new function in_dev_select_addr.

Signed-off-by: Gao Feng <fgao@...ai8.com>
---
 v3: Add cover letter
 v2: Correct the comit log and remove useless braces, per Sergei
 v1: Initial Version 

 net/ipv4/devinet.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 1a9e550..f82d545 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1191,6 +1191,18 @@ static int inet_gifconf(struct net_device *dev, char __user *buf, int len)
 	return done;
 }
 
+static __be32 in_dev_select_addr(const struct in_device *in_dev,
+				 int scope)
+{
+	for_primary_ifa(in_dev) {
+		if (ifa->ifa_scope != RT_SCOPE_LINK &&
+		    ifa->ifa_scope <= scope)
+			return ifa->ifa_local;
+	} endfor_ifa(in_dev);
+
+	return 0;
+}
+
 __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
 {
 	__be32 addr = 0;
@@ -1229,13 +1241,9 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
 		if (dev) {
 			in_dev = __in_dev_get_rcu(dev);
 			if (in_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);
+				addr = in_dev_select_addr(in_dev, scope);
+				if (addr)
+					goto out_unlock;
 			}
 		}
 
@@ -1250,14 +1258,9 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
 			in_dev = __in_dev_get_rcu(dev);
 			if (!in_dev)
 				continue;
-
-			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);
+			addr = in_dev_select_addr(in_dev, scope);
+			if (addr)
+				goto out_unlock;
 		}
 	}
 out_unlock:
-- 
1.9.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ