diff mbox series

[v3,net-next,09/20] ipv6: Handle all fib6_nh in a nexthop in rt6_do_redirect

Message ID 20190607230610.10349-10-dsahern@kernel.org
State Changes Requested
Delegated to: David Miller
Headers show
Series net: Enable nexthop objects with IPv4 and IPv6 routes | expand

Commit Message

David Ahern June 7, 2019, 11:05 p.m. UTC
From: David Ahern <dsahern@gmail.com>

Use nexthop_for_each_fib6_nh and fib6_nh_find_match to find the
fib6_nh in a nexthop that correlates to the device and gateway
in the rt6_info.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 net/ipv6/route.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Comments

Wei Wang June 8, 2019, 12:11 a.m. UTC | #1
On Fri, Jun 7, 2019 at 4:06 PM David Ahern <dsahern@kernel.org> wrote:
>
> From: David Ahern <dsahern@gmail.com>
>
> Use nexthop_for_each_fib6_nh and fib6_nh_find_match to find the
> fib6_nh in a nexthop that correlates to the device and gateway
> in the rt6_info.
>
> Signed-off-by: David Ahern <dsahern@gmail.com>
> ---
>  net/ipv6/route.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 2eb6754c6d11..1c6cff699a76 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -3903,7 +3903,25 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu
>         if (!res.f6i)
>                 goto out;
>
> -       res.nh = res.f6i->fib6_nh;
> +       if (res.f6i->nh) {
> +               struct fib6_nh_match_arg arg = {
> +                       .dev = dst->dev,
> +                       .gw = &rt->rt6i_gateway,
> +               };
> +
> +               nexthop_for_each_fib6_nh(res.f6i->nh,
> +                                        fib6_nh_find_match, &arg);
> +
> +               /* fib6_info uses a nexthop that does not have fib6_nh
> +                * using the dst->dev. Should be impossible
> +                */
> +               if (!arg.match)
> +                       return;
I don't think you can directly return here. We are still holding
rcu_read_lock() here. Probably need "goto out"...


> +               res.nh = arg.match;
> +       } else {
> +               res.nh = res.f6i->fib6_nh;
> +       }
> +
>         res.fib6_flags = res.f6i->fib6_flags;
>         res.fib6_type = res.f6i->fib6_type;
>         nrt = ip6_rt_cache_alloc(&res, &msg->dest, NULL);
> --
> 2.11.0
>
David Ahern June 8, 2019, 12:22 a.m. UTC | #2
On 6/7/19 6:11 PM, Wei Wang wrote:
> I don't think you can directly return here. We are still holding
> rcu_read_lock() here. Probably need "goto out"...

ouch. yes, thank you for catching that.
diff mbox series

Patch

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 2eb6754c6d11..1c6cff699a76 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3903,7 +3903,25 @@  static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_bu
 	if (!res.f6i)
 		goto out;
 
-	res.nh = res.f6i->fib6_nh;
+	if (res.f6i->nh) {
+		struct fib6_nh_match_arg arg = {
+			.dev = dst->dev,
+			.gw = &rt->rt6i_gateway,
+		};
+
+		nexthop_for_each_fib6_nh(res.f6i->nh,
+					 fib6_nh_find_match, &arg);
+
+		/* fib6_info uses a nexthop that does not have fib6_nh
+		 * using the dst->dev. Should be impossible
+		 */
+		if (!arg.match)
+			return;
+		res.nh = arg.match;
+	} else {
+		res.nh = res.f6i->fib6_nh;
+	}
+
 	res.fib6_flags = res.f6i->fib6_flags;
 	res.fib6_type = res.f6i->fib6_type;
 	nrt = ip6_rt_cache_alloc(&res, &msg->dest, NULL);