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.
20 * @file generic-netlink.h
21 * @desc Helper function for making kernel request and process response
24 #ifndef _GRABBER_CONTROL_KERNEL_GENERIC_NETLINK_H_
25 #define _GRABBER_CONTROL_KERNEL_GENERIC_NETLINK_H_
29 #include "nl-helper.h"
32 #include <linux/genetlink.h>
33 #include <linux/rtnetlink.h>
35 enum net_activity_recv {
36 RESOURCED_NET_ACTIVITY_OK,
37 RESOURCED_NET_ACTIVITY_STOP,
38 RESOURCED_NET_ACTIVITY_CONTINUE,
41 netlink_serialization_command *netlink_create_command(
42 struct netlink_serialization_params *params);
44 uint32_t get_family_id(int sock, pid_t pid, char *family_name);
47 * @desc get id for multicasted generic netlink messages
48 * only one multicast group is supported per family id now.
49 * This function also gets family id, due it comes with the
50 * same answer as a multicast generic netlink message.
52 uint32_t get_family_group_id(int sock, pid_t pid,
53 char *family_name, char *group_name,
57 * @desc Extracts family id from answer
58 * accepts opaque pointer
60 uint32_t netlink_get_family(struct genl *nl_ans);
63 * @desc This function sends to kernel command to start
64 * network activity reporting. This function creats
65 * and closes socket itself.
67 resourced_ret_c start_net_activity(void);
70 * @desc Stop network activity @see start_net_activity
72 resourced_ret_c stop_net_activity(void);
74 struct net_activity_info;
77 * @desc Receive and fill activity info from netlink socket.
78 * Received activity_info should contain the same family_id as
79 * net_activity_family_id
81 enum net_activity_recv recv_net_activity(int sock, struct net_activity_info
82 *activity_info, const uint32_t net_activity_family_id);
85 * @desc Extracts family id from answer
86 * accepts opaque pointer
88 uint32_t netlink_get_family(struct genl *nl_ans);
90 void send_start(int sock, const pid_t pid, const int family_id);
92 int send_command(int sock, const pid_t pid, const int family_id, uint8_t cmd);
94 int send_restriction(int sock, const pid_t pid, const int family_id,
95 const u_int32_t classid, const int ifindex,
96 const enum traffic_restriction_type restriction_type,
99 const int snd_warning_threshold,
100 const int rcv_warning_threshold);
102 resourced_ret_c process_netlink_restriction_msg(const struct genl *ans,
103 struct traffic_restriction *restriction, uint8_t *command);
105 #endif /*_GRABBER_CONTROL_KERNEL_GENERIC_NETLINK_H_*/