[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211213153147.17635-3-fw@strlen.de>
Date: Mon, 13 Dec 2021 16:31:45 +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 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>
---
net/core/fib_rules.c | 60 +++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 32 deletions(-)
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index b98afe59a4f1..443405c579ee 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -289,6 +289,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)
@@ -302,24 +321,12 @@ 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,
@@ -336,23 +343,12 @@ 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;
+ }
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