2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __STC_HELPER_NL_H__
18 #define __STC_HELPER_NL_H__
20 //#include "app-stat.h"
24 #include <sys/socket.h>
25 #include <linux/netlink.h>
26 #include <linux/genetlink.h>
27 #include <linux/rtnetlink.h>
29 #include "stc-manager.h"
31 #define NLA_BUF_MAX 65560 /*(65 * 1024) - used in tc_common,
34 /*TODO: move to common place and rewrite because it's from TC*/
35 #define NLMSG_TAIL(nmsg) \
36 ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
38 /*TODO remove unused code */
42 char buf[NLA_BUF_MAX];
45 void put_attr(rt_param *arg, int type, const void *data, int data_len);
48 * Generic macros for dealing with netlink sockets. Might be duplicated
49 * elsewhere. It is recommended that commercial grade applications use
50 * libnl or libnetlink and use the interfaces provided by the library
52 #define GENLMSG_PAYLOAD(glh) (NLMSG_PAYLOAD(glh, 0) - GENL_HDRLEN)
53 #define GENLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + GENL_HDRLEN))
54 #define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN))
56 #define NETLINK_BUF_SIZE 16536
58 enum nfnl_acct_msg_types {
61 NFNL_MSG_ACCT_GET_CTRZERO,
78 enum nfnl_attr_filter_type {
79 NFACCT_FILTER_ATTR_UNSPEC,
80 NFACCT_FILTER_ATTR_MASK,
81 NFACCT_FILTER_ATTR_VALUE,
82 __NFACCT_FILTER_ATTR_MAX
85 #define NFACCT_MAX (__NFACCT_MAX - 1)
90 char buf[NETLINK_BUF_SIZE];
93 struct netlink_serialization_params {
96 struct counter_arg *carg;
97 int (*eval_attr)(struct rtattr *attr_list[__NFACCT_MAX],
99 int (*post_eval_attr)(void *user_data);
103 void (*deserialize_answer)(struct netlink_serialization_params *params);
104 void (*finalize)(struct netlink_serialization_params *params);
105 struct netlink_serialization_params params;
106 } netlink_serialization_command;
108 int create_netlink(int protocol, uint32_t groups);
109 int read_netlink(int sock, void *buf, size_t len);
111 void fill_attribute_list(struct rtattr **atb, const int max_len,
112 struct rtattr *rt_na, int rt_len);
114 #endif /* __STC_HELPER_NL_H__ */