From nobody Thu Feb 5 14:36:40 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4f6KY95zTYz6QdBS for ; Thu, 05 Feb 2026 14:36:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4f6KY93nd0z3HDy for ; Thu, 05 Feb 2026 14:36:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1770302205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qfO7IcUzTDiKueWZKMgGkGY8lC2C8YwuqSKd/Xm1Mi8=; b=E9F16jPhUK8TUKKzaSmh/7oNSFZxDuIUkmw08Fkm44emlId2SSteiJMpJWiCbD4QjIVVBw juAy7p7w3BaBZPznULzaVqwO+GOwkDamuKKWJh4I5UWxJG8pfhSfo4kE+jINCTpE/GgHPY ODJgt+xTAn5+KF/3kuaMqjgx7VHIcqgofDQcwJxApx7NUjz5Db8NOOiKbvoJjiBMsrFTSO dsmQJZpmFqdL0BIQSZXIQ5zzmDy4diSbUFBpaXzVqz8oYdm3TfIDPQvunCLfdZjD5OwqeR 5Ic2u5p7qsLCWUrwB8USjP+j72CtR+Kmf9CN//56rqYa8uuodAH2NTnDgQC5fw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1770302205; a=rsa-sha256; cv=none; b=CnmuNkIbIX7wbw8rRG4uUAP9rSZaTrSRHmc3XppZO7I1THM5w+ljvYMBpUjHSBDxL6DOAz af8jtSCz0ciC4Kvs5lnhi9Cs7Jx9meQmnZ+LLtkl2+Bo2PPQV2h6rTlQL4P6SK5dRO3rU4 ZxpdYwQOa30GmAOumllaTEuT0644Y0IP12+3XKOf4CYHI2SIrHw+wXleBYVns6055qAtjr UsY/C1vk5oTQYktRJzoAFDt1ndIZFdndxWhhBx7lN0xAEjg8l5PBV8RYWrNQUvSsWfhj8U 0LzXjGZekB11yXCXzXSYhRaBWTyAUZFwgoTL8g6Fx6qR1yGcT4Rxc+d3YMZlxA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1770302205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qfO7IcUzTDiKueWZKMgGkGY8lC2C8YwuqSKd/Xm1Mi8=; b=B8xzOCbITt864cdORGTZIV7KqWPHfnGXHR9CZp9QH0CoxbI7Gi2czHWBP4gGv0fq6gRuI/ sf3J94o4XcwHoeMeD7/IR7LZLaYPuo+zCwMWKHNuYqp4hWLFzcMdsQnTCl2rZLMfXiShPi +B95/x2srF7c+W6R1DxPtaZqNchsyqc9FcK/HvODMGwuFYo+6ytfVvasDOGmfpSgKjpcUB tA/iBO6cCaDyKNBcRxMhvk87kTvT7jd9vz2B2Vn+ujbhwZNUcTljRXbi6OLXAM9mhzZsiu q+VEzqdpUH4fqGe8Gj6FAcBsx7iTGvMOsQNXj0I9WCw1m/qZYqJ8/Ql1dzsPPw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f6KY93LFgzZ9X for ; Thu, 05 Feb 2026 14:36:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3ae95 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 05 Feb 2026 14:36:40 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: c137555c3f39 - stable/15 - libc/resolv: Switch default to loopback address List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: c137555c3f39a7defa61c53e357d83638bec8c66 Auto-Submitted: auto-generated Date: Thu, 05 Feb 2026 14:36:40 +0000 Message-Id: <6984aaf8.3ae95.654222a0@gitrepo.freebsd.org> The branch stable/15 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=c137555c3f39a7defa61c53e357d83638bec8c66 commit c137555c3f39a7defa61c53e357d83638bec8c66 Author: Dag-Erling Smørgrav AuthorDate: 2026-01-31 17:52:53 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-02-05 14:36:19 +0000 libc/resolv: Switch default to loopback address If no resolver configuration was found, we would fall back to INADDR_ANY and IN6ADDR_ANY. This made sense when it was first written thirty or forty years ago but not today, especially since connecting to INADDR_ANY or IN6ADDR_ANY is no longer supported. Switch to the loopback address and simplify the code. Note that (as the pre-existing comment in the code states) running without a resolver configuration is not really supported. Still, if we're going to have a hardcoded fallback, it might as well work. PR: 291790 MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55011 (cherry picked from commit 1538284a5fddfce546db678cb873b7edc6adb9ed) --- lib/libc/resolv/res_init.c | 67 ++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/lib/libc/resolv/res_init.c b/lib/libc/resolv/res_init.c index 5a2fce013c8c..b21a3fa1670f 100644 --- a/lib/libc/resolv/res_init.c +++ b/lib/libc/resolv/res_init.c @@ -118,21 +118,12 @@ static u_int32_t net_mask(struct in_addr); /*% * Set up default settings. If the configuration file exist, the values * there will have precedence. Otherwise, the server address is set to - * INADDR_ANY and the default domain name comes from the gethostname(). - * - * An interim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1 - * rather than INADDR_ANY ("0.0.0.0") as the default name server address - * since it was noted that INADDR_ANY actually meant ``the first interface - * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface, - * it had to be "up" in order for you to reach your own name server. It - * was later decided that since the recommended practice is to always - * install local static routes through 127.0.0.1 for all your network - * interfaces, that we could solve this problem without a code change. + * the loopback address the default domain name comes from gethostname(). * * The configuration file should always be used, since it is the only way - * to specify a default domain. If you are running a server on your local - * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1" - * in the configuration file. + * to specify options and a default domain. If you are running a server + * on your local machine, you should say "nameserver 127.0.0.1" or + * "nameserver ::1" in the configuration file. * * Return 0 if completes successfully, -1 on error */ @@ -146,6 +137,26 @@ res_ninit(res_state statp) { /*% This function has to be reachable by res_data.c but not publicly. */ int __res_vinit(res_state statp, int preinit) { + union res_sockaddr_union u[] = { + { .sin = { + .sin_family = AF_INET, +#ifdef HAVE_SA_LEN + .sin_len = sizeof(struct sockaddr_in), +#endif + .sin_port = htons(NAMESERVER_PORT), + .sin_addr = { htonl(INADDR_LOOPBACK) }, + } }, +#ifdef HAS_INET6_STRUCTS + { .sin6 = { + .sin6_family = AF_INET6, +#ifdef HAVE_SA_LEN + .sin6_len = sizeof(struct sockaddr_in6), +#endif + .sin6_port = htons(NAMESERVER_PORT), + .sin6_addr = IN6ADDR_LOOPBACK_INIT, + } }, +#endif + }; FILE *fp; char *cp, **pp; int n; @@ -158,7 +169,6 @@ __res_vinit(res_state statp, int preinit) { char *net; #endif int dots; - union res_sockaddr_union u[2]; int maxns = MAXNS; RES_SET_H_ERRNO(statp, 0); @@ -173,23 +183,6 @@ __res_vinit(res_state statp, int preinit) { statp->id = res_nrandomid(statp); - memset(u, 0, sizeof(u)); - u[nserv].sin.sin_addr.s_addr = INADDR_ANY; - u[nserv].sin.sin_family = AF_INET; - u[nserv].sin.sin_port = htons(NAMESERVER_PORT); -#ifdef HAVE_SA_LEN - u[nserv].sin.sin_len = sizeof(struct sockaddr_in); -#endif - nserv++; -#ifdef HAS_INET6_STRUCTS - u[nserv].sin6.sin6_addr = in6addr_any; - u[nserv].sin6.sin6_family = AF_INET6; - u[nserv].sin6.sin6_port = htons(NAMESERVER_PORT); -#ifdef HAVE_SA_LEN - u[nserv].sin6.sin6_len = sizeof(struct sockaddr_in6); -#endif - nserv++; -#endif statp->nscount = 0; statp->ndots = 1; statp->pfcode = 0; @@ -224,7 +217,7 @@ __res_vinit(res_state statp, int preinit) { #ifdef RESOLVSORT statp->nsort = 0; #endif - res_setservers(statp, u, nserv); + res_setservers(statp, u, nitems(u)); #ifdef SOLARIS2 /* @@ -288,7 +281,6 @@ __res_vinit(res_state statp, int preinit) { (line[sizeof(name) - 1] == ' ' || \ line[sizeof(name) - 1] == '\t')) - nserv = 0; if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) { struct stat sb; struct timespec now; @@ -507,15 +499,8 @@ __res_vinit(res_state statp, int preinit) { #endif (void) fclose(fp); } -/* - * Last chance to get a nameserver. This should not normally - * be necessary - */ -#ifdef NO_RESOLV_CONF - if(nserv == 0) - nserv = get_nameservers(statp); -#endif + /* guess default domain if not set */ if (statp->defdname[0] == 0 && gethostname(buf, sizeof(statp->defdname) - 1) == 0 && (cp = strchr(buf, '.')) != NULL)