#include "counter.h"
#include "helper-nfacct-rule.h"
+#include "helper-iptables.h"
#include "configure_stub.h"
#define INSERT "-I"
#define NFACCT_NAME_MOD " -m nfacct --nfacct-name %s"
-#define REJECT_RULE " -j REJECT"
-#define ACCEPT_RULE " -j ACCEPT"
+#define REJECT_RULE "REJECT"
+#define ACCEPT_RULE "ACCEPT"
#define OUT_RULE "OUTPUT"
#define IN_RULE "INPUT"
#define FORWARD_RULE "FORWARD"
static stc_error_e nfacct_send_new(nfacct_rule_s *counter)
{
- struct genl req;
-
- prepare_netlink_msg(&req, NFNL_MSG_ACCT_NEW, NLM_F_CREATE | NLM_F_ACK);
- add_string_attr(&req, counter->name, NFACCT_NAME);
+ int ret = STC_ERROR_NONE;
+ struct genl *req = MALLOC0(struct genl, 1);
+ if (req == NULL) {
+ STC_LOGE("Failed allocate memory to genl request message"); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+ }
- STC_LOGD("counter name %s", counter->name);
+ prepare_netlink_msg(req, NFNL_MSG_ACCT_NEW, NLM_F_CREATE | NLM_F_ACK);
+ add_string_attr(req, counter->name, NFACCT_NAME);
/* padding */
- add_uint64_attr(&req, 0, NFACCT_PKTS);
- add_uint64_attr(&req, 0, NFACCT_BYTES);
+ add_uint64_attr(req, 0, NFACCT_PKTS);
+ add_uint64_attr(req, 0, NFACCT_BYTES);
+ //LCOV_EXCL_START
if (counter->quota) {
STC_LOGD("quota bytes %"PRId64, counter->quota);
- add_uint32_attr(&req, htobe32(NFACCT_F_QUOTA_BYTES),
+ add_uint32_attr(req, htobe32(NFACCT_F_QUOTA_BYTES),
NFACCT_FLAGS);
- add_uint64_attr(&req, htobe64(counter->quota), NFACCT_QUOTA);
+ add_uint64_attr(req, htobe64(counter->quota), NFACCT_QUOTA);
}
+ //LCOV_EXCL_STOP
- return send_nfacct_request(counter->carg->sock, &req);
+ ret = send_nfacct_request(counter->carg->sock, req);
+ FREE(req);
+ return ret;
}
stc_error_e nfacct_send_del(nfacct_rule_s *counter)
{
- struct genl req;
+ int ret = STC_ERROR_NONE;
+ struct genl *req = MALLOC0(struct genl, 1);
+ if (req == NULL) {
+ STC_LOGE("Failed allocate memory to genl request message"); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+ }
-#if STC_DEBUG_LOG
- STC_LOGD("send remove request for %s", counter->name);
-#endif
+ prepare_netlink_msg(req, NFNL_MSG_ACCT_DEL, NLM_F_ACK);
+ add_string_attr(req, counter->name, NFACCT_NAME);
- prepare_netlink_msg(&req, NFNL_MSG_ACCT_DEL, NLM_F_ACK);
- add_string_attr(&req, counter->name, NFACCT_NAME);
- return send_nfacct_request(counter->carg->sock, &req);
+ ret = send_nfacct_request(counter->carg->sock, req);
+ FREE(req);
+ return ret;
}
#define NFACCT_F_QUOTAS (NFACCT_F_QUOTA_BYTES | NFACCT_F_QUOTA_PKTS)
const char *name,
int mask, int filter)
{
- struct genl req;
+ int ret = STC_ERROR_NONE;
struct nlattr *na;
int flag = !name ? NLM_F_DUMP : 0;
- prepare_netlink_msg(&req, get_type,
- flag);
+ struct genl *req = MALLOC0(struct genl, 1);
+ if (req == NULL) {
+ STC_LOGE("Failed allocate memory to genl request message"); //LCOV_EXCL_LINE
+ return STC_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+ }
+
+ prepare_netlink_msg(req, get_type, flag);
/* due we don't get counter with quota any where else,
* here we will request just counters by default */
if (name)
- add_string_attr(&req, name, NFACCT_NAME);
-
- na = start_nest_attr(&req, NFACCT_FILTER);
- add_uint32_attr(&req, htonl(mask),
- NFACCT_FILTER_ATTR_MASK);
- add_uint32_attr(&req, htonl(filter), NFACCT_FILTER_ATTR_VALUE);
- end_nest_attr(&req, na);
- return send_nfacct_request(carg->sock, &req);
+ add_string_attr(req, name, NFACCT_NAME);
+
+ na = start_nest_attr(req, NFACCT_FILTER);
+ add_uint32_attr(req, htonl(mask), NFACCT_FILTER_ATTR_MASK);
+ add_uint32_attr(req, htonl(filter), NFACCT_FILTER_ATTR_VALUE);
+ end_nest_attr(req, na);
+
+ ret = send_nfacct_request(carg->sock, req);
+ FREE(req);
+ return ret;
}
stc_error_e nfacct_send_get_counters(struct counter_arg *carg, const char *name)
static stc_iface_type_e convert_to_iftype(int type)
{
return (type < STC_IFACE_LAST_ELEM &&
- type > STC_IFACE_UNKNOWN) ? type : STC_IFACE_UNKNOWN;
+ type > STC_IFACE_UNKNOWN) ? type : STC_IFACE_UNKNOWN;
}
bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *cnt)
case 'r':
cnt->intend = NFACCT_BLOCK;
break;
- case 't':
- cnt->intend = NFACCT_TETH_COUNTER;
+ case 'a':
+ cnt->intend = NFACCT_ALLOW;
break;
+ case 't':
+ cnt->intend = NFACCT_TETH_COUNTER; //LCOV_EXCL_LINE
+ break; //LCOV_EXCL_LINE
default:
return false;
}
STRING_SAVE_COPY(cnt->name, cnt_name);
+#if 0
+ /* ========================================================
+ * NOTE:-
+ * Below parsing for tethering case is not in use
+ * stc-manager needs to ignore this for NFACCT_TETH_COUNTER
+ * this is disbaled for future use.
+ * =======================================================*/
+
+ //LCOV_EXCL_START
if (cnt->intend == NFACCT_TETH_COUNTER) {
char ifname_buf[MAX_IFACE_LENGTH];
int ifname_len;
cnt->classid = STC_TETHERING_APP_CLASSID;
return true;
}
+ //LCOV_EXCL_STOP
+#endif
io_part = strtok_r(name, "_", &save_ptr);
if (io_part != NULL)
return &command;
}
-static unsigned int get_args_number(const char *cmd_buf)
-{
- char *str;
- unsigned int count = 0;
-
- for (str = (char *)cmd_buf; *str != '\0'; ++str) {
- if (*str == ' ')
- ++count;
- }
- return count;
-}
-
-static void wait_for_rule_cmd(pid_t pid)
+static char *get_iptables_cmd(const nfacct_rule_action action)
{
- int status;
- pid_t ret_pid;
-
- if (!pid || pid == -1) {
- STC_LOGD("no need to wait");
- return;
- }
+ if (action == NFACCT_ACTION_APPEND)
+ return APPEND;
+ else if (action == NFACCT_ACTION_DELETE)
+ return DELETE;
+ else if (action == NFACCT_ACTION_INSERT)
+ return INSERT;
- ret_pid = waitpid(pid, &status, 0);
- if (ret_pid < 0) {
- char buf[BUF_SIZE_FOR_ERR] = { 0 };
- STC_LOGD("can't wait for a pid %d %d %s", pid, status,
- strerror_r(errno, buf, BUF_SIZE_FOR_ERR));
- }
+ return "";
}
-stc_error_e exec_iptables_cmd(const char *cmd_buf, pid_t *cmd_pid)
-{
- const size_t args_number = get_args_number(cmd_buf);
- *cmd_pid = 0;
-
- ret_value_msg_if(args_number == 0, STC_ERROR_FAIL, "no arguments");
-
- pid_t pid = fork();
-
- if (pid == 0) {
- char *cmd;
- unsigned int i;
- char *args[args_number + 2];
- int ret;
- char *save_ptr = NULL;
-
-#if STC_DEBUG_LOG
- STC_LOGD("executing iptables cmd %s in forked process", cmd_buf);
-#endif
-
- args[0] = "iptables";
- cmd = strtok_r((char *)cmd_buf, " ", &save_ptr);
- if (cmd == NULL) {
- STC_LOGE("no arguments");
- exit(-EINVAL);
+static char *get_iptables_chain(uint32_t classid,
+ const nfacct_rule_direction iotype,
+ const stc_app_state_e app_state,
+ const nfacct_rule_intend intend)
+{
+ if (iotype == NFACCT_COUNTER_IN) {
+ if (intend == NFACCT_COUNTER ||
+ intend == NFACCT_TETH_COUNTER) {
+ if (app_state == STC_APP_STATE_FOREGROUND) {
+ if (intend == NFACCT_ALLOW)
+ return STC_IN_ACCEPT_CHAIN;
+ else
+ return STC_IN_FG_CHAIN;
+ } else
+ return STC_IN_BG_CHAIN;
+ } else if (intend == NFACCT_ALLOW ||
+ intend == NFACCT_TETH_ALLOW) {
+ return STC_IN_ACCEPT_CHAIN;
+ } else {
+ if (classid == STC_BACKGROUND_APP_CLASSID)
+ return STC_IN_BG_DROP_CHAIN;
+ else
+ return STC_IN_DROP_CHAIN;
}
-
- for (i = 1; i <= args_number; ++i)
- args[i] = strtok_r(NULL, " ", &save_ptr);
-
- args[i] = NULL;
-
- ret = execv(cmd, args);
- if (ret) {
- char buf[BUF_SIZE_FOR_ERR] = { 0 };
- STC_LOGE("Can't execute %s: %s",
- cmd_buf, strerror_r(errno, buf,
- BUF_SIZE_FOR_ERR));
+ } else if (iotype == NFACCT_COUNTER_OUT) {
+ if (intend == NFACCT_COUNTER ||
+ intend == NFACCT_TETH_COUNTER) {
+ if (app_state == STC_APP_STATE_FOREGROUND) {
+ if (intend == NFACCT_ALLOW)
+ return STC_OUT_ACCEPT_CHAIN;
+ else
+ return STC_OUT_FG_CHAIN;
+ } else
+ return STC_OUT_BG_CHAIN;
+ } else if (intend == NFACCT_ALLOW ||
+ intend == NFACCT_TETH_ALLOW) {
+ return STC_OUT_ACCEPT_CHAIN;
+ } else {
+ if (classid == STC_BACKGROUND_APP_CLASSID)
+ return STC_OUT_BG_DROP_CHAIN;
+ else
+ return STC_OUT_DROP_CHAIN;
}
- exit(ret);
- }
+ } else if (iotype == NFACCT_COUNTER_FORWARD)
+ return STC_FRWD_CHAIN;
- *cmd_pid = pid;
- return STC_ERROR_NONE;
+ return "";
}
-stc_error_e exec_ip6tables_cmd(const char *cmd_buf, pid_t *cmd_pid)
+static char *get_iptables_jump(const nfacct_rule_jump jump)
{
- const size_t args_number = get_args_number(cmd_buf);
- *cmd_pid = 0;
-
- ret_value_msg_if(args_number == 0, STC_ERROR_FAIL, "no arguments");
-
- pid_t pid = fork();
-
- if (pid == 0) {
- char *cmd;
- unsigned int i;
- char *args[args_number + 2];
- int ret;
- char *save_ptr = NULL;
-
-#if STC_DEBUG_LOG
- STC_LOGD("executing ip6tables cmd %s in forked process", cmd_buf);
-#endif
-
- args[0] = "ip6tables";
- cmd = strtok_r((char *)cmd_buf, " ", &save_ptr);
- if (cmd == NULL) {
- STC_LOGE("no arguments");
- exit(-EINVAL);
- }
-
- for (i = 1; i <= args_number; ++i)
- args[i] = strtok_r(NULL, " ", &save_ptr);
-
- args[i] = NULL;
-
- ret = execv(cmd, args);
- if (ret) {
- char buf[BUF_SIZE_FOR_ERR] = { 0 };
- STC_LOGE("Can't execute %s: %s",
- cmd_buf, strerror_r(errno, buf,
- BUF_SIZE_FOR_ERR));
- }
- exit(ret);
- }
+ if (jump == NFACCT_JUMP_ACCEPT)
+ return ACCEPT_RULE;
+ else if (jump == NFACCT_JUMP_REJECT)
+ return REJECT_RULE;
- *cmd_pid = pid;
- return STC_ERROR_NONE;
+ return "";
}
+/*
static char *choose_iftype_name(nfacct_rule_s *rule)
{
return strlen(rule->ifname) != 0 ? rule->ifname :
get_iftype_name(rule->iftype);
}
+*/
-static stc_error_e exec_iface_cmd(const char *pattern, const char *cmd,
- const char *chain, const char *nfacct,
- const char *jump, char *iftype_name,
- pid_t *pid, nfacct_rule_iptype iptype)
+static stc_error_e exec_iptables_cmd(nfacct_rule_s *rule)
{
- char block_buf[MAX_PATH_LENGTH];
- int ret;
- const char *iptables_type = IPTABLES;
-
- ret_value_msg_if(iftype_name == NULL, STC_ERROR_FAIL,
- "Invalid network interface name argument");
-
- if (iptype == NFACCT_TYPE_IPV6)
- iptables_type = IP6TABLES;
-
- ret = snprintf(block_buf, sizeof(block_buf), pattern, iptables_type,
- cmd, chain, iftype_name, nfacct, jump);
- ret_value_msg_if(ret > sizeof(block_buf), STC_ERROR_FAIL,
- "Not enough buffer");
-
- if (iptype == NFACCT_TYPE_IPV6)
- exec_ip6tables_cmd(block_buf, pid);
+ stc_error_e ret = STC_ERROR_NONE;
+ iptables_ip_type_e iptype;
+ iptables_rule_s iptables_rule;
+ memset(&iptables_rule, 0, sizeof(iptables_rule_s));
+
+ iptables_rule.nfacct_name = g_strdup(rule->name);
+ iptables_rule.ifname = g_strdup(rule->ifname);
+ iptables_rule.target = g_strdup(get_iptables_jump(rule->jump));
+
+ /* In case of tehering rules use chain 'STC_TETHER' */
+ if (rule->intend == NFACCT_TETH_COUNTER ||
+ rule->intend == NFACCT_TETH_ALLOW ||
+ rule->intend == NFACCT_TETH_BLOCK)
+ iptables_rule.chain = g_strdup(STC_TETHER_CHAIN);
else
- exec_iptables_cmd(block_buf, pid);
-
- wait_for_rule_cmd(*pid);
-
- return STC_ERROR_NONE;
-}
-
-static stc_error_e exec_app_cmd(const char *pattern, const char *cmd,
- const char *nfacct, const char *jump,
- const uint32_t classid, char *iftype_name,
- pid_t *pid, nfacct_rule_iptype iptype)
-{
- char block_buf[MAX_PATH_LENGTH];
- int ret;
- const char *iptables_type = IPTABLES;
+ iptables_rule.chain = g_strdup(get_iptables_chain(rule->classid,
+ rule->iotype, rule->app_state, rule->intend));
- ret_value_msg_if(iftype_name == NULL, STC_ERROR_FAIL,
- "Invalid network interface name argument");
-
- if (iptype == NFACCT_TYPE_IPV6)
- iptables_type = IP6TABLES;
-
- ret = snprintf(block_buf, sizeof(block_buf), pattern, iptables_type,
- cmd, iftype_name, classid, nfacct, jump);
- ret_value_msg_if(ret > sizeof(block_buf), STC_ERROR_FAIL,
- "Not enough buffer");
-
- if (iptype == NFACCT_TYPE_IPV6)
- exec_ip6tables_cmd(block_buf, pid);
+ if (rule->classid < STC_RESERVED_CLASSID_MAX)
+ iptables_rule.classid = STC_UNKNOWN_CLASSID;
else
- exec_iptables_cmd(block_buf, pid);
-
- wait_for_rule_cmd(*pid);
-
- return STC_ERROR_NONE;
-}
-
-static char *get_iptables_cmd(const nfacct_rule_action action)
-{
- if (action == NFACCT_ACTION_APPEND)
- return APPEND;
- else if (action == NFACCT_ACTION_DELETE)
- return DELETE;
- else if (action == NFACCT_ACTION_INSERT)
- return INSERT;
-
- return "";
-}
-
-static char *get_iptables_chain(const nfacct_rule_direction iotype)
-{
- if (iotype == NFACCT_COUNTER_IN)
- return IN_RULE;
- else if (iotype == NFACCT_COUNTER_OUT)
- return OUT_RULE;
-
- return "";
-}
+ iptables_rule.classid = rule->classid;
+ iptables_rule.direction = (rule->iotype & NFACCT_COUNTER_IN) ?
+ IPTABLES_DIRECTION_IN : IPTABLES_DIRECTION_OUT;
+ iptype = (iptables_ip_type_e)rule->iptype;
+
+ /* specify the ip range type for source and destination */
+ iptables_rule.s_iprange_type = rule->src_iprange_type;
+ iptables_rule.d_iprange_type = rule->dst_iprange_type;
+
+ /* specify source and destination ip address if any */
+ if (rule->src_ip1)
+ inet_aton(rule->src_ip1, &iptables_rule.s_ip1);
+ if (rule->src_ip2)
+ inet_aton(rule->src_ip2, &iptables_rule.s_ip2);
+ if (rule->dst_ip1)
+ inet_aton(rule->dst_ip1, &iptables_rule.d_ip1);
+ if (rule->dst_ip2)
+ inet_aton(rule->dst_ip2, &iptables_rule.d_ip2);
+
+ if (rule->action == NFACCT_ACTION_DELETE) {
+ /* delete interface rule */
+ ret = iptables_remove(&iptables_rule, iptype);
+ } else {
+ /* add interface rule */
+ ret = iptables_add(&iptables_rule, iptype);
+ }
-static char *get_iptables_jump(const nfacct_rule_jump jump)
-{
- if (jump == NFACCT_JUMP_ACCEPT)
- return ACCEPT_RULE;
- else if (jump == NFACCT_JUMP_REJECT)
- return REJECT_RULE;
+ g_free(iptables_rule.nfacct_name);
+ g_free(iptables_rule.ifname);
+ g_free(iptables_rule.target);
+ g_free(iptables_rule.chain);
- return "";
+ return ret;
}
static stc_error_e produce_app_rule(nfacct_rule_s *rule)
char *set_cmd = get_iptables_cmd(rule->action);
char *jump_cmd = get_iptables_jump(rule->jump);
char nfacct_buf[sizeof(NFACCT_NAME_MOD) +
- 3*MAX_DEC_SIZE(int) + 4];
+ 3*MAX_DEC_SIZE(int) + 4 + 1];
stc_error_e ret = STC_ERROR_NONE;
- pid_t pid = 0;
+ uint32_t classid = rule->classid;
/* income part */
if (rule->iotype & NFACCT_COUNTER_IN) {
ret_value_msg_if(ret > sizeof(nfacct_buf) || ret < 0,
STC_ERROR_FAIL, "Not enought buffer");
- ret = exec_app_cmd(RULE_APP_IN, set_cmd, nfacct_buf, jump_cmd,
- rule->classid, choose_iftype_name(rule),
- &pid, rule->iptype);
+ /* cgroup extention on FORWARD chain are not allowed
+ * remove classid info in case of tethering rules */
+ if (rule->intend == NFACCT_TETH_COUNTER ||
+ rule->intend == NFACCT_TETH_ALLOW ||
+ rule->intend == NFACCT_TETH_BLOCK) {
+ classid = rule->classid;
+ rule->classid = 0;
+ }
+
+ ret = exec_iptables_cmd(rule);
+
+ /* restore the classid info in case of tethering rule */
+ if (rule->intend == NFACCT_TETH_COUNTER ||
+ rule->intend == NFACCT_TETH_ALLOW ||
+ rule->intend == NFACCT_TETH_BLOCK)
+ rule->classid = classid;
+
ret_value_msg_if(ret != STC_ERROR_NONE, STC_ERROR_FAIL,
"Can't set conditional block for ingress"
" traffic, for classid %u, cmd %s, j %s",
ret_value_msg_if(ret > sizeof(nfacct_buf) || ret < 0,
STC_ERROR_FAIL, "Not enought buffer");
- ret = exec_app_cmd(RULE_APP_OUT, set_cmd, nfacct_buf, jump_cmd,
- rule->classid, choose_iftype_name(rule),
- &pid, rule->iptype);
+ /* cgroup extention on FORWARD chain are not allowed
+ * remove classid info in case of tethering rules */
+ if (rule->intend == NFACCT_TETH_COUNTER ||
+ rule->intend == NFACCT_TETH_ALLOW ||
+ rule->intend == NFACCT_TETH_BLOCK) {
+ classid = rule->classid;
+ rule->classid = 0;
+ }
+
+ ret = exec_iptables_cmd(rule);
+
+ /* restore the classid info in case of tethering rule */
+ if (rule->intend == NFACCT_TETH_COUNTER ||
+ rule->intend == NFACCT_TETH_ALLOW ||
+ rule->intend == NFACCT_TETH_BLOCK)
+ rule->classid = classid;
+
ret_value_msg_if(ret != STC_ERROR_NONE, STC_ERROR_FAIL,
"Can't set conditional block for engress"
" traffic, for classid %u, cmd %s, j %s",
rule->classid, set_cmd, jump_cmd);
+
if (rule->action == NFACCT_ACTION_DELETE) {
rule->iptables_rule = nfacct_send_del;
/* not effective, it's better to replace
char *set_cmd = get_iptables_cmd(rule->action);
char *jump_cmd = get_iptables_jump(rule->jump);
char nfacct_buf[sizeof(NFACCT_NAME_MOD) +
- 3*MAX_DEC_SIZE(int) + 4];
+ 3*MAX_DEC_SIZE(int) + 4 + 1];
stc_error_e ret;
- pid_t pid = 0;
if (rule->iotype & NFACCT_COUNTER_IN) {
/* income part */
ret_value_msg_if(ret > sizeof(nfacct_buf) || ret < 0,
STC_ERROR_FAIL, "Not enought buffer");
- ret = exec_iface_cmd(RULE_IFACE_IN, set_cmd,
- get_iptables_chain(rule->iotype),
- nfacct_buf, jump_cmd,
- choose_iftype_name(rule), &pid,
- rule->iptype);
+ ret = exec_iptables_cmd(rule);
ret_value_msg_if(ret != STC_ERROR_NONE, STC_ERROR_FAIL,
"Can't set conditional block for ingress"
" traffic, for iftype %d, cmd %s, j %s",
rule->iftype, set_cmd, jump_cmd);
+ //LCOV_EXCL_START
/* for tethering */
if (rule->intend == NFACCT_WARN ||
rule->intend == NFACCT_BLOCK) {
/* RULE_IFACE_OUT is not a misprint here */
- ret = exec_iface_cmd(RULE_IFACE_IN, set_cmd,
- FORWARD_RULE, nfacct_buf, jump_cmd,
- choose_iftype_name(rule), &pid,
- rule->iptype);
+ nfacct_rule_direction temp_iotype = rule->iotype;
+
+ rule->iotype = NFACCT_COUNTER_FORWARD;
+ ret = exec_iptables_cmd(rule);
+ rule->iotype = temp_iotype;
ret_value_msg_if(ret != STC_ERROR_NONE, STC_ERROR_FAIL,
"Can't set forward rule for ingress "
"traffic, for iftype %d, cmd %s, j %s",
ret_value_msg_if(ret != STC_ERROR_NONE, ret,
"can't del quota counter");
}
+ //LCOV_EXCL_STOP
}
if (rule->iotype & NFACCT_COUNTER_OUT) {
ret_value_msg_if(ret > sizeof(nfacct_buf) || ret < 0,
STC_ERROR_FAIL, "Not enough buffer");
- ret = exec_iface_cmd(RULE_IFACE_OUT, set_cmd, OUT_RULE,
- nfacct_buf, jump_cmd,
- choose_iftype_name(rule), &pid,
- rule->iptype);
+ ret = exec_iptables_cmd(rule);
ret_value_msg_if(ret != STC_ERROR_NONE, STC_ERROR_FAIL,
"Can't set conditional block for "
"engress traffic, for iftype %d, cmd %s, j %s",
rule->iftype, set_cmd, jump_cmd);
+
+ //LCOV_EXCL_START
/* for tethering */
if (rule->intend == NFACCT_WARN ||
rule->intend == NFACCT_BLOCK) {
- ret = exec_iface_cmd(RULE_IFACE_OUT, set_cmd,
- FORWARD_RULE, nfacct_buf, jump_cmd,
- choose_iftype_name(rule), &pid,
- rule->iptype);
+ nfacct_rule_direction temp_iotype = rule->iotype;
+
+ rule->iotype = NFACCT_COUNTER_OUT;
+ ret = exec_iptables_cmd(rule);
+ rule->iotype = temp_iotype;
ret_value_msg_if(ret != STC_ERROR_NONE, STC_ERROR_FAIL,
"Can't set forward rule for engress "
"traffic, for iftype %d, cmd %s, j %s",
ret_value_msg_if(ret != STC_ERROR_NONE, ret,
"can't del quota counter");
}
+ //LCOV_EXCL_STOP
}
+
return STC_ERROR_NONE;
}
if (rule->classid != STC_ALL_APP_CLASSID &&
rule->classid != STC_TETHERING_APP_CLASSID &&
+ rule->classid != STC_BACKGROUND_APP_CLASSID &&
rule->classid != STC_TOTAL_DATACALL_CLASSID &&
rule->classid != STC_TOTAL_WIFI_CLASSID &&
rule->classid != STC_TOTAL_BLUETOOTH_CLASSID &&
STRING_SAVE_COPY(counter->ifname, iftype_name);
}
- if (counter->intend == NFACCT_WARN)
+ if (counter->intend == NFACCT_WARN ||
+ counter->intend == NFACCT_TETH_WARN)
warn_symbol = 'w';
- else if (counter->intend == NFACCT_BLOCK)
+ else if (counter->intend == NFACCT_BLOCK ||
+ counter->intend == NFACCT_TETH_BLOCK)
warn_symbol = 'r';
+ else if (counter->intend == NFACCT_ALLOW ||
+ counter->intend == NFACCT_TETH_ALLOW)
+ warn_symbol = 'a';
+ else if (counter->intend == NFACCT_TETH_COUNTER)
+ warn_symbol = 't';
snprintf(counter->name, NFACCT_NAME_MAX, "%c%d_%d_%d_%s",
warn_symbol, counter->iotype, counter->iftype,
counter->classid, counter->ifname);