• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 #include <string>
20 
21 #include <netd_resolv/resolv.h>  // android_net_context
22 #include <sysutils/FrameworkCommand.h>
23 #include <sysutils/FrameworkListener.h>
24 
25 struct addrinfo;
26 struct hostent;
27 
28 namespace android {
29 namespace net {
30 
31 class DnsProxyListener : public FrameworkListener {
32   public:
33     DnsProxyListener();
~DnsProxyListener()34     virtual ~DnsProxyListener() {}
35 
36     static constexpr const char* SOCKET_NAME = "dnsproxyd";
37 
38   private:
39     class GetAddrInfoCmd : public FrameworkCommand {
40       public:
41         GetAddrInfoCmd();
~GetAddrInfoCmd()42         virtual ~GetAddrInfoCmd() {}
43         int runCommand(SocketClient* c, int argc, char** argv) override;
44     };
45 
46     /* ------ getaddrinfo ------*/
47     class GetAddrInfoHandler {
48       public:
49         // Note: All of host, service, and hints may be NULL
50         GetAddrInfoHandler(SocketClient* c, char* host, char* service, addrinfo* hints,
51                            const android_net_context& netcontext);
52         ~GetAddrInfoHandler();
53 
54         void run();
55 
56       private:
57         void doDns64Synthesis(int32_t* rv, addrinfo** res);
58 
59         SocketClient* mClient;  // ref counted
60         char* mHost;            // owned. TODO: convert to std::string.
61         char* mService;         // owned. TODO: convert to std::string.
62         addrinfo* mHints;       // owned
63         android_net_context mNetContext;
64     };
65 
66     /* ------ gethostbyname ------*/
67     class GetHostByNameCmd : public FrameworkCommand {
68       public:
69         GetHostByNameCmd();
~GetHostByNameCmd()70         virtual ~GetHostByNameCmd() {}
71         int runCommand(SocketClient* c, int argc, char** argv) override;
72     };
73 
74     class GetHostByNameHandler {
75       public:
76         GetHostByNameHandler(SocketClient* c, char* name, int af,
77                              const android_net_context& netcontext);
78         ~GetHostByNameHandler();
79 
80         void run();
81 
82       private:
83         void doDns64Synthesis(int32_t* rv, hostent** hpp);
84 
85         SocketClient* mClient;  // ref counted
86         char* mName;            // owned. TODO: convert to std::string.
87         int mAf;
88         android_net_context mNetContext;
89     };
90 
91     /* ------ gethostbyaddr ------*/
92     class GetHostByAddrCmd : public FrameworkCommand {
93       public:
94         GetHostByAddrCmd();
~GetHostByAddrCmd()95         virtual ~GetHostByAddrCmd() {}
96         int runCommand(SocketClient* c, int argc, char** argv) override;
97     };
98 
99     class GetHostByAddrHandler {
100       public:
101         GetHostByAddrHandler(SocketClient* c, void* address, int addressLen, int addressFamily,
102                              const android_net_context& netcontext);
103         ~GetHostByAddrHandler();
104 
105         void run();
106 
107       private:
108         void doDns64ReverseLookup(hostent** hpp);
109 
110         SocketClient* mClient;  // ref counted
111         void* mAddress;         // address to lookup; owned
112         int mAddressLen;        // length of address to look up
113         int mAddressFamily;     // address family
114         android_net_context mNetContext;
115     };
116 
117     /* ------ resnsend ------*/
118     class ResNSendCommand : public FrameworkCommand {
119       public:
120         ResNSendCommand();
~ResNSendCommand()121         virtual ~ResNSendCommand() {}
122         int runCommand(SocketClient* c, int argc, char** argv) override;
123     };
124 
125     class ResNSendHandler {
126       public:
127         ResNSendHandler(SocketClient* c, std::string msg, uint32_t flags,
128                         const android_net_context& netcontext);
129         ~ResNSendHandler();
130 
131         void run();
132 
133       private:
134         SocketClient* mClient;  // ref counted
135         std::string mMsg;
136         uint32_t mFlags;
137         android_net_context mNetContext;
138     };
139 
140     /* ------ getdnsnetid ------*/
141     class GetDnsNetIdCommand : public FrameworkCommand {
142       public:
143         GetDnsNetIdCommand();
~GetDnsNetIdCommand()144         virtual ~GetDnsNetIdCommand() {}
145         int runCommand(SocketClient* c, int argc, char** argv) override;
146     };
147 };
148 
149 }  // namespace net
150 }  // namespace android
151