Commit 3dfbcc41 authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

[NET] rules: Add support to invert selectors

Introduces a new flag FIB_RULE_INVERT causing rules to apply
if the specified selector doesn't match.
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1f6c9557
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
/* rule is permanent, and cannot be deleted */ /* rule is permanent, and cannot be deleted */
#define FIB_RULE_PERMANENT 1 #define FIB_RULE_PERMANENT 1
#define FIB_RULE_INVERT 2
struct fib_rule_hdr struct fib_rule_hdr
{ {
......
...@@ -107,6 +107,22 @@ int fib_rules_unregister(struct fib_rules_ops *ops) ...@@ -107,6 +107,22 @@ int fib_rules_unregister(struct fib_rules_ops *ops)
EXPORT_SYMBOL_GPL(fib_rules_unregister); EXPORT_SYMBOL_GPL(fib_rules_unregister);
static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops,
struct flowi *fl, int flags)
{
int ret = 0;
if (rule->ifindex && (rule->ifindex != fl->iif))
goto out;
if ((rule->mark ^ fl->mark) & rule->mark_mask)
goto out;
ret = ops->match(rule, fl, flags);
out:
return (rule->flags & FIB_RULE_INVERT) ? !ret : ret;
}
int fib_rules_lookup(struct fib_rules_ops *ops, struct flowi *fl, int fib_rules_lookup(struct fib_rules_ops *ops, struct flowi *fl,
int flags, struct fib_lookup_arg *arg) int flags, struct fib_lookup_arg *arg)
{ {
...@@ -116,13 +132,7 @@ int fib_rules_lookup(struct fib_rules_ops *ops, struct flowi *fl, ...@@ -116,13 +132,7 @@ int fib_rules_lookup(struct fib_rules_ops *ops, struct flowi *fl,
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(rule, ops->rules_list, list) { list_for_each_entry_rcu(rule, ops->rules_list, list) {
if (rule->ifindex && (rule->ifindex != fl->iif)) if (!fib_rule_match(rule, ops, fl, flags))
continue;
if ((rule->mark ^ fl->mark) & rule->mark_mask)
continue;
if (!ops->match(rule, fl, flags))
continue; continue;
err = ops->action(rule, fl, flags, arg); err = ops->action(rule, fl, flags, arg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment