netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipv6: Fix default route failover when CONFIG_IPV6_ROUTER_PREF=n
@ 2012-12-02 10:00 Paul Marks
  2012-12-03 18:59 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Marks @ 2012-12-02 10:00 UTC (permalink / raw)
  To: davem, yoshfuji; +Cc: netdev, Paul Marks

I believe this commit from 2008 was incorrect:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=398bcbebb6f721ac308df1e3d658c0029bb74503

When CONFIG_IPV6_ROUTER_PREF is disabled, the kernel should follow
RFC4861 section 6.3.6: if no route is NUD_VALID, then traffic should be
sprayed across all routers (indirectly triggering NUD) until one of them
becomes NUD_VALID.

However, the following experiment demonstrates that this does not work:

1) Connect to an IPv6 network.
2) Change the router's MAC (and link-local) address.

The kernel will lock onto the first router and never try the new one, even
if the first becomes unreachable.  This patch fixes the problem by
allowing rt6_check_neigh() to return 0; if all routers return 0, then
rt6_select() will fall back to round-robin behavior.

This patch should have no effect when CONFIG_IPV6_ROUTER_PREF=y.

Note that rt6_check_neigh() is only used in a boolean context, so the
presence of both "m = 1" and "m = 2" was irrelevant and confusing.

Signed-off-by: Paul Marks <pmarks@google.com>
---
 net/ipv6/route.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index b1e6cf0..60b2995 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -490,7 +490,7 @@ static inline int rt6_check_dev(struct rt6_info *rt, int oif)
 static inline int rt6_check_neigh(struct rt6_info *rt)
 {
 	struct neighbour *neigh;
-	int m;
+	int m = 0;
 
 	neigh = rt->n;
 	if (rt->rt6i_flags & RTF_NONEXTHOP ||
@@ -499,16 +499,13 @@ static inline int rt6_check_neigh(struct rt6_info *rt)
 	else if (neigh) {
 		read_lock_bh(&neigh->lock);
 		if (neigh->nud_state & NUD_VALID)
-			m = 2;
+			m = 1;
 #ifdef CONFIG_IPV6_ROUTER_PREF
-		else if (neigh->nud_state & NUD_FAILED)
-			m = 0;
-#endif
-		else
+		else if (!(neigh->nud_state & NUD_FAILED))
 			m = 1;
+#endif
 		read_unlock_bh(&neigh->lock);
-	} else
-		m = 0;
+	}
 	return m;
 }
 
-- 
1.7.7.3

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

* Re: [PATCH] ipv6: Fix default route failover when CONFIG_IPV6_ROUTER_PREF=n
  2012-12-02 10:00 [PATCH] ipv6: Fix default route failover when CONFIG_IPV6_ROUTER_PREF=n Paul Marks
@ 2012-12-03 18:59 ` David Miller
  2012-12-03 20:26   ` [PATCH v2] " Paul Marks
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2012-12-03 18:59 UTC (permalink / raw)
  To: pmarks; +Cc: yoshfuji, netdev

From: Paul Marks <pmarks@google.com>
Date: Sun,  2 Dec 2012 02:00:21 -0800

> I believe this commit from 2008 was incorrect:
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=398bcbebb6f721ac308df1e3d658c0029bb74503
> 
> When CONFIG_IPV6_ROUTER_PREF is disabled, the kernel should follow
> RFC4861 section 6.3.6: if no route is NUD_VALID, then traffic should be
> sprayed across all routers (indirectly triggering NUD) until one of them
> becomes NUD_VALID.
> 
> However, the following experiment demonstrates that this does not work:
> 
> 1) Connect to an IPv6 network.
> 2) Change the router's MAC (and link-local) address.
> 
> The kernel will lock onto the first router and never try the new one, even
> if the first becomes unreachable.  This patch fixes the problem by
> allowing rt6_check_neigh() to return 0; if all routers return 0, then
> rt6_select() will fall back to round-robin behavior.
> 
> This patch should have no effect when CONFIG_IPV6_ROUTER_PREF=y.
> 
> Note that rt6_check_neigh() is only used in a boolean context, so the
> presence of both "m = 1" and "m = 2" was irrelevant and confusing.
> 
> Signed-off-by: Paul Marks <pmarks@google.com>

The values '1' and '2' used to influence rt6_score_route() in different
ways.

Please change rt6_check_neigh() to return a "bool" if you are going to
do this.

Thanks.

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

* [PATCH v2] ipv6: Fix default route failover when CONFIG_IPV6_ROUTER_PREF=n
  2012-12-03 18:59 ` David Miller
@ 2012-12-03 20:26   ` Paul Marks
  2012-12-03 20:35     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Marks @ 2012-12-03 20:26 UTC (permalink / raw)
  To: davem; +Cc: yoshfuji, netdev, Paul Marks

I believe this commit from 2008 was incorrect:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=398bcbebb6f721ac308df1e3d658c0029bb74503

When CONFIG_IPV6_ROUTER_PREF is disabled, the kernel should follow
RFC4861 section 6.3.6: if no route is NUD_VALID, then traffic should be
sprayed across all routers (indirectly triggering NUD) until one of them
becomes NUD_VALID.

However, the following experiment demonstrates that this does not work:

1) Connect to an IPv6 network.
2) Change the router's MAC (and link-local) address.

The kernel will lock onto the first router and never try the new one, even
if the first becomes unreachable.  This patch fixes the problem by
allowing rt6_check_neigh() to return 0; if all routers return 0, then
rt6_select() will fall back to round-robin behavior.

This patch should have no effect when CONFIG_IPV6_ROUTER_PREF=y.

Note that rt6_check_neigh() is only used in a boolean context, so I've
changed its return type accordingly.

Signed-off-by: Paul Marks <pmarks@google.com>
---
Changelog since v1:
- Changed return type from 'int' to 'bool'.

 net/ipv6/route.c |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index b1e6cf0..35f2815 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -487,35 +487,32 @@ static inline int rt6_check_dev(struct rt6_info *rt, int oif)
 	return 0;
 }
 
-static inline int rt6_check_neigh(struct rt6_info *rt)
+static inline bool rt6_check_neigh(struct rt6_info *rt)
 {
 	struct neighbour *neigh;
-	int m;
+	bool ret = false;
 
 	neigh = rt->n;
 	if (rt->rt6i_flags & RTF_NONEXTHOP ||
 	    !(rt->rt6i_flags & RTF_GATEWAY))
-		m = 1;
+		ret = true;
 	else if (neigh) {
 		read_lock_bh(&neigh->lock);
 		if (neigh->nud_state & NUD_VALID)
-			m = 2;
+			ret = true;
 #ifdef CONFIG_IPV6_ROUTER_PREF
-		else if (neigh->nud_state & NUD_FAILED)
-			m = 0;
+		else if (!(neigh->nud_state & NUD_FAILED))
+			ret = true;
 #endif
-		else
-			m = 1;
 		read_unlock_bh(&neigh->lock);
-	} else
-		m = 0;
-	return m;
+	}
+	return ret;
 }
 
 static int rt6_score_route(struct rt6_info *rt, int oif,
 			   int strict)
 {
-	int m, n;
+	int m;
 
 	m = rt6_check_dev(rt, oif);
 	if (!m && (strict & RT6_LOOKUP_F_IFACE))
@@ -523,8 +520,7 @@ static int rt6_score_route(struct rt6_info *rt, int oif,
 #ifdef CONFIG_IPV6_ROUTER_PREF
 	m |= IPV6_DECODE_PREF(IPV6_EXTRACT_PREF(rt->rt6i_flags)) << 2;
 #endif
-	n = rt6_check_neigh(rt);
-	if (!n && (strict & RT6_LOOKUP_F_REACHABLE))
+	if (!rt6_check_neigh(rt) && (strict & RT6_LOOKUP_F_REACHABLE))
 		return -1;
 	return m;
 }
-- 
1.7.7.3

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

* Re: [PATCH v2] ipv6: Fix default route failover when CONFIG_IPV6_ROUTER_PREF=n
  2012-12-03 20:26   ` [PATCH v2] " Paul Marks
@ 2012-12-03 20:35     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2012-12-03 20:35 UTC (permalink / raw)
  To: pmarks; +Cc: yoshfuji, netdev

From: Paul Marks <pmarks@google.com>
Date: Mon,  3 Dec 2012 12:26:54 -0800

> I believe this commit from 2008 was incorrect:
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=398bcbebb6f721ac308df1e3d658c0029bb74503
> 
> When CONFIG_IPV6_ROUTER_PREF is disabled, the kernel should follow
> RFC4861 section 6.3.6: if no route is NUD_VALID, then traffic should be
> sprayed across all routers (indirectly triggering NUD) until one of them
> becomes NUD_VALID.
> 
> However, the following experiment demonstrates that this does not work:
> 
> 1) Connect to an IPv6 network.
> 2) Change the router's MAC (and link-local) address.
> 
> The kernel will lock onto the first router and never try the new one, even
> if the first becomes unreachable.  This patch fixes the problem by
> allowing rt6_check_neigh() to return 0; if all routers return 0, then
> rt6_select() will fall back to round-robin behavior.
> 
> This patch should have no effect when CONFIG_IPV6_ROUTER_PREF=y.
> 
> Note that rt6_check_neigh() is only used in a boolean context, so I've
> changed its return type accordingly.
> 
> Signed-off-by: Paul Marks <pmarks@google.com>

Applied to net-next, thanks Paul.

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

end of thread, other threads:[~2012-12-03 20:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-02 10:00 [PATCH] ipv6: Fix default route failover when CONFIG_IPV6_ROUTER_PREF=n Paul Marks
2012-12-03 18:59 ` David Miller
2012-12-03 20:26   ` [PATCH v2] " Paul Marks
2012-12-03 20:35     ` David Miller

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