--- /dev/null
+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
data_counter BIGINT,
PRIMARY KEY (restriction_id)
);
-
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
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
%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/*
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)
--- /dev/null
+/*
+ * 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__ */
gboolean rstns_tree_updated;
GTree *apps; /**< monitored applications */
gboolean apps_tree_updated;
+ GHashTable *excns_hash; /**< exception hash table */
guint background_state;
} stc_system_s;
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__ */
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__;
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;
}
--- /dev/null
+/*
+ * 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;
+}
#include "counter.h"
#include "table-statistics.h"
#include "table-counters.h"
+#include "stc-exception.h"
#include "stc-monitor.h"
#include "stc-manager-plugin.h"
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);
__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)) {
__vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE,
(int *)&g_system->background_state);
+ __fill_exceptions_list();
__fill_restritions_list();
return STC_ERROR_NONE;
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;
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;