]>
Commit | Line | Data |
---|---|---|
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" |
623a4c97 | 29 | #include "in-addr-util.h" |
74b2466e LP |
30 | |
31 | typedef struct DnsResourceKey DnsResourceKey; | |
32 | typedef struct DnsResourceRecord DnsResourceRecord; | |
33 | ||
34 | /* DNS record classes, see RFC 1035 */ | |
35 | enum { | |
36 | DNS_CLASS_IN = 0x01, | |
322345fd | 37 | DNS_CLASS_ANY = 0xFF, |
74b2466e LP |
38 | }; |
39 | ||
40 | /* DNS record types, see RFC 1035 */ | |
41 | enum { | |
42 | /* Normal records */ | |
43 | DNS_TYPE_A = 0x01, | |
44 | DNS_TYPE_NS = 0x02, | |
45 | DNS_TYPE_CNAME = 0x05, | |
46 | DNS_TYPE_SOA = 0x06, | |
47 | DNS_TYPE_PTR = 0x0C, | |
48 | DNS_TYPE_HINFO = 0x0D, | |
49 | DNS_TYPE_MX = 0x0F, | |
50 | DNS_TYPE_TXT = 0x10, | |
51 | DNS_TYPE_AAAA = 0x1C, | |
52 | DNS_TYPE_SRV = 0x21, | |
322345fd | 53 | DNS_TYPE_DNAME = 0x27, |
623a4c97 | 54 | DNS_TYPE_SSHFP = 0x2C, |
74b2466e LP |
55 | |
56 | /* Special records */ | |
57 | DNS_TYPE_ANY = 0xFF, | |
58 | DNS_TYPE_OPT = 0x29, /* EDNS0 option */ | |
59 | DNS_TYPE_TKEY = 0xF9, | |
60 | DNS_TYPE_TSIG = 0xFA, | |
61 | DNS_TYPE_IXFR = 0xFB, | |
62 | DNS_TYPE_AXFR = 0xFC, | |
63 | }; | |
64 | ||
65 | struct DnsResourceKey { | |
faa133f3 LP |
66 | unsigned n_ref; |
67 | uint16_t class, type; | |
68 | char *_name; /* don't access directy, use DNS_RESOURCE_KEY_NAME()! */ | |
74b2466e LP |
69 | }; |
70 | ||
71 | struct DnsResourceRecord { | |
72 | unsigned n_ref; | |
faa133f3 | 73 | DnsResourceKey *key; |
74b2466e | 74 | uint32_t ttl; |
74b2466e LP |
75 | union { |
76 | struct { | |
77 | void *data; | |
78 | uint16_t size; | |
79 | } generic; | |
80 | ||
81 | /* struct { */ | |
82 | /* uint16_t priority; */ | |
83 | /* uint16_t weight; */ | |
84 | /* uint16_t port; */ | |
85 | /* char *name; */ | |
86 | /* } srv; */ | |
87 | ||
88 | struct { | |
89 | char *name; | |
90 | } ptr, ns, cname; | |
91 | ||
92 | struct { | |
93 | char *cpu; | |
94 | char *os; | |
95 | } hinfo; | |
96 | ||
97 | /* struct { */ | |
98 | /* char **list; */ | |
99 | /* } txt; */ | |
100 | ||
101 | struct { | |
102 | struct in_addr in_addr; | |
103 | } a; | |
104 | ||
105 | struct { | |
106 | struct in6_addr in6_addr; | |
107 | } aaaa; | |
7e8e0422 LP |
108 | |
109 | struct { | |
110 | char *mname; | |
111 | char *rname; | |
112 | uint32_t serial; | |
113 | uint32_t refresh; | |
114 | uint32_t retry; | |
115 | uint32_t expire; | |
116 | uint32_t minimum; | |
117 | } soa; | |
74b2466e LP |
118 | }; |
119 | }; | |
120 | ||
faa133f3 LP |
121 | static inline const char* DNS_RESOURCE_KEY_NAME(const DnsResourceKey *key) { |
122 | if (_unlikely_(!key)) | |
123 | return NULL; | |
124 | ||
125 | if (key->_name) | |
126 | return key->_name; | |
127 | ||
128 | return (char*) key + sizeof(DnsResourceKey); | |
129 | } | |
74b2466e | 130 | |
faa133f3 LP |
131 | DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name); |
132 | DnsResourceKey* dns_resource_key_new_consume(uint16_t class, uint16_t type, char *name); | |
133 | DnsResourceKey* dns_resource_key_ref(DnsResourceKey *key); | |
134 | DnsResourceKey* dns_resource_key_unref(DnsResourceKey *key); | |
135 | int dns_resource_key_equal(const DnsResourceKey *a, const DnsResourceKey *b); | |
136 | int dns_resource_key_match_rr(const DnsResourceKey *key, const DnsResourceRecord *rr); | |
137 | int dns_resource_key_match_cname(const DnsResourceKey *key, const DnsResourceRecord *rr); | |
322345fd LP |
138 | unsigned long dns_resource_key_hash_func(const void *i, const uint8_t hash_key[HASH_KEY_SIZE]); |
139 | int dns_resource_key_compare_func(const void *a, const void *b); | |
faa133f3 | 140 | DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceKey*, dns_resource_key_unref); |
322345fd | 141 | |
faa133f3 | 142 | DnsResourceRecord* dns_resource_record_new(DnsResourceKey *key); |
74b2466e LP |
143 | DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr); |
144 | DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr); | |
623a4c97 | 145 | int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name); |
322345fd | 146 | int dns_resource_record_equal(const DnsResourceRecord *a, const DnsResourceRecord *b); |
faa133f3 | 147 | DEFINE_TRIVIAL_CLEANUP_FUNC(DnsResourceRecord*, dns_resource_record_unref); |
322345fd LP |
148 | |
149 | const char *dns_type_to_string(uint16_t type); | |
150 | const char *dns_class_to_string(uint16_t type); |