tizen 2.3.1 release
[kernel/api/system-resource.git] / src / network / include / generic-netlink.h
1 /*
2  * resourced
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 /**
20  * @file generic-netlink.h
21  * @desc Helper function for making kernel request and process response
22  **/
23
24 #ifndef _GRABBER_CONTROL_KERNEL_GENERIC_NETLINK_H_
25 #define _GRABBER_CONTROL_KERNEL_GENERIC_NETLINK_H_
26
27 #include "counter.h"
28 #include "genl.h"
29 #include "nl-helper.h"
30
31 #include <unistd.h>
32 #include <linux/genetlink.h>
33 #include <linux/rtnetlink.h>
34
35 enum net_activity_recv {
36         RESOURCED_NET_ACTIVITY_OK,
37         RESOURCED_NET_ACTIVITY_STOP,
38         RESOURCED_NET_ACTIVITY_CONTINUE,
39 };
40
41 netlink_serialization_command *netlink_create_command(
42         struct netlink_serialization_params *params);
43
44 uint32_t get_family_id(int sock, pid_t pid, char *family_name);
45
46 /**
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.
51  */
52 uint32_t get_family_group_id(int sock, pid_t pid,
53                         char *family_name, char *group_name,
54                         uint32_t *family_id);
55
56 /**
57  * @desc Extracts family id from answer
58  *      accepts opaque pointer
59  **/
60 uint32_t netlink_get_family(struct genl *nl_ans);
61
62 /**
63  * @desc This function sends to kernel command to start
64  *      network activity reporting. This function creats
65  *      and closes socket itself.
66  **/
67 resourced_ret_c start_net_activity(void);
68
69 /**
70  * @desc Stop network activity @see start_net_activity
71  **/
72 resourced_ret_c stop_net_activity(void);
73
74 struct net_activity_info;
75
76 /**
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
80  */
81 enum net_activity_recv recv_net_activity(int sock, struct net_activity_info
82         *activity_info, const uint32_t net_activity_family_id);
83
84 /**
85  * @desc Extracts family id from answer
86  *      accepts opaque pointer
87  **/
88 uint32_t netlink_get_family(struct genl *nl_ans);
89
90 void send_start(int sock, const pid_t pid, const int family_id);
91
92 int send_command(int sock, const pid_t pid, const int family_id, uint8_t cmd);
93
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,
97                      const int send_limit,
98                      const int rcv_limit,
99                      const int snd_warning_threshold,
100                      const int rcv_warning_threshold);
101
102 resourced_ret_c process_netlink_restriction_msg(const struct genl *ans,
103         struct traffic_restriction *restriction, uint8_t *command);
104
105 #endif /*_GRABBER_CONTROL_KERNEL_GENERIC_NETLINK_H_*/