Skip to content

Commit 8c14586

Browse files
David Aherndavem330
authored andcommitted
net: ipv6: Use passed in table for nexthop lookups
Similar to 3bfd847 ("net: Use passed in table for nexthop lookups") for IPv4, if the route spec contains a table id use that to lookup the next hop first and fall back to a full lookup if it fails (per the fix 4c9bcd1 ("net: Fix nexthop lookups")). Example: root@kenny:~# ip -6 ro ls table red local 2100:1::1 dev lo proto none metric 0 pref medium 2100:1::/120 dev eth1 proto kernel metric 256 pref medium local 2100:2::1 dev lo proto none metric 0 pref medium 2100:2::/120 dev eth2 proto kernel metric 256 pref medium local fe80::e0:f9ff:fe09:3cac dev lo proto none metric 0 pref medium local fe80::e0:f9ff:fe1c:b974 dev lo proto none metric 0 pref medium fe80::/64 dev eth1 proto kernel metric 256 pref medium fe80::/64 dev eth2 proto kernel metric 256 pref medium ff00::/8 dev red metric 256 pref medium ff00::/8 dev eth1 metric 256 pref medium ff00::/8 dev eth2 metric 256 pref medium unreachable default dev lo metric 240 error -113 pref medium root@kenny:~# ip -6 ro add table red 2100:3::/64 via 2100:1::64 RTNETLINK answers: No route to host Route add fails even though 2100:1::64 is a reachable next hop: root@kenny:~# ping6 -I red 2100:1::64 ping6: Warning: source address might be selected on device other than red. PING 2100:1::64(2100:1::64) from 2100:1::1 red: 56 data bytes 64 bytes from 2100:1::64: icmp_seq=1 ttl=64 time=1.33 ms With this patch: root@kenny:~# ip -6 ro add table red 2100:3::/64 via 2100:1::64 root@kenny:~# ip -6 ro ls table red local 2100:1::1 dev lo proto none metric 0 pref medium 2100:1::/120 dev eth1 proto kernel metric 256 pref medium local 2100:2::1 dev lo proto none metric 0 pref medium 2100:2::/120 dev eth2 proto kernel metric 256 pref medium 2100:3::/64 via 2100:1::64 dev eth1 metric 1024 pref medium local fe80::e0:f9ff:fe09:3cac dev lo proto none metric 0 pref medium local fe80::e0:f9ff:fe1c:b974 dev lo proto none metric 0 pref medium fe80::/64 dev eth1 proto kernel metric 256 pref medium fe80::/64 dev eth2 proto kernel metric 256 pref medium ff00::/8 dev red metric 256 pref medium ff00::/8 dev eth1 metric 256 pref medium ff00::/8 dev eth2 metric 256 pref medium unreachable default dev lo metric 240 error -113 pref medium Signed-off-by: David Ahern <dsa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 570d8e9 commit 8c14586

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

‎net/ipv6/route.c‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,37 @@ static int ip6_convert_metrics(struct mx6_config *mxc,
17691769
return -EINVAL;
17701770
}
17711771

1772+
static struct rt6_info *ip6_nh_lookup_table(struct net *net,
1773+
struct fib6_config *cfg,
1774+
const struct in6_addr *gw_addr)
1775+
{
1776+
struct flowi6 fl6 = {
1777+
.flowi6_oif = cfg->fc_ifindex,
1778+
.daddr = *gw_addr,
1779+
.saddr = cfg->fc_prefsrc,
1780+
};
1781+
struct fib6_table *table;
1782+
struct rt6_info *rt;
1783+
int flags = 0;
1784+
1785+
table = fib6_get_table(net, cfg->fc_table);
1786+
if (!table)
1787+
return NULL;
1788+
1789+
if (!ipv6_addr_any(&cfg->fc_prefsrc))
1790+
flags |= RT6_LOOKUP_F_HAS_SADDR;
1791+
1792+
rt = ip6_pol_route(net, table, cfg->fc_ifindex, &fl6, flags);
1793+
1794+
/* if table lookup failed, fall back to full lookup */
1795+
if (rt == net->ipv6.ip6_null_entry) {
1796+
ip6_rt_put(rt);
1797+
rt = NULL;
1798+
}
1799+
1800+
return rt;
1801+
}
1802+
17721803
static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
17731804
{
17741805
struct net *net = cfg->fc_nlinfo.nl_net;
@@ -1940,7 +1971,7 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
19401971
rt->rt6i_gateway = *gw_addr;
19411972

19421973
if (gwa_type != (IPV6_ADDR_LINKLOCAL|IPV6_ADDR_UNICAST)) {
1943-
struct rt6_info *grt;
1974+
struct rt6_info *grt = NULL;
19441975

19451976
/* IPv6 strictly inhibits using not link-local
19461977
addresses as nexthop address.
@@ -1952,7 +1983,12 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg)
19521983
if (!(gwa_type & IPV6_ADDR_UNICAST))
19531984
goto out;
19541985

1955-
grt = rt6_lookup(net, gw_addr, NULL, cfg->fc_ifindex, 1);
1986+
if (cfg->fc_table)
1987+
grt = ip6_nh_lookup_table(net, cfg, gw_addr);
1988+
1989+
if (!grt)
1990+
grt = rt6_lookup(net, gw_addr, NULL,
1991+
cfg->fc_ifindex, 1);
19561992

19571993
err = -EHOSTUNREACH;
19581994
if (!grt)

0 commit comments

Comments
 (0)