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#include <set> 22#include <string> 23 24#include "List.h" 25 26typedef android::netd::List<char *> InterfaceCollection; 27typedef android::netd::List<struct in_addr> NetAddressCollection; 28 29class TetherController { 30 InterfaceCollection *mInterfaces; 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; 34 NetAddressCollection *mDnsForwarders; 35 pid_t mDaemonPid; 36 int mDaemonFd; 37 std::set<std::string> mForwardingRequests; 38 39public: 40 TetherController(); 41 virtual ~TetherController(); 42 43 bool enableForwarding(const char* requester); 44 bool disableForwarding(const char* requester); 45 size_t forwardingRequestCount(); 46 47 int startTethering(int num_addrs, struct in_addr* addrs); 48 int stopTethering(); 49 bool isTetheringStarted(); 50 51 unsigned getDnsNetId(); 52 int setDnsForwarders(unsigned netId, char **servers, int numServers); 53 NetAddressCollection *getDnsForwarders(); 54 55 int tetherInterface(const char *interface); 56 int untetherInterface(const char *interface); 57 InterfaceCollection *getTetheredInterfaceList(); 58 59private: 60 int applyDnsInterfaces(); 61 bool setIpFwdEnabled(); 62}; 63 64#endif 65