From owner-freebsd-net@FreeBSD.ORG Thu Jun 24 16:00:14 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 A1AA81065670 for ; Thu, 24 Jun 2010 16:00:14 +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 773028FC12 for ; Thu, 24 Jun 2010 16:00:14 +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 o5OG0Emo069965 for ; Thu, 24 Jun 2010 16:00:14 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o5OG0E3X069964; Thu, 24 Jun 2010 16:00:14 GMT (envelope-from gnats) Date: Thu, 24 Jun 2010 16:00:14 GMT Message-Id: <201006241600.o5OG0E3X069964@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 16:00:14 -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:54:02 +0400 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 1682 nc CALL close(0x3) 1682 nc RET close 0 1682 nc CALL sigprocmask(SIG_BLOCK,0x80063e140,0x7fffffffc640) Problem is related with an [implicit] IPv4 bind() done in in_pcbconnect (or in_pcbbind_setup for explicit bind ). bind results in selected IPv4 address written in inp_inc.inc_ie.ie_dependladdr.ie46_local.ia46_addr4 According to struct in_addr_4in6, interpreting witten value as IPv6 address results in ::127.0.0.1 v6 address for 127.0.0.1 which is not IPv4-mapped address (it is deprecated IPv4-compatible adddress, actually). This address causes udp6_send() returning EINVAL (immediately after IN6_IS_ADDR_V4MAPPED(&inp->in6p_laddr) check) Proposed solution is to add missing :ffff: immediately after successful v4 layer connect, 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 java DNS resolution for me