]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-rr.h
resolved: implement negative caching
[thirdparty/systemd.git] / src / resolve / resolved-dns-rr.h
CommitLineData
74b2466e
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3#pragma once
4
5/***
6 This file is part of systemd.
7
8 Copyright 2014 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24#include <inttypes.h>
25#include <netinet/in.h>
26
27#include "util.h"
322345fd 28#include "hashmap.h"
74b2466e
LP
29
30typedef struct DnsResourceKey DnsResourceKey;
31typedef struct DnsResourceRecord DnsResourceRecord;
32
33/* DNS record classes, see RFC 1035 */
34enum {
35 DNS_CLASS_IN = 0x01,
322345fd 36 DNS_CLASS_ANY = 0xFF,
74b2466e
LP
37};
38
39/* DNS record types, see RFC 1035 */
40enum {
41 /* Normal records */
42 DNS_TYPE_A = 0x01,
43 DNS_TYPE_NS = 0x02,
44 DNS_TYPE_CNAME = 0x05,
45 DNS_TYPE_SOA = 0x06,
46 DNS_TYPE_PTR = 0x0C,
47 DNS_TYPE_HINFO = 0x0D,
48 DNS_TYPE_MX = 0x0F,
49 DNS_TYPE_TXT = 0x10,
50 DNS_TYPE_AAAA = 0x1C,
51 DNS_TYPE_SRV = 0x21,
322345fd
LP
52 DNS_TYPE_SSHFP = 0x2C,
53 DNS_TYPE_DNAME = 0x27,
74b2466e
LP
54
55 /* Special records */
56 DNS_TYPE_ANY = 0xFF,
57 DNS_TYPE_OPT = 0x29, /* EDNS0 option */
58 DNS_TYPE_TKEY = 0xF9,
59 DNS_TYPE_TSIG = 0xFA,
60 DNS_TYPE_IXFR = 0xFB,
61 DNS_TYPE_AXFR = 0xFC,
62};
63
64struct DnsResourceKey {
faa133f3
LP
65 unsigned n_ref;
66 uint16_t class, type;
67 char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */
74b2466e
LP
68};
69
70struct DnsResourceRecord {
71 unsigned n_ref;
faa133f3 72 DnsResourceKey *key;
74b2466e 73 uint32_t ttl;
74b2466e
LP
74 union {
75 struct {
76 void *data;
77 uint16_t size;
78 } generic;
79
80 /* struct { */
81 /* uint16_t priority; */
82 /* uint16_t weight; */
83 /* uint16_t port; */
84 /* char *name; */
85 /* } srv; */
86
87 struct {
88 char *name;
89 } ptr, ns, cname;
90
91 struct {
92 char *cpu;
93 char *os;
94 } hinfo;
95
96 /* struct { */
97 /* char **list; */
98 /* } txt; */
99
100 struct {
101 struct in_addr in_addr;
102 } a;
103
104 struct {
105 struct in6_addr in6_addr;
106 } aaaa;
7e8e0422
LP
107
108 struct {
109 char *mname;
110 char *rname;
111 uint32_t serial;
112 uint32_t refresh;
113 uint32_t retry;
114 uint32_t expire;
115 uint32_t minimum;
116 } soa;
74b2466e
LP
117 };
118};
119
faa133f3
LP
120static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) {
121 if (_unlikely_(!key))
122 return NULL;
123
124 if (key->_name)
125 return key->_name;
126
127 return (char*) key + sizeof(DnsResourceKey);
128}
74b2466e 129
faa133f3
LP
130DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name);
131DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name);
132DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key);
133DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key);
134int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b);
135int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr);
136int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr);
322345fd
LP
137unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]);
138int dns_resource_key_compare_func(const void *a, const void *b);
faa133f3 139DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref);
322345fd 140
faa133f3 141DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key);
74b2466e
LP
142DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
143DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
322345fd 144int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
faa133f3 145DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);
322345fd
LP
146
147const char *dns_type_to_string(uint16_t type);
148const char *dns_class_to_string(uint16_t type);