diff options
author | Mateusz Bajorski <mateusz.bajorski@nokia.com> | 2016-06-29 03:22:10 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-06-30 08:23:19 -0400 |
commit | 153380ec4b9b6802bba61ebd34da432a54994e9d (patch) | |
tree | 0391517ef88107a49eae9825f4a7cd077c8537c4 /net/core | |
parent | 2631b79f6cb8b634fe41b77de9c4add0ec6b3cae (diff) |
fib_rules: Added NLM_F_EXCL support to fib_nl_newrule
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>
Acked-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/fib_rules.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index 98298b11f534..be4629c344a6 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c | |||
@@ -269,6 +269,49 @@ errout: | |||
269 | return err; | 269 | return err; |
270 | } | 270 | } |
271 | 271 | ||
272 | static int rule_exists(struct fib_rules_ops *ops, struct fib_rule_hdr *frh, | ||
273 | struct nlattr **tb, struct fib_rule *rule) | ||
274 | { | ||
275 | struct fib_rule *r; | ||
276 | |||
277 | list_for_each_entry(r, &ops->rules_list, list) { | ||
278 | if (r->action != rule->action) | ||
279 | continue; | ||
280 | |||
281 | if (r->table != rule->table) | ||
282 | continue; | ||
283 | |||
284 | if (r->pref != rule->pref) | ||
285 | continue; | ||
286 | |||
287 | if (memcmp(r->iifname, rule->iifname, IFNAMSIZ)) | ||
288 | continue; | ||
289 | |||
290 | if (memcmp(r->oifname, rule->oifname, IFNAMSIZ)) | ||
291 | continue; | ||
292 | |||
293 | if (r->mark != rule->mark) | ||
294 | continue; | ||
295 | |||
296 | if (r->mark_mask != rule->mark_mask) | ||
297 | continue; | ||
298 | |||
299 | if (r->tun_id != rule->tun_id) | ||
300 | continue; | ||
301 | |||
302 | if (r->fr_net != rule->fr_net) | ||
303 | continue; | ||
304 | |||
305 | if (r->l3mdev != rule->l3mdev) | ||
306 | continue; | ||
307 | |||
308 | if (!ops->compare(r, frh, tb)) | ||
309 | continue; | ||
310 | return 1; | ||
311 | } | ||
312 | return 0; | ||
313 | } | ||
314 | |||
272 | int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh) | 315 | int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh) |
273 | { | 316 | { |
274 | struct net *net = sock_net(skb->sk); | 317 | struct net *net = sock_net(skb->sk); |
@@ -386,6 +429,12 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
386 | if (rule->l3mdev && rule->table) | 429 | if (rule->l3mdev && rule->table) |
387 | goto errout_free; | 430 | goto errout_free; |
388 | 431 | ||
432 | if ((nlh->nlmsg_flags & NLM_F_EXCL) && | ||
433 | rule_exists(ops, frh, tb, rule)) { | ||
434 | err = -EEXIST; | ||
435 | goto errout_free; | ||
436 | } | ||
437 | |||
389 | err = ops->configure(rule, skb, frh, tb); | 438 | err = ops->configure(rule, skb, frh, tb); |
390 | if (err < 0) | 439 | if (err < 0) |
391 | goto errout_free; | 440 | goto errout_free; |