tizen 2.3 release
[kernel/api/system-resource.git] / src / network / include / nfacct-rule.h
1 /*
2  * resourced
3  *
4  * Copyright (c) 2012-2014 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 nfacct-rule.h
21  *
22  * @desc API for nfacct module
23  *
24  * Copyright (c) 2012-2014 Samsung Electronics Co., Ltd. All rights reserved.
25  *
26  */
27
28 #ifndef _RESOURCED_NFACCT_RULE_H
29 #define _RESOURCED_NFACCT_RULE_H
30
31 #include "const.h"
32 #include "data_usage.h"
33
34 #include <stdbool.h>
35 #include <sys/types.h>
36 #include <unistd.h>
37
38 typedef enum {
39         NFACCT_COUNTER_UNKNOWN,
40         NFACCT_COUNTER_IN = (1 << 1),
41         NFACCT_COUNTER_OUT = (1 << 2),
42         NFACCT_COUNTER_LAST_ELEM
43 } nfacct_rule_direction;
44
45 typedef enum {
46         NFACCT_ACTION_UNKNOWN,
47         NFACCT_ACTION_APPEND,
48         NFACCT_ACTION_DELETE,
49         NFACCT_ACTION_INSERT,
50         NFACCT_ACTION_LAST_ELEM,
51 } nfacct_rule_action;
52
53 typedef enum {
54         NFACCT_JUMP_UNKNOWN,
55         NFACCT_JUMP_ACCEPT,
56         NFACCT_JUMP_REJECT,
57         NFACCT_JUMP_LAST_ELEM,
58 } nfacct_rule_jump;
59
60 typedef enum {
61         NFACCT_COUNTER,
62         NFACCT_WARN,
63         NFACCT_BLOCK,
64         NFACCT_RULE_LAST_ELEM,
65 } nfacct_rule_intend;
66
67 struct nfacct_rule {
68         char name[MAX_NAME_LENGTH];
69         char ifname[MAX_NAME_LENGTH];
70
71         pid_t pid;
72         u_int32_t classid;
73         resourced_iface_type iftype;
74         nfacct_rule_direction iotype;
75         nfacct_rule_intend intend;
76         struct counter_arg *carg;
77         resourced_ret_c(*iptables_rule)(struct nfacct_rule *counter);
78         u_int64_t quota;
79 };
80
81 struct counter_arg;
82
83 void generate_counter_name(struct nfacct_rule *counter);
84 bool recreate_counter_by_name(char *cnt_name, struct nfacct_rule *counter);
85
86 resourced_ret_c  nfacct_send_get(struct counter_arg *carg);
87 resourced_ret_c nfacct_send_initiate(struct counter_arg *carg);
88
89 resourced_ret_c exec_iptables_cmd(const char *cmd_buf, pid_t *pid);
90 resourced_ret_c produce_net_rule(struct nfacct_rule *rule,
91                         const int send_limit, const int rcv_limit,
92                         const nfacct_rule_action action,
93                         const nfacct_rule_jump jump,
94                         const nfacct_rule_direction iotype);
95
96 #endif /* _RESOURCED_NFACCT_RULE_H */
97