From: Florian Westphal <fw@strlen.de>
To: <netdev@vger.kernel.org>
Cc: davem@davemloft.net, kuba@kernel.org, dsahern@kernel.org,
Florian Westphal <fw@strlen.de>
Subject: [PATCH net-next 2/4] fib: place common code in a helper
Date: Mon, 13 Dec 2021 16:31:45 +0100 [thread overview]
Message-ID: <20211213153147.17635-3-fw@strlen.de> (raw)
In-Reply-To: <20211213153147.17635-1-fw@strlen.de>
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@strlen.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
next prev parent reply other threads:[~2021-12-13 15:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-13 15:31 [PATCH net-next 0/4] fib: remove suppress indirection, merge nl policies Florian Westphal
2021-12-13 15:31 ` [PATCH net-next 1/4] fib: remove suppress indirection Florian Westphal
2021-12-13 20:39 ` kernel test robot
2021-12-13 20:39 ` kernel test robot
2021-12-13 21:03 ` kernel test robot
2021-12-13 21:03 ` kernel test robot
2021-12-13 21:14 ` kernel test robot
2021-12-13 21:14 ` kernel test robot
2021-12-13 15:31 ` Florian Westphal [this message]
2021-12-13 15:31 ` [PATCH net-next 3/4] fib: rules: remove duplicated nla policies Florian Westphal
2021-12-13 15:31 ` [PATCH net-next 4/4] fib: expand fib_rule_policy Florian Westphal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211213153147.17635-3-fw@strlen.de \
--to=fw@strlen.de \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.