libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
dnsrecord.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_NETWORK
13#include <cstdint>
14#include <promeki/namespace.h>
15#include <promeki/duration.h>
16#include <promeki/ipv4address.h>
17#include <promeki/ipv6address.h>
18#include <promeki/list.h>
19#include <promeki/string.h>
20#if PROMEKI_ENABLE_MDNS
22#endif
23
24PROMEKI_NAMESPACE_BEGIN
25
40struct DnsQuestion {
42 String name;
44 uint16_t type = 0;
46 uint16_t klass = 1;
48 bool unicastResponse = false;
49};
50
88class DnsRecord {
89 public:
100 enum class Type : uint16_t {
101 Unknown = 0,
102 A = 1,
103 Ns = 2,
104 Cname = 5,
105 Soa = 6,
106 Ptr = 12,
107 Mx = 15,
108 Txt = 16,
109 Aaaa = 28,
110 Srv = 33,
111 Naptr = 35,
112 Opt = 41,
113 Ds = 43,
114 Rrsig = 46,
115 Nsec = 47,
116 Dnskey = 48,
117 Tlsa = 52,
118 Svcb = 64,
119 Https = 65,
120 Axfr = 252,
121 Any = 255,
122 Caa = 257,
123 };
124
126 enum class Section : uint8_t {
127 Question = 0,
128 Answer = 1,
129 Authority = 2,
130 Additional = 3,
131 };
132
134 static constexpr int64_t DefaultTtlSeconds = 75 * 60;
135
136 // ===== Common header fields =====================================
138 Type type = Type::Unknown;
140 Section section = Section::Answer;
142 uint16_t klass = 1;
144 String name;
146 Duration ttl;
155 bool cacheFlush = false;
156
157 // ===== Type-specific payload ====================================
159 String ptrTarget;
161 String cnameTarget;
163 String nsTarget;
165 uint16_t srvPriority = 0;
167 uint16_t srvWeight = 0;
169 uint16_t srvPort = 0;
171 String srvTarget;
173 uint16_t mxPreference = 0;
175 String mxExchange;
176#if PROMEKI_ENABLE_MDNS
188 MdnsTxtRecord txt;
189#endif
191 Ipv4Address a;
193 Ipv6Address aaaa;
194
195 // ===== SOA fields (RFC 1035) ====================================
197 String soaMname;
199 String soaRname;
201 uint32_t soaSerial = 0;
203 uint32_t soaRefresh = 0;
205 uint32_t soaRetry = 0;
207 uint32_t soaExpire = 0;
209 uint32_t soaMinimum = 0;
210
211 // ===== NAPTR fields (RFC 3403) ==================================
213 uint16_t naptrOrder = 0;
215 uint16_t naptrPreference = 0;
217 String naptrFlags;
219 String naptrService;
221 String naptrRegexp;
223 String naptrReplacement;
224
225 // ===== CAA fields (RFC 8659) ====================================
227 uint8_t caaFlags = 0;
229 String caaTag;
231 String caaValue;
232
233 // ===== Catch-all =================================================
243 List<uint8_t> rawRdata;
244
245 // ===== Convenience helpers ======================================
247 bool isGoodbye() const { return ttl == Duration::zero(); }
248
250 static DnsRecord makeA(const String &owner, const Ipv4Address &addr,
251 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
252
254 static DnsRecord makeAaaa(const String &owner, const Ipv6Address &addr,
255 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
256
258 static DnsRecord makePtr(const String &owner, const String &target,
259 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
260
262 static DnsRecord makeSrv(const String &owner, const String &target, uint16_t port,
263 uint16_t priority = 0, uint16_t weight = 0,
264 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
265
267 static DnsRecord makeCname(const String &owner, const String &target,
268 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
269
271 static DnsRecord makeNs(const String &owner, const String &target,
272 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
273
275 static DnsRecord makeMx(const String &owner, const String &exchange, uint16_t preference,
276 const Duration &ttl = Duration::fromSeconds(DefaultTtlSeconds));
277};
278
279#if PROMEKI_ENABLE_MDNS
287using MdnsParsedRecord = DnsRecord;
288
294using MdnsParsedQuestion = DnsQuestion;
295#endif
296
297PROMEKI_NAMESPACE_END
298
299#endif // PROMEKI_ENABLE_NETWORK