From owner-freebsd-net@FreeBSD.ORG Thu Sep 11 16:37:54 2003 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0F6B016A4BF for ; Thu, 11 Sep 2003 16:37:54 -0700 (PDT) Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8F4B143FCB for ; Thu, 11 Sep 2003 16:37:49 -0700 (PDT) (envelope-from ru@sunbay.com) Received: from whale.sunbay.crimea.ua (ru@localhost [127.0.0.1]) h8BNbh9F038231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 12 Sep 2003 02:37:45 +0300 (EEST) (envelope-from ru@sunbay.com) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.12.9/8.12.8/Submit) id h8BNbher038226 for net@FreeBSD.org; Fri, 12 Sep 2003 02:37:43 +0300 (EEST) (envelope-from ru) Date: Fri, 12 Sep 2003 02:37:43 +0300 From: Ruslan Ermilov To: net@FreeBSD.org Message-ID: <20030911233743.GA37247@sunbay.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="rQ2U398070+RC21q" Content-Disposition: inline User-Agent: Mutt/1.5.4i Subject: Non-deterministic behavior of the INADDR_ANY destination IP address X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Sep 2003 23:37:54 -0000 --rQ2U398070+RC21q Content-Type: multipart/mixed; boundary="zx4FCpZtqtKETZ7O" Content-Disposition: inline --zx4FCpZtqtKETZ7O Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi there! I always thought (until today) that an empty /etc/resolv.conf is equivalent to specifying the ``nameserver 127.0.0.1'' line in it, but as it turns out, it's not: the resolver(3) library just uses an uninitialized 0.0.0.0 address which is mapped to the first local IP address, not necessarily the one of the lo0 interface). The actual mapping depends on the order you have configured IP addresses. What the attached patch does is to ensure that if the loopback interface is configured for IPv4, its address is used for mapping of the 0.0.0.0 address. If not, then the first local IP address is used, as before. Let me know what do you think about it. Cheers, --=20 Ruslan Ermilov Sysadmin and DBA, ru@sunbay.com Sunbay Software Ltd, ru@FreeBSD.org FreeBSD committer --zx4FCpZtqtKETZ7O Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=p Index: in_pcb.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/in_pcb.c,v retrieving revision 1.122 diff -u -p -r1.122 in_pcb.c --- in_pcb.c 7 Aug 2003 15:04:27 -0000 1.122 +++ in_pcb.c 11 Sep 2003 23:06:35 -0000 @@ -542,14 +542,22 @@ in_pcbconnect_setup(inp, nam, laddrp, lp if (!TAILQ_EMPTY(&in_ifaddrhead)) { /* * If the destination address is INADDR_ANY, + * use the address of a loopback interface, or * use the primary local address. * If the supplied address is INADDR_BROADCAST, * and the primary interface supports broadcast, * choose the broadcast address for that interface. */ - if (faddr.s_addr == INADDR_ANY) - faddr = IA_SIN(TAILQ_FIRST(&in_ifaddrhead))->sin_addr; - else if (faddr.s_addr == (u_long)INADDR_BROADCAST && + if (faddr.s_addr == INADDR_ANY) { + TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) { + if (ia->ia_ifa.ifa_ifp->if_flags & IFF_LOOPBACK) { + faddr = ia->ia_addr.sin_addr; + break; + } + } + if (faddr.s_addr == INADDR_ANY) + faddr = IA_SIN(TAILQ_FIRST(&in_ifaddrhead))->sin_addr; + } else if (faddr.s_addr == (u_long)INADDR_BROADCAST && (TAILQ_FIRST(&in_ifaddrhead)->ia_ifp->if_flags & IFF_BROADCAST)) faddr = satosin(&TAILQ_FIRST( --zx4FCpZtqtKETZ7O-- --rQ2U398070+RC21q Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQE/YQdHUkv4P6juNwoRAo3iAJ0RUAs2SB0SooH3eDocdC0zITHjbACeMJVd 5YcHWxoJRQuaNYWhJqNK0kc= =fXY8 -----END PGP SIGNATURE----- --rQ2U398070+RC21q--