1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 14:55:37 +03:00

resolved: add DNS_ANSWER_REPLACE

C.f. ce913e0ec4.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-05-12 16:45:49 +02:00
parent 14b71de4e1
commit 1117a96087
5 changed files with 15 additions and 17 deletions

View File

@ -490,9 +490,7 @@ int dns_answer_extend(DnsAnswer **a, DnsAnswer *b) {
if (r < 0) if (r < 0)
return r; return r;
dns_answer_unref(*a); DNS_ANSWER_REPLACE(*a, merged);
*a = merged;
return 0; return 0;
} }
@ -714,8 +712,7 @@ int dns_answer_reserve_or_clone(DnsAnswer **a, size_t n_free) {
if (r < 0) if (r < 0)
return r; return r;
dns_answer_unref(*a); DNS_ANSWER_REPLACE(*a, TAKE_PTR(n));
*a = TAKE_PTR(n);
return 0; return 0;
} }

View File

@ -45,6 +45,14 @@ DnsAnswer *dns_answer_new(size_t n);
DnsAnswer *dns_answer_ref(DnsAnswer *a); DnsAnswer *dns_answer_ref(DnsAnswer *a);
DnsAnswer *dns_answer_unref(DnsAnswer *a); DnsAnswer *dns_answer_unref(DnsAnswer *a);
#define DNS_ANSWER_REPLACE(a, b) \
do { \
typeof(a)* _a = &(a); \
typeof(b) _b = (b); \
dns_answer_unref(*_a); \
*_a = _b; \
} while(0)
int dns_answer_add(DnsAnswer *a, DnsResourceRecord *rr, int ifindex, DnsAnswerFlags flags, DnsResourceRecord *rrsig); int dns_answer_add(DnsAnswer *a, DnsResourceRecord *rr, int ifindex, DnsAnswerFlags flags, DnsResourceRecord *rrsig);
int dns_answer_add_extend(DnsAnswer **a, DnsResourceRecord *rr, int ifindex, DnsAnswerFlags flags, DnsResourceRecord *rrsig); int dns_answer_add_extend(DnsAnswer **a, DnsResourceRecord *rr, int ifindex, DnsAnswerFlags flags, DnsResourceRecord *rrsig);
int dns_answer_add_soa(DnsAnswer *a, const char *name, uint32_t ttl, int ifindex); int dns_answer_add_soa(DnsAnswer *a, const char *name, uint32_t ttl, int ifindex);

View File

@ -385,9 +385,7 @@ static void dns_cache_item_update_positive(
dns_resource_key_unref(i->key); dns_resource_key_unref(i->key);
i->key = dns_resource_key_ref(rr->key); i->key = dns_resource_key_ref(rr->key);
dns_answer_ref(answer); DNS_ANSWER_REPLACE(i->answer, dns_answer_ref(answer));
dns_answer_unref(i->answer);
i->answer = answer;
dns_packet_ref(full_packet); dns_packet_ref(full_packet);
dns_packet_unref(i->full_packet); dns_packet_unref(i->full_packet);

View File

@ -850,9 +850,7 @@ static void dns_query_accept(DnsQuery *q, DnsQueryCandidate *c) {
q->answer_query_flags |= dns_transaction_source_to_query_flags(t->answer_source); q->answer_query_flags |= dns_transaction_source_to_query_flags(t->answer_source);
} else { } else {
/* Override non-successful previous answers */ /* Override non-successful previous answers */
dns_answer_unref(q->answer); DNS_ANSWER_REPLACE(q->answer, dns_answer_ref(t->answer));
q->answer = dns_answer_ref(t->answer);
q->answer_query_flags = dns_transaction_source_to_query_flags(t->answer_source); q->answer_query_flags = dns_transaction_source_to_query_flags(t->answer_source);
} }
@ -896,8 +894,7 @@ static void dns_query_accept(DnsQuery *q, DnsQueryCandidate *c) {
!FLAGS_SET(t->answer_query_flags, SD_RESOLVED_AUTHENTICATED)) !FLAGS_SET(t->answer_query_flags, SD_RESOLVED_AUTHENTICATED))
continue; continue;
dns_answer_unref(q->answer); DNS_ANSWER_REPLACE(q->answer, dns_answer_ref(t->answer));
q->answer = dns_answer_ref(t->answer);
q->answer_rcode = t->answer_rcode; q->answer_rcode = t->answer_rcode;
q->answer_dnssec_result = t->answer_dnssec_result; 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_query_flags = t->answer_query_flags | dns_transaction_source_to_query_flags(t->answer_source);

View File

@ -1364,8 +1364,7 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p, bool encrypt
* field is later replaced by the DNSSEC validated subset. The 'answer_auxiliary' field carries the * field is later replaced by the DNSSEC validated subset. The 'answer_auxiliary' field carries the
* original complete record set, including RRSIG and friends. We use this when passing data to * original complete record set, including RRSIG and friends. We use this when passing data to
* clients that ask for DNSSEC metadata. */ * clients that ask for DNSSEC metadata. */
dns_answer_unref(t->answer); DNS_ANSWER_REPLACE(t->answer, dns_answer_ref(p->answer));
t->answer = dns_answer_ref(p->answer);
t->answer_rcode = DNS_PACKET_RCODE(p); t->answer_rcode = DNS_PACKET_RCODE(p);
t->answer_dnssec_result = _DNSSEC_RESULT_INVALID; t->answer_dnssec_result = _DNSSEC_RESULT_INVALID;
SET_FLAG(t->answer_query_flags, SD_RESOLVED_AUTHENTICATED, false); SET_FLAG(t->answer_query_flags, SD_RESOLVED_AUTHENTICATED, false);
@ -3452,8 +3451,7 @@ int dns_transaction_validate_dnssec(DnsTransaction *t) {
break; break;
} }
dns_answer_unref(t->answer); DNS_ANSWER_REPLACE(t->answer, TAKE_PTR(validated));
t->answer = TAKE_PTR(validated);
/* At this point the answer only contains validated /* At this point the answer only contains validated
* RRsets. Now, let's see if it actually answers the question * RRsets. Now, let's see if it actually answers the question