Commit e404b8c7 authored by Benjamin Poirier's avatar Benjamin Poirier Committed by David S. Miller
Browse files

ipv6: Fix route replacement with dev-only route



After commit 27596472 ("ipv6: fix ECMP route replacement") it is no
longer possible to replace an ECMP-able route by a non ECMP-able route.
For example,
	ip route add 2001:db8::1/128 via fe80::1 dev dummy0
	ip route replace 2001:db8::1/128 dev dummy0
does not work as expected.

Tweak the replacement logic so that point 3 in the log of the above commit
becomes:
3. If the new route is not ECMP-able, and no matching non-ECMP-able route
exists, replace matching ECMP-able route (if any) or add the new route.

We can now summarize the entire replace semantics to:
When doing a replace, prefer replacing a matching route of the same
"ECMP-able-ness" as the replace argument. If there is no such candidate,
fallback to the first route found.

Fixes: 27596472 ("ipv6: fix ECMP route replacement")
Signed-off-by: default avatarBenjamin Poirier <bpoirier@cumulusnetworks.com>
Reviewed-by: default avatarMichal Kubecek <mkubecek@suse.cz>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e8023b03
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -1102,7 +1102,6 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
					found++;
					break;
				}
				if (rt_can_ecmp)
				fallback_ins = fallback_ins ?: ins;
				goto next_iter;
			}
@@ -1146,7 +1145,9 @@ next_iter:
	}

	if (fallback_ins && !found) {
		/* No ECMP-able route found, replace first non-ECMP one */
		/* No matching route with same ecmp-able-ness found, replace
		 * first matching route
		 */
		ins = fallback_ins;
		iter = rcu_dereference_protected(*ins,
				    lockdep_is_held(&rt->fib6_table->tb6_lock));
+6 −0
Original line number Diff line number Diff line
@@ -910,6 +910,12 @@ ipv6_rt_replace_mpath()
	check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024"
	log_test $? 0 "Multipath with single path via multipath attribute"

	# multipath with dev-only
	add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
	run_cmd "$IP -6 ro replace 2001:db8:104::/64 dev veth1"
	check_route6 "2001:db8:104::/64 dev veth1 metric 1024"
	log_test $? 0 "Multipath with dev-only"

	# route replace fails - invalid nexthop 1
	add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
	run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:111::3 nexthop via 2001:db8:103::3"