]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/dns-type.c
resolved: cache stringified transaction key once per transaction
[thirdparty/systemd.git] / src / resolve / dns-type.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2014 Zbigniew Jędrzejewski-Szmek
7
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.
12
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.
17
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/>.
20 ***/
21
22 #include "dns-type.h"
23
24 typedef const struct {
25 uint16_t type;
26 const char *name;
27 } dns_type;
28
29 static const struct dns_type_name *
30 lookup_dns_type (register const char *str, register unsigned int len);
31
32 #include "dns_type-from-name.h"
33 #include "dns_type-to-name.h"
34
35 int dns_type_from_string(const char *s) {
36 const struct dns_type_name *sc;
37
38 assert(s);
39
40 sc = lookup_dns_type(s, strlen(s));
41 if (!sc)
42 return _DNS_TYPE_INVALID;
43
44 return sc->id;
45 }
46
47 bool dns_type_is_pseudo(uint16_t type) {
48
49 /* Checks whether the specified type is a "pseudo-type". What
50 * a "pseudo-type" precisely is, is defined only very weakly,
51 * but apparently entails all RR types that are not actually
52 * stored as RRs on the server and should hence also not be
53 * cached. We use this list primarily to validate NSEC type
54 * bitfields, and to verify what to cache. */
55
56 return IN_SET(type,
57 0, /* A Pseudo RR type, according to RFC 2931 */
58 DNS_TYPE_ANY,
59 DNS_TYPE_AXFR,
60 DNS_TYPE_IXFR,
61 DNS_TYPE_OPT,
62 DNS_TYPE_TSIG,
63 DNS_TYPE_TKEY
64 );
65 }
66
67 bool dns_type_is_valid_query(uint16_t type) {
68
69 /* The types valid as questions in packets */
70
71 return !IN_SET(type,
72 0,
73 DNS_TYPE_OPT,
74 DNS_TYPE_TSIG,
75 DNS_TYPE_TKEY);
76 }
77
78 bool dns_type_is_valid_rr(uint16_t type) {
79
80 /* The types valid as RR in packets (but not necessarily
81 * stored on servers). */
82
83 return !IN_SET(type,
84 DNS_TYPE_ANY,
85 DNS_TYPE_AXFR,
86 DNS_TYPE_IXFR);
87 }