]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/dns-type.c
058d14009abff7310ca2e35f7c8e81c7cebcd674
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Zbigniew Jędrzejewski-Szmek
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include "string-util.h"
25 typedef const struct {
30 static const struct dns_type_name
*
31 lookup_dns_type (register const char *str
, register unsigned int len
);
33 #include "dns_type-from-name.h"
34 #include "dns_type-to-name.h"
36 int dns_type_from_string(const char *s
) {
37 const struct dns_type_name
*sc
;
41 sc
= lookup_dns_type(s
, strlen(s
));
43 return _DNS_TYPE_INVALID
;
48 bool dns_type_is_pseudo(uint16_t type
) {
50 /* Checks whether the specified type is a "pseudo-type". What
51 * a "pseudo-type" precisely is, is defined only very weakly,
52 * but apparently entails all RR types that are not actually
53 * stored as RRs on the server and should hence also not be
54 * cached. We use this list primarily to validate NSEC type
55 * bitfields, and to verify what to cache. */
58 0, /* A Pseudo RR type, according to RFC 2931 */
68 bool dns_class_is_pseudo(uint16_t class) {
69 return class == DNS_TYPE_ANY
;
72 bool dns_type_is_valid_query(uint16_t type
) {
74 /* The types valid as questions in packets */
82 /* RRSIG are technically valid as questions, but we refuse doing explicit queries for them, as
83 * they aren't really payload, but signatures for payload, and cannot be validated on their
84 * own. After all they are the signatures, and have no signatures of their own validating
89 bool dns_type_is_valid_rr(uint16_t type
) {
91 /* The types valid as RR in packets (but not necessarily
92 * stored on servers). */
100 bool dns_class_is_valid_rr(uint16_t class) {
101 return class != DNS_CLASS_ANY
;
104 bool dns_type_may_redirect(uint16_t type
) {
105 /* The following record types should never be redirected using
106 * CNAME/DNAME RRs. See
107 * <https://tools.ietf.org/html/rfc4035#section-2.5>. */
109 if (dns_type_is_pseudo(type
))
123 bool dns_type_may_wildcard(uint16_t type
) {
125 /* The following records may not be expanded from wildcard RRsets */
127 if (dns_type_is_pseudo(type
))
134 /* Prohibited by https://tools.ietf.org/html/rfc4592#section-4.4 */
138 bool dns_type_apex_only(uint16_t type
) {
140 /* Returns true for all RR types that may only appear signed in a zone apex */
144 DNS_TYPE_NS
, /* this one can appear elsewhere, too, but not signed */
146 DNS_TYPE_NSEC3PARAM
);
149 bool dns_type_is_dnssec(uint16_t type
) {
156 DNS_TYPE_NSEC3PARAM
);
159 bool dns_type_is_obsolete(uint16_t type
) {
161 /* Obsoleted by RFC 973 */
166 /* Kinda obsoleted by RFC 2505 */
173 /* RFC1127 kinda obsoleted this by recommending against its use */
176 /* Declared historical by RFC 6563 */
179 /* Obsoleted by DNSSEC-bis */
182 /* RFC 1035 removed support for concepts that needed this from RFC 883 */
186 const char *dns_class_to_string(uint16_t class) {
200 int dns_class_from_string(const char *s
) {
203 return _DNS_CLASS_INVALID
;
205 if (strcaseeq(s
, "IN"))
207 else if (strcaseeq(s
, "ANY"))
208 return DNS_CLASS_ANY
;
210 return _DNS_CLASS_INVALID
;