Skip to content
Permalink
Browse files
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@strlen.de>
  • Loading branch information
Florian Westphal authored and intel-lab-lkp committed Dec 14, 2021
1 parent 596c4af commit 59837eba57ced3afe03ce1e6d8bd6da39efd398c
Showing 1 changed file with 30 additions and 32 deletions.
@@ -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,

0 comments on commit 59837eb

Please sign in to comment.