aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2006-04-28 18:59:15 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2006-04-29 21:33:22 -0400
commitc302e6d54e468ee9b1e18152e2e9da06953f3473 (patch)
tree23ea6976bef7aad9a934b56714786a0d55256ec6
parente959d8121fcbfee6ec049cc617e9423d1799f2e4 (diff)
[IPV6]: Fix race in route selection.
We eliminated rt6_dflt_lock (to protect default router pointer) at 2.6.17-rc1, and introduced rt6_select() for general router selection. The function is called in the context of rt6_lock read-lock held, but this means, we have some race conditions when we do round-robin. Signed-off-by; YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/ipv6/route.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 79078747a646..0190e39096b9 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -317,7 +317,7 @@ static struct rt6_info *rt6_select(struct rt6_info **head, int oif,
317 __FUNCTION__, head, head ? *head : NULL, oif); 317 __FUNCTION__, head, head ? *head : NULL, oif);
318 318
319 for (rt = rt0, metric = rt0->rt6i_metric; 319 for (rt = rt0, metric = rt0->rt6i_metric;
320 rt && rt->rt6i_metric == metric; 320 rt && rt->rt6i_metric == metric && (!last || rt != rt0);
321 rt = rt->u.next) { 321 rt = rt->u.next) {
322 int m; 322 int m;
323 323
@@ -343,9 +343,12 @@ static struct rt6_info *rt6_select(struct rt6_info **head, int oif,
343 (strict & RT6_SELECT_F_REACHABLE) && 343 (strict & RT6_SELECT_F_REACHABLE) &&
344 last && last != rt0) { 344 last && last != rt0) {
345 /* no entries matched; do round-robin */ 345 /* no entries matched; do round-robin */
346 static spinlock_t lock = SPIN_LOCK_UNLOCKED;
347 spin_lock(&lock);
346 *head = rt0->u.next; 348 *head = rt0->u.next;
347 rt0->u.next = last->u.next; 349 rt0->u.next = last->u.next;
348 last->u.next = rt0; 350 last->u.next = rt0;
351 spin_unlock(&lock);
349 } 352 }
350 353
351 RT6_TRACE("%s() => %p, score=%d\n", 354 RT6_TRACE("%s() => %p, score=%d\n",