1 /*
2  * Copyright (C) 2008 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 _TETHER_CONTROLLER_H
18 #define _TETHER_CONTROLLER_H
19 
20 #include <netinet/in.h>
21 
22 #include <list>
23 #include <set>
24 #include <string>
25 
26 namespace android {
27 namespace net {
28 
29 class TetherController {
30 private:
31     std::list<std::string> mInterfaces;
32     // NetId to use for forwarded DNS queries. This may not be the default
33     // network, e.g., in the case where we are tethering to a DUN APN.
34     unsigned               mDnsNetId;
35     std::list<std::string> mDnsForwarders;
36     pid_t                  mDaemonPid;
37     int                    mDaemonFd;
38     std::set<std::string>  mForwardingRequests;
39 
40 public:
41     TetherController();
42     virtual ~TetherController();
43 
44     bool enableForwarding(const char* requester);
45     bool disableForwarding(const char* requester);
46     size_t forwardingRequestCount();
47 
48     int startTethering(int num_addrs, char **dhcp_ranges);
49     int stopTethering();
50     bool isTetheringStarted();
51 
52     unsigned getDnsNetId();
53     int setDnsForwarders(unsigned netId, char **servers, int numServers);
54     const std::list<std::string> &getDnsForwarders() const;
55 
56     int tetherInterface(const char *interface);
57     int untetherInterface(const char *interface);
58     const std::list<std::string> &getTetheredInterfaceList() const;
59     bool applyDnsInterfaces();
60 
61 private:
62     bool setIpFwdEnabled();
63 };
64 
65 }  // namespace net
66 }  // namespace android
67 
68 #endif
69