San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 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 | |
Elliott Hughes | 970274a | 2012-09-11 18:56:36 -0700 | [diff] [blame] | 20 | #include <netinet/in.h> |
Erik Kline | 70c0366 | 2016-03-31 11:39:53 +0900 | [diff] [blame] | 21 | |
| 22 | #include <list> |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 23 | #include <set> |
| 24 | #include <string> |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 25 | |
Erik Kline | 70c0366 | 2016-03-31 11:39:53 +0900 | [diff] [blame] | 26 | typedef std::list<char *> InterfaceCollection; |
| 27 | typedef std::list<std::string> NetAddressCollection; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 28 | |
| 29 | class TetherController { |
| 30 | InterfaceCollection *mInterfaces; |
Lorenzo Colitti | 667c477 | 2014-08-26 14:13:07 -0700 | [diff] [blame] | 31 | // NetId to use for forwarded DNS queries. This may not be the default |
| 32 | // network, e.g., in the case where we are tethering to a DUN APN. |
| 33 | unsigned mDnsNetId; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 34 | NetAddressCollection *mDnsForwarders; |
| 35 | pid_t mDaemonPid; |
| 36 | int mDaemonFd; |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 37 | std::set<std::string> mForwardingRequests; |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 38 | |
| 39 | public: |
Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 40 | TetherController(); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 41 | virtual ~TetherController(); |
| 42 | |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 43 | bool enableForwarding(const char* requester); |
| 44 | bool disableForwarding(const char* requester); |
| 45 | size_t forwardingRequestCount(); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 46 | |
Erik Kline | 13fa01f | 2015-11-12 17:49:23 +0900 | [diff] [blame] | 47 | int startTethering(int num_addrs, char **dhcp_ranges); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 48 | int stopTethering(); |
| 49 | bool isTetheringStarted(); |
| 50 | |
Lorenzo Colitti | 667c477 | 2014-08-26 14:13:07 -0700 | [diff] [blame] | 51 | unsigned getDnsNetId(); |
| 52 | int setDnsForwarders(unsigned netId, char **servers, int numServers); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 53 | NetAddressCollection *getDnsForwarders(); |
| 54 | |
| 55 | int tetherInterface(const char *interface); |
| 56 | int untetherInterface(const char *interface); |
| 57 | InterfaceCollection *getTetheredInterfaceList(); |
Robert Greenwalt | 3d4c758 | 2012-12-11 12:33:37 -0800 | [diff] [blame] | 58 | |
| 59 | private: |
| 60 | int applyDnsInterfaces(); |
Lorenzo Colitti | 799625c | 2015-02-25 12:52:00 +0900 | [diff] [blame] | 61 | bool setIpFwdEnabled(); |
San Mehat | 9d10b34 | 2010-01-18 09:51:02 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | #endif |