1/*
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>
21
22#include "BandwidthController.h"
23#include "ClatdController.h"
24#include "EventReporter.h"
25#include "FirewallController.h"
26#include "IdletimerController.h"
27#include "InterfaceController.h"
28#include "IptablesRestoreController.h"
29#include "NatController.h"
30#include "NetworkController.h"
31#include "PppController.h"
32#include "ResolverController.h"
33#include "StrictController.h"
34#include "TetherController.h"
35#include "WakeupController.h"
36#include "XfrmController.h"
37
38namespace android {
39namespace net {
40
41class Controllers {
42public:
43    Controllers();
44
45    NetworkController netCtrl;
46    TetherController tetherCtrl;
47    NatController natCtrl;
48    PppController pppCtrl;
49    BandwidthController bandwidthCtrl;
50    IdletimerController idletimerCtrl;
51    ResolverController resolverCtrl;
52    FirewallController firewallCtrl;
53    ClatdController clatdCtrl;
54    StrictController strictCtrl;
55    EventReporter eventReporter;
56    IptablesRestoreController iptablesRestoreCtrl;
57    WakeupController wakeupCtrl;
58    XfrmController xfrmCtrl;
59
60    void init();
61
62private:
63    friend class ControllersTest;
64    void initIptablesRules();
65    static void initChildChains();
66    static std::set<std::string> findExistingChildChains(const IptablesTarget target,
67                                                         const char* table,
68                                                         const char* parentChain);
69    static void createChildChains(IptablesTarget target, const char* table, const char* parentChain,
70                                  const std::vector<const char*>& childChains, bool exclusive);
71    static int (*execIptablesRestore)(IptablesTarget, const std::string&);
72    static int (*execIptablesRestoreWithOutput)(IptablesTarget, const std::string&, std::string *);
73};
74
75extern Controllers* gCtls;
76
77}  // namespace net
78}  // namespace android
79
80#endif  // _CONTROLLERS_H__
81