mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
Merge pull request #5335 from poettering/resolved-some-fixes
some post-mdns fixes for resolved
This commit is contained in:
commit
4ec426b975
@ -793,15 +793,8 @@ DnsTransaction *dns_scope_find_transaction(DnsScope *scope, DnsResourceKey *key,
|
|||||||
/* Try to find an ongoing transaction that is a equal to the
|
/* Try to find an ongoing transaction that is a equal to the
|
||||||
* specified question */
|
* specified question */
|
||||||
t = hashmap_get(scope->transactions_by_key, key);
|
t = hashmap_get(scope->transactions_by_key, key);
|
||||||
if (!t) {
|
if (!t)
|
||||||
DnsResourceKey *key_any;
|
return NULL;
|
||||||
|
|
||||||
key_any = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_ANY, dns_resource_key_name(key));
|
|
||||||
t = hashmap_get(scope->transactions_by_key, key_any);
|
|
||||||
key_any = dns_resource_key_unref(key_any);
|
|
||||||
if (!t)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Refuse reusing transactions that completed based on cached
|
/* Refuse reusing transactions that completed based on cached
|
||||||
* data instead of a real packet, if that's requested. */
|
* data instead of a real packet, if that's requested. */
|
||||||
@ -1068,49 +1061,46 @@ static int on_announcement_timeout(sd_event_source *s, usec_t usec, void *userda
|
|||||||
|
|
||||||
scope->announce_event_source = sd_event_source_unref(scope->announce_event_source);
|
scope->announce_event_source = sd_event_source_unref(scope->announce_event_source);
|
||||||
|
|
||||||
dns_scope_announce(scope, false);
|
(void) dns_scope_announce(scope, false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dns_scope_announce(DnsScope *scope, bool goodbye) {
|
int dns_scope_announce(DnsScope *scope, bool goodbye) {
|
||||||
_cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL;
|
_cleanup_(dns_answer_unrefp) DnsAnswer *answer = NULL;
|
||||||
_cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
|
_cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
|
||||||
LinkAddress *a;
|
LinkAddress *a;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!scope)
|
if (!scope)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
if (scope->protocol != DNS_PROTOCOL_MDNS)
|
if (scope->protocol != DNS_PROTOCOL_MDNS)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
|
answer = dns_answer_new(scope->link->n_addresses * 2);
|
||||||
|
if (!answer)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
answer = dns_answer_new(4);
|
|
||||||
LIST_FOREACH(addresses, a, scope->link->addresses) {
|
LIST_FOREACH(addresses, a, scope->link->addresses) {
|
||||||
r = dns_answer_add(answer, a->mdns_address_rr, 0, goodbye ? DNS_ANSWER_GOODBYE : DNS_ANSWER_CACHE_FLUSH);
|
r = dns_answer_add(answer, a->mdns_address_rr, 0, goodbye ? DNS_ANSWER_GOODBYE : DNS_ANSWER_CACHE_FLUSH);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_debug_errno(r, "Failed to add address RR to answer: %m");
|
return log_debug_errno(r, "Failed to add address RR to answer: %m");
|
||||||
return;
|
|
||||||
}
|
|
||||||
r = dns_answer_add(answer, a->mdns_ptr_rr, 0, goodbye ? DNS_ANSWER_GOODBYE : DNS_ANSWER_CACHE_FLUSH);
|
r = dns_answer_add(answer, a->mdns_ptr_rr, 0, goodbye ? DNS_ANSWER_GOODBYE : DNS_ANSWER_CACHE_FLUSH);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_debug_errno(r, "Failed to add PTR RR to answer: %m");
|
return log_debug_errno(r, "Failed to add PTR RR to answer: %m");
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dns_answer_isempty(answer))
|
if (dns_answer_isempty(answer))
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
r = dns_scope_make_reply_packet(scope, 0, DNS_RCODE_SUCCESS, NULL, answer, NULL, false, &p);
|
r = dns_scope_make_reply_packet(scope, 0, DNS_RCODE_SUCCESS, NULL, answer, NULL, false, &p);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_debug_errno(r, "Failed to build reply packet: %m");
|
return log_debug_errno(r, "Failed to build reply packet: %m");
|
||||||
return;
|
|
||||||
}
|
|
||||||
r = dns_scope_emit_udp(scope, -1, p);
|
r = dns_scope_emit_udp(scope, -1, p);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_debug_errno(r, "Failed to send reply packet: %m");
|
return log_debug_errno(r, "Failed to send reply packet: %m");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* In section 8.3 of RFC6762: "The Multicast DNS responder MUST send at least two unsolicited
|
/* In section 8.3 of RFC6762: "The Multicast DNS responder MUST send at least two unsolicited
|
||||||
* responses, one second apart." */
|
* responses, one second apart." */
|
||||||
@ -1130,6 +1120,10 @@ void dns_scope_announce(DnsScope *scope, bool goodbye) {
|
|||||||
MDNS_JITTER_RANGE_USEC,
|
MDNS_JITTER_RANGE_USEC,
|
||||||
on_announcement_timeout, scope);
|
on_announcement_timeout, scope);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_debug_errno(r, "Failed to schedule second announcement: %m");
|
return log_debug_errno(r, "Failed to schedule second announcement: %m");
|
||||||
|
|
||||||
|
(void) sd_event_source_set_description(scope->announce_event_source, "mdns-announce");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -117,4 +117,4 @@ bool dns_scope_network_good(DnsScope *s);
|
|||||||
|
|
||||||
int dns_scope_ifindex(DnsScope *s);
|
int dns_scope_ifindex(DnsScope *s);
|
||||||
|
|
||||||
void dns_scope_announce(DnsScope *scope, bool goodbye);
|
int dns_scope_announce(DnsScope *scope, bool goodbye);
|
||||||
|
@ -364,7 +364,7 @@ void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state) {
|
|||||||
dns_zone_item_notify(z);
|
dns_zone_item_notify(z);
|
||||||
SWAP_TWO(t->notify_zone_items, t->notify_zone_items_done);
|
SWAP_TWO(t->notify_zone_items, t->notify_zone_items_done);
|
||||||
if (t->probing)
|
if (t->probing)
|
||||||
dns_scope_announce(t->scope, false);
|
(void) dns_scope_announce(t->scope, false);
|
||||||
|
|
||||||
SET_FOREACH_MOVE(d, t->notify_transactions_done, t->notify_transactions)
|
SET_FOREACH_MOVE(d, t->notify_transactions_done, t->notify_transactions)
|
||||||
dns_transaction_notify(d, t);
|
dns_transaction_notify(d, t);
|
||||||
|
@ -669,6 +669,7 @@ int link_address_new(Link *l, LinkAddress **ret, int family, const union in_addr
|
|||||||
|
|
||||||
a->link = l;
|
a->link = l;
|
||||||
LIST_PREPEND(addresses, l->addresses, a);
|
LIST_PREPEND(addresses, l->addresses, a);
|
||||||
|
l->n_addresses++;
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
*ret = a;
|
*ret = a;
|
||||||
@ -683,6 +684,9 @@ LinkAddress *link_address_free(LinkAddress *a) {
|
|||||||
if (a->link) {
|
if (a->link) {
|
||||||
LIST_REMOVE(addresses, a->link->addresses, a);
|
LIST_REMOVE(addresses, a->link->addresses, a);
|
||||||
|
|
||||||
|
assert(a->link->n_addresses > 0);
|
||||||
|
a->link->n_addresses--;
|
||||||
|
|
||||||
if (a->llmnr_address_rr) {
|
if (a->llmnr_address_rr) {
|
||||||
if (a->family == AF_INET && a->link->llmnr_ipv4_scope)
|
if (a->family == AF_INET && a->link->llmnr_ipv4_scope)
|
||||||
dns_zone_remove_rr(&a->link->llmnr_ipv4_scope->zone, a->llmnr_address_rr);
|
dns_zone_remove_rr(&a->link->llmnr_ipv4_scope->zone, a->llmnr_address_rr);
|
||||||
|
@ -60,6 +60,7 @@ struct Link {
|
|||||||
unsigned flags;
|
unsigned flags;
|
||||||
|
|
||||||
LIST_HEAD(LinkAddress, addresses);
|
LIST_HEAD(LinkAddress, addresses);
|
||||||
|
unsigned n_addresses;
|
||||||
|
|
||||||
LIST_HEAD(DnsServer, dns_servers);
|
LIST_HEAD(DnsServer, dns_servers);
|
||||||
DnsServer *current_dns_server;
|
DnsServer *current_dns_server;
|
||||||
|
@ -78,10 +78,8 @@ static int mdns_scope_process_query(DnsScope *s, DnsPacket *p) {
|
|||||||
assert(p);
|
assert(p);
|
||||||
|
|
||||||
r = dns_packet_extract(p);
|
r = dns_packet_extract(p);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_debug_errno(r, "Failed to extract resource records from incoming packet: %m");
|
return log_debug_errno(r, "Failed to extract resource records from incoming packet: %m");
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: there might be more than one question in mDNS queries. */
|
/* TODO: there might be more than one question in mDNS queries. */
|
||||||
assert_return((dns_question_size(p->question) > 0), -EINVAL);
|
assert_return((dns_question_size(p->question) > 0), -EINVAL);
|
||||||
@ -173,6 +171,19 @@ static int on_mdns_packet(sd_event_source *s, int fd, uint32_t revents, void *us
|
|||||||
t = dns_scope_find_transaction(scope, rr->key, false);
|
t = dns_scope_find_transaction(scope, rr->key, false);
|
||||||
if (t)
|
if (t)
|
||||||
dns_transaction_process_reply(t, p);
|
dns_transaction_process_reply(t, p);
|
||||||
|
|
||||||
|
/* Also look for the various types of ANY transactions */
|
||||||
|
t = dns_scope_find_transaction(scope, &DNS_RESOURCE_KEY_CONST(rr->key->class, DNS_TYPE_ANY, dns_resource_key_name(rr->key)), false);
|
||||||
|
if (t)
|
||||||
|
dns_transaction_process_reply(t, p);
|
||||||
|
|
||||||
|
t = dns_scope_find_transaction(scope, &DNS_RESOURCE_KEY_CONST(DNS_CLASS_ANY, rr->key->type, dns_resource_key_name(rr->key)), false);
|
||||||
|
if (t)
|
||||||
|
dns_transaction_process_reply(t, p);
|
||||||
|
|
||||||
|
t = dns_scope_find_transaction(scope, &DNS_RESOURCE_KEY_CONST(DNS_CLASS_ANY, DNS_TYPE_ANY, dns_resource_key_name(rr->key)), false);
|
||||||
|
if (t)
|
||||||
|
dns_transaction_process_reply(t, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
dns_cache_put(&scope->cache, NULL, DNS_PACKET_RCODE(p), p->answer, false, (uint32_t) -1, 0, p->family, &p->sender);
|
dns_cache_put(&scope->cache, NULL, DNS_PACKET_RCODE(p), p->answer, false, (uint32_t) -1, 0, p->family, &p->sender);
|
||||||
@ -182,7 +193,7 @@ static int on_mdns_packet(sd_event_source *s, int fd, uint32_t revents, void *us
|
|||||||
|
|
||||||
r = mdns_scope_process_query(scope, p);
|
r = mdns_scope_process_query(scope, p);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_debug("mDNS query processing failed.");
|
log_debug_errno(r, "mDNS query processing failed: %m");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
Loading…
Reference in New Issue
Block a user