summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-09-08 19:13:29 +0200
committerLennart Poettering <lennart@poettering.net>2020-09-08 19:47:25 +0200
commitae8f0ec323f3cc1b75e2d25d4832fd9bc232261b (patch)
tree4fc90ffac116b527d78b2537c13ccc580dabe12d
parentresolve: DNSStubListenerExtra → DnsStubListenerExtra (diff)
downloadsystemd-ae8f0ec323f3cc1b75e2d25d4832fd9bc232261b.tar.xz
systemd-ae8f0ec323f3cc1b75e2d25d4832fd9bc232261b.zip
resolved: move dns stub definitions to resolved-dns-stub.[ch]
Just some moving around, no logic changes.
-rw-r--r--src/resolve/resolved-conf.c45
-rw-r--r--src/resolve/resolved-conf.h14
-rw-r--r--src/resolve/resolved-dns-stub.c47
-rw-r--r--src/resolve/resolved-dns-stub.h29
-rw-r--r--src/resolve/resolved-dnssd.c1
-rw-r--r--src/resolve/resolved-manager.h13
6 files changed, 78 insertions, 71 deletions
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c
index 68fb9c918b..6caae5d111 100644
--- a/src/resolve/resolved-conf.c
+++ b/src/resolve/resolved-conf.c
@@ -21,51 +21,6 @@
DEFINE_CONFIG_PARSE_ENUM(config_parse_dns_stub_listener_mode, dns_stub_listener_mode, DnsStubListenerMode, "Failed to parse DNS stub listener mode setting");
-static const char* const dns_stub_listener_mode_table[_DNS_STUB_LISTENER_MODE_MAX] = {
- [DNS_STUB_LISTENER_NO] = "no",
- [DNS_STUB_LISTENER_UDP] = "udp",
- [DNS_STUB_LISTENER_TCP] = "tcp",
- [DNS_STUB_LISTENER_YES] = "yes",
-};
-DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dns_stub_listener_mode, DnsStubListenerMode, DNS_STUB_LISTENER_YES);
-
-static void dns_stub_listener_extra_hash_func(const DnsStubListenerExtra *a, struct siphash *state) {
- assert(a);
-
- siphash24_compress(&a->mode, sizeof(a->mode), state);
- siphash24_compress(&a->family, sizeof(a->family), state);
- siphash24_compress(&a->address, FAMILY_ADDRESS_SIZE(a->family), state);
- siphash24_compress(&a->port, sizeof(a->port), state);
-}
-
-static int dns_stub_listener_extra_compare_func(const DnsStubListenerExtra *a, const DnsStubListenerExtra *b) {
- int r;
-
- assert(a);
- assert(b);
-
- r = CMP(a->mode, b->mode);
- if (r != 0)
- return r;
-
- r = CMP(a->family, b->family);
- if (r != 0)
- return r;
-
- r = memcmp(&a->address, &b->address, FAMILY_ADDRESS_SIZE(a->family));
- if (r != 0)
- return r;
-
- return CMP(a->port, b->port);
-}
-
-DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
- dns_stub_listener_extra_hash_ops,
- DnsStubListenerExtra,
- dns_stub_listener_extra_hash_func,
- dns_stub_listener_extra_compare_func,
- dns_stub_listener_extra_free);
-
static int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const char *word) {
_cleanup_free_ char *server_name = NULL;
union in_addr_union address;
diff --git a/src/resolve/resolved-conf.h b/src/resolve/resolved-conf.h
index 50a0caaf16..09ae8d7a5b 100644
--- a/src/resolve/resolved-conf.h
+++ b/src/resolve/resolved-conf.h
@@ -3,17 +3,6 @@
#include "conf-parser.h"
-typedef enum DnsStubListenerMode DnsStubListenerMode;
-
-enum DnsStubListenerMode {
- DNS_STUB_LISTENER_NO,
- DNS_STUB_LISTENER_UDP = 1 << 0,
- DNS_STUB_LISTENER_TCP = 1 << 1,
- DNS_STUB_LISTENER_YES = DNS_STUB_LISTENER_UDP | DNS_STUB_LISTENER_TCP,
- _DNS_STUB_LISTENER_MODE_MAX,
- _DNS_STUB_LISTENER_MODE_INVALID = -1
-};
-
#include "resolved-dns-server.h"
int manager_parse_config_file(Manager *m);
@@ -31,6 +20,3 @@ CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_name);
CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_service_type);
CONFIG_PARSER_PROTOTYPE(config_parse_dnssd_txt);
CONFIG_PARSER_PROTOTYPE(config_parse_dns_stub_listener_extra);
-
-const char* dns_stub_listener_mode_to_string(DnsStubListenerMode p) _const_;
-DnsStubListenerMode dns_stub_listener_mode_from_string(const char *s) _pure_;
diff --git a/src/resolve/resolved-dns-stub.c b/src/resolve/resolved-dns-stub.c
index 68b8678b5f..c89bf6c13f 100644
--- a/src/resolve/resolved-dns-stub.c
+++ b/src/resolve/resolved-dns-stub.c
@@ -9,12 +9,51 @@
#include "resolved-dns-stub.h"
#include "socket-netlink.h"
#include "socket-util.h"
+#include "string-table.h"
/* The MTU of the loopback device is 64K on Linux, advertise that as maximum datagram size, but subtract the Ethernet,
* IP and UDP header sizes */
#define ADVERTISE_DATAGRAM_SIZE_MAX (65536U-14U-20U-8U)
+static void dns_stub_listener_extra_hash_func(const DnsStubListenerExtra *a, struct siphash *state) {
+ assert(a);
+
+ siphash24_compress(&a->mode, sizeof(a->mode), state);
+ siphash24_compress(&a->family, sizeof(a->family), state);
+ siphash24_compress(&a->address, FAMILY_ADDRESS_SIZE(a->family), state);
+ siphash24_compress(&a->port, sizeof(a->port), state);
+}
+
+static int dns_stub_listener_extra_compare_func(const DnsStubListenerExtra *a, const DnsStubListenerExtra *b) {
+ int r;
+
+ assert(a);
+ assert(b);
+
+ r = CMP(a->mode, b->mode);
+ if (r != 0)
+ return r;
+
+ r = CMP(a->family, b->family);
+ if (r != 0)
+ return r;
+
+ r = memcmp(&a->address, &b->address, FAMILY_ADDRESS_SIZE(a->family));
+ if (r != 0)
+ return r;
+
+ return CMP(a->port, b->port);
+}
+
+DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(
+ dns_stub_listener_extra_hash_ops,
+ DnsStubListenerExtra,
+ dns_stub_listener_extra_hash_func,
+ dns_stub_listener_extra_compare_func,
+ dns_stub_listener_extra_free);
+
int dns_stub_listener_extra_new(DnsStubListenerExtra **ret) {
+
DnsStubListenerExtra *l;
l = new0(DnsStubListenerExtra, 1);
@@ -794,3 +833,11 @@ void manager_dns_stub_stop(Manager *m) {
m->dns_stub_udp_event_source = sd_event_source_unref(m->dns_stub_udp_event_source);
m->dns_stub_tcp_event_source = sd_event_source_unref(m->dns_stub_tcp_event_source);
}
+
+static const char* const dns_stub_listener_mode_table[_DNS_STUB_LISTENER_MODE_MAX] = {
+ [DNS_STUB_LISTENER_NO] = "no",
+ [DNS_STUB_LISTENER_UDP] = "udp",
+ [DNS_STUB_LISTENER_TCP] = "tcp",
+ [DNS_STUB_LISTENER_YES] = "yes",
+};
+DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(dns_stub_listener_mode, DnsStubListenerMode, DNS_STUB_LISTENER_YES);
diff --git a/src/resolve/resolved-dns-stub.h b/src/resolve/resolved-dns-stub.h
index c3b4c5afd9..0ff0289550 100644
--- a/src/resolve/resolved-dns-stub.h
+++ b/src/resolve/resolved-dns-stub.h
@@ -1,10 +1,39 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
+#include "hash-funcs.h"
+
+typedef struct DnsStubListenerExtra DnsStubListenerExtra;
+
+typedef enum DnsStubListenerMode {
+ DNS_STUB_LISTENER_NO,
+ DNS_STUB_LISTENER_UDP = 1 << 0,
+ DNS_STUB_LISTENER_TCP = 1 << 1,
+ DNS_STUB_LISTENER_YES = DNS_STUB_LISTENER_UDP | DNS_STUB_LISTENER_TCP,
+ _DNS_STUB_LISTENER_MODE_MAX,
+ _DNS_STUB_LISTENER_MODE_INVALID = -1
+} DnsStubListenerMode;
+
#include "resolved-manager.h"
+struct DnsStubListenerExtra {
+ DnsStubListenerMode mode;
+
+ int family;
+ union in_addr_union address;
+ uint16_t port;
+
+ sd_event_source *udp_event_source;
+ sd_event_source *tcp_event_source;
+};
+
+extern const struct hash_ops dns_stub_listener_extra_hash_ops;
+
int dns_stub_listener_extra_new(DnsStubListenerExtra **ret);
DnsStubListenerExtra *dns_stub_listener_extra_free(DnsStubListenerExtra *p);
void manager_dns_stub_stop(Manager *m);
int manager_dns_stub_start(Manager *m);
+
+const char* dns_stub_listener_mode_to_string(DnsStubListenerMode p) _const_;
+DnsStubListenerMode dns_stub_listener_mode_from_string(const char *s) _pure_;
diff --git a/src/resolve/resolved-dnssd.c b/src/resolve/resolved-dnssd.c
index 7d482ac5da..945be07740 100644
--- a/src/resolve/resolved-dnssd.c
+++ b/src/resolve/resolved-dnssd.c
@@ -6,6 +6,7 @@
#include "resolved-dnssd.h"
#include "resolved-dns-rr.h"
#include "resolved-manager.h"
+#include "resolved-conf.h"
#include "specifier.h"
#include "strv.h"
diff --git a/src/resolve/resolved-manager.h b/src/resolve/resolved-manager.h
index 905b55aa7a..c30052195a 100644
--- a/src/resolve/resolved-manager.h
+++ b/src/resolve/resolved-manager.h
@@ -15,10 +15,10 @@
typedef struct Manager Manager;
-#include "resolved-conf.h"
#include "resolved-dns-query.h"
#include "resolved-dns-search-domain.h"
#include "resolved-dns-stream.h"
+#include "resolved-dns-stub.h"
#include "resolved-dns-trust-anchor.h"
#include "resolved-link.h"
@@ -31,17 +31,6 @@ typedef struct EtcHosts {
Set *no_address;
} EtcHosts;
-typedef struct DnsStubListenerExtra {
- DnsStubListenerMode mode;
-
- int family;
- union in_addr_union address;
- uint16_t port;
-
- sd_event_source *udp_event_source;
- sd_event_source *tcp_event_source;
-} DnsStubListenerExtra;
-
struct Manager {
sd_event *event;