net: ipv6 bind to device issue
Subsystems (3)
PATCH 1/1 net: ipv6 bind to device issue
hi,
The issue raises when having 2 NICs both assigned the same IPv6 global address.
If a sender binds to a particular NIC (SO_BINDTODEVICE), the outgoing traffic is being sent via the first found. The bonded device is thus not taken into an account during the routing.
Quoted 1 line
From the
ip6_route_outputfunction:
If the binding address is multicast, linklocal or loopback, the RT6_LOOKUP_F_IFACE bit is set, but not for global address.
So binding global address will neglect SO_BINDTODEVICE-binded device, because the fib6_rule_lookup function path won't check for the flowi::oif field and take first route that fits.
Following patch should handle the issue.
wbr,
jirka
---
net/ipv6/route.c +1 -1
@@ -815,7 +815,7 @@ struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, {int flags =0 ; -if (rt6_need_strict (&fl->fl6_dst)) +if (rt6_need_strict (&fl->fl6_dst) || fl->oif) flags |=RT6_LOOKUP_F_IFACE ;if (!ipv6_addr_any (&fl->fl6_src))
Quoted 7 lines · Jiri Olsa
Signed-off-by Jiri Olsa <[email protected]>---
net/ipv6/route.c +0
-0
net/ipv6/route.c struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, · line 821
Quoted 8 lines
net/ipv6/route.c +1
-1@@ -815,7 +815,7 @@ struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, {int flags =0 ; -if (rt6_need_strict (&fl->fl6_dst)) +if (rt6_need_strict (&fl->fl6_dst) || fl->oif) flags |=RT6_LOOKUP_F_IFACE ;if (!ipv6_addr_any (&fl->fl6_src))
Saw this within the past month here too and have been testing this same fix without problems.
Quoted 20 lines · Jiri Olsa
hi,
The issue raises when having 2 NICs both assigned the same IPv6 global address.
If a sender binds to a particular NIC (
SO_BINDTODEVICE), the outgoing traffic is being sent via the first found. The bonded device is thus not taken into an account during the routing.From the
ip6_route_outputfunction:If the binding address is multicast, linklocal or loopback, the
RT6_LOOKUP_F_IFACEbit is set, but not for global address.So binding global address will neglect SO_BINDTODEVICE-binded device, because the
fib6_rule_lookupfunction path won't check for theflowi::oiffield and take first route that fits.
Quoted 7 lines
Following patch should handle the issue.
wbr,
jirkaSigned-off-by Jiri Olsa <[email protected]>
Quoted 14 lines
---
net/ipv6/route.c +1
-1@@ -815,7 +815,7 @@ struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, {int flags =0 ; -if (rt6_need_strict (&fl->fl6_dst)) +if (rt6_need_strict (&fl->fl6_dst) || fl->oif) flags |=RT6_LOOKUP_F_IFACE ;if (!ipv6_addr_any (&fl->fl6_src))
net/ipv6/route.c struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, · line 821
Quoted 13 lines · Jiri Olsa
net/ipv6/route.c +1
-1@@ -815,7 +815,7 @@ struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, {int flags =0 ; -if (rt6_need_strict (&fl->fl6_dst)) +if (rt6_need_strict (&fl->fl6_dst) || fl->oif) flags |=RT6_LOOKUP_F_IFACE ;if (!ipv6_addr_any (&fl->fl6_src))
Actually, looking at this again, we might want to swap the order here since fl->oif should be filled-in for most link-local and multicast requests calling this:
if (fl->oif || rt6_need_strict(&fl->fl6_dst))
Just a thought, but it potentially saves a call to determine the scope of the address.
-Brian
Quoted 19 lines · Brian Haley
net/ipv6/route.c struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, · line 821
Quoted 13 lines · Jiri Olsa
net/ipv6/route.c +1
-1@@ -815,7 +815,7 @@ struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, {int flags =0 ; -if (rt6_need_strict (&fl->fl6_dst)) +if (rt6_need_strict (&fl->fl6_dst) || fl->oif) flags |=RT6_LOOKUP_F_IFACE ;if (!ipv6_addr_any (&fl->fl6_src))Actually, looking at this again, we might want to swap the order here since
fl->oifshould be filled-in for most link-local and multicast requests calling this:
Quoted 6 lines
if (fl->oif || rt6_need_strict(&fl->fl6_dst))Just a thought, but it potentially saves a call to determine the scope of the address.
-Brian
I think it's a good idea, attaching the changed patch
thanks,
jirka
---
The issue raises when having 2 NICs both assigned the same IPv6 global address.
If a sender binds to a particular NIC (SO_BINDTODEVICE), the outgoing traffic is being sent via the first found. The bonded device is thus not taken into an account during the routing.
Quoted 1 line
From the
ip6_route_outputfunction:
If the binding address is multicast, linklocal or loopback, the RT6_LOOKUP_F_IFACE bit is set, but not for global address.
So binding global address will neglect SO_BINDTODEVICE-binded device, because the fib6_rule_lookup function path won't check for the flowi::oif field and take first route that fits.
Following patch should handle the issue.
wbr,
jirka
--- net/ipv6/route.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/ipv6/route.c +1 -1
@@ -815,7 +815,7 @@ struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, {int flags =0 ; -if (rt6_need_strict (&fl->fl6_dst)) +if (fl->oif ||rt6_need_strict (&fl->fl6_dst)) flags |=RT6_LOOKUP_F_IFACE ;if (!ipv6_addr_any (&fl->fl6_src))
David Miller
maintainerFrom: Brian Haley <[email protected]>
Date: Tue, 20 Apr 2010 14:13:39 -0400
Quoted 8 lines
Actually, looking at this again, we might want to swap the order here since
fl->oifshould be filled-in for most link-local and multicast requests calling this:if (fl->oif || rt6_need_strict(&fl->fl6_dst))Just a thought, but it potentially saves a call to determine the scope of the address.
Yes I think we should make this change.
Jiri please respin your patch with the argument order reversed so that we can make the inexpensive check before the expensive one.
Thanks.
David Miller
maintainerFrom: David Miller <[email protected]>
Date: Wed, 21 Apr 2010 22:50:15 -0700 (PDT)
Quoted 3 lines
Jiri please respin your patch with the argument order reversed so that we can make the inexpensive check before the expensive one.
Nevermind, I see you posted an updated version already, which I've applied, thanks!