Added the README.md file for github 90/44090/4
authorRomanKubiak <r.kubiak@samsung.com>
Thu, 16 Jul 2015 14:57:24 +0000 (16:57 +0200)
committerRomanKubiak <r.kubiak@samsung.com>
Fri, 17 Jul 2015 10:01:03 +0000 (12:01 +0200)
Added license info to files
Using unique_ptr<> in manager
Broke up the process() method in manager

Change-Id: I980d281d7decae6d1e23b9f5937117449ac627e3

22 files changed:
README.md [new file with mode: 0644]
config/setrules.sh [changed mode: 0755->0644]
include/logger/backend-file.hpp
include/logger/backend-syslog.hpp
include/nether_CynaraBackend.h
include/nether_FileBackend.h
include/nether_Manager.h
include/nether_Netlink.h
include/nether_PolicyBackend.h
include/nether_Types.h
include/nether_Utils.h
nether.cbp
src/CMakeLists.txt
src/logger/backend-file.cpp
src/logger/backend-journal.cpp
src/logger/backend-syslog.cpp
src/nether_CynaraBackend.cpp
src/nether_FileBackend.cpp
src/nether_Main.cpp
src/nether_Manager.cpp
src/nether_Netlink.cpp
src/nether_NetworkUtils.cpp

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..58650fa
--- /dev/null
+++ b/README.md
@@ -0,0 +1,15 @@
+# nether
+
+An application firewall that enforces the "internet"
+privileges in Tizen. It uses Cynara as a policy backend
+and the NFQUEUE target in netfilter to make decisiions
+about outgoing connections and network packets.
+
+The policy backend can be re-implemented by overloading
+the NetherPolicyBackend class (there is a simple File based
+backend included for testing).
+
+A default policy can be specified in case the policy
+backend stops working.
+
+
old mode 100755 (executable)
new mode 100644 (file)
index 94e6e40..9c2d168
@@ -1,3 +1,20 @@
+#
+#  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#  Contact: Roman Kubiak (r.kubiak@samsung.com)
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License
+#
 #!/bin/bash
 DENY_CHAIN="NETHER-DENY"
 ALLOWLOG_CHAIN="NETHER-ALLOWLOG"
@@ -30,7 +47,7 @@ function clean {
 function create {
        echo "Creating chain"
        echo
-       runcmd iptables -N $DENY_CHAIN  
+       runcmd iptables -N $DENY_CHAIN
        runcmd iptables -N $ALLOWLOG_CHAIN
        runcmd iptables -A $DENY_CHAIN -j AUDIT --type REJECT
        runcmd iptables -A $DENY_CHAIN -j REJECT
index 9a108d101eccae4797d0733dfbb4b4ffbea2fc7f..2fc4822c20b146c04b211bf3df526bca5df11839 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   File backend for logger
+ */
+
 #ifndef COMMON_LOGGER_BACKEND_FILE_HPP
 #define COMMON_LOGGER_BACKEND_FILE_HPP
 
@@ -7,14 +31,14 @@ namespace logger {
 
 class FileBackend : public LogBackend {
 public:
-    FileBackend(const std::string &_filePath) : filePath(_filePath) {}
+    FileBackend(const std::string &filePath) : mfilePath(filePath) {}
     void log(LogLevel logLevel,
              const std::string& file,
              const unsigned int& line,
              const std::string& func,
              const std::string& message) override;
 private:
-    std::string filePath;
+    std::string mfilePath;
 };
 
 } // namespace logger
index 23450b54f15cf303e33c1f572e60e046dfde227c..045fdec313288abc48494cace66f0070dafad187 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   Syslog backend for logger
+ */
+
 #ifndef COMMON_LOGGER_BACKEND_SYSLOG_HPP
 #define COMMON_LOGGER_BACKEND_SYSLOG_HPP
 
index 12427974fb88b37d53443ef7344db1158b513973..a8bc88e5bd44d608011c73d8eb1c0cca85cb1924 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   Cynara policy backend for nether
+ */
+
 #ifndef NETHER_CYNARA_BACKEND_H
 #define NETHER_CYNARA_BACKEND_H
 
index 4060153ec2b9a733c52fadb7ad1ef5efca288d56..213b87f3dee0ec7dc3d74c6523fb7170a31b46c8 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   File policy backend for nether
+ */
+
 #ifndef NETHER_FILE_BACKEND_H
 #define NETHER_FILE_BACKEND_H
 
index 8e58d56c114293789161649377df2b57cd66f776..aa8630e5a8bb38bb801e23588b3ed14d2accb708 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   Manager class implementation for nether
+ */
+
 #ifndef NETHER_MANAGER_H
 #define NETHER_MANAGER_H
 
@@ -19,9 +43,11 @@ class NetherManager : public NetherVerdictListener, public NetherProcessedPacket
         void packetReceived (const NetherPacket &packet);
 
     private:
-        NetherPolicyBackend *netherPrimaryPolicyBackend, *netherBackupPolicyBackend;
-        NetherDummyBackend *netherFallbackPolicyBackend;
-        NetherNetlink *netherNetlink;
+        void handleSignal();
+        const bool handleNetlinkpacket();
+        void setupSelectSockets(fd_set &watchedReadDescriptorsSet, fd_set &watchedWriteDescriptorsSet, struct timeval &timeoutSpecification);
+        std::unique_ptr <NetherPolicyBackend> netherPrimaryPolicyBackend, netherBackupPolicyBackend, netherFallbackPolicyBackend;
+        std::unique_ptr <NetherNetlink> netherNetlink;
         NetherConfig netherConfig;
         int netlinkDescriptor, backendDescriptor, signalDescriptor;
         sigset_t signalMask;
index 8b934a7a9de579bcf364f4b414e27d2eb26ddde6..eac959ca0fdbcb93c16f0702b4fdc791367ff0d3 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   netlink handler class for nether
+ */
+
 #ifndef NETHER_NETLINK_H\r
 #define NETHER_NETLINK_H\r
 \r
index 55879bf7cbe88934f5969d6d459e6232835d3ec3..222780c4a2ae3d003ea21a50a7ebd3724791a916 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   definition of a policy backend class
+ */
+
 #ifndef NETHER_POLICY_BACKEND_H
 #define NETHER_POLICY_BACKEND_H
 
index 624abe8b9d90afacf80f4dbda58c9f1be813fa60..e3ce8c0a7207d7a073baceff53e02b1c7741d47c 100644 (file)
@@ -1,3 +1,28 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   types used in nether
+ */
+
+
 #ifndef NETHER_TYPES_H
 #define NETHER_TYPES_H
 
index 5d654e9fe975933d5ec6752337b0f9d44f7680a4..90505a4de4a7fc8b80a8fdeada1bcedbd1e6db45 100644 (file)
@@ -1,3 +1,28 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   utility functions
+ */
+
+
 #ifndef NETHER_UTILS_H
 #define NETHER_UTILS_H
 #include "nether_Types.h"
index aeedfa53e220bef6eb4bed89a89bcc0d8d9852b8..5ee498d7154ee83e128614dc4959c0ab9d3f3d58 100644 (file)
                        <Add option="-fexceptions" />
                        <Add option="-fPIC" />
                </Compiler>
+               <Unit filename="CMakeLists.txt" />
+               <Unit filename="config/nether.policy" />
+               <Unit filename="config/nether.rules" />
+               <Unit filename="config/setrules.sh" />
                <Unit filename="include/logger/backend-file.hpp" />
                <Unit filename="include/logger/backend-journal.hpp" />
                <Unit filename="include/logger/backend-null.hpp" />
@@ -89,6 +93,9 @@
                <Unit filename="include/nether_PolicyBackend.h" />
                <Unit filename="include/nether_Types.h" />
                <Unit filename="include/nether_Utils.h" />
+               <Unit filename="packaging/nether.manifest" />
+               <Unit filename="packaging/nether.spec" />
+               <Unit filename="src/CMakeLists.txt" />
                <Unit filename="src/logger/backend-file.cpp" />
                <Unit filename="src/logger/backend-journal.cpp" />
                <Unit filename="src/logger/backend-stderr.cpp" />
                <Unit filename="src/logger/logger-scope.cpp" />
                <Unit filename="src/logger/logger.cpp" />
                <Unit filename="src/nether_CynaraBackend.cpp" />
-               <Unit filename="src/nether_DummyBackend.cpp" />
                <Unit filename="src/nether_FileBackend.cpp" />
                <Unit filename="src/nether_Main.cpp" />
                <Unit filename="src/nether_Manager.cpp" />
index 3585b3dea5d7f31745e301e676a66ed6b57573c0..d6bc87350e7489f79136e205a2261af3c0e53c60 100644 (file)
@@ -6,13 +6,13 @@ PKG_CHECK_MODULES (LOGGER libsystemd-journal QUIET)
 
 ADD_EXECUTABLE(nether ${NETHER_SOURCES} ${VASUM_LOGGER})
 
-INCLUDE_DIRECTORIES (
-                       ../include
-                       ${EXTERNAL_INCLUDE_DIRS} 
-                       ${CYNARA_INCLUDE_DIRS}
-                       ${NETFILTER_INCLUDE_DIRS}
-                       ${LOGGER_INCLUDE_DIRS}
-               )
+INCLUDE_DIRECTORIES(../include
+    ${EXTERNAL_INCLUDE_DIRS}
+    ${CYNARA_INCLUDE_DIRS}
+    ${NETFILTER_INCLUDE_DIRS}
+    ${LOGGER_INCLUDE_DIRS}
+)
+
 if(CYNARA_FOUND)
        ADD_DEFINITIONS (-DHAVE_CYNARA=${CYNARA_FOUND})
 endif()
@@ -25,6 +25,7 @@ IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
        ADD_DEFINITIONS (-D_DEBUG=1)
 ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)
 
-TARGET_LINK_LIBRARIES(nether   ${CYNARA_LIBRARIES} 
-                               ${NETFILTER_LIBRARIES}
-                               ${LOGGER_LIBRARIES} )
\ No newline at end of file
+TARGET_LINK_LIBRARIES(nether ${CYNARA_LIBRARIES}
+    ${NETFILTER_LIBRARIES}
+    ${LOGGER_LIBRARIES}
+)
index fcfd1bf615b1d23014337b30395f51fd39feece1..f5828e840baa3d549448c36668fd72d62de2244a 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   File backend for logger
+ */
+
 #include "logger/config.hpp"
 #include "logger/formatter.hpp"
 #include "logger/backend-file.hpp"
@@ -12,11 +36,11 @@ void FileBackend::log(LogLevel logLevel,
                                 const std::string& func,
                                 const std::string& message)
 {
-    std::ofstream out(filePath, std::ios::app);
+    std::ofstream out(mfilePath, std::ios::app);
     out << LogFormatter::getHeader(logLevel, file, line, func);
     out << message;
-    out << "\n";
+    out << std::endl;
 }
 
 
-}
+} // namespace logger
index 85cb46fb0e25f59c49f90215bf903bfeb346d781..af147cdc95fad2425b3e252e3d290f45a8fe65c2 100644 (file)
@@ -69,4 +69,4 @@ void SystemdJournalBackend::log(LogLevel logLevel,
 }
 
 } // namespace logger
-#endif
\ No newline at end of file
+#endif // HAVE_SYSTEMD_JOURNAL
index 0542e46dca590cf93a410d5592dff139c83375a7..42e8ca0cbda919643a4defe850d0b2ce24fcd0c3 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   Syslog backend for logger
+ */
+
 #include "logger/config.hpp"
 #include "logger/formatter.hpp"
 #include "logger/backend-syslog.hpp"
@@ -39,4 +63,4 @@ void SyslogBackend::log(LogLevel logLevel,
     syslog(toSyslogPriority(logLevel), "%s %s", LogFormatter::getHeader(logLevel, file, line, func).c_str(), message.c_str());
 }
 
-}
+} // namespace logger
index 10b426e17cb8827f93e14dad7ea136268f476134..e3ec282663195574b116ab1d9bd08d1755407696 100644 (file)
@@ -1,6 +1,30 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   Cynara policy backend for nether
+ */
+
 #include "nether_CynaraBackend.h"
 
-// #ifdef HAVE_CYNARA
+#ifdef HAVE_CYNARA
 
 NetherCynaraBackend::NetherCynaraBackend(const NetherConfig &netherConfig)
     :   NetherPolicyBackend(netherConfig), currentCynaraDescriptor(0),
@@ -153,4 +177,4 @@ const bool NetherCynaraBackend::processEvents()
     LOGW("cynara_async_process failed " << cynaraErrorCodeToString(ret));
     return (false);
 }
-//#endif
+#endif
index b73281e43877118f60f356be355e1a442d61de61..a6c6f816857fc2aeeb361f5243d0c368555ee7fb 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   File policy backend for nether
+ */
+
 #include "nether_FileBackend.h"
 
 NetherFileBackend::NetherFileBackend (const NetherConfig &netherConfig)
index 1ab5e9bd8bd369b6c0607190fba00ec4677c3386..08b98fafc78cd686224cac86c5e7e6e3997c72b6 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   nether main program
+ */
+
 #include "nether_Types.h"
 #include "nether_Utils.h"
 #include "nether_Manager.h"
@@ -114,6 +138,11 @@ int main(int argc, char *argv[])
         case logfileBackend:
             logger::Logger::setLogBackend (new logger::FileBackend(netherConfig.logBackendArgs));
             break;
+#if defined(HAVE_SYSTEMD_JOURNAL)
+        case journalBackend:
+            logger::Logger::setLogBackend (new logger::SystemdJournalBackend());
+            break;
+#endif
         default:
             logger::Logger::setLogBackend (new logger::StderrBackend(false));
             break;
index 0ec0ae676e81c0897d762879deba3f2f3c298bc3..5f78bdfc80f5f76bf530675a9f3ad0867fe9f063 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   Manager class implementation for nether
+ */
+
 #include "nether_Manager.h"
 #include "nether_CynaraBackend.h"
 #include "nether_FileBackend.h"
@@ -9,24 +33,20 @@ NetherManager::NetherManager(const NetherConfig &_netherConfig)
         netherBackupPolicyBackend(nullptr),
         netherFallbackPolicyBackend(nullptr)
 {
-    netherNetlink               = new NetherNetlink(netherConfig);
+    netherNetlink               = std::unique_ptr<NetherNetlink> (new NetherNetlink(netherConfig));
     netherNetlink->setListener (this);
 
-    netherPrimaryPolicyBackend = getPolicyBackend (netherConfig);
+    netherPrimaryPolicyBackend = std::unique_ptr<NetherPolicyBackend> (getPolicyBackend (netherConfig));
     netherPrimaryPolicyBackend->setListener (this);
 
-    netherBackupPolicyBackend   = getPolicyBackend (netherConfig, false);
+    netherBackupPolicyBackend   = std::unique_ptr<NetherPolicyBackend> (getPolicyBackend (netherConfig, false));
     netherBackupPolicyBackend->setListener (this);
 
-    netherFallbackPolicyBackend = new NetherDummyBackend(netherConfig);
+    netherFallbackPolicyBackend = std::unique_ptr<NetherPolicyBackend> (new NetherDummyBackend(netherConfig));
 }
 
 NetherManager::~NetherManager()
 {
-    deleteAndZero (netherPrimaryPolicyBackend);
-    deleteAndZero (netherBackupPolicyBackend);
-    deleteAndZero (netherFallbackPolicyBackend);
-    deleteAndZero (netherNetlink);
     close (signalDescriptor);
 }
 
@@ -80,43 +100,13 @@ const bool NetherManager::initialize()
 }
 
 const bool NetherManager::process()
-{
-    NetherPacket receivedPacket;
-    int packetReadSize;
-    ssize_t signalRead;
-    struct signalfd_siginfo signalfdSignalInfo;\r
+{\r
     fd_set watchedReadDescriptorsSet, watchedWriteDescriptorsSet;\r
     struct timeval timeoutSpecification;\r
-    char packetBuffer[NETHER_PACKET_BUFFER_SIZE] __attribute__ ((aligned));\r
 \r
-    while (1)\r
+    for (;;)\r
     {\r
-           FD_ZERO (&watchedReadDescriptorsSet);
-           FD_ZERO (&watchedWriteDescriptorsSet);
-
-        /* Always listen for signals */
-        FD_SET (signalDescriptor, &watchedReadDescriptorsSet);
-
-           if ((netlinkDescriptor = netherNetlink->getDescriptor()) >= 0)
-        {\r
-            FD_SET(netlinkDescriptor, &watchedReadDescriptorsSet);
-        }
-
-        if ((backendDescriptor = netherPrimaryPolicyBackend->getDescriptor()) >= 0)
-        {
-            if (netherPrimaryPolicyBackend->getDescriptorStatus() == readOnly)
-            {
-                FD_SET(backendDescriptor, &watchedReadDescriptorsSet);
-            }
-            else if (netherPrimaryPolicyBackend->getDescriptorStatus() == readWrite)
-            {
-                FD_SET(backendDescriptor, &watchedReadDescriptorsSet);
-                FD_SET(backendDescriptor, &watchedWriteDescriptorsSet);
-            }
-        }
-\r
-           timeoutSpecification.tv_sec     = 240;\r
-        timeoutSpecification.tv_usec    = 0;
+           setupSelectSockets (watchedReadDescriptorsSet, watchedWriteDescriptorsSet, timeoutSpecification);
 \r
         if (select (FD_SETSIZE, &watchedReadDescriptorsSet, &watchedWriteDescriptorsSet, NULL, &timeoutSpecification) < 0)\r
         {\r
@@ -126,60 +116,15 @@ const bool NetherManager::process()
 
         if (FD_ISSET(signalDescriptor, &watchedReadDescriptorsSet))
         {
-            LOGD("received signal");
-            signalRead = read (signalDescriptor, &signalfdSignalInfo, sizeof(struct signalfd_siginfo));
-
-            if (signalRead != sizeof(struct signalfd_siginfo))
-            {
-                LOGW("Received incomplete signal information, ignore");
-                continue;
-            }
-
-            if (signalfdSignalInfo.ssi_signo == SIGHUP)
-            {
-                LOGI("SIGHUP received, reloading");
-                if (!netherPrimaryPolicyBackend->reload())
-                    LOGW("primary backend failed to reload");
-                if (!netherBackupPolicyBackend->reload())
-                    LOGW("backup backend failed to reload");
-                if (!netherNetlink->reload())
-                    LOGW("netlink failed to reload");
-                continue;
-            }
+            handleSignal();
         }\r
         if (FD_ISSET(netlinkDescriptor, &watchedReadDescriptorsSet))\r
         {
-            LOGD("netlink descriptor active");
-
-            /* some data arrives on netlink, read it */\r
-            if ((packetReadSize = recv(netlinkDescriptor, packetBuffer, sizeof(packetBuffer), 0)) >= 0)\r
-            {
-                /* try to process the packet using netfilter_queue library, fetch packet info
-                    needed for making a decision about it */\r
-                if (netherNetlink->processPacket (packetBuffer, packetReadSize))
-                {
-                   continue;
-                }
-                else
-                {
-                    /* if we can't process the incoming packets, it's bad. Let's exit now */
-                    LOGE("Failed to process netlink received packet, refusing to continue");
-                    break;
-                }\r
-            }
-\r
-            if (packetReadSize < 0 && errno == ENOBUFS)\r
-            {\r
-                LOGI("NetherManager::process losing packets! [bad things might happen]");\r
-                continue;\r
-            }\r
-\r
-            LOGE("NetherManager::process recv failed " << strerror(errno));\r
-            break;\r
+            if (!handleNetlinkpacket())
+                break;\r
         }
         else if (FD_ISSET(backendDescriptor, &watchedReadDescriptorsSet) || FD_ISSET(backendDescriptor, &watchedWriteDescriptorsSet))
         {
-            LOGD("policy backend descriptor active");
             netherPrimaryPolicyBackend->processEvents();
         }
         else
@@ -189,6 +134,96 @@ const bool NetherManager::process()
     }
 }
 
+void NetherManager::handleSignal()
+{
+    LOGD("received signal");
+    ssize_t signalRead;
+    struct signalfd_siginfo signalfdSignalInfo;
+
+    signalRead = read (signalDescriptor, &signalfdSignalInfo, sizeof(struct signalfd_siginfo));
+
+    if (signalRead != sizeof(struct signalfd_siginfo))
+    {
+        LOGW("Received incomplete signal information, ignore");
+        return;
+    }
+
+    if (signalfdSignalInfo.ssi_signo == SIGHUP)
+    {
+        LOGI("SIGHUP received, reloading");
+        if (!netherPrimaryPolicyBackend->reload())
+            LOGW("primary backend failed to reload");
+        if (!netherBackupPolicyBackend->reload())
+            LOGW("backup backend failed to reload");
+        if (!netherNetlink->reload())
+            LOGW("netlink failed to reload");
+    }
+}
+
+const bool NetherManager::handleNetlinkpacket()
+{
+    LOGD("netlink descriptor active");
+    int packetReadSize;
+    NetherPacket receivedPacket;
+    char packetBuffer[NETHER_PACKET_BUFFER_SIZE] __attribute__ ((aligned));
+
+    /* some data arrives on netlink, read it */\r
+    if ((packetReadSize = recv(netlinkDescriptor, packetBuffer, sizeof(packetBuffer), 0)) >= 0)\r
+    {
+        /* try to process the packet using netfilter_queue library, fetch packet info
+            needed for making a decision about it */\r
+        if (netherNetlink->processPacket (packetBuffer, packetReadSize))
+        {
+            return (true);
+        }
+        else
+        {
+            /* if we can't process the incoming packets, it's bad. Let's exit now */
+            LOGE("Failed to process netlink received packet, refusing to continue");
+            return (false);
+        }\r
+    }
+\r
+    if (packetReadSize < 0 && errno == ENOBUFS)\r
+    {\r
+        LOGI("NetherManager::process losing packets! [bad things might happen]");\r
+        return (true);\r
+    }\r
+\r
+    LOGE("NetherManager::process recv failed " << strerror(errno));\r
+    return (false);
+}
+
+void NetherManager::setupSelectSockets(fd_set &watchedReadDescriptorsSet, fd_set &watchedWriteDescriptorsSet, struct timeval &timeoutSpecification)
+{
+    FD_ZERO (&watchedReadDescriptorsSet);
+    FD_ZERO (&watchedWriteDescriptorsSet);
+
+    /* Always listen for signals */
+    FD_SET (signalDescriptor, &watchedReadDescriptorsSet);
+
+    if ((netlinkDescriptor = netherNetlink->getDescriptor()) >= 0)
+    {\r
+        FD_SET(netlinkDescriptor, &watchedReadDescriptorsSet);
+    }
+
+    if ((backendDescriptor = netherPrimaryPolicyBackend->getDescriptor()) >= 0)
+    {
+        if (netherPrimaryPolicyBackend->getDescriptorStatus() == readOnly)
+        {
+            FD_SET(backendDescriptor, &watchedReadDescriptorsSet);
+        }
+        else if (netherPrimaryPolicyBackend->getDescriptorStatus() == readWrite)
+        {
+            FD_SET(backendDescriptor, &watchedReadDescriptorsSet);
+            FD_SET(backendDescriptor, &watchedWriteDescriptorsSet);
+        }
+    }
+\r
+    timeoutSpecification.tv_sec     = 240;\r
+    timeoutSpecification.tv_usec    = 0;
+}
+
 NetherConfig &NetherManager::getConfig()
 {
     return (netherConfig);
index ed2dd677fd52d9b985edb13c4617db293bf826f0..2326cab6f3958b4c4eea03def3399aa0daf0bda5 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   netlink handler class for nether
+ */
+
 #include "nether_Netlink.h"\r
 \r
 NetherNetlink::NetherNetlink(NetherConfig &netherConfig)\r
index c6e107230b3be9de28c52938812c15a11f12c5b4..2d2c4d2cadfb0181b1c6db15cedaa541d5b8c9f0 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Roman Kubiak (r.kubiak@samsung.com)
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+/**
+ * @file
+ * @author  Roman Kubiak (r.kubiak@samsung.com)
+ * @brief   Network utility functions for nether
+ */
+
 #include <netdb.h>
 #include <linux/types.h>
 #include "nether_Utils.h"
@@ -14,9 +38,9 @@
 
 void decodePacket(NetherPacket &packet, unsigned char *payload)
 {
-    uint8_t ip_version = (payload[0] >> 4) & 0x0F;
+    uint8_t ipVersion = (payload[0] >> 4) & 0x0F;
 
-    switch(ip_version)
+    switch(ipVersion)
     {
         case 4:
             packet.protocolType     = IPv4;
@@ -35,23 +59,23 @@ void decodePacket(NetherPacket &packet, unsigned char *payload)
 
 void decodeIPv6Packet(NetherPacket &packet, unsigned char *payload)
 {
-    const uint16_t start_of_ip_payload = 40;
-    uint8_t next_proto;
+    const uint16_t startOfIpPayload = 40;
+    uint8_t nextProto;
 
     memcpy(packet.localAddress, &payload[8], NETHER_NETWORK_IPV6_ADDR_LEN);
     memcpy(packet.remoteAddress, &payload[24], NETHER_NETWORK_IPV6_ADDR_LEN);
 
-    next_proto = payload[6];
+    nextProto = payload[6];
 
-    switch(next_proto)
+    switch(nextProto)
     {
         case IP_PROTOCOL_UDP:
             packet.transportType = UDP;
-            decodeUdp(packet, &payload[start_of_ip_payload]);
+            decodeUdp(packet, &payload[startOfIpPayload]);
             break;
         case IP_PROTOCOL_TCP:
             packet.transportType = TCP;
-            decodeTcp(packet, &payload[start_of_ip_payload]);
+            decodeTcp(packet, &payload[startOfIpPayload]);
             break;
         case IP_PROTOCOL_ICMP:
             packet.transportType = ICMP;
@@ -67,24 +91,25 @@ void decodeIPv6Packet(NetherPacket &packet, unsigned char *payload)
 
 void decodeIPv4Packet(NetherPacket &packet, unsigned char *payload)
 {
-    uint16_t start_of_ip_payload = 0;
-    uint8_t next_proto;
+    uint16_t startOfIpPayload = 0;
+    uint8_t nextProto;
 
-    start_of_ip_payload = (payload[0]&0x0F) << 2;
+    startOfIpPayload = (payload[0]&0x0F) << 2;
 
     memcpy(packet.localAddress, &payload[12], NETHER_NETWORK_IPV4_ADDR_LEN);
     memcpy(packet.remoteAddress, &payload[16], NETHER_NETWORK_IPV4_ADDR_LEN);
 
-    next_proto = payload[9];
-    switch(next_proto)
+    nextProto = payload[9];
+
+    switch(nextProto)
     {
         case IP_PROTOCOL_UDP:
             packet.transportType = UDP;
-            decodeUdp(packet, &payload[start_of_ip_payload]);
+            decodeUdp(packet, &payload[startOfIpPayload]);
             break;
         case IP_PROTOCOL_TCP:
             packet.transportType = TCP;
-            decodeTcp(packet, &payload[start_of_ip_payload]);
+            decodeTcp(packet, &payload[startOfIpPayload]);
             break;
         case IP_PROTOCOL_ICMP:
             packet.transportType = ICMP;