summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-02-13 20:44:11 +0100
committerLennart Poettering <lennart@poettering.net>2017-02-13 20:44:11 +0100
commit1a63fc5430d66ccd72b0dbe3f6709724a811df40 (patch)
tree425434c200abc98c8764f30eb35140ed2b810d2e
parentbceaa99d49538fc24151abed9f9d40c950f626a2 (diff)
resolved: let's propagate errors from dns_scope_announce() and elsewhere
We don't actually make use of the return value for now, but it matches our coding style elsewhere, and it actually shortens our code quite a bit. Also, add a missing OOM check after dns_answer_new().
-rw-r--r--src/resolve/resolved-dns-scope.c43
-rw-r--r--src/resolve/resolved-dns-scope.h2
-rw-r--r--src/resolve/resolved-dns-transaction.c2
-rw-r--r--src/resolve/resolved-mdns.c8
4 files changed, 26 insertions, 29 deletions
diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c
index 7a26edbaf7..cf098b3b03 100644
--- a/src/resolve/resolved-dns-scope.c
+++ b/src/resolve/resolved-dns-scope.c
@@ -1061,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);
- dns_scope_announce(scope, false);
+ (void) dns_scope_announce(scope, false);
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_packet_unrefp) DnsPacket *p = NULL;
LinkAddress *a;
int r;
if (!scope)
- return;
+ return 0;
if (scope->protocol != DNS_PROTOCOL_MDNS)
- return;
+ return 0;
answer = dns_answer_new(4);
+ if (!answer)
+ return log_oom();
+
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);
- if (r < 0) {
- log_debug_errno(r, "Failed to add address RR to answer: %m");
- return;
- }
+ if (r < 0)
+ return log_debug_errno(r, "Failed to add address RR to answer: %m");
+
r = dns_answer_add(answer, a->mdns_ptr_rr, 0, goodbye ? DNS_ANSWER_GOODBYE : DNS_ANSWER_CACHE_FLUSH);
- if (r < 0) {
- log_debug_errno(r, "Failed to add PTR RR to answer: %m");
- return;
- }
+ if (r < 0)
+ return log_debug_errno(r, "Failed to add PTR RR to answer: %m");
}
if (dns_answer_isempty(answer))
- return;
+ return 0;
r = dns_scope_make_reply_packet(scope, 0, DNS_RCODE_SUCCESS, NULL, answer, NULL, false, &p);
- if (r < 0) {
- log_debug_errno(r, "Failed to build reply packet: %m");
- return;
- }
+ if (r < 0)
+ return log_debug_errno(r, "Failed to build reply packet: %m");
+
r = dns_scope_emit_udp(scope, -1, p);
- if (r < 0) {
- log_debug_errno(r, "Failed to send reply packet: %m");
- return;
- }
+ if (r < 0)
+ return log_debug_errno(r, "Failed to send reply packet: %m");
/* In section 8.3 of RFC6762: "The Multicast DNS responder MUST send at least two unsolicited
* responses, one second apart." */
@@ -1123,6 +1120,8 @@ void dns_scope_announce(DnsScope *scope, bool goodbye) {
MDNS_JITTER_RANGE_USEC,
on_announcement_timeout, scope);
if (r < 0)
- log_debug_errno(r, "Failed to schedule second announcement: %m");
+ return log_debug_errno(r, "Failed to schedule second announcement: %m");
}
+
+ return 0;
}
diff --git a/src/resolve/resolved-dns-scope.h b/src/resolve/resolved-dns-scope.h
index 360d86bc25..6f94b1fdcd 100644
--- a/src/resolve/resolved-dns-scope.h
+++ b/src/resolve/resolved-dns-scope.h
@@ -117,4 +117,4 @@ bool dns_scope_network_good(DnsScope *s);
int dns_scope_ifindex(DnsScope *s);
-void dns_scope_announce(DnsScope *scope, bool goodbye);
+int dns_scope_announce(DnsScope *scope, bool goodbye);
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index 0c7a8867fb..69e1d58ccf 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -364,7 +364,7 @@ void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state) {
dns_zone_item_notify(z);
SWAP_TWO(t->notify_zone_items, t->notify_zone_items_done);
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)
dns_transaction_notify(d, t);
diff --git a/src/resolve/resolved-mdns.c b/src/resolve/resolved-mdns.c
index f5cae6f682..aa7661b5ad 100644
--- a/src/resolve/resolved-mdns.c
+++ b/src/resolve/resolved-mdns.c
@@ -78,10 +78,8 @@ static int mdns_scope_process_query(DnsScope *s, DnsPacket *p) {
assert(p);
r = dns_packet_extract(p);
- if (r < 0) {
- log_debug_errno(r, "Failed to extract resource records from incoming packet: %m");
- return r;
- }
+ if (r < 0)
+ return log_debug_errno(r, "Failed to extract resource records from incoming packet: %m");
/* TODO: there might be more than one question in mDNS queries. */
assert_return((dns_question_size(p->question) > 0), -EINVAL);
@@ -182,7 +180,7 @@ static int on_mdns_packet(sd_event_source *s, int fd, uint32_t revents, void *us
r = mdns_scope_process_query(scope, p);
if (r < 0) {
- log_debug("mDNS query processing failed.");
+ log_debug_errno(r, "mDNS query processing failed: %m");
return 0;
}
} else