[nfacct-rule] Use heap instead of stack, to aviod large stack usage issue. 40/155840/2
authorNishant Chaprana <n.chaprana@samsung.com>
Mon, 16 Oct 2017 09:16:50 +0000 (14:46 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Mon, 16 Oct 2017 09:20:57 +0000 (14:50 +0530)
Change-Id: I5252955200603bc1c21b3b36b150e174447ce20c
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
packaging/stc-manager.spec
src/helper/helper-nfacct-rule.c

index 9500d61..d0d5348 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.0.37
+Version:    0.0.38
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
index ca3a7a9..952e414 100755 (executable)
@@ -131,38 +131,53 @@ static stc_error_e send_nfacct_request(int sock, struct genl *req)
 
 static stc_error_e nfacct_send_new(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");
+               return STC_ERROR_OUT_OF_MEMORY;
+       }
 
-       prepare_netlink_msg(&req, NFNL_MSG_ACCT_NEW, NLM_F_CREATE | NLM_F_ACK);
-       add_string_attr(&req, counter->name, NFACCT_NAME);
+       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);
 
        /* 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);
        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);
        }
 
-       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");
+               return STC_ERROR_OUT_OF_MEMORY;
+       }
 
        if (STC_DEBUG_LOG)
                STC_LOGD("send remove request for %s", counter->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);
+       prepare_netlink_msg(req, NFNL_MSG_ACCT_DEL, NLM_F_ACK);
+       add_string_attr(req, counter->name, NFACCT_NAME);
+
+       ret = send_nfacct_request(counter->carg->sock, req);
+       FREE(req);
+       return ret;
 }
 #define NFACCT_F_QUOTAS (NFACCT_F_QUOTA_BYTES | NFACCT_F_QUOTA_PKTS)
 
@@ -171,22 +186,29 @@ static stc_error_e internal_nfacct_send_get(struct counter_arg *carg,
                                            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");
+               return STC_ERROR_OUT_OF_MEMORY;
+       }
+
+       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)