chiark / gitweb /
resolved: add DNS cache
[elogind.git] / src / resolve / resolved-dns-rr.h
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"
28 #include "hashmap.h"
29
30 typedef struct DnsResourceKey DnsResourceKey;
31 typedef struct DnsResourceRecord DnsResourceRecord;
32
33 /* DNS record classes, see RFC 1035 */
34 enum {
35         DNS_CLASS_IN   = 0x01,
36         DNS_CLASS_ANY  = 0xFF,
37 };
38
39 /* DNS record types, see RFC 1035 */
40 enum {
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,
52         DNS_TYPE_SSHFP = 0x2C,
53         DNS_TYPE_DNAME = 0x27,
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
64 struct DnsResourceKey {
65         uint16_t class;
66         uint16_t type;
67         char *name;
68 };
69
70 struct DnsResourceRecord {
71         unsigned n_ref;
72
73         DnsResourceKey key;
74         uint32_t ttl;
75
76         union {
77                 struct {
78                         void *data;
79                         uint16_t size;
80                 } generic;
81
82                 /* struct { */
83                 /*         uint16_t priority; */
84                 /*         uint16_t weight; */
85                 /*         uint16_t port; */
86                 /*         char *name; */
87                 /* } srv; */
88
89                 struct {
90                         char *name;
91                 } ptr, ns, cname;
92
93                 struct {
94                         char *cpu;
95                         char *os;
96                 } hinfo;
97
98                 /* struct { */
99                 /*         char **list; */
100                 /* } txt; */
101
102                 struct {
103                         struct in_addr in_addr;
104                 } a;
105
106                 struct {
107                         struct in6_addr in6_addr;
108                 } aaaa;
109         };
110 };
111
112 void dns_resource_key_free(DnsResourceKey *key);
113
114 unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]);
115 int dns_resource_key_compare_func(const void *a, const void *b);
116
117 DnsResourceRecord* dns_resource_record_new(void);
118 DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
119 DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
120
121 DnsResourceRecord** dns_resource_record_freev(DnsResourceRecord **rrs, unsigned n);
122
123 int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b);
124
125 const char *dns_type_to_string(uint16_t type);
126 const char *dns_class_to_string(uint16_t type);
127
128 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);