Netdev List
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: Ido Schimmel <idosch@nvidia.com>, netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	edumazet@google.com, horms@kernel.org, willemb@google.com
Subject: Re: [PATCH net-next v2 1/2] ipv6: Honor oif when choosing nexthop for locally generated traffic
Date: Mon, 1 Jun 2026 20:51:21 -0600	[thread overview]
Message-ID: <d6bf3a67-3629-42ce-b2b3-74482c46fe01@kernel.org> (raw)
In-Reply-To: <20260601065300.267960-2-idosch@nvidia.com>

On 6/1/26 12:52 AM, Ido Schimmel wrote:
> Commit 741a11d9e410 ("net: ipv6: Add RT6_LOOKUP_F_IFACE flag if oif is
> set") made the kernel honor the oif parameter when specified as part of
> output route lookup:
> 
>  # ip route add 2001:db8:1::/64 dev dummy1
>  # ip route add ::/0 dev dummy2
>  # ip route get 2001:db8:1::1 oif dummy2 fibmatch
>  default dev dummy2 metric 1024 pref medium
> 
> Due to regression reports, the behavior was partially reverted in commit
> d46a9d678e4c ("net: ipv6: Dont add RT6_LOOKUP_F_IFACE flag if saddr
> set") to only honor the oif if source address is not specified:
> 
>  # ip route get 2001:db8:1::1 from 2001:db8:2::1 oif dummy2 fibmatch
>  2001:db8:1::/64 dev dummy1 metric 1024 pref medium
> 
> That is, when source address is specified, the kernel will choose the
> most specific route even if its nexthop device does not match the
> specified oif.
> 
> This creates a problem for multipath routes. After looking up a route,
> when source address is not specified, the kernel will choose a nexthop
> whose nexthop device matches the specified oif:
> 
>  # sysctl -wq net.ipv6.conf.all.forwarding=1
>  # ip route add 2001:db8:10::/64 nexthop via fe80::1 dev dummy1 nexthop via fe80::2 dev dummy2
>  # for i in {1..100}; do ip route get 2001:db8:10::${i} oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
>       100 dummy2
> 
> But will disregard the oif when source address is specified despite the
> fact that a matching nexthop exists:
> 
>  # for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
>       53 dummy1
>       47 dummy2
> 
> This behavior differs from IPv4:
> 
>  # ip address add 192.0.2.1/32 dev lo
>  # ip route add 198.51.100.0/24 nexthop via inet6 fe80::1 dev dummy1 nexthop via inet6 fe80::2 dev dummy2
>  # for i in {1..100}; do ip route get 198.51.100.${i} from 192.0.2.1 oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
>      100 dummy2
> 
> What happens is that fib6_table_lookup() returns a route with a matching
> nexthop device (assuming it exists):
> 
>  # perf record -e fib6:fib6_table_lookup -- bash -c "for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy2; done > /dev/null"
>  # perf script | grep -o dummy[0-9] | sort | uniq -c
>       100 dummy2
> 
> But it is later overwritten during path selection in fib6_select_path()
> which instead chooses a nexthop according to the calculated hash.
> 
> Solve this by telling fib6_select_path() to skip path selection if we
> have an oif match during output route lookup (iif being
> LOOPBACK_IFINDEX).
> 
> Behavior after the change:
> 
>  # sysctl -wq net.ipv6.conf.all.forwarding=1
>  # ip route add 2001:db8:10::/64 nexthop via fe80::1 dev dummy1 nexthop via fe80::2 dev dummy2
>  # for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
>      100 dummy2
> 
> Note that enabling forwarding is only needed because we did not add
> neighbor entries for the gateway addresses. When forwarding is disabled
> and CONFIG_IPV6_ROUTER_PREF is not enabled in kernel config, the kernel
> will treat non-existing neighbor entries as errors and perform
> round-robin between the nexthops:
> 
>  # sysctl -wq net.ipv6.conf.all.forwarding=0
>  # for i in {1..100}; do ip route get 2001:db8:10::${i} from 2001:db8:2::1 oif dummy2; done | grep -o dummy[0-9] | sort | uniq -c
>       50 dummy1
>       50 dummy2
> 
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> ---
>  net/ipv6/route.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>



  reply	other threads:[~2026-06-02  2:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01  6:52 [PATCH net-next v2 0/2] ipv6: Honor oif when choosing nexthop for locally generated traffic Ido Schimmel
2026-06-01  6:52 ` [PATCH net-next v2 1/2] " Ido Schimmel
2026-06-02  2:51   ` David Ahern [this message]
2026-06-01  6:53 ` [PATCH net-next v2 2/2] selftests: fib_tests: Add test cases for route lookup with oif Ido Schimmel
2026-06-02  2:53   ` David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d6bf3a67-3629-42ce-b2b3-74482c46fe01@kernel.org \
    --to=dsahern@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox