Skip to content

Commit 1fff19a

Browse files
liuhangbingregkh
authored andcommitted
fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied
[ Upstream commit e9919a2 ] With commit 153380e ("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: 153380e ("fib_rules: Added NLM_F_EXCL support to fib_nl_newrule") Reported-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent aca669b commit 1fff19a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/core/fib_rules.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh)
429429
if (rule->l3mdev && rule->table)
430430
goto errout_free;
431431

432-
if ((nlh->nlmsg_flags & NLM_F_EXCL) &&
433-
rule_exists(ops, frh, tb, rule)) {
434-
err = -EEXIST;
432+
if (rule_exists(ops, frh, tb, rule)) {
433+
if (nlh->nlmsg_flags & NLM_F_EXCL)
434+
err = -EEXIST;
435435
goto errout_free;
436436
}
437437

0 commit comments

Comments
 (0)