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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200610034953.28861-3-dsahern@kernel.org>
Date:   Tue,  9 Jun 2020 21:49:47 -0600
From:   David Ahern <dsahern@...nel.org>
To:     netdev@...r.kernel.org
Cc:     davem@...emloft.net, kuba@...nel.org, assogba.emery@...il.com,
        dsahern@...il.com, David Ahern <dsahern@...nel.org>
Subject: [PATCH RFC net-next 2/8] nexthop: Refactor nexthop_select_path

Move the ipv{4,6}_good_nh calls to a separate helper.

Signed-off-by: David Ahern <dsahern@...nel.org>
---
 net/ipv4/nexthop.c | 47 +++++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 5ebc47d5ec56..7d0a170821f3 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -536,6 +536,29 @@ static bool ipv4_good_nh(const struct fib_nh *nh)
 	return !!(state & NUD_VALID);
 }
 
+/* nexthops always check if it is good and does
+ * not rely on a sysctl for this behavior
+ */
+static bool good_nh(struct nexthop *nh)
+{
+	struct nh_info *nhi;
+	bool rc = false;
+
+	nhi = rcu_dereference(nh->nh_info);
+	switch (nhi->family) {
+	case AF_INET:
+		if (ipv4_good_nh(&nhi->fib_nh))
+			rc = true;
+		break;
+	case AF_INET6:
+		if (ipv6_good_nh(&nhi->fib6_nh))
+			rc = true;
+		break;
+	}
+
+	return rc;
+}
+
 struct nexthop *nexthop_select_path(struct nexthop *nh, int hash)
 {
 	struct nexthop *rc = NULL;
@@ -548,31 +571,17 @@ struct nexthop *nexthop_select_path(struct nexthop *nh, int hash)
 	nhg = rcu_dereference(nh->nh_grp);
 	for (i = 0; i < nhg->num_nh; ++i) {
 		struct nh_grp_entry *nhge = &nhg->nh_entries[i];
-		struct nh_info *nhi;
+		struct nexthop *nh;
 
 		if (hash > atomic_read(&nhge->upper_bound))
 			continue;
 
-		if (nhge->nh->is_fdb_nh)
-			return nhge->nh;
-
-		/* nexthops always check if it is good and does
-		 * not rely on a sysctl for this behavior
-		 */
-		nhi = rcu_dereference(nhge->nh->nh_info);
-		switch (nhi->family) {
-		case AF_INET:
-			if (ipv4_good_nh(&nhi->fib_nh))
-				return nhge->nh;
-			break;
-		case AF_INET6:
-			if (ipv6_good_nh(&nhi->fib6_nh))
-				return nhge->nh;
-			break;
-		}
+		nh = nhge->nh;
+		if (nh->is_fdb_nh || good_nh(nh))
+			return nh;
 
 		if (!rc)
-			rc = nhge->nh;
+			rc = nh;
 	}
 
 	return rc;
-- 
2.21.1 (Apple Git-122.3)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ