]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/dns-type.c
resolved: cache stringified transaction key once per transaction
[thirdparty/systemd.git] / src / resolve / dns-type.c
CommitLineData
7263f724
ZJS
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
24typedef const struct {
25 uint16_t type;
26 const char *name;
27} dns_type;
28
29static const struct dns_type_name *
30lookup_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
de292aa1 35int dns_type_from_string(const char *s) {
7263f724
ZJS
36 const struct dns_type_name *sc;
37
38 assert(s);
7263f724
ZJS
39
40 sc = lookup_dns_type(s, strlen(s));
41 if (!sc)
de292aa1 42 return _DNS_TYPE_INVALID;
7263f724 43
de292aa1 44 return sc->id;
7263f724 45}
8e6edc49 46
bea4c76f
LP
47bool 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
c33be4a6 54 * bitfields, and to verify what to cache. */
bea4c76f
LP
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 );
8e6edc49 65}
c463eb78
LP
66
67bool 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
78bool 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}