Skip to contentSkip to conversation

fib_rules: Resolve goto rules target on delete

PATCH Applied Serhey Popovych 2 participants 3 messages Jun 16, 2017 – Jun 21, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

We should avoid marking goto rules unresolved when their target is actually reachable after rule deletion.

Consolder following sample scenario:

  # ip -4 ru sh
  0:      from all lookup local
  32000:  from all goto 32100
  32100:  from all lookup main
  32100:  from all lookup default
  32766:  from all lookup main
  32767:  from all lookup default
  # ip -4 ru del pref 32100 table main
  # ip -4 ru sh
  0:      from all lookup local
  32000:  from all goto 32100 [unresolved]
  32100:  from all lookup default
  32766:  from all lookup main
  32767:  from all lookup default

After removal of first rule with preference 32100 we mark all goto rules as unreachable, even when rule with same preference as removed one still present.

Check if next rule with same preference is available and make all rules with goto action pointing to it.

---
 net/core/fib_rules.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
net/core/fib_rules.c +14 -7
index f21c4d3..3bba291 100644
@@ -568,7 +568,7 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
 	struct net *net = sock_net(skb->sk);
 	struct fib_rule_hdr *frh = nlmsg_data(nlh);
 	struct fib_rules_ops *ops = NULL;
-	struct fib_rule *rule, *tmp;
+	struct fib_rule *rule, *r;
 	struct nlattr *tb[FRA_MAX+1];
 	struct fib_kuid_range range;
 	int err = -EINVAL;
@@ -668,16 +668,23 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
 
 		/*
 		 * Check if this rule is a target to any of them. If so,
+		 * adjust to the next one with the same preference or
 		 * disable them. As this operation is eventually very
-		 * expensive, it is only performed if goto rules have
-		 * actually been added.
+		 * expensive, it is only performed if goto rules, except
+		 * current if it is goto rule, have actually been added.
 		 */
 		if (ops->nr_goto_rules > 0) {
-			list_for_each_entry(tmp, &ops->rules_list, list) {
-				if (rtnl_dereference(tmp->ctarget) == rule) {
-					RCU_INIT_POINTER(tmp->ctarget, NULL);
+			struct fib_rule *n;
+
+			n = list_next_entry(rule, list);
+			if (&n->list == &ops->rules_list || n->pref != rule->pref)
+				n = NULL;
+			list_for_each_entry(r, &ops->rules_list, list) {
+				if (rtnl_dereference(r->ctarget) != rule)
+					continue;
+				rcu_assign_pointer(r->ctarget, n);
+				if (!n)
 					ops->unresolved_rules++;
-				}
 			}
 		}
 
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw

From: Serhey Popovych <[email protected]>
Date: Fri, 16 Jun 2017 15:44:47 +0300

Quoted 21 lines

We should avoid marking goto rules unresolved when their target is actually reachable after rule deletion.

Consolder following sample scenario:

  # ip -4 ru sh
  0:      from all lookup local
  32000:  from all goto 32100
  32100:  from all lookup main
  32100:  from all lookup default
  32766:  from all lookup main
  32767:  from all lookup default
  # ip -4 ru del pref 32100 table main
  # ip -4 ru sh
  0:      from all lookup local
  32000:  from all goto 32100 [unresolved]
  32100:  from all lookup default
  32766:  from all lookup main
  32767:  from all lookup default
Quoted 8 lines

After removal of first rule with preference 32100 we mark all goto rules as unreachable, even when rule with same preference as removed one still present.

Check if next rule with same preference is available and make all rules with goto action pointing to it.

Applied, thanks.

It would be awesome if you could distill the above into a test case that could be run under tools/testing/selftests/networking.

Thanks!

#2 lore raw
Quoted 32 lines

From: Serhey Popovych <[email protected]>
Date: Fri, 16 Jun 2017 15:44:47 +0300

Quoted 28 lines

We should avoid marking goto rules unresolved when their target is actually reachable after rule deletion.

Consolder following sample scenario:

  # ip -4 ru sh
  0:      from all lookup local
  32000:  from all goto 32100
  32100:  from all lookup main
  32100:  from all lookup default
  32766:  from all lookup main
  32767:  from all lookup default
  # ip -4 ru del pref 32100 table main
  # ip -4 ru sh
  0:      from all lookup local
  32000:  from all goto 32100 [unresolved]
  32100:  from all lookup default
  32766:  from all lookup main
  32767:  from all lookup default

After removal of first rule with preference 32100 we mark all goto rules as unreachable, even when rule with same preference as removed one still present.

Check if next rule with same preference is available and make all rules with goto action pointing to it.

Quoted 6 lines
Quoted 1 line

Applied, thanks.

It would be awesome if you could distill the above into a test case that could be run under tools/testing/selftests/networking.

Yes, I already think about testing too.

Actually I have series of patches to improve fib_rules support both in core and per protocol (merge suppress, callback, reduce per network namespace memory consumption - useful for docker setups, more precise validation of netlink configuration messages, additional matching facilities etc) so testing is definitely required before my changes went upstream!

About testing implementation: I see there is no infrastructure to test netlink based configuration in tools/testing. How to make this better? Use libnl, write scripts that use iproute2 utilities? Where I can get additional to Documentation/kselftest.txt information?

Quoted 3 lines

Thanks!

Signature · 1 line
Thanks, Serhey