Merge pull request #9742 from yuwata/workaround-9718

resolve: add option to toggle reading /etc/hosts
This commit is contained in:
Lennart Poettering 2018-07-30 12:40:20 +02:00 committed by GitHub
commit 150a509c9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 6 deletions

View file

@ -227,10 +227,10 @@
<varlistentry> <varlistentry>
<term><varname>Cache=</varname></term> <term><varname>Cache=</varname></term>
<listitem><para>Takes a boolean argument. If "yes" (the default), resolving a domain name which already got <listitem><para>Takes a boolean argument. If <literal>yes</literal> (the default), resolving a domain name
queried earlier will return the previous result as long as it is still valid, and thus does not result in a new which already got queried earlier will return the previous result as long as it is still valid, and thus does
network request. Be aware that turning off caching comes at a performance penalty, which is particularly not result in a new network request. Be aware that turning off caching comes at a performance penalty, which
high when DNSSEC is used.</para> is particularly high when DNSSEC is used.</para>
<para>Note that caching is turned off implicitly if the configured DNS server is on a host-local IP address <para>Note that caching is turned off implicitly if the configured DNS server is on a host-local IP address
(such as 127.0.0.1 or ::1), in order to avoid duplicate local caching.</para></listitem> (such as 127.0.0.1 or ::1), in order to avoid duplicate local caching.</para></listitem>
@ -248,6 +248,13 @@
in use.</para></listitem> in use.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>ReadEtcHosts=</varname></term>
<listitem><para>Takes a boolean argument. If <literal>yes</literal> (the default), the DNS stub resolver will read
<filename>/etc/hosts</filename>, and try to resolve hosts or address by using the entries in the file before
sending query to DNS servers.</para></listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>

View file

@ -236,7 +236,7 @@ static int parse_line(Manager *m, unsigned nr, const char *line) {
return r; return r;
} }
int manager_etc_hosts_read(Manager *m) { static int manager_etc_hosts_read(Manager *m) {
_cleanup_fclose_ FILE *f = NULL; _cleanup_fclose_ FILE *f = NULL;
char line[LINE_MAX]; char line[LINE_MAX];
struct stat st; struct stat st;
@ -324,6 +324,9 @@ int manager_etc_hosts_lookup(Manager *m, DnsQuestion* q, DnsAnswer **answer) {
assert(q); assert(q);
assert(answer); assert(answer);
if (!m->read_etc_hosts)
return 0;
r = manager_etc_hosts_read(m); r = manager_etc_hosts_read(m);
if (r < 0) if (r < 0)
return r; return r;

View file

@ -6,5 +6,4 @@
#include "resolved-dns-answer.h" #include "resolved-dns-answer.h"
void manager_etc_hosts_flush(Manager *m); void manager_etc_hosts_flush(Manager *m);
int manager_etc_hosts_read(Manager *m);
int manager_etc_hosts_lookup(Manager *m, DnsQuestion* q, DnsAnswer **answer); int manager_etc_hosts_lookup(Manager *m, DnsQuestion* q, DnsAnswer **answer);

View file

@ -26,3 +26,4 @@ Resolve.DNSSEC, config_parse_dnssec_mode, 0,
Resolve.DNSOverTLS, config_parse_dns_over_tls_mode, 0, offsetof(Manager, dns_over_tls_mode) Resolve.DNSOverTLS, config_parse_dns_over_tls_mode, 0, offsetof(Manager, dns_over_tls_mode)
Resolve.Cache, config_parse_bool, 0, offsetof(Manager, enable_cache) Resolve.Cache, config_parse_bool, 0, offsetof(Manager, enable_cache)
Resolve.DNSStubListener, config_parse_dns_stub_listener_mode, 0, offsetof(Manager, dns_stub_listener_mode) Resolve.DNSStubListener, config_parse_dns_stub_listener_mode, 0, offsetof(Manager, dns_stub_listener_mode)
Resolve.ReadEtcHosts, config_parse_bool, 0, offsetof(Manager, read_etc_hosts)

View file

@ -581,6 +581,7 @@ int manager_new(Manager **ret) {
m->read_resolv_conf = true; m->read_resolv_conf = true;
m->need_builtin_fallbacks = true; m->need_builtin_fallbacks = true;
m->etc_hosts_last = m->etc_hosts_mtime = USEC_INFINITY; m->etc_hosts_last = m->etc_hosts_mtime = USEC_INFINITY;
m->read_etc_hosts = true;
r = dns_trust_anchor_load(&m->trust_anchor); r = dns_trust_anchor_load(&m->trust_anchor);
if (r < 0) if (r < 0)

View file

@ -117,6 +117,7 @@ struct Manager {
Set* etc_hosts_by_address; Set* etc_hosts_by_address;
Hashmap* etc_hosts_by_name; Hashmap* etc_hosts_by_name;
usec_t etc_hosts_last, etc_hosts_mtime; usec_t etc_hosts_last, etc_hosts_mtime;
bool read_etc_hosts;
/* Local DNS stub on 127.0.0.53:53 */ /* Local DNS stub on 127.0.0.53:53 */
int dns_stub_udp_fd; int dns_stub_udp_fd;

View file

@ -21,3 +21,4 @@
#DNSOverTLS=@DEFAULT_DNS_OVER_TLS_MODE@ #DNSOverTLS=@DEFAULT_DNS_OVER_TLS_MODE@
#Cache=yes #Cache=yes
#DNSStubListener=udp #DNSStubListener=udp
#ReadEtcHosts=yes