diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-05-12 17:12:59 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-05-12 17:15:51 +0200 |
commit | 899e3cdada849f50d2325106fb96e728cfc37dcc (patch) | |
tree | 8dd4c71454bd49260ff60906f4a05b0fb9b44fe9 /src | |
parent | 573184415761f569dca701cb9301fdeaeb78d34b (diff) | |
download | systemd-899e3cdada849f50d2325106fb96e728cfc37dcc.tar.gz |
resolved: add DNS_PACKET_REPLACE
Diffstat (limited to 'src')
-rw-r--r-- | src/resolve/resolved-dns-cache.c | 4 | ||||
-rw-r--r-- | src/resolve/resolved-dns-packet.h | 8 | ||||
-rw-r--r-- | src/resolve/resolved-dns-query.c | 6 | ||||
-rw-r--r-- | src/resolve/resolved-dns-transaction.c | 6 |
4 files changed, 13 insertions, 11 deletions
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index 90d23434cb..e7ab4e5569 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -384,9 +384,7 @@ static void dns_cache_item_update_positive( DNS_ANSWER_REPLACE(i->answer, dns_answer_ref(answer)); - dns_packet_ref(full_packet); - dns_packet_unref(i->full_packet); - i->full_packet = full_packet; + DNS_PACKET_REPLACE(i->full_packet, dns_packet_ref(full_packet)); i->until = calculate_until(rr, min_ttl, UINT32_MAX, timestamp, false); i->query_flags = query_flags & CACHEABLE_QUERY_FLAGS; diff --git a/src/resolve/resolved-dns-packet.h b/src/resolve/resolved-dns-packet.h index 0b797ecb1a..95b0b506ea 100644 --- a/src/resolve/resolved-dns-packet.h +++ b/src/resolve/resolved-dns-packet.h @@ -201,6 +201,14 @@ DnsPacket *dns_packet_unref(DnsPacket *p); DEFINE_TRIVIAL_CLEANUP_FUNC(DnsPacket*, dns_packet_unref); +#define DNS_PACKET_REPLACE(a, b) \ + do { \ + typeof(a)* _a = &(a); \ + typeof(b) _b = (b); \ + dns_packet_unref(*_a); \ + *_a = _b; \ + } while(0) + int dns_packet_validate(DnsPacket *p); int dns_packet_validate_reply(DnsPacket *p); int dns_packet_validate_query(DnsPacket *p); diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c index 3285917471..175fbe2296 100644 --- a/src/resolve/resolved-dns-query.c +++ b/src/resolve/resolved-dns-query.c @@ -857,8 +857,7 @@ static void dns_query_accept(DnsQuery *q, DnsQueryCandidate *c) { q->answer_rcode = t->answer_rcode; q->answer_errno = 0; - dns_packet_unref(q->answer_full_packet); - q->answer_full_packet = dns_packet_ref(t->received); + DNS_PACKET_REPLACE(q->answer_full_packet, dns_packet_ref(t->received)); if (FLAGS_SET(t->answer_query_flags, SD_RESOLVED_AUTHENTICATED)) { has_authenticated = true; @@ -899,8 +898,7 @@ static void dns_query_accept(DnsQuery *q, DnsQueryCandidate *c) { q->answer_dnssec_result = t->answer_dnssec_result; q->answer_query_flags = t->answer_query_flags | dns_transaction_source_to_query_flags(t->answer_source); q->answer_errno = t->answer_errno; - dns_packet_unref(q->answer_full_packet); - q->answer_full_packet = dns_packet_ref(t->received); + DNS_PACKET_REPLACE(q->answer_full_packet, dns_packet_ref(t->received)); state = t->state; break; diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 55626d06e3..c9ef115927 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -1096,10 +1096,8 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p, bool encrypt assert_not_reached(); } - if (t->received != p) { - dns_packet_unref(t->received); - t->received = dns_packet_ref(p); - } + if (t->received != p) + DNS_PACKET_REPLACE(t->received, dns_packet_ref(p)); t->answer_source = DNS_TRANSACTION_NETWORK; |