1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include <sys/socket.h>
7 #include "parse-util.h"
8 #include "string-util.h"
10 typedef const struct {
15 static const struct dns_type_name
*
16 lookup_dns_type (register const char *str
, register GPERF_LEN_TYPE len
);
18 #include "dns_type-from-name.h"
19 #include "dns_type-to-name.h"
21 int dns_type_from_string(const char *s
) {
22 const struct dns_type_name
*sc
;
26 sc
= lookup_dns_type(s
, strlen(s
));
30 s
= startswith_no_case(s
, "TYPE");
34 if (safe_atou(s
, &x
) >= 0 &&
39 return _DNS_TYPE_INVALID
;
42 bool dns_type_is_pseudo(uint16_t type
) {
44 /* Checks whether the specified type is a "pseudo-type". What
45 * a "pseudo-type" precisely is, is defined only very weakly,
46 * but apparently entails all RR types that are not actually
47 * stored as RRs on the server and should hence also not be
48 * cached. We use this list primarily to validate NSEC type
49 * bitfields, and to verify what to cache. */
52 0, /* A Pseudo RR type, according to RFC 2931 */
62 bool dns_class_is_pseudo(uint16_t class) {
63 return class == DNS_CLASS_ANY
;
66 bool dns_type_is_valid_query(uint16_t type
) {
68 /* The types valid as questions in packets */
76 /* RRSIG are technically valid as questions, but we refuse doing explicit queries for them, as
77 * they aren't really payload, but signatures for payload, and cannot be validated on their
78 * own. After all they are the signatures, and have no signatures of their own validating
83 bool dns_type_is_zone_transer(uint16_t type
) {
85 /* Zone transfers, either normal or incremental */
92 bool dns_type_is_valid_rr(uint16_t type
) {
94 /* The types valid as RR in packets (but not necessarily
95 * stored on servers). */
103 bool dns_class_is_valid_rr(uint16_t class) {
104 return class != DNS_CLASS_ANY
;
107 bool dns_type_may_redirect(uint16_t type
) {
108 /* The following record types should never be redirected using
109 * CNAME/DNAME RRs. See
110 * <https://tools.ietf.org/html/rfc4035#section-2.5>. */
112 if (dns_type_is_pseudo(type
))
126 bool dns_type_may_wildcard(uint16_t type
) {
128 /* The following records may not be expanded from wildcard RRsets */
130 if (dns_type_is_pseudo(type
))
137 /* Prohibited by https://tools.ietf.org/html/rfc4592#section-4.4 */
141 bool dns_type_apex_only(uint16_t type
) {
143 /* Returns true for all RR types that may only appear signed in a zone apex */
147 DNS_TYPE_NS
, /* this one can appear elsewhere, too, but not signed */
149 DNS_TYPE_NSEC3PARAM
);
152 bool dns_type_is_dnssec(uint16_t type
) {
159 DNS_TYPE_NSEC3PARAM
);
162 bool dns_type_is_obsolete(uint16_t type
) {
164 /* Obsoleted by RFC 973 */
169 /* Kinda obsoleted by RFC 2505 */
176 /* RFC1127 kinda obsoleted this by recommending against its use */
179 /* Declared historical by RFC 6563 */
182 /* Obsoleted by DNSSEC-bis */
185 /* RFC 1035 removed support for concepts that needed this from RFC 883 */
189 bool dns_type_needs_authentication(uint16_t type
) {
191 /* Returns true for all (non-obsolete) RR types where records are not useful if they aren't
192 * authenticated. I.e. everything that contains crypto keys. */
206 int dns_type_to_af(uint16_t t
) {
223 const char *dns_class_to_string(uint16_t class) {
237 int dns_class_from_string(const char *s
) {
240 return _DNS_CLASS_INVALID
;
242 if (strcaseeq(s
, "IN"))
244 else if (strcaseeq(s
, "ANY"))
245 return DNS_CLASS_ANY
;
247 return _DNS_CLASS_INVALID
;
250 const char* tlsa_cert_usage_to_string(uint8_t cert_usage
) {
252 switch (cert_usage
) {
255 return "CA constraint";
258 return "Service certificate constraint";
261 return "Trust anchor assertion";
264 return "Domain-issued certificate";
270 return "Private use";
273 return NULL
; /* clang cannot count that we covered everything */
276 const char* tlsa_selector_to_string(uint8_t selector
) {
280 return "Full Certificate";
283 return "SubjectPublicKeyInfo";
289 return "Private use";
295 const char* tlsa_matching_type_to_string(uint8_t selector
) {
300 return "No hash used";
312 return "Private use";