Added exception lists for monitoring 71/147971/6
authorhyunuktak <hyunuk.tak@samsung.com>
Wed, 6 Sep 2017 06:54:56 +0000 (15:54 +0900)
committerNishant Chaprana <n.chaprana@samsung.com>
Thu, 14 Sep 2017 05:39:07 +0000 (11:09 +0530)
Change-Id: I4f010db523cc8421a2cabcc62f868db976138597
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
data/exceptions [new file with mode: 0644]
data/traffic_db.sql
packaging/stc-manager.spec
src/CMakeLists.txt
src/monitor/include/stc-exception.h [new file with mode: 0755]
src/monitor/include/stc-monitor.h
src/monitor/stc-app-lifecycle.c
src/monitor/stc-exception.c [new file with mode: 0755]
src/monitor/stc-monitor.c

diff --git a/data/exceptions b/data/exceptions
new file mode 100644 (file)
index 0000000..67ab00e
--- /dev/null
@@ -0,0 +1,31 @@
+bash:inst
+cd:inst
+cp:inst
+mv:inst
+rm:inst
+mkdir:inst
+rmdir:inst
+cat:inst
+more:inst
+touch:inst
+find:inst
+ls:inst
+sed:inst
+rpm:inst
+sh:inst
+sleep:inst
+grep:inst
+killall:inst
+systemctl:inst
+wlan.sh:script
+wpa_supp.sh:script
+dlogutil:sys
+wifi-loader:sys
+launchpad-loader:sys
+wrt-loader:sys
+dotnet-launcher:sys
+volume:app
+iptables:app
+ip6tables:app
+modprobe:inst
+net-cls-release:app
index fda62f8..3fae3f6 100644 (file)
@@ -34,4 +34,3 @@ CREATE TABLE IF NOT EXISTS counters (
   data_counter BIGINT,
   PRIMARY KEY (restriction_id)
 );
-
index e08e1cb..d1befbe 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.0.30
+Version:    0.0.31
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
@@ -71,6 +71,10 @@ rm -rf %{buildroot}
        rm %{buildroot}/usr/share/traffic_db.sql
 %endif
 
+#Exceptions file
+mkdir -p %{buildroot}/%{_localstatedir}/lib/stc
+cp data/exceptions %{buildroot}/%{_localstatedir}/lib/stc/exceptions
+
 #Systemd service file
 mkdir -p %{buildroot}%{_libdir}/systemd/system/
 cp resources/systemd/stc-manager.service %{buildroot}%{_libdir}/systemd/system/stc-manager.service
@@ -91,6 +95,9 @@ cp resources/dbus/stc-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/st
 %attr(644,root,root) %{_libdir}/systemd/system/stc-manager.service
 %attr(644,root,root) %{_libdir}/systemd/system/multi-user.target.wants/stc-manager.service
 
+%attr(755,root,root) /%{_localstatedir}/lib/stc
+%attr(600,root,root) /%{_localstatedir}/lib/stc/exceptions
+
 #DBus DAC
 %attr(644,root,root) %{_sysconfdir}/dbus-1/system.d/*
 
index 736cec3..1ea3658 100644 (file)
@@ -46,12 +46,12 @@ INCLUDE_DIRECTORIES(${LIMITATION_SOURCE_DIR})
 INCLUDE_DIRECTORIES(${LIMITATION_SOURCE_DIR}/include)
 
 FILE(GLOB SOURCE_SRCS        ${SOURCE_DIR}/*.c)
-FILE(GLOB HELPER_SOURCE_SRCS ${HELPER_SOURCE_DIR}/*.c)
+FILE(GLOB HELPER_SRCS        ${HELPER_SOURCE_DIR}/*.c)
 FILE(GLOB MONITOR_SRCS       ${MONITOR_SOURCE_DIR}/*.c)
 FILE(GLOB CONFIGURE_SRCS     ${CONFIGURE_SOURCE_DIR}/*.c)
 FILE(GLOB LIMITATION_SRCS    ${LIMITATION_SOURCE_DIR}/*.c)
 
-SET(SRCS ${SRCS} ${SOURCE_SRCS} ${HELPER_SOURCE_SRCS} ${MONITOR_SRCS} ${CONFIGURE_SRCS} ${LIMITATION_SRCS})
+SET(SRCS ${SRCS} ${SOURCE_SRCS} ${HELPER_SRCS} ${MONITOR_SRCS} ${CONFIGURE_SRCS} ${LIMITATION_SRCS})
 
 IF("${ENABLE_DATABASE}" STREQUAL "YES")
        FILE(GLOB DATABASE_SRCS           ${DATABASE_SOURCE_DIR}/*.c)
diff --git a/src/monitor/include/stc-exception.h b/src/monitor/include/stc-exception.h
new file mode 100755 (executable)
index 0000000..da951ae
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __STC_EXCEPTION_H__
+#define __STC_EXCEPTION_H__
+
+typedef struct {
+       char *process_name;
+       char *exe_type;
+} table_exceptions_info;
+
+typedef stc_cb_ret_e
+(*table_exceptions_info_cb)(const table_exceptions_info *info,
+                             void *user_data);
+
+stc_error_e table_exceptions_foreach(table_exceptions_info_cb info_cb,
+                                      void *user_data);
+
+#endif /*__STC_EXCEPTION_H__ */
index 56d87e2..6601489 100755 (executable)
@@ -100,6 +100,7 @@ typedef struct {
        gboolean rstns_tree_updated;
        GTree *apps;  /**< monitored applications */
        gboolean apps_tree_updated;
+       GHashTable *excns_hash;  /**< exception hash table */
        guint background_state;
 } stc_system_s;
 
@@ -144,6 +145,8 @@ stc_error_e stc_monitor_rstns_tree_add(const table_restrictions_info *info);
 
 stc_error_e stc_monitor_rstns_tree_remove(const table_restrictions_info *info);
 
+stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline);
+
 int stc_monitor_get_counter_socket(void);
 
 #endif /* __STC_MONITOR_H__ */
index 3192c28..829c989 100755 (executable)
@@ -128,6 +128,16 @@ static void __proc_tree_remove(const proc_key_s *key)
        g_tree_remove(proc_tree, key);
 }
 
+static gboolean __check_excn(char *cmdline)
+{
+       stc_error_e ret = stc_monitor_check_excn_by_cmdline(cmdline);
+
+       if (ret == STC_ERROR_NO_DATA)
+               return FALSE;
+       else
+               return TRUE;
+}
+
 static void __open_nl_connector_sock(void)
 {
        __STC_LOG_FUNC_ENTER__;
@@ -312,8 +322,8 @@ static void __process_event_exec(int tid, int pid)
        if (STC_ERROR_NONE == proc_get_cmdline(pid, cmdline) &&
            STC_ERROR_NONE == proc_get_status(pid, status, PROC_BUF_MAX)) {
 
-               if (!g_strcmp0(cmdline, "iptables") || !g_strcmp0(cmdline, "ip6tables") ||
-                   !g_strcmp0(cmdline, "modprobe") || !g_strcmp0(cmdline, "net-cls-release")) {
+               if (__check_excn(cmdline)) {
+                       STC_LOGI("[%s] monitoring is excepted", cmdline);
                        return;
                }
 
diff --git a/src/monitor/stc-exception.c b/src/monitor/stc-exception.c
new file mode 100755 (executable)
index 0000000..87c3eeb
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+/**
+ * This file implements exceptions entity handler methods.
+ *
+ * @file        stc-exception.c
+ */
+
+#include "stc-manager.h"
+#include "stc-exception.h"
+
+#define EXCEPTION_BUF_MAX   64
+#define EXCEPTION_STORAGE   "/var/lib/stc/exceptions"
+
+stc_error_e table_exceptions_foreach(const table_exceptions_info_cb exception_cb,
+                                      void *user_data)
+{
+       __STC_LOG_FUNC_ENTER__;
+
+       stc_error_e error_code = STC_ERROR_NONE;
+       table_exceptions_info data;
+
+       FILE *fp = NULL;
+       char buf[EXCEPTION_BUF_MAX] = {0, };
+
+       fp = fopen(EXCEPTION_STORAGE, "r");
+       ret_value_msg_if(!fp, STC_ERROR_FAIL, "Failed to open %s file");
+
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               char *process_name, *exe_type;
+               char *save_ptr = NULL;
+
+               process_name = strtok_r(buf, ":", &save_ptr);
+               if (process_name != NULL)
+                       data.process_name = process_name;
+               else
+                       data.process_name = "none";
+
+               exe_type = strtok_r(NULL, "\n", &save_ptr);
+               if (exe_type != NULL)
+                       data.exe_type = exe_type;
+               else
+                       data.exe_type = "none";
+
+               if (exception_cb(&data, user_data) == STC_CANCEL)
+                       break;
+       }
+       fclose(fp);
+
+       __STC_LOG_FUNC_EXIT__;
+       return error_code;
+}
index 08f1065..8bcff31 100755 (executable)
@@ -26,6 +26,7 @@
 #include "counter.h"
 #include "table-statistics.h"
 #include "table-counters.h"
+#include "stc-exception.h"
 #include "stc-monitor.h"
 #include "stc-manager-plugin.h"
 
@@ -1499,6 +1500,41 @@ static stc_error_e __process_update_background(void)
        return STC_ERROR_NONE;
 }
 
+static void __excn_hash_foreach_print(gpointer key, gpointer value,
+                                         gpointer data)
+{
+       const char *process_name = key;
+       const char *exe_type = value;
+
+       STC_LOGI("excn info => process_name [%s] exe_type [%s]",
+               process_name, exe_type);
+}
+
+static void __excn_hash_printall(void)
+{
+       g_hash_table_foreach(g_system->excns_hash,
+               __excn_hash_foreach_print, NULL);
+}
+
+static stc_cb_ret_e __insert_exception_cb(const table_exceptions_info *info,
+                                           void *user_data)
+{
+       stc_cb_ret_e ret = STC_CONTINUE;
+
+       if (g_hash_table_insert(g_system->excns_hash,
+                       g_strdup(info->process_name),
+                       g_strdup(info->exe_type)) != TRUE)
+               ret = STC_CANCEL;
+
+       return ret;
+}
+
+static void __fill_exceptions_list(void)
+{
+       table_exceptions_foreach(__insert_exception_cb, NULL);
+       __excn_hash_printall();
+}
+
 stc_error_e stc_monitor_init(void)
 {
        stc_system_s *system = MALLOC0(stc_system_s, 1);
@@ -1518,6 +1554,9 @@ stc_error_e stc_monitor_init(void)
                                        __rstns_tree_key_free,
                                        __rstns_tree_value_free);
 
+       system->excns_hash = g_hash_table_new_full(g_str_hash,
+                                       g_str_equal, g_free, g_free);
+
        /* create netlink socket for updating kernel counters */
        system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
        if (!(system->contr_sock)) {
@@ -1557,6 +1596,7 @@ stc_error_e stc_monitor_init(void)
        __vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE,
                        (int *)&g_system->background_state);
 
+       __fill_exceptions_list();
        __fill_restritions_list();
 
        return STC_ERROR_NONE;
@@ -1583,6 +1623,10 @@ stc_error_e stc_monitor_deinit(void)
        g_tree_destroy(g_system->rstns);
        g_system->rstns = NULL;
 
+       /* destroy exception hash table */
+       g_hash_table_destroy(g_system->excns_hash);
+       g_system->excns_hash = NULL;
+
        FREE(g_system);
 
        return STC_ERROR_NONE;
@@ -1852,6 +1896,19 @@ stc_error_e stc_monitor_rstns_tree_remove(const table_restrictions_info *info)
        return ret;
 }
 
+stc_error_e stc_monitor_check_excn_by_cmdline(char *cmdline)
+{
+       ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
+
+       char *exe_type = NULL;
+
+       exe_type = g_hash_table_lookup(g_system->excns_hash, cmdline);
+       if (!exe_type)
+               return STC_ERROR_NO_DATA;
+
+       return STC_ERROR_NONE;
+}
+
 int stc_monitor_get_counter_socket(void)
 {
        return g_system->contr_sock;