1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include "conf-parser.h"
4 #include "resolve-util.h"
5 #include "string-table.h"
6 
7 DEFINE_CONFIG_PARSE_ENUM(config_parse_resolve_support, resolve_support, ResolveSupport, "Failed to parse resolve support setting");
8 DEFINE_CONFIG_PARSE_ENUM(config_parse_dnssec_mode, dnssec_mode, DnssecMode, "Failed to parse DNSSEC mode setting");
9 DEFINE_CONFIG_PARSE_ENUM(config_parse_dns_over_tls_mode, dns_over_tls_mode, DnsOverTlsMode, "Failed to parse DNS-over-TLS mode setting");
10 
11 static const char* const resolve_support_table[_RESOLVE_SUPPORT_MAX] = {
12         [RESOLVE_SUPPORT_NO] = "no",
13         [RESOLVE_SUPPORT_YES] = "yes",
14         [RESOLVE_SUPPORT_RESOLVE] = "resolve",
15 };
16 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(resolve_support, ResolveSupport, RESOLVE_SUPPORT_YES);
17 
18 static const char* const dnssec_mode_table[_DNSSEC_MODE_MAX] = {
19         [DNSSEC_NO] = "no",
20         [DNSSEC_ALLOW_DOWNGRADE] = "allow-downgrade",
21         [DNSSEC_YES] = "yes",
22 };
23 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dnssec_mode, DnssecMode, DNSSEC_YES);
24 
25 static const char* const dns_over_tls_mode_table[_DNS_OVER_TLS_MODE_MAX] = {
26         [DNS_OVER_TLS_NO] = "no",
27         [DNS_OVER_TLS_OPPORTUNISTIC] = "opportunistic",
28         [DNS_OVER_TLS_YES] = "yes",
29 };
30 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dns_over_tls_mode, DnsOverTlsMode, DNS_OVER_TLS_YES);
31 
dns_server_address_valid(int family,const union in_addr_union * sa)32 bool dns_server_address_valid(int family, const union in_addr_union *sa) {
33 
34         /* Refuses the 0 IP addresses as well as 127.0.0.53/127.0.0.54 (which is our own DNS stub) */
35 
36         if (!in_addr_is_set(family, sa))
37                 return false;
38 
39         if (family == AF_INET && IN_SET(be32toh(sa->in.s_addr), INADDR_DNS_STUB, INADDR_DNS_PROXY_STUB))
40                 return false;
41 
42         return true;
43 }
44 
45 DEFINE_CONFIG_PARSE_ENUM(config_parse_dns_cache_mode, dns_cache_mode, DnsCacheMode, "Failed to parse DNS cache mode setting")
46 
47 static const char* const dns_cache_mode_table[_DNS_CACHE_MODE_MAX] = {
48         [DNS_CACHE_MODE_YES] = "yes",
49         [DNS_CACHE_MODE_NO] = "no",
50         [DNS_CACHE_MODE_NO_NEGATIVE] = "no-negative",
51 };
52 DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dns_cache_mode, DnsCacheMode, DNS_CACHE_MODE_YES);
53