blob: edd6770b7525f3a6dd6369f1a15450aa74e3d716 [file] [log] [blame]
Pierre Imai1cfa5432016-02-24 18:00:03 +09001/*
2 * Copyright (C) 2016 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 _CONTROLLERS_H__
18#define _CONTROLLERS_H__
19
Pierre Imai1cfa5432016-02-24 18:00:03 +090020#include "BandwidthController.h"
Nathan Harold1a371532017-01-30 12:30:48 -080021#include "ClatdController.h"
22#include "EventReporter.h"
23#include "FirewallController.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090024#include "IdletimerController.h"
25#include "InterfaceController.h"
Narayan Kamatha5ace892017-01-06 15:10:02 +000026#include "IptablesRestoreController.h"
Nathan Harold1a371532017-01-30 12:30:48 -080027#include "NetworkController.h"
28#include "PppController.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090029#include "ResolverController.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090030#include "StrictController.h"
Erik Klineb31fd692018-06-06 20:50:11 +090031#include "TcpSocketMonitor.h"
Nathan Harold1a371532017-01-30 12:30:48 -080032#include "TetherController.h"
Chenbo Fengf2759682017-10-10 17:31:57 -070033#include "TrafficController.h"
Joel Scherpelz08b84cd2017-05-22 13:11:54 +090034#include "WakeupController.h"
Nathan Harold1a371532017-01-30 12:30:48 -080035#include "XfrmController.h"
Erik Klineb31fd692018-06-06 20:50:11 +090036#include "netdutils/Log.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090037
38namespace android {
39namespace net {
40
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090041class Controllers {
Erik Klineb31fd692018-06-06 20:50:11 +090042 public:
Pierre Imai1cfa5432016-02-24 18:00:03 +090043 Controllers();
44
45 NetworkController netCtrl;
46 TetherController tetherCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090047 PppController pppCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090048 BandwidthController bandwidthCtrl;
49 IdletimerController idletimerCtrl;
50 ResolverController resolverCtrl;
51 FirewallController firewallCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090052 ClatdController clatdCtrl;
53 StrictController strictCtrl;
Michal Karpinskid5440112016-10-06 16:56:04 +010054 EventReporter eventReporter;
Narayan Kamatha5ace892017-01-06 15:10:02 +000055 IptablesRestoreController iptablesRestoreCtrl;
Joel Scherpelz08b84cd2017-05-22 13:11:54 +090056 WakeupController wakeupCtrl;
Nathan Harold1a371532017-01-30 12:30:48 -080057 XfrmController xfrmCtrl;
Chenbo Fengf2759682017-10-10 17:31:57 -070058 TrafficController trafficCtrl;
Hugo Benichi7b314e12018-01-15 21:54:00 +090059 TcpSocketMonitor tcpSocketMonitor;
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090060
61 void init();
62
Erik Klineb31fd692018-06-06 20:50:11 +090063 private:
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090064 friend class ControllersTest;
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090065 void initIptablesRules();
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090066 static void initChildChains();
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090067 static std::set<std::string> findExistingChildChains(const IptablesTarget target,
68 const char* table,
69 const char* parentChain);
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090070 static void createChildChains(IptablesTarget target, const char* table, const char* parentChain,
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090071 const std::vector<const char*>& childChains, bool exclusive);
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090072 static int (*execIptablesRestore)(IptablesTarget, const std::string&);
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090073 static int (*execIptablesRestoreWithOutput)(IptablesTarget, const std::string&, std::string *);
Pierre Imai1cfa5432016-02-24 18:00:03 +090074};
75
Erik Klineb31fd692018-06-06 20:50:11 +090076extern netdutils::Log gLog;
Pierre Imai1cfa5432016-02-24 18:00:03 +090077extern Controllers* gCtls;
78
79} // namespace net
80} // namespace android
81
82#endif // _CONTROLLERS_H__