From owner-freebsd-net@FreeBSD.ORG Thu Jun 24 15:50:05 2010 Return-Path: Delivered-To: freebsd-net@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D1745106566B for ; Thu, 24 Jun 2010 15:50:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A6CEA8FC14 for ; Thu, 24 Jun 2010 15:50:05 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o5OFo5KR061816 for ; Thu, 24 Jun 2010 15:50:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o5OFo5qG061815; Thu, 24 Jun 2010 15:50:05 GMT (envelope-from gnats) Date: Thu, 24 Jun 2010 15:50:05 GMT Message-Id: <201006241550.o5OFo5qG061815@freefall.freebsd.org> To: freebsd-net@FreeBSD.org From: "Alexander V. Chernikov" Cc: Subject: Re: kern/127057: [udp] Unable to send UDP packet via IPv6 socket to IPv4 mapped address X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: "Alexander V. Chernikov" List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2010 15:50:05 -0000 The following reply was made to PR kern/127057; it has been noted by GNATS. From: "Alexander V. Chernikov" To: bug-followup@FreeBSD.org, saper@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)