blob: ac17ef21fdc47f1e6c0f444703232923262ef608 [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
20#include <sysutils/FrameworkListener.h>
Lorenzo Colittiddf2d5b2016-02-26 11:30:59 +090021
Pierre Imai1cfa5432016-02-24 18:00:03 +090022#include "BandwidthController.h"
Nathan Harold1a371532017-01-30 12:30:48 -080023#include "ClatdController.h"
24#include "EventReporter.h"
25#include "FirewallController.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090026#include "IdletimerController.h"
27#include "InterfaceController.h"
Narayan Kamatha5ace892017-01-06 15:10:02 +000028#include "IptablesRestoreController.h"
Nathan Harold1a371532017-01-30 12:30:48 -080029#include "NetworkController.h"
30#include "PppController.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090031#include "ResolverController.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090032#include "StrictController.h"
Erik Klineb31fd692018-06-06 20:50:11 +090033#include "TcpSocketMonitor.h"
Nathan Harold1a371532017-01-30 12:30:48 -080034#include "TetherController.h"
Chenbo Fengf2759682017-10-10 17:31:57 -070035#include "TrafficController.h"
Joel Scherpelz08b84cd2017-05-22 13:11:54 +090036#include "WakeupController.h"
Nathan Harold1a371532017-01-30 12:30:48 -080037#include "XfrmController.h"
Erik Klineb31fd692018-06-06 20:50:11 +090038#include "netdutils/Log.h"
Pierre Imai1cfa5432016-02-24 18:00:03 +090039
40namespace android {
41namespace net {
42
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090043class Controllers {
Erik Klineb31fd692018-06-06 20:50:11 +090044 public:
Pierre Imai1cfa5432016-02-24 18:00:03 +090045 Controllers();
46
47 NetworkController netCtrl;
48 TetherController tetherCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090049 PppController pppCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090050 BandwidthController bandwidthCtrl;
51 IdletimerController idletimerCtrl;
52 ResolverController resolverCtrl;
53 FirewallController firewallCtrl;
Pierre Imai1cfa5432016-02-24 18:00:03 +090054 ClatdController clatdCtrl;
55 StrictController strictCtrl;
Michal Karpinskid5440112016-10-06 16:56:04 +010056 EventReporter eventReporter;
Narayan Kamatha5ace892017-01-06 15:10:02 +000057 IptablesRestoreController iptablesRestoreCtrl;
Joel Scherpelz08b84cd2017-05-22 13:11:54 +090058 WakeupController wakeupCtrl;
Nathan Harold1a371532017-01-30 12:30:48 -080059 XfrmController xfrmCtrl;
Chenbo Fengf2759682017-10-10 17:31:57 -070060 TrafficController trafficCtrl;
Hugo Benichi7b314e12018-01-15 21:54:00 +090061 TcpSocketMonitor tcpSocketMonitor;
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090062
63 void init();
64
Erik Klineb31fd692018-06-06 20:50:11 +090065 private:
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090066 friend class ControllersTest;
Lorenzo Colitti1ed96e22017-02-02 12:21:56 +090067 void initIptablesRules();
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090068 static void initChildChains();
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090069 static std::set<std::string> findExistingChildChains(const IptablesTarget target,
70 const char* table,
71 const char* parentChain);
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090072 static void createChildChains(IptablesTarget target, const char* table, const char* parentChain,
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090073 const std::vector<const char*>& childChains, bool exclusive);
Lorenzo Colitti341d3a02017-08-08 17:31:35 +090074 static int (*execIptablesRestore)(IptablesTarget, const std::string&);
Lorenzo Colittiadc3a5f2017-08-08 17:23:12 +090075 static int (*execIptablesRestoreWithOutput)(IptablesTarget, const std::string&, std::string *);
Pierre Imai1cfa5432016-02-24 18:00:03 +090076};
77
Erik Klineb31fd692018-06-06 20:50:11 +090078extern netdutils::Log gLog;
Pierre Imai1cfa5432016-02-24 18:00:03 +090079extern Controllers* gCtls;
80
81} // namespace net
82} // namespace android
83
84#endif // _CONTROLLERS_H__