1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

resolved: add DNS_RR_REPLACE

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-05-12 17:03:07 +02:00
parent 1117a96087
commit 7daeec3e6c
5 changed files with 15 additions and 16 deletions

View File

@ -189,16 +189,11 @@ int dns_answer_add(
/* Entry already exists, keep the entry with the higher TTL. */
if (rr->ttl > exist->rr->ttl) {
dns_resource_record_ref(rr);
dns_resource_record_unref(exist->rr);
exist->rr = rr;
DNS_RR_REPLACE(exist->rr, dns_resource_record_ref(rr));
/* Update RRSIG and RR at the same time */
if (rrsig) {
dns_resource_record_ref(rrsig);
dns_resource_record_unref(exist->rrsig);
exist->rrsig = rrsig;
}
if (rrsig)
DNS_RR_REPLACE(exist->rrsig, dns_resource_record_ref(rrsig));
}
exist->flags |= flags;

View File

@ -378,9 +378,7 @@ static void dns_cache_item_update_positive(
assert_se(hashmap_replace(c->by_key, rr->key, i) >= 0);
dns_resource_record_ref(rr);
dns_resource_record_unref(i->rr);
i->rr = rr;
DNS_RR_REPLACE(i->rr, dns_resource_record_ref(rr));
dns_resource_key_unref(i->key);
i->key = dns_resource_key_ref(rr->key);

View File

@ -2359,8 +2359,7 @@ static int dns_packet_extract_answer(DnsPacket *p, DnsAnswer **ret_answer) {
/* Remember this RR, so that we can potentially merge its ->key object with the
* next RR. Note that we only do this if we actually decided to keep the RR around.
*/
dns_resource_record_unref(previous);
previous = dns_resource_record_ref(rr);
DNS_RR_REPLACE(previous, dns_resource_record_ref(rr));
}
if (bad_opt) {

View File

@ -1708,9 +1708,7 @@ int dns_resource_record_clamp_ttl(DnsResourceRecord **rr, uint32_t max_ttl) {
new_rr->ttl = new_ttl;
dns_resource_record_unref(*rr);
*rr = new_rr;
DNS_RR_REPLACE(*rr, new_rr);
return 1;
}

View File

@ -319,6 +319,15 @@ DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
DnsResourceRecord* dns_resource_record_new_full(uint16_t class, uint16_t type, const char *name);
DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
#define DNS_RR_REPLACE(a, b) \
do { \
typeof(a)* _a = &(a); \
typeof(b) _b = (b); \
dns_resource_record_unref(*_a); \
*_a = _b; \
} while(0)
int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name);
int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);