FREE(key);
}
+/*
//LCOV_EXCL_START
static gboolean __processes_tree_foreach_print(gpointer key, gpointer value,
gpointer data)
g_tree_foreach(g_system->apps, __apps_tree_foreach_print, NULL);
}
//LCOV_EXCL_STOP
+*/
static gboolean __apps_tree_foreach_remove_pid(gpointer key, gpointer value,
gpointer data)
remove_pid_context_s *context = (remove_pid_context_s *)data;
stc_app_value_s *app_value = (stc_app_value_s *)value;
- if (!g_tree_remove(app_value->processes, context->proc_key)) {
- if (STC_DEBUG_LOG)
- STC_LOGD("key not found"); //LCOV_EXCL_LINE
+ if (!g_tree_remove(app_value->processes, context->proc_key))
return FALSE;
- }
context->entry_removed = TRUE;
context->app_key = (stc_app_key_s *)key;
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);
+
+ if (connection->tether_state == TRUE &&
+ connection->tether_iface.ifname != NULL &&
+ app_value->classid == STC_TETHERING_APP_CLASSID) {
+ counter.iftype = connection->tether_iface.type;
+ g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+ } else {
+ counter.iftype = connection->type;
+ g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
+ }
if (app_value->classid == STC_TOTAL_IPV4_CLASSID) {
__add_iptables_in(&counter);
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);
+
+ if (connection->tether_state == FALSE &&
+ connection->tether_iface.ifname != NULL &&
+ app_value->classid == STC_TETHERING_APP_CLASSID) {
+ counter.iftype = connection->tether_iface.type;
+ g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+ } else {
+ counter.iftype = connection->type;
+ g_strlcpy(counter.ifname, connection->ifname, MAX_IFACE_LENGTH);
+ }
__del_iptables_in(&counter);
__del_iptables_out(&counter);
static void __print_rstn(stc_rstn_key_s *rstn_key, stc_rstn_value_s *rstn_value)
{
STC_LOGI("rstn info => rstn_id [%llu], "
- "app_id [%s], classid [%lu], ifname [%s], "
+ "app_id [%s], classid [%u], ifname [%s], "
"iftype [%d], rstn_state [%d], rstn_type [%d], "
"limit [ (%lld) bytes], "
"warn_limit [ (%lld) bytes], "
stc_iface_type_e iftype)
{
char *default_ifname = stc_default_connection_get_ifname();
+ default_connection_s *connection = stc_get_default_connection();
struct nfacct_rule counter;
stc_s *stc = stc_get_manager();
if (!stc) {
counter.carg = stc->carg;
counter.classid = classid;
counter.intend = intend;
- counter.iftype = iftype;
- g_strlcpy(counter.ifname, default_ifname, MAX_IFACE_LENGTH);
+
+ if (connection && connection->tether_iface.ifname != NULL &&
+ classid == STC_TETHERING_APP_CLASSID) {
+ counter.iftype = connection->tether_iface.type;
+ g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+ } else {
+ counter.iftype = iftype;
+ g_strlcpy(counter.ifname, default_ifname, MAX_IFACE_LENGTH);
+ }
+
g_free(default_ifname);
/* iptables rule */
stc_iface_type_e iftype)
{
char *default_ifname = stc_default_connection_get_ifname();
+ default_connection_s *connection = stc_get_default_connection();
struct nfacct_rule counter;
stc_s *stc = stc_get_manager();
if (!stc) {
counter.carg = stc->carg;
counter.classid = classid;
counter.intend = intend;
- counter.iftype = iftype;
- g_strlcpy(counter.ifname, default_ifname, MAX_IFACE_LENGTH);
+
+ if (connection && connection->tether_iface.ifname != NULL &&
+ classid == STC_TETHERING_APP_CLASSID) {
+ counter.iftype = connection->tether_iface.type;
+ g_strlcpy(counter.ifname, connection->tether_iface.ifname, MAX_IFACE_LENGTH);
+ } else {
+ counter.iftype = iftype;
+ g_strlcpy(counter.ifname, default_ifname, MAX_IFACE_LENGTH);
+ }
+
g_free(default_ifname);
/* iptables rule */
/* rstn not applicable for this interface */
if (rstn_key->ifname != NULL && g_strcmp0("", rstn_key->ifname) != 0 &&
- g_strcmp0(connection->ifname, rstn_key->ifname) != 0)
+ (g_strcmp0(connection->ifname, rstn_key->ifname) != 0) &&
+ (g_strcmp0(connection->tether_iface.ifname, rstn_key->ifname) != 0))
return;
/* classid is invalid */
rstn_value->data_limit_reached = TRUE;
break;
case RST_UNSET:
- __del_iptables_rule(rstn_value->classid, rstn_value->rstn_type,
- rstn_key->iftype);
+ if (rstn_value->classid == STC_TETHERING_APP_CLASSID)
+ __del_iptables_rule(rstn_value->classid, NFACCT_BLOCK,
+ rstn_key->iftype);
+ else
+ __del_iptables_rule(rstn_value->classid, rstn_value->rstn_type,
+ rstn_key->iftype);
rstn_value->rstn_state = STC_RSTN_STATE_DEACTIVATED;
rstn_value->data_limit_reached = FALSE;
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->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) ||
+ (rstn_value->classid == STC_TETHERING_APP_CLASSID &&
+ context->counter->iftype == STC_IFACE_WIFI) ||
+ (rstn_value->classid == STC_TETHERING_APP_CLASSID &&
+ context->counter->iftype == STC_IFACE_BLUETOOTH) ||
+ (rstn_value->classid == STC_TETHERING_APP_CLASSID &&
+ context->counter->iftype == STC_IFACE_USB) ||
+ (rstn_value->classid == STC_TETHERING_APP_CLASSID &&
+ context->counter->iftype == STC_IFACE_P2P)) {
context->counter->classid = rstn_value->classid;
return __rstn_counter_update(rstn_key, rstn_value, context);
}
memset(&stat_key, 0, sizeof(stc_db_classid_iftype_key));
memset(&stat, 0 , sizeof(stc_db_app_stats));
+ /* Do not update statistics for Tethering
+ * if tethering is in-active found */
+ if (default_connection &&
+ default_connection->tether_state == FALSE &&
+ !strcmp(app_key->app_id, STC_TOTAL_TETHERING))
+ return FALSE;
+
+ /* Do not update statistics for Wi-Fi
+ * if tethering is active on wlan0 iface */
+ if (default_connection && default_connection->tether_state &&
+ default_connection->tether_iface.type == STC_IFACE_WIFI &&
+ !strcmp(app_key->app_id, STC_TOTAL_WIFI))
+ return FALSE;
+
stat_key.classid = app_value->classid;
- stat_key.iftype = default_connection->type;
+
+ if (app_value->classid == STC_TETHERING_APP_CLASSID &&
+ default_connection->tether_state == TRUE)
+ stat_key.iftype = default_connection->tether_iface.type;
+ else
+ stat_key.iftype = default_connection->type;
if (STC_IFACE_DATACALL == stat_key.iftype)
stat_key.subscriber_id = g_strdup(default_connection->subscriber_id);
else
stat_key.subscriber_id = g_strdup("none_subid"); //LCOV_EXCL_LINE
- g_strlcpy(stat_key.ifname, default_connection->ifname,
- MAX_IFACE_LENGTH);
+ if (app_value->classid == STC_TETHERING_APP_CLASSID &&
+ default_connection->tether_state == TRUE)
+ g_strlcpy(stat_key.ifname, default_connection->tether_iface.ifname,
+ MAX_IFACE_LENGTH);
+ else
+ 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;
app_value->counter.in_bytes = context->bytes;
g_system->apps_tree_updated = TRUE;
- if (STC_DEBUG_LOG)
- __apps_tree_foreach_print(app_key, app_value, NULL); //LCOV_EXCL_LINE
+ /*
+ __apps_tree_foreach_print(app_key, app_value, NULL); //LCOV_EXCL_LINE
+ */
break;
case NFACCT_COUNTER_OUT:
app_value->data_usage.out_bytes += context->bytes;
app_value->counter.out_bytes = context->bytes;
g_system->apps_tree_updated = TRUE;
- if (STC_DEBUG_LOG)
- __apps_tree_foreach_print(app_key, app_value, NULL); //LCOV_EXCL_LINE
+ /*
+ __apps_tree_foreach_print(app_key, app_value, NULL); //LCOV_EXCL_LINE
+ */
break;
default:
STC_LOGE("unknown iotype"); //LCOV_EXCL_LINE
(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))
+ context->counter->iftype == STC_IFACE_BLUETOOTH) ||
+ (app_value->classid == STC_TETHERING_APP_CLASSID &&
+ context->counter->iftype == STC_IFACE_WIFI) ||
+ (app_value->classid == STC_TETHERING_APP_CLASSID &&
+ context->counter->iftype == STC_IFACE_BLUETOOTH) ||
+ (app_value->classid == STC_TETHERING_APP_CLASSID &&
+ context->counter->iftype == STC_IFACE_USB) ||
+ (app_value->classid == STC_TETHERING_APP_CLASSID &&
+ context->counter->iftype == STC_IFACE_P2P))
__app_counter_update(app_key, app_value, context);
}
return; //LCOV_EXCL_LINE
}
- STC_LOGI("classid %lu, iftype %u, iotype %d, intend %d, ifname %s, bytes %lld",
- context.counter->classid, context.counter->iftype,
- context.counter->iotype, context.counter->intend,
- context.counter->ifname, context.bytes);
+ if (STC_DEBUG_LOG)
+ STC_LOGI("classid %u, iftype %u, iotype %d, intend %d, ifname %s, bytes %lld",
+ context.counter->classid, context.counter->iftype,
+ context.counter->iotype, context.counter->intend,
+ context.counter->ifname, context.bytes);
if (g_system->rstns)
g_tree_foreach(g_system->rstns,
/* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */
STC_LOGE("Counter socket received G_IO event, closing socket." //LCOV_EXCL_LINE
- "G_IO_ERR [%d], G_IO_HUP [%d], G_IO_NVAL [%s]",
+ "G_IO_ERR [%u], G_IO_HUP [%u], G_IO_NVAL [%u]",
(condition & G_IO_ERR), (condition & G_IO_HUP),
(condition & G_IO_NVAL));
__close_and_reopen_contr_sock(g_system); //LCOV_EXCL_LINE
return TRUE;
}
+/*
//LCOV_EXCL_START
static gboolean __rstn_tree_foreach_print(gpointer key, gpointer value,
gpointer data)
{
g_tree_foreach(g_system->rstns, __rstn_tree_foreach_print, NULL);
}
-//LCOV_EXCL_END
+//LCOV_EXCL_STOP
+*/
static stc_rstn_value_s * __rstn_lookup(GTree *rstns_tree,
const stc_rstn_key_s *key)
{
table_restrictions_foreach(__insert_restriction_cb, NULL);
- if (STC_DEBUG_LOG)
- __rstn_tree_printall();
+ /* __rstn_tree_printall(); */
}
static gboolean __add_rstn_foreach_application(gpointer key,
__add_application_by_interface(STC_TOTAL_BLUETOOTH);
__add_application_by_interface(STC_TOTAL_IPV4);
__add_application_by_interface(STC_TOTAL_IPV6);
+ __add_application_by_interface(STC_TOTAL_TETHERING);
/* creating restriction rules tree */
__update_contr_cb(NULL);
lookup = __application_lookup(g_system->apps, &app_key);
if (lookup) {
- STC_LOGD("app_key already present"); //LCOV_EXCL_LINE
+ if (STC_DEBUG_LOG)
+ STC_LOGD("app_key already present"); //LCOV_EXCL_LINE
return STC_ERROR_NONE; //LCOV_EXCL_LINE
}
app_lookup = __application_lookup(g_system->apps, &app_key);
if (!app_lookup) {
- STC_LOGD("app_key not found"); //LCOV_EXCL_LINE
+ if (STC_DEBUG_LOG)
+ STC_LOGD("app_key not found"); //LCOV_EXCL_LINE
return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
proc_lookup = __process_lookup(app_lookup->processes, &proc_key);
if (proc_lookup) {
- STC_LOGD("proc_key already present"); //LCOV_EXCL_LINE
+ if (STC_DEBUG_LOG)
+ STC_LOGD("proc_key already present"); //LCOV_EXCL_LINE
return STC_ERROR_NONE; //LCOV_EXCL_LINE
}
/* add pid to application cgroup */
place_pids_to_net_cgroup(proc_key.pid, app_key.app_id);
- if (STC_DEBUG_LOG)
- __apps_tree_printall(); //LCOV_EXCL_LINE
+ /*
+ __apps_tree_printall(); //LCOV_EXCL_LINE
+ */
return ret;
}
if (context.entry_removed)
__application_remove_if_empty(context.app_key);
- if (STC_DEBUG_LOG)
- __apps_tree_printall(); //LCOV_EXCL_LINE
+ /*
+ __apps_tree_printall(); //LCOV_EXCL_LINE
+ */
return ret;
}
FREE(old_connection.path);
FREE(old_connection.ifname);
+ FREE(old_connection.tether_iface.ifname);
old_connection.type = 0;
old_connection.roaming = 0;
+ old_connection.tether_state = FALSE;
+ old_connection.tether_iface.type = 0;
if (new_connection != NULL && new_connection->path != NULL) {
if (g_system->apps)
old_connection.path = g_strdup(new_connection->path);
old_connection.ifname = g_strdup(new_connection->ifname);
+ old_connection.tether_iface.ifname = g_strdup(new_connection->tether_iface.ifname);
old_connection.type = new_connection->type;
old_connection.roaming = new_connection->roaming;
+ old_connection.tether_state = new_connection->tether_state;
+ old_connection.tether_iface.type = new_connection->tether_iface.type;
}
}