6e883447ea2678b3d7d8d4e27adc6bf17404497b
[platform/core/security/nether.git] / include / nether_Manager.h
1 /*
2  *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Roman Kubiak (r.kubiak@samsung.com)
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18
19 /**
20  * @file
21  * @author  Roman Kubiak (r.kubiak@samsung.com)
22  * @brief   Manager class implementation for nether
23  */
24
25 #ifndef NETHER_MANAGER_H
26 #define NETHER_MANAGER_H
27
28 #include "nether_Types.h"
29 #include "nether_DummyBackend.h"
30 #include "nether_Netlink.h"
31
32
33 class NetherManager : public NetherVerdictListener, public NetherProcessedPacketListener
34 {
35         public:
36                 NetherManager(const NetherConfig &_netherConfig);
37                 ~NetherManager();
38                 bool initialize();
39                 bool process();
40                 NetherConfig &getConfig();
41                 static NetherPolicyBackend *getPolicyBackend(const NetherConfig &netherConfig, const bool primary = true);
42                 bool verdictCast(const u_int32_t packetId, const NetherVerdict verdict, int mark);
43                 void packetReceived(const NetherPacket &packet);
44                 bool restoreRules();
45
46         private:
47                 static bool isCommandAvailable(const std::string &command);
48                 void handleSignal();
49                 bool handleNetlinkpacket();
50                 void setupSelectSockets(fd_set &watchedReadDescriptorsSet, fd_set &watchedWriteDescriptorsSet, struct timeval &timeoutSpecification);
51                 std::unique_ptr <NetherPolicyBackend> netherPrimaryPolicyBackend;
52                 std::unique_ptr <NetherPolicyBackend> netherBackupPolicyBackend;
53                 std::unique_ptr <NetherPolicyBackend> netherFallbackPolicyBackend;
54                 std::unique_ptr <NetherNetlink> netherNetlink;
55                 NetherConfig netherConfig;
56                 int netlinkDescriptor;
57                 int backendDescriptor;
58                 int signalDescriptor;
59 #ifdef HAVE_AUDIT
60                 int auditDescriptor;
61 #endif // HAVE_AUDIT
62                 sigset_t signalMask;
63 };
64
65 #endif