Subject: Re: Forcing the output interface using ip6_route_output doesn't work

From: David Ahern <[email-masked]>
Date: Fri, 25 Sep 2015 15:13:03 -0600

On 9/25/15 7:56 AM, Wolfgang Nothdurft wrote:
> It seems that the ip6_route_output(net, sk, fl6) kernel function ignores
> the fl6.flowi6_oif parameter for the routing decision.

It is considered, but a mismatch is not considered fatal.

I think the attached should fix your problem.

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 118f8fa1a809..cc52458f7226 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1169,7 +1169,8 @@ struct dst_entry *ip6_route_output(struct net *net, const struct sock *sk,
 
 	fl6->flowi6_iif = LOOPBACK_IFINDEX;
 
-	if ((sk && sk->sk_bound_dev_if) || rt6_need_strict(&fl6->daddr))
+	if ((sk && sk->sk_bound_dev_if) || rt6_need_strict(&fl6->daddr) ||
+	     fl6->flowi6_oif)
 		flags |= RT6_LOOKUP_F_IFACE;
 
 	if (!ipv6_addr_any(&fl6->saddr))