Date: Fri, 12 Sep 2003 02:37:43 +0300 From: Ruslan Ermilov <ru@FreeBSD.org> To: net@FreeBSD.org Subject: Non-deterministic behavior of the INADDR_ANY destination IP address Message-ID: <20030911233743.GA37247@sunbay.com>
next in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030911233743.GA37247>