resolved: move dns stub definitions to resolved-dns-stub.[ch]
Just some moving around, no logic changes.
This commit is contained in:
parent
36aaabc35e
commit
ae8f0ec323
|
@ -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;
|
||||
|
|
|
@ -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_;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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_;
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue