netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX
@ 2019-08-01  8:29 Hangbin Liu
  2019-08-01 19:51 ` David Ahern
  0 siblings, 1 reply; 8+ messages in thread
From: Hangbin Liu @ 2019-08-01  8:29 UTC (permalink / raw)
  To: netdev
  Cc: Stefano Brivio, Marcelo Ricardo Leitner, David Ahern,
	David S . Miller, Hangbin Liu

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 <jishi@redhat.com>
Signed-off-by: Hangbin Liu <liuhangbin@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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX
  2019-08-01  8:29 [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX Hangbin Liu
@ 2019-08-01 19:51 ` David Ahern
  2019-08-02  4:13   ` Hangbin Liu
  2019-08-02 20:35   ` Stefano Brivio
  0 siblings, 2 replies; 8+ messages in thread
From: David Ahern @ 2019-08-01 19:51 UTC (permalink / raw)
  To: Hangbin Liu, netdev
  Cc: Stefano Brivio, Marcelo Ricardo Leitner, David Ahern, David S . Miller

On 8/1/19 2:29 AM, Hangbin Liu wrote:
> 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

so this is a forwarding lookup in which case iif should be set. Based on
the above 'route get' inet_rtm_getroute is doing a lookup as if it is
locally generated traffic.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX
  2019-08-01 19:51 ` David Ahern
@ 2019-08-02  4:13   ` Hangbin Liu
  2019-08-02  4:16     ` David Ahern
  2019-08-02 20:35   ` Stefano Brivio
  1 sibling, 1 reply; 8+ messages in thread
From: Hangbin Liu @ 2019-08-02  4:13 UTC (permalink / raw)
  To: David Ahern
  Cc: netdev, Stefano Brivio, Marcelo Ricardo Leitner, David S . Miller

On Thu, Aug 01, 2019 at 01:51:25PM -0600, David Ahern wrote:
> On 8/1/19 2:29 AM, Hangbin Liu wrote:
> > 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
> 
> so this is a forwarding lookup in which case iif should be set. Based on

with out setting iif in userspace, the kernel set iif to lo by default.

> the above 'route get' inet_rtm_getroute is doing a lookup as if it is
> locally generated traffic.

yeah... but what about the IPv6 part. That cause a different behavior in
userspace.

Thanks
Hangbin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX
  2019-08-02  4:13   ` Hangbin Liu
@ 2019-08-02  4:16     ` David Ahern
  2019-08-12  3:49       ` David Miller
  0 siblings, 1 reply; 8+ messages in thread
From: David Ahern @ 2019-08-02  4:16 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netdev, Stefano Brivio, Marcelo Ricardo Leitner, David S . Miller

On 8/1/19 10:13 PM, Hangbin Liu wrote:
> On Thu, Aug 01, 2019 at 01:51:25PM -0600, David Ahern wrote:
>> On 8/1/19 2:29 AM, Hangbin Liu wrote:
>>> 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
>>
>> so this is a forwarding lookup in which case iif should be set. Based on
> 
> with out setting iif in userspace, the kernel set iif to lo by default.

right, it presumes locally generated traffic.
> 
>> the above 'route get' inet_rtm_getroute is doing a lookup as if it is
>> locally generated traffic.
> 
> yeah... but what about the IPv6 part. That cause a different behavior in
> userspace.

just one of many, many annoying differences between v4 and v6. We could
try to catalog it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX
  2019-08-01 19:51 ` David Ahern
  2019-08-02  4:13   ` Hangbin Liu
@ 2019-08-02 20:35   ` Stefano Brivio
  1 sibling, 0 replies; 8+ messages in thread
From: Stefano Brivio @ 2019-08-02 20:35 UTC (permalink / raw)
  To: David Ahern
  Cc: Hangbin Liu, netdev, Marcelo Ricardo Leitner, David S . Miller

David,

On Thu, 1 Aug 2019 13:51:25 -0600
David Ahern <dsahern@gmail.com> wrote:

> On 8/1/19 2:29 AM, Hangbin Liu wrote:
> > 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  
> 
> so this is a forwarding lookup in which case iif should be set.

On actual forwarding, yes, it will be set.

But if we are just doing a lookup for a route (iif is
LOOPBACK_IFINDEX), I think this should still give us the matching route,
which is what IPv6 already does and what this patch fixes for IPv4.

Otherwise, we have no way to fetch that route, no matter if source
routing is configured. So I think this patch is correct and to some
extent necessary.

-- 
Stefano

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX
  2019-08-02  4:16     ` David Ahern
@ 2019-08-12  3:49       ` David Miller
  2019-08-12 22:58         ` Stefano Brivio
  0 siblings, 1 reply; 8+ messages in thread
From: David Miller @ 2019-08-12  3:49 UTC (permalink / raw)
  To: dsahern; +Cc: liuhangbin, netdev, sbrivio, mleitner

From: David Ahern <dsahern@gmail.com>
Date: Thu, 1 Aug 2019 22:16:00 -0600

> On 8/1/19 10:13 PM, Hangbin Liu wrote:
>> On Thu, Aug 01, 2019 at 01:51:25PM -0600, David Ahern wrote:
>>> On 8/1/19 2:29 AM, Hangbin Liu wrote:
>>>> 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
>>>
>>> so this is a forwarding lookup in which case iif should be set. Based on
>> 
>> with out setting iif in userspace, the kernel set iif to lo by default.
> 
> right, it presumes locally generated traffic.
>> 
>>> the above 'route get' inet_rtm_getroute is doing a lookup as if it is
>>> locally generated traffic.
>> 
>> yeah... but what about the IPv6 part. That cause a different behavior in
>> userspace.
> 
> just one of many, many annoying differences between v4 and v6. We could
> try to catalog it.

I think we just have to accept this difference because this change would
change behavior for all route lookups, not just those done by ip route get.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX
  2019-08-12  3:49       ` David Miller
@ 2019-08-12 22:58         ` Stefano Brivio
  2019-08-13  0:23           ` David Ahern
  0 siblings, 1 reply; 8+ messages in thread
From: Stefano Brivio @ 2019-08-12 22:58 UTC (permalink / raw)
  To: David Miller; +Cc: dsahern, liuhangbin, netdev, mleitner

On Sun, 11 Aug 2019 20:49:18 -0700 (PDT)
David Miller <davem@davemloft.net> wrote:

> From: David Ahern <dsahern@gmail.com>
> Date: Thu, 1 Aug 2019 22:16:00 -0600
> 
> > On 8/1/19 10:13 PM, Hangbin Liu wrote:  
> >> On Thu, Aug 01, 2019 at 01:51:25PM -0600, David Ahern wrote:  
> >>> On 8/1/19 2:29 AM, Hangbin Liu wrote:  
> >>>> 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  
> >>>
> >>> so this is a forwarding lookup in which case iif should be set. Based on  
> >> 
> >> with out setting iif in userspace, the kernel set iif to lo by default.  
> > 
> > right, it presumes locally generated traffic.  
> >>   
> >>> the above 'route get' inet_rtm_getroute is doing a lookup as if it is
> >>> locally generated traffic.  
> >> 
> >> yeah... but what about the IPv6 part. That cause a different behavior in
> >> userspace.  
> > 
> > just one of many, many annoying differences between v4 and v6. We could
> > try to catalog it.  
> 
> I think we just have to accept this difference because this change would
> change behavior for all route lookups, not just those done by ip route get.

How so, actually? I don't see how that would happen. On the forwarding
path, 'iif' is set (not to loopback interface), so that's not affected.

Is there any other route lookup possibility I'm missing?

-- 
Stefano

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX
  2019-08-12 22:58         ` Stefano Brivio
@ 2019-08-13  0:23           ` David Ahern
  0 siblings, 0 replies; 8+ messages in thread
From: David Ahern @ 2019-08-13  0:23 UTC (permalink / raw)
  To: Stefano Brivio, David Miller; +Cc: liuhangbin, netdev, mleitner

On 8/12/19 4:58 PM, Stefano Brivio wrote:
> How so, actually? I don't see how that would happen. On the forwarding
> path, 'iif' is set (not to loopback interface), so that's not affected.
> 
> Is there any other route lookup possibility I'm missing?

Use case is saddr is set and FLOWI_FLAG_ANYSRC is not set and that seems
pretty common to me. From a quick look, icmp_route_lookup,
ipv4_update_pmtu, ipv4_redirect, inet_csk_route_req, ...

Enable trace_fib_table_lookup and look at the flags for various use cases.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-08-13  0:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01  8:29 [PATCH net] ipv4/route: do not check saddr dev if iif is LOOPBACK_IFINDEX Hangbin Liu
2019-08-01 19:51 ` David Ahern
2019-08-02  4:13   ` Hangbin Liu
2019-08-02  4:16     ` David Ahern
2019-08-12  3:49       ` David Miller
2019-08-12 22:58         ` Stefano Brivio
2019-08-13  0:23           ` David Ahern
2019-08-02 20:35   ` Stefano Brivio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).