All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] ipv6: Honor specified parameters in fibmatch lookup
@ 2017-12-20 10:28 Ido Schimmel
  2017-12-21  2:54 ` David Ahern
  2017-12-21 16:51 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Ido Schimmel @ 2017-12-20 10:28 UTC (permalink / raw)
  To: netdev; +Cc: davem, roopa, dsahern, mlxsw, Ido Schimmel

Currently, parameters such as oif and source address are not taken into
account during fibmatch lookup. Example (IPv4 for reference) before
patch:

$ ip -4 route show
192.0.2.0/24 dev dummy0 proto kernel scope link src 192.0.2.1
198.51.100.0/24 dev dummy1 proto kernel scope link src 198.51.100.1

$ ip -6 route show
2001:db8:1::/64 dev dummy0 proto kernel metric 256 pref medium
2001:db8:2::/64 dev dummy1 proto kernel metric 256 pref medium
fe80::/64 dev dummy0 proto kernel metric 256 pref medium
fe80::/64 dev dummy1 proto kernel metric 256 pref medium

$ ip -4 route get fibmatch 192.0.2.2 oif dummy0
192.0.2.0/24 dev dummy0 proto kernel scope link src 192.0.2.1
$ ip -4 route get fibmatch 192.0.2.2 oif dummy1
RTNETLINK answers: No route to host

$ ip -6 route get fibmatch 2001:db8:1::2 oif dummy0
2001:db8:1::/64 dev dummy0 proto kernel metric 256 pref medium
$ ip -6 route get fibmatch 2001:db8:1::2 oif dummy1
2001:db8:1::/64 dev dummy0 proto kernel metric 256 pref medium

After:

$ ip -6 route get fibmatch 2001:db8:1::2 oif dummy0
2001:db8:1::/64 dev dummy0 proto kernel metric 256 pref medium
$ ip -6 route get fibmatch 2001:db8:1::2 oif dummy1
RTNETLINK answers: Network is unreachable

The problem stems from the fact that the necessary route lookup flags
are not set based on these parameters.

Instead of duplicating the same logic for fibmatch, we can simply
resolve the original route from its copy and dump it instead.

Fixes: 18c3a61c4264 ("net: ipv6: RTM_GETROUTE: return matched fib result when requested")
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 net/ipv6/route.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 2bc91c349273..0458b761f3c5 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -4298,19 +4298,13 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
 		if (!ipv6_addr_any(&fl6.saddr))
 			flags |= RT6_LOOKUP_F_HAS_SADDR;
 
-		if (!fibmatch)
-			dst = ip6_route_input_lookup(net, dev, &fl6, flags);
-		else
-			dst = ip6_route_lookup(net, &fl6, 0);
+		dst = ip6_route_input_lookup(net, dev, &fl6, flags);
 
 		rcu_read_unlock();
 	} else {
 		fl6.flowi6_oif = oif;
 
-		if (!fibmatch)
-			dst = ip6_route_output(net, NULL, &fl6);
-		else
-			dst = ip6_route_lookup(net, &fl6, 0);
+		dst = ip6_route_output(net, NULL, &fl6);
 	}
 
 
@@ -4327,6 +4321,15 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
 		goto errout;
 	}
 
+	if (fibmatch && rt->dst.from) {
+		struct rt6_info *ort = container_of(rt->dst.from,
+						    struct rt6_info, dst);
+
+		dst_hold(&ort->dst);
+		ip6_rt_put(rt);
+		rt = ort;
+	}
+
 	skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
 	if (!skb) {
 		ip6_rt_put(rt);
-- 
2.14.3

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

* Re: [PATCH net] ipv6: Honor specified parameters in fibmatch lookup
  2017-12-20 10:28 [PATCH net] ipv6: Honor specified parameters in fibmatch lookup Ido Schimmel
@ 2017-12-21  2:54 ` David Ahern
  2017-12-21 16:51 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Ahern @ 2017-12-21  2:54 UTC (permalink / raw)
  To: Ido Schimmel, netdev; +Cc: davem, roopa, mlxsw

On 12/20/17 3:28 AM, Ido Schimmel wrote:
> @@ -4327,6 +4321,15 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
>  		goto errout;
>  	}
>  
> +	if (fibmatch && rt->dst.from) {
> +		struct rt6_info *ort = container_of(rt->dst.from,
> +						    struct rt6_info, dst);
> +
> +		dst_hold(&ort->dst);
> +		ip6_rt_put(rt);
> +		rt = ort;
> +	}
> +
>  	skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
>  	if (!skb) {
>  		ip6_rt_put(rt);
> 


That's going to need a fixup on the net-next merge -- from was moved
from dst to rt6_info. Change wise it looks ok to me.

Acked-by: David Ahern <dsahern@gmail.com>

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

* Re: [PATCH net] ipv6: Honor specified parameters in fibmatch lookup
  2017-12-20 10:28 [PATCH net] ipv6: Honor specified parameters in fibmatch lookup Ido Schimmel
  2017-12-21  2:54 ` David Ahern
@ 2017-12-21 16:51 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-12-21 16:51 UTC (permalink / raw)
  To: idosch; +Cc: netdev, roopa, dsahern, mlxsw

From: Ido Schimmel <idosch@mellanox.com>
Date: Wed, 20 Dec 2017 12:28:25 +0200

> Currently, parameters such as oif and source address are not taken into
> account during fibmatch lookup. Example (IPv4 for reference) before
> patch:
 ...
> The problem stems from the fact that the necessary route lookup flags
> are not set based on these parameters.
> 
> Instead of duplicating the same logic for fibmatch, we can simply
> resolve the original route from its copy and dump it instead.
> 
> Fixes: 18c3a61c4264 ("net: ipv6: RTM_GETROUTE: return matched fib result when requested")
> Signed-off-by: Ido Schimmel <idosch@mellanox.com>

Applied and queued up for -stable, thanks.

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

end of thread, other threads:[~2017-12-21 16:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-20 10:28 [PATCH net] ipv6: Honor specified parameters in fibmatch lookup Ido Schimmel
2017-12-21  2:54 ` David Ahern
2017-12-21 16:51 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.