Commit c302e6d5 authored by YOSHIFUJI Hideaki's avatar YOSHIFUJI Hideaki Committed by David S. Miller

[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: default avatarDavid S. Miller <davem@davemloft.net>
parent e959d812
...@@ -317,7 +317,7 @@ static struct rt6_info *rt6_select(struct rt6_info **head, int oif, ...@@ -317,7 +317,7 @@ static struct rt6_info *rt6_select(struct rt6_info **head, int oif,
__FUNCTION__, head, head ? *head : NULL, oif); __FUNCTION__, head, head ? *head : NULL, oif);
for (rt = rt0, metric = rt0->rt6i_metric; for (rt = rt0, metric = rt0->rt6i_metric;
rt && rt->rt6i_metric == metric; rt && rt->rt6i_metric == metric && (!last || rt != rt0);
rt = rt->u.next) { rt = rt->u.next) {
int m; int m;
...@@ -343,9 +343,12 @@ static struct rt6_info *rt6_select(struct rt6_info **head, int oif, ...@@ -343,9 +343,12 @@ static struct rt6_info *rt6_select(struct rt6_info **head, int oif,
(strict & RT6_SELECT_F_REACHABLE) && (strict & RT6_SELECT_F_REACHABLE) &&
last && last != rt0) { last && last != rt0) {
/* no entries matched; do round-robin */ /* no entries matched; do round-robin */
static spinlock_t lock = SPIN_LOCK_UNLOCKED;
spin_lock(&lock);
*head = rt0->u.next; *head = rt0->u.next;
rt0->u.next = last->u.next; rt0->u.next = last->u.next;
last->u.next = rt0; last->u.next = rt0;
spin_unlock(&lock);
} }
RT6_TRACE("%s() => %p, score=%d\n", RT6_TRACE("%s() => %p, score=%d\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment