Commit e9919a24 authored by Hangbin Liu's avatar Hangbin Liu Committed by David S. Miller

fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied

With commit 153380ec ("fib_rules: Added NLM_F_EXCL support to
fib_nl_newrule") we now able to check if a rule already exists. But this
only works with iproute2. For other tools like libnl, NetworkManager,
it still could add duplicate rules with only NLM_F_CREATE flag, like

[localhost ~ ]# ip rule
0:      from all lookup local
32766:  from all lookup main
32767:  from all lookup default
100000: from 192.168.7.5 lookup 5
100000: from 192.168.7.5 lookup 5

As it doesn't make sense to create two duplicate rules, let's just return
0 if the rule exists.

Fixes: 153380ec ("fib_rules: Added NLM_F_EXCL support to fib_nl_newrule")
Reported-by: default avatarThomas Haller <thaller@redhat.com>
Signed-off-by: default avatarHangbin Liu <liuhangbin@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 80f23212
...@@ -757,9 +757,9 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -757,9 +757,9 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
if (err) if (err)
goto errout; goto errout;
if ((nlh->nlmsg_flags & NLM_F_EXCL) && if (rule_exists(ops, frh, tb, rule)) {
rule_exists(ops, frh, tb, rule)) { if (nlh->nlmsg_flags & NLM_F_EXCL)
err = -EEXIST; err = -EEXIST;
goto errout_free; goto errout_free;
} }
......
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