4 * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 * @desc Common netlink helper function
24 * Created on: Jun 25, 2012
27 #ifndef RESOURCED_NL_HELPER_H_
28 #define RESOURCED_NL_HELPER_H_
31 /*#include "nfacct-helper.h"*/
33 #include <sys/socket.h>
34 #include <linux/netlink.h>
35 #include <linux/genetlink.h>
36 #include <linux/rtnetlink.h>
38 #define NLA_BUF_MAX 65560 /*(65 * 1024) - used in tc_common,
41 /*TODO: move to common place and rewrite because it's from TC*/
42 #define NLMSG_TAIL(nmsg) \
43 ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
45 /*TODO remove unused code */
49 char buf[NLA_BUF_MAX];
52 void put_attr(rt_param *arg, int type, const void *data, int data_len);
55 * Generic macros for dealing with netlink sockets. Might be duplicated
56 * elsewhere. It is recommended that commercial grade applications use
57 * libnl or libnetlink and use the interfaces provided by the library
59 #define GENLMSG_PAYLOAD(glh) (NLMSG_PAYLOAD(glh, 0) - GENL_HDRLEN)
60 #define GENLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + GENL_HDRLEN))
61 #define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN))
63 #define NETLINK_BUF_SIZE 16536
65 enum nfnl_acct_msg_types {
68 NFNL_MSG_ACCT_GET_CTRZERO,
85 enum nfnl_attr_filter_type {
86 NFACCT_FILTER_ATTR_UNSPEC,
87 NFACCT_FILTER_ATTR_MASK,
88 NFACCT_FILTER_ATTR_VALUE,
89 __NFACCT_FILTER_ATTR_MAX
92 #define NFACCT_MAX (__NFACCT_MAX - 1)
97 char buf[NETLINK_BUF_SIZE];
100 struct netlink_serialization_params {
101 traffic_stat_tree *stat_tree;
103 struct counter_arg *carg;
104 int (*eval_attr)(struct rtattr *attr_list[__NFACCT_MAX],
106 int (*post_eval_attr)(void *user_data);
110 void (*deserialize_answer)(struct netlink_serialization_params *params);
111 void (*finalize)(struct netlink_serialization_params *params);
112 struct netlink_serialization_params params;
113 } netlink_serialization_command;
115 int create_netlink(int protocol, uint32_t groups);
116 int read_netlink(int sock, void *buf, size_t len);
118 void fill_attribute_list(struct rtattr **atb, const int max_len,
119 struct rtattr *rt_na, int rt_len);
121 #endif /* RESOURCED_NL_HELPER_H_ */