Re: ipv6 accept does not convert ipv4 connections to ipv6-mapped

From: Andi Kleen (ak@suse.de)
Date: Thu May 04 2000 - 05:19:52 EST


Felix von Leitner <felix@convergence.de> writes:

> Thus spake Felix von Leitner (felix@convergence.de):
> > I am currently porting tcpserver et al to IPv6.
> > According to the Stevens book (unix network programming, sockets API),
> > when I create an IPv6 server socket on port foo the kernel should
> > transparently accept IPv4 connections on port foo and return an IPv6
> > connection to the server where the IPv6 address is the IPv4 address
> > converted to IPv6-mapped format.
>
> > The Linux kernel does not do this.
>
> Sorry, my mistake.
> The Linux kernel does this if you socket(PF_INET6), which I forgot to
> modify. For some reason I could still bind the fd to an IPv6 address,
> though. That shouldn't be possible, should it?

Yes, it shouldn't. It is a bug in the linux kernel that it doesn't
check sin_family on bind. I suspect changing it will break quite
a lot of programs though :/

Anyways, here is a patch:

--- net/ipv4/af_inet.c-o Sun Feb 27 13:57:19 2000
+++ net/ipv4/af_inet.c Thu May 4 10:52:44 2000
@@ -459,7 +459,8 @@
         if(sk->prot->bind)
                 return sk->prot->bind(sk, uaddr, addr_len);
 
- if (addr_len < sizeof(struct sockaddr_in))
+ if (addr_len < sizeof(struct sockaddr_in) ||
+ addr->sin_family != AF_INET)
                 return -EINVAL;
                 
         chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);

-Andi

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun May 07 2000 - 21:00:14 EST