Skip to contentSkip to conversation

net: ipv6 bind to device issue

PATCH In review Jiri Olsa 3 participants 7 messages Apr 20, 2010 – Apr 22, 2010

Subsystems (3)
lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

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_output function:

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
index c2438e8..7bf7717 100644
@@ -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))
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jiri Olsa

---

net/ipv6/route.c +0 -0
index c2438e8..7bf7717 100644

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.

author
#2 lore raw
In reply to Jiri Olsa
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_output function:

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.

Quoted 7 lines

Following patch should handle the issue.

wbr,
jirka

Quoted 14 lines

---

net/ipv6/route.c +1 -1
index c2438e8..7bf7717 100644
@@ -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))
#3 lore raw
In reply to Jiri Olsa

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
index c2438e8..7bf7717 100644
@@ -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

author
#4 lore raw
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
index c2438e8..7bf7717 100644
@@ -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:

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_output function:

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
index c2438e8..05ebd78 100644
@@ -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))
maintainer
#5 lore raw
In reply to Brian Haley

From: 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->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.

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.

maintainer
#6 lore raw

From: 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!