1 /*
2  * Copyright (C) 2011 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 #ifndef _RESOLVER_CONTROLLER_H_
18 #define _RESOLVER_CONTROLLER_H_
19 
20 #include <list>
21 #include <vector>
22 
23 struct __res_params;
24 struct sockaddr_storage;
25 
26 namespace android {
27 namespace net {
28 
29 struct DnsTlsServer;
30 class DumpWriter;
31 struct ResolverStats;
32 
33 enum class PrivateDnsMode {
34     OFF,
35     OPPORTUNISTIC,
36     STRICT,
37 };
38 
39 
40 class ResolverController {
41 public:
ResolverController()42     ResolverController() {};
43 
~ResolverController()44     virtual ~ResolverController() {};
45 
46     // TODO: delete this function
47     int setDnsServers(unsigned netId, const char* searchDomains, const char** servers,
48             int numservers, const __res_params* params);
49 
50     // Validation status of a DNS over TLS server (on a specific netId).
51     enum class Validation : uint8_t { in_process, success, fail, unknown_server, unknown_netid };
52 
53     struct PrivateDnsStatus {
54         PrivateDnsMode mode;
55         std::list<DnsTlsServer> validatedServers;
56     };
57 
58     // Retrieve the Private DNS status for the given |netid|.
59     //
60     // If the requested |netid| is not known, the PrivateDnsStatus's mode has a
61     // default value of PrivateDnsMode::OFF, and validatedServers is empty.
62     PrivateDnsStatus getPrivateDnsStatus(unsigned netid) const;
63 
64     int clearDnsServers(unsigned netid);
65 
66     int flushDnsCache(unsigned netid);
67 
68     int getDnsInfo(unsigned netId, std::vector<std::string>* servers,
69             std::vector<std::string>* domains, __res_params* params,
70             std::vector<android::net::ResolverStats>* stats);
71 
72     // Binder specific functions, which convert between the binder int/string arrays and the
73     // actual data structures, and call setDnsServer() / getDnsInfo() for the actual processing.
74     int setResolverConfiguration(int32_t netId, const std::vector<std::string>& servers,
75             const std::vector<std::string>& domains, const std::vector<int32_t>& params,
76             const std::string& tlsName, const std::vector<std::string>& tlsServers,
77             const std::set<std::vector<uint8_t>>& tlsFingerprints);
78 
79     int getResolverInfo(int32_t netId, std::vector<std::string>* servers,
80             std::vector<std::string>* domains, std::vector<int32_t>* params,
81             std::vector<int32_t>* stats);
82 
83     void dump(DumpWriter& dw, unsigned netId);
84 
85 };
86 
87 }  // namespace net
88 }  // namespace android
89 
90 #endif /* _RESOLVER_CONTROLLER_H_ */
91