INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/dbus-interface)
-INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/manager/helper")
-
SET(EXTRA_FLAGS "-Wall -Werror -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS} -std=c++11")
#include <arpa/inet.h>
#include <sqlite3.h>
#include "stc-firewall.h"
-#include "helper-firewall.h"
typedef stc_cb_ret_e
(*firewall_chain_cb)(const firewall_chain_s *info, void *user_data);
#ifndef __STC_DATAUSAGE_COUNTER_H__
#define __STC_DATAUSAGE_COUNTER_H__
-#include "stc-db.h"
+#include "stc.h"
struct counter_arg {
int sock;
int app_stat[STC_IFACE_LAST_ELEM - 1];
};
-/**
- * @desc Reschedule existing traffic counter function
- * Rescheduling logic is following, we will postpone
- * execution on delay seconds.
- */
-void reschedule_count_timer(const struct counter_arg *carg, const double delay);
-
-struct counter_arg *init_counter_arg(struct net_counter_opts *opts);
-
-void finalize_carg(struct counter_arg *carg);
-
-GTree *create_nfacct_tree(void);
-
#endif /* __STC_DATAUSAGE_COUNTER_H__ */
} stc_db_classid_iftype_key;
/**
- * @desc This function init db oversize erase timer.
- */
-stc_error_e stc_init_db_guard(void);
-
-/**
* @desc This function deinit db oversize erase timer.
*/
void stc_deinit_db_guard(void);
#ifndef __STC_FIREWALL_H__
#define __STC_FIREWALL_H__
-#include <glib.h>
+#include <arpa/inet.h>
#include "stc.h"
-#include "stc-gdbus.h"
-#include "db/table-firewall.h"
-/*****************************************************************************
- * Macros and Typedefs
- *****************************************************************************/
-
-/*****************************************************************************
- * Functions Declaration
- *****************************************************************************/
-
-gboolean handle_firewall_lock(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- void *user_data);
-
-gboolean handle_firewall_unlock(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- void *user_data);
-
-gboolean handle_firewall_get_lock(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- void *user_data);
-
-gboolean handle_firewall_add_chain(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- gchar *chain,
- void *user_data);
-
-gboolean handle_firewall_remove_chain(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- gchar *chain,
- void *user_data);
-
-gboolean handle_firewall_flush_chain(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- gchar *chain,
- void *user_data);
-
-gboolean handle_firewall_get_all_chain(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- void *user_data);
-
-gboolean handle_firewall_set_chain(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- gchar *chain,
- unsigned int target,
- void *user_data);
-
-gboolean handle_firewall_unset_chain(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- gchar *chain,
- void *user_data);
-
-gboolean handle_firewall_add_rule(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- GVariant *parameters,
- void *user_data);
-
-gboolean handle_firewall_remove_rule(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- GVariant *parameters,
- void *user_data);
-
-gboolean handle_firewall_update_rule(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- GVariant *parameters,
- void *user_data);
-
-gboolean handle_firewall_get_all_rule(StcFirewall *object,
- GDBusMethodInvocation *invocation,
- void *user_data);
+#define FIREWALL_RULE_TARGET_ACCEPT "ACCEPT"
+#define FIREWALL_RULE_TARGET_DROP "DROP"
+#define FIREWALL_RULE_TARGET_LOG "LOG"
+#define FIREWALL_RULE_TARGET_NFLOG "NFLOG"
+
+#define RULE_CHAIN "chain"
+#define RULE_DIRECTION "direction"
+#define RULE_IFNAME "ifname"
+#define RULE_PROTOCOL "protocol"
+#define RULE_TARGET "target"
+#define RULE_TARGETTYPE "target_type"
+
+#define RULE_FAMILY "family"
+#define RULE_SIPTYPE "s_ip_type"
+#define RULE_SIP1 "s_ip1"
+#define RULE_SIP2 "s_ip2"
+#define RULE_DIPTYPE "d_ip_type"
+#define RULE_DIP1 "d_ip1"
+#define RULE_DIP2 "d_ip2"
+#define RULE_SPORTTYPE "s_port_type"
+#define RULE_SPORT1 "s_port1"
+#define RULE_SPORT2 "s_port2"
+#define RULE_DPORTTYPE "d_port_type"
+#define RULE_DPORT1 "d_port1"
+#define RULE_DPORT2 "d_port2"
+
+#define RULE_LOG_LEVEL "log_level"
+#define RULE_LOG_PREFIX "log_prefix"
+#define RULE_NFLOG_GROUP "nflog_group"
+#define RULE_NFLOG_PREFIX "nflog_prefix"
+#define RULE_NFLOG_RANGE "nflog_range"
+#define RULE_NFLOG_THRESHOLD "nflog_threshold"
+
+typedef enum {
+ FIREWALL_UNKONWN,
+ FIREWALL_UNLOCKED,
+ FIREWALL_LOCKED
+} firewall_lock_e;
+
+typedef struct {
+ char *chain;
+ stc_fw_chain_target_e target;
+ guint priority;
+} firewall_chain_s;
+
+typedef union {
+ struct in_addr Ipv4;
+ struct in6_addr Ipv6;
+} ip_addr_u;
+
+typedef struct {
+ guint key;
+ char *chain;
+ stc_fw_direction_e direction;
+ stc_fw_ip_type_e s_ip_type;
+ stc_fw_ip_type_e d_ip_type;
+ stc_fw_port_type_e s_port_type;
+ stc_fw_port_type_e d_port_type;
+ stc_fw_protocol_type_e protocol;
+ stc_fw_family_type_e family;
+ ip_addr_u s_ip1;
+ ip_addr_u s_ip2;
+ ip_addr_u d_ip1;
+ ip_addr_u d_ip2;
+ guint s_port1;
+ guint s_port2;
+ guint d_port1;
+ guint d_port2;
+ char *ifname;
+ stc_fw_rule_target_e target;
+ char *target_str;
+ guchar log_level;
+ char *log_prefix;
+ guint nflog_group;
+ char *nflog_prefix;
+ guint nflog_range;
+ guint nflog_threshold;
+ char *identifier;
+} firewall_rule_s;
+
+stc_error_e firewall_chain_add(firewall_chain_s *chain);
+stc_error_e firewall_chain_remove(firewall_chain_s *chain);
+stc_error_e firewall_chain_set(firewall_chain_s *chain);
+stc_error_e firewall_chain_unset(firewall_chain_s *chain);
+
+stc_error_e firewall_rule_append(firewall_rule_s *rule);
#endif /* __STC_FIREWALL_H__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
-#ifndef __STC_MANAGER_GDBUS_H__
-#define __STC_MANAGER_GDBUS_H__
-
-#include "stc.h"
-#include "stc-generated-dbus.h"
+#include <gio/gio.h>
#define STC_DBUS_SERVICE "net.stc"
#define STC_DBUS_INTERFACE_RESTRICTION STC_DBUS_SERVICE ".restriction"
-#define STC_DBUS_SERVICE_PATH "/net/stc"
#define STC_DBUS_SERVICE_STATISTICS_PATH "/net/stc/statistics"
#define STC_DBUS_SERVICE_RESTRICTION_PATH "/net/stc/restriction"
#define STC_DBUS_SERVICE_FIREWALL_PATH "/net/stc/firewall"
#define STC_DBUS_SERVICE_PCAP_PATH "/net/stc/pcap"
#define STC_DBUS_SERVICE_MANAGER_PATH "/net/stc/manager"
-#define STC_DBUS_REPLY_ERROR_NONE(invocation) \
- g_dbus_method_invocation_return_value((invocation), \
- g_variant_new("(i)", \
- STC_ERROR_NONE));
-
-#define STC_DBUS_REPLY(invocation, parameters) \
- g_dbus_method_invocation_return_value((invocation), parameters);
-
#define DEBUG_PARAMS(parameters) do {\
gchar *params_str = NULL;\
if (parameters)\
typedef void(*dbus_dict_cb)(const char *key, GVariant *value,
void *user_data);
-void stc_manager_gdbus_init(gpointer stc_manager);
-void stc_manager_gdbus_deinit(gpointer stc_manager);
GVariant *stc_manager_gdbus_call_sync(GDBusConnection *connection,
const char *dest, const char *path,
const char *interface_name,
const gchar *interface_name,
const gchar *signal_name,
GVariant *parameters);
-
-gboolean handle_manager_stop(StcManager *object,
- GDBusMethodInvocation *invocation);
-
-gboolean handle_manager_commit_iptables(StcManager *object,
- GDBusMethodInvocation *invocation,
- const gchar *option,
- void *user_data);
-gboolean handle_manager_commit_ip6tables(StcManager *object,
- GDBusMethodInvocation *invocation,
- const gchar *option,
- void *user_data);
-
-#endif /* __STC_MANAGER_GDBUS_H__ */
--- /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.
+ */
+#pragma once
+
+/**
+ * @desc this function sets release agent path into cgroup subsystem
+ * and enables this mechanism
+ * @param cgroup_sussys - cgroup subsystem name, it's relative path to cgroup,
+ * relativelly default cgroup path (DEFAULT_CGROUP)
+ * @param release_agent full path to release agent executable
+ * @return negative value if error
+ */
+int cgroup_set_release_agent(const char *cgroup_subsys,
+ const char *release_agent);
+
+/**
+ * @desc initializes cgroups.
+ */
+void cgroup_init(void);
\ No newline at end of file
--- /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.
+ */
+#pragma once
+
+#include "stc.h"
+
+stc_error_e iptables_flush_chains(void);
+stc_error_e iptables_init(void);
+stc_error_e iptables_deinit(void);
\ No newline at end of file
--- /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.
+ */
+#pragma once
+
+#include <sys/types.h>
+#include <glib.h>
+
+#include "stc.h"
+
+stc_error_e init_current_classid(void);
+
+/**
+ * @desc take classid from net_cls cgroup by appid
+ * This function converts appid to pkgname.
+ * @param pkg_name - name of the cgroup
+ * @param create - in case of true - create cgroup if it's not exists
+ * @return classid
+ */
+uint32_t get_classid_by_app_id(const char *app_id, int create);
+
+stc_error_e place_pids_to_net_cgroup(const int pid, const char *pkg_name);
\ No newline at end of file
--- /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.
+ */
+#pragma once
+
+#include <stdbool.h>
+#include <glib.h>
+#include "stc-helper-nl.h"
+
+#define NFACCT_NAME_MAX 64
+
+typedef enum {
+ NFACCT_COUNTER_UNKNOWN,
+ NFACCT_COUNTER_IN = (1 << 1),
+ NFACCT_COUNTER_OUT = (1 << 2),
+ NFACCT_COUNTER_FORWARD = (1 << 3),
+ NFACCT_COUNTER_LAST_ELEM
+} nfacct_rule_direction;
+
+typedef enum {
+ NFACCT_ACTION_UNKNOWN,
+ NFACCT_ACTION_APPEND,
+ NFACCT_ACTION_DELETE,
+ NFACCT_ACTION_INSERT,
+ NFACCT_ACTION_LAST_ELEM,
+} nfacct_rule_action;
+
+typedef enum {
+ NFACCT_JUMP_UNKNOWN,
+ NFACCT_JUMP_ACCEPT,
+ NFACCT_JUMP_REJECT,
+ NFACCT_JUMP_LAST_ELEM,
+} nfacct_rule_jump;
+
+typedef enum {
+ NFACCT_COUNTER,
+ NFACCT_WARN,
+ NFACCT_BLOCK,
+ NFACCT_ALLOW,
+ NFACCT_TETH_COUNTER,
+ NFACCT_TETH_WARN,
+ NFACCT_TETH_BLOCK,
+ NFACCT_TETH_ALLOW,
+ NFACCT_RULE_LAST_ELEM,
+} nfacct_rule_intend;
+
+typedef enum {
+ NFACCT_TYPE_UNKNOWN,
+ NFACCT_TYPE_IPV4,
+ NFACCT_TYPE_IPV6,
+ NFACCT_TYPE_IPV4_IPV6,
+ NFACCT_TYPE_LAST_ELEM
+} nfacct_rule_iptype;
+
+typedef enum {
+ NFACCT_IPRANGE_TYPE_NONE,
+ NFACCT_IPRANGE_TYPE_SINGLE,
+ NFACCT_IPRANGE_TYPE_MASK,
+ NFACCT_IPRANGE_TYPE_RANGE,
+} nfacct_rule_iprange_type;
+
+/**
+ * it's better to have
+ * base nfacct_rule with following fields:
+ * name, ifname, pid, classid, iftype, intend, carg, iptables_rule
+ *
+ * and inherited nfacct_rule_counter and nfacct_rule_restriction
+ * with additional field:
+ * quota, quota_id, roaming, rstn_state
+ *
+ * But ANSI C doesn't support inheritance.
+ */
+struct nfacct_rule {
+ char name[NFACCT_NAME_MAX];
+ char ifname[MAX_IFACE_LENGTH];
+
+ pid_t pid;
+ uint32_t classid;
+ stc_iface_type_e iftype;
+ nfacct_rule_action action;
+ nfacct_rule_direction iotype;
+ nfacct_rule_intend intend;
+ nfacct_rule_jump jump; /* in most cases jump is evalutation based on intend, but not always */
+ stc_app_state_e app_state;
+ stc_rstn_state_e rstn_state;
+ nfacct_rule_iptype iptype;
+ nfacct_rule_iprange_type src_iprange_type;
+ nfacct_rule_iprange_type dst_iprange_type;
+ char *src_ip1;
+ char *src_ip2;
+ char *dst_ip1;
+ char *dst_ip2;
+
+ struct counter_arg *carg;
+ stc_error_e(*iptables_rule)(struct nfacct_rule *counter);
+ long long int quota;
+ int quota_id;
+ stc_roaming_type_e roaming;
+
+ long long int send_limit;
+ long long int rcv_limit;
+};
+
+typedef struct nfacct_rule nfacct_rule_s;
+
+bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *counter);
+stc_error_e nfacct_send_get_all(struct counter_arg *carg);
+stc_error_e produce_net_rule(nfacct_rule_s *rule);
+stc_error_e produce_net_list(GSList *rule_list,
+ nfacct_rule_iptype iptype, nfacct_rule_action action);
+netlink_serialization_command* netlink_create_command(struct netlink_serialization_params *params);
--- /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.
+ */
+#pragma once
+
+#include <linux/netlink.h>
+#include <linux/genetlink.h>
+#include <linux/rtnetlink.h>
+
+#include "stc.h"
+
+#define NETLINK_BUF_SIZE 16536
+
+enum nfnl_acct_type {
+ NFACCT_UNSPEC,
+ NFACCT_NAME,
+ NFACCT_PKTS,
+ NFACCT_BYTES,
+ NFACCT_USE,
+ NFACCT_FLAGS,
+ NFACCT_QUOTA,
+ NFACCT_FILTER,
+ __NFACCT_MAX
+};
+
+struct genl {
+ struct nlmsghdr n;
+ struct genlmsghdr g;
+ char buf[NETLINK_BUF_SIZE];
+};
+
+struct netlink_serialization_params {
+ int direction;
+ struct genl *ans;
+ struct counter_arg *carg;
+ int (*eval_attr)(struct rtattr *attr_list[__NFACCT_MAX],
+ void *user_data);
+ int (*post_eval_attr)(void *user_data);
+};
+
+typedef struct {
+ void (*deserialize_answer)(struct netlink_serialization_params *params);
+ void (*finalize)(struct netlink_serialization_params *params);
+ struct netlink_serialization_params params;
+} netlink_serialization_command;
+
+int create_netlink(int protocol, uint32_t groups);
+int read_netlink(int sock, void *buf, size_t len);
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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.
+ *
+ */
+#pragma once
+
+#include <stdio.h>
+#include "stc-util.h"
+
+/**
+ * @desc get command line from /proc/{pid}/cmdline
+ * @return negative value if error
+ */
+int proc_get_cmdline(pid_t pid, char *cmdline);
+
+typedef bool (*proc_pid_cb)(pid_t pid, void *user_data);
+
+/**
+ * @desc find pid from /proc
+ */
+void proc_foreach_pid(proc_pid_cb cb, void *user_data);
+
+/**
+ * @desc get status from /proc/{pid}/status
+ * @return negative value if error
+ */
+int proc_get_status(pid_t pid, char status[][PROC_BUF_MAX]);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#ifndef __STC_MANAGER_PLUGIN_EXCEPTION_H__
-#define __STC_MANAGER_PLUGIN_EXCEPTION_H__
-
-#define STC_PLUGIN_EXCEPTION_FILEPATH "/usr/lib/stc-plugin-exception.so"
-
-#include "stc-plugin-iface-exception.h"
-
-int stc_plugin_exception_init(void);
-int stc_plugin_exception_deinit(void);
+#pragma once
int stc_plugin_fill_exception_list(void);
-int stc_plugin_update_exception_list(void);
int stc_plugin_check_exception_by_cmdline(char *cmdline);
-
-#endif /* __STC_MANAGER_PLUGIN_EXCEPTION_H__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
-#ifndef __STC_MANAGER_PLUGIN_FIREWALL_H__
-#define __STC_MANAGER_PLUGIN_FIREWALL_H__
-
-#define STC_PLUGIN_FIREWALL_FILEPATH "/usr/lib/stc-plugin-firewall.so"
-
-#include "stc-plugin-iface-firewall.h"
-
-int stc_plugin_firewall_init(void);
-int stc_plugin_firewall_deinit(void);
-
-int stc_plugin_firewall_lock(void);
-int stc_plugin_firewall_unlock(void);
-int stc_plugin_firewall_get_lock(int *state);
-int stc_plugin_firewall_update(void);
-
-int stc_plugin_firewall_add_chain(char *chain);
-int stc_plugin_firewall_remove_chain(char *chain);
-int stc_plugin_firewall_flush_chain(char *chain);
-int stc_plugin_firewall_get_all_chain(GVariantBuilder *builder);
-int stc_plugin_firewall_set_chain(char *chain, uint target);
-int stc_plugin_firewall_unset_chain(char *chain);
-
-int stc_plugin_firewall_add_rule(GVariant *params);
-int stc_plugin_firewall_remove_rule(GVariant *params);
-int stc_plugin_firewall_update_rule(GVariant *params);
-int stc_plugin_firewall_get_all_rule(GVariantBuilder *builder);
-
-#endif /* __STC_MANAGER_PLUGIN_FIREWALL_H__ */
+int stc_plugin_firewall_update(void);
\ No newline at end of file
int (*deregister_state_changed_cb) (stc_s *stc);
} stc_plugin_appstatus_s;
-int stc_plugin_popup_send_message(const char *content,
- const char *type, const char *app_id, const char *iftype, const char *limit);
-
-int stc_plugin_appstatus_register_changed_cb(stc_s *stc,
- stc_plugin_app_state_changed_cb cb, void *data);
-int stc_plugin_appstatus_deregister_changed_cb(stc_s *stc);
-
#endif /* __STC_PLUGIN_APPSTATUS_H__ */
#ifndef __STC_PLUGIN_EXCEPTION_H__
#define __STC_PLUGIN_EXCEPTION_H__
-#include <glib.h>
-#include "stc.h"
-
typedef struct {
int (*initialize_plugin) (void);
int (*deinitialize_plugin) (void);
int (*check_exception_by_cmdline) (char *cmdline);
} stc_plugin_exception_s;
-int stc_plugin_exception_initialize(void);
-int stc_plugin_exception_deinitialize(void);
-int stc_plugin_exception_fill_list(void);
-int stc_plugin_exception_update_list(void);
-int stc_plugin_exception_check_by_cmdline(char *cmdline);
-
#endif /* __STC_PLUGIN_EXCEPTION_H__ */
#ifndef __STC_PLUGIN_FIREWALL_H__
#define __STC_PLUGIN_FIREWALL_H__
+#include <sys/types.h>
#include <glib.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <errno.h>
-
-#include "stc.h"
-#include "stc-gdbus.h"
-
-typedef struct {
- stc_fw_chain_target_e target;
- long long int priority;
- GSList *rules;
-} stc_fw_data_s;
typedef struct {
int (*initialize_plugin) (void);
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* 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
+ * 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,
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
-#ifndef __STC_PLUGIN_MONITOR_H__
-#define __STC_PLUGIN_MONITOR_H__
-
+#include <stdint.h>
#include <glib.h>
#include "stc.h"
-#include "helper-nl.h"
#include "db/table-restrictions.h"
-/* 1 seconds */
-#define CONTR_TIMER_INTERVAL 1
-
-#ifndef VCONFKEY_STC_BACKGROUND_STATE
-#define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
-#endif
-
-#ifndef VCONFKEY_SETAPPL_DATA_RESTRICTION_INT
-#define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction"
-#endif
-
#define MAC_ADDRESS_LEN 18
typedef void (*stc_manager_stop_cb)(void);
int (*deinitialize_plugin) (void);
int (*add_application) (uint32_t classid,
- const char *app_id,
- const char *pkg_id,
- const stc_app_value_s value);
+ const char *app_id,
+ const char *pkg_id,
+ const stc_app_value_s value);
int (*remove_application) (uint32_t classid,
- const char *app_id);
+ const char *app_id);
int (*add_restriction) (const table_restrictions_info *info);
int (*remove_restriction) (const table_restrictions_info *info);
int (*deinit_connection) (stc_s *stc);
int (*add_process) (uint32_t classid,
- const char *app_id,
- const stc_proc_value_s value);
+ const char *app_id,
+ const stc_proc_value_s value);
int (*remove_process) (uint32_t classid, pid_t pid);
int (*move_process) (uint32_t from, uint32_t to);
int (*update_process_ground) (uint32_t classid,
- const char *app_id,
- const stc_proc_value_s value);
+ const char *app_id,
+ const stc_proc_value_s value);
int (*check_excn_by_cmdline) (char *cmdline);
} stc_plugin_monitor_s;
-
-stc_error_e stc_plugin_monitor_initialize(stc_manager_stop_cb stop_cb);
-stc_error_e stc_plugin_monitor_deinitialize(void);
-
-GHashTable *stc_monitor_get_system_apps(void);
-GHashTable *stc_monitor_get_system_rstns(void);
-int stc_monitor_get_contr_sock(void);
-time_t stc_monitor_get_last_month_ts(void);
-void stc_monitor_set_last_month_ts(time_t time);
-time_t stc_monitor_get_last_week_ts(void);
-void stc_monitor_set_last_week_ts(time_t time);
-time_t stc_monitor_get_last_day_ts(void);
-void stc_monitor_set_last_day_ts(time_t time);
-void stc_monitor_set_rstns_updated(gboolean value);
-gboolean stc_monitor_get_rstns_updated(void);
-void stc_monitor_set_apps_updated(gboolean value);
-gboolean stc_monitor_get_apps_updated(void);
-void stc_monitor_set_background_state(gboolean value);
-gboolean stc_monitor_get_background_state(void);
-void stc_monitor_update_by_connection(void *data);
-void stc_monitor_add_by_connection(void *data);
-void stc_monitor_remove_by_connection(void *data);
-
-#endif /* __STC_PLUGIN_MONITOR_H__ */
const gchar *app_id, const gchar *pkg_id, stc_app_type_e app_type);
} stc_plugin_procfs_s;
-int stc_plugin_procfs_initialize(void);
-int stc_plugin_procfs_deinitialize(void);
-
-int stc_plugin_procfs_load(void);
-stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
- pid_t pid,
- const gchar *app_id,
- const gchar *pkg_id,
- stc_app_type_e app_type);
-
#endif /* __STC_PLUGIN_PROCFS_H__ */
#include <glib.h>
#include <arpa/inet.h>
-#include "stc.h"
-#define TETHERING_SERVICE_INTERFACE "org.tizen.tethering"
-#define SIGNAL_NAME_DHCP_STATUS "dhcp_status"
#define STATION_MAC_STR_LEN 18
#define STATION_STR_HOSTNAME_LEN 33
int (*set_station_classid) (const char *mac, int classid);
} stc_plugin_tether_s;
-int tether_init(void);
-void tether_deinit(void);
-stc_error_e tether_plugin_get_station_ip(const char *mac, char *ip);
-stc_error_e tether_plugin_get_station_by_classid(const int classid, char *mac);
-stc_error_e tether_plugin_set_station_classid(const char *mac, int classid);
#endif /* __STC_PLUGIN_TETHER_H__ */
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* 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
+ * 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,
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
-#ifndef __STC_MANAGER_PLUGIN_MONITOR_H__
-#define __STC_MANAGER_PLUGIN_MONITOR_H__
-
-#define STC_PLUGIN_MONITOR_FILEPATH "/usr/lib/stc-plugin-monitor.so"
-
-#include "db/table-restrictions.h"
+#include <stdint.h>
#include "stc-plugin-iface-monitor.h"
-int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb);
-int stc_plugin_monitor_deinit(void);
-
-int stc_plugin_monitor_add_app(uint32_t classid,
- const char *app_id,
- const char *pkg_id,
- const stc_app_value_s value);
-int stc_plugin_monitor_remove_app(uint32_t classid,
- const char *app_id);
+int stc_plugin_monitor_add_app(uint32_t classid, const char *app_id,
+ const char *pkg_id, const stc_app_value_s value);
+int stc_plugin_monitor_remove_app(uint32_t classid, const char *app_id);
int stc_plugin_monitor_lookup_app(uint32_t classid);
-int stc_plugin_monitor_add_rstn(table_restrictions_info *info);
-int stc_plugin_monitor_remove_rstn(table_restrictions_info *info);
-int stc_plugin_monitor_init_connection(stc_s *stc);
-int stc_plugin_monitor_deinit_connection(stc_s *stc);
-int stc_plugin_monitor_add_proc(uint32_t classid,
- const char *app_id, const stc_proc_value_s value);
+int stc_plugin_monitor_add_proc(uint32_t classid, const char *app_id,
+ const stc_proc_value_s value);
int stc_plugin_monitor_remove_proc(uint32_t classid, pid_t pid);
int stc_plugin_monitor_move_proc(uint32_t from, uint32_t to);
-int stc_plugin_monitor_update_proc_ground(uint32_t classid,
- const char *app_id, const stc_proc_value_s value);
-
-#endif /* __STC_MANAGER_PLUGIN_MONITOR_H__ */
+int stc_plugin_monitor_update_proc_ground(uint32_t classid, const char *app_id,
+ const stc_proc_value_s value);
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
*
* 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
+ * 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,
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#pragma once
-#ifndef __STC_MANAGER_PLUGIN_TETHER_H__
-#define __STC_MANAGER_PLUGIN_TETHER_H__
-
-#define STC_PLUGIN_TETHER_FILEPATH "/usr/lib/stc-plugin-tether.so"
-
-#include "stc-plugin-iface-tether.h"
-
-int stc_plugin_tether_init(void);
-int stc_plugin_tether_deinit(void);
-stc_error_e stc_plugin_tether_load(void);
int stc_plugin_tether_get_station_ip(const char *mac, char **ipaddr);
-int stc_plugin_tether_get_station_by_classid(const int classid, char **mac);
int stc_plugin_tether_set_station_classid(const char *mac, int classid);
-#endif /* __STC_MANAGER_PLUGIN_TETHER_H__ */
+int stc_plugin_tether_get_station_by_classid(const int classid, char **mac);
\ No newline at end of file
#ifndef __STC_RESTRICTION_H__
#define __STC_RESTRICTION_H__
-#include <glib.h>
#include "stc.h"
-#include "stc-gdbus.h"
-#include "db/table-restrictions.h"
#include "stc-transmission.h"
-/*****************************************************************************
- * Macros and Typedefs
- *****************************************************************************/
typedef struct {
stc_app_state_e rs_type;
stc_iface_type_e iftype;
char *subscriber_id;
} stc_restriction_s;
-/*****************************************************************************
- * Functions Declaration
- *****************************************************************************/
-
-gboolean handle_restriction_set(StcRestriction *object,
- GDBusMethodInvocation *invocation,
- GVariant *parameters,
- void *user_data);
-
-gboolean handle_restriction_unset(StcRestriction *object,
- GDBusMethodInvocation *invocation,
- GVariant *parameters,
- void *user_data);
-
-gboolean handle_restriction_set_list(StcRestriction *object,
- GDBusMethodInvocation *invocation,
- GVariant *parameters,
- void *user_data);
-
-gboolean handle_restriction_unset_list(StcRestriction *object,
- GDBusMethodInvocation *invocation,
- GVariant *parameters,
- void *user_data);
-
-gboolean handle_restriction_get(StcRestriction *object,
- GDBusMethodInvocation *invocation,
- const gchar *app_id,
- void *user_data);
-
-gboolean handle_restriction_get_all(StcRestriction *object,
- GDBusMethodInvocation *invocation,
- void *user_data);
-
-gboolean handle_restriction_get_type(StcRestriction *object,
- GDBusMethodInvocation *invocation,
- const gchar *app_id,
- int iftype,
- void *user_data);
-
#endif /* __STC_RESTRICTION_H__ */
+++ /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_STATISTICS_H__
-#define __STC_STATISTICS_H__
-
-#include <glib.h>
-#include "stc.h"
-#include "stc-gdbus.h"
-
-/*****************************************************************************
- * Macros and Typedefs
- *****************************************************************************/
-
-/*****************************************************************************
- * Functions Declaration
- *****************************************************************************/
-
-gboolean handle_statistics_init(StcStatistics *object,
- GDBusMethodInvocation *invocation);
-
-gboolean handle_statistics_get_all(StcStatistics *object,
- GDBusMethodInvocation *invocation,
- GVariant *select_rule,
- void *user_data);
-
-gboolean handle_statistics_get(StcStatistics *object,
- GDBusMethodInvocation *invocation,
- const gchar *app_id,
- GVariant *select_rule,
- void *user_data);
-
-gboolean handle_statistics_reset(StcStatistics *object,
- GDBusMethodInvocation *invocation,
- GVariant *reset_rule,
- void *user_data);
-
-#endif /* __STC_STATISTICS_H__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#ifndef __STC_HELPER_INOTIFY_H__
-#define __STC_HELPER_INOTIFY_H__
+#pragma once
#include <sys/inotify.h>
int inotify_initialize(void);
void inotify_deinitialize(void);
-
-#endif /*__STC_HELPER_INOTIFY_H__*/
#include <stdbool.h> /* bool */
#include <stdint.h> /* uint32_t, uint63_t */
#include <string.h>
-#include <sqlite3.h> /* database handling */
#include <time.h> /* time function */
-#include <vconf/vconf.h>
#include <unistd.h>
#ifdef USE_DLOG
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#ifndef __STC_MANAGER_H__
-#define __STC_MANAGER_H__
+#pragma once
#include "stc-error.h"
#include "stc-util.h"
} stc_s;
stc_s *stc_get_manager(void);
-void stc_stop_manager(void);
-int stc_commit_iptables(char *cmd, int *err_num, char **err_str);
-void stc_set_keep_alive(gboolean keep_alive);
-
-#endif /* __STC_MANAGER__ */
ADD_LIBRARY(${DB_OBJ} OBJECT ${DB_SRCS})
SET_TARGET_PROPERTIES(${DB_OBJ} PROPERTIES POSITION_INDEPENDENT_CODE ON)
-ADD_DEPENDENCIES(${DB_OBJ} GENERATED_DBUS_CODE)
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#include <errno.h>
#include <sys/stat.h>
+#include <vconf.h>
#include "stc-db.h"
#include "db/table-statistics.h"
#ifndef __STC_DB_INTERNAL_H__
#define __STC_DB_INTERNAL_H__
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-/*****************************************************************************
- * Macros and Typedefs
- *****************************************************************************/
-
#define DB_ACTION(command) do { \
if ((command) != SQLITE_OK) { \
error_code = STC_ERROR_DB_FAILED; \
} \
} while (0)
-/*****************************************************************************
- * Enumerations and Structures
- *****************************************************************************/
-
-void stc_db_finalize_statistics(void);
+/**
+ * @desc This function init db oversize erase timer.
+ */
+stc_error_e stc_init_db_guard(void);
stc_error_e stc_db_initialize_once(void);
sqlite3 *stc_db_get_database(void);
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
#endif /* _STC_DB_INTERNAL_H_ */
#define _GNU_SOURCE
#include "helper-cgroup.h"
+#include <errno.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include "helper-file.h"
+
#define RELEASE_AGENT "release_agent"
#define NOTIFY_ON_RELEASE "notify_on_release"
#define CGROUP_FILE_NAME "cgroup.procs"
-#define CLASSID_FILE_NAME "net_cls.classid"
#define MAX_PATH_LENGTH 512
#ifndef __STC_HELPER_CGROUP_H__
#define __STC_HELPER_CGROUP_H__
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <stdlib.h>
-
#include "stc.h"
-#include "helper-file.h"
+#include "stc-helper-cgroup.h"
#define DEFAULT_CGROUP "/sys/fs/cgroup"
#define CGROUP_NETWORK DEFAULT_CGROUP "/net_cls"
const char *release_agent);
/**
- * @desc get PIDs of processes in a certain cgroup, an allocated array must be provided
- * @return 0 if pids were read and array filled
- */
-int cgroup_get_pids(const char *name, GArray **pids);
-
-/**
* @desc initializes cgroups.
*/
void cgroup_init(void);
* limitations under the License.
*/
#define _GNU_SOURCE
+#include <assert.h>
+#include <errno.h>
+#include "stc.h"
#include "helper-file.h"
#define BUF_MAX (BUFSIZ)
#ifndef __STC_HELPER_FILE_H__
#define __STC_HELPER_FILE_H__
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-
-#include "stc.h"
+#include <stdint.h>
/**
* @desc write string to the file
int fwrite_uint(const char *path, const uint32_t number);
-int fwrite_ulong(const char *path, const unsigned long number);
-
-int fread_str(const char *path, char **str);
-
int fread_uint(const char *path, uint32_t *number);
-int fread_ulong(const char *path, unsigned long *number);
-
-int fwrite_array(const char *path, const void *array,
- const size_t size_of_elem,
- const size_t numb_of_elem);
-
#endif /*__STC_HELPER_FILE_H__*/
#ifndef __STC_HELPER_FIREWALL_H__
#define __STC_HELPER_FIREWALL_H__
-#include <arpa/inet.h>
-
#include "stc.h"
+#include "stc-firewall.h"
#define FIREWALL_CHAIN_TARGET_IN "INPUT"
#define FIREWALL_CHAIN_TARGET_OUT "OUTPUT"
-#define FIREWALL_RULE_TARGET_ACCEPT "ACCEPT"
-#define FIREWALL_RULE_TARGET_DROP "DROP"
-#define FIREWALL_RULE_TARGET_LOG "LOG"
-#define FIREWALL_RULE_TARGET_NFLOG "NFLOG"
-
-#define RULE_CHAIN "chain"
-#define RULE_DIRECTION "direction"
-#define RULE_IFNAME "ifname"
-#define RULE_PROTOCOL "protocol"
-#define RULE_TARGET "target"
-#define RULE_TARGETTYPE "target_type"
-
-#define RULE_FAMILY "family"
-#define RULE_SIPTYPE "s_ip_type"
-#define RULE_SIP1 "s_ip1"
-#define RULE_SIP2 "s_ip2"
-#define RULE_DIPTYPE "d_ip_type"
-#define RULE_DIP1 "d_ip1"
-#define RULE_DIP2 "d_ip2"
-#define RULE_SPORTTYPE "s_port_type"
-#define RULE_SPORT1 "s_port1"
-#define RULE_SPORT2 "s_port2"
-#define RULE_DPORTTYPE "d_port_type"
-#define RULE_DPORT1 "d_port1"
-#define RULE_DPORT2 "d_port2"
-
-#define RULE_LOG_LEVEL "log_level"
-#define RULE_LOG_PREFIX "log_prefix"
-#define RULE_NFLOG_GROUP "nflog_group"
-#define RULE_NFLOG_PREFIX "nflog_prefix"
-#define RULE_NFLOG_RANGE "nflog_range"
-#define RULE_NFLOG_THRESHOLD "nflog_threshold"
-
-typedef enum {
- FIREWALL_UNKONWN,
- FIREWALL_UNLOCKED,
- FIREWALL_LOCKED
-} firewall_lock_e;
-
-typedef union {
- struct in_addr Ipv4;
- struct in6_addr Ipv6;
-} ip_addr_u;
-
-typedef struct {
- char *chain;
- stc_fw_chain_target_e target;
- guint priority;
-} firewall_chain_s;
-
-typedef struct {
- guint key;
- char *chain;
- stc_fw_direction_e direction;
- stc_fw_ip_type_e s_ip_type;
- stc_fw_ip_type_e d_ip_type;
- stc_fw_port_type_e s_port_type;
- stc_fw_port_type_e d_port_type;
- stc_fw_protocol_type_e protocol;
- stc_fw_family_type_e family;
- ip_addr_u s_ip1;
- ip_addr_u s_ip2;
- ip_addr_u d_ip1;
- ip_addr_u d_ip2;
- guint s_port1;
- guint s_port2;
- guint d_port1;
- guint d_port2;
- char *ifname;
- stc_fw_rule_target_e target;
- char *target_str;
- guchar log_level;
- char *log_prefix;
- guint nflog_group;
- char *nflog_prefix;
- guint nflog_range;
- guint nflog_threshold;
- char *identifier;
-} firewall_rule_s;
-
-stc_error_e firewall_chain_add(firewall_chain_s *chain);
-stc_error_e firewall_chain_remove(firewall_chain_s *chain);
stc_error_e firewall_chain_flush(firewall_chain_s *chain);
-stc_error_e firewall_chain_set(firewall_chain_s *chain);
-stc_error_e firewall_chain_unset(firewall_chain_s *chain);
-stc_error_e firewall_rule_append(firewall_rule_s *rule);
stc_error_e firewall_rule_insert(firewall_rule_s *rule);
stc_error_e firewall_rule_remove(firewall_rule_s *rule);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "helper-iptables.h"
#include "stc-gdbus.h"
-#include "helper-iptables.h"
#define STC_IPTABLES_DBUS_SERVICE "net.stc.iptables"
#define STC_IPTABLES_DBUS_RULE_INTERFACE STC_IPTABLES_DBUS_SERVICE ".rule"
#include <arpa/inet.h>
#include "stc.h"
+#include "stc-helper-iptables.h"
#define STC_IN_CHAIN "STC_IN"
#define STC_OUT_CHAIN "STC_OUT"
stc_error_e iptables_remove(iptables_rule_s *rule, iptables_ip_type_e iptype);
stc_error_e iptables_add_list(GSList *iptables_list, iptables_ip_type_e iptype);
stc_error_e iptables_remove_list(GSList *iptables_list, iptables_ip_type_e iptype);
-stc_error_e iptables_flush_chains(void);
-stc_error_e iptables_init(void);
-stc_error_e iptables_deinit(void);
#endif /*__STC_HELPER_IPTABLES_H__*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
#include "helper-cgroup.h"
#include "stc-counter.h"
#include <sys/types.h>
#include <glib.h>
-#include <stdbool.h>
#include "stc.h"
+#include "stc-helper-net-cls.h"
-#define PATH_TO_NET_CGROUP_DIR CGROUP_NETWORK
-
+//#define PATH_TO_NET_CGROUP_DIR CGROUP_NETWORK
+/*
enum {
ERROR_CANT_CREATE_NL_SOCKET = 1,
ERROR_UPDATE_PID_LIST = 2,
ERROR_UPDATE_CLASSIDS_LIST = 3,
};
-
-typedef GArray int_array;
-
-stc_error_e init_current_classid(void);
-
-/**
- * @desc take classid from net_cls cgroup by appid
- * This function converts appid to pkgname.
- * @param pkg_name - name of the cgroup
- * @param create - in case of true - create cgroup if it's not exists
- * @return classid
- */
-uint32_t get_classid_by_app_id(const char *app_id, int create);
-
+*/
typedef gboolean(*check_classid_used_cb)(guint32 classid);
-stc_error_e place_pids_to_net_cgroup(const int pid, const char *pkg_name);
-
#endif /*__STC_HELPER_NET_CLS_H__*/
#include "stc-counter.h"
#include "helper-nfacct-rule.h"
#include "helper-iptables.h"
+#include "helper-nl.h"
#include "configure_stub.h"
#include "stc-db.h"
-#include <stdbool.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "helper-nl.h"
-
-#define NFACCT_NAME_MAX 64
-
-typedef enum {
- NFACCT_COUNTER_UNKNOWN,
- NFACCT_COUNTER_IN = (1 << 1),
- NFACCT_COUNTER_OUT = (1 << 2),
- NFACCT_COUNTER_FORWARD = (1 << 3),
- NFACCT_COUNTER_LAST_ELEM
-} nfacct_rule_direction;
-
-typedef enum {
- NFACCT_ACTION_UNKNOWN,
- NFACCT_ACTION_APPEND,
- NFACCT_ACTION_DELETE,
- NFACCT_ACTION_INSERT,
- NFACCT_ACTION_LAST_ELEM,
-} nfacct_rule_action;
-
-typedef enum {
- NFACCT_JUMP_UNKNOWN,
- NFACCT_JUMP_ACCEPT,
- NFACCT_JUMP_REJECT,
- NFACCT_JUMP_LAST_ELEM,
-} nfacct_rule_jump;
-
-typedef enum {
- NFACCT_COUNTER,
- NFACCT_WARN,
- NFACCT_BLOCK,
- NFACCT_ALLOW,
- NFACCT_TETH_COUNTER,
- NFACCT_TETH_WARN,
- NFACCT_TETH_BLOCK,
- NFACCT_TETH_ALLOW,
- NFACCT_RULE_LAST_ELEM,
-} nfacct_rule_intend;
-
-typedef enum {
- NFACCT_TYPE_UNKNOWN,
- NFACCT_TYPE_IPV4,
- NFACCT_TYPE_IPV6,
- NFACCT_TYPE_IPV4_IPV6,
- NFACCT_TYPE_LAST_ELEM
-} nfacct_rule_iptype;
-
-typedef enum {
- NFACCT_IPRANGE_TYPE_NONE,
- NFACCT_IPRANGE_TYPE_SINGLE,
- NFACCT_IPRANGE_TYPE_MASK,
- NFACCT_IPRANGE_TYPE_RANGE,
-} nfacct_rule_iprange_type;
+#include "stc-helper-nfacct-rule.h"
enum nfnl_acct_flags {
NFACCT_F_QUOTA_PKTS = (1 << 0),
NFACCT_F_OVERQUOTA = (1 << 2), /* can't be set from userspace */
};
-/**
- * it's better to have
- * base nfacct_rule with following fields:
- * name, ifname, pid, classid, iftype, intend, carg, iptables_rule
- *
- * and inherited nfacct_rule_counter and nfacct_rule_restriction
- * with additional field:
- * quota, quota_id, roaming, rstn_state
- *
- * But ANSI C doesn't support inheritance.
- */
-struct nfacct_rule {
- char name[NFACCT_NAME_MAX];
- char ifname[MAX_IFACE_LENGTH];
-
- pid_t pid;
- uint32_t classid;
- stc_iface_type_e iftype;
- nfacct_rule_action action;
- nfacct_rule_direction iotype;
- nfacct_rule_intend intend;
- nfacct_rule_jump jump; /* in most cases jump is evalutation based on intend, but not always */
- stc_app_state_e app_state;
- stc_rstn_state_e rstn_state;
- nfacct_rule_iptype iptype;
- nfacct_rule_iprange_type src_iprange_type;
- nfacct_rule_iprange_type dst_iprange_type;
- char *src_ip1;
- char *src_ip2;
- char *dst_ip1;
- char *dst_ip2;
-
- struct counter_arg *carg;
- stc_error_e(*iptables_rule)(struct nfacct_rule *counter);
- long long int quota;
- int quota_id;
- stc_roaming_type_e roaming;
-
- long long int send_limit;
- long long int rcv_limit;
-};
-
-typedef struct nfacct_rule nfacct_rule_s;
-
-struct counter_arg;
-
void generate_counter_name(nfacct_rule_s *counter);
-bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *counter);
-
-stc_error_e nfacct_send_get_all(struct counter_arg *carg);
-stc_error_e produce_net_rule(nfacct_rule_s *rule);
-stc_error_e produce_net_list(GSList *rule_list,
- nfacct_rule_iptype iptype, nfacct_rule_action action);
-
-netlink_serialization_command *
-netlink_create_command(struct netlink_serialization_params *params);
#endif /* __STC_NFACCT_RULE_H__ */
#include <linux/rtnetlink.h>
#include "stc.h"
+#include "stc-helper-nl.h"
#define NLA_BUF_MAX 65560 /*(65 * 1024) - used in tc_common,
we'll do the same */
#define GENLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + GENL_HDRLEN))
#define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN))
-#define NETLINK_BUF_SIZE 16536
-
enum nfnl_acct_msg_types {
NFNL_MSG_ACCT_NEW,
NFNL_MSG_ACCT_GET,
NFNL_MSG_ACCT_MAX
};
-enum nfnl_acct_type {
- NFACCT_UNSPEC,
- NFACCT_NAME,
- NFACCT_PKTS,
- NFACCT_BYTES,
- NFACCT_USE,
- NFACCT_FLAGS,
- NFACCT_QUOTA,
- NFACCT_FILTER,
- __NFACCT_MAX
-};
-
enum nfnl_attr_filter_type {
NFACCT_FILTER_ATTR_UNSPEC,
NFACCT_FILTER_ATTR_MASK,
#define NFACCT_MAX (__NFACCT_MAX - 1)
-struct genl {
- struct nlmsghdr n;
- struct genlmsghdr g;
- char buf[NETLINK_BUF_SIZE];
-};
-
-struct netlink_serialization_params {
- int direction;
- struct genl *ans;
- struct counter_arg *carg;
- int (*eval_attr)(struct rtattr *attr_list[__NFACCT_MAX],
- void *user_data);
- int (*post_eval_attr)(void *user_data);
-};
-
-typedef struct {
- void (*deserialize_answer)(struct netlink_serialization_params *params);
- void (*finalize)(struct netlink_serialization_params *params);
- struct netlink_serialization_params params;
-} netlink_serialization_command;
-
-int create_netlink(int protocol, uint32_t groups);
-int read_netlink(int sock, void *buf, size_t len);
-
void fill_attribute_list(struct rtattr **atb, const int max_len,
struct rtattr *rt_na, int rt_len);
#ifndef __HELPER_PROCFS_H__
#define __HELPER_PROCFS_H__
-#include <stdio.h>
-
-#define PROC_BUF_MAX 64
-
-typedef bool (*proc_pid_cb)(pid_t pid, void *user_data);
-
-/**
- * @desc get command line from /proc/{pid}/cmdline
- * @return negative value if error
- */
-int proc_get_cmdline(pid_t pid, char *cmdline);
+#include "stc-util.h"
+#include "stc-helper-procfs.h"
/**
* @desc find pid with /proc/{pid}/cmdline
pid_t find_pid_from_cmdline(char *cmdline);
/**
- * @desc find pid from /proc
- */
-void proc_foreach_pid(proc_pid_cb cb, void *user_data);
-
-/**
* @desc get smack subject label from /proc/{pid}/attr/current
* this label can indicate package name about child processes
* @return negative value if error or pid doesn't exist
*/
int proc_get_exepath(pid_t pid, char *buf, int len);
-/**
- * @desc get status from /proc/{pid}/status
- * @return negative value if error
- */
-int proc_get_status(pid_t pid, char status[][PROC_BUF_MAX]);
-
#endif /*__HELPER_PROCFS_H__*/
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-firewall.h"
#include "stc-db.h"
#include "stc-firewall.h"
#include "db/table-firewall.h"
-#include "helper-firewall.h"
-#include "stc-gdbus.h"
-#include "stc-plugin-firewall.h"
+#include "stcmgr.h"
+#include "stcmgr-gdbus.h"
+#include "stcmgr-plugin-firewall.h"
#define FIREWALL_DBUS_ERROR_NAME "net.stc.firewall.Error.Failed"
--- /dev/null
+/*
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+#pragma once
+
+#include <glib.h>
+#include "stc-generated-dbus.h"
+
+gboolean handle_firewall_lock(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ void *user_data);
+
+gboolean handle_firewall_unlock(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ void *user_data);
+
+gboolean handle_firewall_get_lock(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ void *user_data);
+
+gboolean handle_firewall_add_chain(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ gchar *chain,
+ void *user_data);
+
+gboolean handle_firewall_remove_chain(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ gchar *chain,
+ void *user_data);
+
+gboolean handle_firewall_flush_chain(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ gchar *chain,
+ void *user_data);
+
+gboolean handle_firewall_get_all_chain(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ void *user_data);
+
+gboolean handle_firewall_set_chain(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ gchar *chain,
+ unsigned int target,
+ void *user_data);
+
+gboolean handle_firewall_unset_chain(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ gchar *chain,
+ void *user_data);
+
+gboolean handle_firewall_add_rule(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ void *user_data);
+
+gboolean handle_firewall_remove_rule(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ void *user_data);
+
+gboolean handle_firewall_update_rule(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ void *user_data);
+
+gboolean handle_firewall_get_all_rule(StcFirewall *object,
+ GDBusMethodInvocation *invocation,
+ void *user_data);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-gdbus.h"
#include "stc.h"
-#include "stc-gdbus.h"
-#include "helper-iptables.h"
-#include "stc-statistics.h"
-#include "stc-restriction.h"
-#include "stc-firewall.h"
-#include "stc-pcap.h"
-#include "stc-plugin-appstatus.h"
-#include "stc-plugin-procfs.h"
-#include "stc-plugin-monitor.h"
-#include "stc-plugin-firewall.h"
+#include "stc-util.h"
+#include "stc-helper-iptables.h"
+#include "stcmgr.h"
+#include "stcmgr-statistics.h"
+#include "stcmgr-restriction.h"
+#include "stcmgr-firewall.h"
+#include "stcmgr-pcap.h"
+#include "stcmgr-plugin-appstatus.h"
+#include "stcmgr-plugin-procfs.h"
+#include "stcmgr-plugin-monitor.h"
+#include "stcmgr-plugin-firewall.h"
#define MANAGER_DBUS_ERROR_NAME "net.stc.manager.Error.Failed"
return ret;
}
+static gboolean handle_manager_stop(StcManager *object,
+ GDBusMethodInvocation *invocation)
+{
+ __STC_LOG_FUNC_ENTER__;
+ GVariant *return_parameters = NULL;
+
+ stc_set_keep_alive(TRUE);
+
+ STC_LOGI("stc manager stop");
+
+ return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
+
+ DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+ STC_DBUS_REPLY(invocation, return_parameters);
+
+ stc_stop_manager();
+
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+}
+
+static gboolean handle_manager_commit_iptables(StcManager *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *option,
+ void *user_data)
+{
+ __STC_LOG_FUNC_ENTER__;
+ GVariant *return_parameters = NULL;
+ int ret = STC_ERROR_NONE;
+ int err_num = 0;
+ char *err_str = NULL;
+ char cmd[STC_CMD_SIZE] = {0,};
+
+ stc_set_keep_alive(TRUE);
+
+ if (option == NULL) {
+ STC_MANAGER_DBUS_REPLY_ERROR(invocation,
+ STC_ERROR_INVALID_PARAMETER);
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+ }
+
+ STC_LOGD("[%s]", option);
+ g_snprintf(cmd, STC_CMD_SIZE, "%s %s", STC_IPTABLES, option);
+
+ ret = stc_commit_iptables(cmd, &err_num, &err_str);
+
+ return_parameters = g_variant_new("(iis)", ret, err_num, err_str);
+
+ DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+ STC_DBUS_REPLY(invocation, return_parameters);
+
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+}
+
+static gboolean handle_manager_commit_ip6tables(StcManager *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *option,
+ void *user_data)
+{
+ __STC_LOG_FUNC_ENTER__;
+ GVariant *return_parameters = NULL;
+ int ret = STC_ERROR_NONE;
+ int err_num = 0;
+ char *err_str = NULL;
+ char cmd[STC_CMD_SIZE] = {0,};
+
+ stc_set_keep_alive(TRUE);
+
+ if (option == NULL) {
+ STC_MANAGER_DBUS_REPLY_ERROR(invocation,
+ STC_ERROR_INVALID_PARAMETER);
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+ }
+
+ STC_LOGD("[%s]", option);
+ g_snprintf(cmd, STC_CMD_SIZE, "%s %s", STC_IP6TABLES, option);
+
+ ret = stc_commit_iptables(cmd, &err_num, &err_str);
+
+ return_parameters = g_variant_new("(iis)", ret, err_num, err_str);
+
+ DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+ STC_DBUS_REPLY(invocation, return_parameters);
+
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+}
+
static gboolean __stc_manager_gdbus_manager_init(stc_s *stc)
{
__STC_LOG_FUNC_ENTER__;
return rv;
}
-
-gboolean handle_manager_stop(StcManager *object,
- GDBusMethodInvocation *invocation)
-{
- __STC_LOG_FUNC_ENTER__;
- GVariant *return_parameters = NULL;
-
- stc_set_keep_alive(TRUE);
-
- STC_LOGI("stc manager stop");
-
- return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
-
- DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
- STC_DBUS_REPLY(invocation, return_parameters);
-
- stc_stop_manager();
-
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
-}
-
-gboolean handle_manager_commit_iptables(StcManager *object,
- GDBusMethodInvocation *invocation,
- const gchar *option,
- void *user_data)
-{
- __STC_LOG_FUNC_ENTER__;
- GVariant *return_parameters = NULL;
- int ret = STC_ERROR_NONE;
- int err_num = 0;
- char *err_str = NULL;
- char cmd[STC_CMD_SIZE] = { 0, };
-
- stc_set_keep_alive(TRUE);
-
- if (option == NULL) {
- STC_MANAGER_DBUS_REPLY_ERROR(invocation,
- STC_ERROR_INVALID_PARAMETER);
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
- }
-
- STC_LOGD("[%s]", option);
- g_snprintf(cmd, STC_CMD_SIZE, "%s %s", STC_IPTABLES, option);
-
- ret = stc_commit_iptables(cmd, &err_num, &err_str);
-
- return_parameters = g_variant_new("(iis)", ret, err_num, err_str);
-
- DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
- STC_DBUS_REPLY(invocation, return_parameters);
-
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
-}
-
-gboolean handle_manager_commit_ip6tables(StcManager *object,
- GDBusMethodInvocation *invocation,
- const gchar *option,
- void *user_data)
-{
- __STC_LOG_FUNC_ENTER__;
- GVariant *return_parameters = NULL;
- int ret = STC_ERROR_NONE;
- int err_num = 0;
- char *err_str = NULL;
- char cmd[STC_CMD_SIZE] = { 0, };
-
- stc_set_keep_alive(TRUE);
-
- if (option == NULL) {
- STC_MANAGER_DBUS_REPLY_ERROR(invocation,
- STC_ERROR_INVALID_PARAMETER);
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
- }
-
- STC_LOGD("[%s]", option);
- g_snprintf(cmd, STC_CMD_SIZE, "%s %s", STC_IP6TABLES, option);
-
- ret = stc_commit_iptables(cmd, &err_num, &err_str);
-
- return_parameters = g_variant_new("(iis)", ret, err_num, err_str);
-
- DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
- STC_DBUS_REPLY(invocation, return_parameters);
-
- __STC_LOG_FUNC_EXIT__;
- return TRUE;
-}
--- /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_MANAGER_GDBUS_H__
+#define __STC_MANAGER_GDBUS_H__
+
+#include "stc-gdbus.h"
+
+#define STC_DBUS_REPLY_ERROR_NONE(invocation) \
+ g_dbus_method_invocation_return_value((invocation), \
+ g_variant_new("(i)", \
+ STC_ERROR_NONE));
+
+#define STC_DBUS_REPLY(invocation, parameters) \
+ g_dbus_method_invocation_return_value((invocation), parameters);
+
+void stc_manager_gdbus_init(gpointer stc_manager);
+void stc_manager_gdbus_deinit(gpointer stc_manager);
+
+#endif /* __STC_MANAGER_GDBUS_H__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-pcap.h"
#include "stc-db.h"
-#include "stc-pcap.h"
-#include "stc-plugin-pcap.h"
+#include "stcmgr.h"
+#include "stcmgr-gdbus.h"
+#include "stcmgr-plugin-pcap.h"
#define PCAP_DBUS_ERROR_NAME "net.stc.pcap.Error.Failed"
#define __STC_PCAP_H__
#include <glib.h>
-#include "stc.h"
-#include "stc-gdbus.h"
+#include "stc-generated-dbus.h"
/*****************************************************************************
* Macros and Typedefs
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-plugin-appstatus.h"
#include <dlfcn.h>
-
#include "stc.h"
-#include "stc-plugin-appstatus.h"
static gboolean stc_plugin_enabled = FALSE;
static void *handle_plugin;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-plugin-exception.h"
#include <dlfcn.h>
-
#include "stc.h"
-#include "stc-plugin-exception.h"
static gboolean stc_plugin_enabled = FALSE;
static void *handle_plugin;
static stc_plugin_exception_s *stc_plugin;
//LCOV_EXCL_START
-API int stc_plugin_exception_init(void)
+int stc_plugin_exception_init(void)
{
__STC_LOG_FUNC_ENTER__;
return STC_ERROR_NONE;
}
-API int stc_plugin_exception_deinit(void)
+int stc_plugin_exception_deinit(void)
{
__STC_LOG_FUNC_ENTER__;
return stc_plugin->fill_exception_list();
}
-API int stc_plugin_update_exception_list(void)
+int stc_plugin_update_exception_list(void)
{
if (!stc_plugin_enabled) {
if (STC_DEBUG_LOG)
--- /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_MANAGER_PLUGIN_EXCEPTION_H__
+#define __STC_MANAGER_PLUGIN_EXCEPTION_H__
+
+#include "stc-plugin-exception.h"
+
+#define STC_PLUGIN_EXCEPTION_FILEPATH "/usr/lib/stc-plugin-exception.so"
+
+#include "stc-plugin-iface-exception.h"
+
+int stc_plugin_exception_init(void);
+int stc_plugin_exception_deinit(void);
+
+int stc_plugin_update_exception_list(void);
+
+#endif /* __STC_MANAGER_PLUGIN_EXCEPTION_H__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-plugin-firewall.h"
#include <dlfcn.h>
-
#include "stc.h"
-#include "stc-plugin-firewall.h"
static gboolean stc_plugin_enabled = FALSE;
static void *handle_plugin;
--- /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_MANAGER_PLUGIN_FIREWALL_H__
+#define __STC_MANAGER_PLUGIN_FIREWALL_H__
+
+#include "stc-plugin-firewall.h"
+#include "stc-plugin-iface-firewall.h"
+
+#define STC_PLUGIN_FIREWALL_FILEPATH "/usr/lib/stc-plugin-firewall.so"
+
+int stc_plugin_firewall_init(void);
+int stc_plugin_firewall_deinit(void);
+
+int stc_plugin_firewall_lock(void);
+int stc_plugin_firewall_unlock(void);
+int stc_plugin_firewall_get_lock(int *state);
+int stc_plugin_firewall_update(void);
+
+int stc_plugin_firewall_add_chain(char *chain);
+int stc_plugin_firewall_remove_chain(char *chain);
+int stc_plugin_firewall_flush_chain(char *chain);
+int stc_plugin_firewall_get_all_chain(GVariantBuilder *builder);
+int stc_plugin_firewall_set_chain(char *chain, uint target);
+int stc_plugin_firewall_unset_chain(char *chain);
+
+int stc_plugin_firewall_add_rule(GVariant *params);
+int stc_plugin_firewall_remove_rule(GVariant *params);
+int stc_plugin_firewall_update_rule(GVariant *params);
+int stc_plugin_firewall_get_all_rule(GVariantBuilder *builder);
+
+#endif /* __STC_MANAGER_PLUGIN_FIREWALL_H__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-plugin-monitor.h"
#include <dlfcn.h>
-
#include "stc.h"
-#include "stc-plugin-monitor.h"
static gboolean stc_plugin_enabled = FALSE;
static void *handle_plugin;
static stc_plugin_monitor_s *stc_plugin;
//LCOV_EXCL_START
-API int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb)
+int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb)
{
__STC_LOG_FUNC_ENTER__;
return STC_ERROR_NONE;
}
-API int stc_plugin_monitor_deinit(void)
+int stc_plugin_monitor_deinit(void)
{
__STC_LOG_FUNC_ENTER__;
return stc_plugin->lookup_application(classid);
}
-API int stc_plugin_monitor_add_rstn(table_restrictions_info *info)
+int stc_plugin_monitor_add_rstn(table_restrictions_info *info)
{
if (!stc_plugin_enabled) {
if (STC_DEBUG_LOG)
return stc_plugin->add_restriction(info);
}
-API int stc_plugin_monitor_remove_rstn(table_restrictions_info *info)
+int stc_plugin_monitor_remove_rstn(table_restrictions_info *info)
{
if (!stc_plugin_enabled) {
if (STC_DEBUG_LOG)
return stc_plugin->remove_restriction(info);
}
-API int stc_plugin_monitor_init_connection(stc_s *stc)
+int stc_plugin_monitor_init_connection(stc_s *stc)
{
if (!stc_plugin_enabled) {
if (STC_DEBUG_LOG)
return stc_plugin->init_connection(stc);
}
-API int stc_plugin_monitor_deinit_connection(stc_s *stc)
+int stc_plugin_monitor_deinit_connection(stc_s *stc)
{
if (!stc_plugin_enabled) {
if (STC_DEBUG_LOG)
--- /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_MANAGER_PLUGIN_MONITOR_H__
+#define __STC_MANAGER_PLUGIN_MONITOR_H__
+
+#include "stc-plugin-monitor.h"
+#include "stc-plugin-iface-monitor.h"
+
+#define STC_PLUGIN_MONITOR_FILEPATH "/usr/lib/stc-plugin-monitor.so"
+
+int stc_plugin_monitor_init(stc_manager_stop_cb stop_cb);
+int stc_plugin_monitor_deinit(void);
+
+int stc_plugin_monitor_add_rstn(table_restrictions_info *info);
+int stc_plugin_monitor_remove_rstn(table_restrictions_info *info);
+int stc_plugin_monitor_init_connection(stc_s *stc);
+int stc_plugin_monitor_deinit_connection(stc_s *stc);
+
+#endif /* __STC_MANAGER_PLUGIN_MONITOR_H__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-plugin-pcap.h"
#include <dlfcn.h>
-
#include "stc.h"
-#include "stc-plugin-pcap.h"
static gboolean stc_plugin_enabled = FALSE;
static void *handle_plugin;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-plugin-procfs.h"
#include <dlfcn.h>
-
#include "stc.h"
-#include "stc-plugin-procfs.h"
static gboolean stc_plugin_enabled = FALSE;
static void *handle_plugin;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-plugin-tether.h"
#include <dlfcn.h>
-
#include "stc.h"
-#include "stc-plugin-tether.h"
static gboolean stc_tether_plugin_enabled = FALSE;
static void *tether_plugin_handle;
--- /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_MANAGER_PLUGIN_TETHER_H__
+#define __STC_MANAGER_PLUGIN_TETHER_H__
+
+#define STC_PLUGIN_TETHER_FILEPATH "/usr/lib/stc-plugin-tether.so"
+
+#include "stc-plugin-tether.h"
+#include "stc-plugin-iface-tether.h"
+
+int stc_plugin_tether_init(void);
+int stc_plugin_tether_deinit(void);
+#endif /* __STC_MANAGER_PLUGIN_TETHER_H__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-restriction.h"
#include "stc-db.h"
#include "stc-restriction.h"
#include "db/table-restrictions.h"
-#include "stc-gdbus.h"
-#include "stc-plugin-monitor.h"
+#include "stcmgr.h"
+#include "stcmgr-gdbus.h"
+#include "stcmgr-plugin-monitor.h"
#define RESTRICTION_DBUS_ERROR_NAME "net.stc.restriction.Error.Failed"
--- /dev/null
+/*
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+#pragma once
+
+#include <glib.h>
+#include "stc-generated-dbus.h"
+
+gboolean handle_restriction_set(StcRestriction *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ void *user_data);
+
+gboolean handle_restriction_unset(StcRestriction *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ void *user_data);
+
+gboolean handle_restriction_set_list(StcRestriction *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ void *user_data);
+
+gboolean handle_restriction_unset_list(StcRestriction *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ void *user_data);
+
+gboolean handle_restriction_get(StcRestriction *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *app_id,
+ void *user_data);
+
+gboolean handle_restriction_get_all(StcRestriction *object,
+ GDBusMethodInvocation *invocation,
+ void *user_data);
+
+gboolean handle_restriction_get_type(StcRestriction *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *app_id,
+ int iftype,
+ void *user_data);
\ No newline at end of file
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcmgr-statistics.h"
#include "stc-db.h"
-#include "stc-statistics.h"
#include "db/table-statistics.h"
-#include "stc-gdbus.h"
+#include "stcmgr.h"
+#include "stcmgr-gdbus.h"
#define STATISTICS_DBUS_ERROR_NAME "net.stc.statistics.Error.Failed"
--- /dev/null
+/*
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+#pragma once
+
+#include <glib.h>
+#include "stc-generated-dbus.h"
+
+gboolean handle_statistics_init(StcStatistics *object,
+ GDBusMethodInvocation *invocation);
+
+gboolean handle_statistics_get_all(StcStatistics *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *select_rule,
+ void *user_data);
+
+gboolean handle_statistics_get(StcStatistics *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *app_id,
+ GVariant *select_rule,
+ void *user_data);
+
+gboolean handle_statistics_reset(StcStatistics *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *reset_rule,
+ void *user_data);
* limitations under the License.
*/
#define _GNU_SOURCE
+#include "stcmgr.h"
+
#include <signal.h>
#include <errno.h>
#include <sys/wait.h>
#include "stc.h"
-#include "stc-gdbus.h"
#include "stc-db.h"
+#include "stc-firewall.h"
#include "stc-counter.h"
#include "stc-util-inotify.h"
+#include "stc-helper-cgroup.h"
+#include "stc-helper-nfacct-rule.h"
+#include "stc-helper-iptables.h"
#include "db/table-restrictions.h"
-#include "helper-cgroup.h"
-#include "helper-nfacct-rule.h"
-#include "helper-iptables.h"
-#include "stc-firewall.h"
-#include "stc-plugin-appstatus.h"
-#include "stc-plugin-exception.h"
-#include "stc-plugin-procfs.h"
-#include "stc-plugin-tether.h"
-#include "stc-plugin-pcap.h"
-#include "stc-plugin-monitor.h"
-#include "stc-plugin-firewall.h"
+#include "stcmgr-gdbus.h"
+#include "stcmgr-plugin-appstatus.h"
+#include "stcmgr-plugin-exception.h"
+#include "stcmgr-plugin-procfs.h"
+#include "stcmgr-plugin-tether.h"
+#include "stcmgr-plugin-pcap.h"
+#include "stcmgr-plugin-monitor.h"
+#include "stcmgr-plugin-firewall.h"
#define BUF_SIZE_FOR_ERR 100
STC_LOGI("Smart Traffic Control Manager");
-#ifdef TIZEN_GTESTS
- setenv("GCOV_PREFIX", "/tmp/daemon", 1);
+#ifdef TIZEN_TEST_GCOV
+ setenv("GCOV_PREFIX", "/opt/usr/daemon", 1);
#endif
/*
--- /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_MANAGER_H__
+#define __STC_MANAGER_H__
+
+#include "stc.h"
+
+void stc_stop_manager(void);
+int stc_commit_iptables(char *cmd, int *err_num, char **err_str);
+void stc_set_keep_alive(gboolean keep_alive);
+
+#endif /* __STC_MANAGER__ */
+/*
+ * Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syspopup_caller.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <dlog.h>
#include <gio/gio.h>
#include <pkgmgr-info.h>
return ret;
}
-static gboolean __update_exceptions_app_list(void *user_data)
-{
- stc_plugin_exception_update_list();
- return TRUE;
-}
-
static stc_error_e pkginfo_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
void *user_data)
{
return err;
}
+int stc_plugin_exception_update_list(void)
+{
+ __remove_exception_appall();
+ pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
+
+ if (STC_STAT_LOG)
+ __excn_hash_printall();
+
+ return STC_ERROR_NONE;
+}
+
+static gboolean __update_exceptions_app_list(void *user_data)
+{
+ stc_plugin_exception_update_list();
+ return TRUE;
+}
+
static stc_error_e table_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
void *user_data)
{
return STC_ERROR_NONE;
}
-int stc_plugin_exception_update_list(void)
-{
- __remove_exception_appall();
- pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
-
- if (STC_STAT_LOG)
- __excn_hash_printall();
-
- return STC_ERROR_NONE;
-}
-
int stc_plugin_exception_check_by_cmdline(char *cmdline)
{
char *exe_type = NULL;
TARGET_LINK_LIBRARIES(${STC_PI_FIREWALL} ${plugin_pkgs_LIBRARIES})
TARGET_COMPILE_OPTIONS(${STC_PI_FIREWALL} PUBLIC ${plugin_pkgs_CFLAGS_OTHER})
SET_TARGET_PROPERTIES(${STC_PI_FIREWALL} PROPERTIES PREFIX "" OUTPUT_NAME ${STC_PI_FIREWALL})
-ADD_DEPENDENCIES(${STC_PI_FIREWALL} GENERATED_DBUS_CODE)
INSTALL(TARGETS ${STC_PI_FIREWALL} DESTINATION ${LIB_INSTALL_DIR})
* limitations under the License.
*/
#include "stc.h"
+#include "stc-gdbus.h"
+#include "stc-firewall.h"
#include "stc-plugin-iface-firewall.h"
#include "db/table-firewall.h"
-#include "helper-firewall.h"
#define LOCK_NAME "admin"
} \
} while (0)
+typedef struct {
+ stc_fw_chain_target_e target;
+ long long int priority;
+ GSList *rules;
+} stc_fw_data_s;
+
static GHashTable *g_firewalls = NULL;
static int g_lock_state = FIREWALL_UNKONWN;
static int g_chain_priority = 0;
TARGET_LINK_LIBRARIES(${STC_PI_MONITOR} ${plugin_pkgs_LIBRARIES} ${monitor_pkgs_LIBRARIES})
TARGET_COMPILE_OPTIONS(${STC_PI_MONITOR} PUBLIC ${plugin_pkgs_CFLAGS_OTHER} ${monitor_pkgs_CFLAGS_OTHER})
SET_TARGET_PROPERTIES(${STC_PI_MONITOR} PROPERTIES PREFIX "" OUTPUT_NAME ${STC_PI_MONITOR})
-ADD_DEPENDENCIES(${STC_PI_MONITOR} GENERATED_DBUS_CODE)
INSTALL(TARGETS ${STC_PI_MONITOR} DESTINATION ${LIB_INSTALL_DIR})
#include "stc-counter.h"
#include "stc-plugin-tether.h"
#include "db/table-statistics.h"
-#include "helper-net-cls.h"
-#include "stc-plugin-iface-monitor.h"
+#include "stc-helper-net-cls.h"
+#include "stcplugin-monitor.h"
#include "stcplugin-monitor-rstn.h"
#include "stcplugin-monitor-proc.h"
#include "stcplugin-monitor-ipt.h"
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-#include <vconf/vconf.h>
+#include <vconf.h>
#include <openssl/sha.h>
#include "stc-gdbus.h"
#include "stc-firewall.h"
#include "stc-plugin-firewall.h"
-#include "stc-plugin-monitor.h"
+#include "stcplugin-monitor.h"
#include "stcplugin-monitor-connection.h"
/* connman service dbus details */
#ifndef __STC_PLUGIN_MONITOR_IPT_H__
#define __STC_PLUGIN_MONITOR_IPT_H__
-#include "helper-nfacct-rule.h"
+#include "stc-helper-nfacct-rule.h"
stc_error_e stc_monitor_ipt_add_in(struct nfacct_rule *counter);
stc_error_e stc_monitor_ipt_add_out(struct nfacct_rule *counter);
* limitations under the License.
*/
-#include "helper-net-cls.h"
-#include "db/table-restrictions.h"
-#include "stc-plugin-iface-monitor.h"
+#include "stc-helper-net-cls.h"
+#include "stcplugin-monitor.h"
#include "stcplugin-monitor-proc.h"
#include "stcplugin-monitor-app.h"
#include "stcplugin-monitor-rstn.h"
#include <bundle_internal.h>
#include <syspopup_caller.h>
+#include "stc-gdbus.h"
#include "stc-counter.h"
#include "stc-plugin-tether.h"
#include "db/table-counters.h"
#include "db/table-restrictions.h"
#include "db/table-statistics.h"
-#include "helper-net-cls.h"
-#include "stc-plugin-iface-monitor.h"
+#include "stc-helper-net-cls.h"
+#include "stcplugin-monitor.h"
#include "stcplugin-monitor-rstn.h"
#include "stcplugin-monitor-ipt.h"
#include "stcplugin-monitor-time.h"
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "stcplugin-monitor.h"
#include <linux/netlink.h>
#include <vconf.h>
#include <vconf-keys.h>
-
+#ifdef TIZEN_TEST_GCOV
+#include <gcov.h>
+#endif
#include "stc-counter.h"
-#include "helper-nl.h"
-#include "helper-nfacct-rule.h"
-#include "helper-net-cls.h"
-#include "helper-cgroup.h"
-#include "helper-iptables.h"
+#include "stc-helper-nl.h"
+#include "stc-helper-nfacct-rule.h"
+#include "stc-helper-net-cls.h"
+#include "stc-helper-cgroup.h"
+#include "stc-helper-iptables.h"
#include "db/table-statistics.h"
#include "db/table-counters.h"
#include "stc-plugin-exception.h"
int ret;
stc_s *stc = stc_get_manager();
-#ifdef TIZEN_GTESTS
- void __gcov_flush(void);
+#ifdef TIZEN_TEST_GCOV
__gcov_flush();
#endif
stc->carg->sock = g_system->contr_sock;
}
-#ifdef TIZEN_GTESTS
- void __gcov_flush(void);
+#ifdef TIZEN_TEST_GCOV
__gcov_flush();
#endif
--- /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_PLUGIN_MONITOR_H__
+#define __STC_PLUGIN_MONITOR_H__
+
+#include <glib.h>
+
+/* 1 seconds */
+#define CONTR_TIMER_INTERVAL 1
+
+#ifndef VCONFKEY_STC_BACKGROUND_STATE
+#define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
+#endif
+
+#ifndef VCONFKEY_SETAPPL_DATA_RESTRICTION_INT
+#define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction"
+#endif
+
+GHashTable *stc_monitor_get_system_apps(void);
+GHashTable *stc_monitor_get_system_rstns(void);
+int stc_monitor_get_contr_sock(void);
+time_t stc_monitor_get_last_month_ts(void);
+void stc_monitor_set_last_month_ts(time_t time);
+time_t stc_monitor_get_last_week_ts(void);
+void stc_monitor_set_last_week_ts(time_t time);
+time_t stc_monitor_get_last_day_ts(void);
+void stc_monitor_set_last_day_ts(time_t time);
+void stc_monitor_set_rstns_updated(gboolean value);
+gboolean stc_monitor_get_rstns_updated(void);
+void stc_monitor_set_apps_updated(gboolean value);
+gboolean stc_monitor_get_apps_updated(void);
+void stc_monitor_set_background_state(gboolean value);
+gboolean stc_monitor_get_background_state(void);
+void stc_monitor_update_by_connection(void *data);
+void stc_monitor_add_by_connection(void *data);
+void stc_monitor_remove_by_connection(void *data);
+
+#endif /* __STC_PLUGIN_MONITOR_H__ */
#ifndef __STC_PLUGIN_PCAP_INTERNAL_H__
#define __STC_PLUGIN_PCAP_INTERNAL_H__
-#include <glib.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <errno.h>
-#include <pcap.h>
-#include <pcap/nflog.h>
#include <arpa/inet.h>
#include <net/ethernet.h>
-#include <net/if_arp.h>
#include <netinet/ether.h>
-#include <netinet/ip.h>
-#include <netinet/ip6.h>
#include <netinet/ip_icmp.h>
+#include <netinet/ip6.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
+#include <glib.h>
+#include <pcap.h>
+#include <pcap/nflog.h>
#include "stc.h"
TARGET_LINK_LIBRARIES(${STC_PI_PROCFS} ${plugin_pkgs_LIBRARIES})
TARGET_COMPILE_OPTIONS(${STC_PI_PROCFS} PUBLIC ${plugin_pkgs_CFLAGS_OTHER})
SET_TARGET_PROPERTIES(${STC_PI_PROCFS} PROPERTIES PREFIX "" OUTPUT_NAME ${STC_PI_PROCFS})
-ADD_DEPENDENCIES(${STC_PI_PROCFS} GENERATED_DBUS_CODE)
INSTALL(TARGETS ${STC_PI_PROCFS} DESTINATION ${LIB_INSTALL_DIR})
#include <glib.h>
#include "stc-plugin-iface-procfs.h"
-#include "helper-net-cls.h"
-#include "helper-procfs.h"
+#include "stc-helper-net-cls.h"
+#include "stc-helper-procfs.h"
+#include "stc-helper-nl.h"
#include "stc-plugin-monitor.h"
#include "stc-plugin-exception.h"
return parent;
}
+stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
+ pid_t pid,
+ const gchar *app_id,
+ const gchar *pkg_id,
+ stc_app_type_e app_type)
+{
+ stc_error_e ret = STC_ERROR_NONE;
+
+ if ((pkg_id && app_id) && STC_STAT_LOG)
+ STC_LOGD("cmd[%d] pkgid[%s] appid[%s] pid[%d] type[%d]",
+ cmd, pkg_id, app_id, pid, app_type);
+
+ switch (cmd) {
+ case STC_CMD_SET_FOREGRD:
+ {
+ uint32_t fg_classid = STC_UNKNOWN_CLASSID;
+ uint32_t bg_classid = STC_UNKNOWN_CLASSID;
+ char *bg_app_id = NULL;
+ stc_app_value_s app_value;
+ stc_proc_value_s proc_value;
+
+ memset(&app_value, 0, sizeof(stc_app_value_s));
+ memset(&proc_value, 0, sizeof(stc_proc_value_s));
+
+ bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+
+ app_value.type = app_type;
+ app_value.state = STC_APP_STATE_FOREGROUND;
+ app_value.processes = NULL;
+
+ proc_value.pid = pid;
+ proc_value.ground = STC_APP_STATE_FOREGROUND;
+
+ bg_classid = get_classid_by_app_id(bg_app_id, FALSE);
+ fg_classid = get_classid_by_app_id(app_id, TRUE);
+
+ stc_plugin_monitor_add_app(fg_classid, app_id, pkg_id, app_value);
+
+ stc_plugin_monitor_move_proc(bg_classid, fg_classid);
+
+ stc_plugin_monitor_add_proc(fg_classid, app_id, proc_value);
+ stc_plugin_monitor_update_proc_ground(fg_classid, app_id, proc_value);
+
+ FREE(bg_app_id);
+ break;
+ }
+ case STC_CMD_SET_BACKGRD:
+ {
+ uint32_t bg_classid = STC_UNKNOWN_CLASSID;
+ uint32_t fg_classid = STC_UNKNOWN_CLASSID;
+ char *bg_app_id = NULL;
+ stc_app_value_s app_value;
+ stc_proc_value_s proc_value;
+
+ memset(&app_value, 0, sizeof(stc_app_value_s));
+ memset(&proc_value, 0, sizeof(stc_proc_value_s));
+
+ bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+
+ app_value.type = app_type;
+ app_value.state = STC_APP_STATE_BACKGROUND;
+ app_value.processes = NULL;
+
+ proc_value.pid = pid;
+ proc_value.ground = STC_APP_STATE_BACKGROUND;
+
+ fg_classid = get_classid_by_app_id(app_id, FALSE);
+ bg_classid = get_classid_by_app_id(bg_app_id, TRUE);
+
+ stc_plugin_monitor_add_app(bg_classid, bg_app_id, pkg_id, app_value);
+
+ stc_plugin_monitor_move_proc(fg_classid, bg_classid);
+
+ stc_plugin_monitor_add_proc(bg_classid, bg_app_id, proc_value);
+ stc_plugin_monitor_update_proc_ground(bg_classid, bg_app_id, proc_value);
+
+ FREE(bg_app_id);
+ break;
+ }
+ case STC_CMD_SET_APP_LAUNCHED:
+ {
+ uint32_t classid = STC_UNKNOWN_CLASSID;
+ stc_app_value_s app_value;
+ stc_proc_value_s proc_value;
+
+ memset(&app_value, 0, sizeof(stc_app_value_s));
+ memset(&proc_value, 0, sizeof(stc_proc_value_s));
+
+ classid = get_classid_by_app_id(app_id, FALSE);
+
+ app_value.type = app_type;
+ app_value.state = STC_APP_STATE_FOREGROUND;
+ app_value.processes = NULL;
+
+ proc_value.pid = pid;
+ proc_value.ground = STC_APP_STATE_FOREGROUND;
+
+ stc_plugin_monitor_add_app(classid, app_id, pkg_id, app_value);
+ stc_plugin_monitor_add_proc(classid, app_id, proc_value);
+
+ break;
+ }
+ case STC_CMD_SET_SERVICE_LAUNCHED:
+ {
+ uint32_t classid = STC_UNKNOWN_CLASSID;
+ char *bg_app_id = NULL;
+ stc_app_value_s app_value;
+ stc_proc_value_s proc_value;
+ gboolean is_exist;
+
+ memset(&app_value, 0, sizeof(stc_app_value_s));
+ memset(&proc_value, 0, sizeof(stc_proc_value_s));
+
+ classid = get_classid_by_app_id(app_id, FALSE);
+ is_exist = stc_plugin_monitor_lookup_app(classid);
+ if (is_exist) {
+ app_value.type = app_type;
+ app_value.state = STC_APP_STATE_FOREGROUND;
+ app_value.processes = NULL;
+
+ proc_value.pid = pid;
+ proc_value.ground = STC_APP_STATE_FOREGROUND;
+
+ stc_plugin_monitor_add_app(classid, app_id, pkg_id, app_value);
+ stc_plugin_monitor_add_proc(classid, app_id, proc_value);
+ } else {
+ bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+ classid = get_classid_by_app_id(bg_app_id, TRUE);
+
+ app_value.type = app_type;
+ app_value.state = STC_APP_STATE_BACKGROUND;
+ app_value.processes = NULL;
+
+ proc_value.pid = pid;
+ proc_value.ground = STC_APP_STATE_BACKGROUND;
+
+ stc_plugin_monitor_add_app(classid, bg_app_id, pkg_id, app_value);
+ stc_plugin_monitor_add_proc(classid, bg_app_id, proc_value);
+
+ FREE(bg_app_id);
+ }
+ break;
+ }
+ case STC_CMD_SET_TERMINATED:
+ {
+ uint32_t classid = STC_UNKNOWN_CLASSID;
+ char *bg_app_id = NULL;
+
+ if (app_type == STC_APP_TYPE_NONE) {
+ bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+ classid = get_classid_by_app_id(bg_app_id, FALSE);
+ }
+
+ if (classid == STC_UNKNOWN_CLASSID)
+ classid = get_classid_by_app_id(bg_app_id, FALSE);
+
+ stc_plugin_monitor_remove_proc(classid, pid);
+
+ FREE(bg_app_id);
+ break;
+ }
+ default:
+ STC_LOGE("Unhandled command");
+ ret = STC_ERROR_INVALID_PARAMETER;
+ }
+
+ return ret;
+}
+
static void __proc_tree_add(proc_key_s *key, proc_value_s *value)
{
proc_value_s *lookup;
return STC_ERROR_NONE;
}
-stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
- pid_t pid,
- const gchar *app_id,
- const gchar *pkg_id,
- stc_app_type_e app_type)
-{
- stc_error_e ret = STC_ERROR_NONE;
-
- if ((pkg_id && app_id) && STC_STAT_LOG)
- STC_LOGD("cmd[%d] pkgid[%s] appid[%s] pid[%d] type[%d]",
- cmd, pkg_id, app_id, pid, app_type);
-
- switch (cmd) {
- case STC_CMD_SET_FOREGRD:
- {
- uint32_t fg_classid = STC_UNKNOWN_CLASSID;
- uint32_t bg_classid = STC_UNKNOWN_CLASSID;
- char *bg_app_id = NULL;
- stc_app_value_s app_value;
- stc_proc_value_s proc_value;
-
- memset(&app_value, 0, sizeof(stc_app_value_s));
- memset(&proc_value, 0, sizeof(stc_proc_value_s));
-
- bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
-
- app_value.type = app_type;
- app_value.state = STC_APP_STATE_FOREGROUND;
- app_value.processes = NULL;
-
- proc_value.pid = pid;
- proc_value.ground = STC_APP_STATE_FOREGROUND;
-
- bg_classid = get_classid_by_app_id(bg_app_id, FALSE);
- fg_classid = get_classid_by_app_id(app_id, TRUE);
-
- stc_plugin_monitor_add_app(fg_classid, app_id, pkg_id, app_value);
-
- stc_plugin_monitor_move_proc(bg_classid, fg_classid);
-
- stc_plugin_monitor_add_proc(fg_classid, app_id, proc_value);
- stc_plugin_monitor_update_proc_ground(fg_classid, app_id, proc_value);
-
- FREE(bg_app_id);
- break;
- }
- case STC_CMD_SET_BACKGRD:
- {
- uint32_t bg_classid = STC_UNKNOWN_CLASSID;
- uint32_t fg_classid = STC_UNKNOWN_CLASSID;
- char *bg_app_id = NULL;
- stc_app_value_s app_value;
- stc_proc_value_s proc_value;
-
- memset(&app_value, 0, sizeof(stc_app_value_s));
- memset(&proc_value, 0, sizeof(stc_proc_value_s));
-
- bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
-
- app_value.type = app_type;
- app_value.state = STC_APP_STATE_BACKGROUND;
- app_value.processes = NULL;
-
- proc_value.pid = pid;
- proc_value.ground = STC_APP_STATE_BACKGROUND;
-
- fg_classid = get_classid_by_app_id(app_id, FALSE);
- bg_classid = get_classid_by_app_id(bg_app_id, TRUE);
-
- stc_plugin_monitor_add_app(bg_classid, bg_app_id, pkg_id, app_value);
-
- stc_plugin_monitor_move_proc(fg_classid, bg_classid);
-
- stc_plugin_monitor_add_proc(bg_classid, bg_app_id, proc_value);
- stc_plugin_monitor_update_proc_ground(bg_classid, bg_app_id, proc_value);
-
- FREE(bg_app_id);
- break;
- }
- case STC_CMD_SET_APP_LAUNCHED:
- {
- uint32_t classid = STC_UNKNOWN_CLASSID;
- stc_app_value_s app_value;
- stc_proc_value_s proc_value;
-
- memset(&app_value, 0, sizeof(stc_app_value_s));
- memset(&proc_value, 0, sizeof(stc_proc_value_s));
-
- classid = get_classid_by_app_id(app_id, FALSE);
-
- app_value.type = app_type;
- app_value.state = STC_APP_STATE_FOREGROUND;
- app_value.processes = NULL;
-
- proc_value.pid = pid;
- proc_value.ground = STC_APP_STATE_FOREGROUND;
-
- stc_plugin_monitor_add_app(classid, app_id, pkg_id, app_value);
- stc_plugin_monitor_add_proc(classid, app_id, proc_value);
-
- break;
- }
- case STC_CMD_SET_SERVICE_LAUNCHED:
- {
- uint32_t classid = STC_UNKNOWN_CLASSID;
- char *bg_app_id = NULL;
- stc_app_value_s app_value;
- stc_proc_value_s proc_value;
- gboolean is_exist;
-
- memset(&app_value, 0, sizeof(stc_app_value_s));
- memset(&proc_value, 0, sizeof(stc_proc_value_s));
-
- classid = get_classid_by_app_id(app_id, FALSE);
- is_exist = stc_plugin_monitor_lookup_app(classid);
- if (is_exist) {
- app_value.type = app_type;
- app_value.state = STC_APP_STATE_FOREGROUND;
- app_value.processes = NULL;
-
- proc_value.pid = pid;
- proc_value.ground = STC_APP_STATE_FOREGROUND;
-
- stc_plugin_monitor_add_app(classid, app_id, pkg_id, app_value);
- stc_plugin_monitor_add_proc(classid, app_id, proc_value);
- } else {
- bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
- classid = get_classid_by_app_id(bg_app_id, TRUE);
-
- app_value.type = app_type;
- app_value.state = STC_APP_STATE_BACKGROUND;
- app_value.processes = NULL;
-
- proc_value.pid = pid;
- proc_value.ground = STC_APP_STATE_BACKGROUND;
-
- stc_plugin_monitor_add_app(classid, bg_app_id, pkg_id, app_value);
- stc_plugin_monitor_add_proc(classid, bg_app_id, proc_value);
-
- FREE(bg_app_id);
- }
- break;
- }
- case STC_CMD_SET_TERMINATED:
- {
- uint32_t classid = STC_UNKNOWN_CLASSID;
- char *bg_app_id = NULL;
-
- if (app_type == STC_APP_TYPE_NONE) {
- bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
- classid = get_classid_by_app_id(bg_app_id, FALSE);
- }
-
- if (classid == STC_UNKNOWN_CLASSID)
- classid = get_classid_by_app_id(bg_app_id, FALSE);
-
- stc_plugin_monitor_remove_proc(classid, pid);
-
- FREE(bg_app_id);
- break;
- }
- default:
- STC_LOGE("Unhandled command");
- ret = STC_ERROR_INVALID_PARAMETER;
- }
-
- return ret;
-}
-
API stc_plugin_procfs_s stc_plugin_procfs = {
.initialize_plugin =
stc_plugin_procfs_initialize,
#include "stc-plugin-monitor.h"
#include "stc-plugin-iface-tether.h"
+#define TETHERING_SERVICE_INTERFACE "org.tizen.tethering"
+#define SIGNAL_NAME_DHCP_STATUS "dhcp_status"
+
static GSList *station_list = NULL;
static GDBusConnection *connection = NULL;
static GCancellable *cancellable = NULL;