2 This file is part of systemd.
4 Copyright 2014 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "alloc-util.h"
23 #include "dns-domain.h"
26 #include "hexdecoct.h"
27 #include "resolved-dns-dnssec.h"
28 #include "resolved-dns-packet.h"
29 #include "resolved-dns-rr.h"
30 #include "string-table.h"
31 #include "string-util.h"
33 #include "terminal-util.h"
35 DnsResourceKey
* dns_resource_key_new(uint16_t class, uint16_t type
, const char *name
) {
42 k
= malloc0(sizeof(DnsResourceKey
) + l
+ 1);
50 strcpy((char*) k
+ sizeof(DnsResourceKey
), name
);
55 DnsResourceKey
* dns_resource_key_new_redirect(const DnsResourceKey
*key
, const DnsResourceRecord
*cname
) {
61 assert(IN_SET(cname
->key
->type
, DNS_TYPE_CNAME
, DNS_TYPE_DNAME
));
63 if (cname
->key
->type
== DNS_TYPE_CNAME
)
64 return dns_resource_key_new(key
->class, key
->type
, cname
->cname
.name
);
67 char *destination
= NULL
;
69 r
= dns_name_change_suffix(dns_resource_key_name(key
), dns_resource_key_name(cname
->key
), cname
->dname
.name
, &destination
);
73 return dns_resource_key_ref((DnsResourceKey
*) key
);
75 k
= dns_resource_key_new_consume(key
->class, key
->type
, destination
);
77 return mfree(destination
);
83 int dns_resource_key_new_append_suffix(DnsResourceKey
**ret
, DnsResourceKey
*key
, char *name
) {
84 DnsResourceKey
*new_key
;
92 if (dns_name_is_root(name
)) {
93 *ret
= dns_resource_key_ref(key
);
97 r
= dns_name_concat(dns_resource_key_name(key
), name
, &joined
);
101 new_key
= dns_resource_key_new_consume(key
->class, key
->type
, joined
);
111 DnsResourceKey
* dns_resource_key_new_consume(uint16_t class, uint16_t type
, char *name
) {
116 k
= new0(DnsResourceKey
, 1);
128 DnsResourceKey
* dns_resource_key_ref(DnsResourceKey
*k
) {
133 /* Static/const keys created with DNS_RESOURCE_KEY_CONST will
134 * set this to -1, they should not be reffed/unreffed */
135 assert(k
->n_ref
!= (unsigned) -1);
137 assert(k
->n_ref
> 0);
143 DnsResourceKey
* dns_resource_key_unref(DnsResourceKey
*k
) {
147 assert(k
->n_ref
!= (unsigned) -1);
148 assert(k
->n_ref
> 0);
159 const char* dns_resource_key_name(const DnsResourceKey
*key
) {
168 name
= (char*) key
+ sizeof(DnsResourceKey
);
170 if (dns_name_is_root(name
))
176 bool dns_resource_key_is_address(const DnsResourceKey
*key
) {
179 /* Check if this is an A or AAAA resource key */
181 return key
->class == DNS_CLASS_IN
&& IN_SET(key
->type
, DNS_TYPE_A
, DNS_TYPE_AAAA
);
184 int dns_resource_key_equal(const DnsResourceKey
*a
, const DnsResourceKey
*b
) {
190 r
= dns_name_equal(dns_resource_key_name(a
), dns_resource_key_name(b
));
194 if (a
->class != b
->class)
197 if (a
->type
!= b
->type
)
203 int dns_resource_key_match_rr(const DnsResourceKey
*key
, DnsResourceRecord
*rr
, const char *search_domain
) {
212 /* Checks if an rr matches the specified key. If a search
213 * domain is specified, it will also be checked if the key
214 * with the search domain suffixed might match the RR. */
216 if (rr
->key
->class != key
->class && key
->class != DNS_CLASS_ANY
)
219 if (rr
->key
->type
!= key
->type
&& key
->type
!= DNS_TYPE_ANY
)
222 r
= dns_name_equal(dns_resource_key_name(rr
->key
), dns_resource_key_name(key
));
227 _cleanup_free_
char *joined
= NULL
;
229 r
= dns_name_concat(dns_resource_key_name(key
), search_domain
, &joined
);
233 return dns_name_equal(dns_resource_key_name(rr
->key
), joined
);
239 int dns_resource_key_match_cname_or_dname(const DnsResourceKey
*key
, const DnsResourceKey
*cname
, const char *search_domain
) {
245 if (cname
->class != key
->class && key
->class != DNS_CLASS_ANY
)
248 if (cname
->type
== DNS_TYPE_CNAME
)
249 r
= dns_name_equal(dns_resource_key_name(key
), dns_resource_key_name(cname
));
250 else if (cname
->type
== DNS_TYPE_DNAME
)
251 r
= dns_name_endswith(dns_resource_key_name(key
), dns_resource_key_name(cname
));
259 _cleanup_free_
char *joined
= NULL
;
261 r
= dns_name_concat(dns_resource_key_name(key
), search_domain
, &joined
);
265 if (cname
->type
== DNS_TYPE_CNAME
)
266 return dns_name_equal(joined
, dns_resource_key_name(cname
));
267 else if (cname
->type
== DNS_TYPE_DNAME
)
268 return dns_name_endswith(joined
, dns_resource_key_name(cname
));
274 int dns_resource_key_match_soa(const DnsResourceKey
*key
, const DnsResourceKey
*soa
) {
278 /* Checks whether 'soa' is a SOA record for the specified key. */
280 if (soa
->class != key
->class)
283 if (soa
->type
!= DNS_TYPE_SOA
)
286 return dns_name_endswith(dns_resource_key_name(key
), dns_resource_key_name(soa
));
289 static void dns_resource_key_hash_func(const void *i
, struct siphash
*state
) {
290 const DnsResourceKey
*k
= i
;
294 dns_name_hash_func(dns_resource_key_name(k
), state
);
295 siphash24_compress(&k
->class, sizeof(k
->class), state
);
296 siphash24_compress(&k
->type
, sizeof(k
->type
), state
);
299 static int dns_resource_key_compare_func(const void *a
, const void *b
) {
300 const DnsResourceKey
*x
= a
, *y
= b
;
303 ret
= dns_name_compare_func(dns_resource_key_name(x
), dns_resource_key_name(y
));
307 if (x
->type
< y
->type
)
309 if (x
->type
> y
->type
)
312 if (x
->class < y
->class)
314 if (x
->class > y
->class)
320 const struct hash_ops dns_resource_key_hash_ops
= {
321 .hash
= dns_resource_key_hash_func
,
322 .compare
= dns_resource_key_compare_func
325 char* dns_resource_key_to_string(const DnsResourceKey
*key
, char *buf
, size_t buf_size
) {
329 /* If we cannot convert the CLASS/TYPE into a known string,
330 use the format recommended by RFC 3597, Section 5. */
332 c
= dns_class_to_string(key
->class);
333 t
= dns_type_to_string(key
->type
);
335 snprintf(buf
, buf_size
, "%s %s%s%.0u %s%s%.0u",
336 dns_resource_key_name(key
),
337 c
?: "", c
? "" : "CLASS", c
? 0 : key
->class,
338 t
?: "", t
? "" : "TYPE", t
? 0 : key
->class);
343 bool dns_resource_key_reduce(DnsResourceKey
**a
, DnsResourceKey
**b
) {
347 /* Try to replace one RR key by another if they are identical, thus saving a bit of memory. Note that we do
348 * this only for RR keys, not for RRs themselves, as they carry a lot of additional metadata (where they come
349 * from, validity data, and suchlike), and cannot be replaced so easily by other RRs that have the same
350 * superficial data. */
357 /* We refuse merging const keys */
358 if ((*a
)->n_ref
== (unsigned) -1)
360 if ((*b
)->n_ref
== (unsigned) -1)
363 /* Already the same? */
367 /* Are they really identical? */
368 if (dns_resource_key_equal(*a
, *b
) <= 0)
371 /* Keep the one which already has more references. */
372 if ((*a
)->n_ref
> (*b
)->n_ref
) {
373 dns_resource_key_unref(*b
);
374 *b
= dns_resource_key_ref(*a
);
376 dns_resource_key_unref(*a
);
377 *a
= dns_resource_key_ref(*b
);
383 DnsResourceRecord
* dns_resource_record_new(DnsResourceKey
*key
) {
384 DnsResourceRecord
*rr
;
386 rr
= new0(DnsResourceRecord
, 1);
391 rr
->key
= dns_resource_key_ref(key
);
392 rr
->expiry
= USEC_INFINITY
;
393 rr
->n_skip_labels_signer
= rr
->n_skip_labels_source
= (unsigned) -1;
398 DnsResourceRecord
* dns_resource_record_new_full(uint16_t class, uint16_t type
, const char *name
) {
399 _cleanup_(dns_resource_key_unrefp
) DnsResourceKey
*key
= NULL
;
401 key
= dns_resource_key_new(class, type
, name
);
405 return dns_resource_record_new(key
);
408 DnsResourceRecord
* dns_resource_record_ref(DnsResourceRecord
*rr
) {
412 assert(rr
->n_ref
> 0);
418 DnsResourceRecord
* dns_resource_record_unref(DnsResourceRecord
*rr
) {
422 assert(rr
->n_ref
> 0);
430 switch(rr
->key
->type
) {
450 dns_txt_item_free_all(rr
->txt
.items
);
459 free(rr
->mx
.exchange
);
467 free(rr
->sshfp
.fingerprint
);
470 case DNS_TYPE_DNSKEY
:
471 free(rr
->dnskey
.key
);
475 free(rr
->rrsig
.signer
);
476 free(rr
->rrsig
.signature
);
480 free(rr
->nsec
.next_domain_name
);
481 bitmap_free(rr
->nsec
.types
);
485 free(rr
->nsec3
.next_hashed_name
);
486 free(rr
->nsec3
.salt
);
487 bitmap_free(rr
->nsec3
.types
);
504 case DNS_TYPE_OPENPGPKEY
:
506 free(rr
->generic
.data
);
509 free(rr
->wire_format
);
510 dns_resource_key_unref(rr
->key
);
517 int dns_resource_record_new_reverse(DnsResourceRecord
**ret
, int family
, const union in_addr_union
*address
, const char *hostname
) {
518 _cleanup_(dns_resource_key_unrefp
) DnsResourceKey
*key
= NULL
;
519 _cleanup_(dns_resource_record_unrefp
) DnsResourceRecord
*rr
= NULL
;
520 _cleanup_free_
char *ptr
= NULL
;
527 r
= dns_name_reverse(family
, address
, &ptr
);
531 key
= dns_resource_key_new_consume(DNS_CLASS_IN
, DNS_TYPE_PTR
, ptr
);
537 rr
= dns_resource_record_new(key
);
541 rr
->ptr
.name
= strdup(hostname
);
551 int dns_resource_record_new_address(DnsResourceRecord
**ret
, int family
, const union in_addr_union
*address
, const char *name
) {
552 DnsResourceRecord
*rr
;
558 if (family
== AF_INET
) {
560 rr
= dns_resource_record_new_full(DNS_CLASS_IN
, DNS_TYPE_A
, name
);
564 rr
->a
.in_addr
= address
->in
;
566 } else if (family
== AF_INET6
) {
568 rr
= dns_resource_record_new_full(DNS_CLASS_IN
, DNS_TYPE_AAAA
, name
);
572 rr
->aaaa
.in6_addr
= address
->in6
;
574 return -EAFNOSUPPORT
;
581 #define FIELD_EQUAL(a, b, field) \
582 ((a).field ## _size == (b).field ## _size && \
583 memcmp((a).field, (b).field, (a).field ## _size) == 0)
585 int dns_resource_record_equal(const DnsResourceRecord
*a
, const DnsResourceRecord
*b
) {
594 r
= dns_resource_key_equal(a
->key
, b
->key
);
598 if (a
->unparseable
!= b
->unparseable
)
601 switch (a
->unparseable
? _DNS_TYPE_INVALID
: a
->key
->type
) {
604 r
= dns_name_equal(a
->srv
.name
, b
->srv
.name
);
608 return a
->srv
.priority
== b
->srv
.priority
&&
609 a
->srv
.weight
== b
->srv
.weight
&&
610 a
->srv
.port
== b
->srv
.port
;
616 return dns_name_equal(a
->ptr
.name
, b
->ptr
.name
);
619 return strcaseeq(a
->hinfo
.cpu
, b
->hinfo
.cpu
) &&
620 strcaseeq(a
->hinfo
.os
, b
->hinfo
.os
);
622 case DNS_TYPE_SPF
: /* exactly the same as TXT */
624 return dns_txt_item_equal(a
->txt
.items
, b
->txt
.items
);
627 return memcmp(&a
->a
.in_addr
, &b
->a
.in_addr
, sizeof(struct in_addr
)) == 0;
630 return memcmp(&a
->aaaa
.in6_addr
, &b
->aaaa
.in6_addr
, sizeof(struct in6_addr
)) == 0;
633 r
= dns_name_equal(a
->soa
.mname
, b
->soa
.mname
);
636 r
= dns_name_equal(a
->soa
.rname
, b
->soa
.rname
);
640 return a
->soa
.serial
== b
->soa
.serial
&&
641 a
->soa
.refresh
== b
->soa
.refresh
&&
642 a
->soa
.retry
== b
->soa
.retry
&&
643 a
->soa
.expire
== b
->soa
.expire
&&
644 a
->soa
.minimum
== b
->soa
.minimum
;
647 if (a
->mx
.priority
!= b
->mx
.priority
)
650 return dns_name_equal(a
->mx
.exchange
, b
->mx
.exchange
);
653 assert(a
->loc
.version
== b
->loc
.version
);
655 return a
->loc
.size
== b
->loc
.size
&&
656 a
->loc
.horiz_pre
== b
->loc
.horiz_pre
&&
657 a
->loc
.vert_pre
== b
->loc
.vert_pre
&&
658 a
->loc
.latitude
== b
->loc
.latitude
&&
659 a
->loc
.longitude
== b
->loc
.longitude
&&
660 a
->loc
.altitude
== b
->loc
.altitude
;
663 return a
->ds
.key_tag
== b
->ds
.key_tag
&&
664 a
->ds
.algorithm
== b
->ds
.algorithm
&&
665 a
->ds
.digest_type
== b
->ds
.digest_type
&&
666 FIELD_EQUAL(a
->ds
, b
->ds
, digest
);
669 return a
->sshfp
.algorithm
== b
->sshfp
.algorithm
&&
670 a
->sshfp
.fptype
== b
->sshfp
.fptype
&&
671 FIELD_EQUAL(a
->sshfp
, b
->sshfp
, fingerprint
);
673 case DNS_TYPE_DNSKEY
:
674 return a
->dnskey
.flags
== b
->dnskey
.flags
&&
675 a
->dnskey
.protocol
== b
->dnskey
.protocol
&&
676 a
->dnskey
.algorithm
== b
->dnskey
.algorithm
&&
677 FIELD_EQUAL(a
->dnskey
, b
->dnskey
, key
);
680 /* do the fast comparisons first */
681 return a
->rrsig
.type_covered
== b
->rrsig
.type_covered
&&
682 a
->rrsig
.algorithm
== b
->rrsig
.algorithm
&&
683 a
->rrsig
.labels
== b
->rrsig
.labels
&&
684 a
->rrsig
.original_ttl
== b
->rrsig
.original_ttl
&&
685 a
->rrsig
.expiration
== b
->rrsig
.expiration
&&
686 a
->rrsig
.inception
== b
->rrsig
.inception
&&
687 a
->rrsig
.key_tag
== b
->rrsig
.key_tag
&&
688 FIELD_EQUAL(a
->rrsig
, b
->rrsig
, signature
) &&
689 dns_name_equal(a
->rrsig
.signer
, b
->rrsig
.signer
);
692 return dns_name_equal(a
->nsec
.next_domain_name
, b
->nsec
.next_domain_name
) &&
693 bitmap_equal(a
->nsec
.types
, b
->nsec
.types
);
696 return a
->nsec3
.algorithm
== b
->nsec3
.algorithm
&&
697 a
->nsec3
.flags
== b
->nsec3
.flags
&&
698 a
->nsec3
.iterations
== b
->nsec3
.iterations
&&
699 FIELD_EQUAL(a
->nsec3
, b
->nsec3
, salt
) &&
700 FIELD_EQUAL(a
->nsec3
, b
->nsec3
, next_hashed_name
) &&
701 bitmap_equal(a
->nsec3
.types
, b
->nsec3
.types
);
704 return a
->tlsa
.cert_usage
== b
->tlsa
.cert_usage
&&
705 a
->tlsa
.selector
== b
->tlsa
.selector
&&
706 a
->tlsa
.matching_type
== b
->tlsa
.matching_type
&&
707 FIELD_EQUAL(a
->tlsa
, b
->tlsa
, data
);
710 return a
->caa
.flags
== b
->caa
.flags
&&
711 streq(a
->caa
.tag
, b
->caa
.tag
) &&
712 FIELD_EQUAL(a
->caa
, b
->caa
, value
);
714 case DNS_TYPE_OPENPGPKEY
:
716 return FIELD_EQUAL(a
->generic
, b
->generic
, data
);
720 static char* format_location(uint32_t latitude
, uint32_t longitude
, uint32_t altitude
,
721 uint8_t size
, uint8_t horiz_pre
, uint8_t vert_pre
) {
723 char NS
= latitude
>= 1U<<31 ? 'N' : 'S';
724 char EW
= longitude
>= 1U<<31 ? 'E' : 'W';
726 int lat
= latitude
>= 1U<<31 ? (int) (latitude
- (1U<<31)) : (int) ((1U<<31) - latitude
);
727 int lon
= longitude
>= 1U<<31 ? (int) (longitude
- (1U<<31)) : (int) ((1U<<31) - longitude
);
728 double alt
= altitude
>= 10000000u ? altitude
- 10000000u : -(double)(10000000u - altitude
);
729 double siz
= (size
>> 4) * exp10((double) (size
& 0xF));
730 double hor
= (horiz_pre
>> 4) * exp10((double) (horiz_pre
& 0xF));
731 double ver
= (vert_pre
>> 4) * exp10((double) (vert_pre
& 0xF));
733 if (asprintf(&s
, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
736 (lat
% 60000) / 1000.,
740 (lon
% 60000) / 1000.,
751 static int format_timestamp_dns(char *buf
, size_t l
, time_t sec
) {
755 assert(l
> strlen("YYYYMMDDHHmmSS"));
757 if (!gmtime_r(&sec
, &tm
))
760 if (strftime(buf
, l
, "%Y%m%d%H%M%S", &tm
) <= 0)
766 static char *format_types(Bitmap
*types
) {
767 _cleanup_strv_free_
char **strv
= NULL
;
768 _cleanup_free_
char *str
= NULL
;
773 BITMAP_FOREACH(type
, types
, i
) {
774 if (dns_type_to_string(type
)) {
775 r
= strv_extend(&strv
, dns_type_to_string(type
));
781 r
= asprintf(&t
, "TYPE%u", type
);
785 r
= strv_consume(&strv
, t
);
791 str
= strv_join(strv
, " ");
795 return strjoin("( ", str
, " )");
798 static char *format_txt(DnsTxtItem
*first
) {
803 LIST_FOREACH(items
, i
, first
)
804 c
+= i
->length
* 4 + 3;
806 p
= s
= new(char, c
);
810 LIST_FOREACH(items
, i
, first
) {
818 for (j
= 0; j
< i
->length
; j
++) {
819 if (i
->data
[j
] < ' ' || i
->data
[j
] == '"' || i
->data
[j
] >= 127) {
821 *(p
++) = '0' + (i
->data
[j
] / 100);
822 *(p
++) = '0' + ((i
->data
[j
] / 10) % 10);
823 *(p
++) = '0' + (i
->data
[j
] % 10);
835 const char *dns_resource_record_to_string(DnsResourceRecord
*rr
) {
836 _cleanup_free_
char *t
= NULL
;
837 char *s
, k
[DNS_RESOURCE_KEY_STRING_MAX
];
843 return rr
->to_string
;
845 dns_resource_key_to_string(rr
->key
, k
, sizeof(k
));
847 switch (rr
->unparseable
? _DNS_TYPE_INVALID
: rr
->key
->type
) {
850 r
= asprintf(&s
, "%s %u %u %u %s",
855 strna(rr
->srv
.name
));
864 s
= strjoin(k
, " ", rr
->ptr
.name
);
871 s
= strjoin(k
, " ", rr
->hinfo
.cpu
, " ", rr
->hinfo
.os
);
876 case DNS_TYPE_SPF
: /* exactly the same as TXT */
878 t
= format_txt(rr
->txt
.items
);
882 s
= strjoin(k
, " ", t
);
888 _cleanup_free_
char *x
= NULL
;
890 r
= in_addr_to_string(AF_INET
, (const union in_addr_union
*) &rr
->a
.in_addr
, &x
);
894 s
= strjoin(k
, " ", x
);
901 r
= in_addr_to_string(AF_INET6
, (const union in_addr_union
*) &rr
->aaaa
.in6_addr
, &t
);
905 s
= strjoin(k
, " ", t
);
911 r
= asprintf(&s
, "%s %s %s %u %u %u %u %u",
913 strna(rr
->soa
.mname
),
914 strna(rr
->soa
.rname
),
925 r
= asprintf(&s
, "%s %u %s",
934 assert(rr
->loc
.version
== 0);
936 t
= format_location(rr
->loc
.latitude
,
945 s
= strjoin(k
, " ", t
);
951 t
= hexmem(rr
->ds
.digest
, rr
->ds
.digest_size
);
955 r
= asprintf(&s
, "%s %u %u %u %s",
966 t
= hexmem(rr
->sshfp
.fingerprint
, rr
->sshfp
.fingerprint_size
);
970 r
= asprintf(&s
, "%s %u %u %s",
979 case DNS_TYPE_DNSKEY
: {
980 _cleanup_free_
char *alg
= NULL
;
985 key_tag
= dnssec_keytag(rr
, true);
987 r
= dnssec_algorithm_to_string_alloc(rr
->dnskey
.algorithm
, &alg
);
991 r
= asprintf(&s
, "%s %u %u %s %n",
1000 r
= base64_append(&s
, n
,
1001 rr
->dnskey
.key
, rr
->dnskey
.key_size
,
1006 r
= asprintf(&ss
, "%s\n"
1007 " -- Flags:%s%s%s\n"
1010 rr
->dnskey
.flags
& DNSKEY_FLAG_SEP
? " SEP" : "",
1011 rr
->dnskey
.flags
& DNSKEY_FLAG_REVOKE
? " REVOKE" : "",
1012 rr
->dnskey
.flags
& DNSKEY_FLAG_ZONE_KEY
? " ZONE_KEY" : "",
1022 case DNS_TYPE_RRSIG
: {
1023 _cleanup_free_
char *alg
= NULL
;
1024 char expiration
[strlen("YYYYMMDDHHmmSS") + 1], inception
[strlen("YYYYMMDDHHmmSS") + 1];
1028 type
= dns_type_to_string(rr
->rrsig
.type_covered
);
1030 r
= dnssec_algorithm_to_string_alloc(rr
->rrsig
.algorithm
, &alg
);
1034 r
= format_timestamp_dns(expiration
, sizeof(expiration
), rr
->rrsig
.expiration
);
1038 r
= format_timestamp_dns(inception
, sizeof(inception
), rr
->rrsig
.inception
);
1043 * http://tools.ietf.org/html/rfc3597#section-5 */
1045 r
= asprintf(&s
, "%s %s%.*u %s %u %u %s %s %u %s %n",
1048 type
? 0 : 1, type
? 0u : (unsigned) rr
->rrsig
.type_covered
,
1051 rr
->rrsig
.original_ttl
,
1060 r
= base64_append(&s
, n
,
1061 rr
->rrsig
.signature
, rr
->rrsig
.signature_size
,
1070 t
= format_types(rr
->nsec
.types
);
1074 r
= asprintf(&s
, "%s %s %s",
1076 rr
->nsec
.next_domain_name
,
1082 case DNS_TYPE_NSEC3
: {
1083 _cleanup_free_
char *salt
= NULL
, *hash
= NULL
;
1085 if (rr
->nsec3
.salt_size
> 0) {
1086 salt
= hexmem(rr
->nsec3
.salt
, rr
->nsec3
.salt_size
);
1091 hash
= base32hexmem(rr
->nsec3
.next_hashed_name
, rr
->nsec3
.next_hashed_name_size
, false);
1095 t
= format_types(rr
->nsec3
.types
);
1099 r
= asprintf(&s
, "%s %"PRIu8
" %"PRIu8
" %"PRIu16
" %s %s %s",
1101 rr
->nsec3
.algorithm
,
1103 rr
->nsec3
.iterations
,
1104 rr
->nsec3
.salt_size
> 0 ? salt
: "-",
1113 case DNS_TYPE_TLSA
: {
1114 const char *cert_usage
, *selector
, *matching_type
;
1116 cert_usage
= tlsa_cert_usage_to_string(rr
->tlsa
.cert_usage
);
1117 selector
= tlsa_selector_to_string(rr
->tlsa
.selector
);
1118 matching_type
= tlsa_matching_type_to_string(rr
->tlsa
.matching_type
);
1120 t
= hexmem(rr
->sshfp
.fingerprint
, rr
->sshfp
.fingerprint_size
);
1126 " -- Cert. usage: %s\n"
1127 " -- Selector: %s\n"
1128 " -- Matching type: %s",
1130 rr
->tlsa
.cert_usage
,
1132 rr
->tlsa
.matching_type
,
1143 case DNS_TYPE_CAA
: {
1144 _cleanup_free_
char *value
;
1146 value
= octescape(rr
->caa
.value
, rr
->caa
.value_size
);
1150 r
= asprintf(&s
, "%s %u %s \"%s\"%s%s%s%.0u",
1155 rr
->caa
.flags
? "\n -- Flags:" : "",
1156 rr
->caa
.flags
& CAA_FLAG_CRITICAL
? " critical" : "",
1157 rr
->caa
.flags
& ~CAA_FLAG_CRITICAL
? " " : "",
1158 rr
->caa
.flags
& ~CAA_FLAG_CRITICAL
);
1165 case DNS_TYPE_OPENPGPKEY
: {
1168 r
= asprintf(&s
, "%s %n",
1174 r
= base64_append(&s
, n
,
1175 rr
->generic
.data
, rr
->generic
.data_size
,
1183 t
= hexmem(rr
->generic
.data
, rr
->generic
.data_size
);
1187 /* Format as documented in RFC 3597, Section 5 */
1188 r
= asprintf(&s
, "%s \\# %zu %s", k
, rr
->generic
.data_size
, t
);
1198 ssize_t
dns_resource_record_payload(DnsResourceRecord
*rr
, void **out
) {
1202 switch(rr
->unparseable
? _DNS_TYPE_INVALID
: rr
->key
->type
) {
1206 case DNS_TYPE_CNAME
:
1207 case DNS_TYPE_DNAME
:
1208 case DNS_TYPE_HINFO
:
1217 case DNS_TYPE_DNSKEY
:
1218 case DNS_TYPE_RRSIG
:
1220 case DNS_TYPE_NSEC3
:
1223 case DNS_TYPE_SSHFP
:
1224 *out
= rr
->sshfp
.fingerprint
;
1225 return rr
->sshfp
.fingerprint_size
;
1228 *out
= rr
->tlsa
.data
;
1229 return rr
->tlsa
.data_size
;
1232 case DNS_TYPE_OPENPGPKEY
:
1234 *out
= rr
->generic
.data
;
1235 return rr
->generic
.data_size
;
1239 int dns_resource_record_to_wire_format(DnsResourceRecord
*rr
, bool canonical
) {
1241 DnsPacket packet
= {
1243 .protocol
= DNS_PROTOCOL_DNS
,
1245 .refuse_compression
= true,
1246 .canonical_form
= canonical
,
1254 /* Generates the RR in wire-format, optionally in the
1255 * canonical form as discussed in the DNSSEC RFC 4034, Section
1256 * 6.2. We allocate a throw-away DnsPacket object on the stack
1257 * here, because we need some book-keeping for memory
1258 * management, and can reuse the DnsPacket serializer, that
1259 * can generate the canonical form, too, but also knows label
1260 * compression and suchlike. */
1262 if (rr
->wire_format
&& rr
->wire_format_canonical
== canonical
)
1265 r
= dns_packet_append_rr(&packet
, rr
, 0, &start
, &rds
);
1270 assert(packet
._data
);
1272 free(rr
->wire_format
);
1273 rr
->wire_format
= packet
._data
;
1274 rr
->wire_format_size
= packet
.size
;
1275 rr
->wire_format_rdata_offset
= rds
;
1276 rr
->wire_format_canonical
= canonical
;
1278 packet
._data
= NULL
;
1279 dns_packet_unref(&packet
);
1284 int dns_resource_record_signer(DnsResourceRecord
*rr
, const char **ret
) {
1291 /* Returns the RRset's signer, if it is known. */
1293 if (rr
->n_skip_labels_signer
== (unsigned) -1)
1296 n
= dns_resource_key_name(rr
->key
);
1297 r
= dns_name_skip(n
, rr
->n_skip_labels_signer
, &n
);
1307 int dns_resource_record_source(DnsResourceRecord
*rr
, const char **ret
) {
1314 /* Returns the RRset's synthesizing source, if it is known. */
1316 if (rr
->n_skip_labels_source
== (unsigned) -1)
1319 n
= dns_resource_key_name(rr
->key
);
1320 r
= dns_name_skip(n
, rr
->n_skip_labels_source
, &n
);
1330 int dns_resource_record_is_signer(DnsResourceRecord
*rr
, const char *zone
) {
1336 r
= dns_resource_record_signer(rr
, &signer
);
1340 return dns_name_equal(zone
, signer
);
1343 int dns_resource_record_is_synthetic(DnsResourceRecord
*rr
) {
1348 /* Returns > 0 if the RR is generated from a wildcard, and is not the asterisk name itself */
1350 if (rr
->n_skip_labels_source
== (unsigned) -1)
1353 if (rr
->n_skip_labels_source
== 0)
1356 if (rr
->n_skip_labels_source
> 1)
1359 r
= dns_name_startswith(dns_resource_key_name(rr
->key
), "*");
1366 void dns_resource_record_hash_func(const void *i
, struct siphash
*state
) {
1367 const DnsResourceRecord
*rr
= i
;
1371 dns_resource_key_hash_func(rr
->key
, state
);
1373 switch (rr
->unparseable
? _DNS_TYPE_INVALID
: rr
->key
->type
) {
1376 siphash24_compress(&rr
->srv
.priority
, sizeof(rr
->srv
.priority
), state
);
1377 siphash24_compress(&rr
->srv
.weight
, sizeof(rr
->srv
.weight
), state
);
1378 siphash24_compress(&rr
->srv
.port
, sizeof(rr
->srv
.port
), state
);
1379 dns_name_hash_func(rr
->srv
.name
, state
);
1384 case DNS_TYPE_CNAME
:
1385 case DNS_TYPE_DNAME
:
1386 dns_name_hash_func(rr
->ptr
.name
, state
);
1389 case DNS_TYPE_HINFO
:
1390 string_hash_func(rr
->hinfo
.cpu
, state
);
1391 string_hash_func(rr
->hinfo
.os
, state
);
1395 case DNS_TYPE_SPF
: {
1398 LIST_FOREACH(items
, j
, rr
->txt
.items
) {
1399 siphash24_compress(j
->data
, j
->length
, state
);
1401 /* Add an extra NUL byte, so that "a" followed by "b" doesn't result in the same hash as "ab"
1402 * followed by "". */
1403 siphash24_compress_byte(0, state
);
1409 siphash24_compress(&rr
->a
.in_addr
, sizeof(rr
->a
.in_addr
), state
);
1413 siphash24_compress(&rr
->aaaa
.in6_addr
, sizeof(rr
->aaaa
.in6_addr
), state
);
1417 dns_name_hash_func(rr
->soa
.mname
, state
);
1418 dns_name_hash_func(rr
->soa
.rname
, state
);
1419 siphash24_compress(&rr
->soa
.serial
, sizeof(rr
->soa
.serial
), state
);
1420 siphash24_compress(&rr
->soa
.refresh
, sizeof(rr
->soa
.refresh
), state
);
1421 siphash24_compress(&rr
->soa
.retry
, sizeof(rr
->soa
.retry
), state
);
1422 siphash24_compress(&rr
->soa
.expire
, sizeof(rr
->soa
.expire
), state
);
1423 siphash24_compress(&rr
->soa
.minimum
, sizeof(rr
->soa
.minimum
), state
);
1427 siphash24_compress(&rr
->mx
.priority
, sizeof(rr
->mx
.priority
), state
);
1428 dns_name_hash_func(rr
->mx
.exchange
, state
);
1432 siphash24_compress(&rr
->loc
.version
, sizeof(rr
->loc
.version
), state
);
1433 siphash24_compress(&rr
->loc
.size
, sizeof(rr
->loc
.size
), state
);
1434 siphash24_compress(&rr
->loc
.horiz_pre
, sizeof(rr
->loc
.horiz_pre
), state
);
1435 siphash24_compress(&rr
->loc
.vert_pre
, sizeof(rr
->loc
.vert_pre
), state
);
1436 siphash24_compress(&rr
->loc
.latitude
, sizeof(rr
->loc
.latitude
), state
);
1437 siphash24_compress(&rr
->loc
.longitude
, sizeof(rr
->loc
.longitude
), state
);
1438 siphash24_compress(&rr
->loc
.altitude
, sizeof(rr
->loc
.altitude
), state
);
1441 case DNS_TYPE_SSHFP
:
1442 siphash24_compress(&rr
->sshfp
.algorithm
, sizeof(rr
->sshfp
.algorithm
), state
);
1443 siphash24_compress(&rr
->sshfp
.fptype
, sizeof(rr
->sshfp
.fptype
), state
);
1444 siphash24_compress(rr
->sshfp
.fingerprint
, rr
->sshfp
.fingerprint_size
, state
);
1447 case DNS_TYPE_DNSKEY
:
1448 siphash24_compress(&rr
->dnskey
.flags
, sizeof(rr
->dnskey
.flags
), state
);
1449 siphash24_compress(&rr
->dnskey
.protocol
, sizeof(rr
->dnskey
.protocol
), state
);
1450 siphash24_compress(&rr
->dnskey
.algorithm
, sizeof(rr
->dnskey
.algorithm
), state
);
1451 siphash24_compress(rr
->dnskey
.key
, rr
->dnskey
.key_size
, state
);
1454 case DNS_TYPE_RRSIG
:
1455 siphash24_compress(&rr
->rrsig
.type_covered
, sizeof(rr
->rrsig
.type_covered
), state
);
1456 siphash24_compress(&rr
->rrsig
.algorithm
, sizeof(rr
->rrsig
.algorithm
), state
);
1457 siphash24_compress(&rr
->rrsig
.labels
, sizeof(rr
->rrsig
.labels
), state
);
1458 siphash24_compress(&rr
->rrsig
.original_ttl
, sizeof(rr
->rrsig
.original_ttl
), state
);
1459 siphash24_compress(&rr
->rrsig
.expiration
, sizeof(rr
->rrsig
.expiration
), state
);
1460 siphash24_compress(&rr
->rrsig
.inception
, sizeof(rr
->rrsig
.inception
), state
);
1461 siphash24_compress(&rr
->rrsig
.key_tag
, sizeof(rr
->rrsig
.key_tag
), state
);
1462 dns_name_hash_func(rr
->rrsig
.signer
, state
);
1463 siphash24_compress(rr
->rrsig
.signature
, rr
->rrsig
.signature_size
, state
);
1467 dns_name_hash_func(rr
->nsec
.next_domain_name
, state
);
1468 /* FIXME: we leave out the type bitmap here. Hash
1469 * would be better if we'd take it into account
1474 siphash24_compress(&rr
->ds
.key_tag
, sizeof(rr
->ds
.key_tag
), state
);
1475 siphash24_compress(&rr
->ds
.algorithm
, sizeof(rr
->ds
.algorithm
), state
);
1476 siphash24_compress(&rr
->ds
.digest_type
, sizeof(rr
->ds
.digest_type
), state
);
1477 siphash24_compress(rr
->ds
.digest
, rr
->ds
.digest_size
, state
);
1480 case DNS_TYPE_NSEC3
:
1481 siphash24_compress(&rr
->nsec3
.algorithm
, sizeof(rr
->nsec3
.algorithm
), state
);
1482 siphash24_compress(&rr
->nsec3
.flags
, sizeof(rr
->nsec3
.flags
), state
);
1483 siphash24_compress(&rr
->nsec3
.iterations
, sizeof(rr
->nsec3
.iterations
), state
);
1484 siphash24_compress(rr
->nsec3
.salt
, rr
->nsec3
.salt_size
, state
);
1485 siphash24_compress(rr
->nsec3
.next_hashed_name
, rr
->nsec3
.next_hashed_name_size
, state
);
1486 /* FIXME: We leave the bitmaps out */
1490 siphash24_compress(&rr
->tlsa
.cert_usage
, sizeof(rr
->tlsa
.cert_usage
), state
);
1491 siphash24_compress(&rr
->tlsa
.selector
, sizeof(rr
->tlsa
.selector
), state
);
1492 siphash24_compress(&rr
->tlsa
.matching_type
, sizeof(rr
->tlsa
.matching_type
), state
);
1493 siphash24_compress(rr
->tlsa
.data
, rr
->tlsa
.data_size
, state
);
1497 siphash24_compress(&rr
->caa
.flags
, sizeof(rr
->caa
.flags
), state
);
1498 string_hash_func(rr
->caa
.tag
, state
);
1499 siphash24_compress(rr
->caa
.value
, rr
->caa
.value_size
, state
);
1502 case DNS_TYPE_OPENPGPKEY
:
1504 siphash24_compress(rr
->generic
.data
, rr
->generic
.data_size
, state
);
1509 static int dns_resource_record_compare_func(const void *a
, const void *b
) {
1510 const DnsResourceRecord
*x
= a
, *y
= b
;
1513 ret
= dns_resource_key_compare_func(x
->key
, y
->key
);
1517 if (dns_resource_record_equal(x
, y
))
1520 /* This is a bit dirty, we don't implement proper ordering, but
1521 * the hashtable doesn't need ordering anyway, hence we don't
1523 return x
< y
? -1 : 1;
1526 const struct hash_ops dns_resource_record_hash_ops
= {
1527 .hash
= dns_resource_record_hash_func
,
1528 .compare
= dns_resource_record_compare_func
,
1531 DnsResourceRecord
*dns_resource_record_copy(DnsResourceRecord
*rr
) {
1532 _cleanup_(dns_resource_record_unrefp
) DnsResourceRecord
*copy
= NULL
;
1533 DnsResourceRecord
*t
;
1537 copy
= dns_resource_record_new(rr
->key
);
1541 copy
->ttl
= rr
->ttl
;
1542 copy
->expiry
= rr
->expiry
;
1543 copy
->n_skip_labels_signer
= rr
->n_skip_labels_signer
;
1544 copy
->n_skip_labels_source
= rr
->n_skip_labels_source
;
1545 copy
->unparseable
= rr
->unparseable
;
1547 switch (rr
->unparseable
? _DNS_TYPE_INVALID
: rr
->key
->type
) {
1550 copy
->srv
.priority
= rr
->srv
.priority
;
1551 copy
->srv
.weight
= rr
->srv
.weight
;
1552 copy
->srv
.port
= rr
->srv
.port
;
1553 copy
->srv
.name
= strdup(rr
->srv
.name
);
1554 if (!copy
->srv
.name
)
1560 case DNS_TYPE_CNAME
:
1561 case DNS_TYPE_DNAME
:
1562 copy
->ptr
.name
= strdup(rr
->ptr
.name
);
1563 if (!copy
->ptr
.name
)
1567 case DNS_TYPE_HINFO
:
1568 copy
->hinfo
.cpu
= strdup(rr
->hinfo
.cpu
);
1569 if (!copy
->hinfo
.cpu
)
1572 copy
->hinfo
.os
= strdup(rr
->hinfo
.os
);
1579 copy
->txt
.items
= dns_txt_item_copy(rr
->txt
.items
);
1580 if (!copy
->txt
.items
)
1589 copy
->aaaa
= rr
->aaaa
;
1593 copy
->soa
.mname
= strdup(rr
->soa
.mname
);
1594 if (!copy
->soa
.mname
)
1596 copy
->soa
.rname
= strdup(rr
->soa
.rname
);
1597 if (!copy
->soa
.rname
)
1599 copy
->soa
.serial
= rr
->soa
.serial
;
1600 copy
->soa
.refresh
= rr
->soa
.refresh
;
1601 copy
->soa
.retry
= rr
->soa
.retry
;
1602 copy
->soa
.expire
= rr
->soa
.expire
;
1603 copy
->soa
.minimum
= rr
->soa
.minimum
;
1607 copy
->mx
.priority
= rr
->mx
.priority
;
1608 copy
->mx
.exchange
= strdup(rr
->mx
.exchange
);
1609 if (!copy
->mx
.exchange
)
1614 copy
->loc
= rr
->loc
;
1617 case DNS_TYPE_SSHFP
:
1618 copy
->sshfp
.algorithm
= rr
->sshfp
.algorithm
;
1619 copy
->sshfp
.fptype
= rr
->sshfp
.fptype
;
1620 copy
->sshfp
.fingerprint
= memdup(rr
->sshfp
.fingerprint
, rr
->sshfp
.fingerprint_size
);
1621 if (!copy
->sshfp
.fingerprint
)
1623 copy
->sshfp
.fingerprint_size
= rr
->sshfp
.fingerprint_size
;
1626 case DNS_TYPE_DNSKEY
:
1627 copy
->dnskey
.flags
= rr
->dnskey
.flags
;
1628 copy
->dnskey
.protocol
= rr
->dnskey
.protocol
;
1629 copy
->dnskey
.algorithm
= rr
->dnskey
.algorithm
;
1630 copy
->dnskey
.key
= memdup(rr
->dnskey
.key
, rr
->dnskey
.key_size
);
1631 if (!copy
->dnskey
.key
)
1633 copy
->dnskey
.key_size
= rr
->dnskey
.key_size
;
1636 case DNS_TYPE_RRSIG
:
1637 copy
->rrsig
.type_covered
= rr
->rrsig
.type_covered
;
1638 copy
->rrsig
.algorithm
= rr
->rrsig
.algorithm
;
1639 copy
->rrsig
.labels
= rr
->rrsig
.labels
;
1640 copy
->rrsig
.original_ttl
= rr
->rrsig
.original_ttl
;
1641 copy
->rrsig
.expiration
= rr
->rrsig
.expiration
;
1642 copy
->rrsig
.inception
= rr
->rrsig
.inception
;
1643 copy
->rrsig
.key_tag
= rr
->rrsig
.key_tag
;
1644 copy
->rrsig
.signer
= strdup(rr
->rrsig
.signer
);
1645 if (!copy
->rrsig
.signer
)
1647 copy
->rrsig
.signature
= memdup(rr
->rrsig
.signature
, rr
->rrsig
.signature_size
);
1648 if (!copy
->rrsig
.signature
)
1650 copy
->rrsig
.signature_size
= rr
->rrsig
.signature_size
;
1654 copy
->nsec
.next_domain_name
= strdup(rr
->nsec
.next_domain_name
);
1655 if (!copy
->nsec
.next_domain_name
)
1657 copy
->nsec
.types
= bitmap_copy(rr
->nsec
.types
);
1658 if (!copy
->nsec
.types
)
1663 copy
->ds
.key_tag
= rr
->ds
.key_tag
;
1664 copy
->ds
.algorithm
= rr
->ds
.algorithm
;
1665 copy
->ds
.digest_type
= rr
->ds
.digest_type
;
1666 copy
->ds
.digest
= memdup(rr
->ds
.digest
, rr
->ds
.digest_size
);
1667 if (!copy
->ds
.digest
)
1669 copy
->ds
.digest_size
= rr
->ds
.digest_size
;
1672 case DNS_TYPE_NSEC3
:
1673 copy
->nsec3
.algorithm
= rr
->nsec3
.algorithm
;
1674 copy
->nsec3
.flags
= rr
->nsec3
.flags
;
1675 copy
->nsec3
.iterations
= rr
->nsec3
.iterations
;
1676 copy
->nsec3
.salt
= memdup(rr
->nsec3
.salt
, rr
->nsec3
.salt_size
);
1677 if (!copy
->nsec3
.salt
)
1679 copy
->nsec3
.salt_size
= rr
->nsec3
.salt_size
;
1680 copy
->nsec3
.next_hashed_name
= memdup(rr
->nsec3
.next_hashed_name
, rr
->nsec3
.next_hashed_name_size
);
1681 if (!copy
->nsec3
.next_hashed_name_size
)
1683 copy
->nsec3
.next_hashed_name_size
= rr
->nsec3
.next_hashed_name_size
;
1684 copy
->nsec3
.types
= bitmap_copy(rr
->nsec3
.types
);
1685 if (!copy
->nsec3
.types
)
1690 copy
->tlsa
.cert_usage
= rr
->tlsa
.cert_usage
;
1691 copy
->tlsa
.selector
= rr
->tlsa
.selector
;
1692 copy
->tlsa
.matching_type
= rr
->tlsa
.matching_type
;
1693 copy
->tlsa
.data
= memdup(rr
->tlsa
.data
, rr
->tlsa
.data_size
);
1694 if (!copy
->tlsa
.data
)
1696 copy
->tlsa
.data_size
= rr
->tlsa
.data_size
;
1700 copy
->caa
.flags
= rr
->caa
.flags
;
1701 copy
->caa
.tag
= strdup(rr
->caa
.tag
);
1704 copy
->caa
.value
= memdup(rr
->caa
.value
, rr
->caa
.value_size
);
1705 if (!copy
->caa
.value
)
1707 copy
->caa
.value_size
= rr
->caa
.value_size
;
1712 copy
->generic
.data
= memdup(rr
->generic
.data
, rr
->generic
.data_size
);
1713 if (!copy
->generic
.data
)
1715 copy
->generic
.data_size
= rr
->generic
.data_size
;
1725 int dns_resource_record_clamp_ttl(DnsResourceRecord
**rr
, uint32_t max_ttl
) {
1726 DnsResourceRecord
*old_rr
, *new_rr
;
1732 if (old_rr
->key
->type
== DNS_TYPE_OPT
)
1735 new_ttl
= MIN(old_rr
->ttl
, max_ttl
);
1736 if (new_ttl
== old_rr
->ttl
)
1739 if (old_rr
->n_ref
== 1) {
1740 /* Patch in place */
1741 old_rr
->ttl
= new_ttl
;
1745 new_rr
= dns_resource_record_copy(old_rr
);
1749 new_rr
->ttl
= new_ttl
;
1751 dns_resource_record_unref(*rr
);
1757 DnsTxtItem
*dns_txt_item_free_all(DnsTxtItem
*i
) {
1766 return dns_txt_item_free_all(n
);
1769 bool dns_txt_item_equal(DnsTxtItem
*a
, DnsTxtItem
*b
) {
1780 if (a
->length
!= b
->length
)
1783 if (memcmp(a
->data
, b
->data
, a
->length
) != 0)
1786 return dns_txt_item_equal(a
->items_next
, b
->items_next
);
1789 DnsTxtItem
*dns_txt_item_copy(DnsTxtItem
*first
) {
1790 DnsTxtItem
*i
, *copy
= NULL
, *end
= NULL
;
1792 LIST_FOREACH(items
, i
, first
) {
1795 j
= memdup(i
, offsetof(DnsTxtItem
, data
) + i
->length
+ 1);
1797 dns_txt_item_free_all(copy
);
1801 LIST_INSERT_AFTER(items
, copy
, end
, j
);
1808 static const char* const dnssec_algorithm_table
[_DNSSEC_ALGORITHM_MAX_DEFINED
] = {
1809 /* Mnemonics as listed on https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml */
1810 [DNSSEC_ALGORITHM_RSAMD5
] = "RSAMD5",
1811 [DNSSEC_ALGORITHM_DH
] = "DH",
1812 [DNSSEC_ALGORITHM_DSA
] = "DSA",
1813 [DNSSEC_ALGORITHM_ECC
] = "ECC",
1814 [DNSSEC_ALGORITHM_RSASHA1
] = "RSASHA1",
1815 [DNSSEC_ALGORITHM_DSA_NSEC3_SHA1
] = "DSA-NSEC3-SHA1",
1816 [DNSSEC_ALGORITHM_RSASHA1_NSEC3_SHA1
] = "RSASHA1-NSEC3-SHA1",
1817 [DNSSEC_ALGORITHM_RSASHA256
] = "RSASHA256",
1818 [DNSSEC_ALGORITHM_RSASHA512
] = "RSASHA512",
1819 [DNSSEC_ALGORITHM_ECC_GOST
] = "ECC-GOST",
1820 [DNSSEC_ALGORITHM_ECDSAP256SHA256
] = "ECDSAP256SHA256",
1821 [DNSSEC_ALGORITHM_ECDSAP384SHA384
] = "ECDSAP384SHA384",
1822 [DNSSEC_ALGORITHM_INDIRECT
] = "INDIRECT",
1823 [DNSSEC_ALGORITHM_PRIVATEDNS
] = "PRIVATEDNS",
1824 [DNSSEC_ALGORITHM_PRIVATEOID
] = "PRIVATEOID",
1826 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(dnssec_algorithm
, int, 255);
1828 static const char* const dnssec_digest_table
[_DNSSEC_DIGEST_MAX_DEFINED
] = {
1829 /* Names as listed on https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml */
1830 [DNSSEC_DIGEST_SHA1
] = "SHA-1",
1831 [DNSSEC_DIGEST_SHA256
] = "SHA-256",
1832 [DNSSEC_DIGEST_GOST_R_34_11_94
] = "GOST_R_34.11-94",
1833 [DNSSEC_DIGEST_SHA384
] = "SHA-384",
1835 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(dnssec_digest
, int, 255);