netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied
@ 2019-05-07  9:11 Hangbin Liu
  2019-05-08 16:35 ` David Miller
  0 siblings, 1 reply; 16+ messages in thread
From: Hangbin Liu @ 2019-05-07  9:11 UTC (permalink / raw)
  To: netdev; +Cc: Mateusz Bajorski, David Ahern, David S . Miller, Hangbin Liu

With commit 153380ec4b9 ("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: 153380ec4b9 ("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>
---
 net/core/fib_rules.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index ffbb827723a2..c49b752ea7eb 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -756,9 +756,9 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (err)
 		goto errout;
 
-	if ((nlh->nlmsg_flags & NLM_F_EXCL) &&
-	    rule_exists(ops, frh, tb, rule)) {
-		err = -EEXIST;
+	if (rule_exists(ops, frh, tb, rule)) {
+		if (nlh->nlmsg_flags & NLM_F_EXCL)
+			err = -EEXIST;
 		goto errout_free;
 	}
 
-- 
2.19.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-06-06 23:01 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-07  9:11 [PATCH net] fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied Hangbin Liu
2019-05-08 16:35 ` David Miller
2019-06-01  1:43   ` Maciej Żenczykowski
2019-06-01  9:32     ` Greg KH
2019-06-05  1:43     ` Hangbin Liu
2019-06-05  1:47       ` Lorenzo Colitti
2019-06-05  2:15         ` Hangbin Liu
2019-06-05  2:25           ` Lorenzo Colitti
2019-06-05  3:29             ` Hangbin Liu
2019-06-05  3:43               ` Lorenzo Colitti
2019-06-05  4:05                 ` Hangbin Liu
2019-06-05  3:57       ` David Ahern
2019-06-05  4:08         ` Hangbin Liu
2019-06-05  4:58         ` Lorenzo Colitti
2019-06-05 15:33           ` David Ahern
2019-06-06 23:01             ` Maciej Żenczykowski

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).