From patchwork Thu Nov 21 21:13:27 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: 101704 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 1A4A53857823 for ; Thu, 21 Nov 2024 21:14:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A4A53857823 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=JpVWInFj 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.133.124]) by sourceware.org (Postfix) with ESMTP id 7E6913857C6E for ; Thu, 21 Nov 2024 21:13:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E6913857C6E 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 7E6913857C6E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732223613; cv=none; b=a+ieFi7iaE3T8QmXo+ab7NKftZKA14oHAt/ZIQ72cU4LvyDtE8eHnnrcLsBsofarqCSoycXjFuxmvFhbXBc5jF4zF44Lt4/O3WxUXJA3bK3sWa8ICqtwz6h3Pin47Du5Y7+m/Ms7rNRAibrt9sRkUQglz3aGNEiopJomD6lArLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732223613; c=relaxed/simple; bh=G+zpLpIUHlRKWg3ItJ8G7L1AxP5neE5GFmgJeTYj2jI=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=p5PBzCkWVgh6mxQIkFOEOXOtfdHpGvGNj6qqJtAmnJ3wCGED8CiRO9Lu/i8d/xn3/1A0/tp40o/ut6dTTcw2ZD27sKkirNDahdtYXPImosk+LPTYFL/81oQ9/dAFguRP6OM7+s+LnhLth9KFEW0eHam70ze2wGsaGg/C7GknIoE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E6913857C6E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732223613; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type:autocrypt:autocrypt; bh=G+zpLpIUHlRKWg3ItJ8G7L1AxP5neE5GFmgJeTYj2jI=; b=JpVWInFjGB/tctmbnUTQBK6jw+0ErZIJ4s4ttoNH+GO7Iem3TUh38GH1vt/Ira/RlokKIG LU2Q0gWa6ep5pI527yuRDbwcWk9WTCnllv6UW3nVzhgG3QWjk1ypaoWaJgg1sLCNxPVGgy /D0zsV5fOozO9xxLsmNvw7rmvPsULYE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-540-xdt_ktr_PKerqq5fsL_sDw-1; Thu, 21 Nov 2024 16:13:31 -0500 X-MC-Unique: xdt_ktr_PKerqq5fsL_sDw-1 X-Mimecast-MFC-AGG-ID: xdt_ktr_PKerqq5fsL_sDw Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315ad4938fso8991905e9.0 for ; Thu, 21 Nov 2024 13:13:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732223609; x=1732828409; h=autocrypt:subject:from:to:content-language:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=G+zpLpIUHlRKWg3ItJ8G7L1AxP5neE5GFmgJeTYj2jI=; b=pLpH0iSh4dFx7t4zMBtn2MGa2QlLByMzcY0NpKnvLbmX6vOPoYvzzubaKsvFMvF5aG uHihB0p+JfgKMOqVTMNQ+CUSm135R9InNTdTDdcRFaLiJ2a0sgNHIcP/vzeg+T6U1Tei 7X8/i0/OzcPA5Fl5cD0fEZ6u9+f+WkzScwlovcZ+XLBjX+0qWxGHrEZDfN9N7gPilVgt 0d1JPJQXhV+FJsqCfKK8NQR68znqZN+393de+f/GnjEMjPG/fu1rvcmEXAO9ZAMaRgcx Za9JUKS9mxcKVAFysgN6u+VnfuldtMEDmyIk6rLzU5MZDpzb5CNpd9lFLM27W0wUbIOH 9L+w== X-Gm-Message-State: AOJu0YxNKKndLtoBZAFW92O/XVztazty4kXn9hsP9nsXljh7WnwogT4E Nby651xKpHoUuQ9opGlhaYDj7apdVudgxggrYqBA1DVNZe+dmu7CjU6W++idZaJQgSvWptaQXmO Y/joVQlmtR3D9jE1a/LAhdA/RlO9+OljAZrBjCNAWMzHQgR879vFy71/dliKr2dPL13oxBiYq4o wdnDiH/tPYOU8rgAlK37Tjz0fiSASyTFtiKA/fncWkKQ== X-Gm-Gg: ASbGncu0ePnJ08PcGI6D7t0XpHvVqz++DWN0cw9PU8yAfEeFsTAc57QI8iBVZrL8M5G 7ILabIz+qUa4WET3itoZn5tf2Iw1n3I4GM02Daxo0e7jrhGTDd5snI6RYbZgYvat3wQjK4Lzn0X OnKuMmjqKhLmtW91293MRQoLAMq//MXTWzOidGsGYlr84s+4LZoP93s0K3m6gWu+s49tru9uMJA WcHWCF8Lti8dR9k7KfZ2qF/+cIV+rcgBmgaK9+nR/PDj8bbsoDPbSeD3FfaPI2d1A+xJsJOotZM X-Received: by 2002:a05:600c:4683:b0:42f:7e87:3438 with SMTP id 5b1f17b1804b1-433ce39e773mr2894535e9.0.1732223609622; Thu, 21 Nov 2024 13:13:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IElxdA7bBcdH49L+21UBWT+D6viJS7nbrZfwl2aJrtVYXNjp4Mdm+7UPXGzJq1BWZEyHmFqgg== X-Received: by 2002:a05:600c:4683:b0:42f:7e87:3438 with SMTP id 5b1f17b1804b1-433ce39e773mr2894295e9.0.1732223609085; Thu, 21 Nov 2024 13:13:29 -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-433b4643194sm66862165e9.40.2024.11.21.13.13.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Nov 2024 13:13:28 -0800 (PST) Message-ID: <197abaa9-0d8c-4b27-a462-d50e73048d4e@redhat.com> Date: Thu, 21 Nov 2024 22:13:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: libc-alpha@sourceware.org From: =?utf-8?b?UGV0ciBNZW7FocOtaw==?= Subject: [PATCH] Implement ipv4+ipv6 flags in resolv.conf 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+uuiG4LGCN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d 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-Spam-Status: No, score=-10.1 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_H3, RCVD_IN_MSPIKE_WL, 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 Hi! I have made a rebase of my older attempt and would like some comments, if possible. The problem is described at bug #30544 [1]. My proposal would be simple disabling of sending A or AAAA queries on hosts. This is a bit modified previous patch. What I want is to have getent ahosts example.com to resolve only IPv4 address, if I added ipv4 option into /etc/resolv.conf. But at the same time it should tell me IPv6 address if I do getent ahostsv6 example.com. It does not have to lie, just does not ask unless asked explicitly. That would make ping example.com try only IPv4 address, but ping -6 example.com try IPv6 address. That is main change compared to noaaaa option. It should not prohibit query, just avoid unless someone asked. Expected into future would be that NetworkManager or any service managing /etc/resolv.conf would add ipv4 when it has non-link local route to ipv4 and similar with ipv6 flag. But even if set manually now it can be useful, IMO. I would like some pointers, how to make this feature tested. This is my first change proposed to glibc and I have no experience with making tests for it. Help with desired. What do you think of that change? Best Regards, Petr 1. https://sourceware.org/bugzilla/show_bug.cgi?id=30544 --- Petr Menšík Senior Software Engineer, RHEL Red Hat, http://www.redhat.com/ PGP: DFCF908DB7C87E8E529925BC4931CA5B6C9FC5CB From 54871094aa2843416696384dd1dca97a4cd9cce3 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] First attempt to implement ipv4+ipv6 flags 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. Resolves: https://sourceware.org/bugzilla/show_bug.cgi?id=30544 --- resolv/nss_dns/dns-host.c | 54 ++++++++++++++++++--------- 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, 44 insertions(+), 18 deletions(-) diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c index 1d60c51f5e..7161a802eb 100644 --- a/resolv/nss_dns/dns-host.c +++ b/resolv/nss_dns/dns-host.c @@ -413,25 +413,43 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat, int olderr = errno; int n; - if ((ctx->resp->options & RES_NOAAAA) == 0) + switch (ctx->resp->options & (RES_NOAAAA|RES_IPV4|RES_IPV6)) { - 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 - { - 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); - } + 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 either. */ + 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) + 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 b0fe69b1aa..86a6e9e115 100644 --- a/resolv/res_debug.c +++ b/resolv/res_debug.c @@ -614,6 +614,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 cce842fa93..6cdeaf4e97 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 ("use-vc"), 0, RES_USEVC }, { STRnLEN ("trust-ad"), 0, RES_TRUSTAD }, { STRnLEN ("no-aaaa"), 0, RES_NOAAAA }, + { STRnLEN ("ipv4"), 0, RES_IPV4 }, + { STRnLEN ("ipv6"), 0, RES_IPV6 }, }; #define noptions (sizeof (options) / sizeof (options[0])) for (int i = 0; i < noptions; ++i) diff --git a/resolv/resolv.h b/resolv/resolv.h index f40d6c58ce..878692ffaa 100644 --- a/resolv/resolv.h +++ b/resolv/resolv.h @@ -133,6 +133,8 @@ struct res_sym { #define RES_NORELOAD 0x02000000 /* No automatic configuration reload. */ #define RES_TRUSTAD 0x04000000 /* Request AD bit, keep it in responses. */ #define RES_NOAAAA 0x08000000 /* Suppress AAAA queries. */ +#define RES_IPV4 0x10000000 /* Query A records on PF_UNSPEC hints. */ +#define RES_IPV6 0x20000000 /* 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 cbdf377b84..155c5a7ffe 100644 --- a/resolv/tst-resolv-res_init-skeleton.c +++ b/resolv/tst-resolv-res_init-skeleton.c @@ -129,6 +129,8 @@ print_resp (FILE *fp, res_state resp) print_option_flag (fp, &options, RES_NORELOAD, "no-reload"); print_option_flag (fp, &options, RES_TRUSTAD, "trust-ad"); print_option_flag (fp, &options, RES_NOAAAA, "no-aaaa"); + 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.41.0