From patchwork Mon Nov 25 17:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UGV0ciBNZW7FocOtaw==?= X-Patchwork-Id: 101841 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C52D3858C5F for ; Mon, 25 Nov 2024 17:54:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C52D3858C5F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ee03nhen X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 86BCF3858D29 for ; Mon, 25 Nov 2024 17:53:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 86BCF3858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 86BCF3858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732557230; cv=none; b=RHtFqbQwgWRArAaj+x/u/fimg0zWOmt1zaFiVQrEs3QTYRfPIxJ7h/D74ZwUS29oRbHpdLP5tEZ+JUnjxio1L9kBu/ys9PjQDLhQKysLFkqTJ9qy0thbwTCmjbTWpJA3wvw1umj9ancav2dRHNv2Kux22TZlREL7gcluRfi+gO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732557230; c=relaxed/simple; bh=fxtKe/N9kSwyl3Rv59uecAJ3K6+vWeGM1skoxzaz9OQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=hjumwJu5oe74CKlXMh2Seek8m/nCBKPc4GhS17/aoF8HkAVUUIub46E/VzdvRq5l0L1bc0Yihy+/pnB9Gn9Fcn8gzX0kxgvnjIfeavMP+LJxN4wn4g64zjE9hPiVhzIHCblrLW23Kpgk/dQKWkQo7OjRu65sPH4dfz2sLwJL1yM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 86BCF3858D29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732557230; 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:autocrypt:autocrypt; bh=6oNRRtE2NeDyFDrhCqsW4KN4vuHfwzJgWTivkSYg/b8=; b=Ee03nhenJJ9z4rlRXCoENoYbQdEC3eS+Iwpvn+RS4G0otIg+vBUxlsqEqDyU/e3XD6LEMY 0NsGGUNp0iPZcFA1obUMNBwwltdaj449xFMJdEOcwsZQnVXGAKNqmE6vuMkF0bz7nzNdH3 iF0drubCdlBVozHggteG4FcLYBD5HoE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-533-cghDBDCGM6Ko8gxTeRAUiQ-1; Mon, 25 Nov 2024 12:53:48 -0500 X-MC-Unique: cghDBDCGM6Ko8gxTeRAUiQ-1 X-Mimecast-MFC-AGG-ID: cghDBDCGM6Ko8gxTeRAUiQ Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-38256bf4828so2428394f8f.1 for ; Mon, 25 Nov 2024 09:53:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732557227; x=1733162027; h=content-transfer-encoding:autocrypt:to:content-language:subject :from:user-agent:mime-version:date:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6oNRRtE2NeDyFDrhCqsW4KN4vuHfwzJgWTivkSYg/b8=; b=m0813chCO/dgAZwgLLY7tx1XxLUGHL+Mb50X6a4G/UnMjfqZG+9KAKJ93ZRLGvod8t 5/P2zFoBHFkuhTjcE3Fanzs5ypR+hnuSDbieCi3KUBTqn8x/+w7fHkLXQsdjY2uzfD7K /AE2NKO+EUNYnX0UpMoauVAbt1XHi2dNA5qRRf/CMvu/qyfcw4hIauj7jv8URxWgz1It iYRXWdkh1CK5YJDkwZCEUmbx05u5m+Hxyzt7Uxi+6937IBp1Dv0UWYxSfB7SBEYaToLE ghYweeQXBrOU7nfLWIA2YihKvJKT2ftpNyuuyOxSGxw+kGTHATbO1WyeXA3lopNUTW94 I3uw== X-Gm-Message-State: AOJu0YxWLd5IyD0vTnYCfMeycwyaLNQMYb/oAE00c1uoKyE8+AwPHizq HIsmLuUZQZMEOhpVrO/DrUItBYRz6hfjqHkfQcb83HrBznFSwLRR4o/5xVsgDCFvjoZXW2vy8V0 li86XGt2SkDNx0MaM/XDwFvvDp7LoUVbgsoBhksR2yRsPPN3fWK8i1yZdnO2vhinDKBrQ2uKyou LGOZY8yiQJ7k5wLJjXd54GoZh6VZdsL4fk3jaCzJJDQA== X-Gm-Gg: ASbGncvbJ8etpWMGGvtfifST5affTzUsfgOnCxiwoCawsmXXCDXyX8vuDshFad3lAo/ DrPStyTCWD6Gpgxlzxezkc4xJbhAiCs7MP9kZ/L3+Ps3zDlblMu8lr4zcGBD0aqXN9aiy8vrm3o qOM/89B4pSpVuxBsej94r1zWZ4+vM9TG00qhXZYS4tibO9gUor88lswljJlgt1kfPBWj7MdWRCO Y1sz0nmJPGPrMcwN1kiGl8rEGZsc75LUofStxjiW8iIOsZcaZan7Js55BqUQMMktIYm/ObA4Bhq X-Received: by 2002:a5d:64ad:0:b0:37c:f561:1130 with SMTP id ffacd0b85a97d-385bfb08f10mr287532f8f.18.1732557227359; Mon, 25 Nov 2024 09:53:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtkejmgJ9T5wsn8IKv/ECNoHe6ckaAhxUY55m1/R62uPQ1DyedMzN08nr2As28aWzVgd1f1w== X-Received: by 2002:a5d:64ad:0:b0:37c:f561:1130 with SMTP id ffacd0b85a97d-385bfb08f10mr287506f8f.18.1732557226834; Mon, 25 Nov 2024 09:53:46 -0800 (PST) Received: from [10.43.2.229] (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3825fbedfccsm10948352f8f.101.2024.11.25.09.53.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Nov 2024 09:53:46 -0800 (PST) Message-ID: Date: Mon, 25 Nov 2024 18:53:46 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: =?utf-8?b?UGV0ciBNZW7FocOtaw==?= Subject: [PATCH] resolv.conf: implement ipv4+ipv6 flags (bug 30544) To: libc-alpha@sourceware.org Autocrypt: addr=pemensik@redhat.com; keydata= xsDNBF17vwQBDACso9gM0++XOzm/b//dGE1bgYyIch8xqCDHe2YXDUL2a65LCmNQUnS7PTxf 8psG4DdBayWlRvA/33L3YQD8gULaZX/KsHbSQov4Np4E2rG9PCljcDqHFCKjHEmmzQ86Z4+r euHoTwUpEroz2xa1XAIsy4fjqro0GHc6H3BVwXQ8Vfrmllq6tW+ubegI/tZSDDfOlnkHyMsh /mX893qn1Sb+A/RqyDDV6voAv4YfoNJyDfBB0jMshEiSLO+S0vspw42ElbAdLO6SHOX8Dy/a yPVTGDe2Jopy3YrbUWtu5HIs8X0vsKbF6tegO1l/m1y3t2Aa153k6NKOWv+79iNiY2ygGefm o1TRzlS/d+xacOxnGO3RCSlvm3xDEUuqNqrSQNF2yVRYAMwh75VWefeTu+/erXR4MGDpTTSA Ebaen0+uui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wrE31Pd aXUHyr47y3IoNXNlc0s7dg542OA6m2FkvQYgfbZlQb66J0PTAl31zvYN/G2C024DDqU1wOpV hn1RYkoc0UTAse2IdP/t2mqE4me2gZ7NrjWwFSzXlGIh08T7KxHLrGtA3Mm2I3XnPHO1ppf6 xBoeGMfESeNfoR8sGWOnYyd52CKdnp7DtJ3TlGLlafnkauwHrHnHdkJb4pkKjXKavKy/DjUG yWG74jexhwARAQABwsD8BBgBCAAmAhsMFiEE38+QjbfIfo5SmSW8STHKW2yfxcsFAmTxxYsF CQs4bYcACgkQSTHKW2yfxct9DAv/YIBB1dENrLjMhh+Y11s++p2VFeP4gxawrrXc6tXRcfXj aEvubqNTG34HIUhIIFKbl7S4HGLFhcCtLdzn6nW3e/jH6Gen2InSLHyHVUpt8U0ysSKFoTpM BgP95IWYhx2I3FtKBpjSmTx/Vwdgf1D2QBBLwEWFYazuUIVY8IxwWOlfwpN56jujdSPrcxZD HGDz5gBKy9bKaoTQT6IZXHTanTi7XVJShtWJsX9pot3dPMi+5W+mTaocEc+gnPyEKI9WoQJ/ Ow5At3mQqJ1CEaRF4BXDK0bXIzOrejHDhv4n3RSrvnFlV2e+BcbfS7uj4rYRPsjZ4nffFpog CiM0Yg6RihUbZ8h6BMghOt0F07LAV3ISpaPeVsp4F6pnFedS5NgMufiBSopSJTc8wLked9E3 PlSxMeSMfi21E/eLg024Wx2c9JdKNFrYGEkgdr+w9WBA7AMKFCIQKDAwb3vPgxO3owDNC+ka AJs6m+d2kZSDzqUdFMZLrqbp0vt3GnIF8l3Y X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: KOKPKZv2mXx_rPM6FNLJ5f03iynsMCQQ985sOUrH-nw_1732557228 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Add separate flags to mark support of address family. Its intention is to react dynamically to changing network conditions. If the host has IPv4 connectivity only, it would set ipv4 option. If it has also IPv6 connectivity, it would set ipv6 option. If it connects IPv6-only network, then it set ipv6 only. For backward compatibility it will keep old behaviour when both ipv4 and ipv6 flags are missing. In this case it behaves the same way as if both were present. This is quite useful when default AF_UNSPEC is used in hints, but the host is on network with just single AF used. Unlike no-aaaa option it would change just AF_UNSPEC behaviour, ie. getent ahosts example.com. getent ahostsv4 and getent ahostsv6 would remain unmodified. Signed-off-by: Petr Menšík --- resolv/nss_dns/dns-host.c | 55 ++++++++++++++++++--------- resolv/res_debug.c | 2 + resolv/res_init.c | 2 + resolv/resolv.h | 2 + resolv/tst-resolv-res_init-skeleton.c | 2 + 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c index 95a7b3f0e5..901bf1c3b5 100644 --- a/resolv/nss_dns/dns-host.c +++ b/resolv/nss_dns/dns-host.c @@ -379,6 +379,7 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, { enum nss_status status = check_name (name, herrnop); char tmp[NS_MAXDNAME]; + if (status != NSS_STATUS_SUCCESS) return status; struct resolv_context *ctx = __resolv_context_get (); @@ -413,25 +414,43 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, int olderr = errno; int n; - if ((ctx->resp->options & RES_NOAAAA) == 0) - { - n = __res_context_search (ctx, name, C_IN, T_QUERY_A_AND_AAAA, - dns_packet_buffer, sizeof (dns_packet_buffer), - &alt_dns_packet_buffer, &ans2p, &nans2p, - &resplen2, &ans2p_malloced); - if (n >= 0) - status = gaih_getanswer (alt_dns_packet_buffer, n, ans2p, resplen2, - &abuf, pat, errnop, herrnop, ttlp); - } - else + switch (ctx->resp->options & (RES_NOAAAA|RES_IPV4|RES_IPV6)) { - n = __res_context_search (ctx, name, C_IN, T_A, - dns_packet_buffer, sizeof (dns_packet_buffer), - &alt_dns_packet_buffer, NULL, NULL, NULL, NULL); - if (n >= 0) - status = gaih_getanswer_noaaaa (alt_dns_packet_buffer, n, - &abuf, pat, errnop, herrnop, ttlp); - } + case RES_IPV4: + case RES_IPV4|RES_NOAAAA: + case RES_NOAAAA: + case RES_IPV6|RES_NOAAAA: /*< this combination should never be used. */ + case RES_IPV4|RES_IPV6|RES_NOAAAA: /*< this does not make sense. */ + n = __res_context_search (ctx, name, C_IN, T_A, + dns_packet_buffer, sizeof (dns_packet_buffer), + NULL, NULL, NULL, NULL, NULL); + if (n >= 0) + status = gaih_getanswer_noaaaa (alt_dns_packet_buffer, n, + &abuf, pat, errnop, herrnop, ttlp); + break; + + case RES_IPV6: + n = __res_context_search (ctx, name, C_IN, T_AAAA, + dns_packet_buffer, sizeof (dns_packet_buffer), + NULL, NULL, NULL, NULL, NULL); + if (n >= 0) /* oh we want AAAA, but not A here. code is the same. */ + status = gaih_getanswer_noaaaa (alt_dns_packet_buffer, n, + &abuf, pat, errnop, herrnop, ttlp); + break; + + case 0: + case RES_IPV4|RES_IPV6: + default: + n = __res_context_search (ctx, name, C_IN, T_QUERY_A_AND_AAAA, + dns_packet_buffer, sizeof (dns_packet_buffer), + &alt_dns_packet_buffer, &ans2p, &nans2p, + &resplen2, &ans2p_malloced); + if (n >= 0) + status = gaih_getanswer (alt_dns_packet_buffer, n, ans2p, resplen2, + &abuf, pat, errnop, herrnop, ttlp); + break; + } + if (n < 0) { switch (errno) diff --git a/resolv/res_debug.c b/resolv/res_debug.c index 1b1f5233f9..c271b60dec 100644 --- a/resolv/res_debug.c +++ b/resolv/res_debug.c @@ -613,6 +613,8 @@ p_option(u_long option) { case RES_NORELOAD: return "no-reload"; case RES_TRUSTAD: return "trust-ad"; case RES_NOAAAA: return "no-aaaa"; + case RES_IPV4: return "ipv4"; + case RES_IPV6: return "ipv6"; /* XXX nonreentrant */ default: sprintf(nbuf, "?0x%lx?", (u_long)option); return (nbuf); diff --git a/resolv/res_init.c b/resolv/res_init.c index b838dc7064..38af14bbb3 100644 --- a/resolv/res_init.c +++ b/resolv/res_init.c @@ -696,6 +696,8 @@ res_setoptions (struct resolv_conf_parser *parser, const char *options) { STRnLEN ("trust-ad"), RES_TRUSTAD }, { STRnLEN ("no-aaaa"), RES_NOAAAA }, { STRnLEN ("strict-error"), RES_STRICTERR }, + { STRnLEN ("ipv4"), RES_IPV4 }, + { STRnLEN ("ipv6"), RES_IPV6 }, }; #define noptions (sizeof (options) / sizeof (options[0])) bool negate_option = *cp == '-'; diff --git a/resolv/resolv.h b/resolv/resolv.h index b8a0f66a5f..647881243d 100644 --- a/resolv/resolv.h +++ b/resolv/resolv.h @@ -134,6 +134,8 @@ struct res_sym { #define RES_TRUSTAD 0x04000000 /* Request AD bit, keep it in responses. */ #define RES_NOAAAA 0x08000000 /* Suppress AAAA queries. */ #define RES_STRICTERR 0x10000000 /* Report more DNS errors as errors. */ +#define RES_IPV4 0x20000000 /* Query A records on PF_UNSPEC hints. */ +#define RES_IPV6 0x40000000 /* Query AAAA records on PF_UNSPEC hints. */ #define RES_DEFAULT (RES_RECURSE|RES_DEFNAMES|RES_DNSRCH) diff --git a/resolv/tst-resolv-res_init-skeleton.c b/resolv/tst-resolv-res_init-skeleton.c index e41bcebd9d..97eb57e2a4 100644 --- a/resolv/tst-resolv-res_init-skeleton.c +++ b/resolv/tst-resolv-res_init-skeleton.c @@ -130,6 +130,8 @@ print_resp (FILE *fp, res_state resp) print_option_flag (fp, &options, RES_TRUSTAD, "trust-ad"); print_option_flag (fp, &options, RES_NOAAAA, "no-aaaa"); print_option_flag (fp, &options, RES_STRICTERR, "strict-error"); + print_option_flag (fp, &options, RES_IPV4, "ipv4"); + print_option_flag (fp, &options, RES_IPV6, "ipv6"); fputc ('\n', fp); if (options != 0) fprintf (fp, "; error: unresolved option bits: 0x%x\n", options);