binpath TEXT,
iftype INT,
ifname TEXT,
- rst_type INT,
+ rstn_type INT,
roaming INT,
subscriber_id TEXT NOT NULL,
data_limit BIGINT,
* @brief Network restriction states
*/
typedef enum {
- STC_RESTRICTION_UNKNOWN,
- STC_RESTRICTION_ACTIVATED, /**< restriction has been activated */
- STC_RESTRICTION_DEACTIVATED, /**< restriction has been deactivated */
- STC_RESTRICTION_LAST_ELEM
-} stc_restriction_state_e;
+ STC_RSTN_STATE_UNKNOWN,
+ STC_RSTN_STATE_ACTIVATED,
+ STC_RSTN_STATE_DEACTIVATED,
+ STC_RSTN_STATE_LAST_ELEM
+} stc_rstn_state_e;
/**
* @brief Network restriction types
*/
typedef enum {
STC_RSTN_TYPE_UNKNOWN,
- STC_RSTN_TYPE_EXCLUDED, /**< exclusion */
- STC_RSTN_TYPE_BLOCKED, /**< block */
+ STC_RSTN_TYPE_ACCEPT,
+ STC_RSTN_TYPE_DROP,
STC_RSTN_TYPE_LAST_ELEM
} stc_rstn_type_e;
GVariant *parameters,
void *user_data);
+gboolean handle_restriction_unset(StcRestriction *object,
+ GDBusMethodInvocation *invocation,
+ GVariant *parameters,
+ void *user_data);
+
gboolean handle_restriction_get(StcRestriction *object,
GDBusMethodInvocation *invocation,
const gchar *app_id,
GDBusMethodInvocation *invocation,
void *user_data);
-gboolean handle_restriction_get_state(StcRestriction *object,
+gboolean handle_restriction_get_type(StcRestriction *object,
GDBusMethodInvocation *invocation,
const gchar *app_id,
int iftype,
void *user_data);
-gboolean handle_restriction_unset(StcRestriction *object,
- GDBusMethodInvocation *invocation,
- GVariant *parameters,
- void *user_data);
-
#endif /* __STC_RESTRICTION_H__ */
<method name='Unlock'>
<arg type='i' name='error_code' direction='out'/>
</method>
+
<method name='GetLock'>
<arg type='i' name='state' direction='out'/>
</method>
<arg type='aa{sv}' name='parameters' direction='out'/>
</method>
- <method name='GetState'>
+ <method name='GetType'>
<arg type='s' name='app_id' direction='in'/>
<arg type='i' name='iftype' direction='in'/>
<arg type='i' name='error_code' direction='out'/>
- <arg type='i' name='state' direction='out'/>
+ <arg type='i' name='type' direction='out'/>
</method>
<method name='Unset'>
Name: stc-manager
Summary: STC(Smart Traffic Control) manager
-Version: 0.0.57
+Version: 0.0.58
Release: 0
Group: Network & Connectivity/Other
License: Apache-2.0
}
};
-
static stc_error_e __ground_status_monitor_init(stc_s *stc)
{
guint i = 0;
char *ifname;
char *subscriber_id;
stc_iface_type_e iftype;
- stc_rstn_type_e rst_type;
+ stc_rstn_type_e rstn_type;
stc_roaming_type_e roaming;
int64_t data_limit;
int64_t data_warn_limit;
void *user_data);
-stc_error_e table_restrictions_get_restriction_state_subscriber_id(const char *app_id,
+stc_error_e table_restrictions_get_restriction_type_subscriber_id(const char *app_id,
stc_iface_type_e iftype,
const char *subscriber_id,
- stc_restriction_state_e *state);
+ stc_rstn_type_e *type);
-stc_error_e table_restrictions_get_restriction_state(const char *app_id,
+stc_error_e table_restrictions_get_restriction_type(const char *app_id,
stc_iface_type_e iftype,
- stc_restriction_state_e *state);
+ stc_rstn_type_e *type);
stc_error_e table_restrictions_update(table_restrictions_info *info);
/* SELECT statements */
#define SELECT_RESTRICTIONS "SELECT binpath, data_limit, " \
- " iftype, rst_type, roaming, ifname, subscriber_id, " \
+ " iftype, rstn_type, roaming, ifname, subscriber_id, " \
" data_warn_limit, restriction_id FROM restrictions"
#define SELECT_RESTRICTIONS_PER_APP "SELECT binpath, data_limit, " \
- " iftype, rst_type, roaming, ifname, subscriber_id, " \
+ " iftype, rstn_type, roaming, ifname, subscriber_id, " \
" data_warn_limit, restriction_id " \
" FROM restrictions INDEXED BY restrictions_index " \
" WHERE binpath = ?"
-#define SELECT_RESTRICTION_STATE "SELECT rst_type " \
+#define SELECT_RESTRICTION_TYPE "SELECT rstn_type " \
" FROM restrictions INDEXED BY restrictions_index " \
" WHERE binpath = ? AND iftype = ?"
-#define SELECT_RESTRICTION_STATE_SUBSCRIBER_ID "SELECT rst_type " \
+#define SELECT_RESTRICTION_TYPE_SUBSCRIBER_ID "SELECT rstn_type " \
" FROM restrictions INDEXED BY restrictions_index " \
" WHERE binpath = ? AND iftype = ? AND subscriber_id = ?"
/* UPDATE statement */
#define UPDATE_NET_RESTRICTIONS "UPDATE restrictions " \
- " SET binpath = ?, data_limit = ?, iftype = ?, rst_type = ?, " \
+ " SET binpath = ?, data_limit = ?, iftype = ?, rstn_type = ?, " \
" roaming = ?, ifname = ?, subscriber_id = ?, data_warn_limit = ? " \
" WHERE restriction_id = ?"
/* INSERT statement */
#define INSERT_NET_RESTRICTIONS "INSERT INTO restrictions " \
- " (binpath, data_limit, iftype, rst_type, " \
+ " (binpath, data_limit, iftype, rstn_type, " \
" roaming, ifname, subscriber_id, data_warn_limit) " \
" VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
/* SELECT statements */
static sqlite3_stmt *select_restriction;
static sqlite3_stmt *select_restriction_per_app;
-static sqlite3_stmt *select_restriction_state;
-static sqlite3_stmt *select_restriction_state_subscriber_id;
+static sqlite3_stmt *select_restriction_type;
+static sqlite3_stmt *select_restriction_type_subscriber_id;
static sqlite3_stmt *select_restriction_id;
/* REPLACE statements */
PREPARE_SELECT(select_restriction, SELECT_RESTRICTIONS);
PREPARE_SELECT(select_restriction_per_app, SELECT_RESTRICTIONS_PER_APP);
- PREPARE_SELECT(select_restriction_state, SELECT_RESTRICTION_STATE);
- PREPARE_SELECT(select_restriction_state_subscriber_id, SELECT_RESTRICTION_STATE_SUBSCRIBER_ID);
+ PREPARE_SELECT(select_restriction_type, SELECT_RESTRICTION_TYPE);
+ PREPARE_SELECT(select_restriction_type_subscriber_id, SELECT_RESTRICTION_TYPE_SUBSCRIBER_ID);
PREPARE_SELECT(select_restriction_id, SELECT_RESTRICTION_ID);
initialized = 1;
FINALIZE(select_restriction);
FINALIZE(select_restriction_per_app);
- FINALIZE(select_restriction_state);
- FINALIZE(select_restriction_state_subscriber_id);
+ FINALIZE(select_restriction_type);
+ FINALIZE(select_restriction_type_subscriber_id);
FINALIZE(select_restriction_id);
__STC_LOG_FUNC_EXIT__;
data.app_id = (char *)sqlite3_column_text(stmt, 0);
data.data_limit = sqlite3_column_int64(stmt, 1);
data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
- data.rst_type =
+ data.rstn_type =
(stc_rstn_type_e)sqlite3_column_int(stmt, 3);
data.roaming = sqlite3_column_int(stmt, 4);
data.ifname = (char *)sqlite3_column_text(stmt, 5);
data.app_id = (char *)sqlite3_column_text(stmt, 0);
data.data_limit = sqlite3_column_int64(stmt, 1);
data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
- data.rst_type =
+ data.rstn_type =
(stc_rstn_type_e)sqlite3_column_int(stmt, 3);
data.roaming = sqlite3_column_int(stmt, 4);
data.ifname = (char *)sqlite3_column_text(stmt, 5);
return error_code;
}
-stc_error_e table_restrictions_get_restriction_state_subscriber_id(const char *app_id,
+stc_error_e table_restrictions_get_restriction_type_subscriber_id(const char *app_id,
stc_iface_type_e iftype,
const char *subscriber_id,
- stc_restriction_state_e *state)
+ stc_rstn_type_e *type)
{
__STC_LOG_FUNC_ENTER__;
int error_code = STC_ERROR_NONE;
int ret;
bool state_subscriber_id = 0;
- if (state == NULL) {
+ if (type == NULL) {
STC_LOGE("Please provide valid argument!"); //LCOV_EXCL_LINE
__STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
- *state = STC_RESTRICTION_UNKNOWN;
- sqlite3_reset(select_restriction_state_subscriber_id);
- sqlite3_reset(select_restriction_state);
+ *type = STC_RSTN_TYPE_UNKNOWN;
+ sqlite3_reset(select_restriction_type_subscriber_id);
+ sqlite3_reset(select_restriction_type);
if (subscriber_id == NULL) {
state_subscriber_id = 0;
- DB_ACTION(sqlite3_bind_text(select_restriction_state, 1,
+ DB_ACTION(sqlite3_bind_text(select_restriction_type, 1,
app_id ? app_id : "", -1,
SQLITE_STATIC));
- DB_ACTION(sqlite3_bind_int(select_restriction_state, 2,
+ DB_ACTION(sqlite3_bind_int(select_restriction_type, 2,
iftype));
- ret = sqlite3_step(select_restriction_state);
+ ret = sqlite3_step(select_restriction_type);
} else {
state_subscriber_id = 1;
- DB_ACTION(sqlite3_bind_text(select_restriction_state_subscriber_id, 1,
+ DB_ACTION(sqlite3_bind_text(select_restriction_type_subscriber_id, 1,
app_id ? app_id : "", -1,
SQLITE_STATIC));
- DB_ACTION(sqlite3_bind_int(select_restriction_state_subscriber_id, 2,
+ DB_ACTION(sqlite3_bind_int(select_restriction_type_subscriber_id, 2,
iftype));
- DB_ACTION(sqlite3_bind_text(select_restriction_state_subscriber_id, 3,
+ DB_ACTION(sqlite3_bind_text(select_restriction_type_subscriber_id, 3,
subscriber_id, -1, SQLITE_STATIC));
- ret = sqlite3_step(select_restriction_state_subscriber_id);
+ ret = sqlite3_step(select_restriction_type_subscriber_id);
}
switch (ret) {
break;
case SQLITE_ROW:
if (state_subscriber_id)
- *state = (stc_restriction_state_e)sqlite3_column_int(select_restriction_state_subscriber_id, 0);
+ *type = (stc_rstn_type_e)sqlite3_column_int(select_restriction_type_subscriber_id, 0);
else
- *state = (stc_restriction_state_e)sqlite3_column_int(select_restriction_state, 0);
+ *type = (stc_rstn_type_e)sqlite3_column_int(select_restriction_type, 0);
break;
case SQLITE_ERROR:
default:
STC_LOGE("Can't perform sql query: %s \n%s", //LCOV_EXCL_LINE
- SELECT_RESTRICTION_STATE,
+ SELECT_RESTRICTION_TYPE,
sqlite3_errmsg(stc_db_get_database()));
error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
handle_error:
- sqlite3_reset(select_restriction_state);
- sqlite3_reset(select_restriction_state_subscriber_id);
+ sqlite3_reset(select_restriction_type);
+ sqlite3_reset(select_restriction_type_subscriber_id);
return error_code;
}
-stc_error_e table_restrictions_get_restriction_state(const char *app_id,
+stc_error_e table_restrictions_get_restriction_type(const char *app_id,
stc_iface_type_e iftype,
- stc_restriction_state_e *state)
+ stc_rstn_type_e *type)
{
__STC_LOG_FUNC_ENTER__;
__STC_LOG_FUNC_EXIT__;
- return table_restrictions_get_restriction_state_subscriber_id(app_id, iftype,
- NULL, state);
+ return table_restrictions_get_restriction_type_subscriber_id(app_id, iftype,
+ NULL, type);
}
stc_error_e table_restrictions_delete(const char *app_id,
-1, SQLITE_TRANSIENT));
DB_ACTION(sqlite3_bind_int64(stmt, 2, info->data_limit));
DB_ACTION(sqlite3_bind_int(stmt, 3, info->iftype));
- DB_ACTION(sqlite3_bind_int(stmt, 4, info->rst_type));
+ DB_ACTION(sqlite3_bind_int(stmt, 4, info->rstn_type));
DB_ACTION(sqlite3_bind_int(stmt, 5, info->roaming));
DB_ACTION(sqlite3_bind_text(stmt, 6, info->ifname ? info->ifname : "",
-1, SQLITE_TRANSIENT));
*
* and inherited nfacct_rule_counter and nfacct_rule_restriction
* with additional field:
- * quota, quota_id, roaming, rst_state
+ * quota, quota_id, roaming, rstn_state
*
* But ANSI C doesn't support inheritance.
*/
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_restriction_state_e rst_state;
+ stc_rstn_state_e rstn_state;
nfacct_rule_iptype iptype;
struct counter_arg *carg;
typedef struct {
uint64_t restriction_id;
uint32_t classid;
- stc_restriction_state_e rst_state;
- stc_rstn_type_e rst_type;
+ stc_rstn_state_e rstn_state;
+ stc_rstn_type_e rstn_type;
int64_t data_limit;
int64_t data_warn_limit;
int64_t data_counter;
{
STC_LOGI("rstn info => rstn_id [%llu], "
"app_id [%s], classid [%lu], ifname [%s], "
- "iftype [%d], rst_state [%d], rst_type [%d], "
+ "iftype [%d], rstn_state [%d], rstn_type [%d], "
"limit [ (%lld) bytes], "
"warn_limit [ (%lld) bytes], "
"counter [ (%lld) bytes], "
"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->rst_type,
+ rstn_key->iftype, rstn_value->rstn_state, rstn_value->rstn_type,
rstn_value->data_limit,
rstn_value->data_warn_limit,
rstn_value->data_counter,
__del_ip6tables_out(&counter);
}
-static void __process_restriction(enum traffic_restriction_type rst_type,
+static void __process_restriction(enum traffic_restriction_type rstn_type,
stc_rstn_key_s *rstn_key,
stc_rstn_value_s *rstn_value, void *data)
{
effective_data_limit = rstn_value->data_limit;
effective_data_warn_limit = rstn_value->data_warn_limit;
- if (rst_type == RST_SET) {
+ if (rstn_type == RST_SET) {
/* TODO: Change this to runtime memory */
table_counters_info info;
rstn_value->restriction_id, effective_data_limit,
effective_data_warn_limit);
- switch (rst_type) {
+ switch (rstn_type) {
case RST_SET:
if (effective_data_limit <= 0)
__add_iptables_rule(rstn_value->classid, NFACCT_BLOCK,
rstn_key->iftype);
- rstn_value->rst_state = STC_RESTRICTION_ACTIVATED;
+ rstn_value->rstn_state = STC_RSTN_STATE_ACTIVATED;
rstn_value->data_limit_reached = FALSE;
break;
case RST_EXCLUDE:
__add_iptables_rule(rstn_value->classid, NFACCT_ALLOW,
rstn_key->iftype);
- rstn_value->rst_state = STC_RESTRICTION_ACTIVATED;
+ rstn_value->rstn_state = STC_RSTN_STATE_ACTIVATED;
rstn_value->data_limit_reached = TRUE;
break;
case RST_UNSET:
- __del_iptables_rule(rstn_value->classid, rstn_value->rst_type,
+ __del_iptables_rule(rstn_value->classid, rstn_value->rstn_type,
rstn_key->iftype);
- rstn_value->rst_state = STC_RESTRICTION_DEACTIVATED;
+ rstn_value->rstn_state = STC_RSTN_STATE_DEACTIVATED;
rstn_value->data_limit_reached = FALSE;
break;
default:
goto out;
/* rstn rule is already removed */
- if (rstn_value->rst_state == STC_RESTRICTION_DEACTIVATED)
+ if (rstn_value->rstn_state == STC_RSTN_STATE_DEACTIVATED)
goto out;
/* remove restriction from system */
stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
/* rstn rule is activated */
- if (rstn_value->rst_state == STC_RESTRICTION_ACTIVATED)
+ if (rstn_value->rstn_state == STC_RSTN_STATE_ACTIVATED)
return FALSE;
- if (rstn_value->rst_type == STC_RSTN_TYPE_EXCLUDED)
+ if (rstn_value->rstn_type == STC_RSTN_TYPE_ACCEPT)
__process_restriction(RST_EXCLUDE, rstn_key, rstn_value, data);
else
__process_restriction(RST_SET, rstn_key, rstn_value, data);
stc_rstn_value_s *rstn_value = (stc_rstn_value_s *)value;
/* rstn rule is activated */
- if (rstn_value->rst_state == STC_RESTRICTION_ACTIVATED)
+ if (rstn_value->rstn_state == STC_RSTN_STATE_ACTIVATED)
return FALSE;
- if (rstn_value->rst_type == STC_RSTN_TYPE_EXCLUDED)
+ if (rstn_value->rstn_type == STC_RSTN_TYPE_ACCEPT)
__process_restriction(RST_EXCLUDE, rstn_key, rstn_value, data);
else
__process_restriction(RST_SET, rstn_key, rstn_value, data);
g_tree_insert(g_system->rstns, rstn_key, rstn_value);
rstn_value->restriction_id = value->restriction_id;
- rstn_value->rst_state = value->rst_state;
- rstn_value->rst_type = value->rst_type;
+ rstn_value->rstn_state = value->rstn_state;
+ rstn_value->rstn_type = value->rstn_type;
rstn_value->classid = value->classid;
rstn_value->data_limit = value->data_limit;
rstn_value->data_warn_limit = value->data_warn_limit;
key.iftype = info->iftype;
key.roaming = info->roaming;
- value.rst_type = info->rst_type;
- value.rst_state = STC_RESTRICTION_UNKNOWN;
+ value.rstn_type = info->rstn_type;
+ value.rstn_state = STC_RSTN_STATE_UNKNOWN;
value.restriction_id = info->restriction_id;
if (info->app_id)
goto out;
/* rstn rule is already applied */
- if (rstn_value->rst_state == STC_RESTRICTION_ACTIVATED)
+ if (rstn_value->rstn_state == STC_RSTN_STATE_ACTIVATED)
goto out;
/* add restriction to system */
- if (rstn_value->rst_type == STC_RSTN_TYPE_EXCLUDED)
+ if (rstn_value->rstn_type == STC_RSTN_TYPE_ACCEPT)
__process_restriction(RST_EXCLUDE, rstn_key, rstn_value, NULL);
else
__process_restriction(RST_SET, rstn_key, rstn_value, NULL);
key.iftype = info->iftype;
key.roaming = info->roaming;
- value.rst_type = info->rst_type;
- value.rst_state = STC_RESTRICTION_UNKNOWN;
+ value.rstn_type = info->rstn_type;
+ value.rstn_state = STC_RSTN_STATE_UNKNOWN;
value.restriction_id = info->restriction_id;
if (info->app_id)
g_signal_connect(restriction, "handle-get-all",
G_CALLBACK(handle_restriction_get_all), stc);
- g_signal_connect(restriction, "handle-get-state",
- G_CALLBACK(handle_restriction_get_state),
+ g_signal_connect(restriction, "handle-get-type",
+ G_CALLBACK(handle_restriction_get_type),
stc);
g_signal_connect(restriction, "handle-unset",
rule->app_id = NULL;
rule->ifname = NULL;
rule->iftype = STC_IFACE_ALL;
- rule->rst_type = STC_RSTN_TYPE_UNKNOWN;
+ rule->rstn_type = STC_RSTN_TYPE_UNKNOWN;
rule->data_limit = 0;
rule->data_warn_limit = 0;
rule->roaming = STC_ROAMING_DISABLE;
}
gboolean __validate_rstn_rule(table_restrictions_info *rule,
- enum traffic_restriction_type rst_type)
+ enum traffic_restriction_type rstn_type)
{
__STC_LOG_FUNC_ENTER__;
return FALSE; //LCOV_EXCL_LINE
}
- if (rst_type <= RST_UNDEFINDED || rst_type >= RST_MAX_VALUE) {
+ if (rstn_type <= RST_UNDEFINDED || rstn_type >= RST_MAX_VALUE) {
__STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
return FALSE; //LCOV_EXCL_LINE
}
g_variant_builder_add(builder, "{sv}", "iftype",
g_variant_new_uint16(info->iftype));
- g_variant_builder_add(builder, "{sv}", "rst_type",
- g_variant_new_uint16(info->rst_type));
+ g_variant_builder_add(builder, "{sv}", "rstn_type",
+ g_variant_new_uint16(info->rstn_type));
g_variant_builder_add(builder, "{sv}", "data_limit",
g_variant_new_int64(info->data_limit));
g_variant_iter_free(iter);
}
- rule.rst_type = STC_RSTN_TYPE_BLOCKED;
+ rule.rstn_type = STC_RSTN_TYPE_DROP;
if (__validate_rstn_rule(&rule, RST_SET) == FALSE) {
STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
g_variant_iter_free(iter);
}
- rule.rst_type = STC_RSTN_TYPE_EXCLUDED;
+ rule.rstn_type = STC_RSTN_TYPE_ACCEPT;
if (__validate_rstn_rule(&rule, RST_EXCLUDE) == FALSE) {
STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
return TRUE;
}
-gboolean handle_restriction_get_state(StcRestriction *object,
+gboolean handle_restriction_get_type(StcRestriction *object,
GDBusMethodInvocation *invocation,
const gchar *app_id,
int iftype,
{
__STC_LOG_FUNC_ENTER__;
GVariant *return_parameters = NULL;
- stc_restriction_state_e state = STC_RESTRICTION_UNKNOWN;
+ stc_rstn_type_e type = STC_RSTN_TYPE_UNKNOWN;
stc_error_e ret;
- ret = table_restrictions_get_restriction_state(app_id, iftype, &state);
+ ret = table_restrictions_get_restriction_type(app_id, iftype, &type);
if (ret < STC_ERROR_NONE) {
STC_RESTRICTION_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
__STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
return TRUE;
}
- return_parameters = g_variant_new("(ii)", STC_ERROR_NONE, state);
+ return_parameters = g_variant_new("(ii)", STC_ERROR_NONE, type);
STC_DBUS_REPLY(invocation, return_parameters);
__STC_LOG_FUNC_EXIT__;
return TRUE;