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)
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)