summaryrefslogtreecommitdiff
path: root/src/resolve
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-08-01 19:37:16 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-08-03 22:02:32 -0400
commit7263f72499e962b3fd54cdb7c79d49ca72121ede (patch)
treed74d2593c003166d21f38945c244b6d5a1180982 /src/resolve
parentfd00a088216f6d6a6c502faf6b46c1e2ae7cbc54 (diff)
resolve: add more record types and convert to gperf table
We are unlikely to evert support most of them, but we can at least display the types properly. The list is taken from the IANA list. The table of number->name mappings is converted to a switch statement. gcc does a nice job of optimizing lookup (when optimization is enabled). systemd-resolve-host -t is now case insensitive.
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/.gitignore4
-rw-r--r--src/resolve/dns-type.c47
-rw-r--r--src/resolve/dns-type.h122
-rw-r--r--src/resolve/resolved-dns-rr.c52
-rw-r--r--src/resolve/resolved-dns-rr.h33
5 files changed, 175 insertions, 83 deletions
diff --git a/src/resolve/.gitignore b/src/resolve/.gitignore
index ca3016e6a3..f0835923b7 100644
--- a/src/resolve/.gitignore
+++ b/src/resolve/.gitignore
@@ -1,2 +1,6 @@
/resolved-gperf.c
/resolved.conf
+/dns_type-from-name.gperf
+/dns_type-from-name.h
+/dns_type-list.txt
+/dns_type-to-name.h
diff --git a/src/resolve/dns-type.c b/src/resolve/dns-type.c
new file mode 100644
index 0000000000..271a7e176b
--- /dev/null
+++ b/src/resolve/dns-type.c
@@ -0,0 +1,47 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Zbigniew Jędrzejewski-Szmek
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "dns-type.h"
+
+typedef const struct {
+ uint16_t type;
+ const char *name;
+} dns_type;
+
+static const struct dns_type_name *
+lookup_dns_type (register const char *str, register unsigned int len);
+
+#include "dns_type-from-name.h"
+#include "dns_type-to-name.h"
+
+int dns_type_from_string(const char *s, uint16_t *type) {
+ const struct dns_type_name *sc;
+
+ assert(s);
+ assert(type);
+
+ sc = lookup_dns_type(s, strlen(s));
+ if (!sc)
+ return -EINVAL;
+
+ *type = sc->id;
+ return 0;
+}
diff --git a/src/resolve/dns-type.h b/src/resolve/dns-type.h
new file mode 100644
index 0000000000..66063153a0
--- /dev/null
+++ b/src/resolve/dns-type.h
@@ -0,0 +1,122 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Zbigniew Jędrzejewski-Szmek
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#pragma once
+
+#include <inttypes.h>
+
+#include "macro.h"
+
+const char *dns_type_to_string(uint16_t type);
+int dns_type_from_string(const char *s, uint16_t *type);
+
+/* DNS record types, taken from
+ * http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml.
+ */
+enum {
+ /* Normal records */
+ DNS_TYPE_A = 0x01,
+ DNS_TYPE_NS,
+ DNS_TYPE_MD,
+ DNS_TYPE_MF,
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TYPE_EUI64,
+
+ DNS_TYPE_TKEY = 0xF9,
+ DNS_TYPE_TSIG,
+ DNS_TYPE_IXFR,
+ DNS_TYPE_AXFR,
+ DNS_TYPE_MAILB,
+ DNS_TYPE_MAILA,
+ DNS_TYPE_ANY,
+ DNS_TYPE_URI,
+ DNS_TYPE_CAA,
+ DNS_TYPE_TA = 0x8000,
+ DNS_TYPE_DLV,
+
+ _DNS_TYPE_MAX,
+ _DNS_TYPE_INVALID = -1
+};
+
+assert_cc(DNS_TYPE_SSHFP == 44);
+assert_cc(DNS_TYPE_TLSA == 52);
+assert_cc(DNS_TYPE_ANY == 255);
diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c
index 7d1cfe4aae..af22a8901d 100644
--- a/src/resolve/resolved-dns-rr.c
+++ b/src/resolve/resolved-dns-rr.c
@@ -25,6 +25,7 @@
#include "resolved-dns-domain.h"
#include "resolved-dns-rr.h"
+#include "dns-type.h"
DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name) {
DnsResourceKey *k;
@@ -627,54 +628,3 @@ int dns_class_from_string(const char *s, uint16_t *class) {
return 0;
}
-
-static const struct {
- uint16_t type;
- const char *name;
-} dns_types[] = {
- { DNS_TYPE_A, "A" },
- { DNS_TYPE_NS, "NS" },
- { DNS_TYPE_CNAME, "CNAME" },
- { DNS_TYPE_SOA, "SOA" },
- { DNS_TYPE_PTR, "PTR" },
- { DNS_TYPE_HINFO, "HINFO" },
- { DNS_TYPE_MX, "MX" },
- { DNS_TYPE_TXT, "TXT" },
- { DNS_TYPE_AAAA, "AAAA" },
- { DNS_TYPE_LOC, "LOC" },
- { DNS_TYPE_SRV, "SRV" },
- { DNS_TYPE_SSHFP, "SSHFP" },
- { DNS_TYPE_SPF, "SPF" },
- { DNS_TYPE_DNAME, "DNAME" },
- { DNS_TYPE_ANY, "ANY" },
- { DNS_TYPE_OPT, "OPT" },
- { DNS_TYPE_TKEY, "TKEY" },
- { DNS_TYPE_TSIG, "TSIG" },
- { DNS_TYPE_IXFR, "IXFR" },
- { DNS_TYPE_AXFR, "AXFR" },
-};
-
-const char *dns_type_to_string(uint16_t type) {
- unsigned i;
-
- for (i = 0; i < ELEMENTSOF(dns_types); i++)
- if (dns_types[i].type == type)
- return dns_types[i].name;
-
- return NULL;
-}
-
-int dns_type_from_string(const char *s, uint16_t *type) {
- unsigned i;
-
- assert(s);
- assert(type);
-
- for (i = 0; i < ELEMENTSOF(dns_types); i++)
- if (strcaseeq(dns_types[i].name, s)) {
- *type = dns_types[i].type;
- return 0;
- }
-
- return -EINVAL;
-}
diff --git a/src/resolve/resolved-dns-rr.h b/src/resolve/resolved-dns-rr.h
index 61c00d59b2..20a344b8ca 100644
--- a/src/resolve/resolved-dns-rr.h
+++ b/src/resolve/resolved-dns-rr.h
@@ -27,6 +27,7 @@
#include "util.h"
#include "hashmap.h"
#include "in-addr-util.h"
+#include "dns-type.h"
typedef struct DnsResourceKey DnsResourceKey;
typedef struct DnsResourceRecord DnsResourceRecord;
@@ -39,35 +40,6 @@ enum {
_DNS_CLASS_INVALID = -1
};
-/* DNS record types, see RFC 1035 */
-enum {
- /* Normal records */
- DNS_TYPE_A = 0x01,
- DNS_TYPE_NS = 0x02,
- DNS_TYPE_CNAME = 0x05,
- DNS_TYPE_SOA = 0x06,
- DNS_TYPE_PTR = 0x0C,
- DNS_TYPE_HINFO = 0x0D,
- DNS_TYPE_MX = 0x0F,
- DNS_TYPE_TXT = 0x10,
- DNS_TYPE_AAAA = 0x1C,
- DNS_TYPE_LOC = 0x1D,
- DNS_TYPE_SRV = 0x21,
- DNS_TYPE_DNAME = 0x27,
- DNS_TYPE_SSHFP = 0x2C,
- DNS_TYPE_SPF = 0x63,
-
- /* Special records */
- DNS_TYPE_ANY = 0xFF,
- DNS_TYPE_OPT = 0x29, /* EDNS0 option */
- DNS_TYPE_TKEY = 0xF9,
- DNS_TYPE_TSIG = 0xFA,
- DNS_TYPE_IXFR = 0xFB,
- DNS_TYPE_AXFR = 0xFC,
- _DNS_TYPE_MAX,
- _DNS_TYPE_INVALID = -1
-};
-
struct DnsResourceKey {
unsigned n_ref;
uint16_t class, type;
@@ -178,8 +150,5 @@ int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecor
int dns_resource_record_to_string(const DnsResourceRecord *rr, char **ret);
DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
-const char *dns_type_to_string(uint16_t type);
-int dns_type_from_string(const char *name, uint16_t *type);
-
const char *dns_class_to_string(uint16_t type);
int dns_class_from_string(const char *name, uint16_t *class);