blob: 8b51ddf12959d40c74126643eb04eef1b8b8be51 [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 "EventReporter.h"
22#include "FirewallController.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090023#include "IdletimerController.h"
24#include "InterfaceController.h"
Narayan Kamatha5ace892017-01-06 15:10:02 +000025#include "IptablesRestoreController.h"
Nathan Harold1a371532017-01-30 12:30:48 -080026#include "NetworkController.h"
27#include "PppController.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090028#include "StrictController.h"
Erik Klineb31fd692018-06-06 20:50:11 +090029#include "TcpSocketMonitor.h"
Nathan Harold1a371532017-01-30 12:30:48 -080030#include "TetherController.h"
Joel Scherpelz08b84cd2017-05-22 13:11:54 +090031#include "WakeupController.h"
Nathan Harold1a371532017-01-30 12:30:48 -080032#include "XfrmController.h"
Erik Klineb31fd692018-06-06 20:50:11 +090033#include "netdutils/Log.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090034
35namespace android {
36namespace net {
37
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090038class Controllers {
Erik Klineb31fd692018-06-06 20:50:11 +090039 public:
Pierre Imai1cfa5432016-02-24 18:00:03 +090040 Controllers();
41
42 NetworkController netCtrl;
43 TetherController tetherCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090044 PppController pppCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090045 BandwidthController bandwidthCtrl;
46 IdletimerController idletimerCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090047 FirewallController firewallCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090048 StrictController strictCtrl;
Michal Karpinskid5440112016-10-06 16:56:04 +010049 EventReporter eventReporter;
Narayan Kamatha5ace892017-01-06 15:10:02 +000050 IptablesRestoreController iptablesRestoreCtrl;
Joel Scherpelz08b84cd2017-05-22 13:11:54 +090051 WakeupController wakeupCtrl;
Nathan Harold1a371532017-01-30 12:30:48 -080052 XfrmController xfrmCtrl;
Hugo Benichi7b314e12018-01-15 21:54:00 +090053 TcpSocketMonitor tcpSocketMonitor;
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090054
55 void init();
56
Erik Klineb31fd692018-06-06 20:50:11 +090057 private:
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090058 friend class ControllersTest;
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090059 void initIptablesRules();
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090060 static void initChildChains();
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090061 static std::set<std::string> findExistingChildChains(const IptablesTarget target,
62 const char* table,
63 const char* parentChain);
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090064 static void createChildChains(IptablesTarget target, const char* table, const char* parentChain,
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090065 const std::vector<const char*>& childChains, bool exclusive);
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090066 static int (*execIptablesRestore)(IptablesTarget, const std::string&);
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090067 static int (*execIptablesRestoreWithOutput)(IptablesTarget, const std::string&, std::string *);
Pierre Imai1cfa5432016-02-24 18:00:03 +090068};
69
Erik Klineb31fd692018-06-06 20:50:11 +090070extern netdutils::Log gLog;
Luke Huang528af602018-08-29 19:06:05 +080071extern netdutils::Log gUnsolicitedLog;
Pierre Imai1cfa5432016-02-24 18:00:03 +090072extern Controllers* gCtls;
73
74} // namespace net
75} // namespace android
76
77#endif // _CONTROLLERS_H__