Jianlin reported a bug that for IPv4, ip route get from src_addr would fail if src_addr is not an address on local system.
\# ip route get 1.1.1.1 from 2.2.2.2 RTNETLINK answers: Invalid argument While IPv6 would get the default route \# ip -6 route get 1111::1 from 2222::2 1111::1 from 2222::2 via fe80:52:0:4982::1fe dev eth0 proto ra src \ 2620::2cf:e2ff:fe40:37 metric 1024 hoplimit 64 pref medium Fix it by disabling the __ip_dev_find() check if iif is LOOPBACK_IFINDEX. Reported-by: Jianlin Shi <ji...@redhat.com> Signed-off-by: Hangbin Liu <liuhang...@gmail.com> --- net/ipv4/route.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 517300d587a7..1be78e8f9e3c 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -2512,7 +2512,8 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4, goto make_route; } - if (!(fl4->flowi4_flags & FLOWI_FLAG_ANYSRC)) { + if (!(fl4->flowi4_flags & FLOWI_FLAG_ANYSRC) && + fl4->flowi4_iif != LOOPBACK_IFINDEX) { /* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */ if (!__ip_dev_find(net, fl4->saddr, false)) goto out; -- 2.19.2