resolved: split out helper for allocating DnsResourceRecord object from raw data

No change in behaviour, just some refactoring.
This commit is contained in:
Lennart Poettering
2022-09-30 14:21:38 +02:00
parent b497a958d6
commit ab26cdf730
3 changed files with 20 additions and 12 deletions
+1 -12
View File
@@ -395,20 +395,9 @@ static int resolve_address(sd_bus *bus, int family, const union in_addr_union *a
static int output_rr_packet(const void *d, size_t l, int ifindex) {
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
_cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
int r;
r = dns_packet_new(&p, DNS_PROTOCOL_DNS, 0, DNS_PACKET_SIZE_MAX);
if (r < 0)
return log_oom();
p->refuse_compression = true;
r = dns_packet_append_blob(p, d, l, NULL);
if (r < 0)
return log_oom();
r = dns_packet_read_rr(p, &rr, NULL, NULL);
r = dns_resource_record_new_from_raw(&rr, d, l);
if (r < 0)
return log_error_errno(r, "Failed to parse RR: %m");
+17
View File
@@ -1832,6 +1832,23 @@ int dns_txt_item_new_empty(DnsTxtItem **ret) {
return 0;
}
int dns_resource_record_new_from_raw(DnsResourceRecord **ret, const void *data, size_t size) {
_cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
int r;
r = dns_packet_new(&p, DNS_PROTOCOL_DNS, 0, DNS_PACKET_SIZE_MAX);
if (r < 0)
return r;
p->refuse_compression = true;
r = dns_packet_append_blob(p, data, size, NULL);
if (r < 0)
return r;
return dns_packet_read_rr(p, ret, NULL, NULL);
}
static const char* const dnssec_algorithm_table[_DNSSEC_ALGORITHM_MAX_DEFINED] = {
/* Mnemonics as listed on https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml */
[DNSSEC_ALGORITHM_RSAMD5] = "RSAMD5",
+2
View File
@@ -364,6 +364,8 @@ bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
DnsTxtItem *dns_txt_item_copy(DnsTxtItem *i);
int dns_txt_item_new_empty(DnsTxtItem **ret);
int dns_resource_record_new_from_raw(DnsResourceRecord **ret, const void *data, size_t size);
void dns_resource_record_hash_func(const DnsResourceRecord *i, struct siphash *state);
int dns_resource_record_compare_func(const DnsResourceRecord *x, const DnsResourceRecord *y);