* [PATCH v4] fib_rules: Added NLM_F_EXCL support to fib_nl_newrule
@ 2016-06-29 7:22 Mateusz Bajorski
2016-06-29 19:38 ` David Ahern
2016-06-30 12:24 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Mateusz Bajorski @ 2016-06-29 7:22 UTC (permalink / raw)
To: netdev
When adding rule with NLM_F_EXCL flag then check if the same rule exist.
If yes then exit with -EEXIST.
This is already implemented in iproute2:
if (cmd == RTM_NEWRULE) {
req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
req.r.rtm_type = RTN_UNICAST;
}
Tested ipv4 and ipv6 with net-next linux on qemu x86
expected behavior after patch:
localhost ~ # ip rule
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
RTNETLINK answers: File exists
localhost ~ # ip rule
0: from all lookup local
1005: from 10.46.177.97 lookup 104
32766: from all lookup main
32767: from all lookup default
There was already topic regarding this but I don't see any changes
merged and problem still occurs.
https://lkml.kernel.org/r/1135778809.5944.7.camel+%28%29+localhost+%21+localdomain
Signed-off-by: Mateusz Bajorski <mateusz.bajorski@nokia.com>
---
Changes in v2: section moved to new place where new rule is already built
Changes in v3: compare moved to helper, added fr_net compare
Changes in v4: added l3mdev compare
net/core/fib_rules.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 98298b1..be4629c 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -269,6 +269,49 @@ errout:
return err;
}
+static int rule_exists(struct fib_rules_ops *ops, struct fib_rule_hdr *frh,
+ struct nlattr **tb, struct fib_rule *rule)
+{
+ struct fib_rule *r;
+
+ list_for_each_entry(r, &ops->rules_list, list) {
+ if (r->action != rule->action)
+ continue;
+
+ if (r->table != rule->table)
+ continue;
+
+ if (r->pref != rule->pref)
+ continue;
+
+ if (memcmp(r->iifname, rule->iifname, IFNAMSIZ))
+ continue;
+
+ if (memcmp(r->oifname, rule->oifname, IFNAMSIZ))
+ continue;
+
+ if (r->mark != rule->mark)
+ continue;
+
+ if (r->mark_mask != rule->mark_mask)
+ continue;
+
+ if (r->tun_id != rule->tun_id)
+ continue;
+
+ if (r->fr_net != rule->fr_net)
+ continue;
+
+ if (r->l3mdev != rule->l3mdev)
+ continue;
+
+ if (!ops->compare(r, frh, tb))
+ continue;
+ return 1;
+ }
+ return 0;
+}
+
int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh)
{
struct net *net = sock_net(skb->sk);
@@ -386,6 +429,12 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh)
if (rule->l3mdev && rule->table)
goto errout_free;
+ if ((nlh->nlmsg_flags & NLM_F_EXCL) &&
+ rule_exists(ops, frh, tb, rule)) {
+ err = -EEXIST;
+ goto errout_free;
+ }
+
err = ops->configure(rule, skb, frh, tb);
if (err < 0)
goto errout_free;
--
2.6.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4] fib_rules: Added NLM_F_EXCL support to fib_nl_newrule
2016-06-29 7:22 [PATCH v4] fib_rules: Added NLM_F_EXCL support to fib_nl_newrule Mateusz Bajorski
@ 2016-06-29 19:38 ` David Ahern
2016-06-30 12:24 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Ahern @ 2016-06-29 19:38 UTC (permalink / raw)
To: Mateusz Bajorski, netdev
On 6/29/16 1:22 AM, Mateusz Bajorski wrote:
> When adding rule with NLM_F_EXCL flag then check if the same rule exist.
> If yes then exit with -EEXIST.
>
> This is already implemented in iproute2:
> if (cmd == RTM_NEWRULE) {
> req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
> req.r.rtm_type = RTN_UNICAST;
> }
>
> Tested ipv4 and ipv6 with net-next linux on qemu x86
>
> expected behavior after patch:
> localhost ~ # ip rule
> 0: from all lookup local
> 32766: from all lookup main
> 32767: from all lookup default
> localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
> localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
> RTNETLINK answers: File exists
> localhost ~ # ip rule
> 0: from all lookup local
> 1005: from 10.46.177.97 lookup 104
> 32766: from all lookup main
> 32767: from all lookup default
>
> There was already topic regarding this but I don't see any changes
> merged and problem still occurs.
> https://lkml.kernel.org/r/1135778809.5944.7.camel+%28%29+localhost+%21+localdomain
>
> Signed-off-by: Mateusz Bajorski <mateusz.bajorski@nokia.com>
> ---
> Changes in v2: section moved to new place where new rule is already built
> Changes in v3: compare moved to helper, added fr_net compare
> Changes in v4: added l3mdev compare
>
> net/core/fib_rules.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 49 insertions(+)
>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4] fib_rules: Added NLM_F_EXCL support to fib_nl_newrule
2016-06-29 7:22 [PATCH v4] fib_rules: Added NLM_F_EXCL support to fib_nl_newrule Mateusz Bajorski
2016-06-29 19:38 ` David Ahern
@ 2016-06-30 12:24 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-06-30 12:24 UTC (permalink / raw)
To: mateusz.bajorski; +Cc: netdev
From: Mateusz Bajorski <mateusz.bajorski@nokia.com>
Date: Wed, 29 Jun 2016 09:22:10 +0200
> When adding rule with NLM_F_EXCL flag then check if the same rule exist.
> If yes then exit with -EEXIST.
>
> This is already implemented in iproute2:
> if (cmd == RTM_NEWRULE) {
> req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
> req.r.rtm_type = RTN_UNICAST;
> }
>
> Tested ipv4 and ipv6 with net-next linux on qemu x86
>
> expected behavior after patch:
> localhost ~ # ip rule
> 0: from all lookup local
> 32766: from all lookup main
> 32767: from all lookup default
> localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
> localhost ~ # ip rule add from 10.46.177.97 lookup 104 pref 1005
> RTNETLINK answers: File exists
> localhost ~ # ip rule
> 0: from all lookup local
> 1005: from 10.46.177.97 lookup 104
> 32766: from all lookup main
> 32767: from all lookup default
>
> There was already topic regarding this but I don't see any changes
> merged and problem still occurs.
> https://lkml.kernel.org/r/1135778809.5944.7.camel+%28%29+localhost+%21+localdomain
>
> Signed-off-by: Mateusz Bajorski <mateusz.bajorski@nokia.com>
Applied to net-next, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-30 12:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-29 7:22 [PATCH v4] fib_rules: Added NLM_F_EXCL support to fib_nl_newrule Mateusz Bajorski
2016-06-29 19:38 ` David Ahern
2016-06-30 12:24 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).