Skip to contentSkip to conversation

ipv6 sit: Set relay to 0.0.0.0 directly if relay_prefixlen == 0.

PATCH RESEND Applied YOSHIFUJI Hideaki 3 participants 7 messages Oct 11, 2009 – Oct 12, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 3/3 ipv6 sit: Set relay to 0.0.0.0 directly if relay_prefixlen == 0.

ipv6 sit: Set relay to 0.0.0.0 directly if relay_prefixlen == 0.

Do not use bit-shift if relay_prefixlen == 0;
relay_prefix << 32 does not result in 0.

---
 net/ipv6/sit.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
net/ipv6/sit.c +6 -3
index 193d0c6..510d31f 100644
@@ -1014,9 +1014,12 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
 					 ip6rd.prefixlen);
 			if (!ipv6_addr_equal(&prefix, &ip6rd.prefix))
 				goto done;
-			relay_prefix = ip6rd.relay_prefix &
-				       htonl(0xffffffffUL <<
-					     (32 - ip6rd.relay_prefixlen));
+			if (ip6rd.relay_prefixlen)
+				relay_prefix = ip6rd.relay_prefix &
+					       htonl(0xffffffffUL <<
+						     (32 - ip6rd.relay_prefixlen));
+			else
+				relay_prefix = 0;
 			if (relay_prefix != ip6rd.relay_prefix)
 				goto done;
 
#1 lore raw
Quoted 20 lines · YOSHIFUJI Hideaki

ipv6 sit: Set relay to 0.0.0.0 directly if relay_prefixlen == 0.

Do not use bit-shift if relay_prefixlen == 0;
relay_prefix << 32 does not result in 0.

---
 net/ipv6/sit.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
net/ipv6/sit.c +0 -2
index 193d0c6..510d31f 100644
@@ -1014,9 +1014,12 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
 					 ip6rd.prefixlen);
 			if (!ipv6_addr_equal(&prefix, &ip6rd.prefix))
 				goto done;
-			relay_prefix = ip6rd.relay_prefix &
-				       htonl(0xffffffffUL <<

net/ipv6/sit.c ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) · line 1025

Quoted 10 lines
net/ipv6/sit.c +6 -1
-					     (32 - ip6rd.relay_prefixlen));
+			if (ip6rd.relay_prefixlen)
+				relay_prefix = ip6rd.relay_prefix &
+					       htonl(0xffffffffUL <<
+						     (32 - ip6rd.relay_prefixlen));
+			else
+				relay_prefix = 0;
 			if (relay_prefix != ip6rd.relay_prefix)
 				goto done;
 

Sorry I dont get it

u32 val = any_value ;
u32 relay_prefix = val & htonl(0xffffffffUL << 32) should give 0

If not, something is broken and should be fixed.

maintainer
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Mon, 12 Oct 2009 09:32:41 +0200

Quoted 6 lines

Sorry I dont get it

u32 val = any_value ;
u32 relay_prefix = val & htonl(0xffffffffUL << 32) should give 0

If not, something is broken and should be fixed.

Indeed, it's "x >> 32" which is undefined and has to be done as something like "(x >> 31) >> 1" when performed on a u32 object.

Yoshfuji is this patch really necessary?

#3 lore raw
Quoted 8 lines · David Miller

From: Eric Dumazet <[email protected]>
Date: Mon, 12 Oct 2009 09:32:41 +0200

Quoted 5 lines

Sorry I dont get it

u32 val = any_value ;
u32 relay_prefix = val & htonl(0xffffffffUL << 32) should give 0

Quoted 6 lines
Quoted 1 line

If not, something is broken and should be fixed.

Indeed, it's "x >> 32" which is undefined and has to be done as something like "(x >> 31) >> 1" when performed on a u32 object.

Yoshfuji is this patch really necessary?

Well, yes.
6rd allows 32 bit suffix (0 bit prefix).

--yoshfuji

#4 lore raw
In reply to Eric Dumazet
Quoted 35 lines · Eric Dumazet
Quoted 20 lines · YOSHIFUJI Hideaki

ipv6 sit: Set relay to 0.0.0.0 directly if relay_prefixlen == 0.

Do not use bit-shift if relay_prefixlen == 0;
relay_prefix << 32 does not result in 0.

---
 net/ipv6/sit.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
net/ipv6/sit.c +0 -2
index 193d0c6..510d31f 100644
@@ -1014,9 +1014,12 @@ ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
 					 ip6rd.prefixlen);
 			if (!ipv6_addr_equal(&prefix, &ip6rd.prefix))
 				goto done;
-			relay_prefix = ip6rd.relay_prefix &
-				       htonl(0xffffffffUL <<

net/ipv6/sit.c ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd) · line 1025

Quoted 10 lines
net/ipv6/sit.c +6 -1
-					     (32 - ip6rd.relay_prefixlen));
+			if (ip6rd.relay_prefixlen)
+				relay_prefix = ip6rd.relay_prefix &
+					       htonl(0xffffffffUL <<
+						     (32 - ip6rd.relay_prefixlen));
+			else
+				relay_prefix = 0;
 			if (relay_prefix != ip6rd.relay_prefix)
 				goto done;
 

Sorry I dont get it

Quoted 4 lines

u32 val = any_value ;
u32 relay_prefix = val & htonl(0xffffffffUL << 32) should give 0

If not, something is broken and should be fixed.

Unfortunately, on x86 architecture (80286 and later at least), lower 5 bits (& 0x1f) are used for shift operation. Thus, 0xffffffffUL << 32 gives 0xffffffffUL.

--yoshfuji

maintainer
#5 lore raw

From: YOSHIFUJI Hideaki <[email protected]>
Date: Mon, 12 Oct 2009 17:50:54 +0900

Quoted 3 lines

Unfortunately, on x86 architecture (80286 and later at least), lower 5 bits (& 0x1f) are used for shift operation. Thus, 0xffffffffUL << 32 gives 0xffffffffUL.

Indeed, thanks for the explanation, I thought only right shift mattered for this case of "shift count larger than type".