aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/route.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv6/route.c')
-rw-r--r--net/ipv6/route.c120
1 files changed, 66 insertions, 54 deletions
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 0e1f4b2cd3dd..ad9b285692ba 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -308,27 +308,18 @@ static inline void rt6_probe(struct rt6_info *rt)
308/* 308/*
309 * Default Router Selection (RFC 2461 6.3.6) 309 * Default Router Selection (RFC 2461 6.3.6)
310 */ 310 */
311static int inline rt6_check_dev(struct rt6_info *rt, int oif) 311static inline int rt6_check_dev(struct rt6_info *rt, int oif)
312{ 312{
313 struct net_device *dev = rt->rt6i_dev; 313 struct net_device *dev = rt->rt6i_dev;
314 int ret = 0; 314 if (!oif || dev->ifindex == oif)
315
316 if (!oif)
317 return 2;
318 if (dev->flags & IFF_LOOPBACK) {
319 if (!WARN_ON(rt->rt6i_idev == NULL) &&
320 rt->rt6i_idev->dev->ifindex == oif)
321 ret = 1;
322 else
323 return 0;
324 }
325 if (dev->ifindex == oif)
326 return 2; 315 return 2;
327 316 if ((dev->flags & IFF_LOOPBACK) &&
328 return ret; 317 rt->rt6i_idev && rt->rt6i_idev->dev->ifindex == oif)
318 return 1;
319 return 0;
329} 320}
330 321
331static int inline rt6_check_neigh(struct rt6_info *rt) 322static inline int rt6_check_neigh(struct rt6_info *rt)
332{ 323{
333 struct neighbour *neigh = rt->rt6i_nexthop; 324 struct neighbour *neigh = rt->rt6i_nexthop;
334 int m = 0; 325 int m = 0;
@@ -363,55 +354,76 @@ static int rt6_score_route(struct rt6_info *rt, int oif,
363 return m; 354 return m;
364} 355}
365 356
366static struct rt6_info *rt6_select(struct rt6_info **head, int oif, 357static struct rt6_info *find_match(struct rt6_info *rt, int oif, int strict,
367 int strict) 358 int *mpri, struct rt6_info *match)
359{
360 int m;
361
362 if (rt6_check_expired(rt))
363 goto out;
364
365 m = rt6_score_route(rt, oif, strict);
366 if (m < 0)
367 goto out;
368
369 if (m > *mpri) {
370 if (strict & RT6_LOOKUP_F_REACHABLE)
371 rt6_probe(match);
372 *mpri = m;
373 match = rt;
374 } else if (strict & RT6_LOOKUP_F_REACHABLE) {
375 rt6_probe(rt);
376 }
377
378out:
379 return match;
380}
381
382static struct rt6_info *find_rr_leaf(struct fib6_node *fn,
383 struct rt6_info *rr_head,
384 u32 metric, int oif, int strict)
368{ 385{
369 struct rt6_info *match = NULL, *last = NULL; 386 struct rt6_info *rt, *match;
370 struct rt6_info *rt, *rt0 = *head;
371 u32 metric;
372 int mpri = -1; 387 int mpri = -1;
373 388
374 RT6_TRACE("%s(head=%p(*head=%p), oif=%d)\n", 389 match = NULL;
375 __FUNCTION__, head, head ? *head : NULL, oif); 390 for (rt = rr_head; rt && rt->rt6i_metric == metric;
391 rt = rt->u.dst.rt6_next)
392 match = find_match(rt, oif, strict, &mpri, match);
393 for (rt = fn->leaf; rt && rt != rr_head && rt->rt6i_metric == metric;
394 rt = rt->u.dst.rt6_next)
395 match = find_match(rt, oif, strict, &mpri, match);
376 396
377 for (rt = rt0, metric = rt0->rt6i_metric; 397 return match;
378 rt && rt->rt6i_metric == metric && (!last || rt != rt0); 398}
379 rt = rt->u.dst.rt6_next) {
380 int m;
381 399
382 if (rt6_check_expired(rt)) 400static struct rt6_info *rt6_select(struct fib6_node *fn, int oif, int strict)
383 continue; 401{
402 struct rt6_info *match, *rt0;
384 403
385 last = rt; 404 RT6_TRACE("%s(fn->leaf=%p, oif=%d)\n",
405 __FUNCTION__, fn->leaf, oif);
386 406
387 m = rt6_score_route(rt, oif, strict); 407 rt0 = fn->rr_ptr;
388 if (m < 0) 408 if (!rt0)
389 continue; 409 fn->rr_ptr = rt0 = fn->leaf;
390 410
391 if (m > mpri) { 411 match = find_rr_leaf(fn, rt0, rt0->rt6i_metric, oif, strict);
392 if (strict & RT6_LOOKUP_F_REACHABLE)
393 rt6_probe(match);
394 match = rt;
395 mpri = m;
396 } else if (strict & RT6_LOOKUP_F_REACHABLE) {
397 rt6_probe(rt);
398 }
399 }
400 412
401 if (!match && 413 if (!match &&
402 (strict & RT6_LOOKUP_F_REACHABLE) && 414 (strict & RT6_LOOKUP_F_REACHABLE)) {
403 last && last != rt0) { 415 struct rt6_info *next = rt0->u.dst.rt6_next;
416
404 /* no entries matched; do round-robin */ 417 /* no entries matched; do round-robin */
405 static DEFINE_SPINLOCK(lock); 418 if (!next || next->rt6i_metric != rt0->rt6i_metric)
406 spin_lock(&lock); 419 next = fn->leaf;
407 *head = rt0->u.dst.rt6_next; 420
408 rt0->u.dst.rt6_next = last->u.dst.rt6_next; 421 if (next != rt0)
409 last->u.dst.rt6_next = rt0; 422 fn->rr_ptr = next;
410 spin_unlock(&lock);
411 } 423 }
412 424
413 RT6_TRACE("%s() => %p, score=%d\n", 425 RT6_TRACE("%s() => %p\n",
414 __FUNCTION__, match, mpri); 426 __FUNCTION__, match);
415 427
416 return (match ? match : &ip6_null_entry); 428 return (match ? match : &ip6_null_entry);
417} 429}
@@ -657,7 +669,7 @@ restart_2:
657 fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src); 669 fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src);
658 670
659restart: 671restart:
660 rt = rt6_select(&fn->leaf, fl->iif, strict | reachable); 672 rt = rt6_select(fn, fl->iif, strict | reachable);
661 BACKTRACK(&fl->fl6_src); 673 BACKTRACK(&fl->fl6_src);
662 if (rt == &ip6_null_entry || 674 if (rt == &ip6_null_entry ||
663 rt->rt6i_flags & RTF_CACHE) 675 rt->rt6i_flags & RTF_CACHE)
@@ -752,7 +764,7 @@ restart_2:
752 fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src); 764 fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src);
753 765
754restart: 766restart:
755 rt = rt6_select(&fn->leaf, fl->oif, strict | reachable); 767 rt = rt6_select(fn, fl->oif, strict | reachable);
756 BACKTRACK(&fl->fl6_src); 768 BACKTRACK(&fl->fl6_src);
757 if (rt == &ip6_null_entry || 769 if (rt == &ip6_null_entry ||
758 rt->rt6i_flags & RTF_CACHE) 770 rt->rt6i_flags & RTF_CACHE)