mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
Merge pull request #6946 from poettering/synthesize-dns
Some DNS RR synthesizing fixes
This commit is contained in:
commit
8bdaf088ca
@ -650,8 +650,7 @@ int bus_add_match_internal(
|
||||
sd_bus *bus,
|
||||
const char *match,
|
||||
struct bus_match_component *components,
|
||||
unsigned n_components,
|
||||
uint64_t cookie) {
|
||||
unsigned n_components) {
|
||||
|
||||
assert(bus);
|
||||
|
||||
@ -686,8 +685,7 @@ static int bus_remove_match_internal_dbus1(
|
||||
|
||||
int bus_remove_match_internal(
|
||||
sd_bus *bus,
|
||||
const char *match,
|
||||
uint64_t cookie) {
|
||||
const char *match) {
|
||||
|
||||
assert(bus);
|
||||
|
||||
|
@ -23,8 +23,5 @@
|
||||
|
||||
#include "bus-match.h"
|
||||
|
||||
int bus_add_match_internal(sd_bus *bus, const char *match, struct bus_match_component *components, unsigned n_components, uint64_t cookie);
|
||||
int bus_remove_match_internal(sd_bus *bus, const char *match, uint64_t cookie);
|
||||
|
||||
int bus_add_match_internal_kernel(sd_bus *bus, struct bus_match_component *components, unsigned n_components, uint64_t cookie);
|
||||
int bus_remove_match_internal_kernel(sd_bus *bus, uint64_t cookie);
|
||||
int bus_add_match_internal(sd_bus *bus, const char *match, struct bus_match_component *components, unsigned n_components);
|
||||
int bus_remove_match_internal(sd_bus *bus, const char *match);
|
||||
|
@ -53,7 +53,6 @@ struct filter_callback {
|
||||
struct match_callback {
|
||||
sd_bus_message_handler_t callback;
|
||||
|
||||
uint64_t cookie;
|
||||
unsigned last_iteration;
|
||||
|
||||
char *match_string;
|
||||
@ -287,8 +286,6 @@ struct sd_bus {
|
||||
uint64_t hello_flags;
|
||||
uint64_t attach_flags;
|
||||
|
||||
uint64_t match_cookie;
|
||||
|
||||
sd_event_source *input_io_event_source;
|
||||
sd_event_source *output_io_event_source;
|
||||
sd_event_source *time_event_source;
|
||||
@ -308,9 +305,6 @@ struct sd_bus {
|
||||
|
||||
char *description;
|
||||
|
||||
size_t bloom_size;
|
||||
unsigned bloom_n_hash;
|
||||
|
||||
sd_bus_track *track_queue;
|
||||
|
||||
LIST_HEAD(sd_bus_slot, slots);
|
||||
|
@ -93,7 +93,7 @@ void bus_slot_disconnect(sd_bus_slot *slot) {
|
||||
case BUS_MATCH_CALLBACK:
|
||||
|
||||
if (slot->match_added)
|
||||
bus_remove_match_internal(slot->bus, slot->match_callback.match_string, slot->match_callback.cookie);
|
||||
bus_remove_match_internal(slot->bus, slot->match_callback.match_string);
|
||||
|
||||
slot->bus->match_callbacks_modified = true;
|
||||
bus_match_remove(&slot->bus->match_callbacks, &slot->match_callback);
|
||||
|
@ -56,7 +56,7 @@
|
||||
#define log_debug_bus_message(m) \
|
||||
do { \
|
||||
sd_bus_message *_mm = (m); \
|
||||
log_debug("Got message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error=%s", \
|
||||
log_debug("Got message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error-name=%s error-message=%s", \
|
||||
bus_message_type_to_string(_mm->header->type), \
|
||||
strna(sd_bus_message_get_sender(_mm)), \
|
||||
strna(sd_bus_message_get_destination(_mm)), \
|
||||
@ -65,6 +65,7 @@
|
||||
strna(sd_bus_message_get_member(_mm)), \
|
||||
BUS_MESSAGE_COOKIE(_mm), \
|
||||
_mm->reply_cookie, \
|
||||
strna(_mm->error.name), \
|
||||
strna(_mm->error.message)); \
|
||||
} while (false)
|
||||
|
||||
@ -1465,7 +1466,7 @@ static int bus_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
|
||||
return r;
|
||||
|
||||
if (*idx >= BUS_MESSAGE_SIZE(m))
|
||||
log_debug("Sent message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error=%s",
|
||||
log_debug("Sent message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error-name=%s error-message=%s",
|
||||
bus_message_type_to_string(m->header->type),
|
||||
strna(sd_bus_message_get_sender(m)),
|
||||
strna(sd_bus_message_get_destination(m)),
|
||||
@ -1474,6 +1475,7 @@ static int bus_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
|
||||
strna(sd_bus_message_get_member(m)),
|
||||
BUS_MESSAGE_COOKIE(m),
|
||||
m->reply_cookie,
|
||||
strna(m->error.name),
|
||||
strna(m->error.message));
|
||||
|
||||
return r;
|
||||
@ -2856,7 +2858,6 @@ _public_ int sd_bus_add_match(
|
||||
}
|
||||
|
||||
s->match_callback.callback = callback;
|
||||
s->match_callback.cookie = ++bus->match_cookie;
|
||||
|
||||
if (bus->bus_client) {
|
||||
enum bus_match_scope scope;
|
||||
@ -2876,7 +2877,7 @@ _public_ int sd_bus_add_match(
|
||||
goto finish;
|
||||
}
|
||||
|
||||
r = bus_add_match_internal(bus, s->match_callback.match_string, components, n_components, s->match_callback.cookie);
|
||||
r = bus_add_match_internal(bus, s->match_callback.match_string, components, n_components);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
|
@ -623,7 +623,18 @@ static int dns_query_synthesize_reply(DnsQuery *q, DnsTransactionState *state) {
|
||||
q->question_utf8,
|
||||
q->ifindex,
|
||||
&answer);
|
||||
if (r == -ENXIO) {
|
||||
/* If we get ENXIO this tells us to generate NXDOMAIN unconditionally. */
|
||||
|
||||
dns_query_reset_answer(q);
|
||||
q->answer_rcode = DNS_RCODE_NXDOMAIN;
|
||||
q->answer_protocol = dns_synthesize_protocol(q->flags);
|
||||
q->answer_family = dns_synthesize_family(q->flags);
|
||||
q->answer_authenticated = true;
|
||||
*state = DNS_TRANSACTION_RCODE_FAILURE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
|
@ -186,6 +186,7 @@ static int answer_add_addresses_ptr(
|
||||
unsigned n_addresses,
|
||||
int af, const union in_addr_union *match) {
|
||||
|
||||
bool added = false;
|
||||
unsigned j;
|
||||
int r;
|
||||
|
||||
@ -215,9 +216,11 @@ static int answer_add_addresses_ptr(
|
||||
r = dns_answer_add(*answer, rr, addresses[j].ifindex, DNS_ANSWER_AUTHENTICATED);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
added = true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return added;
|
||||
}
|
||||
|
||||
static int synthesize_system_hostname_rr(Manager *m, const DnsResourceKey *key, int ifindex, DnsAnswer **answer) {
|
||||
@ -265,6 +268,7 @@ static int synthesize_system_hostname_rr(Manager *m, const DnsResourceKey *key,
|
||||
|
||||
static int synthesize_system_hostname_ptr(Manager *m, int af, const union in_addr_union *address, int ifindex, DnsAnswer **answer) {
|
||||
_cleanup_free_ struct local_address *addresses = NULL;
|
||||
bool added = false;
|
||||
int n, r;
|
||||
|
||||
assert(m);
|
||||
@ -273,10 +277,13 @@ static int synthesize_system_hostname_ptr(Manager *m, int af, const union in_add
|
||||
|
||||
if (af == AF_INET && address->in.s_addr == htobe32(0x7F000002)) {
|
||||
|
||||
/* Always map the IPv4 address 127.0.0.2 to the local
|
||||
* hostname, in addition to "localhost": */
|
||||
/* Always map the IPv4 address 127.0.0.2 to the local hostname, in addition to "localhost": */
|
||||
|
||||
r = dns_answer_reserve(answer, 3);
|
||||
r = dns_answer_reserve(answer, 4);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = answer_add_ptr(answer, "2.0.0.127.in-addr.arpa", m->full_hostname, dns_synthesize_ifindex(ifindex), DNS_ANSWER_AUTHENTICATED);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -292,23 +299,37 @@ static int synthesize_system_hostname_ptr(Manager *m, int af, const union in_add
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
n = local_addresses(m->rtnl, ifindex, af, &addresses);
|
||||
if (n < 0)
|
||||
if (n <= 0)
|
||||
return n;
|
||||
|
||||
r = answer_add_addresses_ptr(answer, m->full_hostname, addresses, n, af, address);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
added = true;
|
||||
|
||||
r = answer_add_addresses_ptr(answer, m->llmnr_hostname, addresses, n, af, address);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
added = true;
|
||||
|
||||
return answer_add_addresses_ptr(answer, m->mdns_hostname, addresses, n, af, address);
|
||||
r = answer_add_addresses_ptr(answer, m->mdns_hostname, addresses, n, af, address);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
added = true;
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
static int synthesize_gateway_rr(Manager *m, const DnsResourceKey *key, int ifindex, DnsAnswer **answer) {
|
||||
_cleanup_free_ struct local_address *addresses = NULL;
|
||||
int n = 0, af;
|
||||
int n = 0, af, r;
|
||||
|
||||
assert(m);
|
||||
assert(key);
|
||||
@ -317,11 +338,15 @@ static int synthesize_gateway_rr(Manager *m, const DnsResourceKey *key, int ifin
|
||||
af = dns_type_to_af(key->type);
|
||||
if (af >= 0) {
|
||||
n = local_gateways(m->rtnl, ifindex, af, &addresses);
|
||||
if (n < 0)
|
||||
return n;
|
||||
if (n <= 0)
|
||||
return n; /* < 0 means: error; == 0 means we have no gateway */
|
||||
}
|
||||
|
||||
return answer_add_addresses_rr(answer, dns_resource_key_name(key), addresses, n);
|
||||
r = answer_add_addresses_rr(answer, dns_resource_key_name(key), addresses, n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 1; /* > 0 means: we have some gateway */
|
||||
}
|
||||
|
||||
static int synthesize_gateway_ptr(Manager *m, int af, const union in_addr_union *address, int ifindex, DnsAnswer **answer) {
|
||||
@ -333,7 +358,7 @@ static int synthesize_gateway_ptr(Manager *m, int af, const union in_addr_union
|
||||
assert(answer);
|
||||
|
||||
n = local_gateways(m->rtnl, ifindex, af, &addresses);
|
||||
if (n < 0)
|
||||
if (n <= 0)
|
||||
return n;
|
||||
|
||||
return answer_add_addresses_ptr(answer, "_gateway", addresses, n, af, address);
|
||||
@ -347,7 +372,7 @@ int dns_synthesize_answer(
|
||||
|
||||
_cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL;
|
||||
DnsResourceKey *key;
|
||||
bool found = false;
|
||||
bool found = false, nxdomain = false;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@ -381,6 +406,10 @@ int dns_synthesize_answer(
|
||||
r = synthesize_gateway_rr(m, key, ifindex, &answer);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to synthesize gateway RRs: %m");
|
||||
if (r == 0) { /* if we have no gateway return NXDOMAIN */
|
||||
nxdomain = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
} else if ((dns_name_endswith(name, "127.in-addr.arpa") > 0 && dns_name_equal(name, "2.0.0.127.in-addr.arpa") == 0) ||
|
||||
dns_name_equal(name, "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa") > 0) {
|
||||
@ -390,26 +419,35 @@ int dns_synthesize_answer(
|
||||
return log_error_errno(r, "Failed to synthesize localhost PTR RRs: %m");
|
||||
|
||||
} else if (dns_name_address(name, &af, &address) > 0) {
|
||||
int v, w;
|
||||
|
||||
r = synthesize_system_hostname_ptr(m, af, &address, ifindex, &answer);
|
||||
if (r < 0)
|
||||
v = synthesize_system_hostname_ptr(m, af, &address, ifindex, &answer);
|
||||
if (v < 0)
|
||||
return log_error_errno(r, "Failed to synthesize system hostname PTR RR: %m");
|
||||
|
||||
r = synthesize_gateway_ptr(m, af, &address, ifindex, &answer);
|
||||
if (r < 0)
|
||||
w = synthesize_gateway_ptr(m, af, &address, ifindex, &answer);
|
||||
if (w < 0)
|
||||
return log_error_errno(r, "Failed to synthesize gateway hostname PTR RR: %m");
|
||||
|
||||
if (v == 0 && w == 0) /* This IP address is neither a local one nor a gateway */
|
||||
continue;
|
||||
|
||||
} else
|
||||
continue;
|
||||
|
||||
found = true;
|
||||
}
|
||||
|
||||
r = found;
|
||||
if (found) {
|
||||
|
||||
if (ret) {
|
||||
*ret = answer;
|
||||
answer = NULL;
|
||||
}
|
||||
if (ret) {
|
||||
*ret = answer;
|
||||
answer = NULL;
|
||||
}
|
||||
|
||||
return r;
|
||||
return 1;
|
||||
} else if (nxdomain)
|
||||
return -ENXIO;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user