1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 namespace android::net {
20 
21 static constexpr int kDohPort = 443;
22 static constexpr int kDotPort = 853;
23 
24 enum class PrivateDnsTransport : uint8_t {
25     kDot,  // DNS over TLS.
26     kDoh,  // DNS over HTTPS.
27 };
28 
29 // Validation status of a private DNS server on a specific netId.
30 enum class Validation : uint8_t {
31     in_process,
32     success,
33     success_but_expired,
34     fail,
35     unknown_server,
36     unknown_netid,
37 };
38 
39 // The private DNS mode on a specific netId.
40 enum class PrivateDnsMode : uint8_t {
41     OFF,
42     OPPORTUNISTIC,
43     STRICT,
44 };
45 
validationStatusToString(Validation value)46 constexpr const char* validationStatusToString(Validation value) {
47     switch (value) {
48         case Validation::in_process:
49             return "in_process";
50         case Validation::success:
51             return "success";
52         case Validation::success_but_expired:
53             return "success_but_expired";
54         case Validation::fail:
55             return "fail";
56         case Validation::unknown_server:
57             return "unknown_server";
58         case Validation::unknown_netid:
59             return "unknown_netid";
60         default:
61             return "unknown_status";
62     }
63 }
64 
getPrivateDnsModeString(PrivateDnsMode mode)65 constexpr const char* getPrivateDnsModeString(PrivateDnsMode mode) {
66     switch (mode) {
67         case PrivateDnsMode::OFF:
68             return "OFF";
69         case PrivateDnsMode::OPPORTUNISTIC:
70             return "OPPORTUNISTIC";
71         case PrivateDnsMode::STRICT:
72             return "STRICT";
73     }
74 }
75 
76 }  // namespace android::net
77