kern/127057: [udp] Unable to send UDP packet via IPv6 socket to IPv4 mapped address

Alexander V. Chernikov melifaro at ipfw.ru
Thu Jun 24 15:50:05 UTC 2010


The following reply was made to PR kern/127057; it has been noted by GNATS.

From: "Alexander V. Chernikov" <melifaro at ipfw.ru>
To: bug-followup at FreeBSD.org, saper at SYSTEM.PL
Cc:  
Subject: Re: kern/127057: [udp] Unable to send UDP packet via IPv6 socket
 to IPv4 mapped address
Date: Thu, 24 Jun 2010 19:44:25 +0400

 1) Problem can be more easily reproduced with nc:
 echo | ktrace nc -nu6 ::ffff:127.0.0.1 53 ; kdump | grep socket -A 15
 
   1682 nc       CALL  socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP)
   1682 nc       RET   socket 3
   1682 nc       CALL  connect(0x3,0x800a050e0,0x1c)
   1682 nc       STRU  struct sockaddr { AF_INET6, [::ffff:127.0.0.1]:53 }
   1682 nc       RET   connect 0
   1682 nc       CALL  poll(0x7fffffffa6b0,0x2,0xffffffff)
   1682 nc       RET   poll 1
   1682 nc       CALL  read(0,0x7fffffffa6c0,0x400)
   1682 nc       GIO   fd 0 read 1 byte
        "
        "
   1682 nc       RET   read 1
   1682 nc       CALL  write(0x3,0x7fffffffa6c0,0x1)
   1682 nc       RET   write -1 errno 22 Invalid argument
 
 Problem is related with [implicit] IPv4 bind done by in_pcbconnect  (or 
 in_pcbbind_setup in case of explicit bind())
 Selected IPv4 IP address is written into inpcb -> 
 inp_inc.inc_ie.ie_dependladdr.ie46_local
 According to struct in_addr_4in6 interpreting written value as IPv6 
 address results in ::127.0.0.1, which is not correct v4-mapped address 
 (it is actually deprecated ipv4-compatible address),
 so IN6_IS_ADDR_V4MAPPED() address check in udp6_send failes with EINVAL.
 
 
 
 Proposed solution is to add required ffff immediately after v4 protocol 
 layer connection succeeded, e.g.
 
 --- sys/netinet6/udp6_usrreq.c.orig     2010-06-24 12:32:10.813316692 +0000
 +++ sys/netinet6/udp6_usrreq.c  2010-06-24 12:33:02.977455989 +0000
 @@ -923,6 +923,8 @@
                 if (error == 0) {
                         inp->inp_vflag |= INP_IPV4;
                         inp->inp_vflag &= ~INP_IPV6;
 +                       /* Make v6 addr v4-mapped */
 +                       
 inp->inp_inc.inc_ie.ie_dependladdr.ie46_local.ia46_pad32[2] = 
 IPV6_ADDR_INT32_SMP;
                         soisconnected(so);
                 }
                 goto out;
 
 This tiny patch fixes an issue with java DNS resolution (at least for me)
 


More information about the freebsd-net mailing list