diff options
| author | David Ahern <dsahern@gmail.com> | 2019-04-09 17:41:18 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2019-04-11 17:24:07 -0400 |
| commit | 0c59d00675874f9ee7a0371ad9d9b69386ea2d03 (patch) | |
| tree | 67f248d29d40dc7f73f6bdec02cd14c188629a80 /net/ipv6 | |
| parent | d83009d462a68ad908a51e1690d46917cbad0440 (diff) | |
ipv6: Refactor rt6_device_match
Move the device and gateway checks in the fib6_next loop to a helper
that can be called per fib6_nh entry.
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
| -rw-r--r-- | net/ipv6/route.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 4acb71f0bc55..0e8becb1e455 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c | |||
| @@ -466,12 +466,34 @@ struct fib6_info *fib6_multipath_select(const struct net *net, | |||
| 466 | * Route lookup. rcu_read_lock() should be held. | 466 | * Route lookup. rcu_read_lock() should be held. |
| 467 | */ | 467 | */ |
| 468 | 468 | ||
| 469 | static bool __rt6_device_match(struct net *net, const struct fib6_nh *nh, | ||
| 470 | const struct in6_addr *saddr, int oif, int flags) | ||
| 471 | { | ||
| 472 | const struct net_device *dev; | ||
| 473 | |||
| 474 | if (nh->fib_nh_flags & RTNH_F_DEAD) | ||
| 475 | return false; | ||
| 476 | |||
| 477 | dev = nh->fib_nh_dev; | ||
| 478 | if (oif) { | ||
| 479 | if (dev->ifindex == oif) | ||
| 480 | return true; | ||
| 481 | } else { | ||
| 482 | if (ipv6_chk_addr(net, saddr, dev, | ||
| 483 | flags & RT6_LOOKUP_F_IFACE)) | ||
| 484 | return true; | ||
| 485 | } | ||
| 486 | |||
| 487 | return false; | ||
| 488 | } | ||
| 489 | |||
| 469 | static inline struct fib6_info *rt6_device_match(struct net *net, | 490 | static inline struct fib6_info *rt6_device_match(struct net *net, |
| 470 | struct fib6_info *rt, | 491 | struct fib6_info *rt, |
| 471 | const struct in6_addr *saddr, | 492 | const struct in6_addr *saddr, |
| 472 | int oif, | 493 | int oif, |
| 473 | int flags) | 494 | int flags) |
| 474 | { | 495 | { |
| 496 | const struct fib6_nh *nh; | ||
| 475 | struct fib6_info *sprt; | 497 | struct fib6_info *sprt; |
| 476 | 498 | ||
| 477 | if (!oif && ipv6_addr_any(saddr) && | 499 | if (!oif && ipv6_addr_any(saddr) && |
| @@ -479,19 +501,9 @@ static inline struct fib6_info *rt6_device_match(struct net *net, | |||
| 479 | return rt; | 501 | return rt; |
| 480 | 502 | ||
| 481 | for (sprt = rt; sprt; sprt = rcu_dereference(sprt->fib6_next)) { | 503 | for (sprt = rt; sprt; sprt = rcu_dereference(sprt->fib6_next)) { |
| 482 | const struct net_device *dev = sprt->fib6_nh.fib_nh_dev; | 504 | nh = &sprt->fib6_nh; |
| 483 | 505 | if (__rt6_device_match(net, nh, saddr, oif, flags)) | |
| 484 | if (sprt->fib6_nh.fib_nh_flags & RTNH_F_DEAD) | 506 | return sprt; |
| 485 | continue; | ||
| 486 | |||
| 487 | if (oif) { | ||
| 488 | if (dev->ifindex == oif) | ||
| 489 | return sprt; | ||
| 490 | } else { | ||
| 491 | if (ipv6_chk_addr(net, saddr, dev, | ||
| 492 | flags & RT6_LOOKUP_F_IFACE)) | ||
| 493 | return sprt; | ||
| 494 | } | ||
| 495 | } | 507 | } |
| 496 | 508 | ||
| 497 | if (oif && flags & RT6_LOOKUP_F_IFACE) | 509 | if (oif && flags & RT6_LOOKUP_F_IFACE) |
