trust_dns_proto/rr/domain/usage.rs
1// Copyright 2015-2018 Benjamin Fry <benjaminfry@me.com>
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8//! Reserved zone names.
9//!
10//! see [Special-Use Domain Names](https://tools.ietf.org/html/rfc6761), RFC 6761 February, 2013
11
12use std::ops::Deref;
13
14use lazy_static::lazy_static;
15
16use crate::rr::domain::Name;
17
18lazy_static! {
19 /// Default Name usage, everything is normal...
20 pub static ref DEFAULT: ZoneUsage = ZoneUsage::default();
21}
22
23lazy_static! {
24 static ref ARPA: Name = Name::from_ascii("arpa.").unwrap();
25 /// zone for ipv4 reverse addresses
26 pub static ref IN_ADDR_ARPA: Name = Name::from_ascii("in-addr").unwrap().append_domain(&ARPA).unwrap();
27 /// zone for ipv6 reverse addresses
28 pub static ref IP6_ARPA: Name = Name::from_ascii("ip6").unwrap().append_domain(&ARPA).unwrap();
29}
30
31lazy_static! {
32 /// localhost.
33 ///
34 /// [Special-Use Domain Names](https://tools.ietf.org/html/rfc6761), RFC 6761 February, 2013
35 ///
36 /// ```text
37 /// 6.3. Domain Name Reservation Considerations for "localhost."
38 ///
39 /// The domain "localhost." and any names falling within ".localhost."
40 /// are special in the following ways:
41 /// ```
42
43 /// localhost. usage
44 pub static ref LOCALHOST: ZoneUsage = ZoneUsage::localhost(Name::from_ascii("localhost.").unwrap());
45
46 /// 127.in-addr.arpa. usage; 127/8 is reserved for loopback
47 pub static ref IN_ADDR_ARPA_127: ZoneUsage = ZoneUsage::localhost(Name::from_ascii("127").unwrap().append_domain(&IN_ADDR_ARPA).unwrap());
48
49 /// 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa. usage; 1/128 is the only address in ipv6 loopback
50 pub static ref IP6_ARPA_1: ZoneUsage = ZoneUsage::localhost(Name::from_ascii("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0").unwrap().append_domain(&IP6_ARPA).unwrap());
51}
52
53lazy_static! {
54 /// .local.
55 ///
56 /// [Multicast DNS](https://tools.ietf.org/html/rfc6762), RFC 6762 February 2013
57 ///
58 /// ```text
59 /// This document specifies that the DNS top-level domain ".local." is a
60 /// special domain with special semantics, namely that any fully
61 /// qualified name ending in ".local." is link-local, and names within
62 /// this domain are meaningful only on the link where they originate.
63 /// This is analogous to IPv4 addresses in the 169.254/16 prefix or IPv6
64 /// addresses in the FE80::/10 prefix, which are link-local and
65 /// meaningful only on the link where they originate.
66 /// ```
67
68 /// localhost. usage
69 pub static ref LOCAL: ZoneUsage = ZoneUsage::local(Name::from_ascii("local.").unwrap());
70
71 // RFC 6762 Multicast DNS February 2013
72
73 // Any DNS query for a name ending with "254.169.in-addr.arpa." MUST
74 // be sent to the mDNS IPv4 link-local multicast address 224.0.0.251
75 // or the mDNS IPv6 multicast address FF02::FB. Since names under
76 // this domain correspond to IPv4 link-local addresses, it is logical
77 // that the local link is the best place to find information
78 // pertaining to those names.
79 //
80 // Likewise, any DNS query for a name within the reverse mapping
81 // domains for IPv6 link-local addresses ("8.e.f.ip6.arpa.",
82 // "9.e.f.ip6.arpa.", "a.e.f.ip6.arpa.", and "b.e.f.ip6.arpa.") MUST
83 // be sent to the mDNS IPv6 link-local multicast address FF02::FB or
84 // the mDNS IPv4 link-local multicast address 224.0.0.251.
85
86 /// 254.169.in-addr.arpa. usage link-local, i.e. mDNS
87 pub static ref IN_ADDR_ARPA_169_254: ZoneUsage = ZoneUsage::local(Name::from_ascii("254.169").unwrap().append_domain(&IN_ADDR_ARPA).unwrap());
88
89 /// 254.169.in-addr.arpa. usage link-local, i.e. mDNS
90 pub static ref IP6_ARPA_FE_8: ZoneUsage = ZoneUsage::local(Name::from_ascii("8.e.f").unwrap().append_domain(&IP6_ARPA).unwrap());
91 /// 254.169.in-addr.arpa. usage link-local, i.e. mDNS
92 pub static ref IP6_ARPA_FE_9: ZoneUsage = ZoneUsage::local(Name::from_ascii("9.e.f").unwrap().append_domain(&IP6_ARPA).unwrap());
93 /// 254.169.in-addr.arpa. usage link-local, i.e. mDNS
94 pub static ref IP6_ARPA_FE_B: ZoneUsage = ZoneUsage::local(Name::from_ascii("b.e.f").unwrap().append_domain(&IP6_ARPA).unwrap());
95}
96
97lazy_static! {
98 /// invalid.
99 ///
100 /// [Special-Use Domain Names](https://tools.ietf.org/html/rfc6761), RFC 6761 February, 2013
101 ///
102 /// ```text
103 /// 6.4. Domain Name Reservation Considerations for "invalid."
104 ///
105 /// The domain "invalid." and any names falling within ".invalid." are
106 /// special in the ways listed below. In the text below, the term
107 /// "invalid" is used in quotes to signify such names, as opposed to
108 /// names that may be invalid for other reasons (e.g., being too long).
109 /// ```
110
111 /// invalid. name usage
112 pub static ref INVALID: ZoneUsage = ZoneUsage::invalid(Name::from_ascii("invalid.").unwrap());
113}
114
115lazy_static! {
116 /// invalid.
117 ///
118 /// [The ".onion" Special-Use Domain Name](https://tools.ietf.org/html/rfc7686), RFC 7686 October, 2015
119 ///
120 /// ```text
121 /// 1. Introduction
122 ///
123 /// The Tor network has the ability to host network
124 /// services using the ".onion" Special-Use Top-Level Domain Name. Such
125 /// names can be used as other domain names would be (e.g., in URLs
126 /// [RFC3986]), but instead of using the DNS infrastructure, .onion names
127 /// functionally correspond to the identity of a given service, thereby
128 /// combining location and authentication.
129 /// ```
130
131 /// onion. name usage
132 pub static ref ONION: ZoneUsage = ZoneUsage {
133 user: UserUsage::Normal, // the domain is special, but this is what seems to match the most
134 app: AppUsage::Normal, // the domain is special, but this is what seems to match the most
135 .. ZoneUsage::invalid(Name::from_ascii("onion.").unwrap())
136 };
137}
138
139/// Users:
140///
141/// Are human users expected to recognize these names as special and
142/// use them differently? In what way?
143#[derive(Clone, Copy, PartialEq, Eq)]
144pub enum UserUsage {
145 /// Users are free to use these names as they would any other
146 /// reverse-mapping names. However, since there is no central
147 /// authority responsible for use of private addresses, users SHOULD
148 /// be aware that these names are likely to yield different results
149 /// on different networks.
150 Normal,
151
152 /// Users are free to use localhost names as they would any other
153 /// domain names. Users may assume that IPv4 and IPv6 address
154 /// queries for localhost names will always resolve to the respective
155 /// IP loopback address.
156 Loopback,
157
158 /// Multi-cast link-local usage
159 LinkLocal,
160
161 /// Users are free to use "invalid" names as they would any other
162 /// domain names. Users MAY assume that queries for "invalid" names
163 /// will always return NXDOMAIN responses.
164 NxDomain,
165}
166
167/// Application Software:
168///
169/// Are writers of application software expected to make their
170/// software recognize these names as special and treat them
171/// differently? In what way? (For example, if a human user enters
172/// such a name, should the application software reject it with an
173/// error message?)
174#[derive(Clone, Copy, PartialEq, Eq)]
175pub enum AppUsage {
176 /// Application software SHOULD NOT recognize these names as special,
177 /// and SHOULD use these names as they would other reverse-mapping
178 /// names.
179 ///
180 /// Application software SHOULD NOT recognize test names as special,
181 /// and SHOULD use test names as they would other domain names.
182 ///
183 /// Application software SHOULD NOT recognize example names as
184 /// special and SHOULD use example names as they would other domain
185 /// names.
186 Normal,
187
188 /// Application software MAY recognize localhost names as special, or
189 /// MAY pass them to name resolution APIs as they would for other
190 /// domain names.
191 Loopback,
192
193 /// Link local, generally for mDNS
194 LinkLocal,
195
196 /// Application software MAY recognize "invalid" names as special or
197 /// MAY pass them to name resolution APIs as they would for other
198 /// domain names.
199 NxDomain,
200}
201
202/// Name Resolution APIs and Libraries:
203///
204/// Are writers of name resolution APIs and libraries expected to
205/// make their software recognize these names as special and treat
206/// them differently? If so, how?
207#[derive(Clone, Copy, PartialEq, Eq)]
208pub enum ResolverUsage {
209 /// Name resolution APIs and libraries SHOULD NOT recognize these
210 /// names as special and SHOULD NOT treat them differently. Name
211 /// resolution APIs SHOULD send queries for these names to their
212 /// configured caching DNS server(s).
213 ///
214 /// Name resolution APIs and libraries SHOULD NOT recognize test
215 /// names as special and SHOULD NOT treat them differently. Name
216 /// resolution APIs SHOULD send queries for test names to their
217 /// configured caching DNS server(s).
218 ///
219 /// Name resolution APIs and libraries SHOULD NOT recognize example
220 /// names as special and SHOULD NOT treat them differently. Name
221 /// resolution APIs SHOULD send queries for example names to their
222 /// configured caching DNS server(s).
223 Normal,
224
225 /// Name resolution APIs and libraries SHOULD recognize localhost
226 /// names as special and SHOULD always return the IP loopback address
227 /// for address queries and negative responses for all other query
228 /// types. Name resolution APIs SHOULD NOT send queries for
229 /// localhost names to their configured caching DNS server(s).
230 Loopback,
231
232 /// Link local, generally for mDNS
233 ///
234 /// Any DNS query for a name ending with ".local." MUST be sent to the
235 /// mDNS IPv4 link-local multicast address 224.0.0.251 (or its IPv6
236 /// equivalent FF02::FB). The design rationale for using a fixed
237 /// multicast address instead of selecting from a range of multicast
238 /// addresses using a hash function is discussed in Appendix B.
239 /// Implementers MAY choose to look up such names concurrently via other
240 /// mechanisms (e.g., Unicast DNS) and coalesce the results in some
241 /// fashion. Implementers choosing to do this should be aware of the
242 /// potential for user confusion when a given name can produce different
243 /// results depending on external network conditions (such as, but not
244 /// limited to, which name lookup mechanism responds faster).
245 LinkLocal,
246
247 /// Name resolution APIs and libraries SHOULD recognize "invalid"
248 /// names as special and SHOULD always return immediate negative
249 /// responses. Name resolution APIs SHOULD NOT send queries for
250 /// "invalid" names to their configured caching DNS server(s).
251 NxDomain,
252}
253
254/// Caching DNS Servers:
255///
256/// Are developers of caching domain name servers expected to make
257/// their implementations recognize these names as special and treat
258/// them differently? If so, how?
259#[derive(Clone, Copy, PartialEq, Eq)]
260pub enum CacheUsage {
261 /// Caching DNS servers SHOULD recognize these names as special and
262 /// SHOULD NOT, by default, attempt to look up NS records for them,
263 /// or otherwise query authoritative DNS servers in an attempt to
264 /// resolve these names. Instead, caching DNS servers SHOULD, by
265 /// default, generate immediate (positive or negative) responses for
266 /// all such queries. This is to avoid unnecessary load on the root
267 /// name servers and other name servers. Caching DNS servers SHOULD
268 /// offer a configuration option (disabled by default) to enable
269 /// upstream resolution of such names, for use in private networks
270 /// where private-address reverse-mapping names are known to be
271 /// handled by an authoritative DNS server in said private network.
272 NonRecursive,
273
274 /// Caching DNS servers SHOULD recognize "invalid" names as special
275 /// and SHOULD NOT attempt to look up NS records for them, or
276 /// otherwise query authoritative DNS servers in an attempt to
277 /// resolve "invalid" names. Instead, caching DNS servers SHOULD
278 /// generate immediate NXDOMAIN responses for all such queries. This
279 /// is to avoid unnecessary load on the root name servers and other
280 /// name servers.
281 NxDomain,
282
283 /// Caching DNS servers SHOULD recognize localhost names as special
284 /// and SHOULD NOT attempt to look up NS records for them, or
285 /// otherwise query authoritative DNS servers in an attempt to
286 /// resolve localhost names. Instead, caching DNS servers SHOULD,
287 /// for all such address queries, generate an immediate positive
288 /// response giving the IP loopback address, and for all other query
289 /// types, generate an immediate negative response. This is to avoid
290 /// unnecessary load on the root name servers and other name servers.
291 Loopback,
292
293 /// Caching DNS servers SHOULD NOT recognize example names as special
294 /// and SHOULD resolve them normally.
295 Normal,
296}
297
298/// Authoritative DNS Servers:
299///
300/// Are developers of authoritative domain name servers expected to
301/// make their implementations recognize these names as special and
302/// treat them differently? If so, how?
303#[derive(Clone, Copy, PartialEq, Eq)]
304pub enum AuthUsage {
305 /// Authoritative DNS servers SHOULD recognize these names as special
306 /// and SHOULD, by default, generate immediate negative responses for
307 /// all such queries, unless explicitly configured by the
308 /// administrator to give positive answers for private-address
309 /// reverse-mapping names.
310 Local,
311
312 /// Authoritative DNS servers SHOULD recognize these names as special
313 /// and SHOULD, by default, generate immediate negative responses for
314 /// all such queries, unless explicitly configured by the
315 /// administrator to give positive answers for private-address
316 /// reverse-mapping names.
317 NxDomain,
318
319 /// Authoritative DNS servers SHOULD recognize localhost names as
320 /// special and handle them as described above for caching DNS
321 /// servers.
322 Loopback,
323
324 /// Authoritative DNS servers SHOULD NOT recognize example names as
325 /// special.
326 Normal,
327}
328
329/// DNS Server Operators:
330///
331/// Does this reserved Special-Use Domain Name have any potential
332/// impact on DNS server operators? If they try to configure their
333/// authoritative DNS server as authoritative for this reserved name,
334/// will compliant name server software reject it as invalid? Do DNS
335/// server operators need to know about that and understand why?
336/// Even if the name server software doesn't prevent them from using
337/// this reserved name, are there other ways that it may not work as
338/// expected, of which the DNS server operator should be aware?
339#[derive(Clone, Copy, PartialEq, Eq)]
340pub enum OpUsage {
341 /// DNS server operators SHOULD, if they are using private addresses,
342 /// configure their authoritative DNS servers to act as authoritative
343 /// for these names.
344 ///
345 /// DNS server operators SHOULD, if they are using test names,
346 /// configure their authoritative DNS servers to act as authoritative
347 /// for test names.
348 Normal,
349
350 /// DNS server operators SHOULD be aware that the effective RDATA for
351 /// localhost names is defined by protocol specification and cannot
352 /// be modified by local configuration.
353 Loopback,
354
355 /// DNS server operators SHOULD be aware that the effective RDATA for
356 /// "invalid" names is defined by protocol specification to be
357 /// nonexistent and cannot be modified by local configuration.
358 NxDomain,
359}
360
361/// DNS Registries/Registrars:
362///
363/// How should DNS Registries/Registrars treat requests to register
364/// this reserved domain name? Should such requests be denied?
365/// Should such requests be allowed, but only to a specially-
366/// designated entity? (For example, the name "www.example.org" is
367/// reserved for documentation examples and is not available for
368/// registration; however, the name is in fact registered; and there
369/// is even a web site at that name, which states circularly that the
370/// name is reserved for use in documentation and cannot be
371/// registered!)
372#[derive(Clone, Copy, PartialEq, Eq)]
373pub enum RegistryUsage {
374 /// Stanard checks apply
375 Normal,
376
377 /// DNS Registries/Registrars MUST NOT grant requests to register
378 /// test names in the normal way to any person or entity. Test names
379 /// are reserved for use in private networks and fall outside the set
380 /// of names available for allocation by registries/registrars.
381 /// Attempting to allocate a test name as if it were a normal DNS
382 /// domain name will probably not work as desired, for reasons 4, 5,
383 /// and 6 above.
384 ///
385 /// DNS Registries/Registrars MUST NOT grant requests to register
386 /// localhost names in the normal way to any person or entity.
387 /// Localhost names are defined by protocol specification and fall
388 /// outside the set of names available for allocation by registries/
389 /// registrars. Attempting to allocate a localhost name as if it
390 /// were a normal DNS domain name will probably not work as desired,
391 /// for reasons 2, 3, 4, and 5 above.
392 ///
393 /// DNS Registries/Registrars MUST NOT grant requests to register
394 /// "invalid" names in the normal way to any person or entity. These
395 /// "invalid" names are defined by protocol specification to be
396 /// nonexistent, and they fall outside the set of names available for
397 /// allocation by registries/registrars. Attempting to allocate a
398 /// "invalid" name as if it were a normal DNS domain name will
399 /// probably not work as desired, for reasons 2, 3, 4, and 5 above.
400 ///
401 /// DNS Registries/Registrars MUST NOT grant requests to register
402 /// example names in the normal way to any person or entity. All
403 /// example names are registered in perpetuity to IANA:
404 Reserved,
405}
406
407/// ZoneUsage represents information about how a name falling in a given zone should be treated
408pub struct ZoneUsage {
409 name: Name,
410 user: UserUsage,
411 app: AppUsage,
412 resolver: ResolverUsage,
413 cache: CacheUsage,
414 auth: AuthUsage,
415 op: OpUsage,
416 registry: RegistryUsage,
417}
418
419impl ZoneUsage {
420 /// Constructs a new ZoneUsage with the associated values
421 #[allow(clippy::too_many_arguments)]
422 pub fn new(
423 name: Name,
424 user: UserUsage,
425 app: AppUsage,
426 resolver: ResolverUsage,
427 cache: CacheUsage,
428 auth: AuthUsage,
429 op: OpUsage,
430 registry: RegistryUsage,
431 ) -> Self {
432 Self {
433 name,
434 user,
435 app,
436 resolver,
437 cache,
438 auth,
439 op,
440 registry,
441 }
442 }
443
444 /// Constructs a new Default, with all no restrictions
445 pub fn default() -> Self {
446 Self::new(
447 Name::root(),
448 UserUsage::Normal,
449 AppUsage::Normal,
450 ResolverUsage::Normal,
451 CacheUsage::Normal,
452 AuthUsage::Normal,
453 OpUsage::Normal,
454 RegistryUsage::Normal,
455 )
456 }
457
458 /// Restrictions for reverse zones
459 pub fn reverse(name: Name) -> Self {
460 Self::new(
461 name,
462 UserUsage::Normal,
463 AppUsage::Normal,
464 ResolverUsage::Normal,
465 CacheUsage::NonRecursive,
466 AuthUsage::Local,
467 OpUsage::Normal,
468 RegistryUsage::Reserved,
469 )
470 }
471
472 /// Restrictions for the .test. zone
473 pub fn test(name: Name) -> Self {
474 Self::new(
475 name,
476 UserUsage::Normal,
477 AppUsage::Normal,
478 ResolverUsage::Normal,
479 CacheUsage::NonRecursive,
480 AuthUsage::Local,
481 OpUsage::Normal,
482 RegistryUsage::Reserved,
483 )
484 }
485
486 /// Restrictions for the .localhost. zone
487 pub fn localhost(name: Name) -> Self {
488 Self::new(
489 name,
490 UserUsage::Loopback,
491 AppUsage::Loopback,
492 ResolverUsage::Loopback,
493 CacheUsage::Loopback,
494 AuthUsage::Loopback,
495 OpUsage::Loopback,
496 RegistryUsage::Reserved,
497 )
498 }
499
500 /// Restrictions for the .local. zone
501 pub fn local(name: Name) -> Self {
502 Self::new(
503 name,
504 UserUsage::LinkLocal,
505 AppUsage::LinkLocal,
506 ResolverUsage::LinkLocal,
507 CacheUsage::Normal,
508 AuthUsage::Local,
509 OpUsage::Normal,
510 RegistryUsage::Reserved,
511 )
512 }
513
514 /// Restrictions for the .invalid. zone
515 pub fn invalid(name: Name) -> Self {
516 Self::new(
517 name,
518 UserUsage::NxDomain,
519 AppUsage::NxDomain,
520 ResolverUsage::NxDomain,
521 CacheUsage::NxDomain,
522 AuthUsage::NxDomain,
523 OpUsage::NxDomain,
524 RegistryUsage::Reserved,
525 )
526 }
527
528 /// Restrictions for the .example. zone
529 pub fn example(name: Name) -> Self {
530 Self::new(
531 name,
532 UserUsage::Normal,
533 AppUsage::Normal,
534 ResolverUsage::Normal,
535 CacheUsage::Normal,
536 AuthUsage::Normal,
537 OpUsage::Normal,
538 RegistryUsage::Reserved,
539 )
540 }
541
542 /// A reference to this zone name
543 pub fn name(&self) -> &Name {
544 &self.name
545 }
546
547 /// Returns the UserUsage of this zone
548 pub fn user(&self) -> UserUsage {
549 self.user
550 }
551
552 /// Returns the AppUsage of this zone
553 pub fn app(&self) -> AppUsage {
554 self.app
555 }
556
557 /// Returns the ResolverUsage of this zone
558 pub fn resolver(&self) -> ResolverUsage {
559 self.resolver
560 }
561
562 /// Returns the CacheUsage of this zone
563 pub fn cache(&self) -> CacheUsage {
564 self.cache
565 }
566
567 /// Returns the AuthUsage of this zone
568 pub fn auth(&self) -> AuthUsage {
569 self.auth
570 }
571
572 /// Returns the OpUsage of this zone
573 pub fn op(&self) -> OpUsage {
574 self.op
575 }
576
577 /// Returns the RegistryUsage of this zone
578 pub fn registry(&self) -> RegistryUsage {
579 self.registry
580 }
581}
582
583impl Deref for ZoneUsage {
584 type Target = Name;
585
586 fn deref(&self) -> &Self::Target {
587 &self.name
588 }
589}