All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipv6: check for IPv4 mapped addresses when connecting IPv6 sockets
@ 2011-08-04  7:42 Max Matveev
  2011-08-04 14:14 ` Vladislav Yasevich
  2011-08-05 10:57 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Max Matveev @ 2011-08-04  7:42 UTC (permalink / raw)
  To: netdev; +Cc: vladislav.yasevich

When support for binding to 'mapped INADDR_ANY (::ffff.0.0.0.0)' was added
in 0f8d3c7ac3693d7b6c731bf2159273a59bf70e12 the rest of the code
wasn't told so now it's possible to bind IPv6 datagram socket to
::ffff.0.0.0.0, connect it to another IPv4 address and it will all
work except for getsockhame() which does not return the local address
as expected.

To give getsockname() something to work with check for 'mapped INADDR_ANY'
when connecting and update the in-core source addresses appropriately.

Signed-off-by: Max Matveev <makc@redhat.com>
---
 net/ipv6/datagram.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index 1656033..d3a65a18 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -33,6 +33,11 @@
 #include <linux/errqueue.h>
 #include <asm/uaccess.h>
 
+static inline int ipv6_mapped_addr_any(const struct in6_addr *a)
+{
+	return (ipv6_addr_v4mapped(a) && (a->s6_addr32[3] == 0));
+}
+
 int ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 {
 	struct sockaddr_in6	*usin = (struct sockaddr_in6 *) uaddr;
@@ -102,10 +107,12 @@ ipv4_connected:
 
 		ipv6_addr_set_v4mapped(inet->inet_daddr, &np->daddr);
 
-		if (ipv6_addr_any(&np->saddr))
+		if (ipv6_addr_any(&np->saddr) ||
+		    ipv6_mapped_addr_any(&np->saddr))
 			ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr);
 
-		if (ipv6_addr_any(&np->rcv_saddr)) {
+		if (ipv6_addr_any(&np->rcv_saddr) || 
+		    ipv6_mapped_addr_any(&np->rcv_saddr)) {
 			ipv6_addr_set_v4mapped(inet->inet_rcv_saddr,
 					       &np->rcv_saddr);
 			if (sk->sk_prot->rehash)
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ipv6: check for IPv4 mapped addresses when connecting IPv6 sockets
  2011-08-04  7:42 [PATCH] ipv6: check for IPv4 mapped addresses when connecting IPv6 sockets Max Matveev
@ 2011-08-04 14:14 ` Vladislav Yasevich
  2011-08-05 10:57 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Vladislav Yasevich @ 2011-08-04 14:14 UTC (permalink / raw)
  To: Max Matveev; +Cc: netdev

On 08/04/2011 03:42 AM, Max Matveev wrote:
> When support for binding to 'mapped INADDR_ANY (::ffff.0.0.0.0)' was added
> in 0f8d3c7ac3693d7b6c731bf2159273a59bf70e12 the rest of the code
> wasn't told so now it's possible to bind IPv6 datagram socket to
> ::ffff.0.0.0.0, connect it to another IPv4 address and it will all
> work except for getsockhame() which does not return the local address
> as expected.
> 
> To give getsockname() something to work with check for 'mapped INADDR_ANY'
> when connecting and update the in-core source addresses appropriately.
> 
> Signed-off-by: Max Matveev <makc@redhat.com>

Yes.  Good catch.

-vlad

> ---
>  net/ipv6/datagram.c |   11 +++++++++--
>  1 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
> index 1656033..d3a65a18 100644
> --- a/net/ipv6/datagram.c
> +++ b/net/ipv6/datagram.c
> @@ -33,6 +33,11 @@
>  #include <linux/errqueue.h>
>  #include <asm/uaccess.h>
>  
> +static inline int ipv6_mapped_addr_any(const struct in6_addr *a)
> +{
> +	return (ipv6_addr_v4mapped(a) && (a->s6_addr32[3] == 0));
> +}
> +
>  int ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
>  {
>  	struct sockaddr_in6	*usin = (struct sockaddr_in6 *) uaddr;
> @@ -102,10 +107,12 @@ ipv4_connected:
>  
>  		ipv6_addr_set_v4mapped(inet->inet_daddr, &np->daddr);
>  
> -		if (ipv6_addr_any(&np->saddr))
> +		if (ipv6_addr_any(&np->saddr) ||
> +		    ipv6_mapped_addr_any(&np->saddr))
>  			ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr);
>  
> -		if (ipv6_addr_any(&np->rcv_saddr)) {
> +		if (ipv6_addr_any(&np->rcv_saddr) || 
> +		    ipv6_mapped_addr_any(&np->rcv_saddr)) {
>  			ipv6_addr_set_v4mapped(inet->inet_rcv_saddr,
>  					       &np->rcv_saddr);
>  			if (sk->sk_prot->rehash)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ipv6: check for IPv4 mapped addresses when connecting IPv6 sockets
  2011-08-04  7:42 [PATCH] ipv6: check for IPv4 mapped addresses when connecting IPv6 sockets Max Matveev
  2011-08-04 14:14 ` Vladislav Yasevich
@ 2011-08-05 10:57 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2011-08-05 10:57 UTC (permalink / raw)
  To: makc; +Cc: netdev, vladislav.yasevich

From: Max Matveev <makc@redhat.com>
Date: Thu, 4 Aug 2011 17:42:44 +1000

> When support for binding to 'mapped INADDR_ANY (::ffff.0.0.0.0)' was added
> in 0f8d3c7ac3693d7b6c731bf2159273a59bf70e12 the rest of the code
> wasn't told so now it's possible to bind IPv6 datagram socket to
> ::ffff.0.0.0.0, connect it to another IPv4 address and it will all
> work except for getsockhame() which does not return the local address
> as expected.
> 
> To give getsockname() something to work with check for 'mapped INADDR_ANY'
> when connecting and update the in-core source addresses appropriately.
> 
> Signed-off-by: Max Matveev <makc@redhat.com>

Applied, but I had to fixup some trailing whitespace:

> @@ -102,10 +107,12 @@ ipv4_connected:
>  
>  		ipv6_addr_set_v4mapped(inet->inet_daddr, &np->daddr);
>  
> -		if (ipv6_addr_any(&np->saddr))
> +		if (ipv6_addr_any(&np->saddr) ||
> +		    ipv6_mapped_addr_any(&np->saddr))
>  			ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr);
>  
> -		if (ipv6_addr_any(&np->rcv_saddr)) {
> +		if (ipv6_addr_any(&np->rcv_saddr) || 
						    ^^

there.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-05 10:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-04  7:42 [PATCH] ipv6: check for IPv4 mapped addresses when connecting IPv6 sockets Max Matveev
2011-08-04 14:14 ` Vladislav Yasevich
2011-08-05 10:57 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.