Add initial source codes for gtest
[platform/core/connectivity/stc-manager.git] / src / helper / helper-nfacct-rule.c
index 374090a..8f5dfee 100755 (executable)
@@ -135,19 +135,20 @@ static stc_error_e nfacct_send_new(nfacct_rule_s *counter)
        int ret = STC_ERROR_NONE;
        struct genl *req = MALLOC0(struct genl, 1);
        if (req == NULL) {
-               STC_LOGE("Failed allocate memory to genl request message");
-               return STC_ERROR_OUT_OF_MEMORY;
+               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, NFNL_MSG_ACCT_NEW, NLM_F_CREATE | NLM_F_ACK);
        add_string_attr(req, counter->name, NFACCT_NAME);
 
        if (STC_DEBUG_LOG)
-               STC_LOGD("counter name %s", counter->name);
+               STC_LOGD("counter name %s", counter->name); //LCOV_EXCL_LINE
 
        /* padding */
        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);
 
@@ -155,6 +156,7 @@ static stc_error_e nfacct_send_new(nfacct_rule_s *counter)
                                NFACCT_FLAGS);
                add_uint64_attr(req, htobe64(counter->quota), NFACCT_QUOTA);
        }
+       //LCOV_EXCL_STOP
 
        ret = send_nfacct_request(counter->carg->sock, req);
        FREE(req);
@@ -166,12 +168,12 @@ stc_error_e nfacct_send_del(nfacct_rule_s *counter)
        int ret = STC_ERROR_NONE;
        struct genl *req = MALLOC0(struct genl, 1);
        if (req == NULL) {
-               STC_LOGE("Failed allocate memory to genl request message");
-               return STC_ERROR_OUT_OF_MEMORY;
+               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);
+               STC_LOGD("send remove request for %s", counter->name); //LCOV_EXCL_LINE
 
        prepare_netlink_msg(req, NFNL_MSG_ACCT_DEL, NLM_F_ACK);
        add_string_attr(req, counter->name, NFACCT_NAME);
@@ -192,8 +194,8 @@ static stc_error_e internal_nfacct_send_get(struct counter_arg *carg,
        int flag = !name ? NLM_F_DUMP : 0;
        struct genl *req = MALLOC0(struct genl, 1);
        if (req == NULL) {
-               STC_LOGE("Failed allocate memory to genl request message");
-               return STC_ERROR_OUT_OF_MEMORY;
+               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);
@@ -278,14 +280,15 @@ bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *cnt)
                cnt->intend  = NFACCT_BLOCK;
                break;
        case 't':
-               cnt->intend  = NFACCT_TETH_COUNTER;
-               break;
+               cnt->intend  = NFACCT_TETH_COUNTER; //LCOV_EXCL_LINE
+               break; //LCOV_EXCL_LINE
        default:
                return false;
        }
 
        STRING_SAVE_COPY(cnt->name, cnt_name);
 
+       //LCOV_EXCL_START
        if (cnt->intend == NFACCT_TETH_COUNTER) {
                char ifname_buf[MAX_IFACE_LENGTH];
                int ifname_len;
@@ -321,6 +324,7 @@ bool recreate_counter_by_name(char *cnt_name, nfacct_rule_s *cnt)
                cnt->classid = STC_TETHERING_APP_CLASSID;
                return true;
        }
+       //LCOV_EXCL_STOP
 
        io_part = strtok_r(name, "_", &save_ptr);
        if (io_part != NULL)
@@ -413,8 +417,8 @@ static char *get_iptables_chain(const nfacct_rule_direction iotype)
                return STC_IN_CHAIN;
        else if (iotype == NFACCT_COUNTER_OUT)
                return STC_OUT_CHAIN;
-       else if (iotype == NFACCT_COUNTER_FORWARD)
-               return STC_FRWD_CHAIN;
+       else if (iotype == NFACCT_COUNTER_FORWARD) //LCOV_EXCL_LINE
+               return STC_FRWD_CHAIN; //LCOV_EXCL_LINE
 
        return "";
 }
@@ -429,11 +433,13 @@ static char *get_iptables_jump(const nfacct_rule_jump jump)
        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_iptables_cmd(nfacct_rule_s *rule)
 {
@@ -611,6 +617,7 @@ static stc_error_e produce_iface_rule(nfacct_rule_s *rule)
                                 " 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) {
@@ -635,6 +642,7 @@ static stc_error_e produce_iface_rule(nfacct_rule_s *rule)
                        ret_value_msg_if(ret != STC_ERROR_NONE, ret,
                                         "can't del quota counter");
                }
+               //LCOV_EXCL_STOP
        }
 
        if (rule->iotype & NFACCT_COUNTER_OUT) {
@@ -668,6 +676,7 @@ static stc_error_e produce_iface_rule(nfacct_rule_s *rule)
                                 "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) {
@@ -691,6 +700,7 @@ static stc_error_e produce_iface_rule(nfacct_rule_s *rule)
                        ret_value_msg_if(ret != STC_ERROR_NONE, ret,
                                         "can't del quota counter");
                }
+               //LCOV_EXCL_STOP
        }
        return STC_ERROR_NONE;
 }