diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-01-06 19:57:11 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-01-10 05:13:11 +0100 |
commit | c08fd7becae0996ef87d4cef53167fe6c637667e (patch) | |
tree | df743dc97f0a1fc2bbdd3fd056b68780b9464a3a /src/resolve/resolved-dns-transaction.c | |
parent | resolve: cleanup dns_packet_ede_rcode() (diff) | |
download | systemd-c08fd7becae0996ef87d4cef53167fe6c637667e.tar.xz systemd-c08fd7becae0996ef87d4cef53167fe6c637667e.zip |
resolve: several follow-ups for ac6844460ca1c01eaf2cb209ffa21c200d21a8f8
- fix indentation,
- drop incorrect comment, dns_packet_ede_rcode() can handle unknown EDE rcode.
- 0 is a valid EDE rcode,
- DnsTransaction.answer_ede_msg may be NULL, so needs to use strempty()
on logging,
- drop redundant ede_rcode temporary variable.
Follow-up for ac6844460ca1c01eaf2cb209ffa21c200d21a8f8.
Diffstat (limited to 'src/resolve/resolved-dns-transaction.c')
-rw-r--r-- | src/resolve/resolved-dns-transaction.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index ea8243a2c8..aeae08f2f6 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -1223,38 +1223,35 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p, bool encrypt switch (t->scope->protocol) { case DNS_PROTOCOL_DNS: { - int ede_rcode; - assert(t->server); - if (dns_packet_ede_rcode(p, &ede_rcode, &t->answer_ede_msg) >= 0) - t->answer_ede_rcode = ede_rcode; + (void) dns_packet_ede_rcode(p, &t->answer_ede_rcode, &t->answer_ede_msg); if (!t->bypass && IN_SET(DNS_PACKET_RCODE(p), DNS_RCODE_FORMERR, DNS_RCODE_SERVFAIL, DNS_RCODE_NOTIMP)) { /* If the server has replied with detailed error data, using a degraded feature set * will likely not help anyone. Examine the detailed error to determine the best * course of action. */ - if (ede_rcode >= 0 && DNS_PACKET_RCODE(p) == DNS_RCODE_SERVFAIL) { + if (t->answer_ede_rcode >= 0 && DNS_PACKET_RCODE(p) == DNS_RCODE_SERVFAIL) { /* These codes are related to DNSSEC configuration errors. If accurate, * this is the domain operator's problem, and retrying won't help. */ - if (dns_ede_rcode_is_dnssec(ede_rcode)) { + if (dns_ede_rcode_is_dnssec(t->answer_ede_rcode)) { log_debug("Server returned error: %s (%s%s%s). Lookup failed.", - FORMAT_DNS_RCODE(DNS_PACKET_RCODE(p)), - FORMAT_DNS_EDE_RCODE(ede_rcode), - isempty(t->answer_ede_msg) ? "" : ": ", - t->answer_ede_msg); + FORMAT_DNS_RCODE(DNS_PACKET_RCODE(p)), + FORMAT_DNS_EDE_RCODE(t->answer_ede_rcode), + isempty(t->answer_ede_msg) ? "" : ": ", + strempty(t->answer_ede_msg)); dns_transaction_complete(t, DNS_TRANSACTION_UPSTREAM_DNSSEC_FAILURE); return; } /* These codes probably indicate a transient error. Let's try again. */ - if (IN_SET(ede_rcode, DNS_EDE_RCODE_NOT_READY, DNS_EDE_RCODE_NET_ERROR)) { + if (IN_SET(t->answer_ede_rcode, DNS_EDE_RCODE_NOT_READY, DNS_EDE_RCODE_NET_ERROR)) { log_debug("Server returned error: %s (%s%s%s), retrying transaction.", - FORMAT_DNS_RCODE(DNS_PACKET_RCODE(p)), - FORMAT_DNS_EDE_RCODE(ede_rcode), - isempty(t->answer_ede_msg) ? "" : ": ", - t->answer_ede_msg); + FORMAT_DNS_RCODE(DNS_PACKET_RCODE(p)), + FORMAT_DNS_EDE_RCODE(t->answer_ede_rcode), + isempty(t->answer_ede_msg) ? "" : ": ", + strempty(t->answer_ede_msg)); dns_transaction_retry(t, false); return; } @@ -1262,11 +1259,12 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p, bool encrypt /* OK, the query failed, but we still shouldn't degrade the feature set for * this server. */ log_debug("Server returned error: %s (%s%s%s)", - FORMAT_DNS_RCODE(DNS_PACKET_RCODE(p)), - FORMAT_DNS_EDE_RCODE(ede_rcode), - isempty(t->answer_ede_msg) ? "" : ": ", t->answer_ede_msg); + FORMAT_DNS_RCODE(DNS_PACKET_RCODE(p)), + FORMAT_DNS_EDE_RCODE(t->answer_ede_rcode), + isempty(t->answer_ede_msg) ? "" : ": ", + strempty(t->answer_ede_msg)); break; - } /* No EDE rcode, or EDE rcode we don't understand */ + } /* Request failed, immediately try again with reduced features */ @@ -1323,9 +1321,9 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p, bool encrypt if (DNS_PACKET_RCODE(p) == DNS_RCODE_REFUSED) { /* This server refused our request? If so, try again, use a different server */ - if (ede_rcode > 0) + if (t->answer_ede_rcode >= 0) log_debug("Server returned REFUSED (%s), switching servers, and retrying.", - FORMAT_DNS_EDE_RCODE(ede_rcode)); + FORMAT_DNS_EDE_RCODE(t->answer_ede_rcode)); else log_debug("Server returned REFUSED, switching servers, and retrying."); |