From 00d28db3222ba0fb04bc498fa6ecf9adf1f940e9 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 27 May 2019 08:35:28 +0900 Subject: [PATCH] resolve: expose dns_server_address_valid() --- src/resolve/resolved-def.h | 3 --- src/resolve/resolved-dns-server.c | 13 ------------- src/resolve/resolved-dns-server.h | 2 -- src/shared/resolve-util.c | 13 +++++++++++++ src/shared/resolve-util.h | 6 ++++++ 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/resolve/resolved-def.h b/src/resolve/resolved-def.h index ea2851b..63c24a0 100644 --- a/src/resolve/resolved-def.h +++ b/src/resolve/resolved-def.h @@ -22,6 +22,3 @@ #define SD_RESOLVED_PROTOCOLS_ALL (SD_RESOLVED_MDNS|SD_RESOLVED_LLMNR|SD_RESOLVED_DNS) #define SD_RESOLVED_QUERY_TIMEOUT_USEC (120 * USEC_PER_SEC) - -/* 127.0.0.53 in native endian */ -#define INADDR_DNS_STUB ((in_addr_t) 0x7f000035U) diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c index 78e5953..cbb3d52 100644 --- a/src/resolve/resolved-dns-server.c +++ b/src/resolve/resolved-dns-server.c @@ -739,19 +739,6 @@ void manager_next_dns_server(Manager *m) { manager_set_dns_server(m, m->dns_servers); } -bool dns_server_address_valid(int family, const union in_addr_union *sa) { - - /* Refuses the 0 IP addresses as well as 127.0.0.53 (which is our own DNS stub) */ - - if (in_addr_is_null(family, sa)) - return false; - - if (family == AF_INET && sa->in.s_addr == htobe32(INADDR_DNS_STUB)) - return false; - - return true; -} - DnssecMode dns_server_get_dnssec_mode(DnsServer *s) { assert(s); diff --git a/src/resolve/resolved-dns-server.h b/src/resolve/resolved-dns-server.h index 2c04572..5433935 100644 --- a/src/resolve/resolved-dns-server.h +++ b/src/resolve/resolved-dns-server.h @@ -132,8 +132,6 @@ DnsServer *manager_set_dns_server(Manager *m, DnsServer *s); DnsServer *manager_get_dns_server(Manager *m); void manager_next_dns_server(Manager *m); -bool dns_server_address_valid(int family, const union in_addr_union *sa); - DnssecMode dns_server_get_dnssec_mode(DnsServer *s); DnsOverTlsMode dns_server_get_dns_over_tls_mode(DnsServer *s); diff --git a/src/shared/resolve-util.c b/src/shared/resolve-util.c index b433cd2..3d14410 100644 --- a/src/shared/resolve-util.c +++ b/src/shared/resolve-util.c @@ -28,3 +28,16 @@ static const char* const dns_over_tls_mode_table[_DNS_OVER_TLS_MODE_MAX] = { [DNS_OVER_TLS_YES] = "yes", }; DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dns_over_tls_mode, DnsOverTlsMode, DNS_OVER_TLS_YES); + +bool dns_server_address_valid(int family, const union in_addr_union *sa) { + + /* Refuses the 0 IP addresses as well as 127.0.0.53 (which is our own DNS stub) */ + + if (in_addr_is_null(family, sa)) + return false; + + if (family == AF_INET && sa->in.s_addr == htobe32(INADDR_DNS_STUB)) + return false; + + return true; +} diff --git a/src/shared/resolve-util.h b/src/shared/resolve-util.h index 6ce2508..cf097df 100644 --- a/src/shared/resolve-util.h +++ b/src/shared/resolve-util.h @@ -2,8 +2,12 @@ #pragma once #include "conf-parser.h" +#include "in-addr-util.h" #include "macro.h" +/* 127.0.0.53 in native endian */ +#define INADDR_DNS_STUB ((in_addr_t) 0x7f000035U) + typedef enum ResolveSupport ResolveSupport; typedef enum DnssecMode DnssecMode; typedef enum DnsOverTlsMode DnsOverTlsMode; @@ -61,3 +65,5 @@ DnssecMode dnssec_mode_from_string(const char *s) _pure_; const char* dns_over_tls_mode_to_string(DnsOverTlsMode p) _const_; DnsOverTlsMode dns_over_tls_mode_from_string(const char *s) _pure_; + +bool dns_server_address_valid(int family, const union in_addr_union *sa); -- 2.7.4