Skip to content

Commit 00d28db

Browse files
committed
resolve: expose dns_server_address_valid()
1 parent 071712b commit 00d28db

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

src/resolve/resolved-def.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,3 @@
2222
#define SD_RESOLVED_PROTOCOLS_ALL (SD_RESOLVED_MDNS|SD_RESOLVED_LLMNR|SD_RESOLVED_DNS)
2323

2424
#define SD_RESOLVED_QUERY_TIMEOUT_USEC (120 * USEC_PER_SEC)
25-
26-
/* 127.0.0.53 in native endian */
27-
#define INADDR_DNS_STUB ((in_addr_t) 0x7f000035U)

src/resolve/resolved-dns-server.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -739,19 +739,6 @@ void manager_next_dns_server(Manager *m) {
739739
manager_set_dns_server(m, m->dns_servers);
740740
}
741741

742-
bool dns_server_address_valid(int family, const union in_addr_union *sa) {
743-
744-
/* Refuses the 0 IP addresses as well as 127.0.0.53 (which is our own DNS stub) */
745-
746-
if (in_addr_is_null(family, sa))
747-
return false;
748-
749-
if (family == AF_INET && sa->in.s_addr == htobe32(INADDR_DNS_STUB))
750-
return false;
751-
752-
return true;
753-
}
754-
755742
DnssecMode dns_server_get_dnssec_mode(DnsServer *s) {
756743
assert(s);
757744

src/resolve/resolved-dns-server.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ DnsServer *manager_set_dns_server(Manager *m, DnsServer *s);
132132
DnsServer *manager_get_dns_server(Manager *m);
133133
void manager_next_dns_server(Manager *m);
134134

135-
bool dns_server_address_valid(int family, const union in_addr_union *sa);
136-
137135
DnssecMode dns_server_get_dnssec_mode(DnsServer *s);
138136
DnsOverTlsMode dns_server_get_dns_over_tls_mode(DnsServer *s);
139137

src/shared/resolve-util.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,16 @@ static const char* const dns_over_tls_mode_table[_DNS_OVER_TLS_MODE_MAX] = {
2828
[DNS_OVER_TLS_YES] = "yes",
2929
};
3030
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dns_over_tls_mode, DnsOverTlsMode, DNS_OVER_TLS_YES);
31+
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 (which is our own DNS stub) */
35+
36+
if (in_addr_is_null(family, sa))
37+
return false;
38+
39+
if (family == AF_INET && sa->in.s_addr == htobe32(INADDR_DNS_STUB))
40+
return false;
41+
42+
return true;
43+
}

src/shared/resolve-util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
#pragma once
33

44
#include "conf-parser.h"
5+
#include "in-addr-util.h"
56
#include "macro.h"
67

8+
/* 127.0.0.53 in native endian */
9+
#define INADDR_DNS_STUB ((in_addr_t) 0x7f000035U)
10+
711
typedef enum ResolveSupport ResolveSupport;
812
typedef enum DnssecMode DnssecMode;
913
typedef enum DnsOverTlsMode DnsOverTlsMode;
@@ -61,3 +65,5 @@ DnssecMode dnssec_mode_from_string(const char *s) _pure_;
6165

6266
const char* dns_over_tls_mode_to_string(DnsOverTlsMode p) _const_;
6367
DnsOverTlsMode dns_over_tls_mode_from_string(const char *s) _pure_;
68+
69+
bool dns_server_address_valid(int family, const union in_addr_union *sa);

0 commit comments

Comments
 (0)