From patchwork Mon Nov 25 18:08:16 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: 101844 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 01EC33858C33 for ; Mon, 25 Nov 2024 18:08:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01EC33858C33 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=D+QNojqT 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 CD4EE3858D29 for ; Mon, 25 Nov 2024 18:08:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD4EE3858D29 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 CD4EE3858D29 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=1732558101; cv=none; b=uIUAZ+UfTrV2jEu25yVIeE0nML78pF9UD81IQLxAU/Qmmo81rTzo/x/JvZQiAGdIgprtZmL//5tWtFRLBK/8HHEcT9m/oAHWNMQLuNNGNC1W/6xDzVuwPwWKCD6a0p+mkDFo9cN9NwwI/05SA2vCZzyZv1OIW17iv5zZxcyg6rY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732558101; c=relaxed/simple; bh=AYp0rPmAWNdK58ungfgZ9T2VcTZwSdvIvJkZxju0omc=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=x4x69X81vRQ5thqnTDYeiRaRA7FDPTbZ13XwKHyztQ/0CMr/dcUJVr0AOed0pxVZeQGqTO5tU6lNL3SvdYVv9z2B9N/NJGvWlNyIO0aIqtYmZxtdcDqfouxmazpbhmqCrneBmshZGFdAb4bH5V1quInvspu99IYhppKX6nkLtEo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD4EE3858D29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732558101; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:autocrypt:autocrypt; bh=AYp0rPmAWNdK58ungfgZ9T2VcTZwSdvIvJkZxju0omc=; b=D+QNojqTArfSgkD6QVRCgEk/k9uKprXasnUeXyMQtSxBcVntZLlos55NbgNoN3JoS+1bDB TjjUz7uqrLqnSDCq2tVj/Qplf2Q2Yg/MO1duSEwe2uOY34O4h6+B5UTrBMBrOXsNuHinZk dIhu4gHBKiUQ+drU5e1Hz01pIrydpBo= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-_XU4lkZQM_uETO453TE2mw-1; Mon, 25 Nov 2024 13:08:19 -0500 X-MC-Unique: _XU4lkZQM_uETO453TE2mw-1 X-Mimecast-MFC-AGG-ID: _XU4lkZQM_uETO453TE2mw Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4316655b2f1so34364985e9.0 for ; Mon, 25 Nov 2024 10:08:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732558098; x=1733162898; h=in-reply-to:autocrypt:to:content-language:references:reply-to :subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=joDEHxRpomIfPnJjV3ms0E2yzlotLhoxOetIHCD2UaQ=; b=WAm+Q+E41GGi099sy0/M9i0QkcLWrwNg8cOYygDhcdG0NLyl/waAizhUPqVyywLyMF 9Exzstwi3A/sDpYuNcNuWZD5K8xNPhLjnABv5cKZ4LfMw23/14fJyNiUu6J04iiUZSkf +6NREHlzQwy2A8gK5N/3AomS14lTgVU+UpF45B0AtCfh31B7ZV00qek01b3QX6VN7wye c/j2aT1fcH9pqDB/n+u78Elk9udAX6U/oCi87OT2Ww8+SvXrXMCPg2esJgZ0ilzzYa5/ lFjtzya9J5RZxP+25MigWHoTDOqcvNdumDSqhkCWI5Ho7kcPwwUzo8TiFwPKDa47F3kQ 1r7Q== X-Gm-Message-State: AOJu0YyPoJHDC4vD/B2XWxssOdfhZElN2ocefDhra356fK0KXcM7u1ax TrdGLyAWl/aMTYIWinXulfxt0duWacs2acxjTeAWxMrNDWru0Th2nEU98uT5PCTwEGoGigfgfAS dPLHOVEtOKwgd7ezwzf8jok+fwg6UCYSHsaCwBDdqSGPZ5DbsTQQv3/E7KectIG44gPSzk86u/N tK/bSvtxpQhIY6mRtZNR23F18sZt9Lepri+zga/7P1/w== X-Gm-Gg: ASbGncuAwiTD4ntm/dPGwTQ+E1yvmVMqzGPllLPXFmqMry9wqfl89+zfLtKEEAU90yU eIEQ+TgWacgZt+kjkrjH1QOBGD7OrhuiFAZQllK3cRTTgcvr9HXq/Z71Odl2UruPvM27EN5km/F lOqL1FppIYZZ6/OAB9+UoFcouqCUqZ2Mt5XQ5IV5f/7XjARCUUfkTSjJrAytxjJ/DELRWJJVbjb ninG3ouubYqIe9p9wFLIwq3xLCXHvwvYSQuBQ08doQfVL8ZhKD5eXavGwkVGp5vY1UOmpqvTjyg X-Received: by 2002:a05:6000:1fa4:b0:381:ec32:3f71 with SMTP id ffacd0b85a97d-38260bcd13fmr11821807f8f.44.1732558098068; Mon, 25 Nov 2024 10:08:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEIwYJfnKwiawQJ9kgj56oDSe2X8u8PiDD+nJy5ncC2Li0ja4srRTp1hKTtqOZkOR0sr7Frg== X-Received: by 2002:a05:6000:1fa4:b0:381:ec32:3f71 with SMTP id ffacd0b85a97d-38260bcd13fmr11821783f8f.44.1732558097523; Mon, 25 Nov 2024 10:08:17 -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 5b1f17b1804b1-433cde8c804sm136954855e9.30.2024.11.25.10.08.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Nov 2024 10:08:16 -0800 (PST) Message-ID: <2781e81e-28b7-48c7-83db-08e6ab822fb0@redhat.com> Date: Mon, 25 Nov 2024 19:08:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: =?utf-8?b?UGV0ciBNZW7FocOtaw==?= Subject: [PATCH v3] resolv.conf: implement ipv4+ipv6 flags (bug 30544) References: <> 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+/erX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6dJ1Tg5aFJyhYCbB8NwrE31Pd 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 In-Reply-To: <> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: PHoqOMlnQLYxlZC3r0Ag02yt8sZ1d1OkVreoeEgAiJk_1732558098 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.8 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: , Reply-To: =?utf-8?b?UGV0ciBNZW7FocOtaw==?= 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 From f85dc2aa9502b25f93b49d12334860c9d81475e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= Date: Mon, 3 Jul 2023 08:32:20 +0200 Subject: [PATCH] resolv.conf: implement ipv4+ipv6 flags (bug 30544) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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); -- 2.47.0