blob: fbd9bf157e4eadf009afbedfe81e60a6efa3f09a [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 "StrictController.h"
Erik Klineb31fd692018-06-06 20:50:11 +090030#include "TcpSocketMonitor.h"
Nathan Harold1a371532017-01-30 12:30:48 -080031#include "TetherController.h"
Chenbo Fengf2759682017-10-10 17:31:57 -070032#include "TrafficController.h"
Joel Scherpelz08b84cd2017-05-22 13:11:54 +090033#include "WakeupController.h"
Nathan Harold1a371532017-01-30 12:30:48 -080034#include "XfrmController.h"
Erik Klineb31fd692018-06-06 20:50:11 +090035#include "netdutils/Log.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090036
37namespace android {
38namespace net {
39
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090040class Controllers {
Erik Klineb31fd692018-06-06 20:50:11 +090041 public:
Pierre Imai1cfa5432016-02-24 18:00:03 +090042 Controllers();
43
44 NetworkController netCtrl;
45 TetherController tetherCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090046 PppController pppCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090047 BandwidthController bandwidthCtrl;
48 IdletimerController idletimerCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090049 FirewallController firewallCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090050 ClatdController clatdCtrl;
51 StrictController strictCtrl;
Michal Karpinskid5440112016-10-06 16:56:04 +010052 EventReporter eventReporter;
Narayan Kamatha5ace892017-01-06 15:10:02 +000053 IptablesRestoreController iptablesRestoreCtrl;
Joel Scherpelz08b84cd2017-05-22 13:11:54 +090054 WakeupController wakeupCtrl;
Nathan Harold1a371532017-01-30 12:30:48 -080055 XfrmController xfrmCtrl;
Chenbo Fengf2759682017-10-10 17:31:57 -070056 TrafficController trafficCtrl;
Hugo Benichi7b314e12018-01-15 21:54:00 +090057 TcpSocketMonitor tcpSocketMonitor;
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090058
59 void init();
60
Erik Klineb31fd692018-06-06 20:50:11 +090061 private:
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090062 friend class ControllersTest;
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090063 void initIptablesRules();
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090064 static void initChildChains();
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090065 static std::set<std::string> findExistingChildChains(const IptablesTarget target,
66 const char* table,
67 const char* parentChain);
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090068 static void createChildChains(IptablesTarget target, const char* table, const char* parentChain,
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090069 const std::vector<const char*>& childChains, bool exclusive);
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090070 static int (*execIptablesRestore)(IptablesTarget, const std::string&);
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090071 static int (*execIptablesRestoreWithOutput)(IptablesTarget, const std::string&, std::string *);
Pierre Imai1cfa5432016-02-24 18:00:03 +090072};
73
Erik Klineb31fd692018-06-06 20:50:11 +090074extern netdutils::Log gLog;
Luke Huang528af602018-08-29 19:06:05 +080075extern netdutils::Log gUnsolicitedLog;
Pierre Imai1cfa5432016-02-24 18:00:03 +090076extern Controllers* gCtls;
77
78} // namespace net
79} // namespace android
80
81#endif // _CONTROLLERS_H__