8da2f645f527f3b07f44c3986ce1b95edb510c36
[platform/core/connectivity/stc-iptables.git] / src / helper / helper-ip6tables.h
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License version 2 as
6  *  published by the Free Software Foundation.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17
18 /*
19  * Manage ip6tables rule using libip6tc
20  */
21 #ifndef __STC_HELPER_IP6TABLES_H__
22 #define __STC_HELPER_IP6TABLES_H__
23
24 #include <libiptc/libip6tc.h>
25
26 #define RULE_SIZE     64
27
28 typedef enum {
29         IP6TABLES_CHAIN_INPUT,
30         IP6TABLES_CHAIN_OUTPUT
31 } ip6tables_chain_e;
32
33 typedef enum {
34         IP6TABLES_DIRECTION_NONE,
35         IP6TABLES_DIRECTION_IN,
36         IP6TABLES_DIRECTION_OUT
37 } ip6tables_direction_e;
38
39 typedef enum {
40         IP6TABLES_IP_NONE,
41         IP6TABLES_IP_SINGLE,
42         IP6TABLES_IP_MASK,
43         IP6TABLES_IP_RANGE
44 } ip6tables_ip_type_e;
45
46 typedef enum {
47         IP6TABLES_PORT_NONE,
48         IP6TABLES_PORT_SINGLE,
49         IP6TABLES_PORT_RANGE
50 } ip6tables_port_type_e;
51
52 typedef enum {
53         IP6TABLES_PROTOCOL_NONE,
54         IP6TABLES_PROTOCOL_TCP,
55         IP6TABLES_PROTOCOL_UDP,
56         IP6TABLES_PROTOCOL_ICMP,
57         IP6TABLES_PROTOCOL_ESP,
58         IP6TABLES_PROTOCOL_AH,
59         IP6TABLES_PROTOCOL_SCTP,
60         IP6TABLES_PROTOCOL_MH,
61         IP6TABLES_PROTOCOL_ALL,
62 } ip6tables_protocol_type_e;
63
64 typedef enum {
65         IP6TABLES_ACTION_NONE,
66         IP6TABLES_ACTION_ACCEPT,
67         IP6TABLES_ACTION_DROP,
68         IP6TABLES_ACTION_LOG,
69         IP6TABLES_ACTION_NFLOG,
70 } ip6tables_target_action_e;
71
72 typedef struct {
73         char *chain;
74         ip6tables_direction_e direction;
75         ip6tables_ip_type_e s_ip_type;
76         ip6tables_ip_type_e d_ip_type;
77         ip6tables_port_type_e s_port_type;
78         ip6tables_port_type_e d_port_type;
79         ip6tables_protocol_type_e protocol;
80         struct in6_addr s_ip1;
81         struct in6_addr s_ip2;
82         struct in6_addr d_ip1;
83         struct in6_addr d_ip2;
84         unsigned int s_port1;
85         unsigned int s_port2;
86         unsigned int d_port1;
87         unsigned int d_port2;
88         char *ifname;
89         int classid;
90         char *nfacct_name;
91         char *target;
92         ip6tables_target_action_e target_type;
93         unsigned char log_level;
94         char *log_prefix;
95         unsigned int nflog_group;
96         char *nflog_prefix;
97         unsigned int nflog_range;
98         unsigned int nflog_threshold;
99 } ip6tables_rule_s;
100
101 /**
102  * @desc This function adds a new ip6tables rule.
103  * @return 0 on success and negative value if error.
104  */
105 int ip6tables_add_rule(ip6tables_rule_s *rule);
106
107 /**
108  * @desc This function inserts a new ip6tables rule.
109  * @return 0 on success and negative value if error.
110  */
111 int ip6tables_insert_rule(ip6tables_rule_s *rule);
112
113 /**
114  * @desc This function removes already set ip6tables rule.
115  * @return 0 on success and negative value if error.
116  */
117 int ip6tables_remove_rule(ip6tables_rule_s *rule);
118
119 /**
120  * @desc This function adds a new ip6tables chain.
121  * @return 0 on success and negative value if error.
122  */
123 int ip6tables_add_chain(const char *chain);
124
125 /**
126  * @desc This function removes already set ip6tables chain.
127  * @return 0 on success and negative value if error.
128  */
129 int ip6tables_remove_chain(const char *chain);
130
131 /**
132  * @desc This function flushes all ip6tables rules in chain.
133  * @return 0 on success and negative value if error.
134  */
135 int ip6tables_flush_chain(const char *chain);
136
137 #endif /*__STC_HELPER_IP6TABLES_H__*/