From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 18 12:03:10 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 7A602495 for ; Thu, 18 Apr 2013 12:03:10 +0000 (UTC) (envelope-from shonnur@chelsio.com) Received: from stargate.chelsio.com (stargate.chelsio.com [67.207.112.58]) by mx1.freebsd.org (Postfix) with ESMTP id 606B0880 for ; Thu, 18 Apr 2013 12:03:10 +0000 (UTC) Received: from maui.asicdesigners.com (maui.asicdesigners.com [10.192.180.15]) by stargate.chelsio.com (8.13.1/8.13.1) with SMTP id r3IC3AwH026229 for ; Thu, 18 Apr 2013 05:03:10 -0700 Received: from corona.asicdesigners.com ([10.192.160.6]) by maui.asicdesigners.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 18 Apr 2013 05:03:10 -0700 Received: from NICE.asicdesigners.com (10.192.160.7) by corona.asicdesigners.com (10.192.160.6) with Microsoft SMTP Server (TLS) id 8.3.83.0; Thu, 18 Apr 2013 05:03:09 -0700 Received: from NICE.asicdesigners.com ([fe80::51b2:ba95:9d72:babc]) by nice.asicdesigners.com ([fe80::51b2:ba95:9d72:babc%15]) with mapi id 14.02.0247.003; Thu, 18 Apr 2013 05:03:09 -0700 From: Sreenivasa Honnur To: "freebsd-hackers@freebsd.org" Subject: IPv6 bind fails with 49 (#define EADDRNOTAVAIL 49 /* Can't assign requested address */) Thread-Topic: IPv6 bind fails with 49 (#define EADDRNOTAVAIL 49 /* Can't assign requested address */) Thread-Index: Ac48LK8jT/jcUDbnSui9QRC6r7ExZA== Date: Thu, 18 Apr 2013 12:03:07 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.193.190.128] MIME-Version: 1.0 X-OriginalArrivalTime: 18 Apr 2013 12:03:10.0066 (UTC) FILETIME=[B1DDE520:01CE3C2C] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Apr 2013 12:03:10 -0000 I have a ipv6 interface(ping6 to a remove ipv6 works) when I try to bind to= this address through a socket program "sobind" fails with "49" as return v= alue. If I give "saddr6.sin6_addr =3D in6addr_any;" sobind works. Any idea what could be going wrong here? roundhay# ifconfig cxgbe1 cxgbe1: flags=3D8843 metric 0 mtu 1= 500 options=3D6c07bb ether 00:07:43:11:89:88 inet6 2010::102 prefixlen 64 inet6 fe80::207:43ff:fe11:8988%cxgbe1 prefixlen 64 scopeid 0xd nd6 options=3D21 media: Ethernet 10Gbase-SR status: active roundhay# ping6 2010::101 PING6(56=3D40+8+8 bytes) 2010::102 --> 2010::101 16 bytes from 2010::101, icmp_seq=3D0 hlim=3D64 time=3D0.950 ms 16 bytes from 2010::101, icmp_seq=3D1 hlim=3D64 time=3D0.158 ms ^C --- 2010::101 ping6 statistics --- 2 packets transmitted, 2 packets received, 0.0% packet loss round-trip min/= avg/max/std-dev =3D 0.158/0.554/0.950/0.396 ms Code: =3D=3D=3D=3D=3D { rv =3D socreate(AF_INET6, &sock, SOCK_STREAM, IPPROTO_TCP, td->td_ucred, td); if (rv !=3D 0) { os_log_error("sock create ipv6 %s failed %d.\n", tbuf, rv); return NULL; } family =3D saddr6.sin6_family =3D AF_INET6; inet_pton(AF_INET6, "2010::102", &saddr6.sin6_addr); saddr6.sin6_port =3D htons(ep->port); saddr6.sin6_len =3D sizeof(struct sockaddr_in6); rv =3D sobind(sock, (struct sockaddr *)&saddr6, td); } Here is the code snippet from where EADDRNOTAVAIL is returned. File : netinet6/in6_pcb.c in6_pcbbind(register struct inpcb *inp, struct sockaddr *nam, struct ucred *cred) { ........ ........ } else if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { struct ifaddr *ifa; sin6->sin6_port =3D 0; /* yech... */ if ((ifa =3D ifa_ifwithaddr((struct sockaddr *)sin6= )) =3D=3D NULL && (inp->inp_flags & INP_BINDANY) =3D=3D 0) { return (EADDRNOTAVAIL); =E8 it fails here s= ince ifa_ifwithaddr() returns NULL } ........ ........ } File: net/if.c struct ifaddr * ifa_ifwithaddr(struct sockaddr *addr) { return (ifa_ifwithaddr_internal(addr, 1)); } ifa_ifwithaddr_internal(struct sockaddr *addr, int getref) { ........ ........ TAILQ_FOREACH(ifp, &V_ifnet, if_link) { IF_ADDR_RLOCK(ifp); printf("ifp->xname:%s ifp->dname:%s\n",ifp->if_xname, ifp->= if_dname); TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { if (ifa->ifa_addr->sa_family !=3D addr->sa_family) = =E8 ifa->ifa_addr->sa_family=3D18 & addr->sa_family=3D28. Even though the = interface is in IPV6 mode its sa_family is not set properly, continue; } Ifa =3D= NULL; ........ ........ }