blob: 6035c25fb3922ce3030f74612d42008a8a0791d2 [file] [log] [blame]
San Mehat9d10b342010-01-18 09:51:02 -08001/*
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 Hughes970274a2012-09-11 18:56:36 -070020#include <netinet/in.h>
Erik Kline70c03662016-03-31 11:39:53 +090021
22#include <list>
Lorenzo Colitti799625c2015-02-25 12:52:00 +090023#include <set>
24#include <string>
San Mehat9d10b342010-01-18 09:51:02 -080025
San Mehat9d10b342010-01-18 09:51:02 -080026
27class TetherController {
Erik Kline2c5aaa12016-06-08 13:24:45 +090028private:
29 std::list<std::string> mInterfaces;
Lorenzo Colitti667c4772014-08-26 14:13:07 -070030 // NetId to use for forwarded DNS queries. This may not be the default
31 // network, e.g., in the case where we are tethering to a DUN APN.
Erik Kline2c5aaa12016-06-08 13:24:45 +090032 unsigned mDnsNetId;
33 std::list<std::string> mDnsForwarders;
34 pid_t mDaemonPid;
35 int mDaemonFd;
36 std::set<std::string> mForwardingRequests;
San Mehat9d10b342010-01-18 09:51:02 -080037
38public:
Sreeram Ramachandran87475a12014-07-15 16:20:28 -070039 TetherController();
San Mehat9d10b342010-01-18 09:51:02 -080040 virtual ~TetherController();
41
Lorenzo Colitti799625c2015-02-25 12:52:00 +090042 bool enableForwarding(const char* requester);
43 bool disableForwarding(const char* requester);
44 size_t forwardingRequestCount();
San Mehat9d10b342010-01-18 09:51:02 -080045
Erik Kline13fa01f2015-11-12 17:49:23 +090046 int startTethering(int num_addrs, char **dhcp_ranges);
San Mehat9d10b342010-01-18 09:51:02 -080047 int stopTethering();
48 bool isTetheringStarted();
49
Lorenzo Colitti667c4772014-08-26 14:13:07 -070050 unsigned getDnsNetId();
51 int setDnsForwarders(unsigned netId, char **servers, int numServers);
Erik Kline2c5aaa12016-06-08 13:24:45 +090052 const std::list<std::string> &getDnsForwarders() const;
San Mehat9d10b342010-01-18 09:51:02 -080053
54 int tetherInterface(const char *interface);
55 int untetherInterface(const char *interface);
Erik Kline2c5aaa12016-06-08 13:24:45 +090056 const std::list<std::string> &getTetheredInterfaceList() const;
Robert Greenwalt3d4c7582012-12-11 12:33:37 -080057
58private:
Erik Kline2c5aaa12016-06-08 13:24:45 +090059 bool applyDnsInterfaces();
Lorenzo Colitti799625c2015-02-25 12:52:00 +090060 bool setIpFwdEnabled();
San Mehat9d10b342010-01-18 09:51:02 -080061};
62
63#endif