chiark / gitweb /
resolved: add a DNS client stub resolver
[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
29 typedef struct DnsResourceKey DnsResourceKey;
30 typedef struct DnsResourceRecord DnsResourceRecord;
31
32 /* DNS record classes, see RFC 1035 */
33 enum {
34         DNS_CLASS_IN   = 0x01,
35 };
36
37 /* DNS record types, see RFC 1035 */
38 enum {
39         /* Normal records */
40         DNS_TYPE_A     = 0x01,
41         DNS_TYPE_NS    = 0x02,
42         DNS_TYPE_CNAME = 0x05,
43         DNS_TYPE_SOA   = 0x06,
44         DNS_TYPE_PTR   = 0x0C,
45         DNS_TYPE_HINFO = 0x0D,
46         DNS_TYPE_MX    = 0x0F,
47         DNS_TYPE_TXT   = 0x10,
48         DNS_TYPE_AAAA  = 0x1C,
49         DNS_TYPE_SRV   = 0x21,
50
51         /* Special records */
52         DNS_TYPE_ANY   = 0xFF,
53         DNS_TYPE_OPT   = 0x29,      /* EDNS0 option */
54         DNS_TYPE_TKEY  = 0xF9,
55         DNS_TYPE_TSIG  = 0xFA,
56         DNS_TYPE_IXFR  = 0xFB,
57         DNS_TYPE_AXFR  = 0xFC,
58 };
59
60 struct DnsResourceKey {
61         uint16_t class;
62         uint16_t type;
63         char *name;
64 };
65
66 struct DnsResourceRecord {
67         unsigned n_ref;
68
69         DnsResourceKey key;
70         uint32_t ttl;
71
72         union {
73                 struct {
74                         void *data;
75                         uint16_t size;
76                 } generic;
77
78                 /* struct { */
79                 /*         uint16_t priority; */
80                 /*         uint16_t weight; */
81                 /*         uint16_t port; */
82                 /*         char *name; */
83                 /* } srv; */
84
85                 struct {
86                         char *name;
87                 } ptr, ns, cname;
88
89                 struct {
90                         char *cpu;
91                         char *os;
92                 } hinfo;
93
94                 /* struct { */
95                 /*         char **list; */
96                 /* } txt; */
97
98                 struct {
99                         struct in_addr in_addr;
100                 } a;
101
102                 struct {
103                         struct in6_addr in6_addr;
104                 } aaaa;
105         };
106 };
107
108 void dns_resource_key_free(DnsResourceKey *key);
109
110 DnsResourceRecord* dns_resource_record_new(void);
111 DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr);
112 DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr);
113
114 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref);