*/
#include <linux/netlink.h>
+#include <vconf.h>
+#include <vconf-keys.h>
#include "stc-default-connection.h"
#include "helper-nl.h"
#include "counter.h"
#include "table-statistics.h"
#include "table-counters.h"
+#include "stc-exception.h"
#include "stc-monitor.h"
#include "stc-manager-plugin.h"
#define MAX_INT_LENGTH 128
+#define VCONFKEY_STC_BACKGROUND_STATE "db/stc/background_state"
typedef struct {
stc_app_key_s *app_key;
static stc_error_e __add_iptables_in(struct nfacct_rule *counter)
{
- return produce_net_rule(counter, 0, 0,
- NFACCT_ACTION_INSERT, __get_jump_by_intend(counter),
- NFACCT_COUNTER_IN);
+ if (counter == NULL)
+ return STC_ERROR_INVALID_PARAMETER;
+
+ counter->action = NFACCT_ACTION_INSERT;
+ counter->iotype = NFACCT_COUNTER_IN;
+ counter->jump = __get_jump_by_intend(counter);
+ counter->iptype = NFACCT_TYPE_IPV4;
+ counter->send_limit = 0;
+ counter->rcv_limit = 0;
+
+ return produce_net_rule(counter);
}
static stc_error_e __add_iptables_out(struct nfacct_rule *counter)
{
- return produce_net_rule(counter, 0, 0,
- NFACCT_ACTION_INSERT, __get_jump_by_intend(counter),
- NFACCT_COUNTER_OUT);
+ if (counter == NULL)
+ return STC_ERROR_INVALID_PARAMETER;
+
+ counter->action = NFACCT_ACTION_INSERT;
+ counter->iotype = NFACCT_COUNTER_OUT;
+ counter->jump = __get_jump_by_intend(counter);
+ counter->iptype = NFACCT_TYPE_IPV4;
+ counter->send_limit = 0;
+ counter->rcv_limit = 0;
+
+ return produce_net_rule(counter);
}
static stc_error_e __del_iptables_in(struct nfacct_rule *counter)
{
- return produce_net_rule(counter, 0, 0,
- NFACCT_ACTION_DELETE, __get_jump_by_intend(counter),
- NFACCT_COUNTER_IN);
+ if (counter == NULL)
+ return STC_ERROR_INVALID_PARAMETER;
+
+ counter->action = NFACCT_ACTION_DELETE;
+ counter->iotype = NFACCT_COUNTER_IN;
+ counter->jump = __get_jump_by_intend(counter);
+ counter->iptype = NFACCT_TYPE_IPV4;
+ counter->send_limit = 0;
+ counter->rcv_limit = 0;
+
+ return produce_net_rule(counter);
}
static stc_error_e __del_iptables_out(struct nfacct_rule *counter)
{
- return produce_net_rule(counter, 0, 0,
- NFACCT_ACTION_DELETE, __get_jump_by_intend(counter),
- NFACCT_COUNTER_OUT);
+ if (counter == NULL)
+ return STC_ERROR_INVALID_PARAMETER;
+
+ counter->action = NFACCT_ACTION_DELETE;
+ counter->iotype = NFACCT_COUNTER_OUT;
+ counter->jump = __get_jump_by_intend(counter);
+ counter->iptype = NFACCT_TYPE_IPV4;
+ counter->send_limit = 0;
+ counter->rcv_limit = 0;
+
+ return produce_net_rule(counter);
+}
+
+static stc_error_e __add_ip6tables_in(struct nfacct_rule *counter)
+{
+ if (counter == NULL)
+ return STC_ERROR_INVALID_PARAMETER;
+
+ counter->action = NFACCT_ACTION_INSERT;
+ counter->iotype = NFACCT_COUNTER_IN;
+ counter->jump = __get_jump_by_intend(counter);
+ counter->iptype = NFACCT_TYPE_IPV6;
+ counter->send_limit = 0;
+ counter->rcv_limit = 0;
+
+ return produce_net_rule(counter);
+}
+
+static stc_error_e __add_ip6tables_out(struct nfacct_rule *counter)
+{
+ if (counter == NULL)
+ return STC_ERROR_INVALID_PARAMETER;
+
+ counter->action = NFACCT_ACTION_INSERT;
+ counter->iotype = NFACCT_COUNTER_OUT;
+ counter->jump = __get_jump_by_intend(counter);
+ counter->iptype = NFACCT_TYPE_IPV6;
+ counter->send_limit = 0;
+ counter->rcv_limit = 0;
+
+ return produce_net_rule(counter);
+}
+
+static stc_error_e __del_ip6tables_in(struct nfacct_rule *counter)
+{
+ if (counter == NULL)
+ return STC_ERROR_INVALID_PARAMETER;
+
+ counter->action = NFACCT_ACTION_DELETE;
+ counter->iotype = NFACCT_COUNTER_IN;
+ counter->jump = __get_jump_by_intend(counter);
+ counter->iptype = NFACCT_TYPE_IPV6;
+ counter->send_limit = 0;
+ counter->rcv_limit = 0;
+
+ return produce_net_rule(counter);
+}
+
+static stc_error_e __del_ip6tables_out(struct nfacct_rule *counter)
+{
+ if (counter == NULL)
+ return STC_ERROR_INVALID_PARAMETER;
+
+ counter->action = NFACCT_ACTION_DELETE;
+ counter->iotype = NFACCT_COUNTER_OUT;
+ counter->jump = __get_jump_by_intend(counter);
+ counter->iptype = NFACCT_TYPE_IPV6;
+ counter->send_limit = 0;
+ counter->rcv_limit = 0;
+
+ return produce_net_rule(counter);
}
static int __processes_tree_key_compare(gconstpointer a, gconstpointer b,
if (ret != 0)
return ret;
- ret = g_strcmp0(key_a->imsi, key_b->imsi);
+ ret = g_strcmp0(key_a->subscriber_id, key_b->subscriber_id);
if (ret != 0)
return ret;
FREE(key->app_id);
FREE(key->ifname);
- FREE(key->imsi);
+ FREE(key->subscriber_id);
FREE(key);
}
default_connection_s *connection = (default_connection_s *)data;
stc_s *stc = stc_get_manager();
+ if (app_value->classid == STC_TOTAL_DATACALL_CLASSID ||
+ app_value->classid == STC_TOTAL_WIFI_CLASSID ||
+ app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID)
+ return FALSE;
+
if (stc && connection && connection->ifname) {
struct nfacct_rule counter;
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return FALSE;
+
stc->carg->sock = stc_monitor_get_counter_socket();
}
counter.carg = stc->carg;
counter.classid = app_value->classid;
counter.intend = NFACCT_COUNTER;
+ counter.iftype = connection->type;
g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
- __add_iptables_in(&counter);
- __add_iptables_out(&counter);
+ if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
+ __add_iptables_in(&counter);
+ __add_iptables_out(&counter);
+ } else if (app_value->classid == STC_TOTAL_IPV6_CLASSID) {
+ __add_ip6tables_in(&counter);
+ __add_ip6tables_out(&counter);
+ } else {
+ __add_iptables_in(&counter);
+ __add_iptables_out(&counter);
+ __add_ip6tables_in(&counter);
+ __add_ip6tables_out(&counter);
+ }
}
return FALSE;
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return FALSE;
+
stc->carg->sock = stc_monitor_get_counter_socket();
}
counter.carg = stc->carg;
counter.classid = app_value->classid;
counter.intend = NFACCT_COUNTER;
+ counter.iftype = connection->type;
g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
__del_iptables_in(&counter);
__del_iptables_out(&counter);
+ __del_ip6tables_in(&counter);
+ __del_ip6tables_out(&counter);
}
return FALSE;
"limit [ (%lld) bytes], "
"warn_limit [ (%lld) bytes], "
"counter [ (%lld) bytes], "
- "roaming [%d], imsi [%s]",
+ "roaming [%d], subscriber_id [%s]",
rstn_value->restriction_id,
rstn_key->app_id, rstn_value->classid , rstn_key->ifname,
rstn_key->iftype, rstn_value->rst_state,
rstn_value->data_limit,
rstn_value->data_warn_limit,
rstn_value->data_counter,
- rstn_key->roaming, rstn_key->imsi);
+ rstn_key->roaming, rstn_key->subscriber_id);
}
static void __process_restriction(enum traffic_restriction_type rst_type,
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL) {
+ g_free(default_ifname);
+ return;
+ }
+
stc->carg->sock =
stc_monitor_get_counter_socket();
}
counter.carg = stc->carg;
counter.classid = rstn_value->classid;
counter.intend = NFACCT_BLOCK;
- counter.iftype = STC_IFACE_UNKNOWN;
+ counter.iftype = rstn_key->iftype;
g_strlcpy(counter.ifname, default_ifname,
MAX_IFACE_LENGTH);
/* iptables rule */
__add_iptables_in(&counter);
__add_iptables_out(&counter);
+
+ /* ip6tables rule */
+ __add_ip6tables_in(&counter);
+ __add_ip6tables_out(&counter);
}
rstn_value->rst_state = STC_RESTRICTION_ACTIVATED;
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL) {
+ g_free(default_ifname);
+ return;
+ }
+
stc->carg->sock =
stc_monitor_get_counter_socket();
}
counter.carg = stc->carg;
counter.classid = rstn_value->classid;
counter.intend = NFACCT_BLOCK;
- counter.iftype = STC_IFACE_UNKNOWN;
+ counter.iftype = rstn_key->iftype;
g_strlcpy(counter.ifname, default_ifname,
MAX_IFACE_LENGTH);
__del_iptables_in(&counter);
__del_iptables_out(&counter);
+ /* ip6tables rule */
+ __del_ip6tables_in(&counter);
+ __del_ip6tables_out(&counter);
+
rstn_value->rst_state = STC_RESTRICTION_REMOVED;
rstn_value->data_limit_reached = FALSE;
}
ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
/* close netlink socket for updating kernel counters */
- if (g_system->contr_sock != -1) {
- close(g_system->contr_sock);
- g_system->contr_sock = -1;
+ if (system->contr_sock != -1) {
+ close(system->contr_sock);
+ system->contr_sock = -1;
}
- if (g_system->contr_gsource_id != 0) {
- g_source_remove(g_system->contr_gsource_id);
- g_system->contr_gsource_id = 0;
+ if (system->contr_gsource_id != 0) {
+ g_source_remove(system->contr_gsource_id);
+ system->contr_gsource_id = 0;
}
return STC_ERROR_NONE;
}
-static gboolean __rstn_counter_update_foreach_classid(gpointer key,
- gpointer value,
- gpointer data)
+static gboolean __process_contr_reply(GIOChannel *source,
+ GIOCondition condition,
+ gpointer user_data);
+
+static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
{
- stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
- stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
- classid_bytes_context_s *context = (classid_bytes_context_s *)data;
+ GIOChannel *gio = NULL;
+ ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
- if (context->counter->intend != NFACCT_COUNTER)
- goto try_next_callback;
+ /* close netlink socket for updating kernel counters */
+ if (system->contr_sock != -1) {
+ close(system->contr_sock);
+ system->contr_sock = -1;
+ }
- if (rstn_value->classid != context->counter->classid)
- goto try_next_callback;
+ if (system->contr_gsource_id != 0) {
+ g_source_remove(system->contr_gsource_id);
+ system->contr_gsource_id = 0;
+ }
- if (rstn_value->data_limit_reached == TRUE) {
- context->data_limit_reached = TRUE;
- goto try_next_callback;
+ /* create netlink socket for updating kernel counters */
+ system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
+ if (!(system->contr_sock)) {
+ STC_LOGE("failed to open socket");
+ FREE(system);
+ return STC_ERROR_FAIL;
}
+ gio = g_io_channel_unix_new(system->contr_sock);
+ system->contr_gsource_id =
+ g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
+ (GIOFunc) __process_contr_reply,
+ NULL);
+ g_io_channel_unref(gio);
+
+ return STC_ERROR_NONE;
+}
+
+static gboolean __rstn_counter_update(stc_rstn_key_s *rstn_key,
+ stc_rstn_value_s *rstn_value,
+ classid_bytes_context_s *context)
+{
switch (context->counter->iotype) {
case NFACCT_COUNTER_IN:
case NFACCT_COUNTER_OUT:
if (rstn_value->data_counter >= rstn_value->data_warn_limit &&
rstn_value->warn_limit_crossed_notified == FALSE) {
- gboolean rv = FALSE;
+ gboolean rv;
char iftype[MAX_INT_LENGTH];
char byte[MAX_INT_LENGTH];
stc_s *stc = (stc_s *)stc_get_manager();
STC_DBUS_SERVICE_RESTRICTION_PATH,
STC_DBUS_INTERFACE_RESTRICTION,
"WarnThresholdCrossed",
- g_variant_new("(s)", rstn_key->app_id));
+ g_variant_new("(si)", rstn_key->app_id, rstn_key->iftype));
if (rv == TRUE)
rstn_value->warn_limit_crossed_notified = TRUE;
if (rstn_value->data_counter >= rstn_value->data_limit &&
rstn_value->rstn_limit_crossed_notified == FALSE) {
- gboolean rv = FALSE;
+ gboolean rv;
char iftype[MAX_INT_LENGTH];
char byte[MAX_INT_LENGTH];
stc_s *stc = (stc_s *)stc_get_manager();
__del_iptables_out(context->counter);
__add_iptables_in(context->counter);
__add_iptables_out(context->counter);
+
+ __del_ip6tables_in(context->counter);
+ __del_ip6tables_out(context->counter);
+ __add_ip6tables_in(context->counter);
+ __add_ip6tables_out(context->counter);
context->counter->intend = NFACCT_COUNTER;
rstn_value->data_limit_reached = TRUE;
STC_DBUS_SERVICE_RESTRICTION_PATH,
STC_DBUS_INTERFACE_RESTRICTION,
"RestrictionThresholdCrossed",
- g_variant_new("(s)", rstn_key->app_id));
+ g_variant_new("(si)", rstn_key->app_id, rstn_key->iftype));
if (rv == TRUE)
rstn_value->rstn_limit_crossed_notified = TRUE;
STC_LOGE("unknown iotype");
}
+ return FALSE;
+}
+
+static gboolean __interface_rstn_counter_update(stc_rstn_key_s *rstn_key,
+ stc_rstn_value_s *rstn_value,
+ classid_bytes_context_s *context)
+{
+ if ((rstn_value->classid == STC_TOTAL_DATACALL_CLASSID &&
+ context->counter->iftype == STC_IFACE_DATACALL) ||
+ (rstn_value->classid == STC_TOTAL_WIFI_CLASSID &&
+ context->counter->iftype == STC_IFACE_WIFI) ||
+ (rstn_value->classid == STC_TOTAL_BLUETOOTH_CLASSID &&
+ context->counter->iftype == STC_IFACE_BLUETOOTH)) {
+ context->counter->classid = rstn_value->classid;
+ return __rstn_counter_update(rstn_key, rstn_value, context);
+ }
-try_next_callback:
return FALSE;
}
+static gboolean __rstn_counter_update_foreach_classid(gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ gboolean rv = FALSE;
+ stc_rstn_key_s *rstn_key = (stc_rstn_key_s *)key;
+ stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
+ classid_bytes_context_s *context = (classid_bytes_context_s *)data;
+ uint32_t classid;
+
+ if (context->counter->intend != NFACCT_COUNTER)
+ goto try_next_callback;
+
+ if (rstn_value->data_limit_reached == TRUE) {
+ context->data_limit_reached = TRUE;
+ goto try_next_callback;
+ }
+
+ classid = context->counter->classid;
+ rv = __interface_rstn_counter_update(rstn_key, rstn_value, context);
+
+ context->counter->classid = classid;
+ if (rstn_value->classid != context->counter->classid)
+ goto try_next_callback;
+
+ rv = __rstn_counter_update(rstn_key, rstn_value, context);
+
+try_next_callback:
+ return rv;
+}
+
static gboolean __update_app_statistics(gpointer key, gpointer value,
gpointer data)
{
time_t *touch_time = (time_t *)data;
stc_db_classid_iftype_key stat_key;
stc_db_app_stats stat;
- char *default_ifname = stc_default_connection_get_ifname();
+ default_connection_s *default_connection = stc_get_default_connection();
memset(&stat_key, 0, sizeof(stc_db_classid_iftype_key));
memset(&stat, 0 , sizeof(stc_db_app_stats));
stat_key.classid = app_value->classid;
- stat_key.iftype = stc_default_connection_get_type();
+ stat_key.iftype = default_connection->type;
+
if (STC_IFACE_DATACALL == stat_key.iftype)
- stat_key.imsi = g_strdup("unknown");
+ stat_key.subscriber_id = g_strdup(default_connection->subscriber_id);
else
- stat_key.imsi = g_strdup("noneimsi");
- g_strlcpy(stat_key.ifname, default_ifname, MAX_IFACE_LENGTH);
+ stat_key.subscriber_id = g_strdup("none_subid");
+
+ g_strlcpy(stat_key.ifname, default_connection->ifname,
+ MAX_IFACE_LENGTH);
stat.app_id = g_strdup(app_key->app_id);
stat.snd_count = app_value->counter.out_bytes;
stat.rcv_count = app_value->counter.in_bytes;
- stat.is_roaming = stc_default_connection_get_roaming();
+ stat.is_roaming = default_connection->roaming;
stat.ground = STC_APP_STATE_UNKNOWN;
table_statistics_insert(&stat_key, &stat, *touch_time);
app_value->counter.in_bytes = 0;
FREE(stat.app_id);
- FREE(stat_key.imsi);
- FREE(default_ifname);
+ FREE(stat_key.subscriber_id);
return FALSE;
}
return G_SOURCE_REMOVE;
}
-static gboolean __apps_counter_update_foreach_classid(gpointer key,
- gpointer value,
- gpointer data)
+static void __app_counter_update(stc_app_key_s *app_key,
+ stc_app_value_s *app_value,
+ classid_bytes_context_s *context)
{
- stc_app_key_s *app_key = (stc_app_key_s *)key;
- stc_app_value_s *app_value = (stc_app_value_s *)value;
- classid_bytes_context_s *context = (classid_bytes_context_s *)data;
-
- if (context->counter->intend != NFACCT_COUNTER)
- goto try_next_callback;
-
- if (app_value->classid != context->counter->classid)
- goto try_next_callback;
-
switch (context->counter->iotype) {
case NFACCT_COUNTER_IN:
app_value->data_usage.in_bytes += context->bytes;
default:
STC_LOGE("unknown iotype");
}
+}
+
+static void __interface_counter_update(stc_app_key_s *app_key,
+ stc_app_value_s *app_value,
+ classid_bytes_context_s *context)
+{
+ if ((app_value->classid == STC_TOTAL_DATACALL_CLASSID &&
+ context->counter->iftype == STC_IFACE_DATACALL) ||
+ (app_value->classid == STC_TOTAL_WIFI_CLASSID &&
+ context->counter->iftype == STC_IFACE_WIFI) ||
+ (app_value->classid == STC_TOTAL_BLUETOOTH_CLASSID &&
+ context->counter->iftype == STC_IFACE_BLUETOOTH))
+ __app_counter_update(app_key, app_value, context);
+}
+
+
+static gboolean __apps_counter_update_foreach_classid(gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ stc_app_key_s *app_key = (stc_app_key_s *)key;
+ stc_app_value_s *app_value = (stc_app_value_s *)value;
+ classid_bytes_context_s *context = (classid_bytes_context_s *)data;
+
+ if (context->counter->intend != NFACCT_COUNTER)
+ goto try_next_callback;
+
+ __interface_counter_update(app_key, app_value, context);
+
+ if (app_value->classid != context->counter->classid)
+ goto try_next_callback;
+
+ __app_counter_update(app_key, app_value, context);
try_next_callback:
return FALSE;
(condition & G_IO_NVAL)) {
/* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */
- __close_contr_sock(g_system);
+ STC_LOGE("Counter socket received G_IO event, closing socket."
+ "G_IO_ERR [%d], G_IO_HUP [%d], G_IO_NVAL [%s]",
+ (condition & G_IO_ERR), (condition & G_IO_HUP),
+ (condition & G_IO_NVAL));
+ __close_and_reopen_contr_sock(g_system);
return FALSE;
}
ret = read_netlink(sock,
&ans, sizeof(struct genl));
- STC_LOGD("Counter data received ret [%d]", ret);
+ /* STC_LOGD("Counter data received ret [%d]", ret); */
if (ret == 0)
goto out;
ret_value_msg_if(stc == NULL, STC_ERROR_FAIL, "Can't get stc data");
if (!stc->carg) {
stc->carg = MALLOC0(counter_arg_s, 1);
+ if (stc->carg == NULL)
+ return TRUE; /* we need to continue the timer */
+
stc->carg->sock = stc_monitor_get_counter_socket();
}
- STC_LOGD("Get all counters");
+ /* STC_LOGD("Get all counters"); */
nfacct_send_get_all(stc->carg);
/* we need to continue the timer */
rstn_key->app_id = g_strdup(key->app_id);
rstn_key->ifname = g_strdup(key->ifname);
- rstn_key->imsi = g_strdup(key->imsi);
+ rstn_key->subscriber_id = g_strdup(key->subscriber_id);
rstn_key->iftype = key->iftype;
rstn_key->roaming = key->roaming;
key.app_id = g_strdup(info->app_id);
key.ifname = g_strdup(info->ifname);
- key.imsi = g_strdup(info->imsi);
+ key.subscriber_id = g_strdup(info->subscriber_id);
key.iftype = info->iftype;
key.roaming = info->roaming;
FREE(key.app_id);
FREE(key.ifname);
- FREE(key.imsi);
+ FREE(key.subscriber_id);
return ret;
}
app_id);
}
+static void __add_application_by_interface(const char *app_id)
+{
+ stc_app_key_s app_key;
+ stc_app_value_s app_value;
+
+ if (app_id == NULL)
+ return;
+
+ memset(&app_key, 0, sizeof(stc_app_key_s));
+ memset(&app_value, 0, sizeof(stc_app_value_s));
+
+ app_key.pkg_id = g_strdup(app_id);
+ app_key.app_id = g_strdup(app_id);
+
+ app_value.type = STC_APP_TYPE_NONE;
+ app_value.processes = NULL;
+ app_value.counter.in_bytes = 0;
+ app_value.counter.out_bytes = 0;
+
+ stc_monitor_application_add(app_key, app_value);
+
+ FREE(app_key.pkg_id);
+ FREE(app_key.app_id);
+}
+
+static int __vconf_get_int(const char *key, int *value)
+{
+ int ret = 0;
+
+ ret = vconf_get_int(key, value);
+ if (ret != VCONF_OK) {
+ STC_LOGE("Failed to get vconfkey [%s] value", key);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int __vconf_set_int(const char *key, int value)
+{
+ int ret = 0;
+
+ ret = vconf_set_int(key, value);
+ if (ret != VCONF_OK) {
+ STC_LOGE("Failed to set vconfkey [%s] value", key);
+ return -1;
+ }
+
+ return 0;
+}
+
+static guint __get_background_state(void)
+{
+ return g_system->background_state;;
+}
+
+static void __set_background_state(guint state)
+{
+ g_system->background_state = state;
+}
+
+static gboolean __processes_tree_foreach_background(gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ stc_process_key_s *proc_key = (stc_process_key_s *)key;
+ stc_app_key_s *app_key = (stc_app_key_s *)data;
+
+ if (g_system->background_state)
+ place_pids_to_net_cgroup(proc_key->pid, STC_BACKGROUND_APP_ID);
+ else
+ place_pids_to_net_cgroup(proc_key->pid, app_key->app_id);
+
+ return FALSE;
+}
+
+static gboolean __apps_tree_foreach_background(gpointer key, gpointer value,
+ gpointer data)
+{
+ stc_app_key_s *app_key = (stc_app_key_s *)key;
+ stc_app_value_s *app_value = (stc_app_value_s *)value;
+
+ if (strstr(app_key->app_id, STC_BACKGROUND_APP_SUFFIX))
+ g_tree_foreach(app_value->processes,
+ __processes_tree_foreach_background, app_key);
+
+ return FALSE;
+}
+
+static stc_error_e __process_update_background(void)
+{
+ ret_value_msg_if(g_system == NULL, STC_ERROR_FAIL, "stc monitor not initialized!");
+
+ g_tree_foreach(g_system->apps, __apps_tree_foreach_background, NULL);
+
+ return STC_ERROR_NONE;
+}
+
+#if 0
+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);
+}
+#endif
+
+static gboolean __remove_exception_app(gpointer key, gpointer value,
+ gpointer data)
+{
+ const char *exe_type = value;
+
+ if (g_strcmp0(exe_type, EXE_TYPE_APPLICATION) == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
+static void __remove_exception_appall(void)
+{
+ g_hash_table_foreach_remove(g_system->excns_hash,
+ __remove_exception_app, NULL);
+}
+
+static stc_cb_ret_e __insert_exception_cb(const stc_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);
+ pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
+
+ /* __excn_hash_printall(); */
+}
+
+static gboolean __update_exceptions_app_list(void *user_data)
+{
+ __remove_exception_appall();
+ pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
+
+ /* __excn_hash_printall(); */
+
+ return TRUE;
+}
+
stc_error_e stc_monitor_init(void)
{
stc_system_s *system = MALLOC0(stc_system_s, 1);
ret_value_msg_if(system == NULL, STC_ERROR_OUT_OF_MEMORY, "stc_system_s malloc fail!");
+ /* initializing current classid */
+ init_current_classid();
+
/* initializing cgroups */
cgroup_init();
__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)) {
g_system = system;
+ __add_application_by_interface(STC_TOTAL_DATACALL);
+ __add_application_by_interface(STC_TOTAL_WIFI);
+ __add_application_by_interface(STC_TOTAL_BLUETOOTH);
+ __add_application_by_interface(STC_TOTAL_IPV4);
+ __add_application_by_interface(STC_TOTAL_IPV6);
+
/* creating restriction rules tree */
__update_contr_cb(NULL);
return STC_ERROR_FAIL;
}
+ __vconf_get_int(VCONFKEY_STC_BACKGROUND_STATE,
+ (int *)&g_system->background_state);
+
+ __fill_exceptions_list();
__fill_restritions_list();
+ g_system->excns_timer_id = g_timeout_add_seconds(EXCNS_TIMER_INTERVAL,
+ __update_exceptions_app_list,
+ NULL);
+
return STC_ERROR_NONE;
}
g_system->contr_timer_id = 0;
}
+ /* remove exceptions app list update timer */
+ if (g_system->excns_timer_id > 0) {
+ g_source_remove(g_system->excns_timer_id);
+ g_system->excns_timer_id = 0;
+ }
+
/* destroy monitored application tree */
g_tree_destroy(g_system->apps);
g_system->apps = NULL;
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;
if (proc_lookup->ground != ground)
proc_lookup->ground = ground;
- if (ground == STC_APP_STATE_BACKGROUND) {
- char *background_app_id = g_strconcat(app_key.app_id,
- STC_BACKGROUND_APP_SUFFIX,
- NULL);
- place_pids_to_net_cgroup(proc_key.pid, background_app_id);
- g_free(background_app_id);
- } else {
+ if (ground == STC_APP_STATE_BACKGROUND && __get_background_state())
+ place_pids_to_net_cgroup(proc_key.pid, STC_BACKGROUND_APP_ID);
+ else
place_pids_to_net_cgroup(proc_key.pid, app_key.app_id);
- }
return ret;
}
key.app_id = g_strdup(info->app_id);
key.ifname = g_strdup(info->ifname);
- key.imsi = g_strdup(info->imsi);
+ key.subscriber_id = g_strdup(info->subscriber_id);
key.iftype = info->iftype;
key.roaming = info->roaming;
else
value.classid = STC_UNKNOWN_CLASSID;
+ if (value.classid == STC_BACKGROUND_APP_CLASSID) {
+ __set_background_state(TRUE);
+ __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state);
+ __process_update_background();
+ }
+
value.data_limit = info->data_limit;
value.data_warn_limit = info->data_warn_limit;
FREE(key.app_id);
FREE(key.ifname);
- FREE(key.imsi);
+ FREE(key.subscriber_id);
return ret;
}
stc_rstn_key_s key = {
.app_id = g_strdup(info->app_id),
.ifname = g_strdup(info->ifname),
- .imsi = g_strdup(info->imsi),
+ .subscriber_id = g_strdup(info->subscriber_id),
.iftype = info->iftype,
.roaming = info->roaming,
};
+ if (!strcmp(key.app_id, STC_BACKGROUND_APP_ID)) {
+ __set_background_state(FALSE);
+ __vconf_set_int(VCONFKEY_STC_BACKGROUND_STATE, g_system->background_state);
+ __process_update_background();
+ }
+
ret = __rstn_tree_remove(&key);
FREE(key.app_id);
FREE(key.ifname);
- FREE(key.imsi);
+ FREE(key.subscriber_id);
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;