hickory_server/server/protocol.rs
1// Copyright 2015-2022 Benjamin Fry <benjaminfry@me.com>
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// https://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// https://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8use std::fmt;
9
10/// For tracking purposes of inbound requests, which protocol was used
11#[non_exhaustive]
12#[derive(Clone, Copy)]
13pub enum Protocol {
14 /// User Datagram Protocol, the default for all DNS requests
15 Udp,
16 /// Transmission Control Protocol, used in DNS primarily for large responses (avoids truncation) and AXFR/IXFR
17 Tcp,
18 /// Transport Layer Security over TCP, for establishing a privacy, DoT (similar to DoH)
19 Tls,
20 /// Datagram Transport Layer Security over UDP
21 Dtls,
22 /// HTTP over TLS, DNS over HTTPS, aka DoH (similar to DoT)
23 Https,
24 /// Quic, DNS over Quic, aka DoQ (similar to DoH)
25 Quic,
26 /// HTTP over Quic, DNS over HTTP/3, aka DoH3 (similar to DoH)
27 H3,
28}
29
30impl fmt::Display for Protocol {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
32 let s = match self {
33 Self::Udp => "UDP",
34 Self::Tcp => "TCP",
35 Self::Tls => "TLS",
36 Self::Dtls => "DTLS",
37 Self::Https => "HTTPS",
38 Self::Quic => "QUIC",
39 Self::H3 => "H3",
40 };
41
42 f.write_str(s)
43 }
44}
45
46impl fmt::Debug for Protocol {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
48 fmt::Display::fmt(self, f)
49 }
50}