Skip to content

Commit

Permalink
Merge pull request systemd#16985 from poettering/resolve-dns-stub-ext…
Browse files Browse the repository at this point in the history
…ra-fixlets

resolved: dns stub listener extra fixes
  • Loading branch information
keszybz committed Sep 9, 2020
2 parents 5887cd7 + 0354029 commit 2bb4d58
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 128 deletions.
49 changes: 2 additions & 47 deletions src/resolve/resolved-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -436,7 +391,7 @@ int config_parse_dns_stub_listener_extra(
void *data,
void *userdata) {

_cleanup_free_ DNSStubListenerExtra *stub = NULL;
_cleanup_free_ DnsStubListenerExtra *stub = NULL;
Manager *m = userdata;
const char *p;
int r;
Expand All @@ -451,7 +406,7 @@ int config_parse_dns_stub_listener_extra(
return 0;
}

r = dns_stub_listener_extra_new(&stub);
r = dns_stub_listener_extra_new(m, &stub);
if (r < 0)
return log_oom();

Expand Down
14 changes: 0 additions & 14 deletions src/resolve/resolved-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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_;
1 change: 0 additions & 1 deletion src/resolve/resolved-dns-packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ struct DnsPacket {
DnsResourceRecord *opt;

/* Packet reception metadata */
int fd; /* Used by UDP extra DNS stub listners */
int ifindex;
int family, ipproto;
union in_addr_union sender, destination;
Expand Down
2 changes: 2 additions & 0 deletions src/resolve/resolved-dns-query.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

typedef struct DnsQueryCandidate DnsQueryCandidate;
typedef struct DnsQuery DnsQuery;
typedef struct DnsStubListenerExtra DnsStubListenerExtra;

#include "resolved-dns-answer.h"
#include "resolved-dns-question.h"
Expand Down Expand Up @@ -82,6 +83,7 @@ struct DnsQuery {
DnsPacket *request_dns_packet;
DnsStream *request_dns_stream;
DnsPacket *reply_dns_packet;
DnsStubListenerExtra *stub_listener_extra;

/* Completion callback */
void (*complete)(DnsQuery* q);
Expand Down
3 changes: 3 additions & 0 deletions src/resolve/resolved-dns-stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ typedef struct DnsServer DnsServer;
typedef struct DnsStream DnsStream;
typedef struct DnsTransaction DnsTransaction;
typedef struct Manager Manager;
typedef struct DnsStubListenerExtra DnsStubListenerExtra;

#include "resolved-dns-packet.h"
#include "resolved-dnstls.h"
Expand Down Expand Up @@ -75,6 +76,8 @@ struct DnsStream {
/* used when DNS-over-TLS is enabled */
bool encrypted:1;

DnsStubListenerExtra *stub_listener_extra;

LIST_FIELDS(DnsStream, streams);
};

Expand Down
Loading

0 comments on commit 2bb4d58

Please sign in to comment.