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]
Date:   Tue, 14 Dec 2021 18:27:29 +0100
From:   Florian Westphal <fw@...len.de>
To:     netdev@...r.kernel.org
Cc:     davem@...emloft.net, kuba@...nel.org, dsahern@...nel.org,
        Florian Westphal <fw@...len.de>
Subject: [PATCH v2 net-next 2/4] fib: place common code in a helper

After moving the ipv4/ipv6 helpers to the core, there is some
overlapping code that can be collapsed into a helper.

This change has no effect on generated code.

Signed-off-by: Florian Westphal <fw@...len.de>
---
 v2: IPV6=n ifdef for fib6_rule_suppress helper.

 net/core/fib_rules.c | 62 +++++++++++++++++++++-----------------------
 1 file changed, 30 insertions(+), 32 deletions(-)

diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 52e67f8aa0c5..c763b69eea8c 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -291,6 +291,25 @@ static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
 	return (rule->flags & FIB_RULE_INVERT) ? !ret : ret;
 }
 
+static bool fib_rule_should_suppress(const struct fib_rule *rule,
+				     const struct net_device *dev,
+				     int prefixlen)
+{
+	/* do not accept result if the route does
+	 * not meet the required prefix length
+	 */
+	if (prefixlen <= rule->suppress_prefixlen)
+		return true;
+
+	/* do not accept result if the route uses a device
+	 * belonging to a forbidden interface group
+	 */
+	if (rule->suppress_ifgroup != -1 && dev && dev->group == rule->suppress_ifgroup)
+		return true;
+
+	return false;
+}
+
 static bool fib4_rule_suppress(struct fib_rule *rule,
 			       int flags,
 			       struct fib_lookup_arg *arg)
@@ -304,30 +323,19 @@ static bool fib4_rule_suppress(struct fib_rule *rule,
 		dev = nhc->nhc_dev;
 	}
 
-	/* do not accept result if the route does
-	 * not meet the required prefix length
-	 */
-	if (result->prefixlen <= rule->suppress_prefixlen)
-		goto suppress_route;
-
-	/* do not accept result if the route uses a device
-	 * belonging to a forbidden interface group
-	 */
-	if (rule->suppress_ifgroup != -1 && dev && dev->group == rule->suppress_ifgroup)
-		goto suppress_route;
-
+	if (fib_rule_should_suppress(rule, dev, result->prefixlen)) {
+		if (!(arg->flags & FIB_LOOKUP_NOREF))
+			fib_info_put(result->fi);
+		return true;
+	}
 	return false;
-
-suppress_route:
-	if (!(arg->flags & FIB_LOOKUP_NOREF))
-		fib_info_put(result->fi);
-	return true;
 }
 
 static bool fib6_rule_suppress(struct fib_rule *rule,
 			       int flags,
 			       struct fib_lookup_arg *arg)
 {
+#if IS_ENABLED(CONFIG_IPV6)
 	struct fib6_result *res = arg->result;
 	struct rt6_info *rt = res->rt6;
 	struct net_device *dev = NULL;
@@ -338,23 +346,13 @@ static bool fib6_rule_suppress(struct fib_rule *rule,
 	if (rt->rt6i_idev)
 		dev = rt->rt6i_idev->dev;
 
-	/* do not accept result if the route does
-	 * not meet the required prefix length
-	 */
-	if (rt->rt6i_dst.plen <= rule->suppress_prefixlen)
-		goto suppress_route;
-
-	/* do not accept result if the route uses a device
-	 * belonging to a forbidden interface group
-	 */
-	if (rule->suppress_ifgroup != -1 && dev && dev->group == rule->suppress_ifgroup)
-		goto suppress_route;
+	if (fib_rule_should_suppress(rule, dev, rt->rt6i_dst.plen)) {
+		ip6_rt_put_flags(rt, flags);
+		return true;
+	}
 
+#endif
 	return false;
-
-suppress_route:
-	ip6_rt_put_flags(rt, flags);
-	return true;
 }
 
 static bool fib_rule_suppress(int family,
-- 
2.32.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ